mirror of
https://github.com/ldc-developers/ldc.git
synced 2025-05-02 08:01:11 +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);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue