mirror of
https://github.com/ldc-developers/ldc.git
synced 2025-05-05 01:20:51 +03:00
Adapt to new multi-dimensional array allocation lowering
Fixes runnable/test28.d.
This commit is contained in:
parent
8c99f6a3ee
commit
a3aadfcce8
4 changed files with 4 additions and 85 deletions
|
@ -679,74 +679,6 @@ DSliceValue *DtoNewDynArray(const Loc &loc, Type *arrayType, DValue *dim,
|
||||||
return new DSliceValue(arrayType, arrayLen, ptr);
|
return new DSliceValue(arrayType, arrayLen, ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
DSliceValue *DtoNewMulDimDynArray(const Loc &loc, Type *arrayType,
|
|
||||||
DValue **dims, size_t ndims) {
|
|
||||||
IF_LOG Logger::println("DtoNewMulDimDynArray : %s", arrayType->toChars());
|
|
||||||
LOG_SCOPE;
|
|
||||||
|
|
||||||
// get value type
|
|
||||||
Type *vtype = arrayType->toBasetype();
|
|
||||||
for (size_t i = 0; i < ndims; ++i) {
|
|
||||||
vtype = vtype->nextOf();
|
|
||||||
}
|
|
||||||
|
|
||||||
// get runtime function
|
|
||||||
const char *fnname =
|
|
||||||
vtype->isZeroInit() ? "_d_newarraymTX" : "_d_newarraymiTX";
|
|
||||||
LLFunction *fn = getRuntimeFunction(loc, gIR->module, fnname);
|
|
||||||
|
|
||||||
// typeinfo arg
|
|
||||||
LLValue *arrayTypeInfo = DtoTypeInfoOf(loc, arrayType);
|
|
||||||
|
|
||||||
// Check if constant
|
|
||||||
bool allDimsConst = true;
|
|
||||||
for (size_t i = 0; i < ndims; ++i) {
|
|
||||||
if (!isaConstant(DtoRVal(dims[i]))) {
|
|
||||||
allDimsConst = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// build dims
|
|
||||||
LLValue *array;
|
|
||||||
if (allDimsConst) {
|
|
||||||
// Build constant array for dimensions
|
|
||||||
std::vector<LLConstant *> argsdims;
|
|
||||||
argsdims.reserve(ndims);
|
|
||||||
for (size_t i = 0; i < ndims; ++i) {
|
|
||||||
argsdims.push_back(isaConstant(DtoRVal(dims[i])));
|
|
||||||
}
|
|
||||||
|
|
||||||
llvm::Constant *dims = llvm::ConstantArray::get(
|
|
||||||
llvm::ArrayType::get(DtoSize_t(), ndims), argsdims);
|
|
||||||
auto gvar = new llvm::GlobalVariable(gIR->module, dims->getType(), true,
|
|
||||||
LLGlobalValue::InternalLinkage, dims,
|
|
||||||
".dimsarray");
|
|
||||||
array = llvm::ConstantExpr::getBitCast(gvar, getPtrToType(dims->getType()));
|
|
||||||
} else {
|
|
||||||
// Build static array for dimensions
|
|
||||||
LLArrayType *type = LLArrayType::get(DtoSize_t(), ndims);
|
|
||||||
array = DtoRawAlloca(type, 0, ".dimarray");
|
|
||||||
for (size_t i = 0; i < ndims; ++i) {
|
|
||||||
DtoStore(DtoRVal(dims[i]), DtoGEP(type, array, 0, i, ".ndim"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
LLStructType *dtype = DtoArrayType(DtoSize_t());
|
|
||||||
LLValue *darray = DtoRawAlloca(dtype, 0, ".array");
|
|
||||||
DtoStore(DtoConstSize_t(ndims), DtoGEP(dtype, darray, 0u, 0, ".len"));
|
|
||||||
DtoStore(DtoBitCast(array, getPtrToType(DtoSize_t())),
|
|
||||||
DtoGEP(dtype, darray, 0, 1, ".ptr"));
|
|
||||||
|
|
||||||
// call allocator
|
|
||||||
LLValue *newptr =
|
|
||||||
gIR->CreateCallOrInvoke(fn, arrayTypeInfo, DtoLoad(dtype, darray), ".gc_mem");
|
|
||||||
|
|
||||||
IF_LOG Logger::cout() << "final ptr = " << *newptr << '\n';
|
|
||||||
|
|
||||||
return getSlice(arrayType, newptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
DSliceValue *DtoAppendDChar(const Loc &loc, DValue *arr, Expression *exp,
|
DSliceValue *DtoAppendDChar(const Loc &loc, DValue *arr, Expression *exp,
|
||||||
|
|
|
@ -62,8 +62,6 @@ void DtoSetArrayToNull(DValue *v);
|
||||||
|
|
||||||
DSliceValue *DtoNewDynArray(const Loc &loc, Type *arrayType, DValue *dim,
|
DSliceValue *DtoNewDynArray(const Loc &loc, Type *arrayType, DValue *dim,
|
||||||
bool defaultInit = true);
|
bool defaultInit = true);
|
||||||
DSliceValue *DtoNewMulDimDynArray(const Loc &loc, Type *arrayType,
|
|
||||||
DValue **dims, size_t ndims);
|
|
||||||
|
|
||||||
DSliceValue *DtoCatArrays(const Loc &loc, Type *type, Expression *e1,
|
DSliceValue *DtoCatArrays(const Loc &loc, Type *type, Expression *e1,
|
||||||
Expression *e2);
|
Expression *e2);
|
||||||
|
|
|
@ -84,12 +84,10 @@ static void checkForImplicitGCCall(const Loc &loc, const char *name) {
|
||||||
"_d_delmemory",
|
"_d_delmemory",
|
||||||
"_d_newarrayT",
|
"_d_newarrayT",
|
||||||
"_d_newarrayiT",
|
"_d_newarrayiT",
|
||||||
"_d_newarraymTX",
|
|
||||||
"_d_newarraymiTX",
|
|
||||||
"_d_newarrayU",
|
"_d_newarrayU",
|
||||||
"_d_newclass",
|
"_d_newclass",
|
||||||
"_d_allocclass",
|
"_d_allocclass",
|
||||||
// TODO: _d_newitemT instantiations
|
// TODO: _d_newitemT and _d_newarraymTX instantiations
|
||||||
};
|
};
|
||||||
|
|
||||||
if (binary_search(&GCNAMES[0],
|
if (binary_search(&GCNAMES[0],
|
||||||
|
@ -601,11 +599,6 @@ static void buildRuntimeModule() {
|
||||||
{"_d_newarrayT", "_d_newarrayiT", "_d_newarrayU"},
|
{"_d_newarrayT", "_d_newarrayiT", "_d_newarrayU"},
|
||||||
{typeInfoTy, sizeTy}, {STCconst, 0});
|
{typeInfoTy, sizeTy}, {STCconst, 0});
|
||||||
|
|
||||||
// void[] _d_newarraymTX (const TypeInfo ti, size_t[] dims)
|
|
||||||
// void[] _d_newarraymiTX(const TypeInfo ti, size_t[] dims)
|
|
||||||
createFwdDecl(LINK::c, voidArrayTy, {"_d_newarraymTX", "_d_newarraymiTX"},
|
|
||||||
{typeInfoTy, sizeTy->arrayOf()}, {STCconst, 0});
|
|
||||||
|
|
||||||
// void[] _d_arrayappendcd(ref byte[] x, dchar c)
|
// void[] _d_arrayappendcd(ref byte[] x, dchar c)
|
||||||
// void[] _d_arrayappendwd(ref byte[] x, dchar c)
|
// void[] _d_arrayappendwd(ref byte[] x, dchar c)
|
||||||
createFwdDecl(LINK::c, voidArrayTy, {"_d_arrayappendcd", "_d_arrayappendwd"},
|
createFwdDecl(LINK::c, voidArrayTy, {"_d_arrayappendcd", "_d_arrayappendwd"},
|
||||||
|
|
10
gen/toir.cpp
10
gen/toir.cpp
|
@ -1533,13 +1533,9 @@ public:
|
||||||
// allocate & init
|
// allocate & init
|
||||||
result = DtoNewDynArray(e->loc, e->newtype, sz, true);
|
result = DtoNewDynArray(e->loc, e->newtype, sz, true);
|
||||||
} else {
|
} else {
|
||||||
size_t ndims = e->arguments->length;
|
assert(e->lowering);
|
||||||
std::vector<DValue *> dims;
|
LLValue *pair = DtoRVal(e->lowering);
|
||||||
dims.reserve(ndims);
|
result = new DSliceValue(e->type, pair);
|
||||||
for (auto arg : *e->arguments) {
|
|
||||||
dims.push_back(toElem(arg));
|
|
||||||
}
|
|
||||||
result = DtoNewMulDimDynArray(e->loc, e->newtype, &dims[0], ndims);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// new static array
|
// new static array
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue