mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Add instructions to allocate and deallocate packs.
Having added these, I'm not entirely sure we couldn't just use alloc_stack and dealloc_stack. Well, if we find ourselves adding a lot of redundancy with those instructions (e.g. around DI), we can always go back and rip these out.
This commit is contained in:
@@ -409,6 +409,11 @@ public:
|
||||
wasMoved));
|
||||
}
|
||||
|
||||
AllocPackInst *createAllocPack(SILLocation loc, SILType packType) {
|
||||
return insert(AllocPackInst::create(getSILDebugLocation(loc), packType,
|
||||
getFunction()));
|
||||
}
|
||||
|
||||
AllocRefInst *createAllocRef(SILLocation Loc, SILType ObjectType,
|
||||
bool objc, bool canAllocOnStack,
|
||||
ArrayRef<SILType> ElementTypes,
|
||||
@@ -2108,6 +2113,10 @@ public:
|
||||
return insert(new (getModule())
|
||||
DeallocStackInst(getSILDebugLocation(Loc), operand));
|
||||
}
|
||||
DeallocPackInst *createDeallocPack(SILLocation loc, SILValue operand) {
|
||||
return insert(new (getModule())
|
||||
DeallocPackInst(getSILDebugLocation(loc), operand));
|
||||
}
|
||||
DeallocStackRefInst *createDeallocStackRef(SILLocation Loc,
|
||||
SILValue operand) {
|
||||
return insert(new (getModule())
|
||||
|
||||
@@ -829,6 +829,16 @@ SILCloner<ImplClass>::visitAllocStackInst(AllocStackInst *Inst) {
|
||||
recordClonedInstruction(Inst, NewInst);
|
||||
}
|
||||
|
||||
template<typename ImplClass>
|
||||
void
|
||||
SILCloner<ImplClass>::visitAllocPackInst(AllocPackInst *Inst) {
|
||||
getBuilder().setCurrentDebugScope(getOpScope(Inst->getDebugScope()));
|
||||
SILLocation Loc = getOpLocation(Inst->getLoc());
|
||||
auto *NewInst = getBuilder().createAllocPack(
|
||||
Loc, getOpType(Inst->getType().getObjectType()));
|
||||
recordClonedInstruction(Inst, NewInst);
|
||||
}
|
||||
|
||||
template<typename ImplClass>
|
||||
void
|
||||
SILCloner<ImplClass>::visitAllocRefInst(AllocRefInst *Inst) {
|
||||
@@ -2647,6 +2657,15 @@ SILCloner<ImplClass>::visitDeallocStackInst(DeallocStackInst *Inst) {
|
||||
getOpValue(Inst->getOperand())));
|
||||
}
|
||||
|
||||
template<typename ImplClass>
|
||||
void
|
||||
SILCloner<ImplClass>::visitDeallocPackInst(DeallocPackInst *Inst) {
|
||||
getBuilder().setCurrentDebugScope(getOpScope(Inst->getDebugScope()));
|
||||
recordClonedInstruction(
|
||||
Inst, getBuilder().createDeallocPack(getOpLocation(Inst->getLoc()),
|
||||
getOpValue(Inst->getOperand())));
|
||||
}
|
||||
|
||||
template<typename ImplClass>
|
||||
void
|
||||
SILCloner<ImplClass>::visitDeallocRefInst(DeallocRefInst *Inst) {
|
||||
|
||||
@@ -2221,6 +2221,32 @@ public:
|
||||
DeallocStackInst *getSingleDeallocStack() const;
|
||||
};
|
||||
|
||||
/// AllocPackInst - This represents the allocation of a value pack
|
||||
/// in stack memory. The memory is provided uninitialized.
|
||||
class AllocPackInst final
|
||||
: public NullaryInstructionWithTypeDependentOperandsBase<
|
||||
SILInstructionKind::AllocPackInst,
|
||||
AllocPackInst,
|
||||
AllocationInst> {
|
||||
friend TrailingObjects;
|
||||
friend SILBuilder;
|
||||
|
||||
AllocPackInst(SILDebugLocation loc, SILType resultType,
|
||||
ArrayRef<SILValue> typeDependentOperands)
|
||||
: NullaryInstructionWithTypeDependentOperandsBase(loc,
|
||||
typeDependentOperands,
|
||||
resultType) {}
|
||||
|
||||
static AllocPackInst *create(SILDebugLocation loc, SILType packType,
|
||||
SILFunction &F);
|
||||
public:
|
||||
/// Return the allocated pack type. The result type of the instruction
|
||||
/// is an address of this type.
|
||||
CanSILPackType getPackType() const {
|
||||
return getType().castTo<SILPackType>();
|
||||
}
|
||||
};
|
||||
|
||||
/// The base class for AllocRefInst and AllocRefDynamicInst.
|
||||
///
|
||||
/// The first NumTailTypes operands are counts for the tail allocated
|
||||
@@ -8298,6 +8324,16 @@ class DeallocStackInst :
|
||||
: UnaryInstructionBase(DebugLoc, operand) {}
|
||||
};
|
||||
|
||||
/// DeallocPackInst - Deallocate stack memory allocated by alloc_pack.
|
||||
class DeallocPackInst :
|
||||
public UnaryInstructionBase<SILInstructionKind::DeallocPackInst,
|
||||
DeallocationInst> {
|
||||
friend SILBuilder;
|
||||
|
||||
DeallocPackInst(SILDebugLocation debugLoc, SILValue operand)
|
||||
: UnaryInstructionBase(debugLoc, operand) {}
|
||||
};
|
||||
|
||||
/// Like DeallocStackInst, but for `alloc_ref [stack]`.
|
||||
class DeallocStackRefInst
|
||||
: public UnaryInstructionBase<SILInstructionKind::DeallocStackRefInst,
|
||||
|
||||
@@ -308,6 +308,8 @@ ABSTRACT_VALUE_AND_INST(SingleValueInstruction, ValueBase, SILInstruction)
|
||||
ABSTRACT_SINGLE_VALUE_INST(AllocationInst, SingleValueInstruction)
|
||||
SINGLE_VALUE_INST(AllocStackInst, alloc_stack,
|
||||
AllocationInst, None, DoesNotRelease)
|
||||
SINGLE_VALUE_INST(AllocPackInst, alloc_pack,
|
||||
AllocationInst, None, DoesNotRelease)
|
||||
SINGLE_VALUE_INST(AllocRefInst, alloc_ref,
|
||||
AllocationInst, None, DoesNotRelease)
|
||||
SINGLE_VALUE_INST(AllocRefDynamicInst, alloc_ref_dynamic,
|
||||
@@ -702,6 +704,8 @@ ABSTRACT_INST(TermInst, SILInstruction)
|
||||
ABSTRACT_INST(DeallocationInst, SILInstruction)
|
||||
NON_VALUE_INST(DeallocStackInst, dealloc_stack,
|
||||
DeallocationInst, MayHaveSideEffects, DoesNotRelease)
|
||||
NON_VALUE_INST(DeallocPackInst, dealloc_pack,
|
||||
DeallocationInst, MayHaveSideEffects, DoesNotRelease)
|
||||
NON_VALUE_INST(DeallocStackRefInst, dealloc_stack_ref,
|
||||
DeallocationInst, MayHaveSideEffects, DoesNotRelease)
|
||||
NON_VALUE_INST(DeallocRefInst, dealloc_ref,
|
||||
|
||||
Reference in New Issue
Block a user