Skip to content

Commit be16822

Browse files
committed
[ownership] Remove BranchPropagatedUser.
The only reason why BranchPropagatedUser existed was because early on in SIL, we weren't sure if cond_br should be able to handle non-trivial values in ossa. Now, we have reached the point where we have enough experience to make the judgement that it is not worth having in the representation due to it not holding its weight. Now that in ToT we have banned cond_br from having non-trivial operands in ossa, I can just eliminate BranchPropagatedUser and replace it with the operands that we used to construct them! A few notes: 1. Part of my motiviation in doing this is that I want to change LiveRange to store operands instead of instructions. This is because we are interested in being able to understand the LiveRange at a use granularity in cases where we have multiple operands. While doing this, I discovered that I needed SILInstructions to use the Linear Lifetime Checker. Then I realized that now was the time to just unwind BranchPropagatedUser. 2. In certain places in SemanticARCOpts, I had to do add some extra copies to transform arrays of instructions from LiveRange into their operand form. I am going to remove them in a subsequent commit when I change LiveRange to work on operands. I am doing this split to be incremental. 3. I changed isSingleInitAllocStack to have an out array of Operand *. The only user of this code is today in SemanticARCOpts and this information is fed to the Linear Lifetime Checker, so I needed to do it.
1 parent 0392b18 commit be16822

14 files changed

+136
-332
lines changed

