Skip to content

Commit 7b7dc15

Browse files
committed
AVRMCCodeEmitter: 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 3544eba commit 7b7dc15

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

llvm/lib/Target/AVR/MCTargetDesc/AVRAsmBackend.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -434,8 +434,8 @@ MCFixupKindInfo AVRAsmBackend::getFixupKindInfo(MCFixupKind Kind) const {
434434
// name offset bits flags
435435
{"fixup_32", 0, 32, 0},
436436

437-
{"fixup_7_pcrel", 3, 7, MCFixupKindInfo::FKF_IsPCRel},
438-
{"fixup_13_pcrel", 0, 12, MCFixupKindInfo::FKF_IsPCRel},
437+
{"fixup_7_pcrel", 3, 7, 0},
438+
{"fixup_13_pcrel", 0, 12, 0},
439439

440440
{"fixup_16", 0, 16, 0},
441441
{"fixup_16_pm", 0, 16, 0},

llvm/lib/Target/AVR/MCTargetDesc/AVRMCCodeEmitter.cpp

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,17 @@
3535

3636
namespace llvm {
3737

38+
static void addFixup(SmallVectorImpl<MCFixup> &Fixups, uint32_t Offset,
39+
const MCExpr *Value, uint16_t Kind) {
40+
bool PCRel = false;
41+
switch (Kind) {
42+
case AVR::fixup_7_pcrel:
43+
case AVR::fixup_13_pcrel:
44+
PCRel = true;
45+
}
46+
Fixups.push_back(MCFixup::create(Offset, Value, Kind, PCRel));
47+
}
48+
3849
/// Performs a post-encoding step on a `LD` or `ST` instruction.
3950
///
4051
/// The encoding of the LD/ST family of instructions is inconsistent w.r.t
@@ -110,7 +121,7 @@ AVRMCCodeEmitter::encodeRelCondBrTarget(const MCInst &MI, unsigned OpNo,
110121
const MCOperand &MO = MI.getOperand(OpNo);
111122

112123
if (MO.isExpr()) {
113-
Fixups.push_back(MCFixup::create(0, MO.getExpr(), MCFixupKind(Fixup)));
124+
addFixup(Fixups, 0, MO.getExpr(), MCFixupKind(Fixup));
114125
return 0;
115126
}
116127

@@ -155,8 +166,7 @@ unsigned AVRMCCodeEmitter::encodeMemri(const MCInst &MI, unsigned OpNo,
155166
OffsetBits = OffsetOp.getImm();
156167
} else if (OffsetOp.isExpr()) {
157168
OffsetBits = 0;
158-
Fixups.push_back(
159-
MCFixup::create(0, OffsetOp.getExpr(), MCFixupKind(AVR::fixup_6)));
169+
addFixup(Fixups, 0, OffsetOp.getExpr(), MCFixupKind(AVR::fixup_6));
160170
} else {
161171
llvm_unreachable("Invalid value for offset");
162172
}
@@ -190,7 +200,7 @@ unsigned AVRMCCodeEmitter::encodeImm(const MCInst &MI, unsigned OpNo,
190200
}
191201

192202
MCFixupKind FixupKind = static_cast<MCFixupKind>(Fixup);
193-
Fixups.push_back(MCFixup::create(Offset, MO.getExpr(), FixupKind));
203+
addFixup(Fixups, Offset, MO.getExpr(), FixupKind);
194204

195205
return 0;
196206
}
@@ -206,7 +216,7 @@ unsigned AVRMCCodeEmitter::encodeCallTarget(const MCInst &MI, unsigned OpNo,
206216

207217
if (MO.isExpr()) {
208218
MCFixupKind FixupKind = static_cast<MCFixupKind>(AVR::fixup_call);
209-
Fixups.push_back(MCFixup::create(0, MO.getExpr(), FixupKind));
219+
addFixup(Fixups, 0, MO.getExpr(), FixupKind);
210220
return 0;
211221
}
212222

@@ -236,7 +246,7 @@ unsigned AVRMCCodeEmitter::getExprOpValue(const MCExpr *Expr,
236246
}
237247

238248
MCFixupKind FixupKind = static_cast<MCFixupKind>(AVRExpr->getFixupKind());
239-
Fixups.push_back(MCFixup::create(0, AVRExpr, FixupKind));
249+
addFixup(Fixups, 0, AVRExpr, FixupKind);
240250
return 0;
241251
}
242252

0 commit comments

Comments
 (0)