Skip to content

[X86] Use MCRegister instead of int64_t in X86MCExpr. NFC #106569

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 1 commit into from
Aug 29, 2024

Conversation

topperc
Copy link
Collaborator

@topperc topperc commented Aug 29, 2024

No description provided.

@llvmbot
Copy link
Member

llvmbot commented Aug 29, 2024

@llvm/pr-subscribers-backend-x86

Author: Craig Topper (topperc)

Changes

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

2 Files Affected:

  • (modified) llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp (+3-3)
  • (modified) llvm/lib/Target/X86/MCTargetDesc/X86MCExpr.h (+7-7)
diff --git a/llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp b/llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
index 864b7d8e769ab1..2b6b0ad16bcf76 100644
--- a/llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
+++ b/llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
@@ -2789,7 +2789,7 @@ bool X86AsmParser::parseATTOperand(OperandVector &Operands) {
       if (auto *RE = dyn_cast<X86MCExpr>(Expr)) {
         // Segment Register. Reset Expr and copy value to register.
         Expr = nullptr;
-        Reg = RE->getRegNo();
+        Reg = RE->getReg();
 
         // Check the register.
         if (Reg == X86::EIZ || Reg == X86::RIZ)
@@ -3052,7 +3052,7 @@ bool X86AsmParser::ParseMemOperand(unsigned SegReg, const MCExpr *Disp,
       return true;
 
     // Check the register.
-    BaseReg = cast<X86MCExpr>(E)->getRegNo();
+    BaseReg = cast<X86MCExpr>(E)->getReg();
     if (BaseReg == X86::EIZ || BaseReg == X86::RIZ)
       return Error(BaseLoc, "eiz and riz can only be used as index registers",
                    SMRange(BaseLoc, EndLoc));
@@ -3079,7 +3079,7 @@ bool X86AsmParser::ParseMemOperand(unsigned SegReg, const MCExpr *Disp,
           Warning(Loc, "scale factor without index register is ignored");
         Scale = 1;
       } else { // IndexReg Found.
-        IndexReg = cast<X86MCExpr>(E)->getRegNo();
+        IndexReg = cast<X86MCExpr>(E)->getReg();
 
         if (BaseReg == X86::RIP)
           return Error(Loc,
diff --git a/llvm/lib/Target/X86/MCTargetDesc/X86MCExpr.h b/llvm/lib/Target/X86/MCTargetDesc/X86MCExpr.h
index c159d30194cc64..37e15193b04357 100644
--- a/llvm/lib/Target/X86/MCTargetDesc/X86MCExpr.h
+++ b/llvm/lib/Target/X86/MCTargetDesc/X86MCExpr.h
@@ -26,16 +26,16 @@ namespace llvm {
 class X86MCExpr : public MCTargetExpr {
 
 private:
-  const int64_t RegNo; // All
+  const MCRegister Reg; // All
 
-  explicit X86MCExpr(int64_t R) : RegNo(R) {}
+  explicit X86MCExpr(MCRegister R) : Reg(R) {}
 
 public:
   /// @name Construction
   /// @{
 
-  static const X86MCExpr *create(int64_t RegNo, MCContext &Ctx) {
-    return new (Ctx) X86MCExpr(RegNo);
+  static const X86MCExpr *create(MCRegister Reg, MCContext &Ctx) {
+    return new (Ctx) X86MCExpr(Reg);
   }
 
   /// @}
@@ -43,14 +43,14 @@ class X86MCExpr : public MCTargetExpr {
   /// @{
 
   /// getSubExpr - Get the child of this expression.
-  int64_t getRegNo() const { return RegNo; }
+  MCRegister getReg() const { return Reg; }
 
   /// @}
 
   void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override {
     if (!MAI || MAI->getAssemblerDialect() == 0)
       OS << '%';
-    OS << X86ATTInstPrinter::getRegisterName(RegNo);
+    OS << X86ATTInstPrinter::getRegisterName(Reg);
   }
 
   bool evaluateAsRelocatableImpl(MCValue &Res, const MCAssembler *Asm,
@@ -61,7 +61,7 @@ class X86MCExpr : public MCTargetExpr {
   bool inlineAssignedExpr() const override { return true; }
   bool isEqualTo(const MCExpr *X) const override {
     if (auto *E = dyn_cast<X86MCExpr>(X))
-      return getRegNo() == E->getRegNo();
+      return getReg() == E->getReg();
     return false;
   }
   void visitUsedExpr(MCStreamer &Streamer) const override {}

Copy link
Collaborator

@RKSimon RKSimon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@topperc topperc merged commit 593526f into llvm:main Aug 29, 2024
10 checks passed
@topperc topperc deleted the pr/x86mcexpr branch August 29, 2024 21:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants