[llvm-commits] CVS: llvm/lib/Transforms/Scalar/LowerInvoke.cpp

Chris Lattner lattner at cs.uiuc.edu
Sat Nov 13 11:07:47 PST 2004



Changes in directory llvm/lib/Transforms/Scalar:

LowerInvoke.cpp updated: 1.19 -> 1.20
---
Log message:

Lazily create the abort message, so only translation units that use unwind
will actually get it.


---
Diffs of the changes:  (+31 -22)

Index: llvm/lib/Transforms/Scalar/LowerInvoke.cpp
diff -u llvm/lib/Transforms/Scalar/LowerInvoke.cpp:1.19 llvm/lib/Transforms/Scalar/LowerInvoke.cpp:1.20
--- llvm/lib/Transforms/Scalar/LowerInvoke.cpp:1.19	Fri Nov 12 16:42:57 2004
+++ llvm/lib/Transforms/Scalar/LowerInvoke.cpp	Sat Nov 13 13:07:32 2004
@@ -66,6 +66,7 @@
     bool doInitialization(Module &M);
     bool runOnFunction(Function &F);
   private:
+    void createAbortMessage();
     void writeAbortMessage(Instruction *IB);
     bool insertCheapEHSupport(Function &F);
     bool insertExpensiveEHSupport(Function &F);
@@ -119,7 +120,34 @@
     LongJmpFn = M.getOrInsertFunction("llvm.longjmp", Type::VoidTy,
                                       PointerType::get(JmpBufTy),
                                       Type::IntTy, 0);
+  }
+
+  // We need the 'write' and 'abort' functions for both models.
+  AbortFn = M.getOrInsertFunction("abort", Type::VoidTy, 0);
 
+  // Unfortunately, 'write' can end up being prototyped in several different
+  // ways.  If the user defines a three (or more) operand function named 'write'
+  // we will use their prototype.  We _do not_ want to insert another instance
+  // of a write prototype, because we don't know that the funcresolve pass will
+  // run after us.  If there is a definition of a write function, but it's not
+  // suitable for our uses, we just don't emit write calls.  If there is no
+  // write prototype at all, we just add one.
+  if (Function *WF = M.getNamedFunction("write")) {
+    if (WF->getFunctionType()->getNumParams() > 3 ||
+        WF->getFunctionType()->isVarArg())
+      WriteFn = WF;
+    else
+      WriteFn = 0;
+  } else {
+    WriteFn = M.getOrInsertFunction("write", Type::VoidTy, Type::IntTy,
+                                    VoidPtrTy, Type::IntTy, 0);
+  }
+  return true;
+}
+
+void LowerInvoke::createAbortMessage() {
+  Module &M = *WriteFn->getParent();
+  if (ExpensiveEHSupport) {
     // The abort message for expensive EH support tells the user that the
     // program 'unwound' without an 'invoke' instruction.
     Constant *Msg =
@@ -145,32 +173,13 @@
     std::vector<Constant*> GEPIdx(2, Constant::getNullValue(Type::LongTy));
     AbortMessage = ConstantExpr::getGetElementPtr(MsgGV, GEPIdx);
   }
-
-  // We need the 'write' and 'abort' functions for both models.
-  AbortFn = M.getOrInsertFunction("abort", Type::VoidTy, 0);
-
-  // Unfortunately, 'write' can end up being prototyped in several different
-  // ways.  If the user defines a three (or more) operand function named 'write'
-  // we will use their prototype.  We _do not_ want to insert another instance
-  // of a write prototype, because we don't know that the funcresolve pass will
-  // run after us.  If there is a definition of a write function, but it's not
-  // suitable for our uses, we just don't emit write calls.  If there is no
-  // write prototype at all, we just add one.
-  if (Function *WF = M.getNamedFunction("write")) {
-    if (WF->getFunctionType()->getNumParams() > 3 ||
-        WF->getFunctionType()->isVarArg())
-      WriteFn = WF;
-    else
-      WriteFn = 0;
-  } else {
-    WriteFn = M.getOrInsertFunction("write", Type::VoidTy, Type::IntTy,
-                                    VoidPtrTy, Type::IntTy, 0);
-  }
-  return true;
 }
 
+
 void LowerInvoke::writeAbortMessage(Instruction *IB) {
   if (WriteFn) {
+    if (AbortMessage == 0) createAbortMessage();
+
     // These are the arguments we WANT...
     std::vector<Value*> Args;
     Args.push_back(ConstantInt::get(Type::IntTy, 2));






More information about the llvm-commits mailing list