mirror of
https://github.com/ldc-developers/ldc.git
synced 2025-04-30 15:10:59 +03:00
Use memset to initialize arrays with constant byte value.
This extends the existing code for null values.
This commit is contained in:
parent
62683c4efe
commit
80a65e34f3
1 changed files with 7 additions and 3 deletions
|
@ -118,14 +118,18 @@ void DtoArrayInit(Loc& loc, DValue* array, DValue* value, int op)
|
|||
LLValue* ptr = DtoArrayPtr(array);
|
||||
Type* arrayelemty = array->getType()->nextOf()->toBasetype();
|
||||
|
||||
// lets first optimize all zero initializations down to a memset.
|
||||
// lets first optimize all zero/constant i8 initializations down to a memset.
|
||||
// this simplifies codegen later on as llvm null's have no address!
|
||||
LLValue *val = value->getRVal();
|
||||
if (isaConstant(val) && isaConstant(val)->isNullValue())
|
||||
if (isaConstant(val) && (isaConstant(val)->isNullValue()
|
||||
|| val->getType() == LLType::getInt8Ty(gIR->context())))
|
||||
{
|
||||
size_t X = getTypePaddedSize(val->getType());
|
||||
LLValue* nbytes = gIR->ir->CreateMul(dim, DtoConstSize_t(X), ".nbytes");
|
||||
DtoMemSetZero(ptr, nbytes);
|
||||
if (isaConstant(val)->isNullValue())
|
||||
DtoMemSetZero(ptr, nbytes);
|
||||
else
|
||||
DtoMemSet(ptr, val, nbytes);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue