[llvm] 6ec27f1 - MCFixup: Remove FKF_IsPCRel
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 4 21:06:59 PDT 2025
Author: Fangrui Song
Date: 2025-07-04T21:06:54-07:00
New Revision: 6ec27f1b8a5aad449dc0be8e64244040858b1b8a
URL: https://github.com/llvm/llvm-project/commit/6ec27f1b8a5aad449dc0be8e64244040858b1b8a
DIFF: https://github.com/llvm/llvm-project/commit/6ec27f1b8a5aad449dc0be8e64244040858b1b8a.diff
LOG: MCFixup: Remove FKF_IsPCRel
PC-relative fixups compute their values as
`sym_a - current_location + offset` (S - P + A).
Now that targets have set PCRel at fixup creation time, we can remove
some overhead from MCAssembler::evaluateFixup.
Added:
Modified:
llvm/include/llvm/MC/MCFixup.h
llvm/include/llvm/MC/MCFixupKindInfo.h
llvm/lib/MC/MCAsmBackend.cpp
llvm/lib/MC/MCAssembler.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/MC/MCFixup.h b/llvm/include/llvm/MC/MCFixup.h
index a8b6281f2fa4b..6a876e8f8e807 100644
--- a/llvm/include/llvm/MC/MCFixup.h
+++ b/llvm/include/llvm/MC/MCFixup.h
@@ -75,8 +75,7 @@ class MCFixup {
/// True if this is a PC-relative fixup. The relocatable expression is
/// typically resolved When SymB is nullptr and SymA is a local symbol defined
- /// within the current section. While MCAssembler currently sets this based on
- /// FKF_IsPCRel, targets should ideally set it at creation.
+ /// within the current section.
bool PCRel = false;
/// Used by RISC-V style linker relaxation. Whether the fixup is
diff --git a/llvm/include/llvm/MC/MCFixupKindInfo.h b/llvm/include/llvm/MC/MCFixupKindInfo.h
index f11cd5caa1d8c..f0e46a48515a6 100644
--- a/llvm/include/llvm/MC/MCFixupKindInfo.h
+++ b/llvm/include/llvm/MC/MCFixupKindInfo.h
@@ -16,10 +16,6 @@ namespace llvm {
/// Target independent information on a fixup kind.
struct MCFixupKindInfo {
enum FixupKindFlags {
- /// Is this fixup kind PCrelative? This is used by the assembler backend to
- /// evaluate fixup values in a target independent manner when possible.
- FKF_IsPCRel = (1 << 0),
-
/// Should this fixup kind force a 4-byte aligned effective PC value?
FKF_IsAlignedDownTo32Bits = (1 << 1),
diff --git a/llvm/lib/MC/MCAsmBackend.cpp b/llvm/lib/MC/MCAsmBackend.cpp
index b38e027033378..b5596b8783fea 100644
--- a/llvm/lib/MC/MCAsmBackend.cpp
+++ b/llvm/lib/MC/MCAsmBackend.cpp
@@ -87,6 +87,7 @@ std::optional<MCFixupKind> MCAsmBackend::getFixupKind(StringRef Name) const {
}
MCFixupKindInfo MCAsmBackend::getFixupKindInfo(MCFixupKind Kind) const {
+ // clang-format off
static const MCFixupKindInfo Builtins[] = {
{"FK_NONE", 0, 0, 0},
{"FK_Data_1", 0, 8, 0},
@@ -94,15 +95,16 @@ MCFixupKindInfo MCAsmBackend::getFixupKindInfo(MCFixupKind Kind) const {
{"FK_Data_4", 0, 32, 0},
{"FK_Data_8", 0, 64, 0},
{"FK_Data_leb128", 0, 0, 0},
- {"FK_PCRel_1", 0, 8, MCFixupKindInfo::FKF_IsPCRel},
- {"FK_PCRel_2", 0, 16, MCFixupKindInfo::FKF_IsPCRel},
- {"FK_PCRel_4", 0, 32, MCFixupKindInfo::FKF_IsPCRel},
- {"FK_PCRel_8", 0, 64, MCFixupKindInfo::FKF_IsPCRel},
+ {"FK_PCRel_1", 0, 8, 0},
+ {"FK_PCRel_2", 0, 16, 0},
+ {"FK_PCRel_4", 0, 32, 0},
+ {"FK_PCRel_8", 0, 64, 0},
{"FK_SecRel_1", 0, 8, 0},
{"FK_SecRel_2", 0, 16, 0},
{"FK_SecRel_4", 0, 32, 0},
{"FK_SecRel_8", 0, 64, 0},
};
+ // clang-format on
assert(size_t(Kind - FK_NONE) < std::size(Builtins) && "Unknown fixup kind");
return Builtins[Kind - FK_NONE];
diff --git a/llvm/lib/MC/MCAssembler.cpp b/llvm/lib/MC/MCAssembler.cpp
index 7e6365a4574d2..64fc0a8f25f43 100644
--- a/llvm/lib/MC/MCAssembler.cpp
+++ b/llvm/lib/MC/MCAssembler.cpp
@@ -161,10 +161,7 @@ bool MCAssembler::evaluateFixup(const MCFragment &F, MCFixup &Fixup,
return true;
}
- // TODO: Require targets to set PCRel at fixup creation time.
unsigned FixupFlags = getBackend().getFixupKindInfo(Fixup.getKind()).Flags;
- if (FixupFlags & MCFixupKindInfo::FKF_IsPCRel)
- Fixup.setPCRel();
bool IsResolved = false;
if (FixupFlags & MCFixupKindInfo::FKF_IsTarget) {
IsResolved = getBackend().evaluateTargetFixup(Fixup, Target, Value);
More information about the llvm-commits
mailing list