Skip to content

Commit 4b39738

Browse files
authored
Merge pull request #39610 from eeckstein/remove-value-buffer-insts
SIL: remove the unused alloc_value_buffer, project_value_buffer and dealloc_value_buffer instructions.
2 parents 58ed9c8 + 7849f09 commit 4b39738

32 files changed

+9
-477
lines changed

docs/SIL.rst

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -3198,23 +3198,6 @@ Releasing a box is undefined behavior if the box's value is uninitialized.
31983198
To deallocate a box whose value has not been initialized, ``dealloc_box``
31993199
should be used.
32003200

3201-
alloc_value_buffer
3202-
``````````````````
3203-
3204-
::
3205-
3206-
sil-instruction ::= 'alloc_value_buffer' sil-type 'in' sil-operand
3207-
3208-
%1 = alloc_value_buffer $(Int, T) in %0 : $*Builtin.UnsafeValueBuffer
3209-
// The operand must have the exact type shown.
3210-
// The result has type $*(Int, T).
3211-
3212-
Given the address of an unallocated value buffer, allocate space in it
3213-
for a value of the given type. This instruction has undefined
3214-
behavior if the value buffer is currently allocated.
3215-
3216-
The type operand must be a lowered object type.
3217-
32183201
alloc_global
32193202
````````````
32203203

@@ -3442,44 +3425,6 @@ This does not destroy the reference type instance. The contents of the
34423425
heap object must have been fully uninitialized or destroyed before
34433426
``dealloc_ref`` is applied.
34443427

3445-
dealloc_value_buffer
3446-
````````````````````
3447-
3448-
::
3449-
3450-
sil-instruction ::= 'dealloc_value_buffer' sil-type 'in' sil-operand
3451-
3452-
dealloc_value_buffer $(Int, T) in %0 : $*Builtin.UnsafeValueBuffer
3453-
// The operand must have the exact type shown.
3454-
3455-
Given the address of a value buffer, deallocate the storage in it.
3456-
This instruction has undefined behavior if the value buffer is not
3457-
currently allocated, or if it was allocated with a type other than the
3458-
type operand.
3459-
3460-
The type operand must be a lowered object type.
3461-
3462-
project_value_buffer
3463-
````````````````````
3464-
3465-
::
3466-
3467-
sil-instruction ::= 'project_value_buffer' sil-type 'in' sil-operand
3468-
3469-
%1 = project_value_buffer $(Int, T) in %0 : $*Builtin.UnsafeValueBuffer
3470-
// The operand must have the exact type shown.
3471-
// The result has type $*(Int, T).
3472-
3473-
Given the address of a value buffer, return the address of the value
3474-
storage in it. This instruction has undefined behavior if the value
3475-
buffer is not currently allocated, or if it was allocated with a type
3476-
other than the type operand.
3477-
3478-
The result is the same value as was originally returned by
3479-
``alloc_value_buffer``.
3480-
3481-
The type operand must be a lowered object type.
3482-
34833428
Debug Information
34843429
~~~~~~~~~~~~~~~~~
34853430

include/swift/SIL/SILBuilder.h

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -399,12 +399,6 @@ class SILBuilder {
399399
ElementCountOperands));
400400
}
401401

402-
AllocValueBufferInst *
403-
createAllocValueBuffer(SILLocation Loc, SILType valueType, SILValue operand) {
404-
return insert(AllocValueBufferInst::create(
405-
getSILDebugLocation(Loc), valueType, operand, *F));
406-
}
407-
408402
AllocBoxInst *createAllocBox(SILLocation Loc, CanSILBoxType BoxType,
409403
Optional<SILDebugVariable> Var = None,
410404
bool hasDynamicLifetime = false) {
@@ -1990,23 +1984,11 @@ class SILBuilder {
19901984
return insert(new (getModule()) DeallocExistentialBoxInst(
19911985
getSILDebugLocation(Loc), concreteType, operand));
19921986
}
1993-
DeallocValueBufferInst *createDeallocValueBuffer(SILLocation Loc,
1994-
SILType valueType,
1995-
SILValue operand) {
1996-
return insert(new (getModule()) DeallocValueBufferInst(
1997-
getSILDebugLocation(Loc), valueType, operand));
1998-
}
19991987
DestroyAddrInst *createDestroyAddr(SILLocation Loc, SILValue Operand) {
20001988
return insert(new (getModule())
20011989
DestroyAddrInst(getSILDebugLocation(Loc), Operand));
20021990
}
20031991

2004-
ProjectValueBufferInst *createProjectValueBuffer(SILLocation Loc,
2005-
SILType valueType,
2006-
SILValue operand) {
2007-
return insert(new (getModule()) ProjectValueBufferInst(
2008-
getSILDebugLocation(Loc), valueType, operand));
2009-
}
20101992
ProjectBoxInst *createProjectBox(SILLocation Loc, SILValue boxOperand,
20111993
unsigned index);
20121994
ProjectExistentialBoxInst *createProjectExistentialBox(SILLocation Loc,

include/swift/SIL/SILCloner.h

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -838,16 +838,6 @@ SILCloner<ImplClass>::visitAllocExistentialBoxInst(
838838
getOpASTType(origFormalType), conformances));
839839
}
840840

