# HG changeset patch # User lindquist # Date 1213889432 -7200 # Node ID 665b81613475d878904eb98409cb5e7a424800b4 # Parent 9f228c1e5311d8f7ea4ff9350be577bb62c7e2b4 [svn r296] Removed: the 'suite' dir, it never took off! Fixed: foreach statement, key-type checks were buggy. Fixed: setting LLVMDC versions on the command line is now an error. Fixed: array compare runtime had incorrect param attrs on call. Fixed: index expressions on dynamic array slices w/o storage was broken. Fixed: scope classes had incorrect finalization in some cases. Fixed: when outputting !ClassInfoS !OffsetTypeInfoS, static class members were trying to be included, crashing the compiler. Fixed: calling LLVMDC with -inline but not any -O option caused assertion failure. Changed: the runtime now uses a single interface to "get" to !TypeInfoS, part of eliminating duplicate !TypeInfo codegen. diff -r 9f228c1e5311 -r 665b81613475 dmd/cond.c --- a/dmd/cond.c Thu Jun 19 13:54:31 2008 +0200 +++ b/dmd/cond.c Thu Jun 19 17:30:32 2008 +0200 @@ -127,7 +127,9 @@ { static char* reserved[] = { - "DigitalMars", "X86", "X86_64", + "DigitalMars", "LLVM", "LLVMDC", + "LLVM64", "LLVM_X86_FP80", + "X86", "X86_64", "PPC", "PPC64", "Windows", "Win32", "Win64", "linux", "LittleEndian", "BigEndian", diff -r 9f228c1e5311 -r 665b81613475 dmd/mars.h --- a/dmd/mars.h Thu Jun 19 13:54:31 2008 +0200 +++ b/dmd/mars.h Thu Jun 19 17:30:32 2008 +0200 @@ -123,7 +123,7 @@ char *resfile; char *exefile; - // LLVM stuff + // LLVMDC stuff char *llvmArch; char forceBE; char *tt_arch; @@ -291,6 +291,7 @@ MATCHexact // exact match }; +// LLVMDC enum ARCH { ARCHx86, diff -r 9f228c1e5311 -r 665b81613475 dmd/statement.c --- a/dmd/statement.c Thu Jun 19 13:54:31 2008 +0200 +++ b/dmd/statement.c Thu Jun 19 17:30:32 2008 +0200 @@ -1180,12 +1180,17 @@ if (arg->storageClass & (STCout | STCref | STClazy)) error("no storage class for key %s", arg->ident->toChars()); TY keyty = arg->type->ty; - if ((keyty != Tint32 && keyty != Tuns32) && - (global.params.is64bit && keyty != Tint64 && keyty != Tuns64) - ) - { - error("foreach: key type must be %s, not %s", global.params.is64bit ? "int, uint, long or ulong" : "int or uint",arg->type->toChars()); - } + if (global.params.is64bit) + { + if (keyty != Tint32 && keyty != Tuns32 && keyty != Tint64 && keyty != Tuns64) + { + error("foreach: key type must be int, uint, long or ulong, not %s", key->type->toChars()); + } + } + else if (keyty != Tint32 && keyty != Tuns32) + { + error("foreach: key type must be int or uint, not %s", key->type->toChars()); + } Initializer *ie = new ExpInitializer(0, new IntegerExp(k)); VarDeclaration *var = new VarDeclaration(loc, arg->type, arg->ident, ie); var->storage_class |= STCconst; @@ -1320,14 +1325,20 @@ error("foreach: %s is not an array of %s", tab->toChars(), value->type->toChars()); } - if (key && - ((key->type->ty != Tint32 && key->type->ty != Tuns32) && - (global.params.is64bit && key->type->ty != Tint64 && key->type->ty != Tuns64) - ) - ) - { - error("foreach: key type must be %s, not %s", global.params.is64bit ? "int, uint, long or ulong" : "int or uint", key->type->toChars()); - } + if (key) + { + if (global.params.is64bit) + { + if (key->type->ty != Tint32 && key->type->ty != Tuns32 && key->type->ty != Tint64 && key->type->ty != Tuns64) + { + error("foreach: key type must be int, uint, long or ulong, not %s", key->type->toChars()); + } + } + else if (key->type->ty != Tint32 && key->type->ty != Tuns32) + { + error("foreach: key type must be int or uint, not %s", key->type->toChars()); + } + } if (key && key->storage_class & (STCout | STCref)) error("foreach: key cannot be out or ref"); diff -r 9f228c1e5311 -r 665b81613475 gen/aa.cpp --- a/gen/aa.cpp Thu Jun 19 13:54:31 2008 +0200 +++ b/gen/aa.cpp Thu Jun 19 17:30:32 2008 +0200 @@ -57,7 +57,6 @@ { // keyti param Type* keytype = key->getType(); - keytype->getTypeInfo(NULL); return DtoTypeInfoOf(keytype, false); } diff -r 9f228c1e5311 -r 665b81613475 gen/arrays.cpp --- a/gen/arrays.cpp Thu Jun 19 13:54:31 2008 +0200 +++ b/gen/arrays.cpp Thu Jun 19 17:30:32 2008 +0200 @@ -750,7 +750,15 @@ args.push_back(DtoBitCast(tival, pt)); } - return gIR->ir->CreateCall(fn, args.begin(), args.end(), "tmp"); + llvm::CallInst* call = gIR->ir->CreateCall(fn, args.begin(), args.end(), "tmp"); + + // set param attrs + llvm::PAListPtr palist; + palist = palist.addAttr(1, llvm::ParamAttr::ByVal); + palist = palist.addAttr(2, llvm::ParamAttr::ByVal); + call->setParamAttrs(palist); + + return call; } ////////////////////////////////////////////////////////////////////////////////////////// diff -r 9f228c1e5311 -r 665b81613475 gen/classes.cpp --- a/gen/classes.cpp Thu Jun 19 13:54:31 2008 +0200 +++ b/gen/classes.cpp Thu Jun 19 17:30:32 2008 +0200 @@ -447,7 +447,7 @@ // typeinfo if (needs_definition) - cd->type->getTypeInfo(NULL); + DtoTypeInfoOf(cd->type, false); } ////////////////////////////////////////////////////////////////////////////////////////// @@ -1255,16 +1255,12 @@ size_t offset = gTargetData->getStructLayout(isaStruct(cd->type->ir.type->get()))->getElementOffset(vd->ir.irField->index+2); inits.push_back(DtoConstSize_t(offset)); - vd->type->getTypeInfo(NULL); - assert(vd->type->vtinfo); - DtoForceDeclareDsymbol(vd->type->vtinfo); - LLConstant* c = isaConstant(vd->type->vtinfo->ir.getIrValue()); - - const LLType* tiTy = getPtrToType(Type::typeinfo->type->ir.type->get()); + LLConstant* c = DtoTypeInfoOf(vd->type, true); + const LLType* tiTy = c->getType(); //Logger::cout() << "tiTy = " << *tiTy << '\n'; types.push_back(tiTy); - inits.push_back(llvm::ConstantExpr::getBitCast(c, tiTy)); + inits.push_back(c); const llvm::StructType* sTy = llvm::StructType::get(types); return llvm::ConstantStruct::get(sTy, inits); @@ -1285,9 +1281,12 @@ Dsymbol *sm = (Dsymbol *)cd2->members->data[i]; if (VarDeclaration* vd = sm->isVarDeclaration()) // is this enough? { - LLConstant* c = build_offti_entry(cd, vd); - assert(c); - arrayInits.push_back(c); + if (!vd->isDataseg()) // static members dont have an offset! + { + LLConstant* c = build_offti_entry(cd, vd); + assert(c); + arrayInits.push_back(c); + } } } } @@ -1389,7 +1388,7 @@ for (size_t i = 0; i < cd2->members->dim; i++) { Dsymbol *sm = (Dsymbol *)cd2->members->data[i]; - if (sm->isVarDeclaration()) // is this enough? + if (sm->isVarDeclaration() && !sm->isVarDeclaration()->isDataseg()) // is this enough? hasOffTi = true; //printf("sm = %s %s\n", sm->kind(), sm->toChars()); if (sm->hasPointers()) diff -r 9f228c1e5311 -r 665b81613475 gen/functions.cpp --- a/gen/functions.cpp Thu Jun 19 13:54:31 2008 +0200 +++ b/gen/functions.cpp Thu Jun 19 17:30:32 2008 +0200 @@ -105,8 +105,6 @@ int nbyval = 0; - llvm::PAListPtr palist; - for (int i=0; i < n; ++i) { Argument* arg = Argument::getNth(f->parameters, i); // ensure scalar @@ -122,11 +120,10 @@ arg->llvmByVal = !refOrOut; } else if (isaArray(at)) { + // static array are passed by reference Logger::println("sarray param"); assert(argT->ty == Tsarray); - //paramvec.push_back(getPtrToType(at->getContainedType(0))); paramvec.push_back(getPtrToType(at)); - //arg->llvmByVal = !refOrOut; // static array are passed by reference } else if (llvm::isa(at)) { Logger::println("opaque param"); diff -r 9f228c1e5311 -r 665b81613475 gen/optimizer.cpp --- a/gen/optimizer.cpp Thu Jun 19 13:54:31 2008 +0200 +++ b/gen/optimizer.cpp Thu Jun 19 17:30:32 2008 +0200 @@ -15,8 +15,6 @@ if (!doinline && lvl < 0) return; - assert(lvl >= 0 && lvl <= 5); - PassManager pm; pm.add(new TargetData(m)); diff -r 9f228c1e5311 -r 665b81613475 gen/structs.cpp --- a/gen/structs.cpp Thu Jun 19 13:54:31 2008 +0200 +++ b/gen/structs.cpp Thu Jun 19 17:30:32 2008 +0200 @@ -357,7 +357,7 @@ // emit typeinfo if (sd->getModule() == gIR->dmodule && sd->llvmInternal != LLVMnotypeinfo) - sd->type->getTypeInfo(NULL); + DtoTypeInfoOf(sd->type, false); } ////////////////////////////////////////////////////////////////////////////////////////// diff -r 9f228c1e5311 -r 665b81613475 gen/toir.cpp --- a/gen/toir.cpp Thu Jun 19 13:54:31 2008 +0200 +++ b/gen/toir.cpp Thu Jun 19 17:30:32 2008 +0200 @@ -124,7 +124,7 @@ else if (TypedefDeclaration* tdef = declaration->isTypedefDeclaration()) { Logger::println("TypedefDeclaration"); - tdef->type->getTypeInfo(NULL); + DtoTypeInfoOf(tdef->type, false); } // attribute declaration else if (AttribDeclaration* a = declaration->isAttribDeclaration()) @@ -287,12 +287,9 @@ } else if (TypeInfoDeclaration* ti = var->isTypeInfoDeclaration()) { - DtoForceDeclareDsymbol(ti); - assert(ti->ir.getIrValue()); const LLType* vartype = DtoType(type); - LLConstant* m = isaConstant(ti->ir.getIrValue()); - assert(m); - if (ti->ir.getIrValue()->getType() != getPtrToType(vartype)) + LLConstant* m = DtoTypeInfoOf(ti->tinfo, false); + if (m->getType() != getPtrToType(vartype)) m = llvm::ConstantExpr::getBitCast(m, vartype); return m; } @@ -1512,8 +1509,7 @@ arrptr = DtoGEP(l->getRVal(), zero, r->getRVal()); } else if (e1type->ty == Tarray) { - arrptr = DtoGEP(l->getRVal(),zero,one); - arrptr = DtoLoad(arrptr); + arrptr = DtoArrayPtr(l); arrptr = DtoGEP1(arrptr,r->getRVal()); } else if (e1type->ty == Taarray) { @@ -1982,10 +1978,9 @@ } else if (DVarValue* vv = dval->isVar()) { if (vv->var && vv->var->onstack) { - if (tc->sym->dtors.dim > 0) { + if (tc->sym->dtors.dim > 0) DtoFinalizeClass(dval->getRVal()); - onstack = true; - } + onstack = true; } } if (!onstack) { @@ -2496,29 +2491,6 @@ { return DtoCatArrayElement(type, e1, e2); } - - /* - IRExp* ex = p->topexp(); - if (ex && ex->e2 == this) { - assert(ex->v); - if (arrNarr) - DtoCatArrays(ex->v->getLVal(),e1,e2); - else - DtoCatArrayElement(ex->v->getLVal(),e1,e2); - return new DImValue(type, ex->v->getLVal(), true); - } - else { - assert(t->ty == Tarray); - const LLType* arrty = DtoType(t); - LLValue* dst = new llvm::AllocaInst(arrty, "tmpmem", p->topallocapoint()); - if (arrNarr) - DtoCatAr - DtoCatArrays(dst,e1,e2); - else - DtoCatArrayElement(dst,e1,e2); - return new DVarValue(type, dst, true); - } - */ } ////////////////////////////////////////////////////////////////////////////////////////// diff -r 9f228c1e5311 -r 665b81613475 gen/toobj.cpp --- a/gen/toobj.cpp Thu Jun 19 13:54:31 2008 +0200 +++ b/gen/toobj.cpp Thu Jun 19 17:30:32 2008 +0200 @@ -606,7 +606,7 @@ LOG_SCOPE; // generate typeinfo - type->getTypeInfo(NULL); + DtoTypeInfoOf(type, false); } /* ================================================================== */ diff -r 9f228c1e5311 -r 665b81613475 gen/typinf.cpp --- a/gen/typinf.cpp Thu Jun 19 13:54:31 2008 +0200 +++ b/gen/typinf.cpp Thu Jun 19 17:30:32 2008 +0200 @@ -383,19 +383,8 @@ TypedefDeclaration *sd = tc->sym; // TypeInfo base - //const LLPointerType* basept = isaPointer(initZ->getOperand(1)->getType()); - //sinits.push_back(llvm::ConstantPointerNull::get(basept)); - Logger::println("generating base typeinfo"); - //sd->basetype = sd->basetype->merge(); - - sd->basetype->getTypeInfo(NULL); // generate vtinfo - assert(sd->basetype->vtinfo); - DtoForceDeclareDsymbol(sd->basetype->vtinfo); - - assert(sd->basetype->vtinfo->ir.irGlobal->value); - assert(llvm::isa(sd->basetype->vtinfo->ir.irGlobal->value)); - LLConstant* castbase = llvm::cast(sd->basetype->vtinfo->ir.irGlobal->value); - castbase = llvm::ConstantExpr::getBitCast(castbase, stype->getElementType(2)); + LLConstant* castbase = DtoTypeInfoOf(sd->basetype, true); + assert(castbase->getType() == stype->getElementType(2)); sinits.push_back(castbase); // char[] name @@ -468,18 +457,8 @@ EnumDeclaration *sd = tc->sym; // TypeInfo base - //const LLPointerType* basept = isaPointer(initZ->getOperand(1)->getType()); - //sinits.push_back(llvm::ConstantPointerNull::get(basept)); - Logger::println("generating base typeinfo"); - //sd->basetype = sd->basetype->merge(); - - sd->memtype->getTypeInfo(NULL); // generate vtinfo - assert(sd->memtype->vtinfo); - DtoForceDeclareDsymbol(sd->memtype->vtinfo); - - assert(llvm::isa(sd->memtype->vtinfo->ir.irGlobal->value)); - LLConstant* castbase = llvm::cast(sd->memtype->vtinfo->ir.irGlobal->value); - castbase = llvm::ConstantExpr::getBitCast(castbase, stype->getElementType(2)); + LLConstant* castbase = DtoTypeInfoOf(sd->memtype, true); + assert(castbase->getType() == stype->getElementType(2)); sinits.push_back(castbase); // char[] name @@ -543,13 +522,8 @@ sinits.push_back(llvm::ConstantPointerNull::get(getPtrToType(LLType::Int8Ty))); // TypeInfo base - Logger::println("generating base typeinfo"); - basetype->getTypeInfo(NULL); - assert(basetype->vtinfo); - DtoForceDeclareDsymbol(basetype->vtinfo); - assert(llvm::isa(basetype->vtinfo->ir.irGlobal->value)); - LLConstant* castbase = llvm::cast(basetype->vtinfo->ir.irGlobal->value); - castbase = llvm::ConstantExpr::getBitCast(castbase, stype->getElementType(2)); + LLConstant* castbase = DtoTypeInfoOf(basetype, true); + assert(castbase->getType() == stype->getElementType(2)); sinits.push_back(castbase); // create the symbol @@ -656,13 +630,8 @@ // value typeinfo assert(tinfo->ty == Tsarray); TypeSArray *tc = (TypeSArray *)tinfo; - tc->next->getTypeInfo(NULL); - - // get symbol - assert(tc->next->vtinfo); - DtoForceDeclareDsymbol(tc->next->vtinfo); - LLConstant* castbase = isaConstant(tc->next->vtinfo->ir.irGlobal->value); - castbase = llvm::ConstantExpr::getBitCast(castbase, stype->getElementType(2)); + LLConstant* castbase = DtoTypeInfoOf(tc->next, true); + assert(castbase->getType() == stype->getElementType(2)); sinits.push_back(castbase); // length @@ -721,23 +690,13 @@ TypeAArray *tc = (TypeAArray *)tinfo; // value typeinfo - tc->next->getTypeInfo(NULL); - - // get symbol - assert(tc->next->vtinfo); - DtoForceDeclareDsymbol(tc->next->vtinfo); - LLConstant* castbase = isaConstant(tc->next->vtinfo->ir.irGlobal->value); - castbase = llvm::ConstantExpr::getBitCast(castbase, stype->getElementType(2)); + LLConstant* castbase = DtoTypeInfoOf(tc->next, true); + assert(castbase->getType() == stype->getElementType(2)); sinits.push_back(castbase); // key typeinfo - tc->index->getTypeInfo(NULL); - - // get symbol - assert(tc->index->vtinfo); - DtoForceDeclareDsymbol(tc->index->vtinfo); - castbase = isaConstant(tc->index->vtinfo->ir.irGlobal->value); - castbase = llvm::ConstantExpr::getBitCast(castbase, stype->getElementType(3)); + castbase = DtoTypeInfoOf(tc->index, true); + assert(castbase->getType() == stype->getElementType(3)); sinits.push_back(castbase); // create the symbol @@ -1179,12 +1138,9 @@ for (size_t i = 0; i < dim; i++) { Argument *arg = (Argument *)tu->arguments->data[i]; - arg->type->getTypeInfo(NULL); - DtoForceDeclareDsymbol(arg->type->vtinfo); - assert(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); + LLConstant* castbase = DtoTypeInfoOf(arg->type, true); + assert(castbase->getType() == tiTy); + arrInits.push_back(castbase); } // build array type diff -r 9f228c1e5311 -r 665b81613475 suite/dwarfdebug/dwarf1/app.d --- a/suite/dwarfdebug/dwarf1/app.d Thu Jun 19 13:54:31 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,12 +0,0 @@ -module app; -import lib; - -void func() -{ - lib_func(); -} - -void main() -{ - func(); -} diff -r 9f228c1e5311 -r 665b81613475 suite/dwarfdebug/dwarf1/build.sh --- a/suite/dwarfdebug/dwarf1/build.sh Thu Jun 19 13:54:31 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,3 +0,0 @@ -#!/bin/bash -llvmdc lib.d -c -g -dis -llvmdc app.d lib.bc -g -dis -ofapp diff -r 9f228c1e5311 -r 665b81613475 suite/dwarfdebug/dwarf1/lib.d --- a/suite/dwarfdebug/dwarf1/lib.d Thu Jun 19 13:54:31 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,7 +0,0 @@ -module lib; - -void lib_func() -{ - int* p; - *p = 666; -} diff -r 9f228c1e5311 -r 665b81613475 suite/dwarfdebug/dwarf2/app.d --- a/suite/dwarfdebug/dwarf2/app.d Thu Jun 19 13:54:31 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,14 +0,0 @@ -module app; -import lib; - -void func() -{ - int* ip; - int i = lib_templ_func(ip); -} - -int main(char[][] args) -{ - func(); - return 0; -} diff -r 9f228c1e5311 -r 665b81613475 suite/dwarfdebug/dwarf2/build.sh --- a/suite/dwarfdebug/dwarf2/build.sh Thu Jun 19 13:54:31 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,3 +0,0 @@ -#!/bin/bash -llvmdc lib.d -c -g -dis -llvmdc app.d lib.bc -g -dis -ofapp diff -r 9f228c1e5311 -r 665b81613475 suite/dwarfdebug/dwarf2/lib.d --- a/suite/dwarfdebug/dwarf2/lib.d Thu Jun 19 13:54:31 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,6 +0,0 @@ -module lib; - -T lib_templ_func(T)(T* a) -{ - return *a; -} diff -r 9f228c1e5311 -r 665b81613475 tango/lib/compiler/llvmdc/genobj.d --- a/tango/lib/compiler/llvmdc/genobj.d Thu Jun 19 13:54:31 2008 +0200 +++ b/tango/lib/compiler/llvmdc/genobj.d Thu Jun 19 17:30:32 2008 +0200 @@ -33,6 +33,7 @@ /* * Modified by Sean Kelly for use with Tango. + * Modified by Tomas Lindquist Olsen for use with LLVMDC. */ module object; @@ -56,7 +57,7 @@ //alias typeof(int.sizeof) size_t; //alias typeof(cast(void*)0 - cast(void*)0) ptrdiff_t; -version( X86_64 ) +version( LLVM64 ) { alias ulong size_t; alias long ptrdiff_t;