Skip to content

[MC] Don't pass MCSubtargetInfo down to shouldForceRelocation and evaluateTargetFixup #141311

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions llvm/include/llvm/MC/MCAsmBackend.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class MCAsmBackend {

// Hook used by the default `addReloc` to check if a relocation is needed.
virtual bool shouldForceRelocation(const MCAssembler &, const MCFixup &,
const MCValue &, const MCSubtargetInfo *) {
const MCValue &) {
return false;
}

Expand All @@ -111,7 +111,6 @@ class MCAsmBackend {

virtual bool evaluateTargetFixup(const MCAssembler &Asm, const MCFixup &Fixup,
const MCFragment *DF, const MCValue &Target,
const MCSubtargetInfo *STI,
uint64_t &Value) {
llvm_unreachable("Need to implement hook if target has custom fixups");
}
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/MC/MCAsmBackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ bool MCAsmBackend::addReloc(MCAssembler &Asm, const MCFragment &F,
const MCFixup &Fixup, const MCValue &Target,
uint64_t &FixedValue, bool IsResolved,
const MCSubtargetInfo *STI) {
if (IsResolved && shouldForceRelocation(Asm, Fixup, Target, STI))
if (IsResolved && shouldForceRelocation(Asm, Fixup, Target))
IsResolved = false;
if (!IsResolved)
Asm.getWriter().recordRelocation(Asm, &F, Fixup, Target, FixedValue);
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/MC/MCAssembler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ bool MCAssembler::evaluateFixup(const MCFixup &Fixup, const MCFragment *DF,
unsigned FixupFlags = getBackend().getFixupKindInfo(Fixup.getKind()).Flags;
if (FixupFlags & MCFixupKindInfo::FKF_IsTarget) {
IsResolved =
getBackend().evaluateTargetFixup(*this, Fixup, DF, Target, STI, Value);
getBackend().evaluateTargetFixup(*this, Fixup, DF, Target, Value);
} else {
const MCSymbol *Add = Target.getAddSym();
const MCSymbol *Sub = Target.getSubSym();
Expand Down
6 changes: 2 additions & 4 deletions llvm/lib/Target/AArch64/MCTargetDesc/AArch64AsmBackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,7 @@ class AArch64AsmBackend : public MCAsmBackend {
unsigned getFixupKindContainereSizeInBytes(unsigned Kind) const;

bool shouldForceRelocation(const MCAssembler &Asm, const MCFixup &Fixup,
const MCValue &Target,
const MCSubtargetInfo *STI) override;
const MCValue &Target) override;
};

} // end anonymous namespace
Expand Down Expand Up @@ -523,8 +522,7 @@ bool AArch64AsmBackend::writeNopData(raw_ostream &OS, uint64_t Count,

bool AArch64AsmBackend::shouldForceRelocation(const MCAssembler &Asm,
const MCFixup &Fixup,
const MCValue &Target,
const MCSubtargetInfo *STI) {
const MCValue &Target) {
// The ADRP instruction adds some multiple of 0x1000 to the current PC &
// ~0xfff. This means that the required offset to reach a symbol can vary by
// up to one step depending on where the ADRP is in memory. For example:
Expand Down
5 changes: 2 additions & 3 deletions llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUAsmBackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class AMDGPUAsmBackend : public MCAsmBackend {
std::optional<MCFixupKind> getFixupKind(StringRef Name) const override;
MCFixupKindInfo getFixupKindInfo(MCFixupKind Kind) const override;
bool shouldForceRelocation(const MCAssembler &, const MCFixup &,
const MCValue &, const MCSubtargetInfo *) override;
const MCValue &) override;
};

} //End anonymous namespace
Expand Down Expand Up @@ -194,8 +194,7 @@ MCFixupKindInfo AMDGPUAsmBackend::getFixupKindInfo(MCFixupKind Kind) const {

bool AMDGPUAsmBackend::shouldForceRelocation(const MCAssembler &,
const MCFixup &,
const MCValue &Target,
const MCSubtargetInfo *) {
const MCValue &Target) {
return Target.getSpecifier();
}

Expand Down
3 changes: 1 addition & 2 deletions llvm/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -971,8 +971,7 @@ unsigned ARMAsmBackend::adjustFixupValue(const MCAssembler &Asm,

bool ARMAsmBackend::shouldForceRelocation(const MCAssembler &Asm,
const MCFixup &Fixup,
const MCValue &Target,
const MCSubtargetInfo *STI) {
const MCValue &Target) {
const MCSymbol *Sym = Target.getAddSym();
const unsigned FixupKind = Fixup.getKind();
if (FixupKind == ARM::fixup_arm_thumb_bl) {
Expand Down
3 changes: 1 addition & 2 deletions llvm/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ class ARMAsmBackend : public MCAsmBackend {
MCFixupKindInfo getFixupKindInfo(MCFixupKind Kind) const override;

bool shouldForceRelocation(const MCAssembler &Asm, const MCFixup &Fixup,
const MCValue &Target,
const MCSubtargetInfo *STI) override;
const MCValue &Target) override;

unsigned adjustFixupValue(const MCAssembler &Asm, const MCFixup &Fixup,
const MCValue &Target, uint64_t Value,
Expand Down
9 changes: 4 additions & 5 deletions llvm/lib/Target/AVR/MCTargetDesc/AVRAsmBackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ bool AVRAsmBackend::addReloc(MCAssembler &Asm, const MCFragment &F,
if (IsResolved) {
auto TargetVal = MCValue::get(Target.getAddSym(), Target.getSubSym(),
FixedValue, Target.getSpecifier());
if (shouldForceRelocation(Asm, Fixup, TargetVal, STI))
if (forceRelocation(Asm, Fixup, TargetVal, STI))
IsResolved = false;
}
if (!IsResolved)
Expand Down Expand Up @@ -515,10 +515,9 @@ bool AVRAsmBackend::writeNopData(raw_ostream &OS, uint64_t Count,
return true;
}

bool AVRAsmBackend::shouldForceRelocation(const MCAssembler &Asm,
const MCFixup &Fixup,
const MCValue &Target,
const MCSubtargetInfo *STI) {
bool AVRAsmBackend::forceRelocation(const MCAssembler &Asm,
const MCFixup &Fixup, const MCValue &Target,
const MCSubtargetInfo *STI) {
switch ((unsigned)Fixup.getKind()) {
default:
return false;
Expand Down
5 changes: 2 additions & 3 deletions llvm/lib/Target/AVR/MCTargetDesc/AVRAsmBackend.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,8 @@ class AVRAsmBackend : public MCAsmBackend {
bool writeNopData(raw_ostream &OS, uint64_t Count,
const MCSubtargetInfo *STI) const override;

bool shouldForceRelocation(const MCAssembler &Asm, const MCFixup &Fixup,
const MCValue &Target,
const MCSubtargetInfo *STI) override;
bool forceRelocation(const MCAssembler &Asm, const MCFixup &Fixup,
const MCValue &Target, const MCSubtargetInfo *);

private:
Triple::OSType OSType;
Expand Down
3 changes: 1 addition & 2 deletions llvm/lib/Target/CSKY/MCTargetDesc/CSKYAsmBackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,7 @@ bool CSKYAsmBackend::mayNeedRelaxation(const MCInst &Inst,

bool CSKYAsmBackend::shouldForceRelocation(const MCAssembler &Asm,
const MCFixup &Fixup,
const MCValue &Target,
const MCSubtargetInfo * /*STI*/) {
const MCValue &Target /*STI*/) {
if (Target.getSpecifier())
return true;
switch (Fixup.getTargetKind()) {
Expand Down
3 changes: 1 addition & 2 deletions llvm/lib/Target/CSKY/MCTargetDesc/CSKYAsmBackend.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ class CSKYAsmBackend : public MCAsmBackend {
const MCSubtargetInfo *STI) const override;

bool shouldForceRelocation(const MCAssembler &Asm, const MCFixup &Fixup,
const MCValue &Target,
const MCSubtargetInfo *STI) override;
const MCValue &Target) override;

std::unique_ptr<MCObjectTargetWriter>
createObjectTargetWriter() const override;
Expand Down
3 changes: 1 addition & 2 deletions llvm/lib/Target/Hexagon/MCTargetDesc/HexagonAsmBackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,7 @@ class HexagonAsmBackend : public MCAsmBackend {
}

bool shouldForceRelocation(const MCAssembler &Asm, const MCFixup &Fixup,
const MCValue &Target,
const MCSubtargetInfo *STI) override {
const MCValue &Target) override {
switch(Fixup.getTargetKind()) {
default:
llvm_unreachable("Unknown Fixup Kind!");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,11 +246,10 @@ bool LoongArchAsmBackend::shouldInsertFixupForCodeAlign(MCAssembler &Asm,

bool LoongArchAsmBackend::shouldForceRelocation(const MCAssembler &Asm,
const MCFixup &Fixup,
const MCValue &Target,
const MCSubtargetInfo *STI) {
const MCValue &Target) {
switch (Fixup.getTargetKind()) {
default:
return STI->hasFeature(LoongArch::FeatureRelax);
return STI.hasFeature(LoongArch::FeatureRelax);
case FK_Data_1:
case FK_Data_2:
case FK_Data_4:
Expand Down
4 changes: 1 addition & 3 deletions llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@ class LoongArchAsmBackend : public MCAsmBackend {
MCAlignFragment &AF) override;

bool shouldForceRelocation(const MCAssembler &Asm, const MCFixup &Fixup,
const MCValue &Target,
const MCSubtargetInfo *STI) override;

const MCValue &Target) override;

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

Expand Down
3 changes: 1 addition & 2 deletions llvm/lib/Target/Mips/MCTargetDesc/MipsAsmBackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -559,8 +559,7 @@ bool MipsAsmBackend::writeNopData(raw_ostream &OS, uint64_t Count,

bool MipsAsmBackend::shouldForceRelocation(const MCAssembler &Asm,
const MCFixup &Fixup,
const MCValue &Target,
const MCSubtargetInfo *STI) {
const MCValue &Target) {
const unsigned FixupKind = Fixup.getKind();
switch (FixupKind) {
default:
Expand Down
3 changes: 1 addition & 2 deletions llvm/lib/Target/Mips/MCTargetDesc/MipsAsmBackend.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ class MipsAsmBackend : public MCAsmBackend {
const MCSubtargetInfo *STI) const override;

bool shouldForceRelocation(const MCAssembler &Asm, const MCFixup &Fixup,
const MCValue &Target,
const MCSubtargetInfo *STI) override;
const MCValue &Target) override;
}; // class MipsAsmBackend

} // namespace
Expand Down
3 changes: 1 addition & 2 deletions llvm/lib/Target/PowerPC/MCTargetDesc/PPCAsmBackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,7 @@ class PPCAsmBackend : public MCAsmBackend {
}

bool shouldForceRelocation(const MCAssembler &Asm, const MCFixup &Fixup,
const MCValue &Target,
const MCSubtargetInfo *STI) override {
const MCValue &Target) override {
// If there is a @ specifier, unless it is optimized out (e.g. constant @l),
// force a relocation.
if (Target.getSpecifier())
Expand Down
8 changes: 5 additions & 3 deletions llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -569,9 +569,11 @@ bool RISCVAsmBackend::isPCRelFixupResolved(const MCAssembler &Asm,
return !Res.getSubSym();
}

bool RISCVAsmBackend::evaluateTargetFixup(
const MCAssembler &Asm, const MCFixup &Fixup, const MCFragment *DF,
const MCValue &Target, const MCSubtargetInfo *STI, uint64_t &Value) {
bool RISCVAsmBackend::evaluateTargetFixup(const MCAssembler &Asm,
const MCFixup &Fixup,
const MCFragment *DF,
const MCValue &Target,
uint64_t &Value) {
const MCFixup *AUIPCFixup;
const MCFragment *AUIPCDF;
MCValue AUIPCTarget;
Expand Down
1 change: 0 additions & 1 deletion llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ class RISCVAsmBackend : public MCAsmBackend {

bool evaluateTargetFixup(const MCAssembler &Asm, const MCFixup &Fixup,
const MCFragment *DF, const MCValue &Target,
const MCSubtargetInfo *STI,
uint64_t &Value) override;

bool addReloc(MCAssembler &Asm, const MCFragment &F, const MCFixup &Fixup,
Expand Down
5 changes: 2 additions & 3 deletions llvm/lib/Target/SystemZ/MCTargetDesc/SystemZMCAsmBackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class SystemZMCAsmBackend : public MCAsmBackend {
std::optional<MCFixupKind> getFixupKind(StringRef Name) const override;
MCFixupKindInfo getFixupKindInfo(MCFixupKind Kind) const override;
bool shouldForceRelocation(const MCAssembler &, const MCFixup &,
const MCValue &, const MCSubtargetInfo *) override;
const MCValue &) override;
void applyFixup(const MCAssembler &Asm, const MCFixup &Fixup,
const MCValue &Target, MutableArrayRef<char> Data,
uint64_t Value, bool IsResolved,
Expand Down Expand Up @@ -157,8 +157,7 @@ MCFixupKindInfo SystemZMCAsmBackend::getFixupKindInfo(MCFixupKind Kind) const {

bool SystemZMCAsmBackend::shouldForceRelocation(const MCAssembler &,
const MCFixup &,
const MCValue &Target,
const MCSubtargetInfo *) {
const MCValue &Target) {
return Target.getSpecifier();
}

Expand Down
3 changes: 1 addition & 2 deletions llvm/lib/Target/VE/MCTargetDesc/VEAsmBackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,7 @@ class VEAsmBackend : public MCAsmBackend {
}

bool shouldForceRelocation(const MCAssembler &Asm, const MCFixup &Fixup,
const MCValue &Target,
const MCSubtargetInfo *STI) override {
const MCValue &Target) override {
switch ((VE::Fixups)Fixup.getKind()) {
default:
return false;
Expand Down
5 changes: 2 additions & 3 deletions llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ class X86AsmBackend : public MCAsmBackend {
MCFixupKindInfo getFixupKindInfo(MCFixupKind Kind) const override;

bool shouldForceRelocation(const MCAssembler &, const MCFixup &,
const MCValue &, const MCSubtargetInfo *) override;
const MCValue &) override;

void applyFixup(const MCAssembler &Asm, const MCFixup &Fixup,
const MCValue &Target, MutableArrayRef<char> Data,
Expand Down Expand Up @@ -693,8 +693,7 @@ static unsigned getFixupKindSize(unsigned Kind) {
// Force relocation when there is a specifier. This might be too conservative -
// GAS doesn't emit a relocation for call local@plt; local:.
bool X86AsmBackend::shouldForceRelocation(const MCAssembler &, const MCFixup &,
const MCValue &Target,
const MCSubtargetInfo *) {
const MCValue &Target) {
return Target.getSpecifier();
}

Expand Down
Loading