841-
template<typename ImplClass>
842-
void
843-
SILCloner<ImplClass>::visitAllocValueBufferInst(AllocValueBufferInst *Inst) {
844-
getBuilder().setCurrentDebugScope(getOpScope(Inst->getDebugScope()));
845-
recordClonedInstruction(Inst, getBuilder().createAllocValueBuffer(
846-
getOpLocation(Inst->getLoc()),
847-
getOpType(Inst->getValueType()),
848-
getOpValue(Inst->getOperand())));
849-
}
850-
851841
template<typename ImplClass>
852842
void
853843
SILCloner<ImplClass>::visitBuiltinInst(BuiltinInst *Inst) {
@@ -2471,16 +2461,6 @@ SILCloner<ImplClass>::visitDeallocPartialRefInst(DeallocPartialRefInst *Inst) {
24712461
getOpValue(Inst->getMetatype())));
24722462
}
24732463

2474-
template<typename ImplClass>
2475-
void SILCloner<ImplClass>::visitDeallocValueBufferInst(
2476-
DeallocValueBufferInst *Inst) {
2477-
getBuilder().setCurrentDebugScope(getOpScope(Inst->getDebugScope()));
2478-
recordClonedInstruction(Inst, getBuilder().createDeallocValueBuffer(
2479-
getOpLocation(Inst->getLoc()),
2480-
getOpType(Inst->getValueType()),
2481-
getOpValue(Inst->getOperand())));
2482-
}
2483-
24842464
template<typename ImplClass>
24852465
void
24862466
SILCloner<ImplClass>::visitDeallocBoxInst(DeallocBoxInst *Inst) {
@@ -2510,16 +2490,6 @@ SILCloner<ImplClass>::visitDestroyAddrInst(DestroyAddrInst *Inst) {
25102490
getOpValue(Inst->getOperand())));
25112491
}
25122492

2513-
template<typename ImplClass>
2514-
void SILCloner<ImplClass>::visitProjectValueBufferInst(
2515-
ProjectValueBufferInst *Inst) {
2516-
getBuilder().setCurrentDebugScope(getOpScope(Inst->getDebugScope()));
2517-
recordClonedInstruction(Inst, getBuilder().createProjectValueBuffer(
2518-
getOpLocation(Inst->getLoc()),
2519-
getOpType(Inst->getValueType()),
2520-
getOpValue(Inst->getOperand())));
2521-
}
2522-
25232493
template<typename ImplClass>
25242494
void SILCloner<ImplClass>::visitProjectBoxInst(ProjectBoxInst *Inst) {
25252495
getBuilder().setCurrentDebugScope(getOpScope(Inst->getDebugScope()));

include/swift/SIL/SILInstruction.h

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -2148,26 +2148,6 @@ class AllocRefDynamicInst final
21482148
}
21492149
};
21502150

