Skip to content

Commit 3e04b86

Browse files
committed
make ModulePassContext conform to CustomStringConvertible
and let its description return a dump of the whole module. This is useful for debugging
1 parent e95c642 commit 3e04b86

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

SwiftCompilerSources/Sources/Optimizer/PassManager/ModulePassContext.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,14 @@ import OptimizerBridging
1818
/// It provides access to all functions, v-tables and witness tables of a module,
1919
/// but it doesn't provide any APIs to modify functions.
2020
/// In order to modify a function, a module pass must use `transform(function:)`.
21-
struct ModulePassContext : Context {
21+
struct ModulePassContext : Context, CustomStringConvertible {
2222
let _bridged: BridgedPassContext
2323

24+
public var description: String {
25+
let stdString = _bridged.getModuleDescription()
26+
return String(_cxxString: stdString)
27+
}
28+
2429
struct FunctionList : CollectionLikeSequence, IteratorProtocol {
2530
private var currentFunction: Function?
2631

include/swift/SILOptimizer/OptimizerBridging.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ struct BridgedPostDomTree {
149149
struct BridgedPassContext {
150150
swift::SwiftPassInvocation * _Nonnull invocation;
151151

152+
std::string getModuleDescription() const;
153+
152154
SWIFT_IMPORT_UNSAFE
153155
BridgedChangeNotificationHandler asNotificationHandler() const {
154156
return {invocation};

lib/SILOptimizer/PassManager/PassManager.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1417,6 +1417,14 @@ void BridgedChangeNotificationHandler::notifyChanges(Kind changeKind) const {
14171417
}
14181418
}
14191419

1420+
std::string BridgedPassContext::getModuleDescription() const {
1421+
std::string str;
1422+
llvm::raw_string_ostream os(str);
1423+
invocation->getPassManager()->getModule()->print(os);
1424+
str.pop_back(); // Remove trailing newline.
1425+
return str;
1426+
}
1427+
14201428
bool BridgedPassContext::tryDeleteDeadClosure(BridgedInstruction closure) const {
14211429
return ::tryDeleteDeadClosure(closure.getAs<SingleValueInstruction>(), InstModCallbacks());
14221430
}

0 commit comments

Comments
 (0)