Skip to content

[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

Merged
merged 4 commits into from
Nov 30, 2024
Merged

Conversation

jsji
Copy link
Member

@jsji jsji commented Nov 30, 2024

b71704436e61
Rewrote the register operands handling,
but the Table only contains physical regs, we will SEGV when there are
non physical regs.

llvm@b71704436e61
Rewrote the register operands handling,
but the Table only contains physical regs, we will SEGV when there are
non physical regs.
@jsji jsji requested a review from jayfoad November 30, 2024 00:56
@jsji jsji self-assigned this Nov 30, 2024
@jsji jsji requested a review from s-barannikov November 30, 2024 00:56
@llvmbot
Copy link
Member

llvmbot commented Nov 30, 2024

@llvm/pr-subscribers-tablegen

Author: Jinsong Ji (jsji)

Changes

b71704436e61
Rewrote the register operands handling,
but the Table only contains physical regs, we will SEGV when there are
non physical regs.


Full diff: https://github.com/llvm/llvm-project/pull/118146.diff

1 Files Affected:

  • (modified) llvm/utils/TableGen/AsmMatcherEmitter.cpp (+3-2)
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";

@jsji jsji changed the title Fix validateOperandClass for non Phyical Reg [TableGen] Fix validateOperandClass for non Phyical Reg Nov 30, 2024
@s-barannikov
Copy link
Contributor

s-barannikov commented Nov 30, 2024

How can a register not be physical here?

@jsji
Copy link
Member Author

jsji commented Nov 30, 2024

How can a register not be physical here?

Target can allow using non-physical registers in assembly.
We do have a downstream target that use virtual registers.
The original code also supports such scenarios in the default clause.

Comment on lines 2525 to 2527
OS << " auto RegID=Operand.getReg().id();\n";
OS << " MatchClassKind OpKind = MCRegister::isPhysicalRegister(RegID)?"
"(MatchClassKind)Table[RegID]: InvalidMatchClass;\n";
Copy link
Contributor

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 ':'

@s-barannikov
Copy link
Contributor

How can a register not be physical here?

Target can allow using non-physical registers in assembly. We do have a downstream target that use virtual registers. The original code also supports such scenarios in the default clause.

I see, thanks.

@jsji jsji requested a review from s-barannikov November 30, 2024 16:48
@jsji
Copy link
Member Author

jsji commented Nov 30, 2024

Thanks @s-barannikov !

@jsji jsji merged commit 2e30df7 into llvm:main Nov 30, 2024
5 of 8 checks passed
@jayfoad
Copy link
Contributor

jayfoad commented Dec 2, 2024

Can you add a test case for this?

@jsji
Copy link
Member Author

jsji commented Dec 2, 2024

Can you add a test case for this?

Sorry, I don't see easy way to do so, it involves defining a new target

@jayfoad
Copy link
Contributor

jayfoad commented Dec 2, 2024

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants