Skip to content

Commit

Permalink
[sil-bug-reducer] Create the sil-passpipeline-dumper tool.
Browse files Browse the repository at this point in the history
This enables one to dump the various passpipelines in a yaml format. Other
pretty print formats can be added in the future as well if desired. Its intended
usage is to provide a source of pass pipeline information for external python
bug-reducing tools. By integrating this as a compiler-tool, we are guaranteed to
never have to update any of these tools in the face of passpipeline changes.
  • Loading branch information
gottesmm committed Dec 12, 2016
1 parent 483388c commit bf4864b
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/SILOptimizer/PassManager/PassPipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ void SILPassPipelinePlan::print(llvm::raw_ostream &os) {
<< " \"" << Pipeline.ExecutionKind << '"';
for (PassKind Kind : getPipelinePasses(Pipeline)) {
os << ",\n [\"" << PassKindID(Kind) << "\"," << PassKindName(Kind)
<< "\"]";
<< ']';
}
}
os << "\n ]\n";
Expand Down
2 changes: 1 addition & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function(get_test_dependencies SDK result_var_name)

set(deps_binaries
swift swift-ide-test sil-opt swift-llvm-opt swift-demangle
sil-func-extractor sil-nm
sil-func-extractor sil-nm sil-passpipeline-dumper
lldb-moduleimport-test swift-reflection-dump swift-remoteast-test
swift-api-digester)
if(NOT SWIFT_BUILT_STANDALONE)
Expand Down
3 changes: 3 additions & 0 deletions test/lit.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ config.swiftc = inferSwiftBinary('swiftc')
config.sil_opt = inferSwiftBinary('sil-opt')
config.sil_func_extractor = inferSwiftBinary('sil-func-extractor')
config.sil_nm = inferSwiftBinary('sil-nm')
config.sil_passpipeline_dumper = inferSwiftBinary('sil-passpipeline-dumper')
config.lldb_moduleimport_test = inferSwiftBinary('lldb-moduleimport-test')
config.swift_ide_test = inferSwiftBinary('swift-ide-test')
config.swift_reflection_dump = inferSwiftBinary('swift-reflection-dump')
Expand Down Expand Up @@ -358,6 +359,7 @@ config.substitutions.append( ('%swiftc_driver', "env SDKROOT= %r %s %s" % (confi
config.substitutions.append( ('%sil-opt', "%r %s" % (config.sil_opt, mcp_opt)) )
config.substitutions.append( ('%sil-func-extractor', "%r %s" % (config.sil_func_extractor, mcp_opt)) )
config.substitutions.append( ('%sil-nm', "%r %s" % (config.sil_nm, mcp_opt)) )
config.substitutions.append( ('%sil-passpipeline-dumper', "%r" % (config.sil_passpipeline_dumper)) )
config.substitutions.append( ('%lldb-moduleimport-test', "%r %s" % (config.lldb_moduleimport_test, mcp_opt)) )
config.substitutions.append( ('%swift-ide-test_plain', config.swift_ide_test) )
config.substitutions.append( ('%swift-ide-test', "%r %s %s -swift-version %s" % (config.swift_ide_test, mcp_opt, ccp_opt, swift_version)) )
Expand Down Expand Up @@ -430,6 +432,7 @@ disallow('swiftc_driver')
disallow('sil-opt')
disallow('sil-func-extractor')
disallow('sil-nm')
disallow('sil-passpipeline-dumper')
disallow('lldb-moduleimport-test')
disallow('swift-ide-test')
disallow('clang')
Expand Down
17 changes: 17 additions & 0 deletions test/sil-passpipeline-dump/basic.test-sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// RUN: %sil-passpipeline-dumper -Onone | %FileCheck %s
// RUN: %sil-passpipeline-dumper -Onone | python -c 'import json; import sys; json.load(sys.stdin)'

// CHECK: [
// CHECK: [
// CHECK: "Prespecialization",
// CHECK: "until_fix_point",
// CHECK: ["UsePrespecialized","use-prespecialized"]
// CHECK: ],
// CHECK: [
// CHECK: "Rest of Onone",
// CHECK: "one_iteration",
// CHECK: ["ExternalDefsToDecls","external-defs-to-decls"],
// CHECK: ["AssumeSingleThreaded","sil-assume-single-threaded"],
// CHECK: ["SILDebugInfoGenerator","sil-debuginfo-gen"]
// CHECK: ]
// CHECK: ]
1 change: 1 addition & 0 deletions tools/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ add_swift_tool_subdirectory(swift-demangle)
add_swift_tool_subdirectory(lldb-moduleimport-test)
add_swift_tool_subdirectory(sil-func-extractor)
add_swift_tool_subdirectory(sil-nm)
add_swift_tool_subdirectory(sil-passpipeline-dumper)
add_swift_tool_subdirectory(swift-llvm-opt)
add_swift_tool_subdirectory(swift-api-digester)

Expand Down
12 changes: 12 additions & 0 deletions tools/sil-passpipeline-dumper/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
add_swift_host_tool(sil-passpipeline-dumper
SILPassPipelineDumper.cpp
LINK_LIBRARIES
swiftFrontend
swiftSILGen
swiftSILOptimizer
swiftSerialization
swiftClangImporter
LLVM_COMPONENT_DEPENDS
DebugInfoCodeView
SWIFT_COMPONENT tools
)
72 changes: 72 additions & 0 deletions tools/sil-passpipeline-dumper/SILPassPipelineDumper.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
//===--- SILPassPipelineDumper.cpp ----------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
///
/// \file
///
/// This is a simple tool that dumps out a yaml description of one of the
/// current list of pass pipelines. Meant to be used to script on top of
/// sil-opt.
///
//===----------------------------------------------------------------------===//

#include "swift/Basic/LLVM.h"
#include "swift/Basic/LLVMInitialize.h"
#include "swift/SILOptimizer/PassManager/PassPipeline.h"
#include "llvm/Support/CommandLine.h"

using namespace swift;

static llvm::cl::opt<PassPipelineKind>
PipelineKind(llvm::cl::desc("<pipeline kind>"), llvm::cl::values(
#define PASSPIPELINE(NAME, DESCRIPTION) \
clEnumValN(PassPipelineKind::NAME, #NAME, DESCRIPTION),
#include "swift/SILOptimizer/PassManager/PassPipeline.def"
clEnumValEnd));

namespace llvm {
llvm::raw_ostream &operator<<(llvm::raw_ostream &os, PassPipelineKind Kind) {
switch (Kind) {
#define PASSPIPELINE(NAME, DESCRIPTION) \
case PassPipelineKind::NAME: \
return os << #NAME;
#include "swift/SILOptimizer/PassManager/PassPipeline.def"
}
}
}

int main(int argc, char **argv) {
INITIALIZE_LLVM(argc, argv);

llvm::cl::ParseCommandLineOptions(argc, argv,
"Swift SIL Pass Pipeline Dumper\n");

// TODO: add options to manipulate this.
SILOptions Opt;

switch (PipelineKind) {
#define PASSPIPELINE(NAME, DESCRIPTION) \
case PassPipelineKind::NAME: { \
SILPassPipelinePlan::get##NAME##PassPipeline().print(llvm::outs()); \
break; \
}
#define PASSPIPELINE_WITH_OPTIONS(NAME, DESCRIPTION) \
case PassPipelineKind::NAME: { \
SILPassPipelinePlan::get##NAME##PassPipeline(Opt).print(llvm::outs()); \
break; \
}
#include "swift/SILOptimizer/PassManager/PassPipeline.def"
}

llvm::outs() << '\n';

return 0;
};

0 comments on commit bf4864b

Please sign in to comment.