[llvm] [AArch64] Rename VariantKind to Specifier (PR #132595)

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 25 23:36:31 PDT 2025


https://github.com/MaskRay updated https://github.com/llvm/llvm-project/pull/132595

>From fd7478392bc478963d37d3fe69b70d674f5cb020 Mon Sep 17 00:00:00 2001
From: Fangrui Song <i at maskray.me>
Date: Sat, 22 Mar 2025 23:33:12 -0700
Subject: [PATCH 1/2] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20in?=
 =?UTF-8?q?itial=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.5-bogner
---
 llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp |   4 +-
 .../lib/Target/AArch64/AArch64MCInstLower.cpp |   6 +-
 .../AArch64/AsmParser/AArch64AsmParser.cpp    | 144 ++++++++----------
 .../MCTargetDesc/AArch64AsmBackend.cpp        |  12 +-
 .../MCTargetDesc/AArch64ELFObjectWriter.cpp   |  11 +-
 .../MCTargetDesc/AArch64MCCodeEmitter.cpp     |   4 +-
 .../AArch64/MCTargetDesc/AArch64MCExpr.cpp    |  14 +-
 .../AArch64/MCTargetDesc/AArch64MCExpr.h      |  28 ++--
 .../AArch64WinCOFFObjectWriter.cpp            |  14 +-
 9 files changed, 112 insertions(+), 125 deletions(-)

diff --git a/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp b/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp
index 79b190388eb75..4178d00782a7e 100644
--- a/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp
+++ b/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp
@@ -923,14 +923,14 @@ void AArch64AsmPrinter::emitHwasanMemaccessSymbols(Module &M) {
           MCInstBuilder(AArch64::ADRP)
               .addReg(AArch64::X16)
               .addExpr(AArch64MCExpr::create(
-                  HwasanTagMismatchRef, AArch64MCExpr::VariantKind::VK_GOT_PAGE,
+                  HwasanTagMismatchRef, AArch64MCExpr::Specifier::VK_GOT_PAGE,
                   OutContext)));
       EmitToStreamer(
           MCInstBuilder(AArch64::LDRXui)
               .addReg(AArch64::X16)
               .addReg(AArch64::X16)
               .addExpr(AArch64MCExpr::create(
-                  HwasanTagMismatchRef, AArch64MCExpr::VariantKind::VK_GOT_LO12,
+                  HwasanTagMismatchRef, AArch64MCExpr::Specifier::VK_GOT_LO12,
                   OutContext)));
       EmitToStreamer(MCInstBuilder(AArch64::BR).addReg(AArch64::X16));
     }
