[llvm] 13bb2f4 - [MC] Rename some VariantKind functions to use Specifier
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 20 22:06:21 PDT 2025
Author: Fangrui Song
Date: 2025-03-20T22:06:16-07:00
New Revision: 13bb2f450ef9f64f393fe5527e5ac68362af8ccd
URL: https://github.com/llvm/llvm-project/commit/13bb2f450ef9f64f393fe5527e5ac68362af8ccd
DIFF: https://github.com/llvm/llvm-project/commit/13bb2f450ef9f64f393fe5527e5ac68362af8ccd.diff
LOG: [MC] Rename some VariantKind functions to use Specifier
Use the more appropriate term "relocation specifier" and avoid the
variable name `Kind`, which conflicts with MCExpr and FixupKind.
Added:
Modified:
llvm/include/llvm/MC/MCAsmInfo.h
llvm/include/llvm/MC/MCParser/MCTargetAsmParser.h
llvm/lib/MC/MCAsmInfo.cpp
llvm/lib/MC/MCExpr.cpp
llvm/lib/MC/MCParser/AsmParser.cpp
llvm/lib/Target/PowerPC/AsmParser/PPCAsmParser.cpp
llvm/lib/Target/PowerPC/MCTargetDesc/PPCInstPrinter.cpp
llvm/lib/Target/PowerPC/MCTargetDesc/PPCMCExpr.cpp
llvm/lib/Target/PowerPC/MCTargetDesc/PPCMCTargetDesc.cpp
llvm/lib/Target/VE/MCTargetDesc/VEMCExpr.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/MC/MCAsmInfo.h b/llvm/include/llvm/MC/MCAsmInfo.h
index 7f03097eba060..d7beebf614516 100644
--- a/llvm/include/llvm/MC/MCAsmInfo.h
+++ b/llvm/include/llvm/MC/MCAsmInfo.h
@@ -424,8 +424,8 @@ class MCAsmInfo {
// If true, use Motorola-style integers in Assembly (ex. $0ac).
bool UseMotorolaIntegers = false;
- llvm::DenseMap<uint32_t, StringRef> VariantKindToName;
- llvm::StringMap<uint32_t> NameToVariantKind;
+ llvm::DenseMap<uint32_t, StringRef> SpecifierToName;
+ llvm::StringMap<uint32_t> NameToSpecifier;
void initializeVariantKinds(ArrayRef<VariantKindDesc> Descs);
public:
@@ -708,8 +708,8 @@ class MCAsmInfo {
bool shouldUseMotorolaIntegers() const { return UseMotorolaIntegers; }
- StringRef getVariantKindName(uint32_t Kind) const;
- std::optional<uint32_t> getVariantKindForName(StringRef Name) const;
+ StringRef getSpecifierName(uint32_t S) const;
+ std::optional<uint32_t> getSpecifierForName(StringRef Name) const;
};
} // end namespace llvm
diff --git a/llvm/include/llvm/MC/MCParser/MCTargetAsmParser.h b/llvm/include/llvm/MC/MCParser/MCTargetAsmParser.h
index 536c7a42bab59..59cee18bfdf42 100644
--- a/llvm/include/llvm/MC/MCParser/MCTargetAsmParser.h
+++ b/llvm/include/llvm/MC/MCParser/MCTargetAsmParser.h
@@ -505,9 +505,8 @@ class MCTargetAsmParser : public MCAsmParserExtension {
// Return whether this parser accept star as start of statement
virtual bool starIsStartOfStatement() { return false; };
- virtual const MCExpr *applyModifierToExpr(const MCExpr *E,
- MCSymbolRefExpr::VariantKind,
- MCContext &Ctx) {
+ virtual const MCExpr *applySpecifier(const MCExpr *E, uint32_t,
+ MCContext &Ctx) {
return nullptr;
}
diff --git a/llvm/lib/MC/MCAsmInfo.cpp b/llvm/lib/MC/MCAsmInfo.cpp
index 69374f69bc8e5..49e8db209102b 100644
--- a/llvm/lib/MC/MCAsmInfo.cpp
+++ b/llvm/lib/MC/MCAsmInfo.cpp
@@ -126,28 +126,28 @@ bool MCAsmInfo::shouldOmitSectionDirective(StringRef SectionName) const {
}
void MCAsmInfo::initializeVariantKinds(ArrayRef<VariantKindDesc> Descs) {
- assert(VariantKindToName.empty() && "cannot initialize twice");
+ assert(SpecifierToName.empty() && "cannot initialize twice");
for (auto Desc : Descs) {
[[maybe_unused]] auto It =
- VariantKindToName.try_emplace(Desc.Kind, Desc.Name);
+ SpecifierToName.try_emplace(Desc.Kind, Desc.Name);
assert(It.second && "duplicate Kind");
[[maybe_unused]] auto It2 =
- NameToVariantKind.try_emplace(Desc.Name.lower(), Desc.Kind);
+ NameToSpecifier.try_emplace(Desc.Name.lower(), Desc.Kind);
// Workaround for VK_PPC_L/VK_PPC_LO ("l").
assert(It2.second || Desc.Name == "l");
}
}
-StringRef MCAsmInfo::getVariantKindName(uint32_t Kind) const {
- auto It = VariantKindToName.find(Kind);
- assert(It != VariantKindToName.end() &&
- "ensure the VariantKind is set in initializeVariantKinds");
+StringRef MCAsmInfo::getSpecifierName(uint32_t S) const {
+ auto It = SpecifierToName.find(S);
+ assert(It != SpecifierToName.end() &&
+ "ensure the specifier is set in initializeVariantKinds");
return It->second;
}
-std::optional<uint32_t> MCAsmInfo::getVariantKindForName(StringRef Name) const {
- auto It = NameToVariantKind.find(Name.lower());
- if (It != NameToVariantKind.end())
+std::optional<uint32_t> MCAsmInfo::getSpecifierForName(StringRef Name) const {
+ auto It = NameToSpecifier.find(Name.lower());
+ if (It != NameToSpecifier.end())
return It->second;
return {};
}
diff --git a/llvm/lib/MC/MCExpr.cpp b/llvm/lib/MC/MCExpr.cpp
index 4f27b609801d6..db3d2c068d99b 100644
--- a/llvm/lib/MC/MCExpr.cpp
+++ b/llvm/lib/MC/MCExpr.cpp
@@ -92,9 +92,9 @@ void MCExpr::print(raw_ostream &OS, const MCAsmInfo *MAI, bool InParens) const {
if (!MAI) // should only be used by dump()
OS << "@<variant " << Kind << '>';
else if (MAI->useParensForSymbolVariant()) // ARM
- OS << '(' << MAI->getVariantKindName(Kind) << ')';
+ OS << '(' << MAI->getSpecifierName(Kind) << ')';
else
- OS << '@' << MAI->getVariantKindName(Kind);
+ OS << '@' << MAI->getSpecifierName(Kind);
}
return;
diff --git a/llvm/lib/MC/MCParser/AsmParser.cpp b/llvm/lib/MC/MCParser/AsmParser.cpp
index 9fb89789c51be..c11c01e52fc2e 100644
--- a/llvm/lib/MC/MCParser/AsmParser.cpp
+++ b/llvm/lib/MC/MCParser/AsmParser.cpp
@@ -680,8 +680,7 @@ class AsmParser : public MCAsmParser {
bool parseEscapedString(std::string &Data) override;
bool parseAngleBracketString(std::string &Data) override;
- const MCExpr *applyModifierToExpr(const MCExpr *E,
- MCSymbolRefExpr::VariantKind Variant);
+ const MCExpr *applySpecifier(const MCExpr *E, uint32_t Variant);
// Macro-like directives
MCAsmMacro *parseMacroLikeBody(SMLoc DirectiveLoc);
@@ -1228,7 +1227,7 @@ bool AsmParser::parsePrimaryExpr(const MCExpr *&Res, SMLoc &EndLoc,
// Lookup the symbol variant if used.
if (!Split.second.empty()) {
- auto MaybeVariant = MAI.getVariantKindForName(Split.second);
+ auto MaybeVariant = MAI.getSpecifierForName(Split.second);
if (MaybeVariant) {
SymbolName = Split.first;
Variant = MCSymbolRefExpr::VariantKind(*MaybeVariant);
@@ -1277,18 +1276,18 @@ bool AsmParser::parsePrimaryExpr(const MCExpr *&Res, SMLoc &EndLoc,
StringRef IDVal = getTok().getString();
// Lookup the symbol variant if used.
std::pair<StringRef, StringRef> Split = IDVal.split('@');
- MCSymbolRefExpr::VariantKind Variant = MCSymbolRefExpr::VK_None;
+ MCSymbolRefExpr::VariantKind Spec = MCSymbolRefExpr::VK_None;
if (Split.first.size() != IDVal.size()) {
- auto MaybeVariant = MAI.getVariantKindForName(Split.second);
- if (!MaybeVariant)
+ auto MaybeSpec = MAI.getSpecifierForName(Split.second);
+ if (!MaybeSpec)
return TokError("invalid variant '" + Split.second + "'");
IDVal = Split.first;
- Variant = MCSymbolRefExpr::VariantKind(*MaybeVariant);
+ Spec = MCSymbolRefExpr::VariantKind(*MaybeSpec);
}
if (IDVal == "f" || IDVal == "b") {
MCSymbol *Sym =
Ctx.getDirectionalLocalSymbol(IntVal, IDVal == "b");
- Res = MCSymbolRefExpr::create(Sym, Variant, getContext());
+ Res = MCSymbolRefExpr::create(Sym, Spec, getContext());
if (IDVal == "b" && Sym->isUndefined())
return Error(Loc, "directional label undefined");
DirLabels.push_back(std::make_tuple(Loc, CppHashInfo, Sym));
@@ -1353,11 +1352,9 @@ bool AsmParser::parseExpression(const MCExpr *&Res) {
return parseExpression(Res, EndLoc);
}
-const MCExpr *
-AsmParser::applyModifierToExpr(const MCExpr *E,
- MCSymbolRefExpr::VariantKind Variant) {
+const MCExpr *AsmParser::applySpecifier(const MCExpr *E, uint32_t Spec) {
// Ask the target implementation about this expression first.
- const MCExpr *NewE = getTargetParser().applyModifierToExpr(E, Variant, Ctx);
+ const MCExpr *NewE = getTargetParser().applySpecifier(E, Spec, Ctx);
if (NewE)
return NewE;
// Recurse over the given expression, rebuilding it to apply the given variant
@@ -1376,12 +1373,12 @@ AsmParser::applyModifierToExpr(const MCExpr *E,
return E;
}
- return MCSymbolRefExpr::create(&SRE->getSymbol(), Variant, getContext());
+ return MCSymbolRefExpr::create(&SRE->getSymbol(), Spec, getContext());
}
case MCExpr::Unary: {
const MCUnaryExpr *UE = cast<MCUnaryExpr>(E);
- const MCExpr *Sub = applyModifierToExpr(UE->getSubExpr(), Variant);
+ const MCExpr *Sub = applySpecifier(UE->getSubExpr(), Spec);
if (!Sub)
return nullptr;
return MCUnaryExpr::create(UE->getOpcode(), Sub, getContext());
@@ -1389,8 +1386,8 @@ AsmParser::applyModifierToExpr(const MCExpr *E,
case MCExpr::Binary: {
const MCBinaryExpr *BE = cast<MCBinaryExpr>(E);
- const MCExpr *LHS = applyModifierToExpr(BE->getLHS(), Variant);
- const MCExpr *RHS = applyModifierToExpr(BE->getRHS(), Variant);
+ const MCExpr *LHS = applySpecifier(BE->getLHS(), Spec);
+ const MCExpr *RHS = applySpecifier(BE->getRHS(), Spec);
if (!LHS && !RHS)
return nullptr;
@@ -1470,12 +1467,11 @@ bool AsmParser::parseExpression(const MCExpr *&Res, SMLoc &EndLoc) {
if (Lexer.isNot(AsmToken::Identifier))
return TokError("unexpected symbol modifier following '@'");
- auto Variant = MAI.getVariantKindForName(getTok().getIdentifier());
- if (!Variant)
+ auto Spec = MAI.getSpecifierForName(getTok().getIdentifier());
+ if (!Spec)
return TokError("invalid variant '" + getTok().getIdentifier() + "'");
- const MCExpr *ModifiedRes =
- applyModifierToExpr(Res, MCSymbolRefExpr::VariantKind(*Variant));
+ const MCExpr *ModifiedRes = applySpecifier(Res, *Spec);
if (!ModifiedRes) {
return TokError("invalid modifier '" + getTok().getIdentifier() +
"' (no symbols present)");
diff --git a/llvm/lib/Target/PowerPC/AsmParser/PPCAsmParser.cpp b/llvm/lib/Target/PowerPC/AsmParser/PPCAsmParser.cpp
index 28abe1a4d47b6..f4b67a6134542 100644
--- a/llvm/lib/Target/PowerPC/AsmParser/PPCAsmParser.cpp
+++ b/llvm/lib/Target/PowerPC/AsmParser/PPCAsmParser.cpp
@@ -155,9 +155,8 @@ class PPCAsmParser : public MCTargetAsmParser {
unsigned validateTargetOperandClass(MCParsedAsmOperand &Op,
unsigned Kind) override;
- const MCExpr *applyModifierToExpr(const MCExpr *E,
- MCSymbolRefExpr::VariantKind,
- MCContext &Ctx) override;
+ const MCExpr *applySpecifier(const MCExpr *E, uint32_t,
+ MCContext &Ctx) override;
};
/// PPCOperand - Instances of this class represent a parsed PowerPC machine
@@ -1848,12 +1847,10 @@ unsigned PPCAsmParser::validateTargetOperandClass(MCParsedAsmOperand &AsmOp,
return Match_InvalidOperand;
}
-const MCExpr *
-PPCAsmParser::applyModifierToExpr(const MCExpr *E,
- MCSymbolRefExpr::VariantKind Variant,
- MCContext &Ctx) {
+const MCExpr *PPCAsmParser::applySpecifier(const MCExpr *E, uint32_t Spec,
+ MCContext &Ctx) {
if (isa<MCConstantExpr>(E)) {
- switch (PPCMCExpr::Specifier(Variant)) {
+ switch (PPCMCExpr::Specifier(Spec)) {
case PPCMCExpr::VK_LO:
case PPCMCExpr::VK_HI:
case PPCMCExpr::VK_HA:
@@ -1869,5 +1866,5 @@ PPCAsmParser::applyModifierToExpr(const MCExpr *E,
}
}
- return PPCMCExpr::create(PPCMCExpr::Specifier(Variant), E, Ctx);
+ return PPCMCExpr::create(PPCMCExpr::Specifier(Spec), E, Ctx);
}
diff --git a/llvm/lib/Target/PowerPC/MCTargetDesc/PPCInstPrinter.cpp b/llvm/lib/Target/PowerPC/MCTargetDesc/PPCInstPrinter.cpp
index 55b427646f6e6..ee4a7009535c7 100644
--- a/llvm/lib/Target/PowerPC/MCTargetDesc/PPCInstPrinter.cpp
+++ b/llvm/lib/Target/PowerPC/MCTargetDesc/PPCInstPrinter.cpp
@@ -581,13 +581,13 @@ void PPCInstPrinter::printTLSCall(const MCInst *MI, unsigned OpNo,
// end like __tls_get_addr(x at tlsgd)@notoc. Instead we want it to look
// like __tls_get_addr at notoc(x at tlsgd).
if (getSpecifier(RefExp) == PPCMCExpr::VK_NOTOC)
- O << '@' << MAI.getVariantKindName(RefExp->getKind());
+ O << '@' << MAI.getSpecifierName(RefExp->getKind());
O << '(';
printOperand(MI, OpNo + 1, STI, O);
O << ')';
if (getSpecifier(RefExp) != PPCMCExpr::VK_None &&
getSpecifier(RefExp) != PPCMCExpr::VK_NOTOC)
- O << '@' << MAI.getVariantKindName(RefExp->getKind());
+ O << '@' << MAI.getSpecifierName(RefExp->getKind());
if (Rhs) {
SmallString<0> Buf;
raw_svector_ostream Tmp(Buf);
diff --git a/llvm/lib/Target/PowerPC/MCTargetDesc/PPCMCExpr.cpp b/llvm/lib/Target/PowerPC/MCTargetDesc/PPCMCExpr.cpp
index 8b82bf14acf83..1df93567d3708 100644
--- a/llvm/lib/Target/PowerPC/MCTargetDesc/PPCMCExpr.cpp
+++ b/llvm/lib/Target/PowerPC/MCTargetDesc/PPCMCExpr.cpp
@@ -27,7 +27,7 @@ const PPCMCExpr *PPCMCExpr::create(Specifier S, const MCExpr *Expr,
void PPCMCExpr::printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const {
getSubExpr()->print(OS, MAI);
- OS << '@' << MAI->getVariantKindName(specifier);
+ OS << '@' << MAI->getSpecifierName(specifier);
}
bool
diff --git a/llvm/lib/Target/PowerPC/MCTargetDesc/PPCMCTargetDesc.cpp b/llvm/lib/Target/PowerPC/MCTargetDesc/PPCMCTargetDesc.cpp
index a51d656b5842f..03a034182ae15 100644
--- a/llvm/lib/Target/PowerPC/MCTargetDesc/PPCMCTargetDesc.cpp
+++ b/llvm/lib/Target/PowerPC/MCTargetDesc/PPCMCTargetDesc.cpp
@@ -225,7 +225,7 @@ class PPCTargetAsmStreamer : public PPCTargetStreamer {
Kind == PPCMCExpr::VK_AIX_TLSIE || Kind == PPCMCExpr::VK_AIX_TLSLE ||
Kind == PPCMCExpr::VK_AIX_TLSLD || Kind == PPCMCExpr::VK_AIX_TLSML)
OS << "\t.tc " << TCSym->getName() << "," << XSym->getName() << "@"
- << getContext().getAsmInfo()->getVariantKindName(Kind) << '\n';
+ << getContext().getAsmInfo()->getSpecifierName(Kind) << '\n';
else
OS << "\t.tc " << TCSym->getName() << "," << XSym->getName() << '\n';
diff --git a/llvm/lib/Target/VE/MCTargetDesc/VEMCExpr.cpp b/llvm/lib/Target/VE/MCTargetDesc/VEMCExpr.cpp
index 429e3a9f0e83f..17d541bd67599 100644
--- a/llvm/lib/Target/VE/MCTargetDesc/VEMCExpr.cpp
+++ b/llvm/lib/Target/VE/MCTargetDesc/VEMCExpr.cpp
@@ -35,7 +35,7 @@ void VEMCExpr::printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const {
const MCExpr *Expr = getSubExpr();
Expr->print(OS, MAI);
if (Kind != VK_None && Kind != VK_REFLONG)
- OS << '@' << MAI->getVariantKindName(Kind);
+ OS << '@' << MAI->getSpecifierName(Kind);
}
VE::Fixups VEMCExpr::getFixupKind(VEMCExpr::Specifier S) {
More information about the llvm-commits
mailing list