rename spt-opt and spt-translate to cirt-*

This commit is contained in:
Chris Lattner 2020-04-29 11:45:54 -07:00
parent 5411096ddd
commit 66e9c9ca25
25 changed files with 271 additions and 56 deletions

View File

@ -7,8 +7,8 @@ configure_lit_site_cfg(
set(CIRT_TEST_DEPENDS
FileCheck count not
spt-opt
spt-translate
cirt-opt
cirt-translate
firtool
)

View File

@ -1,4 +1,4 @@
; RUN: spt-translate -parse-fir --mlir-print-debuginfo %s | spt-translate -emit-verilog -verify-diagnostics | FileCheck %s --strict-whitespace
; RUN: cirt-translate -parse-fir --mlir-print-debuginfo %s | cirt-translate -emit-verilog -verify-diagnostics | FileCheck %s --strict-whitespace
circuit Xorr :
module inputs_only :

View File

@ -1,4 +1,4 @@
// RUN: spt-translate -emit-verilog -verify-diagnostics --split-input-file -mlir-print-op-on-diagnostic=false %s
// RUN: cirt-translate -emit-verilog -verify-diagnostics --split-input-file -mlir-print-op-on-diagnostic=false %s
func @foo() { // expected-error {{unknown operation}}
}

View File

@ -1,4 +1,4 @@
// RUN: spt-translate %s -emit-verilog -verify-diagnostics | FileCheck %s --strict-whitespace
// RUN: cirt-translate %s -emit-verilog -verify-diagnostics | FileCheck %s --strict-whitespace
firrtl.circuit "Circuit" {
firrtl.module @M1(%x : !firrtl.uint<8> { firrtl.name = "y"},

View File

@ -1,4 +1,4 @@
; RUN: spt-translate -parse-fir -verify-diagnostics %s | spt-opt | FileCheck %s
; RUN: cirt-translate -parse-fir -verify-diagnostics %s | cirt-opt | FileCheck %s
circuit basic : ; CHECK: firrtl.circuit "basic" {

View File

@ -1,4 +1,4 @@
; RUN: spt-translate -parse-fir -verify-diagnostics --split-input-file %s
; RUN: cirt-translate -parse-fir -verify-diagnostics --split-input-file %s
circuit test :
extmodule MyModule :

View File

@ -1,4 +1,4 @@
; RUN: spt-translate -parse-fir --mlir-print-debuginfo -verify-diagnostics %s | FileCheck %s
; RUN: cirt-translate -parse-fir --mlir-print-debuginfo -verify-diagnostics %s | FileCheck %s
circuit basic : @[CIRCUIT.scala 127]

View File

@ -1,4 +1,4 @@
// RUN: spt-opt -canonicalize %s | FileCheck %s
// RUN: cirt-opt -canonicalize %s | FileCheck %s
// CHECK-LABEL: firrtl.module @And

View File

@ -1,4 +1,4 @@
// RUN: spt-opt %s -split-input-file -verify-diagnostics
// RUN: cirt-opt %s -split-input-file -verify-diagnostics
firrtl.module @X(%b : !firrtl.unknowntype) {
// expected-error @-1 {{unknown firrtl type}}

View File

@ -1,4 +1,4 @@
// RUN: spt-opt %s | FileCheck %s
// RUN: cirt-opt %s | FileCheck %s
//module MyModule :
// input in: UInt<8>

View File

@ -1,4 +1,4 @@
; RUN: firtool %s --format=fir -mlir | spt-opt | FileCheck %s --check-prefix=MLIR
; RUN: firtool %s --format=fir -mlir | cirt-opt | FileCheck %s --check-prefix=MLIR
; RUN: firtool %s --format=fir -verilog | FileCheck %s --check-prefix=VERILOG
circuit fir_test :

View File

@ -1,4 +1,4 @@
// RUN: firtool %s --format=mlir -mlir | spt-opt | FileCheck %s --check-prefix=MLIR
// RUN: firtool %s --format=mlir -mlir | cirt-opt | FileCheck %s --check-prefix=MLIR
// RUN: firtool %s --format=mlir -verilog | FileCheck %s --check-prefix=VERILOG
firrtl.circuit "Top" {

View File

@ -1,5 +1,5 @@
; RUN: firtool %s --format=fir | spt-opt | FileCheck %s --check-prefix=OPT
; RUN: firtool %s --format=fir -disable-opt | spt-opt | FileCheck %s --check-prefix=NOOPT
; RUN: firtool %s --format=fir | cirt-opt | FileCheck %s --check-prefix=OPT
; RUN: firtool %s --format=fir -disable-opt | cirt-opt | FileCheck %s --check-prefix=NOOPT
circuit optimizations :
module test_cse :

View File

@ -53,8 +53,8 @@ llvm_config.with_environment('PATH', config.llvm_tools_dir, append_path=True)
tool_dirs = [config.spt_tools_dir, config.mlir_tools_dir, config.llvm_tools_dir]
tools = [
'spt-opt',
'spt-translate',
'cirt-opt',
'cirt-translate',
]
llvm_config.add_tool_substitutions(tools, tool_dirs)

View File

@ -1,3 +1,3 @@
// RUN: spt-opt --help | FileCheck %s
// RUN: cirt-opt --help | FileCheck %s
//
// CHECK: OVERVIEW: spt modular optimizer driver

View File

@ -1,4 +1,4 @@
// RUN: spt-opt %s -allow-unregistered-dialect | FileCheck %s
// RUN: cirt-opt %s -allow-unregistered-dialect | FileCheck %s
// CHECK-LABEL: func @simpleCFG(%{{.*}}: i32, %{{.*}}: f32) -> i1 {
func @simpleCFG(%arg0: i32, %f: f32) -> i1 {

View File

@ -1,4 +1,4 @@
add_subdirectory(spt-opt)
add_subdirectory(spt-translate)
add_subdirectory(cirt-opt)
add_subdirectory(cirt-translate)
add_subdirectory(firtool)

View File

@ -0,0 +1,19 @@
set(LIBS
MLIRFIRRTL
MLIRParser
MLIRSupport
MLIRIR
MLIROptLib
MLIRStandardOps
MLIRTransforms
LLVMSupport
)
add_llvm_tool(cirt-opt
cirt-opt.cpp
)
llvm_update_compile_flags(cirt-opt)
target_link_libraries(cirt-opt PRIVATE ${LIBS} ${targets_to_link})

106
tools/cirt-opt/cirt-opt.cpp Normal file
View File

@ -0,0 +1,106 @@
//===- cirt-opt.cpp - The cirt-opt driver ---------------------------------===//
//
// This file implements the 'cirt-opt' tool, which is the spt analog of
// mlir-opt, used to drive compiler passes, e.g. for testing.
//
//===----------------------------------------------------------------------===//
#include "cirt/Dialect/FIRRTL/Dialect.h"
#include "mlir/Dialect/StandardOps/IR/Ops.h"
#include "mlir/Pass/Pass.h"
#include "mlir/Pass/PassManager.h"
#include "mlir/Pass/PassRegistry.h"
#include "mlir/Support/FileUtilities.h"
#include "mlir/Support/MlirOptMain.h"
#include "mlir/Transforms/Passes.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/InitLLVM.h"
#include "llvm/Support/ToolOutputFile.h"
using namespace llvm;
using namespace mlir;
using namespace cirt;
static cl::opt<std::string>
inputFilename(cl::Positional, cl::desc("<input file>"), cl::init("-"));
static cl::opt<std::string> outputFilename("o", cl::desc("Output filename"),
cl::value_desc("filename"),
cl::init("-"));
static cl::opt<bool>
splitInputFile("split-input-file",
cl::desc("Split the input file into pieces and process each "
"chunk independently"),
cl::init(false));
static cl::opt<bool>
verifyDiagnostics("verify-diagnostics",
cl::desc("Check that emitted diagnostics match "
"expected-* lines on the corresponding line"),
cl::init(false));
static cl::opt<bool>
verifyPasses("verify-each",
cl::desc("Run the verifier after each transformation pass"),
cl::init(true));
static cl::opt<bool>
showDialects("show-dialects",
cl::desc("Print the list of registered dialects"),
cl::init(false));
static cl::opt<bool> allowUnregisteredDialects(
"allow-unregistered-dialect",
cl::desc("Allow operation with no registered dialects"), cl::init(false));
int main(int argc, char **argv) {
InitLLVM y(argc, argv);
// Register MLIR stuff
registerDialect<StandardOpsDialect>();
// Register the standard passes we want.
#define GEN_PASS_REGISTRATION_Canonicalizer
#define GEN_PASS_REGISTRATION_CSE
#include "mlir/Transforms/Passes.h.inc"
// Register any pass manager command line options.
registerMLIRContextCLOptions();
registerPassManagerCLOptions();
// Register FIRRTL stuff.
registerDialect<firrtl::FIRRTLDialect>();
PassPipelineCLParser passPipeline("", "Compiler passes to run");
// Parse pass names in main to ensure static initialization completed.
cl::ParseCommandLineOptions(argc, argv, "spt modular optimizer driver\n");
MLIRContext context;
if (showDialects) {
llvm::outs() << "Registered Dialects:\n";
for (Dialect *dialect : context.getRegisteredDialects()) {
llvm::outs() << dialect->getNamespace() << "\n";
}
return 0;
}
// Set up the input file.
std::string errorMessage;
auto file = openInputFile(inputFilename, &errorMessage);
if (!file) {
llvm::errs() << errorMessage << "\n";
return 1;
}
auto output = openOutputFile(outputFilename, &errorMessage);
if (!output) {
llvm::errs() << errorMessage << "\n";
exit(1);
}
return failed(MlirOptMain(output->os(), std::move(file), passPipeline,
splitInputFile, verifyDiagnostics, verifyPasses,
allowUnregisteredDialects));
}

View File

@ -0,0 +1,13 @@
set(LIBS
MLIRTranslation
MLIRIR
MLIRSupport
SPTEmitVerilog
SPTFIRParser
)
add_llvm_tool(cirt-translate
cirt-translate.cpp
)
llvm_update_compile_flags(cirt-translate)
target_link_libraries(cirt-translate PRIVATE ${LIBS} LLVMSupport)

View File

@ -0,0 +1,109 @@
//===- cirt-translate.cpp - CIRT Translation Driver -----------------------===//
//
// This is a command line utility that translates a file from/to MLIR using one
// of the registered translations.
//
//===----------------------------------------------------------------------===//
#include "cirt/Dialect/FIRRTL/Dialect.h"
#include "cirt/EmitVerilog.h"
#include "cirt/FIRParser.h"
#include "mlir/Dialect/StandardOps/IR/Ops.h"
#include "mlir/IR/AsmState.h"
#include "mlir/IR/Diagnostics.h"
#include "mlir/IR/Dialect.h"
#include "mlir/IR/MLIRContext.h"
#include "mlir/Support/FileUtilities.h"
#include "mlir/Support/ToolUtilities.h"
#include "mlir/Translation.h"
#include "llvm/Support/InitLLVM.h"
#include "llvm/Support/ToolOutputFile.h"
using namespace mlir;
using namespace cirt;
static llvm::cl::opt<std::string> inputFilename(llvm::cl::Positional,
llvm::cl::desc("<input file>"),
llvm::cl::init("-"));
static llvm::cl::opt<std::string>
outputFilename("o", llvm::cl::desc("Output filename"),
llvm::cl::value_desc("filename"), llvm::cl::init("-"));
static llvm::cl::opt<bool>
splitInputFile("split-input-file",
llvm::cl::desc("Split the input file into pieces and "
"process each chunk independently"),
llvm::cl::init(false));
static llvm::cl::opt<bool> verifyDiagnostics(
"verify-diagnostics",
llvm::cl::desc("Check that emitted diagnostics match "
"expected-* lines on the corresponding line"),
llvm::cl::init(false));
int main(int argc, char **argv) {
// Register MLIR stuff.
registerAsmPrinterCLOptions();
registerMLIRContextCLOptions();
registerDialect<StandardOpsDialect>();
// Register FIRRTL stuff.
registerDialect<firrtl::FIRRTLDialect>();
registerFIRParserTranslation();
registerVerilogEmitterTranslation();
llvm::InitLLVM y(argc, argv);
// Add flags for all the registered translations.
llvm::cl::opt<const TranslateFunction *, false, TranslationParser>
translationRequested("", llvm::cl::desc("Translation to perform"),
llvm::cl::Required);
llvm::cl::ParseCommandLineOptions(argc, argv, "SPT translation driver\n");
std::string errorMessage;
auto input = openInputFile(inputFilename, &errorMessage);
if (!input) {
llvm::errs() << errorMessage << "\n";
return 1;
}
auto output = openOutputFile(outputFilename, &errorMessage);
if (!output) {
llvm::errs() << errorMessage << "\n";
return 1;
}
// Processes the memory buffer with a new MLIRContext.
auto processBuffer = [&](std::unique_ptr<llvm::MemoryBuffer> ownedBuffer,
raw_ostream &os) {
MLIRContext context;
llvm::SourceMgr sourceMgr;
sourceMgr.AddNewSourceBuffer(std::move(ownedBuffer), llvm::SMLoc());
if (!verifyDiagnostics) {
SourceMgrDiagnosticHandler sourceMgrHandler(sourceMgr, &context);
return (*translationRequested)(sourceMgr, os, &context);
}
// In the diagnostic verification flow, we ignore whether the translation
// failed (in most cases, it is expected to fail). Instead, we check if the
// diagnostics were produced as expected.
SourceMgrDiagnosticVerifierHandler sourceMgrHandler(sourceMgr, &context);
(*translationRequested)(sourceMgr, os, &context);
return sourceMgrHandler.verify();
};
if (splitInputFile) {
if (failed(splitAndProcessBuffer(std::move(input), processBuffer,
output->os())))
return 1;
} else {
if (failed(processBuffer(std::move(input), output->os())))
return 1;
}
output->keep();
return 0;
}

View File

@ -1,19 +0,0 @@
set(LIBS
MLIRFIRRTL
MLIRParser
MLIRSupport
MLIRIR
MLIROptLib
MLIRStandardOps
MLIRTransforms
LLVMSupport
)
add_llvm_tool(spt-opt
spt-opt.cpp
)
llvm_update_compile_flags(spt-opt)
target_link_libraries(spt-opt PRIVATE ${LIBS} ${targets_to_link})

View File

@ -1,6 +1,6 @@
//===- spt-opt.cpp - The spt-opt driver -----------------------------------===//
//===- cirt-opt.cpp - The cirt-opt driver -----------------------------------===//
//
// This file implements the 'spt-opt' tool, which is the spt analog of mlir-opt,
// This file implements the 'cirt-opt' tool, which is the spt analog of mlir-opt,
// used to drive compiler passes, e.g. for testing.
//
//===----------------------------------------------------------------------===//

View File

@ -1,13 +0,0 @@
set(LIBS
MLIRTranslation
MLIRIR
MLIRSupport
SPTEmitVerilog
SPTFIRParser
)
add_llvm_tool(spt-translate
spt-translate.cpp
)
llvm_update_compile_flags(spt-translate)
target_link_libraries(spt-translate PRIVATE ${LIBS} LLVMSupport)

View File

@ -1,4 +1,4 @@
//===- spt-translate.cpp - SPT Translate Driver ---------------------------===//
//===- cirt-translate.cpp - SPT Translate Driver ---------------------------===//
//
// This is a command line utility that translates a file from/to MLIR using one
// of the registered translations.