Skip to content

Commit

Permalink
[Codegen] Change PICLevel.
Browse files Browse the repository at this point in the history
We convert `Default` to `NotPIC` so that target independent code
can reason about this correctly.

Differential Revision:  http://reviews.llvm.org/D21394

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@273024 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
dcci committed Jun 17, 2016
1 parent de71999 commit d2e7196
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 8 deletions.
3 changes: 2 additions & 1 deletion include/llvm/Support/CodeGen.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ namespace llvm {
}

namespace PICLevel {
enum Level { Default=0, Small=1, Large=2 };
// This is used to map -fpic/-fPIC.
enum Level { NotPIC=0, SmallPIC=1, BigPIC=2 };
}

namespace PIELevel {
Expand Down
2 changes: 1 addition & 1 deletion lib/IR/Module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ PICLevel::Level Module::getPICLevel() const {
auto *Val = cast_or_null<ConstantAsMetadata>(getModuleFlag("PIC Level"));

if (!Val)
return PICLevel::Default;
return PICLevel::NotPIC;

return static_cast<PICLevel::Level>(
cast<ConstantInt>(Val->getValue())->getZExtValue());
Expand Down
6 changes: 3 additions & 3 deletions lib/Target/PowerPC/PPCAsmPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ void PPCAsmPrinter::EmitInstruction(const MachineInstr *MI) {
else if (MO.isBlockAddress())
MOSymbol = GetBlockAddressSymbol(MO.getBlockAddress());

if (PL == PICLevel::Small) {
if (PL == PICLevel::SmallPIC) {
const MCExpr *Exp =
MCSymbolRefExpr::create(MOSymbol, MCSymbolRefExpr::VK_GOT,
OutContext);
Expand Down Expand Up @@ -1045,7 +1045,7 @@ void PPCLinuxAsmPrinter::EmitStartOfAsmFile(Module &M) {
TM.getRelocationModel() != Reloc::PIC_)
return AsmPrinter::EmitStartOfAsmFile(M);

if (M.getPICLevel() == PICLevel::Small)
if (M.getPICLevel() == PICLevel::SmallPIC)
return AsmPrinter::EmitStartOfAsmFile(M);

OutStreamer->SwitchSection(OutContext.getELFSection(
Expand All @@ -1072,7 +1072,7 @@ void PPCLinuxAsmPrinter::EmitFunctionEntryLabel() {
// linux/ppc32 - Normal entry label.
if (!Subtarget->isPPC64() &&
(TM.getRelocationModel() != Reloc::PIC_ ||
MF->getFunction()->getParent()->getPICLevel() == PICLevel::Small))
MF->getFunction()->getParent()->getPICLevel() == PICLevel::SmallPIC))
return AsmPrinter::EmitFunctionEntryLabel();

if (!Subtarget->isPPC64()) {
Expand Down
2 changes: 1 addition & 1 deletion lib/Target/PowerPC/PPCISelDAGToDAG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ SDNode *PPCDAGToDAGISel::getGlobalBaseReg() {
if (PPCLowering->getPointerTy(CurDAG->getDataLayout()) == MVT::i32) {
if (PPCSubTarget->isTargetELF()) {
GlobalBaseReg = PPC::R30;
if (M->getPICLevel() == PICLevel::Small) {
if (M->getPICLevel() == PICLevel::SmallPIC) {
BuildMI(FirstMBB, MBBI, dl, TII.get(PPC::MoveGOTtoLR));
BuildMI(FirstMBB, MBBI, dl, TII.get(PPC::MFLR), GlobalBaseReg);
MF->getInfo<PPCFunctionInfo>()->setUsesPICBase(true);
Expand Down
4 changes: 2 additions & 2 deletions lib/Target/PowerPC/PPCISelLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2172,7 +2172,7 @@ SDValue PPCTargetLowering::LowerGlobalTLSAddress(SDValue Op,
GOTPtr = DAG.getNode(PPCISD::ADDIS_TLSGD_HA, dl, PtrVT,
GOTReg, TGA);
} else {
if (picLevel == PICLevel::Small)
if (picLevel == PICLevel::SmallPIC)
GOTPtr = DAG.getNode(PPCISD::GlobalBaseReg, dl, PtrVT);
else
GOTPtr = DAG.getNode(PPCISD::PPC32_PICGOT, dl, PtrVT);
Expand All @@ -2190,7 +2190,7 @@ SDValue PPCTargetLowering::LowerGlobalTLSAddress(SDValue Op,
GOTPtr = DAG.getNode(PPCISD::ADDIS_TLSLD_HA, dl, PtrVT,
GOTReg, TGA);
} else {
if (picLevel == PICLevel::Small)
if (picLevel == PICLevel::SmallPIC)
GOTPtr = DAG.getNode(PPCISD::GlobalBaseReg, dl, PtrVT);
else
GOTPtr = DAG.getNode(PPCISD::PPC32_PICGOT, dl, PtrVT);
Expand Down

0 comments on commit d2e7196

Please sign in to comment.