Skip to content

Commit e1b17b9

Browse files
committed
[region-isolation] Rather than cache a separate vector of argument ids, just cache the function entry partition.
We only ever used this cache of IDs to construct the function arg partition. Since a Partition involves using memory, it makes sense to just cache the Partition itself and eliminate the unnecessary second cache.
1 parent 7fff6cd commit e1b17b9

File tree

1 file changed

+29
-25
lines changed

1 file changed

+29
-25
lines changed

lib/SILOptimizer/Mandatory/SendNonSendable.cpp

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ class PartitionOpTranslator {
339339
std::vector<TrackableValueID> neverTransferredValueIDs;
340340

341341
/// A cache of argument IDs.
342-
SmallVector<TrackableValueID> argIDs;
342+
std::optional<Partition> functionArgPartition;
343343

344344
/// A builder struct that we use to convert individual instructions into lists
345345
/// of PartitionOps.
@@ -523,35 +523,39 @@ class PartitionOpTranslator {
523523

524524
// ===========================================================================
525525

526-
/// Get the vector of IDs corresponding to the arguments to the underlying
527-
/// function, and the self parameter if there is one.
528-
ArrayRef<TrackableValueID> getArgIDs() const {
529-
auto functionArguments = function->getArguments();
530-
if (functionArguments.empty())
531-
return {};
532-
533-
// If we have arguments and argIDs is empty, then we need to initialize our
534-
// lazy array.
535-
if (argIDs.empty()) {
536-
auto *self = const_cast<PartitionOpTranslator *>(this);
537-
for (SILArgument *arg : functionArguments) {
538-
if (auto state = trackIfNonSendable(arg)) {
539-
self->neverTransferredValueIDs.push_back(state->getID());
540-
self->argIDs.push_back(state->getID());
541-
}
542-
}
543-
}
544-
545-
return argIDs;
546-
}
547-
548526
public:
549527
// Create a partition that places all arguments from this function,
550528
// including self if available, into the same region, ensuring those
551529
// arguments get IDs in doing so. This Partition will be used as the
552530
// entry point for the full partition analysis.
553-
Partition getEntryPartition() {
554-
return Partition::singleRegion(getArgIDs());
531+
Partition getEntryPartition() const {
532+
if (!functionArgPartition) {
533+
LLVM_DEBUG(llvm::dbgs() << "Initializing Function Args:\n");
534+
auto *self = const_cast<PartitionOpTranslator *>(this);
535+
auto functionArguments = function->getArguments();
536+
if (functionArguments.empty()) {
537+
LLVM_DEBUG(llvm::dbgs() << " None.\n");
538+
self->functionArgPartition = Partition::singleRegion({});
539+
} else {
540+
llvm::SmallVector<Element, 8> nonSendableIndices;
541+
for (SILArgument *arg : functionArguments) {
542+
if (auto state = tryToTrackValue(arg)) {
543+
// If we have an arg that is an actor, we allow for it to be
544+
// consumed... value ids derived from it though cannot be consumed.
545+
LLVM_DEBUG(llvm::dbgs() << " %%" << state->getID());
546+
self->neverTransferredValueIDs.push_back(state->getID());
547+
nonSendableIndices.push_back(state->getID());
548+
LLVM_DEBUG(llvm::dbgs() << *arg);
549+
}
550+
}
551+
552+
// All non actor values are in the same partition.
553+
self->functionArgPartition =
554+
Partition::singleRegion(nonSendableIndices);
555+
}
556+
}
557+
558+
return *functionArgPartition;
555559
}
556560

557561
// Get the vector of IDs that cannot be legally transferred at any point in

0 commit comments

Comments
 (0)