Skip to content

Commit

Permalink
Push the cmake files far enough along to make spt-opt be able to link in
Browse files Browse the repository at this point in the history
MLIR libraries, parsing and printing the output, running passes, etc.
  • Loading branch information
Chris Lattner committed Mar 7, 2020
1 parent 64cec97 commit 7783a53
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 41 deletions.
8 changes: 7 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions test/spt-opt/trivial.mlir
Original file line number Diff line number Diff line change
@@ -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: }
}
38 changes: 1 addition & 37 deletions tools/spt-opt/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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})
Expand Down
73 changes: 71 additions & 2 deletions tools/spt-opt/spt-opt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

0 comments on commit 7783a53

Please sign in to comment.