Replace getVoidPtrType()

This commit is contained in:
Martin Kinkelin 2024-07-18 23:08:43 +02:00
parent f2fe3f51e5
commit 0c1623c1a0
19 changed files with 64 additions and 77 deletions

View file

@ -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");

View file

@ -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<LLType *> 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; }
parts.push_back(pointerType); // void* overflow_arg_area;
parts.push_back(pointerType); // void* reg_save_area; }
return LLStructType::get(gIR->context(), parts);
}

View file

@ -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);
}

View file

@ -1570,8 +1570,8 @@ 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())
LLConstant *ptr = sd && sd->zeroInit()
? static_cast<LLConstant *>(getNullPtr())
: getIrAggr(ad)->getInitSymbol();
return new DSliceValue(type, size, ptr);
}

View file

@ -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);
}
}

View file

@ -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<LLConstant *>(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(

View file

@ -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,7 +185,7 @@ 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, TypeNameString);

View file

@ -251,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();
}
}
@ -293,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.
@ -525,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

View file

@ -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) {

View file

@ -738,7 +738,9 @@ private:
// ... 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 @@ private:
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");

View file

@ -795,7 +795,7 @@ public:
if (canEmitVTableUnchangedAssumption && !dfnval->vtable &&
dfnval->vthis && dfnval->func->isVirtual()) {
dfnval->vtable =
DtoLoad(getVoidPtrType(), dfnval->vthis, "saved_vtable");
DtoLoad(getOpaquePtrType(), dfnval->vthis, "saved_vtable");
}
}

View file

@ -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();
@ -438,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",
@ -581,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) {
@ -691,14 +691,6 @@ LLPointerType *getOpaquePtrType(unsigned addressSpace) {
return LLPointerType::get(gIR->context(), addressSpace);
}
LLPointerType *getVoidPtrType() {
return getVoidPtrType(gIR->context());
}
LLPointerType *getVoidPtrType(llvm::LLVMContext &C) {
return LLType::getInt8Ty(C)->getPointerTo();
}
llvm::ConstantPointerNull *getNullPtr() {
return llvm::ConstantPointerNull::get(getOpaquePtrType());
}

View file

@ -149,8 +149,6 @@ LLGlobalVariable *isaGlobalVar(LLValue *v);
// llvm::T::get(...) wrappers
LLType *getI8Type();
LLPointerType *getOpaquePtrType(unsigned addressSpace = 0);
LLPointerType *getVoidPtrType();
LLPointerType *getVoidPtrType(llvm::LLVMContext &C);
llvm::ConstantPointerNull *getNullPtr();
LLConstant *getNullValue(LLType *t);

View file

@ -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);

View file

@ -203,7 +203,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;
}
}

View file

@ -189,8 +189,6 @@ LLConstant *IrClass::getVtblInit() {
std::vector<llvm::Constant *> 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;
@ -471,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];
@ -528,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
@ -543,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());
}
}
@ -555,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;
}
@ -678,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;
}
@ -746,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();

View file

@ -135,7 +135,7 @@ LLConstant *IrStruct::getTypeInfoInit() {
} else {
llvm::Constant *initPtr;
if (ts->isZeroInit(Loc())) {
initPtr = getNullValue(getVoidPtrType());
initPtr = getNullPtr();
} else {
initPtr = getInitSymbol();
}

View file

@ -24,7 +24,7 @@
IrTypeClass::IrTypeClass(ClassDeclaration *cd)
: IrTypeAggr(cd), cd(cd), tc(static_cast<TypeClass *>(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

View file

@ -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,