[llvm] 00a1318 - LoongArchMCExpr: Migrate to MCSpecifierExpr

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


Author: Fangrui Song
Date: 2025-06-07T17:42:18-07:00
New Revision: 00a1318d9ad91e0aa6253c0337131771d9222d05

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

LOG: LoongArchMCExpr: Migrate to MCSpecifierExpr

Added: 
    

Modified: 
    llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchMCCodeEmitter.cpp
    llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchMCExpr.cpp
    llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchMCExpr.h

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchMCCodeEmitter.cpp b/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchMCCodeEmitter.cpp
index ef0bf683afc7b..d4ac1cafd42da 100644
--- a/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchMCCodeEmitter.cpp
+++ b/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchMCCodeEmitter.cpp
@@ -130,7 +130,7 @@ LoongArchMCCodeEmitter::getExprOpValue(const MCInst &MI, const MCOperand &MO,
   const MCExpr *Expr = MO.getExpr();
   MCExpr::ExprKind Kind = Expr->getKind();
   unsigned FixupKind = LoongArch::fixup_loongarch_invalid;
-  if (Kind == MCExpr::Target) {
+  if (Kind == MCExpr::Specifier) {
     const LoongArchMCExpr *LAExpr = cast<LoongArchMCExpr>(Expr);
     FixupKind = LAExpr->getSpecifier();
     RelaxCandidate = LAExpr->getRelaxHint();

diff  --git a/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchMCExpr.cpp b/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchMCExpr.cpp
index ecf19738bbc5f..7eec236475000 100644
--- a/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchMCExpr.cpp
+++ b/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchMCExpr.cpp
@@ -38,24 +38,6 @@ void LoongArchMCExpr::printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const {
     OS << ')';
 }
 
-bool LoongArchMCExpr::evaluateAsRelocatableImpl(
-    MCValue &Res,
-    const MCAssembler *Asm) const { // Explicitly drop the layout and assembler
-                                    // to prevent any symbolic folding in
-  // the expression handling.  This is required to preserve symbolic 
diff erence
-  // expressions to emit the paired relocations.
-  if (!getSubExpr()->evaluateAsRelocatable(Res, nullptr))
-    return false;
-
-  Res.setSpecifier(specifier);
-  // Custom fixup types are not valid with symbol 
diff erence expressions.
-  return !Res.getSubSym();
-}
-
-void LoongArchMCExpr::visitUsedExpr(MCStreamer &Streamer) const {
-  Streamer.visitUsedExpr(*getSubExpr());
-}
-
 StringRef LoongArchMCExpr::getSpecifierName(uint16_t S) {
   switch (S) {
   default:

diff  --git a/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchMCExpr.h b/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchMCExpr.h
index 06ebbc034042b..06370001fa412 100644
--- a/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchMCExpr.h
+++ b/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchMCExpr.h
@@ -20,38 +20,24 @@ namespace llvm {
 
 class StringRef;
 
-class LoongArchMCExpr : public MCTargetExpr {
+class LoongArchMCExpr : public MCSpecifierExpr {
 public:
   using Specifier = uint16_t;
   enum { VK_None };
 
 private:
-  const MCExpr *Expr;
-  const Specifier specifier;
   const bool RelaxHint;
 
   explicit LoongArchMCExpr(const MCExpr *Expr, Specifier S, bool Hint)
-      : Expr(Expr), specifier(S), RelaxHint(Hint) {}
+      : MCSpecifierExpr(Expr, S), RelaxHint(Hint) {}
 
 public:
   static const LoongArchMCExpr *create(const MCExpr *Expr, uint16_t S,
                                        MCContext &Ctx, bool Hint = false);
 
-  Specifier getSpecifier() const { return specifier; }
-  const MCExpr *getSubExpr() const { return Expr; }
   bool getRelaxHint() const { return RelaxHint; }
 
   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 StringRef getSpecifierName(uint16_t S);
   static Specifier parseSpecifier(StringRef name);


        


More information about the llvm-commits mailing list