Skip to content

Commit 5e8f438

Browse files
committed
MCValue: Make getSymB private and improve documentation
1 parent b4f7a2a commit 5e8f438

File tree

3 files changed

+28
-21
lines changed

3 files changed

+28
-21
lines changed

llvm/include/llvm/MC/MCExpr.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class MCSymbol;
2626
class MCValue;
2727
class raw_ostream;
2828
class StringRef;
29+
class MCSymbolRefExpr;
2930

3031
using SectionAddrMap = DenseMap<const MCSection *, uint64_t>;
3132

@@ -130,6 +131,11 @@ class MCExpr {
130131
MCFragment *findAssociatedFragment() const;
131132

132133
/// @}
134+
135+
static bool evaluateSymbolicAdd(const MCAssembler *, const SectionAddrMap *,
136+
bool, const MCValue &,
137+
const MCSymbolRefExpr *,
138+
const MCSymbolRefExpr *, int64_t, MCValue &);
133139
};
134140

135141
inline raw_ostream &operator<<(raw_ostream &OS, const MCExpr &E) {

llvm/include/llvm/MC/MCValue.h

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,31 +19,32 @@
1919
namespace llvm {
2020
class raw_ostream;
2121

22-
/// This represents an "assembler immediate".
23-
///
24-
/// In its most general form, this can hold ":Kind:(SymbolA - SymbolB +
25-
/// imm64)". Not all targets supports relocations of this general form, but we
26-
/// need to represent this anyway.
27-
///
28-
/// In general both SymbolA and SymbolB will also have a modifier
29-
/// analogous to the top-level Kind. Current targets are not expected
30-
/// to make use of both though. The choice comes down to whether
31-
/// relocation modifiers apply to the closest symbol or the whole
32-
/// expression.
33-
///
34-
/// Note that this class must remain a simple POD value class, because we need
35-
/// it to live in unions etc.
22+
// Represents a relocatable expression in its most general form:
23+
// relocation_specifier(SymA - SymB + imm64).
24+
//
25+
// Not all targets support SymB. For PC-relative relocations, a specifier is
26+
// typically used instead of setting SymB to DOT.
27+
//
28+
// Some targets encode the relocation specifier within SymA using
29+
// MCSymbolRefExpr::SubclassData and access it via getAccessVariant(), though
30+
// this method is now deprecated.
31+
//
32+
// This class must remain a simple POD value class, as it needs to reside in
33+
// unions and similar structures.
3634
class MCValue {
3735
const MCSymbolRefExpr *SymA = nullptr, *SymB = nullptr;
3836
int64_t Cst = 0;
3937
uint32_t Specifier = 0;
4038

39+
// SymB cannot have a specifier. Use getSubSym instead.
40+
const MCSymbolRefExpr *getSymB() const { return SymB; }
41+
4142
public:
43+
friend class MCAssembler;
4244
friend class MCExpr;
4345
MCValue() = default;
4446
int64_t getConstant() const { return Cst; }
4547
const MCSymbolRefExpr *getSymA() const { return SymA; }
46-
const MCSymbolRefExpr *getSymB() const { return SymB; }
4748
uint32_t getRefKind() const { return Specifier; }
4849
uint32_t getSpecifier() const { return Specifier; }
4950
void setSpecifier(uint32_t S) { Specifier = S; }

llvm/lib/MC/MCExpr.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -434,12 +434,12 @@ static void attemptToFoldSymbolOffsetDifference(const MCAssembler *Asm,
434434
// NOTE: This function can be used before layout is done (see the object
435435
// streamer for example) and having the Asm argument lets us avoid relaxations
436436
// early.
437-
static bool evaluateSymbolicAdd(const MCAssembler *Asm,
438-
const SectionAddrMap *Addrs, bool InSet,
439-
const MCValue &LHS,
440-
const MCSymbolRefExpr *RhsAdd,
441-
const MCSymbolRefExpr *RhsSub, int64_t RHS_Cst,
442-
MCValue &Res) {
437+
bool MCExpr::evaluateSymbolicAdd(const MCAssembler *Asm,
438+
const SectionAddrMap *Addrs, bool InSet,
439+
const MCValue &LHS,
440+
const MCSymbolRefExpr *RhsAdd,
441+
const MCSymbolRefExpr *RhsSub, int64_t RHS_Cst,
442+
MCValue &Res) {
443443
const MCSymbol *LHS_A = LHS.getAddSym();
444444
const MCSymbol *LHS_B = LHS.getSubSym();
445445
int64_t LHS_Cst = LHS.getConstant();

0 commit comments

Comments
 (0)