[llvm] 5e8f438 - MCValue: Make getSymB private and improve documentation
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Sat Apr 5 12:04:05 PDT 2025
Author: Fangrui Song
Date: 2025-04-05T12:03:59-07:00
New Revision: 5e8f43811acfd72ac5da4df2a5436b27ad1eeab4
URL: https://github.com/llvm/llvm-project/commit/5e8f43811acfd72ac5da4df2a5436b27ad1eeab4
DIFF: https://github.com/llvm/llvm-project/commit/5e8f43811acfd72ac5da4df2a5436b27ad1eeab4.diff
LOG: MCValue: Make getSymB private and improve documentation
Added:
Modified:
llvm/include/llvm/MC/MCExpr.h
llvm/include/llvm/MC/MCValue.h
llvm/lib/MC/MCExpr.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/MC/MCExpr.h b/llvm/include/llvm/MC/MCExpr.h
index 3127a93d32581..b0e347d690f0e 100644
--- a/llvm/include/llvm/MC/MCExpr.h
+++ b/llvm/include/llvm/MC/MCExpr.h
@@ -26,6 +26,7 @@ class MCSymbol;
class MCValue;
class raw_ostream;
class StringRef;
+class MCSymbolRefExpr;
using SectionAddrMap = DenseMap<const MCSection *, uint64_t>;
@@ -130,6 +131,11 @@ class MCExpr {
MCFragment *findAssociatedFragment() const;
/// @}
+
+ static bool evaluateSymbolicAdd(const MCAssembler *, const SectionAddrMap *,
+ bool, const MCValue &,
+ const MCSymbolRefExpr *,
+ const MCSymbolRefExpr *, int64_t, MCValue &);
};
inline raw_ostream &operator<<(raw_ostream &OS, const MCExpr &E) {
diff --git a/llvm/include/llvm/MC/MCValue.h b/llvm/include/llvm/MC/MCValue.h
index d291c4cb5aff0..6e37fb56ab27f 100644
--- a/llvm/include/llvm/MC/MCValue.h
+++ b/llvm/include/llvm/MC/MCValue.h
@@ -19,31 +19,32 @@
namespace llvm {
class raw_ostream;
-/// This represents an "assembler immediate".
-///
-/// In its most general form, this can hold ":Kind:(SymbolA - SymbolB +
-/// imm64)". Not all targets supports relocations of this general form, but we
-/// need to represent this anyway.
-///
-/// In general both SymbolA and SymbolB will also have a modifier
-/// analogous to the top-level Kind. Current targets are not expected
-/// to make use of both though. The choice comes down to whether
-/// relocation modifiers apply to the closest symbol or the whole
-/// expression.
-///
-/// Note that this class must remain a simple POD value class, because we need
-/// it to live in unions etc.
+// Represents a relocatable expression in its most general form:
+// relocation_specifier(SymA - SymB + imm64).
+//
+// Not all targets support SymB. For PC-relative relocations, a specifier is
+// typically used instead of setting SymB to DOT.
+//
+// Some targets encode the relocation specifier within SymA using
+// MCSymbolRefExpr::SubclassData and access it via getAccessVariant(), though
+// this method is now deprecated.
+//
+// This class must remain a simple POD value class, as it needs to reside in
+// unions and similar structures.
class MCValue {
const MCSymbolRefExpr *SymA = nullptr, *SymB = nullptr;
int64_t Cst = 0;
uint32_t Specifier = 0;
+ // SymB cannot have a specifier. Use getSubSym instead.
+ const MCSymbolRefExpr *getSymB() const { return SymB; }
+
public:
+ friend class MCAssembler;
friend class MCExpr;
MCValue() = default;
int64_t getConstant() const { return Cst; }
const MCSymbolRefExpr *getSymA() const { return SymA; }
- const MCSymbolRefExpr *getSymB() const { return SymB; }
uint32_t getRefKind() const { return Specifier; }
uint32_t getSpecifier() const { return Specifier; }
void setSpecifier(uint32_t S) { Specifier = S; }
diff --git a/llvm/lib/MC/MCExpr.cpp b/llvm/lib/MC/MCExpr.cpp
index c5500ef9cf34d..11a5a739b4a06 100644
--- a/llvm/lib/MC/MCExpr.cpp
+++ b/llvm/lib/MC/MCExpr.cpp
@@ -434,12 +434,12 @@ static void attemptToFoldSymbolOffsetDifference(const MCAssembler *Asm,
// NOTE: This function can be used before layout is done (see the object
// streamer for example) and having the Asm argument lets us avoid relaxations
// early.
-static bool evaluateSymbolicAdd(const MCAssembler *Asm,
- const SectionAddrMap *Addrs, bool InSet,
- const MCValue &LHS,
- const MCSymbolRefExpr *RhsAdd,
- const MCSymbolRefExpr *RhsSub, int64_t RHS_Cst,
- MCValue &Res) {
+bool MCExpr::evaluateSymbolicAdd(const MCAssembler *Asm,
+ const SectionAddrMap *Addrs, bool InSet,
+ const MCValue &LHS,
+ const MCSymbolRefExpr *RhsAdd,
+ const MCSymbolRefExpr *RhsSub, int64_t RHS_Cst,
+ MCValue &Res) {
const MCSymbol *LHS_A = LHS.getAddSym();
const MCSymbol *LHS_B = LHS.getSubSym();
int64_t LHS_Cst = LHS.getConstant();
More information about the llvm-commits
mailing list