Skip to content

Commit 6ec27f1

Browse files
committed
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.
1 parent 74fcff4 commit 6ec27f1

File tree

4 files changed

+7
-13
lines changed

4 files changed

+7
-13
lines changed

llvm/include/llvm/MC/MCFixup.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,7 @@ class MCFixup {
7575

7676
/// True if this is a PC-relative fixup. The relocatable expression is
7777
/// typically resolved When SymB is nullptr and SymA is a local symbol defined
78-
/// within the current section. While MCAssembler currently sets this based on
79-
/// FKF_IsPCRel, targets should ideally set it at creation.
78+
/// within the current section.
8079
bool PCRel = false;
8180

8281
/// Used by RISC-V style linker relaxation. Whether the fixup is

llvm/include/llvm/MC/MCFixupKindInfo.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@ namespace llvm {
1616
/// Target independent information on a fixup kind.
1717
struct MCFixupKindInfo {
1818
enum FixupKindFlags {
19-
/// Is this fixup kind PCrelative? This is used by the assembler backend to
20-
/// evaluate fixup values in a target independent manner when possible.
21-
FKF_IsPCRel = (1 << 0),
22-
2319
/// Should this fixup kind force a 4-byte aligned effective PC value?
2420
FKF_IsAlignedDownTo32Bits = (1 << 1),
2521

llvm/lib/MC/MCAsmBackend.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,22 +87,24 @@ std::optional<MCFixupKind> MCAsmBackend::getFixupKind(StringRef Name) const {
8787
}
8888

8989
MCFixupKindInfo MCAsmBackend::getFixupKindInfo(MCFixupKind Kind) const {
90+
// clang-format off
9091
static const MCFixupKindInfo Builtins[] = {
9192
{"FK_NONE", 0, 0, 0},
9293
{"FK_Data_1", 0, 8, 0},
9394
{"FK_Data_2", 0, 16, 0},
9495
{"FK_Data_4", 0, 32, 0},
9596
{"FK_Data_8", 0, 64, 0},
9697
{"FK_Data_leb128", 0, 0, 0},
97-
{"FK_PCRel_1", 0, 8, MCFixupKindInfo::FKF_IsPCRel},
98-
{"FK_PCRel_2", 0, 16, MCFixupKindInfo::FKF_IsPCRel},
99-
{"FK_PCRel_4", 0, 32, MCFixupKindInfo::FKF_IsPCRel},
100-
{"FK_PCRel_8", 0, 64, MCFixupKindInfo::FKF_IsPCRel},
98+
{"FK_PCRel_1", 0, 8, 0},
99+
{"FK_PCRel_2", 0, 16, 0},
100+
{"FK_PCRel_4", 0, 32, 0},
101+
{"FK_PCRel_8", 0, 64, 0},
101102
{"FK_SecRel_1", 0, 8, 0},
102103
{"FK_SecRel_2", 0, 16, 0},
103104
{"FK_SecRel_4", 0, 32, 0},
104105
{"FK_SecRel_8", 0, 64, 0},
105106
};
107+
// clang-format on
106108

107109
assert(size_t(Kind - FK_NONE) < std::size(Builtins) && "Unknown fixup kind");
108110
return Builtins[Kind - FK_NONE];

llvm/lib/MC/MCAssembler.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,7 @@ bool MCAssembler::evaluateFixup(const MCFragment &F, MCFixup &Fixup,
161161
return true;
162162
}
163163

164-
// TODO: Require targets to set PCRel at fixup creation time.
165164
unsigned FixupFlags = getBackend().getFixupKindInfo(Fixup.getKind()).Flags;
166-
if (FixupFlags & MCFixupKindInfo::FKF_IsPCRel)
167-
Fixup.setPCRel();
168165
bool IsResolved = false;
169166
if (FixupFlags & MCFixupKindInfo::FKF_IsTarget) {
170167
IsResolved = getBackend().evaluateTargetFixup(Fixup, Target, Value);

0 commit comments

Comments
 (0)