From febf6ab718bcb41c00c060a5320d449faaf88d26 Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Sat, 20 Mar 2010 21:00:25 +0000 Subject: [PATCH] Add a setCalledFunction member to InvokeInst (like in CallInst) and use this (as well as getCalledValue) to access the callee, instead of {g|s}etOperand(0). llvm-svn: 99084 --- llvm/include/llvm/Instructions.h | 5 +++++ llvm/lib/Transforms/IPO/GlobalOpt.cpp | 4 ++-- llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/llvm/include/llvm/Instructions.h b/llvm/include/llvm/Instructions.h index 80b7ca4f82df..b1f199604589 100644 --- a/llvm/include/llvm/Instructions.h +++ b/llvm/include/llvm/Instructions.h @@ -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(getOperand(1)); diff --git a/llvm/lib/Transforms/IPO/GlobalOpt.cpp b/llvm/lib/Transforms/IPO/GlobalOpt.cpp index 7b1e9c0efdd1..d8e97a26ada8 100644 --- a/llvm/lib/Transforms/IPO/GlobalOpt.cpp +++ b/llvm/lib/Transforms/IPO/GlobalOpt.cpp @@ -622,12 +622,12 @@ static bool AllUsesOfValueWillTrapIfNull(Value *V, return false; // Storing the value. } } else if (CallInst *CI = dyn_cast(*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(*UI)) { - if (II->getOperand(0) != V) { + if (II->getCalledValue() != V) { //cerr << "NONTRAPPING USE: " << **UI; return false; // Not calling the ptr } diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp index bdb46ebd1a64..65f2e15d2780 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp @@ -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(OldCall)->setOperand(0, + cast(OldCall)->setCalledFunction( Constant::getNullValue(CalleeF->getType())); return 0; }