Skip to content

Commit e065e5f

Browse files
author
Jinsong Ji
committed
[NFC][PowerPC] Refactor classifyGlobalReference
We always(and only) check the NLP flag after calling classifyGlobalReference to see whether it is accessed indirectly. Refactor to code to use isGVIndirectSym instead. llvm-svn: 372417
1 parent 7dab840 commit e065e5f

File tree

5 files changed

+12
-28
lines changed

5 files changed

+12
-28
lines changed

llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -742,8 +742,7 @@ void PPCAsmPrinter::EmitInstruction(const MachineInstr *MI) {
742742
if (MO.isGlobal()) {
743743
const GlobalValue *GV = MO.getGlobal();
744744
MOSymbol = getSymbol(GV);
745-
unsigned char GVFlags = Subtarget->classifyGlobalReference(GV);
746-
GlobalToc = (GVFlags & PPCII::MO_NLP_FLAG);
745+
GlobalToc = Subtarget->isGVIndirectSymbol(GV);
747746
} else if (MO.isCPI()) {
748747
MOSymbol = GetCPISymbol(MO.getIndex());
749748
} else if (MO.isJTI()) {
@@ -799,8 +798,7 @@ void PPCAsmPrinter::EmitInstruction(const MachineInstr *MI) {
799798
const GlobalValue *GV = MO.getGlobal();
800799
MOSymbol = getSymbol(GV);
801800
LLVM_DEBUG(
802-
unsigned char GVFlags = Subtarget->classifyGlobalReference(GV);
803-
assert((GVFlags & PPCII::MO_NLP_FLAG) &&
801+
assert((Subtarget->isGVIndirectSymbol(GV)) &&
804802
"LDtocL used on symbol that could be accessed directly is "
805803
"invalid. Must match ADDIStocHA8."));
806804
MOSymbol = lookUpOrCreateTOCEntry(MOSymbol);
@@ -827,8 +825,7 @@ void PPCAsmPrinter::EmitInstruction(const MachineInstr *MI) {
827825

828826
if (MO.isGlobal()) {
829827
const GlobalValue *GV = MO.getGlobal();
830-
LLVM_DEBUG(unsigned char GVFlags = Subtarget->classifyGlobalReference(GV);
831-
assert(!(GVFlags & PPCII::MO_NLP_FLAG) &&
828+
LLVM_DEBUG(assert(!(Subtarget->isGVIndirectSymbol(GV)) &&
832829
"Interposable definitions must use indirect access."));
833830
MOSymbol = getSymbol(GV);
834831
} else if (MO.isCPI()) {

llvm/lib/Target/PowerPC/PPCFastISel.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2093,8 +2093,7 @@ unsigned PPCFastISel::PPCMaterializeGV(const GlobalValue *GV, MVT VT) {
20932093
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, TII.get(PPC::ADDIStocHA8),
20942094
HighPartReg).addReg(PPC::X2).addGlobalAddress(GV);
20952095

2096-
unsigned char GVFlags = PPCSubTarget->classifyGlobalReference(GV);
2097-
if (GVFlags & PPCII::MO_NLP_FLAG) {
2096+
if (PPCSubTarget->isGVIndirectSymbol(GV)) {
20982097
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, TII.get(PPC::LDtocL),
20992098
DestReg).addGlobalAddress(GV).addReg(HighPartReg);
21002099
} else {

llvm/lib/Target/PowerPC/PPCISelLowering.cpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14555,14 +14555,8 @@ bool PPCTargetLowering::isAccessedAsGotIndirect(SDValue GA) const {
1455514555
if (isa<JumpTableSDNode>(GA) || isa<BlockAddressSDNode>(GA))
1455614556
return true;
1455714557

14558-
if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(GA)) {
14559-
const GlobalValue *GV = G->getGlobal();
14560-
unsigned char GVFlags = Subtarget.classifyGlobalReference(GV);
14561-
// The NLP flag indicates that a global access has to use an
14562-
// extra indirection.
14563-
if (GVFlags & PPCII::MO_NLP_FLAG)
14564-
return true;
14565-
}
14558+
if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(GA))
14559+
return Subtarget.isGVIndirectSymbol(G->getGlobal());
1456614560

1456714561
return false;
1456814562
}

llvm/lib/Target/PowerPC/PPCSubtarget.cpp

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -229,18 +229,13 @@ bool PPCSubtarget::enableSubRegLiveness() const {
229229
return UseSubRegLiveness;
230230
}
231231

232-
unsigned char
233-
PPCSubtarget::classifyGlobalReference(const GlobalValue *GV) const {
234-
// Note that currently we don't generate non-pic references.
235-
// If a caller wants that, this will have to be updated.
236-
232+
bool PPCSubtarget::isGVIndirectSymbol(const GlobalValue *GV) const {
237233
// Large code model always uses the TOC even for local symbols.
238234
if (TM.getCodeModel() == CodeModel::Large)
239-
return PPCII::MO_PIC_FLAG | PPCII::MO_NLP_FLAG;
240-
235+
return true;
241236
if (TM.shouldAssumeDSOLocal(*GV->getParent(), GV))
242-
return PPCII::MO_PIC_FLAG;
243-
return PPCII::MO_PIC_FLAG | PPCII::MO_NLP_FLAG;
237+
return false;
238+
return true;
244239
}
245240

246241
bool PPCSubtarget::isELFv2ABI() const { return TM.isELFv2ABI(); }

llvm/lib/Target/PowerPC/PPCSubtarget.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -344,9 +344,8 @@ class PPCSubtarget : public PPCGenSubtargetInfo {
344344

345345
bool enableSubRegLiveness() const override;
346346

347-
/// classifyGlobalReference - Classify a global variable reference for the
348-
/// current subtarget accourding to how we should reference it.
349-
unsigned char classifyGlobalReference(const GlobalValue *GV) const;
347+
/// True if the GV will be accessed via an indirect symbol.
348+
bool isGVIndirectSymbol(const GlobalValue *GV) const;
350349

351350
bool isXRaySupported() const override { return IsPPC64 && IsLittleEndian; }
352351
};

0 commit comments

Comments
 (0)