summaryrefslogtreecommitdiff
path: root/lib/Transforms/IPO
diff options
context:
space:
mode:
authorMatthijs Kooijman <matthijs@stdin.nl>2008-06-19 08:53:24 +0000
committerMatthijs Kooijman <matthijs@stdin.nl>2008-06-19 08:53:24 +0000
commitf0da2039d17a3e6b72fd1c0df1f889afac65cbd0 (patch)
tree3b57d034baa2b171bbecd0baec9b680e36e3327b /lib/Transforms/IPO
parent9954c76f2c89ab3c70bfe8222534621a86f9085a (diff)
downloadllvm-f0da2039d17a3e6b72fd1c0df1f889afac65cbd0.tar.gz
llvm-f0da2039d17a3e6b72fd1c0df1f889afac65cbd0.tar.bz2
llvm-f0da2039d17a3e6b72fd1c0df1f889afac65cbd0.tar.xz
Use a CallSite to find the nth argument of a call/invoke instruction instead of
using getOperand() directly. This makes things work with invoke instructions as well. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@52489 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/IPO')
-rw-r--r--lib/Transforms/IPO/IPConstantPropagation.cpp22
1 files changed, 11 insertions, 11 deletions
diff --git a/lib/Transforms/IPO/IPConstantPropagation.cpp b/lib/Transforms/IPO/IPConstantPropagation.cpp
index f528b88983..fa004fda1e 100644
--- a/lib/Transforms/IPO/IPConstantPropagation.cpp
+++ b/lib/Transforms/IPO/IPConstantPropagation.cpp
@@ -218,13 +218,15 @@ bool IPCP::PropagateConstantReturn(Function &F) {
// constant.
bool MadeChange = false;
for (Value::use_iterator UI = F.use_begin(), E = F.use_end(); UI != E; ++UI) {
- // Make sure this is an invoke or call and that the use is for the callee.
- if (!(isa<InvokeInst>(*UI) || isa<CallInst>(*UI)) ||
- UI.getOperandNo() != 0) {
+ CallSite CS = CallSite::get(*UI);
+ Instruction* Call = CS.getInstruction();
+
+ // Not a call instruction or a call instruction that's not calling F
+ // directly?
+ if (!Call || UI.getOperandNo() != 0)
continue;
- }
- Instruction *Call = cast<Instruction>(*UI);
+ // Call result not used?
if (Call->use_empty())
continue;
@@ -234,9 +236,8 @@ bool IPCP::PropagateConstantReturn(Function &F) {
Value* New = RetVals[0];
if (Argument *A = dyn_cast<Argument>(New))
// Was an argument returned? Then find the corresponding argument in
- // the call instruction and use that. Add 1 to the argument number
- // to skip the first argument (the function itself).
- New = Call->getOperand(A->getArgNo() + 1);
+ // the call instruction and use that.
+ New = CS.getArgument(A->getArgNo());
Call->replaceAllUsesWith(New);
continue;
}
@@ -267,9 +268,8 @@ bool IPCP::PropagateConstantReturn(Function &F) {
if (New) {
if (Argument *A = dyn_cast<Argument>(New))
// Was an argument returned? Then find the corresponding argument in
- // the call instruction and use that. Add 1 to the argument number
- // to skip the first argument (the function itself).
- New = Call->getOperand(A->getArgNo() + 1);
+ // the call instruction and use that.
+ New = CS.getArgument(A->getArgNo());
Ins->replaceAllUsesWith(New);
Ins->eraseFromParent();
}