Skip to content

Commit 13bb2f4

Browse files
committed
[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.
1 parent c2692af commit 13bb2f4

File tree

10 files changed

+45
-53
lines changed

10 files changed

+45
-53
lines changed

llvm/include/llvm/MC/MCAsmInfo.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -424,8 +424,8 @@ class MCAsmInfo {
424424
// If true, use Motorola-style integers in Assembly (ex. $0ac).
425425
bool UseMotorolaIntegers = false;
426426

427-
llvm::DenseMap<uint32_t, StringRef> VariantKindToName;
428-
llvm::StringMap<uint32_t> NameToVariantKind;
427+
llvm::DenseMap<uint32_t, StringRef> SpecifierToName;
428+
llvm::StringMap<uint32_t> NameToSpecifier;
429429
void initializeVariantKinds(ArrayRef<VariantKindDesc> Descs);
430430

431431
public:
@@ -708,8 +708,8 @@ class MCAsmInfo {
708708

709709
bool shouldUseMotorolaIntegers() const { return UseMotorolaIntegers; }
710710

711-
StringRef getVariantKindName(uint32_t Kind) const;
712-
std::optional<uint32_t> getVariantKindForName(StringRef Name) const;
711+
StringRef getSpecifierName(uint32_t S) const;
712+
std::optional<uint32_t> getSpecifierForName(StringRef Name) const;
713713
};
714714

715715
} // end namespace llvm

llvm/include/llvm/MC/MCParser/MCTargetAsmParser.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -505,9 +505,8 @@ class MCTargetAsmParser : public MCAsmParserExtension {
505505
// Return whether this parser accept star as start of statement
506506
virtual bool starIsStartOfStatement() { return false; };
507507

508-
virtual const MCExpr *applyModifierToExpr(const MCExpr *E,
509-
MCSymbolRefExpr::VariantKind,
510-
MCContext &Ctx) {
508+
virtual const MCExpr *applySpecifier(const MCExpr *E, uint32_t,
509+
MCContext &Ctx) {
511510
return nullptr;
512511
}
513512

llvm/lib/MC/MCAsmInfo.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -126,28 +126,28 @@ bool MCAsmInfo::shouldOmitSectionDirective(StringRef SectionName) const {
126126
}
127127

128128
void MCAsmInfo::initializeVariantKinds(ArrayRef<VariantKindDesc> Descs) {
129-
assert(VariantKindToName.empty() && "cannot initialize twice");
129+
assert(SpecifierToName.empty() && "cannot initialize twice");
130130
for (auto Desc : Descs) {
131131
[[maybe_unused]] auto It =
132-
VariantKindToName.try_emplace(Desc.Kind, Desc.Name);
132+
SpecifierToName.try_emplace(Desc.Kind, Desc.Name);
133133
assert(It.second && "duplicate Kind");
134134
[[maybe_unused]] auto It2 =
135-
NameToVariantKind.try_emplace(Desc.Name.lower(), Desc.Kind);
135+
NameToSpecifier.try_emplace(Desc.Name.lower(), Desc.Kind);
136136
// Workaround for VK_PPC_L/VK_PPC_LO ("l").
137137
assert(It2.second || Desc.Name == "l");
138138
}
139139
}
140140

141-
StringRef MCAsmInfo::getVariantKindName(uint32_t Kind) const {
142-
auto It = VariantKindToName.find(Kind);
143-
assert(It != VariantKindToName.end() &&
144-
"ensure the VariantKind is set in initializeVariantKinds");
141+
StringRef MCAsmInfo::getSpecifierName(uint32_t S) const {
142+
auto It = SpecifierToName.find(S);
143+
assert(It != SpecifierToName.end() &&
144+
"ensure the specifier is set in initializeVariantKinds");
145145
return It->second;
146146
}
147147

148-
std::optional<uint32_t> MCAsmInfo::getVariantKindForName(StringRef Name) const {
149-
auto It = NameToVariantKind.find(Name.lower());
150-
if (It != NameToVariantKind.end())
148+
std::optional<uint32_t> MCAsmInfo::getSpecifierForName(StringRef Name) const {
149+
auto It = NameToSpecifier.find(Name.lower());
150+
if (It != NameToSpecifier.end())
151151
return It->second;
152152
return {};
153153
}

llvm/lib/MC/MCExpr.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,9 @@ void MCExpr::print(raw_ostream &OS, const MCAsmInfo *MAI, bool InParens) const {
9292
if (!MAI) // should only be used by dump()
9393
OS << "@<variant " << Kind << '>';
9494
else if (MAI->useParensForSymbolVariant()) // ARM
95-
OS << '(' << MAI->getVariantKindName(Kind) << ')';
95+
OS << '(' << MAI->getSpecifierName(Kind) << ')';
9696
else
97-
OS << '@' << MAI->getVariantKindName(Kind);
97+
OS << '@' << MAI->getSpecifierName(Kind);
9898
}
9999

100100
return;

llvm/lib/MC/MCParser/AsmParser.cpp

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -680,8 +680,7 @@ class AsmParser : public MCAsmParser {
680680
bool parseEscapedString(std::string &Data) override;
681681
bool parseAngleBracketString(std::string &Data) override;
682682

683-
const MCExpr *applyModifierToExpr(const MCExpr *E,
684-
MCSymbolRefExpr::VariantKind Variant);
683+
const MCExpr *applySpecifier(const MCExpr *E, uint32_t Variant);
685684

686685
// Macro-like directives
687686
MCAsmMacro *parseMacroLikeBody(SMLoc DirectiveLoc);
@@ -1228,7 +1227,7 @@ bool AsmParser::parsePrimaryExpr(const MCExpr *&Res, SMLoc &EndLoc,
12281227

12291228
// Lookup the symbol variant if used.
12301229
if (!Split.second.empty()) {
1231-
auto MaybeVariant = MAI.getVariantKindForName(Split.second);
1230+
auto MaybeVariant = MAI.getSpecifierForName(Split.second);
12321231
if (MaybeVariant) {
12331232
SymbolName = Split.first;
12341233
Variant = MCSymbolRefExpr::VariantKind(*MaybeVariant);
@@ -1277,18 +1276,18 @@ bool AsmParser::parsePrimaryExpr(const MCExpr *&Res, SMLoc &EndLoc,
12771276
StringRef IDVal = getTok().getString();
12781277
// Lookup the symbol variant if used.
12791278
std::pair<StringRef, StringRef> Split = IDVal.split('@');
1280-
MCSymbolRefExpr::VariantKind Variant = MCSymbolRefExpr::VK_None;
1279+
MCSymbolRefExpr::VariantKind Spec = MCSymbolRefExpr::VK_None;
12811280
if (Split.first.size() != IDVal.size()) {
1282-
auto MaybeVariant = MAI.getVariantKindForName(Split.second);
1283-
if (!MaybeVariant)
1281+
auto MaybeSpec = MAI.getSpecifierForName(Split.second);
1282+
if (!MaybeSpec)
12841283
return TokError("invalid variant '" + Split.second + "'");
12851284
IDVal = Split.first;
1286-
Variant = MCSymbolRefExpr::VariantKind(*MaybeVariant);
1285+
Spec = MCSymbolRefExpr::VariantKind(*MaybeSpec);
12871286
}
12881287
if (IDVal == "f" || IDVal == "b") {
12891288
MCSymbol *Sym =
12901289
Ctx.getDirectionalLocalSymbol(IntVal, IDVal == "b");
1291-
Res = MCSymbolRefExpr::create(Sym, Variant, getContext());
1290+
Res = MCSymbolRefExpr::create(Sym, Spec, getContext());
12921291
if (IDVal == "b" && Sym->isUndefined())
12931292
return Error(Loc, "directional label undefined");
12941293
DirLabels.push_back(std::make_tuple(Loc, CppHashInfo, Sym));
@@ -1353,11 +1352,9 @@ bool AsmParser::parseExpression(const MCExpr *&Res) {
13531352
return parseExpression(Res, EndLoc);
13541353
}
13551354

1356-
const MCExpr *
1357-
AsmParser::applyModifierToExpr(const MCExpr *E,
1358-
MCSymbolRefExpr::VariantKind Variant) {
1355+
const MCExpr *AsmParser::applySpecifier(const MCExpr *E, uint32_t Spec) {
13591356
// Ask the target implementation about this expression first.
1360-
const MCExpr *NewE = getTargetParser().applyModifierToExpr(E, Variant, Ctx);
1357+
const MCExpr *NewE = getTargetParser().applySpecifier(E, Spec, Ctx);
13611358
if (NewE)
13621359
return NewE;
13631360
// Recurse over the given expression, rebuilding it to apply the given variant
@@ -1376,21 +1373,21 @@ AsmParser::applyModifierToExpr(const MCExpr *E,
13761373
return E;
13771374
}
13781375

1379-
return MCSymbolRefExpr::create(&SRE->getSymbol(), Variant, getContext());
1376+
return MCSymbolRefExpr::create(&SRE->getSymbol(), Spec, getContext());
13801377
}
13811378

13821379
case MCExpr::Unary: {
13831380
const MCUnaryExpr *UE = cast<MCUnaryExpr>(E);
1384-
const MCExpr *Sub = applyModifierToExpr(UE->getSubExpr(), Variant);
1381+
const MCExpr *Sub = applySpecifier(UE->getSubExpr(), Spec);
13851382
if (!Sub)
13861383
return nullptr;
13871384
return MCUnaryExpr::create(UE->getOpcode(), Sub, getContext());
13881385
}
13891386

13901387
case MCExpr::Binary: {
13911388
const MCBinaryExpr *BE = cast<MCBinaryExpr>(E);
1392-
const MCExpr *LHS = applyModifierToExpr(BE->getLHS(), Variant);
1393-
const MCExpr *RHS = applyModifierToExpr(BE->getRHS(), Variant);
1389+
const MCExpr *LHS = applySpecifier(BE->getLHS(), Spec);
1390+
const MCExpr *RHS = applySpecifier(BE->getRHS(), Spec);
13941391

13951392
if (!LHS && !RHS)
13961393
return nullptr;
@@ -1470,12 +1467,11 @@ bool AsmParser::parseExpression(const MCExpr *&Res, SMLoc &EndLoc) {
14701467
if (Lexer.isNot(AsmToken::Identifier))
14711468
return TokError("unexpected symbol modifier following '@'");
14721469

1473-
auto Variant = MAI.getVariantKindForName(getTok().getIdentifier());
1474-
if (!Variant)
1470+
auto Spec = MAI.getSpecifierForName(getTok().getIdentifier());
1471+
if (!Spec)
14751472
return TokError("invalid variant '" + getTok().getIdentifier() + "'");
14761473

1477-
const MCExpr *ModifiedRes =
1478-
applyModifierToExpr(Res, MCSymbolRefExpr::VariantKind(*Variant));
1474+
const MCExpr *ModifiedRes = applySpecifier(Res, *Spec);
14791475
if (!ModifiedRes) {
14801476
return TokError("invalid modifier '" + getTok().getIdentifier() +
14811477
"' (no symbols present)");

llvm/lib/Target/PowerPC/AsmParser/PPCAsmParser.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,8 @@ class PPCAsmParser : public MCTargetAsmParser {
155155
unsigned validateTargetOperandClass(MCParsedAsmOperand &Op,
156156
unsigned Kind) override;
157157

158-
const MCExpr *applyModifierToExpr(const MCExpr *E,
159-
MCSymbolRefExpr::VariantKind,
160-
MCContext &Ctx) override;
158+
const MCExpr *applySpecifier(const MCExpr *E, uint32_t,
159+
MCContext &Ctx) override;
161160
};
162161

163162
/// PPCOperand - Instances of this class represent a parsed PowerPC machine
@@ -1848,12 +1847,10 @@ unsigned PPCAsmParser::validateTargetOperandClass(MCParsedAsmOperand &AsmOp,
18481847
return Match_InvalidOperand;
18491848
}
18501849

1851-
const MCExpr *
1852-
PPCAsmParser::applyModifierToExpr(const MCExpr *E,
1853-
MCSymbolRefExpr::VariantKind Variant,
1854-
MCContext &Ctx) {
1850+
const MCExpr *PPCAsmParser::applySpecifier(const MCExpr *E, uint32_t Spec,
1851+
MCContext &Ctx) {
18551852
if (isa<MCConstantExpr>(E)) {
1856-
switch (PPCMCExpr::Specifier(Variant)) {
1853+
switch (PPCMCExpr::Specifier(Spec)) {
18571854
case PPCMCExpr::VK_LO:
18581855
case PPCMCExpr::VK_HI:
18591856
case PPCMCExpr::VK_HA:
@@ -1869,5 +1866,5 @@ PPCAsmParser::applyModifierToExpr(const MCExpr *E,
18691866
}
18701867
}
18711868

1872-
return PPCMCExpr::create(PPCMCExpr::Specifier(Variant), E, Ctx);
1869+
return PPCMCExpr::create(PPCMCExpr::Specifier(Spec), E, Ctx);
18731870
}

llvm/lib/Target/PowerPC/MCTargetDesc/PPCInstPrinter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -581,13 +581,13 @@ void PPCInstPrinter::printTLSCall(const MCInst *MI, unsigned OpNo,
581581
// end like __tls_get_addr(x@tlsgd)@notoc. Instead we want it to look
582582
// like __tls_get_addr@notoc(x@tlsgd).
583583
if (getSpecifier(RefExp) == PPCMCExpr::VK_NOTOC)
584-
O << '@' << MAI.getVariantKindName(RefExp->getKind());
584+
O << '@' << MAI.getSpecifierName(RefExp->getKind());
585585
O << '(';
586586
printOperand(MI, OpNo + 1, STI, O);
587587
O << ')';
588588
if (getSpecifier(RefExp) != PPCMCExpr::VK_None &&
589589
getSpecifier(RefExp) != PPCMCExpr::VK_NOTOC)
590-
O << '@' << MAI.getVariantKindName(RefExp->getKind());
590+
O << '@' << MAI.getSpecifierName(RefExp->getKind());
591591
if (Rhs) {
592592
SmallString<0> Buf;
593593
raw_svector_ostream Tmp(Buf);

llvm/lib/Target/PowerPC/MCTargetDesc/PPCMCExpr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const PPCMCExpr *PPCMCExpr::create(Specifier S, const MCExpr *Expr,
2727

2828
void PPCMCExpr::printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const {
2929
getSubExpr()->print(OS, MAI);
30-
OS << '@' << MAI->getVariantKindName(specifier);
30+
OS << '@' << MAI->getSpecifierName(specifier);
3131
}
3232

3333
bool

llvm/lib/Target/PowerPC/MCTargetDesc/PPCMCTargetDesc.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ class PPCTargetAsmStreamer : public PPCTargetStreamer {
225225
Kind == PPCMCExpr::VK_AIX_TLSIE || Kind == PPCMCExpr::VK_AIX_TLSLE ||
226226
Kind == PPCMCExpr::VK_AIX_TLSLD || Kind == PPCMCExpr::VK_AIX_TLSML)
227227
OS << "\t.tc " << TCSym->getName() << "," << XSym->getName() << "@"
228-
<< getContext().getAsmInfo()->getVariantKindName(Kind) << '\n';
228+
<< getContext().getAsmInfo()->getSpecifierName(Kind) << '\n';
229229
else
230230
OS << "\t.tc " << TCSym->getName() << "," << XSym->getName() << '\n';
231231

llvm/lib/Target/VE/MCTargetDesc/VEMCExpr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ void VEMCExpr::printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const {
3535
const MCExpr *Expr = getSubExpr();
3636
Expr->print(OS, MAI);
3737
if (Kind != VK_None && Kind != VK_REFLONG)
38-
OS << '@' << MAI->getVariantKindName(Kind);
38+
OS << '@' << MAI->getSpecifierName(Kind);
3939
}
4040

4141
VE::Fixups VEMCExpr::getFixupKind(VEMCExpr::Specifier S) {

0 commit comments

Comments
 (0)