Skip to content

Commit 205dcf7

Browse files
committed
PowerPC: Remove redundant MCSymbolRefExpr::VariantKind casts
1 parent 96c1611 commit 205dcf7

File tree

5 files changed

+18
-34
lines changed

5 files changed

+18
-34
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1514,8 +1514,7 @@ bool PPCAsmParser::parseOperand(OperandVector &Operands) {
15141514
Tok.getString().compare_insensitive("plt") == 0))
15151515
return Error(Tok.getLoc(), "expected 'plt'");
15161516
EVal = MCSymbolRefExpr::create(getContext().getOrCreateSymbol(TlsGetAddr),
1517-
MCSymbolRefExpr::VariantKind(PPC::S_PLT),
1518-
getContext());
1517+
PPC::S_PLT, getContext());
15191518
if (parseOptionalToken(AsmToken::Plus)) {
15201519
const MCExpr *Addend = nullptr;
15211520
SMLoc EndLoc;

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

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -329,14 +329,11 @@ PPCMCCodeEmitter::getDispRI34PCRelEncoding(const MCInst &MI, unsigned OpNo,
329329
const MCSymbolRefExpr *SRE = cast<MCSymbolRefExpr>(Expr);
330330
(void)SRE;
331331
// Currently these are the only valid PCRelative Relocations.
332-
assert((getSpecifier(SRE) == PPC::S_PCREL ||
333-
getSpecifier(SRE) == PPC::S_GOT_PCREL ||
334-
getSpecifier(SRE) == PPC::S_GOT_TLSGD_PCREL ||
335-
getSpecifier(SRE) == PPC::S_GOT_TLSLD_PCREL ||
336-
getSpecifier(SRE) == PPC::S_GOT_TPREL_PCREL) &&
337-
"VariantKind must be VK_PCREL or VK_GOT_PCREL or "
338-
"VK_GOT_TLSGD_PCREL or VK_GOT_TLSLD_PCREL or "
339-
"VK_GOT_TPREL_PCREL.");
332+
assert(is_contained({PPC::S_PCREL, PPC::S_GOT_PCREL, PPC::S_GOT_TLSGD_PCREL,
333+
PPC::S_GOT_TLSLD_PCREL, PPC::S_GOT_TPREL_PCREL},
334+
SRE->getSpecifier()) &&
335+
"specifier must be S_PCREL, S_GOT_PCREL, S_GOT_TLSGD_PCREL, "
336+
"S_GOT_TLSLD_PCREL, or S_GOT_TPREL_PCREL");
340337
// Generate the fixup for the relocation.
341338
Fixups.push_back(
342339
MCFixup::create(0, Expr,

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -399,10 +399,8 @@ class PPCTargetXCOFFStreamer : public PPCTargetStreamer {
399399
const MCAsmInfo *MAI = Streamer.getContext().getAsmInfo();
400400
const unsigned PointerSize = MAI->getCodePointerSize();
401401
Streamer.emitValueToAlignment(Align(PointerSize));
402-
Streamer.emitValue(
403-
MCSymbolRefExpr::create(&S, MCSymbolRefExpr::VariantKind(Kind),
404-
Streamer.getContext()),
405-
PointerSize);
402+
Streamer.emitValue(MCSymbolRefExpr::create(&S, Kind, Streamer.getContext()),
403+
PointerSize);
406404
}
407405

408406
void emitMachine(StringRef CPU) override {

llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -144,12 +144,12 @@ enum {
144144
class PPCAsmPrinter : public AsmPrinter {
145145
protected:
146146
// For TLS on AIX, we need to be able to identify TOC entries of specific
147-
// VariantKind so we can add the right relocations when we generate the
147+
// specifier so we can add the right relocations when we generate the
148148
// entries. So each entry is represented by a pair of MCSymbol and
149149
// VariantKind. For example, we need to be able to identify the following
150150
// entry as a TLSGD entry so we can add the @m relocation:
151151
// .tc .i[TC],i[TL]@m
152-
// By default, VK_None is used for the VariantKind.
152+
// By default, 0 is used for the specifier.
153153
MapVector<std::pair<const MCSymbol *, PPCMCExpr::Specifier>, MCSymbol *> TOC;
154154
const PPCSubtarget *Subtarget = nullptr;
155155

@@ -732,8 +732,7 @@ void PPCAsmPrinter::emitTlsCall(const MachineInstr *MI,
732732
if (Subtarget->is32BitELFABI() && isPositionIndependent())
733733
Kind = PPC::S_PLT;
734734

735-
const MCExpr *TlsRef = MCSymbolRefExpr::create(
736-
TlsGetAddr, MCSymbolRefExpr::VariantKind(Kind), OutContext);
735+
const MCExpr *TlsRef = MCSymbolRefExpr::create(TlsGetAddr, Kind, OutContext);
737736

738737
// Add 32768 offset to the symbol so we follow up the latest GOT/PLT ABI.
739738
if (Kind == PPC::S_PLT && Subtarget->isSecurePlt() &&
@@ -743,8 +742,7 @@ void PPCAsmPrinter::emitTlsCall(const MachineInstr *MI,
743742
const MachineOperand &MO = MI->getOperand(2);
744743
const GlobalValue *GValue = MO.getGlobal();
745744
MCSymbol *MOSymbol = getSymbol(GValue);
746-
const MCExpr *SymVar = MCSymbolRefExpr::create(
747-
MOSymbol, MCSymbolRefExpr::VariantKind(VK), OutContext);
745+
const MCExpr *SymVar = MCSymbolRefExpr::create(MOSymbol, VK, OutContext);
748746
EmitToStreamer(*OutStreamer,
749747
MCInstBuilder(Subtarget->isPPC64() ? Opcode
750748
: (unsigned)PPC::BL_TLS)
@@ -801,8 +799,7 @@ getTOCEntryTypeForMO(const MachineOperand &MO) {
801799

802800
const MCExpr *PPCAsmPrinter::symbolWithSpecifier(const MCSymbol *S,
803801
PPCMCExpr::Specifier Spec) {
804-
return MCSymbolRefExpr::create(S, MCSymbolRefExpr::VariantKind(Spec),
805-
OutContext);
802+
return MCSymbolRefExpr::create(S, Spec, OutContext);
806803
}
807804

808805
/// EmitInstruction -- Print out a single PowerPC MI in Darwin syntax to
@@ -954,8 +951,7 @@ void PPCAsmPrinter::emitInstruction(const MachineInstr *MI) {
954951
MCSymbol *GOTSymbol =
955952
OutContext.getOrCreateSymbol(StringRef("_GLOBAL_OFFSET_TABLE_"));
956953
const MCExpr *OffsExpr = MCBinaryExpr::createSub(
957-
MCSymbolRefExpr::create(
958-
GOTSymbol, MCSymbolRefExpr::VariantKind(PPC::S_LOCAL), OutContext),
954+
MCSymbolRefExpr::create(GOTSymbol, PPC::S_LOCAL, OutContext),
959955
MCConstantExpr::create(4, OutContext), OutContext);
960956

961957
// Emit the 'bl'.
@@ -1331,9 +1327,7 @@ void PPCAsmPrinter::emitInstruction(const MachineInstr *MI) {
13311327
const MCSymbol *const MOSymbol = getMCSymbolForTOCPseudoMO(MO, *this);
13321328

13331329
const MCExpr *Exp = MCSymbolRefExpr::create(
1334-
MOSymbol,
1335-
MCSymbolRefExpr::VariantKind(IsAIX ? PPC::S_L : PPC::S_TOC_LO),
1336-
OutContext);
1330+
MOSymbol, IsAIX ? PPC::S_L : PPC::S_TOC_LO, OutContext);
13371331

13381332
TmpInst.getOperand(2) = MCOperand::createExpr(Exp);
13391333
EmitToStreamer(*OutStreamer, TmpInst);
@@ -1728,8 +1722,7 @@ PPCAsmPrinter::getAdjustedFasterLocalExpr(const MachineOperand &MO,
17281722
// assume that the address of extern TLS variables are zero.
17291723
const MCExpr *Expr = MCSymbolRefExpr::create(
17301724
getSymbol(GValue),
1731-
MCSymbolRefExpr::VariantKind(
1732-
Model == TLSModel::LocalExec ? PPC::S_AIX_TLSLE : PPC::S_AIX_TLSLD),
1725+
(Model == TLSModel::LocalExec ? PPC::S_AIX_TLSLE : PPC::S_AIX_TLSLD),
17331726
OutContext);
17341727
Expr = MCBinaryExpr::createAdd(
17351728
Expr, MCConstantExpr::create(Offset, OutContext), OutContext);
@@ -2017,9 +2010,7 @@ void PPCLinuxAsmPrinter::emitFunctionEntryLabel() {
20172010
MCSymbol *Symbol2 = OutContext.getOrCreateSymbol(StringRef(".TOC."));
20182011
// Generates a R_PPC64_TOC relocation for TOC base insertion.
20192012
OutStreamer->emitValue(
2020-
MCSymbolRefExpr::create(
2021-
Symbol2, MCSymbolRefExpr::VariantKind(PPC::S_TOCBASE), OutContext),
2022-
8 /*size*/);
2013+
MCSymbolRefExpr::create(Symbol2, PPC::S_TOCBASE, OutContext), 8 /*size*/);
20232014
// Emit a null environment pointer.
20242015
OutStreamer->emitIntValue(0, 8 /* size */);
20252016
OutStreamer->switchSection(Current.first, Current.second);

llvm/lib/Target/PowerPC/PPCMCInstLower.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,7 @@ static MCOperand GetSymbolRef(const MachineOperand &MO, const MCSymbol *Symbol,
136136
RefKind = PPC::S_PCREL_OPT;
137137
}
138138

139-
const MCExpr *Expr = MCSymbolRefExpr::create(
140-
Symbol, MCSymbolRefExpr::VariantKind(RefKind), Ctx);
139+
const MCExpr *Expr = MCSymbolRefExpr::create(Symbol, RefKind, Ctx);
141140
// If -msecure-plt -fPIC, add 32768 to symbol.
142141
if (Subtarget->isSecurePlt() && TM.isPositionIndependent() &&
143142
M->getPICLevel() == PICLevel::BigPIC &&

0 commit comments

Comments
 (0)