[llvm-commits] [llvm] r140646 - in /llvm/trunk/lib: CodeGen/LLVMTargetMachine.cpp Target/ARM/ARM.h Target/ARM/ARMSjLjLoweringPass.cpp Target/ARM/ARMTargetMachine.cpp

Bill Wendling isanbard at gmail.com
Tue Sep 27 15:14:12 PDT 2011


Author: void
Date: Tue Sep 27 17:14:12 2011
New Revision: 140646

URL: http://llvm.org/viewvc/llvm-project?rev=140646&view=rev
Log:
This is the start of the new SjLj EH preparation pass, which will replace the
current IR-level pass.

The old SjLj EH pass has some problems, especially with the new EH model. Most
significantly, it violates some of the new restrictions the new model has. For
instance, the 'dispatch' table wants to jump to the landing pad, but we cannot
allow that because only an invoke's unwind edge can jump to a landing pad. This
requires us to mangle the code something awful. In addition, we need to keep the
now dead landingpad instructions around instead of CSE'ing them because the
DWARF emitter uses that information (they are dead because no control flow edge
will execute them - the control flow edge from an invoke's unwind is superceded
by the edge coming from the dispatch).

Basically, this pass belongs not at the IR level where SSA is king, but at the
code-gen level, where we have more flexibility.

Added:
    llvm/trunk/lib/Target/ARM/ARMSjLjLoweringPass.cpp
Modified:
    llvm/trunk/lib/CodeGen/LLVMTargetMachine.cpp
    llvm/trunk/lib/Target/ARM/ARM.h
    llvm/trunk/lib/Target/ARM/ARMTargetMachine.cpp

Modified: llvm/trunk/lib/CodeGen/LLVMTargetMachine.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/LLVMTargetMachine.cpp?rev=140646&r1=140645&r2=140646&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/LLVMTargetMachine.cpp (original)
+++ llvm/trunk/lib/CodeGen/LLVMTargetMachine.cpp Tue Sep 27 17:14:12 2011
@@ -45,6 +45,9 @@
   bool EnableFastISel;
 }
 
