From b2da152704fe5f8fc597bc92720e8ec7cfd9b364 Mon Sep 17 00:00:00 2001 From: David Nadlinger Date: Sun, 12 May 2013 00:38:58 +0200 Subject: [PATCH 1/4] Remove D1 ModuleInfo remnants. --- gen/module.cpp | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/gen/module.cpp b/gen/module.cpp index fbbc4204..b99bc6a4 100644 --- a/gen/module.cpp +++ b/gen/module.cpp @@ -38,9 +38,6 @@ #include "ir/irdsymbol.h" #include "ir/irmodule.h" #include "ir/irtype.h" -#if !MODULEINFO_IS_STRUCT -#include "ir/irtypeclass.h" -#endif #include "ir/irvar.h" #include "llvm/Analysis/Verifier.h" #include "llvm/LinkAllPasses.h" @@ -356,7 +353,7 @@ void Module::genmoduleinfo() // resolve ModuleInfo if (!moduleinfo) { - error("object.d is missing the ModuleInfo class"); + error("object.d is missing the ModuleInfo struct"); fatal(); } // check for patch @@ -374,11 +371,7 @@ void Module::genmoduleinfo() RTTIBuilder b(moduleinfo); // some types -#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[] From ad03a435ad4f934cd4ba5fbe2b0fe18eb9ff77b9 Mon Sep 17 00:00:00 2001 From: David Nadlinger Date: Sun, 12 May 2013 00:47:49 +0200 Subject: [PATCH 2/4] Remove code for emitting the old ModuleInfo layout. --- gen/module.cpp | 111 ------------------------------------------------- 1 file changed, 111 deletions(-) diff --git a/gen/module.cpp b/gen/module.cpp index b99bc6a4..57127a94 100644 --- a/gen/module.cpp +++ b/gen/module.cpp @@ -53,8 +53,6 @@ #endif #endif -#define NEW_MODULEINFO_LAYOUT 1 - static llvm::Function* build_module_function(const std::string &name, const std::list &funcs, const std::list &gates = std::list()) { @@ -440,8 +438,6 @@ void Module::genmoduleinfo() localClasses = LLConstantArray::get(localClassesTy, classInits); } -#if NEW_MODULEINFO_LAYOUT - // These must match the values in druntime/src/object_.d #define MIstandalone 4 #define MItlsctor 8 @@ -517,113 +513,6 @@ void Module::genmoduleinfo() // Put out module name as a 0-terminated string, to save bytes b.push(DtoConstStringPtr(toPrettyChars())); -#else - // The layout is: - // char[] name; - // ModuleInfo[] importedModules; - // ClassInfo[] localClasses; - // uint flags; - // - // void function() ctor; - // void function() dtor; - // void function() unitTest; - // - // void* xgetMembers; - // void function() ictor; - // - // version(D_Version2) { - // void *sharedctor; - // void *shareddtor; - // uint index; - // void*[1] reserved; - // } - - LLConstant *c = 0; - - // name - b.push_string(toPrettyChars()); - - // importedModules - if (importedModules) - { - std::string m_name("_D"); - m_name.append(mangle()); - m_name.append("9__importsZ"); - llvm::GlobalVariable* m_gvar = gIR->module->getGlobalVariable(m_name); - if (!m_gvar) m_gvar = new llvm::GlobalVariable(*gIR->module, importedModulesTy, true, llvm::GlobalValue::InternalLinkage, importedModules, m_name); - c = llvm::ConstantExpr::getBitCast(m_gvar, getPtrToType(importedModulesTy->getElementType())); - c = DtoConstSlice(DtoConstSize_t(importInits.size()), c); - } - else - { - c = DtoConstSlice(DtoConstSize_t(0), getNullValue(getPtrToType(moduleinfoTy))); - } - b.push(c); - - // localClasses - if (localClasses) - { - std::string m_name("_D"); - m_name.append(mangle()); - m_name.append("9__classesZ"); - assert(gIR->module->getGlobalVariable(m_name) == NULL); - llvm::GlobalVariable* m_gvar = new llvm::GlobalVariable(*gIR->module, localClassesTy, true, llvm::GlobalValue::InternalLinkage, localClasses, m_name); - c = DtoGEPi(m_gvar, 0, 0); - c = DtoConstSlice(DtoConstSize_t(classInits.size()), c); - } - else - { - c = DtoConstSlice( DtoConstSize_t(0), getNullValue(getPtrToType(getPtrToType(classinfoTy))) ); - } - b.push(c); - - // flags (4 means MIstandalone) - unsigned mi_flags = needmoduleinfo ? 0 : 4; - b.push_uint(mi_flags); - - // function pointer type for next three fields - LLType* fnptrTy = getPtrToType(LLFunctionType::get(LLType::getVoidTy(gIR->context()), std::vector(), false)); - - // ctor - llvm::Function* fctor = build_module_shared_ctor(); - c = fctor ? fctor : getNullValue(fnptrTy); - b.push(c); - - // dtor - llvm::Function* fdtor = build_module_shared_dtor(); - c = fdtor ? fdtor : getNullValue(fnptrTy); - b.push(c); - - // unitTest - llvm::Function* unittest = build_module_unittest(); - c = unittest ? unittest : getNullValue(fnptrTy); - b.push(c); - - // xgetMembers - c = getNullValue(getVoidPtrType()); - b.push(c); - - // ictor - c = getNullValue(fnptrTy); - b.push(c); - - // tls ctor - fctor = build_module_ctor(); - c = fctor ? fctor : getNullValue(fnptrTy); - b.push(c); - - // tls dtor - fdtor = build_module_dtor(); - c = fdtor ? fdtor : getNullValue(fnptrTy); - b.push(c); - - // index + reserved void*[1] - LLType* AT = llvm::ArrayType::get(getVoidPtrType(), 2); - c = getNullValue(AT); - b.push(c); - -#endif - // create and set initializer b.finalize(moduleInfoType, moduleInfoSymbol()); From e1501c712f78073224080c892ea6e47cad2b0749 Mon Sep 17 00:00:00 2001 From: David Nadlinger Date: Sun, 12 May 2013 01:24:04 +0200 Subject: [PATCH 3/4] Moved constant array creation helper to llvmhelpers.h. --- gen/llvmhelpers.h | 13 +++++++++++++ gen/toir.cpp | 15 --------------- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/gen/llvmhelpers.h b/gen/llvmhelpers.h index 4a9ec3f8..ab4c8d45 100644 --- a/gen/llvmhelpers.h +++ b/gen/llvmhelpers.h @@ -220,4 +220,17 @@ void printLabelName(std::ostream& target, const char* func_mangle, const char* l void AppendFunctionToLLVMGlobalCtorsDtors(llvm::Function* func, const uint32_t priority, const bool isCtor); +template +LLConstant* toConstantArray(LLType* ct, LLArrayType* at, T* str, size_t len, bool nullterm = true) +{ + std::vector vals; + vals.reserve(len+1); + for (size_t i = 0; i < len; ++i) { + vals.push_back(LLConstantInt::get(ct, str[i], false)); + } + if (nullterm) + vals.push_back(LLConstantInt::get(ct, 0, false)); + return LLConstantArray::get(at, vals); +} + #endif diff --git a/gen/toir.cpp b/gen/toir.cpp index 7170453e..5b801236 100644 --- a/gen/toir.cpp +++ b/gen/toir.cpp @@ -423,21 +423,6 @@ LLConstant* ComplexExp::toConstElem(IRState* p) ////////////////////////////////////////////////////////////////////////////////////////// -template -static inline LLConstant* toConstantArray(LLType* ct, LLArrayType* at, T* str, size_t len, bool nullterm = true) -{ - std::vector vals; - vals.reserve(len+1); - for (size_t i = 0; i < len; ++i) { - vals.push_back(LLConstantInt::get(ct, str[i], false)); - } - if (nullterm) - vals.push_back(LLConstantInt::get(ct, 0, false)); - return LLConstantArray::get(at, vals); -} - -////////////////////////////////////////////////////////////////////////////////////////// - DValue* StringExp::toElem(IRState* p) { Logger::print("StringExp::toElem: %s @ %s\n", toChars(), type->toChars()); From b2ca861f64d9b3168ae9142469329cb35d0a4cb3 Mon Sep 17 00:00:00 2001 From: David Nadlinger Date: Sun, 12 May 2013 01:25:48 +0200 Subject: [PATCH 4/4] Fixed ModuleInfo module name emission. The name string is actually emitted inline, not as a pointer to a global. GitHub: Fixes #243. --- gen/module.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/gen/module.cpp b/gen/module.cpp index 57127a94..5893de65 100644 --- a/gen/module.cpp +++ b/gen/module.cpp @@ -510,8 +510,12 @@ void Module::genmoduleinfo() b.push(localClasses); } - // Put out module name as a 0-terminated string, to save bytes - b.push(DtoConstStringPtr(toPrettyChars())); + // Put out module name as a 0-terminated string. + const char *name = toPrettyChars(); + const size_t len = strlen(name) + 1; + llvm::IntegerType *it = llvm::IntegerType::getInt8Ty(gIR->context()); + llvm::ArrayType *at = llvm::ArrayType::get(it, len); + b.push(toConstantArray(it, at, name, len, false)); // create and set initializer b.finalize(moduleInfoType, moduleInfoSymbol());