2151-
/// AllocValueBufferInst - Allocate memory in a value buffer.
2152-
class AllocValueBufferInst final
2153-
: public UnaryInstructionWithTypeDependentOperandsBase<
2154-
SILInstructionKind::AllocValueBufferInst,
2155-
AllocValueBufferInst,
2156-
AllocationInst> {
2157-
friend SILBuilder;
2158-
2159-
AllocValueBufferInst(SILDebugLocation DebugLoc, SILType valueType,
2160-
SILValue operand,
2161-
ArrayRef<SILValue> TypeDependentOperands);
2162-
2163-
static AllocValueBufferInst *
2164-
create(SILDebugLocation DebugLoc, SILType valueType, SILValue operand,
2165-
SILFunction &F);
2166-
2167-
public:
2168-
SILType getValueType() const { return getType().getObjectType(); }
2169-
};
2170-
21712151
/// This represents the allocation of a heap box for a Swift value of some type.
21722152
/// The instruction returns two values. The first return value is the object
21732153
/// pointer with Builtin.NativeObject type. The second return value
@@ -7531,22 +7511,6 @@ class DeallocPartialRefInst
75317511
SILValue getMetatype() const { return getOperand(1); }
75327512
};
75337513

7534-
/// Deallocate memory allocated for an unsafe value buffer.
7535-
class DeallocValueBufferInst
7536-
: public UnaryInstructionBase<SILInstructionKind::DeallocValueBufferInst,
7537-
DeallocationInst> {
7538-
friend SILBuilder;
7539-
7540-
SILType ValueType;
7541-
7542-
DeallocValueBufferInst(SILDebugLocation DebugLoc, SILType valueType,
7543-
SILValue operand)
7544-
: UnaryInstructionBase(DebugLoc, operand), ValueType(valueType) {}
7545-
7546-
public:
7547-
SILType getValueType() const { return ValueType; }
7548-
};
7549-
75507514
/// Deallocate memory allocated for a boxed value created by an AllocBoxInst.
75517515
/// It is undefined behavior if the type of the boxed type does not match the
75527516
/// type the box was allocated for.
@@ -7601,21 +7565,6 @@ class DestroyAddrInst
76017565
: UnaryInstructionBase(DebugLoc, Operand) {}
76027566
};
76037567

7604-
/// Project out the address of the value
7605-
/// stored in the given Builtin.UnsafeValueBuffer.
7606-
class ProjectValueBufferInst
7607-
: public UnaryInstructionBase<SILInstructionKind::ProjectValueBufferInst,
7608-
SingleValueInstruction> {
7609-
friend SILBuilder;
7610-
7611-
ProjectValueBufferInst(SILDebugLocation DebugLoc, SILType valueType,
7612-
SILValue operand)
7613-
: UnaryInstructionBase(DebugLoc, operand, valueType.getAddressType()) {}
7614-
7615-
public:
7616-
SILType getValueType() const { return getType().getObjectType(); }
7617-
};
7618-
76197568
/// Project out the address of the value in a box.
76207569
class ProjectBoxInst
76217570
: public UnaryInstructionBase<SILInstructionKind::ProjectBoxInst,

include/swift/SIL/SILNode.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,6 @@ class alignas(8) SILNode :
238238
);
239239
static_assert(32-1-1-NumAllocationInstBits >= 14, "Reconsider bitfield use?");
240240

241-
UIWTDOB_BITFIELD_EMPTY(AllocValueBufferInst, AllocationInst);
242-
243241
// TODO: Sort the following in SILNodes.def order
244242

245243
SWIFT_INLINE_BITFIELD_EMPTY(NonValueInstruction, SILInstruction);

