LLStructType *DtoModuleReferenceType() { if (gIR->moduleRefType) { return gIR->moduleRefType; } // this is a recursive type so start out with a struct without body LLStructType *st = LLStructType::create(gIR->context(), "ModuleReference"); // add members LLType *types[] = {getPtrToType(st), DtoType(Module::moduleinfo->type->pointerTo())}; // resolve type st->setBody(types); // done gIR->moduleRefType = st; return st; }
void RTTIBuilder::finalize(LLType* type, LLValue* value) { llvm::ArrayRef<LLConstant*> inits = llvm::makeArrayRef(this->inits); LLStructType *st = isaStruct(type); assert(st); // set struct body if (st->isOpaque()) { std::vector<LLType*> types; for (int i = 0, n = inits.size(); i < n; ++i) types.push_back(inits[i]->getType()); st->setBody(types); } // create the inititalizer LLConstant* tiInit = LLConstantStruct::get(st, inits); // set the initializer isaGlobalVar(value)->setInitializer(tiInit); }
void RTTIBuilder::finalize(LLType* type, LLValue* value) { llvm::ArrayRef<LLConstant*> inits = llvm::makeArrayRef(this->inits); LLStructType *st = isaStruct(type); assert(st); // set struct body if (st->isOpaque()) { const int n = inits.size(); std::vector<LLType*> types; types.reserve(n); for (int i = 0; i < n; ++i) types.push_back(inits[i]->getType()); st->setBody(types); } // create the inititalizer LLConstant* tiInit = LLConstantStruct::get(st, inits); // set the initializer llvm::GlobalVariable* gvar = llvm::cast<llvm::GlobalVariable>(value); gvar->setInitializer(tiInit); gvar->setLinkage(TYPEINFO_LINKAGE_TYPE); }
LLStructType* DtoModuleReferenceType() { if (gIR->moduleRefType) return gIR->moduleRefType; // this is a recursive type so start out with a struct without body LLStructType* st = LLStructType::create(gIR->context(), "ModuleReference"); // add members std::vector<LLType*> types; types.push_back(getPtrToType(st)); #if DMDV1 types.push_back(DtoType(Module::moduleinfo->type)); #else types.push_back(DtoType(Module::moduleinfo->type->pointerTo())); #endif // resolve type st->setBody(types); // done gIR->moduleRefType = st; return st; }
LLStructType* DtoMutexType() { if (gIR->mutexType) return gIR->mutexType; // The structures defined here must be the same as in druntime/src/rt/critical.c // Windows if (global.params.targetTriple.isOSWindows()) { llvm::Type *VoidPtrTy = llvm::Type::getInt8PtrTy(gIR->context()); llvm::Type *Int32Ty = llvm::Type::getInt32Ty(gIR->context()); // Build RTL_CRITICAL_SECTION; size is 24 (32bit) or 40 (64bit) LLType *rtl_types[] = { VoidPtrTy, // Pointer to DebugInfo Int32Ty, // LockCount Int32Ty, // RecursionCount VoidPtrTy, // Handle of OwningThread VoidPtrTy, // Handle of LockSemaphore VoidPtrTy // SpinCount }; LLStructType* rtl = LLStructType::create(gIR->context(), rtl_types, "RTL_CRITICAL_SECTION"); // Build D_CRITICAL_SECTION; size is 28 (32bit) or 48 (64bit) LLStructType *mutex = LLStructType::create(gIR->context(), "D_CRITICAL_SECTION"); LLType *types[] = { getPtrToType(mutex), rtl }; mutex->setBody(types); // Cache type gIR->mutexType = mutex; return mutex; } // FreeBSD else if (global.params.targetTriple.getOS() == llvm::Triple::FreeBSD) { // Just a pointer return LLStructType::get(gIR->context(), DtoSize_t()); } // pthread_fastlock LLType *types2[] = { DtoSize_t(), LLType::getInt32Ty(gIR->context()) }; LLStructType* fastlock = LLStructType::get(gIR->context(), types2, false); // pthread_mutex LLType *types1[] = { LLType::getInt32Ty(gIR->context()), LLType::getInt32Ty(gIR->context()), getVoidPtrType(), LLType::getInt32Ty(gIR->context()), fastlock }; LLStructType* pmutex = LLStructType::get(gIR->context(), types1, false); // D_CRITICAL_SECTION LLStructType* mutex = LLStructType::create(gIR->context(), "D_CRITICAL_SECTION"); LLType *types[] = { getPtrToType(mutex), pmutex }; mutex->setBody(types); // Cache type gIR->mutexType = mutex; return pmutex; }
LLStructType* DtoMutexType() { if (gIR->mutexType) return gIR->mutexType; // The structures defined here must be the same as in druntime/src/rt/critical.c // Windows if (global.params.os == OSWindows) { llvm::Type *VoidPtrTy = llvm::Type::getInt8PtrTy(gIR->context()); llvm::Type *Int32Ty = llvm::Type::getInt32Ty(gIR->context()); // Build RTL_CRITICAL_SECTION; size is 24 (32bit) or 40 (64bit) std::vector<LLType*> rtl_types; rtl_types.push_back(VoidPtrTy); // Pointer to DebugInfo rtl_types.push_back(Int32Ty); // LockCount rtl_types.push_back(Int32Ty); // RecursionCount rtl_types.push_back(VoidPtrTy); // Handle of OwningThread rtl_types.push_back(VoidPtrTy); // Handle of LockSemaphore rtl_types.push_back(VoidPtrTy); // SpinCount LLStructType* rtl = LLStructType::create(gIR->context(), rtl_types, "RTL_CRITICAL_SECTION"); // Build D_CRITICAL_SECTION; size is 28 (32bit) or 48 (64bit) LLStructType* mutex = LLStructType::create(gIR->context(), "D_CRITICAL_SECTION"); std::vector<LLType*> types; types.push_back(getPtrToType(mutex)); types.push_back(rtl); mutex->setBody(types); // Cache type gIR->mutexType = mutex; return mutex; } // FreeBSD else if (global.params.os == OSFreeBSD) { // Just a pointer return LLStructType::get(gIR->context(), DtoSize_t()); } // pthread_fastlock std::vector<LLType*> types2; types2.push_back(DtoSize_t()); types2.push_back(LLType::getInt32Ty(gIR->context())); LLStructType* fastlock = LLStructType::get(gIR->context(), types2); // pthread_mutex std::vector<LLType*> types1; types1.push_back(LLType::getInt32Ty(gIR->context())); types1.push_back(LLType::getInt32Ty(gIR->context())); types1.push_back(getVoidPtrType()); types1.push_back(LLType::getInt32Ty(gIR->context())); types1.push_back(fastlock); LLStructType* pmutex = LLStructType::get(gIR->context(), types1); // D_CRITICAL_SECTION LLStructType* mutex = LLStructType::create(gIR->context(), "D_CRITICAL_SECTION"); std::vector<LLType*> types; types.push_back(getPtrToType(mutex)); types.push_back(pmutex); mutex->setBody(types); // Cache type gIR->mutexType = mutex; return pmutex; }