Skip to content

Commit

Permalink
[NFC][PowerPC] Refactor classifyGlobalReference
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Jinsong Ji committed Sep 20, 2019
1 parent 7dab840 commit e065e5f
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 28 deletions.
9 changes: 3 additions & 6 deletions llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
Expand Up @@ -742,8 +742,7 @@ void PPCAsmPrinter::EmitInstruction(const MachineInstr *MI) {
if (MO.isGlobal()) {
const GlobalValue *GV = MO.getGlobal();
MOSymbol = getSymbol(GV);
unsigned char GVFlags = Subtarget->classifyGlobalReference(GV);
GlobalToc = (GVFlags & PPCII::MO_NLP_FLAG);
GlobalToc = Subtarget->isGVIndirectSymbol(GV);
} else if (MO.isCPI()) {
MOSymbol = GetCPISymbol(MO.getIndex());
} else if (MO.isJTI()) {
Expand Down Expand Up @@ -799,8 +798,7 @@ void PPCAsmPrinter::EmitInstruction(const MachineInstr *MI) {
const GlobalValue *GV = MO.getGlobal();
MOSymbol = getSymbol(GV);
LLVM_DEBUG(
unsigned char GVFlags = Subtarget->classifyGlobalReference(GV);
assert((GVFlags & PPCII::MO_NLP_FLAG) &&
assert((Subtarget->isGVIndirectSymbol(GV)) &&
"LDtocL used on symbol that could be accessed directly is "
"invalid. Must match ADDIStocHA8."));
MOSymbol = lookUpOrCreateTOCEntry(MOSymbol);
Expand All @@ -827,8 +825,7 @@ void PPCAsmPrinter::EmitInstruction(const MachineInstr *MI) {

if (MO.isGlobal()) {
const GlobalValue *GV = MO.getGlobal();
LLVM_DEBUG(unsigned char GVFlags = Subtarget->classifyGlobalReference(GV);
assert(!(GVFlags & PPCII::MO_NLP_FLAG) &&
LLVM_DEBUG(assert(!(Subtarget->isGVIndirectSymbol(GV)) &&
"Interposable definitions must use indirect access."));
MOSymbol = getSymbol(GV);
} else if (MO.isCPI()) {
Expand Down
3 changes: 1 addition & 2 deletions llvm/lib/Target/PowerPC/PPCFastISel.cpp
Expand Up @@ -2093,8 +2093,7 @@ unsigned PPCFastISel::PPCMaterializeGV(const GlobalValue *GV, MVT VT) {
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, TII.get(PPC::ADDIStocHA8),
HighPartReg).addReg(PPC::X2).addGlobalAddress(GV);

unsigned char GVFlags = PPCSubTarget->classifyGlobalReference(GV);
if (GVFlags & PPCII::MO_NLP_FLAG) {
if (PPCSubTarget->isGVIndirectSymbol(GV)) {
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, TII.get(PPC::LDtocL),
DestReg).addGlobalAddress(GV).addReg(HighPartReg);
} else {
Expand Down
10 changes: 2 additions & 8 deletions llvm/lib/Target/PowerPC/PPCISelLowering.cpp
Expand Up @@ -14555,14 +14555,8 @@ bool PPCTargetLowering::isAccessedAsGotIndirect(SDValue GA) const {
if (isa<JumpTableSDNode>(GA) || isa<BlockAddressSDNode>(GA))
return true;

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

return false;
}
Expand Down
13 changes: 4 additions & 9 deletions llvm/lib/Target/PowerPC/PPCSubtarget.cpp
Expand Up @@ -229,18 +229,13 @@ bool PPCSubtarget::enableSubRegLiveness() const {
return UseSubRegLiveness;
}

unsigned char
PPCSubtarget::classifyGlobalReference(const GlobalValue *GV) const {
// Note that currently we don't generate non-pic references.
// If a caller wants that, this will have to be updated.

bool PPCSubtarget::isGVIndirectSymbol(const GlobalValue *GV) const {
// Large code model always uses the TOC even for local symbols.
if (TM.getCodeModel() == CodeModel::Large)
return PPCII::MO_PIC_FLAG | PPCII::MO_NLP_FLAG;

return true;
if (TM.shouldAssumeDSOLocal(*GV->getParent(), GV))
return PPCII::MO_PIC_FLAG;
return PPCII::MO_PIC_FLAG | PPCII::MO_NLP_FLAG;
return false;
return true;
}

bool PPCSubtarget::isELFv2ABI() const { return TM.isELFv2ABI(); }
Expand Down
5 changes: 2 additions & 3 deletions llvm/lib/Target/PowerPC/PPCSubtarget.h
Expand Up @@ -344,9 +344,8 @@ class PPCSubtarget : public PPCGenSubtargetInfo {

bool enableSubRegLiveness() const override;

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

bool isXRaySupported() const override { return IsPPC64 && IsLittleEndian; }
};
Expand Down

0 comments on commit e065e5f

Please sign in to comment.