Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

WIP: port to llvm 3.0

  • Loading branch information...
commit 629f13929e1a236473c6adc6d874615eafbab122 1 parent 423076d
@AlexeyProkhin AlexeyProkhin authored
Showing with 934 additions and 897 deletions.
  1. +1 −1  dmd/module.c
  2. +2 −2 dmd/module.h
  3. +2 −18 dmd2/func.c
  4. +1 −1  dmd2/module.c
  5. +2 −2 dmd2/module.h
  6. +1 −0  dmd2/statement.h
  7. +10 −10 gen/aa.cpp
  8. +4 −4 gen/abi-generic.h
  9. +5 −5 gen/abi-x86-64.cpp
  10. +1 −1  gen/abi.cpp
  11. +1 −1  gen/abi.h
  12. +52 −41 gen/arrays.cpp
  13. +5 −5 gen/arrays.h
  14. +5 −5 gen/asmstmt.cpp
  15. +16 −15 gen/classes.cpp
  16. +9 −6 gen/complex.cpp
  17. +2 −2 gen/complex.h
  18. +1 −1  gen/configfile.cpp
  19. +34 −6 gen/declarations.cpp
  20. +1 −0  gen/dvalue.cpp
  21. +1 −1  gen/dvalue.h
  22. +14 −14 gen/functions.cpp
  23. +3 −3 gen/functions.h
  24. +5 −5 gen/irstate.cpp
  25. +11 −11 gen/irstate.h
  26. +0 −2  gen/llvm.h
  27. +114 −113 gen/llvmhelpers.cpp
  28. +3 −3 gen/llvmhelpers.h
  29. +1 −1  gen/logger.cpp
  30. +10 −10 gen/main.cpp
  31. +4 −4 gen/naked.cpp
  32. +7 −7 gen/nested.cpp
  33. +1 −2  gen/optimizer.cpp
  34. +4 −4 gen/passes/SimplifyDRuntimeCalls.cpp
  35. +20 −8 gen/rttibuilder.cpp
  36. +2 −1  gen/rttibuilder.h
  37. +188 −169 gen/runtime.cpp
  38. +10 −10 gen/statements.cpp
  39. +6 −7 gen/structs.cpp
  40. +19 −19 gen/tocall.cpp
  41. +8 −8 gen/todebug.cpp
  42. +30 −33 gen/toir.cpp
  43. +81 −86 gen/tollvm.cpp
  44. +30 −30 gen/tollvm.h
  45. +18 −20 gen/toobj.cpp
  46. +9 −8 gen/typinf.cpp
  47. +19 −24 ir/irclass.cpp
  48. +1 −1  ir/irfunction.h
  49. +1 −1  ir/irfuncty.h
  50. +2 −2 ir/irlandingpad.cpp
  51. +18 −21 ir/irstruct.cpp
  52. +7 −7 ir/irstruct.h
  53. +45 −40 ir/irtype.cpp
  54. +16 −14 ir/irtype.h
  55. +20 −35 ir/irtypeclass.cpp
  56. +8 −7 ir/irtypeclass.h
  57. +25 −19 ir/irtypefunction.cpp
  58. +5 −2 ir/irtypefunction.h
  59. +9 −15 ir/irtypestruct.cpp
  60. +1 −1  ir/irtypestruct.h
  61. +2 −2 ir/irvar.cpp
  62. +1 −1  ir/irvar.h
