diff options
author | Fangrui Song <i@maskray.me> | 2025-03-02 22:05:47 -0800 |
---|---|---|
committer | Fangrui Song <i@maskray.me> | 2025-03-02 22:05:47 -0800 |
commit | 04b49b11a8f70424263a3fc1f9c5bc69a9f46844 (patch) | |
tree | 6af27cd92d89a191e3a70b944488fd5a254739ec /llvm/lib | |
parent | 69c8312c0ab30e0906a374ecfc88c60ea7ffe5a4 (diff) | |
download | llvm-04b49b11a8f70424263a3fc1f9c5bc69a9f46844.zip llvm-04b49b11a8f70424263a3fc1f9c5bc69a9f46844.tar.gz llvm-04b49b11a8f70424263a3fc1f9c5bc69a9f46844.tar.bz2 |
[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 f244b8eed37a12539fb11b76e19ec7a7eb41dccc
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/MC/MCAsmInfo.cpp | 10 | ||||
-rw-r--r-- | llvm/lib/MC/MCExpr.cpp | 84 | ||||
-rw-r--r-- | llvm/lib/Target/ARM/MCTargetDesc/ARMMCAsmInfo.cpp | 2 | ||||
-rw-r--r-- | llvm/lib/Target/SystemZ/MCTargetDesc/SystemZMCAsmInfo.cpp | 2 |
4 files changed, 10 insertions, 88 deletions
diff --git a/llvm/lib/MC/MCAsmInfo.cpp b/llvm/lib/MC/MCAsmInfo.cpp index 2ad411d..f7270e8 100644 --- a/llvm/lib/MC/MCAsmInfo.cpp +++ b/llvm/lib/MC/MCAsmInfo.cpp @@ -140,15 +140,13 @@ void MCAsmInfo::initializeVariantKinds(ArrayRef<VariantKindDesc> Descs) { } StringRef MCAsmInfo::getVariantKindName(uint32_t Kind) const { - if (!VariantKindToName.empty()) - return VariantKindToName.find(Kind)->second; - return MCSymbolRefExpr::getVariantKindName( - MCSymbolRefExpr::VariantKind(Kind)); + auto It = VariantKindToName.find(Kind); + assert(It != VariantKindToName.end() && + "ensure the VariantKind is set in initializeVariantKinds"); + return It->second; } uint32_t MCAsmInfo::getVariantKindForName(StringRef Name) const { - if (NameToVariantKind.empty()) - return MCSymbolRefExpr::getVariantKindForName(Name); auto It = NameToVariantKind.find(Name.lower()); if (It != NameToVariantKind.end()) return It->second; diff --git a/llvm/lib/MC/MCExpr.cpp b/llvm/lib/MC/MCExpr.cpp index 2cbb26cb..90536dc 100644 --- a/llvm/lib/MC/MCExpr.cpp +++ b/llvm/lib/MC/MCExpr.cpp @@ -86,12 +86,10 @@ void MCExpr::print(raw_ostream &OS, const MCAsmInfo *MAI, bool InParens) const { const MCSymbolRefExpr::VariantKind Kind = SRE.getKind(); if (Kind != MCSymbolRefExpr::VK_None) { - if (MAI && MAI->useParensForSymbolVariant()) // ARM + if (MAI->useParensForSymbolVariant()) // ARM OS << '(' << MAI->getVariantKindName(Kind) << ')'; - else if (MAI) - OS << '@' << MAI->getVariantKindName(Kind); else - OS << '@' << MCSymbolRefExpr::getVariantKindName(Kind); + OS << '@' << MAI->getVariantKindName(Kind); } return; @@ -248,84 +246,6 @@ const MCSymbolRefExpr *MCSymbolRefExpr::create(StringRef Name, VariantKind Kind, return create(Ctx.getOrCreateSymbol(Name), Kind, Ctx); } -// TODO: Move target-specific Kinds to lib/Target/*/MCTargetDesc/*AsmInfo.cpp. -StringRef MCSymbolRefExpr::getVariantKindName(VariantKind Kind) { - switch (Kind) { - // clang-format off - case VK_Invalid: default: return "<<invalid>>"; - case VK_None: return "<<none>>"; - - case VK_DTPOFF: return "DTPOFF"; - case VK_DTPREL: return "DTPREL"; - case VK_GOT: return "GOT"; - case VK_GOTENT: return "GOTENT"; - case VK_GOTOFF: return "GOTOFF"; - case VK_GOTREL: return "GOTREL"; - case VK_PCREL: return "PCREL"; - case VK_GOTPCREL: return "GOTPCREL"; - case VK_GOTTPOFF: return "GOTTPOFF"; - case VK_INDNTPOFF: return "INDNTPOFF"; - case VK_NTPOFF: return "NTPOFF"; - case VK_GOTNTPOFF: return "GOTNTPOFF"; - case VK_PLT: return "PLT"; - case VK_TLSGD: return "TLSGD"; - case VK_TLSLD: return "TLSLD"; - case VK_TLSLDM: return "TLSLDM"; - case VK_TPOFF: return "TPOFF"; - case VK_TPREL: return "TPREL"; - case VK_TLSCALL: return "tlscall"; - case VK_TLSDESC: return "tlsdesc"; - case VK_TLVP: return "TLVP"; - case VK_TLVPPAGE: return "TLVPPAGE"; - case VK_TLVPPAGEOFF: return "TLVPPAGEOFF"; - case VK_PAGE: return "PAGE"; - case VK_PAGEOFF: return "PAGEOFF"; - case VK_GOTPAGE: return "GOTPAGE"; - case VK_GOTPAGEOFF: return "GOTPAGEOFF"; - case VK_SECREL: return "SECREL32"; - case VK_WEAKREF: return "WEAKREF"; - case VK_COFF_IMGREL32: return "IMGREL"; - // clang-format on - } - llvm_unreachable("Invalid variant kind"); -} - -// FIXME: All variant kinds are target-specific. Move them to -// *AsmParser::getVariantKindForName and remove this function. -MCSymbolRefExpr::VariantKind -MCSymbolRefExpr::getVariantKindForName(StringRef Name) { - return StringSwitch<VariantKind>(Name.lower()) - .Case("dtprel", VK_DTPREL) - .Case("dtpoff", VK_DTPOFF) - .Case("got", VK_GOT) - .Case("gotent", VK_GOTENT) - .Case("gotoff", VK_GOTOFF) - .Case("gotrel", VK_GOTREL) - .Case("pcrel", VK_PCREL) - .Case("gotpcrel", VK_GOTPCREL) - .Case("gottpoff", VK_GOTTPOFF) - .Case("indntpoff", VK_INDNTPOFF) - .Case("ntpoff", VK_NTPOFF) - .Case("plt", VK_PLT) - .Case("tlscall", VK_TLSCALL) - .Case("tlsdesc", VK_TLSDESC) - .Case("tlsgd", VK_TLSGD) - .Case("tlsld", VK_TLSLD) - .Case("tlsldm", VK_TLSLDM) - .Case("tpoff", VK_TPOFF) - .Case("tprel", VK_TPREL) - .Case("tlvp", VK_TLVP) - .Case("tlvppage", VK_TLVPPAGE) - .Case("tlvppageoff", VK_TLVPPAGEOFF) - .Case("page", VK_PAGE) - .Case("pageoff", VK_PAGEOFF) - .Case("gotpage", VK_GOTPAGE) - .Case("gotpageoff", VK_GOTPAGEOFF) - .Case("imgrel", VK_COFF_IMGREL32) - .Case("secrel32", VK_SECREL) - .Default(VK_Invalid); -} - /* *** */ void MCTargetExpr::anchor() {} diff --git a/llvm/lib/Target/ARM/MCTargetDesc/ARMMCAsmInfo.cpp b/llvm/lib/Target/ARM/MCTargetDesc/ARMMCAsmInfo.cpp index b66fde0..90fa70c 100644 --- a/llvm/lib/Target/ARM/MCTargetDesc/ARMMCAsmInfo.cpp +++ b/llvm/lib/Target/ARM/MCTargetDesc/ARMMCAsmInfo.cpp @@ -129,6 +129,8 @@ ARMCOFFMCAsmInfoMicrosoft::ARMCOFFMCAsmInfoMicrosoft() { // Conditional Thumb 4-byte instructions can have an implicit IT. MaxInstLength = 6; + + initializeVariantKinds(variantKindDescs); } void ARMCOFFMCAsmInfoGNU::anchor() { } diff --git a/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZMCAsmInfo.cpp b/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZMCAsmInfo.cpp index ef2d043..be909bc 100644 --- a/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZMCAsmInfo.cpp +++ b/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZMCAsmInfo.cpp @@ -53,6 +53,8 @@ SystemZMCAsmInfoGOFF::SystemZMCAsmInfoGOFF(const Triple &TT) { IsLittleEndian = false; MaxInstLength = 6; SupportsDebugInformation = true; + + initializeVariantKinds(variantKindDescs); } bool SystemZMCAsmInfoGOFF::isAcceptableChar(char C) const { |