Skip to content

Commit bd32151

Browse files
committed
MCExpr::evaluateKnownAbsolute: replace the MCAsmLayout parameter with MCAssembler
and add a comment.
1 parent cbd3f25 commit bd32151

File tree

7 files changed

+19
-20
lines changed

7 files changed

+19
-20
lines changed

llvm/include/llvm/MC/MCExpr.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
namespace llvm {
1717

1818
class MCAsmInfo;
19-
class MCAsmLayout;
2019
class MCAssembler;
2120
class MCContext;
2221
class MCFixup;
@@ -101,7 +100,10 @@ class MCExpr {
101100
bool evaluateAsAbsolute(int64_t &Res, const MCAssembler &Asm) const;
102101
bool evaluateAsAbsolute(int64_t &Res, const MCAssembler *Asm) const;
103102

104-
bool evaluateKnownAbsolute(int64_t &Res, const MCAsmLayout &Layout) const;
103+
/// Aggressive variant of evaluateAsRelocatable when relocations are
104+
/// unavailable (e.g. .fill). Expects callers to handle errors when true is
105+
/// returned.
106+
bool evaluateKnownAbsolute(int64_t &Res, const MCAssembler &Asm) const;
105107

106108
/// Try to evaluate the expression to a relocatable value, i.e. an
107109
/// expression of the fixed form (a - b + constant).

llvm/lib/MC/ELFObjectWriter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ void ELFWriter::writeSymbol(const MCAssembler &Asm, SymbolTableWriter &Writer,
567567

568568
if (ESize) {
569569
int64_t Res;
570-
if (!ESize->evaluateKnownAbsolute(Res, *Asm.getLayout()))
570+
if (!ESize->evaluateKnownAbsolute(Res, Asm))
571571
report_fatal_error("Size expression must be absolute.");
572572
Size = Res;
573573
}

llvm/lib/MC/MCAssembler.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ uint64_t MCAssembler::computeFragmentSize(const MCFragment &F) const {
288288
case MCFragment::FT_Fill: {
289289
auto &FF = cast<MCFillFragment>(F);
290290
int64_t NumValues = 0;
291-
if (!FF.getNumValues().evaluateKnownAbsolute(NumValues, *Layout)) {
291+
if (!FF.getNumValues().evaluateKnownAbsolute(NumValues, *this)) {
292292
getContext().reportError(FF.getLoc(),
293293
"expected assembly-time absolute expression");
294294
return 0;
@@ -1150,7 +1150,7 @@ bool MCAssembler::relaxLEB(MCLEBFragment &LF) {
11501150
// requires that .uleb128 A-B is foldable where A and B reside in different
11511151
// fragments. This is used by __gcc_except_table.
11521152
bool Abs = getSubsectionsViaSymbols()
1153-
? LF.getValue().evaluateKnownAbsolute(Value, *Layout)
1153+
? LF.getValue().evaluateKnownAbsolute(Value, *this)
11541154
: LF.getValue().evaluateAsAbsolute(Value, *this);
11551155
if (!Abs) {
11561156
bool Relaxed, UseZeroPad;
@@ -1248,7 +1248,7 @@ bool MCAssembler::relaxDwarfLineAddr(MCDwarfLineAddrFragment &DF) {
12481248
MCContext &Context = getContext();
12491249
uint64_t OldSize = DF.getContents().size();
12501250
int64_t AddrDelta;
1251-
bool Abs = DF.getAddrDelta().evaluateKnownAbsolute(AddrDelta, *Layout);
1251+
bool Abs = DF.getAddrDelta().evaluateKnownAbsolute(AddrDelta, *this);
12521252
assert(Abs && "We created a line delta with an invalid expression");
12531253
(void)Abs;
12541254
int64_t LineDelta;
@@ -1301,7 +1301,7 @@ bool MCAssembler::relaxCVDefRange(MCCVDefRangeFragment &F) {
13011301
bool MCAssembler::relaxPseudoProbeAddr(MCPseudoProbeAddrFragment &PF) {
13021302
uint64_t OldSize = PF.getContents().size();
13031303
int64_t AddrDelta;
1304-
bool Abs = PF.getAddrDelta().evaluateKnownAbsolute(AddrDelta, *Layout);
1304+
bool Abs = PF.getAddrDelta().evaluateKnownAbsolute(AddrDelta, *this);
13051305
assert(Abs && "We created a pseudo probe with an invalid expression");
13061306
(void)Abs;
13071307
SmallVectorImpl<char> &Data = PF.getContents();

llvm/lib/MC/MCCodeView.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,8 @@ static unsigned computeLabelDiff(MCAsmLayout &Layout, const MCSymbol *Begin,
474474
const MCExpr *AddrDelta =
475475
MCBinaryExpr::create(MCBinaryExpr::Sub, EndRef, BeginRef, Ctx);
476476
int64_t Result;
477-
bool Success = AddrDelta->evaluateKnownAbsolute(Result, Layout);
477+
bool Success =
478+
AddrDelta->evaluateKnownAbsolute(Result, Layout.getAssembler());
478479
assert(Success && "failed to evaluate label difference as absolute");
479480
(void)Success;
480481
assert(Result >= 0 && "negative label difference requested");

llvm/lib/MC/MCExpr.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -563,9 +563,8 @@ bool MCExpr::evaluateAsAbsolute(int64_t &Res, const MCAssembler *Asm) const {
563563
return evaluateAsAbsolute(Res, Asm, nullptr, false);
564564
}
565565

566-
bool MCExpr::evaluateKnownAbsolute(int64_t &Res,
567-
const MCAsmLayout &Layout) const {
568-
return evaluateAsAbsolute(Res, &Layout.getAssembler(), nullptr, true);
566+
bool MCExpr::evaluateKnownAbsolute(int64_t &Res, const MCAssembler &Asm) const {
567+
return evaluateAsAbsolute(Res, &Asm, nullptr, true);
569568
}
570569

571570
bool MCExpr::evaluateAsAbsolute(int64_t &Res, const MCAssembler *Asm,

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ std::pair<bool, bool> LoongArchAsmBackend::relaxLEB128(const MCAssembler &Asm,
303303
MCLEBFragment &LF,
304304
int64_t &Value) const {
305305
const MCExpr &Expr = LF.getValue();
306-
if (LF.isSigned() || !Expr.evaluateKnownAbsolute(Value, *Asm.getLayout()))
306+
if (LF.isSigned() || !Expr.evaluateKnownAbsolute(Value, Asm))
307307
return std::make_pair(false, false);
308308
LF.getFixups().push_back(
309309
MCFixup::create(0, &Expr, FK_Data_leb128, Expr.getLoc()));
@@ -313,7 +313,6 @@ std::pair<bool, bool> LoongArchAsmBackend::relaxLEB128(const MCAssembler &Asm,
313313
bool LoongArchAsmBackend::relaxDwarfLineAddr(const MCAssembler &Asm,
314314
MCDwarfLineAddrFragment &DF,
315315
bool &WasRelaxed) const {
316-
auto &Layout = *Asm.getLayout();
317316
MCContext &C = Asm.getContext();
318317

319318
int64_t LineDelta = DF.getLineDelta();
@@ -325,7 +324,7 @@ bool LoongArchAsmBackend::relaxDwarfLineAddr(const MCAssembler &Asm,
325324
int64_t Value;
326325
if (AddrDelta.evaluateAsAbsolute(Value, Asm))
327326
return false;
328-
bool IsAbsolute = AddrDelta.evaluateKnownAbsolute(Value, Layout);
327+
bool IsAbsolute = AddrDelta.evaluateKnownAbsolute(Value, Asm);
329328
assert(IsAbsolute && "CFA with invalid expression");
330329
(void)IsAbsolute;
331330

@@ -391,7 +390,7 @@ bool LoongArchAsmBackend::relaxDwarfCFA(const MCAssembler &Asm,
391390
int64_t Value;
392391
if (AddrDelta.evaluateAsAbsolute(Value, Asm))
393392
return false;
394-
bool IsAbsolute = AddrDelta.evaluateKnownAbsolute(Value, Layout);
393+
bool IsAbsolute = AddrDelta.evaluateKnownAbsolute(Value, Asm);
395394
assert(IsAbsolute && "CFA with invalid expression");
396395
(void)IsAbsolute;
397396

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ bool RISCVAsmBackend::relaxDwarfLineAddr(const MCAssembler &Asm,
215215

216216
int64_t Value;
217217
[[maybe_unused]] bool IsAbsolute =
218-
AddrDelta.evaluateKnownAbsolute(Value, *Asm.getLayout());
218+
AddrDelta.evaluateKnownAbsolute(Value, Asm);
219219
assert(IsAbsolute && "CFA with invalid expression");
220220

221221
Data.clear();
@@ -271,7 +271,6 @@ bool RISCVAsmBackend::relaxDwarfLineAddr(const MCAssembler &Asm,
271271
bool RISCVAsmBackend::relaxDwarfCFA(const MCAssembler &Asm,
272272
MCDwarfCallFrameFragment &DF,
273273
bool &WasRelaxed) const {
274-
auto &Layout = *Asm.getLayout();
275274
const MCExpr &AddrDelta = DF.getAddrDelta();
276275
SmallVectorImpl<char> &Data = DF.getContents();
277276
SmallVectorImpl<MCFixup> &Fixups = DF.getFixups();
@@ -281,7 +280,7 @@ bool RISCVAsmBackend::relaxDwarfCFA(const MCAssembler &Asm,
281280
if (AddrDelta.evaluateAsAbsolute(Value, Asm))
282281
return false;
283282
[[maybe_unused]] bool IsAbsolute =
284-
AddrDelta.evaluateKnownAbsolute(Value, Layout);
283+
AddrDelta.evaluateKnownAbsolute(Value, Asm);
285284
assert(IsAbsolute && "CFA with invalid expression");
286285

287286
Data.clear();
@@ -341,8 +340,7 @@ std::pair<bool, bool> RISCVAsmBackend::relaxLEB128(const MCAssembler &Asm,
341340
LF.getFixups().push_back(
342341
MCFixup::create(0, &Expr, FK_Data_leb128, Expr.getLoc()));
343342
}
344-
return std::make_pair(Expr.evaluateKnownAbsolute(Value, *Asm.getLayout()),
345-
false);
343+
return std::make_pair(Expr.evaluateKnownAbsolute(Value, Asm), false);
346344
}
347345

348346
// Given a compressed control flow instruction this function returns

0 commit comments

Comments
 (0)