include/swift/SIL/ApplySite.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ class ApplySite {
134134
/// Return the callee operand as a value.
135135
SILValue getCallee() const { return getCalleeOperand()->get(); }
136136

137+
/// Return the callee operand.
138+
Operand *getCalleeOperand() { FOREACH_IMPL_RETURN(getCalleeOperand()); }
139+
137140
/// Return the callee operand.
138141
const Operand *getCalleeOperand() const {
139142
FOREACH_IMPL_RETURN(getCalleeOperand());

include/swift/SIL/BasicBlockUtils.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,13 @@ class DeadEndBlocks {
7171
DeadEndBlocks(const SILFunction *F) : F(F) {}
7272

7373
/// Returns true if \p BB is a dead-end block.
74-
bool isDeadEnd(SILBasicBlock *BB) {
74+
bool isDeadEnd(const SILBasicBlock *block) {
7575
if (!isComputed) {
7676
// Lazily compute the dataflow.
7777
compute();
7878
isComputed = true;
7979
}
80-
return ReachableBlocks.count(BB) == 0;
80+
return ReachableBlocks.count(block) == 0;
8181
}
8282
};
8383

include/swift/SIL/BranchPropagatedUser.h

Lines changed: 0 additions & 158 deletions
This file was deleted.

include/swift/SIL/LinearLifetimeChecker.h

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
#include "swift/Basic/Debug.h"
1717
#include "swift/Basic/LLVM.h"
18-
#include "swift/SIL/BranchPropagatedUser.h"
1918
#include "swift/SIL/SILArgument.h"
2019
#include "swift/SIL/SILInstruction.h"
2120
#include "swift/SIL/SILValue.h"
@@ -29,7 +28,6 @@ class SILInstruction;
2928
class SILModule;
3029
class SILValue;
3130
class DeadEndBlocks;
32-
class BranchPropagatedUser;
3331

3432
namespace ownership {
3533

@@ -167,30 +165,21 @@ class LinearLifetimeChecker {
167165
/// \p leakingBlocks If non-null a list of blocks where the value was detected
168166
/// to leak. Can be used to insert missing destroys.
169167
LinearLifetimeError
170-
checkValue(SILValue value, ArrayRef<BranchPropagatedUser> consumingUses,
171-
ArrayRef<BranchPropagatedUser> nonConsumingUses,
168+
checkValue(SILValue value, ArrayRef<Operand *> consumingUses,
169+
ArrayRef<Operand *> nonConsumingUses,
172170
ownership::ErrorBehaviorKind errorBehavior,
173171
SmallVectorImpl<SILBasicBlock *> *leakingBlocks = nullptr);
174172

175173
/// Returns true that \p value forms a linear lifetime with consuming uses \p
176174
/// consumingUses, non consuming uses \p nonConsumingUses. Returns false
177175
/// otherwise.
178-
bool validateLifetime(SILValue value,
179-
ArrayRef<BranchPropagatedUser> consumingUses,
180-
ArrayRef<BranchPropagatedUser> nonConsumingUses) {
176+
bool validateLifetime(SILValue value, ArrayRef<Operand *> consumingUses,
177+
ArrayRef<Operand *> nonConsumingUses) {
181178
return !checkValue(value, consumingUses, nonConsumingUses,
182179
ownership::ErrorBehaviorKind::ReturnFalse,
183180
nullptr /*leakingBlocks*/)
184181
.getFoundError();
185182
}
186-
187-
bool validateLifetime(SILValue value,
188-
ArrayRef<SILInstruction *> consumingUses,
189-
ArrayRef<SILInstruction *> nonConsumingUses) {
190-
return validateLifetime(
191-
value, BranchPropagatedUser::convertFromInstArray(consumingUses),
192-
BranchPropagatedUser::convertFromInstArray(nonConsumingUses));
193-
}
194183
};
195184

196185
} // namespace swift

include/swift/SIL/MemAccessUtils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ bool memInstMustInitialize(Operand *memOper);
540540
/// alloc_stack. If the alloc_stack is destroyed in pieces, we do not guarantee
541541
/// that the list of destroying users is a minimal jointly post-dominating set.
542542
bool isSingleInitAllocStack(AllocStackInst *asi,
543-
SmallVectorImpl<SILInstruction *> &destroyingUsers);
543+
SmallVectorImpl<Operand *> &destroyingUses);
544544

545545
/// Return true if the given address producer may be the source of a formal
546546
/// access (a read or write of a potentially aliased, user visible variable).

include/swift/SIL/OwnershipUtils.h

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -319,16 +319,15 @@ struct BorrowScopeIntroducingValue {
319319

320320
bool isLocalScope() const { return kind.isLocalScope(); }
321321

322-
/// Returns true if the passed in set of instructions is completely within the
323-
/// lifetime of this borrow introducer.
322+
/// Returns true if the passed in set of uses is completely within
323+
/// the lifetime of this borrow introducer.
324324
///
325325
/// NOTE: Scratch space is used internally to this method to store the end
326326
/// borrow scopes if needed.
327-
bool
328-
areInstructionsWithinScope(ArrayRef<SILInstruction *> instructions,
329-
SmallVectorImpl<SILInstruction *> &scratchSpace,
330-
SmallPtrSetImpl<SILBasicBlock *> &visitedBlocks,
331-
DeadEndBlocks &deadEndBlocks) const;
327+
bool areUsesWithinScope(ArrayRef<Operand *> instructions,
328+
SmallVectorImpl<Operand *> &scratchSpace,
329+
SmallPtrSetImpl<SILBasicBlock *> &visitedBlocks,
330+
DeadEndBlocks &deadEndBlocks) const;
332331

333332
/// Given a local borrow scope introducer, visit all non-forwarding consuming
334333
/// users. This means that this looks through guaranteed block arguments.

include/swift/SIL/SILInstruction.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1875,6 +1875,7 @@ class ApplyInstBase<Impl, Base, false> : public Base {
18751875
/// The operand number of the first argument.
18761876
static unsigned getArgumentOperandNumber() { return NumStaticOperands; }
18771877

1878+
Operand *getCalleeOperand() { return &getAllOperands()[Callee]; }
18781879
const Operand *getCalleeOperand() const { return &getAllOperands()[Callee]; }
18791880
SILValue getCallee() const { return getCalleeOperand()->get(); }
18801881

0 commit comments

Comments
 (0)