diff gen/typinf.cpp @ 156:ccd07d9f2ce9 trunk

[svn r172] moving all IR state previously stored in Dsymbol into IrDsymbol and a Dsymbol->IrDsymbol map
author ChristianK
date Thu, 01 May 2008 13:05:53 +0200
parents 7f92f477ff53
children 5c17f81fc1c1
line wrap: on
line diff
--- a/gen/typinf.cpp	Tue Apr 29 21:33:50 2008 +0200
+++ b/gen/typinf.cpp	Thu May 01 13:05:53 2008 +0200
@@ -250,21 +250,21 @@
 
 void DtoResolveTypeInfo(TypeInfoDeclaration* tid)
 {
-    if (tid->llvmResolved) return;
-    tid->llvmResolved = true;
+    if (gIR->irDsymbol[tid].resolved) return;
+    gIR->irDsymbol[tid].resolved = true;
 
     Logger::println("DtoResolveTypeInfo(%s)", tid->toChars());
     LOG_SCOPE;
 
-    tid->irGlobal = new IrGlobal(tid);
+    gIR->irDsymbol[tid].irGlobal = new IrGlobal(tid);
 
     gIR->declareList.push_back(tid);
 }
 
 void DtoDeclareTypeInfo(TypeInfoDeclaration* tid)
 {
-    if (tid->llvmDeclared) return;
-    tid->llvmDeclared = true;
+    if (gIR->irDsymbol[tid].declared) return;
+    gIR->irDsymbol[tid].declared = true;
 
     Logger::println("DtoDeclareTypeInfo(%s)", tid->toChars());
     LOG_SCOPE;
@@ -282,19 +282,19 @@
             const llvm::Type* t = llvm::OpaqueType::get();
             llvm::GlobalVariable* g = new llvm::GlobalVariable(t, true, llvm::GlobalValue::ExternalLinkage, NULL, mangled, gIR->module);
             assert(g);
-            /*if (!tid->irGlobal)
-                tid->irGlobal = new IrGlobal(tid);*/
-            tid->irGlobal->value = g;
+            /*if (!gIR->irDsymbol[tid].irGlobal)
+                gIR->irDsymbol[tid].irGlobal = new IrGlobal(tid);*/
+            gIR->irDsymbol[tid].irGlobal->value = g;
             mangled.append("__TYPE");
-            gIR->module->addTypeName(mangled, tid->irGlobal->value->getType()->getContainedType(0));
-            Logger::println("Got typeinfo var: %s", tid->irGlobal->value->getName().c_str());
-            tid->llvmInitialized = true;
-            tid->llvmDefined = true;
+            gIR->module->addTypeName(mangled, gIR->irDsymbol[tid].irGlobal->value->getType()->getContainedType(0));
+            Logger::println("Got typeinfo var: %s", gIR->irDsymbol[tid].irGlobal->value->getName().c_str());
+            gIR->irDsymbol[tid].initialized = true;
+            gIR->irDsymbol[tid].defined = true;
         }
-        else if (!tid->irGlobal->value) {
-            tid->irGlobal->value = found;
-            tid->llvmInitialized = true;
-            tid->llvmDefined = true;
+        else if (!gIR->irDsymbol[tid].irGlobal->value) {
+            gIR->irDsymbol[tid].irGlobal->value = found;
+            gIR->irDsymbol[tid].initialized = true;
+            gIR->irDsymbol[tid].defined = true;
         }
     }
     // custom typedef