include/swift/SIL/SILNodes.def

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -440,8 +440,6 @@ ABSTRACT_VALUE_AND_INST(SingleValueInstruction, ValueBase, SILInstruction)
440440
AllocationInst, None, DoesNotRelease)
441441
BRIDGED_SINGLE_VALUE_INST(AllocRefDynamicInst, alloc_ref_dynamic,
442442
AllocationInst, None, DoesNotRelease)
443-
BRIDGED_SINGLE_VALUE_INST(AllocValueBufferInst, alloc_value_buffer,
444-
AllocationInst, None, DoesNotRelease)
445443
BRIDGED_SINGLE_VALUE_INST(AllocBoxInst, alloc_box,
446444
AllocationInst, None, DoesNotRelease)
447445
BRIDGED_SINGLE_VALUE_INST(AllocExistentialBoxInst, alloc_existential_box,
@@ -625,8 +623,6 @@ ABSTRACT_VALUE_AND_INST(SingleValueInstruction, ValueBase, SILInstruction)
625623
#include "swift/AST/ReferenceStorage.def"
626624
SINGLE_VALUE_INST(MarkUninitializedInst, mark_uninitialized,
627625
SingleValueInstruction, None, DoesNotRelease)
628-
SINGLE_VALUE_INST(ProjectValueBufferInst, project_value_buffer,
629-
SingleValueInstruction, MayRead, DoesNotRelease)
630626
SINGLE_VALUE_INST(ProjectBoxInst, project_box,
631627
SingleValueInstruction, None, DoesNotRelease)
632628
SINGLE_VALUE_INST(ProjectExistentialBoxInst, project_existential_box,
@@ -798,8 +794,6 @@ ABSTRACT_INST(DeallocationInst, SILInstruction)
798794
DeallocationInst, MayHaveSideEffects, DoesNotRelease)
799795
NON_VALUE_INST(DeallocPartialRefInst, dealloc_partial_ref,
800796
DeallocationInst, MayHaveSideEffects, DoesNotRelease)
801-
NON_VALUE_INST(DeallocValueBufferInst, dealloc_value_buffer,
802-
DeallocationInst, MayHaveSideEffects, DoesNotRelease)
803797
NON_VALUE_INST(DeallocBoxInst, dealloc_box,
804798
DeallocationInst, MayHaveSideEffects, DoesNotRelease)
805799
NON_VALUE_INST(DeallocExistentialBoxInst, dealloc_existential_box,

lib/IRGen/GenOpaque.cpp

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1293,40 +1293,6 @@ static llvm::Constant *getDeallocateValueInBufferFunction(IRGenModule &IGM) {
12931293
true /*noinline*/);
12941294
}
12951295

1296-
void irgen::emitDeallocateValueInBuffer(IRGenFunction &IGF,
1297-
SILType type,
1298-
Address buffer) {
1299-
// Handle FixedSize types.
1300-
auto &IGM = IGF.IGM;
1301-
auto &Builder = IGF.Builder;
1302-
if (auto *fixedTI = dyn_cast<FixedTypeInfo>(&IGF.getTypeInfo(type))) {
1303-
auto packing = fixedTI->getFixedPacking(IGM);
1304-
1305-
// Inline representation.
1306-
if (packing == FixedPacking::OffsetZero)
1307-
return;
1308-
1309-
// Outline representation.
1310-
assert(packing == FixedPacking::Allocate && "Expect non dynamic packing");
1311-
auto size = fixedTI->getStaticSize(IGM);
1312-
auto alignMask = fixedTI->getStaticAlignmentMask(IGM);
1313-
auto *ptr = Builder.CreateLoad(Address(
1314-
Builder.CreateBitCast(buffer.getAddress(), IGM.Int8PtrPtrTy),
1315-
buffer.getAlignment()));
1316-
IGF.emitDeallocRawCall(ptr, size, alignMask);
1317-
return;
1318-
}
1319-
1320-
// Dynamic packing.
1321-
auto *projectFun = getDeallocateValueInBufferFunction(IGF.IGM);
1322-
auto *metadata = IGF.emitTypeMetadataRefForLayout(type);
1323-
auto *call = Builder.CreateCall(
1324-
projectFun,
1325-
{metadata, Builder.CreateBitCast(buffer.getAddress(), IGM.OpaquePtrTy)});
1326-
call->setCallingConv(IGF.IGM.DefaultCC);
1327-
call->setDoesNotThrow();
1328-
}
1329-
13301296
llvm::Value *
13311297
irgen::emitGetEnumTagSinglePayloadGenericCall(IRGenFunction &IGF,
13321298
SILType payloadType,

lib/IRGen/GenOpaque.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -243,10 +243,6 @@ namespace irgen {
243243
Address emitProjectValueInBuffer(IRGenFunction &IGF,
244244
SILType type,
245245
Address buffer);
246-
void emitDeallocateValueInBuffer(IRGenFunction &IGF,
247-
SILType type,
248-
Address buffer);
249-
250246

251247
using GetExtraInhabitantTagEmitter =
252248
llvm::function_ref<llvm::Value*(IRGenFunction &IGF,

lib/IRGen/IRGenSIL.cpp

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1194,10 +1194,6 @@ class IRGenSILFunction :
11941194
void visitObjCSuperMethodInst(ObjCSuperMethodInst *i);
11951195
void visitWitnessMethodInst(WitnessMethodInst *i);
11961196

1197-
void visitAllocValueBufferInst(AllocValueBufferInst *i);
1198-
void visitProjectValueBufferInst(ProjectValueBufferInst *i);
1199-
void visitDeallocValueBufferInst(DeallocValueBufferInst *i);
1200-
12011197
void visitOpenExistentialAddrInst(OpenExistentialAddrInst *i);
12021198
void visitOpenExistentialMetatypeInst(OpenExistentialMetatypeInst *i);
12031199
void visitOpenExistentialRefInst(OpenExistentialRefInst *i);
@@ -6344,29 +6340,6 @@ void IRGenSILFunction::visitIndexRawPointerInst(swift::IndexRawPointerInst *i) {
63446340
setLoweredExplosion(i, result);
63456341
}
63466342

6347-
void IRGenSILFunction::visitAllocValueBufferInst(
6348-
swift::AllocValueBufferInst *i) {
6349-
Address buffer = getLoweredAddress(i->getOperand());
6350-
auto valueType = i->getValueType();
6351-
Address value = emitAllocateValueInBuffer(*this, valueType, buffer);
6352-
setLoweredAddress(i, value);
6353-
}
6354-
6355-
void IRGenSILFunction::visitProjectValueBufferInst(
6356-
swift::ProjectValueBufferInst *i) {
6357-
Address buffer = getLoweredAddress(i->getOperand());
6358-
auto valueType = i->getValueType();
6359-
Address value = emitProjectValueInBuffer(*this, valueType, buffer);
6360-
setLoweredAddress(i, value);
6361-
}
6362-
6363-
void IRGenSILFunction::visitDeallocValueBufferInst(
6364-
swift::DeallocValueBufferInst *i) {
6365-
Address buffer = getLoweredAddress(i->getOperand());
6366-
auto valueType = i->getValueType();
6367-
emitDeallocateValueInBuffer(*this, valueType, buffer);
6368-
}
6369-
63706343
void IRGenSILFunction::visitInitExistentialAddrInst(swift::InitExistentialAddrInst *i) {
63716344
Address container = getLoweredAddress(i->getOperand());
63726345
SILType destType = i->getOperand()->getType();

lib/SIL/IR/OperandOwnership.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,6 @@ OPERAND_OWNERSHIP(TrivialUse, OpenExistentialMetatype)
167167
OPERAND_OWNERSHIP(TrivialUse, PointerToAddress)
168168
OPERAND_OWNERSHIP(TrivialUse, PointerToThinFunction)
169169
OPERAND_OWNERSHIP(TrivialUse, ProjectBlockStorage)
170-
OPERAND_OWNERSHIP(TrivialUse, ProjectValueBuffer)
171170
OPERAND_OWNERSHIP(TrivialUse, RawPointerToRef)
172171
OPERAND_OWNERSHIP(TrivialUse, SelectEnumAddr)
173172
OPERAND_OWNERSHIP(TrivialUse, StructElementAddr)
@@ -182,8 +181,6 @@ OPERAND_OWNERSHIP(TrivialUse, UncheckedAddrCast)
182181
OPERAND_OWNERSHIP(TrivialUse, UncheckedRefCastAddr)
183182
OPERAND_OWNERSHIP(TrivialUse, UncheckedTakeEnumDataAddr)
184183
OPERAND_OWNERSHIP(TrivialUse, UnconditionalCheckedCastAddr)
185-
OPERAND_OWNERSHIP(TrivialUse, AllocValueBuffer)
186-
OPERAND_OWNERSHIP(TrivialUse, DeallocValueBuffer)
187184

188185
// Use an owned or guaranteed value only for the duration of the operation.
189186
OPERAND_OWNERSHIP(InstantaneousUse, ExistentialMetatype)

lib/SIL/IR/SILInstruction.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -426,11 +426,6 @@ namespace {
426426
return true;
427427
}
428428

429-
bool visitProjectValueBufferInst(const ProjectValueBufferInst *RHS) {
430-
auto *X = cast<ProjectValueBufferInst>(LHS);
431-
return X->getValueType() == RHS->getValueType();
432-
}
433-
434429
bool visitProjectBoxInst(const ProjectBoxInst *RHS) {
435430
return true;
436431
}

0 commit comments

Comments
 (0)