add setJumpBufSize() and setJumpBufAlignment() to target-lowering.
authorDuraid Madina <duraid@octopus.com.au>
Mon, 4 Sep 2006 06:21:35 +0000 (06:21 +0000)
committerDuraid Madina <duraid@octopus.com.au>
Mon, 4 Sep 2006 06:21:35 +0000 (06:21 +0000)
Call these from your backend to enjoy setjmp/longjmp goodness, see
lib/Target/IA64/IA64ISelLowering.cpp for an example

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@30095 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Target/TargetLowering.h
include/llvm/Transforms/Scalar.h
lib/CodeGen/LLVMTargetMachine.cpp
lib/Target/IA64/IA64ISelLowering.cpp
lib/Transforms/Utils/LowerInvoke.cpp

index 3da8baa8670226fe45eac12df15228954311f656..6cecbbc4e587f692bec239bceb1eb4290e3c97f3 100644 (file)
@@ -327,6 +327,18 @@ public:
     return StackPointerRegisterToSaveRestore;
   }
 
+  /// getJumpBufSize - returns the target's jmp_buf size in bytes (if never
+  /// set, the default is 200)
+  unsigned getJumpBufSize() const {
+    return JumpBufSize;
+  }
+
+  /// getJumpBufAlignment - returns the target's jmp_buf alignment in bytes
+  /// (if never set, the default is 0)
+  unsigned getJumpBufAlignment() const {
+    return JumpBufAlignment;
+  }
+  
   //===--------------------------------------------------------------------===//
   // TargetLowering Optimization Methods
   //
@@ -537,6 +549,18 @@ protected:
     TargetDAGCombineArray[NT >> 3] |= 1 << (NT&7);
   }
   
+  /// setJumpBufSize - Set the target's required jmp_buf buffer size (in
+  /// bytes); default is 200
+  void setJumpBufSize(unsigned Size) {
+    JumpBufSize = Size;
+  }
+
+  /// setJumpBufAlignment - Set the target's required jmp_buf buffer
+  /// alignment (in bytes); default is 0
+  void setJumpBufAlignment(unsigned Align) {
+    JumpBufAlignment = Align;
+  }
+  
 public:
 
   //===--------------------------------------------------------------------===//
@@ -718,6 +742,13 @@ private:
   /// _longjmp to implement llvm.setjmp/llvm.longjmp.  Defaults to false.
   bool UseUnderscoreSetJmpLongJmp;
   
+  /// JumpBufSize - The size, in bytes, of the target's jmp_buf buffers
+  unsigned JumpBufSize;
+  
+  /// JumpBufAlignment - The alignment, in bytes, of the target's jmp_buf
+  /// buffers
+  unsigned JumpBufAlignment;
+  
   /// StackPointerRegisterToSaveRestore - If set to a physical register, this
   /// specifies the register that llvm.savestack/llvm.restorestack should save
   /// and restore.
index 077972f681d94240e05ca9ede66a269f4798f284..85242f8a77d6be8dd44bc775a3ecfd291a197cf9 100644 (file)
@@ -286,8 +286,7 @@ FunctionPass *createLowerPackedPass();
 // "my LLVM-to-LLVM pass doesn't support the invoke instruction yet" lowering
 // pass.
 //
-FunctionPass *createLowerInvokePass(unsigned JumBufSize = 200, 
-                                    unsigned JumpBufAlign = 0);
+FunctionPass *createLowerInvokePass(const TargetLowering *TLI = NULL);
 extern const PassInfo *LowerInvokePassID;
 
 
