mirror of
https://github.com/ldc-developers/ldc.git
synced 2025-05-06 10:57:35 +03:00
The runtime functions for multi-dim arrays have changed.
_d_newarraymT and _d_newarraymiT are now named _d_newarraymTX and _d_newarraymiTX. There is also a change in the signature: instead of a variable length argumentlist the functions now require an array of dimensions. This should fix test runnable/test28.d
This commit is contained in:
parent
e91c71c37d
commit
eadefdc676
4 changed files with 53 additions and 23 deletions
|
@ -631,7 +631,7 @@ DSliceValue* DtoNewDynArray(Loc& loc, Type* arrayType, DValue* dim, bool default
|
|||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
DSliceValue* DtoNewMulDimDynArray(Loc& loc, Type* arrayType, DValue** dims, size_t ndims, bool defaultInit)
|
||||
DSliceValue* DtoNewMulDimDynArray(Loc& loc, Type* arrayType, DValue** dims, size_t ndims)
|
||||
{
|
||||
IF_LOG Logger::println("DtoNewMulDimDynArray : %s", arrayType->toChars());
|
||||
LOG_SCOPE;
|
||||
|
@ -641,26 +641,56 @@ DSliceValue* DtoNewMulDimDynArray(Loc& loc, Type* arrayType, DValue** dims, size
|
|||
|
||||
// get value type
|
||||
Type* vtype = arrayType->toBasetype();
|
||||
for (size_t i=0; i<ndims; ++i)
|
||||
for (size_t i = 0; i < ndims; ++i)
|
||||
vtype = vtype->nextOf();
|
||||
|
||||
// get runtime function
|
||||
bool zeroInit = vtype->isZeroInit();
|
||||
if (defaultInit && !isInitialized(vtype))
|
||||
defaultInit = false;
|
||||
|
||||
const char* fnname = zeroInit ? "_d_newarraymT" : "_d_newarraymiT";
|
||||
|
||||
const char* fnname = vtype->isZeroInit() ? "_d_newarraymTX" : "_d_newarraymiTX";
|
||||
LLFunction* fn = LLVM_D_GetRuntimeFunction(loc, gIR->module, fnname);
|
||||
|
||||
std::vector<LLValue*> args;
|
||||
args.reserve(ndims+2);
|
||||
args.push_back(arrayTypeInfo);
|
||||
args.push_back(DtoConstSize_t(ndims));
|
||||
// Check if constant
|
||||
bool allDimsConst = true;
|
||||
for (size_t i = 0; i < ndims; ++i)
|
||||
{
|
||||
if (!isaConstant(dims[i]->getRVal()))
|
||||
allDimsConst = false;
|
||||
}
|
||||
|
||||
// build dims
|
||||
for (size_t i=0; i<ndims; ++i)
|
||||
args.push_back(dims[i]->getRVal());
|
||||
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(dims[i]->getRVal()));
|
||||
}
|
||||
|
||||
llvm::Constant* dims = llvm::ConstantArray::get(llvm::ArrayType::get(DtoSize_t(), ndims), argsdims);
|
||||
LLGlobalVariable* 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");
|
||||
unsigned int i = 0;
|
||||
for (size_t i = 0; i < ndims; ++i)
|
||||
DtoStore(dims[i]->getRVal(), DtoGEPi(array, 0, i, ".ndim"));
|
||||
}
|
||||
|
||||
LLStructType* dtype = DtoArrayType(DtoSize_t());
|
||||
LLValue* darray = DtoRawAlloca(dtype, 0, ".array");
|
||||
DtoStore(DtoConstSize_t(ndims), DtoGEPi(darray, 0, 0, ".len"));
|
||||
DtoStore(DtoBitCast(array, getPtrToType(DtoSize_t())), DtoGEPi(darray, 0, 1, ".ptr"));
|
||||
|
||||
llvm::Value* args[] = {
|
||||
arrayTypeInfo,
|
||||
DtoLoad(darray)
|
||||
};
|
||||
|
||||
// call allocator
|
||||
LLValue* newptr = gIR->CreateCallOrInvoke(fn, args, ".gc_mem").getInstruction();
|
||||
|
|
|
@ -57,7 +57,7 @@ void DtoSetArray(DValue* array, LLValue* dim, LLValue* ptr);
|
|||
void DtoSetArrayToNull(LLValue* v);
|
||||
|
||||
DSliceValue* DtoNewDynArray(Loc& loc, Type* arrayType, DValue* dim, bool defaultInit=true);
|
||||
DSliceValue* DtoNewMulDimDynArray(Loc& loc, Type* arrayType, DValue** dims, size_t ndims, bool defaultInit=true);
|
||||
DSliceValue* DtoNewMulDimDynArray(Loc& loc, Type* arrayType, DValue** dims, size_t ndims);
|
||||
DSliceValue* DtoResizeDynArray(Loc& loc, Type* arrayType, DValue* array, llvm::Value* newdim);
|
||||
|
||||
void DtoCatAssignElement(Loc& loc, Type* type, DValue* arr, Expression* exp);
|
||||
|
|
|
@ -87,8 +87,8 @@ static void checkForImplicitGCCall(const Loc &loc, const char *name)
|
|||
"_d_delmemory",
|
||||
"_d_newarrayT",
|
||||
"_d_newarrayiT",
|
||||
"_d_newarraymT",
|
||||
"_d_newarraymiT",
|
||||
"_d_newarraymTX",
|
||||
"_d_newarraymiTX",
|
||||
"_d_newarrayU",
|
||||
"_d_newclass",
|
||||
"_d_newitemT",
|
||||
|
@ -433,13 +433,13 @@ static void LLVM_D_BuildRuntimeModule()
|
|||
llvm::Function::Create(fty, llvm::GlobalValue::ExternalLinkage, fname2, M);
|
||||
llvm::Function::Create(fty, llvm::GlobalValue::ExternalLinkage, fname3, M);
|
||||
}
|
||||
// void[] _d_newarraymT (const TypeInfo ti, size_t[] dims)
|
||||
// void[] _d_newarraymiT(const TypeInfo ti, size_t[] dims)
|
||||
// void[] _d_newarraymTX (const TypeInfo ti, size_t[] dims)
|
||||
// void[] _d_newarraymiTX(const TypeInfo ti, size_t[] dims)
|
||||
{
|
||||
llvm::StringRef fname ("_d_newarraymT");
|
||||
llvm::StringRef fname2("_d_newarraymiT");
|
||||
llvm::StringRef fname ("_d_newarraymTX");
|
||||
llvm::StringRef fname2("_d_newarraymiTX");
|
||||
LLType *types[] = { typeInfoTy, rt_array(sizeTy) };
|
||||
LLFunctionType* fty = llvm::FunctionType::get(voidArrayTy, types, true);
|
||||
LLFunctionType* fty = llvm::FunctionType::get(voidArrayTy, types, false);
|
||||
llvm::Function::Create(fty, llvm::GlobalValue::ExternalLinkage, fname, M);
|
||||
llvm::Function::Create(fty, llvm::GlobalValue::ExternalLinkage, fname2, M);
|
||||
}
|
||||
|
|
|
@ -1888,7 +1888,7 @@ public:
|
|||
dims.reserve(ndims);
|
||||
for (size_t i=0; i<ndims; ++i)
|
||||
dims.push_back(toElem((*e->arguments)[i]));
|
||||
result = DtoNewMulDimDynArray(e->loc, e->newtype, &dims[0], ndims, true);
|
||||
result = DtoNewMulDimDynArray(e->loc, e->newtype, &dims[0], ndims);
|
||||
}
|
||||
}
|
||||
// new static array
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue