[svn r172] moving all IR state previously stored in Dsymbol into IrDsymbol and a Dsymbol->IrDsymbol map

This commit is contained in:
Christian Kamm
2008-05-01 13:05:53 +02:00
parent 48f1a9c507
commit 24726394f6
22 changed files with 465 additions and 487 deletions

View File

@@ -45,7 +45,6 @@ namespace llvm
class ConstantStruct;
class GlobalVariable;
}
struct IrStruct;
struct DUnion;
struct AggregateDeclaration : ScopeDsymbol
@@ -102,9 +101,6 @@ struct AggregateDeclaration : ScopeDsymbol
Symbol *toInitializer();
AggregateDeclaration *isAggregateDeclaration() { return this; }
// llvmdc
IrStruct* irStruct;
};
struct AnonymousAggregateDeclaration : AggregateDeclaration

View File

@@ -549,9 +549,8 @@ VarDeclaration::VarDeclaration(Loc loc, Type *type, Identifier *id, Initializer
onstack = 0;
canassign = 0;
value = NULL;
irGlobal = NULL;
irLocal = NULL;
irField = NULL;
// LLVMDC
needsStorage = false;
}

View File

@@ -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 @@ struct VarDeclaration : Declaration
VarDeclaration *isVarDeclaration() { return (VarDeclaration *)this; }
// LLVMDC
IrGlobal* irGlobal;
IrLocal* irLocal;
IrField* irField;
bool needsStorage;
IrVar* getIrVar();
llvm::Value*& getIrValue();
};
/**************************************************************/

View File

@@ -47,14 +47,6 @@ Dsymbol::Dsymbol()
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 @@ Dsymbol::Dsymbol(Identifier *ident)
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)

View File

@@ -219,14 +219,6 @@ struct Dsymbol : Object
int llvmInternal;
char* llvmInternal1;
char* llvmInternal2;
//llvm::Value* llvmValue;
Module* llvmDModule;
bool llvmResolved;
bool llvmDeclared;
bool llvmInitialized;
bool llvmDefined;
};
// Dsymbol that generates a scope

View File

@@ -160,9 +160,6 @@ Module::Module(char *filename, Identifier *ident, int doDocComment, int doHdrGen
bcfile = new File(bcfilename);
llfile = new File(llfilename);
symfile = new File(symfilename);
// LLVMDC
irModule = NULL;
}
void Module::setDocfile()

View File

@@ -29,7 +29,6 @@ struct VarDeclaration;
#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 @@ struct Module : Package
void genmoduleinfo();
// LLVMDC
IrModule* irModule;
Module *isModule() { return this; }
};

View File

@@ -44,8 +44,6 @@ AggregateDeclaration::AggregateDeclaration(Loc loc, Identifier *id)
stag = NULL;
sinit = NULL;
scope = NULL;
irStruct = NULL;
}
enum PROT AggregateDeclaration::prot()

View File

@@ -58,8 +58,8 @@ static llvm::Value* to_keyti(DValue* key)
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;
}
/////////////////////////////////////////////////////////////////////////////////////

View File