View
2  dmd/module.c
@@ -153,7 +153,7 @@ Module::Module(char *filename, Identifier *ident, int doDocComment, int doHdrGen
// LDC
llvmForceLogging = false;
moduleInfoVar = NULL;
- moduleInfoType = new llvm::PATypeHolder(llvm::OpaqueType::get(llvm::getGlobalContext()));
+ moduleInfoType = llvm::StructType::create(llvm::getGlobalContext());
this->doDocComment = doDocComment;
this->doHdrGen = doHdrGen;
this->isRoot = false;
View
4 dmd/module.h
@@ -35,7 +35,7 @@ namespace llvm {
class LLVMContext;
class Module;
class GlobalVariable;
- class PATypeHolder;
+ class StructType;
}
#else
@@ -202,7 +202,7 @@ struct Module : Package
bool llvmForceLogging;
llvm::GlobalVariable* moduleInfoVar;
- llvm::PATypeHolder* moduleInfoType;
+ llvm::StructType* moduleInfoType;
// array ops emitted in this module already
StringTable arrayfuncs;
View
20 dmd2/func.c
@@ -1641,28 +1641,12 @@ void FuncDeclaration::semantic3(Scope *sc)
if (ad->isStructDeclaration())
v = v->addressOf(sc);
#endif
-#if IN_LLVM
- //e = new AssertExp(loc, v, NULL);
-
- // LDC: check for null this
- //v = new ThisExp(0);
- //v->type = vthis->type;
- //v->var = vthis; // Error: Expression has no property var... in D1 typeof(v) == ThisExp
-
- //NullExp *nv = new NullExp(0);
- //nv->type = v->type;
-
- //IdentityExp *ie = new IdentityExp(TOKnotidentity, 0, v, nv);
- //ie->type = Type::tbool;
-#endif
Expression *se = new StringExp(0, (char *)"null this");
se = se->semantic(sc);
+#if !IN_LLVM
se->type = Type::tchar->arrayOf();
-//#if IN_LLVM
-// ee = new AssertExp(loc, ie, se);
-//#else
+#endif
e = new AssertExp(loc, v, se);
-//#endif
}
if (ee)
{
View
2  dmd2/module.c
@@ -213,7 +213,7 @@ Module::Module(char *filename, Identifier *ident, int doDocComment, int doHdrGen
// LDC
llvmForceLogging = false;
moduleInfoVar = NULL;
- moduleInfoType = new llvm::PATypeHolder(llvm::OpaqueType::get(llvm::getGlobalContext()));
+ moduleInfoType = llvm::StructType::create(llvm::getGlobalContext());
this->doDocComment = doDocComment;
this->doHdrGen = doHdrGen;
this->isRoot = false;
View
4 dmd2/module.h
@@ -35,7 +35,7 @@ namespace llvm {
class LLVMContext;
class Module;
class GlobalVariable;
- class PATypeHolder;
+ class StructType;
}
#else
@@ -208,7 +208,7 @@ struct Module : Package
bool llvmForceLogging;
llvm::GlobalVariable* moduleInfoVar;
- llvm::PATypeHolder* moduleInfoType;
+ llvm::StructType* moduleInfoType;
// array ops emitted in this module already
StringTable arrayfuncs;
View
1  dmd2/statement.h
@@ -106,6 +106,7 @@ enum BE
struct Statement : Object
{
Loc loc;
+ virtual ~Statement() {}
Statement(Loc loc);
virtual Statement *syntaxCopy();
View
20 gen/aa.cpp
@@ -55,7 +55,7 @@ DValue* DtoAAIndex(Loc& loc, Type* type, DValue* aa, DValue* key, bool lvalue)
#else
llvm::Function* func = LLVM_D_GetRuntimeFunction(gIR->module, lvalue?"_aaGet":"_aaIn");
#endif
- const llvm::FunctionType* funcTy = func->getFunctionType();
+ LLFunctionType* funcTy = func->getFunctionType();
// aa param
LLValue* aaval = lvalue ? aa->getLVal() : aa->getRVal();
@@ -85,7 +85,7 @@ DValue* DtoAAIndex(Loc& loc, Type* type, DValue* aa, DValue* key, bool lvalue)
}
// cast return value
- const LLType* targettype = getPtrToType(DtoType(type));
+ LLType* targettype = getPtrToType(DtoType(type));
if (ret->getType() != targettype)
ret = DtoBitCast(ret, targettype);
@@ -109,7 +109,7 @@ DValue* DtoAAIndex(Loc& loc, Type* type, DValue* aa, DValue* key, bool lvalue)
#if DMDV2
// module param
LLValue *moduleInfoSymbol = gIR->func()->decl->getModule()->moduleInfoSymbol();
- const LLType *moduleInfoType = DtoType(Module::moduleinfo->type);
+ LLType *moduleInfoType = DtoType(Module::moduleinfo->type);
args.push_back(DtoBitCast(moduleInfoSymbol, getPtrToType(moduleInfoType)));
#else
// file param
@@ -123,7 +123,7 @@ DValue* DtoAAIndex(Loc& loc, Type* type, DValue* aa, DValue* key, bool lvalue)
// call
llvm::Function* errorfn = LLVM_D_GetRuntimeFunction(gIR->module, "_d_array_bounds");
- gIR->CreateCallOrInvoke(errorfn, args.begin(), args.end());
+ gIR->CreateCallOrInvoke(errorfn, args);
// the function does not return
gIR->ir->CreateUnreachable();
@@ -152,7 +152,7 @@ DValue* DtoAAIn(Loc& loc, Type* type, DValue* aa, DValue* key)
#else
llvm::Function* func = LLVM_D_GetRuntimeFunction(gIR->module, "_aaIn");
#endif
- const llvm::FunctionType* funcTy = func->getFunctionType();
+ LLFunctionType* funcTy = func->getFunctionType();
if (Logger::enabled())
Logger::cout() << "_aaIn = " << *func << '\n';
@@ -182,7 +182,7 @@ DValue* DtoAAIn(Loc& loc, Type* type, DValue* aa, DValue* key)
LLValue* ret = gIR->CreateCallOrInvoke3(func, aaval, keyti, pkey, "aa.in").getInstruction();
// cast return value
- const LLType* targettype = DtoType(type);
+ LLType* targettype = DtoType(type);
if (ret->getType() != targettype)
ret = DtoBitCast(ret, targettype);
@@ -207,7 +207,7 @@ void DtoAARemove(Loc& loc, DValue* aa, DValue* key)
#else
llvm::Function* func = LLVM_D_GetRuntimeFunction(gIR->module, "_aaDel");
#endif
- const llvm::FunctionType* funcTy = func->getFunctionType();
+ LLFunctionType* funcTy = func->getFunctionType();
if (Logger::enabled())
Logger::cout() << "_aaDel = " << *func << '\n';
@@ -240,7 +240,7 @@ void DtoAARemove(Loc& loc, DValue* aa, DValue* key)
args.push_back(pkey);
// call runtime
- gIR->CreateCallOrInvoke(func, args.begin(), args.end());
+ gIR->CreateCallOrInvoke(func, args);
}
/////////////////////////////////////////////////////////////////////////////////////
@@ -251,7 +251,7 @@ LLValue* DtoAAEquals(Loc& loc, TOK op, DValue* l, DValue* r)
assert(t == r->getType()->toBasetype() && "aa equality is only defined for aas of same type");
#if DMDV2
llvm::Function* func = LLVM_D_GetRuntimeFunction(gIR->module, "_aaEqual");
- const llvm::FunctionType* funcTy = func->getFunctionType();
+ LLFunctionType* funcTy = func->getFunctionType();
LLValue* aaval = DtoBitCast(l->getRVal(), funcTy->getParamType(1));
LLValue* abval = DtoBitCast(r->getRVal(), funcTy->getParamType(2));
@@ -259,7 +259,7 @@ LLValue* DtoAAEquals(Loc& loc, TOK op, DValue* l, DValue* r)
LLValue* res = gIR->CreateCallOrInvoke3(func, aaTypeInfo, aaval, abval, "aaEqRes").getInstruction();
#else
llvm::Function* func = LLVM_D_GetRuntimeFunction(gIR->module, "_aaEq");
- const llvm::FunctionType* funcTy = func->getFunctionType();
+ LLFunctionType* funcTy = func->getFunctionType();
LLValue* aaval = DtoBitCast(l->getRVal(), funcTy->getParamType(0));
LLValue* abval = DtoBitCast(r->getRVal(), funcTy->getParamType(1));
View
8 gen/abi-generic.h
@@ -29,7 +29,7 @@ struct RemoveStructPadding : ABIRewrite {
}
/// return the transformed type for this rewrite
- virtual const LLType* type(Type* dty, const LLType* t) {
+ virtual LLType* type(Type* dty, LLType* t) {
return DtoUnpaddedStructType(dty->toBasetype());
}
};
@@ -47,7 +47,7 @@ struct X87_complex_swap : ABIRewrite
{
return DtoAggrPairSwap(v->getRVal());
}
- const LLType* type(Type*, const LLType* t)
+ LLType* type(Type*, LLType* t)
{
return t;
}
@@ -84,10 +84,10 @@ struct X86_struct_to_register : ABIRewrite
Logger::println("rewriting struct -> int");
assert(dv->isLVal());
LLValue* mem = dv->getLVal();
- const LLType* t = LLIntegerType::get(gIR->context(), dty->size()*8);
+ LLType* t = LLIntegerType::get(gIR->context(), dty->size()*8);
return DtoLoad(DtoBitCast(mem, getPtrToType(t)));
}
- const LLType* type(Type* t, const LLType*)
+ LLType* type(Type* t, LLType*)
{
size_t sz = t->size()*8;
return LLIntegerType::get(gIR->context(), sz);
View
10 gen/abi-x86-64.cpp
@@ -218,7 +218,7 @@ namespace {
// Okay, we may need to transform. Figure out a canonical type:
- std::vector<const LLType*> parts;
+ std::vector<LLType*> parts;
unsigned size = ty->size();
@@ -301,14 +301,14 @@ struct X86_64_C_struct_rewrite : ABIRewrite {
DtoStore(rval, lval);
}
- const LLType* pTy = getPtrToType(DtoType(dty));
+ LLType* pTy = getPtrToType(DtoType(dty));
return DtoLoad(DtoBitCast(lval, pTy), "get-result");
}
// Get struct from ABI-mangled representation, and store in the provided location.
void getL(Type* dty, DValue* v, llvm::Value* lval) {
LLValue* rval = v->getRVal();
- const LLType* pTy = getPtrToType(rval->getType());
+ LLType* pTy = getPtrToType(rval->getType());
DtoStore(rval, DtoBitCast(lval, pTy));
}
@@ -328,12 +328,12 @@ struct X86_64_C_struct_rewrite : ABIRewrite {
LLType* abiTy = getAbiType(dty);
assert(abiTy && "Why are we rewriting a non-rewritten type?");
- const LLType* pTy = getPtrToType(abiTy);
+ LLType* pTy = getPtrToType(abiTy);
return DtoLoad(DtoBitCast(lval, pTy), "put-result");
}
/// should return the transformed type for this rewrite
- const LLType* type(Type* dty, const LLType* t)
+ LLType* type(Type* dty, LLType* t)
{
return getAbiType(dty);
}
View
2  gen/abi.cpp
@@ -76,7 +76,7 @@ struct X86_cfloat_rewrite : ABIRewrite
}
// {float,float} -> i64
- const LLType* type(Type*, const LLType* t)
+ LLType* type(Type*, LLType* t)
{
return LLType::getInt64Ty(gIR->context());
}
View
2  gen/abi.h
@@ -27,7 +27,7 @@ struct ABIRewrite
virtual LLValue* put(Type* dty, DValue* v) = 0;
/// should return the transformed type for this rewrite
- virtual const LLType* type(Type* dty, const LLType* t) = 0;
+ virtual LLType* type(Type* dty, LLType* t) = 0;
};
// interface called by codegen
View
93 gen/arrays.cpp
@@ -25,7 +25,7 @@ static LLValue *DtoSlice(DValue *dval)
LLValue *val = dval->getRVal();
if (dval->getType()->toBasetype()->ty == Tsarray) {
// Convert static array to slice
- const LLStructType *type = DtoArrayType(LLType::getInt8Ty(gIR->context()));
+ LLStructType *type = DtoArrayType(LLType::getInt8Ty(gIR->context()));
LLValue *array = DtoRawAlloca(type, 0, ".array");
DtoStore(DtoArrayLen(dval), DtoGEPi(array, 0, 0, ".len"));
DtoStore(DtoBitCast(val, getVoidPtrType()), DtoGEPi(array, 0, 1, ".ptr"));
@@ -39,7 +39,7 @@ static LLValue *DtoSlice(DValue *dval)
static LLValue *DtoSlicePtr(DValue *dval)
{
Loc loc;
- const LLStructType *type = DtoArrayType(LLType::getInt8Ty(gIR->context()));
+ LLStructType *type = DtoArrayType(LLType::getInt8Ty(gIR->context()));
Type *vt = dval->getType()->toBasetype();
if (vt->ty == Tarray)
return makeLValue(loc, dval);
@@ -55,30 +55,37 @@ static LLValue *DtoSlicePtr(DValue *dval)
//////////////////////////////////////////////////////////////////////////////////////////
-const LLStructType* DtoArrayType(Type* arrayTy)
+LLStructType* DtoArrayType(Type* arrayTy)
{
assert(arrayTy->nextOf());
- const LLType* elemty = DtoType(arrayTy->nextOf());
+ LLType* elemty = DtoType(arrayTy->nextOf());
if (elemty == LLType::getVoidTy(gIR->context()))
elemty = LLType::getInt8Ty(gIR->context());
- return LLStructType::get(gIR->context(), DtoSize_t(), getPtrToType(elemty), NULL);
+
+ llvm::SmallVector<LLType*, 2> elems;
+ elems.push_back(DtoSize_t());
+ elems.push_back(getPtrToType(elemty));
+ return LLStructType::get(gIR->context(), llvm::makeArrayRef(elems));
}
-const LLStructType* DtoArrayType(const LLType* t)
+LLStructType* DtoArrayType(LLType* t)
{
- return LLStructType::get(gIR->context(), DtoSize_t(), getPtrToType(t), NULL);
+ llvm::SmallVector<LLType*, 2> elems;
+ elems.push_back(DtoSize_t());
+ elems.push_back(getPtrToType(t));
+ return LLStructType::get(gIR->context(), llvm::makeArrayRef(elems));
}
//////////////////////////////////////////////////////////////////////////////////////////
-const LLArrayType* DtoStaticArrayType(Type* t)
+LLArrayType* DtoStaticArrayType(Type* t)
{
t = t->toBasetype();
assert(t->ty == Tsarray);
TypeSArray* tsa = (TypeSArray*)t;
Type* tnext = tsa->nextOf();
- const LLType* elemty = DtoType(tnext);
+ LLType* elemty = DtoType(tnext);
if (elemty == LLType::getVoidTy(gIR->context()))
elemty = LLType::getInt8Ty(gIR->context());
@@ -93,7 +100,7 @@ void DtoSetArrayToNull(LLValue* v)
LOG_SCOPE;
assert(isaPointer(v));
- const LLType* t = v->getType()->getContainedType(0);
+ LLType* t = v->getType()->getContainedType(0);
DtoStore(LLConstant::getNullValue(t), v);
}
@@ -118,7 +125,7 @@ void DtoArrayInit(Loc& loc, DValue* array, DValue* value, int op)
if (array->type->ty == Tsarray) {
// Calculate length of the static array
LLValue* rv = array->getRVal();
- const LLArrayType* t = isaArray(rv->getType()->getContainedType(0));
+ LLArrayType* t = isaArray(rv->getType()->getContainedType(0));
uint64_t c = t->getNumElements();
while (t = isaArray(t->getContainedType(0)))
c *= t->getNumElements();
@@ -267,7 +274,7 @@ void DtoArrayInit(Loc& loc, DValue* array, DValue* value, int op)
assert(fn);
if (Logger::enabled())
Logger::cout() << "calling array init function: " << *fn <<'\n';
- LLCallSite call = gIR->CreateCallOrInvoke(fn, args.begin(), args.end());
+ LLCallSite call = gIR->CreateCallOrInvoke(fn, args);
call.setCallingConv(llvm::CallingConv::C);
}
@@ -311,7 +318,7 @@ void DtoArrayAssign(DValue *array, DValue *value, int op)
args.push_back(DtoAggrPaint(DtoSlice(value), fn->getFunctionType()->getParamType(1)));
args.push_back(DtoAggrPaint(DtoSlice(array), fn->getFunctionType()->getParamType(2)));
- LLCallSite call = gIR->CreateCallOrInvoke(fn, args.begin(), args.end(), ".array");
+ LLCallSite call = gIR->CreateCallOrInvoke(fn, args, ".array");
call.setCallingConv(llvm::CallingConv::C);
}
@@ -335,7 +342,7 @@ void DtoArraySetAssign(Loc &loc, DValue *array, DValue *value, int op)
args.push_back(len);
args.push_back(DtoTypeInfoOf(array->type->toBasetype()->nextOf()->toBasetype()));
- LLCallSite call = gIR->CreateCallOrInvoke(fn, args.begin(), args.end(), ".newptr");
+ LLCallSite call = gIR->CreateCallOrInvoke(fn, args, ".newptr");
call.setCallingConv(llvm::CallingConv::C);
}
@@ -382,7 +389,7 @@ LLConstant* DtoConstArrayInitializer(ArrayInitializer* arrinit)
// get elem type
Type* elemty = arrty->nextOf();
- const LLType* llelemty = DtoTypeNotVoid(elemty);
+ LLType* llelemty = DtoTypeNotVoid(elemty);
// true if array elements differ in type, can happen with array of unions
bool mismatch = false;
@@ -444,7 +451,7 @@ LLConstant* DtoConstArrayInitializer(ArrayInitializer* arrinit)
LLConstant* constarr;
if (mismatch)
- constarr = LLConstantStruct::get(gIR->context(), initvals, false); // FIXME should this pack?
+ constarr = LLConstantStruct::getAnon(gIR->context(), initvals); // FIXME should this pack?
else
constarr = LLConstantArray::get(LLArrayType::get(llelemty, arrlen), initvals);
@@ -477,7 +484,7 @@ LLConstant* DtoConstArrayInitializer(ArrayInitializer* arrinit)
static LLValue* get_slice_ptr(DSliceValue* e, LLValue*& sz)
{
assert(e->len != 0);
- const LLType* t = e->ptr->getType()->getContainedType(0);
+ LLType* t = e->ptr->getType()->getContainedType(0);
sz = gIR->ir->CreateMul(DtoConstSize_t(getTypePaddedSize(t)), e->len, "tmp");
return DtoBitCast(e->ptr, getVoidPtrType());
}
@@ -509,7 +516,7 @@ void DtoArrayCopyToSlice(DSliceValue* dst, DValue* src)
LLValue* dstarr = get_slice_ptr(dst,sz1);
LLValue* srcarr = DtoBitCast(DtoArrayPtr(src), getVoidPtrType());
- const LLType* arrayelemty = DtoTypeNotVoid(src->getType()->nextOf()->toBasetype());
+ LLType* arrayelemty = DtoTypeNotVoid(src->getType()->nextOf()->toBasetype());
LLValue* sz2 = gIR->ir->CreateMul(DtoConstSize_t(getTypePaddedSize(arrayelemty)), DtoArrayLen(src), "tmp");
if (global.params.useAssert || global.params.useArrayBounds)
@@ -533,10 +540,14 @@ void DtoStaticArrayCopy(LLValue* dst, LLValue* src)
}
//////////////////////////////////////////////////////////////////////////////////////////
-LLConstant* DtoConstSlice(LLConstant* dim, LLConstant* ptr)
+LLConstant* DtoConstSlice(LLConstant* dim, LLConstant* ptr, Type *type)
{
LLConstant* values[2] = { dim, ptr };
- return LLConstantStruct::get(gIR->context(), values, 2, false);
+ llvm::ArrayRef<LLConstant*> valuesRef = llvm::makeArrayRef(values, 2);
+ LLStructType *lltype = type ?
+ isaStruct(DtoType(type)) :
+ LLConstantStruct::getTypeForElements(gIR->context(), valuesRef);
+ return LLConstantStruct::get(lltype, valuesRef);
}
//////////////////////////////////////////////////////////////////////////////////////////
@@ -567,7 +578,7 @@ static DSliceValue *getSlice(Type *arrayType, LLValue *array)
LLValue* newptr = DtoExtractValue(array, 1, ".ptr");
// cast pointer to wanted type
- const LLType* dstType = DtoType(arrayType)->getContainedType(1);
+ LLType* dstType = DtoType(arrayType)->getContainedType(1);
if (newptr->getType() != dstType)
newptr = DtoBitCast(newptr, dstType, ".gc_mem");
@@ -612,7 +623,7 @@ DSliceValue* DtoNewDynArray(Loc& loc, Type* arrayType, DValue* dim, bool default
LLValue* newptr = gIR->CreateCallOrInvoke2(fn, arrayTypeInfo, arrayLen, ".gc_mem").getInstruction();
// cast to wanted type
- const LLType* dstType = DtoType(arrayType)->getContainedType(1);
+ LLType* dstType = DtoType(arrayType)->getContainedType(1);
if (newptr->getType() != dstType)
newptr = DtoBitCast(newptr, dstType, ".gc_mem");
@@ -658,7 +669,7 @@ DSliceValue* DtoNewMulDimDynArray(Loc& loc, Type* arrayType, DValue** dims, size
args.push_back(dims[i]->getRVal());
// call allocator
- LLValue* newptr = gIR->CreateCallOrInvoke(fn, args.begin(), args.end(), ".gc_mem").getInstruction();
+ LLValue* newptr = gIR->CreateCallOrInvoke(fn, args, ".gc_mem").getInstruction();
if (Logger::enabled())
Logger::cout() << "final ptr = " << *newptr << '\n';
@@ -683,7 +694,7 @@ DSliceValue* DtoNewMulDimDynArray(Loc& loc, Type* arrayType, DValue** dims, size
LLValue* newptr = gIR->CreateCallOrInvoke3(fn, arrayTypeInfo, DtoConstSize_t(ndims), dimsArg, ".gc_mem").getInstruction();
// cast to wanted type
- const LLType* dstType = DtoType(arrayType)->getContainedType(1);
+ LLType* dstType = DtoType(arrayType)->getContainedType(1);
if (newptr->getType() != dstType)
newptr = DtoBitCast(newptr, dstType, ".gc_mem");
@@ -719,7 +730,7 @@ DSliceValue* DtoResizeDynArray(Type* arrayType, DValue* array, LLValue* newdim)
#if DMDV2
args.push_back(DtoBitCast(array->getLVal(), fn->getFunctionType()->getParamType(2)));
- LLValue* newArray = gIR->CreateCallOrInvoke(fn, args.begin(), args.end(), ".gc_mem").getInstruction();
+ LLValue* newArray = gIR->CreateCallOrInvoke(fn, args, ".gc_mem").getInstruction();
return getSlice(arrayType, newArray);
@@ -732,7 +743,7 @@ DSliceValue* DtoResizeDynArray(Type* arrayType, DValue* array, LLValue* 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").getInstruction();
+ LLValue* newptr = gIR->CreateCallOrInvoke(fn, args, ".gc_mem").getInstruction();
if (newptr->getType() != arrPtr->getType())
newptr = DtoBitCast(newptr, arrPtr->getType(), ".gc_mem");
@@ -763,7 +774,7 @@ void DtoCatAssignElement(Loc& loc, Type* arrayType, DValue* array, Expression* e
args.push_back(DtoBitCast(array->getLVal(), fn->getFunctionType()->getParamType(1)));
args.push_back(DtoConstSize_t(1));
- LLValue* appendedArray = gIR->CreateCallOrInvoke(fn, args.begin(), args.end(), ".appendedArray").getInstruction();
+ LLValue* appendedArray = gIR->CreateCallOrInvoke(fn, args, ".appendedArray").getInstruction();
appendedArray = DtoAggrPaint(appendedArray, DtoType(arrayType));
LLValue* val = DtoExtractValue(appendedArray, 1, ".ptr");
@@ -790,7 +801,7 @@ void DtoCatAssignElement(Loc& loc, Type* arrayType, DValue* array, Expression* e
args.push_back(DtoBitCast(array->getLVal(), fn->getFunctionType()->getParamType(1)));
args.push_back(DtoBitCast(valueToAppend, getVoidPtrType()));
- gIR->CreateCallOrInvoke(fn, args.begin(), args.end(), ".appendedArray");
+ gIR->CreateCallOrInvoke(fn, args, ".appendedArray");
}
#endif
@@ -818,7 +829,7 @@ DSliceValue* DtoCatAssignArray(DValue* arr, Expression* exp)
args.push_back(y);
// Call _d_arrayappendT
- LLValue* newArray = gIR->CreateCallOrInvoke(fn, args.begin(), args.end(), ".appendedArray").getInstruction();
+ LLValue* newArray = gIR->CreateCallOrInvoke(fn, args, ".appendedArray").getInstruction();
return getSlice(arrayType, newArray);
}
@@ -905,7 +916,7 @@ DSliceValue* DtoCatArrays(Type* arrayType, Expression* exp1, Expression* exp2)
args.push_back(val);
}
- LLValue *newArray = gIR->CreateCallOrInvoke(fn, args.begin(), args.end(), ".appendedArray").getInstruction();
+ LLValue *newArray = gIR->CreateCallOrInvoke(fn, args, ".appendedArray").getInstruction();
return getSlice(arrayType, newArray);
}
@@ -1036,7 +1047,7 @@ DSliceValue* DtoAppendDChar(DValue* arr, Expression* exp, const char *func)
args.push_back(DtoBitCast(valueToAppend->getRVal(), fn->getFunctionType()->getParamType(1)));
// Call function
- LLValue* newArray = gIR->CreateCallOrInvoke(fn, args.begin(), args.end(), ".appendedArray").getInstruction();
+ LLValue* newArray = gIR->CreateCallOrInvoke(fn, args, ".appendedArray").getInstruction();
return getSlice(arrayType, newArray);
}
@@ -1101,7 +1112,7 @@ static LLValue* DtoArrayEqCmp_impl(Loc& loc, const char* func, DValue* l, DValue
args.push_back(DtoBitCast(tival, fn->getFunctionType()->getParamType(2)));
}
- LLCallSite call = gIR->CreateCallOrInvoke(fn, args.begin(), args.end(), "tmp");
+ LLCallSite call = gIR->CreateCallOrInvoke(fn, args, "tmp");
return call.getInstruction();
}
@@ -1177,7 +1188,7 @@ LLValue* DtoArrayCompare(Loc& loc, TOK op, DValue* l, DValue* r)
}
//////////////////////////////////////////////////////////////////////////////////////////
-LLValue* DtoArrayCastLength(LLValue* len, const LLType* elemty, const LLType* newelemty)
+LLValue* DtoArrayCastLength(LLValue* len, LLType* elemty, LLType* newelemty)
{
Logger::println("DtoArrayCastLength");
LOG_SCOPE;
@@ -1197,7 +1208,7 @@ LLValue* DtoArrayCastLength(LLValue* len, const LLType* elemty, const LLType* ne
args.push_back(LLConstantInt::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").getInstruction();
+ return gIR->CreateCallOrInvoke(fn, args, "tmp").getInstruction();
}
//////////////////////////////////////////////////////////////////////////////////////////
@@ -1283,7 +1294,7 @@ DValue* DtoCastArray(Loc& loc, DValue* u, Type* to)
Logger::println("DtoCastArray");
LOG_SCOPE;
- const LLType* tolltype = DtoType(to);
+ LLType* tolltype = DtoType(to);
Type* totype = to->toBasetype();
Type* fromtype = u->getType()->toBasetype();
@@ -1310,8 +1321,8 @@ DValue* DtoCastArray(Loc& loc, DValue* u, Type* to)
if (Logger::enabled())
Logger::cout() << "to array" << '\n';
- const LLType* ptrty = DtoArrayType(totype)->getContainedType(1);
- const LLType* ety = DtoTypeNotVoid(fromtype->nextOf());
+ LLType* ptrty = DtoArrayType(totype)->getContainedType(1);
+ LLType* ety = DtoTypeNotVoid(fromtype->nextOf());
if (fromtype->ty == Tsarray) {
LLValue* uval = u->getRVal();
@@ -1320,7 +1331,7 @@ DValue* DtoCastArray(Loc& loc, DValue* u, Type* to)
Logger::cout() << "uvalTy = " << *uval->getType() << '\n';
assert(isaPointer(uval->getType()));
- const LLArrayType* arrty = isaArray(uval->getType()->getContainedType(0));
+ LLArrayType* arrty = isaArray(uval->getType()->getContainedType(0));
if(arrty->getNumElements()*fromtype->nextOf()->size() % totype->nextOf()->size() != 0)
{
@@ -1358,7 +1369,7 @@ DValue* DtoCastArray(Loc& loc, DValue* u, Type* to)
assert(isaPointer(uval->getType()));
- /*const LLArrayType* arrty = isaArray(uval->getType()->getContainedType(0));
+ /*LLArrayType* arrty = isaArray(uval->getType()->getContainedType(0));
if(arrty->getNumElements()*fromtype->nextOf()->size() != tosize*totype->nextOf()->size())
{
error(loc, "invalid cast from '%s' to '%s', the sizes are not the same", fromtype->toChars(), totype->toChars());
@@ -1452,7 +1463,7 @@ void DtoArrayBoundsCheck(Loc& loc, DValue* arr, DValue* index, DValue* lowerBoun
#if DMDV2
// module param
LLValue *moduleInfoSymbol = funcmodule->moduleInfoSymbol();
- const LLType *moduleInfoType = DtoType(Module::moduleinfo->type);
+ LLType *moduleInfoType = DtoType(Module::moduleinfo->type);
args.push_back(DtoBitCast(moduleInfoSymbol, getPtrToType(moduleInfoType)));
#else
// file param
@@ -1475,7 +1486,7 @@ void DtoArrayBoundsCheck(Loc& loc, DValue* arr, DValue* index, DValue* lowerBoun
// call
llvm::Function* errorfn = LLVM_D_GetRuntimeFunction(gIR->module, "_d_array_bounds");
- gIR->CreateCallOrInvoke(errorfn, args.begin(), args.end());
+ gIR->CreateCallOrInvoke(errorfn, args);
// the function does not return
gIR->ir->CreateUnreachable();
View
10 gen/arrays.h
@@ -5,12 +5,12 @@ struct ArrayInitializer;
struct DSliceValue;
-const llvm::StructType* DtoArrayType(Type* arrayTy);
-const llvm::StructType* DtoArrayType(const LLType* elemTy);
-const llvm::ArrayType* DtoStaticArrayType(Type* sarrayTy);
+llvm::StructType* DtoArrayType(Type* arrayTy);
+llvm::StructType* DtoArrayType(LLType* elemTy);
+llvm::ArrayType* DtoStaticArrayType(Type* sarrayTy);
LLConstant* DtoConstArrayInitializer(ArrayInitializer* si);
-LLConstant* DtoConstSlice(LLConstant* dim, LLConstant* ptr);
+LLConstant* DtoConstSlice(LLConstant* dim, LLConstant* ptr, Type *type = 0);
void DtoArrayCopySlices(DSliceValue* dst, DSliceValue* src);
void DtoArrayCopyToSlice(DSliceValue* dst, DValue* src);
@@ -45,7 +45,7 @@ LLValue* DtoArrayCompare(Loc& loc, TOK op, DValue* l, DValue* r);
LLValue* DtoDynArrayIs(TOK op, DValue* l, DValue* r);
-LLValue* DtoArrayCastLength(LLValue* len, const LLType* elemty, const LLType* newelemty);
+LLValue* DtoArrayCastLength(LLValue* len, LLType* elemty, LLType* newelemty);
LLValue* DtoArrayLen(DValue* v);
LLValue* DtoArrayPtr(DValue* v);
View
10 gen/asmstmt.cpp
@@ -645,8 +645,8 @@ void AsmBlockStatement::toIR(IRState* p)
// build asm block
std::vector<LLValue*> outargs;
std::vector<LLValue*> inargs;
- std::vector<const LLType*> outtypes;
- std::vector<const LLType*> intypes;
+ std::vector<LLType*> outtypes;
+ std::vector<LLType*> intypes;
std::string out_c;
std::string in_c;
std::string clobbers;
@@ -714,14 +714,14 @@ void AsmBlockStatement::toIR(IRState* p)
Logger::println("constraints = \"%s\"", out_c.c_str());
// build return types
- const LLType* retty;
+ LLType* retty;
if (asmblock->retn)
retty = asmblock->retty;
else
retty = llvm::Type::getVoidTy(gIR->context());
// build argument types
- std::vector<const LLType*> types;
+ std::vector<LLType*> types;
types.insert(types.end(), outtypes.begin(), outtypes.end());
types.insert(types.end(), intypes.begin(), intypes.end());
llvm::FunctionType* fty = llvm::FunctionType::get(retty, types, false);
@@ -746,7 +746,7 @@ void AsmBlockStatement::toIR(IRState* p)
llvm::InlineAsm* ia = llvm::InlineAsm::get(fty, code, out_c, true);
- llvm::CallInst* call = p->ir->CreateCall(ia, args.begin(), args.end(),
+ llvm::CallInst* call = p->ir->CreateCall(ia, args,
retty == LLType::getVoidTy(gIR->context()) ? "" : "asm");
if (Logger::enabled())
View
31 gen/classes.cpp
@@ -230,7 +230,7 @@ void DtoFinalizeClass(LLValue* inst)
LLSmallVector<LLValue*,1> arg;
arg.push_back(DtoBitCast(inst, fn->getFunctionType()->getParamType(0), ".tmp"));
// call
- gIR->CreateCallOrInvoke(fn, arg.begin(), arg.end(), "");
+ gIR->CreateCallOrInvoke(fn, arg, "");
}
//////////////////////////////////////////////////////////////////////////////////////////
@@ -245,7 +245,7 @@ DValue* DtoCastClass(DValue* val, Type* _to)
// class -> pointer
if (to->ty == Tpointer) {
IF_LOG Logger::println("to pointer");
- const LLType* tolltype = DtoType(_to);
+ LLType* tolltype = DtoType(_to);
LLValue* rval = DtoBitCast(val->getRVal(), tolltype);
return new DImValue(_to, rval);
}
@@ -304,7 +304,7 @@ DValue* DtoCastClass(DValue* val, Type* _to)
LLValue* v = val->getRVal();
LLValue* orig = v;
v = DtoGEPi(v, 0, i_index);
- const LLType* ifType = DtoType(_to);
+ LLType* ifType = DtoType(_to);
if (Logger::enabled())
{
Logger::cout() << "V = " << *v << std::endl;
@@ -339,7 +339,7 @@ DValue* DtoCastClass(DValue* val, Type* _to)
// class -> class - static down cast
else if (tc->sym->isBaseOf(fc->sym,NULL)) {
Logger::println("static down cast");
- const LLType* tolltype = DtoType(_to);
+ LLType* tolltype = DtoType(_to);
LLValue* rval = DtoBitCast(val->getRVal(), tolltype);
return new DImValue(_to, rval);
}
@@ -362,7 +362,7 @@ DValue* DtoDynamicCastObject(DValue* val, Type* _to)
ClassDeclaration::classinfo->codegen(Type::sir);
llvm::Function* func = LLVM_D_GetRuntimeFunction(gIR->module, "_d_dynamic_cast");
- const llvm::FunctionType* funcTy = func->getFunctionType();
+ LLFunctionType* funcTy = func->getFunctionType();
std::vector<LLValue*> args;
@@ -398,7 +398,7 @@ DValue* DtoCastInterfaceToObject(DValue* val, Type* to)
// Object _d_toObject(void* p)
llvm::Function* func = LLVM_D_GetRuntimeFunction(gIR->module, "_d_toObject");
- const llvm::FunctionType* funcTy = func->getFunctionType();
+ LLFunctionType* funcTy = func->getFunctionType();
// void* p
LLValue* tmp = val->getRVal();
@@ -427,7 +427,7 @@ DValue* DtoDynamicCastInterface(DValue* val, Type* _to)
ClassDeclaration::classinfo->codegen(Type::sir);
llvm::Function* func = LLVM_D_GetRuntimeFunction(gIR->module, "_d_interface_cast");
- const llvm::FunctionType* funcTy = func->getFunctionType();
+ LLFunctionType* funcTy = func->getFunctionType();
std::vector<LLValue*> args;
@@ -470,7 +470,7 @@ LLValue* DtoIndexClass(LLValue* src, ClassDeclaration* cd, VarDeclaration* vd)
assert(field);
// get the start pointer
- const LLType* st = DtoType(cd->type);
+ LLType* st = DtoType(cd->type);
// cast to the struct type
src = DtoBitCast(src, st);
@@ -575,7 +575,7 @@ static LLConstant* build_offti_entry(ClassDeclaration* cd, VarDeclaration* vd)
return llvm::ConstantStruct::get(inits);
}
-static LLConstant* build_offti_array(ClassDeclaration* cd, const LLType* arrayT)
+static LLConstant* build_offti_array(ClassDeclaration* cd, LLType* arrayT)
{
IrStruct* irstruct = cd->ir.irStruct;
@@ -594,7 +594,7 @@ static LLConstant* build_offti_array(ClassDeclaration* cd, const LLType* arrayT)
return LLConstant::getNullValue( arrayT );
// array type
- const llvm::ArrayType* arrTy = llvm::ArrayType::get(arrayInits[0]->getType(), nvars);
+ LLArrayType* arrTy = llvm::ArrayType::get(arrayInits[0]->getType(), nvars);
LLConstant* arrInit = LLConstantArray::get(arrTy, arrayInits);
// mangle
@@ -701,8 +701,8 @@ LLConstant* DtoDefineClassInfo(ClassDeclaration* cd)
LLConstant* c;
- const LLType* voidPtr = getVoidPtrType();
- const LLType* voidPtrPtr = getPtrToType(voidPtr);
+ LLType* voidPtr = getVoidPtrType();
+ LLType* voidPtrPtr = getPtrToType(voidPtr);
// byte[] init
if (cd->isInterfaceDeclaration())
@@ -711,7 +711,7 @@ LLConstant* DtoDefineClassInfo(ClassDeclaration* cd)
}
else
{
- const LLType* cd_type = stripModifiers(cdty)->irtype->getPA();
+ LLType* cd_type = stripModifiers(cdty)->irtype->getType();
size_t initsz = getTypePaddedSize(cd_type);
b.push_void_array(initsz, ir->getInitSymbol());
}
@@ -807,13 +807,14 @@ LLConstant* DtoDefineClassInfo(ClassDeclaration* cd)
}*/
// build the initializer
- LLConstant* finalinit = b.get_constant();
+ LLType *initType = ir->classInfo->getType()->getContainedType(0);
+ LLConstant* finalinit = b.get_constant(isaStruct(initType));
//Logger::cout() << "built the classinfo initializer:\n" << *finalinit <<'\n';
ir->constClassInfo = finalinit;
// sanity check
- assert(finalinit->getType() == ir->classInfo->getType()->getContainedType(0) &&
+ assert(finalinit->getType() == initType &&
"__ClassZ initializer does not match the ClassInfo type");
// return initializer
View
15 gen/complex.cpp
@@ -12,14 +12,17 @@
//////////////////////////////////////////////////////////////////////////////////////////
-const llvm::StructType* DtoComplexType(Type* type)
+llvm::StructType* DtoComplexType(Type* type)
{
Type* t = type->toBasetype();
- const LLType* base = DtoComplexBaseType(t);
- return llvm::StructType::get(gIR->context(), base, base, NULL);
+ LLType* base = DtoComplexBaseType(t);
+ llvm::SmallVector<LLType*, 2> types;
+ types.push_back(base);
+ types.push_back(base);
+ return llvm::StructType::get(gIR->context(), types);
}
-const LLType* DtoComplexBaseType(Type* t)
+LLType* DtoComplexBaseType(Type* t)
{
TY ty = t->toBasetype()->ty;
if (ty == Tcomplex32) {
@@ -83,7 +86,7 @@ LLValue* DtoImagPart(DValue* val)
DValue* DtoComplex(Loc& loc, Type* to, DValue* val)
{
- const LLType* complexTy = DtoType(to);
+ LLType* complexTy = DtoType(to);
Type* baserety;
Type* baseimty;
@@ -444,7 +447,7 @@ DValue* DtoCastComplex(Loc& loc, DValue* val, Type* _to)
llvm::Value *re, *im;
DtoGetComplexParts(loc, val->getType(), val, re, im);
- const LLType* toty = DtoComplexBaseType(to);
+ LLType* toty = DtoComplexBaseType(to);
if (to->size() < vty->size()) {
re = gIR->ir->CreateFPTrunc(re, toty, "tmp");
View
4 gen/complex.h
@@ -1,8 +1,8 @@
#ifndef LDC_GEN_COMPLEX_H
#define LDC_GEN_COMPLEX_H
-const llvm::StructType* DtoComplexType(Type* t);
-const LLType* DtoComplexBaseType(Type* t);
+llvm::StructType* DtoComplexType(Type* t);
+LLType* DtoComplexBaseType(Type* t);
LLConstant* DtoConstComplex(Type* t, long double re, long double im);
View
2  gen/configfile.cpp
@@ -20,7 +20,7 @@ ConfigFile::ConfigFile()
ConfigFile::~ConfigFile()
{
- delete cfg;
+ // delete cfg;
}
View
40 gen/declarations.cpp
@@ -11,6 +11,7 @@
#include "gen/tollvm.h"
#include "gen/llvmhelpers.h"
#include "gen/logger.h"
+#include "gen/todebug.h"
#include "ir/ir.h"
#include "ir/irvar.h"
@@ -129,14 +130,19 @@ void VarDeclaration::codegen(Ir* p)
bool _isconst = isConst();
#endif
-
Logger::println("Creating global variable");
- const LLType* _type = this->ir.irGlobal->type.get();
- llvm::GlobalValue::LinkageTypes _linkage = DtoLinkage(this);
+ assert(!ir.initialized);
+ ir.initialized = gIR->dmodule;
std::string _name(mangle());
- llvm::GlobalVariable* gvar = new llvm::GlobalVariable(*gIR->module,_type,_isconst,_linkage,NULL,_name,0,isThreadlocal());
+ // build the initializer
+ LLConstant* initVal = DtoConstInitializer(loc, type, init);
+ ir.irGlobal->type = initVal->getType();
+
+ // create the global variable
+ LLGlobalVariable* gvar = new LLGlobalVariable(*gIR->module, initVal->getType(), _isconst,
+ DtoLinkage(this), NULL, _name, 0, isThreadlocal());
this->ir.irGlobal->value = gvar;
// set the alignment
@@ -150,8 +156,30 @@ void VarDeclaration::codegen(Ir* p)
if (nakedUse)
gIR->usedArray.push_back(DtoBitCast(gvar, getVoidPtrType()));
- // initialize
- DtoConstInitGlobal(this);
+ // set the initializer if appropriate
+ assert(!ir.irGlobal->constInit);
+ ir.irGlobal->constInit = initVal;
+
+ // assign the initializer
+ if (!(storage_class & STCextern) && mustDefineSymbol(this))
+ {
+ if (Logger::enabled())
+ {
+ Logger::println("setting initializer");
+ Logger::cout() << "global: " << *gvar << '\n';
+ #if 0
+ Logger::cout() << "init: " << *initVal << '\n';
+ #endif
+ }
+
+ gvar->setInitializer(initVal);
+
+ #ifndef DISABLE_DEBUG_INFO
+ // do debug info
+ if (global.params.symdebug)
+ DtoDwarfGlobalVariable(gvar, this);
+ #endif
+ }
}
}
View
1  gen/dvalue.cpp
@@ -8,6 +8,7 @@
#include "declaration.h"
+
/////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////
View
2  gen/dvalue.h
@@ -9,6 +9,7 @@ handling is necessary, they hold enough information to do-the-right-thing (TM)
#include <cassert>
#include "root.h"
+#include "mem.h"
struct Type;
struct Dsymbol;
@@ -50,7 +51,6 @@ struct DValue : Object
virtual DFieldValue* isField() { return NULL; }
virtual DSliceValue* isSlice() { return NULL; }
virtual DFuncValue* isFunc() { return NULL; }
-
protected:
DValue() {}
DValue(const DValue&) { }
View
28 gen/functions.cpp
@@ -26,7 +26,7 @@
using namespace llvm::Attribute;
-const llvm::FunctionType* DtoFunctionType(Type* type, Type* thistype, Type* nesttype, bool ismain)
+llvm::FunctionType* DtoFunctionType(Type* type, Type* thistype, Type* nesttype, bool ismain)
{
if (Logger::enabled())
Logger::println("DtoFunctionType(%s)", type->toChars());
@@ -187,7 +187,7 @@ const llvm::FunctionType* DtoFunctionType(Type* type, Type* thistype, Type* nest
abi->doneWithFunctionType();
// build the function type
- std::vector<const LLType*> argtypes;
+ std::vector<LLType*> argtypes;
argtypes.reserve(lidx);
if (f->fty.arg_sret) argtypes.push_back(f->fty.arg_sret->ltype);
@@ -209,7 +209,7 @@ const llvm::FunctionType* DtoFunctionType(Type* type, Type* thistype, Type* nest
std::reverse(argtypes.begin() + beg, argtypes.end());
}
- llvm::FunctionType* functype = llvm::FunctionType::get(f->fty.ret->ltype, argtypes, f->fty.c_vararg);
+ LLFunctionType* functype = LLFunctionType::get(f->fty.ret->ltype, argtypes, f->fty.c_vararg);
Logger::cout() << "Final function type: " << *functype << "\n";
@@ -218,10 +218,10 @@ const llvm::FunctionType* DtoFunctionType(Type* type, Type* thistype, Type* nest
//////////////////////////////////////////////////////////////////////////////////////////
-static const llvm::FunctionType* DtoVaFunctionType(FuncDeclaration* fdecl)
+static llvm::FunctionType* DtoVaFunctionType(FuncDeclaration* fdecl)
{
TypeFunction* f = (TypeFunction*)fdecl->type;
- const llvm::FunctionType* fty = 0;
+ LLFunctionType* fty = 0;
// create new ir funcTy
f->fty.reset();
@@ -244,7 +244,7 @@ static const llvm::FunctionType* DtoVaFunctionType(FuncDeclaration* fdecl)
//////////////////////////////////////////////////////////////////////////////////////////
-const llvm::FunctionType* DtoFunctionType(FuncDeclaration* fdecl)
+llvm::FunctionType* DtoFunctionType(FuncDeclaration* fdecl)
{
// handle for C vararg intrinsics
if (fdecl->isVaIntrinsic())
@@ -256,7 +256,7 @@ const llvm::FunctionType* DtoFunctionType(FuncDeclaration* fdecl)
if (AggregateDeclaration* ad = fdecl->isMember2()) {
Logger::println("isMember = this is: %s", ad->type->toChars());
dthis = ad->type;
- const LLType* thisty = DtoType(dthis);
+ LLType* thisty = DtoType(dthis);
//Logger::cout() << "this llvm type: " << *thisty << '\n';
if (ad->isStructDeclaration())
thisty = getPtrToType(thisty);
@@ -270,7 +270,7 @@ const llvm::FunctionType* DtoFunctionType(FuncDeclaration* fdecl)
dnest = Type::tvoid->pointerTo();
}
- const llvm::FunctionType* functype = DtoFunctionType(fdecl->type, dthis, dnest, fdecl->isMain());
+ LLFunctionType* functype = DtoFunctionType(fdecl->type, dthis, dnest, fdecl->isMain());
return functype;
}
@@ -472,15 +472,15 @@ void DtoDeclareFunction(FuncDeclaration* fdecl)
else
mangled_name = fdecl->mangle();
- llvm::Function* vafunc = 0;
+ LLFunction* vafunc = 0;
if (fdecl->isVaIntrinsic())
vafunc = DtoDeclareVaFunction(fdecl);
// construct function
- const llvm::FunctionType* functype = DtoFunctionType(fdecl);
- llvm::Function* func = vafunc ? vafunc : gIR->module->getFunction(mangled_name);
+ LLFunctionType* functype = DtoFunctionType(fdecl);
+ LLFunction* func = vafunc ? vafunc : gIR->module->getFunction(mangled_name);
if (!func) {
- func = llvm::Function::Create(functype, DtoLinkage(fdecl), mangled_name, gIR->module);
+ func = LLFunction::Create(functype, DtoLinkage(fdecl), mangled_name, gIR->module);
} else if (func->getFunctionType() != functype) {
error(fdecl->loc, "Function type does not match previously declared function with the same mangled name: %s", fdecl->mangle());
}
@@ -756,7 +756,7 @@ void DtoDefineFunction(FuncDeclaration* fd)
if (!refout && (!f->fty.args[i]->byref || lazy))
{
// alloca a stack slot for this first class value arg
- const LLType* argt;
+ LLType* argt;
if (lazy)
argt = irloc->value->getType();
else
@@ -877,7 +877,7 @@ void DtoDefineFunction(FuncDeclaration* fd)
//////////////////////////////////////////////////////////////////////////////////////////
-const llvm::FunctionType* DtoBaseFunctionType(FuncDeclaration* fdecl)
+llvm::FunctionType* DtoBaseFunctionType(FuncDeclaration* fdecl)
{
Dsymbol* parent = fdecl->toParent();
ClassDeclaration* cd = parent->isClassDeclaration();
View
6 gen/functions.h
@@ -13,10 +13,10 @@ namespace llvm
class Value;
}
-const llvm::FunctionType* DtoFunctionType(Type* t, Type* thistype, Type* nesttype, bool ismain = false);
-const llvm::FunctionType* DtoFunctionType(FuncDeclaration* fdecl);
+llvm::FunctionType* DtoFunctionType(Type* t, Type* thistype, Type* nesttype, bool ismain = false);
+llvm::FunctionType* DtoFunctionType(FuncDeclaration* fdecl);
-const llvm::FunctionType* DtoBaseFunctionType(FuncDeclaration* fdecl);
+llvm::FunctionType* DtoBaseFunctionType(FuncDeclaration* fdecl);
void DtoResolveFunction(FuncDeclaration* fdecl);
void DtoDeclareFunction(FuncDeclaration* fdecl);
View
10 gen/irstate.cpp
@@ -127,14 +127,14 @@ bool IRState::scopereturned()
LLCallSite IRState::CreateCallOrInvoke(LLValue* Callee, const char* Name)
{
LLSmallVector<LLValue*, 1> args;
- return CreateCallOrInvoke(Callee, args.begin(), args.end(), Name);
+ return CreateCallOrInvoke(Callee, args, 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);
+ return CreateCallOrInvoke(Callee, args, Name);
}
LLCallSite IRState::CreateCallOrInvoke2(LLValue* Callee, LLValue* Arg1, LLValue* Arg2, const char* Name)
@@ -142,7 +142,7 @@ LLCallSite IRState::CreateCallOrInvoke2(LLValue* Callee, LLValue* Arg1, LLValue*
LLSmallVector<LLValue*, 2> args;
args.push_back(Arg1);
args.push_back(Arg2);
- return CreateCallOrInvoke(Callee, args.begin(), args.end(), Name);
+ return CreateCallOrInvoke(Callee, args, Name);
}
LLCallSite IRState::CreateCallOrInvoke3(LLValue* Callee, LLValue* Arg1, LLValue* Arg2, LLValue* Arg3, const char* Name)
@@ -151,7 +151,7 @@ LLCallSite IRState::CreateCallOrInvoke3(LLValue* Callee, LLValue* Arg1, LLValue*
args.push_back(Arg1);
args.push_back(Arg2);
args.push_back(Arg3);
- return CreateCallOrInvoke(Callee, args.begin(), args.end(), Name);
+ return CreateCallOrInvoke(Callee, args, Name);
}
LLCallSite IRState::CreateCallOrInvoke4(LLValue* Callee, LLValue* Arg1, LLValue* Arg2, LLValue* Arg3, LLValue* Arg4, const char* Name)
@@ -161,7 +161,7 @@ LLCallSite IRState::CreateCallOrInvoke4(LLValue* Callee, LLValue* Arg1, LLValue*
args.push_back(Arg2);
args.push_back(Arg3);
args.push_back(Arg4);
- return CreateCallOrInvoke(Callee, args.begin(), args.end(), Name);
+ return CreateCallOrInvoke(Callee, args, Name);
}
View
22 gen/irstate.h
@@ -90,7 +90,7 @@ struct IRAsmBlock
std::vector<Identifier*> internalLabels;
AsmBlockStatement* asmBlock;
- const LLType* retty;
+ LLType* retty;
unsigned retn;
bool retemu; // emulate abi ret with a temporary
LLValue* (*retfixup)(IRBuilderHelper b, LLValue* orig); // Modifies retval
@@ -111,9 +111,9 @@ struct IRState
llvm::Module* module;
// interface info type, used in DtoInterfaceInfoType
- const LLStructType* interfaceInfoType;
- const LLStructType* mutexType;
- const LLStructType* moduleRefType;
+ LLStructType* interfaceInfoType;
+ LLStructType* mutexType;
+ LLStructType* moduleRefType;
// helper to get the LLVMContext of the module
llvm::LLVMContext& context() const { return module->getContext(); }
@@ -148,8 +148,8 @@ 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>
- llvm::CallSite CreateCallOrInvoke(LLValue* Callee, InputIterator ArgBegin, InputIterator ArgEnd, const char* Name="");
+ template <typename T>
+ llvm::CallSite CreateCallOrInvoke(LLValue* Callee, const T& args, 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="");
@@ -196,8 +196,8 @@ struct IRState
std::vector<LLConstant*> usedArray;
};
-template <typename InputIterator>
-llvm::CallSite IRState::CreateCallOrInvoke(LLValue* Callee, InputIterator ArgBegin, InputIterator ArgEnd, const char* Name)
+template <typename T>
+llvm::CallSite IRState::CreateCallOrInvoke(LLValue* Callee, const T &args, const char* Name)
{
llvm::BasicBlock* pad = func()->gen->landingPad;
if(pad)
@@ -206,13 +206,13 @@ llvm::CallSite IRState::CreateCallOrInvoke(LLValue* Callee, InputIterator ArgBeg
LLFunction* funcval = llvm::dyn_cast<LLFunction>(Callee);
if (funcval && (funcval->isIntrinsic() || funcval->doesNotThrow()))
{
- llvm::CallInst* call = ir->CreateCall(Callee, ArgBegin, ArgEnd, Name);
+ llvm::CallInst* call = ir->CreateCall(Callee, args, Name);
call->setAttributes(funcval->getAttributes());
return call;
}
llvm::BasicBlock* postinvoke = llvm::BasicBlock::Create(gIR->context(), "postinvoke", topfunc(), scopeend());
- llvm::InvokeInst* invoke = ir->CreateInvoke(Callee, postinvoke, pad, ArgBegin, ArgEnd, Name);
+ llvm::InvokeInst* invoke = ir->CreateInvoke(Callee, postinvoke, pad, args, Name);
if (LLFunction* fn = llvm::dyn_cast<LLFunction>(Callee))
invoke->setAttributes(fn->getAttributes());
scope() = IRScope(postinvoke, scopeend());
@@ -220,7 +220,7 @@ llvm::CallSite IRState::CreateCallOrInvoke(LLValue* Callee, InputIterator ArgBeg
}
else
{
- llvm::CallInst* call = ir->CreateCall(Callee, ArgBegin, ArgEnd, Name);
+ llvm::CallInst* call = ir->CreateCall(Callee, args, Name);
if (LLFunction* fn = llvm::dyn_cast<LLFunction>(Callee))
call->setAttributes(fn->getAttributes());
return call;
View
2  gen/llvm.h
@@ -47,8 +47,6 @@ using llvm::IRBuilder;
#define LLConstantInt llvm::ConstantInt
#define LLConstantFP llvm::ConstantFP
-#define LLPATypeHolder llvm::PATypeHolder
-
#define LLCallSite llvm::CallSite
#define LLSmallVector llvm::SmallVector
View
227 gen/llvmhelpers.cpp
@@ -51,7 +51,7 @@ void DtoDeleteMemory(LLValue* ptr)
LLSmallVector<LLValue*,1> arg;
arg.push_back(DtoBitCast(ptr, getVoidPtrType(), ".tmp"));
// call
- gIR->CreateCallOrInvoke(fn, arg.begin(), arg.end());
+ gIR->CreateCallOrInvoke(fn, arg);
}
void DtoDeleteClass(LLValue* inst)
@@ -68,7 +68,7 @@ void DtoDeleteClass(LLValue* inst)
#endif
arg.push_back(DtoBitCast(inst, fn->getFunctionType()->getParamType(0), ".tmp"));
// call
- gIR->CreateCallOrInvoke(fn, arg.begin(), arg.end());
+ gIR->CreateCallOrInvoke(fn, arg);
}
void DtoDeleteInterface(LLValue* inst)
@@ -79,7 +79,7 @@ void DtoDeleteInterface(LLValue* inst)
LLSmallVector<LLValue*,1> arg;
arg.push_back(DtoBitCast(inst, fn->getFunctionType()->getParamType(0), ".tmp"));
// call
- gIR->CreateCallOrInvoke(fn, arg.begin(), arg.end());
+ gIR->CreateCallOrInvoke(fn, arg);
}
#if DMDV2
@@ -95,7 +95,7 @@ void DtoDeleteArray(DValue* arr)
arg.push_back(DtoBitCast(DtoTypeInfoOf(arr->type->nextOf()), fn->getFunctionType()->getParamType(1)));
// call
- gIR->CreateCallOrInvoke(fn, arg.begin(), arg.end());
+ gIR->CreateCallOrInvoke(fn, arg);
}
#else
@@ -111,7 +111,7 @@ void DtoDeleteArray(DValue* arr)
arg.push_back(DtoBitCast(DtoArrayPtr(arr), getVoidPtrType(), ".tmp"));
// call
- gIR->CreateCallOrInvoke(fn, arg.begin(), arg.end());
+ gIR->CreateCallOrInvoke(fn, arg);
}
#endif
@@ -124,7 +124,7 @@ void DtoDeleteArray(DValue* arr)
llvm::AllocaInst* DtoAlloca(Type* type, const char* name)
{
- const llvm::Type* lltype = DtoType(type);
+ LLType* lltype = DtoType(type);
llvm::AllocaInst* ai = new llvm::AllocaInst(lltype, name, gIR->topallocapoint());
ai->setAlignment(type->alignsize());
return ai;
@@ -132,14 +132,14 @@ llvm::AllocaInst* DtoAlloca(Type* type, const char* name)
llvm::AllocaInst* DtoArrayAlloca(Type* type, unsigned arraysize, const char* name)
{
- const llvm::Type* lltype = DtoType(type);
+ LLType* lltype = DtoType(type);
llvm::AllocaInst* ai = new llvm::AllocaInst(
lltype, DtoConstUint(arraysize), name, gIR->topallocapoint());
ai->setAlignment(type->alignsize());
return ai;
}
-llvm::AllocaInst* DtoRawAlloca(const llvm::Type* lltype, size_t alignment, const char* name)
+llvm::AllocaInst* DtoRawAlloca(LLType* lltype, size_t alignment, const char* name)
{
llvm::AllocaInst* ai = new llvm::AllocaInst(lltype, name, gIR->topallocapoint());
if (alignment)
@@ -147,16 +147,16 @@ llvm::AllocaInst* DtoRawAlloca(const llvm::Type* lltype, size_t alignment, const
return ai;
}
-LLValue* DtoGcMalloc(const llvm::Type* lltype, const char* name)
+LLValue* DtoGcMalloc(LLType* lltype, const char* name)
{
- // get runtime function
- llvm::Function* fn = LLVM_D_GetRuntimeFunction(gIR->module, "_d_allocmemory");
- // parameters
- LLValue *size = DtoConstSize_t(getTypeAllocSize(lltype));
- // call runtime allocator
- LLValue* mem = gIR->CreateCallOrInvoke(fn, size, name).getInstruction();
- // cast
- return DtoBitCast(mem, getPtrToType(lltype), name);
+ // get runtime function
+ llvm::Function* fn = LLVM_D_GetRuntimeFunction(gIR->module, "_d_allocmemory");
+ // parameters
+ LLValue *size = DtoConstSize_t(getTypeAllocSize(lltype));
+ // call runtime allocator
+ LLValue* mem = gIR->CreateCallOrInvoke(fn, size, name).getInstruction();
+ // cast
+ return DtoBitCast(mem, getPtrToType(lltype), name);
}
/****************************************************************************************/
@@ -197,7 +197,7 @@ void DtoAssert(Module* M, Loc loc, DValue* msg)
args.push_back(c);
// call
- gIR->CreateCallOrInvoke(fn, args.begin(), args.end());
+ gIR->CreateCallOrInvoke(fn, args);
#ifndef DISABLE_DEBUG_INFO
// end debug info
@@ -500,7 +500,7 @@ void DtoAssign(Loc& loc, DValue* lhs, DValue* rhs, int op)
LLValue* r = rhs->getRVal();
if (Logger::enabled())
Logger::cout() << "assign\nlhs: " << *l << "rhs: " << *r << '\n';
- const LLType* lit = l->getType()->getContainedType(0);
+ LLType* lit = l->getType()->getContainedType(0);
if (r->getType() != lit) {
r = DtoCast(loc, rhs, lhs->getType())->getRVal();
if (Logger::enabled())
@@ -532,12 +532,12 @@ DValue* DtoNullValue(Type* type)
{
Type* basetype = type->toBasetype();
TY basety = basetype->ty;
- const LLType* lltype = DtoType(basetype);
+ LLType* lltype = DtoType(basetype);
// complex, needs to be first since complex are also floating
if (basetype->iscomplex())
{
- const LLType* basefp = DtoComplexBaseType(basetype);
+ LLType* basefp = DtoComplexBaseType(basetype);
LLValue* res = DtoAggrPair(DtoType(type), LLConstant::getNullValue(basefp), LLConstant::getNullValue(basefp));
return new DImValue(type, res);
}
@@ -574,7 +574,7 @@ DValue* DtoNullValue(Type* type)
DValue* DtoCastInt(Loc& loc, DValue* val, Type* _to)
{
- const LLType* tolltype = DtoType(_to);
+ LLType* tolltype = DtoType(_to);
Type* to = _to->toBasetype();
Type* from = val->getType()->toBasetype();
@@ -635,7 +635,7 @@ DValue* DtoCastInt(Loc& loc, DValue* val, Type* _to)
DValue* DtoCastPtr(Loc& loc, DValue* val, Type* to)
{
- const LLType* tolltype = DtoType(to);
+ LLType* tolltype = DtoType(to);
Type* totype = to->toBasetype();
Type* fromtype = val->getType()->toBasetype();
@@ -670,7 +670,7 @@ DValue* DtoCastFloat(Loc& loc, DValue* val, Type* to)
if (val->getType() == to)
return val;
- const LLType* tolltype = DtoType(to);
+ LLType* tolltype = DtoType(to);
Type* totype = to->toBasetype();
Type* fromtype = val->getType()->toBasetype();
@@ -913,8 +913,9 @@ void DtoConstInitGlobal(VarDeclaration* vd)
IrGlobal* glob = vd->ir.irGlobal;
llvm::GlobalVariable* gvar = llvm::cast<llvm::GlobalVariable>(glob->value);
- // refine the global's opaque type to the type of the initializer
- llvm::cast<LLOpaqueType>(glob->type.get())->refineAbstractTypeTo(initVal->getType());
+ //if (LLStructType *st = isaStruct(glob->type)) {
+ // st->setBody(initVal);
+ //}
assert(!glob->constInit);
glob->constInit = initVal;
@@ -1050,7 +1051,7 @@ DValue* DtoDeclarationExp(Dsymbol* declaration)
}
#endif
- const LLType* lltype = DtoType(vd->type);
+ LLType* lltype = DtoType(vd->type);
llvm::Value* allocainst;
if(gTargetData->getTypeSizeInBits(lltype) == 0)
@@ -1281,7 +1282,7 @@ LLConstant* DtoConstInitializer(Loc loc, Type* type, Initializer* init)
else if (init->isVoidInitializer())
{
Logger::println("const void initializer");
- const LLType* ty = DtoType(type);
+ LLType* ty = DtoType(type);
_init = LLConstant::getNullValue(ty);
}
else {
@@ -1325,7 +1326,7 @@ DValue* DtoInitializer(LLValue* target, Initializer* init)
static LLConstant* expand_to_sarray(Type *base, Expression* exp)
{
Logger::println("building type %s from expression (%s) of type %s", base->toChars(), exp->toChars(), exp->type->toChars());
- const LLType* dstTy = DtoType(base);
+ LLType* dstTy = DtoType(base);
if (Logger::enabled())
Logger::cout() << "final llvm type requested: " << *dstTy << '\n';
@@ -1355,7 +1356,7 @@ static LLConstant* expand_to_sarray(Type *base, Expression* exp)
std::vector<LLConstant*> inits;
while (i--)
{
- const LLArrayType* arrty = LLArrayType::get(val->getType(), dims[i]);
+ LLArrayType* arrty = LLArrayType::get(val->getType(), dims[i]);
inits.clear();
inits.insert(inits.end(), dims[i], val);
val = LLConstantArray::get(arrty, inits);
@@ -1623,7 +1624,7 @@ size_t realignOffset(size_t offset, Type* type)
// we cannot get the llvm alignment if the type is still opaque, this can happen in some
// forward reference situations, so when this happens we fall back to manual padding.
// also handle arbitrary "by-value" opaques nested inside aggregates.
- const llvm::Type* T = DtoType(type);
+ LLType* T = DtoType(type);
if (!T->isSized())
{
return offset;
@@ -1652,89 +1653,89 @@ size_t realignOffset(size_t offset, Type* type)
Type * stripModifiers( Type * type )
{
#if DMDV2
- if (type->ty == Tfunction)
- return type;
- Type *t = type;
- while (t->mod)
- {
- switch (t->mod)
- {
- case MODconst:
- t = type->cto;
- break;
- case MODshared:
- t = type->sto;
- break;
- case MODimmutable:
- t = type->ito;
- break;
- case MODshared | MODconst:
- t = type->scto;
- break;
- case MODwild:
- t = type->wto;
- break;
- case MODshared | MODwild:
- t = type->swto;
- break;
- default:
- assert(0 && "Unhandled type modifier");
- }
-
- if (!t)
- {
- unsigned sz = type->sizeTy[type->ty];
- t = (Type *)malloc(sz);
- memcpy(t, type, sz);
- t->mod = 0;
- t->deco = NULL;
- t->arrayof = NULL;
- t->pto = NULL;
- t->rto = NULL;
- t->cto = NULL;
- t->ito = NULL;
- t->sto = NULL;
- t->scto = NULL;
- t->wto = NULL;
- t->swto = NULL;
- t->vtinfo = NULL;
- t = t->merge();
-
- t->fixTo(type);
- switch (type->mod)
- {
- case MODconst:
- t->cto = type;
- break;
-
- case MODimmutable:
- t->ito = type;
- break;
-
- case MODshared:
- t->sto = type;
- break;
-
- case MODshared | MODconst:
- t->scto = type;
- break;
-
- case MODwild:
- t->wto = type;
- break;
-
- case MODshared | MODwild:
- t->swto = type;
- break;
-
- default:
- assert(0);
- }
- }
- }
- return t;
+ if (type->ty == Tfunction)
+ return type;
+ Type *t = type;
+ while (t->mod)
+ {
+ switch (t->mod)
+ {
+ case MODconst:
+ t = type->cto;
+ break;
+ case MODshared:
+ t = type->sto;
+ break;
+ case MODimmutable:
+ t = type->ito;
+ break;
+ case MODshared | MODconst:
+ t = type->scto;
+ break;
+ case MODwild:
+ t = type->wto;
+ break;
+ case MODshared | MODwild:
+ t = type->swto;
+ break;
+ default:
+ assert(0 && "Unhandled type modifier");
+ }
+
+ if (!t)
+ {
+ unsigned sz = type->sizeTy[type->ty];
+ t = (Type *)malloc(sz);
+ memcpy(t, type, sz);
+ t->mod = 0;
+ t->deco = NULL;
+ t->arrayof = NULL;
+ t->pto = NULL;
+ t->rto = NULL;
+ t->cto = NULL;
+ t->ito = NULL;
+ t->sto = NULL;
+ t->scto = NULL;
+ t->wto = NULL;
+ t->swto = NULL;
+ t->vtinfo = NULL;
+ t = t->merge();
+
+ t->fixTo(type);
+ switch (type->mod)
+ {
+ case MODconst:
+ t->cto = type;
+ break;
+
+ case MODimmutable:
+ t->ito = type;
+ break;
+
+ case MODshared:
+ t->sto = type;
+ break;
+
+ case MODshared | MODconst:
+ t->scto = type;
+ break;
+
+ case MODwild:
+ t->wto = type;
+ break;
+
+ case MODshared | MODwild:
+ t->swto = type;
+ break;
+
+ default:
+ assert(0);
+ }
+ }
+ }
+ return t;
#else
- return type;
+ return type;
#endif
}
View
6 gen/llvmhelpers.h
@@ -44,8 +44,8 @@ void DtoDeleteArray(DValue* arr);
// emit an alloca
llvm::AllocaInst* DtoAlloca(Type* type, const char* name = "");
llvm::AllocaInst* DtoArrayAlloca(Type* type, unsigned arraysize, const char* name = "");
-llvm::AllocaInst* DtoRawAlloca(const llvm::Type* lltype, size_t alignment, const char* name = "");
-LLValue* DtoGcMalloc(const llvm::Type* lltype, const char* name = "");
+llvm::AllocaInst* DtoRawAlloca(LLType* lltype, size_t alignment, const char* name = "");
+LLValue* DtoGcMalloc(LLType* lltype, const char* name = "");
// assertion generator
void DtoAssert(Module* M, Loc loc, DValue* msg);
@@ -174,7 +174,7 @@ DValue* DtoVaArg(Loc& loc, Type* type, Expression* valistArg);
LLValue* DtoCallableValue(DValue* fn);
///
-const LLFunctionType* DtoExtractFunctionType(const LLType* type);
+LLFunctionType* DtoExtractFunctionType(LLType* type);
///
void DtoBuildDVarArgList(std::vector<LLValue*>& args, llvm::AttrListPtr& palist, TypeFunction* tf, Expressions* arguments, size_t argidx);
View
2  gen/logger.cpp
@@ -20,7 +20,7 @@
void Stream::writeType(std::ostream& OS, const llvm::Type& Ty) {
llvm::raw_os_ostream raw(OS);
- llvm::WriteTypeSymbolic(raw, &Ty, gIR->module);
+ Ty.print(raw);
}
void Stream::writeValue(std::ostream& OS, const llvm::Value& V) {
View
20 gen/main.cpp
@@ -7,11 +7,11 @@
#include "llvm/LinkAllVMCore.h"
#include "llvm/Linker.h"
#include "llvm/LLVMContext.h"
-#include "llvm/Target/SubtargetFeature.h"
#include "llvm/Target/TargetMachine.h"
#include "llvm/Target/TargetOptions.h"
-#include "llvm/Target/TargetRegistry.h"
-#include "llvm/Target/TargetSelect.h"
+#include "llvm/Support/TargetSelect.h"
+#include "llvm/Support/TargetRegistry.h"
+#include "llvm/MC/SubtargetFeature.h"
#include <stdio.h>
#include <stdlib.h>
@@ -435,10 +435,11 @@ int main(int argc, char** argv)
// Allocate target machine.
// first initialize llvm
-#define LLVM_TARGET(A) LLVMInitialize##A##TargetInfo(); LLVMInitialize##A##Target(); LLVMInitialize##A##AsmPrinter();
-// this is defined to be LLVM_TARGET(target name 1) LLVM_TARGET(target name 2) ...
-LDC_TARGETS
-#undef LLVM_TARGET
+ llvm::InitializeAllTargetInfos();
+ llvm::InitializeAllTargets();
+ llvm::InitializeAllAsmPrinters();
+ llvm::InitializeAllTargetMCs();
+
const llvm::Target *theTarget = NULL;
// Check whether the user has explicitly specified an architecture to compile for.
@@ -476,9 +477,8 @@ LDC_TARGETS
if (mCPU.size() || mAttrs.size())
{
llvm::SubtargetFeatures Features;
- Features.setCPU(mCPU);
for (unsigned i = 0; i != mAttrs.size(); ++i)
- Features.AddFeature(mAttrs[i]);
+ Features.AddFeature(mAttrs[i]);
FeaturesStr = Features.getString();
}
@@ -487,7 +487,7 @@ LDC_TARGETS
//assert(target.get() && "Could not allocate target machine!");
//gTargetMachine = target.get();
- llvm::TargetMachine* target = theTarget->createTargetMachine(triple, FeaturesStr);
+ llvm::TargetMachine* target = theTarget->createTargetMachine(triple, mCPU, FeaturesStr);
gTargetMachine = target;
gTargetData = target->getTargetData();
View
8 gen/naked.cpp
@@ -201,7 +201,7 @@ void emitABIReturnAsmStmt(IRAsmBlock* asmblock, Loc loc, FuncDeclaration* fdecl)
IRAsmStmt* as = new IRAsmStmt;
- const LLType* llretTy = DtoType(fdecl->type->nextOf());
+ LLType* llretTy = DtoType(fdecl->type->nextOf());
asmblock->retty = llretTy;
asmblock->retn = 1;
@@ -388,7 +388,7 @@ DValue * DtoInlineAsmExpr(Loc loc, FuncDeclaration * fd, Expressions * arguments
LLSmallVector<llvm::Value*, 8> args;
args.reserve(n-2);
- std::vector<const llvm::Type*> argtypes;
+ std::vector<LLType*> argtypes;
argtypes.reserve(n-2);
for (size_t i = 2; i < n; i++)
@@ -400,14 +400,14 @@ DValue * DtoInlineAsmExpr(Loc loc, FuncDeclaration * fd, Expressions * arguments
// build asm function type
Type* type = fd->type->nextOf()->toBasetype();
- const llvm::Type* ret_type = DtoType(type);
+ LLType* ret_type = DtoType(type);
llvm::FunctionType* FT = llvm::FunctionType::get(ret_type, argtypes, false);
// build asm call
bool sideeffect = true;
llvm::InlineAsm* ia = llvm::InlineAsm::get(FT, code, constraints, sideeffect);
- llvm::Value* rv = gIR->ir->CreateCall(ia, args.begin(), args.end(), "");
+ llvm::Value* rv = gIR->ir->CreateCall(ia, args, "");
// work around missing tuple support for users of the return value
if (type->ty == Tstruct)
View
14 gen/nested.cpp
@@ -392,7 +392,7 @@ static void DtoCreateNestedContextType(FuncDeclaration* fd) {
Logger::println("has nested frame");
// start with adding all enclosing parent frames until a static parent is reached
- const LLStructType* innerFrameType = NULL;
+ LLStructType* innerFrameType = NULL;
unsigned depth = -1;
if (!fd->isStatic()) {
if (FuncDeclaration* parfd = getParentFunc(fd, true)) {
@@ -408,7 +408,7 @@ static void DtoCreateNestedContextType(FuncDeclaration* fd) {
Logger::cout() << "Function " << fd->toChars() << " has depth " << depth << '\n';
- typedef std::vector<const LLType*> TypeVec;
+ typedef std::vector<LLType*> TypeVec;
TypeVec types;
if (depth != 0) {
assert(innerFrameType);
@@ -444,7 +444,7 @@ static void DtoCreateNestedContextType(FuncDeclaration* fd) {
// so handle those cases specially by storing a pointer instead of a value.
assert(vd->ir.irLocal->value);
LLValue* value = vd->ir.irLocal->value;
- const LLType* type = value->getType();
+ LLType* type = value->getType();
if (llvm::isa<llvm::AllocaInst>(llvm::GetUnderlyingObject(value)))
// This will be copied to the nesting frame.
type = type->getContainedType(0);
@@ -461,8 +461,8 @@ static void DtoCreateNestedContextType(FuncDeclaration* fd) {
}
}
- const LLStructType* frameType = LLStructType::get(gIR->context(), types);
- gIR->module->addTypeName(std::string("nest.") + fd->toChars(), frameType);
+ LLStructType* frameType = LLStructType::create(gIR->context(), types,
+ std::string("nest.") + fd->toChars());
Logger::cout() << "frameType = " << *frameType << '\n';
@@ -521,7 +521,7 @@ void DtoCreateNestedContext(FuncDeclaration* fd) {
int nelems = fd->nestedVars.size() + nparelems;
// make array type for nested vars
- const LLType* nestedVarsTy = LLArrayType::get(getVoidPtrType(), nelems);
+ LLType* nestedVarsTy = LLArrayType::get(getVoidPtrType(), nelems);
// alloca it
// FIXME align ?
@@ -580,7 +580,7 @@ void DtoCreateNestedContext(FuncDeclaration* fd) {
{
IrFunction* irfunction = fd->ir.irFunc;
unsigned depth = irfunction->depth;
- const llvm::StructType *frameType = irfunction->frameType;
+ LLStructType *frameType = irfunction->frameType;
// Create frame for current function and append to frames list
// FIXME: alignment ?
LLValue* frame = 0;
View
3  gen/optimizer.cpp
@@ -10,6 +10,7 @@
#include "llvm/Target/TargetData.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/PassNameParser.h"
+#include "llvm/Transforms/IPO.h"
#include "root.h" // error()
#include <cstring> // strcmp();
@@ -174,7 +175,6 @@ static void addPassesForOptLevel(PassManager& pm) {
if (optimizeLevel >= 3)
{
addPass(pm, createArgumentPromotionPass());
- addPass(pm, createTailDuplicationPass());
addPass(pm, createSimplifyLibCallsPass());
addPass(pm, createInstructionCombiningPass());
addPass(pm, createJumpThreadingPass());
@@ -202,7 +202,6 @@ static void addPassesForOptLevel(PassManager& pm) {
addPass(pm, createDeadStoreEliminationPass());
addPass(pm, createAggressiveDCEPass());
addPass(pm, createCFGSimplificationPass());
- addPass(pm, createDeadTypeEliminationPass());
addPass(pm, createConstantMergePass());
}
View
8 gen/passes/SimplifyDRuntimeCalls.cpp
@@ -93,10 +93,10 @@ Value *LibCallOptimization::CastToCStr(Value *V, IRBuilder<> &B) {
Value *LibCallOptimization::EmitMemCpy(Value *Dst, Value *Src, Value *Len,
unsigned Align, IRBuilder<> &B) {
Module *M = Caller->getParent();
- const Type* intTy = Len->getType();
- const Type *VoidPtrTy = PointerType::getUnqual(B.getInt8Ty());
- const Type *Tys[3] ={VoidPtrTy, VoidPtrTy, intTy};
- Value *MemCpy = Intrinsic::getDeclaration(M, Intrinsic::memcpy, Tys, 3);
+ Type* intTy = Len->getType();
+ Type *VoidPtrTy = PointerType::getUnqual(B.getInt8Ty());
+ Type *Tys[3] ={VoidPtrTy, VoidPtrTy, intTy};
+ Value *MemCpy = Intrinsic::getDeclaration(M, Intrinsic::memcpy, llvm::makeArrayRef(Tys, 3));
return B.CreateCall5(MemCpy, CastToCStr(Dst, B), CastToCStr(Src, B), Len,
ConstantInt::get(B.getInt32Ty(), Align), B.getFalse());
View
28 gen/rttibuilder.cpp
@@ -63,7 +63,7 @@ void RTTIBuilder::push_string(const char* str)
void RTTIBuilder::push_null_void_array()
{
- const llvm::Type* T = DtoType(Type::tvoid->arrayOf());
+ LLType* T = DtoType(Type::tvoid->arrayOf());
inits.push_back(getNullValue(T));
}
@@ -143,18 +143,30 @@ void RTTIBuilder::push_funcptr(FuncDeclaration* fd, Type* castto)