Skip to content

Commit 5710759

Browse files
committed
MCAsmBackend,X86: Pass MCValue to fixupNeedsRelaxationAdvanced. NFC
This parameter eliminates a redundant computation for VK_ABS8 in X86 and reduces reliance on shouldForceRelocation in relaxation decisions. Note: `local: jmp local@plt` relaxes JMP. This behavior depends on fixupNeedsRelaxation calling shouldForceRelocation, which might change in the future.
1 parent 52e45a7 commit 5710759

File tree

9 files changed

+44
-50
lines changed

9 files changed

+44
-50
lines changed

llvm/include/llvm/MC/MCAsmBackend.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -153,11 +153,11 @@ class MCAsmBackend {
153153

154154
/// Target specific predicate for whether a given fixup requires the
155155
/// associated instruction to be relaxed.
156-
virtual bool fixupNeedsRelaxationAdvanced(const MCAssembler &Asm,
157-
const MCFixup &Fixup, bool Resolved,
158-
uint64_t Value,
159-
const MCRelaxableFragment *DF,
160-
const bool WasForced) const;
156+
virtual bool fixupNeedsRelaxationAdvanced(const MCAssembler &,
157+
const MCRelaxableFragment &,
158+
const MCFixup &, const MCValue &,
159+
uint64_t, bool Resolved,
160+
bool WasForced) const;
161161

162162
/// Simple predicate for targets where !Resolved implies requiring relaxation
163163
virtual bool fixupNeedsRelaxation(const MCFixup &Fixup,

llvm/lib/MC/MCAsmBackend.cpp

+3-5
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,9 @@ bool MCAsmBackend::shouldForceRelocation(const MCAssembler &, const MCFixup &,
115115
return Target.getSpecifier();
116116
}
117117

118-
bool MCAsmBackend::fixupNeedsRelaxationAdvanced(const MCAssembler &Asm,
119-
const MCFixup &Fixup,
120-
bool Resolved, uint64_t Value,
121-
const MCRelaxableFragment *DF,
122-
const bool WasForced) const {
118+
bool MCAsmBackend::fixupNeedsRelaxationAdvanced(
119+
const MCAssembler &, const MCRelaxableFragment &, const MCFixup &Fixup,
120+
const MCValue &, uint64_t Value, bool Resolved, bool WasForced) const {
123121
if (!Resolved)
124122
return true;
125123
return fixupNeedsRelaxation(Fixup, Value);

llvm/lib/MC/MCAssembler.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1015,8 +1015,8 @@ bool MCAssembler::fixupNeedsRelaxation(const MCFixup &Fixup,
10151015
bool WasForced;
10161016
bool Resolved = evaluateFixup(Fixup, DF, Target, DF->getSubtargetInfo(),
10171017
Value, WasForced);
1018-
return getBackend().fixupNeedsRelaxationAdvanced(*this, Fixup, Resolved,
1019-
Value, DF, WasForced);
1018+
return getBackend().fixupNeedsRelaxationAdvanced(*this, *DF, Fixup, Target,
1019+
Value, Resolved, WasForced);
10201020
}
10211021

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

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

+4-3
Original file line numberDiff line numberDiff line change
@@ -171,10 +171,11 @@ static uint64_t adjustFixupValue(const MCFixup &Fixup, uint64_t Value,
171171
}
172172
}
173173

174-
bool CSKYAsmBackend::fixupNeedsRelaxationAdvanced(const MCAssembler &Asm,
174+
bool CSKYAsmBackend::fixupNeedsRelaxationAdvanced(const MCAssembler &,
175+
const MCRelaxableFragment &,
175176
const MCFixup &Fixup,
176-
bool Resolved, uint64_t Value,
177-
const MCRelaxableFragment *DF,
177+
const MCValue &,
178+
uint64_t Value, bool Resolved,
178179
const bool WasForced) const {
179180
// Return true if the symbol is actually unresolved.
180181
// Resolved could be always false when shouldForceRelocation return true.

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

+4-5
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,10 @@ class CSKYAsmBackend : public MCAsmBackend {
3939
bool mayNeedRelaxation(const MCInst &Inst,
4040
const MCSubtargetInfo &STI) const override;
4141

42-
bool fixupNeedsRelaxationAdvanced(const MCAssembler &Asm,
43-
const MCFixup &Fixup, bool Resolved,
44-
uint64_t Value,
45-
const MCRelaxableFragment *DF,
46-
const bool WasForced) const override;
42+
bool fixupNeedsRelaxationAdvanced(const MCAssembler &,
43+
const MCRelaxableFragment &,
44+
const MCFixup &, const MCValue &, uint64_t,
45+
bool, bool) const override;
4746

4847
bool writeNopData(raw_ostream &OS, uint64_t Count,
4948
const MCSubtargetInfo *STI) const override;

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -566,11 +566,11 @@ class HexagonAsmBackend : public MCAsmBackend {
566566
/// fixupNeedsRelaxation - Target specific predicate for whether a given
567567
/// fixup requires the associated instruction to be relaxed.
568568
bool fixupNeedsRelaxationAdvanced(const MCAssembler &Asm,
569-
const MCFixup &Fixup, bool Resolved,
570-
uint64_t Value,
571-
const MCRelaxableFragment *DF,
572-
const bool WasForced) const override {
573-
MCInst const &MCB = DF->getInst();
569+
const MCRelaxableFragment &DF,
570+
const MCFixup &Fixup, const MCValue &,
571+
uint64_t Value, bool Resolved,
572+
bool) const override {
573+
MCInst const &MCB = DF.getInst();
574574
assert(HexagonMCInstrInfo::isBundle(MCB));
575575

576576
*RelaxTarget = nullptr;

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,9 @@ bool RISCVAsmBackend::shouldForceRelocation(const MCAssembler &Asm,
142142
}
143143

144144
bool RISCVAsmBackend::fixupNeedsRelaxationAdvanced(
145-
const MCAssembler &Asm, const MCFixup &Fixup, bool Resolved, uint64_t Value,
146-
const MCRelaxableFragment *DF, const bool WasForced) const {
145+
const MCAssembler &, const MCRelaxableFragment &, const MCFixup &Fixup,
146+
const MCValue &, uint64_t Value, bool Resolved,
147+
const bool WasForced) const {
147148
if (!RelaxBranches)
148149
return false;
149150

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

+4-6
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,10 @@ class RISCVAsmBackend : public MCAsmBackend {
6868
const MCValue &Target,
6969
const MCSubtargetInfo *STI) override;
7070

71-
bool fixupNeedsRelaxationAdvanced(const MCAssembler &Asm,
72-
const MCFixup &Fixup, bool Resolved,
73-
uint64_t Value,
74-
const MCRelaxableFragment *DF,
75-
const bool WasForced) const override;
76-
71+
bool fixupNeedsRelaxationAdvanced(const MCAssembler &,
72+
const MCRelaxableFragment &,
73+
const MCFixup &, const MCValue &, uint64_t,
74+
bool, bool) const override;
7775

7876
std::optional<MCFixupKind> getFixupKind(StringRef Name) const override;
7977

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

+14-17
Original file line numberDiff line numberDiff line change
@@ -177,11 +177,10 @@ class X86AsmBackend : public MCAsmBackend {
177177
bool mayNeedRelaxation(const MCInst &Inst,
178178
const MCSubtargetInfo &STI) const override;
179179

180-
bool fixupNeedsRelaxationAdvanced(const MCAssembler &Asm,
181-
const MCFixup &Fixup, bool Resolved,
182-
uint64_t Value,
183-
const MCRelaxableFragment *DF,
184-
const bool WasForced) const override;
180+
bool fixupNeedsRelaxationAdvanced(const MCAssembler &,
181+
const MCRelaxableFragment &,
182+
const MCFixup &, const MCValue &, uint64_t,
183+
bool, bool) const override;
185184

186185
void relaxInstruction(MCInst &Inst,
187186
const MCSubtargetInfo &STI) const override;
@@ -731,22 +730,20 @@ bool X86AsmBackend::mayNeedRelaxation(const MCInst &MI,
731730
MI.getOperand(MI.getNumOperands() - 1 - SkipOperands).isExpr());
732731
}
733732

734-
bool X86AsmBackend::fixupNeedsRelaxationAdvanced(const MCAssembler &Asm,
735-
const MCFixup &Fixup,
736-
bool Resolved, uint64_t Value,
737-
const MCRelaxableFragment *DF,
738-
const bool WasForced) const {
733+
bool X86AsmBackend::fixupNeedsRelaxationAdvanced(
734+
const MCAssembler &, const MCRelaxableFragment &, const MCFixup &Fixup,
735+
const MCValue &Target, uint64_t Value, bool Resolved, bool) const {
739736
// If resolved, relax if the value is too big for a (signed) i8.
737+
//
738+
// Currently, `jmp local@plt` relaxes JMP even if the offset is small,
739+
// different from gas.
740740
if (Resolved)
741-
return !isInt<8>(Value);
741+
return !isInt<8>(Value) || Target.getSpecifier();
742742

743743
// Otherwise, relax unless there is a @ABS8 specifier.
744-
if (Fixup.getKind() == FK_Data_1) {
745-
MCValue Target;
746-
if (Fixup.getValue()->evaluateAsRelocatable(Target, &Asm) &&
747-
Target.getAddSym() && Target.getSpecifier() == X86MCExpr::VK_ABS8)
748-
return false;
749-
}
744+
if (Fixup.getKind() == FK_Data_1 && Target.getAddSym() &&
745+
Target.getSpecifier() == X86MCExpr::VK_ABS8)
746+
return false;
750747
return true;
751748
}
752749

0 commit comments

Comments
 (0)