diff --git a/python_native/MlirInit.h b/include/npcomp/Python/MlirInit.h similarity index 89% rename from python_native/MlirInit.h rename to include/npcomp/Python/MlirInit.h index 4d2863eae..c9fc6bcdd 100644 --- a/python_native/MlirInit.h +++ b/include/npcomp/Python/MlirInit.h @@ -6,6 +6,9 @@ // //===----------------------------------------------------------------------===// +#ifndef NPCOMP_PYTHON_MLIRINIT_H +#define NPCOMP_PYTHON_MLIRINIT_H + #include "mlir/Support/LogicalResult.h" #include "llvm/ADT/StringRef.h" @@ -14,7 +17,6 @@ // here for parts of the code that are not RTTI-compatible. namespace mlir { - namespace npcomp { namespace python { @@ -24,3 +26,5 @@ bool npcompMlirInitialize(); } // namespace python } // namespace npcomp } // namespace mlir + +#endif // NPCOMP_PYTHON_MLIRINIT_H diff --git a/python_native/MlirIr.h b/include/npcomp/Python/MlirIr.h similarity index 97% rename from python_native/MlirIr.h rename to include/npcomp/Python/MlirIr.h index 3a6b663b6..d627645f3 100644 --- a/python_native/MlirIr.h +++ b/include/npcomp/Python/MlirIr.h @@ -6,8 +6,8 @@ // //===----------------------------------------------------------------------===// -#ifndef NPCOMP_PYTHON_NATIVE_MLIR_IR_H -#define NPCOMP_PYTHON_NATIVE_MLIR_IR_H +#ifndef NPCOMP_PYTHON_MLIR_IR_H +#define NPCOMP_PYTHON_MLIR_IR_H #include "PybindUtils.h" @@ -198,4 +198,4 @@ protected: } // namespace mlir -#endif // NPCOMP_PYTHON_NATIVE_MLIR_IR_H +#endif // NPCOMP_PYTHON_MLIR_IR_H diff --git a/python_native/MlirPass.h b/include/npcomp/Python/MlirPass.h similarity index 86% rename from python_native/MlirPass.h rename to include/npcomp/Python/MlirPass.h index a8027db99..9ed7de593 100644 --- a/python_native/MlirPass.h +++ b/include/npcomp/Python/MlirPass.h @@ -6,8 +6,8 @@ // //===----------------------------------------------------------------------===// -#ifndef NPCOMP_PYTHON_NATIVE_MLIR_PASS_H -#define NPCOMP_PYTHON_NATIVE_MLIR_PASS_H +#ifndef NPCOMP_PYTHON_MLIR_PASS_H +#define NPCOMP_PYTHON_MLIR_PASS_H #include "MlirIr.h" #include "PybindUtils.h" @@ -29,4 +29,4 @@ private: } // namespace mlir -#endif // NPCOMP_PYTHON_NATIVE_MLIR_PASS_H +#endif // NPCOMP_PYTHON_MLIR_PASS_H diff --git a/python_native/NpcompModule.h b/include/npcomp/Python/NpcompModule.h similarity index 83% rename from python_native/NpcompModule.h rename to include/npcomp/Python/NpcompModule.h index a6b28e039..92017a345 100644 --- a/python_native/NpcompModule.h +++ b/include/npcomp/Python/NpcompModule.h @@ -6,8 +6,8 @@ // //===----------------------------------------------------------------------===// -#ifndef NPCOMP_PYTHON_NATIVE_NPCOMP_MODULE_H -#define NPCOMP_PYTHON_NATIVE_NPCOMP_MODULE_H +#ifndef NPCOMP_PYTHON_NPCOMP_MODULE_H +#define NPCOMP_PYTHON_NPCOMP_MODULE_H #include "PybindUtils.h" @@ -25,4 +25,4 @@ void defineNpcompDialect(py::module m); } // namespace npcomp } // namespace mlir -#endif // NPCOMP_PYTHON_NATIVE_NPCOMP_MODULE_H +#endif // NPCOMP_PYTHON_NPCOMP_MODULE_H diff --git a/python_native/PybindUtils.h b/include/npcomp/Python/PybindUtils.h similarity index 91% rename from python_native/PybindUtils.h rename to include/npcomp/Python/PybindUtils.h index 50b1ff735..c5a8a7fa4 100644 --- a/python_native/PybindUtils.h +++ b/include/npcomp/Python/PybindUtils.h @@ -6,8 +6,8 @@ // //===----------------------------------------------------------------------===// -#ifndef NPCOMP_PYTHON_NATIVE_PYBIND_UTILS_H -#define NPCOMP_PYTHON_NATIVE_PYBIND_UTILS_H +#ifndef NPCOMP_PYTHON_PYBIND_UTILS_H +#define NPCOMP_PYTHON_PYBIND_UTILS_H #include @@ -52,4 +52,4 @@ inline pybind11::error_already_set raiseValueError(const std::string &message) { } // namespace pybind11 -#endif // NPCOMP_PYTHON_NATIVE_PYBIND_UTILS_H +#endif // NPCOMP_PYTHON_PYBIND_UTILS_H diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index c87b7745c..d0b7eeb2d 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -1,6 +1,7 @@ add_subdirectory(Conversion) add_subdirectory(Dialect) add_subdirectory(E2E) +add_subdirectory(Python) ################################################################################ # Setup the initialization target. diff --git a/lib/Python/CMakeLists.txt b/lib/Python/CMakeLists.txt new file mode 100644 index 000000000..01abd3eb2 --- /dev/null +++ b/lib/Python/CMakeLists.txt @@ -0,0 +1,27 @@ +add_library(NPCOMPPythonCommon + MlirInit.cpp + MlirIr.cpp + MlirPass.cpp + NpcompDialect.cpp + PybindUtils.cpp + CoreDialects.cpp +) + +target_link_libraries(NPCOMPPythonCommon + pybind11::module + + NPCOMPInitAll + + # Core dialects + MLIRSCF + + # Upstream depends + LLVMSupport + MLIRDialect + MLIREDSC + MLIREDSCInterface + MLIRIR + MLIRLLVMIR + MLIRPass + MLIRTransforms +) diff --git a/python_native/CoreDialects.cpp b/lib/Python/CoreDialects.cpp similarity index 97% rename from python_native/CoreDialects.cpp rename to lib/Python/CoreDialects.cpp index b080c062a..a47a6eeac 100644 --- a/python_native/CoreDialects.cpp +++ b/lib/Python/CoreDialects.cpp @@ -6,8 +6,8 @@ // //===----------------------------------------------------------------------===// -#include "MlirIr.h" -#include "NpcompModule.h" +#include "npcomp/Python/MlirIr.h" +#include "npcomp/Python/NpcompModule.h" #include "mlir/Dialect/SCF/SCF.h" diff --git a/python_native/MlirInit.cpp b/lib/Python/MlirInit.cpp similarity index 98% rename from python_native/MlirInit.cpp rename to lib/Python/MlirInit.cpp index 4c833221d..13019b693 100644 --- a/python_native/MlirInit.cpp +++ b/lib/Python/MlirInit.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include "MlirInit.h" +#include "npcomp/Python/MlirInit.h" #include "mlir/IR/Dialect.h" #include "mlir/InitAllDialects.h" diff --git a/python_native/MlirIr.cpp b/lib/Python/MlirIr.cpp similarity index 99% rename from python_native/MlirIr.cpp rename to lib/Python/MlirIr.cpp index c6609b484..729a8bbd0 100644 --- a/python_native/MlirIr.cpp +++ b/lib/Python/MlirIr.cpp @@ -6,8 +6,8 @@ // //===----------------------------------------------------------------------===// -#include "MlirIr.h" -#include "NpcompModule.h" +#include "npcomp/Python/MlirIr.h" +#include "npcomp/Python/NpcompModule.h" #include "mlir/Dialect/StandardOps/IR/Ops.h" #include "mlir/IR/Attributes.h" diff --git a/python_native/MlirPass.cpp b/lib/Python/MlirPass.cpp similarity index 96% rename from python_native/MlirPass.cpp rename to lib/Python/MlirPass.cpp index 35f5e8667..5b4459fcf 100644 --- a/python_native/MlirPass.cpp +++ b/lib/Python/MlirPass.cpp @@ -6,9 +6,9 @@ // //===----------------------------------------------------------------------===// -#include "MlirPass.h" -#include "MlirInit.h" -#include "NpcompModule.h" +#include "npcomp/Python/MlirPass.h" +#include "npcomp/Python/MlirInit.h" +#include "npcomp/Python/NpcompModule.h" #include "mlir/Pass/PassRegistry.h" diff --git a/python_native/NpcompDialect.cpp b/lib/Python/NpcompDialect.cpp similarity index 98% rename from python_native/NpcompDialect.cpp rename to lib/Python/NpcompDialect.cpp index 30e8c7e9f..f70ce8d2e 100644 --- a/python_native/NpcompDialect.cpp +++ b/lib/Python/NpcompDialect.cpp @@ -6,8 +6,8 @@ // //===----------------------------------------------------------------------===// -#include "MlirIr.h" -#include "NpcompModule.h" +#include "npcomp/Python/MlirIr.h" +#include "npcomp/Python/NpcompModule.h" #include "npcomp/Dialect/Basicpy/IR/BasicpyDialect.h" #include "npcomp/Dialect/Basicpy/IR/BasicpyOps.h" diff --git a/python_native/PybindUtils.cpp b/lib/Python/PybindUtils.cpp similarity index 94% rename from python_native/PybindUtils.cpp rename to lib/Python/PybindUtils.cpp index 95debdb16..89b989ab6 100644 --- a/python_native/PybindUtils.cpp +++ b/lib/Python/PybindUtils.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include "PybindUtils.h" +#include "npcomp/Python/PybindUtils.h" namespace pybind11 { diff --git a/python_native/CMakeLists.txt b/python_native/CMakeLists.txt index aaf11f99d..cfb38109f 100644 --- a/python_native/CMakeLists.txt +++ b/python_native/CMakeLists.txt @@ -25,21 +25,15 @@ set(NPCOMP_PYEXT_LIBADD ${PYTHON_LIBRARIES}) # compiled separately for now. set(extension_target NPCOMPNativePyExt) set(extension_llvm_sources - MlirInit.cpp ) set(extension_pybind_sources - MlirIr.cpp - MlirPass.cpp - NpcompDialect.cpp NpcompModule.cpp - PybindUtils.cpp - CoreDialects.cpp ) set_source_files_properties( ${extension_pybind_sources} - PROPERTIES COMPILE_FLAGS + PROPERTIES COMPILE_FLAGS "-frtti -fexceptions") -add_library(${extension_target} ${NPCOMP_PYEXT_LINK_MODE} +add_library(${extension_target} ${NPCOMP_PYEXT_LINK_MODE} ${extension_pybind_sources} ${extension_llvm_sources} ) @@ -47,10 +41,10 @@ add_library(${extension_target} ${NPCOMP_PYEXT_LINK_MODE} set_target_properties(${extension_target} PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}") set_target_properties(${extension_target} PROPERTIES OUTPUT_NAME _npcomp) -set_target_properties(${extension_target} PROPERTIES PREFIX +set_target_properties(${extension_target} PROPERTIES PREFIX "${PYTHON_MODULE_PREFIX}") -set_target_properties(${extension_target} PROPERTIES SUFFIX - "${PYTHON_MODULE_EXTENSION}") +set_target_properties(${extension_target} PROPERTIES SUFFIX + "${PYTHON_MODULE_EXTENSION}") # pybind requires binding code to be compiled with -fvisibility=hidden # Better code can be generated if the entire project compiles that way, but @@ -65,16 +59,12 @@ get_property(dialect_libs GLOBAL PROPERTY MLIR_DIALECT_LIBS) get_property(conversion_libs GLOBAL PROPERTY MLIR_CONVERSION_LIBS) # llvm_update_compile_flags(${extension_target}) -target_link_libraries(${extension_target} +target_link_libraries(${extension_target} PRIVATE ${dialect_libs} ${conversion_libs} - pybind11::module - NPCOMPInitAll - - # Core dialects - MLIRSCF + NPCOMPPythonCommon # Upstream depends LLVMSupport diff --git a/python_native/NpcompModule.cpp b/python_native/NpcompModule.cpp index e14f4854c..c3c4a005b 100644 --- a/python_native/NpcompModule.cpp +++ b/python_native/NpcompModule.cpp @@ -9,9 +9,9 @@ #include #include -#include "MlirInit.h" -#include "NpcompModule.h" -#include "PybindUtils.h" +#include "npcomp/Python/MlirInit.h" +#include "npcomp/Python/NpcompModule.h" +#include "npcomp/Python/PybindUtils.h" #include "llvm/Support/CommandLine.h"