[llvm] 5aa3e6b - MC: Reduce MCSymbolRefExpr::VK_None uses
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 27 21:46:42 PDT 2025
Author: Fangrui Song
Date: 2025-06-27T21:46:36-07:00
New Revision: 5aa3e6baa0b07951112cb8782a421c968b39dfb3
URL: https://github.com/llvm/llvm-project/commit/5aa3e6baa0b07951112cb8782a421c968b39dfb3
DIFF: https://github.com/llvm/llvm-project/commit/5aa3e6baa0b07951112cb8782a421c968b39dfb3.diff
LOG: MC: Reduce MCSymbolRefExpr::VK_None uses
Added:
Modified:
llvm/lib/MC/ELFObjectWriter.cpp
llvm/lib/MC/MCAssembler.cpp
llvm/lib/MC/MCExpr.cpp
llvm/lib/MC/MCInst.cpp
llvm/lib/MC/MCParser/AsmParser.cpp
llvm/lib/Target/ARC/MCTargetDesc/ARCInstPrinter.cpp
llvm/lib/Target/AVR/MCTargetDesc/AVRMCAsmInfo.cpp
llvm/lib/Target/Lanai/AsmParser/LanaiAsmParser.cpp
llvm/lib/Target/Mips/AsmParser/MipsAsmParser.cpp
llvm/lib/Target/XCore/MCTargetDesc/XCoreInstPrinter.cpp
Removed:
################################################################################
diff --git a/llvm/lib/MC/ELFObjectWriter.cpp b/llvm/lib/MC/ELFObjectWriter.cpp
index 0b67f79c17f7a..3ee9a5e619df3 100644
--- a/llvm/lib/MC/ELFObjectWriter.cpp
+++ b/llvm/lib/MC/ELFObjectWriter.cpp
@@ -399,8 +399,9 @@ static bool isIFunc(const MCSymbolELF *Symbol) {
const MCSymbolRefExpr *Value;
if (!Symbol->isVariable() ||
!(Value = dyn_cast<MCSymbolRefExpr>(Symbol->getVariableValue())) ||
- Value->getKind() != MCSymbolRefExpr::VK_None ||
- mergeTypeForSet(Symbol->getType(), ELF::STT_GNU_IFUNC) != ELF::STT_GNU_IFUNC)
+ Value->getSpecifier() ||
+ mergeTypeForSet(Symbol->getType(), ELF::STT_GNU_IFUNC) !=
+ ELF::STT_GNU_IFUNC)
return false;
Symbol = &cast<MCSymbolELF>(Value->getSymbol());
}
diff --git a/llvm/lib/MC/MCAssembler.cpp b/llvm/lib/MC/MCAssembler.cpp
index 1866c5b9e0e81..3de3e421ef1ac 100644
--- a/llvm/lib/MC/MCAssembler.cpp
+++ b/llvm/lib/MC/MCAssembler.cpp
@@ -129,7 +129,7 @@ bool MCAssembler::isThumbFunc(const MCSymbol *Symbol) const {
if (!Expr->evaluateAsRelocatable(V, nullptr))
return false;
- if (V.getSubSym() || V.getSpecifier() != MCSymbolRefExpr::VK_None)
+ if (V.getSubSym() || V.getSpecifier())
return false;
auto *Sym = V.getAddSym();
diff --git a/llvm/lib/MC/MCExpr.cpp b/llvm/lib/MC/MCExpr.cpp
index 8919a2627cf6a..aca3ec6bf0a86 100644
--- a/llvm/lib/MC/MCExpr.cpp
+++ b/llvm/lib/MC/MCExpr.cpp
@@ -91,7 +91,7 @@ void MCExpr::print(raw_ostream &OS, const MCAsmInfo *MAI,
Sym.print(OS, MAI);
const MCSymbolRefExpr::VariantKind Kind = SRE.getKind();
- if (Kind != MCSymbolRefExpr::VK_None) {
+ if (Kind) {
if (!MAI) // should only be used by dump()
OS << "@<variant " << Kind << '>';
else if (MAI->useParensForSpecifier()) // ARM
@@ -487,8 +487,7 @@ bool MCExpr::evaluateAsRelocatableImpl(MCValue &Res, const MCAssembler *Asm,
}
return false;
}
- if (Sym.isVariable() && (Kind == MCSymbolRefExpr::VK_None || Layout) &&
- !Sym.isWeakExternal()) {
+ if (Sym.isVariable() && (Kind == 0 || Layout) && !Sym.isWeakExternal()) {
Sym.setIsResolving(true);
auto _ = make_scope_exit([&] { Sym.setIsResolving(false); });
bool IsMachO =
@@ -502,7 +501,7 @@ bool MCExpr::evaluateAsRelocatableImpl(MCValue &Res, const MCAssembler *Asm,
auto *A = Res.getAddSym();
auto *B = Res.getSubSym();
if (InSet || !(A && !B && A->isInSection())) {
- if (Kind != MCSymbolRefExpr::VK_None) {
+ if (Kind) {
if (Res.isAbsolute()) {
Res = MCValue::get(&Sym, nullptr, 0, Kind);
return true;
@@ -510,8 +509,8 @@ bool MCExpr::evaluateAsRelocatableImpl(MCValue &Res, const MCAssembler *Asm,
// If the reference has a variant kind, we can only handle expressions
// which evaluate exactly to a single unadorned symbol. Attach the
// original VariantKind to SymA of the result.
- if (Res.getSpecifier() != MCSymbolRefExpr::VK_None ||
- !Res.getAddSym() || Res.getSubSym() || Res.getConstant())
+ if (Res.getSpecifier() || !Res.getAddSym() || Res.getSubSym() ||
+ Res.getConstant())
return false;
Res.Specifier = Kind;
}
diff --git a/llvm/lib/MC/MCInst.cpp b/llvm/lib/MC/MCInst.cpp
index 832d25060f880..ced41601618a2 100644
--- a/llvm/lib/MC/MCInst.cpp
+++ b/llvm/lib/MC/MCInst.cpp
@@ -62,7 +62,7 @@ bool MCOperand::isBareSymbolRef() const {
const MCExpr *Expr = getExpr();
MCExpr::ExprKind Kind = getExpr()->getKind();
return Kind == MCExpr::SymbolRef &&
- cast<MCSymbolRefExpr>(Expr)->getKind() == MCSymbolRefExpr::VK_None;
+ cast<MCSymbolRefExpr>(Expr)->getSpecifier() == 0;
}
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
diff --git a/llvm/lib/MC/MCParser/AsmParser.cpp b/llvm/lib/MC/MCParser/AsmParser.cpp
index bb8c45bd901cd..3a5cda6e670c9 100644
--- a/llvm/lib/MC/MCParser/AsmParser.cpp
+++ b/llvm/lib/MC/MCParser/AsmParser.cpp
@@ -1353,7 +1353,7 @@ const MCExpr *MCAsmParser::applySpecifier(const MCExpr *E, uint32_t Spec) {
case MCExpr::SymbolRef: {
const MCSymbolRefExpr *SRE = cast<MCSymbolRefExpr>(E);
- if (SRE->getKind() != MCSymbolRefExpr::VK_None) {
+ if (SRE->getSpecifier()) {
TokError("invalid variant on expression '" + getTok().getIdentifier() +
"' (already modified)");
return E;
diff --git a/llvm/lib/Target/ARC/MCTargetDesc/ARCInstPrinter.cpp b/llvm/lib/Target/ARC/MCTargetDesc/ARCInstPrinter.cpp
index e669b9479369d..c54f33cbcb999 100644
--- a/llvm/lib/Target/ARC/MCTargetDesc/ARCInstPrinter.cpp
+++ b/llvm/lib/Target/ARC/MCTargetDesc/ARCInstPrinter.cpp
@@ -124,7 +124,7 @@ static void printExpr(const MCExpr *Expr, const MCAsmInfo *MAI,
SRE = dyn_cast<MCSymbolRefExpr>(Expr);
assert(SRE && "Unexpected MCExpr type.");
}
- assert(SRE->getKind() == MCSymbolRefExpr::VK_None);
+ assert(SRE->getSpecifier() == 0);
// Symbols are prefixed with '@'
OS << '@';
diff --git a/llvm/lib/Target/AVR/MCTargetDesc/AVRMCAsmInfo.cpp b/llvm/lib/Target/AVR/MCTargetDesc/AVRMCAsmInfo.cpp
index cfd7dc5822627..2ba8383e48e80 100644
--- a/llvm/lib/Target/AVR/MCTargetDesc/AVRMCAsmInfo.cpp
+++ b/llvm/lib/Target/AVR/MCTargetDesc/AVRMCAsmInfo.cpp
@@ -195,7 +195,7 @@ bool AVRMCAsmInfo::evaluateAsRelocatableImpl(const MCSpecifierExpr &Expr,
return false;
auto Spec = AVR::S_None;
- if (Value.getSpecifier() != MCSymbolRefExpr::VK_None)
+ if (Value.getSpecifier())
return false;
assert(!Value.getSubSym());
if (E.getSpecifier() == AVR::S_PM)
diff --git a/llvm/lib/Target/Lanai/AsmParser/LanaiAsmParser.cpp b/llvm/lib/Target/Lanai/AsmParser/LanaiAsmParser.cpp
index 6a74686a239d0..a62edffe11397 100644
--- a/llvm/lib/Target/Lanai/AsmParser/LanaiAsmParser.cpp
+++ b/llvm/lib/Target/Lanai/AsmParser/LanaiAsmParser.cpp
@@ -344,7 +344,7 @@ struct LanaiOperand : public MCParsedAsmOperand {
return SymbolRefExpr->getSpecifier() == Lanai::S_None;
if (const MCSymbolRefExpr *SymbolRefExpr =
dyn_cast<MCSymbolRefExpr>(Imm.Value)) {
- return SymbolRefExpr->getKind() == MCSymbolRefExpr::VK_None;
+ return SymbolRefExpr->getSpecifier() == 0;
}
// Binary expression
@@ -354,7 +354,7 @@ struct LanaiOperand : public MCParsedAsmOperand {
return SymbolRefExpr->getSpecifier() == Lanai::S_None;
if (const MCSymbolRefExpr *SymbolRefExpr =
dyn_cast<MCSymbolRefExpr>(BinaryExpr->getLHS()))
- return SymbolRefExpr->getKind() == MCSymbolRefExpr::VK_None;
+ return SymbolRefExpr->getSpecifier() == 0;
}
return false;
@@ -535,8 +535,7 @@ struct LanaiOperand : public MCParsedAsmOperand {
#ifndef NDEBUG
const MCSymbolRefExpr *SymbolRefExpr =
dyn_cast<MCSymbolRefExpr>(getImm());
- assert(SymbolRefExpr &&
- SymbolRefExpr->getKind() == MCSymbolRefExpr::VK_None);
+ assert(SymbolRefExpr && SymbolRefExpr->getSpecifier() == 0);
#endif
Inst.addOperand(MCOperand::createExpr(getImm()));
} else if (isa<MCBinaryExpr>(getImm())) {
diff --git a/llvm/lib/Target/Mips/AsmParser/MipsAsmParser.cpp b/llvm/lib/Target/Mips/AsmParser/MipsAsmParser.cpp
index b559a8b896e0f..cf4b55466a359 100644
--- a/llvm/lib/Target/Mips/AsmParser/MipsAsmParser.cpp
+++ b/llvm/lib/Target/Mips/AsmParser/MipsAsmParser.cpp
@@ -1774,7 +1774,7 @@ static bool isEvaluated(const MCExpr *Expr) {
case MCExpr::Constant:
return true;
case MCExpr::SymbolRef:
- return (cast<MCSymbolRefExpr>(Expr)->getKind() != MCSymbolRefExpr::VK_None);
+ return (cast<MCSymbolRefExpr>(Expr)->getSpecifier());
case MCExpr::Binary: {
const MCBinaryExpr *BE = cast<MCBinaryExpr>(Expr);
if (!isEvaluated(BE->getLHS()))
@@ -1817,7 +1817,7 @@ static bool needsExpandMemInst(MCInst &Inst, const MCInstrDesc &MCID) {
// Expand symbol.
const MCSymbolRefExpr *SR = static_cast<const MCSymbolRefExpr *>(Expr);
- return SR->getKind() == MCSymbolRefExpr::VK_None;
+ return SR->getSpecifier() == 0;
}
return false;
diff --git a/llvm/lib/Target/XCore/MCTargetDesc/XCoreInstPrinter.cpp b/llvm/lib/Target/XCore/MCTargetDesc/XCoreInstPrinter.cpp
index 707c4a7908728..dfd138b99ce0d 100644
--- a/llvm/lib/Target/XCore/MCTargetDesc/XCoreInstPrinter.cpp
+++ b/llvm/lib/Target/XCore/MCTargetDesc/XCoreInstPrinter.cpp
@@ -62,7 +62,7 @@ static void printExpr(const MCExpr *Expr, const MCAsmInfo *MAI,
SRE = dyn_cast<MCSymbolRefExpr>(Expr);
assert(SRE && "Unexpected MCExpr type.");
}
- assert(SRE->getKind() == MCSymbolRefExpr::VK_None);
+ assert(SRE->getSpecifier() == 0);
SRE->getSymbol().print(OS, MAI);
More information about the llvm-commits
mailing list