Skip to content

[SIL] Enabled printing canonical module. #39393

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions include/swift/SILOptimizer/PassManager/Passes.def
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,8 @@ PASS(Outliner, "outliner",
"Function Outlining Optimization")
PASS(OwnershipModelEliminator, "ownership-model-eliminator",
"Eliminate Ownership Annotation of SIL")
PASS(ModulePrinter, "module-printer",
"Print the module")
PASS(NestedSemanticFunctionCheck, "nested-semantic-function-check",
"Diagnose improperly nested '@_semantics' functions")
PASS(NonTransparentFunctionOwnershipModelEliminator,
Expand Down
21 changes: 17 additions & 4 deletions lib/SILOptimizer/PassManager/PassPipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,14 @@ static llvm::cl::opt<bool>
SILViewCFG("sil-view-cfg", llvm::cl::init(false),
llvm::cl::desc("Enable the sil cfg viewer pass"));

static llvm::cl::opt<bool> SILViewGuaranteedCFG(
"sil-view-guaranteed-cfg", llvm::cl::init(false),
static llvm::cl::opt<bool> SILViewCanonicalCFG(
"sil-view-canonical-cfg", llvm::cl::init(false),
llvm::cl::desc("Enable the sil cfg viewer pass after diagnostics"));

static llvm::cl::opt<bool> SILPrintCanonicalModule(
"sil-print-canonical-module", llvm::cl::init(false),
llvm::cl::desc("Print the textual SIL module after diagnostics"));

static llvm::cl::opt<bool> SILViewSILGenCFG(
"sil-view-silgen-cfg", llvm::cl::init(false),
llvm::cl::desc("Enable the sil cfg viewer pass before diagnostics"));
Expand All @@ -64,6 +68,12 @@ static void addCFGPrinterPipeline(SILPassPipelinePlan &P, StringRef Name) {
P.addCFGPrinter();
}

static void addModulePrinterPipeline(SILPassPipelinePlan &plan,
StringRef name) {
plan.startPipeline(name);
plan.addModulePrinter();
}

static void addMandatoryDebugSerialization(SILPassPipelinePlan &P) {
P.startPipeline("Mandatory Debug Serialization");
P.addOwnershipModelEliminator();
Expand Down Expand Up @@ -187,8 +197,11 @@ SILPassPipelinePlan::getDiagnosticPassPipeline(const SILOptions &Options) {
// Otherwise run the rest of diagnostics.
addMandatoryDiagnosticOptPipeline(P);

if (SILViewGuaranteedCFG) {
addCFGPrinterPipeline(P, "SIL View Guaranteed CFG");
if (SILViewCanonicalCFG) {
addCFGPrinterPipeline(P, "SIL View Canonical CFG");
}
if (SILPrintCanonicalModule) {
addModulePrinterPipeline(P, "SIL Print Canonical Module");
}
return P;
}
Expand Down
1 change: 1 addition & 0 deletions lib/SILOptimizer/UtilityPasses/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ target_sources(swiftSILOptimizer PRIVATE
LoopInfoPrinter.cpp
LoopRegionPrinter.cpp
MemBehaviorDumper.cpp
ModulePrinter.cpp
RCIdentityDumper.cpp
SerializeSILPass.cpp
SILDebugInfoGenerator.cpp
Expand Down
38 changes: 38 additions & 0 deletions lib/SILOptimizer/UtilityPasses/ModulePrinter.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//===--- ModulePrinter.cpp - Module printer pass --------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2021 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
//
// A utility module pass to print the module as textual SIL.
//
//===----------------------------------------------------------------------===//

#include "swift/SIL/SILPrintContext.h"
#include "swift/SILOptimizer/PassManager/Passes.h"
#include "swift/SILOptimizer/PassManager/Transforms.h"

using namespace swift;

namespace {

class SILModulePrinter : public SILModuleTransform {

/// The entry point.
void run() override {
auto *module = getModule();
SILPrintContext context(llvm::outs(), /*Verbose*/ true, /*SortedSIL*/ true,
/*PrintFullConvention*/ true);
module->print(context);
}
};

} // end anonymous namespace

SILTransform *swift::createModulePrinter() { return new SILModulePrinter(); }