chore(compiler): Empty MLIR structure

This commit is contained in:
Quentin Bourgerie
2021-05-18 07:41:11 +02:00
parent c6a0a699f5
commit f7c11a0c4e
20 changed files with 184 additions and 0 deletions

1
compiler/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
build/

29
compiler/CMakeLists.txt Normal file
View File

@@ -0,0 +1,29 @@
cmake_minimum_required(VERSION 3.13)
project(zamacompiler LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
find_package(MLIR REQUIRED CONFIG)
message(STATUS "Using MLIR cmake file from: ${MLIR_DIR}")
find_package(LLVM REQUIRED CONFIG)
message(STATUS "Using LLVM cmake file from: ${LLVM_DIR}")
list(APPEND CMAKE_MODULE_PATH "${MLIR_CMAKE_DIR}")
list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_DIR}")
include(TableGen)
include(AddLLVM)
include(AddMLIR)
include_directories(${LLVM_INCLUDE_DIRS})
include_directories(${MLIR_INCLUDE_DIRS})
include_directories(${PROJECT_SOURCE_DIR}/include)
include_directories(${PROJECT_BINARY_DIR}/include)
link_directories(${LLVM_BUILD_LIBRARY_DIR})
add_definitions(${LLVM_DEFINITIONS})
add_subdirectory(include)
add_subdirectory(lib)
add_subdirectory(src)

19
compiler/README.md Normal file
View File

@@ -0,0 +1,19 @@
# Building the compiler
Generate the compiler build system, in the `build` directory
```sh
cmake -B build . -DLLVM_DIR=$LLVM_PROJECT/build/lib/cmake/llvm -DMLIR_DIR=$LLVM_PROJECT/build/lib/cmake/mlir
```
Build the compiler
```sh
make -C build/ zamacompiler
```
Run the compiler
```sh
./build/src/zamacompiler
```

View File

@@ -0,0 +1 @@
add_subdirectory(zamalang)

View File

@@ -0,0 +1 @@
add_subdirectory(Dialect)

View File

@@ -0,0 +1 @@
add_subdirectory(HLFHE)

View File

@@ -0,0 +1 @@
add_subdirectory(IR)

View File

@@ -0,0 +1,3 @@
add_mlir_dialect(HLFHEOps HLFHE)
add_mlir_doc(HLFHEDialect -gen-dialect-doc HLFHEDialect zamalang/)
add_mlir_doc(HLFHEOps -gen-op-doc HLFHEOps zamalang/)

View File

@@ -0,0 +1,13 @@
#ifndef ZAMALANG_DIALECT_HLFHE_HLFHE_DIALECT_H
#define ZAMALANG_DIALECT_HLFHE_HLFHE_DIALECT_H
#include "mlir/IR/BuiltinTypes.h"
#include "mlir/IR/Dialect.h"
#include "mlir/IR/BuiltinOps.h"
#include "mlir/IR/BuiltinTypes.h"
#include "mlir/IR/Dialect.h"
#include "zamalang/Dialect/HLFHE/IR/HLFHEOpsDialect.h.inc"
#endif

View File

@@ -0,0 +1,23 @@
//===- HLFHEDialect.td - HLFHE dialect ----------------*- tablegen -*-===//
//
// This file is licensed under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#ifndef ZAMALANG_DIALECT_HLFHE_IR_HLFHE_DIALECT
#define ZAMALANG_DIALECT_HLFHE_IR_HLFHE_DIALECT
include "mlir/IR/OpBase.td"
def HLFHE_Dialect : Dialect {
let name = "HLFHE";
let summary = "High Level Fully Homorphic Encryption dialect";
let description = [{
A dialect for representation of high level operation on fully homomorphic ciphertext.
}];
let cppNamespace = "::mlir::zamalang::HLFHE";
}
#endif

View File

@@ -0,0 +1,10 @@
#ifndef ZAMALANG_DIALECT_HLFHE_HLFHE_OPS_H
#define ZAMALANG_DIALECT_HLFHE_HLFHE_OPS_H
#include <mlir/IR/BuiltinOps.h>
#include <mlir/IR/BuiltinTypes.h>
#define GET_OP_CLASSES
#include "zamalang/Dialect/HLFHE/IR/HLFHEOps.h.inc"
#endif

View File

@@ -0,0 +1,17 @@
//===- HLFHEOps.td - High level FHE dialect ops ----------------*- tablegen -*-===//
//
// This file is licensed under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#ifndef ZAMALANG_DIALECT_HLFHE_IR_HLFHE_OPS
#define ZAMALANG_DIALECT_HLFHE_IR_HLFHE_OPS
include "zamalang/Dialect/HLFHE/IR/HLFHEDialect.td"
class HLFHE_Op<string mnemonic, list<OpTrait> traits = []> :
Op<HLFHE_Dialect, mnemonic, traits>;
#endif

View File

@@ -0,0 +1 @@
add_subdirectory(Dialect)

View File

@@ -0,0 +1 @@
add_subdirectory(HLFHE)

View File

@@ -0,0 +1 @@
add_subdirectory(IR)

View File

@@ -0,0 +1,14 @@
add_mlir_dialect_library(HLFHEDialect
HLFHEDialect.cpp
HLFHEOps.cpp
ADDITIONAL_HEADER_DIRS
${PROJECT_SOURCE_DIR}/include/zamalang/Dialect/HLFHE
DEPENDS
MLIRHLFHEOpsIncGen
LINK_LIBS PUBLIC
MLIRIR)
target_link_libraries(HLFHEDialect PUBLIC MLIRIR)

View File

@@ -0,0 +1,11 @@
#include "zamalang/Dialect/HLFHE/IR/HLFHEDialect.h"
#include "zamalang/Dialect/HLFHE/IR/HLFHEOps.h"
using namespace mlir::zamalang::HLFHE;
void HLFHEDialect::initialize() {
addOperations<
#define GET_OP_LIST
#include "zamalang/Dialect/HLFHE/IR/HLFHEOps.cpp.inc"
>();
}

View File

@@ -0,0 +1,4 @@
#include "zamalang/Dialect/HLFHE/IR/HLFHEOps.h"
#define GET_OP_CLASSES
#include "zamalang/Dialect/HLFHE/IR/HLFHEOps.cpp.inc"

View File

@@ -0,0 +1,9 @@
add_llvm_tool(zamacompiler main.cpp)
llvm_update_compile_flags(zamacompiler)
target_link_libraries(zamacompiler
PRIVATE
MLIRTransforms
HLFHEDialect)
mlir_check_all_link_libraries(zamacompiler)

24
compiler/src/main.cpp Normal file
View File

@@ -0,0 +1,24 @@
#include "zamalang/Dialect/HLFHE/IR/HLFHEDialect.h"
#include "zamalang/Dialect/HLFHE/IR/HLFHEOps.h"
#include "llvm/Support/SourceMgr.h"
#include <mlir/Dialect/StandardOps/IR/Ops.h>
#include <mlir/IR/Builders.h>
int main(int argc, char **argv) {
mlir::MLIRContext context;
// Load our Dialect in this MLIR Context.
context.getOrLoadDialect<mlir::zamalang::HLFHE::HLFHEDialect>();
context.getOrLoadDialect<mlir::StandardOpsDialect>();
mlir::OpBuilder builder(&context);
mlir::ModuleOp module = mlir::ModuleOp::create(builder.getUnknownLoc());
module.dump();
return 0;
}