Skip to content

Commit 22c7317

Browse files
committed
[MC] Remove the MCAsmLayout parameter from relocation related functions
1 parent 1e6d5de commit 22c7317

File tree

12 files changed

+44
-49
lines changed

12 files changed

+44
-49
lines changed

llvm/include/llvm/MC/MCAsmBackend.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@ class MCAsmBackend {
110110
/// Hook which indicates if the target requires a fixup to be generated when
111111
/// handling an align directive in an executable section
112112
virtual bool shouldInsertFixupForCodeAlign(MCAssembler &Asm,
113-
const MCAsmLayout &Layout,
114113
MCAlignFragment &AF) {
115114
return false;
116115
}
@@ -124,7 +123,7 @@ class MCAsmBackend {
124123
llvm_unreachable("Need to implement hook if target has custom fixups");
125124
}
126125

127-
virtual bool handleAddSubRelocations(const MCAsmLayout &Layout,
126+
virtual bool handleAddSubRelocations(const MCAssembler &Asm,
128127
const MCFragment &F,
129128
const MCFixup &Fixup,
130129
const MCValue &Target,
@@ -160,10 +159,10 @@ class MCAsmBackend {
160159

161160
/// Target specific predicate for whether a given fixup requires the
162161
/// associated instruction to be relaxed.
163-
virtual bool fixupNeedsRelaxationAdvanced(const MCFixup &Fixup, bool Resolved,
162+
virtual bool fixupNeedsRelaxationAdvanced(const MCAssembler &Asm,
163+
const MCFixup &Fixup, bool Resolved,
164164
uint64_t Value,
165165
const MCRelaxableFragment *DF,
166-
const MCAsmLayout &Layout,
167166
const bool WasForced) const;
168167

169168
/// Simple predicate for targets where !Resolved implies requiring relaxation

llvm/lib/MC/MCAsmBackend.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "llvm/MC/MCAsmBackend.h"
10+
#include "llvm/MC/MCAssembler.h"
1011
#include "llvm/MC/MCDXContainerWriter.h"
1112
#include "llvm/MC/MCELFObjectWriter.h"
1213
#include "llvm/MC/MCFixupKindInfo.h"
@@ -115,13 +116,14 @@ const MCFixupKindInfo &MCAsmBackend::getFixupKindInfo(MCFixupKind Kind) const {
115116
return Builtins[Kind];
116117
}
117118

118-
bool MCAsmBackend::fixupNeedsRelaxationAdvanced(
119-
const MCFixup &Fixup, bool Resolved, uint64_t Value,
120-
const MCRelaxableFragment *DF, const MCAsmLayout &Layout,
121-
const bool WasForced) const {
119+
bool MCAsmBackend::fixupNeedsRelaxationAdvanced(const MCAssembler &Asm,
120+
const MCFixup &Fixup,
121+
bool Resolved, uint64_t Value,
122+
const MCRelaxableFragment *DF,
123+
const bool WasForced) const {
122124
if (!Resolved)
123125
return true;
124-
return fixupNeedsRelaxation(Fixup, Value, DF, Layout);
126+
return fixupNeedsRelaxation(Fixup, Value, DF, *Asm.getLayout());
125127
}
126128

127129
bool MCAsmBackend::isDarwinCanonicalPersonality(const MCSymbol *Sym) const {

llvm/lib/MC/MCAssembler.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ bool MCAssembler::evaluateFixup(const MCFixup &Fixup, const MCFragment *DF,
270270
// recordRelocation handle non-VK_None cases like A@plt-B+C.
271271
if (!IsResolved && Target.getSymA() && Target.getSymB() &&
272272
Target.getSymA()->getKind() == MCSymbolRefExpr::VK_None &&
273-
getBackend().handleAddSubRelocations(*Layout, *DF, Fixup, Target, Value))
273+
getBackend().handleAddSubRelocations(*this, *DF, Fixup, Target, Value))
274274
return true;
275275

276276
return IsResolved;
@@ -1040,7 +1040,7 @@ void MCAssembler::layout(MCAsmLayout &Layout) {
10401040
// Insert fixup type for code alignment if the target define
10411041
// shouldInsertFixupForCodeAlign target hook.
10421042
if (Sec.useCodeAlign() && AF.hasEmitNops())
1043-
getBackend().shouldInsertFixupForCodeAlign(*this, Layout, AF);
1043+
getBackend().shouldInsertFixupForCodeAlign(*this, AF);
10441044
continue;
10451045
}
10461046
case MCFragment::FT_Data: {
@@ -1126,8 +1126,8 @@ bool MCAssembler::fixupNeedsRelaxation(const MCFixup &Fixup,
11261126
Target.getSymA()->getKind() == MCSymbolRefExpr::VK_X86_ABS8 &&
11271127
Fixup.getKind() == FK_Data_1)
11281128
return false;
1129-
return getBackend().fixupNeedsRelaxationAdvanced(Fixup, Resolved, Value, DF,
1130-
*Layout, WasForced);
1129+
return getBackend().fixupNeedsRelaxationAdvanced(*this, Fixup, Resolved,
1130+
Value, DF, WasForced);
11311131
}
11321132

11331133
bool MCAssembler::fragmentNeedsRelaxation(const MCRelaxableFragment *F) const {

llvm/lib/Target/CSKY/MCTargetDesc/CSKYAsmBackend.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,10 +171,10 @@ static uint64_t adjustFixupValue(const MCFixup &Fixup, uint64_t Value,
171171
}
172172
}
173173

174-
bool CSKYAsmBackend::fixupNeedsRelaxationAdvanced(const MCFixup &Fixup,
174+
bool CSKYAsmBackend::fixupNeedsRelaxationAdvanced(const MCAssembler &Asm,
175+
const MCFixup &Fixup,
175176
bool Resolved, uint64_t Value,
176177
const MCRelaxableFragment *DF,
177-
const MCAsmLayout &Layout,
178178
const bool WasForced) const {
179179
// Return true if the symbol is actually unresolved.
180180
// Resolved could be always false when shouldForceRelocation return true.

llvm/lib/Target/CSKY/MCTargetDesc/CSKYAsmBackend.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ class CSKYAsmBackend : public MCAsmBackend {
4343
bool mayNeedRelaxation(const MCInst &Inst,
4444
const MCSubtargetInfo &STI) const override;
4545

46-
bool fixupNeedsRelaxationAdvanced(const MCFixup &Fixup, bool Resolved,
46+
bool fixupNeedsRelaxationAdvanced(const MCAssembler &Asm,
47+
const MCFixup &Fixup, bool Resolved,
4748
uint64_t Value,
4849
const MCRelaxableFragment *DF,
49-
const MCAsmLayout &Layout,
5050
const bool WasForced) const override;
5151

5252
bool writeNopData(raw_ostream &OS, uint64_t Count,

llvm/lib/Target/Hexagon/MCTargetDesc/HexagonAsmBackend.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -568,10 +568,10 @@ class HexagonAsmBackend : public MCAsmBackend {
568568

569569
/// fixupNeedsRelaxation - Target specific predicate for whether a given
570570
/// fixup requires the associated instruction to be relaxed.
571-
bool fixupNeedsRelaxationAdvanced(const MCFixup &Fixup, bool Resolved,
571+
bool fixupNeedsRelaxationAdvanced(const MCAssembler &Asm,
572+
const MCFixup &Fixup, bool Resolved,
572573
uint64_t Value,
573574
const MCRelaxableFragment *DF,
574-
const MCAsmLayout &Layout,
575575
const bool WasForced) const override {
576576
MCInst const &MCB = DF->getInst();
577577
assert(HexagonMCInstrInfo::isBundle(MCB));
@@ -598,7 +598,7 @@ class HexagonAsmBackend : public MCAsmBackend {
598598
if (HexagonMCInstrInfo::bundleSize(MCB) < HEXAGON_PACKET_SIZE) {
599599
++relaxedCnt;
600600
*RelaxTarget = &MCI;
601-
setExtender(Layout.getAssembler().getContext());
601+
setExtender(Asm.getContext());
602602
return true;
603603
} else {
604604
return false;
@@ -636,7 +636,7 @@ class HexagonAsmBackend : public MCAsmBackend {
636636
if (HexagonMCInstrInfo::bundleSize(MCB) < HEXAGON_PACKET_SIZE) {
637637
++relaxedCnt;
638638
*RelaxTarget = &MCI;
639-
setExtender(Layout.getAssembler().getContext());
639+
setExtender(Asm.getContext());
640640
return true;
641641
}
642642
}

llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,8 @@ bool LoongArchAsmBackend::shouldInsertExtraNopBytesForCodeAlign(
206206
// addend represent alignment and the other bits of addend represent the
207207
// maximum number of bytes to emit. The maximum number of bytes is zero
208208
// means ignore the emit limit.
209-
bool LoongArchAsmBackend::shouldInsertFixupForCodeAlign(
210-
MCAssembler &Asm, const MCAsmLayout &Layout, MCAlignFragment &AF) {
209+
bool LoongArchAsmBackend::shouldInsertFixupForCodeAlign(MCAssembler &Asm,
210+
MCAlignFragment &AF) {
211211
// Insert the fixup only when linker relaxation enabled.
212212
if (!AF.getSubtargetInfo()->hasFeature(LoongArch::FeatureRelax))
213213
return false;
@@ -451,7 +451,7 @@ bool LoongArchAsmBackend::writeNopData(raw_ostream &OS, uint64_t Count,
451451
return true;
452452
}
453453

454-
bool LoongArchAsmBackend::handleAddSubRelocations(const MCAsmLayout &Layout,
454+
bool LoongArchAsmBackend::handleAddSubRelocations(const MCAssembler &Asm,
455455
const MCFragment &F,
456456
const MCFixup &Fixup,
457457
const MCValue &Target,
@@ -503,9 +503,9 @@ bool LoongArchAsmBackend::handleAddSubRelocations(const MCAsmLayout &Layout,
503503
MCValue B = MCValue::get(Target.getSymB());
504504
auto FA = MCFixup::create(Fixup.getOffset(), nullptr, std::get<0>(FK));
505505
auto FB = MCFixup::create(Fixup.getOffset(), nullptr, std::get<1>(FK));
506-
auto &Asm = Layout.getAssembler();
507-
Asm.getWriter().recordRelocation(Asm, &F, FA, A, FixedValueA);
508-
Asm.getWriter().recordRelocation(Asm, &F, FB, B, FixedValueB);
506+
auto &Assembler = const_cast<MCAssembler &>(Asm);
507+
Asm.getWriter().recordRelocation(Assembler, &F, FA, A, FixedValueA);
508+
Asm.getWriter().recordRelocation(Assembler, &F, FB, B, FixedValueB);
509509
FixedValue = FixedValueA - FixedValueB;
510510
return true;
511511
}

llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class LoongArchAsmBackend : public MCAsmBackend {
3939
STI(STI), OSABI(OSABI), Is64Bit(Is64Bit), TargetOptions(Options) {}
4040
~LoongArchAsmBackend() override {}
4141

42-
bool handleAddSubRelocations(const MCAsmLayout &Layout, const MCFragment &F,
42+
bool handleAddSubRelocations(const MCAssembler &Asm, const MCFragment &F,
4343
const MCFixup &Fixup, const MCValue &Target,
4444
uint64_t &FixedValue) const override;
4545

@@ -54,7 +54,6 @@ class LoongArchAsmBackend : public MCAsmBackend {
5454

5555
// Insert target specific fixup type for alignment directive in code section.
5656
bool shouldInsertFixupForCodeAlign(MCAssembler &Asm,
57-
const MCAsmLayout &Layout,
5857
MCAlignFragment &AF) override;
5958

6059
bool shouldForceRelocation(const MCAssembler &Asm, const MCFixup &Fixup,

llvm/lib/Target/MSP430/MCTargetDesc/MSP430AsmBackend.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@ class MSP430AsmBackend : public MCAsmBackend {
5353
return false;
5454
}
5555

56-
bool fixupNeedsRelaxationAdvanced(const MCFixup &Fixup, bool Resolved,
56+
bool fixupNeedsRelaxationAdvanced(const MCAssembler &Asm,
57+
const MCFixup &Fixup, bool Resolved,
5758
uint64_t Value,
5859
const MCRelaxableFragment *DF,
59-
const MCAsmLayout &Layout,
6060
const bool WasForced) const override {
6161
return false;
6262
}

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

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -139,12 +139,9 @@ bool RISCVAsmBackend::shouldForceRelocation(const MCAssembler &Asm,
139139
return STI->hasFeature(RISCV::FeatureRelax) || ForceRelocs;
140140
}
141141

142-
bool RISCVAsmBackend::fixupNeedsRelaxationAdvanced(const MCFixup &Fixup,
143-
bool Resolved,
144-
uint64_t Value,
145-
const MCRelaxableFragment *DF,
146-
const MCAsmLayout &Layout,
147-
const bool WasForced) const {
142+
bool RISCVAsmBackend::fixupNeedsRelaxationAdvanced(
143+
const MCAssembler &Asm, const MCFixup &Fixup, bool Resolved, uint64_t Value,
144+
const MCRelaxableFragment *DF, const bool WasForced) const {
148145
if (!RelaxBranches)
149146
return false;
150147

@@ -584,7 +581,7 @@ bool RISCVAsmBackend::evaluateTargetFixup(
584581
return true;
585582
}
586583

587-
bool RISCVAsmBackend::handleAddSubRelocations(const MCAsmLayout &Layout,
584+
bool RISCVAsmBackend::handleAddSubRelocations(const MCAssembler &Asm,
588585
const MCFragment &F,
589586
const MCFixup &Fixup,
590587
const MCValue &Target,
@@ -623,9 +620,9 @@ bool RISCVAsmBackend::handleAddSubRelocations(const MCAsmLayout &Layout,
623620
auto FB = MCFixup::create(
624621
Fixup.getOffset(), nullptr,
625622
static_cast<MCFixupKind>(FirstLiteralRelocationKind + TB));
626-
auto &Asm = Layout.getAssembler();
627-
Asm.getWriter().recordRelocation(Asm, &F, FA, A, FixedValueA);
628-
Asm.getWriter().recordRelocation(Asm, &F, FB, B, FixedValueB);
623+
auto &Assembler = const_cast<MCAssembler &>(Asm);
624+
Asm.getWriter().recordRelocation(Assembler, &F, FA, A, FixedValueA);
625+
Asm.getWriter().recordRelocation(Assembler, &F, FB, B, FixedValueB);
629626
FixedValue = FixedValueA - FixedValueB;
630627
return true;
631628
}
@@ -689,7 +686,6 @@ bool RISCVAsmBackend::shouldInsertExtraNopBytesForCodeAlign(
689686
// The function insert fixup_riscv_align fixup which eventually will
690687
// transfer to R_RISCV_ALIGN relocation type.
691688
bool RISCVAsmBackend::shouldInsertFixupForCodeAlign(MCAssembler &Asm,
692-
const MCAsmLayout &Layout,
693689
MCAlignFragment &AF) {
694690
// Insert the fixup only when linker relaxation enabled.
695691
const MCSubtargetInfo *STI = AF.getSubtargetInfo();

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,14 @@ class RISCVAsmBackend : public MCAsmBackend {
4545

4646
// Insert target specific fixup type for alignment directive in code section.
4747
bool shouldInsertFixupForCodeAlign(MCAssembler &Asm,
48-
const MCAsmLayout &Layout,
4948
MCAlignFragment &AF) override;
5049

5150
bool evaluateTargetFixup(const MCAssembler &Asm, const MCAsmLayout &Layout,
5251
const MCFixup &Fixup, const MCFragment *DF,
5352
const MCValue &Target, const MCSubtargetInfo *STI,
5453
uint64_t &Value, bool &WasForced) override;
5554

56-
bool handleAddSubRelocations(const MCAsmLayout &Layout, const MCFragment &F,
55+
bool handleAddSubRelocations(const MCAssembler &Asm, const MCFragment &F,
5756
const MCFixup &Fixup, const MCValue &Target,
5857
uint64_t &FixedValue) const override;
5958

@@ -75,10 +74,10 @@ class RISCVAsmBackend : public MCAsmBackend {
7574
llvm_unreachable("Handled by fixupNeedsRelaxationAdvanced");
7675
}
7776

78-
bool fixupNeedsRelaxationAdvanced(const MCFixup &Fixup, bool Resolved,
77+
bool fixupNeedsRelaxationAdvanced(const MCAssembler &Asm,
78+
const MCFixup &Fixup, bool Resolved,
7979
uint64_t Value,
8080
const MCRelaxableFragment *DF,
81-
const MCAsmLayout &Layout,
8281
const bool WasForced) const override;
8382

8483
unsigned getNumFixupKinds() const override {

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -917,7 +917,7 @@ void X86AsmBackend::finishLayout(MCAssembler const &Asm,
917917
}
918918

919919
#ifndef NDEBUG
920-
const uint64_t OrigOffset = Layout.getFragmentOffset(&F);
920+
const uint64_t OrigOffset = Asm.getFragmentOffset(F);
921921
#endif
922922
const uint64_t OrigSize = Asm.computeFragmentSize(F);
923923

@@ -950,7 +950,7 @@ void X86AsmBackend::finishLayout(MCAssembler const &Asm,
950950
cast<MCBoundaryAlignFragment>(F).setSize(RemainingSize);
951951

952952
#ifndef NDEBUG
953-
const uint64_t FinalOffset = Layout.getFragmentOffset(&F);
953+
const uint64_t FinalOffset = Asm.getFragmentOffset(F);
954954
const uint64_t FinalSize = Asm.computeFragmentSize(F);
955955
assert(OrigOffset + OrigSize == FinalOffset + FinalSize &&
956956
"can't move start of next fragment!");
@@ -973,7 +973,7 @@ void X86AsmBackend::finishLayout(MCAssembler const &Asm,
973973
// The layout is done. Mark every fragment as valid.
974974
for (unsigned int i = 0, n = Layout.getSectionOrder().size(); i != n; ++i) {
975975
MCSection &Section = *Layout.getSectionOrder()[i];
976-
Layout.getFragmentOffset(&*Section.curFragList()->Tail);
976+
Asm.getFragmentOffset(*Section.curFragList()->Tail);
977977
Asm.computeFragmentSize(*Section.curFragList()->Tail);
978978
}
979979
}

0 commit comments

Comments
 (0)