diff --git a/llvm/lib/Target/AArch64/AArch64MCInstLower.cpp b/llvm/lib/Target/AArch64/AArch64MCInstLower.cpp
index db8522cabd681..6a02a75ddbb4d 100644
--- a/llvm/lib/Target/AArch64/AArch64MCInstLower.cpp
+++ b/llvm/lib/Target/AArch64/AArch64MCInstLower.cpp
@@ -266,8 +266,8 @@ MCOperand AArch64MCInstLower::lowerSymbolOperandELF(const MachineOperand &MO,
     Expr = MCBinaryExpr::createAdd(
         Expr, MCConstantExpr::create(MO.getOffset(), Ctx), Ctx);
 
-  AArch64MCExpr::VariantKind RefKind;
-  RefKind = static_cast<AArch64MCExpr::VariantKind>(RefFlags);
+  AArch64MCExpr::Specifier RefKind;
+  RefKind = static_cast<AArch64MCExpr::Specifier>(RefFlags);
   Expr = AArch64MCExpr::create(Expr, RefKind, Ctx);
 
   return MCOperand::createExpr(Expr);
@@ -320,7 +320,7 @@ MCOperand AArch64MCInstLower::lowerSymbolOperandCOFF(const MachineOperand &MO,
     Expr = MCBinaryExpr::createAdd(
         Expr, MCConstantExpr::create(MO.getOffset(), Ctx), Ctx);
 
-  auto RefKind = static_cast<AArch64MCExpr::VariantKind>(RefFlags);
+  auto RefKind = static_cast<AArch64MCExpr::Specifier>(RefFlags);
   assert(RefKind != AArch64MCExpr::VK_INVALID &&
          "Invalid relocation requested");
   Expr = AArch64MCExpr::create(Expr, RefKind, Ctx);
diff --git a/llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp b/llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp
index d678dd88e05da..b107a9a9e8776 100644
--- a/llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp
+++ b/llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp
@@ -338,7 +338,7 @@ class AArch64AsmParser : public MCTargetAsmParser {
   bool parsePrimaryExpr(const MCExpr *&Res, SMLoc &EndLoc) override;
 
   static bool classifySymbolRef(const MCExpr *Expr,
-                                AArch64MCExpr::VariantKind &ELFRefKind,
+                                AArch64MCExpr::Specifier &ELFSpec,
                                 MCSymbolRefExpr::VariantKind &DarwinRefKind,
                                 int64_t &Addend);
 };
@@ -888,30 +888,26 @@ class AArch64Operand : public MCParsedAsmOperand {
   }
 
   bool isSymbolicUImm12Offset(const MCExpr *Expr) const {
-    AArch64MCExpr::VariantKind ELFRefKind;
+    AArch64MCExpr::Specifier ELFSpec;
     MCSymbolRefExpr::VariantKind DarwinRefKind;
     int64_t Addend;
-    if (!AArch64AsmParser::classifySymbolRef(Expr, ELFRefKind, DarwinRefKind,
-                                           Addend)) {
+    if (!AArch64AsmParser::classifySymbolRef(Expr, ELFSpec, DarwinRefKind,
+                                             Addend)) {
       // If we don't understand the expression, assume the best and
       // let the fixup and relocation code deal with it.
       return true;
     }
 
     if (DarwinRefKind == MCSymbolRefExpr::VK_PAGEOFF ||
-        ELFRefKind == AArch64MCExpr::VK_LO12 ||
-        ELFRefKind == AArch64MCExpr::VK_GOT_LO12 ||
-        ELFRefKind == AArch64MCExpr::VK_GOT_AUTH_LO12 ||
-        ELFRefKind == AArch64MCExpr::VK_DTPREL_LO12 ||
-        ELFRefKind == AArch64MCExpr::VK_DTPREL_LO12_NC ||
-        ELFRefKind == AArch64MCExpr::VK_TPREL_LO12 ||
-        ELFRefKind == AArch64MCExpr::VK_TPREL_LO12_NC ||
-        ELFRefKind == AArch64MCExpr::VK_GOTTPREL_LO12_NC ||
-        ELFRefKind == AArch64MCExpr::VK_TLSDESC_LO12 ||
-        ELFRefKind == AArch64MCExpr::VK_TLSDESC_AUTH_LO12 ||
-        ELFRefKind == AArch64MCExpr::VK_SECREL_LO12 ||
-        ELFRefKind == AArch64MCExpr::VK_SECREL_HI12 ||
-        ELFRefKind == AArch64MCExpr::VK_GOT_PAGE_LO15) {
+        llvm::is_contained(
+            {AArch64MCExpr::VK_LO12, AArch64MCExpr::VK_GOT_LO12,
+             AArch64MCExpr::VK_GOT_AUTH_LO12, AArch64MCExpr::VK_DTPREL_LO12,
+             AArch64MCExpr::VK_DTPREL_LO12_NC, AArch64MCExpr::VK_TPREL_LO12,
+             AArch64MCExpr::VK_TPREL_LO12_NC,
+             AArch64MCExpr::VK_GOTTPREL_LO12_NC, AArch64MCExpr::VK_TLSDESC_LO12,
+             AArch64MCExpr::VK_TLSDESC_AUTH_LO12, AArch64MCExpr::VK_SECREL_LO12,
+             AArch64MCExpr::VK_SECREL_HI12, AArch64MCExpr::VK_GOT_PAGE_LO15},
+            ELFSpec)) {
       // Note that we don't range-check the addend. It's adjusted modulo page
       // size when converted, so there is no "out of range" condition when using
       // @pageoff.
@@ -1009,26 +1005,24 @@ class AArch64Operand : public MCParsedAsmOperand {
       Expr = getImm();
     }
 
-    AArch64MCExpr::VariantKind ELFRefKind;
+    AArch64MCExpr::Specifier ELFSpec;
     MCSymbolRefExpr::VariantKind DarwinRefKind;
     int64_t Addend;
-    if (AArch64AsmParser::classifySymbolRef(Expr, ELFRefKind,
-                                          DarwinRefKind, Addend)) {
+    if (AArch64AsmParser::classifySymbolRef(Expr, ELFSpec, DarwinRefKind,
+                                            Addend)) {
       return DarwinRefKind == MCSymbolRefExpr::VK_PAGEOFF ||
              DarwinRefKind == MCSymbolRefExpr::VK_TLVPPAGEOFF ||
              (DarwinRefKind == MCSymbolRefExpr::VK_GOTPAGEOFF && Addend == 0) ||
-             ELFRefKind == AArch64MCExpr::VK_LO12 ||
-             ELFRefKind == AArch64MCExpr::VK_GOT_AUTH_LO12 ||
-             ELFRefKind == AArch64MCExpr::VK_DTPREL_HI12 ||
-             ELFRefKind == AArch64MCExpr::VK_DTPREL_LO12 ||
-             ELFRefKind == AArch64MCExpr::VK_DTPREL_LO12_NC ||
-             ELFRefKind == AArch64MCExpr::VK_TPREL_HI12 ||
-             ELFRefKind == AArch64MCExpr::VK_TPREL_LO12 ||
-             ELFRefKind == AArch64MCExpr::VK_TPREL_LO12_NC ||
-             ELFRefKind == AArch64MCExpr::VK_TLSDESC_LO12 ||
-             ELFRefKind == AArch64MCExpr::VK_TLSDESC_AUTH_LO12 ||
-             ELFRefKind == AArch64MCExpr::VK_SECREL_HI12 ||
-             ELFRefKind == AArch64MCExpr::VK_SECREL_LO12;
+             llvm::is_contained(
+                 {AArch64MCExpr::VK_LO12, AArch64MCExpr::VK_GOT_AUTH_LO12,
+                  AArch64MCExpr::VK_DTPREL_HI12, AArch64MCExpr::VK_DTPREL_LO12,
+                  AArch64MCExpr::VK_DTPREL_LO12_NC,
+                  AArch64MCExpr::VK_TPREL_HI12, AArch64MCExpr::VK_TPREL_LO12,
+                  AArch64MCExpr::VK_TPREL_LO12_NC,
+                  AArch64MCExpr::VK_TLSDESC_LO12,
+                  AArch64MCExpr::VK_TLSDESC_AUTH_LO12,
+                  AArch64MCExpr::VK_SECREL_HI12, AArch64MCExpr::VK_SECREL_LO12},
+                 ELFSpec);
     }
 
     // If it's a constant, it should be a real immediate in range.
@@ -1121,22 +1115,21 @@ class AArch64Operand : public MCParsedAsmOperand {
     return (Val >= -((1<<(N-1)) << 2) && Val <= (((1<<(N-1))-1) << 2));
   }
 
-  bool
-  isMovWSymbol(ArrayRef<AArch64MCExpr::VariantKind> AllowedModifiers) const {
+  bool isMovWSymbol(ArrayRef<AArch64MCExpr::Specifier> AllowedModifiers) const {
     if (!isImm())
       return false;
 
-    AArch64MCExpr::VariantKind ELFRefKind;
+    AArch64MCExpr::Specifier ELFSpec;
     MCSymbolRefExpr::VariantKind DarwinRefKind;
     int64_t Addend;
-    if (!AArch64AsmParser::classifySymbolRef(getImm(), ELFRefKind,
-                                             DarwinRefKind, Addend)) {
+    if (!AArch64AsmParser::classifySymbolRef(getImm(), ELFSpec, DarwinRefKind,
+                                             Addend)) {
       return false;
     }
     if (DarwinRefKind != MCSymbolRefExpr::VK_None)
       return false;
 
-    return llvm::is_contained(AllowedModifiers, ELFRefKind);
+    return llvm::is_contained(AllowedModifiers, ELFSpec);
   }
 
   bool isMovWSymbolG3() const {
@@ -3304,12 +3297,12 @@ ParseStatus AArch64AsmParser::tryParseAdrpLabel(OperandVector &Operands) {
   if (parseSymbolicImmVal(Expr))
     return ParseStatus::Failure;
 
-  AArch64MCExpr::VariantKind ELFRefKind;
+  AArch64MCExpr::Specifier ELFSpec;
   MCSymbolRefExpr::VariantKind DarwinRefKind;
   int64_t Addend;
-  if (classifySymbolRef(Expr, ELFRefKind, DarwinRefKind, Addend)) {
+  if (classifySymbolRef(Expr, ELFSpec, DarwinRefKind, Addend)) {
     if (DarwinRefKind == MCSymbolRefExpr::VK_None &&
-        ELFRefKind == AArch64MCExpr::VK_INVALID) {
+        ELFSpec == AArch64MCExpr::VK_INVALID) {
       // No modifier was specified at all; this is the syntax for an ELF basic
       // ADRP relocation (unfortunately).
       Expr =
@@ -3321,13 +3314,13 @@ ParseStatus AArch64AsmParser::tryParseAdrpLabel(OperandVector &Operands) {
     } else if (DarwinRefKind != MCSymbolRefExpr::VK_PAGE &&
                DarwinRefKind != MCSymbolRefExpr::VK_GOTPAGE &&
                DarwinRefKind != MCSymbolRefExpr::VK_TLVPPAGE &&
-               ELFRefKind != AArch64MCExpr::VK_ABS_PAGE_NC &&
-               ELFRefKind != AArch64MCExpr::VK_GOT_PAGE &&
-               ELFRefKind != AArch64MCExpr::VK_GOT_AUTH_PAGE &&
-               ELFRefKind != AArch64MCExpr::VK_GOT_PAGE_LO15 &&
-               ELFRefKind != AArch64MCExpr::VK_GOTTPREL_PAGE &&
-               ELFRefKind != AArch64MCExpr::VK_TLSDESC_PAGE &&
-               ELFRefKind != AArch64MCExpr::VK_TLSDESC_AUTH_PAGE) {
+               ELFSpec != AArch64MCExpr::VK_ABS_PAGE_NC &&
+               ELFSpec != AArch64MCExpr::VK_GOT_PAGE &&
+               ELFSpec != AArch64MCExpr::VK_GOT_AUTH_PAGE &&
+               ELFSpec != AArch64MCExpr::VK_GOT_PAGE_LO15 &&
+               ELFSpec != AArch64MCExpr::VK_GOTTPREL_PAGE &&
+               ELFSpec != AArch64MCExpr::VK_TLSDESC_PAGE &&
+               ELFSpec != AArch64MCExpr::VK_TLSDESC_AUTH_PAGE) {
       // The operand must be an @page or @gotpage qualified symbolref.
       return Error(S, "page or gotpage label reference expected");
     }
@@ -3358,16 +3351,16 @@ ParseStatus AArch64AsmParser::tryParseAdrLabel(OperandVector &Operands) {
   if (parseSymbolicImmVal(Expr))
     return ParseStatus::Failure;
 
-  AArch64MCExpr::VariantKind ELFRefKind;
+  AArch64MCExpr::Specifier ELFSpec;
   MCSymbolRefExpr::VariantKind DarwinRefKind;
   int64_t Addend;
-  if (classifySymbolRef(Expr, ELFRefKind, DarwinRefKind, Addend)) {
+  if (classifySymbolRef(Expr, ELFSpec, DarwinRefKind, Addend)) {
     if (DarwinRefKind == MCSymbolRefExpr::VK_None &&
-        ELFRefKind == AArch64MCExpr::VK_INVALID) {
+        ELFSpec == AArch64MCExpr::VK_INVALID) {
       // No modifier was specified at all; this is the syntax for an ELF basic
       // ADR relocation (unfortunately).
       Expr = AArch64MCExpr::create(Expr, AArch64MCExpr::VK_ABS, getContext());
-    } else if (ELFRefKind != AArch64MCExpr::VK_GOT_AUTH_PAGE) {
+    } else if (ELFSpec != AArch64MCExpr::VK_GOT_AUTH_PAGE) {
       // For tiny code model, we use :got_auth: operator to fill 21-bit imm of
       // adr. It's not actually GOT entry page address but the GOT address
       // itself - we just share the same variant kind with :got_auth: operator
@@ -4408,7 +4401,7 @@ bool AArch64AsmParser::parseRegister(OperandVector &Operands) {
 
 bool AArch64AsmParser::parseSymbolicImmVal(const MCExpr *&ImmVal) {
   bool HasELFModifier = false;
-  AArch64MCExpr::VariantKind RefKind;
+  AArch64MCExpr::Specifier RefKind;
 
   if (parseOptionalToken(AsmToken::Colon)) {
     HasELFModifier = true;
@@ -4418,7 +4411,7 @@ bool AArch64AsmParser::parseSymbolicImmVal(const MCExpr *&ImmVal) {
 
     std::string LowerCase = getTok().getIdentifier().lower();
     RefKind =
-        StringSwitch<AArch64MCExpr::VariantKind>(LowerCase)
+        StringSwitch<AArch64MCExpr::Specifier>(LowerCase)
             .Case("lo12", AArch64MCExpr::VK_LO12)
             .Case("abs_g3", AArch64MCExpr::VK_ABS_G3)
             .Case("abs_g2", AArch64MCExpr::VK_ABS_G2)
@@ -5824,10 +5817,10 @@ bool AArch64AsmParser::validateInstruction(MCInst &Inst, SMLoc &IDLoc,
     // some slight duplication here.
     if (Inst.getOperand(2).isExpr()) {
       const MCExpr *Expr = Inst.getOperand(2).getExpr();
-      AArch64MCExpr::VariantKind ELFRefKind;
+      AArch64MCExpr::Specifier ELFSpec;
       MCSymbolRefExpr::VariantKind DarwinRefKind;
       int64_t Addend;
-      if (classifySymbolRef(Expr, ELFRefKind, DarwinRefKind, Addend)) {
+      if (classifySymbolRef(Expr, ELFSpec, DarwinRefKind, Addend)) {
 
         // Only allow these with ADDXri.
         if ((DarwinRefKind == MCSymbolRefExpr::VK_PAGEOFF ||
@@ -5836,18 +5829,15 @@ bool AArch64AsmParser::validateInstruction(MCInst &Inst, SMLoc &IDLoc,
           return false;
 
         // Only allow these with ADDXri/ADDWri
-        if ((ELFRefKind == AArch64MCExpr::VK_LO12 ||
-             ELFRefKind == AArch64MCExpr::VK_GOT_AUTH_LO12 ||
-             ELFRefKind == AArch64MCExpr::VK_DTPREL_HI12 ||
-             ELFRefKind == AArch64MCExpr::VK_DTPREL_LO12 ||
-             ELFRefKind == AArch64MCExpr::VK_DTPREL_LO12_NC ||
-             ELFRefKind == AArch64MCExpr::VK_TPREL_HI12 ||
-             ELFRefKind == AArch64MCExpr::VK_TPREL_LO12 ||
-             ELFRefKind == AArch64MCExpr::VK_TPREL_LO12_NC ||
-             ELFRefKind == AArch64MCExpr::VK_TLSDESC_LO12 ||
-             ELFRefKind == AArch64MCExpr::VK_TLSDESC_AUTH_LO12 ||
-             ELFRefKind == AArch64MCExpr::VK_SECREL_LO12 ||
-             ELFRefKind == AArch64MCExpr::VK_SECREL_HI12) &&
+        if (llvm::is_contained(
+                {AArch64MCExpr::VK_LO12, AArch64MCExpr::VK_GOT_AUTH_LO12,
+                 AArch64MCExpr::VK_DTPREL_HI12, AArch64MCExpr::VK_DTPREL_LO12,
+                 AArch64MCExpr::VK_DTPREL_LO12_NC, AArch64MCExpr::VK_TPREL_HI12,
+                 AArch64MCExpr::VK_TPREL_LO12, AArch64MCExpr::VK_TPREL_LO12_NC,
+                 AArch64MCExpr::VK_TLSDESC_LO12,
+                 AArch64MCExpr::VK_TLSDESC_AUTH_LO12,
+                 AArch64MCExpr::VK_SECREL_LO12, AArch64MCExpr::VK_SECREL_HI12},
+                ELFSpec) &&
             (Inst.getOpcode() == AArch64::ADDXri ||
              Inst.getOpcode() == AArch64::ADDWri))
           return false;
@@ -8203,17 +8193,15 @@ bool AArch64AsmParser::parseAuthExpr(const MCExpr *&Res, SMLoc &EndLoc) {
   return false;
 }
 
-bool
-AArch64AsmParser::classifySymbolRef(const MCExpr *Expr,
-                                    AArch64MCExpr::VariantKind &ELFRefKind,
-                                    MCSymbolRefExpr::VariantKind &DarwinRefKind,
-                                    int64_t &Addend) {
-  ELFRefKind = AArch64MCExpr::VK_INVALID;
+bool AArch64AsmParser::classifySymbolRef(
+    const MCExpr *Expr, AArch64MCExpr::Specifier &ELFSpec,
+    MCSymbolRefExpr::VariantKind &DarwinRefKind, int64_t &Addend) {
+  ELFSpec = AArch64MCExpr::VK_INVALID;
   DarwinRefKind = MCSymbolRefExpr::VK_None;
   Addend = 0;
 
   if (const AArch64MCExpr *AE = dyn_cast<AArch64MCExpr>(Expr)) {
-    ELFRefKind = AE->getKind();
+    ELFSpec = AE->getSpecifier();
     Expr = AE->getSubExpr();
   }
 
@@ -8230,9 +8218,9 @@ AArch64AsmParser::classifySymbolRef(const MCExpr *Expr,
   if (!Relocatable || Res.getSymB())
     return false;
 
-  // Treat expressions with an ELFRefKind (like ":abs_g1:3", or
+  // Treat expressions with an ELFSpec (like ":abs_g1:3", or
   // ":abs_g1:x" where x is constant) as symbolic even if there is no symbol.
-  if (!Res.getSymA() && ELFRefKind == AArch64MCExpr::VK_INVALID)
+  if (!Res.getSymA() && ELFSpec == AArch64MCExpr::VK_INVALID)
     return false;
 
   if (Res.getSymA())
@@ -8241,7 +8229,7 @@ AArch64AsmParser::classifySymbolRef(const MCExpr *Expr,
 
   // It's some symbol reference + a constant addend, but really
   // shouldn't use both Darwin and ELF syntax.
-  return ELFRefKind == AArch64MCExpr::VK_INVALID ||
+  return ELFSpec == AArch64MCExpr::VK_INVALID ||
          DarwinRefKind == MCSymbolRefExpr::VK_None;
 }
 
diff --git a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64AsmBackend.cpp b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64AsmBackend.cpp
index 8309c789d0ace..c5accb5e3b51b 100644
--- a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64AsmBackend.cpp
+++ b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64AsmBackend.cpp
@@ -221,8 +221,8 @@ static uint64_t adjustFixupValue(const MCFixup &Fixup, const MCValue &Target,
       Ctx.reportError(Fixup.getLoc(), "fixup must be 16-byte aligned");
     return Value >> 4;
   case AArch64::fixup_aarch64_movw: {
-    AArch64MCExpr::VariantKind RefKind =
-        static_cast<AArch64MCExpr::VariantKind>(Target.getRefKind());
+    AArch64MCExpr::Specifier RefKind =
+        static_cast<AArch64MCExpr::Specifier>(Target.getRefKind());
     if (AArch64MCExpr::getSymbolLoc(RefKind) != AArch64MCExpr::VK_ABS &&
         AArch64MCExpr::getSymbolLoc(RefKind) != AArch64MCExpr::VK_SABS) {
       if (!RefKind) {
@@ -422,8 +422,8 @@ void AArch64AsmBackend::applyFixup(const MCAssembler &Asm, const MCFixup &Fixup,
                                    bool IsResolved,
                                    const MCSubtargetInfo *STI) const {
   if (Fixup.getTargetKind() == FK_Data_8 && TheTriple.isOSBinFormatELF()) {
-    auto RefKind = static_cast<AArch64MCExpr::VariantKind>(Target.getRefKind());
-    AArch64MCExpr::VariantKind SymLoc = AArch64MCExpr::getSymbolLoc(RefKind);
+    auto RefKind = static_cast<AArch64MCExpr::Specifier>(Target.getRefKind());
+    AArch64MCExpr::Specifier SymLoc = AArch64MCExpr::getSymbolLoc(RefKind);
     if (SymLoc == AArch64AuthMCExpr::VK_AUTH ||
         SymLoc == AArch64AuthMCExpr::VK_AUTHADDR) {
       assert(Value == 0);
@@ -474,8 +474,8 @@ void AArch64AsmBackend::applyFixup(const MCAssembler &Asm, const MCFixup &Fixup,
 
   // FIXME: getFixupKindInfo() and getFixupKindNumBytes() could be fixed to
   // handle this more cleanly. This may affect the output of -show-mc-encoding.
-  AArch64MCExpr::VariantKind RefKind =
-      static_cast<AArch64MCExpr::VariantKind>(Target.getRefKind());
+  AArch64MCExpr::Specifier RefKind =
+      static_cast<AArch64MCExpr::Specifier>(Target.getRefKind());
   if (AArch64MCExpr::getSymbolLoc(RefKind) == AArch64MCExpr::VK_SABS ||
       (!RefKind && Fixup.getTargetKind() == AArch64::fixup_aarch64_movw)) {
     // If the immediate is negative, generate MOVN else MOVZ.
diff --git a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFObjectWriter.cpp b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFObjectWriter.cpp
index 19d04b4e83c23..3bee29ad00481 100644
--- a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFObjectWriter.cpp
+++ b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFObjectWriter.cpp
@@ -57,8 +57,7 @@ AArch64ELFObjectWriter::AArch64ELFObjectWriter(uint8_t OSABI, bool IsILP32)
 
 // assumes IsILP32 is true
 static bool isNonILP32reloc(const MCFixup &Fixup,
-                            AArch64MCExpr::VariantKind RefKind,
-                            MCContext &Ctx) {
+                            AArch64MCExpr::Specifier RefKind, MCContext &Ctx) {
   if (Fixup.getTargetKind() != AArch64::fixup_aarch64_movw)
     return false;
   switch (RefKind) {
@@ -111,9 +110,9 @@ unsigned AArch64ELFObjectWriter::getRelocType(MCContext &Ctx,
   unsigned Kind = Fixup.getTargetKind();
   if (Kind >= FirstLiteralRelocationKind)
     return Kind - FirstLiteralRelocationKind;
-  AArch64MCExpr::VariantKind RefKind =
-      static_cast<AArch64MCExpr::VariantKind>(Target.getRefKind());
-  AArch64MCExpr::VariantKind SymLoc = AArch64MCExpr::getSymbolLoc(RefKind);
+  AArch64MCExpr::Specifier RefKind =
+      static_cast<AArch64MCExpr::Specifier>(Target.getRefKind());
+  AArch64MCExpr::Specifier SymLoc = AArch64MCExpr::getSymbolLoc(RefKind);
   bool IsNC = AArch64MCExpr::isNotChecked(RefKind);
 
   assert((!Target.getSymA() ||
@@ -402,7 +401,7 @@ unsigned AArch64ELFObjectWriter::getRelocType(MCContext &Ctx,
       if ((SymLoc == AArch64MCExpr::VK_GOT ||
            SymLoc == AArch64MCExpr::VK_GOT_AUTH) &&
           IsNC) {
-        AArch64MCExpr::VariantKind AddressLoc =
+        AArch64MCExpr::Specifier AddressLoc =
             AArch64MCExpr::getAddressFrag(RefKind);
         bool IsAuth = (SymLoc == AArch64MCExpr::VK_GOT_AUTH);
         if (!IsILP32) {
diff --git a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64MCCodeEmitter.cpp b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64MCCodeEmitter.cpp
index 552477ebca26c..bd43c73396463 100644
--- a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64MCCodeEmitter.cpp
+++ b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64MCCodeEmitter.cpp
@@ -309,7 +309,7 @@ AArch64MCCodeEmitter::getAddSubImmOpValue(const MCInst &MI, unsigned OpIdx,
   // Set the shift bit of the add instruction for relocation types
   // R_AARCH64_TLSLE_ADD_TPREL_HI12 and R_AARCH64_TLSLD_ADD_DTPREL_HI12.
   if (const AArch64MCExpr *A64E = dyn_cast<AArch64MCExpr>(Expr)) {
-    AArch64MCExpr::VariantKind RefKind = A64E->getKind();
+    AArch64MCExpr::Specifier RefKind = A64E->getSpecifier();
     if (RefKind == AArch64MCExpr::VK_TPREL_HI12 ||
         RefKind == AArch64MCExpr::VK_DTPREL_HI12 ||
         RefKind == AArch64MCExpr::VK_SECREL_HI12)
@@ -719,7 +719,7 @@ unsigned AArch64MCCodeEmitter::fixMOVZ(const MCInst &MI, unsigned EncodedValue,
 
   const MCExpr *E = UImm16MO.getExpr();
   if (const AArch64MCExpr *A64E = dyn_cast<AArch64MCExpr>(E)) {
-    switch (A64E->getKind()) {
+    switch (A64E->getSpecifier()) {
     case AArch64MCExpr::VK_DTPREL_G2:
     case AArch64MCExpr::VK_DTPREL_G1:
     case AArch64MCExpr::VK_DTPREL_G0:
diff --git a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64MCExpr.cpp b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64MCExpr.cpp
index a5891c1c6928d..2fcb8e9ee8f4b 100644
--- a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64MCExpr.cpp
+++ b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64MCExpr.cpp
@@ -24,14 +24,14 @@ using namespace llvm;
 
 #define DEBUG_TYPE "aarch64symbolrefexpr"
 
-const AArch64MCExpr *AArch64MCExpr::create(const MCExpr *Expr, VariantKind Kind,
-                                       MCContext &Ctx) {
-  return new (Ctx) AArch64MCExpr(Expr, Kind);
+const AArch64MCExpr *AArch64MCExpr::create(const MCExpr *Expr, Specifier S,
+                                           MCContext &Ctx) {
+  return new (Ctx) AArch64MCExpr(Expr, S);
 }
 
 StringRef AArch64MCExpr::getVariantKindName() const {
   // clang-format off
-  switch (static_cast<uint32_t>(getKind())) {
+  switch (static_cast<uint32_t>(getSpecifier())) {
   case VK_CALL:                return "";
   case VK_LO12:                return ":lo12:";
   case VK_ABS_G3:              return ":abs_g3:";
@@ -113,8 +113,8 @@ bool AArch64MCExpr::evaluateAsRelocatableImpl(MCValue &Res,
   if (!getSubExpr()->evaluateAsRelocatable(Res, Asm))
     return false;
 
-  Res =
-      MCValue::get(Res.getSymA(), Res.getSymB(), Res.getConstant(), getKind());
+  Res = MCValue::get(Res.getSymA(), Res.getSymB(), Res.getConstant(),
+                     getSpecifier());
 
   return true;
 }
@@ -158,6 +158,6 @@ bool AArch64AuthMCExpr::evaluateAsRelocatableImpl(
   if (Res.getSymB())
     report_fatal_error("Auth relocation can't reference two symbols");
 
-  Res = MCValue::get(Res.getSymA(), nullptr, Res.getConstant(), getKind());
+  Res = MCValue::get(Res.getSymA(), nullptr, Res.getConstant(), getSpecifier());
   return true;
 }
diff --git a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64MCExpr.h b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64MCExpr.h
index 3deb65c826664..8b2386a549edc 100644
--- a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64MCExpr.h
+++ b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64MCExpr.h
@@ -23,7 +23,7 @@ namespace llvm {
 
 class AArch64MCExpr : public MCTargetExpr {
 public:
-  enum VariantKind {
+  enum Specifier {
     // clang-format off
     // Symbol locations specifying (roughly speaking) what calculation should be
     // performed to construct the final address for the relocated
@@ -126,25 +126,25 @@ class AArch64MCExpr : public MCTargetExpr {
 
 private:
   const MCExpr *Expr;
-  const VariantKind Kind;
+  const Specifier specifier;
 
 protected:
-  explicit AArch64MCExpr(const MCExpr *Expr, VariantKind Kind)
-    : Expr(Expr), Kind(Kind) {}
+  explicit AArch64MCExpr(const MCExpr *Expr, Specifier S)
+      : Expr(Expr), specifier(S) {}
 
 public:
   /// @name Construction
   /// @{
 
-  static const AArch64MCExpr *create(const MCExpr *Expr, VariantKind Kind,
-                                   MCContext &Ctx);
+  static const AArch64MCExpr *create(const MCExpr *Expr, Specifier,
+                                     MCContext &Ctx);
 
   /// @}
   /// @name Accessors
   /// @{
 
   /// Get the kind of this expression.
-  VariantKind getKind() const { return Kind; }
+  Specifier getSpecifier() const { return specifier; }
 
   /// Get the expression this modifier applies to.
   const MCExpr *getSubExpr() const { return Expr; }
@@ -153,15 +153,15 @@ class AArch64MCExpr : public MCTargetExpr {
   /// @name VariantKind information extractors.
   /// @{
 
-  static VariantKind getSymbolLoc(VariantKind Kind) {
-    return static_cast<VariantKind>(Kind & VK_SymLocBits);
+  static Specifier getSymbolLoc(Specifier S) {
+    return static_cast<Specifier>(S & VK_SymLocBits);
   }
 
-  static VariantKind getAddressFrag(VariantKind Kind) {
-    return static_cast<VariantKind>(Kind & VK_AddressFragBits);
+  static Specifier getAddressFrag(Specifier S) {
+    return static_cast<Specifier>(S & VK_AddressFragBits);
   }
 
-  static bool isNotChecked(VariantKind Kind) { return Kind & VK_NC; }
+  static bool isNotChecked(Specifier S) { return S & VK_NC; }
 
   /// @}
 
@@ -198,7 +198,7 @@ class AArch64AuthMCExpr final : public AArch64MCExpr {
 
   AArch64PACKey::ID getKey() const { return Key; }
   uint16_t getDiscriminator() const { return Discriminator; }
-  bool hasAddressDiversity() const { return getKind() == VK_AUTHADDR; }
+  bool hasAddressDiversity() const { return getSpecifier() == VK_AUTHADDR; }
 
   void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override;
 
@@ -213,7 +213,7 @@ class AArch64AuthMCExpr final : public AArch64MCExpr {
   }
 
   static bool classof(const AArch64MCExpr *E) {
-    return E->getKind() == VK_AUTH || E->getKind() == VK_AUTHADDR;
+    return E->getSpecifier() == VK_AUTH || E->getSpecifier() == VK_AUTHADDR;
   }
 };
 } // end namespace llvm
diff --git a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64WinCOFFObjectWriter.cpp b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64WinCOFFObjectWriter.cpp
index 47228025ce259..eb7866733dd78 100644
--- a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64WinCOFFObjectWriter.cpp
+++ b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64WinCOFFObjectWriter.cpp
@@ -66,8 +66,8 @@ unsigned AArch64WinCOFFObjectWriter::getRelocType(
   const MCExpr *Expr = Fixup.getValue();
 
   if (const AArch64MCExpr *A64E = dyn_cast<AArch64MCExpr>(Expr)) {
-    AArch64MCExpr::VariantKind RefKind = A64E->getKind();
-    switch (AArch64MCExpr::getSymbolLoc(RefKind)) {
+    AArch64MCExpr::Specifier Spec = A64E->getSpecifier();
+    switch (AArch64MCExpr::getSymbolLoc(Spec)) {
     case AArch64MCExpr::VK_ABS:
     case AArch64MCExpr::VK_SECREL:
       // Supported
@@ -118,10 +118,10 @@ unsigned AArch64WinCOFFObjectWriter::getRelocType(
 
   case AArch64::fixup_aarch64_add_imm12:
     if (const AArch64MCExpr *A64E = dyn_cast<AArch64MCExpr>(Expr)) {
-      AArch64MCExpr::VariantKind RefKind = A64E->getKind();
-      if (RefKind == AArch64MCExpr::VK_SECREL_LO12)
+      AArch64MCExpr::Specifier Spec = A64E->getSpecifier();
+      if (Spec == AArch64MCExpr::VK_SECREL_LO12)
         return COFF::IMAGE_REL_ARM64_SECREL_LOW12A;
-      if (RefKind == AArch64MCExpr::VK_SECREL_HI12)
+      if (Spec == AArch64MCExpr::VK_SECREL_HI12)
         return COFF::IMAGE_REL_ARM64_SECREL_HIGH12A;
     }
     return COFF::IMAGE_REL_ARM64_PAGEOFFSET_12A;
@@ -132,8 +132,8 @@ unsigned AArch64WinCOFFObjectWriter::getRelocType(
   case AArch64::fixup_aarch64_ldst_imm12_scale8:
   case AArch64::fixup_aarch64_ldst_imm12_scale16:
     if (const AArch64MCExpr *A64E = dyn_cast<AArch64MCExpr>(Expr)) {
-      AArch64MCExpr::VariantKind RefKind = A64E->getKind();
-      if (RefKind == AArch64MCExpr::VK_SECREL_LO12)
+      AArch64MCExpr::Specifier Spec = A64E->getSpecifier();
+      if (Spec == AArch64MCExpr::VK_SECREL_LO12)
         return COFF::IMAGE_REL_ARM64_SECREL_LOW12L;
     }
     return COFF::IMAGE_REL_ARM64_PAGEOFFSET_12L;

>From f50fb52175abf986bf7e7cc5fdb5074e86a3e0e1 Mon Sep 17 00:00:00 2001
From: Fangrui Song <i at maskray.me>
Date: Tue, 25 Mar 2025 23:36:22 -0700
Subject: [PATCH 2/2] remove unneeded AArch64AuthMCExpr::evaluate* overload

Created using spr 1.3.5-bogner
---
 llvm/lib/Target/AArch64/MCTargetDesc/AArch64MCExpr.h | 2 --
 1 file changed, 2 deletions(-)

diff --git a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64MCExpr.h b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64MCExpr.h
index a8b29a04f6e12..50abaa9861538 100644
--- a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64MCExpr.h
+++ b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64MCExpr.h
@@ -206,8 +206,6 @@ class AArch64AuthMCExpr final : public AArch64MCExpr {
 
   MCFragment *findAssociatedFragment() const override;
 
-  bool evaluateAsRelocatableImpl(MCValue &Res,
-                                 const MCAssembler *Asm) const override;
   static bool classof(const MCExpr *E) {
     return isa<AArch64MCExpr>(E) && classof(cast<AArch64MCExpr>(E));
   }



More information about the llvm-commits mailing list