Skip to content

Commit 04b49b1

Browse files
committed
[MCExpr] Remove generic getVariantKindName and getVariantKindForName
They are error-prone as MCParser may parse a variant kind, which cannot be handled by the target. The replacement in MCAsmInfo should be used instead. Follow-up to f244b8e
1 parent 69c8312 commit 04b49b1

File tree

5 files changed

+10
-96
lines changed

5 files changed

+10
-96
lines changed

llvm/include/llvm/MC/MCExpr.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -418,14 +418,6 @@ class MCSymbolRefExpr : public MCExpr {
418418
return (getSubclassData() & HasSubsectionsViaSymbolsBit) != 0;
419419
}
420420

421-
/// @}
422-
/// \name Static Utility Functions
423-
/// @{
424-
425-
static StringRef getVariantKindName(VariantKind Kind);
426-
427-
static VariantKind getVariantKindForName(StringRef Name);
428-
429421
/// @}
430422

431423
static bool classof(const MCExpr *E) {

llvm/lib/MC/MCAsmInfo.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -140,15 +140,13 @@ void MCAsmInfo::initializeVariantKinds(ArrayRef<VariantKindDesc> Descs) {
140140
}
141141

142142
StringRef MCAsmInfo::getVariantKindName(uint32_t Kind) const {
143-
if (!VariantKindToName.empty())
144-
return VariantKindToName.find(Kind)->second;
145-
return MCSymbolRefExpr::getVariantKindName(
146-
MCSymbolRefExpr::VariantKind(Kind));
143+
auto It = VariantKindToName.find(Kind);
144+
assert(It != VariantKindToName.end() &&
145+
"ensure the VariantKind is set in initializeVariantKinds");
146+
return It->second;
147147
}
148148

149149
uint32_t MCAsmInfo::getVariantKindForName(StringRef Name) const {
150-
if (NameToVariantKind.empty())
151-
return MCSymbolRefExpr::getVariantKindForName(Name);
152150
auto It = NameToVariantKind.find(Name.lower());
153151
if (It != NameToVariantKind.end())
154152
return It->second;

llvm/lib/MC/MCExpr.cpp

Lines changed: 2 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,10 @@ void MCExpr::print(raw_ostream &OS, const MCAsmInfo *MAI, bool InParens) const {
8686

8787
const MCSymbolRefExpr::VariantKind Kind = SRE.getKind();
8888
if (Kind != MCSymbolRefExpr::VK_None) {
89-
if (MAI && MAI->useParensForSymbolVariant()) // ARM
89+
if (MAI->useParensForSymbolVariant()) // ARM
9090
OS << '(' << MAI->getVariantKindName(Kind) << ')';
91-
else if (MAI)
92-
OS << '@' << MAI->getVariantKindName(Kind);
9391
else
94-
OS << '@' << MCSymbolRefExpr::getVariantKindName(Kind);
92+
OS << '@' << MAI->getVariantKindName(Kind);
9593
}
9694

9795
return;
@@ -248,84 +246,6 @@ const MCSymbolRefExpr *MCSymbolRefExpr::create(StringRef Name, VariantKind Kind,
248246
return create(Ctx.getOrCreateSymbol(Name), Kind, Ctx);
249247
}
250248

251-
// TODO: Move target-specific Kinds to lib/Target/*/MCTargetDesc/*AsmInfo.cpp.
252-
StringRef MCSymbolRefExpr::getVariantKindName(VariantKind Kind) {
253-
switch (Kind) {
254-
// clang-format off
255-
case VK_Invalid: default: return "<<invalid>>";
256-
case VK_None: return "<<none>>";
257-
258-
case VK_DTPOFF: return "DTPOFF";
259-
case VK_DTPREL: return "DTPREL";
260-
case VK_GOT: return "GOT";
261-
case VK_GOTENT: return "GOTENT";
262-
case VK_GOTOFF: return "GOTOFF";
263-
case VK_GOTREL: return "GOTREL";
264-
case VK_PCREL: return "PCREL";
265-
case VK_GOTPCREL: return "GOTPCREL";
266-
case VK_GOTTPOFF: return "GOTTPOFF";
267-
case VK_INDNTPOFF: return "INDNTPOFF";
268-
case VK_NTPOFF: return "NTPOFF";
269-
case VK_GOTNTPOFF: return "GOTNTPOFF";
270-
case VK_PLT: return "PLT";
271-
case VK_TLSGD: return "TLSGD";
272-
case VK_TLSLD: return "TLSLD";
273-
case VK_TLSLDM: return "TLSLDM";
274-
case VK_TPOFF: return "TPOFF";
275-
case VK_TPREL: return "TPREL";
276-
case VK_TLSCALL: return "tlscall";
277-
case VK_TLSDESC: return "tlsdesc";
278-
case VK_TLVP: return "TLVP";
279-
case VK_TLVPPAGE: return "TLVPPAGE";
280-
case VK_TLVPPAGEOFF: return "TLVPPAGEOFF";
281-
case VK_PAGE: return "PAGE";
282-
case VK_PAGEOFF: return "PAGEOFF";
283-
case VK_GOTPAGE: return "GOTPAGE";
284-
case VK_GOTPAGEOFF: return "GOTPAGEOFF";
285-
case VK_SECREL: return "SECREL32";
286-
case VK_WEAKREF: return "WEAKREF";
287-
case VK_COFF_IMGREL32: return "IMGREL";
288-
// clang-format on
289-
}
290-
llvm_unreachable("Invalid variant kind");
291-
}
292-
293-
// FIXME: All variant kinds are target-specific. Move them to
294-
// *AsmParser::getVariantKindForName and remove this function.
295-
MCSymbolRefExpr::VariantKind
296-
MCSymbolRefExpr::getVariantKindForName(StringRef Name) {
297-
return StringSwitch<VariantKind>(Name.lower())
298-
.Case("dtprel", VK_DTPREL)
299-
.Case("dtpoff", VK_DTPOFF)
300-
.Case("got", VK_GOT)
301-
.Case("gotent", VK_GOTENT)
302-
.Case("gotoff", VK_GOTOFF)
303-
.Case("gotrel", VK_GOTREL)
304-
.Case("pcrel", VK_PCREL)
305-
.Case("gotpcrel", VK_GOTPCREL)
306-
.Case("gottpoff", VK_GOTTPOFF)
307-
.Case("indntpoff", VK_INDNTPOFF)
308-
.Case("ntpoff", VK_NTPOFF)
309-
.Case("plt", VK_PLT)
310-
.Case("tlscall", VK_TLSCALL)
311-
.Case("tlsdesc", VK_TLSDESC)
312-
.Case("tlsgd", VK_TLSGD)
313-
.Case("tlsld", VK_TLSLD)
314-
.Case("tlsldm", VK_TLSLDM)
315-
.Case("tpoff", VK_TPOFF)
316-
.Case("tprel", VK_TPREL)
317-
.Case("tlvp", VK_TLVP)
318-
.Case("tlvppage", VK_TLVPPAGE)
319-
.Case("tlvppageoff", VK_TLVPPAGEOFF)
320-
.Case("page", VK_PAGE)
321-
.Case("pageoff", VK_PAGEOFF)
322-
.Case("gotpage", VK_GOTPAGE)
323-
.Case("gotpageoff", VK_GOTPAGEOFF)
324-
.Case("imgrel", VK_COFF_IMGREL32)
325-
.Case("secrel32", VK_SECREL)
326-
.Default(VK_Invalid);
327-
}
328-
329249
/* *** */
330250

331251
void MCTargetExpr::anchor() {}

llvm/lib/Target/ARM/MCTargetDesc/ARMMCAsmInfo.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ ARMCOFFMCAsmInfoMicrosoft::ARMCOFFMCAsmInfoMicrosoft() {
129129

130130
// Conditional Thumb 4-byte instructions can have an implicit IT.
131131
MaxInstLength = 6;
132+
133+
initializeVariantKinds(variantKindDescs);
132134
}
133135

134136
void ARMCOFFMCAsmInfoGNU::anchor() { }

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ SystemZMCAsmInfoGOFF::SystemZMCAsmInfoGOFF(const Triple &TT) {
5353
IsLittleEndian = false;
5454
MaxInstLength = 6;
5555
SupportsDebugInformation = true;
56+
57+
initializeVariantKinds(variantKindDescs);
5658
}
5759

5860
bool SystemZMCAsmInfoGOFF::isAcceptableChar(char C) const {

0 commit comments

Comments
 (0)