mirror of https://github.com/llvm/circt.git
Push the cmake files far enough along to make spt-opt be able to link in
MLIR libraries, parsing and printing the output, running passes, etc.
This commit is contained in:
parent
64cec97240
commit
7783a53c8e
|
@ -7,6 +7,11 @@ set(SPT_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
|
|||
|
||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules")
|
||||
|
||||
|
||||
## Should get this from MLIR build files somehow?
|
||||
set(MLIR_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../llvm-project/mlir/include )
|
||||
set(MLIR_BINARY_INCLUDE_DIR ${LLVM_TOOLS_BINARY_DIR}/../tools/mlir/include )
|
||||
|
||||
include(AddSPT)
|
||||
|
||||
# Installing the headers and docs needs to depend on generating any public
|
||||
|
@ -15,7 +20,8 @@ add_custom_target(spt-headers)
|
|||
set_target_properties(spt-headers PROPERTIES FOLDER "Misc")
|
||||
add_custom_target(spt-doc)
|
||||
|
||||
include_directories( "include")
|
||||
include_directories( ${MLIR_INCLUDE_DIR})
|
||||
include_directories( ${MLIR_BINARY_INCLUDE_DIR})
|
||||
include_directories( ${SPT_INCLUDE_DIR})
|
||||
|
||||
#add_subdirectory(include/spt)
|
||||
|
|
|
@ -21,7 +21,7 @@ $ git clone git@github.com:llvm/llvm-project.git
|
|||
$ git clone git@github.com:sifive/clattner-experimental.git spt
|
||||
```
|
||||
|
||||
3) HACK: Add symlink because I can't figure out how to get LLVM_EXTERNAL_SPT_SOURCE_DIR to work with cmake:
|
||||
3) HACK: Add symlink because I can't figure out how to get `LLVM_EXTERNAL_SPT_SOURCE_DIR` to work with cmake:
|
||||
|
||||
```
|
||||
$ cd ~/Projects/llvm-project
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
// RUN: spt-opt %s | FileCheck %s
|
||||
|
||||
// CHECK-LABEL: func @simpleCFG(%{{.*}}: i32, %{{.*}}: f32) -> i1 {
|
||||
func @simpleCFG(%arg0: i32, %f: f32) -> i1 {
|
||||
// CHECK: %{{.*}} = "foo"() : () -> i64
|
||||
%1 = "foo"() : ()->i64
|
||||
// CHECK: "bar"(%{{.*}}) : (i64) -> (i1, i1, i1)
|
||||
%2:3 = "bar"(%1) : (i64) -> (i1,i1,i1)
|
||||
// CHECK: return %{{.*}}#1
|
||||
return %2#1 : i1
|
||||
// CHECK: }
|
||||
}
|
|
@ -1,51 +1,15 @@
|
|||
set(LIB_LIBS
|
||||
MLIRAnalysis
|
||||
MLIRLLVMIR
|
||||
MLIROptLib
|
||||
MLIRParser
|
||||
MLIRPass
|
||||
MLIRTransforms
|
||||
MLIRSupport
|
||||
)
|
||||
add_llvm_library(SPTSptOptMain
|
||||
spt-opt.cpp
|
||||
)
|
||||
target_link_libraries(SPTSptOptMain
|
||||
${LIB_LIBS}
|
||||
)
|
||||
|
||||
#get_property(dialect_libs GLOBAL PROPERTY MLIR_DIALECT_LIBS)
|
||||
#get_property(conversion_libs GLOBAL PROPERTY MLIR_CONVERSION_LIBS)
|
||||
set(LIBS
|
||||
# ${dialect_libs}
|
||||
# ${conversion_libs}
|
||||
MLIRDialect
|
||||
MLIRParser
|
||||
MLIRPass
|
||||
MLIRTransforms
|
||||
MLIRTransformUtils
|
||||
MLIRSupport
|
||||
MLIRIR
|
||||
MLIROptLib
|
||||
MLIRStandardOps
|
||||
LLVMSupport
|
||||
LLVMCore
|
||||
LLVMAsmParser
|
||||
)
|
||||
|
||||
add_llvm_tool(spt-opt
|
||||
spt-opt.cpp
|
||||
)
|
||||
# Manually expand the target library, since our SPT libraries
|
||||
# aren't plugged into the LLVM dependency tracking. If we don't
|
||||
# do this then we can't insert the CodeGen library after ourselves
|
||||
llvm_expand_pseudo_components(TARGET_LIBS AllTargetsCodeGens)
|
||||
|
||||
# Prepend LLVM in front of every target, this is how the library
|
||||
# are named with CMake
|
||||
SET(targets_to_link)
|
||||
FOREACH(t ${TARGET_LIBS})
|
||||
LIST(APPEND targets_to_link "LLVM${t}")
|
||||
ENDFOREACH(t)
|
||||
|
||||
llvm_update_compile_flags(spt-opt)
|
||||
target_link_libraries(spt-opt PRIVATE ${LIBS} ${targets_to_link})
|
||||
|
|
|
@ -5,13 +5,82 @@
|
|||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "mlir/Dialect/StandardOps/IR/Ops.h"
|
||||
#include "mlir/Pass/PassManager.h"
|
||||
#include "mlir/Pass/PassRegistry.h"
|
||||
#include "mlir/Support/MlirOptMain.h"
|
||||
#include "mlir/Support/FileUtilities.h"
|
||||
#include "llvm/Support/CommandLine.h"
|
||||
#include "llvm/Support/InitLLVM.h"
|
||||
#include "llvm/Support/ToolOutputFile.h"
|
||||
|
||||
using namespace llvm;
|
||||
using namespace mlir;
|
||||
|
||||
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));
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
InitLLVM y(argc, argv);
|
||||
|
||||
registerDialect<StandardOpsDialect>();
|
||||
|
||||
// Register any pass manager command line options.
|
||||
registerPassManagerCLOptions();
|
||||
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");
|
||||
|
||||
// TODO: Implement stuff! :-)
|
||||
return 0;
|
||||
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));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue