Skip to content

Commit 4433ab8

Browse files
committed
[rbi] Thread through a SILFunction into print routines so we can access LangOpts.Features so we can change how we print based off of NonisolatedNonsendingByDefault.
We do not actually use this information yet though... This is just to ease review.
1 parent 4ce4fc4 commit 4433ab8

File tree

6 files changed

+115
-115
lines changed

6 files changed

+115
-115
lines changed

include/swift/SILOptimizer/Analysis/RegionAnalysis.h

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -179,16 +179,16 @@ class regionanalysisimpl::TrackableValueState {
179179

180180
void removeFlag(TrackableValueFlag flag) { flagSet -= flag; }
181181

182-
void print(llvm::raw_ostream &os) const {
182+
void print(SILFunction *fn, llvm::raw_ostream &os) const {
183183
os << "TrackableValueState[id: " << id
184184
<< "][is_no_alias: " << (isNoAlias() ? "yes" : "no")
185185
<< "][is_sendable: " << (isSendable() ? "yes" : "no")
186186
<< "][region_value_kind: ";
187-
getIsolationRegionInfo().printForOneLineLogging(os);
187+
getIsolationRegionInfo().printForOneLineLogging(fn, os);
188188
os << "].";
189189
}
190190

191-
SWIFT_DEBUG_DUMP { print(llvm::dbgs()); }
191+
SWIFT_DEBUG_DUMPER(dump(SILFunction *fn)) { print(fn, llvm::dbgs()); }
192192

193193
private:
194194
bool hasIsolationRegionInfo() const { return bool(regionInfo); }
@@ -249,26 +249,26 @@ class regionanalysisimpl::TrackableValue {
249249
/// parameter.
250250
bool isSendingParameter() const;
251251

252-
void printIsolationInfo(SmallString<64> &outString) const {
252+
void printIsolationInfo(SILFunction *fn, SmallString<64> &outString) const {
253253
llvm::raw_svector_ostream os(outString);
254-
getIsolationRegionInfo().printForDiagnostics(os);
254+
getIsolationRegionInfo().printForDiagnostics(fn, os);
255255
}
256256

257-
void print(llvm::raw_ostream &os) const {
257+
void print(SILFunction *fn, llvm::raw_ostream &os) const {
258258
os << "TrackableValue. State: ";
259-
valueState.print(os);
259+
valueState.print(fn, os);
260260
os << "\n Rep Value: ";
261261
getRepresentative().print(os);
262262
}
263263

264-
void printVerbose(llvm::raw_ostream &os) const {
264+
void printVerbose(SILFunction *fn, llvm::raw_ostream &os) const {
265265
os << "TrackableValue. State: ";
266-
valueState.print(os);
266+
valueState.print(fn, os);
267267
os << "\n Rep Value: " << getRepresentative();
268268
}
269269

270-
SWIFT_DEBUG_DUMP {
271-
print(llvm::dbgs());
270+
SWIFT_DEBUG_DUMPER(dump(SILFunction *fn)) {
271+
print(fn, llvm::dbgs());
272272
llvm::dbgs() << '\n';
273273
}
274274
};
@@ -288,8 +288,8 @@ struct regionanalysisimpl::TrackableValueLookupResult {
288288
/// TrackableValue.
289289
std::optional<TrackableValue> base;
290290

291-
void print(llvm::raw_ostream &os) const;
292-
SWIFT_DEBUG_DUMP { print(llvm::dbgs()); }
291+
void print(SILFunction *fn, llvm::raw_ostream &os) const;
292+
SWIFT_DEBUG_DUMPER(dumper(SILFunction *fn)) { print(fn, llvm::dbgs()); }
293293
};
294294

295295
class RegionAnalysis;
@@ -390,6 +390,8 @@ class RegionAnalysisValueMap {
390390
return getUnderlyingTrackedValue(value).value;
391391
}
392392

393+
SILFunction *getFunction() const { return fn; }
394+
393395
/// Returns the value for this instruction if it isn't a fake "represenative
394396
/// value" to inject actor isolation. Asserts in such a case.
395397
SILValue getRepresentative(Element trackableValueID) const;

include/swift/SILOptimizer/Utils/SILIsolationInfo.h

Lines changed: 20 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -289,16 +289,16 @@ class SILIsolationInfo {
289289
return self;
290290
}
291291

292-
void print(llvm::raw_ostream &os) const;
292+
void print(SILFunction *fn, llvm::raw_ostream &os) const;
293293

294294
/// Print a textual representation of the text info that is meant to be
295295
/// included in other logging output for types that compose with
296296
/// SILIsolationInfo. As a result, we only print state that can fit on
297297
/// one line.
298-
void printForOneLineLogging(llvm::raw_ostream &os) const;
298+
void printForOneLineLogging(SILFunction *fn, llvm::raw_ostream &os) const;
299299

300-
SWIFT_DEBUG_DUMP {
301-
print(llvm::dbgs());
300+
SWIFT_DEBUG_DUMPER(dump(SILFunction *fn)) {
301+
print(fn, llvm::dbgs());
302302
llvm::dbgs() << '\n';
303303
}
304304

@@ -307,12 +307,12 @@ class SILIsolationInfo {
307307
///
308308
/// We do this programatically since task-isolated code needs a very different
309309
/// form of diagnostic than other cases.
310-
void printForCodeDiagnostic(llvm::raw_ostream &os) const;
310+
void printForCodeDiagnostic(SILFunction *fn, llvm::raw_ostream &os) const;
311311

312-
void printForDiagnostics(llvm::raw_ostream &os) const;
312+
void printForDiagnostics(SILFunction *fn, llvm::raw_ostream &os) const;
313313

314-
SWIFT_DEBUG_DUMPER(dumpForDiagnostics()) {
315-
printForDiagnostics(llvm::dbgs());
314+
SWIFT_DEBUG_DUMPER(dumpForDiagnostics(SILFunction *fn)) {
315+
printForDiagnostics(fn, llvm::dbgs());
316316
llvm::dbgs() << '\n';
317317
}
318318

@@ -497,10 +497,9 @@ class SILIsolationInfo {
497497
/// A helper function that prints ActorIsolation like we normally do except
498498
/// that it prints nonisolated(nonsending) as nonisolated. This is needed in
499499
/// certain cases when talking about use-after-free uses in send non sendable.
500-
static void
501-
printActorIsolationForDiagnostics(ActorIsolation iso, llvm::raw_ostream &os,
502-
StringRef openingQuotationMark = "'",
503-
bool asNoun = false);
500+
static void printActorIsolationForDiagnostics(
501+
SILFunction *fn, ActorIsolation iso, llvm::raw_ostream &os,
502+
StringRef openingQuotationMark = "'", bool asNoun = false);
504503

505504
void Profile(llvm::FoldingSetNodeID &id) const;
506505

@@ -565,43 +564,25 @@ class SILDynamicMergedIsolationInfo {
565564
SILIsolationInfo::getDisconnected(isUnsafeNonIsolated));
566565
}
567566

568-
SWIFT_DEBUG_DUMP { innerInfo.dump(); }
567+
SWIFT_DEBUG_DUMPER(dump(SILFunction *fn)) { innerInfo.dump(fn); }
569568

570-
void printForDiagnostics(llvm::raw_ostream &os) const {
571-
innerInfo.printForDiagnostics(os);
569+
void printForDiagnostics(SILFunction *fn, llvm::raw_ostream &os) const {
570+
innerInfo.printForDiagnostics(fn, os);
572571
}
573572

574-
SWIFT_DEBUG_DUMPER(dumpForDiagnostics()) {
575-
innerInfo.dumpForDiagnostics();
573+
SWIFT_DEBUG_DUMPER(dumpForDiagnostics(SILFunction *fn)) {
574+
innerInfo.dumpForDiagnostics(fn);
576575
}
577576

578-
void printForCodeDiagnostic(llvm::raw_ostream &os) const {
579-
innerInfo.printForCodeDiagnostic(os);
577+
void printForCodeDiagnostic(SILFunction *fn, llvm::raw_ostream &os) const {
578+
innerInfo.printForCodeDiagnostic(fn, os);
580579
}
581580

582-
void printForOneLineLogging(llvm::raw_ostream &os) const {
583-
innerInfo.printForOneLineLogging(os);
581+
void printForOneLineLogging(SILFunction *fn, llvm::raw_ostream &os) const {
582+
innerInfo.printForOneLineLogging(fn, os);
584583
}
585584
};
586585

587586
} // namespace swift
588587

589-
namespace llvm {
590-
591-
inline llvm::raw_ostream &
592-
operator<<(llvm::raw_ostream &os,
593-
const swift::SILIsolationInfo &isolationInfo) {
594-
isolationInfo.printForOneLineLogging(os);
595-
return os;
596-
}
597-
598-
inline llvm::raw_ostream &
599-
operator<<(llvm::raw_ostream &os,
600-
const swift::SILDynamicMergedIsolationInfo &isolationInfo) {
601-
isolationInfo.printForOneLineLogging(os);
602-
return os;
603-
}
604-
605-
} // namespace llvm
606-
607588
#endif

lib/SILOptimizer/Analysis/RegionAnalysis.cpp

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -823,7 +823,7 @@ void RegionAnalysisValueMap::print(llvm::raw_ostream &os) const {
823823
for (auto p : temp) {
824824
os << "%%" << p.first << ": ";
825825
auto value = getValueForId(Element(p.first));
826-
value->print(os);
826+
value->print(getFunction(), os);
827827
}
828828
#endif
829829
}
@@ -1130,12 +1130,13 @@ bool TrackableValue::isSendingParameter() const {
11301130
// MARK: TrackableValueLookupResult
11311131
//===----------------------------------------------------------------------===//
11321132

1133-
void TrackableValueLookupResult::print(llvm::raw_ostream &os) const {
1133+
void TrackableValueLookupResult::print(SILFunction *fn,
1134+
llvm::raw_ostream &os) const {
11341135
os << "Value:\n";
1135-
value.print(os);
1136+
value.print(fn, os);
11361137
if (base) {
11371138
os << "Base:\n";
1138-
base->print(os);
1139+
base->print(fn, os);
11391140
}
11401141
}
11411142

@@ -1633,6 +1634,11 @@ struct PartitionOpBuilder {
16331634
initialPartitionOpIndex = currentInstPartitionOps->size();
16341635
}
16351636

1637+
SILFunction *getFunction() const {
1638+
assert(currentInst);
1639+
return currentInst->getFunction();
1640+
}
1641+
16361642
void reset(SILInstruction *inst) {
16371643
assert(currentInstPartitionOps);
16381644
currentInst = inst;
@@ -2006,7 +2012,8 @@ class PartitionOpTranslator {
20062012
isNonSendableType(val->getType())) {
20072013
auto trackVal = getTrackableValue(val, true);
20082014
(void)trackVal;
2009-
REGIONBASEDISOLATION_LOG(trackVal.print(llvm::dbgs()));
2015+
REGIONBASEDISOLATION_LOG(
2016+
trackVal.print(val->getFunction(), llvm::dbgs()));
20102017
continue;
20112018
}
20122019
if (auto *pbi = dyn_cast<ProjectBoxInst>(val)) {
@@ -2083,7 +2090,7 @@ class PartitionOpTranslator {
20832090
// send list and to the region join list.
20842091
REGIONBASEDISOLATION_LOG(
20852092
llvm::dbgs() << " %%" << value.getID() << ": ";
2086-
value.print(llvm::dbgs()); llvm::dbgs() << *arg);
2093+
value.print(function, llvm::dbgs()); llvm::dbgs() << *arg);
20872094
nonSendableJoinedIndices.push_back(value.getID());
20882095
} else {
20892096
REGIONBASEDISOLATION_LOG(llvm::dbgs() << " Sendable: " << *arg);
@@ -2258,14 +2265,15 @@ class PartitionOpTranslator {
22582265
REGIONBASEDISOLATION_LOG(
22592266
llvm::dbgs() << "Merge Failure!\n"
22602267
<< "Original Info: ";
2261-
if (originalMergedInfo)
2262-
originalMergedInfo->printForDiagnostics(llvm::dbgs());
2268+
if (originalMergedInfo) originalMergedInfo->printForDiagnostics(
2269+
builder.getFunction(), llvm::dbgs());
22632270
else llvm::dbgs() << "nil";
22642271
llvm::dbgs() << "\nValue Rep: "
22652272
<< value.getRepresentative().getValue();
22662273
llvm::dbgs() << "Original Src: " << src;
22672274
llvm::dbgs() << "Value Info: ";
2268-
value.getIsolationRegionInfo().printForDiagnostics(llvm::dbgs());
2275+
value.getIsolationRegionInfo().printForDiagnostics(
2276+
builder.getFunction(), llvm::dbgs());
22692277
llvm::dbgs() << "\n");
22702278
builder.addUnknownPatternError(src);
22712279
continue;
@@ -3222,7 +3230,7 @@ void PartitionOpBuilder::print(llvm::raw_ostream &os) const {
32223230
auto trackableValue = translator->getValueForId(opArg);
32233231
assert(trackableValue);
32243232
llvm::dbgs() << "State: %%" << opArg << ". ";
3225-
trackableValue->getValueState().print(llvm::dbgs());
3233+
trackableValue->getValueState().print(getFunction(), llvm::dbgs());
32263234
llvm::dbgs() << "\n Rep Value: "
32273235
<< trackableValue->getRepresentative();
32283236
if (auto value = trackableValue->getRepresentative().maybeGetValue()) {
@@ -4300,7 +4308,7 @@ static FunctionTest
43004308
RegionAnalysisValueMap valueMap(&function);
43014309
auto value = arguments.takeValue();
43024310
auto trackableValue = valueMap.getTrackableValue(value);
4303-
trackableValue.print(llvm::outs());
4311+
trackableValue.print(&function, llvm::outs());
43044312
llvm::outs() << '\n';
43054313
});
43064314

0 commit comments

Comments
 (0)