diff --git a/compiler/.gitignore b/compiler/.gitignore new file mode 100644 index 000000000..d16386367 --- /dev/null +++ b/compiler/.gitignore @@ -0,0 +1 @@ +build/ \ No newline at end of file diff --git a/compiler/CMakeLists.txt b/compiler/CMakeLists.txt new file mode 100644 index 000000000..bb462a7f1 --- /dev/null +++ b/compiler/CMakeLists.txt @@ -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) diff --git a/compiler/README.md b/compiler/README.md new file mode 100644 index 000000000..4e1ecfa05 --- /dev/null +++ b/compiler/README.md @@ -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 +``` \ No newline at end of file diff --git a/compiler/include/CMakeLists.txt b/compiler/include/CMakeLists.txt new file mode 100644 index 000000000..f0ca28852 --- /dev/null +++ b/compiler/include/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(zamalang) diff --git a/compiler/include/zamalang/CMakeLists.txt b/compiler/include/zamalang/CMakeLists.txt new file mode 100644 index 000000000..0ca0f41c5 --- /dev/null +++ b/compiler/include/zamalang/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(Dialect) diff --git a/compiler/include/zamalang/Dialect/CMakeLists.txt b/compiler/include/zamalang/Dialect/CMakeLists.txt new file mode 100644 index 000000000..4f48b3c5b --- /dev/null +++ b/compiler/include/zamalang/Dialect/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(HLFHE) diff --git a/compiler/include/zamalang/Dialect/HLFHE/CMakeLists.txt b/compiler/include/zamalang/Dialect/HLFHE/CMakeLists.txt new file mode 100644 index 000000000..f33061b2d --- /dev/null +++ b/compiler/include/zamalang/Dialect/HLFHE/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(IR) diff --git a/compiler/include/zamalang/Dialect/HLFHE/IR/CMakeLists.txt b/compiler/include/zamalang/Dialect/HLFHE/IR/CMakeLists.txt new file mode 100644 index 000000000..7f3bb0c9e --- /dev/null +++ b/compiler/include/zamalang/Dialect/HLFHE/IR/CMakeLists.txt @@ -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/) diff --git a/compiler/include/zamalang/Dialect/HLFHE/IR/HLFHEDialect.h b/compiler/include/zamalang/Dialect/HLFHE/IR/HLFHEDialect.h new file mode 100644 index 000000000..4b599159d --- /dev/null +++ b/compiler/include/zamalang/Dialect/HLFHE/IR/HLFHEDialect.h @@ -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 diff --git a/compiler/include/zamalang/Dialect/HLFHE/IR/HLFHEDialect.td b/compiler/include/zamalang/Dialect/HLFHE/IR/HLFHEDialect.td new file mode 100644 index 000000000..21092c681 --- /dev/null +++ b/compiler/include/zamalang/Dialect/HLFHE/IR/HLFHEDialect.td @@ -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 diff --git a/compiler/include/zamalang/Dialect/HLFHE/IR/HLFHEOps.h b/compiler/include/zamalang/Dialect/HLFHE/IR/HLFHEOps.h new file mode 100644 index 000000000..bb4c40fa1 --- /dev/null +++ b/compiler/include/zamalang/Dialect/HLFHE/IR/HLFHEOps.h @@ -0,0 +1,10 @@ +#ifndef ZAMALANG_DIALECT_HLFHE_HLFHE_OPS_H +#define ZAMALANG_DIALECT_HLFHE_HLFHE_OPS_H + +#include +#include + +#define GET_OP_CLASSES +#include "zamalang/Dialect/HLFHE/IR/HLFHEOps.h.inc" + +#endif diff --git a/compiler/include/zamalang/Dialect/HLFHE/IR/HLFHEOps.td b/compiler/include/zamalang/Dialect/HLFHE/IR/HLFHEOps.td new file mode 100644 index 000000000..1db0bef3e --- /dev/null +++ b/compiler/include/zamalang/Dialect/HLFHE/IR/HLFHEOps.td @@ -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 traits = []> : + Op; + +#endif diff --git a/compiler/lib/CMakeLists.txt b/compiler/lib/CMakeLists.txt new file mode 100644 index 000000000..0ca0f41c5 --- /dev/null +++ b/compiler/lib/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(Dialect) diff --git a/compiler/lib/Dialect/CMakeLists.txt b/compiler/lib/Dialect/CMakeLists.txt new file mode 100644 index 000000000..4f48b3c5b --- /dev/null +++ b/compiler/lib/Dialect/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(HLFHE) diff --git a/compiler/lib/Dialect/HLFHE/CMakeLists.txt b/compiler/lib/Dialect/HLFHE/CMakeLists.txt new file mode 100644 index 000000000..f33061b2d --- /dev/null +++ b/compiler/lib/Dialect/HLFHE/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(IR) diff --git a/compiler/lib/Dialect/HLFHE/IR/CMakeLists.txt b/compiler/lib/Dialect/HLFHE/IR/CMakeLists.txt new file mode 100644 index 000000000..f432ad8ed --- /dev/null +++ b/compiler/lib/Dialect/HLFHE/IR/CMakeLists.txt @@ -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) diff --git a/compiler/lib/Dialect/HLFHE/IR/HLFHEDialect.cpp b/compiler/lib/Dialect/HLFHE/IR/HLFHEDialect.cpp new file mode 100644 index 000000000..a5a8b998e --- /dev/null +++ b/compiler/lib/Dialect/HLFHE/IR/HLFHEDialect.cpp @@ -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" + >(); +} diff --git a/compiler/lib/Dialect/HLFHE/IR/HLFHEOps.cpp b/compiler/lib/Dialect/HLFHE/IR/HLFHEOps.cpp new file mode 100644 index 000000000..93863a07d --- /dev/null +++ b/compiler/lib/Dialect/HLFHE/IR/HLFHEOps.cpp @@ -0,0 +1,4 @@ +#include "zamalang/Dialect/HLFHE/IR/HLFHEOps.h" + +#define GET_OP_CLASSES +#include "zamalang/Dialect/HLFHE/IR/HLFHEOps.cpp.inc" diff --git a/compiler/src/CMakeLists.txt b/compiler/src/CMakeLists.txt new file mode 100644 index 000000000..eebc241da --- /dev/null +++ b/compiler/src/CMakeLists.txt @@ -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) diff --git a/compiler/src/main.cpp b/compiler/src/main.cpp new file mode 100644 index 000000000..46a94162c --- /dev/null +++ b/compiler/src/main.cpp @@ -0,0 +1,24 @@ +#include "zamalang/Dialect/HLFHE/IR/HLFHEDialect.h" +#include "zamalang/Dialect/HLFHE/IR/HLFHEOps.h" + +#include "llvm/Support/SourceMgr.h" + +#include +#include + + +int main(int argc, char **argv) { + mlir::MLIRContext context; + + // Load our Dialect in this MLIR Context. + context.getOrLoadDialect(); + context.getOrLoadDialect(); + + mlir::OpBuilder builder(&context); + + mlir::ModuleOp module = mlir::ModuleOp::create(builder.getUnknownLoc()); + + module.dump(); + + return 0; +}