Add a setCalledFunction member to InvokeInst (like in CallInst)
authorGabor Greif <ggreif@gmail.com>
Sat, 20 Mar 2010 21:00:25 +0000 (21:00 +0000)
committerGabor Greif <ggreif@gmail.com>
Sat, 20 Mar 2010 21:00:25 +0000 (21:00 +0000)
and use this (as well as getCalledValue) to access the callee,
instead of {g|s}etOperand(0).

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

include/llvm/Instructions.h
lib/Transforms/IPO/GlobalOpt.cpp
lib/Transforms/InstCombine/InstCombineCalls.cpp

index 80b7ca4f82df35eb3e85be2b52d326be2c07560b..b1f1996045898a355f5d06a6634f6f3a20d70b61 100644 (file)
@@ -2516,6 +2516,11 @@ public:
   const Value *getCalledValue() const { return getOperand(0); }
         Value *getCalledValue()       { return getOperand(0); }
 
+  /// setCalledFunction - Set the function called.
+  void setCalledFunction(Value* Fn) {
+    Op<0>() = Fn;
+  }
+
   // get*Dest - Return the destination basic blocks...
   BasicBlock *getNormalDest() const {
     return cast<BasicBlock>(getOperand(1));
index 7b1e9c0efdd1cb3da15e8fee4596e5f58d0464c8..d8e97a26ada83adaff40103ebc123c130b3bea53 100644 (file)
@@ -622,12 +622,12 @@ static bool AllUsesOfValueWillTrapIfNull(Value *V,
         return false;  // Storing the value.
       }
     } else if (CallInst *CI = dyn_cast<CallInst>(*UI)) {
-      if (CI->getOperand(0) != V) {
+      if (CI->getCalledValue() != V) {
         //cerr << "NONTRAPPING USE: " << **UI;
         return false;  // Not calling the ptr
       }
     } else if (InvokeInst *II = dyn_cast<InvokeInst>(*UI)) {
-      if (II->getOperand(0) != V) {
+      if (II->getCalledValue() != V) {
         //cerr << "NONTRAPPING USE: " << **UI;
         return false;  // Not calling the ptr
       }
index bdb46ebd1a6436c36abf6d5631f3040311d6b0a8..65f2e15d2780b958456d5b825204966a3c38790e 100644 (file)
@@ -820,7 +820,7 @@ Instruction *InstCombiner::visitCallSite(CallSite CS) {
       
       // We cannot remove an invoke, because it would change the CFG, just
       // change the callee to a null pointer.
-      cast<InvokeInst>(OldCall)->setOperand(0,
+      cast<InvokeInst>(OldCall)->setCalledFunction(
                                     Constant::getNullValue(CalleeF->getType()));
       return 0;
     }