llvm.org GIT mirror llvm / 1544e47
Emit exception handling info for functions which are not marked nounwind, or for all functions when -enable-eh is set, provided the target supports Dwarf EH. llvm-gcc generates nounwind in the right places; other FEs will need to do so also. Given such a FE, -enable-eh should no longer be needed. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@49006 91177308-0d34-0410-b5e6-96231b3b80d8 Dale Johannesen 11 years ago
8 changed file(s) with 49 addition(s) and 25 deletion(s). Raw diff Collapse all Expand all
27772777
27782778 std::vector EHFrames;
27792779
2780 /// shouldEmit - Flag to indicate if debug information should be emitted.
2781 ///
2780 /// shouldEmit - Per-function flag to indicate if EH information should
2781 /// be emitted.
27822782 bool shouldEmit;
2783
2784 /// shouldEmitModule - Per-module flag to indicate if EH information should
2785 /// be emitted.
2786 bool shouldEmitModule;
27832787
27842788 /// EmitCommonEHFrame - Emit the common eh unwind frame.
27852789 ///
33673371 DwarfException(std::ostream &OS, AsmPrinter *A, const TargetAsmInfo *T)
33683372 : Dwarf(OS, A, T, "eh")
33693373 , shouldEmit(false)
3374 , shouldEmitModule(false)
33703375 {}
33713376
33723377 virtual ~DwarfException() {}
33863391 /// EndModule - Emit all exception information that should come after the
33873392 /// content.
33883393 void EndModule() {
3389 if (!shouldEmit) return;
3394 if (!shouldEmitModule) return;
33903395
33913396 const std::vector Personalities = MMI->getPersonalities();
33923397 for (unsigned i =0; i < Personalities.size(); ++i)
34023407 void BeginFunction(MachineFunction *MF) {
34033408 this->MF = MF;
34043409
3405 if (MMI &&
3406 ExceptionHandling &&
3410 shouldEmit = false;
3411 if ((ExceptionHandling || !MF->getFunction()->doesNotThrow()) &&
34073412 TAI->doesSupportExceptionHandling()) {
34083413 shouldEmit = true;
34093414 // Assumes in correct section after the entry point.
34103415 EmitLabel("eh_func_begin", ++SubprogramCount);
34113416 }
3417 shouldEmitModule |= shouldEmit;
34123418 }
34133419
34143420 /// EndFunction - Gather and emit post-function exception information.
6565
6666 PM.add(createGCLoweringPass());
6767
68 if (!ExceptionHandling)
69 PM.add(createLowerInvokePass(getTargetLowering()));
68 PM.add(createLowerInvokePass(getTargetLowering()));
7069
7170 // Make sure that no unreachable blocks are instruction selected.
7271 PM.add(createUnreachableBlockEliminationPass());
191190
192191 PM.add(createGCLoweringPass());
193192
194 if (!ExceptionHandling)
195 PM.add(createLowerInvokePass(getTargetLowering()));
193 PM.add(createLowerInvokePass(getTargetLowering()));
196194
197195 // Make sure that no unreachable blocks are instruction selected.
198196 PM.add(createUnreachableBlockEliminationPass());
168168 Function &Fn;
169169 MachineFunction &MF;
170170 MachineRegisterInfo &RegInfo;
171 bool needsExceptionHandling;
171172
172173 FunctionLoweringInfo(TargetLowering &TLI, Function &Fn,MachineFunction &MF);
173174
303304 BuildMI(MBB, TII->get(TargetInstrInfo::PHI), PHIReg+i);
304305 }
305306 }
307
308 // Figure out whether we need to generate EH info. Currently we do this for
309 // all functions not marked no-unwind, or if requested via -enable-eh.
310 needsExceptionHandling = ExceptionHandling || !Fn.doesNotThrow();
306311 }
307312
308313 /// CreateRegForValue - Allocate the appropriate number of virtual registers of
28262831 }
28272832
28282833 case Intrinsic::eh_exception: {
2829 if (ExceptionHandling) {
2834 if (FuncInfo.needsExceptionHandling) {
28302835 if (!CurMBB->isLandingPad()) {
28312836 // FIXME: Mark exception register as live in. Hack for PR1508.
28322837 unsigned Reg = TLI.getExceptionAddressRegister();
28512856 MVT::ValueType VT = (Intrinsic == Intrinsic::eh_selector_i32 ?
28522857 MVT::i32 : MVT::i64);
28532858
2854 if (ExceptionHandling && MMI) {
2859 if (FuncInfo.needsExceptionHandling && MMI) {
28552860 if (CurMBB->isLandingPad())
28562861 addCatchInfo(I, MMI, CurMBB);
28572862 else {
29012906 case Intrinsic::eh_return: {
29022907 MachineModuleInfo *MMI = DAG.getMachineModuleInfo();
29032908
2904 if (MMI && ExceptionHandling) {
2909 if (MMI && FuncInfo.needsExceptionHandling) {
29052910 MMI->setCallsEHReturn(true);
29062911 DAG.setRoot(DAG.getNode(ISD::EH_RETURN,
29072912 MVT::Other,
29242929 }
29252930
29262931 case Intrinsic::eh_dwarf_cfa: {
2927 if (ExceptionHandling) {
2932 if (FuncInfo.needsExceptionHandling) {
29282933 MVT::ValueType VT = getValue(I.getOperand(1)).getValueType();
29292934 SDOperand CfaArg;
29302935 if (MVT::getSizeInBits(VT) > MVT::getSizeInBits(TLI.getPointerTy()))
31753180 Args.push_back(Entry);
31763181 }
31773182
3178 if (LandingPad && ExceptionHandling && MMI) {
3183 if (LandingPad && FuncInfo.needsExceptionHandling && MMI) {
31793184 // Insert a label before the invoke call to mark the try range. This can be
31803185 // used to detect deletion of the invoke via the MachineModuleInfo.
31813186 BeginLabel = MMI->NextLabelID();
31943199 setValue(CS.getInstruction(), Result.first);
31953200 DAG.setRoot(Result.second);
31963201
3197 if (LandingPad && ExceptionHandling && MMI) {
3202 if (LandingPad && FuncInfo.needsExceptionHandling && MMI) {
31983203 // Insert a label at the end of the invoke call to mark the try range. This
31993204 // can be used to detect deletion of the invoke via the MachineModuleInfo.
32003205 EndLabel = MMI->NextLabelID();
46134618
46144619 FunctionLoweringInfo FuncInfo(TLI, Fn, MF);
46154620
4616 if (ExceptionHandling)
4621 if (FuncInfo.needsExceptionHandling)
46174622 for (Function::iterator I = Fn.begin(), E = Fn.end(); I != E; ++I)
46184623 if (InvokeInst *Invoke = dyn_cast(I->getTerminator()))
46194624 // Mark landing pad.
47564761
47574762 MachineModuleInfo *MMI = DAG.getMachineModuleInfo();
47584763
4759 if (ExceptionHandling && MMI && BB->isLandingPad()) {
4764 if (FuncInfo.needsExceptionHandling && MMI && BB->isLandingPad()) {
47604765 // Add a label to mark the beginning of the landing pad. Deletion of the
47614766 // landing pad can thus be detected via the MachineModuleInfo.
47624767 unsigned LabelID = MMI->addLandingPad(BB);
10851085
10861086 O << "\n";
10871087
1088 if (ExceptionHandling && TAI->doesSupportExceptionHandling() && MMI) {
1088 if (TAI->doesSupportExceptionHandling() && MMI) {
10891089 // Add the (possibly multiple) personalities to the set of global values.
1090 // Only referenced functions get into the Personalities list.
10901091 const std::vector& Personalities = MMI->getPersonalities();
10911092
10921093 for (std::vector::const_iterator I = Personalities.begin(),
1919 #include "PPCFrameInfo.h"
2020 #include "PPCSubtarget.h"
2121 #include "llvm/Constants.h"
22 #include "llvm/Function.h"
2223 #include "llvm/Type.h"
2324 #include "llvm/CodeGen/ValueTypes.h"
2425 #include "llvm/CodeGen/MachineInstrBuilder.h"
945946 MachineBasicBlock::iterator MBBI = MBB.begin();
946947 MachineFrameInfo *MFI = MF.getFrameInfo();
947948 MachineModuleInfo *MMI = MFI->getMachineModuleInfo();
949 bool needsFrameInfo = (MMI && MMI->hasDebugInfo()) ||
950 ExceptionHandling || !MF.getFunction()->doesNotThrow();
948951
949952 // Prepare for frame info.
950953 unsigned FrameLabelId = 0;
10181021 unsigned TargetAlign = MF.getTarget().getFrameInfo()->getStackAlignment();
10191022 unsigned MaxAlign = MFI->getMaxAlignment();
10201023
1021 if (MMI && MMI->needsFrameInfo()) {
1024 if (needsFrameInfo) {
10221025 // Mark effective beginning of when frame pointer becomes valid.
10231026 FrameLabelId = MMI->NextLabelID();
10241027 BuildMI(MBB, MBBI, TII.get(PPC::LABEL)).addImm(FrameLabelId).addImm(0);
10941097 }
10951098 }
10961099
1097 if (MMI && MMI->needsFrameInfo()) {
1100 if (needsFrameInfo) {
10981101 std::vector &Moves = MMI->getFrameMoves();
10991102
11001103 if (NegFrameSize) {
380380
381381 O << "\n";
382382
383 if (ExceptionHandling && TAI->doesSupportExceptionHandling() && MMI &&
384 !Subtarget->is64Bit()) {
383 if (TAI->doesSupportExceptionHandling() && MMI && !Subtarget->is64Bit()) {
385384 // Add the (possibly multiple) personalities to the set of global values.
385 // Only referenced functions get into the Personalities list.
386386 const std::vector& Personalities = MMI->getPersonalities();
387387
388388 for (std::vector::const_iterator I = Personalities.begin(),
503503 MachineModuleInfo *MMI = MFI->getMachineModuleInfo();
504504 X86MachineFunctionInfo *X86FI = MF.getInfo();
505505 MachineBasicBlock::iterator MBBI = MBB.begin();
506 bool needsFrameInfo = (MMI && MMI->hasDebugInfo()) ||
507 ExceptionHandling || !Fn->doesNotThrow();
506508
507509 // Prepare for frame info.
508510 unsigned FrameLabelId = 0;
535537 .addReg(FramePtr);
536538 NumBytes -= SlotSize;
537539
538 if (MMI && MMI->needsFrameInfo()) {
540 if (needsFrameInfo) {
539541 // Mark effective beginning of when frame pointer becomes valid.
540542 FrameLabelId = MMI->NextLabelID();
541543 BuildMI(MBB, MBBI, TII.get(X86::LABEL)).addImm(FrameLabelId).addImm(0);
547549 }
548550
549551 unsigned ReadyLabelId = 0;
550 if (MMI && MMI->needsFrameInfo()) {
552 if (needsFrameInfo) {
551553 // Mark effective beginning of when frame pointer is ready.
552554 ReadyLabelId = MMI->NextLabelID();
553555 BuildMI(MBB, MBBI, TII.get(X86::LABEL)).addImm(ReadyLabelId).addImm(0);
606608 }
607609 }
608610
609 if (MMI && MMI->needsFrameInfo()) {
611 if (needsFrameInfo) {
610612 std::vector &Moves = MMI->getFrameMoves();
611613 const TargetData *TD = MF.getTarget().getTargetData();
612614
4646 #include "llvm/Support/CommandLine.h"
4747 #include "llvm/Support/Compiler.h"
4848 #include "llvm/Target/TargetLowering.h"
49 #include "llvm/Target/TargetOptions.h"
50 #include "llvm/Target/TargetMachine.h"
51 #include "llvm/Target/TargetAsmInfo.h"
4952 #include
5053 #include
5154 using namespace llvm;
591594 }
592595
593596 bool LowerInvoke::runOnFunction(Function &F) {
597 // If we will be generating exception info, don't do anything here.
598 if ((ExceptionHandling || !F.doesNotThrow()) &&
599 TLI &&
600 TLI->getTargetMachine().getTargetAsmInfo()->
601 doesSupportExceptionHandling())
602 return false;
594603 if (ExpensiveEHSupport)
595604 return insertExpensiveEHSupport(F);
596605 else