-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[TableGen] Fix validateOperandClass for non Phyical Reg #118146
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
llvm@b71704436e61 Rewrote the register operands handling, but the Table only contains physical regs, we will SEGV when there are non physical regs.
@llvm/pr-subscribers-tablegen Author: Jinsong Ji (jsji) Changesb71704436e61 Full diff: https://github.com/llvm/llvm-project/pull/118146.diff 1 Files Affected:
diff --git a/llvm/utils/TableGen/AsmMatcherEmitter.cpp b/llvm/utils/TableGen/AsmMatcherEmitter.cpp
index 28efd780c5c615..1823783e82be4a 100644
--- a/llvm/utils/TableGen/AsmMatcherEmitter.cpp
+++ b/llvm/utils/TableGen/AsmMatcherEmitter.cpp
@@ -2522,8 +2522,9 @@ static void emitValidateOperandClass(const CodeGenTarget &Target,
for (auto &MatchClassName : Table)
OS << " " << MatchClassName << ",\n";
OS << " };\n\n";
- OS << " MatchClassKind OpKind = "
- "(MatchClassKind)Table[Operand.getReg().id()];\n";
+ OS << " auto RegID=Operand.getReg().id();\n";
+ OS << " MatchClassKind OpKind = Register::isPhysicalRegister(RegID)?"
+ "(MatchClassKind)Table[RegID]: InvalidMatchClass;\n";
OS << " return isSubclass(OpKind, Kind) ? "
<< "(unsigned)MCTargetAsmParser::Match_Success :\n "
<< " getDiagKindFromRegisterClass(Kind);\n }\n\n";
|
How can a register not be physical here? |
Target can allow using non-physical registers in assembly. |
OS << " auto RegID=Operand.getReg().id();\n"; | ||
OS << " MatchClassKind OpKind = MCRegister::isPhysicalRegister(RegID)?" | ||
"(MatchClassKind)Table[RegID]: InvalidMatchClass;\n"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpicking
auto
is discouraged by the coding standard- the generated code is misformatted around '=', '?' and ':'
I see, thanks. |
Co-authored-by: Sergei Barannikov <[email protected]>
Thanks @s-barannikov ! |
Can you add a test case for this? |
Sorry, I don't see easy way to do so, it involves defining a new target |
Well, OK, but with no test and no in-tree use there is nothing to stop your use case being broken again in future. Did you consider just carrying the tablegen change downstream? |
b71704436e61
Rewrote the register operands handling,
but the Table only contains physical regs, we will SEGV when there are
non physical regs.