re-commit r66920 (which has been backed out in r66953) I may have more luck this...
authorGabor Greif <ggreif@gmail.com>
Thu, 3 Sep 2009 00:18:58 +0000 (00:18 +0000)
committerGabor Greif <ggreif@gmail.com>
Thu, 3 Sep 2009 00:18:58 +0000 (00:18 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@80858 91177308-0d34-0410-b5e6-96231b3b80d8

12 files changed:
include/llvm/Instructions.h
include/llvm/Support/CallSite.h
lib/Analysis/IPA/Andersens.cpp
lib/Analysis/IPA/GlobalsModRef.cpp
lib/Bitcode/Writer/BitcodeWriter.cpp
lib/Transforms/IPO/DeadArgumentElimination.cpp
lib/Transforms/IPO/PruneEH.cpp
lib/Transforms/Scalar/SimplifyCFGPass.cpp
lib/Transforms/Utils/LowerInvoke.cpp
lib/VMCore/AsmWriter.cpp
lib/VMCore/Instructions.cpp
lib/VMCore/Verifier.cpp

index e6f1c54483a1b11d04ef9307d7775d2baa2503f2..ee5af697619fb66902199c56a0990a1f4724625c 100644 (file)
@@ -2466,27 +2466,26 @@ public:
   /// indirect function invocation.
   ///
   Function *getCalledFunction() const {
-    return dyn_cast<Function>(getOperand(0));
+    return dyn_cast<Function>(Op<-3>());
   }
 
   /// getCalledValue - Get a pointer to the function that is invoked by this
   /// instruction
-  const Value *getCalledValue() const { return getOperand(0); }
-        Value *getCalledValue()       { return getOperand(0); }
+  const Value *getCalledValue() const { return Op<-3>(); }
+        Value *getCalledValue()       { return Op<-3>(); }
 
   // get*Dest - Return the destination basic blocks...
   BasicBlock *getNormalDest() const {
-    return cast<BasicBlock>(getOperand(1));
+    return cast<BasicBlock>(Op<-2>());
   }
   BasicBlock *getUnwindDest() const {
-    return cast<BasicBlock>(getOperand(2));
+    return cast<BasicBlock>(Op<-1>());
   }
   void setNormalDest(BasicBlock *B) {
-    setOperand(1, B);
+    Op<-2>() = B;
   }
-
   void setUnwindDest(BasicBlock *B) {
-    setOperand(2, B);
+    Op<-1>() = B;
   }
 
   BasicBlock *getSuccessor(unsigned i) const {
@@ -2496,7 +2495,7 @@ public:
 
   void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
     assert(idx < 2 && "Successor # out of range for invoke!");
-    setOperand(idx+1, NewSucc);
+    *(&Op<-2>() + idx) = NewSucc;
   }
 
   unsigned getNumSuccessors() const { return 2; }
@@ -2509,6 +2508,7 @@ public:
   static inline bool classof(const Value *V) {
     return isa<Instruction>(V) && classof(cast<Instruction>(V));
   }
+
 private:
   virtual BasicBlock *getSuccessorV(unsigned idx) const;
   virtual unsigned getNumSuccessorsV() const;
index 285b558afccbae1f4acd669e1250cf2dfd803b63..5bfcc6d84ffa4561458b1fda0cb7c6eeac503fbf 100644 (file)
@@ -118,7 +118,7 @@ public:
   ///
   Value *getCalledValue() const {
     assert(getInstruction() && "Not a call or invoke instruction!");
-    return getInstruction()->getOperand(0);
+    return *getCallee();
   }
 
   /// getCalledFunction - Return the function being called if this is a direct
@@ -132,7 +132,7 @@ public:
   ///
   void setCalledFunction(Value *V) {
     assert(getInstruction() && "Not a call or invoke instruction!");
-    getInstruction()->setOperand(0, V);
+    *getCallee() = V;
   }
 
   Value *getArgument(unsigned ArgNo) const {
@@ -146,6 +146,16 @@ public:
     getInstruction()->setOperand(getArgumentOffset() + ArgNo, newVal);
   }
 
+  /// Given a value use iterator, returns the argument that corresponds to it.
+  /// Iterator must actually correspond to an argument.
+  unsigned getArgumentNo(Value::use_iterator I) const {
+    assert(getInstruction() && "Not a call or invoke instruction!");
+    assert(arg_begin() <= &I.getUse() && &I.getUse() < arg_end()
+           && "Argument # out of range!");
+
+    return &I.getUse() - arg_begin();
+  }
+
   /// Given an operand number, returns the argument that corresponds to it.
   /// OperandNo must be a valid operand number that actually corresponds to an
   /// argument.
@@ -171,7 +181,7 @@ public:
     return getInstruction()->op_begin() + getArgumentOffset();
   }
 
