Skip to content

Commit 7e3e2e1

Browse files
committed
MCParser: Add SMLoc to expressions
The information will be used when we change MCFixup::getLoc to use the MCExpr location, making MCFixup smaller.
1 parent 7ee2c72 commit 7e3e2e1

File tree

7 files changed

+13
-12
lines changed

7 files changed

+13
-12
lines changed

llvm/include/llvm/MC/MCExpr.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,8 +341,8 @@ class MCBinaryExpr : public MCExpr {
341341
SMLoc Loc = SMLoc());
342342

343343
static const MCBinaryExpr *createAdd(const MCExpr *LHS, const MCExpr *RHS,
344-
MCContext &Ctx) {
345-
return create(Add, LHS, RHS, Ctx);
344+
MCContext &Ctx, SMLoc Loc = SMLoc()) {
345+
return create(Add, LHS, RHS, Ctx, Loc);
346346
}
347347

348348
static const MCBinaryExpr *createAnd(const MCExpr *LHS, const MCExpr *RHS,

llvm/lib/MC/ConstantPools.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ const MCExpr *ConstantPool::addEntry(const MCExpr *Value, MCContext &Context,
5959
MCSymbol *CPEntryLabel = Context.createTempSymbol();
6060

6161
Entries.push_back(ConstantPoolEntry(CPEntryLabel, Value, Size, Loc));
62-
const auto SymRef = MCSymbolRefExpr::create(CPEntryLabel, Context);
62+
const auto SymRef = MCSymbolRefExpr::create(CPEntryLabel, Context, Loc);
6363
if (C)
6464
CachedConstantEntries[std::make_pair(C->getValue(), Size)] = SymRef;
6565
if (S)

llvm/lib/MC/MCParser/AsmParser.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1268,7 +1268,7 @@ bool AsmParser::parsePrimaryExpr(const MCExpr *&Res, SMLoc &EndLoc,
12681268
if (IDVal == "f" || IDVal == "b") {
12691269
MCSymbol *Sym =
12701270
Ctx.getDirectionalLocalSymbol(IntVal, IDVal == "b");
1271-
Res = MCSymbolRefExpr::create(Sym, Spec, getContext());
1271+
Res = MCSymbolRefExpr::create(Sym, Spec, getContext(), Loc);
12721272
if (IDVal == "b" && Sym->isUndefined())
12731273
return Error(Loc, "directional label undefined");
12741274
DirLabels.push_back(std::make_tuple(Loc, CppHashInfo, Sym));

llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3299,7 +3299,8 @@ ParseStatus AArch64AsmParser::tryParseAdrpLabel(OperandVector &Operands) {
32993299
if (DarwinSpec == AArch64::S_None && ELFSpec == AArch64::S_INVALID) {
33003300
// No modifier was specified at all; this is the syntax for an ELF basic
33013301
// ADRP relocation (unfortunately).
3302-
Expr = MCSpecifierExpr::create(Expr, AArch64::S_ABS_PAGE, getContext());
3302+
Expr =
3303+
MCSpecifierExpr::create(Expr, AArch64::S_ABS_PAGE, getContext(), S);
33033304
} else if ((DarwinSpec == AArch64::S_MACHO_GOTPAGE ||
33043305
DarwinSpec == AArch64::S_MACHO_TLVPPAGE) &&
33053306
Addend != 0) {
@@ -3351,7 +3352,7 @@ ParseStatus AArch64AsmParser::tryParseAdrLabel(OperandVector &Operands) {
33513352
if (DarwinSpec == AArch64::S_None && ELFSpec == AArch64::S_INVALID) {
33523353
// No modifier was specified at all; this is the syntax for an ELF basic
33533354
// ADR relocation (unfortunately).
3354-
Expr = MCSpecifierExpr::create(Expr, AArch64::S_ABS, getContext());
3355+
Expr = MCSpecifierExpr::create(Expr, AArch64::S_ABS, getContext(), S);
33553356
} else if (ELFSpec != AArch64::S_GOT_AUTH_PAGE) {
33563357
// For tiny code model, we use :got_auth: operator to fill 21-bit imm of
33573358
// adr. It's not actually GOT entry page address but the GOT address
@@ -4394,7 +4395,7 @@ bool AArch64AsmParser::parseRegister(OperandVector &Operands) {
43944395
bool AArch64AsmParser::parseSymbolicImmVal(const MCExpr *&ImmVal) {
43954396
bool HasELFModifier = false;
43964397
AArch64::Specifier RefKind;
4397-
4398+
SMLoc Loc = getLexer().getLoc();
43984399
if (parseOptionalToken(AsmToken::Colon)) {
43994400
HasELFModifier = true;
44004401

@@ -4468,7 +4469,7 @@ bool AArch64AsmParser::parseSymbolicImmVal(const MCExpr *&ImmVal) {
44684469
return true;
44694470

44704471
if (HasELFModifier)
4471-
ImmVal = MCSpecifierExpr::create(ImmVal, RefKind, getContext());
4472+
ImmVal = MCSpecifierExpr::create(ImmVal, RefKind, getContext(), Loc);
44724473

44734474
SMLoc EndLoc;
44744475
if (getContext().getAsmInfo()->hasSubsectionsViaSymbols()) {
@@ -8211,7 +8212,7 @@ bool AArch64AsmParser::parseDataExpr(const MCExpr *&Res) {
82118212
const MCExpr *Term;
82128213
if (getParser().parsePrimaryExpr(Term, EndLoc, nullptr))
82138214
return true;
8214-
Res = MCBinaryExpr::create(*Opcode, Res, Term, getContext());
8215+
Res = MCBinaryExpr::create(*Opcode, Res, Term, getContext(), Res->getLoc());
82158216
}
82168217
return false;
82178218
}

llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2107,7 +2107,7 @@ bool RISCVAsmParser::parseExprWithSpecifier(const MCExpr *&Res, SMLoc &E) {
21072107
if (getParser().parseParenExpression(SubExpr, E))
21082108
return true;
21092109

2110-
Res = MCSpecifierExpr::create(SubExpr, Spec, getContext());
2110+
Res = MCSpecifierExpr::create(SubExpr, Spec, getContext(), SubExpr->getLoc());
21112111
return false;
21122112
}
21132113

llvm/lib/Target/SystemZ/MCTargetDesc/SystemZMCCodeEmitter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ SystemZMCCodeEmitter::getPCRelEncoding(const MCInst &MI, unsigned OpNum,
203203
// into MI. Add Offset to the relocation value to cancel out
204204
// this difference.
205205
const MCExpr *OffsetExpr = MCConstantExpr::create(Offset, Ctx);
206-
Expr = MCBinaryExpr::createAdd(Expr, OffsetExpr, Ctx);
206+
Expr = MCBinaryExpr::createAdd(Expr, OffsetExpr, Ctx, Loc);
207207
}
208208
}
209209
Fixups.push_back(MCFixup::create(Offset, Expr, (MCFixupKind)Kind, Loc));

llvm/lib/Target/X86/MCTargetDesc/X86MCCodeEmitter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,7 @@ void X86MCCodeEmitter::emitImmediate(const MCOperand &DispOp, SMLoc Loc,
603603

604604
if (ImmOffset)
605605
Expr = MCBinaryExpr::createAdd(Expr, MCConstantExpr::create(ImmOffset, Ctx),
606-
Ctx);
606+
Ctx, Expr->getLoc());
607607

608608
// Emit a symbolic constant as a fixup and 4 zeros.
609609
Fixups.push_back(MCFixup::create(static_cast<uint32_t>(CB.size() - StartByte),

0 commit comments

Comments
 (0)