Skip to content
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
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ add_subdirectory(tools)
# Tools built by this project or LLVM
set(MLIR_NEURA_OPT ${CMAKE_BINARY_DIR}/tools/mlir-neura-opt/mlir-neura-opt)
set(NEURA_INTERPRETER ${CMAKE_BINARY_DIR}/tools/neura-interpreter/neura-interpreter)
set(NEURA_COMPILER ${CMAKE_BINARY_DIR}/tools/neura-compiler/neura-compiler)
set(FILECHECK ${LLVM_TOOLS_BINARY_DIR}/FileCheck)
set(MLIR_OPT ${LLVM_TOOLS_BINARY_DIR}/mlir-opt)
set(MLIR_TRANSLATE ${LLVM_TOOLS_BINARY_DIR}/mlir-translate)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Build LLVM & Neura
- Clone this repo.

- Build LLVM:
- Check out to commit `cd70802` (a stable version randomly picked, will sync to the latest version).
- Check out to commit `6146a88` (a stable version randomly picked, will sync to the latest version).
- Build:
```sh
$ mkdir build && cd build
Expand Down
2 changes: 2 additions & 0 deletions include/NeuraDialect/NeuraPasses.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
namespace mlir {
namespace neura {

void registerNeuraConversionPassPipeline();

// Passes defined in GraphPasses.td
#define GEN_PASS_DECL
#include "NeuraDialect/NeuraPasses.h.inc"
Expand Down
3 changes: 3 additions & 0 deletions lib/NeuraDialect/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@ add_public_tablegen_target(MLIRNeuraDialectIncGen)
add_mlir_dialect_library(MLIRNeura
Neura.cpp
NeuraTypes.cpp
NeuraPasses.cpp

ADDITIONAL_HEADER_DIRS
${PROJECT_SOURCE_DIR}/include/NeuraDialect

DEPENDS
MLIRNeuraDialectIncGen
MLIRNeuraTransformsIncGen
MLIRConversionIncGen

LINK_LIBS PUBLIC
MLIRIR
Expand Down
20 changes: 20 additions & 0 deletions lib/NeuraDialect/NeuraPasses.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include "mlir/Pass/PassManager.h"
#include "mlir/Pass/PassRegistry.h"
#include "mlir/Transforms/Passes.h"

#include "NeuraDialect/NeuraDialect.h"
#include "NeuraDialect/NeuraOps.h"
#include "NeuraDialect/NeuraPasses.h"
#include "NeuraDialect/NeuraTypes.h"
#include "Conversion/ConversionPasses.h"

// This pass pipeline can convert all the other dialects into the Neura dialect
void mlir::neura::registerNeuraConversionPassPipeline() {
PassPipelineRegistration<>("neura-conversion",
"Convert all dialects to Neura dialect",
[](OpPassManager &pm) {
// Convert all the other dialects into the Neura dialect
pm.addPass(mlir::createLowerArithToNeuraPass());
pm.addPass(mlir::createLowerLlvmToNeuraPass());
});
}
7 changes: 5 additions & 2 deletions test/arith2neura/add.mlir
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
// RUN: mlir-neura-opt --lower-arith-to-neura %s | FileCheck %s
// RUN: neura-compiler --neura-conversion %s | FileCheck %s --check-prefix=COMPILER
// RUN: mlir-neura-opt --lower-arith-to-neura %s | FileCheck %s --check-prefix=OPT

func.func @test(%a: f32) -> f32 {
%b = arith.constant 2.0 : f32
%res = arith.addf %a, %b : f32
// CHECK: neura.fadd
return %res : f32
}

// COMPILER: neura.fadd
// OPT: neura.fadd
1 change: 1 addition & 0 deletions test/lit.cfg.in
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ config.test_exec_root = os.path.dirname(__file__)
# Tool substitutions from CMake
config.substitutions.append(('mlir-neura-opt', '@MLIR_NEURA_OPT@'))
config.substitutions.append(('neura-interpreter', '@NEURA_INTERPRETER@'))
config.substitutions.append(('neura-compiler', '@NEURA_COMPILER@'))
config.substitutions.append(('FileCheck', '@FILECHECK@'))
config.substitutions.append(('mlir-opt', '@MLIR_OPT@'))
config.substitutions.append(('mlir-translate', '@MLIR_TRANSLATE@'))
Expand Down
3 changes: 2 additions & 1 deletion tools/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
add_subdirectory(mlir-neura-opt)
add_subdirectory(neura-interpreter)
add_subdirectory(neura-interpreter)
add_subdirectory(neura-compiler)
18 changes: 18 additions & 0 deletions tools/neura-compiler/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
add_executable(neura-compiler neura-compiler.cpp)
get_property(dialect_libs GLOBAL PROPERTY MLIR_DIALECT_LIBS)
get_property(conversion_libs GLOBAL PROPERTY MLIR_CONVERSION_LIBS)
set(LIBS
${dialect_libs}
${conversion_libs}
MLIRNeuraTransforms
MLIRConversion
MLIRNeura
MLIRTransforms
MLIROptLib
MLIRPass
MLIRIR
MLIRParser
MLIRSupport
)

target_link_libraries(neura-compiler PRIVATE ${LIBS})
32 changes: 32 additions & 0 deletions tools/neura-compiler/neura-compiler.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// neura-compiler.cpp

#include "mlir/Dialect/Affine/IR/AffineOps.h"
#include "mlir/Dialect/DLTI/DLTI.h"
#include "mlir/Dialect/LLVMIR/LLVMDialect.h"
#include "mlir/InitAllDialects.h"
#include "mlir/InitAllPasses.h"
#include "mlir/Support/FileUtilities.h"
#include "mlir/Support/LogicalResult.h"
#include "mlir/Tools/mlir-opt/MlirOptMain.h"

#include "Conversion/ConversionPasses.h"
#include "NeuraDialect/NeuraDialect.h"
#include "NeuraDialect/NeuraPasses.h"

int main(int argc, char **argv) {
// Registers MLIR dialects.
mlir::DialectRegistry registry;
registry.insert<mlir::neura::NeuraDialect>();
registry.insert<mlir::func::FuncDialect>();
registry.insert<mlir::arith::ArithDialect>();
registry.insert<mlir::DLTIDialect>();
registry.insert<mlir::LLVM::LLVMDialect>();
registry.insert<mlir::affine::AffineDialect>();
registry.insert<mlir::memref::MemRefDialect>();

mlir::neura::registerNeuraConversionPassPipeline();

// Runs the MLIR optimizer.
return mlir::asMainReturnCode(
mlir::MlirOptMain(argc, argv, "Neura Dialect Compiler", registry));
}