Author: Fangrui Song Date: 2025-07-04T00:58:07-07:00 New Revision: 7e3e2e1b8c6ff21e68782a56164139cca334fcf3
URL: https://github.com/llvm/llvm-project/commit/7e3e2e1b8c6ff21e68782a56164139cca334fcf3 DIFF: https://github.com/llvm/llvm-project/commit/7e3e2e1b8c6ff21e68782a56164139cca334fcf3.diff LOG: MCParser: Add SMLoc to expressions The information will be used when we change MCFixup::getLoc to use the MCExpr location, making MCFixup smaller. Added: Modified: llvm/include/llvm/MC/MCExpr.h llvm/lib/MC/ConstantPools.cpp llvm/lib/MC/MCParser/AsmParser.cpp llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp llvm/lib/Target/SystemZ/MCTargetDesc/SystemZMCCodeEmitter.cpp llvm/lib/Target/X86/MCTargetDesc/X86MCCodeEmitter.cpp Removed: ################################################################################ diff --git a/llvm/include/llvm/MC/MCExpr.h b/llvm/include/llvm/MC/MCExpr.h index b3585693afa02..e460c95ea4dff 100644 --- a/llvm/include/llvm/MC/MCExpr.h +++ b/llvm/include/llvm/MC/MCExpr.h @@ -341,8 +341,8 @@ class MCBinaryExpr : public MCExpr { SMLoc Loc = SMLoc()); static const MCBinaryExpr *createAdd(const MCExpr *LHS, const MCExpr *RHS, - MCContext &Ctx) { - return create(Add, LHS, RHS, Ctx); + MCContext &Ctx, SMLoc Loc = SMLoc()) { + return create(Add, LHS, RHS, Ctx, Loc); } static const MCBinaryExpr *createAnd(const MCExpr *LHS, const MCExpr *RHS, diff --git a/llvm/lib/MC/ConstantPools.cpp b/llvm/lib/MC/ConstantPools.cpp index 824d2463f30fc..bf74ad42f91fd 100644 --- a/llvm/lib/MC/ConstantPools.cpp +++ b/llvm/lib/MC/ConstantPools.cpp @@ -59,7 +59,7 @@ const MCExpr *ConstantPool::addEntry(const MCExpr *Value, MCContext &Context, MCSymbol *CPEntryLabel = Context.createTempSymbol(); Entries.push_back(ConstantPoolEntry(CPEntryLabel, Value, Size, Loc)); - const auto SymRef = MCSymbolRefExpr::create(CPEntryLabel, Context); + const auto SymRef = MCSymbolRefExpr::create(CPEntryLabel, Context, Loc); if (C) CachedConstantEntries[std::make_pair(C->getValue(), Size)] = SymRef; if (S) diff --git a/llvm/lib/MC/MCParser/AsmParser.cpp b/llvm/lib/MC/MCParser/AsmParser.cpp index 91914d0cb3746..05771a5797635 100644 --- a/llvm/lib/MC/MCParser/AsmParser.cpp +++ b/llvm/lib/MC/MCParser/AsmParser.cpp @@ -1268,7 +1268,7 @@ bool AsmParser::parsePrimaryExpr(const MCExpr *&Res, SMLoc &EndLoc, if (IDVal == "f" || IDVal == "b") { MCSymbol *Sym = Ctx.getDirectionalLocalSymbol(IntVal, IDVal == "b"); - Res = MCSymbolRefExpr::create(Sym, Spec, getContext()); + Res = MCSymbolRefExpr::create(Sym, Spec, getContext(), Loc); if (IDVal == "b" && Sym->isUndefined()) return Error(Loc, "directional label undefined"); DirLabels.push_back(std::make_tuple(Loc, CppHashInfo, Sym)); diff --git a/llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp b/llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp index e989892b9e056..2ccae27f87a33 100644 --- a/llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp +++ b/llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp @@ -3299,7 +3299,8 @@ ParseStatus AArch64AsmParser::tryParseAdrpLabel(OperandVector &Operands) { if (DarwinSpec == AArch64::S_None && ELFSpec == AArch64::S_INVALID) { // No modifier was specified at all; this is the syntax for an ELF basic // ADRP relocation (unfortunately). - Expr = MCSpecifierExpr::create(Expr, AArch64::S_ABS_PAGE, getContext()); + Expr = + MCSpecifierExpr::create(Expr, AArch64::S_ABS_PAGE, getContext(), S); } else if ((DarwinSpec == AArch64::S_MACHO_GOTPAGE || DarwinSpec == AArch64::S_MACHO_TLVPPAGE) && Addend != 0) { @@ -3351,7 +3352,7 @@ ParseStatus AArch64AsmParser::tryParseAdrLabel(OperandVector &Operands) { if (DarwinSpec == AArch64::S_None && ELFSpec == AArch64::S_INVALID) { // No modifier was specified at all; this is the syntax for an ELF basic // ADR relocation (unfortunately). - Expr = MCSpecifierExpr::create(Expr, AArch64::S_ABS, getContext()); + Expr = MCSpecifierExpr::create(Expr, AArch64::S_ABS, getContext(), S); } else if (ELFSpec != AArch64::S_GOT_AUTH_PAGE) { // For tiny code model, we use :got_auth: operator to fill 21-bit imm of // adr. It's not actually GOT entry page address but the GOT address @@ -4394,7 +4395,7 @@ bool AArch64AsmParser::parseRegister(OperandVector &Operands) { bool AArch64AsmParser::parseSymbolicImmVal(const MCExpr *&ImmVal) { bool HasELFModifier = false; AArch64::Specifier RefKind; - + SMLoc Loc = getLexer().getLoc(); if (parseOptionalToken(AsmToken::Colon)) { HasELFModifier = true; @@ -4468,7 +4469,7 @@ bool AArch64AsmParser::parseSymbolicImmVal(const MCExpr *&ImmVal) { return true; if (HasELFModifier) - ImmVal = MCSpecifierExpr::create(ImmVal, RefKind, getContext()); + ImmVal = MCSpecifierExpr::create(ImmVal, RefKind, getContext(), Loc); SMLoc EndLoc; if (getContext().getAsmInfo()->hasSubsectionsViaSymbols()) { @@ -8211,7 +8212,7 @@ bool AArch64AsmParser::parseDataExpr(const MCExpr *&Res) { const MCExpr *Term; if (getParser().parsePrimaryExpr(Term, EndLoc, nullptr)) return true; - Res = MCBinaryExpr::create(*Opcode, Res, Term, getContext()); + Res = MCBinaryExpr::create(*Opcode, Res, Term, getContext(), Res->getLoc()); } return false; } diff --git a/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp b/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp index a983ea9585226..9410c600cf280 100644 --- a/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp +++ b/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp @@ -2107,7 +2107,7 @@ bool RISCVAsmParser::parseExprWithSpecifier(const MCExpr *&Res, SMLoc &E) { if (getParser().parseParenExpression(SubExpr, E)) return true; - Res = MCSpecifierExpr::create(SubExpr, Spec, getContext()); + Res = MCSpecifierExpr::create(SubExpr, Spec, getContext(), SubExpr->getLoc()); return false; } diff --git a/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZMCCodeEmitter.cpp b/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZMCCodeEmitter.cpp index b161eed95d6e2..3e5e2aca769cb 100644 --- a/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZMCCodeEmitter.cpp +++ b/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZMCCodeEmitter.cpp @@ -203,7 +203,7 @@ SystemZMCCodeEmitter::getPCRelEncoding(const MCInst &MI, unsigned OpNum, // into MI. Add Offset to the relocation value to cancel out // this diff erence. const MCExpr *OffsetExpr = MCConstantExpr::create(Offset, Ctx); - Expr = MCBinaryExpr::createAdd(Expr, OffsetExpr, Ctx); + Expr = MCBinaryExpr::createAdd(Expr, OffsetExpr, Ctx, Loc); } } Fixups.push_back(MCFixup::create(Offset, Expr, (MCFixupKind)Kind, Loc)); diff --git a/llvm/lib/Target/X86/MCTargetDesc/X86MCCodeEmitter.cpp b/llvm/lib/Target/X86/MCTargetDesc/X86MCCodeEmitter.cpp index 8c6f82042eb21..11bd3b0efde3e 100644 --- a/llvm/lib/Target/X86/MCTargetDesc/X86MCCodeEmitter.cpp +++ b/llvm/lib/Target/X86/MCTargetDesc/X86MCCodeEmitter.cpp @@ -603,7 +603,7 @@ void X86MCCodeEmitter::emitImmediate(const MCOperand &DispOp, SMLoc Loc, if (ImmOffset) Expr = MCBinaryExpr::createAdd(Expr, MCConstantExpr::create(ImmOffset, Ctx), - Ctx); + Ctx, Expr->getLoc()); // Emit a symbolic constant as a fixup and 4 zeros. Fixups.push_back(MCFixup::create(static_cast<uint32_t>(CB.size() - StartByte), _______________________________________________ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits