Skip to content

Commit b73e144

Browse files
committed
MCValue: Simplify code with getSubSym
MCValue::SymB is a MCSymbolRefExpr *, which might become MCSymbol * in the future. Simplify some code that uses MCValue::SymB.
1 parent 8a13388 commit b73e144

File tree

13 files changed

+30
-36
lines changed

13 files changed

+30
-36
lines changed

llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1564,7 +1564,7 @@ const MCExpr *TargetLoweringObjectFileMachO::getIndirectSymViaGOTPCRel(
15641564
// The offset must consider the original displacement from the base symbol
15651565
// since 32-bit targets don't have a GOTPCREL to fold the PC displacement.
15661566
Offset = -MV.getConstant();
1567-
const MCSymbol *BaseSym = &MV.getSymB()->getSymbol();
1567+
const MCSymbol *BaseSym = MV.getSubSym();
15681568

15691569
// Access the final symbol via sym$non_lazy_ptr and generate the appropriated
15701570
// non_lazy_ptr stubs.

llvm/lib/MC/ELFObjectWriter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1376,8 +1376,8 @@ void ELFObjectWriter::recordRelocation(MCAssembler &Asm,
13761376
MCContext &Ctx = Asm.getContext();
13771377
const MCTargetOptions *TO = Ctx.getTargetOptions();
13781378

1379-
if (const MCSymbolRefExpr *RefB = Target.getSymB()) {
1380-
const auto &SymB = cast<MCSymbolELF>(RefB->getSymbol());
1379+
if (auto *RefB = Target.getSubSym()) {
1380+
const auto &SymB = cast<MCSymbolELF>(*RefB);
13811381
if (SymB.isUndefined()) {
13821382
Ctx.reportError(Fixup.getLoc(),
13831383
Twine("symbol '") + SymB.getName() +

llvm/lib/MC/MCAssembler.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ bool MCAssembler::isThumbFunc(const MCSymbol *Symbol) const {
122122
if (!Expr->evaluateAsRelocatable(V, nullptr))
123123
return false;
124124

125-
if (V.getSymB() || V.getRefKind() != MCSymbolRefExpr::VK_None)
125+
if (V.getSubSym() || V.getRefKind() != MCSymbolRefExpr::VK_None)
126126
return false;
127127

128128
const MCSymbolRefExpr *Ref = V.getSymA();
@@ -236,7 +236,7 @@ bool MCAssembler::evaluateFixup(const MCFixup &Fixup, const MCFragment *DF,
236236

237237
// A linker relaxation target may emit ADD/SUB relocations for A-B+C. Let
238238
// recordRelocation handle non-VK_None cases like A@plt-B+C.
239-
if (!IsResolved && Target.getSymA() && Target.getSymB() &&
239+
if (!IsResolved && Target.getSymA() && Target.getSubSym() &&
240240
Target.getSymA()->getKind() == MCSymbolRefExpr::VK_None &&
241241
getBackend().handleAddSubRelocations(*this, *DF, Fixup, Target, Value))
242242
return true;

llvm/lib/MC/MCExpr.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ bool MCExpr::evaluateAsRelocatableImpl(MCValue &Res, const MCAssembler *Asm,
547547
// which evaluate exactly to a single unadorned symbol. Attach the
548548
// original VariantKind to SymA of the result.
549549
if (Res.getRefKind() != MCSymbolRefExpr::VK_None || !Res.getSymA() ||
550-
Res.getSymB() || Res.getConstant())
550+
Res.getSubSym() || Res.getConstant())
551551
return false;
552552
Res =
553553
MCValue::get(MCSymbolRefExpr::create(&Res.getSymA()->getSymbol(),
@@ -558,7 +558,7 @@ bool MCExpr::evaluateAsRelocatableImpl(MCValue &Res, const MCAssembler *Asm,
558558
return true;
559559

560560
const MCSymbolRefExpr *A = Res.getSymA();
561-
const MCSymbolRefExpr *B = Res.getSymB();
561+
auto *B = Res.getSubSym();
562562
// FIXME: This is small hack. Given
563563
// a = b + 4
564564
// .long a
@@ -592,7 +592,7 @@ bool MCExpr::evaluateAsRelocatableImpl(MCValue &Res, const MCAssembler *Asm,
592592
break;
593593
case MCUnaryExpr::Minus:
594594
/// -(a - b + const) ==> (b - a - const)
595-
if (Value.getSymA() && !Value.getSymB())
595+
if (Value.getSymA() && !Value.getSubSym())
596596
return false;
597597

598598
// The cast avoids undefined behavior if the constant is INT64_MIN.

llvm/lib/MC/MCMachOStreamer.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,8 @@ void MCMachOStreamer::emitAssignment(MCSymbol *Symbol, const MCExpr *Value) {
184184
if (Value->evaluateAsRelocatable(Res, nullptr)) {
185185
if (const MCSymbolRefExpr *SymAExpr = Res.getSymA()) {
186186
const MCSymbol &SymA = SymAExpr->getSymbol();
187-
if (!Res.getSymB() && (SymA.getName() == "" || Res.getConstant() != 0))
187+
if (!Res.getSubSym() &&
188+
(SymA.getName().empty() || Res.getConstant() != 0))
188189
cast<MCSymbolMachO>(Symbol)->setAltEntry();
189190
}
190191
}

llvm/lib/MC/MCObjectStreamer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,7 @@ getOffsetAndDataFragment(const MCSymbol &Symbol, uint32_t &RelocOffset,
605605
return std::nullopt;
606606
}
607607

608-
if (OffsetVal.getSymB())
608+
if (OffsetVal.getSubSym())
609609
return std::make_pair(false,
610610
std::string(".reloc symbol offset is not "
611611
"representable"));
@@ -672,7 +672,7 @@ MCObjectStreamer::emitRelocDirective(const MCExpr &Offset, StringRef Name,
672672
MCFixup::create(OffsetVal.getConstant(), Expr, Kind, Loc));
673673
return std::nullopt;
674674
}
675-
if (OffsetVal.getSymB())
675+
if (OffsetVal.getSubSym())
676676
return std::make_pair(false,
677677
std::string(".reloc offset is not representable"));
678678

llvm/lib/MC/MachObjectWriter.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,15 +112,15 @@ uint64_t MachObjectWriter::getSymbolAddress(const MCSymbol &S,
112112
if (Target.getSymA() && Target.getSymA()->getSymbol().isUndefined())
113113
report_fatal_error("unable to evaluate offset to undefined symbol '" +
114114
Target.getSymA()->getSymbol().getName() + "'");
115-
if (Target.getSymB() && Target.getSymB()->getSymbol().isUndefined())
115+
if (Target.getSubSym() && Target.getSubSym()->isUndefined())
116116
report_fatal_error("unable to evaluate offset to undefined symbol '" +
117-
Target.getSymB()->getSymbol().getName() + "'");
117+
Target.getSubSym()->getName() + "'");
118118

119119
uint64_t Address = Target.getConstant();
120120
if (Target.getSymA())
121121
Address += getSymbolAddress(Target.getSymA()->getSymbol(), Asm);
122-
if (Target.getSymB())
123-
Address += getSymbolAddress(Target.getSymB()->getSymbol(), Asm);
122+
if (Target.getSubSym())
123+
Address += getSymbolAddress(*Target.getSubSym(), Asm);
124124
return Address;
125125
}
126126

@@ -507,7 +507,7 @@ void MachObjectWriter::writeLinkerOptionsLoadCommand(
507507
static bool isFixupTargetValid(const MCValue &Target) {
508508
// Target is (LHS - RHS + cst).
509509
// We don't support the form where LHS is null: -RHS + cst
510-
if (!Target.getSymA() && Target.getSymB())
510+
if (!Target.getSymA() && Target.getSubSym())
511511
return false;
512512
return true;
513513
}

llvm/lib/MC/WasmObjectWriter.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -490,9 +490,8 @@ void WasmObjectWriter::recordRelocation(MCAssembler &Asm,
490490
MCContext &Ctx = Asm.getContext();
491491
bool IsLocRel = false;
492492

493-
if (const MCSymbolRefExpr *RefB = Target.getSymB()) {
494-
495-
const auto &SymB = cast<MCSymbolWasm>(RefB->getSymbol());
493+
if (const auto *RefB = Target.getSubSym()) {
494+
const auto &SymB = cast<MCSymbolWasm>(*RefB);
496495

497496
if (FixupSection.isText()) {
498497
Ctx.reportError(Fixup.getLoc(),

llvm/lib/MC/WinCOFFObjectWriter.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -860,10 +860,7 @@ void WinCOFFWriter::recordRelocation(MCAssembler &Asm,
860860
"Section must already have been defined in executePostLayoutBinding!");
861861

862862
COFFSection *Sec = SectionMap[MCSec];
863-
const MCSymbolRefExpr *SymB = Target.getSymB();
864-
865-
if (SymB) {
866-
const MCSymbol *B = &SymB->getSymbol();
863+
if (const MCSymbol *B = Target.getSubSym()) {
867864
if (!B->getFragment()) {
868865
Asm.getContext().reportError(
869866
Fixup.getLoc(),
@@ -923,7 +920,7 @@ void WinCOFFWriter::recordRelocation(MCAssembler &Asm,
923920

924921
Reloc.Data.VirtualAddress += Fixup.getOffset();
925922
Reloc.Data.Type = OWriter.TargetObjectWriter->getRelocType(
926-
Asm.getContext(), Target, Fixup, SymB, Asm.getBackend());
923+
Asm.getContext(), Target, Fixup, Target.getSubSym(), Asm.getBackend());
927924

928925
// The *_REL32 relocations are relative to the end of the relocation,
929926
// not to the start.

llvm/lib/Target/AArch64/MCTargetDesc/AArch64MachObjectWriter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ void AArch64MachObjectWriter::recordRelocation(
213213
// FIXME: x86_64 sets the type to a branch reloc here. Should we do
214214
// something similar?
215215
}
216-
} else if (Target.getSymB()) { // A - B + constant
216+
} else if (Target.getSubSym()) { // A - B + constant
217217
const MCSymbol *A = &Target.getSymA()->getSymbol();
218218
const MCSymbol *A_Base = Writer->getAtom(*A);
219219

llvm/lib/Target/ARM/MCTargetDesc/ARMMachObjectWriter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ void ARMMachObjectWriter::recordRelocation(MachObjectWriter *Writer,
378378
// If this is a difference or a defined symbol plus an offset, then we need a
379379
// scattered relocation entry. Differences always require scattered
380380
// relocations.
381-
if (Target.getSymB()) {
381+
if (Target.getSubSym()) {
382382
if (RelocType == MachO::ARM_RELOC_HALF)
383383
return recordARMScatteredHalfRelocation(Writer, Asm, Fragment, Fixup,
384384
Target, FixedValue);

llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,7 @@ bool RISCVAsmBackend::evaluateTargetFixup(const MCAssembler &Asm,
551551
}
552552
}
553553

554-
if (!AUIPCTarget.getSymA() || AUIPCTarget.getSymB())
554+
if (!AUIPCTarget.getSymA() || AUIPCTarget.getSubSym())
555555
return false;
556556

557557
const MCSymbolRefExpr *A = AUIPCTarget.getSymA();

llvm/lib/Target/X86/MCTargetDesc/X86MachObjectWriter.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -139,13 +139,13 @@ void X86MachObjectWriter::RecordX86_64Relocation(
139139
IsExtern = 1;
140140
Type = MachO::X86_64_RELOC_BRANCH;
141141
}
142-
} else if (Target.getSymB()) { // A - B + constant
142+
} else if (Target.getSubSym()) { // A - B + constant
143143
const MCSymbol *A = &Target.getSymA()->getSymbol();
144144
if (A->isTemporary())
145145
A = &Writer->findAliasedSymbol(*A);
146146
const MCSymbol *A_Base = Writer->getAtom(*A);
147147

148-
const MCSymbol *B = &Target.getSymB()->getSymbol();
148+
const MCSymbol *B = Target.getSubSym();
149149
if (B->isTemporary())
150150
B = &Writer->findAliasedSymbol(*B);
151151
const MCSymbol *B_Base = Writer->getAtom(*B);
@@ -385,9 +385,7 @@ bool X86MachObjectWriter::recordScatteredRelocation(MachObjectWriter *Writer,
385385
FixedValue += SecAddr;
386386
uint32_t Value2 = 0;
387387

388-
if (const MCSymbolRefExpr *B = Target.getSymB()) {
389-
const MCSymbol *SB = &B->getSymbol();
390-
388+
if (const MCSymbol *SB = Target.getSubSym()) {
391389
if (!SB->getFragment()) {
392390
Asm.getContext().reportError(
393391
Fixup.getLoc(),
@@ -474,13 +472,12 @@ void X86MachObjectWriter::recordTLVPRelocation(MachObjectWriter *Writer,
474472
// subtraction from the picbase. For 32-bit pic the addend is the difference
475473
// between the picbase and the next address. For 32-bit static the addend is
476474
// zero.
477-
if (auto *SymB = Target.getSymB()) {
475+
if (auto *SymB = Target.getSubSym()) {
478476
// If this is a subtraction then we're pcrel.
479477
uint32_t FixupAddress =
480478
Writer->getFragmentAddress(Asm, Fragment) + Fixup.getOffset();
481479
IsPCRel = 1;
482-
FixedValue = FixupAddress -
483-
Writer->getSymbolAddress(SymB->getSymbol(), Asm) +
480+
FixedValue = FixupAddress - Writer->getSymbolAddress(*SymB, Asm) +
484481
Target.getConstant();
485482
FixedValue += 1ULL << Log2Size;
486483
} else {
@@ -514,7 +511,7 @@ void X86MachObjectWriter::RecordX86Relocation(MachObjectWriter *Writer,
514511
// If this is a difference or a defined symbol plus an offset, then we need a
515512
// scattered relocation entry. Differences always require scattered
516513
// relocations.
517-
if (Target.getSymB()) {
514+
if (Target.getSubSym()) {
518515
recordScatteredRelocation(Writer, Asm, Fragment, Fixup, Target, Log2Size,
519516
FixedValue);
520517
return;

0 commit comments

Comments
 (0)