mirror of
https://github.com/ldc-developers/ldc.git
synced 2025-05-05 01:20:51 +03:00
More in-place construction
Also for struct literal fields, array literal elements and associative array literal elements as well as basic types allocated on the heap.
This commit is contained in:
parent
9f728a4b4c
commit
126184a8b6
7 changed files with 107 additions and 109 deletions
|
@ -173,10 +173,9 @@ static void DtoArrayInit(Loc &loc, LLValue *ptr, LLValue *length,
|
|||
|
||||
LLValue *itr_val = DtoLoad(itr);
|
||||
// assign array element value
|
||||
DValue *arrayelem =
|
||||
new DLValue(dvalue->type->toBasetype(),
|
||||
DLValue arrayelem(dvalue->type->toBasetype(),
|
||||
DtoGEP1(ptr, itr_val, true, "arrayinit.arrayelem"));
|
||||
DtoAssign(loc, arrayelem, dvalue, op);
|
||||
DtoAssign(loc, &arrayelem, dvalue, op);
|
||||
|
||||
// increment iterator
|
||||
DtoStore(gIR->ir->CreateAdd(itr_val, DtoConstSize_t(1), "arrayinit.new_itr"),
|
||||
|
@ -562,9 +561,8 @@ void initializeArrayLiteral(IRState *p, ArrayLiteralExp *ale, LLValue *dstMem) {
|
|||
|
||||
// Don't try to write nothing to a zero-element array, we might represent it
|
||||
// as a null pointer.
|
||||
if (elemCount == 0) {
|
||||
if (elemCount == 0)
|
||||
return;
|
||||
}
|
||||
|
||||
if (isConstLiteral(ale)) {
|
||||
llvm::Constant *constarr = arrayLiteralToConst(p, ale);
|
||||
|
@ -590,11 +588,14 @@ void initializeArrayLiteral(IRState *p, ArrayLiteralExp *ale, LLValue *dstMem) {
|
|||
} else {
|
||||
// Store the elements one by one.
|
||||
for (size_t i = 0; i < elemCount; ++i) {
|
||||
DValue *rhs = toElem(indexArrayLiteral(ale, i));
|
||||
Expression *rhsExp = indexArrayLiteral(ale, i);
|
||||
|
||||
LLValue *lhsPtr = DtoGEPi(dstMem, 0, i, "", p->scopebb());
|
||||
DLValue lhs(rhs->type, DtoBitCast(lhsPtr, DtoPtrToType(rhs->type)));
|
||||
DtoAssign(ale->loc, &lhs, rhs, TOKconstruct, true);
|
||||
DLValue lhs(rhsExp->type, DtoBitCast(lhsPtr, DtoPtrToType(rhsExp->type)));
|
||||
|
||||
// try to construct it in-place
|
||||
if (!toInPlaceConstruction(&lhs, rhsExp))
|
||||
DtoAssign(ale->loc, &lhs, toElem(rhsExp), TOKconstruct, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -744,12 +745,12 @@ DSliceValue *DtoResizeDynArray(Loc &loc, Type *arrayType, DValue *array,
|
|||
getRuntimeFunction(loc, gIR->module, zeroInit ? "_d_arraysetlengthT"
|
||||
: "_d_arraysetlengthiT");
|
||||
|
||||
LLValue *newArray = gIR->CreateCallOrInvoke(
|
||||
fn, DtoTypeInfoOf(arrayType), newdim,
|
||||
DtoBitCast(DtoLVal(array),
|
||||
fn->getFunctionType()->getParamType(2)),
|
||||
".gc_mem")
|
||||
.getInstruction();
|
||||
LLValue *newArray =
|
||||
gIR->CreateCallOrInvoke(
|
||||
fn, DtoTypeInfoOf(arrayType), newdim,
|
||||
DtoBitCast(DtoLVal(array), fn->getFunctionType()->getParamType(2)),
|
||||
".gc_mem")
|
||||
.getInstruction();
|
||||
|
||||
return getSlice(arrayType, newArray);
|
||||
}
|
||||
|
@ -773,16 +774,16 @@ void DtoCatAssignElement(Loc &loc, Type *arrayType, DValue *array,
|
|||
LLValue *appendedArray =
|
||||
gIR->CreateCallOrInvoke(
|
||||
fn, DtoTypeInfoOf(arrayType),
|
||||
DtoBitCast(DtoLVal(array),
|
||||
fn->getFunctionType()->getParamType(1)),
|
||||
DtoBitCast(DtoLVal(array), fn->getFunctionType()->getParamType(1)),
|
||||
DtoConstSize_t(1), ".appendedArray")
|
||||
.getInstruction();
|
||||
appendedArray = DtoAggrPaint(appendedArray, DtoType(arrayType));
|
||||
|
||||
LLValue *val = DtoArrayPtr(array);
|
||||
val = DtoGEP1(val, oldLength, true, ".lastElem");
|
||||
DtoAssign(loc, new DLValue(arrayType->nextOf(), val), expVal, TOKblit);
|
||||
callPostblit(loc, exp, val);
|
||||
LLValue *ptr = DtoArrayPtr(array);
|
||||
ptr = DtoGEP1(ptr, oldLength, true, ".lastElem");
|
||||
DLValue lastElem(arrayType->nextOf(), ptr);
|
||||
DtoAssign(loc, &lastElem, expVal, TOKblit);
|
||||
callPostblit(loc, exp, ptr);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue