Skip to content

Commit 3544eba

Browse files
committed
MSP430MCCodeEmitter: 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 b418e73 commit 3544eba

File tree

2 files changed

+24
-11
lines changed

2 files changed

+24
-11
lines changed

llvm/lib/Target/MSP430/MCTargetDesc/MSP430AsmBackend.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,21 +46,23 @@ class MSP430AsmBackend : public MCAsmBackend {
4646
}
4747

4848
MCFixupKindInfo getFixupKindInfo(MCFixupKind Kind) const override {
49+
// clang-format off
4950
const static MCFixupKindInfo Infos[MSP430::NumTargetFixupKinds] = {
5051
// This table must be in the same order of enum in MSP430FixupKinds.h.
5152
//
5253
// name offset bits flags
5354
{"fixup_32", 0, 32, 0},
54-
{"fixup_10_pcrel", 0, 10, MCFixupKindInfo::FKF_IsPCRel},
55+
{"fixup_10_pcrel", 0, 10, 0},
5556
{"fixup_16", 0, 16, 0},
56-
{"fixup_16_pcrel", 0, 16, MCFixupKindInfo::FKF_IsPCRel},
57+
{"fixup_16_pcrel", 0, 16, 0},
5758
{"fixup_16_byte", 0, 16, 0},
58-
{"fixup_16_pcrel_byte", 0, 16, MCFixupKindInfo::FKF_IsPCRel},
59-
{"fixup_2x_pcrel", 0, 10, MCFixupKindInfo::FKF_IsPCRel},
60-
{"fixup_rl_pcrel", 0, 16, MCFixupKindInfo::FKF_IsPCRel},
59+
{"fixup_16_pcrel_byte", 0, 16, 0},
60+
{"fixup_2x_pcrel", 0, 10, 0},
61+
{"fixup_rl_pcrel", 0, 16, 0},
6162
{"fixup_8", 0, 8, 0},
6263
{"fixup_sym_diff", 0, 32, 0},
6364
};
65+
// clang-format on
6466
static_assert((std::size(Infos)) == MSP430::NumTargetFixupKinds,
6567
"Not all fixup kinds added to Infos array");
6668

llvm/lib/Target/MSP430/MCTargetDesc/MSP430MCCodeEmitter.cpp

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,20 @@ class MSP430MCCodeEmitter : public MCCodeEmitter {
7777
const MCSubtargetInfo &STI) const override;
7878
};
7979

80+
static void addFixup(SmallVectorImpl<MCFixup> &Fixups, uint32_t Offset,
81+
const MCExpr *Value, uint16_t Kind) {
82+
bool PCRel = false;
83+
switch (Kind) {
84+
case MSP430::fixup_10_pcrel:
85+
case MSP430::fixup_16_pcrel:
86+
case MSP430::fixup_16_pcrel_byte:
87+
case MSP430::fixup_2x_pcrel:
88+
case MSP430::fixup_rl_pcrel:
89+
PCRel = true;
90+
}
91+
Fixups.push_back(MCFixup::create(Offset, Value, Kind, PCRel));
92+
}
93+
8094
void MSP430MCCodeEmitter::encodeInstruction(const MCInst &MI,
8195
SmallVectorImpl<char> &CB,
8296
SmallVectorImpl<MCFixup> &Fixups,
@@ -111,8 +125,7 @@ unsigned MSP430MCCodeEmitter::getMachineOpValue(const MCInst &MI,
111125
}
112126

113127
assert(MO.isExpr() && "Expected expr operand");
114-
Fixups.push_back(MCFixup::create(
115-
Offset, MO.getExpr(), static_cast<MCFixupKind>(MSP430::fixup_16_byte)));
128+
addFixup(Fixups, Offset, MO.getExpr(), MSP430::fixup_16_byte);
116129
Offset += 2;
117130
return 0;
118131
}
@@ -143,8 +156,7 @@ unsigned MSP430MCCodeEmitter::getMemOpValue(const MCInst &MI, unsigned Op,
143156
FixupKind = MSP430::fixup_16_byte;
144157
break;
145158
}
146-
Fixups.push_back(MCFixup::create(Offset, MO2.getExpr(),
147-
static_cast<MCFixupKind>(FixupKind)));
159+
addFixup(Fixups, Offset, MO2.getExpr(), FixupKind);
148160
Offset += 2;
149161
return Reg;
150162
}
@@ -157,8 +169,7 @@ unsigned MSP430MCCodeEmitter::getPCRelImmOpValue(const MCInst &MI, unsigned Op,
157169
return MO.getImm();
158170

159171
assert(MO.isExpr() && "Expr operand expected");
160-
Fixups.push_back(MCFixup::create(
161-
0, MO.getExpr(), static_cast<MCFixupKind>(MSP430::fixup_10_pcrel)));
172+
addFixup(Fixups, 0, MO.getExpr(), MSP430::fixup_10_pcrel);
162173
return 0;
163174
}
164175

0 commit comments

Comments
 (0)