DtoTypeInfoOf(): Make Loc param mandatory and move to 1st position

This commit is contained in:
Martin Kinkelin 2020-12-13 15:15:37 +01:00
parent a9aafac862
commit d3574b9835
9 changed files with 35 additions and 35 deletions

View file

@ -25,11 +25,11 @@
#include "ir/irmodule.h" #include "ir/irmodule.h"
// returns the keytype typeinfo // returns the keytype typeinfo
static LLConstant *to_keyti(DValue *aa, LLType *targetType) { static LLConstant *to_keyti(const Loc &loc, DValue *aa, LLType *targetType) {
// keyti param // keyti param
assert(aa->type->toBasetype()->ty == Taarray); assert(aa->type->toBasetype()->ty == Taarray);
TypeAArray *aatype = static_cast<TypeAArray *>(aa->type->toBasetype()); TypeAArray *aatype = static_cast<TypeAArray *>(aa->type->toBasetype());
LLConstant *ti = DtoTypeInfoOf(aatype->index, /*base=*/false); LLConstant *ti = DtoTypeInfoOf(loc, aatype->index, /*base=*/false);
return DtoBitCast(ti, targetType); return DtoBitCast(ti, targetType);
} }
@ -61,13 +61,13 @@ DLValue *DtoAAIndex(const Loc &loc, Type *type, DValue *aa, DValue *key,
LLValue *ret; LLValue *ret;
if (lvalue) { if (lvalue) {
LLValue *rawAATI = LLValue *rawAATI =
DtoTypeInfoOf(aa->type->unSharedOf()->mutableOf(), /*base=*/false, loc); DtoTypeInfoOf(loc, aa->type->unSharedOf()->mutableOf(), /*base=*/false);
LLValue *castedAATI = DtoBitCast(rawAATI, funcTy->getParamType(1)); LLValue *castedAATI = DtoBitCast(rawAATI, funcTy->getParamType(1));
LLValue *valsize = DtoConstSize_t(getTypeAllocSize(DtoType(type))); LLValue *valsize = DtoConstSize_t(getTypeAllocSize(DtoType(type)));
ret = gIR->CreateCallOrInvoke(func, aaval, castedAATI, valsize, pkey, ret = gIR->CreateCallOrInvoke(func, aaval, castedAATI, valsize, pkey,
"aa.index"); "aa.index");
} else { } else {
LLValue *keyti = to_keyti(aa, funcTy->getParamType(1)); LLValue *keyti = to_keyti(loc, aa, funcTy->getParamType(1));
ret = gIR->CreateCallOrInvoke(func, aaval, keyti, pkey, "aa.index"); ret = gIR->CreateCallOrInvoke(func, aaval, keyti, pkey, "aa.index");
} }
@ -125,7 +125,7 @@ DValue *DtoAAIn(const Loc &loc, Type *type, DValue *aa, DValue *key) {
aaval = DtoBitCast(aaval, funcTy->getParamType(0)); aaval = DtoBitCast(aaval, funcTy->getParamType(0));
// keyti param // keyti param
LLValue *keyti = to_keyti(aa, funcTy->getParamType(1)); LLValue *keyti = to_keyti(loc, aa, funcTy->getParamType(1));
// pkey param // pkey param
LLValue *pkey = makeLValue(loc, key); LLValue *pkey = makeLValue(loc, key);
@ -169,7 +169,7 @@ DValue *DtoAARemove(const Loc &loc, DValue *aa, DValue *key) {
aaval = DtoBitCast(aaval, funcTy->getParamType(0)); aaval = DtoBitCast(aaval, funcTy->getParamType(0));
// keyti param // keyti param
LLValue *keyti = to_keyti(aa, funcTy->getParamType(1)); LLValue *keyti = to_keyti(loc, aa, funcTy->getParamType(1));
// pkey param // pkey param
LLValue *pkey = makeLValue(loc, key); LLValue *pkey = makeLValue(loc, key);
@ -192,7 +192,7 @@ LLValue *DtoAAEquals(const Loc &loc, TOK op, DValue *l, DValue *r) {
LLValue *aaval = DtoBitCast(DtoRVal(l), funcTy->getParamType(1)); LLValue *aaval = DtoBitCast(DtoRVal(l), funcTy->getParamType(1));
LLValue *abval = DtoBitCast(DtoRVal(r), funcTy->getParamType(2)); LLValue *abval = DtoBitCast(DtoRVal(r), funcTy->getParamType(2));
LLValue *aaTypeInfo = DtoTypeInfoOf(t, /*base=*/true, loc); LLValue *aaTypeInfo = DtoTypeInfoOf(loc, t);
LLValue *res = LLValue *res =
gIR->CreateCallOrInvoke(func, aaTypeInfo, aaval, abval, "aaEqRes"); gIR->CreateCallOrInvoke(func, aaTypeInfo, aaval, abval, "aaEqRes");

View file

@ -294,17 +294,16 @@ void DtoArrayAssign(const Loc &loc, DValue *lhs, DValue *rhs, int op,
} }
} else if (isConstructing) { } else if (isConstructing) {
LLFunction *fn = getRuntimeFunction(loc, gIR->module, "_d_arrayctor"); LLFunction *fn = getRuntimeFunction(loc, gIR->module, "_d_arrayctor");
gIR->CreateCallOrInvoke(fn, DtoTypeInfoOf(elemType, /*base=*/true, loc), gIR->CreateCallOrInvoke(fn, DtoTypeInfoOf(loc, elemType),
DtoSlice(rhsPtr, rhsLength), DtoSlice(rhsPtr, rhsLength),
DtoSlice(lhsPtr, lhsLength)); DtoSlice(lhsPtr, lhsLength));
} else // assigning } else { // assigning
{
LLValue *tmpSwap = DtoAlloca(elemType, "arrayAssign.tmpSwap"); LLValue *tmpSwap = DtoAlloca(elemType, "arrayAssign.tmpSwap");
LLFunction *fn = getRuntimeFunction( LLFunction *fn = getRuntimeFunction(
loc, gIR->module, loc, gIR->module,
!canSkipPostblit ? "_d_arrayassign_l" : "_d_arrayassign_r"); !canSkipPostblit ? "_d_arrayassign_l" : "_d_arrayassign_r");
gIR->CreateCallOrInvoke( gIR->CreateCallOrInvoke(
fn, DtoTypeInfoOf(elemType, /*base=*/true, loc), DtoSlice(rhsPtr, rhsLength), fn, DtoTypeInfoOf(loc, elemType), DtoSlice(rhsPtr, rhsLength),
DtoSlice(lhsPtr, lhsLength), DtoBitCast(tmpSwap, getVoidPtrType())); DtoSlice(lhsPtr, lhsLength), DtoBitCast(tmpSwap, getVoidPtrType()));
} }
} else { } else {
@ -338,7 +337,7 @@ void DtoArrayAssign(const Loc &loc, DValue *lhs, DValue *rhs, int op,
fn, lhsPtr, DtoBitCast(makeLValue(loc, rhs), getVoidPtrType()), fn, lhsPtr, DtoBitCast(makeLValue(loc, rhs), getVoidPtrType()),
gIR->ir->CreateTruncOrBitCast(lhsLength, gIR->ir->CreateTruncOrBitCast(lhsLength,
LLType::getInt32Ty(gIR->context())), LLType::getInt32Ty(gIR->context())),
DtoTypeInfoOf(stripModifiers(t2), /*base=*/true, loc)); DtoTypeInfoOf(loc, stripModifiers(t2)));
} }
} }
} }
@ -694,7 +693,7 @@ DSliceValue *DtoNewDynArray(const Loc &loc, Type *arrayType, DValue *dim,
LLFunction *fn = getRuntimeFunction(loc, gIR->module, fnname); LLFunction *fn = getRuntimeFunction(loc, gIR->module, fnname);
// typeinfo arg // typeinfo arg
LLValue *arrayTypeInfo = DtoTypeInfoOf(arrayType, /*base=*/true, loc); LLValue *arrayTypeInfo = DtoTypeInfoOf(loc, arrayType);
// dim arg // dim arg
assert(DtoType(dim->type) == DtoSize_t()); assert(DtoType(dim->type) == DtoSize_t());
@ -728,7 +727,7 @@ DSliceValue *DtoNewMulDimDynArray(const Loc &loc, Type *arrayType,
LLFunction *fn = getRuntimeFunction(loc, gIR->module, fnname); LLFunction *fn = getRuntimeFunction(loc, gIR->module, fnname);
// typeinfo arg // typeinfo arg
LLValue *arrayTypeInfo = DtoTypeInfoOf(arrayType, /*base=*/true, loc); LLValue *arrayTypeInfo = DtoTypeInfoOf(loc, arrayType);
// Check if constant // Check if constant
bool allDimsConst = true; bool allDimsConst = true;
@ -799,7 +798,7 @@ DSliceValue *DtoResizeDynArray(const Loc &loc, Type *arrayType, DValue *array,
: "_d_arraysetlengthiT"); : "_d_arraysetlengthiT");
LLValue *newArray = gIR->CreateCallOrInvoke( LLValue *newArray = gIR->CreateCallOrInvoke(
fn, DtoTypeInfoOf(arrayType, /*base=*/true, loc), newdim, fn, DtoTypeInfoOf(loc, arrayType), newdim,
DtoBitCast(DtoLVal(array), fn->getFunctionType()->getParamType(2)), DtoBitCast(DtoLVal(array), fn->getFunctionType()->getParamType(2)),
".gc_mem"); ".gc_mem");
@ -823,7 +822,7 @@ void DtoCatAssignElement(const Loc &loc, DValue *array, Expression *exp) {
// potentially moved to a new block). // potentially moved to a new block).
LLFunction *fn = getRuntimeFunction(loc, gIR->module, "_d_arrayappendcTX"); LLFunction *fn = getRuntimeFunction(loc, gIR->module, "_d_arrayappendcTX");
gIR->CreateCallOrInvoke( gIR->CreateCallOrInvoke(
fn, DtoTypeInfoOf(arrayType, /*base=*/true, loc), fn, DtoTypeInfoOf(loc, arrayType),
DtoBitCast(DtoLVal(array), fn->getFunctionType()->getParamType(1)), DtoBitCast(DtoLVal(array), fn->getFunctionType()->getParamType(1)),
DtoConstSize_t(1), ".appendedArray"); DtoConstSize_t(1), ".appendedArray");
@ -848,7 +847,7 @@ DSliceValue *DtoCatAssignArray(const Loc &loc, DValue *arr, Expression *exp) {
LLFunction *fn = getRuntimeFunction(loc, gIR->module, "_d_arrayappendT"); LLFunction *fn = getRuntimeFunction(loc, gIR->module, "_d_arrayappendT");
// Call _d_arrayappendT(TypeInfo ti, byte[] *px, byte[] y) // Call _d_arrayappendT(TypeInfo ti, byte[] *px, byte[] y)
LLValue *newArray = gIR->CreateCallOrInvoke( LLValue *newArray = gIR->CreateCallOrInvoke(
fn, DtoTypeInfoOf(arrayType, /*base=*/true, loc), fn, DtoTypeInfoOf(loc, arrayType),
DtoBitCast(DtoLVal(arr), fn->getFunctionType()->getParamType(1)), DtoBitCast(DtoLVal(arr), fn->getFunctionType()->getParamType(1)),
DtoAggrPaint(DtoSlice(exp), fn->getFunctionType()->getParamType(2)), DtoAggrPaint(DtoSlice(exp), fn->getFunctionType()->getParamType(2)),
".appendedArray"); ".appendedArray");
@ -902,14 +901,14 @@ DSliceValue *DtoCatArrays(const Loc &loc, Type *arrayType, Expression *exp1,
LLType::getInt8Ty(gIR->context())))))); LLType::getInt8Ty(gIR->context()))))));
// TypeInfo ti // TypeInfo ti
args.push_back(DtoTypeInfoOf(arrayType, /*base=*/true, loc)); args.push_back(DtoTypeInfoOf(loc, arrayType));
// byte[][] arrs // byte[][] arrs
args.push_back(val); args.push_back(val);
} else { } else {
fn = getRuntimeFunction(loc, gIR->module, "_d_arraycatT"); fn = getRuntimeFunction(loc, gIR->module, "_d_arraycatT");
// TypeInfo ti // TypeInfo ti
args.push_back(DtoTypeInfoOf(arrayType, /*base=*/true, loc)); args.push_back(DtoTypeInfoOf(loc, arrayType));
// byte[] x // byte[] x
LLValue *val = DtoLoad(DtoSlicePtr(exp1)); LLValue *val = DtoLoad(DtoSlicePtr(exp1));
val = DtoAggrPaint(val, fn->getFunctionType()->getParamType(1)); val = DtoAggrPaint(val, fn->getFunctionType()->getParamType(1));
@ -987,7 +986,7 @@ LLValue *DtoArrayEqCmp_impl(const Loc &loc, const char *func, DValue *l,
// pass array typeinfo ? // pass array typeinfo ?
if (useti) { if (useti) {
LLValue *tival = DtoTypeInfoOf(l->type, /*base=*/true, loc); LLValue *tival = DtoTypeInfoOf(loc, l->type);
args.push_back(DtoBitCast(tival, fn->getFunctionType()->getParamType(2))); args.push_back(DtoBitCast(tival, fn->getFunctionType()->getParamType(2)));
} }

View file

@ -82,7 +82,7 @@ LLValue *DtoNew(const Loc &loc, Type *newtype) {
// get runtime function // get runtime function
llvm::Function *fn = getRuntimeFunction(loc, gIR->module, "_d_allocmemoryT"); llvm::Function *fn = getRuntimeFunction(loc, gIR->module, "_d_allocmemoryT");
// get type info // get type info
LLConstant *ti = DtoTypeInfoOf(newtype, /*base=*/true, loc); LLConstant *ti = DtoTypeInfoOf(loc, newtype);
assert(isaPointer(ti)); assert(isaPointer(ti));
// call runtime allocator // call runtime allocator
LLValue *mem = gIR->CreateCallOrInvoke(fn, ti, ".gc_mem"); LLValue *mem = gIR->CreateCallOrInvoke(fn, ti, ".gc_mem");
@ -94,7 +94,7 @@ LLValue *DtoNewStruct(const Loc &loc, TypeStruct *newtype) {
llvm::Function *fn = getRuntimeFunction( llvm::Function *fn = getRuntimeFunction(
loc, gIR->module, loc, gIR->module,
newtype->isZeroInit(newtype->sym->loc) ? "_d_newitemT" : "_d_newitemiT"); newtype->isZeroInit(newtype->sym->loc) ? "_d_newitemT" : "_d_newitemiT");
LLConstant *ti = DtoTypeInfoOf(newtype, /*base=*/true, loc); LLConstant *ti = DtoTypeInfoOf(loc, newtype);
LLValue *mem = gIR->CreateCallOrInvoke(fn, ti, ".gc_struct"); LLValue *mem = gIR->CreateCallOrInvoke(fn, ti, ".gc_struct");
return DtoBitCast(mem, DtoPtrToType(newtype), ".gc_struct"); return DtoBitCast(mem, DtoPtrToType(newtype), ".gc_struct");
} }
@ -111,7 +111,7 @@ void DtoDeleteStruct(const Loc &loc, DValue *ptr) {
LLValue *lval = (ptr->isLVal() ? DtoLVal(ptr) : makeLValue(loc, ptr)); LLValue *lval = (ptr->isLVal() ? DtoLVal(ptr) : makeLValue(loc, ptr));
gIR->CreateCallOrInvoke( gIR->CreateCallOrInvoke(
fn, DtoBitCast(lval, fn->getFunctionType()->getParamType(0)), fn, DtoBitCast(lval, fn->getFunctionType()->getParamType(0)),
DtoBitCast(DtoTypeInfoOf(ptr->type->nextOf(), /*base=*/true, loc), DtoBitCast(DtoTypeInfoOf(loc, ptr->type->nextOf()),
fn->getFunctionType()->getParamType(1))); fn->getFunctionType()->getParamType(1)));
} }
@ -137,8 +137,8 @@ void DtoDeleteArray(const Loc &loc, DValue *arr) {
Type *elementType = arr->type->nextOf(); Type *elementType = arr->type->nextOf();
bool hasDtor = (elementType->toBasetype()->ty == Tstruct && bool hasDtor = (elementType->toBasetype()->ty == Tstruct &&
elementType->needsDestruction()); elementType->needsDestruction());
LLValue *typeInfo = (!hasDtor ? getNullPtr(fty->getParamType(1)) LLValue *typeInfo = !hasDtor ? getNullPtr(fty->getParamType(1))
: DtoTypeInfoOf(elementType, /*base=*/true, loc)); : DtoTypeInfoOf(loc, elementType);
LLValue *lval = (arr->isLVal() ? DtoLVal(arr) : makeLValue(loc, arr)); LLValue *lval = (arr->isLVal() ? DtoLVal(arr) : makeLValue(loc, arr));
gIR->CreateCallOrInvoke(fn, DtoBitCast(lval, fty->getParamType(0)), gIR->CreateCallOrInvoke(fn, DtoBitCast(lval, fty->getParamType(0)),
@ -1192,7 +1192,7 @@ LLConstant *DtoConstExpInit(const Loc &loc, Type *targetType, Expression *exp) {
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
LLConstant *DtoTypeInfoOf(Type *type, bool base, const Loc &loc) { LLConstant *DtoTypeInfoOf(const Loc &loc, Type *type, bool base) {
IF_LOG Logger::println("DtoTypeInfoOf(type = '%s', base='%d')", IF_LOG Logger::println("DtoTypeInfoOf(type = '%s', base='%d')",
type->toChars(), base); type->toChars(), base);
LOG_SCOPE LOG_SCOPE

View file

@ -126,7 +126,7 @@ LLConstant *DtoConstInitializer(const Loc &loc, Type *type,
LLConstant *DtoConstExpInit(const Loc &loc, Type *targetType, Expression *exp); LLConstant *DtoConstExpInit(const Loc &loc, Type *targetType, Expression *exp);
// getting typeinfo of type, base=true casts to object.TypeInfo // getting typeinfo of type, base=true casts to object.TypeInfo
LLConstant *DtoTypeInfoOf(Type *type, bool base = true, const Loc &loc = Loc()); LLConstant *DtoTypeInfoOf(const Loc &loc, Type *type, bool base = true);
// target stuff // target stuff
void findDefaultTarget(); void findDefaultTarget();

View file

@ -62,7 +62,7 @@ void RTTIBuilder::push_null(Type *T) { push(getNullValue(DtoType(T))); }
void RTTIBuilder::push_null_vp() { push(getNullValue(getVoidPtrType())); } void RTTIBuilder::push_null_vp() { push(getNullValue(getVoidPtrType())); }
void RTTIBuilder::push_typeinfo(Type *t) { push(DtoTypeInfoOf(t)); } void RTTIBuilder::push_typeinfo(Type *t) { push(DtoTypeInfoOf(Loc(), t)); }
void RTTIBuilder::push_string(const char *str) { push(DtoConstString(str)); } void RTTIBuilder::push_string(const char *str) { push(DtoConstString(str)); }

View file

@ -250,7 +250,8 @@ static LLValue *getTypeinfoArrayArgumentForDVarArg(Expressions *argexps,
std::vector<LLConstant *> vtypeinfos; std::vector<LLConstant *> vtypeinfos;
vtypeinfos.reserve(numVariadicArgs); vtypeinfos.reserve(numVariadicArgs);
for (size_t i = begin; i < numArgExps; i++) { for (size_t i = begin; i < numArgExps; i++) {
vtypeinfos.push_back(DtoTypeInfoOf((*argexps)[i]->type, /*base=*/true, (*argexps)[i]->loc)); Expression *argExp = (*argexps)[i];
vtypeinfos.push_back(DtoTypeInfoOf(argExp->loc, argExp->type));
} }
// apply initializer // apply initializer

View file

@ -82,7 +82,7 @@ public:
} }
if (TypeInfoDeclaration *ti = e->var->isTypeInfoDeclaration()) { if (TypeInfoDeclaration *ti = e->var->isTypeInfoDeclaration()) {
result = DtoTypeInfoOf(ti->tinfo, false, e->loc); result = DtoTypeInfoOf(e->loc, ti->tinfo, /*base=*/false);
result = DtoBitCast(result, DtoType(e->type)); result = DtoBitCast(result, DtoType(e->type));
return; return;
} }
@ -685,7 +685,7 @@ public:
return; return;
} }
result = DtoTypeInfoOf(t, /*base=*/false, e->loc); result = DtoTypeInfoOf(e->loc, t, /*base=*/false);
result = DtoBitCast(result, DtoType(e->type)); result = DtoBitCast(result, DtoType(e->type));
} }

View file

@ -2402,9 +2402,9 @@ public:
llvm::Function *func = llvm::Function *func =
getRuntimeFunction(e->loc, gIR->module, "_d_assocarrayliteralTX"); getRuntimeFunction(e->loc, gIR->module, "_d_assocarrayliteralTX");
LLFunctionType *funcTy = func->getFunctionType(); LLFunctionType *funcTy = func->getFunctionType();
LLValue *aaTypeInfo = LLValue *aaTypeInfo = DtoBitCast(
DtoBitCast(DtoTypeInfoOf(stripModifiers(aatype), /*base=*/false, e->loc), DtoTypeInfoOf(e->loc, stripModifiers(aatype), /*base=*/false),
DtoType(getAssociativeArrayTypeInfoType())); DtoType(getAssociativeArrayTypeInfoType()));
LLConstant *idxs[2] = {DtoConstUint(0), DtoConstUint(0)}; LLConstant *idxs[2] = {DtoConstUint(0), DtoConstUint(0)};

View file

@ -314,7 +314,7 @@ public:
LLType *tiTy = DtoType(getTypeInfoType()); LLType *tiTy = DtoType(getTypeInfoType());
for (auto arg : *tu->arguments) { for (auto arg : *tu->arguments) {
arrInits.push_back(DtoTypeInfoOf(arg->type)); arrInits.push_back(DtoTypeInfoOf(decl->loc, arg->type));
} }
// build array // build array