llvm.org GIT mirror llvm / 36a5502
Fix @llvm.frameaddress codegen. FP elimination optimization should be disabled when frame address is desired. Also add support for depth > 0. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@56683 91177308-0d34-0410-b5e6-96231b3b80d8 Evan Cheng 11 years ago
13 changed file(s) with 56 addition(s) and 16 deletion(s). Raw diff Collapse all Expand all
117117 ///
118118 bool HasVarSizedObjects;
119119
120 /// FrameAddressTaken - This boolean keeps track of whether there is a call
121 /// to builtin @llvm.frameaddress.
122 bool FrameAddressTaken;
123
120124 /// StackSize - The prolog/epilog code inserter calculates the final stack
121125 /// offsets for all of the fixed size objects, updating the Objects list
122126 /// above. It then updates StackSize to contain the number of bytes that need
173177 MachineFrameInfo(const TargetFrameInfo &tfi) : TFI(tfi) {
174178 StackSize = NumFixedObjects = OffsetAdjustment = MaxAlignment = 0;
175179 HasVarSizedObjects = false;
180 FrameAddressTaken = false;
176181 HasCalls = false;
177182 MaxCallFrameSize = 0;
178183 MMI = 0;
188193 /// contains any variable sized objects.
189194 ///
190195 bool hasVarSizedObjects() const { return HasVarSizedObjects; }
196
197 /// isFrameAddressTaken - This method may be called any time after instruction
198 /// selection is complete to determine if there is a call to
199 /// @llvm.frameaddress in this function.
200 bool isFrameAddressTaken() const { return FrameAddressTaken; }
201 void setFrameAddressIsTaken(bool T) { FrameAddressTaken = T; }
191202
192203 /// getObjectIndexBegin - Return the minimum frame object index...
193204 ///
34823482 setValue(&I, DAG.getNode(ISD::RETURNADDR, TLI.getPointerTy(),
34833483 getValue(I.getOperand(1))));
34843484 return 0;
3485 case Intrinsic::frameaddress:
3485 case Intrinsic::frameaddress: {
3486 MachineFrameInfo *MFI = CurMBB->getParent()->getFrameInfo();
3487 MFI->setFrameAddressIsTaken(true);
34863488 setValue(&I, DAG.getNode(ISD::FRAMEADDR, TLI.getPointerTy(),
34873489 getValue(I.getOperand(1))));
34883490 return 0;
3491 }
34893492 case Intrinsic::setjmp:
34903493 return "_setjmp"+!TLI.usesUnderscoreSetJmp();
34913494 break;
208208 /// or if frame pointer elimination is disabled.
209209 ///
210210 bool ARMRegisterInfo::hasFP(const MachineFunction &MF) const {
211 return NoFramePointerElim || MF.getFrameInfo()->hasVarSizedObjects();
211 const MachineFrameInfo *MFI = MF.getFrameInfo();
212 return NoFramePointerElim || MFI->hasVarSizedObjects() ||
213 MFI->isFrameAddressTaken();
212214 }
213215
214216 // hasReservedCallFrame - Under normal circumstances, when a frame pointer is
103103 //
104104 bool AlphaRegisterInfo::hasFP(const MachineFunction &MF) const {
105105 const MachineFrameInfo *MFI = MF.getFrameInfo();
106 return MFI->hasVarSizedObjects();
106 return MFI->hasVarSizedObjects() || MFI->isFrameAddressTaken();
107107 }
108108
109109 void AlphaRegisterInfo::
293293 //
294294 static bool needsFP(const MachineFunction &MF) {
295295 const MachineFrameInfo *MFI = MF.getFrameInfo();
296 return NoFramePointerElim || MFI->hasVarSizedObjects();
296 return NoFramePointerElim || MFI->hasVarSizedObjects() ||
297 MFI->isFrameAddressTaken();
297298 }
298299
299300 //--------------------------------------------------------------------------
7474 // if frame pointer elimination is disabled.
7575 //
7676 bool IA64RegisterInfo::hasFP(const MachineFunction &MF) const {
77 return NoFramePointerElim || MF.getFrameInfo()->hasVarSizedObjects();
77 const MachineFrameInfo *MFI = MF.getFrameInfo();
78 return NoFramePointerElim || MFI->hasVarSizedObjects() ||
79 MFI->isFrameAddressTaken();
7880 }
7981
8082 void IA64RegisterInfo::
323323 // if frame pointer elimination is disabled.
324324 bool MipsRegisterInfo::
325325 hasFP(const MachineFunction &MF) const {
326 return (NoFramePointerElim || MF.getFrameInfo()->hasVarSizedObjects());
326 const MachineFrameInfo *MFI = MF.getFrameInfo();
327 return NoFramePointerElim || MFI->hasVarSizedObjects() ||
328 MFI->isFrameAddressTaken();
327329 }
328330
329331 // This function eliminate ADJCALLSTACKDOWN,
332332 static bool needsFP(const MachineFunction &MF) {
333333 const MachineFrameInfo *MFI = MF.getFrameInfo();
334334 return NoFramePointerElim || MFI->hasVarSizedObjects() ||
335 MFI->isFrameAddressTaken() ||
335336 (PerformTailCallOpt && MF.getInfo()->hasFastCall());
336337 }
337338
56445644 }
56455645
56465646 SDValue X86TargetLowering::LowerFRAMEADDR(SDValue Op, SelectionDAG &DAG) {
5647 // Depths > 0 not supported yet!
5648 if (cast(Op.getOperand(0))->getZExtValue() > 0)
5649 return SDValue();
5650
5651 SDValue RetAddrFI = getReturnAddressFrameIndex(DAG);
5652 return DAG.getNode(ISD::SUB, getPointerTy(), RetAddrFI,
5653 DAG.getIntPtrConstant(TD->getPointerSize()));
5647 unsigned Depth = cast(Op.getOperand(0))->getZExtValue();
5648 unsigned FrameReg = Subtarget->is64Bit() ? X86::RBP : X86::EBP;
5649 SDValue FrameAddr = DAG.getRegister(FrameReg, getPointerTy());
5650 while (Depth--)
5651 FrameAddr = DAG.getLoad(getPointerTy(), DAG.getEntryNode(), FrameAddr,
5652 NULL, 0);
5653 return FrameAddr;
56545654 }
56555655
56565656 SDValue X86TargetLowering::LowerFRAME_TO_ARGS_OFFSET(SDValue Op,
298298 return (NoFramePointerElim ||
299299 needsStackRealignment(MF) ||
300300 MFI->hasVarSizedObjects() ||
301 MFI->isFrameAddressTaken() ||
301302 MF.getInfo()->getForceFramePointer() ||
302303 (MMI && MMI->callsUnwindInit()));
303304 }
None ; RUN: llvm-as < %s | llc -march=x86-64 | grep {leaq -8(%rsp), %rax}
1 @llvm.noinline = appending global [1 x i8*] [ i8* bitcast (i64* ()* @stack_end_address to i8*) ], section "llvm.metadata"
0 ; RUN: llvm-as < %s | llc -march=x86-64 | grep movq | grep rbp
21
3 define internal i64* @stack_end_address() nounwind {
2 define i64* @stack_end_address() nounwind {
43 entry:
54 tail call i8* @llvm.frameaddress( i32 0 )
65 bitcast i8* %0 to i64*
0 ; RUN: llvm-as < %s | llc -march=x86 | grep mov | grep ebp
1
2 define i8* @t() nounwind {
3 entry:
4 %0 = tail call i8* @llvm.frameaddress(i32 0)
5 ret i8* %0
6 }
7
8 declare i8* @llvm.frameaddress(i32) nounwind readnone
0 ; RUN: llvm-as < %s | llc -march=x86 | grep mov | count 3
1
2 define i8* @t() nounwind {
3 entry:
4 %0 = tail call i8* @llvm.frameaddress(i32 2)
5 ret i8* %0
6 }
7
8 declare i8* @llvm.frameaddress(i32) nounwind readnone