mirror of
https://github.com/ldc-developers/ldc.git
synced 2025-05-01 07:30:43 +03:00
Use llvm::CallSite instead of custom CallOrInvoke class.
This commit is contained in:
parent
b7febcf35a
commit
dd41366a99
9 changed files with 46 additions and 76 deletions
|
@ -84,7 +84,7 @@ DValue* DtoAAIndex(Loc& loc, Type* type, DValue* aa, DValue* key, bool lvalue)
|
|||
pkey = DtoBitCast(pkey, funcTy->getParamType(3));
|
||||
|
||||
// call runtime
|
||||
LLValue* ret = gIR->CreateCallOrInvoke4(func, aaval, keyti, valsize, pkey, "aa.index")->get();
|
||||
LLValue* ret = gIR->CreateCallOrInvoke4(func, aaval, keyti, valsize, pkey, "aa.index").getInstruction();
|
||||
|
||||
// cast return value
|
||||
const LLType* targettype = getPtrToType(DtoType(type));
|
||||
|
@ -126,7 +126,7 @@ DValue* DtoAAIn(Loc& loc, Type* type, DValue* aa, DValue* key)
|
|||
pkey = DtoBitCast(pkey, funcTy->getParamType(2));
|
||||
|
||||
// call runtime
|
||||
LLValue* ret = gIR->CreateCallOrInvoke3(func, aaval, keyti, pkey, "aa.in")->get();
|
||||
LLValue* ret = gIR->CreateCallOrInvoke3(func, aaval, keyti, pkey, "aa.in").getInstruction();
|
||||
|
||||
// cast return value
|
||||
const LLType* targettype = DtoType(type);
|
||||
|
|
|
@ -200,8 +200,8 @@ void DtoArrayInit(Loc& loc, DValue* array, DValue* value)
|
|||
assert(fn);
|
||||
if (Logger::enabled())
|
||||
Logger::cout() << "calling array init function: " << *fn <<'\n';
|
||||
CallOrInvoke* call = gIR->CreateCallOrInvoke(fn, args.begin(), args.end());
|
||||
call->setCallingConv(llvm::CallingConv::C);
|
||||
LLCallSite call = gIR->CreateCallOrInvoke(fn, args.begin(), args.end());
|
||||
call.setCallingConv(llvm::CallingConv::C);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -392,7 +392,7 @@ DSliceValue* DtoNewDynArray(Loc& loc, Type* arrayType, DValue* dim, bool default
|
|||
LLFunction* fn = LLVM_D_GetRuntimeFunction(gIR->module, fnname);
|
||||
|
||||
// call allocator
|
||||
LLValue* newptr = gIR->CreateCallOrInvoke2(fn, arrayTypeInfo, arrayLen, ".gc_mem")->get();
|
||||
LLValue* newptr = gIR->CreateCallOrInvoke2(fn, arrayTypeInfo, arrayLen, ".gc_mem").getInstruction();
|
||||
|
||||
// cast to wanted type
|
||||
const LLType* dstType = DtoType(arrayType)->getContainedType(1);
|
||||
|
@ -435,7 +435,7 @@ DSliceValue* DtoNewMulDimDynArray(Loc& loc, Type* arrayType, DValue** dims, size
|
|||
}
|
||||
|
||||
// call allocator
|
||||
LLValue* newptr = gIR->CreateCallOrInvoke3(fn, arrayTypeInfo, DtoConstSize_t(ndims), dimsArg, ".gc_mem")->get();
|
||||
LLValue* newptr = gIR->CreateCallOrInvoke3(fn, arrayTypeInfo, DtoConstSize_t(ndims), dimsArg, ".gc_mem").getInstruction();
|
||||
|
||||
// cast to wanted type
|
||||
const LLType* dstType = DtoType(arrayType)->getContainedType(1);
|
||||
|
@ -476,7 +476,7 @@ DSliceValue* DtoResizeDynArray(Type* arrayType, DValue* array, DValue* newdim)
|
|||
Logger::cout() << "arrPtr = " << *arrPtr << '\n';
|
||||
args.push_back(DtoBitCast(arrPtr, fn->getFunctionType()->getParamType(3), "tmp"));
|
||||
|
||||
LLValue* newptr = gIR->CreateCallOrInvoke(fn, args.begin(), args.end(), ".gc_mem")->get();
|
||||
LLValue* newptr = gIR->CreateCallOrInvoke(fn, args.begin(), args.end(), ".gc_mem").getInstruction();
|
||||
if (newptr->getType() != arrPtr->getType())
|
||||
newptr = DtoBitCast(newptr, arrPtr->getType(), ".gc_mem");
|
||||
|
||||
|
@ -684,9 +684,9 @@ static LLValue* DtoArrayEqCmp_impl(Loc& loc, const char* func, DValue* l, DValue
|
|||
args.push_back(DtoBitCast(tival, fn->getFunctionType()->getParamType(2)));
|
||||
}
|
||||
|
||||
CallOrInvoke* call = gIR->CreateCallOrInvoke(fn, args.begin(), args.end(), "tmp");
|
||||
LLCallSite call = gIR->CreateCallOrInvoke(fn, args.begin(), args.end(), "tmp");
|
||||
|
||||
return call->get();
|
||||
return call.getInstruction();
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -780,7 +780,7 @@ LLValue* DtoArrayCastLength(LLValue* len, const LLType* elemty, const LLType* ne
|
|||
args.push_back(llvm::ConstantInt::get(DtoSize_t(), nsz, false));
|
||||
|
||||
LLFunction* fn = LLVM_D_GetRuntimeFunction(gIR->module, "_d_array_cast_len");
|
||||
return gIR->CreateCallOrInvoke(fn, args.begin(), args.end(), "tmp")->get();
|
||||
return gIR->CreateCallOrInvoke(fn, args.begin(), args.end(), "tmp").getInstruction();
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -993,7 +993,7 @@ void DtoArrayBoundsCheck(Loc& loc, DValue* arr, DValue* index, bool isslice)
|
|||
|
||||
// call
|
||||
llvm::Function* errorfn = LLVM_D_GetRuntimeFunction(gIR->module, "_d_array_bounds");
|
||||
CallOrInvoke* call = gIR->CreateCallOrInvoke(errorfn, args.begin(), args.end());
|
||||
gIR->CreateCallOrInvoke(errorfn, args.begin(), args.end());
|
||||
|
||||
// the function does not return
|
||||
gIR->ir->CreateUnreachable();
|
||||
|
|
|
@ -919,7 +919,7 @@ DValue* DtoNewClass(Loc loc, TypeClass* tc, NewExp* newexp)
|
|||
{
|
||||
llvm::Function* fn = LLVM_D_GetRuntimeFunction(gIR->module, "_d_allocclass");
|
||||
LLConstant* ci = DtoBitCast(tc->sym->ir.irStruct->classInfo, DtoType(ClassDeclaration::classinfo->type));
|
||||
mem = gIR->CreateCallOrInvoke(fn, ci, ".newclass_gc_alloc")->get();
|
||||
mem = gIR->CreateCallOrInvoke(fn, ci, ".newclass_gc_alloc").getInstruction();
|
||||
mem = DtoBitCast(mem, DtoType(tc), ".newclass_gc");
|
||||
}
|
||||
|
||||
|
@ -1137,7 +1137,7 @@ DValue* DtoDynamicCastObject(DValue* val, Type* _to)
|
|||
assert(funcTy->getParamType(1) == cinfo->getType());
|
||||
|
||||
// call it
|
||||
LLValue* ret = gIR->CreateCallOrInvoke2(func, obj, cinfo, "tmp")->get();
|
||||
LLValue* ret = gIR->CreateCallOrInvoke2(func, obj, cinfo, "tmp").getInstruction();
|
||||
|
||||
// cast return value
|
||||
ret = DtoBitCast(ret, DtoType(_to));
|
||||
|
@ -1160,7 +1160,7 @@ DValue* DtoCastInterfaceToObject(DValue* val, Type* to)
|
|||
tmp = DtoBitCast(tmp, funcTy->getParamType(0));
|
||||
|
||||
// call it
|
||||
LLValue* ret = gIR->CreateCallOrInvoke(func, tmp, "tmp")->get();
|
||||
LLValue* ret = gIR->CreateCallOrInvoke(func, tmp, "tmp").getInstruction();
|
||||
|
||||
// cast return value
|
||||
if (to != NULL)
|
||||
|
@ -1200,7 +1200,7 @@ DValue* DtoDynamicCastInterface(DValue* val, Type* _to)
|
|||
cinfo = DtoBitCast(cinfo, funcTy->getParamType(1));
|
||||
|
||||
// call it
|
||||
LLValue* ret = gIR->CreateCallOrInvoke2(func, ptr, cinfo, "tmp")->get();
|
||||
LLValue* ret = gIR->CreateCallOrInvoke2(func, ptr, cinfo, "tmp").getInstruction();
|
||||
|
||||
// cast return value
|
||||
ret = DtoBitCast(ret, DtoType(_to));
|
||||
|
|
|
@ -121,20 +121,20 @@ bool IRState::scopereturned()
|
|||
return !scopebb()->empty() && scopebb()->back().isTerminator();
|
||||
}
|
||||
|
||||
CallOrInvoke* IRState::CreateCallOrInvoke(LLValue* Callee, const char* Name)
|
||||
LLCallSite IRState::CreateCallOrInvoke(LLValue* Callee, const char* Name)
|
||||
{
|
||||
LLSmallVector<LLValue*, 1> args;
|
||||
return CreateCallOrInvoke(Callee, args.begin(), args.end(), Name);
|
||||
}
|
||||
|
||||
CallOrInvoke* IRState::CreateCallOrInvoke(LLValue* Callee, LLValue* Arg1, const char* Name)
|
||||
LLCallSite IRState::CreateCallOrInvoke(LLValue* Callee, LLValue* Arg1, const char* Name)
|
||||
{
|
||||
LLSmallVector<LLValue*, 1> args;
|
||||
args.push_back(Arg1);
|
||||
return CreateCallOrInvoke(Callee, args.begin(), args.end(), Name);
|
||||
}
|
||||
|
||||
CallOrInvoke* IRState::CreateCallOrInvoke2(LLValue* Callee, LLValue* Arg1, LLValue* Arg2, const char* Name)
|
||||
LLCallSite IRState::CreateCallOrInvoke2(LLValue* Callee, LLValue* Arg1, LLValue* Arg2, const char* Name)
|
||||
{
|
||||
LLSmallVector<LLValue*, 2> args;
|
||||
args.push_back(Arg1);
|
||||
|
@ -142,7 +142,7 @@ CallOrInvoke* IRState::CreateCallOrInvoke2(LLValue* Callee, LLValue* Arg1, LLVal
|
|||
return CreateCallOrInvoke(Callee, args.begin(), args.end(), Name);
|
||||
}
|
||||
|
||||
CallOrInvoke* IRState::CreateCallOrInvoke3(LLValue* Callee, LLValue* Arg1, LLValue* Arg2, LLValue* Arg3, const char* Name)
|
||||
LLCallSite IRState::CreateCallOrInvoke3(LLValue* Callee, LLValue* Arg1, LLValue* Arg2, LLValue* Arg3, const char* Name)
|
||||
{
|
||||
LLSmallVector<LLValue*, 3> args;
|
||||
args.push_back(Arg1);
|
||||
|
@ -151,7 +151,7 @@ CallOrInvoke* IRState::CreateCallOrInvoke3(LLValue* Callee, LLValue* Arg1, LLVal
|
|||
return CreateCallOrInvoke(Callee, args.begin(), args.end(), Name);
|
||||
}
|
||||
|
||||
CallOrInvoke* IRState::CreateCallOrInvoke4(LLValue* Callee, LLValue* Arg1, LLValue* Arg2, LLValue* Arg3, LLValue* Arg4, const char* Name)
|
||||
LLCallSite IRState::CreateCallOrInvoke4(LLValue* Callee, LLValue* Arg1, LLValue* Arg2, LLValue* Arg3, LLValue* Arg4, const char* Name)
|
||||
{
|
||||
LLSmallVector<LLValue*, 4> args;
|
||||
args.push_back(Arg1);
|
||||
|
|
|
@ -13,6 +13,8 @@
|
|||
#include "ir/irstruct.h"
|
||||
#include "ir/irvar.h"
|
||||
|
||||
#include "llvm/Support/CallSite.h"
|
||||
|
||||
namespace llvm {
|
||||
class TargetMachine;
|
||||
}
|
||||
|
@ -106,42 +108,6 @@ struct IRAsmBlock
|
|||
{}
|
||||
};
|
||||
|
||||
// llvm::CallInst and llvm::InvokeInst don't share a common base
|
||||
// but share common functionality. to avoid duplicating code for
|
||||
// adjusting these common properties these structs are made
|
||||
struct CallOrInvoke
|
||||
{
|
||||
virtual void setAttributes(const llvm::AttrListPtr& Attrs) = 0;
|
||||
virtual void setCallingConv(unsigned CC) = 0;
|
||||
virtual llvm::Instruction* get() = 0;
|
||||
};
|
||||
|
||||
struct CallOrInvoke_Call : public CallOrInvoke
|
||||
{
|
||||
llvm::CallInst* inst;
|
||||
CallOrInvoke_Call(llvm::CallInst* call) : inst(call) {}
|
||||
|
||||
virtual void setAttributes(const llvm::AttrListPtr& Attrs)
|
||||
{ inst->setAttributes(Attrs); }
|
||||
virtual void setCallingConv(unsigned CC)
|
||||
{ inst->setCallingConv(CC); }
|
||||
virtual llvm::Instruction* get()
|
||||
{ return inst; }
|
||||
};
|
||||
|
||||
struct CallOrInvoke_Invoke : public CallOrInvoke
|
||||
{
|
||||
llvm::InvokeInst* inst;
|
||||
CallOrInvoke_Invoke(llvm::InvokeInst* invoke) : inst(invoke) {}
|
||||
|
||||
virtual void setAttributes(const llvm::AttrListPtr& Attrs)
|
||||
{ inst->setAttributes(Attrs); }
|
||||
virtual void setCallingConv(unsigned CC)
|
||||
{ inst->setCallingConv(CC); }
|
||||
virtual llvm::Instruction* get()
|
||||
{ return inst; }
|
||||
};
|
||||
|
||||
// represents the module
|
||||
struct IRState
|
||||
{
|
||||
|
@ -184,12 +150,12 @@ struct IRState
|
|||
// create a call or invoke, depending on the landing pad info
|
||||
// the template function is defined further down in this file
|
||||
template <typename InputIterator>
|
||||
CallOrInvoke* CreateCallOrInvoke(LLValue* Callee, InputIterator ArgBegin, InputIterator ArgEnd, const char* Name="");
|
||||
CallOrInvoke* CreateCallOrInvoke(LLValue* Callee, const char* Name="");
|
||||
CallOrInvoke* CreateCallOrInvoke(LLValue* Callee, LLValue* Arg1, const char* Name="");
|
||||
CallOrInvoke* CreateCallOrInvoke2(LLValue* Callee, LLValue* Arg1, LLValue* Arg2, const char* Name="");
|
||||
CallOrInvoke* CreateCallOrInvoke3(LLValue* Callee, LLValue* Arg1, LLValue* Arg2, LLValue* Arg3, const char* Name="");
|
||||
CallOrInvoke* CreateCallOrInvoke4(LLValue* Callee, LLValue* Arg1, LLValue* Arg2, LLValue* Arg3, LLValue* Arg4, const char* Name="");
|
||||
llvm::CallSite CreateCallOrInvoke(LLValue* Callee, InputIterator ArgBegin, InputIterator ArgEnd, const char* Name="");
|
||||
llvm::CallSite CreateCallOrInvoke(LLValue* Callee, const char* Name="");
|
||||
llvm::CallSite CreateCallOrInvoke(LLValue* Callee, LLValue* Arg1, const char* Name="");
|
||||
llvm::CallSite CreateCallOrInvoke2(LLValue* Callee, LLValue* Arg1, LLValue* Arg2, const char* Name="");
|
||||
llvm::CallSite CreateCallOrInvoke3(LLValue* Callee, LLValue* Arg1, LLValue* Arg2, LLValue* Arg3, const char* Name="");
|
||||
llvm::CallSite CreateCallOrInvoke4(LLValue* Callee, LLValue* Arg1, LLValue* Arg2, LLValue* Arg3, LLValue* Arg4, const char* Name="");
|
||||
|
||||
// loop blocks
|
||||
typedef std::vector<IRLoopScope> LoopScopeVec;
|
||||
|
@ -237,7 +203,7 @@ struct IRState
|
|||
};
|
||||
|
||||
template <typename InputIterator>
|
||||
CallOrInvoke* IRState::CreateCallOrInvoke(LLValue* Callee, InputIterator ArgBegin, InputIterator ArgEnd, const char* Name)
|
||||
llvm::CallSite IRState::CreateCallOrInvoke(LLValue* Callee, InputIterator ArgBegin, InputIterator ArgEnd, const char* Name)
|
||||
{
|
||||
llvm::BasicBlock* pad;
|
||||
if(pad = func()->landingPad.get())
|
||||
|
@ -246,16 +212,16 @@ CallOrInvoke* IRState::CreateCallOrInvoke(LLValue* Callee, InputIterator ArgBegi
|
|||
LLFunction* funcval = llvm::dyn_cast<LLFunction>(Callee);
|
||||
if (funcval && funcval->isIntrinsic())
|
||||
{
|
||||
return new CallOrInvoke_Call(ir->CreateCall(Callee, ArgBegin, ArgEnd, Name));
|
||||
return ir->CreateCall(Callee, ArgBegin, ArgEnd, Name);
|
||||
}
|
||||
|
||||
llvm::BasicBlock* postinvoke = llvm::BasicBlock::Create("postinvoke", topfunc(), scopeend());
|
||||
llvm::InvokeInst* invoke = ir->CreateInvoke(Callee, postinvoke, pad, ArgBegin, ArgEnd, Name);
|
||||
scope() = IRScope(postinvoke, scopeend());
|
||||
return new CallOrInvoke_Invoke(invoke);
|
||||
return invoke;
|
||||
}
|
||||
else
|
||||
return new CallOrInvoke_Call(ir->CreateCall(Callee, ArgBegin, ArgEnd, Name));
|
||||
return ir->CreateCall(Callee, ArgBegin, ArgEnd, Name);
|
||||
}
|
||||
|
||||
#endif // LDC_GEN_IRSTATE_H
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
|
||||
#include "llvm/Analysis/DebugInfo.h"
|
||||
|
||||
#include "llvm/Support/CallSite.h"
|
||||
|
||||
#include "llvm/Support/IRBuilder.h"
|
||||
using llvm::IRBuilder;
|
||||
|
||||
|
@ -47,6 +49,8 @@ using llvm::IRBuilder;
|
|||
|
||||
#define LLPATypeHolder llvm::PATypeHolder
|
||||
|
||||
#define LLCallSite llvm::CallSite
|
||||
|
||||
#define LLSmallVector llvm::SmallVector
|
||||
|
||||
using llvm::APFloat;
|
||||
|
|
|
@ -37,7 +37,7 @@ LLValue* DtoNew(Type* newtype)
|
|||
LLConstant* ti = DtoTypeInfoOf(newtype);
|
||||
assert(isaPointer(ti));
|
||||
// call runtime allocator
|
||||
LLValue* mem = gIR->CreateCallOrInvoke(fn, ti, ".gc_mem")->get();
|
||||
LLValue* mem = gIR->CreateCallOrInvoke(fn, ti, ".gc_mem").getInstruction();
|
||||
// cast
|
||||
return DtoBitCast(mem, getPtrToType(DtoType(newtype)), ".gc_mem");
|
||||
}
|
||||
|
@ -136,7 +136,7 @@ void DtoAssert(Module* M, Loc* loc, DValue* msg)
|
|||
args.push_back(c);
|
||||
|
||||
// call
|
||||
CallOrInvoke* call = gIR->CreateCallOrInvoke(fn, args.begin(), args.end());
|
||||
gIR->CreateCallOrInvoke(fn, args.begin(), args.end());
|
||||
|
||||
// end debug info
|
||||
if (global.params.symdebug)
|
||||
|
|
|
@ -736,9 +736,9 @@ static LLValue* call_string_switch_runtime(llvm::Value* table, Expression* e)
|
|||
LLValue* llval = val->getRVal();
|
||||
assert(llval->getType() == fn->getFunctionType()->getParamType(1));
|
||||
|
||||
CallOrInvoke* call = gIR->CreateCallOrInvoke2(fn, table, llval, "tmp");
|
||||
LLCallSite call = gIR->CreateCallOrInvoke2(fn, table, llval, "tmp");
|
||||
|
||||
return call->get();
|
||||
return call.getInstruction();
|
||||
}
|
||||
|
||||
void SwitchStatement::toIR(IRState* p)
|
||||
|
@ -1438,7 +1438,7 @@ void SwitchErrorStatement::toIR(IRState* p)
|
|||
args.push_back(c);
|
||||
|
||||
// call
|
||||
CallOrInvoke* call = gIR->CreateCallOrInvoke(fn, args.begin(), args.end());
|
||||
gIR->CreateCallOrInvoke(fn, args.begin(), args.end());
|
||||
|
||||
gIR->ir->CreateUnreachable();
|
||||
}
|
||||
|
|
|
@ -459,10 +459,10 @@ DValue* DtoCallFunction(Loc& loc, Type* resulttype, DValue* fnval, Expressions*
|
|||
Logger::cout() << "Calling: " << *callable << '\n';
|
||||
|
||||
// call the function
|
||||
CallOrInvoke* call = gIR->CreateCallOrInvoke(callable, args.begin(), args.end(), varname);
|
||||
LLCallSite call = gIR->CreateCallOrInvoke(callable, args.begin(), args.end(), varname);
|
||||
|
||||
// get return value
|
||||
LLValue* retllval = (retinptr) ? args[0] : call->get();
|
||||
LLValue* retllval = (retinptr) ? args[0] : call.getInstruction();
|
||||
|
||||
if (tf->linkage == LINKintrinsic)
|
||||
{
|
||||
|
@ -521,11 +521,11 @@ DValue* DtoCallFunction(Loc& loc, Type* resulttype, DValue* fnval, Expressions*
|
|||
if (llfunc && llfunc->isIntrinsic()) // override intrinsic attrs
|
||||
attrlist = llvm::Intrinsic::getAttributes((llvm::Intrinsic::ID)llfunc->getIntrinsicID());
|
||||
else
|
||||
call->setCallingConv(callconv);
|
||||
call.setCallingConv(callconv);
|
||||
}
|
||||
else
|
||||
call->setCallingConv(callconv);
|
||||
call->setAttributes(attrlist);
|
||||
call.setCallingConv(callconv);
|
||||
call.setAttributes(attrlist);
|
||||
|
||||
return new DImValue(resulttype, retllval);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue