Skip to content

Commit 926b4b1

Browse files
committed
[region-isolation] Change TransferredReason to use a std::multimap.
In a future commit, I think I am going to change this to use a SmallFrozenMultiMap so we can avoid the heap cost in most cases. For now though I am just changing it to a std::multimap to make it cleaner and avoid having to reason about when to freeze the SmallFrozenMultiMap.
1 parent 81a20e8 commit 926b4b1

File tree

1 file changed

+14
-22
lines changed

1 file changed

+14
-22
lines changed

lib/SILOptimizer/Mandatory/SendNonSendable.cpp

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1237,50 +1237,43 @@ struct LocalTransferredReason {
12371237
// to be informative, so distance is used as a heuristic to choose which
12381238
// access sites to display in diagnostics given a racy consumption.
12391239
class TransferredReason {
1240-
std::map<unsigned, std::vector<PartitionOp>> transferOps;
1240+
std::multimap<unsigned, PartitionOp> transferOps;
12411241

12421242
friend class TransferRequireAccumulator;
12431243

12441244
bool containsOp(const PartitionOp& op) {
1245-
for (auto [_, vec] : transferOps)
1246-
for (auto vecOp : vec)
1247-
if (op == vecOp)
1248-
return true;
1249-
return false;
1245+
return llvm::any_of(transferOps,
1246+
[&](const std::pair<unsigned, PartitionOp> &pair) {
1247+
return pair.second == op;
1248+
});
12501249
}
12511250

12521251
public:
1253-
// a TransferredReason is valid if it contains at least one transfer
1254-
// instruction
1255-
bool isValid() {
1256-
for (auto [_, vec] : transferOps)
1257-
if (!vec.empty())
1258-
return true;
1259-
return false;
1260-
}
1252+
// A TransferredReason is valid if it contains at least one transfer
1253+
// instruction.
1254+
bool isValid() { return transferOps.size(); }
12611255

12621256
TransferredReason() {}
12631257

12641258
TransferredReason(LocalTransferredReason localReason) {
12651259
assert(localReason.kind == LocalTransferredReasonKind::LocalTransferInst);
1266-
transferOps[0] = {localReason.localInst.value()};
1260+
transferOps.emplace(0, localReason.localInst.value());
12671261
}
12681262

12691263
void addTransferOp(PartitionOp transferOp, unsigned distance) {
12701264
assert(transferOp.getKind() == PartitionOpKind::Transfer);
12711265
// duplicates should not arise
12721266
if (!containsOp(transferOp))
1273-
transferOps[distance].push_back(transferOp);
1267+
transferOps.emplace(distance, transferOp);
12741268
}
12751269

12761270
// merge in another transferredReason, adding the specified distane to all its
12771271
// ops
12781272
void addOtherReasonAtDistance(const TransferredReason &otherReason,
12791273
unsigned distance) {
1280-
for (auto &[otherDistance, otherTransferOpsAtDistance] :
1274+
for (auto &[otherDistance, otherTransferOpAtDistance] :
12811275
otherReason.transferOps)
1282-
for (auto otherTransferOp : otherTransferOpsAtDistance)
1283-
addTransferOp(otherTransferOp, distance + otherDistance);
1276+
addTransferOp(otherTransferOpAtDistance, distance + otherDistance);
12841277
}
12851278
};
12861279

@@ -1319,9 +1312,8 @@ class TransferRequireAccumulator {
13191312

13201313
void accumulateTransferredReason(PartitionOp requireOp,
13211314
const TransferredReason &transferredReason) {
1322-
for (auto [distance, transferOps] : transferredReason.transferOps)
1323-
for (auto transferOp : transferOps)
1324-
requirementsForTransfers[transferOp].insert({requireOp, distance});
1315+
for (auto [distance, transferOp] : transferredReason.transferOps)
1316+
requirementsForTransfers[transferOp].insert({requireOp, distance});
13251317
}
13261318

13271319
void emitErrorsForTransferRequire(

0 commit comments

Comments
 (0)