-  arg_iterator arg_end() const { return getInstruction()->op_end(); }
+  arg_iterator arg_end() const { return getInstruction()->op_end() - getArgumentEndOffset(); }
   bool arg_empty() const { return arg_end() == arg_begin(); }
   unsigned arg_size() const { return unsigned(arg_end() - arg_begin()); }
 
@@ -180,17 +190,25 @@ public:
   }
 
   bool isCallee(Value::use_iterator UI) const {
-    return getInstruction()->op_begin() == &UI.getUse();
+    return getCallee() == &UI.getUse();
   }
-
 private:
   /// Returns the operand number of the first argument
   unsigned getArgumentOffset() const {
     if (isCall())
       return 1; // Skip Function
     else
-      return 3; // Skip Function, BB, BB
+      return 0; // Args are at the front
   }
+
+  unsigned getArgumentEndOffset() const {
+    if (isCall())
+      return 0; // Unchanged
+    else
+      return 3; // Skip BB, BB, Function
+  }
+
+  User::op_iterator getCallee() const;
 };
 
 } // End llvm namespace
index 9de1fcc5c199f5344e6b7a4ec9b9ce69400f8c60..6f21a4f2ed942a184dd65ae5cf4c2ed86d91ac7e 100644 (file)
@@ -1018,7 +1018,7 @@ bool Andersens::AnalyzeUsesOfFunction(Value *V) {
     } else if (InvokeInst *II = dyn_cast<InvokeInst>(*UI)) {
       // Make sure that this is just the function being called, not that it is
       // passing into the function.
-      for (unsigned i = 3, e = II->getNumOperands(); i != e; ++i)
+      for (unsigned i = 0, e = II->getNumOperands() - 3; i != e; ++i)
         if (II->getOperand(i) == V) return true;
     } else if (ConstantExpr *CE = dyn_cast<ConstantExpr>(*UI)) {
       if (CE->getOpcode() == Instruction::GetElementPtr ||
index 2e9884aa01b404069c98ffc0e67abc790b3f5470..bfc6e117bdc4aabdbd6c5f9a86a22aeee23c8746 100644 (file)
@@ -244,7 +244,7 @@ bool GlobalsModRef::AnalyzeUsesOfPointer(Value *V,
     } else if (InvokeInst *II = dyn_cast<InvokeInst>(*UI)) {
       // Make sure that this is just the function being called, not that it is
       // passing into the function.
-      for (unsigned i = 3, e = II->getNumOperands(); i != e; ++i)
+      for (unsigned i = 0, e = II->getNumOperands() - 3; i != e; ++i)
         if (II->getOperand(i) == V) return true;
     } else if (ConstantExpr *CE = dyn_cast<ConstantExpr>(*UI)) {
       if (CE->getOpcode() == Instruction::GetElementPtr ||
index 9cb57585762cd938a51ef8c71f4ed77d318a5f50..3ea963174855ae4d13d357b7ea6cb43cce937d37 100644 (file)
@@ -960,11 +960,11 @@ static void WriteInstruction(const Instruction &I, unsigned InstID,
     
     // Emit value #'s for the fixed parameters.
     for (unsigned i = 0, e = FTy->getNumParams(); i != e; ++i)
-      Vals.push_back(VE.getValueID(I.getOperand(i+3)));  // fixed param.
+      Vals.push_back(VE.getValueID(I.getOperand(i)));  // fixed param.
 
     // Emit type/value pairs for varargs params.
     if (FTy->isVarArg()) {
-      for (unsigned i = 3+FTy->getNumParams(), e = I.getNumOperands();
+      for (unsigned i = FTy->getNumParams(), e = I.getNumOperands()-3;
            i != e; ++i)
         PushValueAndType(I.getOperand(i), InstID, Vals, VE); // vararg
     }
index 79a32f02aace813611df9b3c7e66c1421517edbc..ca11e2d8fd35abdca6c1e4d32648013d31597d52 100644 (file)
@@ -353,14 +353,14 @@ DAE::Liveness DAE::SurveyUse(Value::use_iterator U, UseVector &MaybeLiveUses,
         // argument, since if it was the function argument this would be an
         // indirect call and the we know can't be looking at a value of the
         // label type (for the invoke instruction).
-        unsigned ArgNo = CS.getArgumentNo(U.getOperandNo());
+        unsigned ArgNo = CS.getArgumentNo(U);
 
         if (ArgNo >= F->getFunctionType()->getNumParams())
           // The value is passed in through a vararg! Must be live.
           return Live;
 
-        assert(CS.getArgument(ArgNo) 
-               == CS.getInstruction()->getOperand(U.getOperandNo()) 
+        assert(CS.getArgument(ArgNo)
+               == CS.getInstruction()->getOperand(U.getOperandNo())
                && "Argument is not where we expected it");
 
         // Value passed to a normal call. It's only live when the corresponding
index daf81e9259da50fb54ed6cb2442c50ca38a61eb9..4533f892f55b007b2dca946d739c677a174c1825 100644 (file)
@@ -169,7 +169,7 @@ bool PruneEH::SimplifyFunction(Function *F) {
   for (Function::iterator BB = F->begin(), E = F->end(); BB != E; ++BB) {
     if (InvokeInst *II = dyn_cast<InvokeInst>(BB->getTerminator()))
       if (II->doesNotThrow()) {
-        SmallVector<Value*, 8> Args(II->op_begin()+3, II->op_end());
+        SmallVector<Value*, 8> Args(II->op_begin(), II->op_end() - 3);
         // Insert a call instruction before the invoke.
         CallInst *Call = CallInst::Create(II->getCalledValue(),
                                           Args.begin(), Args.end(), "", II);
index 29712b3c13de82d9c025f9f30ea08b684f0530e1..d565eb5e8343d702de926b3fd742627188f90454 100644 (file)
@@ -78,7 +78,7 @@ static void ChangeToUnreachable(Instruction *I, LLVMContext &Context) {
 /// ChangeToCall - Convert the specified invoke into a normal call.
 static void ChangeToCall(InvokeInst *II) {
   BasicBlock *BB = II->getParent();
-  SmallVector<Value*, 8> Args(II->op_begin()+3, II->op_end());
+  SmallVector<Value*, 8> Args(II->op_begin(), II->op_end() - 3);
   CallInst *NewCall = CallInst::Create(II->getCalledValue(), Args.begin(),
                                        Args.end(), "", II);
   NewCall->takeName(II);
index 4ecf6d7ba2604de466159f46f244059e8912c377..788a2514db2552cacab6486510140300a21b2839 100644 (file)
@@ -228,7 +228,7 @@ bool LowerInvoke::insertCheapEHSupport(Function &F) {
   bool Changed = false;
   for (Function::iterator BB = F.begin(), E = F.end(); BB != E; ++BB)
     if (InvokeInst *II = dyn_cast<InvokeInst>(BB->getTerminator())) {
-      std::vector<Value*> CallArgs(II->op_begin()+3, II->op_end());
+      std::vector<Value*> CallArgs(II->op_begin(), II->op_end() - 3);
       // Insert a normal call instruction...
       CallInst *NewCall = CallInst::Create(II->getCalledValue(),
                                            CallArgs.begin(), CallArgs.end(), "",II);
@@ -300,7 +300,7 @@ void LowerInvoke::rewriteExpensiveInvoke(InvokeInst *II, unsigned InvokeNo,
   CatchSwitch->addCase(InvokeNoC, II->getUnwindDest());
 
   // Insert a normal call instruction.
-  std::vector<Value*> CallArgs(II->op_begin()+3, II->op_end());
+  std::vector<Value*> CallArgs(II->op_begin(), II->op_end() - 3);
   CallInst *NewCall = CallInst::Create(II->getCalledValue(),
                                        CallArgs.begin(), CallArgs.end(), "",
                                        II);
index 5062075a46c2f9b764109036b937e0858d7677be..5d5c2e36558cd6c812c5a8da1403354604b01e7c 100644 (file)
@@ -1863,6 +1863,7 @@ void AssemblyWriter::printInstruction(const Instruction &I) {
     if (PAL.getFnAttributes() != Attribute::None)
       Out << ' ' << Attribute::getAsString(PAL.getFnAttributes());
   } else if (const InvokeInst *II = dyn_cast<InvokeInst>(&I)) {
+    Operand = II->getCalledValue();
     const PointerType    *PTy = cast<PointerType>(Operand->getType());
     const FunctionType   *FTy = cast<FunctionType>(PTy->getElementType());
     const Type         *RetTy = FTy->getReturnType();
@@ -1899,10 +1900,10 @@ void AssemblyWriter::printInstruction(const Instruction &I) {
       writeOperand(Operand, true);
     }
     Out << '(';
-    for (unsigned op = 3, Eop = I.getNumOperands(); op < Eop; ++op) {
-      if (op > 3)
+    for (unsigned op = 0, Eop = I.getNumOperands() - 3; op < Eop; ++op) {
+      if (op)
         Out << ", ";
-      writeParamOperand(I.getOperand(op), PAL.getParamAttributes(op-2));
+      writeParamOperand(I.getOperand(op), PAL.getParamAttributes(op + 1));
     }
 
     Out << ')';
index a12075fe0d9ff5c752bef9770a7bbc92efc46405..d5847ef49362d51809098e0467d2d46f3aa58bf4 100644 (file)
@@ -95,6 +95,13 @@ bool CallSite::hasArgument(const Value *Arg) const {
   return false;
 }
 
+User::op_iterator CallSite::getCallee() const {
+  Instruction *II(getInstruction());
+  return isCall()
+    ? cast<CallInst>(II)->op_begin()
+    : cast<InvokeInst>(II)->op_end() - 3; // Skip BB, BB, Function
+}
+
 #undef CALLSITE_DELEGATE_GETTER
 #undef CALLSITE_DELEGATE_SETTER
 
@@ -435,10 +442,9 @@ bool CallInst::paramHasAttr(unsigned i, Attributes attr) const {
 void InvokeInst::init(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
                       Value* const *Args, unsigned NumArgs) {
   assert(NumOperands == 3+NumArgs && "NumOperands not set up?");
-  Use *OL = OperandList;
-  OL[0] = Fn;
-  OL[1] = IfNormal;
-  OL[2] = IfException;
+  Op<-3>() = Fn;
+  Op<-2>() = IfNormal;
+  Op<-1>() = IfException;
   const FunctionType *FTy =
     cast<FunctionType>(cast<PointerType>(Fn->getType())->getElementType());
   FTy = FTy;  // silence warning.
@@ -447,12 +453,13 @@ void InvokeInst::init(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
           (FTy->isVarArg() && NumArgs > FTy->getNumParams())) &&
          "Calling a function with bad signature");
 
+  Use *OL = OperandList;
   for (unsigned i = 0, e = NumArgs; i != e; i++) {
     assert((i >= FTy->getNumParams() || 
             FTy->getParamType(i) == Args[i]->getType()) &&
            "Invoking a function with a bad signature!");
     
-    OL[i+3] = Args[i];
+    OL[i] = Args[i];
   }
 }
 
index eed4e2d7a67d20a6f93a139b6decd31028ca59de..99f54e5a975bc947ff86746423e74e77c4078a84 100644 (file)
@@ -1412,7 +1412,7 @@ void Verifier::visitInstruction(Instruction &I) {
                 "Instruction does not dominate all uses!", Op, &I);
       }
     } else if (isa<InlineAsm>(I.getOperand(i))) {
-      Assert1(i == 0 && (isa<CallInst>(I) || isa<InvokeInst>(I)),
+      Assert1((i == 0 && isa<CallInst>(I)) || (i + 3 == e && isa<InvokeInst>(I)),
               "Cannot take the address of an inline asm!", &I);
     }
   }