Skip to content

Commit 5f85a7b

Browse files
author
Sean Fertile
committed
[PowerPC] Add combined ELF ABI and 32/64 bit queries to the subtarget. [NFC]
A lot of places in the code combine checks for both ABI (SVR4/Darwin/AIX) and addressing mode (64-bit vs 32-bit). In an attempt to make some of the code more readable I've added a couple functions that combine checking for the ELF abi and 64-bit/32-bit code at once. As we add more AIX support I intend to add similar functions for the AIX ABI. Differential Revision: https://reviews.llvm.org/D65814 llvm-svn: 369658
1 parent 18fd1b0 commit 5f85a7b

6 files changed

+59
-58
lines changed

llvm/lib/Target/PowerPC/PPCFastISel.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -2464,7 +2464,7 @@ namespace llvm {
24642464
const TargetLibraryInfo *LibInfo) {
24652465
// Only available on 64-bit ELF for now.
24662466
const PPCSubtarget &Subtarget = FuncInfo.MF->getSubtarget<PPCSubtarget>();
2467-
if (Subtarget.isPPC64() && Subtarget.isSVR4ABI())
2467+
if (Subtarget.is64BitELFABI())
24682468
return new PPCFastISel(FuncInfo, LibInfo);
24692469
return nullptr;
24702470
}

llvm/lib/Target/PowerPC/PPCISelDAGToDAG.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -5152,8 +5152,8 @@ void PPCDAGToDAGISel::Select(SDNode *N) {
51525152
}
51535153
case PPCISD::PPC32_PICGOT:
51545154
// Generate a PIC-safe GOT reference.
5155-
assert(!PPCSubTarget->isPPC64() && PPCSubTarget->isSVR4ABI() &&
5156-
"PPCISD::PPC32_PICGOT is only supported for 32-bit SVR4");
5155+
assert(PPCSubTarget->is32BitELFABI() &&
5156+
"PPCISD::PPC32_PICGOT is only supported for 32-bit SVR4");
51575157
CurDAG->SelectNodeTo(N, PPC::PPC32PICGOT,
51585158
PPCLowering->getPointerTy(CurDAG->getDataLayout()),
51595159
MVT::i32);

llvm/lib/Target/PowerPC/PPCISelLowering.cpp

