Skip to content

Commit c9fe8ff

Browse files
committed
[region-isolation] Eliminate unnecessary using TrackableValueID = Element.
Having two artificial typedefs for the same wrapped value is just confusing. Better to just have one and make the code simpler to understand.
1 parent beaab91 commit c9fe8ff

File tree

3 files changed

+22
-27
lines changed

3 files changed

+22
-27
lines changed

include/swift/SILOptimizer/Analysis/RegionAnalysis.h

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class RegionAnalysisFunctionInfo;
2828
namespace regionanalysisimpl {
2929

3030
using TransferringOperandSetFactory = Partition::TransferringOperandSetFactory;
31-
using TrackableValueID = PartitionPrimitives::Element;
31+
using Element = PartitionPrimitives::Element;
3232
using Region = PartitionPrimitives::Region;
3333

3434
/// Check if the passed in type is NonSendable.
@@ -175,7 +175,7 @@ class regionanalysisimpl::TrackableValueState {
175175

176176
SILIsolationInfo getIsolationRegionInfo() const { return regionInfo; }
177177

178-
TrackableValueID getID() const { return TrackableValueID(id); }
178+
Element getID() const { return Element(id); }
179179

180180
void addFlag(TrackableValueFlag flag) { flagSet |= flag; }
181181

@@ -276,9 +276,7 @@ class regionanalysisimpl::TrackableValue {
276276
return valueState.getIsolationRegionInfo();
277277
}
278278

279-
TrackableValueID getID() const {
280-
return TrackableValueID(valueState.getID());
281-
}
279+
Element getID() const { return Element(valueState.getID()); }
282280

283281
/// Return the representative value of this equivalence class of values.
284282
RepresentativeValue getRepresentative() const { return representativeValue; }
@@ -320,7 +318,6 @@ class RegionAnalysisValueMap {
320318
using Region = PartitionPrimitives::Region;
321319
using TrackableValue = regionanalysisimpl::TrackableValue;
322320
using TrackableValueState = regionanalysisimpl::TrackableValueState;
323-
using TrackableValueID = Element;
324321
using RepresentativeValue = regionanalysisimpl::RepresentativeValue;
325322

326323
private:
@@ -374,14 +371,14 @@ class RegionAnalysisValueMap {
374371
SILInstruction *introducingInst) const;
375372

376373
private:
377-
std::optional<TrackableValue> getValueForId(TrackableValueID id) const;
374+
std::optional<TrackableValue> getValueForId(Element id) const;
378375
std::optional<TrackableValue> tryToTrackValue(SILValue value) const;
379376
TrackableValue
380377
getActorIntroducingRepresentative(SILInstruction *introducingInst,
381378
SILIsolationInfo isolation) const;
382379
bool mergeIsolationRegionInfo(SILValue value, SILIsolationInfo isolation);
383380
bool valueHasID(SILValue value, bool dumpIfHasNoID = false);
384-
TrackableValueID lookupValueID(SILValue value);
381+
Element lookupValueID(SILValue value);
385382
};
386383

387384
class RegionAnalysisFunctionInfo {

lib/SILOptimizer/Analysis/RegionAnalysis.cpp

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1145,11 +1145,10 @@ struct PartitionOpBuilder {
11451145
currentInstPartitionOps.clear();
11461146
}
11471147

1148-
TrackableValueID lookupValueID(SILValue value);
1148+
Element lookupValueID(SILValue value);
11491149
bool valueHasID(SILValue value, bool dumpIfHasNoID = false);
11501150

1151-
TrackableValueID
1152-
getActorIntroducingRepresentative(SILIsolationInfo actorIsolation);
1151+
Element getActorIntroducingRepresentative(SILIsolationInfo actorIsolation);
11531152

11541153
void addAssignFresh(SILValue value) {
11551154
currentInstPartitionOps.emplace_back(
@@ -1160,7 +1159,7 @@ struct PartitionOpBuilder {
11601159
assert(valueHasID(src, /*dumpIfHasNoID=*/true) &&
11611160
"source value of assignment should already have been encountered");
11621161

1163-
TrackableValueID srcID = lookupValueID(src);
1162+
Element srcID = lookupValueID(src);
11641163
if (lookupValueID(tgt) == srcID) {
11651164
LLVM_DEBUG(llvm::dbgs() << " Skipping assign since tgt and src have "
11661165
"the same representative.\n");
@@ -1501,7 +1500,7 @@ class PartitionOpTranslator {
15011500
return partialApplyReachabilityDataflow.isReachable(value, inst);
15021501
}
15031502

1504-
std::optional<TrackableValue> getValueForId(TrackableValueID id) const {
1503+
std::optional<TrackableValue> getValueForId(Element id) const {
15051504
return valueMap.getValueForId(id);
15061505
}
15071506

@@ -1542,7 +1541,7 @@ class PartitionOpTranslator {
15421541
return valueMap.valueHasID(value, dumpIfHasNoID);
15431542
}
15441543

1545-
TrackableValueID lookupValueID(SILValue value) {
1544+
Element lookupValueID(SILValue value) {
15461545
return valueMap.lookupValueID(value);
15471546
}
15481547

@@ -2288,11 +2287,11 @@ class PartitionOpTranslator {
22882287
} // namespace regionanalysisimpl
22892288
} // namespace swift
22902289

2291-
TrackableValueID PartitionOpBuilder::lookupValueID(SILValue value) {
2290+
Element PartitionOpBuilder::lookupValueID(SILValue value) {
22922291
return translator->lookupValueID(value);
22932292
}
22942293

2295-
TrackableValueID PartitionOpBuilder::getActorIntroducingRepresentative(
2294+
Element PartitionOpBuilder::getActorIntroducingRepresentative(
22962295
SILIsolationInfo actorIsolation) {
22972296
return translator
22982297
->getActorIntroducingRepresentative(currentInst, actorIsolation)
@@ -2332,17 +2331,17 @@ void PartitionOpBuilder::print(llvm::raw_ostream &os) const {
23322331

23332332
// Now print out a translation from region to equivalence class value.
23342333
llvm::dbgs() << " └─────╼ Used Values\n";
2335-
llvm::SmallVector<TrackableValueID, 8> opsToPrint;
2334+
llvm::SmallVector<Element, 8> opsToPrint;
23362335
SWIFT_DEFER { opsToPrint.clear(); };
23372336
for (const PartitionOp &op : ops) {
23382337
// Now dump our the root value we map.
23392338
for (unsigned opArg : op.getOpArgs()) {
23402339
// If we didn't insert, skip this. We only emit this once.
2341-
opsToPrint.push_back(TrackableValueID(opArg));
2340+
opsToPrint.push_back(Element(opArg));
23422341
}
23432342
}
23442343
sortUnique(opsToPrint);
2345-
for (TrackableValueID opArg : opsToPrint) {
2344+
for (Element opArg : opsToPrint) {
23462345
llvm::dbgs() << " └╼ ";
23472346
auto trackableValue = translator->getValueForId(opArg);
23482347
assert(trackableValue);
@@ -3202,7 +3201,7 @@ SILInstruction *RegionAnalysisValueMap::maybeGetActorIntroducingInst(
32023201
}
32033202

32043203
std::optional<TrackableValue>
3205-
RegionAnalysisValueMap::getValueForId(TrackableValueID id) const {
3204+
RegionAnalysisValueMap::getValueForId(Element id) const {
32063205
auto iter = stateIndexToEquivalenceClass.find(id);
32073206
if (iter == stateIndexToEquivalenceClass.end())
32083207
return {};
@@ -3579,7 +3578,7 @@ bool RegionAnalysisValueMap::valueHasID(SILValue value, bool dumpIfHasNoID) {
35793578
return hasID;
35803579
}
35813580

3582-
TrackableValueID RegionAnalysisValueMap::lookupValueID(SILValue value) {
3581+
Element RegionAnalysisValueMap::lookupValueID(SILValue value) {
35833582
auto state = getTrackableValue(value);
35843583
assert(state.isNonSendable() &&
35853584
"only non-Sendable values should be entered in the map");

lib/SILOptimizer/Mandatory/TransferNonSendable.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ using namespace swift::regionanalysisimpl;
4646
namespace {
4747

4848
using TransferringOperandSetFactory = Partition::TransferringOperandSetFactory;
49-
using TrackableValueID = PartitionPrimitives::Element;
49+
using Element = PartitionPrimitives::Element;
5050
using Region = PartitionPrimitives::Region;
5151

5252
} // namespace
@@ -1330,10 +1330,9 @@ struct DiagnosticEvaluator final
13301330
transferredNonTransferrable(transferredNonTransferrable) {}
13311331

13321332
void handleLocalUseAfterTransfer(const PartitionOp &partitionOp,
1333-
TrackableValueID transferredVal,
1333+
Element transferredVal,
13341334
Operand *transferringOp) const {
13351335
auto &operandState = operandToStateMap.get(transferringOp);
1336-
13371336
// Ignore this if we have a gep like instruction that is returning a
13381337
// sendable type and transferringOp was not set with closure
13391338
// capture.
@@ -1364,7 +1363,7 @@ struct DiagnosticEvaluator final
13641363

13651364
void
13661365
handleTransferNonTransferrable(const PartitionOp &partitionOp,
1367-
TrackableValueID transferredVal,
1366+
Element transferredVal,
13681367
SILIsolationInfo isolationRegionInfo) const {
13691368
LLVM_DEBUG(llvm::dbgs()
13701369
<< " Emitting TransferNonTransferrable Error!\n"
@@ -1384,8 +1383,8 @@ struct DiagnosticEvaluator final
13841383

13851384
void
13861385
handleTransferNonTransferrable(const PartitionOp &partitionOp,
1387-
TrackableValueID transferredVal,
1388-
TrackableValueID actualNonTransferrableValue,
1386+
Element transferredVal,
1387+
Element actualNonTransferrableValue,
13891388
SILIsolationInfo isolationRegionInfo) const {
13901389
LLVM_DEBUG(llvm::dbgs()
13911390
<< " Emitting TransferNonTransferrable Error!\n"

0 commit comments

Comments
 (0)