llvm.org GIT mirror llvm / 08bfe00
[WinEH] Remove unused intrinsic llvm.x86.seh.restoreframe We can clean this up now that we have the X86 CATCHRET instruction to restore the FP, SP, and BP. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@255677 91177308-0d34-0410-b5e6-96231b3b80d8 Reid Kleckner 4 years ago
4 changed file(s) with 5 addition(s) and 74 deletion(s). Raw diff Collapse all Expand all
2323
2424 // Marks the EH registration node created in LLVM IR prior to code generation.
2525 def int_x86_seh_ehregnode : Intrinsic<[], [llvm_ptr_ty], []>;
26
27 // Restores the frame, base, and stack pointers as necessary after recovering
28 // from an exception. Any block resuming control flow in the parent function
29 // should call this before accessing any stack memory.
30 def int_x86_seh_restoreframe : Intrinsic<[], [], []>;
3126
3227 // Given a pointer to the end of an EH registration object, returns the true
3328 // parent frame address that can be used with llvm.localrecover.
1616716167 case EHPersonality::MSVC_CXX: return 16;
1616816168 default: break;
1616916169 }
16170 report_fatal_error("can only recover FP for MSVC EH personality functions");
16170 report_fatal_error(
16171 "can only recover FP for 32-bit MSVC EH personality functions");
1617116172 }
1617216173
1617316174 /// When the 32-bit MSVC runtime transfers control to us, either to an outlined
1707617077 return DAG.getMergeValues(Results, DL);
1707717078 }
1707817079
17079 static SDValue LowerSEHRESTOREFRAME(SDValue Op, const X86Subtarget *Subtarget,
17080 SelectionDAG &DAG) {
17081 MachineFunction &MF = DAG.getMachineFunction();
17082 const Function *Fn = MF.getFunction();
17083 SDLoc dl(Op);
17084 SDValue Chain = Op.getOperand(0);
17085
17086 assert(Subtarget->getFrameLowering()->hasFP(MF) &&
17087 "using llvm.x86.seh.restoreframe requires a frame pointer");
17088
17089 const TargetLowering &TLI = DAG.getTargetLoweringInfo();
17090 MVT VT = TLI.getPointerTy(DAG.getDataLayout());
17091
17092 const X86RegisterInfo *RegInfo = Subtarget->getRegisterInfo();
17093 unsigned FrameReg =
17094 RegInfo->getPtrSizedFrameRegister(DAG.getMachineFunction());
17095 unsigned SPReg = RegInfo->getStackRegister();
17096 unsigned SlotSize = RegInfo->getSlotSize();
17097
17098 // Get incoming EBP.
17099 SDValue IncomingEBP =
17100 DAG.getCopyFromReg(Chain, dl, FrameReg, VT);
17101
17102 // SP is saved in the first field of every registration node, so load
17103 // [EBP-RegNodeSize] into SP.
17104 int RegNodeSize = getSEHRegistrationNodeSize(Fn);
17105 SDValue SPAddr = DAG.getNode(ISD::ADD, dl, VT, IncomingEBP,
17106 DAG.getConstant(-RegNodeSize, dl, VT));
17107 SDValue NewSP =
17108 DAG.getLoad(VT, dl, Chain, SPAddr, MachinePointerInfo(), false, false,
17109 false, VT.getScalarSizeInBits() / 8);
17110 Chain = DAG.getCopyToReg(Chain, dl, SPReg, NewSP);
17111
17112 if (!RegInfo->needsStackRealignment(MF)) {
17113 // Adjust EBP to point back to the original frame position.
17114 SDValue NewFP = recoverFramePointer(DAG, Fn, IncomingEBP);
17115 Chain = DAG.getCopyToReg(Chain, dl, FrameReg, NewFP);
17116 } else {
17117 assert(RegInfo->hasBasePointer(MF) &&
17118 "functions with Win32 EH must use frame or base pointer register");
17119
17120 // Reload the base pointer (ESI) with the adjusted incoming EBP.
17121 SDValue NewBP = recoverFramePointer(DAG, Fn, IncomingEBP);
17122 Chain = DAG.getCopyToReg(Chain, dl, RegInfo->getBaseRegister(), NewBP);
17123
17124 // Reload the spilled EBP value, now that the stack and base pointers are
17125 // set up.
17126 X86MachineFunctionInfo *X86FI = MF.getInfo();
17127 X86FI->setHasSEHFramePtrSave(true);
17128 int FI = MF.getFrameInfo()->CreateSpillStackObject(SlotSize, SlotSize);
17129 X86FI->setSEHFramePtrSaveIndex(FI);
17130 SDValue NewFP = DAG.getLoad(VT, dl, Chain, DAG.getFrameIndex(FI, VT),
17131 MachinePointerInfo(), false, false, false,
17132 VT.getScalarSizeInBits() / 8);
17133 Chain = DAG.getCopyToReg(NewFP, dl, FrameReg, NewFP);
17134 }
17135
17136 return Chain;
17137 }
17138
1713917080 static SDValue MarkEHRegistrationNode(SDValue Op, SelectionDAG &DAG) {
1714017081 MachineFunction &MF = DAG.getMachineFunction();
1714117082 SDValue Chain = Op.getOperand(0);
1719717138
1719817139 const IntrinsicData* IntrData = getIntrinsicWithChain(IntNo);
1719917140 if (!IntrData) {
17200 if (IntNo == llvm::Intrinsic::x86_seh_restoreframe)
17201 return LowerSEHRESTOREFRAME(Op, Subtarget, DAG);
17202 else if (IntNo == llvm::Intrinsic::x86_seh_ehregnode)
17141 if (IntNo == llvm::Intrinsic::x86_seh_ehregnode)
1720317142 return MarkEHRegistrationNode(Op, DAG);
1720417143 return SDValue();
1720517144 }
8383 /// of pushes to pass function parameters.
8484 bool HasPushSequences = false;
8585
86 /// True if the function uses llvm.x86.seh.restoreframe, and it needed a spill
87 /// slot for the frame pointer.
86 /// True if the function recovers from an SEH exception, and therefore needs
87 /// to spill and restore the frame pointer.
8888 bool HasSEHFramePtrSave = false;
8989
9090 /// The frame index of a stack object containing the original frame pointer
8686 Function *FrameRecover = nullptr;
8787 Function *FrameAddress = nullptr;
8888 Function *FrameEscape = nullptr;
89 Function *RestoreFrame = nullptr;
9089
9190 // Per-function state
9291 EHPersonality Personality = EHPersonality::Unknown;
119118 FrameEscape = Intrinsic::getDeclaration(TheModule, Intrinsic::localescape);
120119 FrameRecover = Intrinsic::getDeclaration(TheModule, Intrinsic::localrecover);
121120 FrameAddress = Intrinsic::getDeclaration(TheModule, Intrinsic::frameaddress);
122 RestoreFrame =
123 Intrinsic::getDeclaration(TheModule, Intrinsic::x86_seh_restoreframe);
124121 return false;
125122 }
126123