@@ -306,8 +306,8 @@
 
 void DtoConstInitTypeInfo(TypeInfoDeclaration* tid)
 {
-    if (tid->llvmInitialized) return;
-    tid->llvmInitialized = true;
+    if (gIR->irDsymbol[tid].initialized) return;
+    gIR->irDsymbol[tid].initialized = true;
 
     Logger::println("DtoConstInitTypeInfo(%s)", tid->toChars());
     LOG_SCOPE;
@@ -317,8 +317,8 @@
 
 void DtoDefineTypeInfo(TypeInfoDeclaration* tid)
 {
-    if (tid->llvmDefined) return;
-    tid->llvmDefined = true;
+    if (gIR->irDsymbol[tid].defined) return;
+    gIR->irDsymbol[tid].defined = true;
 
     Logger::println("DtoDefineTypeInfo(%s)", tid->toChars());
     LOG_SCOPE;
@@ -356,7 +356,7 @@
     const llvm::StructType* stype = isaStruct(base->type->llvmType->get());
 
     // create the symbol
-    irGlobal->value = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module);
+    gIR->irDsymbol[this].irGlobal->value = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module);
 }
 
 void TypeInfoTypedefDeclaration::llvmDefine()
@@ -372,7 +372,7 @@
 
     // vtbl
     std::vector<llvm::Constant*> sinits;
-    sinits.push_back(base->irStruct->vtbl);
+    sinits.push_back(gIR->irDsymbol[base].irStruct->vtbl);
 
     // monitor
     sinits.push_back(getNullPtr(getPtrToType(llvm::Type::Int8Ty)));
@@ -391,9 +391,9 @@
     assert(sd->basetype->vtinfo);
     DtoForceDeclareDsymbol(sd->basetype->vtinfo);
 
-    assert(sd->basetype->vtinfo->irGlobal->value);
-    assert(llvm::isa<llvm::Constant>(sd->basetype->vtinfo->irGlobal->value));
-    llvm::Constant* castbase = llvm::cast<llvm::Constant>(sd->basetype->vtinfo->irGlobal->value);
+    assert(gIR->irDsymbol[sd->basetype->vtinfo].irGlobal->value);
+    assert(llvm::isa<llvm::Constant>(gIR->irDsymbol[sd->basetype->vtinfo].irGlobal->value));
+    llvm::Constant* castbase = llvm::cast<llvm::Constant>(gIR->irDsymbol[sd->basetype->vtinfo].irGlobal->value);
     castbase = llvm::ConstantExpr::getBitCast(castbase, stype->getElementType(2));
     sinits.push_back(castbase);
 
@@ -421,7 +421,7 @@
 
     // create the symbol
     llvm::Constant* tiInit = llvm::ConstantStruct::get(stype, sinits);
-    isaGlobalVar(irGlobal->value)->setInitializer(tiInit);
+    isaGlobalVar(gIR->irDsymbol[this].irGlobal->value)->setInitializer(tiInit);
 }
 
 void TypeInfoTypedefDeclaration::toDt(dt_t **pdt)
@@ -442,7 +442,7 @@
     const llvm::StructType* stype = isaStruct(base->type->llvmType->get());
 
     // create the symbol
-    irGlobal->value = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module);
+    gIR->irDsymbol[this].irGlobal->value = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module);
 }
 
 void TypeInfoEnumDeclaration::llvmDefine()
@@ -457,7 +457,7 @@
 
     // vtbl
     std::vector<llvm::Constant*> sinits;
-    sinits.push_back(base->irStruct->vtbl);
+    sinits.push_back(gIR->irDsymbol[base].irStruct->vtbl);
 
     // monitor
     sinits.push_back(llvm::ConstantPointerNull::get(getPtrToType(llvm::Type::Int8Ty)));
@@ -476,8 +476,8 @@
     assert(sd->memtype->vtinfo);
     DtoForceDeclareDsymbol(sd->memtype->vtinfo);
 
-    assert(llvm::isa<llvm::Constant>(sd->memtype->vtinfo->irGlobal->value));
-    llvm::Constant* castbase = llvm::cast<llvm::Constant>(sd->memtype->vtinfo->irGlobal->value);
+    assert(llvm::isa<llvm::Constant>(gIR->irDsymbol[sd->memtype->vtinfo].irGlobal->value));
+    llvm::Constant* castbase = llvm::cast<llvm::Constant>(gIR->irDsymbol[sd->memtype->vtinfo].irGlobal->value);
     castbase = llvm::ConstantExpr::getBitCast(castbase, stype->getElementType(2));
     sinits.push_back(castbase);
 
