Skip to content

Commit 91ebb78

Browse files
committed
MCAsmBackend: Simplify applyFixup
Remove the MCSubtargetInfo argument from applyFixup, introduced in https://reviews.llvm.org/D45962 , as it's only required by ARM. Instead, add const MCFragment & so that ARMAsmBackend can retrieve MCSubtargetInfo via a static member function. Additionally, make applyReloc non-const. Its arguments now fully cover addReloc's functionality.
1 parent f0ff2be commit 91ebb78

File tree

33 files changed

+130
-149
lines changed

33 files changed

+130
-149
lines changed

llvm/include/llvm/MC/MCAsmBackend.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,9 @@ class MCAsmBackend {
123123
/// the offset specified by the fixup and following the fixup kind as
124124
/// appropriate. Errors (such as an out of range fixup value) should be
125125
/// reported via \p Ctx.
126-
/// The \p STI is present only for fragments of type MCRelaxableFragment and
127-
/// MCDataFragment with hasInstructions() == true.
128-
virtual void applyFixup(const MCAssembler &Asm, const MCFixup &Fixup,
126+
virtual void applyFixup(MCAssembler &, const MCFragment &, const MCFixup &,
129127
const MCValue &Target, MutableArrayRef<char> Data,
130-
uint64_t Value, bool IsResolved,
131-
const MCSubtargetInfo *STI) const = 0;
128+
uint64_t Value, bool IsResolved) = 0;
132129

133130
/// @}
134131

@@ -216,6 +213,10 @@ class MCAsmBackend {
216213

217214
bool isDarwinCanonicalPersonality(const MCSymbol *Sym) const;
218215

216+
// Return STI for fragments of type MCRelaxableFragment and MCDataFragment
217+
// with hasInstructions() == true.
218+
static const MCSubtargetInfo *getSubtargetInfo(const MCFragment &F);
219+
219220
private:
220221
const bool LinkerRelaxation;
221222
};

llvm/include/llvm/MC/MCAssembler.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,16 +90,15 @@ class MCAssembler {
9090
/// Evaluate a fixup to a relocatable expression and the value which should be
9191
/// placed into the fixup.
9292
///
93+
/// \param F The fragment the fixup is inside.
9394
/// \param Fixup The fixup to evaluate.
94-
/// \param DF The fragment the fixup is inside.
9595
/// \param Target [out] On return, the relocatable expression the fixup
9696
/// evaluates to.
9797
/// \param Value [out] On return, the value of the fixup as currently laid
9898
/// out.
9999
/// \param RecordReloc Record relocation if needed.
100100
/// relocation.
101-
bool evaluateFixup(const MCFixup &Fixup, const MCFragment *DF,
102-
MCValue &Target, const MCSubtargetInfo *STI,
101+
bool evaluateFixup(const MCFragment *F, const MCFixup &Fixup, MCValue &Target,
103102
uint64_t &Value, bool RecordReloc,
104103
MutableArrayRef<char> Contents) const;
105104

llvm/include/llvm/MC/MCFragment.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ class MCFragment {
108108
/// this is false, but specific fragment types may set it to true.
109109
bool hasInstructions() const { return HasInstructions; }
110110

111+
const MCSubtargetInfo *getSubtargetInfo() const;
112+
111113
void dump() const;
112114
};
113115

llvm/lib/MC/MCAsmBackend.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,3 +143,24 @@ bool MCAsmBackend::isDarwinCanonicalPersonality(const MCSymbol *Sym) const {
143143
// Reserving an empty slot for it seems silly.
144144
return name == "___gxx_personality_v0" || name == "___objc_personality_v0";
145145
}
146+
147+
const MCSubtargetInfo *MCAsmBackend::getSubtargetInfo(const MCFragment &F) {
148+
const MCSubtargetInfo *STI = nullptr;
149+
switch (F.getKind()) {
150+
case MCFragment::FT_Data: {
151+
auto &DF = cast<MCDataFragment>(F);
152+
STI = DF.getSubtargetInfo();
153+
assert(!DF.hasInstructions() || STI != nullptr);
154+
break;
155+
}
156+
case MCFragment::FT_Relaxable: {
157+
auto &RF = cast<MCRelaxableFragment>(F);
158+
STI = RF.getSubtargetInfo();
159+
assert(!RF.hasInstructions() || STI != nullptr);
160+
break;
161+
}
162+
default:
163+
break;
164+
}
165+
return STI;
166+
}

llvm/lib/MC/MCAssembler.cpp

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,9 @@ bool MCAssembler::isThumbFunc(const MCSymbol *Symbol) const {
136136
return true;
137137
}
138138

139-
bool MCAssembler::evaluateFixup(const MCFixup &Fixup, const MCFragment *DF,
140-
MCValue &Target, const MCSubtargetInfo *STI,
141-
uint64_t &Value, bool RecordReloc,
139+
bool MCAssembler::evaluateFixup(const MCFragment *DF, const MCFixup &Fixup,
140+
MCValue &Target, uint64_t &Value,
141+
bool RecordReloc,
142142
MutableArrayRef<char> Contents) const {
143143
++stats::evaluateFixup;
144144

@@ -200,8 +200,8 @@ bool MCAssembler::evaluateFixup(const MCFixup &Fixup, const MCFragment *DF,
200200
IsResolved = false;
201201
IsResolved = getBackend().addReloc(const_cast<MCAssembler &>(*this), *DF,
202202
Fixup, Target, Value, IsResolved);
203-
getBackend().applyFixup(*this, Fixup, Target, Contents, Value, IsResolved,
204-
STI);
203+
getBackend().applyFixup(const_cast<MCAssembler &>(*this), *DF, Fixup, Target,
204+
Contents, Value, IsResolved);
205205
return true;
206206
}
207207

@@ -906,7 +906,6 @@ void MCAssembler::layout() {
906906
for (MCFragment &Frag : Sec) {
907907
MutableArrayRef<MCFixup> Fixups;
908908
MutableArrayRef<char> Contents;
909-
const MCSubtargetInfo *STI = nullptr;
910909

911910
// Process MCAlignFragment and MCEncodedFragmentWithFixups here.
912911
switch (Frag.getKind()) {
@@ -924,16 +923,12 @@ void MCAssembler::layout() {
924923
MCDataFragment &DF = cast<MCDataFragment>(Frag);
925924
Fixups = DF.getFixups();
926925
Contents = DF.getContents();
927-
STI = DF.getSubtargetInfo();
928-
assert(!DF.hasInstructions() || STI != nullptr);
929926
break;
930927
}
931928
case MCFragment::FT_Relaxable: {
932929
MCRelaxableFragment &RF = cast<MCRelaxableFragment>(Frag);
933930
Fixups = RF.getFixups();
934931
Contents = RF.getContents();
935-
STI = RF.getSubtargetInfo();
936-
assert(!RF.hasInstructions() || STI != nullptr);
937932
break;
938933
}
939934
case MCFragment::FT_CVDefRange: {
@@ -970,7 +965,7 @@ void MCAssembler::layout() {
970965
for (const MCFixup &Fixup : Fixups) {
971966
uint64_t FixedValue;
972967
MCValue Target;
973-
evaluateFixup(Fixup, &Frag, Target, STI, FixedValue,
968+
evaluateFixup(&Frag, Fixup, Target, FixedValue,
974969
/*RecordReloc=*/true, Contents);
975970
}
976971
}
@@ -991,9 +986,8 @@ bool MCAssembler::fixupNeedsRelaxation(const MCFixup &Fixup,
991986
assert(getBackendPtr() && "Expected assembler backend");
992987
MCValue Target;
993988
uint64_t Value;
994-
bool Resolved =
995-
evaluateFixup(const_cast<MCFixup &>(Fixup), DF, Target,
996-
DF->getSubtargetInfo(), Value, /*RecordReloc=*/false, {});
989+
bool Resolved = evaluateFixup(DF, const_cast<MCFixup &>(Fixup), Target, Value,
990+
/*RecordReloc=*/false, {});
997991
return getBackend().fixupNeedsRelaxationAdvanced(*this, Fixup, Target, Value,
998992
Resolved);
999993
}

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,9 @@ class AArch64AsmBackend : public MCAsmBackend {
8181
return Infos[Kind - FirstTargetFixupKind];
8282
}
8383

84-
void applyFixup(const MCAssembler &Asm, const MCFixup &Fixup,
84+
void applyFixup(MCAssembler &, const MCFragment &, const MCFixup &,
8585
const MCValue &Target, MutableArrayRef<char> Data,
86-
uint64_t Value, bool IsResolved,
87-
const MCSubtargetInfo *STI) const override;
86+
uint64_t Value, bool IsResolved) override;
8887

8988
bool fixupNeedsRelaxation(const MCFixup &Fixup,
9089
uint64_t Value) const override;
@@ -415,11 +414,10 @@ unsigned AArch64AsmBackend::getFixupKindContainereSizeInBytes(unsigned Kind) con
415414
}
416415
}
417416

418-
void AArch64AsmBackend::applyFixup(const MCAssembler &Asm, const MCFixup &Fixup,
419-
const MCValue &Target,
417+
void AArch64AsmBackend::applyFixup(MCAssembler &Asm, const MCFragment &,
418+
const MCFixup &Fixup, const MCValue &Target,
420419
MutableArrayRef<char> Data, uint64_t Value,
421-
bool IsResolved,
422-
const MCSubtargetInfo *STI) const {
420+
bool IsResolved) {
423421
MCFixupKind Kind = Fixup.getKind();
424422
if (mc::isRelocation(Kind))
425423
return;

llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUAsmBackend.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,9 @@ class AMDGPUAsmBackend : public MCAsmBackend {
3232
public:
3333
AMDGPUAsmBackend(const Target &T) : MCAsmBackend(llvm::endianness::little) {}
3434

35-
36-
void applyFixup(const MCAssembler &Asm, const MCFixup &Fixup,
35+
void applyFixup(MCAssembler &, const MCFragment &, const MCFixup &,
3736
const MCValue &Target, MutableArrayRef<char> Data,
38-
uint64_t Value, bool IsResolved,
39-
const MCSubtargetInfo *STI) const override;
37+
uint64_t Value, bool IsResolved) override;
4038
bool fixupNeedsRelaxation(const MCFixup &Fixup,
4139
uint64_t Value) const override;
4240

@@ -133,11 +131,10 @@ static uint64_t adjustFixupValue(const MCFixup &Fixup, uint64_t Value,
133131
}
134132
}
135133

136-
void AMDGPUAsmBackend::applyFixup(const MCAssembler &Asm, const MCFixup &Fixup,
137-
const MCValue &Target,
134+
void AMDGPUAsmBackend::applyFixup(MCAssembler &Asm, const MCFragment &,
135+
const MCFixup &Fixup, const MCValue &Target,
138136
MutableArrayRef<char> Data, uint64_t Value,
139-
bool IsResolved,
140-
const MCSubtargetInfo *STI) const {
137+
bool IsResolved) {
141138
if (mc::isRelocation(Fixup.getKind()))
142139
return;
143140

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1127,16 +1127,16 @@ static unsigned getFixupKindContainerSizeBytes(unsigned Kind) {
11271127
}
11281128
}
11291129

1130-
void ARMAsmBackend::applyFixup(const MCAssembler &Asm, const MCFixup &Fixup,
1131-
const MCValue &Target,
1130+
void ARMAsmBackend::applyFixup(MCAssembler &Asm, const MCFragment &F,
1131+
const MCFixup &Fixup, const MCValue &Target,
11321132
MutableArrayRef<char> Data, uint64_t Value,
1133-
bool IsResolved,
1134-
const MCSubtargetInfo* STI) const {
1133+
bool IsResolved) {
11351134
auto Kind = Fixup.getKind();
11361135
if (mc::isRelocation(Kind))
11371136
return;
11381137
MCContext &Ctx = Asm.getContext();
1139-
Value = adjustFixupValue(Asm, Fixup, Target, Value, IsResolved, Ctx, STI);
1138+
Value = adjustFixupValue(Asm, Fixup, Target, Value, IsResolved, Ctx,
1139+
getSubtargetInfo(F));
11401140
if (!Value)
11411141
return; // Doesn't change encoding.
11421142
const unsigned NumBytes = getFixupKindNumBytes(Kind);

llvm/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,9 @@ class ARMAsmBackend : public MCAsmBackend {
3838
bool IsResolved, MCContext &Ctx,
3939
const MCSubtargetInfo *STI) const;
4040

41-
void applyFixup(const MCAssembler &Asm, const MCFixup &Fixup,
41+
void applyFixup(MCAssembler &, const MCFragment &, const MCFixup &,
4242
const MCValue &Target, MutableArrayRef<char> Data,
43-
uint64_t Value, bool IsResolved,
44-
const MCSubtargetInfo *STI) const override;
43+
uint64_t Value, bool IsResolved) override;
4544

4645
unsigned getRelaxedOpcode(unsigned Op, const MCSubtargetInfo &STI) const;
4746

llvm/lib/Target/AVR/MCTargetDesc/AVRAsmBackend.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -384,11 +384,10 @@ bool AVRAsmBackend::addReloc(MCAssembler &Asm, const MCFragment &F,
384384
return IsResolved;
385385
}
386386

387-
void AVRAsmBackend::applyFixup(const MCAssembler &Asm, const MCFixup &Fixup,
388-
const MCValue &Target,
387+
void AVRAsmBackend::applyFixup(MCAssembler &Asm, const MCFragment &,
388+
const MCFixup &Fixup, const MCValue &Target,
389389
MutableArrayRef<char> Data, uint64_t Value,
390-
bool IsResolved,
391-
const MCSubtargetInfo *STI) const {
390+
bool IsResolved) {
392391
if (mc::isRelocation(Fixup.getKind()))
393392
return;
394393
adjustFixupValue(Fixup, Target, Value, &Asm.getContext());

0 commit comments

Comments
 (0)