From: Anton Korobeynikov Date: Wed, 17 Jun 2009 22:20:46 +0000 (+0000) Subject: Honour calling convention and attributes of Callee by default. X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=bf823e75907c81d0ba74b7aff9d34131587c1d8b;p=oota-llvm.git Honour calling convention and attributes of Callee by default. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@73646 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/Support/IRBuilder.h b/include/llvm/Support/IRBuilder.h index bdbd8985475..316a8ad3371 100644 --- a/include/llvm/Support/IRBuilder.h +++ b/include/llvm/Support/IRBuilder.h @@ -17,6 +17,7 @@ #include "llvm/Constants.h" #include "llvm/Instructions.h" +#include "llvm/GlobalAlias.h" #include "llvm/GlobalVariable.h" #include "llvm/Function.h" #include "llvm/Support/ConstantFolder.h" @@ -586,32 +587,49 @@ public: return Insert(PHINode::Create(Ty), Name); } + CallInst *TransferAttributes(CallInst *CI, const Value* Callee) const { + if (const GlobalAlias *GA = dyn_cast(Callee)) + Callee = GA->getAliasedGlobal(); + + if (const Function *F = dyn_cast(Callee)) { + CI->setCallingConv(F->getCallingConv()); + CI->setAttributes(F->getAttributes()); + } + + return CI; + } + CallInst *CreateCall(Value *Callee, const char *Name = "") { - return Insert(CallInst::Create(Callee), Name); + return Insert(TransferAttributes(CallInst::Create(Callee), Callee), Name); } CallInst *CreateCall(Value *Callee, Value *Arg, const char *Name = "") { - return Insert(CallInst::Create(Callee, Arg), Name); + return Insert(TransferAttributes(CallInst::Create(Callee, Arg), + Callee), Name); } CallInst *CreateCall2(Value *Callee, Value *Arg1, Value *Arg2, const char *Name = "") { Value *Args[] = { Arg1, Arg2 }; - return Insert(CallInst::Create(Callee, Args, Args+2), Name); + return Insert(TransferAttributes(CallInst::Create(Callee, Args, Args+2), + Callee), Name); } CallInst *CreateCall3(Value *Callee, Value *Arg1, Value *Arg2, Value *Arg3, const char *Name = "") { Value *Args[] = { Arg1, Arg2, Arg3 }; - return Insert(CallInst::Create(Callee, Args, Args+3), Name); + return Insert(TransferAttributes(CallInst::Create(Callee, Args, Args+3), + Callee), Name); } CallInst *CreateCall4(Value *Callee, Value *Arg1, Value *Arg2, Value *Arg3, Value *Arg4, const char *Name = "") { Value *Args[] = { Arg1, Arg2, Arg3, Arg4 }; - return Insert(CallInst::Create(Callee, Args, Args+4), Name); + return Insert(TransferAttributes(CallInst::Create(Callee, Args, Args+4), + Callee), Name); } template CallInst *CreateCall(Value *Callee, InputIterator ArgBegin, InputIterator ArgEnd, const char *Name = "") { - return Insert(CallInst::Create(Callee, ArgBegin, ArgEnd), Name); + return Insert(TransferAttributes(CallInst::Create(Callee, ArgBegin, ArgEnd), + Callee), Name); } Value *CreateSelect(Value *C, Value *True, Value *False,