@@ -506,7 +506,7 @@
 
     // create the symbol
     llvm::Constant* tiInit = llvm::ConstantStruct::get(stype, sinits);
-    isaGlobalVar(irGlobal->value)->setInitializer(tiInit);
+    isaGlobalVar(gIR->irDsymbol[this].irGlobal->value)->setInitializer(tiInit);
 }
 
 void TypeInfoEnumDeclaration::toDt(dt_t **pdt)
@@ -524,7 +524,7 @@
     const llvm::StructType* stype = isaStruct(base->type->llvmType->get());
 
     // create the symbol
-    tid->irGlobal->value = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,tid->toChars(),gIR->module);
+    gIR->irDsymbol[tid].irGlobal->value = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,tid->toChars(),gIR->module);
 }
 
 static llvm::Constant* LLVM_D_Define_TypeInfoBase(Type* basetype, TypeInfoDeclaration* tid, ClassDeclaration* cd)
@@ -536,7 +536,7 @@
 
     // vtbl
     std::vector<llvm::Constant*> sinits;
-    sinits.push_back(base->irStruct->vtbl);
+    sinits.push_back(gIR->irDsymbol[base].irStruct->vtbl);
 
     // monitor
     sinits.push_back(llvm::ConstantPointerNull::get(getPtrToType(llvm::Type::Int8Ty)));
@@ -546,14 +546,14 @@
     basetype->getTypeInfo(NULL);
     assert(basetype->vtinfo);
     DtoForceDeclareDsymbol(basetype->vtinfo);
-    assert(llvm::isa<llvm::Constant>(basetype->vtinfo->irGlobal->value));
-    llvm::Constant* castbase = llvm::cast<llvm::Constant>(basetype->vtinfo->irGlobal->value);
+    assert(llvm::isa<llvm::Constant>(gIR->irDsymbol[basetype->vtinfo].irGlobal->value));
+    llvm::Constant* castbase = llvm::cast<llvm::Constant>(gIR->irDsymbol[basetype->vtinfo].irGlobal->value);
     castbase = llvm::ConstantExpr::getBitCast(castbase, stype->getElementType(2));
     sinits.push_back(castbase);
 
     // create the symbol
     llvm::Constant* tiInit = llvm::ConstantStruct::get(stype, sinits);
-    isaGlobalVar(tid->irGlobal->value)->setInitializer(tiInit);
+    isaGlobalVar(gIR->irDsymbol[tid].irGlobal->value)->setInitializer(tiInit);
 }
 
 /* ========================================================================= */
@@ -629,7 +629,7 @@
     const llvm::StructType* stype = isaStruct(base->type->llvmType->get());
 
     // create the symbol
-    irGlobal->value = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module);
+    gIR->irDsymbol[this].irGlobal->value = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module);
 }
 
 void TypeInfoStaticArrayDeclaration::llvmDefine()
@@ -647,7 +647,7 @@
     // initializer vector
     std::vector<llvm::Constant*> sinits;
     // first is always the vtable
-    sinits.push_back(base->irStruct->vtbl);
+    sinits.push_back(gIR->irDsymbol[base].irStruct->vtbl);
 
     // monitor
     sinits.push_back(llvm::ConstantPointerNull::get(getPtrToType(llvm::Type::Int8Ty)));
@@ -660,7 +660,7 @@
     // get symbol
     assert(tc->next->vtinfo);
     DtoForceDeclareDsymbol(tc->next->vtinfo);
-    llvm::Constant* castbase = isaConstant(tc->next->vtinfo->irGlobal->value);
+    llvm::Constant* castbase = isaConstant(gIR->irDsymbol[tc->next->vtinfo].irGlobal->value);
     castbase = llvm::ConstantExpr::getBitCast(castbase, stype->getElementType(2));
     sinits.push_back(castbase);
 
