[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.
This commit is contained in:
Tomas Lindquist Olsen 2008-06-19 17:30:32 +02:00
parent f235b71c7b
commit 928f7d4de5
19 changed files with 76 additions and 177 deletions

View file

@ -127,7 +127,9 @@ void VersionCondition::checkPredefined(Loc loc, char *ident)
{ {
static char* reserved[] = static char* reserved[] =
{ {
"DigitalMars", "X86", "X86_64", "DigitalMars", "LLVM", "LLVMDC",
"LLVM64", "LLVM_X86_FP80",
"X86", "X86_64", "PPC", "PPC64",
"Windows", "Win32", "Win64", "Windows", "Win32", "Win64",
"linux", "linux",
"LittleEndian", "BigEndian", "LittleEndian", "BigEndian",

View file

@ -123,7 +123,7 @@ struct Param
char *resfile; char *resfile;
char *exefile; char *exefile;
// LLVM stuff // LLVMDC stuff
char *llvmArch; char *llvmArch;
char forceBE; char forceBE;
char *tt_arch; char *tt_arch;
@ -291,6 +291,7 @@ enum MATCH
MATCHexact // exact match MATCHexact // exact match
}; };
// LLVMDC
enum ARCH enum ARCH
{ {
ARCHx86, ARCHx86,

View file

@ -1180,11 +1180,16 @@ Statement *ForeachStatement::semantic(Scope *sc)
if (arg->storageClass & (STCout | STCref | STClazy)) if (arg->storageClass & (STCout | STCref | STClazy))
error("no storage class for key %s", arg->ident->toChars()); error("no storage class for key %s", arg->ident->toChars());
TY keyty = arg->type->ty; TY keyty = arg->type->ty;
if ((keyty != Tint32 && keyty != Tuns32) && if (global.params.is64bit)
(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 (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)); Initializer *ie = new ExpInitializer(0, new IntegerExp(k));
VarDeclaration *var = new VarDeclaration(loc, arg->type, arg->ident, ie); VarDeclaration *var = new VarDeclaration(loc, arg->type, arg->ident, ie);
@ -1320,13 +1325,19 @@ Statement *ForeachStatement::semantic(Scope *sc)
error("foreach: %s is not an array of %s", tab->toChars(), value->type->toChars()); error("foreach: %s is not an array of %s", tab->toChars(), value->type->toChars());
} }
if (key && 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 (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)) if (key && key->storage_class & (STCout | STCref))

View file

@ -57,7 +57,6 @@ static LLValue* to_keyti(DValue* key)
{ {
// keyti param // keyti param
Type* keytype = key->getType(); Type* keytype = key->getType();
keytype->getTypeInfo(NULL);
return DtoTypeInfoOf(keytype, false); return DtoTypeInfoOf(keytype, false);
} }

View file

@ -750,7 +750,15 @@ static LLValue* DtoArrayEqCmp_impl(const char* func, DValue* l, DValue* r, bool
args.push_back(DtoBitCast(tival, pt)); 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;
} }
////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////

View file

@ -447,7 +447,7 @@ void DtoDeclareClass(ClassDeclaration* cd)
// typeinfo // typeinfo
if (needs_definition) 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); size_t offset = gTargetData->getStructLayout(isaStruct(cd->type->ir.type->get()))->getElementOffset(vd->ir.irField->index+2);
inits.push_back(DtoConstSize_t(offset)); inits.push_back(DtoConstSize_t(offset));
vd->type->getTypeInfo(NULL); LLConstant* c = DtoTypeInfoOf(vd->type, true);
assert(vd->type->vtinfo); const LLType* tiTy = c->getType();
DtoForceDeclareDsymbol(vd->type->vtinfo);
LLConstant* c = isaConstant(vd->type->vtinfo->ir.getIrValue());
const LLType* tiTy = getPtrToType(Type::typeinfo->type->ir.type->get());
//Logger::cout() << "tiTy = " << *tiTy << '\n'; //Logger::cout() << "tiTy = " << *tiTy << '\n';
types.push_back(tiTy); types.push_back(tiTy);
inits.push_back(llvm::ConstantExpr::getBitCast(c, tiTy)); inits.push_back(c);
const llvm::StructType* sTy = llvm::StructType::get(types); const llvm::StructType* sTy = llvm::StructType::get(types);
return llvm::ConstantStruct::get(sTy, inits); return llvm::ConstantStruct::get(sTy, inits);
@ -1284,6 +1280,8 @@ static LLConstant* build_offti_array(ClassDeclaration* cd, LLConstant* init)
{ {
Dsymbol *sm = (Dsymbol *)cd2->members->data[i]; Dsymbol *sm = (Dsymbol *)cd2->members->data[i];
if (VarDeclaration* vd = sm->isVarDeclaration()) // is this enough? if (VarDeclaration* vd = sm->isVarDeclaration()) // is this enough?
{
if (!vd->isDataseg()) // static members dont have an offset!
{ {
LLConstant* c = build_offti_entry(cd, vd); LLConstant* c = build_offti_entry(cd, vd);
assert(c); assert(c);
@ -1292,6 +1290,7 @@ static LLConstant* build_offti_array(ClassDeclaration* cd, LLConstant* init)
} }
} }
} }
}
size_t ninits = arrayInits.size(); size_t ninits = arrayInits.size();
LLConstant* size = DtoConstSize_t(ninits); LLConstant* size = DtoConstSize_t(ninits);
@ -1389,7 +1388,7 @@ static uint build_classinfo_flags(ClassDeclaration* cd)
for (size_t i = 0; i < cd2->members->dim; i++) for (size_t i = 0; i < cd2->members->dim; i++)
{ {
Dsymbol *sm = (Dsymbol *)cd2->members->data[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; hasOffTi = true;
//printf("sm = %s %s\n", sm->kind(), sm->toChars()); //printf("sm = %s %s\n", sm->kind(), sm->toChars());
if (sm->hasPointers()) if (sm->hasPointers())

View file

@ -105,8 +105,6 @@ const llvm::FunctionType* DtoFunctionType(Type* type, const LLType* thistype, bo
int nbyval = 0; int nbyval = 0;
llvm::PAListPtr palist;
for (int i=0; i < n; ++i) { for (int i=0; i < n; ++i) {
Argument* arg = Argument::getNth(f->parameters, i); Argument* arg = Argument::getNth(f->parameters, i);
// ensure scalar // ensure scalar
@ -122,11 +120,10 @@ const llvm::FunctionType* DtoFunctionType(Type* type, const LLType* thistype, bo
arg->llvmByVal = !refOrOut; arg->llvmByVal = !refOrOut;
} }
else if (isaArray(at)) { else if (isaArray(at)) {
// static array are passed by reference
Logger::println("sarray param"); Logger::println("sarray param");
assert(argT->ty == Tsarray); assert(argT->ty == Tsarray);
//paramvec.push_back(getPtrToType(at->getContainedType(0)));
paramvec.push_back(getPtrToType(at)); paramvec.push_back(getPtrToType(at));
//arg->llvmByVal = !refOrOut; // static array are passed by reference
} }
else if (llvm::isa<llvm::OpaqueType>(at)) { else if (llvm::isa<llvm::OpaqueType>(at)) {
Logger::println("opaque param"); Logger::println("opaque param");

View file

@ -15,8 +15,6 @@ void llvmdc_optimize_module(Module* m, char lvl, bool doinline)
if (!doinline && lvl < 0) if (!doinline && lvl < 0)
return; return;
assert(lvl >= 0 && lvl <= 5);
PassManager pm; PassManager pm;
pm.add(new TargetData(m)); pm.add(new TargetData(m));

View file

@ -357,7 +357,7 @@ void DtoConstInitStruct(StructDeclaration* sd)
// emit typeinfo // emit typeinfo
if (sd->getModule() == gIR->dmodule && sd->llvmInternal != LLVMnotypeinfo) if (sd->getModule() == gIR->dmodule && sd->llvmInternal != LLVMnotypeinfo)
sd->type->getTypeInfo(NULL); DtoTypeInfoOf(sd->type, false);
} }
////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////

View file

@ -124,7 +124,7 @@ DValue* DeclarationExp::toElem(IRState* p)
else if (TypedefDeclaration* tdef = declaration->isTypedefDeclaration()) else if (TypedefDeclaration* tdef = declaration->isTypedefDeclaration())
{ {
Logger::println("TypedefDeclaration"); Logger::println("TypedefDeclaration");
tdef->type->getTypeInfo(NULL); DtoTypeInfoOf(tdef->type, false);
} }
// attribute declaration // attribute declaration
else if (AttribDeclaration* a = declaration->isAttribDeclaration()) else if (AttribDeclaration* a = declaration->isAttribDeclaration())
@ -287,12 +287,9 @@ LLConstant* VarExp::toConstElem(IRState* p)
} }
else if (TypeInfoDeclaration* ti = var->isTypeInfoDeclaration()) else if (TypeInfoDeclaration* ti = var->isTypeInfoDeclaration())
{ {
DtoForceDeclareDsymbol(ti);
assert(ti->ir.getIrValue());
const LLType* vartype = DtoType(type); const LLType* vartype = DtoType(type);
LLConstant* m = isaConstant(ti->ir.getIrValue()); LLConstant* m = DtoTypeInfoOf(ti->tinfo, false);
assert(m); if (m->getType() != getPtrToType(vartype))
if (ti->ir.getIrValue()->getType() != getPtrToType(vartype))
m = llvm::ConstantExpr::getBitCast(m, vartype); m = llvm::ConstantExpr::getBitCast(m, vartype);
return m; return m;
} }
@ -1512,8 +1509,7 @@ DValue* IndexExp::toElem(IRState* p)
arrptr = DtoGEP(l->getRVal(), zero, r->getRVal()); arrptr = DtoGEP(l->getRVal(), zero, r->getRVal());
} }
else if (e1type->ty == Tarray) { else if (e1type->ty == Tarray) {
arrptr = DtoGEP(l->getRVal(),zero,one); arrptr = DtoArrayPtr(l);
arrptr = DtoLoad(arrptr);
arrptr = DtoGEP1(arrptr,r->getRVal()); arrptr = DtoGEP1(arrptr,r->getRVal());
} }
else if (e1type->ty == Taarray) { else if (e1type->ty == Taarray) {
@ -1982,12 +1978,11 @@ DValue* DeleteExp::toElem(IRState* p)
} }
else if (DVarValue* vv = dval->isVar()) { else if (DVarValue* vv = dval->isVar()) {
if (vv->var && vv->var->onstack) { if (vv->var && vv->var->onstack) {
if (tc->sym->dtors.dim > 0) { if (tc->sym->dtors.dim > 0)
DtoFinalizeClass(dval->getRVal()); DtoFinalizeClass(dval->getRVal());
onstack = true; onstack = true;
} }
} }
}
if (!onstack) { if (!onstack) {
LLValue* rval = dval->getRVal(); LLValue* rval = dval->getRVal();
DtoDeleteClass(rval); DtoDeleteClass(rval);
@ -2496,29 +2491,6 @@ DValue* CatExp::toElem(IRState* p)
{ {
return DtoCatArrayElement(type, e1, e2); 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);
}
*/
} }
////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////

View file

@ -606,7 +606,7 @@ void TypedefDeclaration::toObjFile()
LOG_SCOPE; LOG_SCOPE;
// generate typeinfo // generate typeinfo
type->getTypeInfo(NULL); DtoTypeInfoOf(type, false);
} }
/* ================================================================== */ /* ================================================================== */