@@ -673,10 +673,10 @@ static llvm::Value* DtoArrayEqCmp_impl(const char* func, DValue* l, DValue* r, b
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");

View File

@@ -35,15 +35,15 @@ static void LLVM_AddBaseClassInterfaces(ClassDeclaration* target, BaseClasses* b
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 @@ static void LLVM_AddBaseClassData(BaseClasses* bcs)
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 @@ void DtoResolveClass(ClassDeclaration* cd)
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 @@ void DtoResolveClass(ClassDeclaration* cd)
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 @@ void DtoResolveClass(ClassDeclaration* cd)
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 @@ void DtoResolveClass(ClassDeclaration* cd)
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 @@ void DtoResolveClass(ClassDeclaration* cd)
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 @@ void DtoResolveClass(ClassDeclaration* cd)
// 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 DtoResolveClass(ClassDeclaration* cd)
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 @@ void DtoDeclareClass(ClassDeclaration* cd)
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 @@ void DtoDeclareClass(ClassDeclaration* cd)
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 @@ void DtoDeclareClass(ClassDeclaration* cd)
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 DtoDeclareClass(ClassDeclaration* cd)
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 @@ void DtoConstInitClass(ClassDeclaration* cd)
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 @@ void DtoConstInitClass(ClassDeclaration* cd)
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 @@ void DtoConstInitClass(ClassDeclaration* cd)
}
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 @@ void DtoConstInitClass(ClassDeclaration* cd)
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 @@ void DtoConstInitClass(ClassDeclaration* cd)
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 @@ void DtoConstInitClass(ClassDeclaration* cd)
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 @@ void DtoConstInitClass(ClassDeclaration* cd)
#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 @@ void DtoConstInitClass(ClassDeclaration* cd)
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 @@ void DtoConstInitClass(ClassDeclaration* cd)
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 @@ void DtoConstInitClass(ClassDeclaration* cd)
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 DtoConstInitClass(ClassDeclaration* cd)
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 @@ void DtoDefineClass(ClassDeclaration* cd)
// 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 @@ DValue* DtoNewClass(TypeClass* tc, NewExp* newexp)
{
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 @@ DValue* DtoNewClass(TypeClass* tc, NewExp* newexp)
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 @@ DValue* DtoNewClass(TypeClass* tc, NewExp* newexp)
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 @@ void DtoInitClass(TypeClass* tc, llvm::Value* dst)
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 @@ void DtoInitClass(TypeClass* tc, llvm::Value* dst)
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 @@ DValue* DtoCallClassCtor(TypeClass* type, CtorDeclaration* ctor, Array* argument
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 @@ void DtoCallClassDtors(TypeClass* tc, llvm::Value* instance)
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 @@ DValue* DtoDynamicCastObject(DValue* val, Type* _to)
// 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 @@ DValue* DtoDynamicCastInterface(DValue* val, Type* _to)
// 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 @@ llvm::Value* DtoIndexClass(llvm::Value* ptr, ClassDeclaration* cd, Type* t, unsi
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 @@ llvm::Value* DtoIndexClass(llvm::Value* ptr, ClassDeclaration* cd, Type* t, unsi
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 @@ llvm::Value* DtoVirtualFunctionPointer(DValue* inst, FuncDeclaration* fdecl)
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 @@ void DtoDeclareClassInfo(ClassDeclaration* cd)
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 @@ static llvm::Constant* build_offti_entry(VarDeclaration* vd)
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 @@ static llvm::Constant* build_class_dtor(ClassDeclaration* cd)
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 @@ static llvm::Constant* build_class_dtor(ClassDeclaration* cd)
{
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 DtoDefineClassInfo(ClassDeclaration* cd)
// 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 @@ void DtoDefineClassInfo(ClassDeclaration* cd)
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 @@ void DtoDefineClassInfo(ClassDeclaration* cd)
// 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 @@ void DtoDefineClassInfo(ClassDeclaration* cd)
// 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 @@ void DtoDefineClassInfo(ClassDeclaration* cd)
// 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 @@ void DtoDefineClassInfo(ClassDeclaration* cd)
// 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 @@ void DtoDefineClassInfo(ClassDeclaration* cd)
}*/
// 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);
}

View File

@@ -74,10 +74,10 @@ const llvm::FunctionType* DtoFunctionType(Type* type, const llvm::Type* thistype
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 @@ static llvm::Function* DtoDeclareVaFunction(FuncDeclaration* fdecl)
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 @@ void DtoResolveFunction(FuncDeclaration* fdecl)
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 @@ void DtoResolveFunction(FuncDeclaration* fdecl)
{
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 DtoResolveFunction(FuncDeclaration* fdecl)
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 @@ void DtoDeclareFunction(FuncDeclaration* fdecl)
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 @@ void DtoDeclareFunction(FuncDeclaration* fdecl)
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 @@ void DtoDeclareFunction(FuncDeclaration* fdecl)
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 @@ void DtoDeclareFunction(FuncDeclaration* fdecl)
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 @@ void DtoDeclareFunction(FuncDeclaration* fdecl)
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 @@ void DtoDeclareFunction(FuncDeclaration* fdecl)
//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 DtoDeclareFunction(FuncDeclaration* fdecl)
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 @@ void DtoDefineFunc(FuncDeclaration* fd)
// 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 @@ void DtoDefineFunc(FuncDeclaration* fd)
// 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 @@ void DtoDefineFunc(FuncDeclaration* fd)
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 @@ void DtoDefineFunc(FuncDeclaration* fd)
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 @@ void DtoDefineFunc(FuncDeclaration* fd)
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 @@ void DtoDefineFunc(FuncDeclaration* fd)
}
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 @@ void DtoDefineFunc(FuncDeclaration* fd)
// 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

View File

@@ -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 TypeStruct;
struct BaseClass;
struct TryFinallyStatement;
struct IrModule;
// represents a scope
struct IRScope
{
@@ -73,12 +76,13 @@ struct IRState
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();

View File

@@ -77,11 +77,11 @@ void ReturnStatement::toIR(IRState* p)
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 @@ void ForeachStatement::toIR(IRState* p)
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 @@ void ForeachStatement::toIR(IRState* p)
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 @@ void ForeachStatement::toIR(IRState* p)
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 @@ void WithStatement::toIR(IRState* p)
assert(body);
DValue* e = exp->toElem(p);
wthis->irLocal->value = e->getRVal();
gIR->irDsymbol[wthis].irLocal->value = e->getRVal();
delete e;
body->toIR(p);

View File

@@ -95,11 +95,11 @@ llvm::Constant* DtoConstStructInitializer(StructInitializer* si)
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 @@ llvm::Value* DtoIndexStruct(llvm::Value* ptr, StructDeclaration* sd, Type* t, un
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 @@ llvm::Value* DtoIndexStruct(llvm::Value* ptr, StructDeclaration* sd, Type* t, un
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 @@ llvm::Value* DtoIndexStruct(llvm::Value* ptr, StructDeclaration* sd, Type* t, un
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 @@ void DtoResolveStruct(StructDeclaration* sd)
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 @@ void DtoResolveStruct(StructDeclaration* sd)
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 @@ void DtoResolveStruct(StructDeclaration* sd)
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 @@ void DtoResolveStruct(StructDeclaration* sd)
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 DtoResolveStruct(StructDeclaration* sd)
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 @@ void DtoDeclareStruct(StructDeclaration* sd)
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 DtoDeclareStruct(StructDeclaration* sd)
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 @@ void DtoConstInitStruct(StructDeclaration* sd)
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 @@ void DtoConstInitStruct(StructDeclaration* sd)
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 @@ void DtoConstInitStruct(StructDeclaration* sd)
}
// 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 @@ void DtoConstInitStruct(StructDeclaration* sd)
}
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 DtoConstInitStruct(StructDeclaration* sd)
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;
}
//////////////////////////////////////////////////////////////////////////////////////////

View File

@@ -114,12 +114,12 @@ const llvm::StructType* GetDwarfSubProgramType() {
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* DtoDwarfCompileUnit(Module* m)
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 @@ llvm::GlobalVariable* DtoDwarfSubProgram(FuncDeclaration* fd, llvm::GlobalVariab
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));
}
//////////////////////////////////////////////////////////////////////////////////////////////////

View File

@@ -61,10 +61,10 @@ DValue* DeclarationExp::toElem(IRState* p)
// 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 @@ DValue* DeclarationExp::toElem(IRState* p)
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 @@ DValue* VarExp::toElem(IRState* p)
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 @@ DValue* VarExp::toElem(IRState* p)
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 @@ DValue* VarExp::toElem(IRState* p)
{
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 @@ DValue* VarExp::toElem(IRState* p)
{
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 @@ DValue* VarExp::toElem(IRState* p)
// 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 @@ DValue* VarExp::toElem(IRState* p)
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 @@ DValue* VarExp::toElem(IRState* p)
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 @@ DValue* VarExp::toElem(IRState* p)
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 @@ llvm::Constant* VarExp::toConstElem(IRState* p)
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 @@ DValue* CallExp::toElem(IRState* p)
}
// 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 @@ DValue* CallExp::toElem(IRState* p)
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 @@ DValue* SymOffExp::toElem(IRState* p)
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 @@ DValue* AddrExp::toElem(IRState* p)
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 @@ DValue* DotVarExp::toElem(IRState* p)
// 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 @@ DValue* DotVarExp::toElem(IRState* p)
// 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 @@ DValue* ThisExp::toElem(IRState* p)
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 @@ DValue* NewExp::toElem(IRState* p)
}
else {
assert(ts->sym);
DtoStructCopy(emem,ts->sym->irStruct->init);
DtoStructCopy(emem,gIR->irDsymbol[ts->sym].irStruct->init);
}
}
@@ -2216,7 +2216,7 @@ DValue* DelegateExp::toElem(IRState* p)
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 @@ DValue* DelegateExp::toElem(IRState* p)
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 @@ DValue* FuncExp::toElem(IRState* p)
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 @@ DValue* FuncExp::toElem(IRState* p)
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 @@ DValue* StructLiteralExp::toElem(IRState* p)
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) {

View File

@@ -116,7 +116,7 @@ const llvm::Type* DtoType(Type* t)
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 @@ const llvm::Type* DtoType(Type* t)
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 @@ llvm::Constant* DtoConstFieldInitializer(Type* t, Initializer* init)
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 @@ static const llvm::Type* get_next_frame_ptr_type(Dsymbol* sc)
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 @@ static llvm::Value* get_frame_ptr_impl(FuncDeclaration* func, Dsymbol* sc, llvm:
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 @@ static llvm::Value* get_frame_ptr_impl(FuncDeclaration* func, Dsymbol* sc, llvm:
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 @@ static llvm::Value* get_frame_ptr(FuncDeclaration* func)
// 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 @@ llvm::Value* DtoNestedVariable(VarDeclaration* vd)
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 @@ void DtoAssign(DValue* lhs, DValue* rhs)
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 DtoDefineDsymbol(Dsymbol* dsym)
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 @@ void DtoConstInitGlobal(VarDeclaration* vd)
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 @@ void DtoConstInitGlobal(VarDeclaration* vd)
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 DtoEmptyAllLists()
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 DtoForceDeclareDsymbol(Dsymbol* dsym)
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 DtoForceConstInitDsymbol(Dsymbol* dsym)
void DtoForceDefineDsymbol(Dsymbol* dsym)
{
if (dsym->llvmDefined) return;
if (gIR->irDsymbol[dsym].defined) return;
Logger::println("DtoForceDefineDsymbol(%s)", dsym->toPrettyChars());
LOG_SCOPE;
DtoResolveDsymbol(dsym);

View File

@@ -67,7 +67,7 @@ void Module::genobjfile()
// 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 @@ static llvm::Function* build_module_ctor()
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 @@ static llvm::Function* build_module_ctor()
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 @@ static llvm::Function* build_module_dtor()
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 @@ static llvm::Function* build_module_dtor()
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 @@ static llvm::Function* build_module_unittest()
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 @@ static llvm::Function* build_module_unittest()
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 @@ void Module::genmoduleinfo()
llvm::Constant* c = 0;
// vtable
c = moduleinfo->irStruct->vtbl;
c = gIR->irDsymbol[moduleinfo].irStruct->vtbl;
initVec.push_back(c);
// monitor
@@ -341,7 +341,7 @@ void Module::genmoduleinfo()
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 @@ void Module::genmoduleinfo()
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 @@ void Module::genmoduleinfo()
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 @@ void Module::genmoduleinfo()
// 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 @@ void VarDeclaration::toObjFile()
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 @@ void VarDeclaration::toObjFile()
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 @@ void VarDeclaration::toObjFile()
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)));

View File

@@ -250,21 +250,21 @@ void TypeInfoDeclaration::toObjFile()
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 @@ void DtoDeclareTypeInfo(TypeInfoDeclaration* tid)
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 DtoDeclareTypeInfo(TypeInfoDeclaration* tid)
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 DtoConstInitTypeInfo(TypeInfoDeclaration* tid)
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 @@ void TypeInfoTypedefDeclaration::llvmDeclare()
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 @@ void TypeInfoTypedefDeclaration::llvmDefine()
// 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 @@ void TypeInfoTypedefDeclaration::llvmDefine()
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 @@ void TypeInfoTypedefDeclaration::llvmDefine()
// 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 @@ void TypeInfoEnumDeclaration::llvmDeclare()
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 @@ void TypeInfoEnumDeclaration::llvmDefine()
// 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 @@ void TypeInfoEnumDeclaration::llvmDefine()
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 @@ void TypeInfoEnumDeclaration::llvmDefine()
// 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 @@ static llvm::Constant* LLVM_D_Declare_TypeInfoBase(TypeInfoDeclaration* tid, Cla
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 @@ static llvm::Constant* LLVM_D_Define_TypeInfoBase(Type* basetype, TypeInfoDeclar
// 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 @@ static llvm::Constant* LLVM_D_Define_TypeInfoBase(Type* basetype, TypeInfoDeclar
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 @@ void TypeInfoStaticArrayDeclaration::llvmDeclare()
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 @@ void TypeInfoStaticArrayDeclaration::llvmDefine()
// 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 @@ void TypeInfoStaticArrayDeclaration::llvmDefine()
// 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 @@ void TypeInfoStaticArrayDeclaration::llvmDefine()
// 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 @@ void TypeInfoAssociativeArrayDeclaration::llvmDeclare()
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 @@ void TypeInfoAssociativeArrayDeclaration::llvmDefine()
// 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 @@ void TypeInfoAssociativeArrayDeclaration::llvmDefine()
// 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 @@ void TypeInfoAssociativeArrayDeclaration::llvmDefine()
// 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 @@ void TypeInfoStructDeclaration::llvmDeclare()
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 @@ void TypeInfoStructDeclaration::llvmDefine()
// 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 @@ void TypeInfoStructDeclaration::llvmDefine()
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 @@ void TypeInfoStructDeclaration::llvmDefine()
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 @@ void TypeInfoStructDeclaration::llvmDefine()
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 @@ void TypeInfoStructDeclaration::llvmDefine()
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 @@ void TypeInfoStructDeclaration::llvmDefine()
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 @@ void TypeInfoClassDeclaration::llvmDeclare()
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 @@ void TypeInfoClassDeclaration::llvmDefine()
// 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 @@ void TypeInfoClassDeclaration::llvmDefine()
// 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 @@ void TypeInfoInterfaceDeclaration::llvmDeclare()
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 @@ void TypeInfoInterfaceDeclaration::llvmDefine()
// 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 @@ void TypeInfoInterfaceDeclaration::llvmDefine()
// 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 @@ void TypeInfoTupleDeclaration::llvmDeclare()
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 @@ void TypeInfoTupleDeclaration::llvmDefine()
// 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 @@ void TypeInfoTupleDeclaration::llvmDefine()
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 @@ void TypeInfoTupleDeclaration::llvmDefine()
// 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)

40
ir/irsymbol.h Normal file
View File

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

View File

@@ -3,21 +3,6 @@
#include "ir/irvar.h"
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
IrVar* VarDeclaration::getIrVar()
{
assert(irGlobal || irLocal || irField);
return irGlobal ? (IrVar*)irGlobal : irLocal ? (IrVar*)irLocal : (IrVar*)irField;
}
llvm::Value*& VarDeclaration::getIrValue()
{
return getIrVar()->value;
}
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////