@@ -669,7 +669,7 @@
 
     // create the symbol
     llvm::Constant* tiInit = llvm::ConstantStruct::get(stype, sinits);
-    isaGlobalVar(irGlobal->value)->setInitializer(tiInit);
+    isaGlobalVar(gIR->irDsymbol[this].irGlobal->value)->setInitializer(tiInit);
 }
 
 void TypeInfoStaticArrayDeclaration::toDt(dt_t **pdt)
@@ -692,7 +692,7 @@
     const llvm::StructType* stype = isaStruct(base->type->llvmType->get());
 
     // create the symbol
-    irGlobal->value = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module);
+    gIR->irDsymbol[this].irGlobal->value = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module);
 }
 
 void TypeInfoAssociativeArrayDeclaration::llvmDefine()
@@ -710,7 +710,7 @@
     // initializer vector
     std::vector<llvm::Constant*> sinits;
     // first is always the vtable
-    sinits.push_back(base->irStruct->vtbl);
+    sinits.push_back(gIR->irDsymbol[base].irStruct->vtbl);
 
     // monitor
     sinits.push_back(llvm::ConstantPointerNull::get(getPtrToType(llvm::Type::Int8Ty)));
@@ -725,7 +725,7 @@
     // get symbol
     assert(tc->next->vtinfo);
     DtoForceDeclareDsymbol(tc->next->vtinfo);
-    llvm::Constant* castbase = isaConstant(tc->next->vtinfo->irGlobal->value);
+    llvm::Constant* castbase = isaConstant(gIR->irDsymbol[tc->next->vtinfo].irGlobal->value);
     castbase = llvm::ConstantExpr::getBitCast(castbase, stype->getElementType(2));
     sinits.push_back(castbase);
 
@@ -735,13 +735,13 @@
     // get symbol
     assert(tc->index->vtinfo);
     DtoForceDeclareDsymbol(tc->index->vtinfo);
-    castbase = isaConstant(tc->index->vtinfo->irGlobal->value);
+    castbase = isaConstant(gIR->irDsymbol[tc->index->vtinfo].irGlobal->value);
     castbase = llvm::ConstantExpr::getBitCast(castbase, stype->getElementType(3));
     sinits.push_back(castbase);
 
     // create the symbol
     llvm::Constant* tiInit = llvm::ConstantStruct::get(stype, sinits);
-    isaGlobalVar(irGlobal->value)->setInitializer(tiInit);
+    isaGlobalVar(gIR->irDsymbol[this].irGlobal->value)->setInitializer(tiInit);
 }
 
 void TypeInfoAssociativeArrayDeclaration::toDt(dt_t **pdt)
@@ -825,7 +825,7 @@
     const llvm::StructType* stype = isaStruct(((TypeClass*)base->type)->llvmType->get());
 
     // create the symbol
-    irGlobal->value = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module);
+    gIR->irDsymbol[this].irGlobal->value = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module);
 }
 
 void TypeInfoStructDeclaration::llvmDefine()
@@ -845,7 +845,7 @@
 
     // vtbl
     std::vector<llvm::Constant*> sinits;
-    sinits.push_back(base->irStruct->vtbl);
+    sinits.push_back(gIR->irDsymbol[base].irStruct->vtbl);
 
     // monitor
     sinits.push_back(llvm::ConstantPointerNull::get(getPtrToType(llvm::Type::Int8Ty)));
@@ -865,7 +865,7 @@
     else
     {
         size_t cisize = getTypeStoreSize(tc->llvmType->get());
-        llvm::Constant* cicast = llvm::ConstantExpr::getBitCast(sd->irStruct->init, initpt);
+        llvm::Constant* cicast = llvm::ConstantExpr::getBitCast(gIR->irDsymbol[sd].irStruct->init, initpt);
         sinits.push_back(DtoConstSlice(DtoConstSize_t(cisize), cicast));
     }
 