View file

@ -383,19 +383,8 @@ void TypeInfoTypedefDeclaration::llvmDefine()
TypedefDeclaration *sd = tc->sym; TypedefDeclaration *sd = tc->sym;
// TypeInfo base // TypeInfo base
//const LLPointerType* basept = isaPointer(initZ->getOperand(1)->getType()); LLConstant* castbase = DtoTypeInfoOf(sd->basetype, true);
//sinits.push_back(llvm::ConstantPointerNull::get(basept)); assert(castbase->getType() == stype->getElementType(2));
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<llvm::Constant>(sd->basetype->vtinfo->ir.irGlobal->value));
LLConstant* castbase = llvm::cast<llvm::Constant>(sd->basetype->vtinfo->ir.irGlobal->value);
castbase = llvm::ConstantExpr::getBitCast(castbase, stype->getElementType(2));
sinits.push_back(castbase); sinits.push_back(castbase);
// char[] name // char[] name
@ -468,18 +457,8 @@ void TypeInfoEnumDeclaration::llvmDefine()
EnumDeclaration *sd = tc->sym; EnumDeclaration *sd = tc->sym;
// TypeInfo base // TypeInfo base
//const LLPointerType* basept = isaPointer(initZ->getOperand(1)->getType()); LLConstant* castbase = DtoTypeInfoOf(sd->memtype, true);
//sinits.push_back(llvm::ConstantPointerNull::get(basept)); assert(castbase->getType() == stype->getElementType(2));
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<llvm::Constant>(sd->memtype->vtinfo->ir.irGlobal->value));
LLConstant* castbase = llvm::cast<llvm::Constant>(sd->memtype->vtinfo->ir.irGlobal->value);
castbase = llvm::ConstantExpr::getBitCast(castbase, stype->getElementType(2));
sinits.push_back(castbase); sinits.push_back(castbase);
// char[] name // char[] name
@ -543,13 +522,8 @@ static LLConstant* LLVM_D_Define_TypeInfoBase(Type* basetype, TypeInfoDeclaratio
sinits.push_back(llvm::ConstantPointerNull::get(getPtrToType(LLType::Int8Ty))); sinits.push_back(llvm::ConstantPointerNull::get(getPtrToType(LLType::Int8Ty)));
// TypeInfo base // TypeInfo base
Logger::println("generating base typeinfo"); LLConstant* castbase = DtoTypeInfoOf(basetype, true);
basetype->getTypeInfo(NULL); assert(castbase->getType() == stype->getElementType(2));
assert(basetype->vtinfo);
DtoForceDeclareDsymbol(basetype->vtinfo);
assert(llvm::isa<llvm::Constant>(basetype->vtinfo->ir.irGlobal->value));
LLConstant* castbase = llvm::cast<llvm::Constant>(basetype->vtinfo->ir.irGlobal->value);
castbase = llvm::ConstantExpr::getBitCast(castbase, stype->getElementType(2));
sinits.push_back(castbase); sinits.push_back(castbase);
// create the symbol // create the symbol
@ -656,13 +630,8 @@ void TypeInfoStaticArrayDeclaration::llvmDefine()
// value typeinfo // value typeinfo
assert(tinfo->ty == Tsarray); assert(tinfo->ty == Tsarray);
TypeSArray *tc = (TypeSArray *)tinfo; TypeSArray *tc = (TypeSArray *)tinfo;
tc->next->getTypeInfo(NULL); LLConstant* castbase = DtoTypeInfoOf(tc->next, true);
assert(castbase->getType() == stype->getElementType(2));
// 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));
sinits.push_back(castbase); sinits.push_back(castbase);
// length // length
@ -721,23 +690,13 @@ void TypeInfoAssociativeArrayDeclaration::llvmDefine()
TypeAArray *tc = (TypeAArray *)tinfo; TypeAArray *tc = (TypeAArray *)tinfo;
// value typeinfo // value typeinfo
tc->next->getTypeInfo(NULL); LLConstant* castbase = DtoTypeInfoOf(tc->next, true);
assert(castbase->getType() == stype->getElementType(2));
// 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));
sinits.push_back(castbase); sinits.push_back(castbase);
// key typeinfo // key typeinfo
tc->index->getTypeInfo(NULL); castbase = DtoTypeInfoOf(tc->index, true);
assert(castbase->getType() == stype->getElementType(3));
// 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));
sinits.push_back(castbase); sinits.push_back(castbase);
// create the symbol // create the symbol
@ -1179,12 +1138,9 @@ void TypeInfoTupleDeclaration::llvmDefine()
for (size_t i = 0; i < dim; i++) for (size_t i = 0; i < dim; i++)
{ {
Argument *arg = (Argument *)tu->arguments->data[i]; Argument *arg = (Argument *)tu->arguments->data[i];
arg->type->getTypeInfo(NULL); LLConstant* castbase = DtoTypeInfoOf(arg->type, true);
DtoForceDeclareDsymbol(arg->type->vtinfo); assert(castbase->getType() == tiTy);
assert(arg->type->vtinfo->ir.irGlobal->value); arrInits.push_back(castbase);
LLConstant* c = isaConstant(arg->type->vtinfo->ir.irGlobal->value);
c = llvm::ConstantExpr::getBitCast(c, tiTy);
arrInits.push_back(c);
} }
// build array type // build array type

View file

@ -1,12 +0,0 @@
module app;
import lib;
void func()
{
lib_func();
}
void main()
{
func();
}

View file

@ -1,3 +0,0 @@
#!/bin/bash
llvmdc lib.d -c -g -dis
llvmdc app.d lib.bc -g -dis -ofapp

View file

@ -1,7 +0,0 @@
module lib;
void lib_func()
{
int* p;
*p = 666;
}

View file

@ -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;
}

View file

@ -1,3 +0,0 @@
#!/bin/bash
llvmdc lib.d -c -g -dis
llvmdc app.d lib.bc -g -dis -ofapp

View file

@ -1,6 +0,0 @@
module lib;
T lib_templ_func(T)(T* a)
{
return *a;
}

View file

@ -33,6 +33,7 @@
/* /*
* Modified by Sean Kelly <sean@f4.ca> for use with Tango. * Modified by Sean Kelly <sean@f4.ca> for use with Tango.
* Modified by Tomas Lindquist Olsen <tomas@famolsen.dk> for use with LLVMDC.
*/ */
module object; module object;
@ -56,7 +57,7 @@ private
//alias typeof(int.sizeof) size_t; //alias typeof(int.sizeof) size_t;
//alias typeof(cast(void*)0 - cast(void*)0) ptrdiff_t; //alias typeof(cast(void*)0 - cast(void*)0) ptrdiff_t;
version( X86_64 ) version( LLVM64 )
{ {
alias ulong size_t; alias ulong size_t;
alias long ptrdiff_t; alias long ptrdiff_t;