# HG changeset patch # User lindquist # Date 1212168724 -7200 # Node ID 7816aafeea3c84cdc7e3dbd0d740674d71b10f53 # Parent 4c2689d57ba4854e9b6c5bc483bf0eac8b28666c [svn r229] Updated the object.d implementation to the latest Tango. Fixed a bunch of the built-in typeinfos for arrays, they did not inherit TypeInfo_Array. Applied patch to tango/text/convert/Layout.d by fvbommel, closes #47 . Cleaned up some type code. Replaced uses of llvm::Type with LLType (a typedef), same for Value and Constant. Fixed a few cases where typeinfo for user structs could be emitted multiple times, seems to still be some cases of this :/ diff -r 4c2689d57ba4 -r 7816aafeea3c gen/aa.cpp --- a/gen/aa.cpp Tue May 27 22:14:24 2008 +0200 +++ b/gen/aa.cpp Fri May 30 19:32:04 2008 +0200 @@ -13,11 +13,11 @@ // makes sure the key value lives in memory so it can be passed to the runtime functions without problems // returns the pointer -static llvm::Value* to_pkey(DValue* key) +static LLValue* to_pkey(DValue* key) { Type* keytype = key->getType(); bool needmem = !DtoIsPassedByRef(keytype); - llvm::Value* pkey; + LLValue* pkey; if (key->isIm()) { pkey = key->getRVal(); } @@ -35,7 +35,7 @@ pkey = key->getRVal(); } else { - llvm::Value* tmp = new llvm::AllocaInst(DtoType(keytype), "aatmpkeystorage", gIR->topallocapoint()); + LLValue* tmp = new llvm::AllocaInst(DtoType(keytype), "aatmpkeystorage", gIR->topallocapoint()); DVarValue* var = new DVarValue(keytype, tmp, true); DtoAssign(var, key); return tmp; @@ -43,7 +43,7 @@ // give memory if (needmem) { - llvm::Value* tmp = new llvm::AllocaInst(DtoType(keytype), "aatmpkeystorage", gIR->topallocapoint()); + LLValue* tmp = new llvm::AllocaInst(DtoType(keytype), "aatmpkeystorage", gIR->topallocapoint()); DtoStore(pkey, tmp); pkey = tmp; } @@ -52,17 +52,12 @@ } // returns the keytype typeinfo -static llvm::Value* to_keyti(DValue* key) +static LLValue* to_keyti(DValue* key) { // keyti param Type* keytype = key->getType(); keytype->getTypeInfo(NULL); - TypeInfoDeclaration* tid = keytype->getTypeInfoDeclaration(); - assert(tid); - DtoResolveDsymbol(Type::typeinfo); - DtoForceDeclareDsymbol(tid); - assert(tid->ir.irGlobal->value); - return tid->ir.irGlobal->value; + return DtoTypeInfoOf(keytype, false); } ///////////////////////////////////////////////////////////////////////////////////// @@ -77,32 +72,32 @@ const llvm::FunctionType* funcTy = func->getFunctionType(); // aa param - llvm::Value* aaval = aa->getLVal(); + LLValue* aaval = aa->getLVal(); aaval = DtoBitCast(aaval, funcTy->getParamType(0)); // keyti param - llvm::Value* keyti = to_keyti(key); + LLValue* keyti = to_keyti(key); keyti = DtoBitCast(keyti, funcTy->getParamType(1)); // valuesize param - llvm::Value* valsize = DtoConstSize_t(getABITypeSize(DtoType(type))); + LLValue* valsize = DtoConstSize_t(getABITypeSize(DtoType(type))); // pkey param - llvm::Value* pkey = to_pkey(key); + LLValue* pkey = to_pkey(key); pkey = DtoBitCast(pkey, funcTy->getParamType(3)); // build arg vector - std::vector args; + LLSmallVector args; args.push_back(aaval); args.push_back(keyti); args.push_back(valsize); args.push_back(pkey); // call runtime - llvm::Value* ret = gIR->ir->CreateCall(func, args.begin(), args.end(), "aa.index"); + LLValue* ret = gIR->ir->CreateCall(func, args.begin(), args.end(), "aa.index"); // cast return value - const llvm::Type* targettype = getPtrToType(DtoType(type)); + const LLType* targettype = getPtrToType(DtoType(type)); if (ret->getType() != targettype) ret = DtoBitCast(ret, targettype); @@ -123,30 +118,30 @@ Logger::cout() << "_aaIn = " << *func << '\n'; // aa param - llvm::Value* aaval = aa->getRVal(); + LLValue* aaval = aa->getRVal(); Logger::cout() << "aaval: " << *aaval << '\n'; Logger::cout() << "totype: " << *funcTy->getParamType(0) << '\n'; aaval = DtoBitCast(aaval, funcTy->getParamType(0)); // keyti param - llvm::Value* keyti = to_keyti(key); + LLValue* keyti = to_keyti(key); keyti = DtoBitCast(keyti, funcTy->getParamType(1)); // pkey param - llvm::Value* pkey = to_pkey(key); + LLValue* pkey = to_pkey(key); pkey = DtoBitCast(pkey, funcTy->getParamType(2)); // build arg vector - std::vector args; + LLSmallVector args; args.push_back(aaval); args.push_back(keyti); args.push_back(pkey); // call runtime - llvm::Value* ret = gIR->ir->CreateCall(func, args.begin(), args.end(), "aa.in"); + LLValue* ret = gIR->ir->CreateCall(func, args.begin(), args.end(), "aa.in"); // cast return value - const llvm::Type* targettype = DtoType(type); + const LLType* targettype = DtoType(type); if (ret->getType() != targettype) ret = DtoBitCast(ret, targettype); @@ -167,21 +162,21 @@ Logger::cout() << "_aaDel = " << *func << '\n'; // aa param - llvm::Value* aaval = aa->getRVal(); + LLValue* aaval = aa->getRVal(); Logger::cout() << "aaval: " << *aaval << '\n'; Logger::cout() << "totype: " << *funcTy->getParamType(0) << '\n'; aaval = DtoBitCast(aaval, funcTy->getParamType(0)); // keyti param - llvm::Value* keyti = to_keyti(key); + LLValue* keyti = to_keyti(key); keyti = DtoBitCast(keyti, funcTy->getParamType(1)); // pkey param - llvm::Value* pkey = to_pkey(key); + LLValue* pkey = to_pkey(key); pkey = DtoBitCast(pkey, funcTy->getParamType(2)); // build arg vector - std::vector args; + LLSmallVector args; args.push_back(aaval); args.push_back(keyti); args.push_back(pkey); diff -r 4c2689d57ba4 -r 7816aafeea3c gen/arrays.cpp --- a/gen/arrays.cpp Tue May 27 22:14:24 2008 +0200 +++ b/gen/arrays.cpp Fri May 30 19:32:04 2008 +0200 @@ -18,23 +18,10 @@ const llvm::StructType* DtoArrayType(Type* t) { assert(t->next); - const llvm::Type* at = DtoType(t->next); - const llvm::Type* arrty; - - if (at == llvm::Type::VoidTy) { - at = llvm::Type::Int8Ty; - } - arrty = getPtrToType(at); - - std::vector members; - if (global.params.is64bit) - members.push_back(llvm::Type::Int64Ty); - else - members.push_back(llvm::Type::Int32Ty); - - members.push_back(arrty); - - return llvm::StructType::get(members); + const LLType* elemty = DtoType(t->next); + if (elemty == llvm::Type::VoidTy) + elemty = llvm::Type::Int8Ty; + return llvm::StructType::get(DtoSize_t(), getPtrToType(elemty), 0); } ////////////////////////////////////////////////////////////////////////////////////////// @@ -47,7 +34,7 @@ assert(t->ty == Tsarray); assert(t->next); - const llvm::Type* at = DtoType(t->next); + const LLType* at = DtoType(t->next); TypeSArray* tsa = (TypeSArray*)t; assert(tsa->dim->type->isintegral()); @@ -60,24 +47,24 @@ ////////////////////////////////////////////////////////////////////////////////////////// -void DtoSetArrayToNull(llvm::Value* v) +void DtoSetArrayToNull(LLValue* v) { Logger::println("DtoSetArrayToNull"); LOG_SCOPE; - llvm::Value* len = DtoGEPi(v,0,0,"tmp",gIR->scopebb()); - llvm::Value* zerolen = llvm::ConstantInt::get(len->getType()->getContainedType(0), 0, false); + LLValue* len = DtoGEPi(v,0,0,"tmp",gIR->scopebb()); + LLValue* zerolen = llvm::ConstantInt::get(len->getType()->getContainedType(0), 0, false); new llvm::StoreInst(zerolen, len, gIR->scopebb()); - llvm::Value* ptr = DtoGEPi(v,0,1,"tmp",gIR->scopebb()); + LLValue* ptr = DtoGEPi(v,0,1,"tmp",gIR->scopebb()); const llvm::PointerType* pty = isaPointer(ptr->getType()->getContainedType(0)); - llvm::Value* nullptr = llvm::ConstantPointerNull::get(pty); + LLValue* nullptr = llvm::ConstantPointerNull::get(pty); new llvm::StoreInst(nullptr, ptr, gIR->scopebb()); } ////////////////////////////////////////////////////////////////////////////////////////// -void DtoArrayAssign(llvm::Value* dst, llvm::Value* src) +void DtoArrayAssign(LLValue* dst, LLValue* src) { Logger::println("DtoArrayAssign"); LOG_SCOPE; @@ -85,8 +72,8 @@ assert(gIR); if (dst->getType() == src->getType()) { - llvm::Value* ptr = DtoGEPi(src,0,0,"tmp",gIR->scopebb()); - llvm::Value* val = new llvm::LoadInst(ptr,"tmp",gIR->scopebb()); + LLValue* ptr = DtoGEPi(src,0,0,"tmp",gIR->scopebb()); + LLValue* val = new llvm::LoadInst(ptr,"tmp",gIR->scopebb()); ptr = DtoGEPi(dst,0,0,"tmp",gIR->scopebb()); new llvm::StoreInst(val, ptr, gIR->scopebb()); @@ -104,38 +91,38 @@ Logger::cout() << "invalid: " << *src << '\n'; assert(0); } - const llvm::Type* dstty = getPtrToType(arrty->getElementType()); + const LLType* dstty = getPtrToType(arrty->getElementType()); - llvm::Value* dstlen = DtoGEPi(dst,0,0,"tmp",gIR->scopebb()); - llvm::Value* srclen = DtoConstSize_t(arrty->getNumElements()); + LLValue* dstlen = DtoGEPi(dst,0,0,"tmp",gIR->scopebb()); + LLValue* srclen = DtoConstSize_t(arrty->getNumElements()); new llvm::StoreInst(srclen, dstlen, gIR->scopebb()); - llvm::Value* dstptr = DtoGEPi(dst,0,1,"tmp",gIR->scopebb()); - llvm::Value* srcptr = new llvm::BitCastInst(src,dstty,"tmp",gIR->scopebb()); + LLValue* dstptr = DtoGEPi(dst,0,1,"tmp",gIR->scopebb()); + LLValue* srcptr = DtoBitCast(src, dstty); new llvm::StoreInst(srcptr, dstptr, gIR->scopebb()); } } ////////////////////////////////////////////////////////////////////////////////////////// -void DtoArrayInit(llvm::Value* l, llvm::Value* r) +void DtoArrayInit(LLValue* l, LLValue* r) { Logger::println("DtoArrayInit"); LOG_SCOPE; const llvm::PointerType* ptrty = isaPointer(l->getType()); - const llvm::Type* t = ptrty->getContainedType(0); + const LLType* t = ptrty->getContainedType(0); const llvm::ArrayType* arrty = isaArray(t); if (arrty) { - llvm::Value* ptr = DtoGEPi(l,0,0,"tmp",gIR->scopebb()); - llvm::Value* dim = llvm::ConstantInt::get(DtoSize_t(), arrty->getNumElements(), false); + LLValue* ptr = DtoGEPi(l,0,0,"tmp",gIR->scopebb()); + LLValue* dim = llvm::ConstantInt::get(DtoSize_t(), arrty->getNumElements(), false); DtoArrayInit(ptr, dim, r); } else if (isaStruct(t)) { - llvm::Value* dim = DtoLoad(DtoGEPi(l, 0,0, "tmp")); - llvm::Value* ptr = DtoLoad(DtoGEPi(l, 0,1, "tmp")); + LLValue* dim = DtoLoad(DtoGEPi(l, 0,0, "tmp")); + LLValue* ptr = DtoLoad(DtoGEPi(l, 0,1, "tmp")); DtoArrayInit(ptr, dim, r); } else @@ -144,9 +131,9 @@ ////////////////////////////////////////////////////////////////////////////////////////// -typedef const llvm::Type* constLLVMTypeP; +typedef const LLType* constLLVMTypeP; -static size_t checkRectArrayInit(const llvm::Type* pt, constLLVMTypeP& finalty) +static size_t checkRectArrayInit(const LLType* pt, constLLVMTypeP& finalty) { if (const llvm::ArrayType* arrty = isaArray(pt)) { size_t n = checkRectArrayInit(arrty->getElementType(), finalty); @@ -158,28 +145,28 @@ return 0; } -void DtoArrayInit(llvm::Value* ptr, llvm::Value* dim, llvm::Value* val) +void DtoArrayInit(LLValue* ptr, LLValue* dim, LLValue* val) { Logger::println("DtoArrayInit"); LOG_SCOPE; Logger::cout() << "array: " << *ptr << " dim: " << *dim << " val: " << *val << '\n'; - const llvm::Type* pt = ptr->getType()->getContainedType(0); - const llvm::Type* t = val->getType(); - const llvm::Type* finalTy; + const LLType* pt = ptr->getType()->getContainedType(0); + const LLType* t = val->getType(); + const LLType* finalTy; size_t aggrsz = 0; if (size_t arrsz = checkRectArrayInit(pt, finalTy)) { assert(finalTy == t); - llvm::Constant* c = isaConstant(dim); + LLConstant* c = isaConstant(dim); assert(c); dim = llvm::ConstantExpr::getMul(c, DtoConstSize_t(arrsz)); ptr = gIR->ir->CreateBitCast(ptr, getPtrToType(finalTy), "tmp"); } else if (isaStruct(t)) { aggrsz = getABITypeSize(t); - llvm::Constant* c = isaConstant(val); + LLConstant* c = isaConstant(val); if (c && c->isNullValue()) { - llvm::Value* nbytes; + LLValue* nbytes; if (aggrsz == 1) nbytes = dim; else @@ -197,7 +184,7 @@ Logger::cout() << "array: " << *ptr << " dim: " << *dim << " val: " << *val << '\n'; - std::vector args; + std::vector args; args.push_back(ptr); args.push_back(dim); args.push_back(val); @@ -211,13 +198,13 @@ else if (isaPointer(t)) { funcname = "_d_array_init_pointer"; - const llvm::Type* dstty = getPtrToType(getPtrToType(llvm::Type::Int8Ty)); + const LLType* dstty = getPtrToType(getPtrToType(llvm::Type::Int8Ty)); if (args[0]->getType() != dstty) - args[0] = new llvm::BitCastInst(args[0],dstty,"tmp",gIR->scopebb()); + args[0] = DtoBitCast(args[0],dstty); - const llvm::Type* valty = getPtrToType(llvm::Type::Int8Ty); + const LLType* valty = getPtrToType(llvm::Type::Int8Ty); if (args[2]->getType() != valty) - args[2] = new llvm::BitCastInst(args[2],valty,"tmp",gIR->scopebb()); + args[2] = DtoBitCast(args[2],valty); } else if (t == llvm::Type::Int1Ty) { funcname = "_d_array_init_i1"; @@ -254,7 +241,7 @@ ////////////////////////////////////////////////////////////////////////////////////////// -void DtoSetArray(llvm::Value* arr, llvm::Value* dim, llvm::Value* ptr) +void DtoSetArray(LLValue* arr, LLValue* dim, LLValue* ptr) { Logger::println("DtoSetArray"); LOG_SCOPE; @@ -265,20 +252,20 @@ const llvm::StructType* st = isaStruct(arr->getType()->getContainedType(0)); - llvm::Value* zero = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false); - llvm::Value* one = llvm::ConstantInt::get(llvm::Type::Int32Ty, 1, false); + LLValue* zero = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false); + LLValue* one = llvm::ConstantInt::get(llvm::Type::Int32Ty, 1, false); - llvm::Value* arrdim = DtoGEP(arr,zero,zero,"tmp",gIR->scopebb()); + LLValue* arrdim = DtoGEP(arr,zero,zero,"tmp",gIR->scopebb()); Logger::cout() << "arrdim = " << *arrdim << '\n'; new llvm::StoreInst(dim, arrdim, gIR->scopebb()); - llvm::Value* arrptr = DtoGEP(arr,zero,one,"tmp",gIR->scopebb()); + LLValue* arrptr = DtoGEP(arr,zero,one,"tmp",gIR->scopebb()); Logger::cout() << "arrptr = " << *arrptr << '\n'; new llvm::StoreInst(ptr, arrptr, gIR->scopebb()); } ////////////////////////////////////////////////////////////////////////////////////////// -llvm::Constant* DtoConstArrayInitializer(ArrayInitializer* arrinit) +LLConstant* DtoConstArrayInitializer(ArrayInitializer* arrinit) { Logger::println("DtoConstArrayInitializer: %s | %s", arrinit->toChars(), arrinit->type->toChars()); LOG_SCOPE; @@ -303,10 +290,10 @@ Logger::println("dim = %u", tdim); - std::vector inits(tdim, NULL); + std::vector inits(tdim, NULL); Type* arrnext = arrinittype->next; - const llvm::Type* elemty = DtoType(arrinittype->next); + const LLType* elemty = DtoType(arrinittype->next); assert(arrinit->index.dim == arrinit->value.dim); for (unsigned i=0,j=0; i < tdim; ++i) @@ -319,7 +306,7 @@ else idx = NULL; - llvm::Constant* v = NULL; + LLConstant* v = NULL; if (idx) { @@ -331,7 +318,7 @@ Logger::println("has idx->type", i); //integer_t k = idx->toInteger(); //Logger::println("getting value for exp: %s | %s", idx->toChars(), arrnext->toChars()); - llvm::Constant* cc = idx->toConstElem(gIR); + LLConstant* cc = idx->toConstElem(gIR); Logger::println("value gotten"); assert(cc != NULL); llvm::ConstantInt* ci = llvm::dyn_cast(cc); @@ -365,7 +352,7 @@ Logger::println("building constant array"); const llvm::ArrayType* arrty = llvm::ArrayType::get(elemty,tdim); - llvm::Constant* constarr = llvm::ConstantArray::get(arrty, inits); + LLConstant* constarr = llvm::ConstantArray::get(arrty, inits); if (arrinittype->ty == Tsarray) return constarr; @@ -373,16 +360,16 @@ assert(arrinittype->ty == Tarray); llvm::GlobalVariable* gvar = new llvm::GlobalVariable(arrty,true,llvm::GlobalValue::InternalLinkage,constarr,"constarray",gIR->module); - llvm::Constant* idxs[2] = { DtoConstUint(0), DtoConstUint(0) }; - llvm::Constant* gep = llvm::ConstantExpr::getGetElementPtr(gvar,idxs,2); + LLConstant* idxs[2] = { DtoConstUint(0), DtoConstUint(0) }; + LLConstant* gep = llvm::ConstantExpr::getGetElementPtr(gvar,idxs,2); return DtoConstSlice(DtoConstSize_t(tdim),gep); } ////////////////////////////////////////////////////////////////////////////////////////// -static llvm::Value* get_slice_ptr(DSliceValue* e, llvm::Value*& sz) +static LLValue* get_slice_ptr(DSliceValue* e, LLValue*& sz) { - const llvm::Type* t = e->ptr->getType()->getContainedType(0); - llvm::Value* ret = 0; + const LLType* t = e->ptr->getType()->getContainedType(0); + LLValue* ret = 0; if (e->len != 0) { // this means it's a real slice ret = e->ptr; @@ -415,7 +402,7 @@ size_t elembsz = getABITypeSize(ret->getType()->getContainedType(0)); llvm::ConstantInt* elemsz = llvm::ConstantInt::get(DtoSize_t(), elembsz, false); - llvm::Value* len = DtoGEPi(e->ptr, 0, 0, "tmp", gIR->scopebb()); + LLValue* len = DtoGEPi(e->ptr, 0, 0, "tmp", gIR->scopebb()); len = new llvm::LoadInst(len, "tmp", gIR->scopebb()); sz = llvm::BinaryOperator::createMul(len,elemsz,"tmp",gIR->scopebb()); } @@ -428,16 +415,16 @@ void DtoArrayCopySlices(DSliceValue* dst, DSliceValue* src) { Logger::println("ArrayCopySlices"); - const llvm::Type* arrty = getPtrToType(llvm::Type::Int8Ty); + const LLType* arrty = getPtrToType(llvm::Type::Int8Ty); - llvm::Value* sz1; - llvm::Value* dstarr = new llvm::BitCastInst(get_slice_ptr(dst,sz1),arrty,"tmp",gIR->scopebb()); + LLValue* sz1; + LLValue* dstarr = DtoBitCast(get_slice_ptr(dst,sz1),arrty); - llvm::Value* sz2; - llvm::Value* srcarr = new llvm::BitCastInst(get_slice_ptr(src,sz2),arrty,"tmp",gIR->scopebb()); + LLValue* sz2; + LLValue* srcarr = DtoBitCast(get_slice_ptr(src,sz2),arrty); llvm::Function* fn = (global.params.is64bit) ? LLVM_DeclareMemCpy64() : LLVM_DeclareMemCpy32(); - std::vector llargs; + std::vector llargs; llargs.resize(4); llargs[0] = dstarr; llargs[1] = srcarr; @@ -450,14 +437,14 @@ void DtoArrayCopyToSlice(DSliceValue* dst, DValue* src) { Logger::println("ArrayCopyToSlice"); - const llvm::Type* arrty = getPtrToType(llvm::Type::Int8Ty); + const LLType* arrty = getPtrToType(llvm::Type::Int8Ty); - llvm::Value* sz1; - llvm::Value* dstarr = new llvm::BitCastInst(get_slice_ptr(dst,sz1),arrty,"tmp",gIR->scopebb()); - llvm::Value* srcarr = new llvm::BitCastInst(DtoArrayPtr(src),arrty,"tmp",gIR->scopebb()); + LLValue* sz1; + LLValue* dstarr = DtoBitCast(get_slice_ptr(dst,sz1),arrty); + LLValue* srcarr = DtoBitCast(DtoArrayPtr(src),arrty); llvm::Function* fn = (global.params.is64bit) ? LLVM_DeclareMemCpy64() : LLVM_DeclareMemCpy32(); - std::vector llargs; + std::vector llargs; llargs.resize(4); llargs[0] = dstarr; llargs[1] = srcarr; @@ -468,19 +455,19 @@ } ////////////////////////////////////////////////////////////////////////////////////////// -void DtoStaticArrayCopy(llvm::Value* dst, llvm::Value* src) +void DtoStaticArrayCopy(LLValue* dst, LLValue* src) { Logger::cout() << "static array copy: " << *dst << " from " << *src << '\n'; assert(dst->getType() == src->getType()); size_t arrsz = getABITypeSize(dst->getType()->getContainedType(0)); - llvm::Value* n = llvm::ConstantInt::get(DtoSize_t(), arrsz, false); + LLValue* n = llvm::ConstantInt::get(DtoSize_t(), arrsz, false); - const llvm::Type* arrty = getPtrToType(llvm::Type::Int8Ty); - llvm::Value* dstarr = new llvm::BitCastInst(dst,arrty,"tmp",gIR->scopebb()); - llvm::Value* srcarr = new llvm::BitCastInst(src,arrty,"tmp",gIR->scopebb()); + const LLType* arrty = getPtrToType(llvm::Type::Int8Ty); + LLValue* dstarr = DtoBitCast(dst,arrty); + LLValue* srcarr = DtoBitCast(src,arrty); llvm::Function* fn = (global.params.is64bit) ? LLVM_DeclareMemCpy64() : LLVM_DeclareMemCpy32(); - std::vector llargs; + std::vector llargs; llargs.resize(4); llargs[0] = dstarr; llargs[1] = srcarr; @@ -491,13 +478,13 @@ } ////////////////////////////////////////////////////////////////////////////////////////// -llvm::Constant* DtoConstSlice(llvm::Constant* dim, llvm::Constant* ptr) +LLConstant* DtoConstSlice(LLConstant* dim, LLConstant* ptr) { - std::vector types; + std::vector types; types.push_back(dim->getType()); types.push_back(ptr->getType()); const llvm::StructType* type = llvm::StructType::get(types); - std::vector values; + std::vector values; values.push_back(dim); values.push_back(ptr); return llvm::ConstantStruct::get(type,values); @@ -512,13 +499,13 @@ bool zeroInit = arrayType->toBasetype()->nextOf()->isZeroInit(); llvm::Function* fn = LLVM_D_GetRuntimeFunction(gIR->module, zeroInit ? "_d_newarrayT" : "_d_newarrayiT" ); - llvm::SmallVector args; + LLSmallVector args; args.push_back(DtoTypeInfoOf(arrayType)); assert(DtoType(dim->getType()) == DtoSize_t()); args.push_back(dim->getRVal()); - llvm::Value* newptr = gIR->ir->CreateCall(fn, args.begin(), args.end(), ".gc_mem"); - const llvm::Type* dstType = DtoType(arrayType)->getContainedType(1); + LLValue* newptr = gIR->ir->CreateCall(fn, args.begin(), args.end(), ".gc_mem"); + const LLType* dstType = DtoType(arrayType)->getContainedType(1); if (newptr->getType() != dstType) newptr = DtoBitCast(newptr, dstType, ".gc_mem"); @@ -551,15 +538,15 @@ // call runtime llvm::Function* fn = LLVM_D_GetRuntimeFunction(gIR->module, zeroInit ? "_d_arraysetlengthT" : "_d_arraysetlengthiT" ); - llvm::SmallVector args; + LLSmallVector args; args.push_back(DtoTypeInfoOf(arrayType)); args.push_back(newdim->getRVal()); args.push_back(DtoArrayLen(array)); - llvm::Value* arrPtr = DtoArrayPtr(array); + LLValue* arrPtr = DtoArrayPtr(array); Logger::cout() << "arrPtr = " << *arrPtr << '\n'; args.push_back(DtoBitCast(arrPtr, fn->getFunctionType()->getParamType(3), "tmp")); - llvm::Value* newptr = gIR->ir->CreateCall(fn, args.begin(), args.end(), ".gc_mem"); + LLValue* newptr = gIR->ir->CreateCall(fn, args.begin(), args.end(), ".gc_mem"); if (newptr->getType() != arrPtr->getType()) newptr = DtoBitCast(newptr, arrPtr->getType(), ".gc_mem"); @@ -574,14 +561,14 @@ assert(array); - llvm::Value* idx = DtoArrayLen(array); - llvm::Value* one = DtoConstSize_t(1); - llvm::Value* len = gIR->ir->CreateAdd(idx,one,"tmp"); + LLValue* idx = DtoArrayLen(array); + LLValue* one = DtoConstSize_t(1); + LLValue* len = gIR->ir->CreateAdd(idx,one,"tmp"); DValue* newdim = new DImValue(Type::tsize_t, len); DSliceValue* slice = DtoResizeDynArray(array->getType(), array, newdim); - llvm::Value* ptr = slice->ptr; + LLValue* ptr = slice->ptr; ptr = llvm::GetElementPtrInst::Create(ptr, idx, "tmp", gIR->scopebb()); DValue* dptr = new DVarValue(exp->type, ptr, true); @@ -620,8 +607,8 @@ src1 = gIR->ir->CreateGEP(src1,len1,"tmp"); // memcpy - llvm::Value* elemSize = DtoConstSize_t(getABITypeSize(src2->getType()->getContainedType(0))); - llvm::Value* bytelen = gIR->ir->CreateMul(len2, elemSize, "tmp"); + LLValue* elemSize = DtoConstSize_t(getABITypeSize(src2->getType()->getContainedType(0))); + LLValue* bytelen = gIR->ir->CreateMul(len2, elemSize, "tmp"); DtoMemCpy(src1,src2,bytelen); return slice; @@ -650,14 +637,14 @@ DValue* lenval = new DImValue(Type::tsize_t, res); DSliceValue* slice = DtoNewDynArray(type, lenval, false); - llvm::Value* mem = slice->ptr; + LLValue* mem = slice->ptr; src1 = DtoArrayPtr(e1); src2 = DtoArrayPtr(e2); // first memcpy - llvm::Value* elemSize = DtoConstSize_t(getABITypeSize(src1->getType()->getContainedType(0))); - llvm::Value* bytelen = gIR->ir->CreateMul(len1, elemSize, "tmp"); + LLValue* elemSize = DtoConstSize_t(getABITypeSize(src1->getType()->getContainedType(0))); + LLValue* bytelen = gIR->ir->CreateMul(len1, elemSize, "tmp"); DtoMemCpy(mem,src1,bytelen); // second memcpy @@ -690,7 +677,7 @@ DValue* lenval = new DImValue(Type::tsize_t, res); DSliceValue* slice = DtoNewDynArray(type, lenval, false); - llvm::Value* mem = slice->ptr; + LLValue* mem = slice->ptr; DVarValue* memval = new DVarValue(e1->getType(), mem, true); DtoAssign(memval, e1); @@ -699,8 +686,8 @@ mem = gIR->ir->CreateGEP(mem,DtoConstSize_t(1),"tmp"); - llvm::Value* elemSize = DtoConstSize_t(getABITypeSize(src1->getType()->getContainedType(0))); - llvm::Value* bytelen = gIR->ir->CreateMul(len1, elemSize, "tmp"); + LLValue* elemSize = DtoConstSize_t(getABITypeSize(src1->getType()->getContainedType(0))); + LLValue* bytelen = gIR->ir->CreateMul(len1, elemSize, "tmp"); DtoMemCpy(mem,src1,bytelen); @@ -714,12 +701,12 @@ DValue* lenval = new DImValue(Type::tsize_t, res); DSliceValue* slice = DtoNewDynArray(type, lenval, false); - llvm::Value* mem = slice->ptr; + LLValue* mem = slice->ptr; src1 = DtoArrayPtr(e1); - llvm::Value* elemSize = DtoConstSize_t(getABITypeSize(src1->getType()->getContainedType(0))); - llvm::Value* bytelen = gIR->ir->CreateMul(len1, elemSize, "tmp"); + LLValue* elemSize = DtoConstSize_t(getABITypeSize(src1->getType()->getContainedType(0))); + LLValue* bytelen = gIR->ir->CreateMul(len1, elemSize, "tmp"); DtoMemCpy(mem,src1,bytelen); mem = gIR->ir->CreateGEP(mem,len1,"tmp"); @@ -732,14 +719,14 @@ ////////////////////////////////////////////////////////////////////////////////////////// // helper for eq and cmp -static llvm::Value* DtoArrayEqCmp_impl(const char* func, DValue* l, DValue* r, bool useti) +static LLValue* DtoArrayEqCmp_impl(const char* func, DValue* l, DValue* r, bool useti) { Logger::println("comparing arrays"); llvm::Function* fn = LLVM_D_GetRuntimeFunction(gIR->module, func); assert(fn); - llvm::Value* lmem; - llvm::Value* rmem; + LLValue* lmem; + LLValue* rmem; // cast static arrays to dynamic ones, this turns them into DSliceValues Logger::println("casting to dynamic arrays"); @@ -785,9 +772,9 @@ else rmem = r->getRVal(); - const llvm::Type* pt = fn->getFunctionType()->getParamType(0); + const LLType* pt = fn->getFunctionType()->getParamType(0); - std::vector args; + std::vector args; Logger::cout() << "bitcasting to " << *pt << '\n'; Logger::cout() << *lmem << '\n'; Logger::cout() << *rmem << '\n'; @@ -796,24 +783,26 @@ // pass element typeinfo ? if (useti) { - TypeInfoDeclaration* ti = DtoDType(l->getType())->next->getTypeInfoDeclaration(); - DtoForceConstInitDsymbol(ti); - Logger::cout() << "typeinfo decl: " << *ti->ir.getIrValue() << '\n'; + Type* t = DtoDType(l->getType())->next; + LLValue* tival = DtoTypeInfoOf(t); + // DtoTypeInfoOf only does declare, not enough in this case :/ + DtoForceConstInitDsymbol(t->vtinfo); + Logger::cout() << "typeinfo decl: " << *tival << '\n'; pt = fn->getFunctionType()->getParamType(2); - args.push_back(DtoBitCast(ti->ir.getIrValue(), pt)); + args.push_back(DtoBitCast(tival, pt)); } return gIR->ir->CreateCall(fn, args.begin(), args.end(), "tmp"); } ////////////////////////////////////////////////////////////////////////////////////////// -llvm::Value* DtoArrayEquals(TOK op, DValue* l, DValue* r) +LLValue* DtoArrayEquals(TOK op, DValue* l, DValue* r) { llvm::Function* fn = LLVM_D_GetRuntimeFunction(gIR->module, "_adEq"); assert(fn); - llvm::Value* res = DtoArrayEqCmp_impl("_adEq", l, r, true); + LLValue* res = DtoArrayEqCmp_impl("_adEq", l, r, true); if (op == TOKnotequal) res = gIR->ir->CreateNot(res, "tmp"); @@ -821,9 +810,9 @@ } ////////////////////////////////////////////////////////////////////////////////////////// -llvm::Value* DtoArrayCompare(TOK op, DValue* l, DValue* r) +LLValue* DtoArrayCompare(TOK op, DValue* l, DValue* r) { - llvm::Value* res = 0; + LLValue* res = 0; llvm::ICmpInst::Predicate cmpop; bool skip = false; @@ -880,7 +869,7 @@ } ////////////////////////////////////////////////////////////////////////////////////////// -llvm::Value* DtoArrayCastLength(llvm::Value* len, const llvm::Type* elemty, const llvm::Type* newelemty) +LLValue* DtoArrayCastLength(LLValue* len, const LLType* elemty, const LLType* newelemty) { Logger::println("DtoArrayCastLength"); LOG_SCOPE; @@ -894,7 +883,7 @@ if (esz == nsz) return len; - std::vector args; + std::vector args; args.push_back(len); args.push_back(llvm::ConstantInt::get(DtoSize_t(), esz, false)); args.push_back(llvm::ConstantInt::get(DtoSize_t(), nsz, false)); @@ -904,41 +893,41 @@ } ////////////////////////////////////////////////////////////////////////////////////////// -llvm::Value* DtoDynArrayIs(TOK op, llvm::Value* l, llvm::Value* r) +LLValue* DtoDynArrayIs(TOK op, LLValue* l, LLValue* r) { llvm::ICmpInst::Predicate pred = (op == TOKidentity) ? llvm::ICmpInst::ICMP_EQ : llvm::ICmpInst::ICMP_NE; if (r == NULL) { - llvm::Value* ll = gIR->ir->CreateLoad(DtoGEPi(l, 0,0, "tmp"),"tmp"); - llvm::Value* rl = llvm::Constant::getNullValue(ll->getType());//DtoConstSize_t(0); - llvm::Value* b1 = gIR->ir->CreateICmp(pred,ll,rl,"tmp"); + LLValue* ll = gIR->ir->CreateLoad(DtoGEPi(l, 0,0, "tmp"),"tmp"); + LLValue* rl = llvm::Constant::getNullValue(ll->getType());//DtoConstSize_t(0); + LLValue* b1 = gIR->ir->CreateICmp(pred,ll,rl,"tmp"); - llvm::Value* lp = gIR->ir->CreateLoad(DtoGEPi(l, 0,1, "tmp"),"tmp"); + LLValue* lp = gIR->ir->CreateLoad(DtoGEPi(l, 0,1, "tmp"),"tmp"); const llvm::PointerType* pty = isaPointer(lp->getType()); - llvm::Value* rp = llvm::ConstantPointerNull::get(pty); - llvm::Value* b2 = gIR->ir->CreateICmp(pred,lp,rp,"tmp"); + LLValue* rp = llvm::ConstantPointerNull::get(pty); + LLValue* b2 = gIR->ir->CreateICmp(pred,lp,rp,"tmp"); - llvm::Value* b = gIR->ir->CreateAnd(b1,b2,"tmp"); + LLValue* b = gIR->ir->CreateAnd(b1,b2,"tmp"); return b; } else { assert(l->getType() == r->getType()); - llvm::Value* ll = gIR->ir->CreateLoad(DtoGEPi(l, 0,0, "tmp"),"tmp"); - llvm::Value* rl = gIR->ir->CreateLoad(DtoGEPi(r, 0,0, "tmp"),"tmp"); - llvm::Value* b1 = gIR->ir->CreateICmp(pred,ll,rl,"tmp"); + LLValue* ll = gIR->ir->CreateLoad(DtoGEPi(l, 0,0, "tmp"),"tmp"); + LLValue* rl = gIR->ir->CreateLoad(DtoGEPi(r, 0,0, "tmp"),"tmp"); + LLValue* b1 = gIR->ir->CreateICmp(pred,ll,rl,"tmp"); - llvm::Value* lp = gIR->ir->CreateLoad(DtoGEPi(l, 0,1, "tmp"),"tmp"); - llvm::Value* rp = gIR->ir->CreateLoad(DtoGEPi(r, 0,1, "tmp"),"tmp"); - llvm::Value* b2 = gIR->ir->CreateICmp(pred,lp,rp,"tmp"); + LLValue* lp = gIR->ir->CreateLoad(DtoGEPi(l, 0,1, "tmp"),"tmp"); + LLValue* rp = gIR->ir->CreateLoad(DtoGEPi(r, 0,1, "tmp"),"tmp"); + LLValue* b2 = gIR->ir->CreateICmp(pred,lp,rp,"tmp"); - llvm::Value* b = gIR->ir->CreateAnd(b1,b2,"tmp"); + LLValue* b = gIR->ir->CreateAnd(b1,b2,"tmp"); return b; } } ////////////////////////////////////////////////////////////////////////////////////////// -llvm::Constant* DtoConstStaticArray(const llvm::Type* t, llvm::Constant* c) +LLConstant* DtoConstStaticArray(const LLType* t, LLConstant* c) { const llvm::ArrayType* at = isaArray(t); assert(at); @@ -950,13 +939,13 @@ else { assert(at->getElementType() == c->getType()); } - std::vector initvals; + std::vector initvals; initvals.resize(at->getNumElements(), c); return llvm::ConstantArray::get(at, initvals); } ////////////////////////////////////////////////////////////////////////////////////////// -llvm::Value* DtoArrayLen(DValue* v) +LLValue* DtoArrayLen(DValue* v) { Logger::println("DtoArrayLen"); LOG_SCOPE; @@ -977,7 +966,7 @@ } else if (t->ty == Tsarray) { assert(!v->isSlice()); - llvm::Value* rv = v->getRVal(); + LLValue* rv = v->getRVal(); Logger::cout() << "casting: " << *rv << '\n'; const llvm::ArrayType* t = isaArray(rv->getType()->getContainedType(0)); return DtoConstSize_t(t->getNumElements()); @@ -987,7 +976,7 @@ } ////////////////////////////////////////////////////////////////////////////////////////// -llvm::Value* DtoArrayPtr(DValue* v) +LLValue* DtoArrayPtr(DValue* v) { Logger::println("DtoArrayPtr"); LOG_SCOPE; @@ -996,7 +985,7 @@ if (t->ty == Tarray) { if (DSliceValue* s = v->isSlice()) { if (s->len) return s->ptr; - const llvm::Type* t = s->ptr->getType()->getContainedType(0); + const LLType* t = s->ptr->getType()->getContainedType(0); Logger::cout() << "ptr of full slice: " << *s->ptr << '\n'; const llvm::ArrayType* arrTy = isaArray(s->ptr->getType()->getContainedType(0)); if (arrTy) @@ -1019,14 +1008,14 @@ Logger::println("DtoCastArray"); LOG_SCOPE; - const llvm::Type* tolltype = DtoType(to); + const LLType* tolltype = DtoType(to); Type* totype = DtoDType(to); Type* fromtype = DtoDType(u->getType()); assert(fromtype->ty == Tarray || fromtype->ty == Tsarray); - llvm::Value* rval; - llvm::Value* rval2; + LLValue* rval; + LLValue* rval2; bool isslice = false; Logger::cout() << "from array or sarray" << '\n'; @@ -1038,37 +1027,37 @@ } else if (totype->ty == Tarray) { Logger::cout() << "to array" << '\n'; - const llvm::Type* ptrty = DtoType(totype->next); + const LLType* ptrty = DtoType(totype->next); if (ptrty == llvm::Type::VoidTy) ptrty = llvm::Type::Int8Ty; ptrty = getPtrToType(ptrty); - const llvm::Type* ety = DtoType(fromtype->next); + const LLType* ety = DtoType(fromtype->next); if (ety == llvm::Type::VoidTy) ety = llvm::Type::Int8Ty; if (DSliceValue* usl = u->isSlice()) { Logger::println("from slice"); Logger::cout() << "from: " << *usl->ptr << " to: " << *ptrty << '\n'; - rval = new llvm::BitCastInst(usl->ptr, ptrty, "tmp", gIR->scopebb()); + rval = DtoBitCast(usl->ptr, ptrty); if (fromtype->next->size() == totype->next->size()) rval2 = DtoArrayLen(usl); else rval2 = DtoArrayCastLength(DtoArrayLen(usl), ety, ptrty->getContainedType(0)); } else { - llvm::Value* uval = u->getRVal(); + LLValue* uval = u->getRVal(); if (fromtype->ty == Tsarray) { Logger::cout() << "uvalTy = " << *uval->getType() << '\n'; assert(isaPointer(uval->getType())); const llvm::ArrayType* arrty = isaArray(uval->getType()->getContainedType(0)); rval2 = llvm::ConstantInt::get(DtoSize_t(), arrty->getNumElements(), false); rval2 = DtoArrayCastLength(rval2, ety, ptrty->getContainedType(0)); - rval = new llvm::BitCastInst(uval, ptrty, "tmp", gIR->scopebb()); + rval = DtoBitCast(uval, ptrty); } else { - llvm::Value* zero = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false); - llvm::Value* one = llvm::ConstantInt::get(llvm::Type::Int32Ty, 1, false); + LLValue* zero = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false); + LLValue* one = llvm::ConstantInt::get(llvm::Type::Int32Ty, 1, false); rval2 = DtoGEP(uval,zero,zero,"tmp",gIR->scopebb()); rval2 = new llvm::LoadInst(rval2, "tmp", gIR->scopebb()); rval2 = DtoArrayCastLength(rval2, ety, ptrty->getContainedType(0)); @@ -1076,7 +1065,7 @@ rval = DtoGEP(uval,zero,one,"tmp",gIR->scopebb()); rval = new llvm::LoadInst(rval, "tmp", gIR->scopebb()); //Logger::cout() << *e->mem->getType() << '|' << *ptrty << '\n'; - rval = new llvm::BitCastInst(rval, ptrty, "tmp", gIR->scopebb()); + rval = DtoBitCast(rval, ptrty); } } isslice = true; diff -r 4c2689d57ba4 -r 7816aafeea3c gen/arrays.h --- a/gen/arrays.h Tue May 27 22:14:24 2008 +0200 +++ b/gen/arrays.h Fri May 30 19:32:04 2008 +0200 @@ -6,18 +6,18 @@ const llvm::StructType* DtoArrayType(Type* t); const llvm::ArrayType* DtoStaticArrayType(Type* t); -llvm::Constant* DtoConstArrayInitializer(ArrayInitializer* si); -llvm::Constant* DtoConstSlice(llvm::Constant* dim, llvm::Constant* ptr); -llvm::Constant* DtoConstStaticArray(const llvm::Type* t, llvm::Constant* c); +LLConstant* DtoConstArrayInitializer(ArrayInitializer* si); +LLConstant* DtoConstSlice(LLConstant* dim, LLConstant* ptr); +LLConstant* DtoConstStaticArray(const llvm::Type* t, LLConstant* c); void DtoArrayCopySlices(DSliceValue* dst, DSliceValue* src); void DtoArrayCopyToSlice(DSliceValue* dst, DValue* src); -void DtoArrayInit(llvm::Value* l, llvm::Value* r); -void DtoArrayInit(llvm::Value* ptr, llvm::Value* dim, llvm::Value* val); -void DtoArrayAssign(llvm::Value* l, llvm::Value* r); -void DtoSetArray(llvm::Value* arr, llvm::Value* dim, llvm::Value* ptr); -void DtoSetArrayToNull(llvm::Value* v); +void DtoArrayInit(LLValue* l, LLValue* r); +void DtoArrayInit(LLValue* ptr, LLValue* dim, LLValue* val); +void DtoArrayAssign(LLValue* l, LLValue* r); +void DtoSetArray(LLValue* arr, LLValue* dim, LLValue* ptr); +void DtoSetArrayToNull(LLValue* v); DSliceValue* DtoNewDynArray(Type* arrayType, DValue* dim, bool defaultInit=true); DSliceValue* DtoResizeDynArray(Type* arrayType, DValue* array, DValue* newdim); @@ -27,17 +27,17 @@ DSliceValue* DtoCatArrays(Type* type, Expression* e1, Expression* e2); DSliceValue* DtoCatArrayElement(Type* type, Expression* exp1, Expression* exp2); -void DtoStaticArrayCopy(llvm::Value* dst, llvm::Value* src); +void DtoStaticArrayCopy(LLValue* dst, LLValue* src); -llvm::Value* DtoArrayEquals(TOK op, DValue* l, DValue* r); -llvm::Value* DtoArrayCompare(TOK op, DValue* l, DValue* r); +LLValue* DtoArrayEquals(TOK op, DValue* l, DValue* r); +LLValue* DtoArrayCompare(TOK op, DValue* l, DValue* r); -llvm::Value* DtoDynArrayIs(TOK op, llvm::Value* l, llvm::Value* r); +LLValue* DtoDynArrayIs(TOK op, LLValue* l, LLValue* r); -llvm::Value* DtoArrayCastLength(llvm::Value* len, const llvm::Type* elemty, const llvm::Type* newelemty); +LLValue* DtoArrayCastLength(LLValue* len, const llvm::Type* elemty, const llvm::Type* newelemty); -llvm::Value* DtoArrayLen(DValue* v); -llvm::Value* DtoArrayPtr(DValue* v); +LLValue* DtoArrayLen(DValue* v); +LLValue* DtoArrayPtr(DValue* v); DValue* DtoCastArray(DValue* val, Type* to); diff -r 4c2689d57ba4 -r 7816aafeea3c gen/binops.cpp --- a/gen/binops.cpp Tue May 27 22:14:24 2008 +0200 +++ b/gen/binops.cpp Fri May 30 19:32:04 2008 +0200 @@ -10,7 +10,7 @@ DValue* DtoBinAdd(DValue* lhs, DValue* rhs) { - llvm::Value* v = gIR->ir->CreateAdd(lhs->getRVal(), rhs->getRVal(), "tmp"); + LLValue* v = gIR->ir->CreateAdd(lhs->getRVal(), rhs->getRVal(), "tmp"); return new DImValue( lhs->getType(), v ); } @@ -18,7 +18,7 @@ DValue* DtoBinSub(DValue* lhs, DValue* rhs) { - llvm::Value* v = gIR->ir->CreateSub(lhs->getRVal(), rhs->getRVal(), "tmp"); + LLValue* v = gIR->ir->CreateSub(lhs->getRVal(), rhs->getRVal(), "tmp"); return new DImValue( lhs->getType(), v ); } @@ -26,7 +26,7 @@ DValue* DtoBinMul(DValue* lhs, DValue* rhs) { - llvm::Value* v = gIR->ir->CreateMul(lhs->getRVal(), rhs->getRVal(), "tmp"); + LLValue* v = gIR->ir->CreateMul(lhs->getRVal(), rhs->getRVal(), "tmp"); return new DImValue( lhs->getType(), v ); } @@ -38,7 +38,7 @@ llvm::Value *l, *r; l = lhs->getRVal(); r = rhs->getRVal(); - llvm::Value* res; + LLValue* res; if (t->isfloating()) res = gIR->ir->CreateFDiv(l, r, "tmp"); else if (!t->isunsigned()) @@ -56,7 +56,7 @@ llvm::Value *l, *r; l = lhs->getRVal(); r = rhs->getRVal(); - llvm::Value* res; + LLValue* res; if (t->isfloating()) res = gIR->ir->CreateFRem(l, r, "tmp"); else if (!t->isunsigned()) diff -r 4c2689d57ba4 -r 7816aafeea3c gen/classes.cpp --- a/gen/classes.cpp Tue May 27 22:14:24 2008 +0200 +++ b/gen/classes.cpp Fri May 30 19:32:04 2008 +0200 @@ -129,11 +129,11 @@ gIR->classes.push_back(cd); // vector holding the field types - std::vector fieldtypes; + std::vector fieldtypes; // add vtable ts->ir.vtblType = new llvm::PATypeHolder(llvm::OpaqueType::get()); - const llvm::Type* vtabty = getPtrToType(ts->ir.vtblType->get()); + const LLType* vtabty = getPtrToType(ts->ir.vtblType->get()); fieldtypes.push_back(vtabty); // add monitor @@ -162,7 +162,7 @@ Logger::println("has fields"); unsigned prevsize = (unsigned)-1; unsigned lastoffset = (unsigned)-1; - const llvm::Type* fieldtype = NULL; + const LLType* fieldtype = NULL; VarDeclaration* fieldinit = NULL; size_t fieldpad = 0; int idx = 0; @@ -241,7 +241,7 @@ // set vtbl type TypeClass* itc = (TypeClass*)id->type; - const llvm::Type* ivtblTy = getPtrToType(itc->ir.vtblType->get()); + const LLType* ivtblTy = getPtrToType(itc->ir.vtblType->get()); fieldtypes.push_back(ivtblTy); // fix the interface vtable type @@ -287,7 +287,7 @@ = llvm::ArrayType::get(getVoidPtrType(), cd->vtbl.dim); #else - std::vector sinits_ty; + std::vector sinits_ty; for (int k=0; k < cd->vtbl.dim; k++) { @@ -299,14 +299,14 @@ DtoResolveFunction(fd); //assert(fd->type->ty == Tfunction); //TypeFunction* tf = (TypeFunction*)fd->type; - //const llvm::Type* fpty = getPtrToType(tf->ir.type->get()); + //const LLType* fpty = getPtrToType(tf->ir.type->get()); const llvm::FunctionType* vfty = DtoBaseFunctionType(fd); - const llvm::Type* vfpty = getPtrToType(vfty); + const LLType* vfpty = getPtrToType(vfty); sinits_ty.push_back(vfpty); } else if (ClassDeclaration* cd2 = dsym->isClassDeclaration()) { Logger::println("*** ClassDeclaration in vtable: %s", cd2->toChars()); - const llvm::Type* cinfoty; + const LLType* cinfoty; if (cd->isInterfaceDeclaration()) { cinfoty = infoTy; } @@ -317,7 +317,7 @@ // this is the ClassInfo class, the type is this type cinfoty = ts->ir.type->get(); } - const llvm::Type* cty = getPtrToType(cinfoty); + const LLType* cty = getPtrToType(cinfoty); sinits_ty.push_back(cty); } else @@ -420,7 +420,7 @@ assert(iri->vtblTy); iri->vtbl = new llvm::GlobalVariable(iri->vtblTy, true, _linkage, 0, nam, gIR->module); - llvm::Constant* idxs[2] = {DtoConstUint(0), DtoConstUint(idx)}; + LLConstant* idxs[2] = {DtoConstUint(0), DtoConstUint(idx)}; iri->info = llvm::ConstantExpr::getGetElementPtr(irstruct->interfaceInfos, idxs, 2); idx++; } @@ -477,18 +477,18 @@ for (IrStruct::OffsetMap::iterator i=irstruct->offsets.begin(); i!=irstruct->offsets.end(); ++i) { IrStruct::Offset* so = &i->second; - llvm::Constant* finit = DtoConstFieldInitializer(so->var->type, so->var->init); + LLConstant* finit = DtoConstFieldInitializer(so->var->type, so->var->init); so->init = finit; so->var->ir.irField->constInit = finit; } // fill out fieldtypes/inits - std::vector fieldinits; + std::vector fieldinits; // first field is always the vtable if (cd->isAbstract() || cd->isInterfaceDeclaration()) { - const llvm::Type* ptrTy = getPtrToType(ts->ir.vtblType->get()); + const LLType* ptrTy = getPtrToType(ts->ir.vtblType->get()); fieldinits.push_back(llvm::Constant::getNullValue(ptrTy)); } else @@ -503,7 +503,7 @@ // go through the field inits and build the default initializer size_t nfi = irstruct->defaultFields.size(); for (size_t i=0; idefaultFields[i]) { c = irstruct->defaultFields[i]->ir.irField->constInit; assert(c); @@ -511,7 +511,7 @@ else { const llvm::ArrayType* arrty = isaArray(structtype->getElementType(i+2)); assert(arrty); - std::vector vals(arrty->getNumElements(), llvm::ConstantInt::get(llvm::Type::Int8Ty, 0, false)); + std::vector vals(arrty->getNumElements(), llvm::ConstantInt::get(llvm::Type::Int8Ty, 0, false)); c = llvm::ConstantArray::get(arrty, vals); } fieldinits.push_back(c); @@ -552,7 +552,7 @@ } #endif - llvm::Constant* _init = llvm::ConstantStruct::get(structtype, fieldinits); + LLConstant* _init = llvm::ConstantStruct::get(structtype, fieldinits); assert(_init); cd->ir.irStruct->constInit = _init; @@ -561,7 +561,7 @@ if (!cd->isInterfaceDeclaration() && !cd->isAbstract()) { // generate vtable initializer - std::vector sinits; + std::vector sinits; for (int k=0; k < cd->vtbl.dim; k++) { @@ -570,12 +570,12 @@ //Logger::cout() << "vtblsym: " << dsym->toChars() << '\n'; #if OPAQUE_VTBLS - const llvm::Type* targetTy = getVoidPtrType(); + const LLType* targetTy = getVoidPtrType(); #else - const llvm::Type* targetTy = vtbltype->getElementType(k); + const LLType* targetTy = vtbltype->getElementType(k); #endif - llvm::Constant* c = NULL; + LLConstant* c = NULL; // virtual method if (FuncDeclaration* fd = dsym->isFuncDeclaration()) { DtoForceDeclareDsymbol(fd); @@ -599,7 +599,7 @@ cd->ir.irStruct->constVtbl = llvm::ConstantArray::get(svtbl_ty, sinits); #else const llvm::StructType* svtbl_ty = isaStruct(ts->ir.vtblType->get()); - llvm::Constant* cvtblInit = llvm::ConstantStruct::get(svtbl_ty, sinits); + LLConstant* cvtblInit = llvm::ConstantStruct::get(svtbl_ty, sinits); cd->ir.irStruct->constVtbl = llvm::cast(cvtblInit); #endif @@ -620,15 +620,15 @@ #endif // generate interface info initializer - std::vector infoInits; + std::vector infoInits; // classinfo assert(id->ir.irStruct->classInfo); - llvm::Constant* c = id->ir.irStruct->classInfo; + LLConstant* c = id->ir.irStruct->classInfo; infoInits.push_back(c); // vtbl - const llvm::Type* byteptrptrty = getPtrToType(getPtrToType(llvm::Type::Int8Ty)); + const LLType* byteptrptrty = getPtrToType(getPtrToType(llvm::Type::Int8Ty)); c = llvm::ConstantExpr::getBitCast(iri->vtbl, byteptrptrty); c = DtoConstSlice(DtoConstSize_t(b->vtbl.dim), c); infoInits.push_back(c); @@ -642,11 +642,11 @@ iri->infoInit = llvm::cast(llvm::ConstantStruct::get(iri->infoTy, infoInits)); // generate vtable initializer - std::vector iinits; + std::vector iinits; // add interface info #if OPAQUE_VTBLS - const llvm::Type* targetTy = getVoidPtrType(); + const LLType* targetTy = getVoidPtrType(); iinits.push_back(llvm::ConstantExpr::getBitCast(iri->info, targetTy)); #else iinits.push_back(iri->info); @@ -661,10 +661,10 @@ assert(fd); DtoForceDeclareDsymbol(fd); assert(fd->ir.irFunc->func); - llvm::Constant* c = llvm::cast(fd->ir.irFunc->func); + LLConstant* c = llvm::cast(fd->ir.irFunc->func); #if !OPAQUE_VTBLS - const llvm::Type* targetTy = iri->vtblTy->getContainedType(k); + const LLType* targetTy = iri->vtblTy->getContainedType(k); #endif // we have to bitcast, as the type created in ResolveClass expects a different this type @@ -675,10 +675,10 @@ #if OPAQUE_VTBLS Logger::cout() << "n: " << iinits.size() << " ivtbl_ty: " << *ivtbl_ty << '\n'; - llvm::Constant* civtblInit = llvm::ConstantArray::get(ivtbl_ty, iinits); + LLConstant* civtblInit = llvm::ConstantArray::get(ivtbl_ty, iinits); iri->vtblInit = llvm::cast(civtblInit); #else - llvm::Constant* civtblInit = llvm::ConstantStruct::get(ivtbl_ty, iinits); + LLConstant* civtblInit = llvm::ConstantStruct::get(ivtbl_ty, iinits); iri->vtblInit = llvm::cast(civtblInit); #endif } @@ -698,15 +698,15 @@ TypeClass* its = (TypeClass*)id->type; // generate interface info initializer - std::vector infoInits; + std::vector infoInits; // classinfo assert(id->ir.irStruct->classInfo); - llvm::Constant* c = id->ir.irStruct->classInfo; + LLConstant* c = id->ir.irStruct->classInfo; infoInits.push_back(c); // vtbl - const llvm::Type* byteptrptrty = getPtrToType(getPtrToType(llvm::Type::Int8Ty)); + const LLType* byteptrptrty = getPtrToType(getPtrToType(llvm::Type::Int8Ty)); c = DtoConstSlice(DtoConstSize_t(0), getNullPtr(byteptrptrty)); infoInits.push_back(c); @@ -758,7 +758,7 @@ // always do interface info array when possible IrStruct* irstruct = cd->ir.irStruct; - std::vector infoInits; + std::vector infoInits; for (IrStruct::InterfaceVectorIter i=irstruct->interfaceVec.begin(); i!=irstruct->interfaceVec.end(); ++i) { IrInterface* iri = *i; @@ -767,7 +767,7 @@ // set initializer if (!infoInits.empty()) { - llvm::Constant* arrInit = llvm::ConstantArray::get(irstruct->interfaceInfosTy, infoInits); + LLConstant* arrInit = llvm::ConstantArray::get(irstruct->interfaceInfosTy, infoInits); irstruct->interfaceInfos->setInitializer(arrInit); } else @@ -788,7 +788,7 @@ DtoForceDeclareDsymbol(tc->sym); // allocate - llvm::Value* mem; + LLValue* mem; if (newexp->onstack) { mem = new llvm::AllocaInst(DtoType(tc)->getContainedType(0), "newclass_alloca", gIR->topallocapoint()); @@ -796,7 +796,7 @@ else { llvm::Function* fn = LLVM_D_GetRuntimeFunction(gIR->module, "_d_newclass"); - std::vector args; + std::vector args; args.push_back(tc->sym->ir.irStruct->classInfo); mem = gIR->ir->CreateCall(fn, args.begin(), args.end(), "newclass_gc_alloc"); mem = DtoBitCast(mem, DtoType(tc), "newclass_gc"); @@ -812,8 +812,8 @@ LOG_SCOPE; DValue* thisval = newexp->thisexp->toElem(gIR); size_t idx = 2 + tc->sym->vthis->ir.irField->index; - llvm::Value* src = thisval->getRVal(); - llvm::Value* dst = DtoGEPi(mem,0,idx,"tmp"); + LLValue* src = thisval->getRVal(); + LLValue* dst = DtoGEPi(mem,0,idx,"tmp"); Logger::cout() << "dst: " << *dst << "\nsrc: " << *src << '\n'; DtoStore(src, dst); } @@ -824,11 +824,11 @@ LOG_SCOPE; size_t idx = 2; //idx += tc->sym->ir.irStruct->interfaces.size(); - llvm::Value* nest = gIR->func()->decl->ir.irFunc->nestedVar; + LLValue* nest = gIR->func()->decl->ir.irFunc->nestedVar; if (!nest) nest = gIR->func()->decl->ir.irFunc->thisVar; assert(nest); - llvm::Value* gep = DtoGEPi(mem,0,idx,"tmp"); + LLValue* gep = DtoGEPi(mem,0,idx,"tmp"); nest = DtoBitCast(nest, gep->getType()->getContainedType(0)); DtoStore(nest, gep); } @@ -846,7 +846,7 @@ ////////////////////////////////////////////////////////////////////////////////////////// -void DtoInitClass(TypeClass* tc, llvm::Value* dst) +void DtoInitClass(TypeClass* tc, LLValue* dst) { size_t presz = 2*getABITypeSize(DtoSize_t()); uint64_t n = getABITypeSize(tc->ir.type->get()) - presz; @@ -856,7 +856,7 @@ DtoStore(tc->sym->ir.irStruct->vtbl, DtoGEPi(dst,0,0,"vtbl")); // monitor always defaults to zero - llvm::Value* tmp = DtoGEPi(dst,0,1,"monitor"); + LLValue* tmp = DtoGEPi(dst,0,1,"monitor"); DtoStore(llvm::Constant::getNullValue(tmp->getType()->getContainedType(0)), tmp); // done? @@ -867,16 +867,16 @@ assert(tc->sym->ir.irStruct->init); assert(dst->getType() == tc->sym->ir.irStruct->init->getType()); - const llvm::Type* arrty = getPtrToType(llvm::Type::Int8Ty); + const LLType* arrty = getPtrToType(llvm::Type::Int8Ty); - llvm::Value* dstarr = DtoGEPi(dst,0,2,"tmp"); + LLValue* dstarr = DtoGEPi(dst,0,2,"tmp"); dstarr = DtoBitCast(dstarr, arrty); - llvm::Value* srcarr = DtoGEPi(tc->sym->ir.irStruct->init,0,2,"tmp"); + LLValue* srcarr = DtoGEPi(tc->sym->ir.irStruct->init,0,2,"tmp"); srcarr = DtoBitCast(srcarr, arrty); llvm::Function* fn = LLVM_DeclareMemCpy32(); - std::vector llargs; + std::vector llargs; llargs.resize(4); llargs[0] = dstarr; llargs[1] = srcarr; @@ -888,7 +888,7 @@ ////////////////////////////////////////////////////////////////////////////////////////// -DValue* DtoCallClassCtor(TypeClass* type, CtorDeclaration* ctor, Array* arguments, llvm::Value* mem) +DValue* DtoCallClassCtor(TypeClass* type, CtorDeclaration* ctor, Array* arguments, LLValue* mem) { Logger::println("Calling constructor"); LOG_SCOPE; @@ -898,15 +898,15 @@ llvm::Function* fn = ctor->ir.irFunc->func; TypeFunction* tf = (TypeFunction*)DtoDType(ctor->type); - std::vector ctorargs; + std::vector ctorargs; ctorargs.push_back(mem); for (size_t i=0; idim; ++i) { Expression* ex = (Expression*)arguments->data[i]; Argument* fnarg = Argument::getNth(tf->parameters, i); DValue* argval = DtoArgument(fnarg, ex); - llvm::Value* a = argval->getRVal(); - const llvm::Type* aty = fn->getFunctionType()->getParamType(i+1); + LLValue* a = argval->getRVal(); + const LLType* aty = fn->getFunctionType()->getParamType(i+1); if (a->getType() != aty) a = DtoBitCast(a, aty); ctorargs.push_back(a); @@ -919,12 +919,12 @@ ////////////////////////////////////////////////////////////////////////////////////////// -void DtoFinalizeClass(llvm::Value* inst) +void DtoFinalizeClass(LLValue* inst) { // get runtime function llvm::Function* fn = LLVM_D_GetRuntimeFunction(gIR->module, "_d_callfinalizer"); // build args - llvm::SmallVector arg; + LLSmallVector arg; arg.push_back(DtoBitCast(inst, fn->getFunctionType()->getParamType(0), ".tmp")); // call llvm::CallInst::Create(fn, arg.begin(), arg.end(), "", gIR->scopebb()); @@ -939,8 +939,8 @@ Type* to = DtoDType(_to); if (to->ty == Tpointer) { - const llvm::Type* tolltype = DtoType(_to); - llvm::Value* rval = DtoBitCast(val->getRVal(), tolltype); + const LLType* tolltype = DtoType(_to); + LLValue* rval = DtoBitCast(val->getRVal(), tolltype); return new DImValue(_to, rval); } @@ -970,8 +970,8 @@ } else if (!tc->sym->isInterfaceDeclaration() && tc->sym->isBaseOf(fc->sym,NULL)) { Logger::println("static down cast)"); - const llvm::Type* tolltype = DtoType(_to); - llvm::Value* rval = DtoBitCast(val->getRVal(), tolltype); + const LLType* tolltype = DtoType(_to); + LLValue* rval = DtoBitCast(val->getRVal(), tolltype); return new DImValue(_to, rval); } else { @@ -994,10 +994,10 @@ llvm::Function* func = LLVM_D_GetRuntimeFunction(gIR->module, "_d_dynamic_cast"); const llvm::FunctionType* funcTy = func->getFunctionType(); - std::vector args; + std::vector args; // Object o - llvm::Value* tmp = val->getRVal(); + LLValue* tmp = val->getRVal(); tmp = DtoBitCast(tmp, funcTy->getParamType(0)); args.push_back(tmp); assert(funcTy->getParamType(0) == tmp->getType()); @@ -1014,7 +1014,7 @@ assert(funcTy->getParamType(1) == tmp->getType()); // call it - llvm::Value* ret = gIR->ir->CreateCall(func, args.begin(), args.end(), "tmp"); + LLValue* ret = gIR->ir->CreateCall(func, args.begin(), args.end(), "tmp"); // cast return value ret = DtoBitCast(ret, DtoType(_to)); @@ -1033,11 +1033,11 @@ const llvm::FunctionType* funcTy = func->getFunctionType(); // void* p - llvm::Value* tmp = val->getRVal(); + LLValue* tmp = val->getRVal(); tmp = DtoBitCast(tmp, funcTy->getParamType(0)); // call it - llvm::Value* ret = gIR->ir->CreateCall(func, tmp, "tmp"); + LLValue* ret = gIR->ir->CreateCall(func, tmp, "tmp"); // cast return value if (to != NULL) @@ -1061,10 +1061,10 @@ llvm::Function* func = LLVM_D_GetRuntimeFunction(gIR->module, "_d_interface_cast"); const llvm::FunctionType* funcTy = func->getFunctionType(); - std::vector args; + std::vector args; // void* p - llvm::Value* tmp = val->getRVal(); + LLValue* tmp = val->getRVal(); tmp = DtoBitCast(tmp, funcTy->getParamType(0)); args.push_back(tmp); @@ -1079,7 +1079,7 @@ args.push_back(tmp); // call it - llvm::Value* ret = gIR->ir->CreateCall(func, args.begin(), args.end(), "tmp"); + LLValue* ret = gIR->ir->CreateCall(func, args.begin(), args.end(), "tmp"); // cast return value ret = DtoBitCast(ret, DtoType(_to)); @@ -1127,7 +1127,7 @@ ////////////////////////////////////////////////////////////////////////////////////////// -llvm::Value* DtoIndexClass(llvm::Value* ptr, ClassDeclaration* cd, Type* t, unsigned os, std::vector& idxs) +LLValue* DtoIndexClass(LLValue* ptr, ClassDeclaration* cd, Type* t, unsigned os, std::vector& idxs) { Logger::println("checking for offset %u type %s:", os, t->toChars()); LOG_SCOPE; @@ -1135,13 +1135,13 @@ if (idxs.empty()) idxs.push_back(0); - const llvm::Type* st = DtoType(cd->type); + const LLType* st = DtoType(cd->type); if (ptr->getType() != st) { //assert(cd->ir.irStruct->hasUnions); ptr = gIR->ir->CreateBitCast(ptr, st, "tmp"); } - const llvm::Type* llt = getPtrToType(DtoType(t)); + const LLType* llt = getPtrToType(DtoType(t)); unsigned dataoffset = 2; IrStruct* irstruct = cd->ir.irStruct; @@ -1180,7 +1180,7 @@ return DtoIndexStruct(ptr, ssd, t, os-vd->offset, tmp); } else { - const llvm::Type* sty = getPtrToType(DtoType(vd->type)); + const LLType* sty = getPtrToType(DtoType(vd->type)); if (ptr->getType() != sty) { ptr = gIR->ir->CreateBitCast(ptr, sty, "tmp"); std::vector tmp; @@ -1203,16 +1203,16 @@ ////////////////////////////////////////////////////////////////////////////////////////// -llvm::Value* DtoVirtualFunctionPointer(DValue* inst, FuncDeclaration* fdecl) +LLValue* DtoVirtualFunctionPointer(DValue* inst, FuncDeclaration* fdecl) { assert(fdecl->isVirtual());//fdecl->isAbstract() || (!fdecl->isFinal() && fdecl->isVirtual())); assert(fdecl->vtblIndex > 0); assert(DtoDType(inst->getType())->ty == Tclass); - llvm::Value* vthis = inst->getRVal(); + LLValue* vthis = inst->getRVal(); Logger::cout() << "vthis: " << *vthis << '\n'; - llvm::Value* funcval; + LLValue* funcval; funcval = DtoGEPi(vthis, 0, 0, "tmp"); funcval = DtoLoad(funcval); funcval = DtoGEPi(funcval, 0, fdecl->vtblIndex, fdecl->toPrettyChars()); @@ -1251,15 +1251,15 @@ else gname.append("11__InterfaceZ"); - const llvm::Type* st = cinfo->type->ir.type->get(); + const LLType* st = cinfo->type->ir.type->get(); cd->ir.irStruct->classInfo = new llvm::GlobalVariable(st, true, DtoLinkage(cd), NULL, gname, gIR->module); } -static llvm::Constant* build_offti_entry(VarDeclaration* vd) +static LLConstant* build_offti_entry(VarDeclaration* vd) { - std::vector types; - std::vector inits; + std::vector types; + std::vector inits; types.push_back(DtoSize_t()); @@ -1274,9 +1274,9 @@ vd->type->getTypeInfo(NULL); assert(vd->type->vtinfo); DtoForceDeclareDsymbol(vd->type->vtinfo); - llvm::Constant* c = isaConstant(vd->type->vtinfo->ir.getIrValue()); + LLConstant* c = isaConstant(vd->type->vtinfo->ir.getIrValue()); - const llvm::Type* tiTy = getPtrToType(Type::typeinfo->type->ir.type->get()); + const LLType* tiTy = getPtrToType(Type::typeinfo->type->ir.type->get()); //Logger::cout() << "tiTy = " << *tiTy << '\n'; types.push_back(tiTy); @@ -1286,12 +1286,12 @@ return llvm::ConstantStruct::get(sTy, inits); } -static llvm::Constant* build_offti_array(ClassDeclaration* cd, llvm::Constant* init) +static LLConstant* build_offti_array(ClassDeclaration* cd, LLConstant* init) { const llvm::StructType* initTy = isaStruct(init->getType()); assert(initTy); - std::vector arrayInits; + std::vector arrayInits; for (ClassDeclaration *cd2 = cd; cd2; cd2 = cd2->baseClass) { if (cd2->members) @@ -1301,7 +1301,7 @@ Dsymbol *sm = (Dsymbol *)cd2->members->data[i]; if (VarDeclaration* vd = sm->isVarDeclaration()) // is this enough? { - llvm::Constant* c = build_offti_entry(vd); + LLConstant* c = build_offti_entry(vd); assert(c); arrayInits.push_back(c); } @@ -1310,20 +1310,20 @@ } size_t ninits = arrayInits.size(); - llvm::Constant* size = DtoConstSize_t(ninits); - llvm::Constant* ptr; + LLConstant* size = DtoConstSize_t(ninits); + LLConstant* ptr; if (ninits > 0) { // OffsetTypeInfo type - std::vector elemtypes; + std::vector elemtypes; elemtypes.push_back(DtoSize_t()); - const llvm::Type* tiTy = getPtrToType(Type::typeinfo->type->ir.type->get()); + const LLType* tiTy = getPtrToType(Type::typeinfo->type->ir.type->get()); elemtypes.push_back(tiTy); const llvm::StructType* sTy = llvm::StructType::get(elemtypes); // array type const llvm::ArrayType* arrTy = llvm::ArrayType::get(sTy, ninits); - llvm::Constant* arrInit = llvm::ConstantArray::get(arrTy, arrayInits); + LLConstant* arrInit = llvm::ConstantArray::get(arrTy, arrayInits); std::string name(cd->type->vtinfo->toChars()); name.append("__OffsetTypeInfos"); @@ -1338,10 +1338,10 @@ return DtoConstSlice(size, ptr); } -static llvm::Constant* build_class_dtor(ClassDeclaration* cd) +static LLConstant* build_class_dtor(ClassDeclaration* cd) { // construct the function - std::vector paramTypes; + std::vector paramTypes; paramTypes.push_back(getPtrToType(cd->type->ir.type->get())); const llvm::FunctionType* fnTy = llvm::FunctionType::get(llvm::Type::VoidTy, paramTypes, false); @@ -1361,7 +1361,7 @@ gname.append("12__destructorMFZv"); llvm::Function* func = llvm::Function::Create(fnTy, DtoInternalLinkage(cd), gname, gIR->module); - llvm::Value* thisptr = func->arg_begin(); + LLValue* thisptr = func->arg_begin(); thisptr->setName("this"); llvm::BasicBlock* bb = llvm::BasicBlock::Create("entry", func); @@ -1445,13 +1445,13 @@ } // holds the list of initializers for llvm - std::vector inits; + std::vector inits; ClassDeclaration* cinfo = ClassDeclaration::classinfo; DtoForceConstInitDsymbol(cinfo); assert(cinfo->ir.irStruct->constInit); - llvm::Constant* c; + LLConstant* c; // own vtable c = cinfo->ir.irStruct->constInit->getOperand(0); @@ -1463,7 +1463,7 @@ inits.push_back(c); // byte[] init - const llvm::Type* byteptrty = getPtrToType(llvm::Type::Int8Ty); + const LLType* byteptrty = getPtrToType(llvm::Type::Int8Ty); if (cd->isInterfaceDeclaration() || cd->isAbstract()) { c = cinfo->ir.irStruct->constInit->getOperand(2); } @@ -1492,7 +1492,7 @@ c = cinfo->ir.irStruct->constInit->getOperand(4); } else { - const llvm::Type* byteptrptrty = getPtrToType(byteptrty); + const LLType* byteptrptrty = getPtrToType(byteptrty); assert(!cd->ir.irStruct->vtbl->getType()->isAbstract()); c = llvm::ConstantExpr::getBitCast(cd->ir.irStruct->vtbl, byteptrptrty); assert(!cd->ir.irStruct->constVtbl->getType()->isAbstract()); @@ -1511,7 +1511,7 @@ c = cinfo->ir.irStruct->constInit->getOperand(5); } else { - const llvm::Type* t = cinfo->ir.irStruct->constInit->getOperand(5)->getType()->getContainedType(1); + const LLType* t = cinfo->ir.irStruct->constInit->getOperand(5)->getType()->getContainedType(1); c = llvm::ConstantExpr::getBitCast(irstruct->interfaceInfos, t); size_t iisz = irstruct->interfaceInfosTy->getNumElements(); c = DtoConstSlice(DtoConstSize_t(iisz), c); @@ -1573,7 +1573,7 @@ if (cd->defaultCtor && !cd->isInterfaceDeclaration() && !cd->isAbstract()) { DtoForceDeclareDsymbol(cd->defaultCtor); c = isaConstant(cd->defaultCtor->ir.irFunc->func); - const llvm::Type* toTy = cinfo->ir.irStruct->constInit->getOperand(12)->getType(); + const LLType* toTy = cinfo->ir.irStruct->constInit->getOperand(12)->getType(); c = llvm::ConstantExpr::getBitCast(c, toTy); } else { @@ -1589,7 +1589,7 @@ // build the initializer const llvm::StructType* st = isaStruct(cinfo->ir.irStruct->constInit->getType()); - llvm::Constant* finalinit = llvm::ConstantStruct::get(st, inits); + LLConstant* finalinit = llvm::ConstantStruct::get(st, inits); //Logger::cout() << "built the classinfo initializer:\n" << *finalinit <<'\n'; cd->ir.irStruct->constClassInfo = finalinit; diff -r 4c2689d57ba4 -r 7816aafeea3c gen/classes.h --- a/gen/classes.h Tue May 27 22:14:24 2008 +0200 +++ b/gen/classes.h Fri May 30 19:32:04 2008 +0200 @@ -25,9 +25,9 @@ void DtoDefineClassInfo(ClassDeclaration* cd); DValue* DtoNewClass(TypeClass* type, NewExp* newexp); -void DtoInitClass(TypeClass* tc, llvm::Value* dst); -DValue* DtoCallClassCtor(TypeClass* type, CtorDeclaration* ctor, Array* arguments, llvm::Value* mem); -void DtoFinalizeClass(llvm::Value* inst); +void DtoInitClass(TypeClass* tc, LLValue* dst); +DValue* DtoCallClassCtor(TypeClass* type, CtorDeclaration* ctor, Array* arguments, LLValue* mem); +void DtoFinalizeClass(LLValue* inst); DValue* DtoCastClass(DValue* val, Type* to); DValue* DtoDynamicCastObject(DValue* val, Type* to); @@ -35,8 +35,8 @@ DValue* DtoCastInterfaceToObject(DValue* val, Type* to); DValue* DtoDynamicCastInterface(DValue* val, Type* to); -llvm::Value* DtoIndexClass(llvm::Value* ptr, ClassDeclaration* cd, Type* t, unsigned os, std::vector& idxs); +LLValue* DtoIndexClass(LLValue* ptr, ClassDeclaration* cd, Type* t, unsigned os, std::vector& idxs); -llvm::Value* DtoVirtualFunctionPointer(DValue* inst, FuncDeclaration* fdecl); +LLValue* DtoVirtualFunctionPointer(DValue* inst, FuncDeclaration* fdecl); #endif diff -r 4c2689d57ba4 -r 7816aafeea3c gen/complex.cpp --- a/gen/complex.cpp Tue May 27 22:14:24 2008 +0200 +++ b/gen/complex.cpp Fri May 30 19:32:04 2008 +0200 @@ -14,19 +14,19 @@ { Type* t = DtoDType(type); - const llvm::Type* base = DtoComplexBaseType(t); + const LLType* base = DtoComplexBaseType(t); - std::vector types; + std::vector types; types.push_back(base); types.push_back(base); return llvm::StructType::get(types); } -const llvm::Type* DtoComplexBaseType(Type* t) +const LLType* DtoComplexBaseType(Type* t) { TY ty = DtoDType(t)->ty; - const llvm::Type* base; + const LLType* base; if (ty == Tcomplex32) { return llvm::Type::FloatTy; } @@ -40,12 +40,12 @@ ////////////////////////////////////////////////////////////////////////////////////////// -llvm::Constant* DtoConstComplex(Type* ty, llvm::Constant* re, llvm::Constant* im) +LLConstant* DtoConstComplex(Type* ty, LLConstant* re, LLConstant* im) { assert(0); - const llvm::Type* base = DtoComplexBaseType(ty); + const LLType* base = DtoComplexBaseType(ty); - std::vector inits; + std::vector inits; inits.push_back(re); inits.push_back(im); @@ -53,14 +53,14 @@ return llvm::ConstantVector::get(vt, inits); } -llvm::Constant* DtoConstComplex(Type* _ty, long double re, long double im) +LLConstant* DtoConstComplex(Type* _ty, long double re, long double im) { TY ty = DtoDType(_ty)->ty; llvm::ConstantFP* fre; llvm::ConstantFP* fim; - const llvm::Type* base; + const LLType* base; if (ty == Tcomplex32) { fre = DtoConstFP(Type::tfloat32, re); @@ -75,17 +75,17 @@ else assert(0); - std::vector inits; + std::vector inits; inits.push_back(fre); inits.push_back(fim); return llvm::ConstantStruct::get(DtoComplexType(_ty), inits); } -llvm::Constant* DtoUndefComplex(Type* _ty) +LLConstant* DtoUndefComplex(Type* _ty) { assert(0); TY ty = DtoDType(_ty)->ty; - const llvm::Type* base; + const LLType* base; if (ty == Tcomplex32) { base = llvm::Type::FloatTy; } @@ -95,7 +95,7 @@ else assert(0); - std::vector inits; + std::vector inits; inits.push_back(llvm::UndefValue::get(base)); inits.push_back(llvm::UndefValue::get(base)); @@ -105,7 +105,7 @@ ////////////////////////////////////////////////////////////////////////////////////////// -llvm::Value* DtoRealPart(DValue* val) +LLValue* DtoRealPart(DValue* val) { assert(0); return gIR->ir->CreateExtractElement(val->getRVal(), DtoConstUint(0), "tmp"); @@ -113,7 +113,7 @@ ////////////////////////////////////////////////////////////////////////////////////////// -llvm::Value* DtoImagPart(DValue* val) +LLValue* DtoImagPart(DValue* val) { assert(0); return gIR->ir->CreateExtractElement(val->getRVal(), DtoConstUint(1), "tmp"); @@ -130,10 +130,10 @@ return DtoCastComplex(val, to); } - const llvm::Type* base = DtoComplexBaseType(to); + const LLType* base = DtoComplexBaseType(to); - llvm::Constant* undef = llvm::UndefValue::get(base); - llvm::Constant* zero; + LLConstant* undef = llvm::UndefValue::get(base); + LLConstant* zero; if (ty == Tfloat32 || ty == Timaginary32 || ty == Tcomplex32) zero = llvm::ConstantFP::get(llvm::APFloat(0.0f)); else if (ty == Tfloat64 || ty == Timaginary64 || ty == Tcomplex64 || ty == Tfloat80 || ty == Timaginary80 || ty == Tcomplex80) @@ -151,13 +151,13 @@ ////////////////////////////////////////////////////////////////////////////////////////// -void DtoComplexAssign(llvm::Value* l, llvm::Value* r) +void DtoComplexAssign(LLValue* l, LLValue* r) { DtoStore(DtoLoad(DtoGEPi(r, 0,0, "tmp")), DtoGEPi(l,0,0,"tmp")); DtoStore(DtoLoad(DtoGEPi(r, 0,1, "tmp")), DtoGEPi(l,0,1,"tmp")); } -void DtoComplexSet(llvm::Value* c, llvm::Value* re, llvm::Value* im) +void DtoComplexSet(LLValue* c, LLValue* re, LLValue* im) { DtoStore(re, DtoGEPi(c,0,0,"tmp")); DtoStore(im, DtoGEPi(c,0,1,"tmp")); @@ -165,7 +165,7 @@ ////////////////////////////////////////////////////////////////////////////////////////// -void DtoGetComplexParts(DValue* c, llvm::Value*& re, llvm::Value*& im) +void DtoGetComplexParts(DValue* c, LLValue*& re, LLValue*& im) { // lhs values if (DComplexValue* cx = c->isComplex()) { @@ -300,7 +300,7 @@ ////////////////////////////////////////////////////////////////////////////////////////// -llvm::Value* DtoComplexEquals(TOK op, DValue* lhs, DValue* rhs) +LLValue* DtoComplexEquals(TOK op, DValue* lhs, DValue* rhs) { Type* type = lhs->getType(); @@ -322,7 +322,7 @@ cmpop = llvm::FCmpInst::FCMP_UNE; // (l.re==r.re && l.im==r.im) - llvm::Value* b1 = new llvm::FCmpInst(cmpop, a, c, "tmp", gIR->scopebb()); - llvm::Value* b2 = new llvm::FCmpInst(cmpop, b, d, "tmp", gIR->scopebb()); + LLValue* b1 = new llvm::FCmpInst(cmpop, a, c, "tmp", gIR->scopebb()); + LLValue* b2 = new llvm::FCmpInst(cmpop, b, d, "tmp", gIR->scopebb()); return gIR->ir->CreateAnd(b1,b2,"tmp"); } diff -r 4c2689d57ba4 -r 7816aafeea3c gen/complex.h --- a/gen/complex.h Tue May 27 22:14:24 2008 +0200 +++ b/gen/complex.h Fri May 30 19:32:04 2008 +0200 @@ -4,20 +4,20 @@ const llvm::StructType* DtoComplexType(Type* t); const llvm::Type* DtoComplexBaseType(Type* t); -llvm::Constant* DtoConstComplex(Type* t, llvm::Constant* re, llvm::Constant* im); -llvm::Constant* DtoConstComplex(Type* t, long double re, long double im); -llvm::Constant* DtoUndefComplex(Type* _ty); +LLConstant* DtoConstComplex(Type* t, LLConstant* re, LLConstant* im); +LLConstant* DtoConstComplex(Type* t, long double re, long double im); +LLConstant* DtoUndefComplex(Type* _ty); -llvm::Constant* DtoComplexShuffleMask(unsigned a, unsigned b); +LLConstant* DtoComplexShuffleMask(unsigned a, unsigned b); -llvm::Value* DtoRealPart(DValue* val); -llvm::Value* DtoImagPart(DValue* val); +LLValue* DtoRealPart(DValue* val); +LLValue* DtoImagPart(DValue* val); DValue* DtoComplex(Type* to, DValue* val); -void DtoComplexAssign(llvm::Value* l, llvm::Value* r); -void DtoComplexSet(llvm::Value* c, llvm::Value* re, llvm::Value* im); +void DtoComplexAssign(LLValue* l, LLValue* r); +void DtoComplexSet(LLValue* c, LLValue* re, LLValue* im); -void DtoGetComplexParts(DValue* c, llvm::Value*& re, llvm::Value*& im); +void DtoGetComplexParts(DValue* c, LLValue*& re, LLValue*& im); DValue* DtoComplexAdd(Type* type, DValue* lhs, DValue* rhs); DValue* DtoComplexSub(Type* type, DValue* lhs, DValue* rhs); @@ -25,6 +25,6 @@ DValue* DtoComplexDiv(Type* type, DValue* lhs, DValue* rhs); DValue* DtoComplexNeg(Type* type, DValue* val); -llvm::Value* DtoComplexEquals(TOK op, DValue* lhs, DValue* rhs); +LLValue* DtoComplexEquals(TOK op, DValue* lhs, DValue* rhs); #endif // LLVMDC_GEN_COMPLEX_H diff -r 4c2689d57ba4 -r 7816aafeea3c gen/dvalue.cpp --- a/gen/dvalue.cpp Tue May 27 22:14:24 2008 +0200 +++ b/gen/dvalue.cpp Fri May 30 19:32:04 2008 +0200 @@ -10,7 +10,7 @@ ///////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////// -DVarValue::DVarValue(VarDeclaration* vd, llvm::Value* llvmValue, bool lvalue) +DVarValue::DVarValue(VarDeclaration* vd, LLValue* llvmValue, bool lvalue) { var = vd; val = llvmValue; @@ -19,7 +19,7 @@ type = var->type; } -DVarValue::DVarValue(Type* t, llvm::Value* lv, llvm::Value* rv) +DVarValue::DVarValue(Type* t, LLValue* lv, LLValue* rv) { var = 0; val = lv; @@ -28,7 +28,7 @@ type = t; } -DVarValue::DVarValue(Type* t, llvm::Value* llvmValue, bool lvalue) +DVarValue::DVarValue(Type* t, LLValue* llvmValue, bool lvalue) { var = 0; val = llvmValue; @@ -37,13 +37,13 @@ type = t; } -llvm::Value* DVarValue::getLVal() +LLValue* DVarValue::getLVal() { assert(val && lval); return val; } -llvm::Value* DVarValue::getRVal() +LLValue* DVarValue::getRVal() { assert(rval || val); if (DtoIsPassedByRef(type)) { @@ -63,7 +63,7 @@ ///////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////// -DFuncValue::DFuncValue(FuncDeclaration* fd, llvm::Value* v, llvm::Value* vt) +DFuncValue::DFuncValue(FuncDeclaration* fd, LLValue* v, LLValue* vt) { func = fd; type = func->type; @@ -72,13 +72,13 @@ cc = (unsigned)-1; } -llvm::Value* DFuncValue::getLVal() +LLValue* DFuncValue::getLVal() { assert(0); return 0; } -llvm::Value* DFuncValue::getRVal() +LLValue* DFuncValue::getRVal() { assert(val); return val; @@ -87,7 +87,7 @@ ///////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////// -llvm::Value* DConstValue::getRVal() +LLValue* DConstValue::getRVal() { assert(c); return c; diff -r 4c2689d57ba4 -r 7816aafeea3c gen/dvalue.h --- a/gen/dvalue.h Tue May 27 22:14:24 2008 +0200 +++ b/gen/dvalue.h Fri May 30 19:32:04 2008 +0200 @@ -39,8 +39,8 @@ { virtual Type* getType() = 0; - virtual llvm::Value* getLVal() { assert(0); return 0; } - virtual llvm::Value* getRVal() { assert(0); return 0; } + virtual LLValue* getLVal() { assert(0); return 0; } + virtual LLValue* getRVal() { assert(0); return 0; } virtual DImValue* isIm() { return NULL; } virtual DConstValue* isConst() { return NULL; } @@ -66,12 +66,12 @@ struct DImValue : DValue { Type* type; - llvm::Value* val; + LLValue* val; bool inplace; - DImValue(Type* t, llvm::Value* v, bool in_place = false) { type = t; val = v; inplace = in_place; } + DImValue(Type* t, LLValue* v, bool in_place = false) { type = t; val = v; inplace = in_place; } - virtual llvm::Value* getRVal() { assert(val); return val; } + virtual LLValue* getRVal() { assert(val); return val; } virtual Type* getType() { assert(type); return type; } virtual DImValue* isIm() { return this; } @@ -83,11 +83,11 @@ struct DConstValue : DValue { Type* type; - llvm::Constant* c; + LLConstant* c; - DConstValue(Type* t, llvm::Constant* con) { type = t; c = con; } + DConstValue(Type* t, LLConstant* con) { type = t; c = con; } - virtual llvm::Value* getRVal(); + virtual LLValue* getRVal(); virtual Type* getType() { assert(type); return type; } virtual DConstValue* isConst() { return this; } @@ -96,7 +96,7 @@ // null d-value struct DNullValue : DConstValue { - DNullValue(Type* t, llvm::Constant* con) : DConstValue(t,con) {} + DNullValue(Type* t, LLConstant* con) : DConstValue(t,con) {} virtual DNullValue* isNull() { return this; } }; @@ -105,16 +105,16 @@ { Type* type; VarDeclaration* var; - llvm::Value* val; - llvm::Value* rval; + LLValue* val; + LLValue* rval; bool lval; - DVarValue(VarDeclaration* vd, llvm::Value* llvmValue, bool lvalue); - DVarValue(Type* vd, llvm::Value* lv, llvm::Value* rv); - DVarValue(Type* t, llvm::Value* llvmValue, bool lvalue); + DVarValue(VarDeclaration* vd, LLValue* llvmValue, bool lvalue); + DVarValue(Type* vd, LLValue* lv, LLValue* rv); + DVarValue(Type* t, LLValue* llvmValue, bool lvalue); - virtual llvm::Value* getLVal(); - virtual llvm::Value* getRVal(); + virtual LLValue* getLVal(); + virtual LLValue* getRVal(); virtual Type* getType() { assert(type); return type; } virtual DVarValue* isVar() { return this; } @@ -123,21 +123,21 @@ // field d-value struct DFieldValue : DVarValue { - DFieldValue(Type* t, llvm::Value* llvmValue, bool l) : DVarValue(t, llvmValue, l) {} + DFieldValue(Type* t, LLValue* llvmValue, bool l) : DVarValue(t, llvmValue, l) {} virtual DFieldValue* isField() { return this; } }; // this d-value struct DThisValue : DVarValue { - DThisValue(VarDeclaration* vd, llvm::Value* llvmValue) : DVarValue(vd, llvmValue, true) {} + DThisValue(VarDeclaration* vd, LLValue* llvmValue) : DVarValue(vd, llvmValue, true) {} virtual DThisValue* isThis() { return this; } }; // array length d-value struct DArrayLenValue : DVarValue { - DArrayLenValue(Type* t, llvm::Value* llvmValue) : DVarValue(t, llvmValue, true) {} + DArrayLenValue(Type* t, LLValue* llvmValue) : DVarValue(t, llvmValue, true) {} virtual DArrayLenValue* isArrayLen() { return this; } }; @@ -145,10 +145,10 @@ struct DSliceValue : DValue { Type* type; - llvm::Value* len; - llvm::Value* ptr; + LLValue* len; + LLValue* ptr; - DSliceValue(Type* t, llvm::Value* l, llvm::Value* p) { type=t; ptr=p; len=l; } + DSliceValue(Type* t, LLValue* l, LLValue* p) { type=t; ptr=p; len=l; } virtual Type* getType() { assert(type); return type; } virtual DSliceValue* isSlice() { return this; } @@ -159,14 +159,14 @@ { Type* type; FuncDeclaration* func; - llvm::Value* val; - llvm::Value* vthis; + LLValue* val; + LLValue* vthis; unsigned cc; - DFuncValue(FuncDeclaration* fd, llvm::Value* v, llvm::Value* vt = 0); + DFuncValue(FuncDeclaration* fd, LLValue* v, LLValue* vt = 0); - virtual llvm::Value* getLVal(); - virtual llvm::Value* getRVal(); + virtual LLValue* getLVal(); + virtual LLValue* getRVal(); virtual Type* getType() { assert(type); return type; } virtual DFuncValue* isFunc() { return this; } @@ -176,19 +176,19 @@ struct DLRValue : DValue { Type* ltype; - llvm::Value* lval; + LLValue* lval; Type* rtype; - llvm::Value* rval; + LLValue* rval; - DLRValue(Type* lt, llvm::Value* l, Type* rt, llvm::Value* r) { + DLRValue(Type* lt, LLValue* l, Type* rt, LLValue* r) { ltype = lt; lval = l; rtype = rt; rval = r; } - virtual llvm::Value* getLVal() { assert(lval); return lval; } - virtual llvm::Value* getRVal() { assert(rval); return rval; } + virtual LLValue* getLVal() { assert(lval); return lval; } + virtual LLValue* getRVal() { assert(rval); return rval; } Type* getLType() { return ltype; } Type* getRType() { return rtype; } @@ -200,10 +200,10 @@ struct DComplexValue : DValue { Type* type; - llvm::Value* re; - llvm::Value* im; + LLValue* re; + LLValue* im; - DComplexValue(Type* t, llvm::Value* r, llvm::Value* i) { + DComplexValue(Type* t, LLValue* r, LLValue* i) { type = t; re = r; im = i; diff -r 4c2689d57ba4 -r 7816aafeea3c gen/functions.cpp --- a/gen/functions.cpp Tue May 27 22:14:24 2008 +0200 +++ b/gen/functions.cpp Fri May 30 19:32:04 2008 +0200 @@ -18,7 +18,7 @@ #include "gen/classes.h" #include "gen/dvalue.h" -const llvm::FunctionType* DtoFunctionType(Type* type, const llvm::Type* thistype, bool ismain) +const llvm::FunctionType* DtoFunctionType(Type* type, const LLType* thistype, bool ismain) { TypeFunction* f = (TypeFunction*)type; assert(f != 0); @@ -38,8 +38,8 @@ } // return value type - const llvm::Type* rettype; - const llvm::Type* actualRettype; + const LLType* rettype; + const LLType* actualRettype; Type* rt = f->next; bool retinptr = false; bool usesthis = false; @@ -63,7 +63,7 @@ } // parameter types - std::vector paramvec; + std::vector paramvec; if (retinptr) { //Logger::cout() << "returning through pointer parameter: " << *rettype << '\n'; @@ -80,10 +80,10 @@ ti->toObjFile(); DtoForceConstInitDsymbol(ti); assert(ti->ir.irStruct->constInit); - std::vector types; + std::vector types; types.push_back(DtoSize_t()); types.push_back(getPtrToType(getPtrToType(ti->ir.irStruct->constInit->getType()))); - const llvm::Type* t1 = llvm::StructType::get(types); + const LLType* t1 = llvm::StructType::get(types); paramvec.push_back(getPtrToType(t1)); paramvec.push_back(getPtrToType(llvm::Type::Int8Ty)); } @@ -100,7 +100,7 @@ Type* argT = DtoDType(arg->type); assert(argT); - const llvm::Type* at = DtoType(argT); + const LLType* at = DtoType(argT); if (isaStruct(at)) { Logger::println("struct param"); paramvec.push_back(getPtrToType(at)); @@ -156,7 +156,7 @@ assert(f != 0); const llvm::PointerType* i8pty = getPtrToType(llvm::Type::Int8Ty); - std::vector args; + std::vector args; if (fdecl->llvmInternal == LLVMva_start) { args.push_back(i8pty); @@ -187,7 +187,7 @@ // unittest has null type, just build it manually /*if (fdecl->isUnitTestDeclaration()) { - std::vector args; + std::vector args; return llvm::FunctionType::get(llvm::Type::VoidTy, args, false); }*/ @@ -196,7 +196,7 @@ return llvm::cast(fdecl->type->ir.type->get()); } - const llvm::Type* thisty = NULL; + const LLType* thisty = NULL; if (fdecl->needThis()) { if (AggregateDeclaration* ad = fdecl->isMember2()) { Logger::println("isMember = this is: %s", ad->type->toChars()); @@ -225,7 +225,7 @@ { TypeFunction* f = (TypeFunction*)DtoDType(fdecl->type); const llvm::FunctionType* fty = DtoVaFunctionType(fdecl); - llvm::Constant* fn = 0; + LLConstant* fn = 0; if (fdecl->llvmInternal == LLVMva_start) { fn = gIR->module->getOrInsertFunction("llvm.va_start", fty); @@ -499,7 +499,7 @@ gIR->scopes.push_back(IRScope(beginbb, endbb)); // create alloca point - llvm::Instruction* allocaPoint = new llvm::BitCastInst(llvm::ConstantInt::get(llvm::Type::Int32Ty,0,false),llvm::Type::Int32Ty,"alloca point",gIR->scopebb()); + llvm::Instruction* allocaPoint = new llvm::AllocaInst(llvm::Type::Int32Ty, "alloca point", beginbb); gIR->func()->allocapoint = allocaPoint; // need result variable? (not nested) @@ -522,13 +522,13 @@ if (!vd->needsStorage || vd->nestedref || vd->isRef() || vd->isOut() || DtoIsPassedByRef(vd->type)) continue; - llvm::Value* a = vd->ir.irLocal->value; + LLValue* a = vd->ir.irLocal->value; assert(a); std::string s(a->getName()); Logger::println("giving argument '%s' storage", s.c_str()); s.append("_storage"); - llvm::Value* v = new llvm::AllocaInst(a->getType(),s,allocaPoint); + LLValue* v = new llvm::AllocaInst(a->getType(),s,allocaPoint); gIR->ir->CreateStore(a,v); vd->ir.irLocal->value = v; } @@ -537,7 +537,7 @@ // debug info if (global.params.symdebug) DtoDwarfFuncStart(fd); - llvm::Value* parentNested = NULL; + LLValue* parentNested = NULL; if (FuncDeclaration* fd2 = fd->toParent2()->isFuncDeclaration()) { if (!fd->isStatic()) // huh? parentNested = fd2->ir.irFunc->nestedVar; @@ -551,7 +551,7 @@ // construct nested variables struct if (!fd->nestedVars.empty() || parentNested) { - std::vector nestTypes; + std::vector nestTypes; int j = 0; if (parentNested) { nestTypes.push_back(parentNested->getType()); @@ -580,7 +580,7 @@ fd->ir.irFunc->nestedVar = new llvm::AllocaInst(nestSType,"nestedvars",allocaPoint); if (parentNested) { assert(fd->ir.irFunc->thisVar); - llvm::Value* ptr = gIR->ir->CreateBitCast(fd->ir.irFunc->thisVar, parentNested->getType(), "tmp"); + LLValue* ptr = gIR->ir->CreateBitCast(fd->ir.irFunc->thisVar, parentNested->getType(), "tmp"); gIR->ir->CreateStore(ptr, DtoGEPi(fd->ir.irFunc->nestedVar, 0,0, "tmp")); } for (std::set::iterator i=fd->nestedVars.begin(); i!=fd->nestedVars.end(); ++i) { @@ -596,7 +596,7 @@ // copy _argptr to a memory location if (f->linkage == LINKd && f->varargs == 1) { - llvm::Value* argptrmem = new llvm::AllocaInst(fd->ir.irFunc->_argptr->getType(), "_argptrmem", gIR->topallocapoint()); + LLValue* argptrmem = new llvm::AllocaInst(fd->ir.irFunc->_argptr->getType(), "_argptrmem", gIR->topallocapoint()); new llvm::StoreInst(fd->ir.irFunc->_argptr, argptrmem, gIR->scopebb()); fd->ir.irFunc->_argptr = argptrmem; } @@ -665,12 +665,12 @@ assert(ir.emitMain && ir.mainFunc); // parameter types - std::vector pvec; - pvec.push_back((const llvm::Type*)llvm::Type::Int32Ty); - const llvm::Type* chPtrType = (const llvm::Type*)getPtrToType(llvm::Type::Int8Ty); - pvec.push_back((const llvm::Type*)getPtrToType(chPtrType)); - pvec.push_back((const llvm::Type*)getPtrToType(chPtrType)); - const llvm::Type* rettype = (const llvm::Type*)llvm::Type::Int32Ty; + std::vector pvec; + pvec.push_back((const LLType*)llvm::Type::Int32Ty); + const LLType* chPtrType = (const LLType*)getPtrToType(llvm::Type::Int8Ty); + pvec.push_back((const LLType*)getPtrToType(chPtrType)); + pvec.push_back((const LLType*)getPtrToType(chPtrType)); + const LLType* rettype = (const LLType*)llvm::Type::Int32Ty; llvm::FunctionType* functype = llvm::FunctionType::get(rettype, pvec, false); llvm::Function* func = llvm::Function::Create(functype,llvm::GlobalValue::ExternalLinkage,"main",ir.module); @@ -694,18 +694,18 @@ { // main with arguments assert(mainty->getNumParams() == 1); - std::vector args; + std::vector args; llvm::Function* mfn = LLVM_D_GetRuntimeFunction(ir.module,"_d_main_args"); llvm::Function::arg_iterator argi = func->arg_begin(); args.push_back(argi++); args.push_back(argi++); - const llvm::Type* at = mainty->getParamType(0)->getContainedType(0); - llvm::Value* arr = new llvm::AllocaInst(at->getContainedType(1)->getContainedType(0), func->arg_begin(), "argstorage", apt); - llvm::Value* a = new llvm::AllocaInst(at, "argarray", apt); - llvm::Value* ptr = DtoGEPi(a,0,0,"tmp",bb); - llvm::Value* v = args[0]; + const LLType* at = mainty->getParamType(0)->getContainedType(0); + LLValue* arr = new llvm::AllocaInst(at->getContainedType(1)->getContainedType(0), func->arg_begin(), "argstorage", apt); + LLValue* a = new llvm::AllocaInst(at, "argarray", apt); + LLValue* ptr = DtoGEPi(a,0,0,"tmp",bb); + LLValue* v = args[0]; if (v->getType() != DtoSize_t()) v = new llvm::ZExtInst(v, DtoSize_t(), "tmp", bb); new llvm::StoreInst(v,ptr,bb); @@ -778,7 +778,7 @@ // aggregate arg else if (DtoIsPassedByRef(argexp->type)) { - llvm::Value* alloc = new llvm::AllocaInst(DtoType(argexp->type), "tmpparam", gIR->topallocapoint()); + LLValue* alloc = new llvm::AllocaInst(DtoType(argexp->type), "tmpparam", gIR->topallocapoint()); DVarValue* vv = new DVarValue(argexp->type, alloc, true); DtoAssign(vv, arg); arg = vv; @@ -794,7 +794,7 @@ ////////////////////////////////////////////////////////////////////////////////////////// -void DtoVariadicArgument(Expression* argexp, llvm::Value* dst) +void DtoVariadicArgument(Expression* argexp, LLValue* dst) { Logger::println("DtoVariadicArgument"); LOG_SCOPE; diff -r 4c2689d57ba4 -r 7816aafeea3c gen/functions.h --- a/gen/functions.h Tue May 27 22:14:24 2008 +0200 +++ b/gen/functions.h Fri May 30 19:32:04 2008 +0200 @@ -1,7 +1,7 @@ #ifndef LLVMDC_GEN_FUNCTIONS_H #define LLVMDC_GEN_FUNCTIONS_H -const llvm::FunctionType* DtoFunctionType(Type* t, const llvm::Type* thistype, bool ismain = false); +const llvm::FunctionType* DtoFunctionType(Type* t, const LLType* thistype, bool ismain = false); const llvm::FunctionType* DtoFunctionType(FuncDeclaration* fdecl); const llvm::FunctionType* DtoBaseFunctionType(FuncDeclaration* fdecl); @@ -11,7 +11,7 @@ void DtoDefineFunc(FuncDeclaration* fd); DValue* DtoArgument(Argument* fnarg, Expression* argexp); -void DtoVariadicArgument(Expression* argexp, llvm::Value* dst); +void DtoVariadicArgument(Expression* argexp, LLValue* dst); void DtoMain(); diff -r 4c2689d57ba4 -r 7816aafeea3c gen/irstate.cpp --- a/gen/irstate.cpp Tue May 27 22:14:24 2008 +0200 +++ b/gen/irstate.cpp Fri May 30 19:32:04 2008 +0200 @@ -53,11 +53,6 @@ emitMain = false; mainFunc = 0; ir.state = this; - llvm_DeclareMemSet32 = NULL; - llvm_DeclareMemSet64 = NULL; - llvm_DeclareMemCpy32 = NULL; - llvm_DeclareMemCpy64 = NULL; - llvm_DeclareMemBarrier = NULL; } IrFunction* IRState::func() diff -r 4c2689d57ba4 -r 7816aafeea3c gen/irstate.h --- a/gen/irstate.h Tue May 27 22:14:24 2008 +0200 +++ b/gen/irstate.h Fri May 30 19:32:04 2008 +0200 @@ -140,13 +140,6 @@ FuncDeclVector ctors; FuncDeclVector dtors; FuncDeclVector unitTests; - - // intrinsics - llvm::Function* llvm_DeclareMemSet32; - llvm::Function* llvm_DeclareMemSet64; - llvm::Function* llvm_DeclareMemCpy32; - llvm::Function* llvm_DeclareMemCpy64; - llvm::Function* llvm_DeclareMemBarrier; }; #endif // LLVMDC_GEN_IRSTATE_H diff -r 4c2689d57ba4 -r 7816aafeea3c gen/llvm.h --- a/gen/llvm.h Tue May 27 22:14:24 2008 +0200 +++ b/gen/llvm.h Fri May 30 19:32:04 2008 +0200 @@ -16,4 +16,13 @@ #include "llvm/Support/IRBuilder.h" using llvm::IRBuilder; +#define GET_INTRINSIC_DECL(_X) (llvm::Intrinsic::getDeclaration(gIR->module, llvm::Intrinsic:: _X )) + +// shortcuts for the _very_ common llvm types +typedef llvm::Type LLType; +typedef llvm::Value LLValue; +typedef llvm::Constant LLConstant; + +#define LLSmallVector llvm::SmallVector + #endif // GEN_LLVM_H diff -r 4c2689d57ba4 -r 7816aafeea3c gen/runtime.cpp --- a/gen/runtime.cpp Tue May 27 22:14:24 2008 +0200 +++ b/gen/runtime.cpp Fri May 30 19:32:04 2008 +0200 @@ -132,49 +132,49 @@ ////////////////////////////////////////////////////////////////////////////////////////////////// -static const llvm::Type* rt_ptr(const llvm::Type* t) +static const LLType* rt_ptr(const LLType* t) { return getPtrToType(t); } -static const llvm::Type* rt_array(const llvm::Type* elemty) +static const LLType* rt_array(const LLType* elemty) { - std::vector t; + std::vector t; t.push_back(DtoSize_t()); t.push_back(rt_ptr(elemty)); return rt_ptr(llvm::StructType::get(t)); } -static const llvm::Type* rt_array2(const llvm::Type* elemty) +static const LLType* rt_array2(const LLType* elemty) { - std::vector t; + std::vector t; t.push_back(DtoSize_t()); t.push_back(rt_ptr(elemty)); return llvm::StructType::get(t); } -static const llvm::Type* rt_dg1() +static const LLType* rt_dg1() { - std::vector types; + std::vector types; types.push_back(rt_ptr(llvm::Type::Int8Ty)); types.push_back(rt_ptr(llvm::Type::Int8Ty)); const llvm::FunctionType* fty = llvm::FunctionType::get(llvm::Type::Int32Ty, types, false); - std::vector t; + std::vector t; t.push_back(rt_ptr(llvm::Type::Int8Ty)); t.push_back(rt_ptr(fty)); return rt_ptr(llvm::StructType::get(t)); } -static const llvm::Type* rt_dg2() +static const LLType* rt_dg2() { - std::vector types; + std::vector types; types.push_back(rt_ptr(llvm::Type::Int8Ty)); types.push_back(rt_ptr(llvm::Type::Int8Ty)); types.push_back(rt_ptr(llvm::Type::Int8Ty)); const llvm::FunctionType* fty = llvm::FunctionType::get(llvm::Type::Int32Ty, types, false); - std::vector t; + std::vector t; t.push_back(rt_ptr(llvm::Type::Int8Ty)); t.push_back(rt_ptr(fty)); return rt_ptr(llvm::StructType::get(t)); @@ -184,23 +184,23 @@ { M = new llvm::Module("llvmdc internal runtime"); - const llvm::Type* voidTy = llvm::Type::VoidTy; - const llvm::Type* boolTy = llvm::Type::Int1Ty; - const llvm::Type* byteTy = llvm::Type::Int8Ty; - const llvm::Type* shortTy = llvm::Type::Int16Ty; - const llvm::Type* intTy = llvm::Type::Int32Ty; - const llvm::Type* longTy = llvm::Type::Int64Ty; - const llvm::Type* floatTy = llvm::Type::FloatTy; - const llvm::Type* doubleTy = llvm::Type::DoubleTy; - const llvm::Type* sizeTy = DtoSize_t(); - const llvm::Type* voidPtrTy = rt_ptr(byteTy); - const llvm::Type* stringTy = rt_array(byteTy); - const llvm::Type* wstringTy = rt_array(shortTy); - const llvm::Type* dstringTy = rt_array(intTy); - const llvm::Type* objectTy = rt_ptr(ClassDeclaration::object->type->ir.type->get()); - const llvm::Type* classInfoTy = rt_ptr(ClassDeclaration::classinfo->type->ir.type->get()); - const llvm::Type* typeInfoTy = rt_ptr(Type::typeinfo->type->ir.type->get()); - const llvm::Type* aaTy = rt_ptr(llvm::OpaqueType::get()); + const LLType* voidTy = llvm::Type::VoidTy; + const LLType* boolTy = llvm::Type::Int1Ty; + const LLType* byteTy = llvm::Type::Int8Ty; + const LLType* shortTy = llvm::Type::Int16Ty; + const LLType* intTy = llvm::Type::Int32Ty; + const LLType* longTy = llvm::Type::Int64Ty; + const LLType* floatTy = llvm::Type::FloatTy; + const LLType* doubleTy = llvm::Type::DoubleTy; + const LLType* sizeTy = DtoSize_t(); + const LLType* voidPtrTy = rt_ptr(byteTy); + const LLType* stringTy = rt_array(byteTy); + const LLType* wstringTy = rt_array(shortTy); + const LLType* dstringTy = rt_array(intTy); + const LLType* objectTy = rt_ptr(ClassDeclaration::object->type->ir.type->get()); + const LLType* classInfoTy = rt_ptr(ClassDeclaration::classinfo->type->ir.type->get()); + const LLType* typeInfoTy = rt_ptr(Type::typeinfo->type->ir.type->get()); + const LLType* aaTy = rt_ptr(llvm::OpaqueType::get()); ///////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////// @@ -213,7 +213,7 @@ std::string fname("_d_assert"); std::string fname2("_d_array_bounds"); std::string fname3("_d_switch_error"); - std::vector types; + std::vector types; types.push_back(stringTy); types.push_back(intTy); const llvm::FunctionType* fty = llvm::FunctionType::get(voidTy, types, false); @@ -225,7 +225,7 @@ // void _d_assert_msg( char[] msg, char[] file, uint line ) { std::string fname("_d_assert_msg"); - std::vector types; + std::vector types; types.push_back(stringTy); types.push_back(stringTy); types.push_back(intTy); @@ -240,7 +240,7 @@ // void* _d_allocmemoryT(TypeInfo ti) { std::string fname("_d_allocmemoryT"); - std::vector types; + std::vector types; types.push_back(typeInfoTy); const llvm::FunctionType* fty = llvm::FunctionType::get(voidPtrTy, types, false); llvm::Function::Create(fty, llvm::GlobalValue::ExternalLinkage, fname, M); @@ -251,7 +251,7 @@ { std::string fname("_d_newarrayT"); std::string fname2("_d_newarrayiT"); - std::vector types; + std::vector types; types.push_back(typeInfoTy); types.push_back(sizeTy); const llvm::FunctionType* fty = llvm::FunctionType::get(voidPtrTy, types, false); @@ -264,7 +264,7 @@ { std::string fname("_d_arraysetlengthT"); std::string fname2("_d_arraysetlengthiT"); - std::vector types; + std::vector types; types.push_back(typeInfoTy); types.push_back(sizeTy); types.push_back(sizeTy); @@ -277,7 +277,7 @@ // Object _d_newclass(ClassInfo ci) { std::string fname("_d_newclass"); - std::vector types; + std::vector types; types.push_back(classInfoTy); const llvm::FunctionType* fty = llvm::FunctionType::get(objectTy, types, false); llvm::Function::Create(fty, llvm::GlobalValue::ExternalLinkage, fname, M); @@ -286,7 +286,7 @@ // void _d_delarray(size_t plength, void* pdata) { std::string fname("_d_delarray"); - std::vector types; + std::vector types; types.push_back(sizeTy); types.push_back(voidPtrTy); const llvm::FunctionType* fty = llvm::FunctionType::get(voidTy, types, false); @@ -300,7 +300,7 @@ std::string fname("_d_delmemory"); std::string fname2("_d_delinterface"); std::string fname3("_d_callfinalizer"); - std::vector types; + std::vector types; types.push_back(voidPtrTy); const llvm::FunctionType* fty = llvm::FunctionType::get(voidTy, types, false); llvm::Function::Create(fty, llvm::GlobalValue::ExternalLinkage, fname, M); @@ -311,7 +311,7 @@ // void _d_delclass(Object p) { std::string fname("_d_delclass"); - std::vector types; + std::vector types; types.push_back(objectTy); const llvm::FunctionType* fty = llvm::FunctionType::get(voidTy, types, false); llvm::Function::Create(fty, llvm::GlobalValue::ExternalLinkage, fname, M); @@ -325,7 +325,7 @@ { \ std::string fname("_d_array_init_"); \ fname.append(suffix); \ - std::vector types; \ + std::vector types; \ types.push_back(rt_ptr(TY)); \ types.push_back(sizeTy); \ types.push_back(TY); \ @@ -348,7 +348,7 @@ // void _d_array_init_mem(void* a, size_t na, void* v, size_t nv) { std::string fname("_d_array_init_mem"); - std::vector types; + std::vector types; types.push_back(voidPtrTy); types.push_back(sizeTy); types.push_back(voidPtrTy); @@ -365,7 +365,7 @@ { \ std::string fname(a); \ std::string fname2(b); \ - std::vector types; \ + std::vector types; \ types.push_back(TY); \ types.push_back(rt_dg1()); \ const llvm::FunctionType* fty = llvm::FunctionType::get(intTy, types, false); \ @@ -381,7 +381,7 @@ { \ std::string fname(a); \ std::string fname2(b); \ - std::vector types; \ + std::vector types; \ types.push_back(TY); \ types.push_back(rt_dg2()); \ const llvm::FunctionType* fty = llvm::FunctionType::get(intTy, types, false); \ @@ -397,7 +397,7 @@ { \ std::string fname(a); \ std::string fname2(b); \ - std::vector types; \ + std::vector types; \ types.push_back(TY); \ types.push_back(rt_dg1()); \ const llvm::FunctionType* fty = llvm::FunctionType::get(intTy, types, false); \ @@ -413,7 +413,7 @@ { \ std::string fname(a); \ std::string fname2(b); \ - std::vector types; \ + std::vector types; \ types.push_back(TY); \ types.push_back(rt_dg2()); \ const llvm::FunctionType* fty = llvm::FunctionType::get(intTy, types, false); \ @@ -433,7 +433,7 @@ // size_t _d_array_cast_len(size_t len, size_t elemsz, size_t newelemsz) { std::string fname("_d_array_cast_len"); - std::vector types; + std::vector types; types.push_back(sizeTy); types.push_back(sizeTy); types.push_back(sizeTy); @@ -449,7 +449,7 @@ // void _d_main_args(uint n, char** args, ref char[][] res) { std::string fname("_d_main_args"); - std::vector types; + std::vector types; types.push_back(intTy); types.push_back(rt_ptr(rt_ptr(byteTy))); types.push_back(rt_array(stringTy->getContainedType(0))); @@ -465,7 +465,7 @@ // Object _d_toObject(void* p) { std::string fname("_d_toObject"); - std::vector types; + std::vector types; types.push_back(voidPtrTy); const llvm::FunctionType* fty = llvm::FunctionType::get(objectTy, types, false); llvm::Function::Create(fty, llvm::GlobalValue::ExternalLinkage, fname, M); @@ -475,7 +475,7 @@ // Object _d_interface_cast(void* p, ClassInfo c) { std::string fname("_d_interface_cast"); - std::vector types; + std::vector types; types.push_back(voidPtrTy); types.push_back(classInfoTy); const llvm::FunctionType* fty = llvm::FunctionType::get(objectTy, types, false); @@ -486,7 +486,7 @@ // Object _d_dynamic_cast(Object o, ClassInfo c) { std::string fname("_d_dynamic_cast"); - std::vector types; + std::vector types; types.push_back(objectTy); types.push_back(classInfoTy); const llvm::FunctionType* fty = llvm::FunctionType::get(objectTy, types, false); @@ -502,7 +502,7 @@ { std::string fname("_adReverseChar"); std::string fname2("_adSortChar"); - std::vector types; + std::vector types; types.push_back(stringTy); types.push_back(stringTy); const llvm::FunctionType* fty = llvm::FunctionType::get(voidTy, types, false); @@ -515,7 +515,7 @@ { std::string fname("_adReverseWchar"); std::string fname2("_adSortWchar"); - std::vector types; + std::vector types; types.push_back(wstringTy); types.push_back(wstringTy); const llvm::FunctionType* fty = llvm::FunctionType::get(voidTy, types, false); @@ -526,7 +526,7 @@ // Array _adReverse(Array a, size_t szelem) { std::string fname("_adReverse"); - std::vector types; + std::vector types; types.push_back(rt_array(byteTy)); types.push_back(rt_array(byteTy)); types.push_back(sizeTy); @@ -537,7 +537,7 @@ // Array _adDupT(TypeInfo ti, Array a) { std::string fname("_adDupT"); - std::vector types; + std::vector types; types.push_back(rt_array(byteTy)); types.push_back(typeInfoTy); types.push_back(rt_array(byteTy)); @@ -550,7 +550,7 @@ { std::string fname("_adEq"); std::string fname2("_adCmp"); - std::vector types; + std::vector types; types.push_back(rt_array(byteTy)); types.push_back(rt_array(byteTy)); types.push_back(typeInfoTy); @@ -562,7 +562,7 @@ // int _adCmpChar(Array a1, Array a2) { std::string fname("_adCmpChar"); - std::vector types; + std::vector types; types.push_back(rt_array(byteTy)); types.push_back(rt_array(byteTy)); const llvm::FunctionType* fty = llvm::FunctionType::get(intTy, types, false); @@ -572,7 +572,7 @@ // Array _adSort(Array a, TypeInfo ti) { std::string fname("_adSort"); - std::vector types; + std::vector types; types.push_back(rt_array(byteTy)); types.push_back(rt_array(byteTy)); types.push_back(typeInfoTy); @@ -587,7 +587,7 @@ // size_t _aaLen(AA aa) { std::string fname("_aaLen"); - std::vector types; + std::vector types; types.push_back(aaTy); const llvm::FunctionType* fty = llvm::FunctionType::get(sizeTy, types, false); llvm::Function::Create(fty, llvm::GlobalValue::ExternalLinkage, fname, M); @@ -596,7 +596,7 @@ // void* _aaGet(AA* aa, TypeInfo keyti, size_t valuesize, void* pkey) { std::string fname("_aaGet"); - std::vector types; + std::vector types; types.push_back(aaTy); types.push_back(typeInfoTy); types.push_back(sizeTy); @@ -608,7 +608,7 @@ // void* _aaGetRvalue(AA aa, TypeInfo keyti, size_t valuesize, void* pkey) { std::string fname("_aaGetRvalue"); - std::vector types; + std::vector types; types.push_back(aaTy); types.push_back(typeInfoTy); types.push_back(sizeTy); @@ -620,7 +620,7 @@ // void* _aaIn(AA aa, TypeInfo keyti, void* pkey) { std::string fname("_aaIn"); - std::vector types; + std::vector types; types.push_back(aaTy); types.push_back(typeInfoTy); types.push_back(voidPtrTy); @@ -631,7 +631,7 @@ // void _aaDel(AA aa, TypeInfo keyti, void* pkey) { std::string fname("_aaDel"); - std::vector types; + std::vector types; types.push_back(aaTy); types.push_back(typeInfoTy); types.push_back(voidPtrTy); @@ -642,7 +642,7 @@ // ArrayRet_t _aaValues(AA aa, size_t keysize, size_t valuesize) { std::string fname("_aaValues"); - std::vector types; + std::vector types; types.push_back(rt_array(byteTy)); types.push_back(aaTy); types.push_back(sizeTy); @@ -654,7 +654,7 @@ // void* _aaRehash(AA* paa, TypeInfo keyti) { std::string fname("_aaRehash"); - std::vector types; + std::vector types; types.push_back(aaTy); types.push_back(typeInfoTy); const llvm::FunctionType* fty = llvm::FunctionType::get(voidPtrTy, types, false); @@ -664,7 +664,7 @@ // ArrayRet_t _aaKeys(AA aa, size_t keysize) { std::string fname("_aaKeys"); - std::vector types; + std::vector types; types.push_back(rt_array(byteTy)); types.push_back(aaTy); types.push_back(sizeTy); @@ -675,7 +675,7 @@ // int _aaApply(AA aa, size_t keysize, dg_t dg) { std::string fname("_aaApply"); - std::vector types; + std::vector types; types.push_back(aaTy); types.push_back(sizeTy); types.push_back(rt_dg1()); @@ -686,7 +686,7 @@ // int _aaApply2(AA aa, size_t keysize, dg2_t dg) { std::string fname("_aaApply2"); - std::vector types; + std::vector types; types.push_back(aaTy); types.push_back(sizeTy); types.push_back(rt_dg1()); @@ -703,7 +703,7 @@ { std::string fname("_moduleCtor"); std::string fname2("_moduleDtor"); - std::vector types; + std::vector types; const llvm::FunctionType* fty = llvm::FunctionType::get(voidTy, types, false); llvm::Function::Create(fty, llvm::GlobalValue::ExternalLinkage, fname, M); llvm::Function::Create(fty, llvm::GlobalValue::ExternalLinkage, fname2, M); @@ -716,7 +716,7 @@ // Object _d_toObject(void* p) { std::string fname("_d_toObject"); - std::vector types; + std::vector types; types.push_back(voidPtrTy); const llvm::FunctionType* fty = llvm::FunctionType::get(objectTy, types, false); llvm::Function::Create(fty, llvm::GlobalValue::ExternalLinkage, fname, M); @@ -725,7 +725,7 @@ // Object _d_dynamic_cast(Object o, ClassInfo c) { std::string fname("_d_dynamic_cast"); - std::vector types; + std::vector types; types.push_back(objectTy); types.push_back(classInfoTy); const llvm::FunctionType* fty = llvm::FunctionType::get(objectTy, types, false); @@ -735,7 +735,7 @@ // Object _d_interface_cast(void* p, ClassInfo c) { std::string fname("_d_interface_cast"); - std::vector types; + std::vector types; types.push_back(voidPtrTy); types.push_back(classInfoTy); const llvm::FunctionType* fty = llvm::FunctionType::get(objectTy, types, false); @@ -749,7 +749,7 @@ // void _d_throw_exception(Object e) { std::string fname("_d_throw_exception"); - std::vector types; + std::vector types; types.push_back(objectTy); const llvm::FunctionType* fty = llvm::FunctionType::get(voidTy, types, false); llvm::Function::Create(fty, llvm::GlobalValue::ExternalLinkage, fname, M); @@ -762,7 +762,7 @@ // int _d_switch_string(char[][] table, char[] ca) { std::string fname("_d_switch_string"); - std::vector types; + std::vector types; types.push_back(rt_array(rt_array2(byteTy))); types.push_back(stringTy); const llvm::FunctionType* fty = llvm::FunctionType::get(intTy, types, false); @@ -772,7 +772,7 @@ // int _d_switch_ustring(wchar[][] table, wchar[] ca) { std::string fname("_d_switch_ustring"); - std::vector types; + std::vector types; types.push_back(rt_array(rt_array2(shortTy))); types.push_back(wstringTy); const llvm::FunctionType* fty = llvm::FunctionType::get(intTy, types, false); @@ -782,7 +782,7 @@ // int _d_switch_dstring(dchar[][] table, dchar[] ca) { std::string fname("_d_switch_dstring"); - std::vector types; + std::vector types; types.push_back(rt_array(rt_array2(intTy))); types.push_back(dstringTy); const llvm::FunctionType* fty = llvm::FunctionType::get(intTy, types, false); diff -r 4c2689d57ba4 -r 7816aafeea3c gen/statements.cpp --- a/gen/statements.cpp Tue May 27 22:14:24 2008 +0200 +++ b/gen/statements.cpp Fri May 30 19:32:04 2008 +0200 @@ -104,7 +104,7 @@ else { if (global.params.symdebug) DtoDwarfStopPoint(loc.linnum); DValue* e = exp->toElem(p); - llvm::Value* v = e->getRVal(); + LLValue* v = e->getRVal(); delete e; Logger::cout() << "return value is '" <<*v << "'\n"; @@ -177,13 +177,13 @@ if (match) { - llvm::Value* allocainst = new llvm::AllocaInst(DtoType(match->type), "._tmp_if_var", p->topallocapoint()); + LLValue* allocainst = new llvm::AllocaInst(DtoType(match->type), "._tmp_if_var", p->topallocapoint()); match->ir.irLocal = new IrLocal(match); match->ir.irLocal->value = allocainst; } DValue* cond_e = condition->toElem(p); - llvm::Value* cond_val = cond_e->getRVal(); + LLValue* cond_val = cond_e->getRVal(); delete cond_e; llvm::BasicBlock* oldend = gIR->scopeend(); @@ -196,7 +196,7 @@ Logger::cout() << "if conditional: " << *cond_val << '\n'; cond_val = DtoBoolean(cond_val); } - llvm::Value* ifgoback = llvm::BranchInst::Create(ifbb, elsebb, cond_val, gIR->scopebb()); + LLValue* ifgoback = llvm::BranchInst::Create(ifbb, elsebb, cond_val, gIR->scopebb()); // replace current scope gIR->scope() = IRScope(ifbb,elsebb); @@ -274,11 +274,11 @@ // create the condition DValue* cond_e = condition->toElem(p); - llvm::Value* cond_val = DtoBoolean(cond_e->getRVal()); + LLValue* cond_val = DtoBoolean(cond_e->getRVal()); delete cond_e; // conditional branch - llvm::Value* ifbreak = llvm::BranchInst::Create(whilebodybb, endbb, cond_val, p->scopebb()); + LLValue* ifbreak = llvm::BranchInst::Create(whilebodybb, endbb, cond_val, p->scopebb()); // rewrite scope gIR->scope() = IRScope(whilebodybb,endbb); @@ -322,11 +322,11 @@ // create the condition DValue* cond_e = condition->toElem(p); - llvm::Value* cond_val = DtoBoolean(cond_e->getRVal()); + LLValue* cond_val = DtoBoolean(cond_e->getRVal()); delete cond_e; // conditional branch - llvm::Value* ifbreak = llvm::BranchInst::Create(dowhilebb, endbb, cond_val, gIR->scopebb()); + LLValue* ifbreak = llvm::BranchInst::Create(dowhilebb, endbb, cond_val, gIR->scopebb()); // rewrite the scope gIR->scope() = IRScope(endbb,oldend); @@ -361,7 +361,7 @@ // create the condition DValue* cond_e = condition->toElem(p); - llvm::Value* cond_val = DtoBoolean(cond_e->getRVal()); + LLValue* cond_val = DtoBoolean(cond_e->getRVal()); delete cond_e; // conditional branch @@ -571,7 +571,7 @@ DValue* e = exp->toElem(p); llvm::Function* fn = LLVM_D_GetRuntimeFunction(gIR->module, "_d_throw_exception"); //Logger::cout() << "calling: " << *fn << '\n'; - llvm::Value* arg = DtoBitCast(e->getRVal(), fn->getFunctionType()->getParamType(0)); + LLValue* arg = DtoBitCast(e->getRVal(), fn->getFunctionType()->getParamType(0)); //Logger::cout() << "arg: " << *arg << '\n'; gIR->ir->CreateCall(fn, arg, ""); gIR->ir->CreateUnreachable(); @@ -596,7 +596,7 @@ } }; -static llvm::Value* call_string_switch_runtime(llvm::GlobalVariable* table, Expression* e) +static LLValue* call_string_switch_runtime(llvm::GlobalVariable* table, Expression* e) { Type* dt = DtoDType(e->type); Type* dtnext = DtoDType(dt->next); @@ -616,14 +616,14 @@ } llvm::Function* fn = LLVM_D_GetRuntimeFunction(gIR->module, fname); - std::vector args; + std::vector args; Logger::cout() << *table->getType() << '\n'; Logger::cout() << *fn->getFunctionType()->getParamType(0) << '\n'; assert(table->getType() == fn->getFunctionType()->getParamType(0)); args.push_back(table); DValue* val = e->toElem(gIR); - llvm::Value* llval; + LLValue* llval; if (DSliceValue* sval = val->isSlice()) { // give storage @@ -667,7 +667,7 @@ do { // integral case if (cs->exp->type->isintegral()) { - llvm::Constant* c = cs->exp->toConstElem(p); + LLConstant* c = cs->exp->toConstElem(p); tmp.push_back(isaConstantInt(c)); } // string case @@ -694,7 +694,7 @@ // first sort it caseArray.sort(); // iterate and add indices to cases - std::vector inits; + std::vector inits; for (size_t i=0; istr->toConstElem(p)); } // build static array for ptr or final array - const llvm::Type* elemTy = DtoType(condition->type); + const LLType* elemTy = DtoType(condition->type); const llvm::ArrayType* arrTy = llvm::ArrayType::get(elemTy, inits.size()); - llvm::Constant* arrInit = llvm::ConstantArray::get(arrTy, inits); + LLConstant* arrInit = llvm::ConstantArray::get(arrTy, inits); llvm::GlobalVariable* arr = new llvm::GlobalVariable(arrTy, true, llvm::GlobalValue::InternalLinkage, arrInit, "string_switch_table_data", gIR->module); - const llvm::Type* elemPtrTy = getPtrToType(elemTy); - llvm::Constant* arrPtr = llvm::ConstantExpr::getBitCast(arr, elemPtrTy); + const LLType* elemPtrTy = getPtrToType(elemTy); + LLConstant* arrPtr = llvm::ConstantExpr::getBitCast(arr, elemPtrTy); // build the static table - std::vector types; + std::vector types; types.push_back(DtoSize_t()); types.push_back(elemPtrTy); const llvm::StructType* sTy = llvm::StructType::get(types); - std::vector sinits; + std::vector sinits; sinits.push_back(DtoConstSize_t(inits.size())); sinits.push_back(arrPtr); - llvm::Constant* sInit = llvm::ConstantStruct::get(sTy, sinits); + LLConstant* sInit = llvm::ConstantStruct::get(sTy, sinits); switchTable = new llvm::GlobalVariable(sTy, true, llvm::GlobalValue::InternalLinkage, sInit, "string_switch_table", gIR->module); } @@ -734,7 +734,7 @@ llvm::BasicBlock* endbb = llvm::BasicBlock::Create("switchend", p->topfunc(), oldend); // condition var - llvm::Value* condVal; + LLValue* condVal; // integral switch if (condition->type->isintegral()) { DValue* cond = condition->toElem(p); @@ -845,8 +845,8 @@ Logger::println("aggr = %s", aggr->toChars()); // key - const llvm::Type* keytype = key ? DtoType(key->type) : DtoSize_t(); - llvm::Value* keyvar = new llvm::AllocaInst(keytype, "foreachkey", p->topallocapoint()); + const LLType* keytype = key ? DtoType(key->type) : DtoSize_t(); + LLValue* keyvar = new llvm::AllocaInst(keytype, "foreachkey", p->topallocapoint()); if (key) { //key->llvmValue = keyvar; @@ -854,12 +854,12 @@ key->ir.irLocal = new IrLocal(key); key->ir.irLocal->value = keyvar; } - llvm::Value* zerokey = llvm::ConstantInt::get(keytype,0,false); + LLValue* zerokey = llvm::ConstantInt::get(keytype,0,false); // value Logger::println("value = %s", value->toPrettyChars()); - const llvm::Type* valtype = DtoType(value->type); - llvm::Value* valvar = NULL; + const LLType* valtype = DtoType(value->type); + LLValue* valvar = NULL; if (!value->isRef() && !value->isOut()) valvar = new llvm::AllocaInst(valtype, "foreachval", p->topallocapoint()); if (!value->ir.irLocal) @@ -870,8 +870,8 @@ Type* aggrtype = DtoDType(aggr->type); // get length and pointer - llvm::Value* val = 0; - llvm::Value* niters = 0; + LLValue* val = 0; + LLValue* niters = 0; // static array if (aggrtype->ty == Tsarray) @@ -922,7 +922,7 @@ niters = gIR->ir->CreateBitCast(niters, keytype, "foreachtrunckey"); } - llvm::Constant* delta = 0; + LLConstant* delta = 0; if (op == TOKforeach) { new llvm::StoreInst(zerokey, keyvar, p->scopebb()); } @@ -941,8 +941,8 @@ // condition p->scope() = IRScope(condbb,bodybb); - llvm::Value* done = 0; - llvm::Value* load = new llvm::LoadInst(keyvar, "tmp", p->scopebb()); + LLValue* done = 0; + LLValue* load = new llvm::LoadInst(keyvar, "tmp", p->scopebb()); if (op == TOKforeach) { done = new llvm::ICmpInst(llvm::ICmpInst::ICMP_ULT, load, niters, "tmp", p->scopebb()); } @@ -957,8 +957,8 @@ p->scope() = IRScope(bodybb,nextbb); // get value for this iteration - llvm::Constant* zero = llvm::ConstantInt::get(keytype,0,false); - llvm::Value* loadedKey = p->ir->CreateLoad(keyvar,"tmp"); + LLConstant* zero = llvm::ConstantInt::get(keytype,0,false); + LLValue* loadedKey = p->ir->CreateLoad(keyvar,"tmp"); if (aggrtype->ty == Tsarray) value->ir.irLocal->value = DtoGEP(val,zero,loadedKey,"tmp"); else if (aggrtype->ty == Tarray) @@ -982,7 +982,7 @@ // next p->scope() = IRScope(nextbb,endbb); if (op == TOKforeach) { - llvm::Value* load = DtoLoad(keyvar); + LLValue* load = DtoLoad(keyvar); load = p->ir->CreateAdd(load, llvm::ConstantInt::get(keytype, 1, false), "tmp"); DtoStore(load, keyvar); } @@ -1141,7 +1141,7 @@ Logger::println("asm expr = '%s'", asmstr.c_str()); // create function type - std::vector args; + std::vector args; const llvm::FunctionType* fty = llvm::FunctionType::get(DtoSize_t(), args, false); // create inline asm callee diff -r 4c2689d57ba4 -r 7816aafeea3c gen/structs.cpp --- a/gen/structs.cpp Tue May 27 22:14:24 2008 +0200 +++ b/gen/structs.cpp Fri May 30 19:32:04 2008 +0200 @@ -17,54 +17,55 @@ ////////////////////////////////////////////////////////////////////////////////////////// -const llvm::Type* DtoStructType(Type* t) +const LLType* DtoStructType(Type* t) { assert(0); - std::vector types; + std::vector types; return llvm::StructType::get(types); } ////////////////////////////////////////////////////////////////////////////////////////// -llvm::Value* DtoStructZeroInit(llvm::Value* v) +LLValue* DtoStructZeroInit(LLValue* v) { assert(gIR); uint64_t n = getTypeStoreSize(v->getType()->getContainedType(0)); - //llvm::Type* sarrty = getPtrToType(llvm::ArrayType::get(llvm::Type::Int8Ty, n)); - const llvm::Type* sarrty = getPtrToType(llvm::Type::Int8Ty); + //LLType* sarrty = getPtrToType(llvm::ArrayType::get(llvm::Type::Int8Ty, n)); + const LLType* sarrty = getPtrToType(llvm::Type::Int8Ty); - llvm::Value* sarr = DtoBitCast(v, sarrty); + LLValue* sarr = DtoBitCast(v, sarrty); llvm::Function* fn = LLVM_DeclareMemSet32(); - std::vector llargs; + assert(fn); + std::vector llargs; llargs.resize(4); llargs[0] = sarr; llargs[1] = llvm::ConstantInt::get(llvm::Type::Int8Ty, 0, false); llargs[2] = llvm::ConstantInt::get(llvm::Type::Int32Ty, n, false); llargs[3] = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false); - llvm::Value* ret = llvm::CallInst::Create(fn, llargs.begin(), llargs.end(), "", gIR->scopebb()); + LLValue* ret = llvm::CallInst::Create(fn, llargs.begin(), llargs.end(), "", gIR->scopebb()); return ret; } ////////////////////////////////////////////////////////////////////////////////////////// -llvm::Value* DtoStructCopy(llvm::Value* dst, llvm::Value* src) +LLValue* DtoStructCopy(LLValue* dst, LLValue* src) { Logger::cout() << "dst = " << *dst << " src = " << *src << '\n'; assert(dst->getType() == src->getType()); assert(gIR); uint64_t n = getTypeStoreSize(dst->getType()->getContainedType(0)); - //llvm::Type* sarrty = getPtrToType(llvm::ArrayType::get(llvm::Type::Int8Ty, n)); - const llvm::Type* arrty = getPtrToType(llvm::Type::Int8Ty); + //LLType* sarrty = getPtrToType(llvm::ArrayType::get(llvm::Type::Int8Ty, n)); + const LLType* arrty = getPtrToType(llvm::Type::Int8Ty); - llvm::Value* dstarr = new llvm::BitCastInst(dst,arrty,"tmp",gIR->scopebb()); - llvm::Value* srcarr = new llvm::BitCastInst(src,arrty,"tmp",gIR->scopebb()); + LLValue* dstarr = DtoBitCast(dst,arrty); + LLValue* srcarr = DtoBitCast(src,arrty); llvm::Function* fn = LLVM_DeclareMemCpy32(); - std::vector llargs; + std::vector llargs; llargs.resize(4); llargs[0] = dstarr; llargs[1] = srcarr; @@ -75,7 +76,7 @@ } ////////////////////////////////////////////////////////////////////////////////////////// -llvm::Constant* DtoConstStructInitializer(StructInitializer* si) +LLConstant* DtoConstStructInitializer(StructInitializer* si) { Logger::println("DtoConstStructInitializer: %s", si->toChars()); LOG_SCOPE; @@ -94,7 +95,7 @@ assert(ini); VarDeclaration* vd = (VarDeclaration*)si->vars.data[i]; assert(vd); - llvm::Constant* v = DtoConstInitializer(vd->type, ini); + LLConstant* v = DtoConstInitializer(vd->type, ini); inits.push_back(DUnionIdx(vd->ir.irField->index, vd->ir.irField->indexOffset, v)); } @@ -104,7 +105,7 @@ ////////////////////////////////////////////////////////////////////////////////////////// -llvm::Value* DtoIndexStruct(llvm::Value* ptr, StructDeclaration* sd, Type* t, unsigned os, std::vector& idxs) +LLValue* DtoIndexStruct(LLValue* ptr, StructDeclaration* sd, Type* t, unsigned os, std::vector& idxs) { Logger::println("checking for offset %u type %s:", os, t->toChars()); LOG_SCOPE; @@ -112,8 +113,8 @@ if (idxs.empty()) idxs.push_back(0); - const llvm::Type* llt = getPtrToType(DtoType(t)); - const llvm::Type* st = getPtrToType(DtoType(sd->type)); + const LLType* llt = getPtrToType(DtoType(t)); + const LLType* st = getPtrToType(DtoType(sd->type)); if (ptr->getType() != st) { assert(sd->ir.irStruct->hasUnions); ptr = gIR->ir->CreateBitCast(ptr, st, "tmp"); @@ -147,7 +148,7 @@ return DtoIndexStruct(ptr, ssd, t, os-vd->offset, tmp); } else { - const llvm::Type* sty = getPtrToType(DtoType(vd->type)); + const LLType* sty = getPtrToType(DtoType(vd->type)); if (ptr->getType() != sty) { ptr = DtoBitCast(ptr, sty); std::vector tmp; @@ -221,7 +222,7 @@ Logger::println("doing struct fields"); const llvm::StructType* structtype = 0; - std::vector fieldtypes; + std::vector fieldtypes; if (irstruct->offsets.empty()) { @@ -234,7 +235,7 @@ Logger::println("has fields"); unsigned prevsize = (unsigned)-1; unsigned lastoffset = (unsigned)-1; - const llvm::Type* fieldtype = NULL; + const LLType* fieldtype = NULL; VarDeclaration* fieldinit = NULL; size_t fieldpad = 0; int idx = 0; @@ -361,7 +362,7 @@ for (IrStruct::OffsetMap::iterator i=irstruct->offsets.begin(); i!=irstruct->offsets.end(); ++i) { IrStruct::Offset* so = &i->second; - llvm::Constant* finit = DtoConstFieldInitializer(so->var->type, so->var->init); + LLConstant* finit = DtoConstFieldInitializer(so->var->type, so->var->init); so->init = finit; so->var->ir.irField->constInit = finit; } @@ -369,17 +370,17 @@ const llvm::StructType* structtype = isaStruct(sd->type->ir.type->get()); // go through the field inits and build the default initializer - std::vector fieldinits_ll; + std::vector fieldinits_ll; size_t nfi = irstruct->defaultFields.size(); for (size_t i=0; idefaultFields[i] != NULL) { c = irstruct->defaultFields[i]->ir.irField->constInit; assert(c); } else { const llvm::ArrayType* arrty = isaArray(structtype->getElementType(i)); - std::vector vals(arrty->getNumElements(), llvm::ConstantInt::get(llvm::Type::Int8Ty, 0, false)); + std::vector vals(arrty->getNumElements(), llvm::ConstantInt::get(llvm::Type::Int8Ty, 0, false)); c = llvm::ConstantArray::get(arrty, vals); } fieldinits_ll.push_back(c); @@ -446,7 +447,7 @@ { unsigned o = i->first; IrStruct::Offset* so = &i->second; - const llvm::Type* ft = so->init->getType(); + const LLType* ft = so->init->getType(); size_t sz = getABITypeSize(ft); if (f == NULL) { // new field fields.push_back(DUnionField()); @@ -494,17 +495,17 @@ }*/ } -static void push_nulls(size_t nbytes, std::vector& out) +static void push_nulls(size_t nbytes, std::vector& out) { assert(nbytes > 0); - std::vector i(nbytes, llvm::ConstantInt::get(llvm::Type::Int8Ty, 0, false)); + std::vector i(nbytes, llvm::ConstantInt::get(llvm::Type::Int8Ty, 0, false)); out.push_back(llvm::ConstantArray::get(llvm::ArrayType::get(llvm::Type::Int8Ty, nbytes), i)); } -llvm::Constant* DUnion::getConst(std::vector& in) +LLConstant* DUnion::getConst(std::vector& in) { std::sort(in.begin(), in.end()); - std::vector out; + std::vector out; size_t nin = in.size(); size_t nfields = fields.size(); @@ -561,7 +562,7 @@ } } - std::vector tys; + std::vector tys; size_t nout = out.size(); for (size_t i=0; igetType()); diff -r 4c2689d57ba4 -r 7816aafeea3c gen/structs.h --- a/gen/structs.h Tue May 27 22:14:24 2008 +0200 +++ b/gen/structs.h Fri May 30 19:32:04 2008 +0200 @@ -3,12 +3,12 @@ struct StructInitializer; -const llvm::Type* DtoStructType(Type* t); +const LLType* DtoStructType(Type* t); -llvm::Value* DtoStructZeroInit(llvm::Value* v); -llvm::Value* DtoStructCopy(llvm::Value* dst, llvm::Value* src); +LLValue* DtoStructZeroInit(LLValue* v); +LLValue* DtoStructCopy(LLValue* dst, LLValue* src); -llvm::Constant* DtoConstStructInitializer(StructInitializer* si); +LLConstant* DtoConstStructInitializer(StructInitializer* si); /** * Resolves the llvm type for a struct @@ -30,14 +30,14 @@ */ void DtoDefineStruct(StructDeclaration* sd); -llvm::Value* DtoIndexStruct(llvm::Value* ptr, StructDeclaration* sd, Type* t, unsigned os, std::vector& idxs); +LLValue* DtoIndexStruct(LLValue* ptr, StructDeclaration* sd, Type* t, unsigned os, std::vector& idxs); struct DUnionField { unsigned offset; size_t size; - std::vector types; - llvm::Constant* init; + std::vector types; + LLConstant* init; size_t initsize; DUnionField() { @@ -51,11 +51,11 @@ struct DUnionIdx { unsigned idx,idxos; - llvm::Constant* c; + LLConstant* c; DUnionIdx() : idx(0), c(0) {} - DUnionIdx(unsigned _idx, unsigned _idxos, llvm::Constant* _c) + DUnionIdx(unsigned _idx, unsigned _idxos, LLConstant* _c) : idx(_idx), idxos(_idxos), c(_c) {} bool operator<(const DUnionIdx& i) const { return (idx < i.idx) || (idx == i.idx && idxos < i.idxos); @@ -67,7 +67,7 @@ std::vector fields; public: DUnion(); - llvm::Constant* getConst(std::vector& in); + LLConstant* getConst(std::vector& in); }; #endif diff -r 4c2689d57ba4 -r 7816aafeea3c gen/todebug.cpp --- a/gen/todebug.cpp Tue May 27 22:14:24 2008 +0200 +++ b/gen/todebug.cpp Fri May 30 19:32:04 2008 +0200 @@ -15,18 +15,18 @@ using namespace llvm::dwarf; -static const llvm::PointerType* ptrTy(const llvm::Type* t) +static const llvm::PointerType* ptrTy(const LLType* t) { return llvm::PointerType::get(t, 0); } static const llvm::PointerType* dbgArrTy() { - std::vector t; + std::vector t; return ptrTy(llvm::StructType::get(t)); } -static llvm::Constant* dbgToArrTy(llvm::Constant* c) +static LLConstant* dbgToArrTy(LLConstant* c) { Logger::cout() << "casting: " << *c << '\n'; return llvm::ConstantExpr::getBitCast(c, dbgArrTy()); @@ -48,7 +48,7 @@ uint ;; Tag of descriptors grouped by the anchor } */ - std::vector elems(2, Ty(Int32Ty)); + std::vector elems(2, Ty(Int32Ty)); const llvm::StructType* t = isaStruct(gIR->module->getTypeByName("llvm.dbg.anchor.type")); /* @@ -57,26 +57,26 @@ %llvm.dbg.subprograms = linkonce constant %llvm.dbg.anchor.type { uint 0, uint 46 } ;; DW_TAG_subprogram */ if (!gIR->module->getNamedGlobal("llvm.dbg.compile_units")) { - std::vector vals; + std::vector vals; vals.push_back(DtoConstUint(llvm::LLVMDebugVersion)); vals.push_back(DtoConstUint(DW_TAG_compile_unit)); - llvm::Constant* i = llvm::ConstantStruct::get(t, vals); + LLConstant* i = llvm::ConstantStruct::get(t, vals); dbg_compile_units = new llvm::GlobalVariable(t,true,llvm::GlobalValue::LinkOnceLinkage,i,"llvm.dbg.compile_units",gIR->module); dbg_compile_units->setSection("llvm.metadata"); } if (!gIR->module->getNamedGlobal("llvm.dbg.global_variables")) { - std::vector vals; + std::vector vals; vals.push_back(DtoConstUint(llvm::LLVMDebugVersion)); vals.push_back(DtoConstUint(DW_TAG_variable)); - llvm::Constant* i = llvm::ConstantStruct::get(t, vals); + LLConstant* i = llvm::ConstantStruct::get(t, vals); dbg_global_variables = new llvm::GlobalVariable(t,true,llvm::GlobalValue::LinkOnceLinkage,i,"llvm.dbg.global_variables",gIR->module); dbg_global_variables->setSection("llvm.metadata"); } if (!gIR->module->getNamedGlobal("llvm.dbg.subprograms")) { - std::vector vals; + std::vector vals; vals.push_back(DtoConstUint(llvm::LLVMDebugVersion)); vals.push_back(DtoConstUint(DW_TAG_subprogram)); - llvm::Constant* i = llvm::ConstantStruct::get(t, vals); + LLConstant* i = llvm::ConstantStruct::get(t, vals); dbg_subprograms = new llvm::GlobalVariable(t,true,llvm::GlobalValue::LinkOnceLinkage,i,"llvm.dbg.subprograms",gIR->module); dbg_subprograms->setSection("llvm.metadata"); } @@ -84,7 +84,7 @@ return t; } -llvm::Constant* GetDwarfAnchor(llvm::dwarf::dwarf_constants c) +LLConstant* GetDwarfAnchor(llvm::dwarf::dwarf_constants c) { GetDwarfAnchorType(); switch (c) @@ -124,9 +124,9 @@ // create a valid compile unit constant for the current module - llvm::Constant* c = NULL; + LLConstant* c = NULL; - std::vector vals; + std::vector vals; vals.push_back(llvm::ConstantExpr::getAdd( DtoConstUint(DW_TAG_compile_unit), DtoConstUint(llvm::LLVMDebugVersion))); @@ -156,7 +156,7 @@ llvm::GlobalVariable* DtoDwarfSubProgram(FuncDeclaration* fd, llvm::GlobalVariable* compileUnit) { - std::vector vals; + std::vector vals; vals.push_back(llvm::ConstantExpr::getAdd( DtoConstUint(DW_TAG_subprogram), DtoConstUint(llvm::LLVMDebugVersion))); @@ -172,7 +172,7 @@ vals.push_back(DtoConstBool(fd->protection == PROTprivate)); vals.push_back(DtoConstBool(fd->getModule() == gIR->dmodule)); - llvm::Constant* c = llvm::ConstantStruct::get(GetDwarfSubProgramType(), vals); + LLConstant* c = llvm::ConstantStruct::get(GetDwarfSubProgramType(), vals); llvm::GlobalVariable* gv = new llvm::GlobalVariable(c->getType(), true, llvm::GlobalValue::InternalLinkage, c, "llvm.dbg.subprogram", gIR->module); gv->setSection("llvm.metadata"); return gv; @@ -196,7 +196,7 @@ void DtoDwarfStopPoint(unsigned ln) { - std::vector args; + std::vector args; args.push_back(DtoConstUint(ln)); args.push_back(DtoConstUint(0)); FuncDeclaration* fd = gIR->func()->decl; diff -r 4c2689d57ba4 -r 7816aafeea3c gen/toir.cpp --- a/gen/toir.cpp Tue May 27 22:14:24 2008 +0200 +++ b/gen/toir.cpp Fri May 30 19:32:04 2008 +0200 @@ -69,7 +69,7 @@ // normal stack variable else { // allocate storage on the stack - const llvm::Type* lltype = DtoType(vd->type); + const LLType* lltype = DtoType(vd->type); llvm::AllocaInst* allocainst = new llvm::AllocaInst(lltype, vd->toChars(), p->topallocapoint()); //allocainst->setAlignment(vd->type->alignsize()); // TODO assert(!vd->ir.irLocal); @@ -157,7 +157,7 @@ vd->ir.getIrValue() = p->func()->decl->irFunc->_arguments; assert(vd->ir.getIrValue()); return new DVarValue(vd, vd->ir.getIrValue(), true);*/ - llvm::Value* v = p->func()->decl->ir.irFunc->_arguments; + LLValue* v = p->func()->decl->ir.irFunc->_arguments; assert(v); return new DVarValue(vd, v, true); } @@ -169,7 +169,7 @@ vd->ir.getIrValue() = p->func()->decl->irFunc->_argptr; assert(vd->ir.getIrValue()); return new DVarValue(vd, vd->ir.getIrValue(), true);*/ - llvm::Value* v = p->func()->decl->ir.irFunc->_argptr; + LLValue* v = p->func()->decl->ir.irFunc->_argptr; assert(v); return new DVarValue(vd, v, true); } @@ -178,7 +178,7 @@ { Logger::println("Id::dollar"); assert(!p->arrays.empty()); - llvm::Value* tmp = DtoArrayLen(p->arrays.back()); + LLValue* tmp = DtoArrayLen(p->arrays.back()); return new DVarValue(vd, tmp, false); } // typeinfo @@ -187,8 +187,8 @@ Logger::println("TypeInfoDeclaration"); DtoForceDeclareDsymbol(tid); assert(tid->ir.getIrValue()); - const llvm::Type* vartype = DtoType(type); - llvm::Value* m; + const LLType* vartype = DtoType(type); + LLValue* m; if (tid->ir.getIrValue()->getType() != getPtrToType(vartype)) m = p->ir->CreateBitCast(tid->ir.getIrValue(), vartype, "tmp"); else @@ -263,7 +263,7 @@ ////////////////////////////////////////////////////////////////////////////////////////// -llvm::Constant* VarExp::toConstElem(IRState* p) +LLConstant* VarExp::toConstElem(IRState* p) { Logger::print("VarExp::toConstElem: %s | %s\n", toChars(), type->toChars()); LOG_SCOPE; @@ -282,8 +282,8 @@ { DtoForceDeclareDsymbol(ti); assert(ti->ir.getIrValue()); - const llvm::Type* vartype = DtoType(type); - llvm::Constant* m = isaConstant(ti->ir.getIrValue()); + const LLType* vartype = DtoType(type); + LLConstant* m = isaConstant(ti->ir.getIrValue()); assert(m); if (ti->ir.getIrValue()->getType() != getPtrToType(vartype)) m = llvm::ConstantExpr::getBitCast(m, vartype); @@ -299,24 +299,24 @@ { Logger::print("IntegerExp::toElem: %s | %s\n", toChars(), type->toChars()); LOG_SCOPE; - llvm::Constant* c = toConstElem(p); + LLConstant* c = toConstElem(p); return new DConstValue(type, c); } ////////////////////////////////////////////////////////////////////////////////////////// -llvm::Constant* IntegerExp::toConstElem(IRState* p) +LLConstant* IntegerExp::toConstElem(IRState* p) { Logger::print("IntegerExp::toConstElem: %s | %s\n", toChars(), type->toChars()); LOG_SCOPE; - const llvm::Type* t = DtoType(type); + const LLType* t = DtoType(type); if (isaPointer(t)) { Logger::println("pointer"); - llvm::Constant* i = llvm::ConstantInt::get(DtoSize_t(),(uint64_t)value,false); + LLConstant* i = llvm::ConstantInt::get(DtoSize_t(),(uint64_t)value,false); return llvm::ConstantExpr::getIntToPtr(i, t); } assert(llvm::isa(t)); - llvm::Constant* c = llvm::ConstantInt::get(t,(uint64_t)value,!type->isunsigned()); + LLConstant* c = llvm::ConstantInt::get(t,(uint64_t)value,!type->isunsigned()); assert(c); Logger::cout() << "value = " << *c << '\n'; return c; @@ -328,13 +328,13 @@ { Logger::print("RealExp::toElem: %s | %s\n", toChars(), type->toChars()); LOG_SCOPE; - llvm::Constant* c = toConstElem(p); + LLConstant* c = toConstElem(p); return new DConstValue(type, c); } ////////////////////////////////////////////////////////////////////////////////////////// -llvm::Constant* RealExp::toConstElem(IRState* p) +LLConstant* RealExp::toConstElem(IRState* p) { Logger::print("RealExp::toConstElem: %s | %s\n", toChars(), type->toChars()); LOG_SCOPE; @@ -348,17 +348,17 @@ { Logger::print("NullExp::toElem(type=%s): %s\n", type->toChars(),toChars()); LOG_SCOPE; - llvm::Constant* c = toConstElem(p); + LLConstant* c = toConstElem(p); return new DNullValue(type, c); } ////////////////////////////////////////////////////////////////////////////////////////// -llvm::Constant* NullExp::toConstElem(IRState* p) +LLConstant* NullExp::toConstElem(IRState* p) { Logger::print("NullExp::toConstElem(type=%s): %s\n", type->toChars(),toChars()); LOG_SCOPE; - const llvm::Type* t = DtoType(type); + const LLType* t = DtoType(type); if (type->ty == Tarray) { assert(isaStruct(t)); return llvm::ConstantAggregateZero::get(t); @@ -376,7 +376,7 @@ { Logger::print("ComplexExp::toElem(): %s | %s\n", toChars(), type->toChars()); LOG_SCOPE; - llvm::Constant* c = toConstElem(p); + LLConstant* c = toConstElem(p); if (c->isNullValue()) { Type* t = DtoDType(type); @@ -392,7 +392,7 @@ ////////////////////////////////////////////////////////////////////////////////////////// -llvm::Constant* ComplexExp::toConstElem(IRState* p) +LLConstant* ComplexExp::toConstElem(IRState* p) { Logger::print("ComplexExp::toConstElem(): %s | %s\n", toChars(), type->toChars()); LOG_SCOPE; @@ -409,13 +409,13 @@ Type* dtype = DtoDType(type); Type* cty = DtoDType(dtype->next); - const llvm::Type* ct = DtoType(cty); + const LLType* ct = DtoType(cty); if (ct == llvm::Type::VoidTy) ct = llvm::Type::Int8Ty; //printf("ct = %s\n", type->next->toChars()); const llvm::ArrayType* at = llvm::ArrayType::get(ct,len+1); - llvm::Constant* _init; + LLConstant* _init; if (cty->size() == 1) { uint8_t* str = (uint8_t*)string; std::string cont((char*)str, len); @@ -423,7 +423,7 @@ } else if (cty->size() == 2) { uint16_t* str = (uint16_t*)string; - std::vector vals; + std::vector vals; for(size_t i=0; isize() == 4) { uint32_t* str = (uint32_t*)string; - std::vector vals; + std::vector vals; for(size_t i=0; imodule); llvm::ConstantInt* zero = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false); - llvm::Constant* idxs[2] = { zero, zero }; - llvm::Constant* arrptr = llvm::ConstantExpr::getGetElementPtr(gvar,idxs,2); + LLConstant* idxs[2] = { zero, zero }; + LLConstant* arrptr = llvm::ConstantExpr::getGetElementPtr(gvar,idxs,2); if (dtype->ty == Tarray) { - llvm::Constant* clen = llvm::ConstantInt::get(DtoSize_t(),len,false); + LLConstant* clen = llvm::ConstantInt::get(DtoSize_t(),len,false); if (!p->topexp() || p->topexp()->e2 != this) { - llvm::Value* tmpmem = new llvm::AllocaInst(DtoType(dtype),"tempstring",p->topallocapoint()); + LLValue* tmpmem = new llvm::AllocaInst(DtoType(dtype),"tempstring",p->topallocapoint()); DtoSetArray(tmpmem, clen, arrptr); return new DVarValue(type, tmpmem, true); } @@ -471,8 +471,8 @@ assert(0); } else if (dtype->ty == Tsarray) { - const llvm::Type* dstType = getPtrToType(llvm::ArrayType::get(ct, len)); - llvm::Value* emem = (gvar->getType() == dstType) ? gvar : DtoBitCast(gvar, dstType); + const LLType* dstType = getPtrToType(llvm::ArrayType::get(ct, len)); + LLValue* emem = (gvar->getType() == dstType) ? gvar : DtoBitCast(gvar, dstType); return new DVarValue(type, emem, true); } else if (dtype->ty == Tpointer) { @@ -485,7 +485,7 @@ ////////////////////////////////////////////////////////////////////////////////////////// -llvm::Constant* StringExp::toConstElem(IRState* p) +LLConstant* StringExp::toConstElem(IRState* p) { Logger::print("StringExp::toConstElem: %s | %s\n", toChars(), type->toChars()); LOG_SCOPE; @@ -496,10 +496,10 @@ bool nullterm = (t->ty != Tsarray); size_t endlen = nullterm ? len+1 : len; - const llvm::Type* ct = DtoType(cty); + const LLType* ct = DtoType(cty); const llvm::ArrayType* at = llvm::ArrayType::get(ct,endlen); - llvm::Constant* _init; + LLConstant* _init; if (cty->size() == 1) { uint8_t* str = (uint8_t*)string; std::string cont((char*)str, len); @@ -507,7 +507,7 @@ } else if (cty->size() == 2) { uint16_t* str = (uint16_t*)string; - std::vector vals; + std::vector vals; for(size_t i=0; isize() == 4) { uint32_t* str = (uint32_t*)string; - std::vector vals; + std::vector vals; for(size_t i=0; igetType(),true,_linkage,_init,".stringliteral",gIR->module); llvm::ConstantInt* zero = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false); - llvm::Constant* idxs[2] = { zero, zero }; - llvm::Constant* arrptr = llvm::ConstantExpr::getGetElementPtr(gvar,idxs,2); + LLConstant* idxs[2] = { zero, zero }; + LLConstant* arrptr = llvm::ConstantExpr::getGetElementPtr(gvar,idxs,2); if (t->ty == Tpointer) { return arrptr; } else if (t->ty == Tarray) { - llvm::Constant* clen = llvm::ConstantInt::get(DtoSize_t(),len,false); + LLConstant* clen = llvm::ConstantInt::get(DtoSize_t(),len,false); return DtoConstSlice(clen, arrptr); } @@ -586,7 +586,7 @@ if (l->isSlice() || l->isComplex()) return l; - llvm::Value* v; + LLValue* v; if (l->isVar() && l->isVar()->lval) v = l->getLVal(); else @@ -619,7 +619,7 @@ TypeStruct* ts = (TypeStruct*)e1next; std::vector offsets; - llvm::Value* v = DtoIndexStruct(l->getRVal(), ts->sym, t->next, cofs->getZExtValue(), offsets); + LLValue* v = DtoIndexStruct(l->getRVal(), ts->sym, t->next, cofs->getZExtValue(), offsets); return new DFieldValue(type, v, true); } else if (e1type->ty == Tpointer) { @@ -631,7 +631,7 @@ return new DImValue(type, l->getRVal()); } } - llvm::Value* v = llvm::GetElementPtrInst::Create(l->getRVal(), r->getRVal(), "tmp", p->scopebb()); + LLValue* v = llvm::GetElementPtrInst::Create(l->getRVal(), r->getRVal(), "tmp", p->scopebb()); return new DImValue(type, v); } else if (t->iscomplex()) { @@ -663,7 +663,7 @@ DValue* res; if (DtoDType(e1->type)->ty == Tpointer) { - llvm::Value* gep = llvm::GetElementPtrInst::Create(l->getRVal(),r->getRVal(),"tmp",p->scopebb()); + LLValue* gep = llvm::GetElementPtrInst::Create(l->getRVal(),r->getRVal(),"tmp",p->scopebb()); res = new DImValue(type, gep); } else if (t->iscomplex()) { @@ -701,19 +701,19 @@ Type* t2 = DtoDType(e2->type); if (t1->ty == Tpointer && t2->ty == Tpointer) { - llvm::Value* lv = l->getRVal(); - llvm::Value* rv = r->getRVal(); + LLValue* lv = l->getRVal(); + LLValue* rv = r->getRVal(); Logger::cout() << "lv: " << *lv << " rv: " << *rv << '\n'; lv = p->ir->CreatePtrToInt(lv, DtoSize_t(), "tmp"); rv = p->ir->CreatePtrToInt(rv, DtoSize_t(), "tmp"); - llvm::Value* diff = p->ir->CreateSub(lv,rv,"tmp"); + LLValue* diff = p->ir->CreateSub(lv,rv,"tmp"); if (diff->getType() != DtoType(type)) diff = p->ir->CreateIntToPtr(diff, DtoType(type), "tmp"); return new DImValue(type, diff); } else if (t1->ty == Tpointer) { - llvm::Value* idx = p->ir->CreateNeg(r->getRVal(), "tmp"); - llvm::Value* v = llvm::GetElementPtrInst::Create(l->getRVal(), idx, "tmp", p->scopebb()); + LLValue* idx = p->ir->CreateNeg(r->getRVal(), "tmp"); + LLValue* v = llvm::GetElementPtrInst::Create(l->getRVal(), idx, "tmp", p->scopebb()); return new DImValue(type, v); } else if (t->iscomplex()) { @@ -739,8 +739,8 @@ DValue* res; if (DtoDType(e1->type)->ty == Tpointer) { Logger::println("ptr"); - llvm::Value* tmp = r->getRVal(); - llvm::Value* zero = llvm::ConstantInt::get(tmp->getType(),0,false); + LLValue* tmp = r->getRVal(); + LLValue* zero = llvm::ConstantInt::get(tmp->getType(),0,false); tmp = llvm::BinaryOperator::createSub(zero,tmp,"tmp",p->scopebb()); tmp = llvm::GetElementPtrInst::Create(l->getRVal(),tmp,"tmp",p->scopebb()); res = new DImValue(type, tmp); @@ -878,8 +878,8 @@ Type* e1type = DtoDType(e1->type); bool delegateCall = false; - llvm::Value* zero = llvm::ConstantInt::get(llvm::Type::Int32Ty,0,false); - llvm::Value* one = llvm::ConstantInt::get(llvm::Type::Int32Ty,1,false); + LLValue* zero = llvm::ConstantInt::get(llvm::Type::Int32Ty,0,false); + LLValue* one = llvm::ConstantInt::get(llvm::Type::Int32Ty,1,false); LINK dlink = LINKd; // hidden struct return parameter handling @@ -929,7 +929,7 @@ Expression* exp = (Expression*)arguments->data[0]; DValue* expelem = exp->toElem(p); Type* t = DtoDType(type); - const llvm::Type* llt = DtoType(type); + const LLType* llt = DtoType(type); if (DtoIsPassedByRef(t)) llt = getPtrToType(llt); // TODO @@ -944,7 +944,7 @@ DValue* expv = exp->toElem(p); if (expv->getType()->toBasetype()->ty != Tint32) expv = DtoCast(expv, Type::tint32); - llvm::Value* alloc = new llvm::AllocaInst(llvm::Type::Int8Ty, expv->getRVal(), "alloca", p->scopebb()); + LLValue* alloc = new llvm::AllocaInst(llvm::Type::Int8Ty, expv->getRVal(), "alloca", p->scopebb()); return new DImValue(type, alloc); } } @@ -959,9 +959,9 @@ if (tf->linkage == LINKd && tf->varargs == 1) n+=2; if (dfn && dfn->func && dfn->func->isNested()) n++; - llvm::Value* funcval = fn->getRVal(); + LLValue* funcval = fn->getRVal(); assert(funcval != 0); - std::vector llargs(n, 0); + std::vector llargs(n, 0); const llvm::FunctionType* llfnty = 0; @@ -985,7 +985,7 @@ else if (isaStruct(funcval->getType()->getContainedType(0))) { funcval = DtoGEP(funcval,zero,one,"tmp",p->scopebb()); funcval = new llvm::LoadInst(funcval,"tmp",p->scopebb()); - const llvm::Type* ty = funcval->getType()->getContainedType(0); + const LLType* ty = funcval->getType()->getContainedType(0); llfnty = llvm::cast(ty); } // unknown @@ -1011,7 +1011,7 @@ if (retinptr) { if (topexp && topexp->e2 == this) { assert(topexp->v); - llvm::Value* tlv = topexp->v->getLVal(); + LLValue* tlv = topexp->v->getLVal(); assert(isaStruct(tlv->getType()->getContainedType(0))); llargs[j] = tlv; isInPlace = true; @@ -1026,7 +1026,7 @@ } if (dfn && dfn->func && dfn->func->runTimeHack) { - const llvm::Type* rettype = getPtrToType(DtoType(type)); + const LLType* rettype = getPtrToType(DtoType(type)); if (llargs[j]->getType() != llfnty->getParamType(j)) { Logger::println("llvmRunTimeHack==true - force casting return value param"); Logger::cout() << "casting: " << *llargs[j] << " to type: " << *llfnty->getParamType(j) << '\n'; @@ -1054,7 +1054,7 @@ // delegate context arguments else if (delegateCall) { Logger::println("Delegate Call"); - llvm::Value* contextptr = DtoGEP(fn->getRVal(),zero,zero,"tmp",p->scopebb()); + LLValue* contextptr = DtoGEP(fn->getRVal(),zero,zero,"tmp",p->scopebb()); llargs[j] = new llvm::LoadInst(contextptr,"tmp",p->scopebb()); ++j; ++argiter; @@ -1062,7 +1062,7 @@ // nested call else if (dfn && dfn->func && dfn->func->isNested()) { Logger::println("Nested Call"); - llvm::Value* contextptr = DtoNestedContext(dfn->func->toParent2()->isFuncDeclaration()); + LLValue* contextptr = DtoNestedContext(dfn->func->toParent2()->isFuncDeclaration()); if (!contextptr) contextptr = llvm::ConstantPointerNull::get(getPtrToType(llvm::Type::Int8Ty)); llargs[j] = DtoBitCast(contextptr, getPtrToType(llvm::Type::Int8Ty)); @@ -1092,8 +1092,7 @@ size_t nimplicit = j; - std::vector vtypes; - std::vector vtypeinfos; + std::vector vtypes; // number of non variadic args int begin = tf->parameters->dim; @@ -1108,7 +1107,7 @@ } const llvm::StructType* vtype = llvm::StructType::get(vtypes); Logger::cout() << "d-variadic argument struct type:\n" << *vtype << '\n'; - llvm::Value* mem = new llvm::AllocaInst(vtype,"_argptr_storage",p->topallocapoint()); + LLValue* mem = new llvm::AllocaInst(vtype,"_argptr_storage",p->topallocapoint()); // store arguments in the struct for (int i=begin,k=0; idim; i++,k++) @@ -1121,27 +1120,32 @@ // build type info array assert(Type::typeinfo->ir.irStruct->constInit); - const llvm::Type* typeinfotype = DtoType(Type::typeinfo->type); + const LLType* typeinfotype = DtoType(Type::typeinfo->type); const llvm::ArrayType* typeinfoarraytype = llvm::ArrayType::get(typeinfotype,vtype->getNumElements()); - llvm::Value* typeinfomem = new llvm::AllocaInst(typeinfoarraytype,"_arguments_storage",p->topallocapoint()); + llvm::GlobalVariable* typeinfomem = + new llvm::GlobalVariable(typeinfoarraytype, true, llvm::GlobalValue::InternalLinkage, NULL, "._arguments.storage", gIR->module); Logger::cout() << "_arguments storage: " << *typeinfomem << '\n'; + + std::vector vtypeinfos; for (int i=begin,k=0; idim; i++,k++) { Expression* argexp = (Expression*)arguments->data[i]; - TypeInfoDeclaration* tidecl = argexp->type->getTypeInfoDeclaration(); - DtoForceDeclareDsymbol(tidecl); - assert(tidecl->ir.getIrValue()); - vtypeinfos.push_back(tidecl->ir.getIrValue()); - llvm::Value* v = p->ir->CreateBitCast(vtypeinfos[k], typeinfotype, "tmp"); - p->ir->CreateStore(v, DtoGEPi(typeinfomem,0,k,"tmp")); + vtypeinfos.push_back(DtoTypeInfoOf(argexp->type)); } + // apply initializer + LLConstant* tiinits = llvm::ConstantArray::get(typeinfoarraytype, vtypeinfos); + typeinfomem->setInitializer(tiinits); + // put data in d-array - llvm::Value* typeinfoarrayparam = new llvm::AllocaInst(llfnty->getParamType(j)->getContainedType(0),"_arguments_array",p->topallocapoint()); - p->ir->CreateStore(DtoConstSize_t(vtype->getNumElements()), DtoGEPi(typeinfoarrayparam,0,0,"tmp")); - llvm::Value* casttypeinfomem = p->ir->CreateBitCast(typeinfomem, getPtrToType(typeinfotype), "tmp"); - p->ir->CreateStore(casttypeinfomem, DtoGEPi(typeinfoarrayparam,0,1,"tmp")); + std::vector pinits; + pinits.push_back(DtoConstSize_t(vtype->getNumElements())); + pinits.push_back(llvm::ConstantExpr::getBitCast(typeinfomem, getPtrToType(typeinfotype))); + const LLType* tiarrty = llfnty->getParamType(j)->getContainedType(0); + tiinits = llvm::ConstantStruct::get(pinits); + LLValue* typeinfoarrayparam = new llvm::GlobalVariable(tiarrty, + true, llvm::GlobalValue::InternalLinkage, tiinits, "._arguments.array", gIR->module); // specify arguments llargs[j] = typeinfoarrayparam;; @@ -1205,10 +1209,10 @@ // call the function llvm::CallInst* call = llvm::CallInst::Create(funcval, llargs.begin(), llargs.end(), varname, p->scopebb()); - llvm::Value* retllval = (retinptr) ? llargs[0] : call; + LLValue* retllval = (retinptr) ? llargs[0] : call; if (retinptr && dfn && dfn->func && dfn->func->runTimeHack) { - const llvm::Type* rettype = getPtrToType(DtoType(type)); + const LLType* rettype = getPtrToType(DtoType(type)); if (retllval->getType() != rettype) { Logger::println("llvmRunTimeHack==true - force casting return value"); Logger::cout() << "from: " << *retllval->getType() << " to: " << *rettype << '\n'; @@ -1286,15 +1290,15 @@ Type* tnext = DtoDType(t->next); Type* vdtype = DtoDType(vd->type); - llvm::Value* llvalue = vd->nestedref ? DtoNestedVariable(vd) : vd->ir.getIrValue(); - llvm::Value* varmem = 0; + LLValue* llvalue = vd->nestedref ? DtoNestedVariable(vd) : vd->ir.getIrValue(); + LLValue* varmem = 0; if (vdtype->ty == Tstruct && !(t->ty == Tpointer && t->next == vdtype)) { Logger::println("struct"); TypeStruct* vdt = (TypeStruct*)vdtype; assert(vdt->sym); - const llvm::Type* llt = DtoType(t); + const LLType* llt = DtoType(t); if (offset == 0) { varmem = p->ir->CreateBitCast(llvalue, llt, "tmp"); } @@ -1309,8 +1313,8 @@ assert(llvalue); //e->arg = llvalue; // TODO - const llvm::Type* llt = DtoType(t); - llvm::Value* off = 0; + const LLType* llt = DtoType(t); + LLValue* off = 0; if (offset != 0) { Logger::println("offset = %d\n", offset); } @@ -1318,7 +1322,7 @@ varmem = llvalue; } else { - const llvm::Type* elemtype = llvalue->getType()->getContainedType(0)->getContainedType(0); + const LLType* elemtype = llvalue->getType()->getContainedType(0)->getContainedType(0); size_t elemsz = getABITypeSize(elemtype); varmem = DtoGEPi(llvalue, 0, offset / elemsz, "tmp"); } @@ -1329,7 +1333,7 @@ assert(llvalue); varmem = llvalue; - const llvm::Type* llt = DtoType(t); + const LLType* llt = DtoType(t); if (llvalue->getType() != llt) { varmem = p->ir->CreateBitCast(varmem, llt, "tmp"); } @@ -1386,8 +1390,8 @@ } // this should be deterministic but right now lvalue casts don't propagate lvalueness !?! - llvm::Value* lv = a->getRVal(); - llvm::Value* v = lv; + LLValue* lv = a->getRVal(); + LLValue* v = lv; if (DtoCanLoad(v)) v = DtoLoad(v); return new DLRValue(e1->type, lv, type, v); @@ -1409,13 +1413,13 @@ //Logger::cout() << *DtoType(e1type) << '\n'; if (VarDeclaration* vd = var->isVarDeclaration()) { - llvm::Value* arrptr; + LLValue* arrptr; if (e1type->ty == Tpointer) { assert(e1type->next->ty == Tstruct); TypeStruct* ts = (TypeStruct*)e1type->next; Logger::println("Struct member offset:%d", vd->offset); - llvm::Value* src = l->getRVal(); + LLValue* src = l->getRVal(); std::vector vdoffsets; arrptr = DtoIndexStruct(src, ts->sym, vd->type, vd->offset, vdoffsets); @@ -1424,7 +1428,7 @@ TypeClass* tc = (TypeClass*)e1type; Logger::println("Class member offset: %d", vd->offset); - llvm::Value* src = l->getRVal(); + LLValue* src = l->getRVal(); std::vector vdoffsets; arrptr = DtoIndexClass(src, tc->sym, vd->type, vd->offset, vdoffsets); @@ -1432,7 +1436,7 @@ /*std::vector vdoffsets(1,0); tc->sym->offsetToIndex(vd->type, vd->offset, vdoffsets); - llvm::Value* src = l->getRVal(); + LLValue* src = l->getRVal(); Logger::println("indices:"); for (size_t i=0; ity == Tclass) { TypeClass* tc = (TypeClass*)e1type; if (tc->sym->isInterfaceDeclaration()) { vthis2 = DtoCastInterfaceToObject(l, NULL)->getRVal(); } } - llvm::Value* vthis = l->getRVal(); + LLValue* vthis = l->getRVal(); if (!vthis2) vthis2 = vthis; //unsigned cc = (unsigned)-1; @@ -1475,8 +1479,8 @@ assert(fdecl->vtblIndex > 0); assert(e1type->ty == Tclass); - llvm::Value* zero = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false); - llvm::Value* vtblidx = llvm::ConstantInt::get(llvm::Type::Int32Ty, (size_t)fdecl->vtblIndex, false); + LLValue* zero = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false); + LLValue* vtblidx = llvm::ConstantInt::get(llvm::Type::Int32Ty, (size_t)fdecl->vtblIndex, false); //Logger::cout() << "vthis: " << *vthis << '\n'; funcval = DtoGEP(vthis, zero, zero, "tmp", p->scopebb()); funcval = new llvm::LoadInst(funcval,"tmp",p->scopebb()); @@ -1514,11 +1518,11 @@ LOG_SCOPE; if (VarDeclaration* vd = var->isVarDeclaration()) { - llvm::Value* v; + LLValue* v; v = p->func()->decl->ir.irFunc->thisVar; if (llvm::isa(v)) v = new llvm::LoadInst(v, "tmp", p->scopebb()); - const llvm::Type* t = DtoType(type); + const LLType* t = DtoType(type); if (v->getType() != t) v = DtoBitCast(v, t, "tmp"); return new DThisValue(vd, v); @@ -1543,10 +1547,10 @@ DValue* r = e2->toElem(p); p->arrays.pop_back(); - llvm::Value* zero = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false); - llvm::Value* one = llvm::ConstantInt::get(llvm::Type::Int32Ty, 1, false); - - llvm::Value* arrptr = 0; + LLValue* zero = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false); + LLValue* one = llvm::ConstantInt::get(llvm::Type::Int32Ty, 1, false); + + LLValue* arrptr = 0; if (e1type->ty == Tpointer) { arrptr = llvm::GetElementPtrInst::Create(l->getRVal(),r->getRVal(),"tmp",p->scopebb()); } @@ -1579,14 +1583,14 @@ Type* e1type = DtoDType(e1->type); DValue* v = e1->toElem(p); - llvm::Value* vmem = v->getRVal(); + LLValue* vmem = v->getRVal(); assert(vmem); - llvm::Value* zero = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false); - llvm::Value* one = llvm::ConstantInt::get(llvm::Type::Int32Ty, 1, false); - - llvm::Value* emem = 0; - llvm::Value* earg = 0; + LLValue* zero = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false); + LLValue* one = llvm::ConstantInt::get(llvm::Type::Int32Ty, 1, false); + + LLValue* emem = 0; + LLValue* earg = 0; // partial slice if (lwr) @@ -1604,7 +1608,7 @@ emem = v->getRVal(); } else if (e1type->ty == Tarray) { - llvm::Value* tmp = DtoGEP(vmem,zero,one,"tmp",p->scopebb()); + LLValue* tmp = DtoGEP(vmem,zero,one,"tmp",p->scopebb()); emem = new llvm::LoadInst(tmp,"tmp",p->scopebb()); } else if (e1type->ty == Tsarray) { @@ -1621,7 +1625,7 @@ else { if (e1type->ty == Tarray) { - llvm::Value* tmp = DtoGEP(vmem,zero,one,"tmp",p->scopebb()); + LLValue* tmp = DtoGEP(vmem,zero,one,"tmp",p->scopebb()); tmp = new llvm::LoadInst(tmp,"tmp",p->scopebb()); emem = llvm::GetElementPtrInst::Create(tmp,lo->getRVal(),"tmp",p->scopebb()); } @@ -1648,8 +1652,8 @@ } else { if (lo->isConst()) { - llvm::Constant* clo = llvm::cast(lo->getRVal()); - llvm::Constant* cup = llvm::cast(cv->c); + LLConstant* clo = llvm::cast(lo->getRVal()); + LLConstant* cup = llvm::cast(cv->c); earg = llvm::ConstantExpr::getSub(cup, clo); } else { @@ -1693,7 +1697,7 @@ Type* e2t = DtoDType(e2->type); assert(DtoType(t) == DtoType(e2t)); - llvm::Value* eval = 0; + LLValue* eval = 0; if (t->isintegral() || t->ty == Tpointer) { @@ -1737,8 +1741,8 @@ } if (!skip) { - llvm::Value* a = l->getRVal(); - llvm::Value* b = r->getRVal(); + LLValue* a = l->getRVal(); + LLValue* b = r->getRVal(); Logger::cout() << "type 1: " << *a << '\n'; Logger::cout() << "type 2: " << *b << '\n'; eval = new llvm::ICmpInst(cmpop, a, b, "tmp", p->scopebb()); @@ -1806,7 +1810,7 @@ Type* e2t = DtoDType(e2->type); //assert(t == e2t); - llvm::Value* eval = 0; + LLValue* eval = 0; if (t->isintegral() || t->ty == Tpointer) { @@ -1823,8 +1827,8 @@ default: assert(0); } - llvm::Value* lv = l->getRVal(); - llvm::Value* rv = r->getRVal(); + LLValue* lv = l->getRVal(); + LLValue* rv = r->getRVal(); if (rv->getType() != lv->getType()) { rv = DtoBitCast(rv, lv->getType()); } @@ -1880,8 +1884,8 @@ DValue* l = e1->toElem(p); DValue* r = e2->toElem(p); - llvm::Value* val = l->getRVal(); - llvm::Value* post = 0; + LLValue* val = l->getRVal(); + LLValue* post = 0; Type* e1type = DtoDType(e1->type); Type* e2type = DtoDType(e2->type); @@ -1889,7 +1893,7 @@ if (e1type->isintegral()) { assert(e2type->isintegral()); - llvm::Value* one = llvm::ConstantInt::get(val->getType(), 1, !e2type->isunsigned()); + LLValue* one = llvm::ConstantInt::get(val->getType(), 1, !e2type->isunsigned()); if (op == TOKplusplus) { post = llvm::BinaryOperator::createAdd(val,one,"tmp",p->scopebb()); } @@ -1900,15 +1904,15 @@ else if (e1type->ty == Tpointer) { assert(e2type->isintegral()); - llvm::Constant* minusone = llvm::ConstantInt::get(DtoSize_t(),(uint64_t)-1,true); - llvm::Constant* plusone = llvm::ConstantInt::get(DtoSize_t(),(uint64_t)1,false); - llvm::Constant* whichone = (op == TOKplusplus) ? plusone : minusone; + LLConstant* minusone = llvm::ConstantInt::get(DtoSize_t(),(uint64_t)-1,true); + LLConstant* plusone = llvm::ConstantInt::get(DtoSize_t(),(uint64_t)1,false); + LLConstant* whichone = (op == TOKplusplus) ? plusone : minusone; post = llvm::GetElementPtrInst::Create(val, whichone, "tmp", p->scopebb()); } else if (e1type->isfloating()) { assert(e2type->isfloating()); - llvm::Value* one = DtoConstFP(e1type, 1.0); + LLValue* one = DtoConstFP(e1type, 1.0); if (op == TOKplusplus) { post = llvm::BinaryOperator::createAdd(val,one,"tmp",p->scopebb()); } @@ -1961,8 +1965,9 @@ // new struct else if (ntype->ty == Tstruct) { + Logger::println("new struct on heap: %s\n", newtype->toChars()); // allocate - llvm::Value* mem = DtoNew(newtype); + LLValue* mem = DtoNew(newtype); // init TypeStruct* ts = (TypeStruct*)ntype; if (ts->isZeroInit()) { @@ -1978,7 +1983,7 @@ else { // allocate - llvm::Value* mem = DtoNew(newtype); + LLValue* mem = DtoNew(newtype); DVarValue tmpvar(newtype, mem, true); // default initialize @@ -2006,7 +2011,7 @@ // simple pointer if (et->ty == Tpointer) { - llvm::Value* rval = dval->getRVal(); + LLValue* rval = dval->getRVal(); DtoDeleteMemory(rval); if (dval->isVar() && dval->isVar()->lval) DtoStore(llvm::Constant::getNullValue(rval->getType()), dval->getLVal()); @@ -2030,11 +2035,11 @@ } } if (!onstack) { - llvm::Value* rval = dval->getRVal(); + LLValue* rval = dval->getRVal(); DtoDeleteClass(rval); } if (!dval->isThis() && dval->isVar() && dval->isVar()->lval) { - llvm::Value* lval = dval->getLVal(); + LLValue* lval = dval->getLVal(); DtoStore(llvm::Constant::getNullValue(lval->getType()->getContainedType(0)), lval); } } @@ -2091,7 +2096,7 @@ llvm::BasicBlock* endbb = llvm::BasicBlock::Create("noassert", p->topfunc(), oldend); // test condition - llvm::Value* condval = cond->getRVal(); + LLValue* condval = cond->getRVal(); condval = DtoBoolean(condval); // branch @@ -2120,9 +2125,9 @@ DValue* u = e1->toElem(p); - llvm::Value* b = DtoBoolean(u->getRVal()); - - llvm::Constant* zero = llvm::ConstantInt::get(llvm::Type::Int1Ty, 0, true); + LLValue* b = DtoBoolean(u->getRVal()); + + LLConstant* zero = llvm::ConstantInt::get(llvm::Type::Int1Ty, 0, true); b = p->ir->CreateICmpEQ(b,zero); return new DImValue(type, b); @@ -2136,7 +2141,7 @@ LOG_SCOPE; // allocate a temporary for the final result. failed to come up with a better way :/ - llvm::Value* resval = 0; + LLValue* resval = 0; llvm::BasicBlock* entryblock = &p->topfunc()->front(); resval = new llvm::AllocaInst(llvm::Type::Int1Ty,"andandtmp",p->topallocapoint()); @@ -2146,15 +2151,15 @@ llvm::BasicBlock* andand = llvm::BasicBlock::Create("andand", gIR->topfunc(), oldend); llvm::BasicBlock* andandend = llvm::BasicBlock::Create("andandend", gIR->topfunc(), oldend); - llvm::Value* ubool = DtoBoolean(u->getRVal()); + LLValue* ubool = DtoBoolean(u->getRVal()); new llvm::StoreInst(ubool,resval,p->scopebb()); llvm::BranchInst::Create(andand,andandend,ubool,p->scopebb()); p->scope() = IRScope(andand, andandend); DValue* v = e2->toElem(p); - llvm::Value* vbool = DtoBoolean(v->getRVal()); - llvm::Value* uandvbool = llvm::BinaryOperator::create(llvm::BinaryOperator::And, ubool, vbool,"tmp",p->scopebb()); + LLValue* vbool = DtoBoolean(v->getRVal()); + LLValue* uandvbool = llvm::BinaryOperator::create(llvm::BinaryOperator::And, ubool, vbool,"tmp",p->scopebb()); new llvm::StoreInst(uandvbool,resval,p->scopebb()); llvm::BranchInst::Create(andandend,p->scopebb()); @@ -2172,7 +2177,7 @@ LOG_SCOPE; // allocate a temporary for the final result. failed to come up with a better way :/ - llvm::Value* resval = 0; + LLValue* resval = 0; llvm::BasicBlock* entryblock = &p->topfunc()->front(); resval = new llvm::AllocaInst(llvm::Type::Int1Ty,"orortmp",p->topallocapoint()); @@ -2182,14 +2187,14 @@ llvm::BasicBlock* oror = llvm::BasicBlock::Create("oror", gIR->topfunc(), oldend); llvm::BasicBlock* ororend = llvm::BasicBlock::Create("ororend", gIR->topfunc(), oldend); - llvm::Value* ubool = DtoBoolean(u->getRVal()); + LLValue* ubool = DtoBoolean(u->getRVal()); new llvm::StoreInst(ubool,resval,p->scopebb()); llvm::BranchInst::Create(ororend,oror,ubool,p->scopebb()); p->scope() = IRScope(oror, ororend); DValue* v = e2->toElem(p); - llvm::Value* vbool = DtoBoolean(v->getRVal()); + LLValue* vbool = DtoBoolean(v->getRVal()); new llvm::StoreInst(vbool,resval,p->scopebb()); llvm::BranchInst::Create(ororend,p->scopebb()); @@ -2208,7 +2213,7 @@ LOG_SCOPE; \ DValue* u = e1->toElem(p); \ DValue* v = e2->toElem(p); \ - llvm::Value* x = llvm::BinaryOperator::create(llvm::Instruction::Y, u->getRVal(), v->getRVal(), "tmp", p->scopebb()); \ + LLValue* x = llvm::BinaryOperator::create(llvm::Instruction::Y, u->getRVal(), v->getRVal(), "tmp", p->scopebb()); \ return new DImValue(type, x); \ } \ \ @@ -2221,9 +2226,9 @@ p->topexp()->v = u; \ DValue* v = e2->toElem(p); \ p->exps.pop_back(); \ - llvm::Value* uval = u->getRVal(); \ - llvm::Value* vval = v->getRVal(); \ - llvm::Value* tmp = llvm::BinaryOperator::create(llvm::Instruction::Y, uval, vval, "tmp", p->scopebb()); \ + LLValue* uval = u->getRVal(); \ + LLValue* vval = v->getRVal(); \ + LLValue* tmp = llvm::BinaryOperator::create(llvm::Instruction::Y, uval, vval, "tmp", p->scopebb()); \ new llvm::StoreInst(DtoPointedType(u->getLVal(), tmp), u->getLVal(), p->scopebb()); \ return u; \ } @@ -2257,7 +2262,7 @@ const llvm::PointerType* int8ptrty = getPtrToType(llvm::Type::Int8Ty); - llvm::Value* lval; + LLValue* lval; bool inplace = false; if (p->topexp() && p->topexp()->e2 == this) { assert(p->topexp()->v); @@ -2269,11 +2274,11 @@ } DValue* u = e1->toElem(p); - llvm::Value* uval; + LLValue* uval; if (DFuncValue* f = u->isFunc()) { //assert(f->vthis); //uval = f->vthis; - llvm::Value* nestvar = p->func()->decl->ir.irFunc->nestedVar; + LLValue* nestvar = p->func()->decl->ir.irFunc->nestedVar; if (nestvar) uval = nestvar; else @@ -2295,15 +2300,15 @@ Logger::cout() << "context = " << *uval << '\n'; - llvm::Value* context = DtoGEPi(lval,0,0,"tmp"); - llvm::Value* castcontext = DtoBitCast(uval, int8ptrty); + LLValue* context = DtoGEPi(lval,0,0,"tmp"); + LLValue* castcontext = DtoBitCast(uval, int8ptrty); DtoStore(castcontext, context); - llvm::Value* fptr = DtoGEPi(lval,0,1,"tmp"); + LLValue* fptr = DtoGEPi(lval,0,1,"tmp"); Logger::println("func: '%s'", func->toPrettyChars()); - llvm::Value* castfptr; + LLValue* castfptr; if (func->isVirtual()) castfptr = DtoVirtualFunctionPointer(u, func); else if (func->isAbstract()) @@ -2332,12 +2337,12 @@ DValue* u = e1->toElem(p); DValue* v = e2->toElem(p); - llvm::Value* l = u->getRVal(); - llvm::Value* r = v->getRVal(); + LLValue* l = u->getRVal(); + LLValue* r = v->getRVal(); Type* t1 = DtoDType(e1->type); - llvm::Value* eval = 0; + LLValue* eval = 0; if (t1->ty == Tarray) { if (v->isNull()) { @@ -2402,11 +2407,11 @@ LOG_SCOPE; Type* dtype = DtoDType(type); - const llvm::Type* resty = DtoType(dtype); + const LLType* resty = DtoType(dtype); // allocate a temporary for the final result. failed to come up with a better way :/ llvm::BasicBlock* entryblock = &p->topfunc()->front(); - llvm::Value* resval = new llvm::AllocaInst(resty,"condtmp",p->topallocapoint()); + LLValue* resval = new llvm::AllocaInst(resty,"condtmp",p->topallocapoint()); DVarValue* dvv = new DVarValue(type, resval, true); llvm::BasicBlock* oldend = p->scopeend(); @@ -2415,7 +2420,7 @@ llvm::BasicBlock* condend = llvm::BasicBlock::Create("condend", gIR->topfunc(), oldend); DValue* c = econd->toElem(p); - llvm::Value* cond_val = DtoBoolean(c->getRVal()); + LLValue* cond_val = DtoBoolean(c->getRVal()); llvm::BranchInst::Create(condtrue,condfalse,cond_val,p->scopebb()); p->scope() = IRScope(condtrue, condfalse); @@ -2441,8 +2446,8 @@ DValue* u = e1->toElem(p); - llvm::Value* value = u->getRVal(); - llvm::Value* minusone = llvm::ConstantInt::get(value->getType(), -1, true); + LLValue* value = u->getRVal(); + LLValue* minusone = llvm::ConstantInt::get(value->getType(), -1, true); value = llvm::BinaryOperator::create(llvm::Instruction::Xor, value, minusone, "tmp", p->scopebb()); return new DImValue(type, value); @@ -2461,10 +2466,10 @@ return DtoComplexNeg(type, l); } - llvm::Value* val = l->getRVal(); + LLValue* val = l->getRVal(); Type* t = DtoDType(type); - llvm::Value* zero = 0; + LLValue* zero = 0; if (t->isintegral()) zero = llvm::ConstantInt::get(val->getType(), 0, true); else if (t->isfloating()) { @@ -2512,8 +2517,8 @@ } else { assert(t->ty == Tarray); - const llvm::Type* arrty = DtoType(t); - llvm::Value* dst = new llvm::AllocaInst(arrty, "tmpmem", p->topallocapoint()); + const LLType* arrty = DtoType(t); + LLValue* dst = new llvm::AllocaInst(arrty, "tmpmem", p->topallocapoint()); if (arrNarr) DtoCatAr DtoCatArrays(dst,e1,e2); @@ -2566,34 +2571,34 @@ DtoForceDefineDsymbol(fd); bool temp = false; - llvm::Value* lval = NULL; + LLValue* lval = NULL; if (p->topexp() && p->topexp()->e2 == this) { assert(p->topexp()->v); lval = p->topexp()->v->getLVal(); } else { - const llvm::Type* dgty = DtoType(type); + const LLType* dgty = DtoType(type); Logger::cout() << "delegate without explicit storage:" << '\n' << *dgty << '\n'; lval = new llvm::AllocaInst(dgty,"dgstorage",p->topallocapoint()); temp = true; } - llvm::Value* context = DtoGEPi(lval,0,0,"tmp",p->scopebb()); + LLValue* context = DtoGEPi(lval,0,0,"tmp",p->scopebb()); const llvm::PointerType* pty = isaPointer(context->getType()->getContainedType(0)); - llvm::Value* llvmNested = p->func()->decl->ir.irFunc->nestedVar; + LLValue* llvmNested = p->func()->decl->ir.irFunc->nestedVar; if (llvmNested == NULL) { - llvm::Value* nullcontext = llvm::ConstantPointerNull::get(pty); + LLValue* nullcontext = llvm::ConstantPointerNull::get(pty); p->ir->CreateStore(nullcontext, context); } else { - llvm::Value* nestedcontext = p->ir->CreateBitCast(llvmNested, pty, "tmp"); + LLValue* nestedcontext = p->ir->CreateBitCast(llvmNested, pty, "tmp"); p->ir->CreateStore(nestedcontext, context); } - llvm::Value* fptr = DtoGEPi(lval,0,1,"tmp",p->scopebb()); + LLValue* fptr = DtoGEPi(lval,0,1,"tmp",p->scopebb()); assert(fd->ir.irFunc->func); - llvm::Value* castfptr = new llvm::BitCastInst(fd->ir.irFunc->func,fptr->getType()->getContainedType(0),"tmp",p->scopebb()); + LLValue* castfptr = DtoBitCast(fd->ir.irFunc->func,fptr->getType()->getContainedType(0)); new llvm::StoreInst(castfptr, fptr, p->scopebb()); if (temp) @@ -2621,15 +2626,15 @@ bool sliceInPlace = false; // llvm target type - const llvm::Type* llType = DtoType(arrayType); + const LLType* llType = DtoType(arrayType); Logger::cout() << (dyn?"dynamic":"static") << " array literal with length " << len << " of D type: '" << arrayType->toChars() << "' has llvm type: '" << *llType << "'\n"; // llvm storage type - const llvm::Type* llStoType = llvm::ArrayType::get(DtoType(elemType), len); + const LLType* llStoType = llvm::ArrayType::get(DtoType(elemType), len); Logger::cout() << "llvm storage type: '" << *llStoType << "'\n"; // dst pointer - llvm::Value* dstMem = 0; + LLValue* dstMem = 0; // rvalue of assignment if (p->topexp() && p->topexp()->e2 == this) @@ -2661,7 +2666,7 @@ for (size_t i=0; idata[i]; - llvm::Value* elemAddr = DtoGEPi(dstMem,0,i,"tmp",p->scopebb()); + LLValue* elemAddr = DtoGEPi(dstMem,0,i,"tmp",p->scopebb()); // emulate assignment DVarValue* vv = new DVarValue(expr->type, elemAddr, true); @@ -2683,18 +2688,18 @@ ////////////////////////////////////////////////////////////////////////////////////////// -llvm::Constant* ArrayLiteralExp::toConstElem(IRState* p) +LLConstant* ArrayLiteralExp::toConstElem(IRState* p) { Logger::print("ArrayLiteralExp::toConstElem: %s | %s\n", toChars(), type->toChars()); LOG_SCOPE; - const llvm::Type* t = DtoType(type); + const LLType* t = DtoType(type); Logger::cout() << "array literal has llvm type: " << *t << '\n'; assert(isaArray(t)); const llvm::ArrayType* arrtype = isaArray(t); assert(arrtype->getNumElements() == elements->dim); - std::vector vals(elements->dim, NULL); + std::vector vals(elements->dim, NULL); for (unsigned i=0; idim; ++i) { Expression* expr = (Expression*)elements->data[i]; @@ -2711,10 +2716,10 @@ Logger::print("StructLiteralExp::toElem: %s | %s\n", toChars(), type->toChars()); LOG_SCOPE; - llvm::Value* sptr; - const llvm::Type* llt = DtoType(type); - - llvm::Value* mem = 0; + LLValue* sptr; + const LLType* llt = DtoType(type); + + LLValue* mem = 0; // temporary struct literal if (!p->topexp() || p->topexp()->e2 != this) @@ -2734,7 +2739,7 @@ // unions might have different types for each literal if (sd->ir.irStruct->hasUnions) { // build the type of the literal - std::vector tys; + std::vector tys; for (unsigned i=0; idata[i]; if (!vx) continue; @@ -2759,7 +2764,7 @@ if (!vx) continue; Logger::cout() << "getting index " << j << " of " << *sptr << '\n'; - llvm::Value* arrptr = DtoGEPi(sptr,0,j,"tmp",p->scopebb()); + LLValue* arrptr = DtoGEPi(sptr,0,j,"tmp",p->scopebb()); DValue* darrptr = new DVarValue(vx->type, arrptr, true); p->exps.push_back(IRExp(NULL,vx,darrptr)); @@ -2777,13 +2782,13 @@ ////////////////////////////////////////////////////////////////////////////////////////// -llvm::Constant* StructLiteralExp::toConstElem(IRState* p) +LLConstant* StructLiteralExp::toConstElem(IRState* p) { Logger::print("StructLiteralExp::toConstElem: %s | %s\n", toChars(), type->toChars()); LOG_SCOPE; unsigned n = elements->dim; - std::vector vals(n, NULL); + std::vector vals(n, NULL); for (unsigned i=0; ity == Tstruct); - const llvm::Type* t = DtoType(type); + const LLType* t = DtoType(type); const llvm::StructType* st = isaStruct(t); return llvm::ConstantStruct::get(st,vals); } @@ -2844,7 +2849,7 @@ } else { - llvm::Value* tmp = new llvm::AllocaInst(DtoType(type),"aaliteral",p->topallocapoint()); + LLValue* tmp = new llvm::AllocaInst(DtoType(type),"aaliteral",p->topallocapoint()); aa = new DVarValue(type, tmp, true); } @@ -2945,7 +2950,7 @@ //STUB(StructLiteralExp); STUB(TupleExp); -#define CONSTSTUB(x) llvm::Constant* x::toConstElem(IRState * p) {error("const Exp type "#x" not implemented: '%s' type: '%s'", toChars(), type->toChars()); fatal(); return NULL; } +#define CONSTSTUB(x) LLConstant* x::toConstElem(IRState * p) {error("const Exp type "#x" not implemented: '%s' type: '%s'", toChars(), type->toChars()); fatal(); return NULL; } CONSTSTUB(Expression); //CONSTSTUB(IntegerExp); //CONSTSTUB(RealExp); diff -r 4c2689d57ba4 -r 7816aafeea3c gen/tollvm.cpp --- a/gen/tollvm.cpp Tue May 27 22:14:24 2008 +0200 +++ b/gen/tollvm.cpp Fri May 30 19:32:04 2008 +0200 @@ -36,7 +36,7 @@ return t; } -const llvm::Type* DtoType(Type* t) +const LLType* DtoType(Type* t) { assert(t); switch (t->ty) @@ -45,21 +45,21 @@ case Tint8: case Tuns8: case Tchar: - return (const llvm::Type*)llvm::Type::Int8Ty; + return (const LLType*)llvm::Type::Int8Ty; case Tint16: case Tuns16: case Twchar: - return (const llvm::Type*)llvm::Type::Int16Ty; + return (const LLType*)llvm::Type::Int16Ty; case Tint32: case Tuns32: case Tdchar: - return (const llvm::Type*)llvm::Type::Int32Ty; + return (const LLType*)llvm::Type::Int32Ty; case Tint64: case Tuns64: - return (const llvm::Type*)llvm::Type::Int64Ty; + return (const LLType*)llvm::Type::Int64Ty; case Tbool: - return (const llvm::Type*)llvm::ConstantInt::getTrue()->getType(); + return (const LLType*)llvm::ConstantInt::getTrue()->getType(); // floats case Tfloat32: @@ -81,9 +81,9 @@ case Tpointer: { assert(t->next); if (t->next->ty == Tvoid) - return (const llvm::Type*)getPtrToType(llvm::Type::Int8Ty); + return (const LLType*)getPtrToType(llvm::Type::Int8Ty); else - return (const llvm::Type*)getPtrToType(DtoType(t->next)); + return (const LLType*)getPtrToType(DtoType(t->next)); } // arrays @@ -178,7 +178,7 @@ case Taarray: { TypeAArray* taa = (TypeAArray*)t; - std::vector types; + std::vector types; types.push_back(DtoType(taa->key)); types.push_back(DtoType(taa->next)); return getPtrToType(llvm::StructType::get(types)); @@ -195,11 +195,11 @@ const llvm::StructType* DtoDelegateType(Type* t) { - const llvm::Type* i8ptr = getPtrToType(llvm::Type::Int8Ty); - const llvm::Type* func = DtoFunctionType(t->next, i8ptr); - const llvm::Type* funcptr = getPtrToType(func); + const LLType* i8ptr = getPtrToType(llvm::Type::Int8Ty); + const LLType* func = DtoFunctionType(t->next, i8ptr); + const LLType* funcptr = getPtrToType(func); - std::vector types; + std::vector types; types.push_back(i8ptr); types.push_back(funcptr); return llvm::StructType::get(types); @@ -207,20 +207,21 @@ ////////////////////////////////////////////////////////////////////////////////////////// +/* static llvm::Function* LLVM_DeclareMemIntrinsic(const char* name, int bits, bool set=false) { assert(bits == 32 || bits == 64); - const llvm::Type* int8ty = (const llvm::Type*)llvm::Type::Int8Ty; - const llvm::Type* int32ty = (const llvm::Type*)llvm::Type::Int32Ty; - const llvm::Type* int64ty = (const llvm::Type*)llvm::Type::Int64Ty; - const llvm::Type* int8ptrty = (const llvm::Type*)getPtrToType(llvm::Type::Int8Ty); - const llvm::Type* voidty = (const llvm::Type*)llvm::Type::VoidTy; + const LLType* int8ty = (const LLType*)llvm::Type::Int8Ty; + const LLType* int32ty = (const LLType*)llvm::Type::Int32Ty; + const LLType* int64ty = (const LLType*)llvm::Type::Int64Ty; + const LLType* int8ptrty = (const LLType*)getPtrToType(llvm::Type::Int8Ty); + const LLType* voidty = (const LLType*)llvm::Type::VoidTy; assert(gIR); assert(gIR->module); // parameter types - std::vector pvec; + std::vector pvec; pvec.push_back(int8ptrty); pvec.push_back(set?int8ty:int8ptrty); pvec.push_back(bits==32?int32ty:int64ty); @@ -228,26 +229,21 @@ llvm::FunctionType* functype = llvm::FunctionType::get(voidty, pvec, false); return llvm::cast(gIR->module->getOrInsertFunction(name, functype)); } +*/ ////////////////////////////////////////////////////////////////////////////////////////// // llvm.memset.i32 llvm::Function* LLVM_DeclareMemSet32() { - if (gIR->llvm_DeclareMemSet32 == 0) { - gIR->llvm_DeclareMemSet32 = LLVM_DeclareMemIntrinsic("llvm.memset.i32", 32, true); - } - return gIR->llvm_DeclareMemSet32; + return GET_INTRINSIC_DECL(memset_i32); } ////////////////////////////////////////////////////////////////////////////////////////// llvm::Function* LLVM_DeclareMemSet64() { - if (gIR->llvm_DeclareMemSet64 == 0) { - gIR->llvm_DeclareMemSet64 = LLVM_DeclareMemIntrinsic("llvm.memset.i64", 64, true); - } - return gIR->llvm_DeclareMemSet64; + return GET_INTRINSIC_DECL(memset_i64); } ////////////////////////////////////////////////////////////////////////////////////////// @@ -255,10 +251,7 @@ // llvm.memcpy.i32 llvm::Function* LLVM_DeclareMemCpy32() { - if (gIR->llvm_DeclareMemCpy32 == 0) { - gIR->llvm_DeclareMemCpy32 = LLVM_DeclareMemIntrinsic("llvm.memcpy.i32", 32); - } - return gIR->llvm_DeclareMemCpy32; + return GET_INTRINSIC_DECL(memcpy_i32); } ////////////////////////////////////////////////////////////////////////////////////////// @@ -266,35 +259,15 @@ // llvm.memcpy.i64 llvm::Function* LLVM_DeclareMemCpy64() { - if (gIR->llvm_DeclareMemCpy64 == 0) { - gIR->llvm_DeclareMemCpy64 = LLVM_DeclareMemIntrinsic("llvm.memcpy.i64", 64); - } - return gIR->llvm_DeclareMemCpy64; -} - -// llvm.memory.barrier -static llvm::Function* LLVM_DeclareMemBarrier() -{ - if (gIR->llvm_DeclareMemBarrier == 0) { - std::vector pvec; - pvec.push_back(llvm::Type::Int1Ty); - pvec.push_back(llvm::Type::Int1Ty); - pvec.push_back(llvm::Type::Int1Ty); - pvec.push_back(llvm::Type::Int1Ty); - pvec.push_back(llvm::Type::Int1Ty); - llvm::FunctionType* functype = llvm::FunctionType::get(llvm::Type::VoidTy, pvec, false); - gIR->llvm_DeclareMemBarrier = llvm::cast(gIR->module->getOrInsertFunction("llvm.memory.barrier", functype)); - assert(gIR->llvm_DeclareMemBarrier != NULL); - } - return gIR->llvm_DeclareMemBarrier; + return GET_INTRINSIC_DECL(memcpy_i64); } void DtoMemoryBarrier(bool ll, bool ls, bool sl, bool ss, bool device) { - llvm::Function* fn = LLVM_DeclareMemBarrier(); + llvm::Function* fn = GET_INTRINSIC_DECL(memory_barrier); assert(fn != NULL); - llvm::SmallVector llargs; + LLSmallVector llargs; llargs.push_back(DtoConstBool(ll)); llargs.push_back(DtoConstBool(ls)); llargs.push_back(DtoConstBool(sl)); @@ -306,64 +279,39 @@ ////////////////////////////////////////////////////////////////////////////////////////// -llvm::Value* DtoDelegateToNull(llvm::Value* v) +void DtoDelegateToNull(LLValue* v) { - assert(gIR); - d_uns64 n = (global.params.is64bit) ? 16 : 8; - - const llvm::Type* i8p_ty = getPtrToType(llvm::Type::Int8Ty); - - llvm::Value* arr = new llvm::BitCastInst(v,i8p_ty,"tmp",gIR->scopebb()); - - llvm::Function* fn = LLVM_DeclareMemSet32(); - std::vector llargs; - llargs.resize(4); - llargs[0] = arr; - llargs[1] = llvm::ConstantInt::get(llvm::Type::Int8Ty, 0, false); - llargs[2] = llvm::ConstantInt::get(llvm::Type::Int32Ty, n, false); - llargs[3] = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false); - - llvm::Value* ret = llvm::CallInst::Create(fn, llargs.begin(), llargs.end(), "", gIR->scopebb()); - - return ret; + LLSmallVector args; + args.push_back(DtoBitCast(v, getVoidPtrType())); + args.push_back(llvm::Constant::getNullValue(llvm::Type::Int8Ty)); + args.push_back(DtoConstInt(global.params.is64bit ? 16 : 8)); + args.push_back(DtoConstInt(0)); + gIR->ir->CreateCall(GET_INTRINSIC_DECL(memset_i32), args.begin(), args.end(), ""); } ////////////////////////////////////////////////////////////////////////////////////////// -llvm::Value* DtoDelegateCopy(llvm::Value* dst, llvm::Value* src) +void DtoDelegateCopy(LLValue* dst, LLValue* src) { - assert(dst->getType() == src->getType()); - assert(gIR); - - d_uns64 n = (global.params.is64bit) ? 16 : 8; - - const llvm::Type* arrty = getPtrToType(llvm::Type::Int8Ty); - - llvm::Value* dstarr = new llvm::BitCastInst(dst,arrty,"tmp",gIR->scopebb()); - llvm::Value* srcarr = new llvm::BitCastInst(src,arrty,"tmp",gIR->scopebb()); - - llvm::Function* fn = LLVM_DeclareMemCpy32(); - std::vector llargs; - llargs.resize(4); - llargs[0] = dstarr; - llargs[1] = srcarr; - llargs[2] = llvm::ConstantInt::get(llvm::Type::Int32Ty, n, false); - llargs[3] = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false); - - return llvm::CallInst::Create(fn, llargs.begin(), llargs.end(), "", gIR->scopebb()); + LLSmallVector args; + args.push_back(DtoBitCast(dst,getVoidPtrType())); + args.push_back(DtoBitCast(src,getVoidPtrType())); + args.push_back(DtoConstInt(global.params.is64bit ? 16 : 8)); + args.push_back(DtoConstInt(0)); + gIR->ir->CreateCall(GET_INTRINSIC_DECL(memcpy_i32), args.begin(), args.end(), ""); } ////////////////////////////////////////////////////////////////////////////////////////// -llvm::Value* DtoDelegateCompare(TOK op, llvm::Value* lhs, llvm::Value* rhs) +LLValue* DtoDelegateCompare(TOK op, LLValue* lhs, LLValue* rhs) { Logger::println("Doing delegate compare"); llvm::ICmpInst::Predicate pred = (op == TOKequal || op == TOKidentity) ? llvm::ICmpInst::ICMP_EQ : llvm::ICmpInst::ICMP_NE; llvm::Value *b1, *b2; if (rhs == NULL) { - llvm::Value* l = gIR->ir->CreateLoad(DtoGEPi(lhs,0,0,"tmp"),"tmp"); - llvm::Value* r = llvm::Constant::getNullValue(l->getType()); + LLValue* l = gIR->ir->CreateLoad(DtoGEPi(lhs,0,0,"tmp"),"tmp"); + LLValue* r = llvm::Constant::getNullValue(l->getType()); b1 = gIR->ir->CreateICmp(pred,l,r,"tmp"); l = gIR->ir->CreateLoad(DtoGEPi(lhs,0,1,"tmp"),"tmp"); r = llvm::Constant::getNullValue(l->getType()); @@ -371,14 +319,14 @@ } else { - llvm::Value* l = gIR->ir->CreateLoad(DtoGEPi(lhs,0,0,"tmp"),"tmp"); - llvm::Value* r = gIR->ir->CreateLoad(DtoGEPi(rhs,0,0,"tmp"),"tmp"); + LLValue* l = gIR->ir->CreateLoad(DtoGEPi(lhs,0,0,"tmp"),"tmp"); + LLValue* r = gIR->ir->CreateLoad(DtoGEPi(rhs,0,0,"tmp"),"tmp"); b1 = gIR->ir->CreateICmp(pred,l,r,"tmp"); l = gIR->ir->CreateLoad(DtoGEPi(lhs,0,1,"tmp"),"tmp"); r = gIR->ir->CreateLoad(DtoGEPi(rhs,0,1,"tmp"),"tmp"); b2 = gIR->ir->CreateICmp(pred,l,r,"tmp"); } - llvm::Value* b = gIR->ir->CreateAnd(b1,b2,"tmp"); + LLValue* b = gIR->ir->CreateAnd(b1,b2,"tmp"); if (op == TOKnotequal || op == TOKnotidentity) return gIR->ir->CreateNot(b,"tmp"); return b; @@ -467,10 +415,10 @@ ////////////////////////////////////////////////////////////////////////////////////////// -llvm::Value* DtoPointedType(llvm::Value* ptr, llvm::Value* val) +LLValue* DtoPointedType(LLValue* ptr, LLValue* val) { - const llvm::Type* ptrTy = ptr->getType()->getContainedType(0); - const llvm::Type* valTy = val->getType(); + const LLType* ptrTy = ptr->getType()->getContainedType(0); + const LLType* valTy = val->getType(); // ptr points to val's type if (ptrTy == valTy) { @@ -500,20 +448,20 @@ ////////////////////////////////////////////////////////////////////////////////////////// -llvm::Value* DtoBoolean(llvm::Value* val) +LLValue* DtoBoolean(LLValue* val) { - const llvm::Type* t = val->getType(); + const LLType* t = val->getType(); if (t->isInteger()) { if (t == llvm::Type::Int1Ty) return val; else { - llvm::Value* zero = llvm::ConstantInt::get(t, 0, false); + LLValue* zero = llvm::ConstantInt::get(t, 0, false); return new llvm::ICmpInst(llvm::ICmpInst::ICMP_NE, val, zero, "tmp", gIR->scopebb()); } } else if (isaPointer(t)) { - llvm::Value* zero = llvm::Constant::getNullValue(t); + LLValue* zero = llvm::Constant::getNullValue(t); return new llvm::ICmpInst(llvm::ICmpInst::ICMP_NE, val, zero, "tmp", gIR->scopebb()); } else @@ -526,7 +474,7 @@ ////////////////////////////////////////////////////////////////////////////////////////// -const llvm::Type* DtoSize_t() +const LLType* DtoSize_t() { if (global.params.is64bit) return llvm::Type::Int64Ty; @@ -536,9 +484,9 @@ ////////////////////////////////////////////////////////////////////////////////////////// -llvm::Constant* DtoConstInitializer(Type* type, Initializer* init) +LLConstant* DtoConstInitializer(Type* type, Initializer* init) { - llvm::Constant* _init = 0; // may return zero + LLConstant* _init = 0; // may return zero if (!init) { Logger::println("const default initializer for %s", type->toChars()); @@ -562,7 +510,7 @@ else if (init->isVoidInitializer()) { Logger::println("const void initializer"); - const llvm::Type* ty = DtoType(type); + const LLType* ty = DtoType(type); _init = llvm::Constant::getNullValue(ty); } else { @@ -573,14 +521,14 @@ ////////////////////////////////////////////////////////////////////////////////////////// -llvm::Constant* DtoConstFieldInitializer(Type* t, Initializer* init) +LLConstant* DtoConstFieldInitializer(Type* t, Initializer* init) { Logger::println("DtoConstFieldInitializer"); LOG_SCOPE; - const llvm::Type* _type = DtoType(t); + const LLType* _type = DtoType(t); - llvm::Constant* _init = DtoConstInitializer(t, init); + LLConstant* _init = DtoConstInitializer(t, init); assert(_init); if (_type != _init->getType()) { @@ -589,7 +537,7 @@ { const llvm::ArrayType* arrty = isaArray(_type); uint64_t n = arrty->getNumElements(); - std::vector vals(n,_init); + std::vector vals(n,_init); _init = llvm::ConstantArray::get(arrty, vals); } else if (t->ty == Tarray) @@ -642,9 +590,9 @@ ////////////////////////////////////////////////////////////////////////////////////////// -llvm::Value* DtoGEP(llvm::Value* ptr, llvm::Value* i0, llvm::Value* i1, const std::string& var, llvm::BasicBlock* bb) +LLValue* DtoGEP(LLValue* ptr, LLValue* i0, LLValue* i1, const std::string& var, llvm::BasicBlock* bb) { - std::vector v(2); + std::vector v(2); v[0] = i0; v[1] = i1; Logger::cout() << "DtoGEP: " << *ptr << ", " << *i0 << ", " << *i1 << '\n'; @@ -653,10 +601,10 @@ ////////////////////////////////////////////////////////////////////////////////////////// -llvm::Value* DtoGEP(llvm::Value* ptr, const std::vector& src, const std::string& var, llvm::BasicBlock* bb) +LLValue* DtoGEP(LLValue* ptr, const std::vector& src, const std::string& var, llvm::BasicBlock* bb) { size_t n = src.size(); - std::vector dst(n, NULL); + std::vector dst(n, NULL); //std::ostream& ostr = Logger::cout(); //ostr << "indices for '" << *ptr << "':"; for (size_t i=0; iscopebb()); } ////////////////////////////////////////////////////////////////////////////////////////// -llvm::Value* DtoGEPi(llvm::Value* ptr, unsigned i0, unsigned i1, const std::string& var, llvm::BasicBlock* bb) +LLValue* DtoGEPi(LLValue* ptr, unsigned i0, unsigned i1, const std::string& var, llvm::BasicBlock* bb) { - std::vector v(2); + std::vector v(2); v[0] = llvm::ConstantInt::get(llvm::Type::Int32Ty, i0, false); v[1] = llvm::ConstantInt::get(llvm::Type::Int32Ty, i1, false); return llvm::GetElementPtrInst::Create(ptr, v.begin(), v.end(), var, bb?bb:gIR->scopebb()); @@ -687,50 +635,50 @@ ////////////////////////////////////////////////////////////////////////////////////////// -llvm::Value* DtoNew(Type* newtype) +LLValue* DtoNew(Type* newtype) { // get runtime function llvm::Function* fn = LLVM_D_GetRuntimeFunction(gIR->module, "_d_allocmemoryT"); // get type info - llvm::Constant* ti = DtoTypeInfoOf(newtype); + LLConstant* ti = DtoTypeInfoOf(newtype); assert(isaPointer(ti)); // call runtime - llvm::SmallVector arg; + LLSmallVector arg; arg.push_back(ti); // allocate - llvm::Value* mem = gIR->ir->CreateCall(fn, arg.begin(), arg.end(), ".gc_mem"); + LLValue* mem = gIR->ir->CreateCall(fn, arg.begin(), arg.end(), ".gc_mem"); // cast return DtoBitCast(mem, getPtrToType(DtoType(newtype)), ".gc_mem"); } -void DtoDeleteMemory(llvm::Value* ptr) +void DtoDeleteMemory(LLValue* ptr) { // get runtime function llvm::Function* fn = LLVM_D_GetRuntimeFunction(gIR->module, "_d_delmemory"); // build args - llvm::SmallVector arg; + LLSmallVector arg; arg.push_back(DtoBitCast(ptr, getVoidPtrType(), ".tmp")); // call llvm::CallInst::Create(fn, arg.begin(), arg.end(), "", gIR->scopebb()); } -void DtoDeleteClass(llvm::Value* inst) +void DtoDeleteClass(LLValue* inst) { // get runtime function llvm::Function* fn = LLVM_D_GetRuntimeFunction(gIR->module, "_d_delclass"); // build args - llvm::SmallVector arg; + LLSmallVector arg; arg.push_back(DtoBitCast(inst, fn->getFunctionType()->getParamType(0), ".tmp")); // call llvm::CallInst::Create(fn, arg.begin(), arg.end(), "", gIR->scopebb()); } -void DtoDeleteInterface(llvm::Value* inst) +void DtoDeleteInterface(LLValue* inst) { // get runtime function llvm::Function* fn = LLVM_D_GetRuntimeFunction(gIR->module, "_d_delinterface"); // build args - llvm::SmallVector arg; + LLSmallVector arg; arg.push_back(DtoBitCast(inst, fn->getFunctionType()->getParamType(0), ".tmp")); // call llvm::CallInst::Create(fn, arg.begin(), arg.end(), "", gIR->scopebb()); @@ -741,7 +689,7 @@ // get runtime function llvm::Function* fn = LLVM_D_GetRuntimeFunction(gIR->module, "_d_delarray"); // build args - llvm::SmallVector arg; + LLSmallVector arg; arg.push_back(DtoArrayLen(arr)); arg.push_back(DtoBitCast(DtoArrayPtr(arr), getVoidPtrType(), ".tmp")); // call @@ -752,8 +700,8 @@ void DtoAssert(Loc* loc, DValue* msg) { - std::vector args; - llvm::Constant* c; + std::vector args; + LLConstant* c; // func const char* fname = msg ? "_d_assert_msg" : "_d_assert"; @@ -788,7 +736,7 @@ alloc = new llvm::AllocaInst(c->getType(), ".srcfile", gIR->topallocapoint()); gIR->func()->srcfileArg = alloc; } - llvm::Value* ptr = DtoGEPi(alloc, 0,0, "tmp"); + LLValue* ptr = DtoGEPi(alloc, 0,0, "tmp"); DtoStore(c->getOperand(0), ptr); ptr = DtoGEPi(alloc, 0,1, "tmp"); DtoStore(c->getOperand(1), ptr); @@ -804,7 +752,7 @@ ////////////////////////////////////////////////////////////////////////////////////////// -static const llvm::Type* get_next_frame_ptr_type(Dsymbol* sc) +static const LLType* get_next_frame_ptr_type(Dsymbol* sc) { assert(sc->isFuncDeclaration() || sc->isClassDeclaration()); Dsymbol* p = sc->toParent2(); @@ -813,7 +761,7 @@ assert(p->isFuncDeclaration() || p->isClassDeclaration()); if (FuncDeclaration* fd = p->isFuncDeclaration()) { - llvm::Value* v = fd->ir.irFunc->nestedVar; + LLValue* v = fd->ir.irFunc->nestedVar; assert(v); return v->getType(); } @@ -830,7 +778,7 @@ ////////////////////////////////////////////////////////////////////////////////////////// -static llvm::Value* get_frame_ptr_impl(FuncDeclaration* func, Dsymbol* sc, llvm::Value* v) +static LLValue* get_frame_ptr_impl(FuncDeclaration* func, Dsymbol* sc, LLValue* v) { LOG_SCOPE; if (sc == func) @@ -888,7 +836,7 @@ ////////////////////////////////////////////////////////////////////////////////////////// -static llvm::Value* get_frame_ptr(FuncDeclaration* func) +static LLValue* get_frame_ptr(FuncDeclaration* func) { Logger::println("Resolving context pointer for nested function: '%s'", func->toPrettyChars()); LOG_SCOPE; @@ -899,7 +847,7 @@ return irfunc->decl->ir.irFunc->nestedVar; // use the 'this' pointer - llvm::Value* ptr = irfunc->decl->ir.irFunc->thisVar; + LLValue* ptr = irfunc->decl->ir.irFunc->thisVar; assert(ptr); // return the fully resolved frame pointer @@ -912,10 +860,10 @@ ////////////////////////////////////////////////////////////////////////////////////////// -llvm::Value* DtoNestedContext(FuncDeclaration* func) +LLValue* DtoNestedContext(FuncDeclaration* func) { // resolve frame ptr - llvm::Value* ptr = get_frame_ptr(func); + LLValue* ptr = get_frame_ptr(func); Logger::cout() << "Nested context ptr = "; if (ptr) Logger::cout() << *ptr; else Logger::cout() << "NULL"; @@ -953,7 +901,7 @@ ////////////////////////////////////////////////////////////////////////////////////////// -llvm::Value* DtoNestedVariable(VarDeclaration* vd) +LLValue* DtoNestedVariable(VarDeclaration* vd) { // log the frame list IrFunction* irfunc = gIR->func(); @@ -963,14 +911,14 @@ // resolve frame ptr FuncDeclaration* func = vd->toParent2()->isFuncDeclaration(); assert(func); - llvm::Value* ptr = DtoNestedContext(func); + LLValue* ptr = DtoNestedContext(func); assert(ptr && "nested var, but no context"); // we must cast here to be sure. nested classes just have a void* ptr = DtoBitCast(ptr, func->ir.irFunc->nestedVar->getType()); // index nested var and load (if necessary) - llvm::Value* v = DtoGEPi(ptr, 0, vd->ir.irLocal->nestedIndex, "tmp"); + LLValue* v = DtoGEPi(ptr, 0, vd->ir.irLocal->nestedIndex, "tmp"); // references must be loaded, for normal variables this IS already the variable storage!!! if (vd->isParameter() && (vd->isRef() || vd->isOut() || DtoIsPassedByRef(vd->type))) v = DtoLoad(v); @@ -1018,7 +966,7 @@ // rhs is slice else if (DSliceValue* s = rhs->isSlice()) { assert(s->getType()->toBasetype() == lhs->getType()->toBasetype()); - DtoSetArray(lhs->getLVal(),s->len,s->ptr); + DtoSetArray(lhs->getLVal(),DtoArrayLen(s),DtoArrayPtr(s)); } // null else if (rhs->isNull()) { @@ -1041,8 +989,8 @@ if (rhs->isNull()) DtoDelegateToNull(lhs->getLVal()); else if (!rhs->inPlace()) { - llvm::Value* l = lhs->getLVal(); - llvm::Value* r = rhs->getRVal(); + LLValue* l = lhs->getLVal(); + LLValue* r = rhs->getRVal(); Logger::cout() << "assign\nlhs: " << *l << "rhs: " << *r << '\n'; DtoDelegateCopy(l, r); } @@ -1051,7 +999,7 @@ assert(t2->ty == Tclass); // assignment to this in constructor special case if (lhs->isThis()) { - llvm::Value* tmp = rhs->getRVal(); + LLValue* tmp = rhs->getRVal(); FuncDeclaration* fdecl = gIR->func()->decl; // respecify the this param if (!llvm::isa(fdecl->ir.irFunc->thisVar)) @@ -1066,7 +1014,7 @@ else if (t->iscomplex()) { assert(!lhs->isComplex()); - llvm::Value* dst; + LLValue* dst; if (DLRValue* lr = lhs->isLRValue()) { dst = lr->getLVal(); rhs = DtoCastComplex(rhs, lr->getLType()); @@ -1081,10 +1029,10 @@ DtoComplexAssign(dst, rhs->getRVal()); } else { - llvm::Value* l = lhs->getLVal(); - llvm::Value* r = rhs->getRVal(); + LLValue* l = lhs->getLVal(); + LLValue* r = rhs->getRVal(); Logger::cout() << "assign\nlhs: " << *l << "rhs: " << *r << '\n'; - const llvm::Type* lit = l->getType()->getContainedType(0); + const LLType* lit = l->getType()->getContainedType(0); if (r->getType() != lit) { // handle lvalue cast assignments if (DLRValue* lr = lhs->isLRValue()) { @@ -1104,7 +1052,7 @@ ////////////////////////////////////////////////////////////////////////////////////////// DValue* DtoCastInt(DValue* val, Type* _to) { - const llvm::Type* tolltype = DtoType(_to); + const LLType* tolltype = DtoType(_to); Type* to = DtoDType(_to); Type* from = DtoDType(val->getType()); @@ -1113,7 +1061,7 @@ size_t fromsz = from->size(); size_t tosz = to->size(); - llvm::Value* rval = val->getRVal(); + LLValue* rval = val->getRVal(); if (rval->getType() == tolltype) { return new DImValue(_to, rval); } @@ -1131,7 +1079,7 @@ rval = new llvm::TruncInst(rval, tolltype, "tmp", gIR->scopebb()); } else { - rval = new llvm::BitCastInst(rval, tolltype, "tmp", gIR->scopebb()); + rval = DtoBitCast(rval, tolltype); } } else if (to->isfloating()) { @@ -1155,18 +1103,18 @@ DValue* DtoCastPtr(DValue* val, Type* to) { - const llvm::Type* tolltype = DtoType(to); + const LLType* tolltype = DtoType(to); Type* totype = DtoDType(to); Type* fromtype = DtoDType(val->getType()); assert(fromtype->ty == Tpointer); - llvm::Value* rval; + LLValue* rval; if (totype->ty == Tpointer || totype->ty == Tclass) { - llvm::Value* src = val->getRVal(); + LLValue* src = val->getRVal(); Logger::cout() << "src: " << *src << "to type: " << *tolltype << '\n'; - rval = new llvm::BitCastInst(src, tolltype, "tmp", gIR->scopebb()); + rval = DtoBitCast(src, tolltype); } else if (totype->isintegral()) { rval = new llvm::PtrToIntInst(val->getRVal(), tolltype, "tmp", gIR->scopebb()); @@ -1184,7 +1132,7 @@ if (val->getType() == to) return val; - const llvm::Type* tolltype = DtoType(to); + const LLType* tolltype = DtoType(to); Type* totype = DtoDType(to); Type* fromtype = DtoDType(val->getType()); @@ -1193,7 +1141,7 @@ size_t fromsz = fromtype->size(); size_t tosz = totype->size(); - llvm::Value* rval; + LLValue* rval; if (totype->iscomplex()) { assert(0); @@ -1238,7 +1186,7 @@ llvm::Value *re, *im; DtoGetComplexParts(val, re, im); - const llvm::Type* toty = DtoComplexBaseType(to); + const LLType* toty = DtoComplexBaseType(to); if (to->size() < vty->size()) { re = gIR->ir->CreateFPTrunc(re, toty, "tmp"); @@ -1257,21 +1205,21 @@ // unfortunately at this point, the cast value can show up as the lvalue for += and similar expressions. // so we need to give it storage, or fix the system that handles this stuff (DLRValue) - llvm::Value* mem = new llvm::AllocaInst(DtoType(_to), "castcomplextmp", gIR->topallocapoint()); + LLValue* mem = new llvm::AllocaInst(DtoType(_to), "castcomplextmp", gIR->topallocapoint()); DtoComplexSet(mem, re, im); return new DLRValue(val->getType(), val->getRVal(), _to, mem); } else if (to->isimaginary()) { if (val->isComplex()) return new DImValue(to, val->isComplex()->im); - llvm::Value* v = val->getRVal(); + LLValue* v = val->getRVal(); DImValue* im = new DImValue(to, DtoLoad(DtoGEPi(v,0,1,"tmp"))); return DtoCastFloat(im, to); } else if (to->isfloating()) { if (val->isComplex()) return new DImValue(to, val->isComplex()->re); - llvm::Value* v = val->getRVal(); + LLValue* v = val->getRVal(); DImValue* re = new DImValue(to, DtoLoad(DtoGEPi(v,0,0,"tmp"))); return DtoCastFloat(re, to); } @@ -1320,7 +1268,7 @@ { return llvm::ConstantInt::get(llvm::Type::Int32Ty, i, true); } -llvm::Constant* DtoConstBool(bool b) +LLConstant* DtoConstBool(bool b) { return llvm::ConstantInt::get(llvm::Type::Int1Ty, b, false); } @@ -1337,34 +1285,34 @@ ////////////////////////////////////////////////////////////////////////////////////////// -llvm::Constant* DtoConstString(const char* str) +LLConstant* DtoConstString(const char* str) { std::string s(str); - llvm::Constant* init = llvm::ConstantArray::get(s, true); + LLConstant* init = llvm::ConstantArray::get(s, true); llvm::GlobalVariable* gvar = new llvm::GlobalVariable( init->getType(), true,llvm::GlobalValue::InternalLinkage, init, "stringliteral", gIR->module); - llvm::Constant* idxs[2] = { DtoConstUint(0), DtoConstUint(0) }; + LLConstant* idxs[2] = { DtoConstUint(0), DtoConstUint(0) }; return DtoConstSlice( DtoConstSize_t(s.length()), llvm::ConstantExpr::getGetElementPtr(gvar,idxs,2) ); } -llvm::Constant* DtoConstStringPtr(const char* str, const char* section) +LLConstant* DtoConstStringPtr(const char* str, const char* section) { std::string s(str); - llvm::Constant* init = llvm::ConstantArray::get(s, true); + LLConstant* init = llvm::ConstantArray::get(s, true); llvm::GlobalVariable* gvar = new llvm::GlobalVariable( init->getType(), true,llvm::GlobalValue::InternalLinkage, init, "stringliteral", gIR->module); if (section) gvar->setSection(section); - llvm::Constant* idxs[2] = { DtoConstUint(0), DtoConstUint(0) }; + LLConstant* idxs[2] = { DtoConstUint(0), DtoConstUint(0) }; return llvm::ConstantExpr::getGetElementPtr(gvar,idxs,2); } ////////////////////////////////////////////////////////////////////////////////////////// -void DtoMemSetZero(llvm::Value* dst, llvm::Value* nbytes) +void DtoMemSetZero(LLValue* dst, LLValue* nbytes) { - const llvm::Type* arrty = getPtrToType(llvm::Type::Int8Ty); + const LLType* arrty = getPtrToType(llvm::Type::Int8Ty); llvm::Value *dstarr; if (dst->getType() == arrty) { @@ -1372,11 +1320,11 @@ } else { - dstarr = new llvm::BitCastInst(dst,arrty,"tmp",gIR->scopebb()); + dstarr = DtoBitCast(dst,arrty); } llvm::Function* fn = (global.params.is64bit) ? LLVM_DeclareMemSet64() : LLVM_DeclareMemSet32(); - std::vector llargs; + std::vector llargs; llargs.resize(4); llargs[0] = dstarr; llargs[1] = llvm::ConstantInt::get(llvm::Type::Int8Ty, 0, false); @@ -1388,24 +1336,24 @@ ////////////////////////////////////////////////////////////////////////////////////////// -void DtoMemCpy(llvm::Value* dst, llvm::Value* src, llvm::Value* nbytes) +void DtoMemCpy(LLValue* dst, LLValue* src, LLValue* nbytes) { - const llvm::Type* arrty = getVoidPtrType(); + const LLType* arrty = getVoidPtrType(); - llvm::Value* dstarr; + LLValue* dstarr; if (dst->getType() == arrty) dstarr = dst; else dstarr = DtoBitCast(dst, arrty, "tmp"); - llvm::Value* srcarr; + LLValue* srcarr; if (src->getType() == arrty) srcarr = src; else srcarr = DtoBitCast(src, arrty, "tmp"); llvm::Function* fn = (global.params.is64bit) ? LLVM_DeclareMemCpy64() : LLVM_DeclareMemCpy32(); - std::vector llargs; + std::vector llargs; llargs.resize(4); llargs[0] = dstarr; llargs[1] = srcarr; @@ -1417,20 +1365,20 @@ ////////////////////////////////////////////////////////////////////////////////////////// -llvm::Value* DtoLoad(llvm::Value* src) +LLValue* DtoLoad(LLValue* src, const char* name) { - llvm::Value* ld = gIR->ir->CreateLoad(src,"tmp"); + LLValue* ld = gIR->ir->CreateLoad(src, name ? name : "tmp"); //ld->setVolatile(gIR->func()->inVolatile); return ld; } -void DtoStore(llvm::Value* src, llvm::Value* dst) +void DtoStore(LLValue* src, LLValue* dst) { - llvm::Value* st = gIR->ir->CreateStore(src,dst); + LLValue* st = gIR->ir->CreateStore(src,dst); //st->setVolatile(gIR->func()->inVolatile); } -bool DtoCanLoad(llvm::Value* ptr) +bool DtoCanLoad(LLValue* ptr) { if (isaPointer(ptr->getType())) { return ptr->getType()->getContainedType(0)->isFirstClassType(); @@ -1440,7 +1388,7 @@ ////////////////////////////////////////////////////////////////////////////////////////// -llvm::Value* DtoBitCast(llvm::Value* v, const llvm::Type* t, const char* name) +LLValue* DtoBitCast(LLValue* v, const LLType* t, const char* name) { if (v->getType() == t) return v; @@ -1449,59 +1397,59 @@ ////////////////////////////////////////////////////////////////////////////////////////// -const llvm::PointerType* isaPointer(llvm::Value* v) +const llvm::PointerType* isaPointer(LLValue* v) { return llvm::dyn_cast(v->getType()); } -const llvm::PointerType* isaPointer(const llvm::Type* t) +const llvm::PointerType* isaPointer(const LLType* t) { return llvm::dyn_cast(t); } -const llvm::ArrayType* isaArray(llvm::Value* v) +const llvm::ArrayType* isaArray(LLValue* v) { return llvm::dyn_cast(v->getType()); } -const llvm::ArrayType* isaArray(const llvm::Type* t) +const llvm::ArrayType* isaArray(const LLType* t) { return llvm::dyn_cast(t); } -const llvm::StructType* isaStruct(llvm::Value* v) +const llvm::StructType* isaStruct(LLValue* v) { return llvm::dyn_cast(v->getType()); } -const llvm::StructType* isaStruct(const llvm::Type* t) +const llvm::StructType* isaStruct(const LLType* t) { return llvm::dyn_cast(t); } -llvm::Constant* isaConstant(llvm::Value* v) +LLConstant* isaConstant(LLValue* v) { return llvm::dyn_cast(v); } -llvm::ConstantInt* isaConstantInt(llvm::Value* v) +llvm::ConstantInt* isaConstantInt(LLValue* v) { return llvm::dyn_cast(v); } -llvm::Argument* isaArgument(llvm::Value* v) +llvm::Argument* isaArgument(LLValue* v) { return llvm::dyn_cast(v); } -llvm::GlobalVariable* isaGlobalVar(llvm::Value* v) +llvm::GlobalVariable* isaGlobalVar(LLValue* v) { return llvm::dyn_cast(v); } ////////////////////////////////////////////////////////////////////////////////////////// -const llvm::PointerType* getPtrToType(const llvm::Type* t) +const llvm::PointerType* getPtrToType(const LLType* t) { return llvm::PointerType::get(t, 0); } @@ -1511,7 +1459,7 @@ return getPtrToType(llvm::Type::Int8Ty); } -llvm::ConstantPointerNull* getNullPtr(const llvm::Type* t) +llvm::ConstantPointerNull* getNullPtr(const LLType* t) { const llvm::PointerType* pt = llvm::cast(t); return llvm::ConstantPointerNull::get(pt); @@ -1519,17 +1467,17 @@ ////////////////////////////////////////////////////////////////////////////////////////// -size_t getTypeBitSize(const llvm::Type* t) +size_t getTypeBitSize(const LLType* t) { return gTargetData->getTypeSizeInBits(t); } -size_t getTypeStoreSize(const llvm::Type* t) +size_t getTypeStoreSize(const LLType* t) { return gTargetData->getTypeStoreSize(t); } -size_t getABITypeSize(const llvm::Type* t) +size_t getABITypeSize(const LLType* t) { return gTargetData->getABITypeSize(t); } @@ -1548,7 +1496,7 @@ ////////////////////////////////////////////////////////////////////////////////////////// -void DtoLazyStaticInit(bool istempl, llvm::Value* gvar, Initializer* init, Type* t) +void DtoLazyStaticInit(bool istempl, LLValue* gvar, Initializer* init, Type* t) { // create a flag to make sure initialization only happens once llvm::GlobalValue::LinkageTypes gflaglink = istempl ? llvm::GlobalValue::WeakLinkage : llvm::GlobalValue::InternalLinkage; @@ -1560,7 +1508,7 @@ llvm::BasicBlock* oldend = gIR->scopeend(); llvm::BasicBlock* initbb = llvm::BasicBlock::Create("ifnotinit",gIR->topfunc(),oldend); llvm::BasicBlock* endinitbb = llvm::BasicBlock::Create("ifnotinitend",gIR->topfunc(),oldend); - llvm::Value* cond = gIR->ir->CreateICmpEQ(gIR->ir->CreateLoad(gflag,"tmp"),DtoConstBool(false)); + LLValue* cond = gIR->ir->CreateICmpEQ(gIR->ir->CreateLoad(gflag,"tmp"),DtoConstBool(false)); gIR->ir->CreateCondBr(cond, initbb, endinitbb); gIR->scope() = IRScope(initbb,endinitbb); DValue* ie = DtoInitializer(init); @@ -1673,7 +1621,7 @@ bool emitRTstaticInit = false; - llvm::Constant* _init = 0; + LLConstant* _init = 0; if (vd->parent && vd->parent->isFuncDeclaration() && vd->init && vd->init->isExpInitializer()) { _init = DtoConstInitializer(vd->type, NULL); emitRTstaticInit = true; @@ -1682,7 +1630,7 @@ _init = DtoConstInitializer(vd->type, vd->init); } - const llvm::Type* _type = DtoType(vd->type); + const LLType* _type = DtoType(vd->type); Type* t = DtoDType(vd->type); //Logger::cout() << "initializer: " << *_init << '\n'; @@ -1888,15 +1836,15 @@ return gIR->interfaceInfoType; // build interface info type - std::vector types; + std::vector types; // ClassInfo classinfo ClassDeclaration* cd2 = ClassDeclaration::classinfo; DtoResolveClass(cd2); types.push_back(getPtrToType(cd2->type->ir.type->get())); // void*[] vtbl - std::vector vtbltypes; + std::vector vtbltypes; vtbltypes.push_back(DtoSize_t()); - const llvm::Type* byteptrptrty = getPtrToType(getPtrToType(llvm::Type::Int8Ty)); + const LLType* byteptrptrty = getPtrToType(getPtrToType(llvm::Type::Int8Ty)); vtbltypes.push_back(byteptrptrty); types.push_back(llvm::StructType::get(vtbltypes)); // int offset @@ -1909,15 +1857,19 @@ ////////////////////////////////////////////////////////////////////////////////////////// -llvm::Constant* DtoTypeInfoOf(Type* type) +LLConstant* DtoTypeInfoOf(Type* type, bool base) { - const llvm::Type* typeinfotype = DtoType(Type::typeinfo->type); - TypeInfoDeclaration* tidecl = type->getTypeInfoDeclaration(); + const LLType* typeinfotype = DtoType(Type::typeinfo->type); + if (!type->vtinfo) + type->getTypeInfo(NULL); + TypeInfoDeclaration* tidecl = type->vtinfo; DtoForceDeclareDsymbol(tidecl); assert(tidecl->ir.irGlobal != NULL); - llvm::Constant* c = isaConstant(tidecl->ir.irGlobal->value); + LLConstant* c = isaConstant(tidecl->ir.irGlobal->value); assert(c != NULL); - return llvm::ConstantExpr::getBitCast(c, typeinfotype); + if (base) + return llvm::ConstantExpr::getBitCast(c, typeinfotype); + return c; } diff -r 4c2689d57ba4 -r 7816aafeea3c gen/tollvm.h --- a/gen/tollvm.h Tue May 27 22:14:24 2008 +0200 +++ b/gen/tollvm.h Fri May 30 19:32:04 2008 +0200 @@ -8,7 +8,7 @@ #include "declaration.h" // D->LLVM type handling stuff -const llvm::Type* DtoType(Type* t); +const LLType* DtoType(Type* t); bool DtoIsPassedByRef(Type* type); // resolve typedefs to their real type. @@ -17,9 +17,9 @@ // delegate helpers const llvm::StructType* DtoDelegateType(Type* t); -llvm::Value* DtoDelegateToNull(llvm::Value* v); -llvm::Value* DtoDelegateCopy(llvm::Value* dst, llvm::Value* src); -llvm::Value* DtoDelegateCompare(TOK op, llvm::Value* lhs, llvm::Value* rhs); +void DtoDelegateToNull(LLValue* v); +void DtoDelegateCopy(LLValue* dst, LLValue* src); +LLValue* DtoDelegateCompare(TOK op, LLValue* lhs, LLValue* rhs); // return linkage type for symbol using the current ir state for context llvm::GlobalValue::LinkageTypes DtoLinkage(Dsymbol* sym); @@ -30,21 +30,21 @@ unsigned DtoCallingConv(LINK l); // TODO: this one should be removed!!! -llvm::Value* DtoPointedType(llvm::Value* ptr, llvm::Value* val); +LLValue* DtoPointedType(LLValue* ptr, LLValue* val); // casts any value to a boolean -llvm::Value* DtoBoolean(llvm::Value* val); +LLValue* DtoBoolean(LLValue* val); // some types -const llvm::Type* DtoSize_t(); +const LLType* DtoSize_t(); const llvm::StructType* DtoInterfaceInfoType(); -// getting typeinfo of type -llvm::Constant* DtoTypeInfoOf(Type* ty); +// getting typeinfo of type, base=true casts to object.TypeInfo +LLConstant* DtoTypeInfoOf(Type* ty, bool base=true); // initializer helpers -llvm::Constant* DtoConstInitializer(Type* type, Initializer* init); -llvm::Constant* DtoConstFieldInitializer(Type* type, Initializer* init); +LLConstant* DtoConstInitializer(Type* type, Initializer* init); +LLConstant* DtoConstFieldInitializer(Type* type, Initializer* init); DValue* DtoInitializer(Initializer* init); // declaration of memset/cpy intrinsics @@ -54,24 +54,24 @@ llvm::Function* LLVM_DeclareMemCpy64(); // getelementptr helpers -llvm::Value* DtoGEP(llvm::Value* ptr, llvm::Value* i0, llvm::Value* i1, const std::string& var, llvm::BasicBlock* bb=NULL); -llvm::Value* DtoGEP(llvm::Value* ptr, const std::vector& src, const std::string& var, llvm::BasicBlock* bb=NULL); -llvm::Value* DtoGEPi(llvm::Value* ptr, unsigned i0, const std::string& var, llvm::BasicBlock* bb=NULL); -llvm::Value* DtoGEPi(llvm::Value* ptr, unsigned i0, unsigned i1, const std::string& var, llvm::BasicBlock* bb=NULL); +LLValue* DtoGEP(LLValue* ptr, LLValue* i0, LLValue* i1, const std::string& var, llvm::BasicBlock* bb=NULL); +LLValue* DtoGEP(LLValue* ptr, const std::vector& src, const std::string& var, llvm::BasicBlock* bb=NULL); +LLValue* DtoGEPi(LLValue* ptr, unsigned i0, const std::string& var, llvm::BasicBlock* bb=NULL); +LLValue* DtoGEPi(LLValue* ptr, unsigned i0, unsigned i1, const std::string& var, llvm::BasicBlock* bb=NULL); // dynamic memory helpers -llvm::Value* DtoNew(Type* newtype); -void DtoDeleteMemory(llvm::Value* ptr); -void DtoDeleteClass(llvm::Value* inst); -void DtoDeleteInterface(llvm::Value* inst); +LLValue* DtoNew(Type* newtype); +void DtoDeleteMemory(LLValue* ptr); +void DtoDeleteClass(LLValue* inst); +void DtoDeleteInterface(LLValue* inst); void DtoDeleteArray(DValue* arr); // assertion generator void DtoAssert(Loc* loc, DValue* msg); // nested variable/class helpers -llvm::Value* DtoNestedContext(FuncDeclaration* func); -llvm::Value* DtoNestedVariable(VarDeclaration* vd); +LLValue* DtoNestedContext(FuncDeclaration* func); +LLValue* DtoNestedVariable(VarDeclaration* vd); // annotation generator void DtoAnnotation(const char* str); @@ -82,15 +82,15 @@ llvm::ConstantInt* DtoConstInt(int i); llvm::ConstantFP* DtoConstFP(Type* t, long double value); -llvm::Constant* DtoConstString(const char*); -llvm::Constant* DtoConstStringPtr(const char* str, const char* section = 0); -llvm::Constant* DtoConstBool(bool); +LLConstant* DtoConstString(const char*); +LLConstant* DtoConstStringPtr(const char* str, const char* section = 0); +LLConstant* DtoConstBool(bool); // is template instance check bool DtoIsTemplateInstance(Dsymbol* s); // generates lazy static initialization code for a global variable -void DtoLazyStaticInit(bool istempl, llvm::Value* gvar, Initializer* init, Type* t); +void DtoLazyStaticInit(bool istempl, LLValue* gvar, Initializer* init, Type* t); // these are all basically drivers for the codegeneration called by the main loop void DtoResolveDsymbol(Dsymbol* dsym); @@ -107,35 +107,35 @@ void DtoForceDefineDsymbol(Dsymbol* dsym); // llvm wrappers -void DtoMemSetZero(llvm::Value* dst, llvm::Value* nbytes); -void DtoMemCpy(llvm::Value* dst, llvm::Value* src, llvm::Value* nbytes); +void DtoMemSetZero(LLValue* dst, LLValue* nbytes); +void DtoMemCpy(LLValue* dst, LLValue* src, LLValue* nbytes); void DtoMemoryBarrier(bool ll, bool ls, bool sl, bool ss, bool device=false); -bool DtoCanLoad(llvm::Value* ptr); -llvm::Value* DtoLoad(llvm::Value* src); -void DtoStore(llvm::Value* src, llvm::Value* dst); -llvm::Value* DtoBitCast(llvm::Value* v, const llvm::Type* t, const char* name=0); +bool DtoCanLoad(LLValue* ptr); +LLValue* DtoLoad(LLValue* src, const char* name=0); +void DtoStore(LLValue* src, LLValue* dst); +LLValue* DtoBitCast(LLValue* v, const LLType* t, const char* name=0); // llvm::dyn_cast wrappers -const llvm::PointerType* isaPointer(llvm::Value* v); -const llvm::PointerType* isaPointer(const llvm::Type* t); -const llvm::ArrayType* isaArray(llvm::Value* v); -const llvm::ArrayType* isaArray(const llvm::Type* t); -const llvm::StructType* isaStruct(llvm::Value* v); -const llvm::StructType* isaStruct(const llvm::Type* t); -llvm::Constant* isaConstant(llvm::Value* v); -llvm::ConstantInt* isaConstantInt(llvm::Value* v); -llvm::Argument* isaArgument(llvm::Value* v); -llvm::GlobalVariable* isaGlobalVar(llvm::Value* v); +const llvm::PointerType* isaPointer(LLValue* v); +const llvm::PointerType* isaPointer(const LLType* t); +const llvm::ArrayType* isaArray(LLValue* v); +const llvm::ArrayType* isaArray(const LLType* t); +const llvm::StructType* isaStruct(LLValue* v); +const llvm::StructType* isaStruct(const LLType* t); +LLConstant* isaConstant(LLValue* v); +llvm::ConstantInt* isaConstantInt(LLValue* v); +llvm::Argument* isaArgument(LLValue* v); +llvm::GlobalVariable* isaGlobalVar(LLValue* v); // llvm::T::get(...) wrappers -const llvm::PointerType* getPtrToType(const llvm::Type* t); +const llvm::PointerType* getPtrToType(const LLType* t); const llvm::PointerType* getVoidPtrType(); -llvm::ConstantPointerNull* getNullPtr(const llvm::Type* t); +llvm::ConstantPointerNull* getNullPtr(const LLType* t); // type sizes -size_t getTypeBitSize(const llvm::Type* t); -size_t getTypeStoreSize(const llvm::Type* t); -size_t getABITypeSize(const llvm::Type* t); +size_t getTypeBitSize(const LLType* t); +size_t getTypeStoreSize(const LLType* t); +size_t getABITypeSize(const LLType* t); // basic operations void DtoAssign(DValue* lhs, DValue* rhs); diff -r 4c2689d57ba4 -r 7816aafeea3c gen/toobj.cpp --- a/gen/toobj.cpp Tue May 27 22:14:24 2008 +0200 +++ b/gen/toobj.cpp Fri May 30 19:32:04 2008 +0200 @@ -187,7 +187,7 @@ name.append(gIR->dmodule->mangle()); name.append("6__ctorZ"); - std::vector argsTy; + std::vector argsTy; const llvm::FunctionType* fnTy = llvm::FunctionType::get(llvm::Type::VoidTy,argsTy,false); assert(gIR->module->getFunction(name) == NULL); llvm::Function* fn = llvm::Function::Create(fnTy, llvm::GlobalValue::InternalLinkage, name, gIR->module); @@ -221,7 +221,7 @@ name.append(gIR->dmodule->mangle()); name.append("6__dtorZ"); - std::vector argsTy; + std::vector argsTy; const llvm::FunctionType* fnTy = llvm::FunctionType::get(llvm::Type::VoidTy,argsTy,false); assert(gIR->module->getFunction(name) == NULL); llvm::Function* fn = llvm::Function::Create(fnTy, llvm::GlobalValue::InternalLinkage, name, gIR->module); @@ -255,7 +255,7 @@ name.append(gIR->dmodule->mangle()); name.append("10__unittestZ"); - std::vector argsTy; + std::vector argsTy; const llvm::FunctionType* fnTy = llvm::FunctionType::get(llvm::Type::VoidTy,argsTy,false); assert(gIR->module->getFunction(name) == NULL); llvm::Function* fn = llvm::Function::Create(fnTy, llvm::GlobalValue::InternalLinkage, name, gIR->module); @@ -302,8 +302,8 @@ const llvm::StructType* classinfoTy = isaStruct(ClassDeclaration::classinfo->type->ir.type->get()); // initializer vector - std::vector initVec; - llvm::Constant* c = 0; + std::vector initVec; + LLConstant* c = 0; // vtable c = moduleinfo->ir.irStruct->vtbl; @@ -320,7 +320,7 @@ // importedModules[] int aimports_dim = aimports.dim; - std::vector importInits; + std::vector importInits; for (size_t i = 0; i < aimports.dim; i++) { Module *m = (Module *)aimports.data[i]; @@ -365,7 +365,7 @@ member->addLocalClass(&aclasses); } // fill inits - std::vector classInits; + std::vector classInits; for (size_t i = 0; i < aclasses.dim; i++) { ClassDeclaration* cd = (ClassDeclaration*)aclasses.data[i]; @@ -433,7 +433,7 @@ }*/ // create initializer - llvm::Constant* constMI = llvm::ConstantStruct::get(moduleinfoTy, initVec); + LLConstant* constMI = llvm::ConstantStruct::get(moduleinfoTy, initVec); // create name std::string MIname("_D"); @@ -449,9 +449,9 @@ // declare the appending array const llvm::ArrayType* appendArrTy = llvm::ArrayType::get(getPtrToType(llvm::Type::Int8Ty), 1); - std::vector appendInits; + std::vector appendInits; appendInits.push_back(llvm::ConstantExpr::getBitCast(gvar, getPtrToType(llvm::Type::Int8Ty))); - llvm::Constant* appendInit = llvm::ConstantArray::get(appendArrTy, appendInits); + LLConstant* appendInit = llvm::ConstantArray::get(appendArrTy, appendInits); std::string appendName("_d_moduleinfo_array"); llvm::GlobalVariable* appendVar = new llvm::GlobalVariable(appendArrTy, true, llvm::GlobalValue::AppendingLinkage, appendInit, appendName, gIR->module); } @@ -545,7 +545,7 @@ Logger::println("Creating global variable"); - const llvm::Type* _type = this->ir.irGlobal->type.get(); + const LLType* _type = this->ir.irGlobal->type.get(); llvm::GlobalValue::LinkageTypes _linkage = DtoLinkage(this); std::string _name(mangle()); @@ -565,7 +565,7 @@ { Logger::println("Aggregate var declaration: '%s' offset=%d", toChars(), offset); - const llvm::Type* _type = DtoType(type); + const LLType* _type = DtoType(type); this->ir.irField = new IrField(this); // add the field in the IRStruct diff -r 4c2689d57ba4 -r 7816aafeea3c gen/typinf.cpp --- a/gen/typinf.cpp Tue May 27 22:14:24 2008 +0200 +++ b/gen/typinf.cpp Fri May 30 19:32:04 2008 +0200 @@ -233,7 +233,7 @@ Expression *createTypeInfoArray(Scope *sc, Expression *exps[], int dim) { - assert(0); + assert(0); // done elsewhere in llvmdc return NULL; } @@ -276,10 +276,10 @@ // this is a declaration of a builtin __initZ var if (tid->tinfo->builtinTypeInfo()) { - llvm::Value* found = gIR->module->getNamedGlobal(mangled); + LLValue* found = gIR->module->getNamedGlobal(mangled); if (!found) { - const llvm::Type* t = llvm::OpaqueType::get(); + const LLType* t = llvm::OpaqueType::get(); llvm::GlobalVariable* g = new llvm::GlobalVariable(t, true, llvm::GlobalValue::ExternalLinkage, NULL, mangled, gIR->module); assert(g); /*if (!tid->ir.irGlobal) @@ -371,7 +371,7 @@ Logger::cout() << "got stype: " << *stype << '\n'; // vtbl - std::vector sinits; + std::vector sinits; sinits.push_back(base->ir.irStruct->vtbl); // monitor @@ -393,7 +393,7 @@ assert(sd->basetype->vtinfo->ir.irGlobal->value); assert(llvm::isa(sd->basetype->vtinfo->ir.irGlobal->value)); - llvm::Constant* castbase = llvm::cast(sd->basetype->vtinfo->ir.irGlobal->value); + LLConstant* castbase = llvm::cast(sd->basetype->vtinfo->ir.irGlobal->value); castbase = llvm::ConstantExpr::getBitCast(castbase, stype->getElementType(2)); sinits.push_back(castbase); @@ -410,17 +410,17 @@ } else { - llvm::Constant* ci = DtoConstInitializer(sd->basetype, sd->init); + LLConstant* ci = DtoConstInitializer(sd->basetype, sd->init); std::string ciname(sd->mangle()); ciname.append("__init"); llvm::GlobalVariable* civar = new llvm::GlobalVariable(DtoType(sd->basetype),true,llvm::GlobalValue::InternalLinkage,ci,ciname,gIR->module); - llvm::Constant* cicast = llvm::ConstantExpr::getBitCast(civar, initpt); + LLConstant* cicast = llvm::ConstantExpr::getBitCast(civar, initpt); size_t cisize = getTypeStoreSize(DtoType(sd->basetype)); sinits.push_back(DtoConstSlice(DtoConstSize_t(cisize), cicast)); } // create the symbol - llvm::Constant* tiInit = llvm::ConstantStruct::get(stype, sinits); + LLConstant* tiInit = llvm::ConstantStruct::get(stype, sinits); isaGlobalVar(this->ir.irGlobal->value)->setInitializer(tiInit); } @@ -456,7 +456,7 @@ const llvm::StructType* stype = isaStruct(base->type->ir.type->get()); // vtbl - std::vector sinits; + std::vector sinits; sinits.push_back(base->ir.irStruct->vtbl); // monitor @@ -477,7 +477,7 @@ DtoForceDeclareDsymbol(sd->memtype->vtinfo); assert(llvm::isa(sd->memtype->vtinfo->ir.irGlobal->value)); - llvm::Constant* castbase = llvm::cast(sd->memtype->vtinfo->ir.irGlobal->value); + LLConstant* castbase = llvm::cast(sd->memtype->vtinfo->ir.irGlobal->value); castbase = llvm::ConstantExpr::getBitCast(castbase, stype->getElementType(2)); sinits.push_back(castbase); @@ -494,18 +494,18 @@ } else { - const llvm::Type* memty = DtoType(sd->memtype); - llvm::Constant* ci = llvm::ConstantInt::get(memty, sd->defaultval, !sd->memtype->isunsigned()); + const LLType* memty = DtoType(sd->memtype); + LLConstant* ci = llvm::ConstantInt::get(memty, sd->defaultval, !sd->memtype->isunsigned()); std::string ciname(sd->mangle()); ciname.append("__init"); llvm::GlobalVariable* civar = new llvm::GlobalVariable(memty,true,llvm::GlobalValue::InternalLinkage,ci,ciname,gIR->module); - llvm::Constant* cicast = llvm::ConstantExpr::getBitCast(civar, initpt); + LLConstant* cicast = llvm::ConstantExpr::getBitCast(civar, initpt); size_t cisize = getTypeStoreSize(memty); sinits.push_back(DtoConstSlice(DtoConstSize_t(cisize), cicast)); } // create the symbol - llvm::Constant* tiInit = llvm::ConstantStruct::get(stype, sinits); + LLConstant* tiInit = llvm::ConstantStruct::get(stype, sinits); isaGlobalVar(this->ir.irGlobal->value)->setInitializer(tiInit); } @@ -516,7 +516,7 @@ /* ========================================================================= */ -static llvm::Constant* LLVM_D_Declare_TypeInfoBase(TypeInfoDeclaration* tid, ClassDeclaration* cd) +static LLConstant* LLVM_D_Declare_TypeInfoBase(TypeInfoDeclaration* tid, ClassDeclaration* cd) { ClassDeclaration* base = cd; DtoResolveClass(base); @@ -527,7 +527,7 @@ tid->ir.irGlobal->value = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,tid->toChars(),gIR->module); } -static llvm::Constant* LLVM_D_Define_TypeInfoBase(Type* basetype, TypeInfoDeclaration* tid, ClassDeclaration* cd) +static LLConstant* LLVM_D_Define_TypeInfoBase(Type* basetype, TypeInfoDeclaration* tid, ClassDeclaration* cd) { ClassDeclaration* base = cd; DtoForceConstInitDsymbol(base); @@ -535,7 +535,7 @@ const llvm::StructType* stype = isaStruct(base->type->ir.type->get()); // vtbl - std::vector sinits; + std::vector sinits; sinits.push_back(base->ir.irStruct->vtbl); // monitor @@ -547,12 +547,12 @@ assert(basetype->vtinfo); DtoForceDeclareDsymbol(basetype->vtinfo); assert(llvm::isa(basetype->vtinfo->ir.irGlobal->value)); - llvm::Constant* castbase = llvm::cast(basetype->vtinfo->ir.irGlobal->value); + LLConstant* castbase = llvm::cast(basetype->vtinfo->ir.irGlobal->value); castbase = llvm::ConstantExpr::getBitCast(castbase, stype->getElementType(2)); sinits.push_back(castbase); // create the symbol - llvm::Constant* tiInit = llvm::ConstantStruct::get(stype, sinits); + LLConstant* tiInit = llvm::ConstantStruct::get(stype, sinits); isaGlobalVar(tid->ir.irGlobal->value)->setInitializer(tiInit); } @@ -645,7 +645,7 @@ const llvm::StructType* stype = isaStruct(base->type->ir.type->get()); // initializer vector - std::vector sinits; + std::vector sinits; // first is always the vtable sinits.push_back(base->ir.irStruct->vtbl); @@ -660,7 +660,7 @@ // get symbol assert(tc->next->vtinfo); DtoForceDeclareDsymbol(tc->next->vtinfo); - llvm::Constant* castbase = isaConstant(tc->next->vtinfo->ir.irGlobal->value); + LLConstant* castbase = isaConstant(tc->next->vtinfo->ir.irGlobal->value); castbase = llvm::ConstantExpr::getBitCast(castbase, stype->getElementType(2)); sinits.push_back(castbase); @@ -668,7 +668,7 @@ sinits.push_back(DtoConstSize_t(tc->dim->toInteger())); // create the symbol - llvm::Constant* tiInit = llvm::ConstantStruct::get(stype, sinits); + LLConstant* tiInit = llvm::ConstantStruct::get(stype, sinits); isaGlobalVar(this->ir.irGlobal->value)->setInitializer(tiInit); } @@ -708,7 +708,7 @@ const llvm::StructType* stype = isaStruct(base->type->ir.type->get()); // initializer vector - std::vector sinits; + std::vector sinits; // first is always the vtable sinits.push_back(base->ir.irStruct->vtbl); @@ -725,7 +725,7 @@ // get symbol assert(tc->next->vtinfo); DtoForceDeclareDsymbol(tc->next->vtinfo); - llvm::Constant* castbase = isaConstant(tc->next->vtinfo->ir.irGlobal->value); + LLConstant* castbase = isaConstant(tc->next->vtinfo->ir.irGlobal->value); castbase = llvm::ConstantExpr::getBitCast(castbase, stype->getElementType(2)); sinits.push_back(castbase); @@ -740,7 +740,7 @@ sinits.push_back(castbase); // create the symbol - llvm::Constant* tiInit = llvm::ConstantStruct::get(stype, sinits); + LLConstant* tiInit = llvm::ConstantStruct::get(stype, sinits); isaGlobalVar(this->ir.irGlobal->value)->setInitializer(tiInit); } @@ -844,7 +844,7 @@ const llvm::StructType* stype = isaStruct(base->type->ir.type->get()); // vtbl - std::vector sinits; + std::vector sinits; sinits.push_back(base->ir.irStruct->vtbl); // monitor @@ -858,14 +858,17 @@ // void[] init const llvm::PointerType* initpt = getPtrToType(llvm::Type::Int8Ty); +#if 0 + // the implementation of TypeInfo_Struct uses this to determine size. :/ if (sd->zeroInit) // 0 initializer, or the same as the base type { sinits.push_back(DtoConstSlice(DtoConstSize_t(0), llvm::ConstantPointerNull::get(initpt))); } else +#endif { size_t cisize = getTypeStoreSize(tc->ir.type->get()); - llvm::Constant* cicast = llvm::ConstantExpr::getBitCast(sd->ir.irStruct->init, initpt); + LLConstant* cicast = llvm::ConstantExpr::getBitCast(sd->ir.irStruct->init, initpt); sinits.push_back(DtoConstSlice(DtoConstSize_t(cisize), cicast)); } @@ -926,7 +929,7 @@ if (fd) { DtoForceDeclareDsymbol(fd); assert(fd->ir.irFunc->func != 0); - llvm::Constant* c = isaConstant(fd->ir.irFunc->func); + LLConstant* c = isaConstant(fd->ir.irFunc->func); assert(c); c = llvm::ConstantExpr::getBitCast(c, ptty); sinits.push_back(c); @@ -952,7 +955,7 @@ if (fd) { DtoForceDeclareDsymbol(fd); assert(fd->ir.irFunc->func != 0); - llvm::Constant* c = isaConstant(fd->ir.irFunc->func); + LLConstant* c = isaConstant(fd->ir.irFunc->func); assert(c); c = llvm::ConstantExpr::getBitCast(c, ptty); sinits.push_back(c); @@ -980,7 +983,7 @@ if (fd) { DtoForceDeclareDsymbol(fd); assert(fd->ir.irFunc->func != 0); - llvm::Constant* c = isaConstant(fd->ir.irFunc->func); + LLConstant* c = isaConstant(fd->ir.irFunc->func); assert(c); c = llvm::ConstantExpr::getBitCast(c, ptty); sinits.push_back(c); @@ -998,7 +1001,7 @@ sinits.push_back(DtoConstUint(tc->hasPointers())); // create the symbol - llvm::Constant* tiInit = llvm::ConstantStruct::get(stype, sinits); + LLConstant* tiInit = llvm::ConstantStruct::get(stype, sinits); llvm::GlobalVariable* gvar = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,tiInit,toChars(),gIR->module); isaGlobalVar(this->ir.irGlobal->value)->setInitializer(tiInit); @@ -1042,7 +1045,7 @@ const llvm::StructType* stype = isaStruct(base->type->ir.type->get()); // initializer vector - std::vector sinits; + std::vector sinits; // first is always the vtable sinits.push_back(base->ir.irStruct->vtbl); @@ -1057,7 +1060,7 @@ sinits.push_back(tc->sym->ir.irStruct->classInfo); // create the symbol - llvm::Constant* tiInit = llvm::ConstantStruct::get(stype, sinits); + LLConstant* tiInit = llvm::ConstantStruct::get(stype, sinits); isaGlobalVar(this->ir.irGlobal->value)->setInitializer(tiInit); } @@ -1099,7 +1102,7 @@ const llvm::StructType* stype = isaStruct(base->type->ir.type->get()); // initializer vector - std::vector sinits; + std::vector sinits; // first is always the vtable sinits.push_back(base->ir.irStruct->vtbl); @@ -1113,7 +1116,7 @@ sinits.push_back(tc->sym->ir.irStruct->classInfo); // create the symbol - llvm::Constant* tiInit = llvm::ConstantStruct::get(stype, sinits); + LLConstant* tiInit = llvm::ConstantStruct::get(stype, sinits); isaGlobalVar(this->ir.irGlobal->value)->setInitializer(tiInit); } @@ -1155,7 +1158,7 @@ const llvm::StructType* stype = isaStruct(base->type->ir.type->get()); // initializer vector - std::vector sinits; + std::vector sinits; // first is always the vtable sinits.push_back(base->ir.irStruct->vtbl); @@ -1167,9 +1170,9 @@ TypeTuple *tu = (TypeTuple *)tinfo; size_t dim = tu->arguments->dim; - std::vector arrInits; + std::vector arrInits; - const llvm::Type* tiTy = Type::typeinfo->type->ir.type->get(); + const LLType* tiTy = Type::typeinfo->type->ir.type->get(); tiTy = getPtrToType(tiTy); for (size_t i = 0; i < dim; i++) @@ -1178,21 +1181,21 @@ arg->type->getTypeInfo(NULL); DtoForceDeclareDsymbol(arg->type->vtinfo); assert(arg->type->vtinfo->ir.irGlobal->value); - llvm::Constant* c = isaConstant(arg->type->vtinfo->ir.irGlobal->value); + LLConstant* c = isaConstant(arg->type->vtinfo->ir.irGlobal->value); c = llvm::ConstantExpr::getBitCast(c, tiTy); arrInits.push_back(c); } // build array type const llvm::ArrayType* arrTy = llvm::ArrayType::get(tiTy, dim); - llvm::Constant* arrC = llvm::ConstantArray::get(arrTy, arrInits); + LLConstant* arrC = llvm::ConstantArray::get(arrTy, arrInits); // build the slice - llvm::Constant* slice = DtoConstSlice(DtoConstSize_t(dim), arrC); + LLConstant* slice = DtoConstSlice(DtoConstSize_t(dim), arrC); sinits.push_back(slice); // create the symbol - llvm::Constant* tiInit = llvm::ConstantStruct::get(stype, sinits); + LLConstant* tiInit = llvm::ConstantStruct::get(stype, sinits); isaGlobalVar(this->ir.irGlobal->value)->setInitializer(tiInit); } diff -r 4c2689d57ba4 -r 7816aafeea3c llvmdc.kdevelop.filelist --- a/llvmdc.kdevelop.filelist Tue May 27 22:14:24 2008 +0200 +++ b/llvmdc.kdevelop.filelist Fri May 30 19:32:04 2008 +0200 @@ -747,6 +747,7 @@ tangotests tangotests/a.d tangotests/aa1.d +tangotests/aa2.d tangotests/b.d tangotests/c.d tangotests/classes1.d @@ -775,6 +776,7 @@ tangotests/templ1.d tangotests/vararg1.d tangotests/vararg2.d +tangotests/vararg3.d test test/a.d test/aa1.d diff -r 4c2689d57ba4 -r 7816aafeea3c tango/lib/compiler/llvmdc/genobj.d --- a/tango/lib/compiler/llvmdc/genobj.d Tue May 27 22:14:24 2008 +0200 +++ b/tango/lib/compiler/llvmdc/genobj.d Fri May 30 19:32:04 2008 +0200 @@ -37,11 +37,11 @@ module object; -//debug=PRINTF; +//debug=PRINTF private { - import tango.stdc.string; // : memcmp, memcpy; + import tango.stdc.string; // : memcmp, memcpy, memmove; import tango.stdc.stdlib; // : calloc, realloc, free; import util.string; debug(PRINTF) import tango.stdc.stdio; // : printf; @@ -126,7 +126,8 @@ /** * Information about an interface. - * A pointer to this appears as the first entry in the interface's vtbl[]. + * When an object is accessed via an interface, an Interface* appears as the + * first entry in its vtbl. */ struct Interface { @@ -436,7 +437,7 @@ TypeInfo next() { return value; -} + } uint flags() { return 1; } } @@ -623,8 +624,7 @@ hash_t getHash(void *p) { Object o = *cast(Object*)p; - assert(o); - return o.toHash(); + return o ? o.toHash() : 0; } int equals(void *p1, void *p2) @@ -888,24 +888,38 @@ } } + +//////////////////////////////////////////////////////////////////////////////// +// Exception +//////////////////////////////////////////////////////////////////////////////// + + class Exception : Object { + interface TraceInfo + { + int opApply( int delegate( inout char[] ) ); + } + char[] msg; char[] file; size_t line; + TraceInfo info; Exception next; - this(char[] msg, Exception next = null) + this( char[] msg, Exception next = null ) { this.msg = msg; this.next = next; + this.info = traceContext(); } - this(char[] msg, char[] file, size_t line, Exception next = null) + this( char[] msg, char[] file, size_t line, Exception next = null ) { this(msg, next); this.file = file; this.line = line; + this.info = traceContext(); } char[] toString() @@ -915,6 +929,44 @@ } +alias Exception.TraceInfo function( void* ptr = null ) TraceHandler; +private TraceHandler traceHandler = null; + + +/** + * Overrides the default trace hander with a user-supplied version. + * + * Params: + * h = The new trace handler. Set to null to use the default handler. + */ +extern (C) void rt_setTraceHandler( TraceHandler h ) +{ + traceHandler = h; +} + + +/** + * This function will be called when an Exception is constructed. The + * user-supplied trace handler will be called if one has been supplied, + * otherwise no trace will be generated. + * + * Params: + * ptr = A pointer to the location from which to generate the trace, or null + * if the trace should be generated from within the trace handler + * itself. + * + * Returns: + * An object describing the current calling context or null if no handler is + * supplied. + */ +Exception.TraceInfo traceContext( void* ptr = null ) +{ + if( traceHandler is null ) + return null; + return traceHandler( ptr ); +} + + //////////////////////////////////////////////////////////////////////////////// // ModuleInfo //////////////////////////////////////////////////////////////////////////////// @@ -1094,11 +1146,20 @@ // Monitor //////////////////////////////////////////////////////////////////////////////// -alias Object.Monitor IMonitor; +alias Object.Monitor IMonitor; +alias void delegate(Object) DEvent; +// NOTE: The dtor callback feature is only supported for monitors that are not +// supplied by the user. The assumption is that any object with a user- +// supplied monitor may have special storage or lifetime requirements and +// that as a result, storing references to local objects within Monitor +// may not be safe or desirable. Thus, devt is only valid if impl is +// null. struct Monitor { IMonitor impl; + /* internal */ + DEvent[] devt; /* stuff */ } @@ -1126,6 +1187,7 @@ IMonitor i = m.impl; if (i is null) { + _d_monitor_devt(m, h); _d_monitor_destroy(h); setMonitor(h, null); return; @@ -1168,3 +1230,71 @@ } i.unlock(); } + +extern (C) void _d_monitor_devt(Monitor* m, Object h) +{ + if (m.devt.length) + { + DEvent[] devt; + + synchronized (h) + { + devt = m.devt; + m.devt = null; + } + foreach (v; devt) + { + if (v) + v(h); + } + free(devt.ptr); + } +} + +extern (C) void rt_attachDisposeEvent(Object h, DEvent e) +{ + synchronized (h) + { + Monitor* m = getMonitor(h); + assert(m.impl is null); + + foreach (inout v; m.devt) + { + if (v is null || v == e) + { + v = e; + return; + } + } + + auto len = m.devt.length + 4; // grow by 4 elements + auto pos = m.devt.length; // insert position + auto p = realloc(m.devt.ptr, DEvent.sizeof * len); + if (!p) + onOutOfMemoryError(); + m.devt = (cast(DEvent*)p)[0 .. len]; + m.devt[pos+1 .. len] = null; + m.devt[pos] = e; + } +} + +extern (C) void rt_detachDisposeEvent(Object h, DEvent e) +{ + synchronized (h) + { + Monitor* m = getMonitor(h); + assert(m.impl is null); + + foreach (p, v; m.devt) + { + if (v == e) + { + memmove(&m.devt[p], + &m.devt[p+1], + (m.devt.length - p - 1) * DEvent.sizeof); + m.devt[$ - 1] = null; + return; + } + } + } +} diff -r 4c2689d57ba4 -r 7816aafeea3c tango/lib/compiler/llvmdc/typeinfo/ti_AC.d --- a/tango/lib/compiler/llvmdc/typeinfo/ti_AC.d Tue May 27 22:14:24 2008 +0200 +++ b/tango/lib/compiler/llvmdc/typeinfo/ti_AC.d Fri May 30 19:32:04 2008 +0200 @@ -2,7 +2,7 @@ // Object[] -class TypeInfo_AC : TypeInfo +class TypeInfo_AC : TypeInfo_Array { hash_t getHash(void *p) { Object[] s = *cast(Object[]*)p; diff -r 4c2689d57ba4 -r 7816aafeea3c tango/lib/compiler/llvmdc/typeinfo/ti_Acdouble.d --- a/tango/lib/compiler/llvmdc/typeinfo/ti_Acdouble.d Tue May 27 22:14:24 2008 +0200 +++ b/tango/lib/compiler/llvmdc/typeinfo/ti_Acdouble.d Fri May 30 19:32:04 2008 +0200 @@ -27,7 +27,7 @@ // cdouble[] -class TypeInfo_Ar : TypeInfo +class TypeInfo_Ar : TypeInfo_Array { char[] toString() { return "cdouble[]"; } diff -r 4c2689d57ba4 -r 7816aafeea3c tango/lib/compiler/llvmdc/typeinfo/ti_Acfloat.d --- a/tango/lib/compiler/llvmdc/typeinfo/ti_Acfloat.d Tue May 27 22:14:24 2008 +0200 +++ b/tango/lib/compiler/llvmdc/typeinfo/ti_Acfloat.d Fri May 30 19:32:04 2008 +0200 @@ -27,7 +27,7 @@ // cfloat[] -class TypeInfo_Aq : TypeInfo +class TypeInfo_Aq : TypeInfo_Array { char[] toString() { return "cfloat[]"; } diff -r 4c2689d57ba4 -r 7816aafeea3c tango/lib/compiler/llvmdc/typeinfo/ti_Acreal.d --- a/tango/lib/compiler/llvmdc/typeinfo/ti_Acreal.d Tue May 27 22:14:24 2008 +0200 +++ b/tango/lib/compiler/llvmdc/typeinfo/ti_Acreal.d Fri May 30 19:32:04 2008 +0200 @@ -27,7 +27,7 @@ // creal[] -class TypeInfo_Ac : TypeInfo +class TypeInfo_Ac : TypeInfo_Array { char[] toString() { return "creal[]"; } diff -r 4c2689d57ba4 -r 7816aafeea3c tango/lib/compiler/llvmdc/typeinfo/ti_Adouble.d --- a/tango/lib/compiler/llvmdc/typeinfo/ti_Adouble.d Tue May 27 22:14:24 2008 +0200 +++ b/tango/lib/compiler/llvmdc/typeinfo/ti_Adouble.d Fri May 30 19:32:04 2008 +0200 @@ -27,7 +27,7 @@ // double[] -class TypeInfo_Ad : TypeInfo +class TypeInfo_Ad : TypeInfo_Array { char[] toString() { return "double[]"; } diff -r 4c2689d57ba4 -r 7816aafeea3c tango/lib/compiler/llvmdc/typeinfo/ti_Afloat.d --- a/tango/lib/compiler/llvmdc/typeinfo/ti_Afloat.d Tue May 27 22:14:24 2008 +0200 +++ b/tango/lib/compiler/llvmdc/typeinfo/ti_Afloat.d Fri May 30 19:32:04 2008 +0200 @@ -27,7 +27,7 @@ // float[] -class TypeInfo_Af : TypeInfo +class TypeInfo_Af : TypeInfo_Array { char[] toString() { return "float[]"; } diff -r 4c2689d57ba4 -r 7816aafeea3c tango/lib/compiler/llvmdc/typeinfo/ti_Ag.d --- a/tango/lib/compiler/llvmdc/typeinfo/ti_Ag.d Tue May 27 22:14:24 2008 +0200 +++ b/tango/lib/compiler/llvmdc/typeinfo/ti_Ag.d Fri May 30 19:32:04 2008 +0200 @@ -6,7 +6,7 @@ // byte[] -class TypeInfo_Ag : TypeInfo +class TypeInfo_Ag : TypeInfo_Array { char[] toString() { return "byte[]"; } diff -r 4c2689d57ba4 -r 7816aafeea3c tango/lib/compiler/llvmdc/typeinfo/ti_Aint.d --- a/tango/lib/compiler/llvmdc/typeinfo/ti_Aint.d Tue May 27 22:14:24 2008 +0200 +++ b/tango/lib/compiler/llvmdc/typeinfo/ti_Aint.d Fri May 30 19:32:04 2008 +0200 @@ -5,7 +5,7 @@ // int[] -class TypeInfo_Ai : TypeInfo +class TypeInfo_Ai : TypeInfo_Array { char[] toString() { return "int[]"; } diff -r 4c2689d57ba4 -r 7816aafeea3c tango/lib/compiler/llvmdc/typeinfo/ti_Along.d --- a/tango/lib/compiler/llvmdc/typeinfo/ti_Along.d Tue May 27 22:14:24 2008 +0200 +++ b/tango/lib/compiler/llvmdc/typeinfo/ti_Along.d Fri May 30 19:32:04 2008 +0200 @@ -5,7 +5,7 @@ // long[] -class TypeInfo_Al : TypeInfo +class TypeInfo_Al : TypeInfo_Array { char[] toString() { return "long[]"; } diff -r 4c2689d57ba4 -r 7816aafeea3c tango/lib/compiler/llvmdc/typeinfo/ti_Areal.d --- a/tango/lib/compiler/llvmdc/typeinfo/ti_Areal.d Tue May 27 22:14:24 2008 +0200 +++ b/tango/lib/compiler/llvmdc/typeinfo/ti_Areal.d Fri May 30 19:32:04 2008 +0200 @@ -27,7 +27,7 @@ // real[] -class TypeInfo_Ae : TypeInfo +class TypeInfo_Ae : TypeInfo_Array { char[] toString() { return "real[]"; } diff -r 4c2689d57ba4 -r 7816aafeea3c tango/lib/compiler/llvmdc/typeinfo/ti_Ashort.d --- a/tango/lib/compiler/llvmdc/typeinfo/ti_Ashort.d Tue May 27 22:14:24 2008 +0200 +++ b/tango/lib/compiler/llvmdc/typeinfo/ti_Ashort.d Fri May 30 19:32:04 2008 +0200 @@ -5,7 +5,7 @@ // short[] -class TypeInfo_As : TypeInfo +class TypeInfo_As : TypeInfo_Array { char[] toString() { return "short[]"; } diff -r 4c2689d57ba4 -r 7816aafeea3c tango/lib/gc/basic/gc.d --- a/tango/lib/gc/basic/gc.d Tue May 27 22:14:24 2008 +0200 +++ b/tango/lib/gc/basic/gc.d Fri May 30 19:32:04 2008 +0200 @@ -69,8 +69,15 @@ // // NOTE: Due to popular demand, this has been re-enabled. It still has // the problems mentioned above though, so I guess we'll see. + version(LLVMDC) + { + // currently crashes a lot + } + else + { _gc.fullCollectNoStack(); // not really a 'collect all' -- still scans // static data area, roots, and ranges. + } _gc.Dtor(); } diff -r 4c2689d57ba4 -r 7816aafeea3c tango/tango/text/convert/Layout.d --- a/tango/tango/text/convert/Layout.d Tue May 27 22:14:24 2008 +0200 +++ b/tango/tango/text/convert/Layout.d Fri May 30 19:32:04 2008 +0200 @@ -193,8 +193,26 @@ assert (formatStr, "null format specifier"); assert (arguments.length < 64, "too many args in Layout.convert"); - version (X86_64) + version (LLVMDC) + { + static va_list get_va_arg(TypeInfo ti, ref va_list vp) { + auto tisize = ti.tsize; + size_t size = tisize > size_t.sizeof ? size_t.sizeof : tisize; + va_list vptmp = cast(va_list)((cast(size_t)vp + size - 1) & ~(size - 1)); + vp = vptmp + tisize; + return vptmp; + } + + Arg[64] arglist = void; + foreach (i, arg; arguments) + { + arglist[i] = get_va_arg(arg, args); + } + } + else version (X86_64) + { + // code for x86-64 GDC Arg[64] arglist = void; int[64] intargs = void; byte[64] byteargs = void; @@ -265,25 +283,9 @@ } } } - else version (LLVMDC) - { - static va_list get_va_arg(TypeInfo ti, ref va_list vp) - { - auto tisize = ti.tsize; - size_t size = tisize > size_t.sizeof ? size_t.sizeof : tisize; - va_list vptmp = cast(va_list)((cast(size_t)vp + size - 1) & ~(size - 1)); - vp = vptmp + tisize; - return vptmp; - } - - Arg[64] arglist = void; - foreach (i, arg; arguments) - { - arglist[i] = get_va_arg(arg, args); - } - } else { + // code for DMD & x86 GDC (may also work on other 32-bit targets) Arg[64] arglist = void; foreach (i, arg; arguments) {