Skip to content

Commit b760fec

Browse files
committed
[region-isolation] Just iterate directly over a block state's partition ops rather than use a callback.
There isn't a strong reason to use a callback here since we aren't ever composing transformations on partition ops. Better instead to go for simplicity and just iterate directly. If we start doing complex transformations over partition ops with composable APIs, we can always add this back in later. As a nice benefit, one doesn't need to worry that the callback API is hiding actual complexity... since just by using a for loop we communicate that nothing interesting is happening here. Just reducing the amount of code surface area in the pass.
1 parent 332ba1f commit b760fec

File tree

1 file changed

+14
-27
lines changed

1 file changed

+14
-27
lines changed

lib/SILOptimizer/Mandatory/TransferNonSendable.cpp

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1398,15 +1398,6 @@ class BlockPartitionState {
13981398
}
13991399

14001400
public:
1401-
/// Run the passed action on each partitionOp in this block. Action should
1402-
/// return true iff iteration should continue.
1403-
void forEachPartitionOp(
1404-
llvm::function_ref<bool(const PartitionOp &)> action) const {
1405-
for (const PartitionOp &partitionOp : blockPartitionOps)
1406-
if (!action(partitionOp))
1407-
break;
1408-
}
1409-
14101401
ArrayRef<PartitionOp> getPartitionOps() const { return blockPartitionOps; }
14111402

14121403
const Partition &getEntryPartition() const { return entryPartition; }
@@ -1831,15 +1822,15 @@ class RaceTracer {
18311822
if (!targetOp && transferredAtExitReasons.count({SILBlock, transferredVal}))
18321823
return transferredAtExitReasons.at({SILBlock, transferredVal});
18331824

1834-
const BlockPartitionState &block = blockStates[SILBlock];
1825+
const BlockPartitionState &blockState = blockStates[SILBlock];
18351826

18361827
// If targetOp is null, we're checking why the value is transferred at exit,
18371828
// so assert that it's actually transferred at exit
1838-
assert(targetOp || block.getExitPartition().isTransferred(transferredVal));
1829+
assert(targetOp || blockState.getExitPartition().isTransferred(transferredVal));
18391830

18401831
std::optional<LocalTransferredReason> transferredReason;
18411832

1842-
Partition workingPartition = block.getEntryPartition();
1833+
Partition workingPartition = blockState.getEntryPartition();
18431834

18441835
// We are looking for a local reason, so if the value is transferred at
18451836
// entry, revive it for the sake of this search.
@@ -1849,10 +1840,10 @@ class RaceTracer {
18491840
eval.apply(PartitionOp::AssignFresh(transferredVal));
18501841
}
18511842

1852-
int i = 0;
1853-
block.forEachPartitionOp([&](const PartitionOp &partitionOp) {
1843+
for (const auto &partitionOp : blockState.getPartitionOps()) {
18541844
if (targetOp == partitionOp)
1855-
return false; // break
1845+
break;
1846+
18561847
PartitionOpEvaluator eval(workingPartition);
18571848
eval.emitLog = false;
18581849
eval.apply(partitionOp);
@@ -1869,16 +1860,12 @@ class RaceTracer {
18691860
if (!workingPartition.isTransferred(transferredVal) && transferredReason)
18701861
// Value is no longer transferred - e.g. reassigned or assigned fresh.
18711862
transferredReason = llvm::None;
1872-
1873-
// continue walking block
1874-
i++;
1875-
return true;
1876-
});
1863+
}
18771864

18781865
// If we failed to find a local transfer reason, but the value was
18791866
// transferred at entry to the block, then the reason is "NonLocal".
18801867
if (!transferredReason &&
1881-
block.getEntryPartition().isTransferred(transferredVal))
1868+
blockState.getEntryPartition().isTransferred(transferredVal))
18821869
transferredReason = LocalTransferredReason::NonLocal();
18831870

18841871
// If transferredReason is none, then transferredVal was not actually
@@ -1902,13 +1889,14 @@ class RaceTracer {
19021889

19031890
bool printBlockSearch(raw_ostream &os, SILBasicBlock *SILBlock,
19041891
TrackableValueID transferredVal) const {
1905-
unsigned i = 0;
1906-
const BlockPartitionState &block = blockStates[SILBlock];
1907-
Partition working = block.getEntryPartition();
1892+
const BlockPartitionState &blockState = blockStates[SILBlock];
1893+
Partition working = blockState.getEntryPartition();
19081894
PartitionOpEvaluator eval(working);
19091895
os << "┌──────────╼\n";
19101896
working.print(os);
1911-
block.forEachPartitionOp([&](const PartitionOp &op) {
1897+
1898+
unsigned i = 0;
1899+
for (const auto &op : blockState.getPartitionOps()) {
19121900
os << "├[" << i++ << "] ";
19131901
op.print(os);
19141902
eval.apply(op);
@@ -1917,8 +1905,7 @@ class RaceTracer {
19171905
os << "(" << transferredVal << " TRANSFERRED) ";
19181906
}
19191907
working.print(os);
1920-
return true;
1921-
});
1908+
}
19221909
os << "└──────────╼\n";
19231910
return false;
19241911
}

0 commit comments

Comments
 (0)