+47-45
Original file line numberDiff line numberDiff line change
@@ -431,28 +431,26 @@ PPCTargetLowering::PPCTargetLowering(const PPCTargetMachine &TM,
431431
// VASTART needs to be custom lowered to use the VarArgsFrameIndex
432432
setOperationAction(ISD::VASTART , MVT::Other, Custom);
433433

434-
if (Subtarget.isSVR4ABI()) {
435-
if (isPPC64) {
436-
// VAARG always uses double-word chunks, so promote anything smaller.
437-
setOperationAction(ISD::VAARG, MVT::i1, Promote);
438-
AddPromotedToType (ISD::VAARG, MVT::i1, MVT::i64);
439-
setOperationAction(ISD::VAARG, MVT::i8, Promote);
440-
AddPromotedToType (ISD::VAARG, MVT::i8, MVT::i64);
441-
setOperationAction(ISD::VAARG, MVT::i16, Promote);
442-
AddPromotedToType (ISD::VAARG, MVT::i16, MVT::i64);
443-
setOperationAction(ISD::VAARG, MVT::i32, Promote);
444-
AddPromotedToType (ISD::VAARG, MVT::i32, MVT::i64);
445-
setOperationAction(ISD::VAARG, MVT::Other, Expand);
446-
} else {
447-
// VAARG is custom lowered with the 32-bit SVR4 ABI.
448-
setOperationAction(ISD::VAARG, MVT::Other, Custom);
449-
setOperationAction(ISD::VAARG, MVT::i64, Custom);
450-
}
434+
if (Subtarget.is64BitELFABI()) {
435+
// VAARG always uses double-word chunks, so promote anything smaller.
436+
setOperationAction(ISD::VAARG, MVT::i1, Promote);
437+
AddPromotedToType(ISD::VAARG, MVT::i1, MVT::i64);
438+
setOperationAction(ISD::VAARG, MVT::i8, Promote);
439+
AddPromotedToType(ISD::VAARG, MVT::i8, MVT::i64);
440+
setOperationAction(ISD::VAARG, MVT::i16, Promote);
441+
AddPromotedToType(ISD::VAARG, MVT::i16, MVT::i64);
442+
setOperationAction(ISD::VAARG, MVT::i32, Promote);
443+
AddPromotedToType(ISD::VAARG, MVT::i32, MVT::i64);
444+
setOperationAction(ISD::VAARG, MVT::Other, Expand);
445+
} else if (Subtarget.is32BitELFABI()) {
446+
// VAARG is custom lowered with the 32-bit SVR4 ABI.
447+
setOperationAction(ISD::VAARG, MVT::Other, Custom);
448+
setOperationAction(ISD::VAARG, MVT::i64, Custom);
451449
} else
452450
setOperationAction(ISD::VAARG, MVT::Other, Expand);
453451

454-
if (Subtarget.isSVR4ABI() && !isPPC64)
455-
// VACOPY is custom lowered with the 32-bit SVR4 ABI.
452+
// VACOPY is custom lowered with the 32-bit SVR4 ABI.
453+
if (Subtarget.is32BitELFABI())
456454
setOperationAction(ISD::VACOPY , MVT::Other, Custom);
457455
else
458456
setOperationAction(ISD::VACOPY , MVT::Other, Expand);
@@ -2694,7 +2692,7 @@ SDValue PPCTargetLowering::LowerConstantPool(SDValue Op,
26942692

26952693
// 64-bit SVR4 ABI code is always position-independent.
26962694
// The actual address of the GlobalValue is stored in the TOC.
2697-
if (Subtarget.isSVR4ABI() && Subtarget.isPPC64()) {
2695+
if (Subtarget.is64BitELFABI()) {
26982696
setUsesTOCBasePtr(DAG);
26992697
SDValue GA = DAG.getTargetConstantPool(C, PtrVT, CP->getAlignment(), 0);
27002698
return getTOCEntry(DAG, SDLoc(CP), GA);
@@ -2770,7 +2768,7 @@ SDValue PPCTargetLowering::LowerJumpTable(SDValue Op, SelectionDAG &DAG) const {
27702768

27712769
// 64-bit SVR4 ABI code is always position-independent.
27722770
// The actual address of the GlobalValue is stored in the TOC.
2773-
if (Subtarget.isSVR4ABI() && Subtarget.isPPC64()) {
2771+
if (Subtarget.is64BitELFABI()) {
27742772
setUsesTOCBasePtr(DAG);
27752773
SDValue GA = DAG.getTargetJumpTable(JT->getIndex(), PtrVT);
27762774
return getTOCEntry(DAG, SDLoc(JT), GA);
@@ -2799,14 +2797,18 @@ SDValue PPCTargetLowering::LowerBlockAddress(SDValue Op,
27992797

28002798
// 64-bit SVR4 ABI code is always position-independent.
28012799
// The actual BlockAddress is stored in the TOC.
2802-
if (Subtarget.isSVR4ABI() &&
2803-
(Subtarget.isPPC64() || isPositionIndependent())) {
2804-
if (Subtarget.isPPC64())
2805-
setUsesTOCBasePtr(DAG);
2800+
if (Subtarget.is64BitELFABI()) {
2801+
setUsesTOCBasePtr(DAG);
28062802
SDValue GA = DAG.getTargetBlockAddress(BA, PtrVT, BASDN->getOffset());
28072803
return getTOCEntry(DAG, SDLoc(BASDN), GA);
28082804
}
28092805

2806+
// 32-bit position-independent ELF stores the BlockAddress in the .got.
2807+
if (Subtarget.is32BitELFABI() && isPositionIndependent())
2808+
return getTOCEntry(
2809+
DAG, SDLoc(BASDN),
2810+
DAG.getTargetBlockAddress(BA, PtrVT, BASDN->getOffset()));
2811+
28102812
unsigned MOHiFlag, MOLoFlag;
28112813
bool IsPIC = isPositionIndependent();
28122814
getLabelAccessInfo(IsPIC, Subtarget, MOHiFlag, MOLoFlag);
@@ -2921,7 +2923,7 @@ SDValue PPCTargetLowering::LowerGlobalAddress(SDValue Op,
29212923

29222924
// 64-bit SVR4 ABI & AIX ABI code is always position-independent.
29232925
// The actual address of the GlobalValue is stored in the TOC.
2924-
if ((Subtarget.isSVR4ABI() && Subtarget.isPPC64()) || Subtarget.isAIXABI()) {
2926+
if (Subtarget.is64BitELFABI() || Subtarget.isAIXABI()) {
29252927
setUsesTOCBasePtr(DAG);
29262928
SDValue GA = DAG.getTargetGlobalAddress(GV, DL, PtrVT, GSDN->getOffset());
29272929
return getTOCEntry(DAG, DL, GA);
@@ -3383,17 +3385,17 @@ SDValue PPCTargetLowering::LowerFormalArguments(
33833385
SDValue Chain, CallingConv::ID CallConv, bool isVarArg,
33843386
const SmallVectorImpl<ISD::InputArg> &Ins, const SDLoc &dl,
33853387
SelectionDAG &DAG, SmallVectorImpl<SDValue> &InVals) const {
3386-
if (Subtarget.isSVR4ABI()) {
3387-
if (Subtarget.isPPC64())
3388-
return LowerFormalArguments_64SVR4(Chain, CallConv, isVarArg, Ins,
3389-
dl, DAG, InVals);
3390-
else
3391-
return LowerFormalArguments_32SVR4(Chain, CallConv, isVarArg, Ins,
3392-
dl, DAG, InVals);
3393-
} else {
3394-
return LowerFormalArguments_Darwin(Chain, CallConv, isVarArg, Ins,
3395-
dl, DAG, InVals);
3396-
}
3388+
if (Subtarget.is64BitELFABI())
3389+
return LowerFormalArguments_64SVR4(Chain, CallConv, isVarArg, Ins, dl, DAG,
3390+
InVals);
3391+
else if (Subtarget.is32BitELFABI())
3392+
return LowerFormalArguments_32SVR4(Chain, CallConv, isVarArg, Ins, dl, DAG,
3393+
InVals);
3394+
3395+
// FIXME: We are using this for both AIX and Darwin. We should add appropriate
3396+
// AIX testing, and rename it appropriately.
3397+
return LowerFormalArguments_Darwin(Chain, CallConv, isVarArg, Ins, dl, DAG,
3398+
InVals);
33973399
}
33983400

33993401
SDValue PPCTargetLowering::LowerFormalArguments_32SVR4(
@@ -4522,7 +4524,7 @@ callsShareTOCBase(const Function *Caller, SDValue Callee,
45224524
static bool
45234525
needStackSlotPassParameters(const PPCSubtarget &Subtarget,
45244526
const SmallVectorImpl<ISD::OutputArg> &Outs) {
4525-
assert(Subtarget.isSVR4ABI() && Subtarget.isPPC64());
4527+
assert(Subtarget.is64BitELFABI());
45264528

45274529
const unsigned PtrByteSize = 8;
45284530
const unsigned LinkageSize = Subtarget.getFrameLowering()->getLinkageSize();
@@ -4932,7 +4934,7 @@ PrepareCall(SelectionDAG &DAG, SDValue &Callee, SDValue &InFlag, SDValue &Chain,
49324934
ImmutableCallSite CS, const PPCSubtarget &Subtarget) {
49334935
bool isPPC64 = Subtarget.isPPC64();
49344936
bool isSVR4ABI = Subtarget.isSVR4ABI();
4935-
bool isELFv2ABI = Subtarget.isELFv2ABI();
4937+
bool is64BitELFv1ABI = isPPC64 && isSVR4ABI && !Subtarget.isELFv2ABI();
49364938
bool isAIXABI = Subtarget.isAIXABI();
49374939

49384940
EVT PtrVT = DAG.getTargetLoweringInfo().getPointerTy(DAG.getDataLayout());
@@ -5003,7 +5005,7 @@ PrepareCall(SelectionDAG &DAG, SDValue &Callee, SDValue &InFlag, SDValue &Chain,
50035005
// to do the call, we can't use PPCISD::CALL.
50045006
SDValue MTCTROps[] = {Chain, Callee, InFlag};
50055007

5006-
if (isSVR4ABI && isPPC64 && !isELFv2ABI) {
5008+
if (is64BitELFv1ABI) {
50075009
// Function pointers in the 64-bit SVR4 ABI do not point to the function
50085010
// entry point, but to the function descriptor (the function entry point
50095011
// address is part of the function descriptor though).
@@ -5091,7 +5093,7 @@ PrepareCall(SelectionDAG &DAG, SDValue &Callee, SDValue &InFlag, SDValue &Chain,
50915093
CallOpc = PPCISD::BCTRL;
50925094
Callee.setNode(nullptr);
50935095
// Add use of X11 (holding environment pointer)
5094-
if (isSVR4ABI && isPPC64 && !isELFv2ABI && !hasNest)
5096+
if (is64BitELFv1ABI && !hasNest)
50955097
Ops.push_back(DAG.getRegister(PPC::X11, PtrVT));
50965098
// Add CTR register as callee so a bctr can be emitted later.
50975099
if (isTailCall)
@@ -10511,7 +10513,7 @@ PPCTargetLowering::emitEHSjLjSetJmp(MachineInstr &MI,
1051110513
Register LabelReg = MRI.createVirtualRegister(PtrRC);
1051210514
Register BufReg = MI.getOperand(1).getReg();
1051310515

10514-
if (Subtarget.isPPC64() && Subtarget.isSVR4ABI()) {
10516+
if (Subtarget.is64BitELFABI()) {
1051510517
setUsesTOCBasePtr(*MBB->getParent());
1051610518
MIB = BuildMI(*thisMBB, MI, DL, TII->get(PPC::STD))
1051710519
.addReg(PPC::X2)
@@ -10688,7 +10690,7 @@ PPCTargetLowering::EmitInstrWithCustomInserter(MachineInstr &MI,
1068810690
MachineBasicBlock *BB) const {
1068910691
if (MI.getOpcode() == TargetOpcode::STACKMAP ||
1069010692
MI.getOpcode() == TargetOpcode::PATCHPOINT) {
10691-
if (Subtarget.isPPC64() && Subtarget.isSVR4ABI() &&
10693+
if (Subtarget.is64BitELFABI() &&
1069210694
MI.getOpcode() == TargetOpcode::PATCHPOINT) {
1069310695
// Call lowering should have added an r2 operand to indicate a dependence
1069410696
// on the TOC base pointer value. It can't however, because there is no
@@ -14424,7 +14426,7 @@ unsigned PPCTargetLowering::getRegisterByName(const char* RegName, EVT VT,
1442414426

1442514427
bool PPCTargetLowering::isAccessedAsGotIndirect(SDValue GA) const {
1442614428
// 32-bit SVR4 ABI access everything as got-indirect.
14427-
if (Subtarget.isSVR4ABI() && !Subtarget.isPPC64())
14429+
if (Subtarget.is32BitELFABI())
1442814430
return true;
1442914431

1443014432
// AIX accesses everything indirectly through the TOC, which is similar to
@@ -15243,7 +15245,7 @@ SDValue PPCTargetLowering::combineMUL(SDNode *N, DAGCombinerInfo &DCI) const {
1524315245

1524415246
bool PPCTargetLowering::mayBeEmittedAsTailCall(const CallInst *CI) const {
1524515247
// Only duplicate to increase tail-calls for the 64bit SysV ABIs.
15246-
if (!Subtarget.isSVR4ABI() || !Subtarget.isPPC64())
15248+
if (!Subtarget.is64BitELFABI())
1524715249
return false;
1524815250

1524915251
// If not a tail call then no need to proceed.

llvm/lib/Target/PowerPC/PPCRegisterInfo.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -325,13 +325,13 @@ BitVector PPCRegisterInfo::getReservedRegs(const MachineFunction &MF) const {
325325

326326
bool IsPositionIndependent = TM.isPositionIndependent();
327327
if (hasBasePointer(MF)) {
328-
if (Subtarget.isSVR4ABI() && !TM.isPPC64() && IsPositionIndependent)
328+
if (Subtarget.is32BitELFABI() && IsPositionIndependent)
329329
markSuperRegs(Reserved, PPC::R29);
330330
else
331331
markSuperRegs(Reserved, PPC::R30);
332332
}
333333

334-
if (Subtarget.isSVR4ABI() && !TM.isPPC64() && IsPositionIndependent)
334+
if (Subtarget.is32BitELFABI() && IsPositionIndependent)
335335
markSuperRegs(Reserved, PPC::R30);
336336

337337
// Reserve Altivec registers when Altivec is unavailable.

llvm/lib/Target/PowerPC/PPCRegisterInfo.td

+4-8
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,7 @@ def GPRC : RegisterClass<"PPC", [i32], 32, (add (sequence "R%u", 2, 12),
260260
// put it at the end of the list.
261261
let AltOrders = [(add (sub GPRC, R2), R2)];
262262
let AltOrderSelect = [{
263-
const PPCSubtarget &S = MF.getSubtarget<PPCSubtarget>();
264-
return S.isPPC64() && S.isSVR4ABI();
263+
return MF.getSubtarget<PPCSubtarget>().is64BitELFABI();
265264
}];
266265
}
267266

@@ -272,8 +271,7 @@ def G8RC : RegisterClass<"PPC", [i64], 64, (add (sequence "X%u", 2, 12),
272271
// put it at the end of the list.
273272
let AltOrders = [(add (sub G8RC, X2), X2)];
274273
let AltOrderSelect = [{
275-
const PPCSubtarget &S = MF.getSubtarget<PPCSubtarget>();
276-
return S.isPPC64() && S.isSVR4ABI();
274+
return MF.getSubtarget<PPCSubtarget>().is64BitELFABI();
277275
}];
278276
}
279277

@@ -285,8 +283,7 @@ def GPRC_NOR0 : RegisterClass<"PPC", [i32], 32, (add (sub GPRC, R0), ZERO)> {
285283
// put it at the end of the list.
286284
let AltOrders = [(add (sub GPRC_NOR0, R2), R2)];
287285
let AltOrderSelect = [{
288-
const PPCSubtarget &S = MF.getSubtarget<PPCSubtarget>();
289-
return S.isPPC64() && S.isSVR4ABI();
286+
return MF.getSubtarget<PPCSubtarget>().is64BitELFABI();
290287
}];
291288
}
292289

@@ -295,8 +292,7 @@ def G8RC_NOX0 : RegisterClass<"PPC", [i64], 64, (add (sub G8RC, X0), ZERO8)> {
295292
// put it at the end of the list.
296293
let AltOrders = [(add (sub G8RC_NOX0, X2), X2)];
297294
let AltOrderSelect = [{
298-
const PPCSubtarget &S = MF.getSubtarget<PPCSubtarget>();
299-
return S.isPPC64() && S.isSVR4ABI();
295+
return MF.getSubtarget<PPCSubtarget>().is64BitELFABI();
300296
}];
301297
}
302298

llvm/lib/Target/PowerPC/PPCSubtarget.h

+3
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,9 @@ class PPCSubtarget : public PPCGenSubtargetInfo {
320320
bool isSVR4ABI() const { return !isDarwinABI() && !isAIXABI(); }
321321
bool isELFv2ABI() const;
322322

323+
bool is64BitELFABI() const { return isSVR4ABI() && isPPC64(); }
324+
bool is32BitELFABI() const { return isSVR4ABI() && !isPPC64(); }
325+
323326
/// Originally, this function return hasISEL(). Now we always enable it,
324327
/// but may expand the ISEL instruction later.
325328
bool enableEarlyIfConversion() const override { return true; }

0 commit comments

Comments
 (0)