changeset 1013:8c73ff5f69e0

Use llvm::CallSite instead of custom CallOrInvoke class.
author Frits van Bommel <fvbommel wxs.nl>
date Sat, 28 Feb 2009 22:16:52 +0100
parents 39cf8fa483fd
children 47f8b54f90b3
files gen/aa.cpp gen/arrays.cpp gen/classes.cpp gen/irstate.cpp gen/irstate.h gen/llvm.h gen/llvmhelpers.cpp gen/statements.cpp gen/tocall.cpp
diffstat 9 files changed, 46 insertions(+), 76 deletions(-) [+]
line wrap: on
line diff
--- a/gen/aa.cpp	Sat Feb 28 19:58:30 2009 +0100
+++ b/gen/aa.cpp	Sat Feb 28 22:16:52 2009 +0100
@@ -84,7 +84,7 @@
     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 @@
     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);
--- a/gen/arrays.cpp	Sat Feb 28 19:58:30 2009 +0100
+++ b/gen/arrays.cpp	Sat Feb 28 22:16:52 2009 +0100
@@ -200,8 +200,8 @@
     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 @@
     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 @@
     }
 
     // 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 @@
         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 @@
         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 @@
     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 @@
 
     // 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();
--- a/gen/classes.cpp	Sat Feb 28 19:58:30 2009 +0100
+++ b/gen/classes.cpp	Sat Feb 28 22:16:52 2009 +0100
@@ -919,7 +919,7 @@
     {
         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 @@
     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 @@
     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 @@
     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));
--- a/gen/irstate.cpp	Sat Feb 28 19:58:30 2009 +0100
+++ b/gen/irstate.cpp	Sat Feb 28 22:16:52 2009 +0100
@@ -121,20 +121,20 @@
     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 @@
     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 @@
     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);
--- a/gen/irstate.h	Sat Feb 28 19:58:30 2009 +0100
+++ b/gen/irstate.h	Sat Feb 28 22:16:52 2009 +0100
@@ -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 @@
     {}
 };
 
-// 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 @@
     // 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 @@
 };
 
 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 @@
         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
--- a/gen/llvm.h	Sat Feb 28 19:58:30 2009 +0100
+++ b/gen/llvm.h	Sat Feb 28 22:16:52 2009 +0100
@@ -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 @@
 
 #define LLPATypeHolder llvm::PATypeHolder
 
+#define LLCallSite llvm::CallSite
+
 #define LLSmallVector llvm::SmallVector
 
 using llvm::APFloat;
--- a/gen/llvmhelpers.cpp	Sat Feb 28 19:58:30 2009 +0100
+++ b/gen/llvmhelpers.cpp	Sat Feb 28 22:16:52 2009 +0100
@@ -37,7 +37,7 @@
     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 @@
     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)
--- a/gen/statements.cpp	Sat Feb 28 19:58:30 2009 +0100
+++ b/gen/statements.cpp	Sat Feb 28 22:16:52 2009 +0100
@@ -736,9 +736,9 @@
     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 @@
     args.push_back(c);
 
     // call
-    CallOrInvoke* call = gIR->CreateCallOrInvoke(fn, args.begin(), args.end());
+    gIR->CreateCallOrInvoke(fn, args.begin(), args.end());
 
     gIR->ir->CreateUnreachable();
 }
--- a/gen/tocall.cpp	Sat Feb 28 19:58:30 2009 +0100
+++ b/gen/tocall.cpp	Sat Feb 28 22:16:52 2009 +0100
@@ -459,10 +459,10 @@
         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 @@
         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);
 }