[llvm-branch-commits] [llvm-branch] r105267 - in /llvm/branches/wendling/eh: include/llvm/Instructions.h include/llvm/Support/CallSite.h lib/VMCore/AsmWriter.cpp lib/VMCore/Instructions.cpp lib/VMCore/Verifier.cpp

Bill Wendling isanbard at gmail.com
Tue Jun 1 00:37:59 PDT 2010


Author: void
Date: Tue Jun  1 02:37:59 2010
New Revision: 105267

URL: http://llvm.org/viewvc/llvm-project?rev=105267&view=rev
Log:
- Add support in the bitcode reader/writer for writing and reading the new
  invoke instruction.

- Make the catch-all type and destination member variables of the InvokeInst
  class. The new "Op<#>" operand encoding scheme and the verifier doesn't like
  null operands. But the catch-all is optional, so potentially null

I can now assemble and disassemble a .ll file using the new syntax!

Modified:
    llvm/branches/wendling/eh/include/llvm/Instructions.h
    llvm/branches/wendling/eh/include/llvm/Support/CallSite.h
    llvm/branches/wendling/eh/lib/VMCore/AsmWriter.cpp
    llvm/branches/wendling/eh/lib/VMCore/Instructions.cpp
    llvm/branches/wendling/eh/lib/VMCore/Verifier.cpp

Modified: llvm/branches/wendling/eh/include/llvm/Instructions.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/wendling/eh/include/llvm/Instructions.h?rev=105267&r1=105266&r2=105267&view=diff
==============================================================================
--- llvm/branches/wendling/eh/include/llvm/Instructions.h (original)
+++ llvm/branches/wendling/eh/include/llvm/Instructions.h Tue Jun  1 02:37:59 2010
@@ -2366,6 +2366,9 @@
   unsigned ReservedSpace;
   unsigned NumCatches;
 
+  Value *CatchAllType;
+  BasicBlock *CatchAllDest;
+
   AttrListPtr AttributeList;
   InvokeInst(const InvokeInst &BI);
   void init(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
@@ -2427,7 +2430,7 @@
                             InputIterator ArgBegin, InputIterator ArgEnd,
                             const Twine &NameStr = "",
                             Instruction *InsertBefore = 0) {
-    unsigned Values(ArgEnd - ArgBegin + 6);
+    unsigned Values(ArgEnd - ArgBegin + 4);
     return new(Values) InvokeInst(Func, IfNormal, IfException, PersFn,
                                   CatchAllTy, CatchAll, NumCatches,
                                   ArgBegin, ArgEnd,
@@ -2441,7 +2444,7 @@
                             InputIterator ArgBegin, InputIterator ArgEnd,
                             const Twine &NameStr,
                             BasicBlock *InsertAtEnd) {
-    unsigned Values(ArgEnd - ArgBegin + 6);
+    unsigned Values(ArgEnd - ArgBegin + 4);
     return new(Values) InvokeInst(Func, IfNormal, IfException, PersFn,
                                   CatchAllTy, CatchAll, NumCatches,
                                   ArgBegin, ArgEnd,
@@ -2541,50 +2544,50 @@
   /// indirect function invocation.
   ///
   Function *getCalledFunction() const {
-    return dyn_cast<Function>(Op<-6>());
+    return dyn_cast<Function>(Op<-4>());
   }
 
   /// getCalledValue - Get a pointer to the function that is invoked by this
   /// instruction
-  const Value *getCalledValue() const { return Op<-6>(); }
-        Value *getCalledValue()       { return Op<-6>(); }
+  const Value *getCalledValue() const { return Op<-4>(); }
+        Value *getCalledValue()       { return Op<-4>(); }
 
   /// setCalledFunction - Set the function called.
   void setCalledFunction(Value* Fn) {
-    Op<-6>() = Fn;
+    Op<-4>() = Fn;
   }
 
   // Getter/Setters for EH information from the invoke statement.
   BasicBlock *getNormalDest() const {
-    return cast<BasicBlock>(Op<-5>());
+    return cast<BasicBlock>(Op<-3>());
   }
   void setNormalDest(BasicBlock *B) {
-    Op<-5>() = reinterpret_cast<Value*>(B);
+    Op<-3>() = reinterpret_cast<Value*>(B);
   }
   BasicBlock *getUnwindDest() const {
-    return cast<BasicBlock>(Op<-4>());
+    return cast<BasicBlock>(Op<-2>());
   }
   void setUnwindDest(BasicBlock *B) {
-    Op<-4>() = reinterpret_cast<Value*>(B);
+    Op<-2>() = reinterpret_cast<Value*>(B);
   }
 
   Value *getPersonalityFn() const {
-    return Op<-3>();
+    return Op<-1>();
   }
   void setPersonalityFn(Value *V) {
-    Op<-3>() = V;
+    Op<-1>() = V;
   }
   Value *getCatchAllType() const {
-    return Op<-2>();
+    return CatchAllType;
   }
   void setCatchAllType(Value *V) {
-    Op<-2>() = V;
+    CatchAllType = V;
   }
   BasicBlock *getCatchAllDest() const {
-    return cast<BasicBlock>(Op<-1>());
+    return CatchAllDest;
   }
   void setCatchAllDest(BasicBlock *B) {
-    Op<-1>() = reinterpret_cast<Value*>(B);
+    CatchAllDest = B;
   }
 
   /// getNumCatches - Return the number of catch blocks for this invoke
@@ -2598,7 +2601,7 @@
     assert(I < getNumCatches() && "Illegal catch type to get!");
     return CatchList[I * 2];
   }
-  const Value *getCatchType(unsigned I) const {
+  Value *getCatchType(unsigned I) const {
     assert(I < getNumCatches() && "Illegal catch type to get!");
     return CatchList[I * 2];
   }
@@ -2608,7 +2611,7 @@
     assert(I < getNumCatches() && "Illegal catch destination to get!");
     return cast<BasicBlock>(CatchList[I * 2 + 1]);
   }
-  const BasicBlock *getCatchDest(unsigned I) const {
+  BasicBlock *getCatchDest(unsigned I) const {
     assert(I < getNumCatches() && "Illegal catch destination to get!");
     return cast<BasicBlock>(CatchList[I * 2 + 1]);
   }
@@ -2618,16 +2621,25 @@
 
   // Successor accessors.
   BasicBlock *getSuccessor(unsigned i) const {
-    assert(i < 2 && "Successor # out of range for invoke!");
-    return i == 0 ? getNormalDest() : getUnwindDest();
+    assert(i < 2 + getNumCatches() && "Successor # out of range for invoke!");
+
+    if (i == 0)
+      return getNormalDest();
+
+    if (i == 1)
+      return getUnwindDest();
+
+    return getCatchDest(i - 2);
   }
 
   void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
     assert(idx < 2 && "Successor # out of range for invoke!");
-    *(&Op<-5>() + idx) = reinterpret_cast<Value*>(NewSucc);
+    *(&Op<-3>() + idx) = reinterpret_cast<Value*>(NewSucc);
   }
 
-  unsigned getNumSuccessors() const { return 2; }
+  unsigned getNumSuccessors() const {
+    return 2 + getNumCatches();
+  }
 
   // Methods for support type inquiry through isa, cast, and dyn_cast:
   static inline bool classof(const InvokeInst *) { return true; }

Modified: llvm/branches/wendling/eh/include/llvm/Support/CallSite.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/wendling/eh/include/llvm/Support/CallSite.h?rev=105267&r1=105266&r2=105267&view=diff
==============================================================================
--- llvm/branches/wendling/eh/include/llvm/Support/CallSite.h (original)
+++ llvm/branches/wendling/eh/include/llvm/Support/CallSite.h Tue Jun  1 02:37:59 2010
@@ -265,17 +265,18 @@
     if (isCall())
       return 0; // Unchanged (ATM)
     else
-      return 3; // Skip BB, BB, Function
+      // An invoke.
+      return 4; // Skip PersFn, BB, BB, Function
   }
 
   IterTy getCallee() const {
-      // FIXME: this is slow, since we do not have the fast versions
-      // of the op_*() functions here. See CallSite::getCallee.
-      //
+    // FIXME: this is slow, since we do not have the fast versions of the op_*()
+    // functions here. See CallSite::getCallee.
     if (isCall())
-      return getInstruction()->op_begin(); // Unchanged (ATM)
+      return getInstruction()->op_begin();   // Unchanged (ATM)
     else
-      return getInstruction()->op_end() - 3; // Skip BB, BB, Function
+      // An invoke.
+      return getInstruction()->op_end() - 4; // Skip PersFn, BB, BB, Function
   }
 };
 