@@ -925,8 +925,8 @@
         fd = fdx->overloadExactMatch(tftohash);
         if (fd) {
             DtoForceDeclareDsymbol(fd);
-            assert(gIR->irFunc[fd]->func != 0);
-            llvm::Constant* c = isaConstant(gIR->irFunc[fd]->func);
+            assert(gIR->irDsymbol[fd].irFunc->func != 0);
+            llvm::Constant* c = isaConstant(gIR->irDsymbol[fd].irFunc->func);
             assert(c);
             c = llvm::ConstantExpr::getBitCast(c, ptty);
             sinits.push_back(c);
@@ -951,8 +951,8 @@
             fd = fdx->overloadExactMatch(tfeqptr);
             if (fd) {
                 DtoForceDeclareDsymbol(fd);
-                assert(gIR->irFunc[fd]->func != 0);
-                llvm::Constant* c = isaConstant(gIR->irFunc[fd]->func);
+                assert(gIR->irDsymbol[fd].irFunc->func != 0);
+                llvm::Constant* c = isaConstant(gIR->irDsymbol[fd].irFunc->func);
                 assert(c);
                 c = llvm::ConstantExpr::getBitCast(c, ptty);
                 sinits.push_back(c);
@@ -979,8 +979,8 @@
         fd = fdx->overloadExactMatch(tftostring);
         if (fd) {
             DtoForceDeclareDsymbol(fd);
-            assert(gIR->irFunc[fd]->func != 0);
-            llvm::Constant* c = isaConstant(gIR->irFunc[fd]->func);
+            assert(gIR->irDsymbol[fd].irFunc->func != 0);
+            llvm::Constant* c = isaConstant(gIR->irDsymbol[fd].irFunc->func);
             assert(c);
             c = llvm::ConstantExpr::getBitCast(c, ptty);
             sinits.push_back(c);
@@ -1001,7 +1001,7 @@
     llvm::Constant* tiInit = llvm::ConstantStruct::get(stype, sinits);
     llvm::GlobalVariable* gvar = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,tiInit,toChars(),gIR->module);
 
-    isaGlobalVar(irGlobal->value)->setInitializer(tiInit);
+    isaGlobalVar(gIR->irDsymbol[this].irGlobal->value)->setInitializer(tiInit);
 }
 
 void TypeInfoStructDeclaration::toDt(dt_t **pdt)
@@ -1025,7 +1025,7 @@
     const llvm::StructType* stype = isaStruct(base->type->llvmType->get());
 
     // create the symbol
-    irGlobal->value = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module);
+    gIR->irDsymbol[this].irGlobal->value = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module);
 }
 
 void TypeInfoClassDeclaration::llvmDefine()
@@ -1044,7 +1044,7 @@
     // initializer vector
     std::vector<llvm::Constant*> sinits;
     // first is always the vtable
-    sinits.push_back(base->irStruct->vtbl);
+    sinits.push_back(gIR->irDsymbol[base].irStruct->vtbl);
 
     // monitor
     sinits.push_back(llvm::ConstantPointerNull::get(getPtrToType(llvm::Type::Int8Ty)));
@@ -1052,12 +1052,12 @@
     // get classinfo
     assert(tinfo->ty == Tclass);
     TypeClass *tc = (TypeClass *)tinfo;
-    assert(tc->sym->irStruct->classInfo);
-    sinits.push_back(tc->sym->irStruct->classInfo);
+    assert(gIR->irDsymbol[tc->sym].irStruct->classInfo);
+    sinits.push_back(gIR->irDsymbol[tc->sym].irStruct->classInfo);
 
     // create the symbol
     llvm::Constant* tiInit = llvm::ConstantStruct::get(stype, sinits);
-    isaGlobalVar(irGlobal->value)->setInitializer(tiInit);
+    isaGlobalVar(gIR->irDsymbol[this].irGlobal->value)->setInitializer(tiInit);
 }
 
 void TypeInfoClassDeclaration::toDt(dt_t **pdt)
@@ -1081,7 +1081,7 @@
     const llvm::StructType* stype = isaStruct(base->type->llvmType->get());
 
     // create the symbol
-    irGlobal->value = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module);
+    gIR->irDsymbol[this].irGlobal->value = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module);
 }
 
 void TypeInfoInterfaceDeclaration::llvmDefine()
@@ -1100,7 +1100,7 @@
     // initializer vector
     std::vector<llvm::Constant*> sinits;
     // first is always the vtable
-    sinits.push_back(base->irStruct->vtbl);
+    sinits.push_back(gIR->irDsymbol[base].irStruct->vtbl);
 
     // monitor
     sinits.push_back(llvm::ConstantPointerNull::get(getPtrToType(llvm::Type::Int8Ty)));
@@ -1108,12 +1108,12 @@
     // get classinfo
     assert(tinfo->ty == Tclass);
     TypeClass *tc = (TypeClass *)tinfo;
-    assert(tc->sym->irStruct->classInfo);
-    sinits.push_back(tc->sym->irStruct->classInfo);
+    assert(gIR->irDsymbol[tc->sym].irStruct->classInfo);
+    sinits.push_back(gIR->irDsymbol[tc->sym].irStruct->classInfo);
 
     // create the symbol
     llvm::Constant* tiInit = llvm::ConstantStruct::get(stype, sinits);
-    isaGlobalVar(irGlobal->value)->setInitializer(tiInit);
+    isaGlobalVar(gIR->irDsymbol[this].irGlobal->value)->setInitializer(tiInit);
 }
 
 void TypeInfoInterfaceDeclaration::toDt(dt_t **pdt)
@@ -1137,7 +1137,7 @@
     const llvm::StructType* stype = isaStruct(base->type->llvmType->get());
 
     // create the symbol
-    irGlobal->value = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module);
+    gIR->irDsymbol[this].irGlobal->value = new llvm::GlobalVariable(stype,true,llvm::GlobalValue::WeakLinkage,NULL,toChars(),gIR->module);
 }
 
 void TypeInfoTupleDeclaration::llvmDefine()
@@ -1156,7 +1156,7 @@
     // initializer vector
     std::vector<llvm::Constant*> sinits;
     // first is always the vtable
-    sinits.push_back(base->irStruct->vtbl);
+    sinits.push_back(gIR->irDsymbol[base].irStruct->vtbl);
 
     // monitor
     sinits.push_back(llvm::ConstantPointerNull::get(getPtrToType(llvm::Type::Int8Ty)));
@@ -1176,8 +1176,8 @@
         Argument *arg = (Argument *)tu->arguments->data[i];
         arg->type->getTypeInfo(NULL);
         DtoForceDeclareDsymbol(arg->type->vtinfo);
-        assert(arg->type->vtinfo->irGlobal->value);
-        llvm::Constant* c = isaConstant(arg->type->vtinfo->irGlobal->value);
+        assert(gIR->irDsymbol[arg->type->vtinfo].irGlobal->value);
+        llvm::Constant* c = isaConstant(gIR->irDsymbol[arg->type->vtinfo].irGlobal->value);
         c = llvm::ConstantExpr::getBitCast(c, tiTy);
         arrInits.push_back(c);
     }
@@ -1192,7 +1192,7 @@
 
     // create the symbol
     llvm::Constant* tiInit = llvm::ConstantStruct::get(stype, sinits);
-    isaGlobalVar(irGlobal->value)->setInitializer(tiInit);
+    isaGlobalVar(gIR->irDsymbol[this].irGlobal->value)->setInitializer(tiInit);
 }
 
 void TypeInfoTupleDeclaration::toDt(dt_t **pdt)