summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Greene <greened@obbligato.org>2007-08-01 03:43:44 +0000
committerDavid Greene <greened@obbligato.org>2007-08-01 03:43:44 +0000
commit52eec548206d0b135b55ba52dd0e82e978f15ae5 (patch)
tree1c9794c86069c19f235104ec8c2a6f91405552d2
parent7fc77611eff7c47e8c37fad58af637138e2a9d7a (diff)
downloadexternal_llvm-52eec548206d0b135b55ba52dd0e82e978f15ae5.zip
external_llvm-52eec548206d0b135b55ba52dd0e82e978f15ae5.tar.gz
external_llvm-52eec548206d0b135b55ba52dd0e82e978f15ae5.tar.bz2
New CallInst interface to address GLIBCXX_DEBUG errors caused by
indexing an empty std::vector. Updates to all clients. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@40660 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/llvm/Instructions.h62
-rw-r--r--include/llvm/Support/LLVMBuilder.h23
-rw-r--r--lib/AsmParser/llvmAsmParser.y2
-rw-r--r--lib/Bitcode/Reader/BitcodeReader.cpp2
-rw-r--r--lib/CodeGen/IntrinsicLowering.cpp8
-rw-r--r--lib/ExecutionEngine/JIT/JIT.cpp2
-rw-r--r--lib/Transforms/IPO/ArgumentPromotion.cpp2
-rw-r--r--lib/Transforms/IPO/DeadArgumentElimination.cpp4
-rw-r--r--lib/Transforms/IPO/LowerSetJmp.cpp8
-rw-r--r--lib/Transforms/IPO/PruneEH.cpp2
-rw-r--r--lib/Transforms/IPO/SimplifyLibCalls.cpp32
-rw-r--r--lib/Transforms/Instrumentation/ProfilingUtils.cpp2
-rw-r--r--lib/Transforms/Scalar/ADCE.cpp2
-rw-r--r--lib/Transforms/Scalar/InstructionCombining.cpp2
-rw-r--r--lib/Transforms/Scalar/LowerGC.cpp15
-rw-r--r--lib/Transforms/Scalar/ScalarReplAggregates.cpp4
-rw-r--r--lib/Transforms/Utils/CodeExtractor.cpp2
-rw-r--r--lib/Transforms/Utils/LowerInvoke.cpp6
-rw-r--r--lib/Transforms/Utils/SimplifyCFG.cpp4
-rw-r--r--lib/VMCore/Instructions.cpp13
-rw-r--r--tools/bugpoint/Miscompilation.cpp10
-rw-r--r--tools/llvm-upgrade/UpgradeParser.y17
22 files changed, 158 insertions, 66 deletions
diff --git a/include/llvm/Instructions.h b/include/llvm/Instructions.h
index 2412298..660776a 100644
--- a/include/llvm/Instructions.h
+++ b/include/llvm/Instructions.h
@@ -16,7 +16,10 @@
#ifndef LLVM_INSTRUCTIONS_H
#define LLVM_INSTRUCTIONS_H
+#include <iterator>
+
#include "llvm/InstrTypes.h"
+#include "llvm/DerivedTypes.h"
namespace llvm {
@@ -735,12 +738,12 @@ public:
//===----------------------------------------------------------------------===//
// CallInst Class
//===----------------------------------------------------------------------===//
-
/// CallInst - This class represents a function call, abstracting a target
/// machine's calling convention. This class uses low bit of the SubClassData
/// field to indicate whether or not this is a tail call. The rest of the bits
/// hold the calling convention of the call.
///
+
class CallInst : public Instruction {
ParamAttrsList *ParamAttrs; ///< parameter attributes for call
CallInst(const CallInst &CI);
@@ -749,18 +752,73 @@ class CallInst : public Instruction {
void init(Value *Func, Value *Actual);
void init(Value *Func);
+ template<typename InputIterator>
+ void init(Value *Func, InputIterator ArgBegin, InputIterator ArgEnd,
+ const std::string &Name,
+ // This argument ensures that we have an iterator we can
+ // do arithmetic on in constant time
+ std::random_access_iterator_tag) {
+ typename std::iterator_traits<InputIterator>::difference_type NumArgs =
+ std::distance(ArgBegin, ArgEnd);
+
+ if (NumArgs > 0) {
+ // This requires that the iterator points to contiguous memory.
+ init(Func, &*ArgBegin, NumArgs);
+ }
+ else {
+ init(Func, 0, NumArgs);
+ }
+
+ setName(Name);
+ }
+
public:
+ /// Construct a CallInst given a range of arguments. InputIterator
+ /// must be a random-access iterator pointing to contiguous storage
+ /// (e.g. a std::vector<>::iterator). Checks are made for
+ /// random-accessness but not for contiguous storage as that would
+ /// incur runtime overhead.
+ /// @brief Construct a CallInst from a range of arguments
+ template<typename InputIterator>
+ CallInst(Value *Func, InputIterator ArgBegin, InputIterator ArgEnd,
+ const std::string &Name = "", Instruction *InsertBefore = 0)
+ : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
+ ->getElementType())->getReturnType(),
+ Instruction::Call, 0, 0, InsertBefore) {
+ init(Func, ArgBegin, ArgEnd, Name,
+ typename std::iterator_traits<InputIterator>::iterator_category());
+ }
+
+ /// Construct a CallInst given a range of arguments. InputIterator
+ /// must be a random-access iterator pointing to contiguous storage
+ /// (e.g. a std::vector<>::iterator). Checks are made for
+ /// random-accessness but not for contiguous storage as that would
+ /// incur runtime overhead.
+ /// @brief Construct a CallInst from a range of arguments
+ template<typename InputIterator>
+ CallInst(Value *Func, InputIterator ArgBegin, InputIterator ArgEnd,
+ const std::string &Name, BasicBlock *InsertAtEnd)
+ : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
+ ->getElementType())->getReturnType(),
+ Instruction::Call, 0, 0, InsertAtEnd) {
+ init(Func, ArgBegin, ArgEnd, Name,
+ typename std::iterator_traits<InputIterator>::iterator_category());
+ }
+
+#if 0
+ // Leave these here for llvm-gcc
CallInst(Value *F, Value* const *Args, unsigned NumArgs,
const std::string &Name = "", Instruction *InsertBefore = 0);
CallInst(Value *F, Value *const *Args, unsigned NumArgs,
const std::string &Name, BasicBlock *InsertAtEnd);
-
+
// Alternate CallInst ctors w/ two actuals, w/ one actual and no
// actuals, respectively.
CallInst(Value *F, Value *Actual1, Value *Actual2,
const std::string& Name = "", Instruction *InsertBefore = 0);
CallInst(Value *F, Value *Actual1, Value *Actual2,
const std::string& Name, BasicBlock *InsertAtEnd);
+#endif
CallInst(Value *F, Value *Actual, const std::string& Name = "",
Instruction *InsertBefore = 0);
CallInst(Value *F, Value *Actual, const std::string& Name,
diff --git a/include/llvm/Support/LLVMBuilder.h b/include/llvm/Support/LLVMBuilder.h
index 5a80e41..bd450dc 100644
--- a/include/llvm/Support/LLVMBuilder.h
+++ b/include/llvm/Support/LLVMBuilder.h
@@ -380,22 +380,31 @@ public:
}
CallInst *CreateCall(Value *Callee, const char *Name = "") {
- return Insert(new CallInst(Callee, (Value**)0, 0, Name));
+ return Insert(new CallInst(Callee, Name));
}
CallInst *CreateCall(Value *Callee, Value *Arg, const char *Name = "") {
- return Insert(new CallInst(Callee, &Arg, 1, Name));
+ return Insert(new CallInst(Callee, Arg, Name));
}
- CallInst *CreateCall(Value *Callee, Value *Arg0, Value *Arg1,
+
+ template<typename InputIterator>
+ CallInst *CreateCall(Value *Callee, InputIterator ArgBegin, InputIterator ArgEnd,
const char *Name = "") {
- Value *Args[] = { Arg0, Arg1 };
- return Insert(new CallInst(Callee, Args, 2, Name));
+ return(Insert(new CallInst(Callee, ArgBegin, ArgEnd, Name)));
}
-
+#if 0
+ CallInst *CreateCall(Value *Callee, Value *Arg0, Value *Arg1,
+ const char *Name = "") {
+ Value *Args[] = { Arg0, Arg1 };
+ return Insert(new CallInst(Callee, Args, Args+2, Name));
+ }
+
+ // Leave this here for llvm-gcc
CallInst *CreateCall(Value *Callee, Value* const *Args, unsigned NumArgs,
const char *Name = "") {
- return Insert(new CallInst(Callee, Args, NumArgs, Name));
+ return Insert(new CallInst(Callee, Args, Args+NumArgs, Name));
}
+#endif
SelectInst *CreateSelect(Value *C, Value *True, Value *False,
const char *Name = "") {
diff --git a/lib/AsmParser/llvmAsmParser.y b/lib/AsmParser/llvmAsmParser.y
index fd2713f..28eb339 100644
--- a/lib/AsmParser/llvmAsmParser.y
+++ b/lib/AsmParser/llvmAsmParser.y
@@ -2958,7 +2958,7 @@ InstVal : ArithmeticOps Types ValueRef ',' ValueRef {
GEN_ERROR("Invalid number of parameters detected");
}
// Create the call node
- CallInst *CI = new CallInst(V, &Args[0], Args.size());
+ CallInst *CI = new CallInst(V, Args.begin(), Args.end());
CI->setTailCall($1);
CI->setCallingConv($2);
$$ = CI;
diff --git a/lib/Bitcode/Reader/BitcodeReader.cpp b/lib/Bitcode/Reader/BitcodeReader.cpp
index b040df3..ee6ed0a 100644
--- a/lib/Bitcode/Reader/BitcodeReader.cpp
+++ b/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -1499,7 +1499,7 @@ bool BitcodeReader::ParseFunctionBody(Function *F) {
}
}
- I = new CallInst(Callee, &Args[0], Args.size());
+ I = new CallInst(Callee, Args.begin(), Args.end());
cast<CallInst>(I)->setCallingConv(CCInfo>>1);
cast<CallInst>(I)->setTailCall(CCInfo & 1);
break;
diff --git a/lib/CodeGen/IntrinsicLowering.cpp b/lib/CodeGen/IntrinsicLowering.cpp
index 8ae4df6..d92ee3f 100644
--- a/lib/CodeGen/IntrinsicLowering.cpp
+++ b/lib/CodeGen/IntrinsicLowering.cpp
@@ -53,8 +53,8 @@ static CallInst *ReplaceCallWith(const char *NewFn, CallInst *CI,
FunctionType::get(RetTy, ParamTys, false));
}
- SmallVector<Value*, 8> Operands(ArgBegin, ArgEnd);
- CallInst *NewCI = new CallInst(FCache, &Operands[0], Operands.size(),
+ SmallVector<Value *, 8> Args(ArgBegin, ArgEnd);
+ CallInst *NewCI = new CallInst(FCache, Args.begin(), Args.end(),
CI->getName(), CI);
if (!CI->use_empty())
CI->replaceAllUsesWith(NewCI);
@@ -421,7 +421,7 @@ static Instruction *LowerPartSelect(CallInst *CI) {
CI->getOperand(2),
CI->getOperand(3)
};
- return new CallInst(F, Args, sizeof(Args)/sizeof(Args[0]), CI->getName(), CI);
+ return new CallInst(F, Args, Args+sizeof(Args)/sizeof(Args[0]), CI->getName(), CI);
}
/// Convert the llvm.part.set.iX.iY.iZ intrinsic. This intrinsic takes
@@ -587,7 +587,7 @@ static Instruction *LowerPartSet(CallInst *CI) {
CI->getOperand(3),
CI->getOperand(4)
};
- return new CallInst(F, Args, sizeof(Args)/sizeof(Args[0]), CI->getName(), CI);
+ return new CallInst(F, Args, Args+sizeof(Args)/sizeof(Args[0]), CI->getName(), CI);
}
diff --git a/lib/ExecutionEngine/JIT/JIT.cpp b/lib/ExecutionEngine/JIT/JIT.cpp
index 926142f..d6b080e 100644
--- a/lib/ExecutionEngine/JIT/JIT.cpp
+++ b/lib/ExecutionEngine/JIT/JIT.cpp
@@ -224,7 +224,7 @@ GenericValue JIT::runFunction(Function *F,
Args.push_back(C);
}
- CallInst *TheCall = new CallInst(F, &Args[0], Args.size(), "", StubBB);
+ CallInst *TheCall = new CallInst(F, Args.begin(), Args.end(), "", StubBB);
TheCall->setTailCall();
if (TheCall->getType() != Type::VoidTy)
new ReturnInst(TheCall, StubBB); // Return result of the call.
diff --git a/lib/Transforms/IPO/ArgumentPromotion.cpp b/lib/Transforms/IPO/ArgumentPromotion.cpp
index 9a7bcc7..78703a4 100644
--- a/lib/Transforms/IPO/ArgumentPromotion.cpp
+++ b/lib/Transforms/IPO/ArgumentPromotion.cpp
@@ -450,7 +450,7 @@ Function *ArgPromotion::DoPromotion(Function *F,
&Args[0], Args.size(), "", Call);
cast<InvokeInst>(New)->setCallingConv(CS.getCallingConv());
} else {
- New = new CallInst(NF, &Args[0], Args.size(), "", Call);
+ New = new CallInst(NF, Args.begin(), Args.end(), "", Call);
cast<CallInst>(New)->setCallingConv(CS.getCallingConv());
if (cast<CallInst>(Call)->isTailCall())
cast<CallInst>(New)->setTailCall();
diff --git a/lib/Transforms/IPO/DeadArgumentElimination.cpp b/lib/Transforms/IPO/DeadArgumentElimination.cpp
index 943ea30..b5ec103 100644
--- a/lib/Transforms/IPO/DeadArgumentElimination.cpp
+++ b/lib/Transforms/IPO/DeadArgumentElimination.cpp
@@ -177,7 +177,7 @@ bool DAE::DeleteDeadVarargs(Function &Fn) {
&Args[0], Args.size(), "", Call);
cast<InvokeInst>(New)->setCallingConv(CS.getCallingConv());
} else {
- New = new CallInst(NF, &Args[0], Args.size(), "", Call);
+ New = new CallInst(NF, Args.begin(), Args.end(), "", Call);
cast<CallInst>(New)->setCallingConv(CS.getCallingConv());
if (cast<CallInst>(Call)->isTailCall())
cast<CallInst>(New)->setTailCall();
@@ -543,7 +543,7 @@ void DAE::RemoveDeadArgumentsFromFunction(Function *F) {
&Args[0], Args.size(), "", Call);
cast<InvokeInst>(New)->setCallingConv(CS.getCallingConv());
} else {
- New = new CallInst(NF, &Args[0], Args.size(), "", Call);
+ New = new CallInst(NF, Args.begin(), Args.end(), "", Call);
cast<CallInst>(New)->setCallingConv(CS.getCallingConv());
if (cast<CallInst>(Call)->isTailCall())
cast<CallInst>(New)->setTailCall();
diff --git a/lib/Transforms/IPO/LowerSetJmp.cpp b/lib/Transforms/IPO/LowerSetJmp.cpp
index 0243980..2fa6a10 100644
--- a/lib/Transforms/IPO/LowerSetJmp.cpp
+++ b/lib/Transforms/IPO/LowerSetJmp.cpp
@@ -49,6 +49,7 @@
#include "llvm/ADT/Statistic.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/VectorExtras.h"
+#include "llvm/ADT/SmallVector.h"
using namespace llvm;
STATISTIC(LongJmpsTransformed, "Number of longjmps transformed");
@@ -263,7 +264,10 @@ void LowerSetJmp::TransformLongJmpCall(CallInst* Inst)
// Inst's uses and doesn't get a name.
CastInst* CI =
new BitCastInst(Inst->getOperand(1), SBPTy, "LJBuf", Inst);
- new CallInst(ThrowLongJmp, CI, Inst->getOperand(2), "", Inst);
+ SmallVector<Value *, 2> Args;
+ Args.push_back(CI);
+ Args.push_back(Inst->getOperand(2));
+ new CallInst(ThrowLongJmp, Args.begin(), Args.end(), "", Inst);
SwitchValuePair& SVP = SwitchValMap[Inst->getParent()->getParent()];
@@ -381,7 +385,7 @@ void LowerSetJmp::TransformSetJmpCall(CallInst* Inst)
make_vector<Value*>(GetSetJmpMap(Func), BufPtr,
ConstantInt::get(Type::Int32Ty,
SetJmpIDMap[Func]++), 0);
- new CallInst(AddSJToMap, &Args[0], Args.size(), "", Inst);
+ new CallInst(AddSJToMap, Args.begin(), Args.end(), "", Inst);
// We are guaranteed that there are no values live across basic blocks
// (because we are "not in SSA form" yet), but there can still be values live
diff --git a/lib/Transforms/IPO/PruneEH.cpp b/lib/Transforms/IPO/PruneEH.cpp
index a783272..52f8d5e 100644
--- a/lib/Transforms/IPO/PruneEH.cpp
+++ b/lib/Transforms/IPO/PruneEH.cpp
@@ -153,7 +153,7 @@ bool PruneEH::SimplifyFunction(Function *F) {
SmallVector<Value*, 8> Args(II->op_begin()+3, II->op_end());
// Insert a call instruction before the invoke.
CallInst *Call = new CallInst(II->getCalledValue(),
- &Args[0], Args.size(), "", II);
+ Args.begin(), Args.end(), "", II);
Call->takeName(II);
Call->setCallingConv(II->getCallingConv());
diff --git a/lib/Transforms/IPO/SimplifyLibCalls.cpp b/lib/Transforms/IPO/SimplifyLibCalls.cpp
index b0f9128..5925f58 100644
--- a/lib/Transforms/IPO/SimplifyLibCalls.cpp
+++ b/lib/Transforms/IPO/SimplifyLibCalls.cpp
@@ -509,7 +509,7 @@ public:
ConstantInt::get(SLC.getIntPtrType(), SrcStr.size()+1), // copy nul byte.
ConstantInt::get(Type::Int32Ty, 1) // alignment
};
- new CallInst(SLC.get_memcpy(), Vals, 4, "", CI);
+ new CallInst(SLC.get_memcpy(), Vals, Vals + 4, "", CI);
return ReplaceCallWith(CI, Dst);
}
@@ -549,7 +549,7 @@ public:
CI->getOperand(2),
ConstantInt::get(SLC.getIntPtrType(), Str.size()+1)
};
- return ReplaceCallWith(CI, new CallInst(SLC.get_memchr(), Args, 3,
+ return ReplaceCallWith(CI, new CallInst(SLC.get_memchr(), Args, Args + 3,
CI->getName(), CI));
}
@@ -752,7 +752,7 @@ public:
ConstantInt::get(SLC.getIntPtrType(), SrcStr.size()+1),
ConstantInt::get(Type::Int32Ty, 1) // alignment
};
- new CallInst(SLC.get_memcpy(), MemcpyOps, 4, "", CI);
+ new CallInst(SLC.get_memcpy(), MemcpyOps, MemcpyOps + 4, "", CI);
return ReplaceCallWith(CI, Dst);
}
@@ -1294,7 +1294,7 @@ public:
ConstantInt::get(SLC.getIntPtrType(), 1),
CI->getOperand(1)
};
- new CallInst(SLC.get_fwrite(FILEty), FWriteArgs, 4, CI->getName(), CI);
+ new CallInst(SLC.get_fwrite(FILEty), FWriteArgs, FWriteArgs + 4, CI->getName(), CI);
return ReplaceCallWith(CI, ConstantInt::get(CI->getType(),
FormatStr.size()));
}
@@ -1311,7 +1311,10 @@ public:
const Type *FILETy = CI->getOperand(1)->getType();
Value *C = CastInst::createZExtOrBitCast(CI->getOperand(3), Type::Int32Ty,
CI->getName()+".int", CI);
- new CallInst(SLC.get_fputc(FILETy), C, CI->getOperand(1), "", CI);
+ SmallVector<Value *, 2> Args;
+ Args.push_back(C);
+ Args.push_back(CI->getOperand(1));
+ new CallInst(SLC.get_fputc(FILETy), Args.begin(), Args.end(), "", CI);
return ReplaceCallWith(CI, ConstantInt::get(CI->getType(), 1));
}
case 's': {
@@ -1323,8 +1326,11 @@ public:
return false;
// fprintf(file,"%s",str) -> fputs(str,file)
- new CallInst(SLC.get_fputs(FILETy), CastToCStr(CI->getOperand(3), CI),
- CI->getOperand(1), CI->getName(), CI);
+ SmallVector<Value *, 2> Args;
+ Args.push_back(CastToCStr(CI->getOperand(3), CI));
+ Args.push_back(CI->getOperand(1));
+ new CallInst(SLC.get_fputs(FILETy), Args.begin(),
+ Args.end(), CI->getName(), CI);
return ReplaceCallWith(CI, 0);
}
default:
@@ -1375,7 +1381,7 @@ public:
FormatStr.size()+1), // Copy the nul byte.
ConstantInt::get(Type::Int32Ty, 1)
};
- new CallInst(SLC.get_memcpy(), MemCpyArgs, 4, "", CI);
+ new CallInst(SLC.get_memcpy(), MemCpyArgs, MemCpyArgs + 4, "", CI);
return ReplaceCallWith(CI, ConstantInt::get(CI->getType(),
FormatStr.size()));
}
@@ -1412,7 +1418,7 @@ public:
Len,
ConstantInt::get(Type::Int32Ty, 1)
};
- new CallInst(SLC.get_memcpy(), MemcpyArgs, 4, "", CI);
+ new CallInst(SLC.get_memcpy(), MemcpyArgs, MemcpyArgs + 4, "", CI);
// The strlen result is the unincremented number of bytes in the string.
if (!CI->use_empty()) {
@@ -1464,7 +1470,7 @@ public:
ConstantInt::get(SLC.getIntPtrType(), 1),
CI->getOperand(2)
};
- new CallInst(SLC.get_fwrite(FILETy), FWriteParms, 4, "", CI);
+ new CallInst(SLC.get_fwrite(FILETy), FWriteParms, FWriteParms + 4, "", CI);
return ReplaceCallWith(CI, 0); // Known to have no uses (see above).
}
} FPutsOptimizer;
@@ -1505,12 +1511,14 @@ public:
// If this is writing one byte, turn it into fputc.
if (EltSize == 1 && EltCount == 1) {
+ SmallVector<Value *, 2> Args;
// fwrite(s,1,1,F) -> fputc(s[0],F)
Value *Ptr = CI->getOperand(1);
Value *Val = new LoadInst(Ptr, Ptr->getName()+".byte", CI);
- Val = new ZExtInst(Val, Type::Int32Ty, Val->getName()+".int", CI);
+ Args.push_back(new ZExtInst(Val, Type::Int32Ty, Val->getName()+".int", CI));
+ Args.push_back(CI->getOperand(4));
const Type *FILETy = CI->getOperand(4)->getType();
- new CallInst(SLC.get_fputc(FILETy), Val, CI->getOperand(4), "", CI);
+ new CallInst(SLC.get_fputc(FILETy), Args.begin(), Args.end(), "", CI);
return ReplaceCallWith(CI, ConstantInt::get(CI->getType(), 1));
}
return false;
diff --git a/lib/Transforms/Instrumentation/ProfilingUtils.cpp b/lib/Transforms/Instrumentation/ProfilingUtils.cpp
index 54ea803..91b8ec2 100644
--- a/lib/Transforms/Instrumentation/ProfilingUtils.cpp
+++ b/lib/Transforms/Instrumentation/ProfilingUtils.cpp
@@ -54,7 +54,7 @@ void llvm::InsertProfilingInitCall(Function *MainFn, const char *FnName,
}
Args[3] = ConstantInt::get(Type::Int32Ty, NumElements);
- Instruction *InitCall = new CallInst(InitFn, &Args[0], Args.size(),
+ Instruction *InitCall = new CallInst(InitFn, Args.begin(), Args.end(),
"newargc", InsertPos);
// If argc or argv are not available in main, just pass null values in.
diff --git a/lib/Transforms/Scalar/ADCE.cpp b/lib/Transforms/Scalar/ADCE.cpp
index 4968fc9..d5201b8 100644
--- a/lib/Transforms/Scalar/ADCE.cpp
+++ b/lib/Transforms/Scalar/ADCE.cpp
@@ -194,7 +194,7 @@ bool ADCE::doADCE() {
// The function cannot unwind. Convert it to a call with a branch
// after it to the normal destination.
SmallVector<Value*, 8> Args(II->op_begin()+3, II->op_end());
- CallInst *NewCall = new CallInst(F, &Args[0], Args.size(), "", II);
+ CallInst *NewCall = new CallInst(F, Args.begin(), Args.end(), "", II);
NewCall->takeName(II);
NewCall->setCallingConv(II->getCallingConv());
II->replaceAllUsesWith(NewCall);
diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp
index a7e817a..8b706fd 100644
--- a/lib/Transforms/Scalar/InstructionCombining.cpp
+++ b/lib/Transforms/Scalar/InstructionCombining.cpp
@@ -7978,7 +7978,7 @@ bool InstCombiner::transformConstExprCastCall(CallSite CS) {
&Args[0], Args.size(), Caller->getName(), Caller);
cast<InvokeInst>(NC)->setCallingConv(II->getCallingConv());
} else {
- NC = new CallInst(Callee, &Args[0], Args.size(), Caller->getName(), Caller);
+ NC = new CallInst(Callee, Args.begin(), Args.end(), Caller->getName(), Caller);
if (cast<CallInst>(Caller)->isTailCall())
cast<CallInst>(NC)->setTailCall();
cast<CallInst>(NC)->setCallingConv(cast<CallInst>(Caller)->getCallingConv());
diff --git a/lib/Transforms/Scalar/LowerGC.cpp b/lib/Transforms/Scalar/LowerGC.cpp
index 27cccd5..a3c4a41 100644
--- a/lib/Transforms/Scalar/LowerGC.cpp
+++ b/lib/Transforms/Scalar/LowerGC.cpp
@@ -27,6 +27,7 @@
#include "llvm/Module.h"
#include "llvm/Pass.h"
#include "llvm/Support/Compiler.h"
+#include "llvm/ADT/SmallVector.h"
using namespace llvm;
namespace {
@@ -197,8 +198,18 @@ bool LowerGC::runOnFunction(Function &F) {
CI->setOperand(0, GCRead);
} else {
// Create a whole new call to replace the old one.
- CallInst *NC = new CallInst(GCRead, CI->getOperand(1),
- CI->getOperand(2),
+
+ // It sure would be nice to pass op_begin()+1,
+ // op_begin()+2 but it runs into trouble with
+ // CallInst::init's &*ierator, which requires a
+ // conversion from Use* to Value*. The conversion
+ // from Use to Value * is not useful because the
+ // memory for Value * won't be contiguous.
+ SmallVector<Value *, 2> Args;
+ Args.push_back(CI->getOperand(1));
+ Args.push_back(CI->getOperand(2));
+ CallInst *NC = new CallInst(GCRead, Args.begin(),
+ Args.end(),
CI->getName(), CI);
// These functions only deal with ptr type results so BitCast
// is the correct kind of cast (no-op cast).
diff --git a/lib/Transforms/Scalar/ScalarReplAggregates.cpp b/lib/Transforms/Scalar/ScalarReplAggregates.cpp
index e303468..45bf562 100644
--- a/lib/Transforms/Scalar/ScalarReplAggregates.cpp
+++ b/lib/Transforms/Scalar/ScalarReplAggregates.cpp
@@ -709,7 +709,7 @@ void SROA::RewriteBitCastUserOfAlloca(Instruction *BCInst, AllocationInst *AI,
ConstantInt::get(MI->getOperand(3)->getType(), EltSize), // Size
Zero // Align
};
- new CallInst(TheFn, Ops, 4, "", MI);
+ new CallInst(TheFn, Ops, Ops + 4, "", MI);
} else {
assert(isa<MemSetInst>(MI));
Value *Ops[] = {
@@ -717,7 +717,7 @@ void SROA::RewriteBitCastUserOfAlloca(Instruction *BCInst, AllocationInst *AI,
ConstantInt::get(MI->getOperand(3)->getType(), EltSize), // Size
Zero // Align
};
- new CallInst(TheFn, Ops, 4, "", MI);
+ new CallInst(TheFn, Ops, Ops + 4, "", MI);
}
}
diff --git a/lib/Transforms/Utils/CodeExtractor.cpp b/lib/Transforms/Utils/CodeExtractor.cpp
index aaf9986..90642f1 100644
--- a/lib/Transforms/Utils/CodeExtractor.cpp
+++ b/lib/Transforms/Utils/CodeExtractor.cpp
@@ -393,7 +393,7 @@ emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer,
}
// Emit the call to the function
- CallInst *call = new CallInst(newFunction, &params[0], params.size(),
+ CallInst *call = new CallInst(newFunction, params.begin(), params.end(),
NumExitBlocks > 1 ? "targetBlock" : "");
codeReplacer->getInstList().push_back(call);
diff --git a/lib/Transforms/Utils/LowerInvoke.cpp b/lib/Transforms/Utils/LowerInvoke.cpp
index d72c018..551ca7f 100644
--- a/lib/Transforms/Utils/LowerInvoke.cpp
+++ b/lib/Transforms/Utils/LowerInvoke.cpp
@@ -212,7 +212,7 @@ bool LowerInvoke::insertCheapEHSupport(Function &F) {
std::vector<Value*> CallArgs(II->op_begin()+3, II->op_end());
// Insert a normal call instruction...
CallInst *NewCall = new CallInst(II->getCalledValue(),
- &CallArgs[0], CallArgs.size(), "", II);
+ CallArgs.begin(), CallArgs.end(), "", II);
NewCall->takeName(II);
NewCall->setCallingConv(II->getCallingConv());
II->replaceAllUsesWith(NewCall);
@@ -269,7 +269,7 @@ void LowerInvoke::rewriteExpensiveInvoke(InvokeInst *II, unsigned InvokeNo,
// Insert a normal call instruction.
std::vector<Value*> CallArgs(II->op_begin()+3, II->op_end());
CallInst *NewCall = new CallInst(II->getCalledValue(),
- &CallArgs[0], CallArgs.size(), "",
+ CallArgs.begin(), CallArgs.end(), "",
II);
NewCall->takeName(II);
NewCall->setCallingConv(II->getCallingConv());
@@ -542,7 +542,7 @@ bool LowerInvoke::insertExpensiveEHSupport(Function &F) {
Idx.push_back(ConstantInt::get(Type::Int32Ty, 0));
Idx[0] = new GetElementPtrInst(BufPtr, &Idx[0], 2, "JmpBuf", UnwindBlock);
Idx[1] = ConstantInt::get(Type::Int32Ty, 1);
- new CallInst(LongJmpFn, &Idx[0], Idx.size(), "", UnwindBlock);
+ new CallInst(LongJmpFn, Idx.begin(), Idx.end(), "", UnwindBlock);
new UnreachableInst(UnwindBlock);
// Set up the term block ("throw without a catch").
diff --git a/lib/Transforms/Utils/SimplifyCFG.cpp b/lib/Transforms/Utils/SimplifyCFG.cpp
index 6c34d02..470daf3 100644
--- a/lib/Transforms/Utils/SimplifyCFG.cpp
+++ b/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -1374,7 +1374,7 @@ bool llvm::SimplifyCFG(BasicBlock *BB) {
// Insert the call now...
SmallVector<Value*,8> Args(II->op_begin()+3, II->op_end());
CallInst *CI = new CallInst(II->getCalledValue(),
- &Args[0], Args.size(), II->getName(), BI);
+ Args.begin(), Args.end(), II->getName(), BI);
CI->setCallingConv(II->getCallingConv());
// If the invoke produced a value, the Call now does instead
II->replaceAllUsesWith(CI);
@@ -1748,7 +1748,7 @@ bool llvm::SimplifyCFG(BasicBlock *BB) {
// Insert the call now...
SmallVector<Value*, 8> Args(II->op_begin()+3, II->op_end());
CallInst *CI = new CallInst(II->getCalledValue(),
- &Args[0], Args.size(),
+ Args.begin(), Args.end(),
II->getName(), BI);
CI->setCallingConv(II->getCallingConv());
// If the invoke produced a value, the Call does now instead.
diff --git a/lib/VMCore/Instructions.cpp b/lib/VMCore/Instructions.cpp
index 7dfe5ae..5297374 100644
--- a/lib/VMCore/Instructions.cpp
+++ b/lib/VMCore/Instructions.cpp
@@ -267,19 +267,21 @@ void CallInst::init(Value *Func) {
assert(FTy->getNumParams() == 0 && "Calling a function with bad signature");
}
+#if 0
+// Leave for llvm-gcc
CallInst::CallInst(Value *Func, Value* const *Args, unsigned NumArgs,
const std::string &Name, BasicBlock *InsertAtEnd)
: Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
- ->getElementType())->getReturnType(),
+ ->getElementType())->getReturnType(),
Instruction::Call, 0, 0, InsertAtEnd) {
init(Func, Args, NumArgs);
setName(Name);
}
CallInst::CallInst(Value *Func, Value* const *Args, unsigned NumArgs,
const std::string &Name, Instruction *InsertBefore)
-: Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
- ->getElementType())->getReturnType(),
- Instruction::Call, 0, 0, InsertBefore) {
+ : Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
+ ->getElementType())->getReturnType(),
+ Instruction::Call, 0, 0, InsertBefore) {
init(Func, Args, NumArgs);
setName(Name);
}
@@ -301,7 +303,7 @@ CallInst::CallInst(Value *Func, Value *Actual1, Value *Actual2,
init(Func, Actual1, Actual2);
setName(Name);
}
-
+#endif
CallInst::CallInst(Value *Func, Value* Actual, const std::string &Name,
Instruction *InsertBefore)
: Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
@@ -319,7 +321,6 @@ CallInst::CallInst(Value *Func, Value* Actual, const std::string &Name,
init(Func, Actual);
setName(Name);
}
-
CallInst::CallInst(Value *Func, const std::string &Name,
Instruction *InsertBefore)
: Instruction(cast<FunctionType>(cast<PointerType>(Func->getType())
diff --git a/tools/bugpoint/Miscompilation.cpp b/tools/bugpoint/Miscompilation.cpp
index 925a7a8..be820c8 100644
--- a/tools/bugpoint/Miscompilation.cpp
+++ b/tools/bugpoint/Miscompilation.cpp
@@ -663,7 +663,7 @@ static void CleanupAndPrepareModules(BugDriver &BD, Module *&Test,
// Call the old main function and return its result
BasicBlock *BB = new BasicBlock("entry", newMain);
- CallInst *call = new CallInst(oldMainProto, &args[0], args.size(),
+ CallInst *call = new CallInst(oldMainProto, args.begin(), args.end(),
"", BB);
// If the type of old function wasn't void, return value of call
@@ -734,8 +734,8 @@ static void CleanupAndPrepareModules(BugDriver &BD, Module *&Test,
// Resolve the call to function F via the JIT API:
//
// call resolver(GetElementPtr...)
- CallInst *Resolver = new CallInst(resolverFunc, &ResolverArgs[0],
- ResolverArgs.size(),
+ CallInst *Resolver = new CallInst(resolverFunc, ResolverArgs.begin(),
+ ResolverArgs.end(),
"resolver", LookupBB);
// cast the result from the resolver to correctly-typed function
CastInst *CastedResolver = new BitCastInst(Resolver,
@@ -757,10 +757,10 @@ static void CleanupAndPrepareModules(BugDriver &BD, Module *&Test,
// Pass on the arguments to the real function, return its result
if (F->getReturnType() == Type::VoidTy) {
- new CallInst(FuncPtr, &Args[0], Args.size(), "", DoCallBB);
+ new CallInst(FuncPtr, Args.begin(), Args.end(), "", DoCallBB);
new ReturnInst(DoCallBB);
} else {
- CallInst *Call = new CallInst(FuncPtr, &Args[0], Args.size(),
+ CallInst *Call = new CallInst(FuncPtr, Args.begin(), Args.end(),
"retval", DoCallBB);
new ReturnInst(Call, DoCallBB);
}
diff --git a/tools/llvm-upgrade/UpgradeParser.y b/tools/llvm-upgrade/UpgradeParser.y
index ed84267..c9b3e6a 100644
--- a/tools/llvm-upgrade/UpgradeParser.y
+++ b/tools/llvm-upgrade/UpgradeParser.y
@@ -1513,7 +1513,7 @@ upgradeIntrinsicCall(const Type* RetTy, const ValID &ID,
const PointerType *PFTy = PointerType::get(FTy);
Value* Func = getVal(PFTy, ID);
Args[0] = new BitCastInst(Args[0], PtrTy, makeNameUnique("va"), CurBB);
- return new CallInst(Func, &Args[0], Args.size());
+ return new CallInst(Func, Args.begin(), Args.end());
} else if (Name == "llvm.va_copy") {
if (Args.size() != 2)
error("Invalid prototype for " + Name + " prototype");
@@ -1527,7 +1527,7 @@ upgradeIntrinsicCall(const Type* RetTy, const ValID &ID,
std::string InstName1(makeNameUnique("va1"));
Args[0] = new BitCastInst(Args[0], PtrTy, InstName0, CurBB);
Args[1] = new BitCastInst(Args[1], PtrTy, InstName1, CurBB);
- return new CallInst(Func, &Args[0], Args.size());
+ return new CallInst(Func, Args.begin(), Args.end());
}
}
}
@@ -1751,11 +1751,12 @@ Module* UpgradeAssembly(const std::string &infile, std::istream& in,
while (!F->use_empty()) {
CallInst* CI = cast<CallInst>(F->use_back());
- AllocaInst* a = new AllocaInst(ArgTy, 0, "vacopy.fix.1", CI);
- AllocaInst* b = new AllocaInst(ArgTy, 0, "vacopy.fix.2", CI);
- new StoreInst(CI->getOperand(1), b, CI);
- new CallInst(NF, a, b, "", CI);
- Value* foo = new LoadInst(a, "vacopy.fix.3", CI);
+ SmallVector<Value *, 2> Args;
+ Args.push_back(new AllocaInst(ArgTy, 0, "vacopy.fix.1", CI));
+ Args.push_back(new AllocaInst(ArgTy, 0, "vacopy.fix.2", CI));
+ new StoreInst(CI->getOperand(1), Args[1], CI);
+ new CallInst(NF, Args.begin(), Args.end(), "", CI);
+ Value* foo = new LoadInst(Args[0], "vacopy.fix.3", CI);
CI->replaceAllUsesWith(foo);
CI->getParent()->getInstList().erase(CI);
}
@@ -3806,7 +3807,7 @@ InstVal
}
// Create the call instruction
- CallInst *CI = new CallInst(V, &Args[0], Args.size());
+ CallInst *CI = new CallInst(V, Args.begin(), Args.end());
CI->setTailCall($1);
CI->setCallingConv(upgradeCallingConv($2));
$$.I = CI;