+static cl::opt<bool> DisableOldSjLjEH("disable-old-sjlj-eh", cl::Hidden,
+    cl::desc("Disable the old SjLj EH preparation pass"));
+
 static cl::opt<bool> DisablePostRA("disable-post-ra", cl::Hidden,
     cl::desc("Disable Post Regalloc"));
 static cl::opt<bool> DisableBranchFold("disable-branch-fold", cl::Hidden,
@@ -322,7 +325,8 @@
     // removed from the parent invoke(s). This could happen when a landing
     // pad is shared by multiple invokes and is also a target of a normal
     // edge from elsewhere.
-    PM.add(createSjLjEHPass(getTargetLowering()));
+    if (!DisableOldSjLjEH)
+      PM.add(createSjLjEHPass(getTargetLowering()));
     // FALLTHROUGH
   case ExceptionHandling::DwarfCFI:
   case ExceptionHandling::ARM:

Modified: llvm/trunk/lib/Target/ARM/ARM.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/ARM.h?rev=140646&r1=140645&r2=140646&view=diff
==============================================================================
--- llvm/trunk/lib/Target/ARM/ARM.h (original)
+++ llvm/trunk/lib/Target/ARM/ARM.h Tue Sep 27 17:14:12 2011
@@ -41,6 +41,7 @@
 FunctionPass *createARMExpandPseudoPass();
 FunctionPass *createARMGlobalMergePass(const TargetLowering* tli);
 FunctionPass *createARMConstantIslandPass();
+FunctionPass *createARMSjLjLoweringPass();
 FunctionPass *createNEONMoveFixPass();
 FunctionPass *createMLxExpansionPass();
 FunctionPass *createThumb2ITBlockPass();

Added: llvm/trunk/lib/Target/ARM/ARMSjLjLoweringPass.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/ARMSjLjLoweringPass.cpp?rev=140646&view=auto
==============================================================================
--- llvm/trunk/lib/Target/ARM/ARMSjLjLoweringPass.cpp (added)
+++ llvm/trunk/lib/Target/ARM/ARMSjLjLoweringPass.cpp Tue Sep 27 17:14:12 2011
@@ -0,0 +1,118 @@
+//===-- ARMSjLjLoweringPass.cpp - ARM SjLj Lowering Pass ------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file contains a pass that lowers the SjLj exception handling into
+// machine instructions.
+//
+//===----------------------------------------------------------------------===//
+
+#define DEBUG_TYPE "arm-sjlj-lowering"
+#include "ARM.h"
+#include "llvm/Function.h"
+#include "llvm/CodeGen/MachineFrameInfo.h"
+#include "llvm/CodeGen/MachineFunction.h"
+#include "llvm/CodeGen/MachineFunctionPass.h"
+#include "llvm/Target/TargetData.h"
+#include "llvm/Target/TargetLowering.h"
+#include "llvm/Support/CommandLine.h"
+using namespace llvm;
+
+// Hidden options for the new EH stuff.
+static cl::opt<bool>
+EnableNewSjLjEHPrepare("enable-new-sjlj-eh", cl::Hidden,
+                       cl::desc("Use the new SjLj EH preparation pass"));
+
+namespace {
+
+class ARMSjLjLowering : public MachineFunctionPass {
+  Type *FunctionCtxTy;
+  LLVMContext *Context;
+
+  MachineFunction *MF;
+  const Function *Fn;
+  const TargetLowering *TLI;
+  const TargetInstrInfo *TII;
+  const TargetRegisterInfo *TRI;
+
+  /// createFunctionContext - Create the function context on the stack. This
+  /// returns the nonnegative identifier representing it in the FrameInfo.
+  int createFunctionContext();
+
+public:
+  static char ID;
+  ARMSjLjLowering() : MachineFunctionPass(ID) {}
+
+  virtual bool runOnMachineFunction(MachineFunction &mf);
+
+  virtual const char *getPassName() const {
+    return "ARM setjmp/longjmp exception handling lowering pass";
+  }
+};
+
+char ARMSjLjLowering::ID = 0;
+
+} // end anonymous namespace
+
+FunctionPass *llvm::createARMSjLjLoweringPass() {
+  return new ARMSjLjLowering();
+}
+
+bool ARMSjLjLowering::runOnMachineFunction(MachineFunction &mf) {
+  if (!EnableNewSjLjEHPrepare) return false;
+
+  MF = &mf;
+  Fn = MF->getFunction();
+  Context = &Fn->getContext();
+  TLI = MF->getTarget().getTargetLowering();
+  TII = MF->getTarget().getInstrInfo();
+  TRI = MF->getTarget().getRegisterInfo();
+
+  int FrameIdx = createFunctionContext(); (void)FrameIdx;
+
+  return true;
+}
+
+/// createFunctionContext - Create the function context on the stack.
+int ARMSjLjLowering::createFunctionContext() {
+  // struct _Unwind_FunctionContext {
+  //   // next function in stack of handlers.
+  //   struct _Unwind_FunctionContext *prev;
+  //
+  //   // set by calling function before registering to be the landing pad.
+  //   uintptr_t resumeLocation;
+  //
+  //   // set by personality handler to be parameters passed to landing pad
+  //   // function.
+  //   uintptr_t resumeParameters[4];
+  //
+  //   // set by calling function before registering
+  //   __personality_routine personality;  // arm offset=24
+  //
+  //   uintptr_t lsda                      // arm offset=28
+  //
+  //   // variable length array, contains registers to restore
+  //   // 0 = r7, 1 = pc, 2 = sp
+  //   void *jbuf[];  // 5 for GCC compatibility.
+  // };
+  Type *VoidPtrTy = Type::getInt8PtrTy(*Context);
+  Type *Int32Ty = Type::getInt32Ty(*Context);
+  FunctionCtxTy =
+    StructType::get(VoidPtrTy,                        // prev
+                    Int32Ty,                          // resumeLocation
+                    ArrayType::get(Int32Ty, 4),       // resumeParameters
+                    VoidPtrTy,                        // personality
+                    VoidPtrTy,                        // lsda
+                    ArrayType::get(VoidPtrTy, 5),     // jbuf
+                    NULL);
+
+  uint64_t TySize = TLI->getTargetData()->getTypeAllocSize(FunctionCtxTy);
+  unsigned Align = TLI->getTargetData()->getPrefTypeAlignment(FunctionCtxTy);
+
+  return MF->getFrameInfo()->CreateStackObject(TySize, Align, false, false);
+}

Modified: llvm/trunk/lib/Target/ARM/ARMTargetMachine.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/ARMTargetMachine.cpp?rev=140646&r1=140645&r2=140646&view=diff
==============================================================================
--- llvm/trunk/lib/Target/ARM/ARMTargetMachine.cpp (original)
+++ llvm/trunk/lib/Target/ARM/ARMTargetMachine.cpp Tue Sep 27 17:14:12 2011
@@ -15,6 +15,7 @@
 #include "ARM.h"
 #include "llvm/PassManager.h"
 #include "llvm/CodeGen/Passes.h"
+#include "llvm/MC/MCAsmInfo.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/FormattedStream.h"
 #include "llvm/Support/TargetRegistry.h"
@@ -107,7 +108,8 @@
     PM.add(createARMLoadStoreOptimizationPass(true));
   if (OptLevel != CodeGenOpt::None && Subtarget.isCortexA9())
     PM.add(createMLxExpansionPass());
-
+  if (getMCAsmInfo()->getExceptionHandlingType() == ExceptionHandling::SjLj)
+    createARMSjLjLoweringPass();
   return true;
 }
 





More information about the llvm-commits mailing list