From 928f7d4de595b2fcd7d84d53ff64bbaa7f724f29 Mon Sep 17 00:00:00 2001 From: Tomas Lindquist Olsen Date: Thu, 19 Jun 2008 17:30:32 +0200 Subject: [PATCH] [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. --- dmd/cond.c | 4 +- dmd/mars.h | 3 +- dmd/statement.c | 39 ++++++++++------ gen/aa.cpp | 1 - gen/arrays.cpp | 10 +++- gen/classes.cpp | 23 +++++----- gen/functions.cpp | 5 +- gen/optimizer.cpp | 2 - gen/structs.cpp | 2 +- gen/toir.cpp | 40 +++------------- gen/toobj.cpp | 2 +- gen/typinf.cpp | 74 ++++++------------------------ suite/dwarfdebug/dwarf1/app.d | 12 ----- suite/dwarfdebug/dwarf1/build.sh | 3 -- suite/dwarfdebug/dwarf1/lib.d | 7 --- suite/dwarfdebug/dwarf2/app.d | 14 ------ suite/dwarfdebug/dwarf2/build.sh | 3 -- suite/dwarfdebug/dwarf2/lib.d | 6 --- tango/lib/compiler/llvmdc/genobj.d | 3 +- 19 files changed, 76 insertions(+), 177 deletions(-) delete mode 100644 suite/dwarfdebug/dwarf1/app.d delete mode 100755 suite/dwarfdebug/dwarf1/build.sh delete mode 100644 suite/dwarfdebug/dwarf1/lib.d delete mode 100644 suite/dwarfdebug/dwarf2/app.d delete mode 100755 suite/dwarfdebug/dwarf2/build.sh delete mode 100644 suite/dwarfdebug/dwarf2/lib.d diff --git a/dmd/cond.c b/dmd/cond.c index 309fa34b..5ba97f7c 100644 --- a/dmd/cond.c +++ b/dmd/cond.c @@ -127,7 +127,9 @@ void VersionCondition::checkPredefined(Loc loc, char *ident) { 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 --git a/dmd/mars.h b/dmd/mars.h index 4605510a..ef21cf8f 100644 --- a/dmd/mars.h +++ b/dmd/mars.h @@ -123,7 +123,7 @@ struct Param char *resfile; char *exefile; - // LLVM stuff + // LLVMDC stuff char *llvmArch; char forceBE; char *tt_arch; @@ -291,6 +291,7 @@ enum MATCH MATCHexact // exact match }; +// LLVMDC enum ARCH { ARCHx86, diff --git a/dmd/statement.c b/dmd/statement.c index f099fdff..0117aeab 100644 --- a/dmd/statement.c +++ b/dmd/statement.c @@ -1180,12 +1180,17 @@ Statement *ForeachStatement::semantic(Scope *sc) 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 @@ Statement *ForeachStatement::semantic(Scope *sc) 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 --git a/gen/aa.cpp b/gen/aa.cpp index 4072b373..254240f1 100644 --- a/gen/aa.cpp +++ b/gen/aa.cpp @@ -57,7 +57,6 @@ static LLValue* to_keyti(DValue* key) { // keyti param Type* keytype = key->getType(); - keytype->getTypeInfo(NULL); return DtoTypeInfoOf(keytype, false); } diff --git a/gen/arrays.cpp b/gen/arrays.cpp index 08cbcc1e..a3047c47 100644 --- a/gen/arrays.cpp +++ b/gen/arrays.cpp @@ -750,7 +750,15 @@ static LLValue* DtoArrayEqCmp_impl(const char* func, DValue* l, DValue* r, bool 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 --git a/gen/classes.cpp b/gen/classes.cpp index 766f0d1d..cdd08d7d 100644 --- a/gen/classes.cpp +++ b/gen/classes.cpp @@ -447,7 +447,7 @@ void DtoDeclareClass(ClassDeclaration* cd) // typeinfo if (needs_definition) - cd->type->getTypeInfo(NULL); + DtoTypeInfoOf(cd->type, false); } ////////////////////////////////////////////////////////////////////////////////////////// @@ -1255,16 +1255,12 @@ static LLConstant* build_offti_entry(ClassDeclaration* cd, VarDeclaration* vd) 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 @@ static LLConstant* build_offti_array(ClassDeclaration* cd, LLConstant* init) 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 @@ static uint build_classinfo_flags(ClassDeclaration* cd) 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 --git a/gen/functions.cpp b/gen/functions.cpp index 777e1207..023970c7 100644 --- a/gen/functions.cpp +++ b/gen/functions.cpp @@ -105,8 +105,6 @@ const llvm::FunctionType* DtoFunctionType(Type* type, const LLType* thistype, bo 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 @@ const llvm::FunctionType* DtoFunctionType(Type* type, const LLType* thistype, bo 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 --git a/gen/optimizer.cpp b/gen/optimizer.cpp index 7148d74e..134c79ee 100644 --- a/gen/optimizer.cpp +++ b/gen/optimizer.cpp @@ -15,8 +15,6 @@ void llvmdc_optimize_module(Module* m, char lvl, bool doinline) if (!doinline && lvl < 0) return; - assert(lvl >= 0 && lvl <= 5); - PassManager pm; pm.add(new TargetData(m)); diff --git a/gen/structs.cpp b/gen/structs.cpp index ede8d7ee..d7a973e0 100644 --- a/gen/structs.cpp +++ b/gen/structs.cpp @@ -357,7 +357,7 @@ void DtoConstInitStruct(StructDeclaration* sd) // emit typeinfo if (sd->getModule() == gIR->dmodule && sd->llvmInternal != LLVMnotypeinfo) - sd->type->getTypeInfo(NULL); + DtoTypeInfoOf(sd->type, false); } ////////////////////////////////////////////////////////////////////////////////////////// diff --git a/gen/toir.cpp b/gen/toir.cpp index b894dae6..d7fad4ca 100644 --- a/gen/toir.cpp +++ b/gen/toir.cpp @@ -124,7 +124,7 @@ DValue* DeclarationExp::toElem(IRState* p) 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 @@ LLConstant* VarExp::toConstElem(IRState* p) } 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 @@ DValue* IndexExp::toElem(IRState* p) 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 @@ DValue* DeleteExp::toElem(IRState* p) } 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 @@ DValue* CatExp::toElem(IRState* p) { 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 --git a/gen/toobj.cpp b/gen/toobj.cpp index 7eb15e29..dc08ada5 100644 --- a/gen/toobj.cpp +++ b/gen/toobj.cpp @@ -606,7 +606,7 @@ void TypedefDeclaration::toObjFile() LOG_SCOPE; // generate typeinfo - type->getTypeInfo(NULL); + DtoTypeInfoOf(type, false); } /* ================================================================== */ diff --git a/gen/typinf.cpp b/gen/typinf.cpp index 15d09c76..669d4d9a 100644 --- a/gen/typinf.cpp +++ b/gen/typinf.cpp @@ -383,19 +383,8 @@ void TypeInfoTypedefDeclaration::llvmDefine() 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 @@ void TypeInfoEnumDeclaration::llvmDefine() 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 @@ static LLConstant* LLVM_D_Define_TypeInfoBase(Type* basetype, TypeInfoDeclaratio 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 @@ void TypeInfoStaticArrayDeclaration::llvmDefine() // 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 @@ void TypeInfoAssociativeArrayDeclaration::llvmDefine() 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 @@ void TypeInfoTupleDeclaration::llvmDefine() 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 --git a/suite/dwarfdebug/dwarf1/app.d b/suite/dwarfdebug/dwarf1/app.d deleted file mode 100644 index 4b013efa..00000000 --- a/suite/dwarfdebug/dwarf1/app.d +++ /dev/null @@ -1,12 +0,0 @@ -module app; -import lib; - -void func() -{ - lib_func(); -} - -void main() -{ - func(); -} diff --git a/suite/dwarfdebug/dwarf1/build.sh b/suite/dwarfdebug/dwarf1/build.sh deleted file mode 100755 index 07d8303f..00000000 --- a/suite/dwarfdebug/dwarf1/build.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash -llvmdc lib.d -c -g -dis -llvmdc app.d lib.bc -g -dis -ofapp diff --git a/suite/dwarfdebug/dwarf1/lib.d b/suite/dwarfdebug/dwarf1/lib.d deleted file mode 100644 index 3f57ac5e..00000000 --- a/suite/dwarfdebug/dwarf1/lib.d +++ /dev/null @@ -1,7 +0,0 @@ -module lib; - -void lib_func() -{ - int* p; - *p = 666; -} diff --git a/suite/dwarfdebug/dwarf2/app.d b/suite/dwarfdebug/dwarf2/app.d deleted file mode 100644 index f63152c2..00000000 --- a/suite/dwarfdebug/dwarf2/app.d +++ /dev/null @@ -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 --git a/suite/dwarfdebug/dwarf2/build.sh b/suite/dwarfdebug/dwarf2/build.sh deleted file mode 100755 index 07d8303f..00000000 --- a/suite/dwarfdebug/dwarf2/build.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash -llvmdc lib.d -c -g -dis -llvmdc app.d lib.bc -g -dis -ofapp diff --git a/suite/dwarfdebug/dwarf2/lib.d b/suite/dwarfdebug/dwarf2/lib.d deleted file mode 100644 index d1c7d2c2..00000000 --- a/suite/dwarfdebug/dwarf2/lib.d +++ /dev/null @@ -1,6 +0,0 @@ -module lib; - -T lib_templ_func(T)(T* a) -{ - return *a; -} diff --git a/tango/lib/compiler/llvmdc/genobj.d b/tango/lib/compiler/llvmdc/genobj.d index c0a2ca34..1fe2f31e 100644 --- a/tango/lib/compiler/llvmdc/genobj.d +++ b/tango/lib/compiler/llvmdc/genobj.d @@ -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 @@ private //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;