static bool AllCalleesPassInValidPointerForArgument(Argument *Arg) {
Function *Callee = Arg->getParent();
- unsigned ArgNo = std::distance(Callee->arg_begin(), Function::arg_iterator(Arg));
+ unsigned ArgNo = std::distance(Callee->arg_begin(),
+ Function::arg_iterator(Arg));
// Look at all call sites of the function. At this pointer we know we only
// have direct callees.
Instruction *New;
if (InvokeInst *II = dyn_cast<InvokeInst>(Call)) {
New = new InvokeInst(NF, II->getNormalDest(), II->getUnwindDest(),
- Args, "", Call);
+ &Args[0], Args.size(), "", Call);
cast<InvokeInst>(New)->setCallingConv(CS.getCallingConv());
} else {
- New = new CallInst(NF, Args, "", Call);
+ New = new CallInst(NF, &Args[0], Args.size(), "", Call);
cast<CallInst>(New)->setCallingConv(CS.getCallingConv());
if (cast<CallInst>(Call)->isTailCall())
cast<CallInst>(New)->setTailCall();
// Loop over the argument list, transfering uses of the old arguments over to
// the new arguments, also transfering over the names as well.
//
- for (Function::arg_iterator I = F->arg_begin(), E = F->arg_end(), I2 = NF->arg_begin();
- I != E; ++I)
+ for (Function::arg_iterator I = F->arg_begin(), E = F->arg_end(),
+ I2 = NF->arg_begin(); I != E; ++I)
if (!ArgsToPromote.count(I)) {
// If this is an unmodified argument, move the name and users over to the
// new version.
Instruction *New;
if (InvokeInst *II = dyn_cast<InvokeInst>(Call)) {
New = new InvokeInst(NF, II->getNormalDest(), II->getUnwindDest(),
- Args, "", Call);
+ &Args[0], Args.size(), "", Call);
cast<InvokeInst>(New)->setCallingConv(CS.getCallingConv());
} else {
- New = new CallInst(NF, Args, "", Call);
+ New = new CallInst(NF, &Args[0], Args.size(), "", Call);
cast<CallInst>(New)->setCallingConv(CS.getCallingConv());
if (cast<CallInst>(Call)->isTailCall())
cast<CallInst>(New)->setTailCall();
Instruction *New;
if (InvokeInst *II = dyn_cast<InvokeInst>(Call)) {
New = new InvokeInst(NF, II->getNormalDest(), II->getUnwindDest(),
- Args, "", Call);
+ &Args[0], Args.size(), "", Call);
cast<InvokeInst>(New)->setCallingConv(CS.getCallingConv());
} else {
- New = new CallInst(NF, Args, "", Call);
+ New = new CallInst(NF, &Args[0], Args.size(), "", Call);
cast<CallInst>(New)->setCallingConv(CS.getCallingConv());
if (cast<CallInst>(Call)->isTailCall())
cast<CallInst>(New)->setTailCall();
// Inst's uses and doesn't get a name.
CastInst* CI =
new BitCastInst(Inst->getOperand(1), SBPTy, "LJBuf", Inst);
- new CallInst(ThrowLongJmp, make_vector<Value*>(CI, Inst->getOperand(2), 0),
- "", Inst);
+ new CallInst(ThrowLongJmp, CI, Inst->getOperand(2), "", Inst);
SwitchValuePair& SVP = SwitchValMap[Inst->getParent()->getParent()];
// Fill in the alloca and call to initialize the SJ map.
const Type *SBPTy = PointerType::get(Type::Int8Ty);
AllocaInst* Map = new AllocaInst(SBPTy, 0, "SJMap", Inst);
- new CallInst(InitSJMap, make_vector<Value*>(Map, 0), "", Inst);
+ new CallInst(InitSJMap, Map, "", Inst);
return SJMap[Func] = Map;
}
PrelimBBMap[Func] = LongJmpPre;
// Grab the exception.
- CallInst* Cond = new
- CallInst(IsLJException, std::vector<Value*>(), "IsLJExcept");
+ CallInst* Cond = new CallInst(IsLJException, "IsLJExcept");
LongJmpPreIL.push_back(Cond);
// The "decision basic block" gets the number associated with the
new BranchInst(DecisionBB, Rethrow, Cond, LongJmpPre);
// Fill in the "decision" basic block.
- CallInst* LJVal = new CallInst(GetLJValue, std::vector<Value*>(), "LJVal");
+ CallInst* LJVal = new CallInst(GetLJValue, "LJVal");
DecisionBBIL.push_back(LJVal);
- CallInst* SJNum = new
- CallInst(TryCatchLJ, make_vector<Value*>(GetSetJmpMap(Func), 0), "SJNum");
+ CallInst* SJNum = new CallInst(TryCatchLJ, GetSetJmpMap(Func), "SJNum");
DecisionBBIL.push_back(SJNum);
SwitchInst* SI = new SwitchInst(SJNum, Rethrow, 0, DecisionBB);
const Type* SBPTy = PointerType::get(Type::Int8Ty);
CastInst* BufPtr =
new BitCastInst(Inst->getOperand(1), SBPTy, "SBJmpBuf", Inst);
- new CallInst(AddSJToMap,
- make_vector<Value*>(GetSetJmpMap(Func), BufPtr,
- ConstantInt::get(Type::Int32Ty,
- SetJmpIDMap[Func]++), 0),
- "", Inst);
+ std::vector<Value*> Args =
+ make_vector<Value*>(GetSetJmpMap(Func), BufPtr,
+ ConstantInt::get(Type::Int32Ty,
+ SetJmpIDMap[Func]++), 0);
+ new CallInst(AddSJToMap, &Args[0], Args.size(), "", 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
std::vector<Value*> Params(CI.op_begin() + 1, CI.op_end());
InvokeInst* II = new
InvokeInst(CI.getCalledValue(), NewBB, PrelimBBMap[Func],
- Params, CI.getName(), Term);
+ &Params[0], Params.size(), CI.getName(), Term);
// Replace the old call inst with the invoke inst and remove the call.
CI.replaceAllUsesWith(II);
// If this is a longjmp exception, then branch to the preliminary BB of
// the longjmp exception handling. Otherwise, go to the old exception.
- CallInst* IsLJExcept = new
- CallInst(IsLJException, std::vector<Value*>(), "IsLJExcept");
+ CallInst* IsLJExcept = new CallInst(IsLJException, "IsLJExcept");
InstList.push_back(IsLJExcept);
new BranchInst(PrelimBBMap[Func], ExceptBB, IsLJExcept, NewExceptBB);
// function.
void LowerSetJmp::visitReturnInst(ReturnInst &RI) {
Function* Func = RI.getParent()->getParent();
- new CallInst(DestroySJMap, make_vector<Value*>(GetSetJmpMap(Func), 0),
- "", &RI);
+ new CallInst(DestroySJMap, GetSetJmpMap(Func), "", &RI);
}
// visitUnwindInst - We want to destroy the setjmp map upon exit from the
// function.
void LowerSetJmp::visitUnwindInst(UnwindInst &UI) {
Function* Func = UI.getParent()->getParent();
- new CallInst(DestroySJMap, make_vector<Value*>(GetSetJmpMap(Func), 0),
- "", &UI);
+ new CallInst(DestroySJMap, GetSetJmpMap(Func), "", &UI);
}
ModulePass *llvm::createLowerSetJmpPass() {
#include "llvm/Intrinsics.h"
#include "llvm/Instructions.h"
#include "llvm/Analysis/CallGraph.h"
+#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/Support/CFG.h"
#include "llvm/Support/Compiler.h"
if (InvokeInst *II = dyn_cast<InvokeInst>(BB->getTerminator()))
if (Function *F = II->getCalledFunction())
if (DoesNotUnwind.count(CG[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(),
- std::vector<Value*>(II->op_begin()+3,
- II->op_end()),
- "", II);
+ &Args[0], Args.size(), "", II);
Call->takeName(II);
Call->setCallingConv(II->getCallingConv());
}
Args[3] = ConstantInt::get(Type::Int32Ty, NumElements);
- Instruction *InitCall = new CallInst(InitFn, Args, "newargc", InsertPos);
+ Instruction *InitCall = new CallInst(InitFn, &Args[0], Args.size(),
+ "newargc", InsertPos);
// If argc or argv are not available in main, just pass null values in.
Function::arg_iterator AI;
#include "llvm/Transforms/Utils/UnifyFunctionExitNodes.h"
#include "llvm/Support/Debug.h"
#include "llvm/ADT/DepthFirstIterator.h"
+#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/Support/Compiler.h"
if (AA.onlyReadsMemory(F)) {
// The function cannot unwind. Convert it to a call with a branch
// after it to the normal destination.
- std::vector<Value*> Args(II->op_begin()+3, II->op_end());
- CallInst *NewCall = new CallInst(F, Args, "", II);
+ SmallVector<Value*, 8> Args(II->op_begin()+3, II->op_end());
+ CallInst *NewCall = new CallInst(F, &Args[0], Args.size(), "", II);
NewCall->takeName(II);
NewCall->setCallingConv(II->getCallingConv());
II->replaceAllUsesWith(NewCall);
Instruction *NC;
if (InvokeInst *II = dyn_cast<InvokeInst>(Caller)) {
NC = new InvokeInst(Callee, II->getNormalDest(), II->getUnwindDest(),
- Args, Caller->getName(), Caller);
+ &Args[0], Args.size(), Caller->getName(), Caller);
cast<InvokeInst>(II)->setCallingConv(II->getCallingConv());
} else {
- NC = new CallInst(Callee, Args, Caller->getName(), Caller);
+ NC = new CallInst(Callee, &Args[0], Args.size(), Caller->getName(), Caller);
if (cast<CallInst>(Caller)->isTailCall())
cast<CallInst>(NC)->setTailCall();
cast<CallInst>(NC)->setCallingConv(cast<CallInst>(Caller)->getCallingConv());
NewBB->getInstList().remove(CI);
// Create a new invoke instruction.
+ std::vector<Value*> Args(CI->op_begin()+1, CI->op_end());
+
Value *II = new InvokeInst(CI->getCalledValue(), NewBB, Cleanup,
- std::vector<Value*>(CI->op_begin()+1,
- CI->op_end()),
- CI->getName(), CBB);
+ &Args[0], Args.size(), CI->getName(), CBB);
CI->replaceAllUsesWith(II);
delete CI;
}
}
// Emit the call to the function
- CallInst *call = new CallInst(newFunction, params,
+ CallInst *call = new CallInst(newFunction, ¶ms[0], params.size(),
NumExitBlocks > 1 ? "targetBlock" : "");
codeReplacer->getInstList().push_back(call);
#include "llvm/Instructions.h"
#include "llvm/Intrinsics.h"
#include "llvm/Analysis/CallGraph.h"
+#include "llvm/ADT/SmallVector.h"
#include "llvm/Support/CallSite.h"
using namespace llvm;
// Next, create the new invoke instruction, inserting it at the end
// of the old basic block.
+ SmallVector<Value*, 8> InvokeArgs(CI->op_begin()+1, CI->op_end());
InvokeInst *II =
new InvokeInst(CI->getCalledValue(), Split, InvokeDest,
- std::vector<Value*>(CI->op_begin()+1, CI->op_end()),
+ &InvokeArgs[0], InvokeArgs.size(),
CI->getName(), BB->getTerminator());
II->setCallingConv(CI->getCallingConv());
createAbortMessage(IB->getParent()->getParent()->getParent());
// These are the arguments we WANT...
- std::vector<Value*> Args;
- Args.push_back(ConstantInt::get(Type::Int32Ty, 2));
- Args.push_back(AbortMessage);
- Args.push_back(ConstantInt::get(Type::Int32Ty, AbortMessageLength));
- (new CallInst(WriteFn, Args, "", IB))->setTailCall();
+ Value* Args[3];
+ Args[0] = ConstantInt::get(Type::Int32Ty, 2);
+ Args[1] = AbortMessage;
+ Args[2] = ConstantInt::get(Type::Int32Ty, AbortMessageLength);
+ (new CallInst(WriteFn, Args, 3, "", IB))->setTailCall();
}
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());
// Insert a normal call instruction...
CallInst *NewCall = new CallInst(II->getCalledValue(),
- std::vector<Value*>(II->op_begin()+3,
- II->op_end()), "", II);
+ &CallArgs[0], CallArgs.size(), "", II);
NewCall->takeName(II);
NewCall->setCallingConv(II->getCallingConv());
II->replaceAllUsesWith(NewCall);
writeAbortMessage(UI);
// Insert a call to abort()
- (new CallInst(AbortFn, std::vector<Value*>(), "", UI))->setTailCall();
+ (new CallInst(AbortFn, "", UI))->setTailCall();
// Insert a return instruction. This really should be a "barrier", as it
// is unreachable.
CatchSwitch->addCase(InvokeNoC, II->getUnwindDest());
// Insert a normal call instruction.
+ std::vector<Value*> CallArgs(II->op_begin()+3, II->op_end());
CallInst *NewCall = new CallInst(II->getCalledValue(),
- std::vector<Value*>(II->op_begin()+3,
- II->op_end()), "",
+ &CallArgs[0], CallArgs.size(), "",
II);
NewCall->takeName(II);
NewCall->setCallingConv(II->getCallingConv());
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, "", UnwindBlock);
+ new CallInst(LongJmpFn, &Idx[0], Idx.size(), "", UnwindBlock);
new UnreachableInst(UnwindBlock);
// Set up the term block ("throw without a catch").
writeAbortMessage(TermBlock->getTerminator());
// Insert a call to abort()
- (new CallInst(AbortFn, std::vector<Value*>(), "",
+ (new CallInst(AbortFn, "",
TermBlock->getTerminator()))->setTailCall();
#include "llvm/Support/Debug.h"
#include "llvm/Analysis/ConstantFolding.h"
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
+#include "llvm/ADT/SmallVector.h"
#include <algorithm>
#include <functional>
#include <set>
Pred->getInstList().remove(II); // Take out of symbol table
// Insert the call now...
- std::vector<Value*> Args(II->op_begin()+3, II->op_end());
- CallInst *CI = new CallInst(II->getCalledValue(), Args,
- II->getName(), BI);
+ SmallVector<Value*,8> Args(II->op_begin()+3, II->op_end());
+ CallInst *CI = new CallInst(II->getCalledValue(),
+ &Args[0], Args.size(), II->getName(), BI);
CI->setCallingConv(II->getCallingConv());
// If the invoke produced a value, the Call now does instead
II->replaceAllUsesWith(CI);
II->removeFromParent(); // Take out of symbol table
// Insert the call now...
- std::vector<Value*> Args(II->op_begin()+3, II->op_end());
- CallInst *CI = new CallInst(II->getCalledValue(), Args,
+ SmallVector<Value*, 8> Args(II->op_begin()+3, II->op_end());
+ CallInst *CI = new CallInst(II->getCalledValue(),
+ &Args[0], Args.size(),
II->getName(), BI);
CI->setCallingConv(II->getCallingConv());
// If the invoke produced a value, the Call does now instead.