[llvm] 5710759 - MCAsmBackend,X86: Pass MCValue to fixupNeedsRelaxationAdvanced. NFC
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Sun Apr 13 15:20:59 PDT 2025
Author: Fangrui Song
Date: 2025-04-13T15:20:53-07:00
New Revision: 5710759eb390c0d5274c2a4d43967282d7df1993
URL: https://github.com/llvm/llvm-project/commit/5710759eb390c0d5274c2a4d43967282d7df1993
DIFF: https://github.com/llvm/llvm-project/commit/5710759eb390c0d5274c2a4d43967282d7df1993.diff
LOG: 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 at plt` relaxes JMP. This behavior depends on
fixupNeedsRelaxation calling shouldForceRelocation, which might change
in the future.
Added:
Modified:
llvm/include/llvm/MC/MCAsmBackend.h
llvm/lib/MC/MCAsmBackend.cpp
llvm/lib/MC/MCAssembler.cpp
llvm/lib/Target/CSKY/MCTargetDesc/CSKYAsmBackend.cpp
llvm/lib/Target/CSKY/MCTargetDesc/CSKYAsmBackend.h
llvm/lib/Target/Hexagon/MCTargetDesc/HexagonAsmBackend.cpp
llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp
llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.h
llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/MC/MCAsmBackend.h b/llvm/include/llvm/MC/MCAsmBackend.h
index 5953de30c2eb2..8391a465ea264 100644
--- a/llvm/include/llvm/MC/MCAsmBackend.h
+++ b/llvm/include/llvm/MC/MCAsmBackend.h
@@ -153,11 +153,11 @@ class MCAsmBackend {
/// Target specific predicate for whether a given fixup requires the
/// associated instruction to be relaxed.
- virtual bool fixupNeedsRelaxationAdvanced(const MCAssembler &Asm,
- const MCFixup &Fixup, bool Resolved,
- uint64_t Value,
- const MCRelaxableFragment *DF,
- const bool WasForced) const;
+ virtual bool fixupNeedsRelaxationAdvanced(const MCAssembler &,
+ const MCRelaxableFragment &,
+ const MCFixup &, const MCValue &,
+ uint64_t, bool Resolved,
+ bool WasForced) const;
/// Simple predicate for targets where !Resolved implies requiring relaxation
virtual bool fixupNeedsRelaxation(const MCFixup &Fixup,
diff --git a/llvm/lib/MC/MCAsmBackend.cpp b/llvm/lib/MC/MCAsmBackend.cpp
index 23cc134f65b52..dedb9c174db3c 100644
--- a/llvm/lib/MC/MCAsmBackend.cpp
+++ b/llvm/lib/MC/MCAsmBackend.cpp
@@ -115,11 +115,9 @@ bool MCAsmBackend::shouldForceRelocation(const MCAssembler &, const MCFixup &,
return Target.getSpecifier();
}
-bool MCAsmBackend::fixupNeedsRelaxationAdvanced(const MCAssembler &Asm,
- const MCFixup &Fixup,
- bool Resolved, uint64_t Value,
- const MCRelaxableFragment *DF,
- const bool WasForced) const {
+bool MCAsmBackend::fixupNeedsRelaxationAdvanced(
+ const MCAssembler &, const MCRelaxableFragment &, const MCFixup &Fixup,
+ const MCValue &, uint64_t Value, bool Resolved, bool WasForced) const {
if (!Resolved)
return true;
return fixupNeedsRelaxation(Fixup, Value);
diff --git a/llvm/lib/MC/MCAssembler.cpp b/llvm/lib/MC/MCAssembler.cpp
index 934bdb40d530d..db1f95215f906 100644
--- a/llvm/lib/MC/MCAssembler.cpp
+++ b/llvm/lib/MC/MCAssembler.cpp
@@ -1015,8 +1015,8 @@ bool MCAssembler::fixupNeedsRelaxation(const MCFixup &Fixup,
bool WasForced;
bool Resolved = evaluateFixup(Fixup, DF, Target, DF->getSubtargetInfo(),
Value, WasForced);
- return getBackend().fixupNeedsRelaxationAdvanced(*this, Fixup, Resolved,
- Value, DF, WasForced);
+ return getBackend().fixupNeedsRelaxationAdvanced(*this, *DF, Fixup, Target,
+ Value, Resolved, WasForced);
}
bool MCAssembler::fragmentNeedsRelaxation(const MCRelaxableFragment *F) const {
diff --git a/llvm/lib/Target/CSKY/MCTargetDesc/CSKYAsmBackend.cpp b/llvm/lib/Target/CSKY/MCTargetDesc/CSKYAsmBackend.cpp
index ea7968f01ee4a..c6736baa0f32f 100644
--- a/llvm/lib/Target/CSKY/MCTargetDesc/CSKYAsmBackend.cpp
+++ b/llvm/lib/Target/CSKY/MCTargetDesc/CSKYAsmBackend.cpp
@@ -171,10 +171,11 @@ static uint64_t adjustFixupValue(const MCFixup &Fixup, uint64_t Value,
}
}
-bool CSKYAsmBackend::fixupNeedsRelaxationAdvanced(const MCAssembler &Asm,
+bool CSKYAsmBackend::fixupNeedsRelaxationAdvanced(const MCAssembler &,
+ const MCRelaxableFragment &,
const MCFixup &Fixup,
- bool Resolved, uint64_t Value,
- const MCRelaxableFragment *DF,
+ const MCValue &,
+ uint64_t Value, bool Resolved,
const bool WasForced) const {
// Return true if the symbol is actually unresolved.
// Resolved could be always false when shouldForceRelocation return true.
diff --git a/llvm/lib/Target/CSKY/MCTargetDesc/CSKYAsmBackend.h b/llvm/lib/Target/CSKY/MCTargetDesc/CSKYAsmBackend.h
index 07c5065ea4b50..a419ccafe8dee 100644
--- a/llvm/lib/Target/CSKY/MCTargetDesc/CSKYAsmBackend.h
+++ b/llvm/lib/Target/CSKY/MCTargetDesc/CSKYAsmBackend.h
@@ -39,11 +39,10 @@ class CSKYAsmBackend : public MCAsmBackend {
bool mayNeedRelaxation(const MCInst &Inst,
const MCSubtargetInfo &STI) const override;
- bool fixupNeedsRelaxationAdvanced(const MCAssembler &Asm,
- const MCFixup &Fixup, bool Resolved,
- uint64_t Value,
- const MCRelaxableFragment *DF,
- const bool WasForced) const override;
+ bool fixupNeedsRelaxationAdvanced(const MCAssembler &,
+ const MCRelaxableFragment &,
+ const MCFixup &, const MCValue &, uint64_t,
+ bool, bool) const override;
bool writeNopData(raw_ostream &OS, uint64_t Count,
const MCSubtargetInfo *STI) const override;
diff --git a/llvm/lib/Target/Hexagon/MCTargetDesc/HexagonAsmBackend.cpp b/llvm/lib/Target/Hexagon/MCTargetDesc/HexagonAsmBackend.cpp
index 1c1454a41cc09..37669c56ea5e6 100644
--- a/llvm/lib/Target/Hexagon/MCTargetDesc/HexagonAsmBackend.cpp
+++ b/llvm/lib/Target/Hexagon/MCTargetDesc/HexagonAsmBackend.cpp
@@ -566,11 +566,11 @@ class HexagonAsmBackend : public MCAsmBackend {
/// fixupNeedsRelaxation - Target specific predicate for whether a given
/// fixup requires the associated instruction to be relaxed.
bool fixupNeedsRelaxationAdvanced(const MCAssembler &Asm,
- const MCFixup &Fixup, bool Resolved,
- uint64_t Value,
- const MCRelaxableFragment *DF,
- const bool WasForced) const override {
- MCInst const &MCB = DF->getInst();
+ const MCRelaxableFragment &DF,
+ const MCFixup &Fixup, const MCValue &,
+ uint64_t Value, bool Resolved,
+ bool) const override {
+ MCInst const &MCB = DF.getInst();
assert(HexagonMCInstrInfo::isBundle(MCB));
*RelaxTarget = nullptr;
diff --git a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp
index 49c8c6957aa34..94d3a006bf47d 100644
--- a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp
+++ b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp
@@ -142,8 +142,9 @@ bool RISCVAsmBackend::shouldForceRelocation(const MCAssembler &Asm,
}
bool RISCVAsmBackend::fixupNeedsRelaxationAdvanced(
- const MCAssembler &Asm, const MCFixup &Fixup, bool Resolved, uint64_t Value,
- const MCRelaxableFragment *DF, const bool WasForced) const {
+ const MCAssembler &, const MCRelaxableFragment &, const MCFixup &Fixup,
+ const MCValue &, uint64_t Value, bool Resolved,
+ const bool WasForced) const {
if (!RelaxBranches)
return false;
diff --git a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.h b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.h
index f5e8d340d9bce..36bf50fcb2b8a 100644
--- a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.h
+++ b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.h
@@ -68,12 +68,10 @@ class RISCVAsmBackend : public MCAsmBackend {
const MCValue &Target,
const MCSubtargetInfo *STI) override;
- bool fixupNeedsRelaxationAdvanced(const MCAssembler &Asm,
- const MCFixup &Fixup, bool Resolved,
- uint64_t Value,
- const MCRelaxableFragment *DF,
- const bool WasForced) const override;
-
+ bool fixupNeedsRelaxationAdvanced(const MCAssembler &,
+ const MCRelaxableFragment &,
+ const MCFixup &, const MCValue &, uint64_t,
+ bool, bool) const override;
std::optional<MCFixupKind> getFixupKind(StringRef Name) const override;
diff --git a/llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp b/llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp
index 767818107de8d..28f707eb18ae5 100644
--- a/llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp
+++ b/llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp
@@ -177,11 +177,10 @@ class X86AsmBackend : public MCAsmBackend {
bool mayNeedRelaxation(const MCInst &Inst,
const MCSubtargetInfo &STI) const override;
- bool fixupNeedsRelaxationAdvanced(const MCAssembler &Asm,
- const MCFixup &Fixup, bool Resolved,
- uint64_t Value,
- const MCRelaxableFragment *DF,
- const bool WasForced) const override;
+ bool fixupNeedsRelaxationAdvanced(const MCAssembler &,
+ const MCRelaxableFragment &,
+ const MCFixup &, const MCValue &, uint64_t,
+ bool, bool) const override;
void relaxInstruction(MCInst &Inst,
const MCSubtargetInfo &STI) const override;
@@ -731,22 +730,20 @@ bool X86AsmBackend::mayNeedRelaxation(const MCInst &MI,
MI.getOperand(MI.getNumOperands() - 1 - SkipOperands).isExpr());
}
-bool X86AsmBackend::fixupNeedsRelaxationAdvanced(const MCAssembler &Asm,
- const MCFixup &Fixup,
- bool Resolved, uint64_t Value,
- const MCRelaxableFragment *DF,
- const bool WasForced) const {
+bool X86AsmBackend::fixupNeedsRelaxationAdvanced(
+ const MCAssembler &, const MCRelaxableFragment &, const MCFixup &Fixup,
+ const MCValue &Target, uint64_t Value, bool Resolved, bool) const {
// If resolved, relax if the value is too big for a (signed) i8.
+ //
+ // Currently, `jmp local at plt` relaxes JMP even if the offset is small,
+ //
diff erent from gas.
if (Resolved)
- return !isInt<8>(Value);
+ return !isInt<8>(Value) || Target.getSpecifier();
// Otherwise, relax unless there is a @ABS8 specifier.
- if (Fixup.getKind() == FK_Data_1) {
- MCValue Target;
- if (Fixup.getValue()->evaluateAsRelocatable(Target, &Asm) &&
- Target.getAddSym() && Target.getSpecifier() == X86MCExpr::VK_ABS8)
- return false;
- }
+ if (Fixup.getKind() == FK_Data_1 && Target.getAddSym() &&
+ Target.getSpecifier() == X86MCExpr::VK_ABS8)
+ return false;
return true;
}
More information about the llvm-commits
mailing list