Modified: llvm/branches/wendling/eh/lib/VMCore/AsmWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/wendling/eh/lib/VMCore/AsmWriter.cpp?rev=105267&r1=105266&r2=105267&view=diff
==============================================================================
--- llvm/branches/wendling/eh/lib/VMCore/AsmWriter.cpp (original)
+++ llvm/branches/wendling/eh/lib/VMCore/AsmWriter.cpp Tue Jun  1 02:37:59 2010
@@ -1890,13 +1890,13 @@
     const PointerType    *PTy = cast<PointerType>(Operand->getType());
     const FunctionType   *FTy = cast<FunctionType>(PTy->getElementType());
     const Type         *RetTy = FTy->getReturnType();
-    const AttrListPtr &PAL = II->getAttributes();
+    const AttrListPtr    &PAL = II->getAttributes();
 
     // Print the calling convention being used.
     switch (II->getCallingConv()) {
     case CallingConv::C: break;   // default
-    case CallingConv::Fast:  Out << " fastcc"; break;
-    case CallingConv::Cold:  Out << " coldcc"; break;
+    case CallingConv::Fast:         Out << " fastcc"; break;
+    case CallingConv::Cold:         Out << " coldcc"; break;
     case CallingConv::X86_StdCall:  Out << " x86_stdcallcc"; break;
     case CallingConv::X86_FastCall: Out << " x86_fastcallcc"; break;
     case CallingConv::X86_ThisCall: Out << " x86_thiscallcc"; break;
@@ -1925,7 +1925,7 @@
       writeOperand(Operand, true);
     }
     Out << '(';
-    for (unsigned op = 0, Eop = I.getNumOperands() - 3; op < Eop; ++op) {
+    for (unsigned op = 0, Eop = I.getNumOperands() - 4; op < Eop; ++op) {
       if (op)
         Out << ", ";
       writeParamOperand(I.getOperand(op), PAL.getParamAttributes(op + 1));

Modified: llvm/branches/wendling/eh/lib/VMCore/Instructions.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/wendling/eh/lib/VMCore/Instructions.cpp?rev=105267&r1=105266&r2=105267&view=diff
==============================================================================
--- llvm/branches/wendling/eh/lib/VMCore/Instructions.cpp (original)
+++ llvm/branches/wendling/eh/lib/VMCore/Instructions.cpp Tue Jun  1 02:37:59 2010
@@ -548,13 +548,11 @@
                       Value *PersFn, Value *CatchAllTy, BasicBlock *CatchAll,
                       unsigned NumCatches, Value * const *Args,
                       unsigned NumArgs) {
-  assert(NumOperands == 6 + NumArgs && "NumOperands not set up?");
-  Op<-6>() = Fn;
-  Op<-5>() = IfNormal;
-  Op<-4>() = IfException;
-  Op<-3>() = PersFn;
-  Op<-2>() = CatchAllTy;
-  Op<-1>() = CatchAll;
+  assert(NumOperands == 4 + NumArgs && "NumOperands not set up?");
+  Op<-4>() = Fn;
+  Op<-3>() = IfNormal;
+  Op<-2>() = IfException;
+  Op<-1>() = PersFn;
   const FunctionType *FTy =
     cast<FunctionType>(cast<PointerType>(Fn->getType())->getElementType());
   FTy = FTy;  // Silence warning.
@@ -563,6 +561,9 @@
           (FTy->isVarArg() && NumArgs > FTy->getNumParams())) &&
          "Invoking a function with bad signature");
 
+  CatchAllType = CatchAllTy;
+  CatchAllDest = CatchAll;
+
   // Allocate space for the catches.
   ReservedSpace = NumCatches * 2;
   this->NumCatches = 0;

Modified: llvm/branches/wendling/eh/lib/VMCore/Verifier.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/wendling/eh/lib/VMCore/Verifier.cpp?rev=105267&r1=105266&r2=105267&view=diff
==============================================================================
--- llvm/branches/wendling/eh/lib/VMCore/Verifier.cpp (original)
+++ llvm/branches/wendling/eh/lib/VMCore/Verifier.cpp Tue Jun  1 02:37:59 2010
@@ -1200,6 +1200,10 @@
 }
 
 void Verifier::visitInvokeInst(InvokeInst &II) {
+  for (unsigned I = 0, E = II.getNumCatches(); I != E; ++I)
+    Assert1(II.getCatchType(I) != 0 && II.getCatchDest(I) != 0,
+            "Catches are not correct in invoke instruction!", &II);
+
   VerifyCallSite(&II);
 }
 





More information about the llvm-branch-commits mailing list