Adapt to new _d_arraycatnTX template lowering

This commit is contained in:
Martin Kinkelin 2023-07-16 13:26:32 +02:00
parent 8e60686bdd
commit 67885a8ef7
3 changed files with 7 additions and 110 deletions

View file

@ -750,105 +750,6 @@ DSliceValue *DtoNewMulDimDynArray(const Loc &loc, Type *arrayType,
////////////////////////////////////////////////////////////////////////////////
static LLValue *DtoSlicePtr(DValue *dval) {
Loc loc;
Type *vt = dval->type->toBasetype();
if (vt->ty == TY::Tarray) {
return makeLValue(loc, dval);
}
bool isStaticArray = vt->ty == TY::Tsarray;
LLValue *val = isStaticArray ? DtoLVal(dval) : makeLValue(loc, dval);
LLStructType *i8arrty = DtoArrayType(LLType::getInt8Ty(gIR->context()));
LLValue *array = DtoRawAlloca(i8arrty, 0, ".array");
LLValue *len = isStaticArray ? DtoArrayLen(dval) : DtoConstSize_t(1);
DtoStore(len, DtoGEP(i8arrty, array, 0u, 0));
DtoStore(DtoBitCast(val, getVoidPtrType()), DtoGEP(i8arrty, array, 0, 1));
return array;
}
static llvm::StructType *DtoSlicePtrType(DValue *dval) {
if(dval->type->toBasetype()->ty == TY::Tarray)
return isaStruct(DtoType(dval->type->toBasetype()));
else
return DtoArrayType(LLType::getInt8Ty(gIR->context()));
}
static LLValue *DtoSlicePtr(Expression *e) {
return DtoSlicePtr(toElem(e));
}
DSliceValue *DtoCatArrays(const Loc &loc, Type *arrayType, Expression *exp1,
Expression *exp2) {
IF_LOG Logger::println("DtoCatArrays");
LOG_SCOPE;
llvm::SmallVector<llvm::Value *, 3> args;
LLFunction *fn = nullptr;
if (auto ce = exp1->isCatExp()) { // handle multiple concat
fn = getRuntimeFunction(loc, gIR->module, "_d_arraycatnTX");
// Create array of slices
typedef llvm::SmallVector<llvm::Value *, 16> ArgVector;
ArgVector arrs;
DValue * dval = toElem(exp2);
arrs.push_back(DtoSlicePtr(dval));
do {
arrs.push_back(DtoSlicePtr(ce->e2));
ce = static_cast<CatExp *>(ce->e1);
} while (ce->op == EXP::concatenate);
arrs.push_back(DtoSlicePtr(ce));
// Create static array from slices
LLPointerType *ptrarraytype = isaPointer(arrs[0]);
assert(ptrarraytype && "Expected pointer type");
LLStructType *arraytype = DtoSlicePtrType(dval);
assert(arraytype && "Expected struct type");
LLArrayType *type = LLArrayType::get(arraytype, arrs.size());
LLValue *array = DtoRawAlloca(type, 0, ".slicearray");
unsigned int i = 0;
for (ArgVector::reverse_iterator I = arrs.rbegin(), E = arrs.rend(); I != E;
++I) {
LLValue *v = DtoLoad(arraytype, DtoBitCast(*I, ptrarraytype));
DtoStore(v, DtoGEP(type, array, 0, i++, ".slice"));
}
LLStructType *type2 = DtoArrayType(arraytype);
LLValue *array2 = DtoRawAlloca(type2, 0, ".array");
DtoStore(DtoConstSize_t(arrs.size()), DtoGEP(type2, array2, 0u, 0, ".len"));
DtoStore(DtoBitCast(array, ptrarraytype), DtoGEP(type2, array2, 0, 1, ".ptr"));
LLType *bytearrarr = DtoArrayType(DtoArrayType(LLType::getInt8Ty(gIR->context())));
LLType *pbytearrarr = getPtrToType(bytearrarr);
LLValue *val = DtoLoad(bytearrarr, DtoBitCast(array2, pbytearrarr));
// TypeInfo ti
args.push_back(DtoTypeInfoOf(loc, arrayType));
// byte[][] arrs
args.push_back(val);
} else {
fn = getRuntimeFunction(loc, gIR->module, "_d_arraycatT");
// TypeInfo ti
args.push_back(DtoTypeInfoOf(loc, arrayType));
auto loadArray = [fn](Expression* e, int paramTypeIdx) {
DValue * dval = toElem(e);
LLValue *val = DtoLoad(DtoSlicePtrType(dval), DtoSlicePtr(dval));
return DtoSlicePaint(val, fn->getFunctionType()->getParamType(paramTypeIdx));
};
// byte[] x
args.push_back(loadArray(exp1,1));
// byte[] y
args.push_back(loadArray(exp2,2));
}
auto newArray = gIR->CreateCallOrInvoke(fn, args, ".appendedArray");
return getSlice(arrayType, newArray);
}
////////////////////////////////////////////////////////////////////////////////
DSliceValue *DtoAppendDChar(const Loc &loc, DValue *arr, Expression *exp,
const char *func) {
LLValue *valueToAppend = DtoRVal(exp);