Skip to content

Commit b5663d0

Browse files
committed
MCAsmBackend: Remove the MCAssembler argument from relax*
1 parent 48056a7 commit b5663d0

File tree

6 files changed

+30
-39
lines changed

6 files changed

+30
-39
lines changed

llvm/include/llvm/MC/MCAsmBackend.h

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -165,22 +165,20 @@ class MCAsmBackend {
165165
virtual void relaxInstruction(MCInst &Inst,
166166
const MCSubtargetInfo &STI) const {};
167167

168-
virtual bool relaxDwarfLineAddr(const MCAssembler &Asm,
169-
MCDwarfLineAddrFragment &DF,
168+
// Defined by linker relaxation targets.
169+
virtual bool relaxDwarfLineAddr(MCDwarfLineAddrFragment &DF,
170170
bool &WasRelaxed) const {
171171
return false;
172172
}
173-
174-
virtual bool relaxDwarfCFA(const MCAssembler &Asm,
175-
MCDwarfCallFrameFragment &DF,
173+
virtual bool relaxDwarfCFA(MCDwarfCallFrameFragment &DF,
176174
bool &WasRelaxed) const {
177175
return false;
178176
}
179177

180178
// Defined by linker relaxation targets to possibly emit LEB128 relocations
181179
// and set Value at the relocated location.
182-
virtual std::pair<bool, bool>
183-
relaxLEB128(const MCAssembler &Asm, MCLEBFragment &LF, int64_t &Value) const {
180+
virtual std::pair<bool, bool> relaxLEB128(MCLEBFragment &LF,
181+
int64_t &Value) const {
184182
return std::make_pair(false, false);
185183
}
186184

llvm/lib/MC/MCAssembler.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,7 +1046,7 @@ bool MCAssembler::relaxLEB(MCLEBFragment &LF) {
10461046
: LF.getValue().evaluateAsAbsolute(Value, *this);
10471047
if (!Abs) {
10481048
bool Relaxed, UseZeroPad;
1049-
std::tie(Relaxed, UseZeroPad) = getBackend().relaxLEB128(*this, LF, Value);
1049+
std::tie(Relaxed, UseZeroPad) = getBackend().relaxLEB128(LF, Value);
10501050
if (!Relaxed) {
10511051
getContext().reportError(LF.getValue().getLoc(),
10521052
Twine(LF.isSigned() ? ".s" : ".u") +
@@ -1134,7 +1134,7 @@ bool MCAssembler::relaxBoundaryAlign(MCBoundaryAlignFragment &BF) {
11341134

11351135
bool MCAssembler::relaxDwarfLineAddr(MCDwarfLineAddrFragment &DF) {
11361136
bool WasRelaxed;
1137-
if (getBackend().relaxDwarfLineAddr(*this, DF, WasRelaxed))
1137+
if (getBackend().relaxDwarfLineAddr(DF, WasRelaxed))
11381138
return WasRelaxed;
11391139

11401140
MCContext &Context = getContext();
@@ -1156,7 +1156,7 @@ bool MCAssembler::relaxDwarfLineAddr(MCDwarfLineAddrFragment &DF) {
11561156

11571157
bool MCAssembler::relaxDwarfCallFrameFragment(MCDwarfCallFrameFragment &DF) {
11581158
bool WasRelaxed;
1159-
if (getBackend().relaxDwarfCFA(*this, DF, WasRelaxed))
1159+
if (getBackend().relaxDwarfCFA(DF, WasRelaxed))
11601160
return WasRelaxed;
11611161

11621162
MCContext &Context = getContext();

llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -282,19 +282,17 @@ getRelocPairForSize(unsigned Size) {
282282
}
283283
}
284284

285-
std::pair<bool, bool> LoongArchAsmBackend::relaxLEB128(const MCAssembler &Asm,
286-
MCLEBFragment &LF,
285+
std::pair<bool, bool> LoongArchAsmBackend::relaxLEB128(MCLEBFragment &LF,
287286
int64_t &Value) const {
288287
const MCExpr &Expr = LF.getValue();
289-
if (LF.isSigned() || !Expr.evaluateKnownAbsolute(Value, Asm))
288+
if (LF.isSigned() || !Expr.evaluateKnownAbsolute(Value, *Asm))
290289
return std::make_pair(false, false);
291290
LF.getFixups().push_back(
292291
MCFixup::create(0, &Expr, FK_Data_leb128, Expr.getLoc()));
293292
return std::make_pair(true, true);
294293
}
295294

296-
bool LoongArchAsmBackend::relaxDwarfLineAddr(const MCAssembler &Asm,
297-
MCDwarfLineAddrFragment &DF,
295+
bool LoongArchAsmBackend::relaxDwarfLineAddr(MCDwarfLineAddrFragment &DF,
298296
bool &WasRelaxed) const {
299297
MCContext &C = getContext();
300298

@@ -305,9 +303,9 @@ bool LoongArchAsmBackend::relaxDwarfLineAddr(const MCAssembler &Asm,
305303
size_t OldSize = Data.size();
306304

307305
int64_t Value;
308-
if (AddrDelta.evaluateAsAbsolute(Value, Asm))
306+
if (AddrDelta.evaluateAsAbsolute(Value, *Asm))
309307
return false;
310-
bool IsAbsolute = AddrDelta.evaluateKnownAbsolute(Value, Asm);
308+
bool IsAbsolute = AddrDelta.evaluateKnownAbsolute(Value, *Asm);
311309
assert(IsAbsolute && "CFA with invalid expression");
312310
(void)IsAbsolute;
313311

@@ -361,18 +359,17 @@ bool LoongArchAsmBackend::relaxDwarfLineAddr(const MCAssembler &Asm,
361359
return true;
362360
}
363361

364-
bool LoongArchAsmBackend::relaxDwarfCFA(const MCAssembler &Asm,
365-
MCDwarfCallFrameFragment &DF,
362+
bool LoongArchAsmBackend::relaxDwarfCFA(MCDwarfCallFrameFragment &DF,
366363
bool &WasRelaxed) const {
367364
const MCExpr &AddrDelta = DF.getAddrDelta();
368365
SmallVectorImpl<char> &Data = DF.getContents();
369366
SmallVectorImpl<MCFixup> &Fixups = DF.getFixups();
370367
size_t OldSize = Data.size();
371368

372369
int64_t Value;
373-
if (AddrDelta.evaluateAsAbsolute(Value, Asm))
370+
if (AddrDelta.evaluateAsAbsolute(Value, *Asm))
374371
return false;
375-
bool IsAbsolute = AddrDelta.evaluateKnownAbsolute(Value, Asm);
372+
bool IsAbsolute = AddrDelta.evaluateKnownAbsolute(Value, *Asm);
376373
assert(IsAbsolute && "CFA with invalid expression");
377374
(void)IsAbsolute;
378375

llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,12 @@ class LoongArchAsmBackend : public MCAsmBackend {
6060
void relaxInstruction(MCInst &Inst,
6161
const MCSubtargetInfo &STI) const override {}
6262

63-
std::pair<bool, bool> relaxLEB128(const MCAssembler &Asm, MCLEBFragment &LF,
64-
int64_t &Value) const override;
65-
66-
bool relaxDwarfLineAddr(const MCAssembler &Asm, MCDwarfLineAddrFragment &DF,
63+
bool relaxDwarfLineAddr(MCDwarfLineAddrFragment &DF,
6764
bool &WasRelaxed) const override;
68-
bool relaxDwarfCFA(const MCAssembler &Asm, MCDwarfCallFrameFragment &DF,
65+
bool relaxDwarfCFA(MCDwarfCallFrameFragment &DF,
6966
bool &WasRelaxed) const override;
67+
std::pair<bool, bool> relaxLEB128(MCLEBFragment &LF,
68+
int64_t &Value) const override;
7069

7170
bool writeNopData(raw_ostream &OS, uint64_t Count,
7271
const MCSubtargetInfo *STI) const override;

llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,7 @@ void RISCVAsmBackend::relaxInstruction(MCInst &Inst,
235235
Inst = std::move(Res);
236236
}
237237

238-
bool RISCVAsmBackend::relaxDwarfLineAddr(const MCAssembler &Asm,
239-
MCDwarfLineAddrFragment &DF,
238+
bool RISCVAsmBackend::relaxDwarfLineAddr(MCDwarfLineAddrFragment &DF,
240239
bool &WasRelaxed) const {
241240
MCContext &C = getContext();
242241

@@ -248,7 +247,7 @@ bool RISCVAsmBackend::relaxDwarfLineAddr(const MCAssembler &Asm,
248247

249248
int64_t Value;
250249
[[maybe_unused]] bool IsAbsolute =
251-
AddrDelta.evaluateKnownAbsolute(Value, Asm);
250+
AddrDelta.evaluateKnownAbsolute(Value, *Asm);
252251
assert(IsAbsolute && "CFA with invalid expression");
253252

254253
Data.clear();
@@ -301,19 +300,18 @@ bool RISCVAsmBackend::relaxDwarfLineAddr(const MCAssembler &Asm,
301300
return true;
302301
}
303302

304-
bool RISCVAsmBackend::relaxDwarfCFA(const MCAssembler &Asm,
305-
MCDwarfCallFrameFragment &DF,
303+
bool RISCVAsmBackend::relaxDwarfCFA(MCDwarfCallFrameFragment &DF,
306304
bool &WasRelaxed) const {
307305
const MCExpr &AddrDelta = DF.getAddrDelta();
308306
SmallVectorImpl<char> &Data = DF.getContents();
309307
SmallVectorImpl<MCFixup> &Fixups = DF.getFixups();
310308
size_t OldSize = Data.size();
311309

312310
int64_t Value;
313-
if (AddrDelta.evaluateAsAbsolute(Value, Asm))
311+
if (AddrDelta.evaluateAsAbsolute(Value, *Asm))
314312
return false;
315313
[[maybe_unused]] bool IsAbsolute =
316-
AddrDelta.evaluateKnownAbsolute(Value, Asm);
314+
AddrDelta.evaluateKnownAbsolute(Value, *Asm);
317315
assert(IsAbsolute && "CFA with invalid expression");
318316

319317
Data.clear();
@@ -363,8 +361,7 @@ bool RISCVAsmBackend::relaxDwarfCFA(const MCAssembler &Asm,
363361
return true;
364362
}
365363

366-
std::pair<bool, bool> RISCVAsmBackend::relaxLEB128(const MCAssembler &Asm,
367-
MCLEBFragment &LF,
364+
std::pair<bool, bool> RISCVAsmBackend::relaxLEB128(MCLEBFragment &LF,
368365
int64_t &Value) const {
369366
if (LF.isSigned())
370367
return std::make_pair(false, false);
@@ -373,7 +370,7 @@ std::pair<bool, bool> RISCVAsmBackend::relaxLEB128(const MCAssembler &Asm,
373370
LF.getFixups().push_back(
374371
MCFixup::create(0, &Expr, FK_Data_leb128, Expr.getLoc()));
375372
}
376-
return std::make_pair(Expr.evaluateKnownAbsolute(Value, Asm), false);
373+
return std::make_pair(Expr.evaluateKnownAbsolute(Value, *Asm), false);
377374
}
378375

379376
bool RISCVAsmBackend::mayNeedRelaxation(const MCInst &Inst,

llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,11 @@ class RISCVAsmBackend : public MCAsmBackend {
7272
void relaxInstruction(MCInst &Inst,
7373
const MCSubtargetInfo &STI) const override;
7474

75-
bool relaxDwarfLineAddr(const MCAssembler &Asm, MCDwarfLineAddrFragment &DF,
75+
bool relaxDwarfLineAddr(MCDwarfLineAddrFragment &DF,
7676
bool &WasRelaxed) const override;
77-
bool relaxDwarfCFA(const MCAssembler &Asm, MCDwarfCallFrameFragment &DF,
77+
bool relaxDwarfCFA(MCDwarfCallFrameFragment &DF,
7878
bool &WasRelaxed) const override;
79-
std::pair<bool, bool> relaxLEB128(const MCAssembler &Asm, MCLEBFragment &LF,
79+
std::pair<bool, bool> relaxLEB128(MCLEBFragment &LF,
8080
int64_t &Value) const override;
8181

8282
bool writeNopData(raw_ostream &OS, uint64_t Count,

0 commit comments

Comments
 (0)