[llvm] 1e8fbb3 - [MC] Inline MCExpr::printVariantKind & remove UseParensForSymbolVariantBit
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 1 00:10:44 PDT 2020
Author: Fangrui Song
Date: 2020-10-01T00:10:06-07:00
New Revision: 1e8fbb3b745916160a35a6af4dfdba9bbe26c730
URL: https://github.com/llvm/llvm-project/commit/1e8fbb3b745916160a35a6af4dfdba9bbe26c730
DIFF: https://github.com/llvm/llvm-project/commit/1e8fbb3b745916160a35a6af4dfdba9bbe26c730.diff
LOG: [MC] Inline MCExpr::printVariantKind & remove UseParensForSymbolVariantBit
Note, MAI may be nullptr in -show-encoding.
Added:
Modified:
llvm/include/llvm/MC/MCExpr.h
llvm/lib/MC/MCExpr.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/MC/MCExpr.h b/llvm/include/llvm/MC/MCExpr.h
index 3cc43e15db83..46e60d8f258d 100644
--- a/llvm/include/llvm/MC/MCExpr.h
+++ b/llvm/include/llvm/MC/MCExpr.h
@@ -355,30 +355,20 @@ class MCSymbolRefExpr : public MCExpr {
/// The symbol being referenced.
const MCSymbol *Symbol;
- // Subclass data stores VariantKind in bits 0..15, UseParensForSymbolVariant
- // in bit 16 and HasSubsectionsViaSymbols in bit 17.
+ // Subclass data stores VariantKind in bits 0..15 and HasSubsectionsViaSymbols
+ // in bit 16.
static const unsigned VariantKindBits = 16;
static const unsigned VariantKindMask = (1 << VariantKindBits) - 1;
- /// Specifies how the variant kind should be printed.
- static const unsigned UseParensForSymbolVariantBit = 1 << VariantKindBits;
-
// FIXME: Remove this bit.
- static const unsigned HasSubsectionsViaSymbolsBit =
- 1 << (VariantKindBits + 1);
+ static const unsigned HasSubsectionsViaSymbolsBit = 1 << VariantKindBits;
static unsigned encodeSubclassData(VariantKind Kind,
- bool UseParensForSymbolVariant,
- bool HasSubsectionsViaSymbols) {
+ bool HasSubsectionsViaSymbols) {
return (unsigned)Kind |
- (UseParensForSymbolVariant ? UseParensForSymbolVariantBit : 0) |
(HasSubsectionsViaSymbols ? HasSubsectionsViaSymbolsBit : 0);
}
- bool useParensForSymbolVariant() const {
- return (getSubclassData() & UseParensForSymbolVariantBit) != 0;
- }
-
explicit MCSymbolRefExpr(const MCSymbol *Symbol, VariantKind Kind,
const MCAsmInfo *MAI, SMLoc Loc = SMLoc());
@@ -405,8 +395,6 @@ class MCSymbolRefExpr : public MCExpr {
return (VariantKind)(getSubclassData() & VariantKindMask);
}
- void printVariantKind(raw_ostream &OS) const;
-
bool hasSubsectionsViaSymbols() const {
return (getSubclassData() & HasSubsectionsViaSymbolsBit) != 0;
}
diff --git a/llvm/lib/MC/MCExpr.cpp b/llvm/lib/MC/MCExpr.cpp
index 1953fd3fdd45..b433277c3dc5 100644
--- a/llvm/lib/MC/MCExpr.cpp
+++ b/llvm/lib/MC/MCExpr.cpp
@@ -85,8 +85,13 @@ void MCExpr::print(raw_ostream &OS, const MCAsmInfo *MAI, bool InParens) const {
} else
Sym.print(OS, MAI);
- if (SRE.getKind() != MCSymbolRefExpr::VK_None)
- SRE.printVariantKind(OS);
+ const MCSymbolRefExpr::VariantKind Kind = SRE.getKind();
+ if (Kind != MCSymbolRefExpr::VK_None) {
+ if (MAI && MAI->useParensForSymbolVariant()) // ARM
+ OS << '(' << MCSymbolRefExpr::getVariantKindName(Kind) << ')';
+ else
+ OS << '@' << MCSymbolRefExpr::getVariantKindName(Kind);
+ }
return;
}
@@ -197,8 +202,7 @@ const MCConstantExpr *MCConstantExpr::create(int64_t Value, MCContext &Ctx,
MCSymbolRefExpr::MCSymbolRefExpr(const MCSymbol *Symbol, VariantKind Kind,
const MCAsmInfo *MAI, SMLoc Loc)
: MCExpr(MCExpr::SymbolRef, Loc,
- encodeSubclassData(Kind, MAI->useParensForSymbolVariant(),
- MAI->hasSubsectionsViaSymbols())),
+ encodeSubclassData(Kind, MAI->hasSubsectionsViaSymbols())),
Symbol(Symbol) {
assert(Symbol);
}
@@ -510,13 +514,6 @@ MCSymbolRefExpr::getVariantKindForName(StringRef Name) {
.Default(VK_Invalid);
}
-void MCSymbolRefExpr::printVariantKind(raw_ostream &OS) const {
- if (useParensForSymbolVariant())
- OS << '(' << MCSymbolRefExpr::getVariantKindName(getKind()) << ')';
- else
- OS << '@' << MCSymbolRefExpr::getVariantKindName(getKind());
-}
-
/* *** */
void MCTargetExpr::anchor() {}
More information about the llvm-commits
mailing list