diff --git a/driver/codegenerator.cpp b/driver/codegenerator.cpp index 2881238960..6c211a5968 100644 --- a/driver/codegenerator.cpp +++ b/driver/codegenerator.cpp @@ -109,14 +109,14 @@ void emitLLVMUsedArray(IRState &irs) { return; } - auto *i8PtrType = getVoidPtrType(irs.context()); + auto ptrType = LLPointerType::get(irs.context(), 0); // Convert all elements to i8* (the expected type for llvm.used) for (auto &elem : irs.usedArray) { - elem = llvm::ConstantExpr::getBitCast(elem, i8PtrType); + elem = llvm::ConstantExpr::getBitCast(elem, ptrType); } - auto *arrayType = llvm::ArrayType::get(i8PtrType, irs.usedArray.size()); + auto *arrayType = llvm::ArrayType::get(ptrType, irs.usedArray.size()); auto *llvmUsed = new llvm::GlobalVariable( irs.module, arrayType, false, llvm::GlobalValue::AppendingLinkage, llvm::ConstantArray::get(arrayType, irs.usedArray), "llvm.used"); diff --git a/gen/abi/generic.h b/gen/abi/generic.h index 3647d8be79..02c664e525 100644 --- a/gen/abi/generic.h +++ b/gen/abi/generic.h @@ -250,7 +250,7 @@ struct IndirectByvalRewrite : ABIRewrite { return v; } - LLType *type(Type *t) override { return DtoPtrToType(t); } + LLType *type(Type *t) override { return getOpaquePtrType(); } void applyTo(IrFuncTyArg &arg, LLType *finalLType = nullptr) override { ABIRewrite::applyTo(arg, finalLType); diff --git a/gen/abi/x86-64.cpp b/gen/abi/x86-64.cpp index 6018b38046..253d0c2ab8 100644 --- a/gen/abi/x86-64.cpp +++ b/gen/abi/x86-64.cpp @@ -130,7 +130,7 @@ struct ImplicitByvalRewrite : ABIRewrite { LLValue *getLVal(Type *dty, LLValue *v) override { return v; } - LLType *type(Type *t) override { return DtoPtrToType(t); } + LLType *type(Type *t) override { return getOpaquePtrType(); } void applyTo(IrFuncTyArg &arg, LLType *finalLType = nullptr) override { ABIRewrite::applyTo(arg, finalLType); @@ -336,13 +336,13 @@ void X86_64TargetABI::rewriteVarargs(IrFuncTy &fty, LLType *X86_64TargetABI::getValistType() { LLType *uintType = LLType::getInt32Ty(gIR->context()); - LLType *voidPointerType = getVoidPtrType(); + LLType *pointerType = getOpaquePtrType(); - std::vector parts; // struct __va_list_tag { - parts.push_back(uintType); // uint gp_offset; - parts.push_back(uintType); // uint fp_offset; - parts.push_back(voidPointerType); // void* overflow_arg_area; - parts.push_back(voidPointerType); // void* reg_save_area; } + std::vector parts; // struct __va_list_tag { + parts.push_back(uintType); // uint gp_offset; + parts.push_back(uintType); // uint fp_offset; + parts.push_back(pointerType); // void* overflow_arg_area; + parts.push_back(pointerType); // void* reg_save_area; } return LLStructType::get(gIR->context(), parts); } diff --git a/gen/arrays.cpp b/gen/arrays.cpp index 716026331a..0f86908b4e 100644 --- a/gen/arrays.cpp +++ b/gen/arrays.cpp @@ -36,19 +36,6 @@ static void DtoSetArray(DValue *array, DValue *rhs); //////////////////////////////////////////////////////////////////////////////// -LLStructType *DtoArrayType(Type *arrayTy) { - assert(arrayTy->nextOf()); - llvm::Type *elems[] = {DtoSize_t(), DtoPtrToType(arrayTy->nextOf())}; - return llvm::StructType::get(gIR->context(), elems, false); -} - -LLStructType *DtoArrayType(LLType *t) { - llvm::Type *elems[] = {DtoSize_t(), getPtrToType(t)}; - return llvm::StructType::get(gIR->context(), elems, false); -} - -//////////////////////////////////////////////////////////////////////////////// - LLArrayType *DtoStaticArrayType(Type *t) { t = t->toBasetype(); assert(t->ty == TY::Tsarray); @@ -714,11 +701,8 @@ LLValue *DtoArrayEqCmp_impl(const Loc &loc, const char *func, DValue *l, LLSmallVector args; - // get values, reinterpret cast to void[] - args.push_back(DtoSlicePaint(DtoRVal(l), - DtoArrayType(LLType::getInt8Ty(gIR->context())))); - args.push_back(DtoSlicePaint(DtoRVal(r), - DtoArrayType(LLType::getInt8Ty(gIR->context())))); + args.push_back(DtoRVal(l)); + args.push_back(DtoRVal(r)); // pass array typeinfo ? if (useti) { @@ -929,16 +913,13 @@ LLValue *DtoArrayPtr(DValue *v) { LOG_SCOPE; Type *t = v->type->toBasetype(); - // v's LL array element type may not be the real one - // due to implicit casts (e.g., to base class) - LLType *wantedLLPtrType = DtoPtrToType(t->nextOf()); LLValue *ptr = nullptr; if (t->ty == TY::Tarray) { if (v->isNull()) { - ptr = getNullPtr(wantedLLPtrType); + ptr = getNullPtr(); } else if (v->isLVal()) { - ptr = DtoLoad(wantedLLPtrType, DtoGEP(DtoType(v->type), DtoLVal(v), 0, 1), ".ptr"); + ptr = DtoLoad(getOpaquePtrType(), DtoGEP(DtoType(v->type), DtoLVal(v), 0, 1), ".ptr"); } else { auto slice = v->isSlice(); assert(slice); @@ -1035,7 +1016,7 @@ DValue *DtoCastArray(const Loc &loc, DValue *u, Type *to) { if (totype->ty == TY::Tbool) { // return (arr.ptr !is null) LLValue *ptr = DtoArrayPtr(u); - LLConstant *nul = getNullPtr(ptr->getType()); + LLConstant *nul = getNullPtr(); return new DImValue(to, gIR->ir->CreateICmpNE(ptr, nul)); } diff --git a/gen/arrays.h b/gen/arrays.h index 9e38cb7fa4..4e2c7e52fd 100644 --- a/gen/arrays.h +++ b/gen/arrays.h @@ -25,8 +25,6 @@ struct IRState; struct Loc; class Type; -llvm::StructType *DtoArrayType(Type *arrayTy); -llvm::StructType *DtoArrayType(LLType *elemTy); llvm::ArrayType *DtoStaticArrayType(Type *sarrayTy); /// Creates a (global) constant with the element data for the given arary diff --git a/gen/classes.cpp b/gen/classes.cpp index 3ac7f2ef66..5d686f084d 100644 --- a/gen/classes.cpp +++ b/gen/classes.cpp @@ -303,19 +303,17 @@ DValue *DtoCastClass(const Loc &loc, DValue *val, Type *_to) { // it's just a GEP and (maybe) a pointer-to-pointer BitCast, so it // should be pretty cheap and perfectly safe even if the original was // null. - LLValue *isNull = gIR->ir->CreateICmpEQ( - orig, LLConstant::getNullValue(orig->getType()), ".nullcheck"); - v = gIR->ir->CreateSelect( - isNull, LLConstant::getNullValue(getVoidPtrType()), v, ".interface"); + const auto nullPtr = getNullPtr(); + LLValue *isNull = gIR->ir->CreateICmpEQ(orig, nullPtr, ".nullcheck"); + v = gIR->ir->CreateSelect(isNull, nullPtr, v, ".interface"); // return r-value return new DImValue(_to, v); } if (fc->sym->classKind == ClassKind::cpp) { Logger::println("C++ class/interface cast"); - LLValue *v = tc->sym->classKind == ClassKind::cpp - ? DtoRVal(val) - : LLConstant::getNullValue(getVoidPtrType()); + LLValue *v = + tc->sym->classKind == ClassKind::cpp ? DtoRVal(val) : getNullPtr(); return new DImValue(_to, v); } diff --git a/gen/dvalue.cpp b/gen/dvalue.cpp index 2debc5c405..bdad72263b 100644 --- a/gen/dvalue.cpp +++ b/gen/dvalue.cpp @@ -121,10 +121,7 @@ bool DFuncValue::definedInFuncEntryBB() { //////////////////////////////////////////////////////////////////////////////// DLValue::DLValue(Type *t, LLValue *v) : DValue(t, v) { - // v may be an addrspace qualified pointer so strip it before doing a pointer - // equality check. - assert(t->toBasetype()->ty == TY::Ttuple || - stripAddrSpaces(v->getType()) == DtoPtrToType(t)); + assert(t->toBasetype()->ty == TY::Ttuple || v->getType()->isPointerTy()); } DRValue *DLValue::getRVal() { @@ -163,11 +160,11 @@ DSpecialRefValue::DSpecialRefValue(Type *t, LLValue *v) : DLValue(v, t) { } DRValue *DSpecialRefValue::getRVal() { - return DLValue(type, DtoLoad(DtoPtrToType(type), val)).getRVal(); + return DLValue(type, DtoLoad(getOpaquePtrType(), val)).getRVal(); } DLValue *DSpecialRefValue::getLVal() { - return new DLValue(type, DtoLoad(DtoPtrToType(type), val)); + return new DLValue(type, DtoLoad(getOpaquePtrType(), val)); } //////////////////////////////////////////////////////////////////////////////// diff --git a/gen/functions.cpp b/gen/functions.cpp index ada3c8141d..55174bb6ac 100644 --- a/gen/functions.cpp +++ b/gen/functions.cpp @@ -279,11 +279,6 @@ llvm::FunctionType *DtoFunctionType(FuncDeclaration *fdecl) { if (AggregateDeclaration *ad = fdecl->isMember2()) { IF_LOG Logger::println("isMember = this is: %s", ad->type->toChars()); dthis = ad->type; - LLType *thisty = DtoType(dthis); - // Logger::cout() << "this llvm type: " << *thisty << '\n'; - if (ad->isStructDeclaration()) { - thisty = getPtrToType(thisty); - } } else { IF_LOG Logger::println("chars: %s type: %s kind: %s", fdecl->toChars(), fdecl->type->toChars(), fdecl->kind()); diff --git a/gen/llvmhelpers.cpp b/gen/llvmhelpers.cpp index 0850aadbb8..85a1f7deea 100644 --- a/gen/llvmhelpers.cpp +++ b/gen/llvmhelpers.cpp @@ -119,13 +119,12 @@ void DtoDeleteInterface(const Loc &loc, DValue *inst) { void DtoDeleteArray(const Loc &loc, DValue *arr) { llvm::Function *fn = getRuntimeFunction(loc, gIR->module, "_d_delarray_t"); - llvm::FunctionType *fty = fn->getFunctionType(); // the TypeInfo argument must be null if the type has no dtor Type *elementType = arr->type->nextOf(); bool hasDtor = (elementType->toBasetype()->ty == TY::Tstruct && elementType->needsDestruction()); - LLValue *typeInfo = !hasDtor ? getNullPtr(fty->getParamType(1)) + LLValue *typeInfo = !hasDtor ? getNullPtr() : DtoTypeInfoOf(loc, elementType); LLValue *lval = (arr->isLVal() ? DtoLVal(arr) : makeLValue(loc, arr)); @@ -478,7 +477,7 @@ DValue *DtoNullValue(Type *type, Loc loc) { // dynamic array if (basety == TY::Tarray) { LLValue *len = DtoConstSize_t(0); - LLValue *ptr = getNullPtr(DtoPtrToType(basetype->nextOf())); + LLValue *ptr = getNullPtr(); return new DSliceValue(type, len, ptr); } error(loc, "`null` not known for type `%s`", type->toChars()); @@ -647,7 +646,7 @@ DValue *DtoCastVector(const Loc &loc, DValue *val, Type *to) { LLValue *vector = DtoLVal(val); IF_LOG Logger::cout() << "src: " << *vector << " to type: " << *tolltype << " (casting address)\n"; - return new DLValue(to, DtoBitCast(vector, getPtrToType(tolltype))); + return new DLValue(to, vector); } LLValue *vector = DtoRVal(val); @@ -900,7 +899,7 @@ void DtoVarDeclaration(VarDeclaration *vd) { bool isRealAlloca = false; LLType *lltype = DtoType(type); // void for noreturn if (lltype->isVoidTy() || gDataLayout->getTypeSizeInBits(lltype) == 0) { - allocainst = llvm::ConstantPointerNull::get(getPtrToType(lltype)); + allocainst = getNullPtr(); } else if (type != vd->type) { allocainst = DtoAlloca(type, vd->toChars()); isRealAlloca = true; @@ -1571,9 +1570,9 @@ DValue *DtoSymbolAddress(const Loc &loc, Type *type, Declaration *decl) { if (tb->ty != TY::Tstruct) { assert(tb->ty == TY::Tarray && tb->nextOf()->ty == TY::Tvoid); const auto size = DtoConstSize_t(ad->structsize); - llvm::Constant *ptr = sd && sd->zeroInit() - ? getNullValue(getVoidPtrType()) - : getIrAggr(ad)->getInitSymbol(); + LLConstant *ptr = sd && sd->zeroInit() + ? static_cast(getNullPtr()) + : getIrAggr(ad)->getInitSymbol(); return new DSliceValue(type, size, ptr); } diff --git a/gen/moduleinfo.cpp b/gen/moduleinfo.cpp index 3763a4554e..f484ff89a5 100644 --- a/gen/moduleinfo.cpp +++ b/gen/moduleinfo.cpp @@ -173,7 +173,8 @@ llvm::Constant *buildImportedModules(Module *m, size_t &count) { if (importInits.empty()) return nullptr; - const auto type = llvm::ArrayType::get(getVoidPtrType(), importInits.size()); + const auto type = + llvm::ArrayType::get(getOpaquePtrType(), importInits.size()); return LLConstantArray::get(type, importInits); } @@ -207,7 +208,8 @@ llvm::Constant *buildLocalClasses(Module *m, size_t &count) { if (classInfoRefs.empty()) return nullptr; - const auto type = llvm::ArrayType::get(getVoidPtrType(), classInfoRefs.size()); + const auto type = + llvm::ArrayType::get(getOpaquePtrType(), classInfoRefs.size()); return LLConstantArray::get(type, classInfoRefs); } } diff --git a/gen/modules.cpp b/gen/modules.cpp index 6d0c3c4a68..67191e1d9b 100644 --- a/gen/modules.cpp +++ b/gen/modules.cpp @@ -136,8 +136,7 @@ LLFunction *build_module_reference_and_ctor(const char *moduleMangle, // provide the default initializer LLStructType *modulerefTy = DtoModuleReferenceType(); - LLConstant *mrefvalues[] = {LLConstant::getNullValue(getVoidPtrType()), - moduleinfo}; + LLConstant *mrefvalues[] = {getNullPtr(), moduleinfo}; LLConstant *thismrefinit = LLConstantStruct::get( modulerefTy, llvm::ArrayRef(mrefvalues)); @@ -149,10 +148,10 @@ LLFunction *build_module_reference_and_ctor(const char *moduleMangle, // make sure _Dmodule_ref is declared const auto mrefIRMangle = getIRMangledVarName("_Dmodule_ref", LINK::c); LLConstant *mref = gIR->module.getNamedGlobal(mrefIRMangle); - LLType *modulerefPtrTy = getVoidPtrType(); + LLType *ptrTy = getOpaquePtrType(); if (!mref) { mref = - declareGlobal(Loc(), gIR->module, modulerefPtrTy, mrefIRMangle, false, + declareGlobal(Loc(), gIR->module, ptrTy, mrefIRMangle, false, false, global.params.dllimport != DLLImport::none); } @@ -166,7 +165,7 @@ LLFunction *build_module_reference_and_ctor(const char *moduleMangle, gIR->DBuilder.EmitModuleCTor(ctor, fname.c_str()); // get current beginning - LLValue *curbeg = builder.CreateLoad(modulerefPtrTy, mref, "current"); + LLValue *curbeg = builder.CreateLoad(ptrTy, mref, "current"); // put current beginning as the next of this one LLValue *gep = builder.CreateStructGEP( diff --git a/gen/ms-cxx-helper.cpp b/gen/ms-cxx-helper.cpp index 71ac41650a..d17cd3c677 100644 --- a/gen/ms-cxx-helper.cpp +++ b/gen/ms-cxx-helper.cpp @@ -142,7 +142,6 @@ bool isCatchSwitchBlock(llvm::BasicBlock *bb) { // routines for constructing the llvm types for MS RTTI structs. llvm::StructType *getTypeDescriptorType(IRState &irs, - llvm::Constant *classInfoPtr, llvm::StringRef TypeInfoString) { llvm::SmallString<256> TDTypeName("rtti.TypeDescriptor"); TDTypeName += llvm::utostr(TypeInfoString.size()); @@ -151,9 +150,10 @@ llvm::StructType *getTypeDescriptorType(IRState &irs, if (TypeDescriptorType) return TypeDescriptorType; auto int8Ty = LLType::getInt8Ty(gIR->context()); + auto ptrTy = getOpaquePtrType(); llvm::Type *FieldTypes[] = { - classInfoPtr->getType(), // CGM.Int8PtrPtrTy, - getPtrToType(int8Ty), // CGM.Int8PtrTy, + ptrTy, // CGM.Int8PtrPtrTy, + ptrTy, // CGM.Int8PtrTy, llvm::ArrayType::get(int8Ty, TypeInfoString.size() + 1)}; TypeDescriptorType = llvm::StructType::create(gIR->context(), FieldTypes, TDTypeName); @@ -163,7 +163,7 @@ llvm::StructType *getTypeDescriptorType(IRState &irs, llvm::GlobalVariable *getTypeDescriptor(IRState &irs, ClassDeclaration *cd) { if (cd->isCPPclass()) { const char *name = target.cpp.typeInfoMangle(cd); - return declareGlobal(cd->loc, irs.module, getVoidPtrType(), name, + return declareGlobal(cd->loc, irs.module, getOpaquePtrType(), name, /*isConstant*/ true, false, /*useDLLImport*/ cd->isExport()); } @@ -185,10 +185,10 @@ llvm::GlobalVariable *getTypeDescriptor(IRState &irs, ClassDeclaration *cd) { // Declare and initialize the TypeDescriptor. llvm::Constant *Fields[] = { classInfoPtr, // VFPtr - llvm::ConstantPointerNull::get(getVoidPtrType()), // Runtime data + getNullPtr(), // Runtime data llvm::ConstantDataArray::getString(gIR->context(), TypeNameString)}; llvm::StructType *TypeDescriptorType = - getTypeDescriptorType(irs, classInfoPtr, TypeNameString); + getTypeDescriptorType(irs, TypeNameString); const LinkageWithCOMDAT lwc = {LLGlobalVariable::LinkOnceODRLinkage, true}; Var = defineGlobal(cd->loc, gIR->module, TypeDescName, diff --git a/gen/ms-cxx-helper.h b/gen/ms-cxx-helper.h index 2eeee75216..dfc6086ad2 100644 --- a/gen/ms-cxx-helper.h +++ b/gen/ms-cxx-helper.h @@ -12,7 +12,6 @@ #include "gen/irstate.h" llvm::StructType *getTypeDescriptorType(IRState &irs, - llvm::Constant *classInfoPtr, llvm::StringRef TypeInfoString); llvm::GlobalVariable *getTypeDescriptor(IRState &irs, ClassDeclaration *cd); diff --git a/gen/nested.cpp b/gen/nested.cpp index 36122e3f4b..0d22b5c071 100644 --- a/gen/nested.cpp +++ b/gen/nested.cpp @@ -82,7 +82,7 @@ DValue *DtoNestedVariable(const Loc &loc, Type *astype, VarDeclaration *vd, if (!fd) { error(loc, "function `%s` cannot access frame of function `%s`", irfunc->decl->toPrettyChars(), vdparent->toPrettyChars()); - return new DLValue(astype, llvm::UndefValue::get(DtoPtrToType(astype))); + return new DLValue(astype, llvm::UndefValue::get(getOpaquePtrType())); } // is the nested variable in this scope? @@ -128,10 +128,7 @@ DValue *DtoNestedVariable(const Loc &loc, Type *astype, VarDeclaration *vd, if (irLocal->nestedIndex == -1) { Logger::println( "WARNING: isn't actually nested, using invalid null storage"); - auto llType = DtoPtrToType(astype); - if (isSpecialRefVar(vd)) - llType = llType->getPointerTo(); - return makeVarDValue(astype, vd, llvm::ConstantPointerNull::get(llType)); + return makeVarDValue(astype, vd, getNullPtr()); } //////////////////////////////////// @@ -254,7 +251,7 @@ LLValue *DtoNestedContext(const Loc &loc, Dsymbol *sym) { if (depth == -1 || (depth == 0 && !symfd->closureVars.empty())) { Logger::println("function does not have context or creates its own " "from scratch, returning null"); - return llvm::ConstantPointerNull::get(getVoidPtrType()); + return getNullPtr(); } } @@ -296,7 +293,7 @@ LLValue *DtoNestedContext(const Loc &loc, Dsymbol *sym) { sym->toPrettyChars(), irFunc.decl->toPrettyChars()); fatal(); } - return llvm::ConstantPointerNull::get(getVoidPtrType()); + return getNullPtr(); } // The symbol may need a parent context of the current function. @@ -528,7 +525,7 @@ void DtoCreateNestedContext(FuncGenState &funcGen) { } if (depth > 1) { DtoMemCpy(frame, src, DtoConstSize_t((depth - 1) * target.ptrsize), - getABITypeAlign(getVoidPtrType())); + getABITypeAlign(getOpaquePtrType())); } // Copy nestArg into framelist; the outer frame is not in the list of // pointers diff --git a/gen/rttibuilder.cpp b/gen/rttibuilder.cpp index a08303aedc..7110af0fa9 100644 --- a/gen/rttibuilder.cpp +++ b/gen/rttibuilder.cpp @@ -59,7 +59,7 @@ void RTTIBuilder::push(llvm::Constant *C) { void RTTIBuilder::push_null(Type *T) { push(getNullValue(DtoType(T))); } -void RTTIBuilder::push_null_vp() { push(getNullValue(getVoidPtrType())); } +void RTTIBuilder::push_null_vp() { push(getNullPtr()); } void RTTIBuilder::push_typeinfo(Type *t) { push(DtoTypeInfoOf(Loc(), t)); } @@ -125,7 +125,7 @@ void RTTIBuilder::push_uint(unsigned u) { push(DtoConstUint(u)); } void RTTIBuilder::push_size(uint64_t s) { push(DtoConstSize_t(s)); } void RTTIBuilder::push_size_as_vp(uint64_t s) { - push(llvm::ConstantExpr::getIntToPtr(DtoConstSize_t(s), getVoidPtrType())); + push(llvm::ConstantExpr::getIntToPtr(DtoConstSize_t(s), getOpaquePtrType())); } void RTTIBuilder::push_funcptr(FuncDeclaration *fd) { diff --git a/gen/tocall.cpp b/gen/tocall.cpp index fc77c5f554..97f5ca9f0c 100644 --- a/gen/tocall.cpp +++ b/gen/tocall.cpp @@ -738,7 +738,9 @@ class ImplicitArgumentsBuilder { // ... or a delegate context arg LLValue *ctxarg; if (fnval->isLVal()) { - ctxarg = DtoLoad(getVoidPtrType(), DtoGEP(DtoType(fnval->type), DtoLVal(fnval), 0u, 0), ".ptr"); + ctxarg = DtoLoad(getOpaquePtrType(), + DtoGEP(DtoType(fnval->type), DtoLVal(fnval), 0u, 0), + ".ptr"); } else { ctxarg = gIR->ir->CreateExtractValue(DtoRVal(fnval), 0, ".ptr"); } @@ -749,7 +751,7 @@ class ImplicitArgumentsBuilder { LLValue *contextptr = DtoNestedContext(loc, dfnval->func); args.push_back(contextptr); } else { - args.push_back(llvm::UndefValue::get(getVoidPtrType())); + args.push_back(llvm::UndefValue::get(getOpaquePtrType())); } } else { error(loc, "Context argument required but none given"); diff --git a/gen/toconstelem.cpp b/gen/toconstelem.cpp index 92f4fddab9..1e7fb936d2 100644 --- a/gen/toconstelem.cpp +++ b/gen/toconstelem.cpp @@ -493,7 +493,7 @@ class ToConstElemVisitor : public Visitor { assert(result); if (fd->tok != TOK::function_) { - auto contextPtr = getNullPtr(getVoidPtrType()); + auto contextPtr = getNullPtr(); result = LLConstantStruct::getAnon(gIR->context(), {contextPtr, result}); } } diff --git a/gen/toir.cpp b/gen/toir.cpp index b53c097fca..3e5181a391 100644 --- a/gen/toir.cpp +++ b/gen/toir.cpp @@ -796,7 +796,7 @@ class ToElemVisitor : public Visitor { if (canEmitVTableUnchangedAssumption && !dfnval->vtable && dfnval->vthis && dfnval->func->isVirtual()) { dfnval->vtable = - DtoLoad(getVoidPtrType(), dfnval->vthis, "saved_vtable"); + DtoLoad(getOpaquePtrType(), dfnval->vthis, "saved_vtable"); } } @@ -2320,8 +2320,7 @@ class ToElemVisitor : public Visitor { // don't allocate storage for zero length dynamic array literals if (dyn && len == 0) { // dmd seems to just make them null... - result = new DSliceValue(e->type, DtoConstSize_t(0), - getNullPtr(getPtrToType(llElemType))); + result = new DSliceValue(e->type, DtoConstSize_t(0), getNullPtr()); return; } diff --git a/gen/tollvm.cpp b/gen/tollvm.cpp index 18e8496d82..90b6385d62 100644 --- a/gen/tollvm.cpp +++ b/gen/tollvm.cpp @@ -187,7 +187,7 @@ LLType *DtoType(Type *t) { // associative arrays case TY::Taarray: - return getVoidPtrType(); + return getOpaquePtrType(); case TY::Tvector: return IrTypeVector::get(t)->getLLType(); @@ -200,8 +200,6 @@ LLType *DtoType(Type *t) { LLType *DtoMemType(Type *t) { return i1ToI8(voidToI8(DtoType(t))); } -LLPointerType *DtoPtrToType(Type *t) { return DtoMemType(t)->getPointerTo(); } - LLType *voidToI8(LLType *t) { return t->isVoidTy() ? LLType::getInt8Ty(t->getContext()) : t; } @@ -440,10 +438,10 @@ void DtoMemCpy(LLType *type, LLValue *dst, LLValue *src, bool withPadding, unsig LLValue *DtoMemCmp(LLValue *lhs, LLValue *rhs, LLValue *nbytes) { // int memcmp ( const void * ptr1, const void * ptr2, size_t num ); - LLType *VoidPtrTy = getVoidPtrType(); LLFunction *fn = gIR->module.getFunction("memcmp"); if (!fn) { - LLType *Tys[] = {VoidPtrTy, VoidPtrTy, DtoSize_t()}; + LLType *ptrTy = getOpaquePtrType(); + LLType *Tys[] = {ptrTy, ptrTy, DtoSize_t()}; LLFunctionType *fty = LLFunctionType::get(LLType::getInt32Ty(gIR->context()), Tys, false); fn = LLFunction::Create(fty, LLGlobalValue::ExternalLinkage, "memcmp", @@ -583,7 +581,7 @@ LLType *stripAddrSpaces(LLType *t) if (!pt) return t; - return getVoidPtrType(); + return getOpaquePtrType(); } LLValue *DtoBitCast(LLValue *v, LLType *t, const llvm::Twine &name) { @@ -689,23 +687,12 @@ llvm::GlobalVariable *isaGlobalVar(LLValue *v) { LLType *getI8Type() { return LLType::getInt8Ty(gIR->context()); } -LLPointerType *getPtrToType(LLType *t) { - if (t == LLType::getVoidTy(gIR->context())) - t = LLType::getInt8Ty(gIR->context()); - return t->getPointerTo(); -} - -LLPointerType *getVoidPtrType() { - return getVoidPtrType(gIR->context()); +LLPointerType *getOpaquePtrType(unsigned addressSpace) { + return LLPointerType::get(gIR->context(), addressSpace); } -LLPointerType *getVoidPtrType(llvm::LLVMContext &C) { - return LLType::getInt8Ty(C)->getPointerTo(); -} - -llvm::ConstantPointerNull *getNullPtr(LLType *t) { - LLPointerType *pt = llvm::cast(t); - return llvm::ConstantPointerNull::get(pt); +llvm::ConstantPointerNull *getNullPtr() { + return llvm::ConstantPointerNull::get(getOpaquePtrType()); } LLConstant *getNullValue(LLType *t) { return LLConstant::getNullValue(t); } @@ -729,16 +716,10 @@ LLStructType *DtoModuleReferenceType() { 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), DtoPtrToType(getModuleInfoType())}; - - // resolve type - st->setBody(types); + auto ptrType = getOpaquePtrType(); + LLType *elems[] = {ptrType, ptrType}; + auto st = LLStructType::get(gIR->context(), elems, "ModuleReference"); - // done gIR->moduleRefType = st; return st; } diff --git a/gen/tollvm.h b/gen/tollvm.h index fc2b9cfa1e..f8e195d2ac 100644 --- a/gen/tollvm.h +++ b/gen/tollvm.h @@ -34,8 +34,6 @@ LLType *DtoType(Type *t); // Uses DtoType(), but promotes i1 and void to i8. LLType *DtoMemType(Type *t); -// Returns a pointer to the type returned by DtoMemType(t). -LLPointerType *DtoPtrToType(Type *t); LLType *voidToI8(LLType *t); LLType *i1ToI8(LLType *t); @@ -150,10 +148,8 @@ LLGlobalVariable *isaGlobalVar(LLValue *v); // llvm::T::get(...) wrappers LLType *getI8Type(); -LLPointerType *getPtrToType(LLType *t); -LLPointerType *getVoidPtrType(); -LLPointerType *getVoidPtrType(llvm::LLVMContext &C); -llvm::ConstantPointerNull *getNullPtr(LLType *t); +LLPointerType *getOpaquePtrType(unsigned addressSpace = 0); +llvm::ConstantPointerNull *getNullPtr(); LLConstant *getNullValue(LLType *t); // type sizes diff --git a/gen/trycatchfinally.cpp b/gen/trycatchfinally.cpp index 59d79213e7..3f982d93a0 100644 --- a/gen/trycatchfinally.cpp +++ b/gen/trycatchfinally.cpp @@ -83,7 +83,7 @@ void TryCatchScope::emitCatchBodies(IRState &irs, llvm::Value *ehPtrSlot) { const auto enterCatchFn = getRuntimeFunction( c->loc, irs.module, isCPPclass ? "__cxa_begin_catch" : "_d_eh_enter_catch"); - const auto ptr = DtoLoad(getVoidPtrType(), ehPtrSlot); + const auto ptr = DtoLoad(getOpaquePtrType(), ehPtrSlot); const auto throwableObj = irs.ir->CreateCall(enterCatchFn, ptr); // For catches that use the Throwable object, create storage for it. @@ -171,7 +171,7 @@ void TryCatchScope::emitCatchBodies(IRState &irs, llvm::Value *ehPtrSlot) { if (!ci) { const char *name = target.cpp.typeInfoMangle(p.cd); auto cpp_ti = declareGlobal( - p.cd->loc, irs.module, getVoidPtrType(), name, + p.cd->loc, irs.module, getOpaquePtrType(), name, /*isConstant*/ true, false, /*useDLLImport*/ p.cd->isExport()); const auto cppTypeInfoPtrType = getCppTypeInfoPtrType(); @@ -230,7 +230,7 @@ void emitBeginCatchMSVC(IRState &irs, Catch *ctch, exnObj = DtoAlloca(ctch->type, "exnObj"); } else { // catch all - exnObj = LLConstant::getNullValue(getVoidPtrType()); + exnObj = getNullPtr(); } bool isCPPclass = false; @@ -242,8 +242,8 @@ void emitBeginCatchMSVC(IRState &irs, Catch *ctch, clssInfo = getIrAggr(cd)->getClassInfoSymbol(); } else { // catch all - typeDesc = LLConstant::getNullValue(getVoidPtrType()); - clssInfo = LLConstant::getNullValue(DtoType(getClassInfoType())); + typeDesc = getNullPtr(); + clssInfo = getNullPtr(); } // "catchpad within %switch [TypeDescriptor, 0, &caughtObject]" must be @@ -662,7 +662,7 @@ TryCatchFinallyScopes::getLandingPadRef(CleanupCursor scope) { namespace { llvm::LandingPadInst *createLandingPadInst(IRState &irs) { - LLType *retType = LLStructType::get(getVoidPtrType(irs.context()), + LLType *retType = LLStructType::get(getOpaquePtrType(), LLType::getInt32Ty(irs.context())); if (!irs.func()->hasLLVMPersonalityFn()) { irs.func()->setLLVMPersonalityFn( @@ -761,7 +761,7 @@ llvm::BasicBlock *TryCatchFinallyScopes::emitLandingPad() { llvm::AllocaInst *TryCatchFinallyScopes::getOrCreateEhPtrSlot() { if (!ehPtrSlot) - ehPtrSlot = DtoRawAlloca(getVoidPtrType(), 0, "eh.ptr"); + ehPtrSlot = DtoRawAlloca(getOpaquePtrType(), 0, "eh.ptr"); return ehPtrSlot; } @@ -773,7 +773,7 @@ llvm::BasicBlock *TryCatchFinallyScopes::getOrCreateResumeUnwindBlock() { irs.ir->SetInsertPoint(resumeUnwindBlock); llvm::Function *resumeFn = getUnwindResumeFunction(Loc(), irs.module); - irs.ir->CreateCall(resumeFn, DtoLoad(getVoidPtrType(), getOrCreateEhPtrSlot())); + irs.ir->CreateCall(resumeFn, DtoLoad(getOpaquePtrType(), getOrCreateEhPtrSlot())); irs.ir->CreateUnreachable(); irs.ir->SetInsertPoint(oldBB); @@ -832,7 +832,7 @@ TryCatchFinallyScopes::runCleanupPad(CleanupCursor scope, // preparation to allocate some space on the stack where _d_enter_cleanup // can place an exception frame (but not done here) - auto frame = getNullPtr(getVoidPtrType()); + auto frame = getNullPtr(); const auto savedInsertPoint = irs.saveInsertPoint(); diff --git a/ir/iraggr.cpp b/ir/iraggr.cpp index d8b0bb1762..482dc027c0 100644 --- a/ir/iraggr.cpp +++ b/ir/iraggr.cpp @@ -204,7 +204,7 @@ IrAggr::createInitializerConstant(const VarInitMap &explicitInitializers) { // add monitor (except for C++ classes) if (!cd->isCPPclass()) { - constants.push_back(getNullValue(getVoidPtrType())); + constants.push_back(getNullPtr()); offset += target.ptrsize; } } diff --git a/ir/irclass.cpp b/ir/irclass.cpp index 34e1ef3d3e..0db3d2039f 100644 --- a/ir/irclass.cpp +++ b/ir/irclass.cpp @@ -189,8 +189,6 @@ LLConstant *IrClass::getVtblInit() { std::vector constants; constants.reserve(cd->vtbl.length); - const auto voidPtrType = getVoidPtrType(); - // start with the classinfo llvm::Constant *c; if (!cd->isCPPclass()) { @@ -198,7 +196,7 @@ LLConstant *IrClass::getVtblInit() { c = getClassInfoSymbol(); } else { // use null if there are no TypeInfos - c = llvm::Constant::getNullValue(voidPtrType); + c = getNullPtr(); } constants.push_back(c); } @@ -213,7 +211,7 @@ LLConstant *IrClass::getVtblInit() { assert(fd && "vtbl entry not a function"); if (cd->isAbstract() || (fd->isAbstract() && !fd->fbody)) { - c = getNullValue(voidPtrType); + c = getNullPtr(); } else { // If inferring return type and semantic3 has not been run, do it now. // This pops up in some other places in the frontend as well, however @@ -224,7 +222,7 @@ LLConstant *IrClass::getVtblInit() { if (fd->hasSemantic3Errors()) { Logger::println( "functionSemantic failed; using null for vtbl entry."); - constants.push_back(getNullValue(voidPtrType)); + constants.push_back(getNullPtr()); continue; } error(fd->loc, @@ -276,7 +274,7 @@ LLConstant *IrClass::getVtblInit() { } // build the constant array - LLArrayType *vtblTy = LLArrayType::get(voidPtrType, constants.size()); + LLArrayType *vtblTy = LLArrayType::get(getOpaquePtrType(), constants.size()); constVtbl = LLConstantArray::get(vtblTy, constants); return constVtbl; @@ -358,9 +356,6 @@ LLConstant *IrClass::getClassInfoInit() { RTTIBuilder b(cinfoType); - LLType *voidPtr = getVoidPtrType(); - LLType *voidPtrPtr = getPtrToType(voidPtr); - // adapted from original dmd code // byte[] m_init if (isInterface) { @@ -378,7 +373,7 @@ LLConstant *IrClass::getClassInfoInit() { // void*[] vtbl if (isInterface) { - b.push_array(0, getNullValue(voidPtrPtr)); + b.push_array(0, getNullPtr()); } else { b.push_array(cd->vtbl.length, getVtblSymbol()); } @@ -474,7 +469,7 @@ llvm::GlobalVariable *IrClass::getInterfaceVtblSymbol(BaseClass *b, gvar = it->second; } else { llvm::Type *vtblType = - LLArrayType::get(getVoidPtrType(), b->sym->vtbl.length); + LLArrayType::get(getOpaquePtrType(), b->sym->vtbl.length); // Thunk prefix char thunkPrefix[16]; @@ -531,8 +526,6 @@ LLConstant *IrClass::getInterfaceVtblInit(BaseClass *b, char thunkPrefix[16]; snprintf(thunkPrefix, 16, "Thn%d_", b->offset); - const auto voidPtrTy = getVoidPtrType(); - if (!b->sym->isCPPinterface()) { // skip interface info for CPP interfaces if (!suppressTypeInfo()) { // index into the interfaces array @@ -546,7 +539,7 @@ LLConstant *IrClass::getInterfaceVtblInit(BaseClass *b, constants.push_back(c); } else { // use null if there are no TypeInfos - constants.push_back(llvm::Constant::getNullValue(voidPtrTy)); + constants.push_back(getNullPtr()); } } @@ -558,7 +551,7 @@ LLConstant *IrClass::getInterfaceVtblInit(BaseClass *b, // FIXME // why is this null? // happens for mini/s.d - constants.push_back(getNullValue(voidPtrTy)); + constants.push_back(getNullPtr()); continue; } @@ -681,7 +674,7 @@ LLConstant *IrClass::getInterfaceVtblInit(BaseClass *b, // build the vtbl constant llvm::Constant *vtbl_constant = LLConstantArray::get( - LLArrayType::get(voidPtrTy, constants.size()), constants); + LLArrayType::get(getOpaquePtrType(), constants.size()), constants); return vtbl_constant; } @@ -749,7 +742,7 @@ LLConstant *IrClass::getClassInfoInterfaces() { LLConstant *vtb; // interface get a null if (cd->isInterfaceDeclaration()) { - vtb = DtoConstSlice(DtoConstSize_t(0), getNullValue(getVoidPtrType())); + vtb = DtoConstSlice(DtoConstSize_t(0), getNullPtr()); } else { vtb = getInterfaceVtblSymbol(it, i); auto vtblSize = itc->getVtblType()->getNumContainedTypes(); diff --git a/ir/irstruct.cpp b/ir/irstruct.cpp index 17bdba4561..1b0f4003c0 100644 --- a/ir/irstruct.cpp +++ b/ir/irstruct.cpp @@ -135,7 +135,7 @@ LLConstant *IrStruct::getTypeInfoInit() { } else { llvm::Constant *initPtr; if (ts->isZeroInit(Loc())) { - initPtr = getNullValue(getVoidPtrType()); + initPtr = getNullPtr(); } else { initPtr = getInitSymbol(); } diff --git a/ir/irtypeclass.cpp b/ir/irtypeclass.cpp index 365be66a1f..e29b746070 100644 --- a/ir/irtypeclass.cpp +++ b/ir/irtypeclass.cpp @@ -24,7 +24,7 @@ IrTypeClass::IrTypeClass(ClassDeclaration *cd) : IrTypeAggr(cd), cd(cd), tc(static_cast(cd->type)) { - vtbl_type = LLArrayType::get(getVoidPtrType(), cd->vtbl.length); + vtbl_type = LLArrayType::get(getOpaquePtrType(), cd->vtbl.length); } void IrTypeClass::addClassData(AggrTypeBuilder &builder, @@ -48,7 +48,7 @@ void IrTypeClass::addClassData(AggrTypeBuilder &builder, // add to the interface map addInterfaceToMap(b->sym, builder.currentFieldIndex()); - auto vtblTy = LLArrayType::get(getVoidPtrType(), b->sym->vtbl.length); + auto vtblTy = LLArrayType::get(getOpaquePtrType(), b->sym->vtbl.length); builder.addType(llvm::PointerType::get(vtblTy, 0), target.ptrsize); ++num_interface_vtbls; @@ -83,7 +83,7 @@ IrTypeClass *IrTypeClass::get(ClassDeclaration *cd) { // classes have monitor and fields if (!cd->isCPPclass() && !cd->isCPPinterface()) { // add monitor - builder.addType(getVoidPtrType(), target.ptrsize); + builder.addType(getOpaquePtrType(), target.ptrsize); } // add data members recursively diff --git a/ir/irtypefunction.cpp b/ir/irtypefunction.cpp index dd124a1c9c..93629b2acf 100644 --- a/ir/irtypefunction.cpp +++ b/ir/irtypefunction.cpp @@ -56,7 +56,7 @@ IrTypeDelegate *IrTypeDelegate::get(Type *t) { llvm::Type *ltf = DtoFunctionType(tf, irFty, nullptr, pointerTo(Type::tvoid)); llvm::Type *fptr = ltf->getPointerTo(gDataLayout->getProgramAddressSpace()); - llvm::Type *types[] = {getVoidPtrType(), fptr}; + llvm::Type *types[] = {getOpaquePtrType(), fptr}; LLStructType *lt = LLStructType::get(gIR->context(), types, false); // Could have already built the type as part of a struct forward reference,