Mercurial > projects > ldc
changeset 156:ccd07d9f2ce9 trunk
[svn r172] moving all IR state previously stored in Dsymbol into IrDsymbol and a Dsymbol->IrDsymbol map
author | ChristianK |
---|---|
date | Thu, 01 May 2008 13:05:53 +0200 |
parents | 7f92f477ff53 |
children | 5c17f81fc1c1 |
files | dmd/aggregate.h dmd/declaration.c dmd/declaration.h dmd/dsymbol.c dmd/dsymbol.h dmd/module.c dmd/module.h dmd/struct.c gen/aa.cpp gen/arrays.cpp gen/classes.cpp gen/functions.cpp gen/irstate.h gen/statements.cpp gen/structs.cpp gen/todebug.cpp gen/toir.cpp gen/tollvm.cpp gen/toobj.cpp gen/typinf.cpp ir/irsymbol.h ir/irvar.cpp |
diffstat | 22 files changed, 465 insertions(+), 487 deletions(-) [+] |
line wrap: on
line diff
--- a/dmd/aggregate.h Tue Apr 29 21:33:50 2008 +0200 +++ b/dmd/aggregate.h Thu May 01 13:05:53 2008 +0200 @@ -45,7 +45,6 @@ class ConstantStruct; class GlobalVariable; } -struct IrStruct; struct DUnion; struct AggregateDeclaration : ScopeDsymbol @@ -102,9 +101,6 @@ Symbol *toInitializer(); AggregateDeclaration *isAggregateDeclaration() { return this; } - - // llvmdc - IrStruct* irStruct; }; struct AnonymousAggregateDeclaration : AggregateDeclaration
--- a/dmd/declaration.c Tue Apr 29 21:33:50 2008 +0200 +++ b/dmd/declaration.c Thu May 01 13:05:53 2008 +0200 @@ -549,9 +549,8 @@ onstack = 0; canassign = 0; value = NULL; - irGlobal = NULL; - irLocal = NULL; - irField = NULL; + + // LLVMDC needsStorage = false; }
--- a/dmd/declaration.h Tue Apr 29 21:33:50 2008 +0200 +++ b/dmd/declaration.h Thu May 01 13:05:53 2008 +0200 @@ -21,14 +21,6 @@ #include "lexer.h" #include "mtype.h" -namespace llvm { - class Value; -} -struct IrVar; -struct IrGlobal; -struct IrLocal; -struct IrField; - struct Expression; struct Statement; struct LabelDsymbol; @@ -263,13 +255,7 @@ VarDeclaration *isVarDeclaration() { return (VarDeclaration *)this; } // LLVMDC - IrGlobal* irGlobal; - IrLocal* irLocal; - IrField* irField; bool needsStorage; - - IrVar* getIrVar(); - llvm::Value*& getIrValue(); }; /**************************************************************/
--- a/dmd/dsymbol.c Tue Apr 29 21:33:50 2008 +0200 +++ b/dmd/dsymbol.c Thu May 01 13:05:53 2008 +0200 @@ -47,14 +47,6 @@ this->llvmInternal = LLVMnone; this->llvmInternal1 = NULL; this->llvmInternal2 = NULL; - - //this->llvmValue = NULL; - this->llvmDModule = NULL; - - this->llvmResolved = false; - this->llvmDeclared = false; - this->llvmInitialized = false; - this->llvmDefined = false; } Dsymbol::Dsymbol(Identifier *ident) @@ -71,14 +63,6 @@ this->llvmInternal = LLVMnone; this->llvmInternal1 = NULL; this->llvmInternal2 = NULL; - - //this->llvmValue = NULL; - this->llvmDModule = NULL; - - this->llvmResolved = false; - this->llvmDeclared = false; - this->llvmInitialized = false; - this->llvmDefined = false; } int Dsymbol::equals(Object *o)
--- a/dmd/dsymbol.h Tue Apr 29 21:33:50 2008 +0200 +++ b/dmd/dsymbol.h Thu May 01 13:05:53 2008 +0200 @@ -219,14 +219,6 @@ int llvmInternal; char* llvmInternal1; char* llvmInternal2; - - //llvm::Value* llvmValue; - Module* llvmDModule; - - bool llvmResolved; - bool llvmDeclared; - bool llvmInitialized; - bool llvmDefined; }; // Dsymbol that generates a scope
--- a/dmd/module.c Tue Apr 29 21:33:50 2008 +0200 +++ b/dmd/module.c Thu May 01 13:05:53 2008 +0200 @@ -160,9 +160,6 @@ bcfile = new File(bcfilename); llfile = new File(llfilename); symfile = new File(symfilename); - - // LLVMDC - irModule = NULL; } void Module::setDocfile()
--- a/dmd/module.h Tue Apr 29 21:33:50 2008 +0200 +++ b/dmd/module.h Thu May 01 13:05:53 2008 +0200 @@ -29,7 +29,6 @@ #if IN_LLVM struct DValue; typedef DValue elem; -struct IrModule; #else #ifdef IN_GCC union tree_node; typedef union tree_node elem; @@ -169,8 +168,6 @@ void genmoduleinfo(); // LLVMDC - IrModule* irModule; - Module *isModule() { return this; } };
--- a/dmd/struct.c Tue Apr 29 21:33:50 2008 +0200 +++ b/dmd/struct.c Thu May 01 13:05:53 2008 +0200 @@ -44,8 +44,6 @@ stag = NULL; sinit = NULL; scope = NULL; - - irStruct = NULL; } enum PROT AggregateDeclaration::prot()
--- a/gen/aa.cpp Tue Apr 29 21:33:50 2008 +0200 +++ b/gen/aa.cpp Thu May 01 13:05:53 2008 +0200 @@ -58,8 +58,8 @@ assert(tid); DtoResolveDsymbol(Type::typeinfo); DtoForceDeclareDsymbol(tid); - assert(tid->irGlobal->value); - return tid->irGlobal->value; + assert(gIR->irDsymbol[tid].irGlobal->value); + return gIR->irDsymbol[tid].irGlobal->value; } /////////////////////////////////////////////////////////////////////////////////////
--- a/gen/arrays.cpp Tue Apr 29 21:33:50 2008 +0200 +++ b/gen/arrays.cpp Thu May 01 13:05:53 2008 +0200 @@ -673,10 +673,10 @@ if (useti) { TypeInfoDeclaration* ti = DtoDType(l->getType())->next->getTypeInfoDeclaration(); DtoForceConstInitDsymbol(ti); - Logger::cout() << "typeinfo decl: " << *ti->getIrValue() << '\n'; + Logger::cout() << "typeinfo decl: " << *gIR->irDsymbol[ti].getIrValue() << '\n'; pt = fn->getFunctionType()->getParamType(2); - args.push_back(DtoBitCast(ti->getIrValue(), pt)); + args.push_back(DtoBitCast(gIR->irDsymbol[ti].getIrValue(), pt)); } return gIR->ir->CreateCall(fn, args.begin(), args.end(), "tmp");
--- a/gen/classes.cpp Tue Apr 29 21:33:50 2008 +0200 +++ b/gen/classes.cpp Thu May 01 13:05:53 2008 +0200 @@ -35,15 +35,15 @@ if (bc->base->isInterfaceDeclaration()) { // don't add twice - if (target->irStruct->interfaceMap.find(bc->base) == target->irStruct->interfaceMap.end()) + if (gIR->irDsymbol[target].irStruct->interfaceMap.find(bc->base) == gIR->irDsymbol[target].irStruct->interfaceMap.end()) { Logger::println("adding interface '%s'", bc->base->toPrettyChars()); IrInterface* iri = new IrInterface(bc, NULL); // add to map - target->irStruct->interfaceMap.insert(std::make_pair(bc->base, iri)); + gIR->irDsymbol[target].irStruct->interfaceMap.insert(std::make_pair(bc->base, iri)); // add to ordered list - target->irStruct->interfaceVec.push_back(iri); + gIR->irDsymbol[target].irStruct->interfaceVec.push_back(iri); // Fill in vtbl[] if (!target->isAbstract()) { @@ -88,8 +88,8 @@ void DtoResolveClass(ClassDeclaration* cd) { - if (cd->llvmResolved) return; - cd->llvmResolved = true; + if (gIR->irDsymbol[cd].resolved) return; + gIR->irDsymbol[cd].resolved = true; Logger::println("DtoResolveClass(%s): %s", cd->toPrettyChars(), cd->loc.toChars()); LOG_SCOPE; @@ -99,10 +99,10 @@ TypeClass* ts = (TypeClass*)cd->type; // make sure the IrStruct is created - IrStruct* irstruct = cd->irStruct; + IrStruct* irstruct = gIR->irDsymbol[cd].irStruct; if (!irstruct) { irstruct = new IrStruct(ts); - cd->irStruct = irstruct; + gIR->irDsymbol[cd].irStruct = irstruct; } // resolve the base class @@ -169,7 +169,7 @@ fieldtype = i->second.type; fieldinit = i->second.var; prevsize = getABITypeSize(fieldtype); - i->second.var->irField->index = idx; + gIR->irDsymbol[i->second.var].irField->index = idx; } // colliding offset? else if (lastoffset == i->first) { @@ -178,16 +178,16 @@ fieldpad += s - prevsize; prevsize = s; } - cd->irStruct->hasUnions = true; - i->second.var->irField->index = idx; + gIR->irDsymbol[cd].irStruct->hasUnions = true; + gIR->irDsymbol[i->second.var].irField->index = idx; } // intersecting offset? else if (i->first < (lastoffset + prevsize)) { size_t s = getABITypeSize(i->second.type); assert((i->first + s) <= (lastoffset + prevsize)); // this holds because all types are aligned to their size - cd->irStruct->hasUnions = true; - i->second.var->irField->index = idx; - i->second.var->irField->indexOffset = (i->first - lastoffset) / s; + gIR->irDsymbol[cd].irStruct->hasUnions = true; + gIR->irDsymbol[i->second.var].irField->index = idx; + gIR->irDsymbol[i->second.var].irField->indexOffset = (i->first - lastoffset) / s; } // fresh offset else { @@ -207,7 +207,7 @@ fieldtype = i->second.type; fieldinit = i->second.var; prevsize = getABITypeSize(fieldtype); - i->second.var->irField->index = idx; + gIR->irDsymbol[i->second.var].irField->index = idx; fieldpad = 0; } } @@ -224,8 +224,8 @@ Logger::println("Adding interfaces to '%s'", cd->toPrettyChars()); LOG_SCOPE; LLVM_AddBaseClassInterfaces(cd, &cd->baseclasses); - Logger::println("%d interfaces added", cd->irStruct->interfaceVec.size()); - assert(cd->irStruct->interfaceVec.size() == cd->irStruct->interfaceMap.size()); + Logger::println("%d interfaces added", gIR->irDsymbol[cd].irStruct->interfaceVec.size()); + assert(gIR->irDsymbol[cd].irStruct->interfaceVec.size() == gIR->irDsymbol[cd].irStruct->interfaceMap.size()); } // add interface vtables at the end @@ -246,8 +246,8 @@ // set index iri->index = interIdx++; } - Logger::println("%d interface vtables added", cd->irStruct->interfaceVec.size()); - assert(cd->irStruct->interfaceVec.size() == cd->irStruct->interfaceMap.size()); + Logger::println("%d interface vtables added", gIR->irDsymbol[cd].irStruct->interfaceVec.size()); + assert(gIR->irDsymbol[cd].irStruct->interfaceVec.size() == gIR->irDsymbol[cd].irStruct->interfaceMap.size()); // create type const llvm::StructType* structtype = llvm::StructType::get(fieldtypes); @@ -330,8 +330,8 @@ void DtoDeclareClass(ClassDeclaration* cd) { - if (cd->llvmDeclared) return; - cd->llvmDeclared = true; + if (gIR->irDsymbol[cd].declared) return; + gIR->irDsymbol[cd].declared = true; Logger::println("DtoDeclareClass(%s): %s", cd->toPrettyChars(), cd->loc.toChars()); LOG_SCOPE; @@ -339,8 +339,8 @@ assert(cd->type->ty == Tclass); TypeClass* ts = (TypeClass*)cd->type; - assert(cd->irStruct); - IrStruct* irstruct = cd->irStruct; + assert(gIR->irDsymbol[cd].irStruct); + IrStruct* irstruct = gIR->irDsymbol[cd].irStruct; gIR->structs.push_back(irstruct); gIR->classes.push_back(cd); @@ -361,20 +361,20 @@ varname.append("6__vtblZ"); const llvm::StructType* svtbl_ty = isaStruct(ts->llvmVtblType->get()); - cd->irStruct->vtbl = new llvm::GlobalVariable(svtbl_ty, true, _linkage, 0, varname, gIR->module); + gIR->irDsymbol[cd].irStruct->vtbl = new llvm::GlobalVariable(svtbl_ty, true, _linkage, 0, varname, gIR->module); } // get interface info type const llvm::StructType* infoTy = DtoInterfaceInfoType(); // interface info array - if (!cd->irStruct->interfaceVec.empty()) { + if (!gIR->irDsymbol[cd].irStruct->interfaceVec.empty()) { // symbol name std::string nam = "_D"; nam.append(cd->mangle()); nam.append("16__interfaceInfosZ"); // resolve array type - const llvm::ArrayType* arrTy = llvm::ArrayType::get(infoTy, cd->irStruct->interfaceVec.size()); + const llvm::ArrayType* arrTy = llvm::ArrayType::get(infoTy, gIR->irDsymbol[cd].irStruct->interfaceVec.size()); // declare global irstruct->interfaceInfosTy = arrTy; irstruct->interfaceInfos = new llvm::GlobalVariable(arrTy, true, _linkage, NULL, nam, gIR->module); @@ -409,7 +409,7 @@ initname.append("6__initZ"); llvm::GlobalVariable* initvar = new llvm::GlobalVariable(ts->llvmType->get(), true, _linkage, NULL, initname, gIR->module); - cd->irStruct->init = initvar; + gIR->irDsymbol[cd].irStruct->init = initvar; } gIR->classes.pop_back(); @@ -431,8 +431,8 @@ void DtoConstInitClass(ClassDeclaration* cd) { - if (cd->llvmInitialized) return; - cd->llvmInitialized = true; + if (gIR->irDsymbol[cd].initialized) return; + gIR->irDsymbol[cd].initialized = true; if (cd->isInterfaceDeclaration()) return; // nothing to do @@ -440,7 +440,7 @@ Logger::println("DtoConstInitClass(%s): %s", cd->toPrettyChars(), cd->loc.toChars()); LOG_SCOPE; - IrStruct* irstruct = cd->irStruct; + IrStruct* irstruct = gIR->irDsymbol[cd].irStruct; gIR->structs.push_back(irstruct); gIR->classes.push_back(cd); @@ -456,7 +456,7 @@ IrStruct::Offset* so = &i->second; llvm::Constant* finit = DtoConstFieldInitializer(so->var->type, so->var->init); so->init = finit; - so->var->irField->constInit = finit; + gIR->irDsymbol[so->var].irField->constInit = finit; } // fill out fieldtypes/inits @@ -475,8 +475,8 @@ } else { - assert(cd->irStruct->vtbl != 0); - fieldinits.push_back(cd->irStruct->vtbl); + assert(gIR->irDsymbol[cd].irStruct->vtbl != 0); + fieldinits.push_back(gIR->irDsymbol[cd].irStruct->vtbl); } // then comes monitor @@ -487,7 +487,7 @@ for (size_t i=0; i<nfi; ++i) { llvm::Constant* c; if (irstruct->defaultFields[i]) { - c = irstruct->defaultFields[i]->irField->constInit; + c = gIR->irDsymbol[irstruct->defaultFields[i]].irField->constInit; assert(c); } else { @@ -536,7 +536,7 @@ llvm::Constant* _init = llvm::ConstantStruct::get(structtype, fieldinits); assert(_init); - cd->irStruct->constInit = _init; + gIR->irDsymbol[cd].irStruct->constInit = _init; // abstract classes have no static vtable // neither do interfaces (on their own, the implementing class supplies the vtable) @@ -553,16 +553,16 @@ if (FuncDeclaration* fd = dsym->isFuncDeclaration()) { DtoForceDeclareDsymbol(fd); - assert(gIR->irFunc[fd]->func); - llvm::Constant* c = llvm::cast<llvm::Constant>(gIR->irFunc[fd]->func); + assert(gIR->irDsymbol[fd].irFunc->func); + llvm::Constant* c = llvm::cast<llvm::Constant>(gIR->irDsymbol[fd].irFunc->func); // cast if necessary (overridden method) if (c->getType() != vtbltype->getElementType(k)) c = llvm::ConstantExpr::getBitCast(c, vtbltype->getElementType(k)); sinits.push_back(c); } else if (ClassDeclaration* cd2 = dsym->isClassDeclaration()) { - assert(cd->irStruct->classInfo); - llvm::Constant* c = cd->irStruct->classInfo; + assert(gIR->irDsymbol[cd].irStruct->classInfo); + llvm::Constant* c = gIR->irDsymbol[cd].irStruct->classInfo; sinits.push_back(c); } else @@ -581,7 +581,7 @@ #endif llvm::Constant* cvtblInit = llvm::ConstantStruct::get(svtbl_ty, sinits); - cd->irStruct->constVtbl = llvm::cast<llvm::ConstantStruct>(cvtblInit); + gIR->irDsymbol[cd].irStruct->constVtbl = llvm::cast<llvm::ConstantStruct>(cvtblInit); // create interface vtable const initalizers for (IrStruct::InterfaceVectorIter i=irstruct->interfaceVec.begin(); i!=irstruct->interfaceVec.end(); ++i) @@ -599,8 +599,8 @@ std::vector<llvm::Constant*> infoInits; // classinfo - assert(id->irStruct->classInfo); - llvm::Constant* c = id->irStruct->classInfo; + assert(gIR->irDsymbol[id].irStruct->classInfo); + llvm::Constant* c = gIR->irDsymbol[id].irStruct->classInfo; infoInits.push_back(c); // vtbl @@ -636,8 +636,8 @@ FuncDeclaration* fd = dsym->isFuncDeclaration(); assert(fd); DtoForceDeclareDsymbol(fd); - assert(gIR->irFunc[fd]->func); - llvm::Constant* c = llvm::cast<llvm::Constant>(gIR->irFunc[fd]->func); + assert(gIR->irDsymbol[fd].irFunc->func); + llvm::Constant* c = llvm::cast<llvm::Constant>(gIR->irDsymbol[fd].irFunc->func); // we have to bitcast, as the type created in ResolveClass expects a different this type c = llvm::ConstantExpr::getBitCast(c, iri->vtblTy->getContainedType(k)); @@ -673,8 +673,8 @@ std::vector<llvm::Constant*> infoInits; // classinfo - assert(id->irStruct->classInfo); - llvm::Constant* c = id->irStruct->classInfo; + assert(gIR->irDsymbol[id].irStruct->classInfo); + llvm::Constant* c = gIR->irDsymbol[id].irStruct->classInfo; infoInits.push_back(c); // vtbl @@ -698,8 +698,8 @@ void DtoDefineClass(ClassDeclaration* cd) { - if (cd->llvmDefined) return; - cd->llvmDefined = true; + if (gIR->irDsymbol[cd].defined) return; + gIR->irDsymbol[cd].defined = true; Logger::println("DtoDefineClass(%s): %s", cd->toPrettyChars(), cd->loc.toChars()); LOG_SCOPE; @@ -713,11 +713,11 @@ // neither do abstract classes if (!cd->isInterfaceDeclaration() && !cd->isAbstract()) { - cd->irStruct->init->setInitializer(cd->irStruct->constInit); - cd->irStruct->vtbl->setInitializer(cd->irStruct->constVtbl); + gIR->irDsymbol[cd].irStruct->init->setInitializer(gIR->irDsymbol[cd].irStruct->constInit); + gIR->irDsymbol[cd].irStruct->vtbl->setInitializer(gIR->irDsymbol[cd].irStruct->constVtbl); // initialize interface vtables - IrStruct* irstruct = cd->irStruct; + IrStruct* irstruct = gIR->irDsymbol[cd].irStruct; std::vector<llvm::Constant*> infoInits; for (IrStruct::InterfaceVectorIter i=irstruct->interfaceVec.begin(); i!=irstruct->interfaceVec.end(); ++i) { @@ -755,7 +755,7 @@ { llvm::Function* fn = LLVM_D_GetRuntimeFunction(gIR->module, "_d_newclass"); std::vector<llvm::Value*> args; - args.push_back(tc->sym->irStruct->classInfo); + args.push_back(gIR->irDsymbol[tc->sym].irStruct->classInfo); mem = gIR->ir->CreateCall(fn, args.begin(), args.end(), "newclass_gc_alloc"); mem = DtoBitCast(mem, DtoType(tc), "newclass_gc"); } @@ -770,7 +770,7 @@ LOG_SCOPE; DValue* thisval = newexp->thisexp->toElem(gIR); size_t idx = 2; - //idx += tc->sym->irStruct->interfaces.size(); + //idx += gIR->irDsymbol[tc->sym].irStruct->interfaces.size(); llvm::Value* dst = thisval->getRVal(); llvm::Value* src = DtoGEPi(mem,0,idx,"tmp"); Logger::cout() << "dst: " << *dst << "\nsrc: " << *src << '\n'; @@ -782,10 +782,10 @@ Logger::println("Resolving nested context"); LOG_SCOPE; size_t idx = 2; - //idx += tc->sym->irStruct->interfaces.size(); - llvm::Value* nest = gIR->irFunc[gIR->func()->decl]->nestedVar; + //idx += gIR->irDsymbol[tc->sym].irStruct->interfaces.size(); + llvm::Value* nest = gIR->irDsymbol[gIR->func()->decl].irFunc->nestedVar; if (!nest) - nest = gIR->irFunc[gIR->func()->decl]->thisVar; + nest = gIR->irDsymbol[gIR->func()->decl].irFunc->thisVar; assert(nest); llvm::Value* gep = DtoGEPi(mem,0,idx,"tmp"); nest = DtoBitCast(nest, gep->getType()->getContainedType(0)); @@ -808,8 +808,8 @@ uint64_t n = getABITypeSize(tc->llvmType->get()) - presz; // set vtable field seperately, this might give better optimization - assert(tc->sym->irStruct->vtbl); - DtoStore(tc->sym->irStruct->vtbl, DtoGEPi(dst,0,0,"vtbl")); + assert(gIR->irDsymbol[tc->sym].irStruct->vtbl); + DtoStore(gIR->irDsymbol[tc->sym].irStruct->vtbl, DtoGEPi(dst,0,0,"vtbl")); // monitor always defaults to zero llvm::Value* tmp = DtoGEPi(dst,0,1,"monitor"); @@ -820,15 +820,15 @@ return; // copy the rest from the static initializer - assert(tc->sym->irStruct->init); - assert(dst->getType() == tc->sym->irStruct->init->getType()); + assert(gIR->irDsymbol[tc->sym].irStruct->init); + assert(dst->getType() == gIR->irDsymbol[tc->sym].irStruct->init->getType()); const llvm::Type* arrty = getPtrToType(llvm::Type::Int8Ty); llvm::Value* dstarr = DtoGEPi(dst,0,2,"tmp"); dstarr = DtoBitCast(dstarr, arrty); - llvm::Value* srcarr = DtoGEPi(tc->sym->irStruct->init,0,2,"tmp"); + llvm::Value* srcarr = DtoGEPi(gIR->irDsymbol[tc->sym].irStruct->init,0,2,"tmp"); srcarr = DtoBitCast(srcarr, arrty); llvm::Function* fn = LLVM_DeclareMemCpy32(); @@ -851,7 +851,7 @@ assert(ctor); DtoForceDeclareDsymbol(ctor); - llvm::Function* fn = gIR->irFunc[ctor]->func; + llvm::Function* fn = gIR->irDsymbol[ctor].irFunc->func; TypeFunction* tf = (TypeFunction*)DtoDType(ctor->type); std::vector<llvm::Value*> ctorargs; @@ -881,8 +881,8 @@ for (size_t i=0; i<arr->dim; i++) { FuncDeclaration* fd = (FuncDeclaration*)arr->data[i]; - assert(gIR->irFunc[fd]->func); - new llvm::CallInst(gIR->irFunc[fd]->func, instance, "", gIR->scopebb()); + assert(gIR->irDsymbol[fd].irFunc->func); + new llvm::CallInst(gIR->irDsymbol[fd].irFunc->func, instance, "", gIR->scopebb()); } } @@ -961,8 +961,8 @@ // ClassInfo c TypeClass* to = (TypeClass*)DtoDType(_to); DtoForceDeclareDsymbol(to->sym); - assert(to->sym->irStruct->classInfo); - tmp = to->sym->irStruct->classInfo; + assert(gIR->irDsymbol[to->sym].irStruct->classInfo); + tmp = gIR->irDsymbol[to->sym].irStruct->classInfo; // unfortunately this is needed as the implementation of object differs somehow from the declaration // this could happen in user code as well :/ tmp = DtoBitCast(tmp, funcTy->getParamType(1)); @@ -1027,8 +1027,8 @@ // ClassInfo c TypeClass* to = (TypeClass*)DtoDType(_to); DtoForceDeclareDsymbol(to->sym); - assert(to->sym->irStruct->classInfo); - tmp = to->sym->irStruct->classInfo; + assert(gIR->irDsymbol[to->sym].irStruct->classInfo); + tmp = gIR->irDsymbol[to->sym].irStruct->classInfo; // unfortunately this is needed as the implementation of object differs somehow from the declaration // this could happen in user code as well :/ tmp = DtoBitCast(tmp, funcTy->getParamType(1)); @@ -1094,13 +1094,13 @@ const llvm::Type* llt = getPtrToType(DtoType(t)); const llvm::Type* st = DtoType(cd->type); if (ptr->getType() != st) { - assert(cd->irStruct->hasUnions); + assert(gIR->irDsymbol[cd].irStruct->hasUnions); ptr = gIR->ir->CreateBitCast(ptr, st, "tmp"); } unsigned dataoffset = 2; - IrStruct* irstruct = cd->irStruct; + IrStruct* irstruct = gIR->irDsymbol[cd].irStruct; for (IrStruct::OffsetMap::iterator i=irstruct->offsets.begin(); i!=irstruct->offsets.end(); ++i) { //for (unsigned i=0; i<cd->fields.dim; ++i) { //VarDeclaration* vd = (VarDeclaration*)cd->fields.data[i]; @@ -1108,29 +1108,29 @@ assert(vd); Type* vdtype = DtoDType(vd->type); Logger::println("found %u type %s", vd->offset, vdtype->toChars()); - assert(vd->irField->index >= 0); + assert(gIR->irDsymbol[vd].irField->index >= 0); if (os == vd->offset && vdtype == t) { - idxs.push_back(vd->irField->index + dataoffset); + idxs.push_back(gIR->irDsymbol[vd].irField->index + dataoffset); Logger::cout() << "indexing: " << *ptr << '\n'; ptr = DtoGEP(ptr, idxs, "tmp"); if (ptr->getType() != llt) ptr = gIR->ir->CreateBitCast(ptr, llt, "tmp"); Logger::cout() << "indexing: " << *ptr << '\n'; - if (vd->irField->indexOffset) - ptr = new llvm::GetElementPtrInst(ptr, DtoConstUint(vd->irField->indexOffset), "tmp", gIR->scopebb()); + if (gIR->irDsymbol[vd].irField->indexOffset) + ptr = new llvm::GetElementPtrInst(ptr, DtoConstUint(gIR->irDsymbol[vd].irField->indexOffset), "tmp", gIR->scopebb()); Logger::cout() << "indexing: " << *ptr << '\n'; return ptr; } else if (vdtype->ty == Tstruct && (vd->offset + vdtype->size()) > os) { TypeStruct* ts = (TypeStruct*)vdtype; StructDeclaration* ssd = ts->sym; - idxs.push_back(vd->irField->index + dataoffset); - if (vd->irField->indexOffset) { + idxs.push_back(gIR->irDsymbol[vd].irField->index + dataoffset); + if (gIR->irDsymbol[vd].irField->indexOffset) { Logger::println("has union field offset"); ptr = DtoGEP(ptr, idxs, "tmp"); if (ptr->getType() != llt) ptr = gIR->ir->CreateBitCast(ptr, llt, "tmp"); - ptr = new llvm::GetElementPtrInst(ptr, DtoConstUint(vd->irField->indexOffset), "tmp", gIR->scopebb()); + ptr = new llvm::GetElementPtrInst(ptr, DtoConstUint(gIR->irDsymbol[vd].irField->indexOffset), "tmp", gIR->scopebb()); std::vector<unsigned> tmp; return DtoIndexStruct(ptr, ssd, t, os-vd->offset, tmp); } @@ -1183,8 +1183,8 @@ void DtoDeclareClassInfo(ClassDeclaration* cd) { - if (cd->irStruct->classDeclared) return; - cd->irStruct->classDeclared = true; + if (gIR->irDsymbol[cd].irStruct->classDeclared) return; + gIR->irDsymbol[cd].irStruct->classDeclared = true; Logger::println("DtoDeclareClassInfo(%s)", cd->toChars()); LOG_SCOPE; @@ -1201,7 +1201,7 @@ const llvm::Type* st = cinfo->type->llvmType->get(); - cd->irStruct->classInfo = new llvm::GlobalVariable(st, true, DtoLinkage(cd), NULL, gname, gIR->module); + gIR->irDsymbol[cd].irStruct->classInfo = new llvm::GlobalVariable(st, true, DtoLinkage(cd), NULL, gname, gIR->module); } static llvm::Constant* build_offti_entry(VarDeclaration* vd) @@ -1222,7 +1222,7 @@ vd->type->getTypeInfo(NULL); assert(vd->type->vtinfo); DtoForceDeclareDsymbol(vd->type->vtinfo); - llvm::Constant* c = isaConstant(vd->type->vtinfo->getIrValue()); + llvm::Constant* c = isaConstant(gIR->irDsymbol[vd->type->vtinfo].getIrValue()); const llvm::Type* tiTy = getPtrToType(Type::typeinfo->type->llvmType->get()); //Logger::cout() << "tiTy = " << *tiTy << '\n'; @@ -1300,8 +1300,8 @@ else if (cd->dtors.dim == 1) { DtorDeclaration *d = (DtorDeclaration *)cd->dtors.data[0]; DtoForceDeclareDsymbol(d); - assert(gIR->irFunc[d]->func); - return llvm::ConstantExpr::getBitCast(isaConstant(gIR->irFunc[d]->func), getPtrToType(llvm::Type::Int8Ty)); + assert(gIR->irDsymbol[d].irFunc->func); + return llvm::ConstantExpr::getBitCast(isaConstant(gIR->irDsymbol[d].irFunc->func), getPtrToType(llvm::Type::Int8Ty)); } std::string gname("_D"); @@ -1319,8 +1319,8 @@ { DtorDeclaration *d = (DtorDeclaration *)cd->dtors.data[i]; DtoForceDeclareDsymbol(d); - assert(gIR->irFunc[d]->func); - builder.CreateCall(gIR->irFunc[d]->func, thisptr); + assert(gIR->irDsymbol[d].irFunc->func); + builder.CreateCall(gIR->irDsymbol[d].irFunc->func, thisptr); } builder.CreateRetVoid(); @@ -1375,21 +1375,21 @@ // void *defaultConstructor; // } - if (cd->irStruct->classDefined) return; - cd->irStruct->classDefined = true; + if (gIR->irDsymbol[cd].irStruct->classDefined) return; + gIR->irDsymbol[cd].irStruct->classDefined = true; Logger::println("DtoDefineClassInfo(%s)", cd->toChars()); LOG_SCOPE; assert(cd->type->ty == Tclass); - assert(cd->irStruct->classInfo); + assert(gIR->irDsymbol[cd].irStruct->classInfo); TypeClass* cdty = (TypeClass*)cd->type; if (!cd->isInterfaceDeclaration() && !cd->isAbstract()) { - assert(cd->irStruct->init); - assert(cd->irStruct->constInit); - assert(cd->irStruct->vtbl); - assert(cd->irStruct->constVtbl); + assert(gIR->irDsymbol[cd].irStruct->init); + assert(gIR->irDsymbol[cd].irStruct->constInit); + assert(gIR->irDsymbol[cd].irStruct->vtbl); + assert(gIR->irDsymbol[cd].irStruct->constVtbl); } // holds the list of initializers for llvm @@ -1397,28 +1397,28 @@ ClassDeclaration* cinfo = ClassDeclaration::classinfo; DtoForceConstInitDsymbol(cinfo); - assert(cinfo->irStruct->constInit); + assert(gIR->irDsymbol[cinfo].irStruct->constInit); llvm::Constant* c; // own vtable - c = cinfo->irStruct->constInit->getOperand(0); + c = gIR->irDsymbol[cinfo].irStruct->constInit->getOperand(0); assert(c); inits.push_back(c); // monitor - c = cinfo->irStruct->constInit->getOperand(1); + c = gIR->irDsymbol[cinfo].irStruct->constInit->getOperand(1); inits.push_back(c); // byte[] init const llvm::Type* byteptrty = getPtrToType(llvm::Type::Int8Ty); if (cd->isInterfaceDeclaration() || cd->isAbstract()) { - c = cinfo->irStruct->constInit->getOperand(2); + c = gIR->irDsymbol[cinfo].irStruct->constInit->getOperand(2); } else { - c = llvm::ConstantExpr::getBitCast(cd->irStruct->init, byteptrty); - assert(!cd->irStruct->constInit->getType()->isAbstract()); - size_t initsz = getABITypeSize(cd->irStruct->constInit->getType()); + c = llvm::ConstantExpr::getBitCast(gIR->irDsymbol[cd].irStruct->init, byteptrty); + assert(!gIR->irDsymbol[cd].irStruct->constInit->getType()->isAbstract()); + size_t initsz = getABITypeSize(gIR->irDsymbol[cd].irStruct->constInit->getType()); c = DtoConstSlice(DtoConstSize_t(initsz), c); } inits.push_back(c); @@ -1437,25 +1437,25 @@ // vtbl array if (cd->isInterfaceDeclaration() || cd->isAbstract()) { - c = cinfo->irStruct->constInit->getOperand(4); + c = gIR->irDsymbol[cinfo].irStruct->constInit->getOperand(4); } else { const llvm::Type* byteptrptrty = getPtrToType(byteptrty); - assert(!cd->irStruct->vtbl->getType()->isAbstract()); - c = llvm::ConstantExpr::getBitCast(cd->irStruct->vtbl, byteptrptrty); - assert(!cd->irStruct->constVtbl->getType()->isAbstract()); - size_t vtblsz = cd->irStruct->constVtbl->getType()->getNumElements(); + assert(!gIR->irDsymbol[cd].irStruct->vtbl->getType()->isAbstract()); + c = llvm::ConstantExpr::getBitCast(gIR->irDsymbol[cd].irStruct->vtbl, byteptrptrty); + assert(!gIR->irDsymbol[cd].irStruct->constVtbl->getType()->isAbstract()); + size_t vtblsz = gIR->irDsymbol[cd].irStruct->constVtbl->getType()->getNumElements(); c = DtoConstSlice(DtoConstSize_t(vtblsz), c); } inits.push_back(c); // interfaces array - IrStruct* irstruct = cd->irStruct; + IrStruct* irstruct = gIR->irDsymbol[cd].irStruct; if (cd->isInterfaceDeclaration() || !irstruct->interfaceInfos || cd->isAbstract()) { - c = cinfo->irStruct->constInit->getOperand(5); + c = gIR->irDsymbol[cinfo].irStruct->constInit->getOperand(5); } else { - const llvm::Type* t = cinfo->irStruct->constInit->getOperand(5)->getType()->getContainedType(1); + const llvm::Type* t = gIR->irDsymbol[cinfo].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); @@ -1465,19 +1465,19 @@ // base classinfo if (cd->baseClass && !cd->isInterfaceDeclaration() && !cd->isAbstract()) { DtoDeclareClassInfo(cd->baseClass); - c = cd->baseClass->irStruct->classInfo; + c = gIR->irDsymbol[cd->baseClass].irStruct->classInfo; assert(c); inits.push_back(c); } else { // null - c = cinfo->irStruct->constInit->getOperand(6); + c = gIR->irDsymbol[cinfo].irStruct->constInit->getOperand(6); inits.push_back(c); } // destructor if (cd->isInterfaceDeclaration() || cd->isAbstract()) { - c = cinfo->irStruct->constInit->getOperand(7); + c = gIR->irDsymbol[cinfo].irStruct->constInit->getOperand(7); } else { c = build_class_dtor(cd); @@ -1486,12 +1486,12 @@ // invariant // TODO - c = cinfo->irStruct->constInit->getOperand(8); + c = gIR->irDsymbol[cinfo].irStruct->constInit->getOperand(8); inits.push_back(c); // uint flags if (cd->isInterfaceDeclaration() || cd->isAbstract()) { - c = cinfo->irStruct->constInit->getOperand(9); + c = gIR->irDsymbol[cinfo].irStruct->constInit->getOperand(9); } else { uint flags = build_classinfo_flags(cd); @@ -1501,27 +1501,27 @@ // allocator // TODO - c = cinfo->irStruct->constInit->getOperand(10); + c = gIR->irDsymbol[cinfo].irStruct->constInit->getOperand(10); inits.push_back(c); // offset typeinfo if (cd->isInterfaceDeclaration() || cd->isAbstract()) { - c = cinfo->irStruct->constInit->getOperand(11); + c = gIR->irDsymbol[cinfo].irStruct->constInit->getOperand(11); } else { - c = build_offti_array(cd, cinfo->irStruct->constInit->getOperand(11)); + c = build_offti_array(cd, gIR->irDsymbol[cinfo].irStruct->constInit->getOperand(11)); } inits.push_back(c); // default constructor if (cd->defaultCtor && !cd->isInterfaceDeclaration() && !cd->isAbstract()) { DtoForceDeclareDsymbol(cd->defaultCtor); - c = isaConstant(gIR->irFunc[cd->defaultCtor]->func); - const llvm::Type* toTy = cinfo->irStruct->constInit->getOperand(12)->getType(); + c = isaConstant(gIR->irDsymbol[cd->defaultCtor].irFunc->func); + const llvm::Type* toTy = gIR->irDsymbol[cinfo].irStruct->constInit->getOperand(12)->getType(); c = llvm::ConstantExpr::getBitCast(c, toTy); } else { - c = cinfo->irStruct->constInit->getOperand(12); + c = gIR->irDsymbol[cinfo].irStruct->constInit->getOperand(12); } inits.push_back(c); @@ -1532,10 +1532,10 @@ }*/ // build the initializer - const llvm::StructType* st = isaStruct(cinfo->irStruct->constInit->getType()); + const llvm::StructType* st = isaStruct(gIR->irDsymbol[cinfo].irStruct->constInit->getType()); llvm::Constant* finalinit = llvm::ConstantStruct::get(st, inits); //Logger::cout() << "built the classinfo initializer:\n" << *finalinit <<'\n'; - cd->irStruct->constClassInfo = finalinit; - cd->irStruct->classInfo->setInitializer(finalinit); + gIR->irDsymbol[cd].irStruct->constClassInfo = finalinit; + gIR->irDsymbol[cd].irStruct->classInfo->setInitializer(finalinit); }
--- a/gen/functions.cpp Tue Apr 29 21:33:50 2008 +0200 +++ b/gen/functions.cpp Thu May 01 13:05:53 2008 +0200 @@ -74,10 +74,10 @@ ClassDeclaration* ti = Type::typeinfo; ti->toObjFile(); DtoForceConstInitDsymbol(ti); - assert(ti->irStruct->constInit); + assert(gIR->irDsymbol[ti].irStruct->constInit); std::vector<const llvm::Type*> types; types.push_back(DtoSize_t()); - types.push_back(getPtrToType(getPtrToType(ti->irStruct->constInit->getType()))); + types.push_back(getPtrToType(getPtrToType(gIR->irDsymbol[ti].irStruct->constInit->getType()))); const llvm::Type* t1 = llvm::StructType::get(types); paramvec.push_back(getPtrToType(t1)); paramvec.push_back(getPtrToType(llvm::Type::Int8Ty)); @@ -232,7 +232,7 @@ llvm::Function* func = llvm::dyn_cast<llvm::Function>(fn); assert(func); assert(func->isIntrinsic()); - gIR->irFunc[fdecl]->func = func; + gIR->irDsymbol[fdecl].irFunc->func = func; return func; } @@ -251,8 +251,8 @@ return; } - if (fdecl->llvmResolved) return; - fdecl->llvmResolved = true; + if (gIR->irDsymbol[fdecl].resolved) return; + gIR->irDsymbol[fdecl].resolved = true; Logger::println("DtoResolveFunction(%s): %s", fdecl->toPrettyChars(), fdecl->loc.toChars()); LOG_SCOPE; @@ -272,9 +272,9 @@ { Logger::println("magic va_arg found"); fdecl->llvmInternal = LLVMva_arg; - fdecl->llvmDeclared = true; - fdecl->llvmInitialized = true; - fdecl->llvmDefined = true; + gIR->irDsymbol[fdecl].declared = true; + gIR->irDsymbol[fdecl].initialized = true; + gIR->irDsymbol[fdecl].defined = true; return; // this gets mapped to an instruction so a declaration makes no sence } else if (tempdecl->llvmInternal == LLVMva_start) @@ -295,8 +295,8 @@ void DtoDeclareFunction(FuncDeclaration* fdecl) { - if (fdecl->llvmDeclared) return; - fdecl->llvmDeclared = true; + if (gIR->irDsymbol[fdecl].declared) return; + gIR->irDsymbol[fdecl].declared = true; Logger::println("DtoDeclareFunction(%s): %s", fdecl->toPrettyChars(), fdecl->loc.toChars()); LOG_SCOPE; @@ -311,9 +311,9 @@ if (fdecl->runTimeHack) { Logger::println("runtime hack func chars: %s", fdecl->toChars()); - if (gIR->irFunc.find(fdecl) == gIR->irFunc.end()) { - gIR->irFunc[fdecl] = new IrFunction(fdecl); - gIR->irFunc[fdecl]->func = LLVM_D_GetRuntimeFunction(gIR->module, fdecl->toChars()); + if (!gIR->irDsymbol[fdecl].irFunc) { + gIR->irDsymbol[fdecl].irFunc = new IrFunction(fdecl); + gIR->irDsymbol[fdecl].irFunc->func = LLVM_D_GetRuntimeFunction(gIR->module, fdecl->toChars()); } return; } @@ -330,8 +330,8 @@ else if (fdecl->llvmInternal == LLVMva_start) declareOnly = true; - if (gIR->irFunc.find(fdecl) == gIR->irFunc.end()) { - gIR->irFunc[fdecl] = new IrFunction(fdecl); + if (!gIR->irDsymbol[fdecl].irFunc) { + gIR->irDsymbol[fdecl].irFunc = new IrFunction(fdecl); } // mangled name @@ -358,7 +358,7 @@ assert(func->getFunctionType() == functype); // add func to IRFunc - gIR->irFunc[fdecl]->func = func; + gIR->irDsymbol[fdecl].irFunc->func = func; // calling convention if (!vafunc && fdecl->llvmInternal != LLVMintrinsic) @@ -366,7 +366,7 @@ else // fall back to C, it should be the right thing to do func->setCallingConv(llvm::CallingConv::C); - gIR->irFunc[fdecl]->func = func; + gIR->irDsymbol[fdecl].irFunc->func = func; assert(llvm::isa<llvm::FunctionType>(f->llvmType->get())); // main @@ -388,22 +388,22 @@ int k = 0; if (f->llvmRetInPtr) { iarg->setName("retval"); - gIR->irFunc[fdecl]->retArg = iarg; + gIR->irDsymbol[fdecl].irFunc->retArg = iarg; ++iarg; } if (f->llvmUsesThis) { iarg->setName("this"); - gIR->irFunc[fdecl]->thisVar = iarg; - assert(gIR->irFunc[fdecl]->thisVar); + gIR->irDsymbol[fdecl].irFunc->thisVar = iarg; + assert(gIR->irDsymbol[fdecl].irFunc->thisVar); ++iarg; } if (f->linkage == LINKd && f->varargs == 1) { iarg->setName("_arguments"); - gIR->irFunc[fdecl]->_arguments = iarg; + gIR->irDsymbol[fdecl].irFunc->_arguments = iarg; ++iarg; iarg->setName("_argptr"); - gIR->irFunc[fdecl]->_argptr = iarg; + gIR->irDsymbol[fdecl].irFunc->_argptr = iarg; ++iarg; } @@ -414,15 +414,15 @@ //Logger::println("identifier: '%s' %p\n", arg->ident->toChars(), arg->ident); if (arg && arg->ident != 0) { if (arg->vardecl) { - if (arg->vardecl->irLocal) + if (gIR->irDsymbol[arg->vardecl].irLocal) { - Logger::cout() << "WTF!?!: " << *arg->vardecl->irLocal->value << '\n'; + Logger::cout() << "WTF!?!: " << *gIR->irDsymbol[arg->vardecl].irLocal->value << '\n'; } - assert(!arg->vardecl->irLocal); - assert(!arg->vardecl->irGlobal); - assert(!arg->vardecl->irField); - arg->vardecl->irLocal = new IrLocal(arg->vardecl); - arg->vardecl->irLocal->value = iarg; + assert(!gIR->irDsymbol[arg->vardecl].irLocal); + assert(!gIR->irDsymbol[arg->vardecl].irGlobal); + assert(!gIR->irDsymbol[arg->vardecl].irField); + gIR->irDsymbol[arg->vardecl].irLocal = new IrLocal(arg->vardecl); + gIR->irDsymbol[arg->vardecl].irLocal->value = iarg; } iarg->setName(arg->ident->toChars()); } @@ -446,10 +446,10 @@ void DtoDefineFunc(FuncDeclaration* fd) { - if (fd->llvmDefined) return; - fd->llvmDefined = true; + if (gIR->irDsymbol[fd].defined) return; + gIR->irDsymbol[fd].defined = true; - assert(fd->llvmDeclared); + assert(gIR->irDsymbol[fd].declared); Logger::println("DtoDefineFunc(%s): %s", fd->toPrettyChars(), fd->loc.toChars()); LOG_SCOPE; @@ -457,27 +457,27 @@ // debug info if (global.params.symdebug) { Module* mo = fd->getModule(); - gIR->irFunc[fd]->dwarfSubProg = DtoDwarfSubProgram(fd, DtoDwarfCompileUnit(mo)); + gIR->irDsymbol[fd].irFunc->dwarfSubProg = DtoDwarfSubProgram(fd, DtoDwarfCompileUnit(mo)); } Type* t = DtoDType(fd->type); TypeFunction* f = (TypeFunction*)t; assert(f->llvmType); - llvm::Function* func = gIR->irFunc[fd]->func; + llvm::Function* func = gIR->irDsymbol[fd].irFunc->func; const llvm::FunctionType* functype = func->getFunctionType(); // only members of the current module or template instances maybe be defined if (fd->getModule() == gIR->dmodule || DtoIsTemplateInstance(fd->parent)) { - fd->llvmDModule = gIR->dmodule; + gIR->irDsymbol[fd].DModule = gIR->dmodule; // function definition if (fd->fbody != 0) { Logger::println("Doing function body for: %s", fd->toChars()); - assert(gIR->irFunc.count(fd) != 0); - gIR->functions.push_back(gIR->irFunc[fd]); + assert(gIR->irDsymbol[fd].irFunc); + gIR->functions.push_back(gIR->irDsymbol[fd].irFunc); if (fd->isMain()) gIR->emitMain = true; @@ -495,8 +495,8 @@ // need result variable? (not nested) if (fd->vresult && !fd->vresult->nestedref) { Logger::println("non-nested vresult value"); - fd->vresult->irLocal = new IrLocal(fd->vresult); - fd->vresult->irLocal->value = new llvm::AllocaInst(DtoType(fd->vresult->type),"function_vresult",allocaPoint); + gIR->irDsymbol[fd->vresult].irLocal = new IrLocal(fd->vresult); + gIR->irDsymbol[fd->vresult].irLocal->value = new llvm::AllocaInst(DtoType(fd->vresult->type),"function_vresult",allocaPoint); } // give arguments storage @@ -507,14 +507,14 @@ VarDeclaration* vd = arg->vardecl; if (!vd->needsStorage || vd->nestedref || vd->isRef() || vd->isOut() || DtoIsPassedByRef(vd->type)) continue; - llvm::Value* a = vd->irLocal->value; + llvm::Value* a = gIR->irDsymbol[vd].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); gIR->ir->CreateStore(a,v); - vd->irLocal->value = v; + gIR->irDsymbol[vd].irLocal->value = v; } else { Logger::attention(fd->loc, "some unknown argument: %s", arg ? arg->toChars() : 0); @@ -527,7 +527,7 @@ llvm::Value* parentNested = NULL; if (FuncDeclaration* fd2 = fd->toParent2()->isFuncDeclaration()) { if (!fd->isStatic()) // huh? - parentNested = gIR->irFunc[fd2]->nestedVar; + parentNested = gIR->irDsymbol[fd2].irFunc->nestedVar; } // need result variable? (nested) @@ -547,16 +547,16 @@ for (std::set<VarDeclaration*>::iterator i=fd->nestedVars.begin(); i!=fd->nestedVars.end(); ++i) { VarDeclaration* vd = *i; Logger::println("referenced nested variable %s", vd->toChars()); - if (!vd->irLocal) - vd->irLocal = new IrLocal(vd); - vd->irLocal->nestedIndex = j++; + if (!gIR->irDsymbol[vd].irLocal) + gIR->irDsymbol[vd].irLocal = new IrLocal(vd); + gIR->irDsymbol[vd].irLocal->nestedIndex = j++; if (vd->isParameter()) { - if (!vd->irLocal->value) { + if (!gIR->irDsymbol[vd].irLocal->value) { assert(vd == fd->vthis); - vd->irLocal->value = gIR->irFunc[fd]->thisVar; + gIR->irDsymbol[vd].irLocal->value = gIR->irDsymbol[fd].irFunc->thisVar; } - assert(vd->irLocal->value); - nestTypes.push_back(vd->irLocal->value->getType()); + assert(gIR->irDsymbol[vd].irLocal->value); + nestTypes.push_back(gIR->irDsymbol[vd].irLocal->value->getType()); } else { nestTypes.push_back(DtoType(vd->type)); @@ -564,18 +564,18 @@ } const llvm::StructType* nestSType = llvm::StructType::get(nestTypes); Logger::cout() << "nested var struct has type:" << *nestSType << '\n'; - gIR->irFunc[fd]->nestedVar = new llvm::AllocaInst(nestSType,"nestedvars",allocaPoint); + gIR->irDsymbol[fd].irFunc->nestedVar = new llvm::AllocaInst(nestSType,"nestedvars",allocaPoint); if (parentNested) { - assert(gIR->irFunc[fd]->thisVar); - llvm::Value* ptr = gIR->ir->CreateBitCast(gIR->irFunc[fd]->thisVar, parentNested->getType(), "tmp"); - gIR->ir->CreateStore(ptr, DtoGEPi(gIR->irFunc[fd]->nestedVar, 0,0, "tmp")); + assert(gIR->irDsymbol[fd].irFunc->thisVar); + llvm::Value* ptr = gIR->ir->CreateBitCast(gIR->irDsymbol[fd].irFunc->thisVar, parentNested->getType(), "tmp"); + gIR->ir->CreateStore(ptr, DtoGEPi(gIR->irDsymbol[fd].irFunc->nestedVar, 0,0, "tmp")); } for (std::set<VarDeclaration*>::iterator i=fd->nestedVars.begin(); i!=fd->nestedVars.end(); ++i) { VarDeclaration* vd = *i; if (vd->isParameter()) { - assert(vd->irLocal); - gIR->ir->CreateStore(vd->irLocal->value, DtoGEPi(gIR->irFunc[fd]->nestedVar, 0, vd->irLocal->nestedIndex, "tmp")); - vd->irLocal->value = gIR->irFunc[fd]->nestedVar; + assert(gIR->irDsymbol[vd].irLocal); + gIR->ir->CreateStore(gIR->irDsymbol[vd].irLocal->value, DtoGEPi(gIR->irDsymbol[fd].irFunc->nestedVar, 0, gIR->irDsymbol[vd].irLocal->nestedIndex, "tmp")); + gIR->irDsymbol[vd].irLocal->value = gIR->irDsymbol[fd].irFunc->nestedVar; } } } @@ -583,9 +583,9 @@ // copy _argptr to a memory location if (f->linkage == LINKd && f->varargs == 1) { - llvm::Value* argptrmem = new llvm::AllocaInst(gIR->irFunc[fd]->_argptr->getType(), "_argptrmem", gIR->topallocapoint()); - new llvm::StoreInst(gIR->irFunc[fd]->_argptr, argptrmem, gIR->scopebb()); - gIR->irFunc[fd]->_argptr = argptrmem; + llvm::Value* argptrmem = new llvm::AllocaInst(gIR->irDsymbol[fd].irFunc->_argptr->getType(), "_argptrmem", gIR->topallocapoint()); + new llvm::StoreInst(gIR->irDsymbol[fd].irFunc->_argptr, argptrmem, gIR->scopebb()); + gIR->irDsymbol[fd].irFunc->_argptr = argptrmem; } // output function body
--- a/gen/irstate.h Tue Apr 29 21:33:50 2008 +0200 +++ b/gen/irstate.h Thu May 01 13:05:53 2008 +0200 @@ -11,6 +11,7 @@ #include "ir/irfunction.h" #include "ir/irstruct.h" #include "ir/irvar.h" +#include "ir/irsymbol.h" // global ir state for current module struct IRState; @@ -26,6 +27,8 @@ struct BaseClass; struct TryFinallyStatement; +struct IrModule; + // represents a scope struct IRScope { @@ -73,12 +76,13 @@ Module* dmodule; llvm::Module* module; + // ir data associated with DMD Dsymbol nodes + std::map<Dsymbol*, IrDsymbol> irDsymbol; + // functions typedef std::vector<IrFunction*> FunctionVector; FunctionVector functions; IrFunction* func(); - // ir data associated with function declarations - std::map<FuncDeclaration*, IrFunction*> irFunc; llvm::Function* topfunc(); TypeFunction* topfunctype();
--- a/gen/statements.cpp Tue Apr 29 21:33:50 2008 +0200 +++ b/gen/statements.cpp Thu May 01 13:05:53 2008 +0200 @@ -77,11 +77,11 @@ if (p->topfunc()->getReturnType() == llvm::Type::VoidTy) { IrFunction* f = p->func(); assert(f->type->llvmRetInPtr); - assert(gIR->irFunc[f->decl]->retArg); + assert(gIR->irDsymbol[f->decl].irFunc->retArg); if (global.params.symdebug) DtoDwarfStopPoint(loc.linnum); - DValue* rvar = new DVarValue(f->type->next, gIR->irFunc[f->decl]->retArg, true); + DValue* rvar = new DVarValue(f->type->next, gIR->irDsymbol[f->decl].irFunc->retArg, true); p->exps.push_back(IRExp(NULL,exp,rvar)); DValue* e = exp->toElem(p); @@ -801,9 +801,9 @@ if (key) { //key->llvmValue = keyvar; - assert(!key->irLocal); - key->irLocal = new IrLocal(key); - key->irLocal->value = keyvar; + assert(!gIR->irDsymbol[key].irLocal); + gIR->irDsymbol[key].irLocal = new IrLocal(key); + gIR->irDsymbol[key].irLocal->value = keyvar; } llvm::Value* zerokey = llvm::ConstantInt::get(keytype,0,false); @@ -812,8 +812,8 @@ llvm::Value* valvar = NULL; if (!value->isRef() && !value->isOut()) valvar = new llvm::AllocaInst(valtype, "foreachval", p->topallocapoint()); - assert(!value->irLocal); - value->irLocal = new IrLocal(value); + assert(!gIR->irDsymbol[value].irLocal); + gIR->irDsymbol[value].irLocal = new IrLocal(value); // what to iterate DValue* aggrval = aggr->toElem(p); @@ -909,15 +909,15 @@ llvm::Constant* zero = llvm::ConstantInt::get(keytype,0,false); llvm::Value* loadedKey = p->ir->CreateLoad(keyvar,"tmp"); if (aggrtype->ty == Tsarray) - value->irLocal->value = DtoGEP(val,zero,loadedKey,"tmp"); + gIR->irDsymbol[value].irLocal->value = DtoGEP(val,zero,loadedKey,"tmp"); else if (aggrtype->ty == Tarray) - value->irLocal->value = new llvm::GetElementPtrInst(val,loadedKey,"tmp",p->scopebb()); + gIR->irDsymbol[value].irLocal->value = new llvm::GetElementPtrInst(val,loadedKey,"tmp",p->scopebb()); if (!value->isRef() && !value->isOut()) { DValue* dst = new DVarValue(value->type, valvar, true); - DValue* src = new DVarValue(value->type, value->irLocal->value, true); + DValue* src = new DVarValue(value->type, gIR->irDsymbol[value].irLocal->value, true); DtoAssign(dst, src); - value->irLocal->value = valvar; + gIR->irDsymbol[value].irLocal->value = valvar; } // emit body @@ -1046,7 +1046,7 @@ assert(body); DValue* e = exp->toElem(p); - wthis->irLocal->value = e->getRVal(); + gIR->irDsymbol[wthis].irLocal->value = e->getRVal(); delete e; body->toIR(p);
--- a/gen/structs.cpp Tue Apr 29 21:33:50 2008 +0200 +++ b/gen/structs.cpp Thu May 01 13:05:53 2008 +0200 @@ -95,11 +95,11 @@ VarDeclaration* vd = (VarDeclaration*)si->vars.data[i]; assert(vd); llvm::Constant* v = DtoConstInitializer(vd->type, ini); - inits.push_back(DUnionIdx(vd->irField->index, vd->irField->indexOffset, v)); + inits.push_back(DUnionIdx(gIR->irDsymbol[vd].irField->index, gIR->irDsymbol[vd].irField->indexOffset, v)); } DtoConstInitStruct((StructDeclaration*)si->ad); - return si->ad->irStruct->dunion->getConst(inits); + return gIR->irDsymbol[si->ad].irStruct->dunion->getConst(inits); } ////////////////////////////////////////////////////////////////////////////////////////// @@ -115,7 +115,7 @@ const llvm::Type* llt = getPtrToType(DtoType(t)); const llvm::Type* st = getPtrToType(DtoType(sd->type)); if (ptr->getType() != st) { - assert(sd->irStruct->hasUnions); + assert(gIR->irDsymbol[sd].irStruct->hasUnions); ptr = gIR->ir->CreateBitCast(ptr, st, "tmp"); } @@ -123,26 +123,26 @@ VarDeclaration* vd = (VarDeclaration*)sd->fields.data[i]; Type* vdtype = DtoDType(vd->type); Logger::println("found %u type %s", vd->offset, vdtype->toChars()); - assert(vd->irField->index >= 0); + assert(gIR->irDsymbol[vd].irField->index >= 0); if (os == vd->offset && vdtype == t) { - idxs.push_back(vd->irField->index); + idxs.push_back(gIR->irDsymbol[vd].irField->index); ptr = DtoGEP(ptr, idxs, "tmp"); if (ptr->getType() != llt) ptr = gIR->ir->CreateBitCast(ptr, llt, "tmp"); - if (vd->irField->indexOffset) - ptr = new llvm::GetElementPtrInst(ptr, DtoConstUint(vd->irField->indexOffset), "tmp", gIR->scopebb()); + if (gIR->irDsymbol[vd].irField->indexOffset) + ptr = new llvm::GetElementPtrInst(ptr, DtoConstUint(gIR->irDsymbol[vd].irField->indexOffset), "tmp", gIR->scopebb()); return ptr; } else if (vdtype->ty == Tstruct && (vd->offset + vdtype->size()) > os) { TypeStruct* ts = (TypeStruct*)vdtype; StructDeclaration* ssd = ts->sym; - idxs.push_back(vd->irField->index); - if (vd->irField->indexOffset) { + idxs.push_back(gIR->irDsymbol[vd].irField->index); + if (gIR->irDsymbol[vd].irField->indexOffset) { Logger::println("has union field offset"); ptr = DtoGEP(ptr, idxs, "tmp"); if (ptr->getType() != llt) ptr = DtoBitCast(ptr, llt); - ptr = new llvm::GetElementPtrInst(ptr, DtoConstUint(vd->irField->indexOffset), "tmp", gIR->scopebb()); + ptr = new llvm::GetElementPtrInst(ptr, DtoConstUint(gIR->irDsymbol[vd].irField->indexOffset), "tmp", gIR->scopebb()); std::vector<unsigned> tmp; return DtoIndexStruct(ptr, ssd, t, os-vd->offset, tmp); } @@ -170,8 +170,8 @@ void DtoResolveStruct(StructDeclaration* sd) { - if (sd->llvmResolved) return; - sd->llvmResolved = true; + if (gIR->irDsymbol[sd].resolved) return; + gIR->irDsymbol[sd].resolved = true; Logger::println("DtoResolveStruct(%s): %s", sd->toChars(), sd->loc.toChars()); LOG_SCOPE; @@ -179,7 +179,7 @@ TypeStruct* ts = (TypeStruct*)DtoDType(sd->type); IrStruct* irstruct = new IrStruct(ts); - sd->irStruct = irstruct; + gIR->irDsymbol[sd].irStruct = irstruct; gIR->structs.push_back(irstruct); // fields @@ -243,7 +243,7 @@ fieldtype = i->second.type; fieldinit = i->second.var; prevsize = getABITypeSize(fieldtype); - i->second.var->irField->index = idx; + gIR->irDsymbol[i->second.var].irField->index = idx; } // colliding offset? else if (lastoffset == i->first) { @@ -252,16 +252,16 @@ fieldpad += s - prevsize; prevsize = s; } - sd->irStruct->hasUnions = true; - i->second.var->irField->index = idx; + gIR->irDsymbol[sd].irStruct->hasUnions = true; + gIR->irDsymbol[i->second.var].irField->index = idx; } // intersecting offset? else if (i->first < (lastoffset + prevsize)) { size_t s = getABITypeSize(i->second.type); assert((i->first + s) <= (lastoffset + prevsize)); // this holds because all types are aligned to their size - sd->irStruct->hasUnions = true; - i->second.var->irField->index = idx; - i->second.var->irField->indexOffset = (i->first - lastoffset) / s; + gIR->irDsymbol[sd].irStruct->hasUnions = true; + gIR->irDsymbol[i->second.var].irField->index = idx; + gIR->irDsymbol[i->second.var].irField->indexOffset = (i->first - lastoffset) / s; } // fresh offset else { @@ -281,7 +281,7 @@ fieldtype = i->second.type; fieldinit = i->second.var; prevsize = getABITypeSize(fieldtype); - i->second.var->irField->index = idx; + gIR->irDsymbol[i->second.var].irField->index = idx; fieldpad = 0; } } @@ -320,8 +320,8 @@ void DtoDeclareStruct(StructDeclaration* sd) { - if (sd->llvmDeclared) return; - sd->llvmDeclared = true; + if (gIR->irDsymbol[sd].declared) return; + gIR->irDsymbol[sd].declared = true; Logger::println("DtoDeclareStruct(%s): %s", sd->toChars(), sd->loc.toChars()); LOG_SCOPE; @@ -334,7 +334,7 @@ llvm::GlobalValue::LinkageTypes _linkage = DtoExternalLinkage(sd); llvm::GlobalVariable* initvar = new llvm::GlobalVariable(ts->llvmType->get(), true, _linkage, NULL, initname, gIR->module); - sd->irStruct->init = initvar; + gIR->irDsymbol[sd].irStruct->init = initvar; gIR->constInitList.push_back(sd); if (sd->getModule() == gIR->dmodule) @@ -345,13 +345,13 @@ void DtoConstInitStruct(StructDeclaration* sd) { - if (sd->llvmInitialized) return; - sd->llvmInitialized = true; + if (gIR->irDsymbol[sd].initialized) return; + gIR->irDsymbol[sd].initialized = true; Logger::println("DtoConstInitStruct(%s): %s", sd->toChars(), sd->loc.toChars()); LOG_SCOPE; - IrStruct* irstruct = sd->irStruct; + IrStruct* irstruct = gIR->irDsymbol[sd].irStruct; gIR->structs.push_back(irstruct); // make sure each offset knows its default initializer @@ -360,7 +360,7 @@ IrStruct::Offset* so = &i->second; llvm::Constant* finit = DtoConstFieldInitializer(so->var->type, so->var->init); so->init = finit; - so->var->irField->constInit = finit; + gIR->irDsymbol[so->var].irField->constInit = finit; } const llvm::StructType* structtype = isaStruct(sd->type->llvmType->get()); @@ -371,7 +371,7 @@ for (size_t i=0; i<nfi; ++i) { llvm::Constant* c; if (irstruct->defaultFields[i] != NULL) { - c = irstruct->defaultFields[i]->irField->constInit; + c = gIR->irDsymbol[irstruct->defaultFields[i]].irField->constInit; assert(c); } else { @@ -383,7 +383,7 @@ } // generate the union mapper - sd->irStruct->dunion = new DUnion; // uses gIR->topstruct() + gIR->irDsymbol[sd].irStruct->dunion = new DUnion; // uses gIR->topstruct() // always generate the constant initalizer if (!sd->zeroInit) { @@ -399,11 +399,11 @@ } Logger::cout() << "Initializer printed" << '\n'; #endif - sd->irStruct->constInit = llvm::ConstantStruct::get(structtype,fieldinits_ll); + gIR->irDsymbol[sd].irStruct->constInit = llvm::ConstantStruct::get(structtype,fieldinits_ll); } else { Logger::println("Zero initialized"); - sd->irStruct->constInit = llvm::ConstantAggregateZero::get(structtype); + gIR->irDsymbol[sd].irStruct->constInit = llvm::ConstantAggregateZero::get(structtype); } gIR->structs.pop_back(); @@ -417,17 +417,17 @@ void DtoDefineStruct(StructDeclaration* sd) { - if (sd->llvmDefined) return; - sd->llvmDefined = true; + if (gIR->irDsymbol[sd].defined) return; + gIR->irDsymbol[sd].defined = true; Logger::println("DtoDefineStruct(%s): %s", sd->toChars(), sd->loc.toChars()); LOG_SCOPE; assert(sd->type->ty == Tstruct); TypeStruct* ts = (TypeStruct*)sd->type; - sd->irStruct->init->setInitializer(sd->irStruct->constInit); + gIR->irDsymbol[sd].irStruct->init->setInitializer(gIR->irDsymbol[sd].irStruct->constInit); - sd->llvmDModule = gIR->dmodule; + gIR->irDsymbol[sd].DModule = gIR->dmodule; } //////////////////////////////////////////////////////////////////////////////////////////
--- a/gen/todebug.cpp Tue Apr 29 21:33:50 2008 +0200 +++ b/gen/todebug.cpp Thu May 01 13:05:53 2008 +0200 @@ -114,12 +114,12 @@ llvm::GlobalVariable* DtoDwarfCompileUnit(Module* m) { - if (!m->irModule) - m->irModule = new IrModule(m); - else if (m->irModule->dwarfCompileUnit) + if (!gIR->irDsymbol[m].irModule) + gIR->irDsymbol[m].irModule = new IrModule(m); + else if (gIR->irDsymbol[m].irModule->dwarfCompileUnit) { - if (m->irModule->dwarfCompileUnit->getParent() == gIR->module) - return m->irModule->dwarfCompileUnit; + if (gIR->irDsymbol[m].irModule->dwarfCompileUnit->getParent() == gIR->module) + return gIR->irDsymbol[m].irModule->dwarfCompileUnit; } // create a valid compile unit constant for the current module @@ -148,7 +148,7 @@ llvm::GlobalVariable* gv = new llvm::GlobalVariable(GetDwarfCompileUnitType(), true, llvm::GlobalValue::InternalLinkage, c, "llvm.dbg.compile_unit", gIR->module); gv->setSection("llvm.metadata"); - m->irModule->dwarfCompileUnit = gv; + gIR->irDsymbol[m].irModule->dwarfCompileUnit = gv; return gv; } @@ -182,14 +182,14 @@ void DtoDwarfFuncStart(FuncDeclaration* fd) { - assert(gIR->irFunc[fd]->dwarfSubProg); - gIR->ir->CreateCall(gIR->module->getFunction("llvm.dbg.func.start"), dbgToArrTy(gIR->irFunc[fd]->dwarfSubProg)); + assert(gIR->irDsymbol[fd].irFunc->dwarfSubProg); + gIR->ir->CreateCall(gIR->module->getFunction("llvm.dbg.func.start"), dbgToArrTy(gIR->irDsymbol[fd].irFunc->dwarfSubProg)); } void DtoDwarfFuncEnd(FuncDeclaration* fd) { - assert(gIR->irFunc[fd]->dwarfSubProg); - gIR->ir->CreateCall(gIR->module->getFunction("llvm.dbg.region.end"), dbgToArrTy(gIR->irFunc[fd]->dwarfSubProg)); + assert(gIR->irDsymbol[fd].irFunc->dwarfSubProg); + gIR->ir->CreateCall(gIR->module->getFunction("llvm.dbg.region.end"), dbgToArrTy(gIR->irDsymbol[fd].irFunc->dwarfSubProg)); } //////////////////////////////////////////////////////////////////////////////////////////////////
--- a/gen/toir.cpp Tue Apr 29 21:33:50 2008 +0200 +++ b/gen/toir.cpp Thu May 01 13:05:53 2008 +0200 @@ -61,10 +61,10 @@ // referenced by nested delegate? if (vd->nestedref) { Logger::println("has nestedref set"); - assert(vd->irLocal); - vd->irLocal->value = gIR->irFunc[p->func()->decl]->nestedVar; - assert(vd->irLocal->value); - assert(vd->irLocal->nestedIndex >= 0); + assert(gIR->irDsymbol[vd].irLocal); + gIR->irDsymbol[vd].irLocal->value = gIR->irDsymbol[p->func()->decl].irFunc->nestedVar; + assert(gIR->irDsymbol[vd].irLocal->value); + assert(gIR->irDsymbol[vd].irLocal->nestedIndex >= 0); } // normal stack variable else { @@ -72,16 +72,16 @@ const llvm::Type* lltype = DtoType(vd->type); llvm::AllocaInst* allocainst = new llvm::AllocaInst(lltype, vd->toChars(), p->topallocapoint()); //allocainst->setAlignment(vd->type->alignsize()); // TODO - assert(!vd->irLocal); - vd->irLocal = new IrLocal(vd); - vd->irLocal->value = allocainst; + assert(!gIR->irDsymbol[vd].irLocal); + gIR->irDsymbol[vd].irLocal = new IrLocal(vd); + gIR->irDsymbol[vd].irLocal->value = allocainst; } - Logger::cout() << "llvm value for decl: " << *vd->irLocal->value << '\n'; + Logger::cout() << "llvm value for decl: " << *gIR->irDsymbol[vd].irLocal->value << '\n'; DValue* ie = DtoInitializer(vd->init); } - return new DVarValue(vd, vd->getIrValue(), true); + return new DVarValue(vd, gIR->irDsymbol[vd].getIrValue(), true); } // struct declaration else if (StructDeclaration* s = declaration->isStructDeclaration()) @@ -153,11 +153,11 @@ if (vd->ident == Id::_arguments) { Logger::println("Id::_arguments"); - /*if (!vd->getIrValue()) - vd->getIrValue() = p->func()->decl->irFunc->_arguments; - assert(vd->getIrValue()); - return new DVarValue(vd, vd->getIrValue(), true);*/ - llvm::Value* v = gIR->irFunc[p->func()->decl]->_arguments; + /*if (!gIR->irDsymbol[vd].getIrValue()) + gIR->irDsymbol[vd].getIrValue() = p->func()->decl->irFunc->_arguments; + assert(gIR->irDsymbol[vd].getIrValue()); + return new DVarValue(vd, gIR->irDsymbol[vd].getIrValue(), true);*/ + llvm::Value* v = gIR->irDsymbol[p->func()->decl].irFunc->_arguments; assert(v); return new DVarValue(vd, v, true); } @@ -165,11 +165,11 @@ else if (vd->ident == Id::_argptr) { Logger::println("Id::_argptr"); - /*if (!vd->getIrValue()) - vd->getIrValue() = p->func()->decl->irFunc->_argptr; - assert(vd->getIrValue()); - return new DVarValue(vd, vd->getIrValue(), true);*/ - llvm::Value* v = gIR->irFunc[p->func()->decl]->_argptr; + /*if (!gIR->irDsymbol[vd].getIrValue()) + gIR->irDsymbol[vd].getIrValue() = p->func()->decl->irFunc->_argptr; + assert(gIR->irDsymbol[vd].getIrValue()); + return new DVarValue(vd, gIR->irDsymbol[vd].getIrValue(), true);*/ + llvm::Value* v = gIR->irDsymbol[p->func()->decl].irFunc->_argptr; assert(v); return new DVarValue(vd, v, true); } @@ -186,13 +186,13 @@ { Logger::println("TypeInfoDeclaration"); DtoForceDeclareDsymbol(tid); - assert(tid->getIrValue()); + assert(gIR->irDsymbol[tid].getIrValue()); const llvm::Type* vartype = DtoType(type); llvm::Value* m; - if (tid->getIrValue()->getType() != getPtrToType(vartype)) - m = p->ir->CreateBitCast(tid->getIrValue(), vartype, "tmp"); + if (gIR->irDsymbol[tid].getIrValue()->getType() != getPtrToType(vartype)) + m = p->ir->CreateBitCast(gIR->irDsymbol[tid].getIrValue(), vartype, "tmp"); else - m = tid->getIrValue(); + m = gIR->irDsymbol[tid].getIrValue(); return new DVarValue(vd, m, true); } // classinfo @@ -200,8 +200,8 @@ { Logger::println("ClassInfoDeclaration: %s", cid->cd->toChars()); DtoDeclareClassInfo(cid->cd); - assert(cid->cd->irStruct->classInfo); - return new DVarValue(vd, cid->cd->irStruct->classInfo, true); + assert(gIR->irDsymbol[cid->cd].irStruct->classInfo); + return new DVarValue(vd, gIR->irDsymbol[cid->cd].irStruct->classInfo, true); } // nested variable else if (vd->nestedref) { @@ -211,16 +211,16 @@ // function parameter else if (vd->isParameter()) { Logger::println("function param"); - if (!vd->getIrValue()) { + if (!gIR->irDsymbol[vd].getIrValue()) { // TODO: determine this properly // this happens when the DMD frontend generates by pointer wrappers for struct opEquals(S) and opCmp(S) - vd->getIrValue() = &p->func()->func->getArgumentList().back(); + gIR->irDsymbol[vd].getIrValue() = &p->func()->func->getArgumentList().back(); } - if (vd->isRef() || vd->isOut() || DtoIsPassedByRef(vd->type) || llvm::isa<llvm::AllocaInst>(vd->getIrValue())) { - return new DVarValue(vd, vd->getIrValue(), true); + if (vd->isRef() || vd->isOut() || DtoIsPassedByRef(vd->type) || llvm::isa<llvm::AllocaInst>(gIR->irDsymbol[vd].getIrValue())) { + return new DVarValue(vd, gIR->irDsymbol[vd].getIrValue(), true); } - else if (llvm::isa<llvm::Argument>(vd->getIrValue())) { - return new DImValue(type, vd->getIrValue()); + else if (llvm::isa<llvm::Argument>(gIR->irDsymbol[vd].getIrValue())) { + return new DImValue(type, gIR->irDsymbol[vd].getIrValue()); } else assert(0); } @@ -230,11 +230,11 @@ vd->toObjFile(); DtoConstInitGlobal(vd); } - if (!vd->getIrValue() || vd->getIrValue()->getType()->isAbstract()) { + if (!gIR->irDsymbol[vd].getIrValue() || gIR->irDsymbol[vd].getIrValue()->getType()->isAbstract()) { Logger::println("global variable not resolved :/ %s", vd->toChars()); assert(0); } - return new DVarValue(vd, vd->getIrValue(), true); + return new DVarValue(vd, gIR->irDsymbol[vd].getIrValue(), true); } } else if (FuncDeclaration* fdecl = var->isFuncDeclaration()) @@ -243,7 +243,7 @@ if (fdecl->llvmInternal != LLVMva_arg) {// && fdecl->llvmValue == 0) DtoForceDeclareDsymbol(fdecl); } - return new DFuncValue(fdecl, gIR->irFunc[fdecl]->func); + return new DFuncValue(fdecl, gIR->irDsymbol[fdecl].irFunc->func); } else if (SymbolDeclaration* sdecl = var->isSymbolDeclaration()) { @@ -253,8 +253,8 @@ assert(sdecltype->ty == Tstruct); TypeStruct* ts = (TypeStruct*)sdecltype; assert(ts->sym); - assert(ts->sym->irStruct->init); - return new DVarValue(type, ts->sym->irStruct->init, true); + assert(gIR->irDsymbol[ts->sym].irStruct->init); + return new DVarValue(type, gIR->irDsymbol[ts->sym].irStruct->init, true); } else { @@ -278,17 +278,17 @@ assert(sdecltype->ty == Tstruct); TypeStruct* ts = (TypeStruct*)sdecltype; DtoForceConstInitDsymbol(ts->sym); - assert(ts->sym->irStruct->constInit); - return ts->sym->irStruct->constInit; + assert(gIR->irDsymbol[ts->sym].irStruct->constInit); + return gIR->irDsymbol[ts->sym].irStruct->constInit; } else if (TypeInfoDeclaration* ti = var->isTypeInfoDeclaration()) { DtoForceDeclareDsymbol(ti); - assert(ti->getIrValue()); + assert(gIR->irDsymbol[ti].getIrValue()); const llvm::Type* vartype = DtoType(type); - llvm::Constant* m = isaConstant(ti->getIrValue()); + llvm::Constant* m = isaConstant(gIR->irDsymbol[ti].getIrValue()); assert(m); - if (ti->getIrValue()->getType() != getPtrToType(vartype)) + if (gIR->irDsymbol[ti].getIrValue()->getType() != getPtrToType(vartype)) m = llvm::ConstantExpr::getBitCast(m, vartype); return m; } @@ -1079,7 +1079,7 @@ } // build type info array - assert(Type::typeinfo->irStruct->constInit); + assert(gIR->irDsymbol[Type::typeinfo].irStruct->constInit); const llvm::Type* typeinfotype = DtoType(Type::typeinfo->type); const llvm::ArrayType* typeinfoarraytype = llvm::ArrayType::get(typeinfotype,vtype->getNumElements()); @@ -1090,8 +1090,8 @@ Expression* argexp = (Expression*)arguments->data[i]; TypeInfoDeclaration* tidecl = argexp->type->getTypeInfoDeclaration(); DtoForceDeclareDsymbol(tidecl); - assert(tidecl->getIrValue()); - vtypeinfos.push_back(tidecl->getIrValue()); + assert(gIR->irDsymbol[tidecl].getIrValue()); + vtypeinfos.push_back(gIR->irDsymbol[tidecl].getIrValue()); llvm::Value* v = p->ir->CreateBitCast(vtypeinfos[k], typeinfotype, "tmp"); p->ir->CreateStore(v, DtoGEPi(typeinfomem,0,k,"tmp")); } @@ -1233,16 +1233,16 @@ Logger::println("VarDeclaration"); // handle forward reference - if (!vd->llvmDeclared && vd->isDataseg()) { + if (!gIR->irDsymbol[vd].declared && vd->isDataseg()) { vd->toObjFile(); // TODO } - assert(vd->getIrValue()); + assert(gIR->irDsymbol[vd].getIrValue()); Type* t = DtoDType(type); Type* tnext = DtoDType(t->next); Type* vdtype = DtoDType(vd->type); - llvm::Value* llvalue = vd->nestedref ? DtoNestedVariable(vd) : vd->getIrValue(); + llvm::Value* llvalue = vd->nestedref ? DtoNestedVariable(vd) : gIR->irDsymbol[vd].getIrValue(); llvm::Value* varmem = 0; if (vdtype->ty == Tstruct && !(t->ty == Tpointer && t->next == vdtype)) { @@ -1317,7 +1317,7 @@ FuncDeclaration* fd = fv->func; assert(fd); DtoForceDeclareDsymbol(fd); - return new DFuncValue(fd, gIR->irFunc[fd]->func); + return new DFuncValue(fd, gIR->irDsymbol[fd].irFunc->func); } else if (DImValue* im = v->isIm()) { Logger::println("is immediate"); @@ -1422,7 +1422,7 @@ // super call if (e1->op == TOKsuper) { DtoForceDeclareDsymbol(fdecl); - funcval = gIR->irFunc[fdecl]->func; + funcval = gIR->irDsymbol[fdecl].irFunc->func; assert(funcval); } // normal virtual call @@ -1443,7 +1443,7 @@ // static call else { DtoForceDeclareDsymbol(fdecl); - funcval = gIR->irFunc[fdecl]->func; + funcval = gIR->irDsymbol[fdecl].irFunc->func; assert(funcval); //assert(funcval->getType() == DtoType(fdecl->type)); } @@ -1466,7 +1466,7 @@ if (VarDeclaration* vd = var->isVarDeclaration()) { llvm::Value* v; - v = gIR->irFunc[p->func()->decl]->thisVar; + v = gIR->irDsymbol[p->func()->decl].irFunc->thisVar; if (llvm::isa<llvm::AllocaInst>(v)) v = new llvm::LoadInst(v, "tmp", p->scopebb()); return new DThisValue(vd, v); @@ -1932,7 +1932,7 @@ } else { assert(ts->sym); - DtoStructCopy(emem,ts->sym->irStruct->init); + DtoStructCopy(emem,gIR->irDsymbol[ts->sym].irStruct->init); } } @@ -2216,7 +2216,7 @@ if (DFuncValue* f = u->isFunc()) { //assert(f->vthis); //uval = f->vthis; - llvm::Value* nestvar = gIR->irFunc[p->func()->decl]->nestedVar; + llvm::Value* nestvar = gIR->irDsymbol[p->func()->decl].irFunc->nestedVar; if (nestvar) uval = nestvar; else @@ -2256,7 +2256,7 @@ else { DtoForceDeclareDsymbol(func); - castfptr = gIR->irFunc[func]->func; + castfptr = gIR->irDsymbol[func].irFunc->func; } castfptr = DtoBitCast(castfptr, fptr->getType()->getContainedType(0)); @@ -2490,7 +2490,7 @@ llvm::Value* context = DtoGEPi(lval,0,0,"tmp",p->scopebb()); const llvm::PointerType* pty = isaPointer(context->getType()->getContainedType(0)); - llvm::Value* llvmNested = gIR->irFunc[p->func()->decl]->nestedVar; + llvm::Value* llvmNested = gIR->irDsymbol[p->func()->decl].irFunc->nestedVar; if (llvmNested == NULL) { llvm::Value* nullcontext = llvm::ConstantPointerNull::get(pty); p->ir->CreateStore(nullcontext, context); @@ -2502,8 +2502,8 @@ llvm::Value* fptr = DtoGEPi(lval,0,1,"tmp",p->scopebb()); - assert(gIR->irFunc[fd]->func); - llvm::Value* castfptr = new llvm::BitCastInst(gIR->irFunc[fd]->func,fptr->getType()->getContainedType(0),"tmp",p->scopebb()); + assert(gIR->irDsymbol[fd].irFunc->func); + llvm::Value* castfptr = new llvm::BitCastInst(gIR->irDsymbol[fd].irFunc->func,fptr->getType()->getContainedType(0),"tmp",p->scopebb()); new llvm::StoreInst(castfptr, fptr, p->scopebb()); if (temp) @@ -2632,7 +2632,7 @@ unsigned n = elements->dim; // unions might have different types for each literal - if (sd->irStruct->hasUnions) { + if (gIR->irDsymbol[sd].irStruct->hasUnions) { // build the type of the literal std::vector<const llvm::Type*> tys; for (unsigned i=0; i<n; ++i) {
--- a/gen/tollvm.cpp Tue Apr 29 21:33:50 2008 +0200 +++ b/gen/tollvm.cpp Thu May 01 13:05:53 2008 +0200 @@ -116,7 +116,7 @@ TypeStruct* ts = (TypeStruct*)t; assert(ts->sym); DtoResolveDsymbol(ts->sym); - return ts->sym->irStruct->recty.get();//t->llvmType->get(); + return gIR->irDsymbol[ts->sym].irStruct->recty.get();//t->llvmType->get(); } case Tclass: { @@ -139,7 +139,7 @@ TypeClass* tc = (TypeClass*)t; assert(tc->sym); DtoResolveDsymbol(tc->sym); - return getPtrToType(tc->sym->irStruct->recty.get());//t->llvmType->get()); + return getPtrToType(gIR->irDsymbol[tc->sym].irStruct->recty.get());//t->llvmType->get()); } // functions @@ -561,8 +561,8 @@ TypeStruct* ts = (TypeStruct*)t; assert(ts); assert(ts->sym); - assert(ts->sym->irStruct->constInit); - _init = ts->sym->irStruct->constInit; + assert(gIR->irDsymbol[ts->sym].irStruct->constInit); + _init = gIR->irDsymbol[ts->sym].irStruct->constInit; } else if (t->ty == Tclass) { @@ -724,7 +724,7 @@ assert(p->isFuncDeclaration() || p->isClassDeclaration()); if (FuncDeclaration* fd = p->isFuncDeclaration()) { - llvm::Value* v = gIR->irFunc[fd]->nestedVar; + llvm::Value* v = gIR->irDsymbol[fd].irFunc->nestedVar; assert(v); return v->getType(); } @@ -754,9 +754,9 @@ if (fd->toParent2() == func) { - if (!gIR->irFunc[func]->nestedVar) + if (!gIR->irDsymbol[func].irFunc->nestedVar) return NULL; - return DtoBitCast(v, gIR->irFunc[func]->nestedVar->getType()); + return DtoBitCast(v, gIR->irDsymbol[func].irFunc->nestedVar->getType()); } v = DtoBitCast(v, get_next_frame_ptr_type(fd)); @@ -770,7 +770,7 @@ else if (ClassDeclaration* cd = fd->toParent2()->isClassDeclaration()) { size_t idx = 2; - //idx += cd->irStruct->interfaceVec.size(); + //idx += gIR->irDsymbol[cd].irStruct->interfaceVec.size(); v = DtoGEPi(v,0,idx,"tmp"); v = DtoLoad(v); } @@ -807,10 +807,10 @@ // in the right scope already if (func == irfunc->decl) - return gIR->irFunc[irfunc->decl]->nestedVar; + return gIR->irDsymbol[irfunc->decl].irFunc->nestedVar; // use the 'this' pointer - llvm::Value* ptr = gIR->irFunc[irfunc->decl]->thisVar; + llvm::Value* ptr = gIR->irDsymbol[irfunc->decl].irFunc->thisVar; assert(ptr); // return the fully resolved frame pointer @@ -878,10 +878,10 @@ assert(ptr && "nested var, but no context"); // we must cast here to be sure. nested classes just have a void* - ptr = DtoBitCast(ptr, gIR->irFunc[func]->nestedVar->getType()); + ptr = DtoBitCast(ptr, gIR->irDsymbol[func].irFunc->nestedVar->getType()); // index nested var and load (if necessary) - llvm::Value* v = DtoGEPi(ptr, 0, vd->irLocal->nestedIndex, "tmp"); + llvm::Value* v = DtoGEPi(ptr, 0, gIR->irDsymbol[vd].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); @@ -964,9 +964,9 @@ llvm::Value* tmp = rhs->getRVal(); FuncDeclaration* fdecl = gIR->func()->decl; // respecify the this param - if (!llvm::isa<llvm::AllocaInst>(gIR->irFunc[fdecl]->thisVar)) - gIR->irFunc[fdecl]->thisVar = new llvm::AllocaInst(tmp->getType(), "newthis", gIR->topallocapoint()); - DtoStore(tmp, gIR->irFunc[fdecl]->thisVar); + if (!llvm::isa<llvm::AllocaInst>(gIR->irDsymbol[fdecl].irFunc->thisVar)) + gIR->irDsymbol[fdecl].irFunc->thisVar = new llvm::AllocaInst(tmp->getType(), "newthis", gIR->topallocapoint()); + DtoStore(tmp, gIR->irDsymbol[fdecl].irFunc->thisVar); } // regular class ref -> class ref assignment else { @@ -1572,8 +1572,8 @@ void DtoConstInitGlobal(VarDeclaration* vd) { - if (vd->llvmInitialized) return; - vd->llvmInitialized = gIR->dmodule; + if (gIR->irDsymbol[vd].initialized) return; + gIR->irDsymbol[vd].initialized = gIR->dmodule; Logger::println("* DtoConstInitGlobal(%s)", vd->toChars()); LOG_SCOPE; @@ -1605,8 +1605,8 @@ llvm::GlobalVariable* gv = llvm::cast<llvm::GlobalVariable>(_init); assert(t->ty == Tstruct); TypeStruct* ts = (TypeStruct*)t; - assert(ts->sym->irStruct->constInit); - _init = ts->sym->irStruct->constInit; + assert(gIR->irDsymbol[ts->sym].irStruct->constInit); + _init = gIR->irDsymbol[ts->sym].irStruct->constInit; } // array single value init else if (isaArray(_type)) @@ -1626,11 +1626,11 @@ if (_init && _init->getType() != _type) _type = _init->getType(); - llvm::cast<llvm::OpaqueType>(vd->irGlobal->type.get())->refineAbstractTypeTo(_type); - _type = vd->irGlobal->type.get(); + llvm::cast<llvm::OpaqueType>(gIR->irDsymbol[vd].irGlobal->type.get())->refineAbstractTypeTo(_type); + _type = gIR->irDsymbol[vd].irGlobal->type.get(); assert(!_type->isAbstract()); - llvm::GlobalVariable* gvar = llvm::cast<llvm::GlobalVariable>(vd->irGlobal->value); + llvm::GlobalVariable* gvar = llvm::cast<llvm::GlobalVariable>(gIR->irDsymbol[vd].irGlobal->value); if (!(vd->storage_class & STCextern) && (vd->getModule() == gIR->dmodule || istempl)) { gvar->setInitializer(_init); @@ -1728,7 +1728,7 @@ void DtoForceDeclareDsymbol(Dsymbol* dsym) { - if (dsym->llvmDeclared) return; + if (gIR->irDsymbol[dsym].declared) return; Logger::println("DtoForceDeclareDsymbol(%s)", dsym->toPrettyChars()); LOG_SCOPE; DtoResolveDsymbol(dsym); @@ -1742,7 +1742,7 @@ void DtoForceConstInitDsymbol(Dsymbol* dsym) { - if (dsym->llvmInitialized) return; + if (gIR->irDsymbol[dsym].initialized) return; Logger::println("DtoForceConstInitDsymbol(%s)", dsym->toPrettyChars()); LOG_SCOPE; DtoResolveDsymbol(dsym); @@ -1757,7 +1757,7 @@ void DtoForceDefineDsymbol(Dsymbol* dsym) { - if (dsym->llvmDefined) return; + if (gIR->irDsymbol[dsym].defined) return; Logger::println("DtoForceDefineDsymbol(%s)", dsym->toPrettyChars()); LOG_SCOPE; DtoResolveDsymbol(dsym);
--- a/gen/toobj.cpp Tue Apr 29 21:33:50 2008 +0200 +++ b/gen/toobj.cpp Thu May 01 13:05:53 2008 +0200 @@ -67,7 +67,7 @@ // module ir state // might already exist via import, just overwrite... - irModule = new IrModule(this); + gIR->irDsymbol[this].irModule = new IrModule(this); // name the module std::string mname(toChars()); @@ -177,7 +177,7 @@ size_t n = gIR->ctors.size(); if (n == 1) - return gIR->irFunc[gIR->ctors[0]]->func; + return gIR->irDsymbol[gIR->ctors[0]].irFunc->func; std::string name("_D"); name.append(gIR->dmodule->mangle()); @@ -192,7 +192,7 @@ LLVMBuilder builder(bb); for (size_t i=0; i<n; i++) { - llvm::Function* f = gIR->irFunc[gIR->ctors[i]]->func; + llvm::Function* f = gIR->irDsymbol[gIR->ctors[i]].irFunc->func; llvm::CallInst* call = builder.CreateCall(f,""); call->setCallingConv(llvm::CallingConv::Fast); } @@ -210,7 +210,7 @@ size_t n = gIR->dtors.size(); if (n == 1) - return gIR->irFunc[gIR->dtors[0]]->func; + return gIR->irDsymbol[gIR->dtors[0]].irFunc->func; std::string name("_D"); name.append(gIR->dmodule->mangle()); @@ -225,7 +225,7 @@ LLVMBuilder builder(bb); for (size_t i=0; i<n; i++) { - llvm::Function* f = gIR->irFunc[gIR->dtors[i]]->func; + llvm::Function* f = gIR->irDsymbol[gIR->dtors[i]].irFunc->func; llvm::CallInst* call = builder.CreateCall(f,""); call->setCallingConv(llvm::CallingConv::Fast); } @@ -243,7 +243,7 @@ size_t n = gIR->unitTests.size(); if (n == 1) - return gIR->irFunc[gIR->unitTests[0]]->func; + return gIR->irDsymbol[gIR->unitTests[0]].irFunc->func; std::string name("_D"); name.append(gIR->dmodule->mangle()); @@ -258,7 +258,7 @@ LLVMBuilder builder(bb); for (size_t i=0; i<n; i++) { - llvm::Function* f = gIR->irFunc[gIR->unitTests[i]]->func; + llvm::Function* f = gIR->irDsymbol[gIR->unitTests[i]].irFunc->func; llvm::CallInst* call = builder.CreateCall(f,""); call->setCallingConv(llvm::CallingConv::Fast); } @@ -299,7 +299,7 @@ llvm::Constant* c = 0; // vtable - c = moduleinfo->irStruct->vtbl; + c = gIR->irDsymbol[moduleinfo].irStruct->vtbl; initVec.push_back(c); // monitor @@ -341,7 +341,7 @@ c = DtoConstSlice(DtoConstSize_t(importInits.size()), c); } else - c = moduleinfo->irStruct->constInit->getOperand(3); + c = gIR->irDsymbol[moduleinfo].irStruct->constInit->getOperand(3); initVec.push_back(c); // localClasses[] @@ -366,8 +366,8 @@ continue; } Logger::println("class: %s", cd->toPrettyChars()); - assert(cd->irStruct->classInfo); - classInits.push_back(cd->irStruct->classInfo); + assert(gIR->irDsymbol[cd].irStruct->classInfo); + classInits.push_back(gIR->irDsymbol[cd].irStruct->classInfo); } // has class array? if (!classInits.empty()) @@ -382,7 +382,7 @@ c = DtoConstSlice(DtoConstSize_t(classInits.size()), c); } else - c = moduleinfo->irStruct->constInit->getOperand(4); + c = gIR->irDsymbol[moduleinfo].irStruct->constInit->getOperand(4); initVec.push_back(c); // flags @@ -393,25 +393,25 @@ // ctor llvm::Function* fctor = build_module_ctor(); - c = fctor ? fctor : moduleinfo->irStruct->constInit->getOperand(6); + c = fctor ? fctor : gIR->irDsymbol[moduleinfo].irStruct->constInit->getOperand(6); initVec.push_back(c); // dtor llvm::Function* fdtor = build_module_dtor(); - c = fdtor ? fdtor : moduleinfo->irStruct->constInit->getOperand(7); + c = fdtor ? fdtor : gIR->irDsymbol[moduleinfo].irStruct->constInit->getOperand(7); initVec.push_back(c); // unitTest llvm::Function* unittest = build_module_unittest(); - c = unittest ? unittest : moduleinfo->irStruct->constInit->getOperand(8); + c = unittest ? unittest : gIR->irDsymbol[moduleinfo].irStruct->constInit->getOperand(8); initVec.push_back(c); // xgetMembers - c = moduleinfo->irStruct->constInit->getOperand(9); + c = gIR->irDsymbol[moduleinfo].irStruct->constInit->getOperand(9); initVec.push_back(c); // ictor - c = moduleinfo->irStruct->constInit->getOperand(10); + c = gIR->irDsymbol[moduleinfo].irStruct->constInit->getOperand(10); initVec.push_back(c); /*Logger::println("MODULE INFO INITIALIZERS"); @@ -511,11 +511,11 @@ return; // don't duplicate work - if (llvmResolved) return; - llvmResolved = true; - llvmDeclared = true; + if (gIR->irDsymbol[this].resolved) return; + gIR->irDsymbol[this].resolved = true; + gIR->irDsymbol[this].declared = true; - irGlobal = new IrGlobal(this); + gIR->irDsymbol[this].irGlobal = new IrGlobal(this); Logger::println("parent: %s (%s)", parent->toChars(), parent->kind()); @@ -532,12 +532,12 @@ Logger::println("Creating global variable"); - const llvm::Type* _type = irGlobal->type.get(); + const llvm::Type* _type = gIR->irDsymbol[this].irGlobal->type.get(); llvm::GlobalValue::LinkageTypes _linkage = DtoLinkage(this); std::string _name(mangle()); llvm::GlobalVariable* gvar = new llvm::GlobalVariable(_type,_isconst,_linkage,NULL,_name,gIR->module); - irGlobal->value = gvar; + gIR->irDsymbol[this].irGlobal->value = gvar; if (static_local) DtoConstInitGlobal(this); @@ -551,7 +551,7 @@ Logger::println("Aggregate var declaration: '%s' offset=%d", toChars(), offset); const llvm::Type* _type = DtoType(type); - irField = new IrField(this); + gIR->irDsymbol[this].irField = new IrField(this); // add the field in the IRStruct gIR->topstruct()->offsets.insert(std::make_pair(offset, IrStruct::Offset(this, _type)));
--- a/gen/typinf.cpp Tue Apr 29 21:33:50 2008 +0200 +++ b/gen/typinf.cpp Thu May 01 13:05:53 2008 +0200 @@ -250,21 +250,21 @@ void DtoResolveTypeInfo(TypeInfoDeclaration* tid) { - if (tid->llvmResolved) return; - tid->llvmResolved = true; + if (gIR->irDsymbol[tid].resolved) return; + gIR->irDsymbol[tid].resolved = true; Logger::println("DtoResolveTypeInfo(%s)", tid->toChars()); LOG_SCOPE; - tid->irGlobal = new IrGlobal(tid); + gIR->irDsymbol[tid].irGlobal = new IrGlobal(tid); gIR->declareList.push_back(tid); } void DtoDeclareTypeInfo(TypeInfoDeclaration* tid) { - if (tid->llvmDeclared) return; - tid->llvmDeclared = true; + if (gIR->irDsymbol[tid].declared) return; + gIR->irDsymbol[tid].declared = true; Logger::println("DtoDeclareTypeInfo(%s)", tid->toChars()); LOG_SCOPE; @@ -282,19 +282,19 @@ const llvm::Type* t = llvm::OpaqueType::get(); llvm::GlobalVariable* g = new llvm::GlobalVariable(t, true, llvm::GlobalValue::ExternalLinkage, NULL, mangled, gIR->module); assert(g); - /*if (!tid->irGlobal) - tid->irGlobal = new IrGlobal(tid);*/ - tid->irGlobal->value = g; + /*if (!gIR->irDsymbol[tid].irGlobal) + gIR->irDsymbol[tid].irGlobal = new IrGlobal(tid);*/ + gIR->irDsymbol[tid].irGlobal->value = g; mangled.append("__TYPE"); - gIR->module->addTypeName(mangled, tid->irGlobal->value->getType()->getContainedType(0)); - Logger::println("Got typeinfo var: %s", tid->irGlobal->value->getName().c_str()); - tid->llvmInitialized = true; - tid->llvmDefined = true; + gIR->module->addTypeName(mangled, gIR->irDsymbol[tid].irGlobal->value->getType()->getContainedType(0)); + Logger::println("Got typeinfo var: %s", gIR->irDsymbol[tid].irGlobal->value->getName().c_str()); + gIR->irDsymbol[tid].initialized = true; + gIR->irDsymbol[tid].defined = true; } - else if (!tid->irGlobal->value) { - tid->irGlobal->value = found; - tid->llvmInitialized = true; - tid->llvmDefined = true; + else if (!gIR->irDsymbol[tid].irGlobal->value) { + gIR->irDsymbol[tid].irGlobal->value = found; + gIR->irDsymbol[tid].initialized = true; + gIR->irDsymbol[tid].defined = true; } } // custom typedef @@ -306,8 +306,8 @@ void DtoConstInitTypeInfo(TypeInfoDeclaration* tid) { - if (tid->llvmInitialized) return; - tid->llvmInitialized = true; + if (gIR->irDsymbol[tid].initialized) return; + gIR->irDsymbol[tid].initialized = true; Logger::println("DtoConstInitTypeInfo(%s)", tid->toChars()); LOG_SCOPE; @@ -317,8 +317,8 @@ void DtoDefineTypeInfo(TypeInfoDeclaration* tid) { - if (tid->llvmDefined) return; - tid->llvmDefined = true; + if (gIR->irDsymbol[tid].defined) return; + gIR->irDsymbol[tid].defined = true; Logger::println("DtoDefineTypeInfo(%s)", tid->toChars()); LOG_SCOPE; @@ -356,7 +356,7 @@ const llvm::StructType* stype = isaStruct(base->type->llvmType->get()); // create the symbol - irGlobal->value = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module); + gIR->irDsymbol[this].irGlobal->value = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module); } void TypeInfoTypedefDeclaration::llvmDefine() @@ -372,7 +372,7 @@ // vtbl std::vector<llvm::Constant*> sinits; - sinits.push_back(base->irStruct->vtbl); + sinits.push_back(gIR->irDsymbol[base].irStruct->vtbl); // monitor sinits.push_back(getNullPtr(getPtrToType(llvm::Type::Int8Ty))); @@ -391,9 +391,9 @@ assert(sd->basetype->vtinfo); DtoForceDeclareDsymbol(sd->basetype->vtinfo); - assert(sd->basetype->vtinfo->irGlobal->value); - assert(llvm::isa<llvm::Constant>(sd->basetype->vtinfo->irGlobal->value)); - llvm::Constant* castbase = llvm::cast<llvm::Constant>(sd->basetype->vtinfo->irGlobal->value); + assert(gIR->irDsymbol[sd->basetype->vtinfo].irGlobal->value); + assert(llvm::isa<llvm::Constant>(gIR->irDsymbol[sd->basetype->vtinfo].irGlobal->value)); + llvm::Constant* castbase = llvm::cast<llvm::Constant>(gIR->irDsymbol[sd->basetype->vtinfo].irGlobal->value); castbase = llvm::ConstantExpr::getBitCast(castbase, stype->getElementType(2)); sinits.push_back(castbase); @@ -421,7 +421,7 @@ // create the symbol llvm::Constant* tiInit = llvm::ConstantStruct::get(stype, sinits); - isaGlobalVar(irGlobal->value)->setInitializer(tiInit); + isaGlobalVar(gIR->irDsymbol[this].irGlobal->value)->setInitializer(tiInit); } void TypeInfoTypedefDeclaration::toDt(dt_t **pdt) @@ -442,7 +442,7 @@ const llvm::StructType* stype = isaStruct(base->type->llvmType->get()); // create the symbol - irGlobal->value = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module); + gIR->irDsymbol[this].irGlobal->value = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module); } void TypeInfoEnumDeclaration::llvmDefine() @@ -457,7 +457,7 @@ // vtbl std::vector<llvm::Constant*> sinits; - sinits.push_back(base->irStruct->vtbl); + sinits.push_back(gIR->irDsymbol[base].irStruct->vtbl); // monitor sinits.push_back(llvm::ConstantPointerNull::get(getPtrToType(llvm::Type::Int8Ty))); @@ -476,8 +476,8 @@ assert(sd->memtype->vtinfo); DtoForceDeclareDsymbol(sd->memtype->vtinfo); - assert(llvm::isa<llvm::Constant>(sd->memtype->vtinfo->irGlobal->value)); - llvm::Constant* castbase = llvm::cast<llvm::Constant>(sd->memtype->vtinfo->irGlobal->value); + assert(llvm::isa<llvm::Constant>(gIR->irDsymbol[sd->memtype->vtinfo].irGlobal->value)); + llvm::Constant* castbase = llvm::cast<llvm::Constant>(gIR->irDsymbol[sd->memtype->vtinfo].irGlobal->value); castbase = llvm::ConstantExpr::getBitCast(castbase, stype->getElementType(2)); sinits.push_back(castbase); @@ -506,7 +506,7 @@ // create the symbol llvm::Constant* tiInit = llvm::ConstantStruct::get(stype, sinits); - isaGlobalVar(irGlobal->value)->setInitializer(tiInit); + isaGlobalVar(gIR->irDsymbol[this].irGlobal->value)->setInitializer(tiInit); } void TypeInfoEnumDeclaration::toDt(dt_t **pdt) @@ -524,7 +524,7 @@ const llvm::StructType* stype = isaStruct(base->type->llvmType->get()); // create the symbol - tid->irGlobal->value = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,tid->toChars(),gIR->module); + gIR->irDsymbol[tid].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) @@ -536,7 +536,7 @@ // vtbl std::vector<llvm::Constant*> sinits; - sinits.push_back(base->irStruct->vtbl); + sinits.push_back(gIR->irDsymbol[base].irStruct->vtbl); // monitor sinits.push_back(llvm::ConstantPointerNull::get(getPtrToType(llvm::Type::Int8Ty))); @@ -546,14 +546,14 @@ basetype->getTypeInfo(NULL); assert(basetype->vtinfo); DtoForceDeclareDsymbol(basetype->vtinfo); - assert(llvm::isa<llvm::Constant>(basetype->vtinfo->irGlobal->value)); - llvm::Constant* castbase = llvm::cast<llvm::Constant>(basetype->vtinfo->irGlobal->value); + assert(llvm::isa<llvm::Constant>(gIR->irDsymbol[basetype->vtinfo].irGlobal->value)); + llvm::Constant* castbase = llvm::cast<llvm::Constant>(gIR->irDsymbol[basetype->vtinfo].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); - isaGlobalVar(tid->irGlobal->value)->setInitializer(tiInit); + isaGlobalVar(gIR->irDsymbol[tid].irGlobal->value)->setInitializer(tiInit); } /* ========================================================================= */ @@ -629,7 +629,7 @@ const llvm::StructType* stype = isaStruct(base->type->llvmType->get()); // create the symbol - irGlobal->value = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module); + gIR->irDsymbol[this].irGlobal->value = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module); } void TypeInfoStaticArrayDeclaration::llvmDefine() @@ -647,7 +647,7 @@ // initializer vector std::vector<llvm::Constant*> sinits; // first is always the vtable - sinits.push_back(base->irStruct->vtbl); + sinits.push_back(gIR->irDsymbol[base].irStruct->vtbl); // monitor sinits.push_back(llvm::ConstantPointerNull::get(getPtrToType(llvm::Type::Int8Ty))); @@ -660,7 +660,7 @@ // get symbol assert(tc->next->vtinfo); DtoForceDeclareDsymbol(tc->next->vtinfo); - llvm::Constant* castbase = isaConstant(tc->next->vtinfo->irGlobal->value); + llvm::Constant* castbase = isaConstant(gIR->irDsymbol[tc->next->vtinfo].irGlobal->value); castbase = llvm::ConstantExpr::getBitCast(castbase, stype->getElementType(2)); sinits.push_back(castbase); @@ -669,7 +669,7 @@ // create the symbol llvm::Constant* tiInit = llvm::ConstantStruct::get(stype, sinits); - isaGlobalVar(irGlobal->value)->setInitializer(tiInit); + isaGlobalVar(gIR->irDsymbol[this].irGlobal->value)->setInitializer(tiInit); } void TypeInfoStaticArrayDeclaration::toDt(dt_t **pdt) @@ -692,7 +692,7 @@ const llvm::StructType* stype = isaStruct(base->type->llvmType->get()); // create the symbol - irGlobal->value = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module); + gIR->irDsymbol[this].irGlobal->value = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module); } void TypeInfoAssociativeArrayDeclaration::llvmDefine() @@ -710,7 +710,7 @@ // initializer vector std::vector<llvm::Constant*> sinits; // first is always the vtable - sinits.push_back(base->irStruct->vtbl); + sinits.push_back(gIR->irDsymbol[base].irStruct->vtbl); // monitor sinits.push_back(llvm::ConstantPointerNull::get(getPtrToType(llvm::Type::Int8Ty))); @@ -725,7 +725,7 @@ // get symbol assert(tc->next->vtinfo); DtoForceDeclareDsymbol(tc->next->vtinfo); - llvm::Constant* castbase = isaConstant(tc->next->vtinfo->irGlobal->value); + llvm::Constant* castbase = isaConstant(gIR->irDsymbol[tc->next->vtinfo].irGlobal->value); castbase = llvm::ConstantExpr::getBitCast(castbase, stype->getElementType(2)); sinits.push_back(castbase); @@ -735,13 +735,13 @@ // get symbol assert(tc->index->vtinfo); DtoForceDeclareDsymbol(tc->index->vtinfo); - castbase = isaConstant(tc->index->vtinfo->irGlobal->value); + castbase = isaConstant(gIR->irDsymbol[tc->index->vtinfo].irGlobal->value); castbase = llvm::ConstantExpr::getBitCast(castbase, stype->getElementType(3)); sinits.push_back(castbase); // create the symbol llvm::Constant* tiInit = llvm::ConstantStruct::get(stype, sinits); - isaGlobalVar(irGlobal->value)->setInitializer(tiInit); + isaGlobalVar(gIR->irDsymbol[this].irGlobal->value)->setInitializer(tiInit); } void TypeInfoAssociativeArrayDeclaration::toDt(dt_t **pdt) @@ -825,7 +825,7 @@ const llvm::StructType* stype = isaStruct(((TypeClass*)base->type)->llvmType->get()); // create the symbol - irGlobal->value = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module); + gIR->irDsymbol[this].irGlobal->value = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module); } void TypeInfoStructDeclaration::llvmDefine() @@ -845,7 +845,7 @@ // vtbl std::vector<llvm::Constant*> sinits; - sinits.push_back(base->irStruct->vtbl); + sinits.push_back(gIR->irDsymbol[base].irStruct->vtbl); // monitor sinits.push_back(llvm::ConstantPointerNull::get(getPtrToType(llvm::Type::Int8Ty))); @@ -865,7 +865,7 @@ else { size_t cisize = getTypeStoreSize(tc->llvmType->get()); - llvm::Constant* cicast = llvm::ConstantExpr::getBitCast(sd->irStruct->init, initpt); + llvm::Constant* cicast = llvm::ConstantExpr::getBitCast(gIR->irDsymbol[sd].irStruct->init, initpt); sinits.push_back(DtoConstSlice(DtoConstSize_t(cisize), cicast)); } @@ -925,8 +925,8 @@ fd = fdx->overloadExactMatch(tftohash); if (fd) { DtoForceDeclareDsymbol(fd); - assert(gIR->irFunc[fd]->func != 0); - llvm::Constant* c = isaConstant(gIR->irFunc[fd]->func); + assert(gIR->irDsymbol[fd].irFunc->func != 0); + llvm::Constant* c = isaConstant(gIR->irDsymbol[fd].irFunc->func); assert(c); c = llvm::ConstantExpr::getBitCast(c, ptty); sinits.push_back(c); @@ -951,8 +951,8 @@ fd = fdx->overloadExactMatch(tfeqptr); if (fd) { DtoForceDeclareDsymbol(fd); - assert(gIR->irFunc[fd]->func != 0); - llvm::Constant* c = isaConstant(gIR->irFunc[fd]->func); + assert(gIR->irDsymbol[fd].irFunc->func != 0); + llvm::Constant* c = isaConstant(gIR->irDsymbol[fd].irFunc->func); assert(c); c = llvm::ConstantExpr::getBitCast(c, ptty); sinits.push_back(c); @@ -979,8 +979,8 @@ fd = fdx->overloadExactMatch(tftostring); if (fd) { DtoForceDeclareDsymbol(fd); - assert(gIR->irFunc[fd]->func != 0); - llvm::Constant* c = isaConstant(gIR->irFunc[fd]->func); + assert(gIR->irDsymbol[fd].irFunc->func != 0); + llvm::Constant* c = isaConstant(gIR->irDsymbol[fd].irFunc->func); assert(c); c = llvm::ConstantExpr::getBitCast(c, ptty); sinits.push_back(c); @@ -1001,7 +1001,7 @@ llvm::Constant* tiInit = llvm::ConstantStruct::get(stype, sinits); llvm::GlobalVariable* gvar = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,tiInit,toChars(),gIR->module); - isaGlobalVar(irGlobal->value)->setInitializer(tiInit); + isaGlobalVar(gIR->irDsymbol[this].irGlobal->value)->setInitializer(tiInit); } void TypeInfoStructDeclaration::toDt(dt_t **pdt) @@ -1025,7 +1025,7 @@ const llvm::StructType* stype = isaStruct(base->type->llvmType->get()); // create the symbol - irGlobal->value = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module); + gIR->irDsymbol[this].irGlobal->value = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module); } void TypeInfoClassDeclaration::llvmDefine() @@ -1044,7 +1044,7 @@ // initializer vector std::vector<llvm::Constant*> sinits; // first is always the vtable - sinits.push_back(base->irStruct->vtbl); + sinits.push_back(gIR->irDsymbol[base].irStruct->vtbl); // monitor sinits.push_back(llvm::ConstantPointerNull::get(getPtrToType(llvm::Type::Int8Ty))); @@ -1052,12 +1052,12 @@ // get classinfo assert(tinfo->ty == Tclass); TypeClass *tc = (TypeClass *)tinfo; - assert(tc->sym->irStruct->classInfo); - sinits.push_back(tc->sym->irStruct->classInfo); + assert(gIR->irDsymbol[tc->sym].irStruct->classInfo); + sinits.push_back(gIR->irDsymbol[tc->sym].irStruct->classInfo); // create the symbol llvm::Constant* tiInit = llvm::ConstantStruct::get(stype, sinits); - isaGlobalVar(irGlobal->value)->setInitializer(tiInit); + isaGlobalVar(gIR->irDsymbol[this].irGlobal->value)->setInitializer(tiInit); } void TypeInfoClassDeclaration::toDt(dt_t **pdt) @@ -1081,7 +1081,7 @@ const llvm::StructType* stype = isaStruct(base->type->llvmType->get()); // create the symbol - irGlobal->value = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module); + gIR->irDsymbol[this].irGlobal->value = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module); } void TypeInfoInterfaceDeclaration::llvmDefine() @@ -1100,7 +1100,7 @@ // initializer vector std::vector<llvm::Constant*> sinits; // first is always the vtable - sinits.push_back(base->irStruct->vtbl); + sinits.push_back(gIR->irDsymbol[base].irStruct->vtbl); // monitor sinits.push_back(llvm::ConstantPointerNull::get(getPtrToType(llvm::Type::Int8Ty))); @@ -1108,12 +1108,12 @@ // get classinfo assert(tinfo->ty == Tclass); TypeClass *tc = (TypeClass *)tinfo; - assert(tc->sym->irStruct->classInfo); - sinits.push_back(tc->sym->irStruct->classInfo); + assert(gIR->irDsymbol[tc->sym].irStruct->classInfo); + sinits.push_back(gIR->irDsymbol[tc->sym].irStruct->classInfo); // create the symbol llvm::Constant* tiInit = llvm::ConstantStruct::get(stype, sinits); - isaGlobalVar(irGlobal->value)->setInitializer(tiInit); + isaGlobalVar(gIR->irDsymbol[this].irGlobal->value)->setInitializer(tiInit); } void TypeInfoInterfaceDeclaration::toDt(dt_t **pdt) @@ -1137,7 +1137,7 @@ const llvm::StructType* stype = isaStruct(base->type->llvmType->get()); // create the symbol - irGlobal->value = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module); + gIR->irDsymbol[this].irGlobal->value = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module); } void TypeInfoTupleDeclaration::llvmDefine() @@ -1156,7 +1156,7 @@ // initializer vector std::vector<llvm::Constant*> sinits; // first is always the vtable - sinits.push_back(base->irStruct->vtbl); + sinits.push_back(gIR->irDsymbol[base].irStruct->vtbl); // monitor sinits.push_back(llvm::ConstantPointerNull::get(getPtrToType(llvm::Type::Int8Ty))); @@ -1176,8 +1176,8 @@ Argument *arg = (Argument *)tu->arguments->data[i]; arg->type->getTypeInfo(NULL); DtoForceDeclareDsymbol(arg->type->vtinfo); - assert(arg->type->vtinfo->irGlobal->value); - llvm::Constant* c = isaConstant(arg->type->vtinfo->irGlobal->value); + assert(gIR->irDsymbol[arg->type->vtinfo].irGlobal->value); + llvm::Constant* c = isaConstant(gIR->irDsymbol[arg->type->vtinfo].irGlobal->value); c = llvm::ConstantExpr::getBitCast(c, tiTy); arrInits.push_back(c); } @@ -1192,7 +1192,7 @@ // create the symbol llvm::Constant* tiInit = llvm::ConstantStruct::get(stype, sinits); - isaGlobalVar(irGlobal->value)->setInitializer(tiInit); + isaGlobalVar(gIR->irDsymbol[this].irGlobal->value)->setInitializer(tiInit); } void TypeInfoTupleDeclaration::toDt(dt_t **pdt)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ir/irsymbol.h Thu May 01 13:05:53 2008 +0200 @@ -0,0 +1,40 @@ +#ifndef LLVMDC_IR_IRSYMBOL_H +#define LLVMDC_IR_IRSYMBOL_H + +#include "ir/ir.h" + +struct IrModule; +struct IrFunction; +struct IrStruct; +struct IrGlobal; +struct IrLocal; +struct IrField; +struct IrVar; + +struct IrDsymbol +{ + Module* DModule; + + bool resolved; + bool declared; + bool initialized; + bool defined; + + IrModule* irModule; + + IrStruct* irStruct; + + IrFunction* irFunc; + + IrGlobal* irGlobal; + IrLocal* irLocal; + IrField* irField; + IrVar* getIrVar() + { + assert(irGlobal || irLocal || irField); + return irGlobal ? (IrVar*)irGlobal : irLocal ? (IrVar*)irLocal : (IrVar*)irField; + } + llvm::Value*& getIrValue() { return getIrVar()->value; } +}; + +#endif
--- a/ir/irvar.cpp Tue Apr 29 21:33:50 2008 +0200 +++ b/ir/irvar.cpp Thu May 01 13:05:53 2008 +0200 @@ -7,21 +7,6 @@ ////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////// -IrVar* VarDeclaration::getIrVar() -{ - assert(irGlobal || irLocal || irField); - return irGlobal ? (IrVar*)irGlobal : irLocal ? (IrVar*)irLocal : (IrVar*)irField; -} - -llvm::Value*& VarDeclaration::getIrValue() -{ - return getIrVar()->value; -} - -////////////////////////////////////////////////////////////////////////////// -////////////////////////////////////////////////////////////////////////////// -////////////////////////////////////////////////////////////////////////////// - IrVar::IrVar(VarDeclaration* var) { V = var;