Skip to content

[region-isolation] Fix actor region propagation and some other smaller issues. #69387

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 27 additions & 10 deletions include/swift/SILOptimizer/Utils/PartitionUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,21 +171,22 @@ class PartitionOp {
void print(llvm::raw_ostream &os) const {
switch (OpKind) {
case PartitionOpKind::Assign:
os << "assign %%" << OpArgs[0] << " = %%" << OpArgs[1] << "\n";
os << "assign %%" << OpArgs[0] << " = %%" << OpArgs[1];
break;
case PartitionOpKind::AssignFresh:
os << "assign_fresh %%" << OpArgs[0] << "\n";
os << "assign_fresh %%" << OpArgs[0];
break;
case PartitionOpKind::Transfer:
os << "transfer %%" << OpArgs[0] << "\n";
os << "transfer %%" << OpArgs[0];
break;
case PartitionOpKind::Merge:
os << "merge %%" << OpArgs[0] << " with %%" << OpArgs[1] << "\n";
os << "merge %%" << OpArgs[0] << " with %%" << OpArgs[1];
break;
case PartitionOpKind::Require:
os << "require %%" << OpArgs[0] << "\n";
os << "require %%" << OpArgs[0];
break;
}
os << ": " << *getSourceInst(true);
}
};

Expand Down Expand Up @@ -408,7 +409,9 @@ class Partition {
[](const PartitionOp &, Element) {},
ArrayRef<Element> nonconsumables = {},
llvm::function_ref<void(const PartitionOp &, Element)>
handleConsumeNonConsumable = [](const PartitionOp &, Element) {}) {
handleConsumeNonConsumable = [](const PartitionOp &, Element) {},
llvm::function_ref<bool(Element)> isActorDerived = nullptr) {

REGIONBASEDISOLATION_VERBOSE_LOG(llvm::dbgs() << "Applying: ";
op.print(llvm::dbgs()));
REGIONBASEDISOLATION_VERBOSE_LOG(llvm::dbgs() << " Before: ";
Expand Down Expand Up @@ -444,7 +447,7 @@ class Partition {
fresh_label = Region(fresh_label + 1);
canonical = false;
break;
case PartitionOpKind::Transfer:
case PartitionOpKind::Transfer: {
assert(op.OpArgs.size() == 1 &&
"Consume PartitionOp should be passed 1 argument");
assert(labels.count(op.OpArgs[0]) &&
Expand All @@ -464,12 +467,26 @@ class Partition {
}
}

// ensure region is transferred
// If this value is actor derived or if any elements in its region are
// actor derived, we need to treat as non-consumable.
if (isActorDerived && isActorDerived(op.OpArgs[0]))
return handleConsumeNonConsumable(op, op.OpArgs[0]);
Region elementRegion = labels.at(op.OpArgs[0]);
if (llvm::any_of(labels,
[&](const std::pair<Element, Region> &pair) -> bool {
if (pair.second != elementRegion)
return false;
return isActorDerived && isActorDerived(pair.first);
}))
return handleConsumeNonConsumable(op, op.OpArgs[0]);

// Ensure if the region is transferred...
if (!isTransferred(op.OpArgs[0]))
// mark region as transferred
// that all elements associated with the region are marked as
// transferred.
horizontalUpdate(labels, op.OpArgs[0], Region::transferred());

break;
}
case PartitionOpKind::Merge:
assert(op.OpArgs.size() == 2 &&
"Merge PartitionOp should be passed 2 arguments");
Expand Down
Loading