Remove getContainedType from DtoMemSetZero (#4157)

This commit is contained in:
Nicholas Wilson 2022-09-13 21:39:05 +08:00 committed by GitHub
parent a433746018
commit 838146be71
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 14 additions and 12 deletions

View file

@ -105,7 +105,8 @@ struct RemoveStructPadding : ABIRewrite {
LLValue *lval = DtoAlloca(dty, ".RemoveStructPadding_dump"); LLValue *lval = DtoAlloca(dty, ".RemoveStructPadding_dump");
// Make sure the padding is zero, so struct comparisons work. // Make sure the padding is zero, so struct comparisons work.
// TODO: Only do this if there's padding, and/or only initialize padding. // TODO: Only do this if there's padding, and/or only initialize padding.
DtoMemSetZero(lval, DtoConstSize_t(getTypeAllocSize(DtoType(dty)))); DtoMemSetZero(DtoType(dty), lval,
DtoConstSize_t(getTypeAllocSize(DtoType(dty))));
DtoPaddedStruct(dty->toBasetype(), v, lval); DtoPaddedStruct(dty->toBasetype(), v, lval);
return lval; return lval;
} }

View file

@ -254,7 +254,7 @@ void DtoArrayAssign(const Loc &loc, DValue *lhs, DValue *rhs, EXP op,
const size_t elementSize = getTypeAllocSize(DtoMemType(elemType)); const size_t elementSize = getTypeAllocSize(DtoMemType(elemType));
if (rhs->isNull()) { if (rhs->isNull()) {
LLValue *lhsSize = computeSize(lhsLength, elementSize); LLValue *lhsSize = computeSize(lhsLength, elementSize);
DtoMemSetZero(lhsPtr, lhsSize); DtoMemSetZero(getI8Type(), lhsPtr, lhsSize);
} else { } else {
bool knownInBounds = bool knownInBounds =
isConstructing || (t->ty == TY::Tsarray && t2->ty == TY::Tsarray); isConstructing || (t->ty == TY::Tsarray && t2->ty == TY::Tsarray);

View file

@ -65,8 +65,9 @@ bool walkPostorder(Expression *e, StoppableVisitor *v);
static LLValue *write_zeroes(LLValue *mem, unsigned start, unsigned end) { static LLValue *write_zeroes(LLValue *mem, unsigned start, unsigned end) {
mem = DtoBitCast(mem, getVoidPtrType()); mem = DtoBitCast(mem, getVoidPtrType());
LLValue *gep = DtoGEP1(LLType::getInt8Ty(gIR->context()), mem, start, ".padding"); LLType *i8 = LLType::getInt8Ty(gIR->context());
DtoMemSetZero(gep, DtoConstSize_t(end - start)); LLValue *gep = DtoGEP1(i8, mem, start, ".padding");
DtoMemSetZero(i8, gep, DtoConstSize_t(end - start));
return mem; return mem;
} }
@ -546,7 +547,7 @@ public:
Logger::println("performing aggregate zero initialization"); Logger::println("performing aggregate zero initialization");
assert(e->e2->toInteger() == 0); assert(e->e2->toInteger() == 0);
LLValue *lval = DtoLVal(lhs); LLValue *lval = DtoLVal(lhs);
DtoMemSetZero(lval); DtoMemSetZero(DtoType(lhs->type), lval);
TypeStruct *ts = static_cast<TypeStruct *>(e->e1->type); TypeStruct *ts = static_cast<TypeStruct *>(e->e1->type);
if (ts->sym->isNested() && ts->sym->vthis) if (ts->sym->isNested() && ts->sym->vthis)
DtoResolveNestedContext(e->loc, ts->sym, lval); DtoResolveNestedContext(e->loc, ts->sym, lval);
@ -2319,7 +2320,7 @@ public:
dstMem = DtoAlloca(e->type, ".structliteral"); dstMem = DtoAlloca(e->type, ".structliteral");
if (sd->zeroInit) { if (sd->zeroInit) {
DtoMemSetZero(dstMem); DtoMemSetZero(DtoType(e->type), dstMem);
} else { } else {
LLValue *initsym = getIrAggr(sd)->getInitSymbol(); LLValue *initsym = getIrAggr(sd)->getInitSymbol();
initsym = DtoBitCast(initsym, DtoType(e->type->pointerTo())); initsym = DtoBitCast(initsym, DtoType(e->type->pointerTo()));
@ -2839,7 +2840,7 @@ bool toInPlaceConstruction(DLValue *lhs, Expression *rhs) {
DtoResolveStruct(sd); DtoResolveStruct(sd);
if (sd->zeroInit) { if (sd->zeroInit) {
Logger::println("success, zeroing out"); Logger::println("success, zeroing out");
DtoMemSetZero(DtoLVal(lhs)); DtoMemSetZero(DtoType(lhs->type) ,DtoLVal(lhs));
return true; return true;
} }
} }

View file

@ -397,13 +397,13 @@ void DtoMemSet(LLValue *dst, LLValue *val, LLValue *nbytes, unsigned align) {
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void DtoMemSetZero(LLValue *dst, LLValue *nbytes, unsigned align) { void DtoMemSetZero(LLType *type, LLValue *dst, LLValue *nbytes, unsigned align) {
DtoMemSet(dst, DtoConstUbyte(0), nbytes, align); DtoMemSet(dst, DtoConstUbyte(0), nbytes, align);
} }
void DtoMemSetZero(LLValue *dst, unsigned align) { void DtoMemSetZero(LLType *type, LLValue *dst, unsigned align) {
uint64_t n = getTypeStoreSize(dst->getType()->getContainedType(0)); uint64_t n = getTypeStoreSize(dst->getType()->getContainedType(0));
DtoMemSetZero(dst, DtoConstSize_t(n), align); DtoMemSetZero(type, dst, DtoConstSize_t(n), align);
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////

View file

@ -178,7 +178,7 @@ void DtoMemSet(LLValue *dst, LLValue *val, LLValue *nbytes, unsigned align = 1);
* @param nbytes Number of bytes to overwrite. * @param nbytes Number of bytes to overwrite.
* @param align The minimum alignment of the destination memory. * @param align The minimum alignment of the destination memory.
*/ */
void DtoMemSetZero(LLValue *dst, LLValue *nbytes, unsigned align = 1); void DtoMemSetZero(LLType *type, LLValue *dst, LLValue *nbytes, unsigned align = 1);
/** /**
* The same as DtoMemSetZero but figures out the size itself based on the * The same as DtoMemSetZero but figures out the size itself based on the
@ -186,7 +186,7 @@ void DtoMemSetZero(LLValue *dst, LLValue *nbytes, unsigned align = 1);
* @param dst Destination memory. * @param dst Destination memory.
* @param align The minimum alignment of the destination memory. * @param align The minimum alignment of the destination memory.
*/ */
void DtoMemSetZero(LLValue *dst, unsigned align = 1); void DtoMemSetZero(LLType *type, LLValue *dst, unsigned align = 1);
/** /**
* Generates a call to llvm.memcpy.i32 (or i64 depending on architecture). * Generates a call to llvm.memcpy.i32 (or i64 depending on architecture).