@@ -3362,9 +3362,8 @@ visitIsUniqueOrPinnedInst(swift::IsUniqueOrPinnedInst *i) {
3362
3362
}
3363
3363
3364
3364
static bool tryDeferFixedSizeBufferInitialization (IRGenSILFunction &IGF,
3365
- const SILInstruction *allocInst,
3365
+ SILInstruction *allocInst,
3366
3366
const TypeInfo &ti,
3367
- SILValue addressValue,
3368
3367
Address fixedSizeBuffer,
3369
3368
const llvm::Twine &name) {
3370
3369
// There's no point in doing this for fixed-sized types, since we'll allocate
@@ -3384,8 +3383,8 @@ static bool tryDeferFixedSizeBufferInitialization(IRGenSILFunction &IGF,
3384
3383
// Does this instruction use the allocation? If not, continue.
3385
3384
auto Ops = inst->getAllOperands ();
3386
3385
if (std::none_of (Ops.begin (), Ops.end (),
3387
- [&addressValue ](const Operand &Op) {
3388
- return Op.get () == addressValue ;
3386
+ [allocInst ](const Operand &Op) {
3387
+ return Op.get () == allocInst ;
3389
3388
}))
3390
3389
continue ;
3391
3390
@@ -3409,7 +3408,7 @@ static bool tryDeferFixedSizeBufferInitialization(IRGenSILFunction &IGF,
3409
3408
IGF.Builder .CreateLifetimeStart (fixedSizeBuffer,
3410
3409
getFixedBufferSize (IGF.IGM ));
3411
3410
}
3412
- IGF.setContainerOfUnallocatedAddress (addressValue , fixedSizeBuffer);
3411
+ IGF.setContainerOfUnallocatedAddress (allocInst , fixedSizeBuffer);
3413
3412
return true ;
3414
3413
}
3415
3414
@@ -3456,10 +3455,7 @@ void IRGenSILFunction::visitAllocStackInst(swift::AllocStackInst *i) {
3456
3455
// If a dynamic alloc_stack is immediately initialized by a copy_addr
3457
3456
// operation, we can combine the allocation and initialization using an
3458
3457
// optimized value witness.
3459
- if (tryDeferFixedSizeBufferInitialization (*this , i, type,
3460
- i,
3461
- Address (),
3462
- dbgname))
3458
+ if (tryDeferFixedSizeBufferInitialization (*this , i, type, Address (), dbgname))
3463
3459
return ;
3464
3460
3465
3461
auto addr = type.allocateStack (*this ,
@@ -4257,7 +4253,7 @@ void IRGenSILFunction::visitInitExistentialAddrInst(swift::InitExistentialAddrIn
4257
4253
auto &srcTI = getTypeInfo (i->getLoweredConcreteType ());
4258
4254
4259
4255
// See if we can defer initialization of the buffer to a copy_addr into it.
4260
- if (tryDeferFixedSizeBufferInitialization (*this , i, srcTI, i, buffer, " " ))
4256
+ if (tryDeferFixedSizeBufferInitialization (*this , i, srcTI, buffer, " " ))
4261
4257
return ;
4262
4258
4263
4259
// Allocate in the destination fixed-size buffer.
@@ -4460,52 +4456,37 @@ void IRGenSILFunction::setAllocatedAddressForBuffer(SILValue v,
4460
4456
4461
4457
void IRGenSILFunction::visitCopyAddrInst (swift::CopyAddrInst *i) {
4462
4458
SILType addrTy = i->getSrc ()->getType ();
4459
+ const TypeInfo &addrTI = getTypeInfo (addrTy);
4463
4460
Address src = getLoweredAddress (i->getSrc ());
4464
- Address dest;
4465
- bool isFixedBufferInitialization;
4466
4461
// See whether we have a deferred fixed-size buffer initialization.
4467
4462
auto &loweredDest = getLoweredValue (i->getDest ());
4468
4463
if (loweredDest.isUnallocatedAddressInBuffer ()) {
4469
- isFixedBufferInitialization = true ;
4470
- dest = loweredDest.getContainerOfAddress ();
4471
- } else {
4472
- isFixedBufferInitialization = false ;
4473
- dest = loweredDest.getAddress ();
4474
- }
4475
-
4476
- const TypeInfo &addrTI = getTypeInfo (addrTy);
4477
-
4478
- unsigned takeAndOrInitialize =
4479
- (i->isTakeOfSrc () << 1U ) | i->isInitializationOfDest ();
4480
- static const unsigned COPY = 0 , TAKE = 2 , ASSIGN = 0 , INITIALIZE = 1 ;
4481
-
4482
- switch (takeAndOrInitialize) {
4483
- case ASSIGN | COPY:
4484
- assert (!isFixedBufferInitialization
4485
- && " can't assign into an unallocated buffer" );
4486
- addrTI.assignWithCopy (*this , dest, src, addrTy);
4487
- break ;
4488
- case INITIALIZE | COPY:
4489
- if (isFixedBufferInitialization) {
4490
- Address addr = addrTI.initializeBufferWithCopy (*this , dest, src, addrTy);
4464
+ assert (i->isInitializationOfDest ()
4465
+ && " need to initialize an unallocated buffer" );
4466
+ Address cont = loweredDest.getContainerOfAddress ();
4467
+ if (i->isTakeOfSrc ()) {
4468
+ Address addr = addrTI.initializeBufferWithTake (*this , cont, src, addrTy);
4491
4469
setAllocatedAddressForBuffer (i->getDest (), addr);
4492
- } else
4493
- addrTI.initializeWithCopy (*this , dest, src, addrTy);
4494
- break ;
4495
- case ASSIGN | TAKE:
4496
- assert (!isFixedBufferInitialization
4497
- && " can't assign into an unallocated buffer" );
4498
- addrTI.assignWithTake (*this , dest, src, addrTy);
4499
- break ;
4500
- case INITIALIZE | TAKE:
4501
- if (isFixedBufferInitialization) {
4502
- Address addr = addrTI.initializeBufferWithTake (*this , dest, src, addrTy);
4470
+ } else {
4471
+ Address addr = addrTI.initializeBufferWithCopy (*this , cont, src, addrTy);
4503
4472
setAllocatedAddressForBuffer (i->getDest (), addr);
4504
- } else
4505
- addrTI.initializeWithTake (*this , dest, src, addrTy);
4506
- break ;
4507
- default :
4508
- llvm_unreachable (" unexpected take/initialize attribute combination?!" );
4473
+ }
4474
+ } else {
4475
+ Address dest = loweredDest.getAddress ();
4476
+
4477
+ if (i->isInitializationOfDest ()) {
4478
+ if (i->isTakeOfSrc ()) {
4479
+ addrTI.initializeWithTake (*this , dest, src, addrTy);
4480
+ } else {
4481
+ addrTI.initializeWithCopy (*this , dest, src, addrTy);
4482
+ }
4483
+ } else {
4484
+ if (i->isTakeOfSrc ()) {
4485
+ addrTI.assignWithTake (*this , dest, src, addrTy);
4486
+ } else {
4487
+ addrTI.assignWithCopy (*this , dest, src, addrTy);
4488
+ }
4489
+ }
4509
4490
}
4510
4491
}
4511
4492
0 commit comments