From 464c695814864372e0a7233af7bd1391c38d57dc Mon Sep 17 00:00:00 2001 From: David Nadlinger Date: Thu, 20 Dec 2012 06:23:27 +0100 Subject: [PATCH] Renamed IrType::get/IrType::getD, treat classes as the special case they are. --- gen/classes.cpp | 2 +- gen/module.cpp | 16 ++++++++++++---- gen/tollvm.cpp | 2 +- gen/typinf.cpp | 5 +++-- ir/irclass.cpp | 4 ++-- ir/irtype.h | 6 ++---- ir/irtypeclass.cpp | 11 +++++++++-- ir/irtypeclass.h | 6 +++++- 8 files changed, 35 insertions(+), 17 deletions(-) diff --git a/gen/classes.cpp b/gen/classes.cpp index 4141da1c..d7374797 100644 --- a/gen/classes.cpp +++ b/gen/classes.cpp @@ -722,7 +722,7 @@ LLConstant* DtoDefineClassInfo(ClassDeclaration* cd) } else { - LLType* cd_type = stripModifiers(cdty)->irtype->getType(); + LLType* cd_type = cdty->irtype->isClass()->getMemoryLLType(); size_t initsz = getTypePaddedSize(cd_type); b.push_void_array(initsz, ir->getInitSymbol()); } diff --git a/gen/module.cpp b/gen/module.cpp index 17bac5e5..e8a85e26 100644 --- a/gen/module.cpp +++ b/gen/module.cpp @@ -50,6 +50,10 @@ #include "ir/irmodule.h" #include "ir/irtype.h" +#if !MODULEINFO_IS_STRUCT +#include "ir/irtypeclass.h" +#endif + #if DMDV2 #define NEW_MODULEINFO_LAYOUT 1 #endif @@ -379,8 +383,12 @@ void Module::genmoduleinfo() RTTIBuilder b(moduleinfo); // some types - LLType* moduleinfoTy = moduleinfo->type->irtype->getType(); - LLType* classinfoTy = ClassDeclaration::classinfo->type->irtype->getType(); +#if MODULEINFO_IS_STRUCT + LLType* moduleinfoTy = moduleinfo->type->irtype->getLLType(); +#else + LLType* moduleinfoTy = moduleinfo->type->irtype->isClass()->getMemoryLLType(); +#endif + LLType* classinfoTy = ClassDeclaration::classinfo->type->irtype->getLLType(); // importedModules[] std::vector importInits; @@ -438,13 +446,13 @@ void Module::genmoduleinfo() continue; } Logger::println("class: %s", cd->toPrettyChars()); - LLConstant *c = DtoBitCast(cd->ir.irStruct->getClassInfoSymbol(), getPtrToType(classinfoTy)); + LLConstant *c = DtoBitCast(cd->ir.irStruct->getClassInfoSymbol(), classinfoTy); classInits.push_back(c); } // has class array? if (!classInits.empty()) { - localClassesTy = llvm::ArrayType::get(getPtrToType(classinfoTy), classInits.size()); + localClassesTy = llvm::ArrayType::get(classinfoTy, classInits.size()); localClasses = LLConstantArray::get(localClassesTy, classInits); } diff --git a/gen/tollvm.cpp b/gen/tollvm.cpp index ca4392ce..92a0440b 100644 --- a/gen/tollvm.cpp +++ b/gen/tollvm.cpp @@ -79,7 +79,7 @@ LLType* DtoType(Type* t) if (t->irtype) { - return t->irtype->get(); + return t->irtype->getLLType(); } IF_LOG Logger::println("Building type: %s", t->toChars()); diff --git a/gen/typinf.cpp b/gen/typinf.cpp index 748039d2..e786ec40 100644 --- a/gen/typinf.cpp +++ b/gen/typinf.cpp @@ -53,6 +53,7 @@ #include "ir/irvar.h" #include "ir/irtype.h" +#include /******************************************* * Get a canonicalized form of the TypeInfo for use with the internal @@ -323,7 +324,7 @@ void DtoResolveTypeInfo(TypeInfoDeclaration* tid) if (!irg->value) { if (tid->tinfo->builtinTypeInfo()) // this is a declaration of a builtin __initZ var - irg->type = Type::typeinfo->type->irtype->getType(); + irg->type = Type::typeinfo->type->irtype->isClass()->getMemoryLLType(); else irg->type = LLStructType::create(gIR->context(), tid->toPrettyChars()); irg->value = new llvm::GlobalVariable(*gIR->module, irg->type, true, @@ -638,7 +639,7 @@ void TypeInfoStructDeclaration::llvmDefine() // void[] init // never emit a null array, even for zero initialized typeinfo // the size() method uses this array! - size_t init_size = getTypeStoreSize(tc->irtype->getType()); + size_t init_size = getTypeStoreSize(tc->irtype->getLLType()); b.push_void_array(init_size, irstruct->getInitSymbol()); // toX functions ground work diff --git a/ir/irclass.cpp b/ir/irclass.cpp index 248d4e42..14a56266 100644 --- a/ir/irclass.cpp +++ b/ir/irclass.cpp @@ -78,9 +78,9 @@ LLGlobalVariable * IrStruct::getClassInfoSymbol() IrTypeClass* tc = stripModifiers(cinfo->type)->irtype->isClass(); assert(tc && "invalid ClassInfo type"); - // classinfos cannot be constants since they're used a locks for synchronized + // classinfos cannot be constants since they're used as locks for synchronized classInfo = new llvm::GlobalVariable( - *gIR->module, tc->getType(), false, _linkage, NULL, initname); + *gIR->module, tc->getMemoryLLType(), false, _linkage, NULL, initname); #if USE_METADATA // Generate some metadata on this ClassInfo if it's for a class. diff --git a/ir/irtype.h b/ir/irtype.h index cb5dd090..1ba67e6d 100644 --- a/ir/irtype.h +++ b/ir/irtype.h @@ -71,11 +71,9 @@ public: #endif /// - Type* getD() { return dtype; } + Type* getDType() { return dtype; } /// - virtual llvm::Type* get() { return type; } - /// - llvm::Type* getType() { return type; } + virtual llvm::Type* getLLType() { return type; } /// virtual llvm::Type* buildType() = 0; diff --git a/ir/irtypeclass.cpp b/ir/irtypeclass.cpp index 943b2b2c..48788028 100644 --- a/ir/irtypeclass.cpp +++ b/ir/irtypeclass.cpp @@ -279,7 +279,7 @@ llvm::Type* IrTypeClass::buildType() IF_LOG Logger::cout() << "class type: " << *type << std::endl; - return get(); + return getLLType(); } ////////////////////////////////////////////////////////////////////////////// @@ -349,13 +349,20 @@ std::vector IrTypeClass::buildVtblType(Type* first, Array* vtbl_arr ////////////////////////////////////////////////////////////////////////////// -llvm::Type * IrTypeClass::get() +llvm::Type * IrTypeClass::getLLType() { return llvm::PointerType::get(type, 0); } ////////////////////////////////////////////////////////////////////////////// +llvm::Type * IrTypeClass::getMemoryLLType() +{ + return type; +} + +////////////////////////////////////////////////////////////////////////////// + size_t IrTypeClass::getInterfaceIndex(ClassDeclaration * inter) { ClassIndexMap::iterator it = interfaceMap.find(inter); diff --git a/ir/irtypeclass.h b/ir/irtypeclass.h index 6e6c5b43..17b4f900 100644 --- a/ir/irtypeclass.h +++ b/ir/irtypeclass.h @@ -31,7 +31,11 @@ public: llvm::Type* buildType(); /// - llvm::Type* get(); + llvm::Type* getLLType(); + + /// Returns the actual storage type, i.e. without the indirection + /// for the class reference. + llvm::Type* getMemoryLLType(); /// Returns the vtable type for this class. llvm::Type* getVtbl() { return vtbl_type; }