Skip to content

Commit 755b473

Browse files
committed
VEMCCodeEmitter: Set PCRel at fixup creation
Avoid reliance on the MCAssembler::evaluateFixup workaround that checks MCFixupKindInfo::FKF_IsPCRel. Additionally, standardize how fixups are appended. This helper will facilitate future fixup data structure optimizations.
1 parent 7b7dc15 commit 755b473

File tree

2 files changed

+22
-19
lines changed

2 files changed

+22
-19
lines changed

llvm/lib/Target/VE/MCTargetDesc/VEAsmBackend.cpp

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -96,22 +96,14 @@ class VEAsmBackend : public MCAsmBackend {
9696
MCFixupKindInfo getFixupKindInfo(MCFixupKind Kind) const override {
9797
const static MCFixupKindInfo Infos[VE::NumTargetFixupKinds] = {
9898
// name, offset, bits, flags
99-
{"fixup_ve_reflong", 0, 32, 0},
100-
{"fixup_ve_srel32", 0, 32, MCFixupKindInfo::FKF_IsPCRel},
101-
{"fixup_ve_hi32", 0, 32, 0},
102-
{"fixup_ve_lo32", 0, 32, 0},
103-
{"fixup_ve_pc_hi32", 0, 32, MCFixupKindInfo::FKF_IsPCRel},
104-
{"fixup_ve_pc_lo32", 0, 32, MCFixupKindInfo::FKF_IsPCRel},
105-
{"fixup_ve_got_hi32", 0, 32, 0},
106-
{"fixup_ve_got_lo32", 0, 32, 0},
107-
{"fixup_ve_gotoff_hi32", 0, 32, 0},
108-
{"fixup_ve_gotoff_lo32", 0, 32, 0},
109-
{"fixup_ve_plt_hi32", 0, 32, 0},
110-
{"fixup_ve_plt_lo32", 0, 32, 0},
111-
{"fixup_ve_tls_gd_hi32", 0, 32, 0},
112-
{"fixup_ve_tls_gd_lo32", 0, 32, 0},
113-
{"fixup_ve_tpoff_hi32", 0, 32, 0},
114-
{"fixup_ve_tpoff_lo32", 0, 32, 0},
99+
{"fixup_ve_reflong", 0, 32, 0}, {"fixup_ve_srel32", 0, 32, 0},
100+
{"fixup_ve_hi32", 0, 32, 0}, {"fixup_ve_lo32", 0, 32, 0},
101+
{"fixup_ve_pc_hi32", 0, 32, 0}, {"fixup_ve_pc_lo32", 0, 32, 0},
102+
{"fixup_ve_got_hi32", 0, 32, 0}, {"fixup_ve_got_lo32", 0, 32, 0},
103+
{"fixup_ve_gotoff_hi32", 0, 32, 0}, {"fixup_ve_gotoff_lo32", 0, 32, 0},
104+
{"fixup_ve_plt_hi32", 0, 32, 0}, {"fixup_ve_plt_lo32", 0, 32, 0},
105+
{"fixup_ve_tls_gd_hi32", 0, 32, 0}, {"fixup_ve_tls_gd_lo32", 0, 32, 0},
106+
{"fixup_ve_tpoff_hi32", 0, 32, 0}, {"fixup_ve_tpoff_lo32", 0, 32, 0},
115107
};
116108

117109
if (Kind < FirstTargetFixupKind)

llvm/lib/Target/VE/MCTargetDesc/VEMCCodeEmitter.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,18 @@ class VEMCCodeEmitter : public MCCodeEmitter {
7676

7777
} // end anonymous namespace
7878

79+
static void addFixup(SmallVectorImpl<MCFixup> &Fixups, uint32_t Offset,
80+
const MCExpr *Value, uint16_t Kind) {
81+
bool PCRel = false;
82+
switch (Kind) {
83+
case VE::fixup_ve_srel32:
84+
case VE::fixup_ve_pc_hi32:
85+
case VE::fixup_ve_pc_lo32:
86+
PCRel = true;
87+
}
88+
Fixups.push_back(MCFixup::create(Offset, Value, Kind, PCRel));
89+
}
90+
7991
void VEMCCodeEmitter::encodeInstruction(const MCInst &MI,
8092
SmallVectorImpl<char> &CB,
8193
SmallVectorImpl<MCFixup> &Fixups,
@@ -100,7 +112,7 @@ unsigned VEMCCodeEmitter::getMachineOpValue(const MCInst &MI,
100112
const MCExpr *Expr = MO.getExpr();
101113
if (const auto *SExpr = dyn_cast<MCSpecifierExpr>(Expr)) {
102114
auto Kind = VE::getFixupKind(SExpr->getSpecifier());
103-
Fixups.push_back(MCFixup::create(0, Expr, Kind));
115+
addFixup(Fixups, 0, Expr, Kind);
104116
return 0;
105117
}
106118

@@ -120,8 +132,7 @@ VEMCCodeEmitter::getBranchTargetOpValue(const MCInst &MI, unsigned OpNo,
120132
if (MO.isReg() || MO.isImm())
121133
return getMachineOpValue(MI, MO, Fixups, STI);
122134

123-
Fixups.push_back(
124-
MCFixup::create(0, MO.getExpr(), (MCFixupKind)VE::fixup_ve_srel32));
135+
addFixup(Fixups, 0, MO.getExpr(), VE::fixup_ve_srel32);
125136
return 0;
126137
}
127138

0 commit comments

Comments
 (0)