llvm.org GIT mirror llvm / 3fc027d
implement __builtin_return_addr(0) on ppc. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@44700 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 12 years ago
6 changed file(s) with 72 addition(s) and 11 deletion(s). Raw diff Collapse all Expand all
30353035 case ISD::SCALAR_TO_VECTOR: return LowerSCALAR_TO_VECTOR(Op, DAG);
30363036 case ISD::MUL: return LowerMUL(Op, DAG);
30373037
3038 // Frame & Return address. Currently unimplemented
3039 case ISD::RETURNADDR: break;
3038 // Frame & Return address.
3039 case ISD::RETURNADDR: return LowerRETURNADDR(Op, DAG);
30403040 case ISD::FRAMEADDR: return LowerFRAMEADDR(Op, DAG);
30413041 }
30423042 return SDOperand();
35753575 return false;
35763576 }
35773577
3578 SDOperand PPCTargetLowering::LowerFRAMEADDR(SDOperand Op, SelectionDAG &DAG)
3579 {
3578 SDOperand PPCTargetLowering::LowerRETURNADDR(SDOperand Op, SelectionDAG &DAG) {
3579 // Depths > 0 not supported yet!
3580 if (cast(Op.getOperand(0))->getValue() > 0)
3581 return SDOperand();
3582
3583 MachineFunction &MF = DAG.getMachineFunction();
3584 PPCFunctionInfo *FuncInfo = MF.getInfo();
3585 int RAIdx = FuncInfo->getReturnAddrSaveIndex();
3586 if (RAIdx == 0) {
3587 bool isPPC64 = PPCSubTarget.isPPC64();
3588 int Offset =
3589 PPCFrameInfo::getReturnSaveOffset(isPPC64, PPCSubTarget.isMachoABI());
3590
3591 // Set up a frame object for the return address.
3592 RAIdx = MF.getFrameInfo()->CreateFixedObject(isPPC64 ? 8 : 4, Offset);
3593
3594 // Remember it for next time.
3595 FuncInfo->setReturnAddrSaveIndex(RAIdx);
3596
3597 // Make sure the function really does not optimize away the store of the RA
3598 // to the stack.
3599 FuncInfo->setLRStoreRequired();
3600 }
3601
3602 // Just load the return address off the stack.
3603 SDOperand RetAddrFI = DAG.getFrameIndex(RAIdx, getPointerTy());
3604 return DAG.getLoad(getPointerTy(), DAG.getEntryNode(), RetAddrFI, NULL, 0);
3605 }
3606
3607 SDOperand PPCTargetLowering::LowerFRAMEADDR(SDOperand Op, SelectionDAG &DAG) {
35803608 // Depths > 0 not supported yet!
35813609 if (cast(Op.getOperand(0))->getValue() > 0)
35823610 return SDOperand();
287287 /// the offset of the target addressing mode.
288288 virtual bool isLegalAddressImmediate(GlobalValue *GV) const;
289289
290 SDOperand LowerRETURNADDR(SDOperand Op, SelectionDAG &DAG);
290291 SDOperand LowerFRAMEADDR(SDOperand Op, SelectionDAG &DAG);
291292 };
292293 }
2626 /// when using frame pointers (dyna_add, dyna_sub.)
2727 int FramePointerSaveIndex;
2828
29 /// UsesLR - Indicates whether LR is used in the current function.
29 /// ReturnAddrSaveIndex - Frame index of where the return address is stored.
3030 ///
31 int ReturnAddrSaveIndex;
32
33 /// UsesLR - Indicates whether LR is used in the current function. This is
34 /// only valid after the initial scan of the function by PEI.
3135 bool UsesLR;
3236
37 /// LRStoreRequired - The bool indicates whether there is some explicit use of
38 /// the LR/LR8 stack slot that is not obvious from scanning the code. This
39 /// requires that the code generator produce a store of LR to the stack on
40 /// entry, even though LR may otherwise apparently not be used.
41 bool LRStoreRequired;
3342 public:
34 PPCFunctionInfo(MachineFunction& MF)
35 : FramePointerSaveIndex(0)
36 {}
43 PPCFunctionInfo(MachineFunction &MF)
44 : FramePointerSaveIndex(0), ReturnAddrSaveIndex(0), LRStoreRequired(false){}
3745
3846 int getFramePointerSaveIndex() const { return FramePointerSaveIndex; }
3947 void setFramePointerSaveIndex(int Idx) { FramePointerSaveIndex = Idx; }
48
49 int getReturnAddrSaveIndex() const { return ReturnAddrSaveIndex; }
50 void setReturnAddrSaveIndex(int idx) { ReturnAddrSaveIndex = idx; }
4051
4152 /// UsesLR - This is set when the prolog/epilog inserter does its initial scan
4253 /// of the function, it is true if the LR/LR8 register is ever explicitly
4556 void setUsesLR(bool U) { UsesLR = U; }
4657 bool usesLR() const { return UsesLR; }
4758
59 void setLRStoreRequired() { LRStoreRequired = true; }
60 bool isLRStoreRequired() const { return LRStoreRequired; }
61
4862 };
4963
5064 } // end of namespace llvm
645645 }
646646
647647 /// MustSaveLR - Return true if this function requires that we save the LR
648 /// register onto the stack in the prolog and restore it in the epilog of the function.
648 /// register onto the stack in the prolog and restore it in the epilog of the
649 /// function.
649650 static bool MustSaveLR(const MachineFunction &MF) {
650 return MF.getInfo()->usesLR() ||
651 const PPCFunctionInfo *MFI = MF.getInfo();
652
653 // We need an save/restore of LR if there is any use/def of LR explicitly, or
654 // if there is some use of the LR stack slot (e.g. for builtin_return_address.
655 return MFI->usesLR() || MFI->isLRStoreRequired() ||
651656 // FIXME: Anything that has a call should clobber the LR register,
652657 // isn't this redundant??
653658 MF.getFrameInfo()->hasCalls();
22 TODO:
33 * gpr0 allocation
44 * implement do-loop -> bdnz transform
5 * __builtin_return_address not supported on PPC
65
76 ===-------------------------------------------------------------------------===
87
0 ; RUN: llvm-as < %s | llc -march=ppc32 | grep mflr
1 ; RUN: llvm-as < %s | llc -march=ppc32 | grep lwz
2
3 target triple = "powerpc-apple-darwin8"
4
5 define void @foo(i8** %X) {
6 entry:
7 %tmp = tail call i8* @llvm.returnaddress( i32 0 ) ; [#uses=1]
8 store i8* %tmp, i8** %X, align 4
9 ret void
10 }
11
12 declare i8* @llvm.returnaddress(i32)
13