Skip to content

Commit ca8cdc1

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. (cherry picked from commit 4433ab8)
1 parent 0ec2527 commit ca8cdc1

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 isolatedness. 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
@@ -337,16 +337,16 @@ class SILIsolationInfo {
337337
return self;
338338
}
339339

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

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

348-
SWIFT_DEBUG_DUMP {
349-
print(llvm::dbgs());
348+
SWIFT_DEBUG_DUMPER(dump(SILFunction *fn)) {
349+
print(fn, llvm::dbgs());
350350
llvm::dbgs() << '\n';
351351
}
352352

@@ -355,12 +355,12 @@ class SILIsolationInfo {
355355
///
356356
/// We do this programatically since task-isolated code needs a very different
357357
/// form of diagnostic than other cases.
358-
void printForCodeDiagnostic(llvm::raw_ostream &os) const;
358+
void printForCodeDiagnostic(SILFunction *fn, llvm::raw_ostream &os) const;
359359

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

362-
SWIFT_DEBUG_DUMPER(dumpForDiagnostics()) {
363-
printForDiagnostics(llvm::dbgs());
362+
SWIFT_DEBUG_DUMPER(dumpForDiagnostics(SILFunction *fn)) {
363+
printForDiagnostics(fn, llvm::dbgs());
364364
llvm::dbgs() << '\n';
365365
}
366366

@@ -552,10 +552,9 @@ class SILIsolationInfo {
552552
/// A helper function that prints ActorIsolation like we normally do except
553553
/// that it prints nonisolated(nonsending) as nonisolated. This is needed in
554554
/// certain cases when talking about use-after-free uses in send non sendable.
555-
static void
556-
printActorIsolationForDiagnostics(ActorIsolation iso, llvm::raw_ostream &os,
557-
StringRef openingQuotationMark = "'",
558-
bool asNoun = false);
555+
static void printActorIsolationForDiagnostics(
556+
SILFunction *fn, ActorIsolation iso, llvm::raw_ostream &os,
557+
StringRef openingQuotationMark = "'", bool asNoun = false);
559558

560559
void Profile(llvm::FoldingSetNodeID &id) const;
561560

@@ -620,43 +619,25 @@ class SILDynamicMergedIsolationInfo {
620619
SILIsolationInfo::getDisconnected(isUnsafeNonIsolated));
621620
}
622621

623-
SWIFT_DEBUG_DUMP { innerInfo.dump(); }
622+
SWIFT_DEBUG_DUMPER(dump(SILFunction *fn)) { innerInfo.dump(fn); }
624623

625-
void printForDiagnostics(llvm::raw_ostream &os) const {
626-
innerInfo.printForDiagnostics(os);
624+
void printForDiagnostics(SILFunction *fn, llvm::raw_ostream &os) const {
625+
innerInfo.printForDiagnostics(fn, os);
627626
}
628627

629-
SWIFT_DEBUG_DUMPER(dumpForDiagnostics()) {
630-
innerInfo.dumpForDiagnostics();
628+
SWIFT_DEBUG_DUMPER(dumpForDiagnostics(SILFunction *fn)) {
629+
innerInfo.dumpForDiagnostics(fn);
631630
}
632631

633-
void printForCodeDiagnostic(llvm::raw_ostream &os) const {
634-
innerInfo.printForCodeDiagnostic(os);
632+
void printForCodeDiagnostic(SILFunction *fn, llvm::raw_ostream &os) const {
633+
innerInfo.printForCodeDiagnostic(fn, os);
635634
}
636635

637-
void printForOneLineLogging(llvm::raw_ostream &os) const {
638-
innerInfo.printForOneLineLogging(os);
636+
void printForOneLineLogging(SILFunction *fn, llvm::raw_ostream &os) const {
637+
innerInfo.printForOneLineLogging(fn, os);
639638
}
640639
};
641640

642641
} // namespace swift
643642

644-
namespace llvm {
645-
646-
inline llvm::raw_ostream &
647-
operator<<(llvm::raw_ostream &os,
648-
const swift::SILIsolationInfo &isolationInfo) {
649-
isolationInfo.printForOneLineLogging(os);
650-
return os;
651-
}
652-
653-
inline llvm::raw_ostream &
654-
operator<<(llvm::raw_ostream &os,
655-
const swift::SILDynamicMergedIsolationInfo &isolationInfo) {
656-
isolationInfo.printForOneLineLogging(os);
657-
return os;
658-
}
659-
660-
} // namespace llvm
661-
662643
#endif

lib/SILOptimizer/Analysis/RegionAnalysis.cpp

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -820,7 +820,7 @@ void RegionAnalysisValueMap::print(llvm::raw_ostream &os) const {
820820
for (auto p : temp) {
821821
os << "%%" << p.first << ": ";
822822
auto value = getValueForId(Element(p.first));
823-
value->print(os);
823+
value->print(getFunction(), os);
824824
}
825825
#endif
826826
}
@@ -1127,12 +1127,13 @@ bool TrackableValue::isSendingParameter() const {
11271127
// MARK: TrackableValueLookupResult
11281128
//===----------------------------------------------------------------------===//
11291129

1130-
void TrackableValueLookupResult::print(llvm::raw_ostream &os) const {
1130+
void TrackableValueLookupResult::print(SILFunction *fn,
1131+
llvm::raw_ostream &os) const {
11311132
os << "Value:\n";
1132-
value.print(os);
1133+
value.print(fn, os);
11331134
if (base) {
11341135
os << "Base:\n";
1135-
base->print(os);
1136+
base->print(fn, os);
11361137
}
11371138
}
11381139

@@ -1618,6 +1619,11 @@ struct PartitionOpBuilder {
16181619
/// generating partition ops.
16191620
SmallVector<PartitionOp, 8> currentInstPartitionOps;
16201621

1622+
SILFunction *getFunction() const {
1623+
assert(currentInst);
1624+
return currentInst->getFunction();
1625+
}
1626+
16211627
void reset(SILInstruction *inst) {
16221628
currentInst = inst;
16231629
currentInstPartitionOps.clear();
@@ -1978,7 +1984,8 @@ class PartitionOpTranslator {
19781984
isNonSendableType(val->getType())) {
19791985
auto trackVal = getTrackableValue(val, true);
19801986
(void)trackVal;
1981-
REGIONBASEDISOLATION_LOG(trackVal.print(llvm::dbgs()));
1987+
REGIONBASEDISOLATION_LOG(
1988+
trackVal.print(val->getFunction(), llvm::dbgs()));
19821989
continue;
19831990
}
19841991
if (auto *pbi = dyn_cast<ProjectBoxInst>(val)) {
@@ -2055,7 +2062,7 @@ class PartitionOpTranslator {
20552062
// send list and to the region join list.
20562063
REGIONBASEDISOLATION_LOG(
20572064
llvm::dbgs() << " %%" << value.getID() << ": ";
2058-
value.print(llvm::dbgs()); llvm::dbgs() << *arg);
2065+
value.print(function, llvm::dbgs()); llvm::dbgs() << *arg);
20592066
nonSendableJoinedIndices.push_back(value.getID());
20602067
} else {
20612068
REGIONBASEDISOLATION_LOG(llvm::dbgs() << " Sendable: " << *arg);
@@ -2228,14 +2235,15 @@ class PartitionOpTranslator {
22282235
REGIONBASEDISOLATION_LOG(
22292236
llvm::dbgs() << "Merge Failure!\n"
22302237
<< "Original Info: ";
2231-
if (originalMergedInfo)
2232-
originalMergedInfo->printForDiagnostics(llvm::dbgs());
2238+
if (originalMergedInfo) originalMergedInfo->printForDiagnostics(
2239+
builder.getFunction(), llvm::dbgs());
22332240
else llvm::dbgs() << "nil";
22342241
llvm::dbgs() << "\nValue Rep: "
22352242
<< value.getRepresentative().getValue();
22362243
llvm::dbgs() << "Original Src: " << src;
22372244
llvm::dbgs() << "Value Info: ";
2238-
value.getIsolationRegionInfo().printForDiagnostics(llvm::dbgs());
2245+
value.getIsolationRegionInfo().printForDiagnostics(
2246+
builder.getFunction(), llvm::dbgs());
22392247
llvm::dbgs() << "\n");
22402248
builder.addUnknownPatternError(src);
22412249
continue;
@@ -3220,7 +3228,7 @@ void PartitionOpBuilder::print(llvm::raw_ostream &os) const {
32203228
auto trackableValue = translator->getValueForId(opArg);
32213229
assert(trackableValue);
32223230
llvm::dbgs() << "State: %%" << opArg << ". ";
3223-
trackableValue->getValueState().print(llvm::dbgs());
3231+
trackableValue->getValueState().print(getFunction(), llvm::dbgs());
32243232
llvm::dbgs() << "\n Rep Value: "
32253233
<< trackableValue->getRepresentative();
32263234
if (auto value = trackableValue->getRepresentative().maybeGetValue()) {
@@ -4310,7 +4318,7 @@ static FunctionTest
43104318
RegionAnalysisValueMap valueMap(&function);
43114319
auto value = arguments.takeValue();
43124320
auto trackableValue = valueMap.getTrackableValue(value);
4313-
trackableValue.print(llvm::outs());
4321+
trackableValue.print(&function, llvm::outs());
43144322
llvm::outs() << '\n';
43154323
});
43164324

0 commit comments

Comments
 (0)