[llvm] e997eb4 - VEMCExpr: Migrate to MCSpecifierExpr

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Sat Jun 7 17:30:47 PDT 2025


Author: Fangrui Song
Date: 2025-06-07T17:30:42-07:00
New Revision: e997eb4c3951ccd43046cc2da3c7a5fd1d9319ec

URL: https://github.com/llvm/llvm-project/commit/e997eb4c3951ccd43046cc2da3c7a5fd1d9319ec
DIFF: https://github.com/llvm/llvm-project/commit/e997eb4c3951ccd43046cc2da3c7a5fd1d9319ec.diff

LOG: VEMCExpr: Migrate to MCSpecifierExpr

Follow-up to 97a32f2ad9ded95806db1dcfc281f64b0c1874a6

Added: 
    

Modified: 
    llvm/include/llvm/MC/MCExpr.h
    llvm/lib/Target/VE/AsmParser/VEAsmParser.cpp
    llvm/lib/Target/VE/MCTargetDesc/VEMCCodeEmitter.cpp
    llvm/lib/Target/VE/MCTargetDesc/VEMCExpr.cpp
    llvm/lib/Target/VE/MCTargetDesc/VEMCExpr.h

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/MC/MCExpr.h b/llvm/include/llvm/MC/MCExpr.h
index 0ba5532aac994..79be10af8baea 100644
--- a/llvm/include/llvm/MC/MCExpr.h
+++ b/llvm/include/llvm/MC/MCExpr.h
@@ -523,7 +523,8 @@ class LLVM_ABI MCSpecifierExpr : public MCExpr {
   const MCExpr *getSubExpr() const { return Expr; }
 
   virtual void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const = 0;
-  bool evaluateAsRelocatableImpl(MCValue &Res, const MCAssembler *Asm) const;
+  virtual bool evaluateAsRelocatableImpl(MCValue &Res,
+                                         const MCAssembler *Asm) const;
 
   static bool classof(const MCExpr *E) {
     return E->getKind() == MCExpr::Specifier;

diff  --git a/llvm/lib/Target/VE/AsmParser/VEAsmParser.cpp b/llvm/lib/Target/VE/AsmParser/VEAsmParser.cpp
index be4a5ec4a66d2..a58ef127bbd5d 100644
--- a/llvm/lib/Target/VE/AsmParser/VEAsmParser.cpp
+++ b/llvm/lib/Target/VE/AsmParser/VEAsmParser.cpp
@@ -1054,7 +1054,7 @@ const MCExpr *VEAsmParser::extractSpecifier(const MCExpr *E,
   case MCExpr::SymbolRef: {
     const MCSymbolRefExpr *SRE = cast<MCSymbolRefExpr>(E);
 
-    switch (getSpecifier(SRE)) {
+    switch (SRE->getSpecifier()) {
     case VEMCExpr::VK_None:
       // Use VK_REFLONG to a symbol without modifiers.
       Variant = VEMCExpr::VK_REFLONG;

diff  --git a/llvm/lib/Target/VE/MCTargetDesc/VEMCCodeEmitter.cpp b/llvm/lib/Target/VE/MCTargetDesc/VEMCCodeEmitter.cpp
index 77fea1cb1756e..7dece1b309a96 100644
--- a/llvm/lib/Target/VE/MCTargetDesc/VEMCCodeEmitter.cpp
+++ b/llvm/lib/Target/VE/MCTargetDesc/VEMCCodeEmitter.cpp
@@ -99,7 +99,7 @@ unsigned VEMCCodeEmitter::getMachineOpValue(const MCInst &MI,
 
   const MCExpr *Expr = MO.getExpr();
   if (const VEMCExpr *SExpr = dyn_cast<VEMCExpr>(Expr)) {
-    MCFixupKind Kind = (MCFixupKind)SExpr->getFixupKind();
+    auto Kind = VEMCExpr::getFixupKind(SExpr->getSpecifier());
     Fixups.push_back(MCFixup::create(0, Expr, Kind));
     return 0;
   }

diff  --git a/llvm/lib/Target/VE/MCTargetDesc/VEMCExpr.cpp b/llvm/lib/Target/VE/MCTargetDesc/VEMCExpr.cpp
index 62f5ae67fb012..a7986ab9006dc 100644
--- a/llvm/lib/Target/VE/MCTargetDesc/VEMCExpr.cpp
+++ b/llvm/lib/Target/VE/MCTargetDesc/VEMCExpr.cpp
@@ -22,9 +22,9 @@ using namespace llvm;
 
 #define DEBUG_TYPE "vemcexpr"
 
-const VEMCExpr *VEMCExpr::create(Specifier Kind, const MCExpr *Expr,
+const VEMCExpr *VEMCExpr::create(Specifier S, const MCExpr *Expr,
                                  MCContext &Ctx) {
-  return new (Ctx) VEMCExpr(Kind, Expr);
+  return new (Ctx) VEMCExpr(Expr, S);
 }
 
 void VEMCExpr::printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const {
@@ -35,7 +35,7 @@ void VEMCExpr::printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const {
     OS << '@' << MAI->getSpecifierName(specifier);
 }
 
-VE::Fixups VEMCExpr::getFixupKind(VEMCExpr::Specifier S) {
+VE::Fixups VEMCExpr::getFixupKind(MCSpecifierExpr::Spec S) {
   switch (S) {
   default:
     llvm_unreachable("Unhandled VEMCExpr::Specifier");
@@ -79,7 +79,3 @@ bool VEMCExpr::evaluateAsRelocatableImpl(MCValue &Res,
   Res.setSpecifier(specifier);
   return true;
 }
-
-void VEMCExpr::visitUsedExpr(MCStreamer &Streamer) const {
-  Streamer.visitUsedExpr(*getSubExpr());
-}

diff  --git a/llvm/lib/Target/VE/MCTargetDesc/VEMCExpr.h b/llvm/lib/Target/VE/MCTargetDesc/VEMCExpr.h
index a176cd3f09710..80ea350a61661 100644
--- a/llvm/lib/Target/VE/MCTargetDesc/VEMCExpr.h
+++ b/llvm/lib/Target/VE/MCTargetDesc/VEMCExpr.h
@@ -20,7 +20,7 @@
 namespace llvm {
 
 class StringRef;
-class VEMCExpr : public MCTargetExpr {
+class VEMCExpr : public MCSpecifierExpr {
 public:
   enum Specifier {
     VK_None,
@@ -43,51 +43,20 @@ class VEMCExpr : public MCTargetExpr {
   };
 
 private:
-  const Specifier specifier;
-  const MCExpr *Expr;
-
-  explicit VEMCExpr(Specifier S, const MCExpr *Expr)
-      : specifier(S), Expr(Expr) {}
+  explicit VEMCExpr(const MCExpr *Expr, Specifier S)
+      : MCSpecifierExpr(Expr, S) {}
 
 public:
-  /// @name Construction
-  /// @{
-
   static const VEMCExpr *create(Specifier Kind, const MCExpr *Expr,
                                 MCContext &Ctx);
-  /// @}
-  /// @name Accessors
-  /// @{
-
-  /// getOpcode - Get the kind of this expression.
-  Specifier getSpecifier() const { return specifier; }
-
-  /// getSubExpr - Get the child of this expression.
-  const MCExpr *getSubExpr() const { return Expr; }
 
-  /// getFixupKind - Get the fixup kind of this expression.
-  VE::Fixups getFixupKind() const { return getFixupKind(specifier); }
-
-  /// @}
   void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override;
   bool evaluateAsRelocatableImpl(MCValue &Res,
                                  const MCAssembler *Asm) const override;
-  void visitUsedExpr(MCStreamer &Streamer) const override;
-  MCFragment *findAssociatedFragment() const override {
-    return getSubExpr()->findAssociatedFragment();
-  }
-
-  static bool classof(const MCExpr *E) {
-    return E->getKind() == MCExpr::Target;
-  }
 
-  static VE::Fixups getFixupKind(Specifier S);
+  static VE::Fixups getFixupKind(Spec S);
 };
 
-static inline VEMCExpr::Specifier getSpecifier(const MCSymbolRefExpr *SRE) {
-  return VEMCExpr::Specifier(SRE->getKind());
-}
-
 } // namespace llvm
 
 #endif


        


More information about the llvm-commits mailing list