index 2f250c8a889785067427a80958432538a742138f..6c4544a11732ddd18bb83ee424de37ad74ecb53c 100644 (file)
@@ -33,7 +33,7 @@ bool LLVMTargetMachine::addPassesToEmitFile(FunctionPassManager &PM,
   PM.add(createLowerGCPass());
   
   // FIXME: Implement the invoke/unwind instructions!
-  PM.add(createLowerInvokePass());
+  PM.add(createLowerInvokePass(getTargetLowering()));
   
   // Make sure that no unreachable blocks are instruction selected.
   PM.add(createUnreachableBlockEliminationPass());
@@ -107,7 +107,7 @@ bool LLVMTargetMachine::addPassesToEmitMachineCode(FunctionPassManager &PM,
   PM.add(createLowerGCPass());
   
   // FIXME: Implement the invoke/unwind instructions!
-  PM.add(createLowerInvokePass());
+  PM.add(createLowerInvokePass(getTargetLowering()));
   
   // Make sure that no unreachable blocks are instruction selected.
   PM.add(createUnreachableBlockEliminationPass());
index 3693d858908278c3489b5347196df69fc2e95890..2a64570be885a840119fb05f657b583aa7b15fe4 100644 (file)
@@ -109,6 +109,9 @@ IA64TargetLowering::IA64TargetLowering(TargetMachine &TM)
 
       setStackPointerRegisterToSaveRestore(IA64::r12);
 
+      setJumpBufSize(704); // on ia64-linux, jmp_bufs are 704 bytes..
+      setJumpBufAlignment(16); // ...and must be 16-byte aligned
+      
       computeRegisterProperties();
 
       setOperationAction(ISD::ConstantFP, MVT::f64, Expand);
index 8702810837c2aad7557b3210b5ed0e01be2c60d0..73d703b7388ee33c45795512df9393b974797fc4 100644 (file)
@@ -45,6 +45,7 @@
 #include "llvm/ADT/Statistic.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/Compiler.h"
+#include "llvm/Target/TargetLowering.h"
 #include <csetjmp>
 using namespace llvm;
 
@@ -67,9 +68,12 @@ namespace {
     const Type *JBLinkTy;
     GlobalVariable *JBListHead;
     Function *SetJmpFn, *LongJmpFn;
+    
+    // We peek in TLI to grab the target's jmp_buf size and alignment
+    const TargetLowering *TLI;
+    
   public:
-    LowerInvoke(unsigned Size = 200, unsigned Align = 0) : JumpBufSize(Size),
-      JumpBufAlign(Align) {}
+    LowerInvoke(const TargetLowering *tli = NULL) : TLI(tli) { }
     bool doInitialization(Module &M);
     bool runOnFunction(Function &F);
  
@@ -89,9 +93,6 @@ namespace {
     void rewriteExpensiveInvoke(InvokeInst *II, unsigned InvokeNo,
                                 AllocaInst *InvokeNum, SwitchInst *CatchSwitch);
     bool insertExpensiveEHSupport(Function &F);
-    
-    unsigned JumpBufSize;
-    unsigned JumpBufAlign;
   };
 
   RegisterPass<LowerInvoke>
@@ -101,9 +102,8 @@ namespace {
 const PassInfo *llvm::LowerInvokePassID = X.getPassInfo();
 
 // Public Interface To the LowerInvoke pass.
-FunctionPass *llvm::createLowerInvokePass(unsigned JumpBufSize, 
-                                          unsigned JumpBufAlign) { 
-  return new LowerInvoke(JumpBufSize, JumpBufAlign); 
+FunctionPass *llvm::createLowerInvokePass(const TargetLowering *TLI) { 
+  return new LowerInvoke(TLI); 
 }
 
 // doInitialization - Make sure that there is a prototype for abort in the
@@ -113,7 +113,7 @@ bool LowerInvoke::doInitialization(Module &M) {
   AbortMessage = 0;
   if (ExpensiveEHSupport) {
     // Insert a type for the linked list of jump buffers.
-    const Type *JmpBufTy = ArrayType::get(VoidPtrTy, JumpBufSize);
+    const Type *JmpBufTy = ArrayType::get(VoidPtrTy, TLI->getJumpBufSize());
 
     { // The type is recursive, so use a type holder.
       std::vector<const Type*> Elements;
@@ -453,7 +453,7 @@ bool LowerInvoke::insertExpensiveEHSupport(Function &F) {
     // that needs to be restored on all exits from the function.  This is an
     // alloca because the value needs to be live across invokes.
     AllocaInst *JmpBuf = 
-      new AllocaInst(JBLinkTy, 0, JumpBufAlign, "jblink", F.begin()->begin());
+      new AllocaInst(JBLinkTy, 0, TLI->getJumpBufAlignment(), "jblink", F.begin()->begin());
     
     std::vector<Value*> Idx;
     Idx.push_back(Constant::getNullValue(Type::IntTy));