aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYann Herklotz <git@yannherklotz.com>2022-09-26 19:08:01 +0100
committerYann Herklotz <git@yannherklotz.com>2022-09-26 19:08:48 +0100
commit0034f32d6d85d7f21cf04c82083860cdb2fe1ddb (patch)
treef37f65190acd6040a262cdb7d2dbf6e2b17556f5
parentb018c1ef00eade87c9efbf48cc2e3466877ea79d (diff)
downloadgsa-mlir-master.tar.gz
gsa-mlir-master.zip
Update MLIR files and include LLVM directoryHEADmaster
-rw-r--r--.gitmodules5
-rw-r--r--CMakeLists.txt11
-rw-r--r--README.md54
-rw-r--r--include/Standalone-c/Dialects.h24
-rw-r--r--include/Standalone/StandaloneDialect.td2
-rw-r--r--include/Standalone/StandaloneOps.h1
-rw-r--r--include/Standalone/StandaloneOps.td5
-rw-r--r--lib/CAPI/CMakeLists.txt5
-rw-r--r--lib/CAPI/Dialects.cpp15
-rw-r--r--lib/CMakeLists.txt1
-rw-r--r--lib/Standalone/CMakeLists.txt1
m---------llvm0
-rw-r--r--python/CMakeLists.txt64
-rw-r--r--python/StandaloneExtension.cpp31
-rw-r--r--python/mlir_standalone/dialects/StandaloneOps.td15
-rw-r--r--python/mlir_standalone/dialects/standalone.py6
-rw-r--r--standalone-opt/CMakeLists.txt1
-rw-r--r--standalone-opt/standalone-opt.cpp7
-rw-r--r--standalone-translate/CMakeLists.txt4
-rw-r--r--standalone-translate/standalone-translate.cpp2
-rw-r--r--test/CAPI/CMakeLists.txt20
-rw-r--r--test/CAPI/lit.local.cfg1
-rw-r--r--test/CAPI/standalone-capi-test.c49
-rw-r--r--test/CMakeLists.txt10
-rw-r--r--test/Standalone/dummy.mlir4
-rw-r--r--test/lit.cfg.py11
-rw-r--r--test/lit.site.cfg.py.in45
-rw-r--r--test/python/lit.local.cfg4
-rw-r--r--test/python/smoketest.py17
29 files changed, 305 insertions, 110 deletions
diff --git a/.gitmodules b/.gitmodules
new file mode 100644
index 0000000..ae7efdd
--- /dev/null
+++ b/.gitmodules
@@ -0,0 +1,5 @@
+[submodule "llvm"]
+ path = llvm
+ url = https://github.com/llvm/llvm-project
+ shallow = true
+ branch = main
diff --git a/CMakeLists.txt b/CMakeLists.txt
index fc42e3e..84bce58 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -3,7 +3,7 @@ project(standalone-dialect LANGUAGES CXX C)
set(CMAKE_BUILD_WITH_INSTALL_NAME_DIR ON)
-set(CMAKE_CXX_STANDARD 14 CACHE STRING "C++ standard to conform to")
+set(CMAKE_CXX_STANDARD 17 CACHE STRING "C++ standard to conform to")
find_package(MLIR REQUIRED CONFIG)
@@ -21,6 +21,11 @@ include(AddLLVM)
include(AddMLIR)
include(HandleLLVMOptions)
+if(MLIR_ENABLE_BINDINGS_PYTHON)
+ include(MLIRDetectPythonEnv)
+ mlir_configure_python_dev_packages()
+endif()
+
include_directories(${LLVM_INCLUDE_DIRS})
include_directories(${MLIR_INCLUDE_DIRS})
include_directories(${PROJECT_SOURCE_DIR}/include)
@@ -30,6 +35,10 @@ add_definitions(${LLVM_DEFINITIONS})
add_subdirectory(include)
add_subdirectory(lib)
+if(MLIR_ENABLE_BINDINGS_PYTHON)
+ message(STATUS "Enabling Python API")
+ add_subdirectory(python)
+endif()
add_subdirectory(test)
add_subdirectory(standalone-opt)
add_subdirectory(standalone-translate)
diff --git a/README.md b/README.md
index fc01b01..b1ca627 100644
--- a/README.md
+++ b/README.md
@@ -1,66 +1,18 @@
# An out-of-tree MLIR dialect
-This is an example of an out-of-tree [MLIR](https://mlir.llvm.org/) dialect along with a standalone
-`opt`-like tool to operate on that dialect.
-
-## Setting up Docker
-
-First, set up docker volumes so that the installation persists across multiple images, and pull the
-right image.
-
-``` sh
-docker pull ymherklotz/polyhedral:1.0
-docker volume create llvm
-docker run -itd --name gsa-mlir -v llvm:/opt ymherklotz/polyhedral:1.0
-docker exec -it gsa-mlir /bin/bash
-```
-
-## Setting up LLVM
-
-First, download and install MLIR from the [`llvm-project`](https://github.com/llvm/llvm-project/)
-and compile it, installing it in `/opt/llvm`
-
-``` sh
-cd /opt
-git clone https://github.com/llvm/llvm-project.git
-mkdir llvm-project/build
-cd llvm-project/build
-cmake -G Ninja ../llvm \
- -DLLVM_ENABLE_PROJECTS=mlir \
- -DLLVM_BUILD_EXAMPLES=ON \
- -DLLVM_TARGETS_TO_BUILD="X86;NVPTX;AMDGPU" \
- -DCMAKE_BUILD_TYPE=Release \
- -DLLVM_ENABLE_ASSERTIONS=ON \
- -DLLVM_INSTALL_UTILS=ON \
- -DCMAKE_INSTALL_PREFIX=/opt/llvm
-cmake --build . --target check-mlir
-mkdir -p /opt/llvm
-ninja install
-```
-
-This should create a `BUILD_DIR` under `/opt/llvm-project/build`, and install everything under
-`PREFIX` which is `/opt/llvm`.
+This is an example of an out-of-tree [MLIR](https://mlir.llvm.org/) dialect along with a standalone `opt`-like tool to operate on that dialect.
## Building
-These instructions are now to build this repository, which should be in a separate place to the
-directories above.
-
-This setup assumes that you have built LLVM and MLIR in `$BUILD_DIR` and installed them to
-`$PREFIX`. To build and launch the tests, run
-
+This setup assumes that you have built LLVM and MLIR in `$BUILD_DIR` and installed them to `$PREFIX`. To build and launch the tests, run
```sh
mkdir build && cd build
cmake -G Ninja .. -DMLIR_DIR=$PREFIX/lib/cmake/mlir -DLLVM_EXTERNAL_LIT=$BUILD_DIR/bin/llvm-lit
cmake --build . --target check-standalone
```
-
To build the documentation from the TableGen description of the dialect operations, run
-
```sh
cmake --build . --target mlir-doc
```
-
-**Note**: Make sure to pass `-DLLVM_INSTALL_UTILS=ON` when building LLVM with CMake in order to
-install `FileCheck` to the chosen installation prefix.
+**Note**: Make sure to pass `-DLLVM_INSTALL_UTILS=ON` when building LLVM with CMake in order to install `FileCheck` to the chosen installation prefix.
diff --git a/include/Standalone-c/Dialects.h b/include/Standalone-c/Dialects.h
new file mode 100644
index 0000000..b3e4775
--- /dev/null
+++ b/include/Standalone-c/Dialects.h
@@ -0,0 +1,24 @@
+//===- Dialects.h - CAPI for dialects -----------------------------*- C -*-===//
+//
+// 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 STANDALONE_C_DIALECTS_H
+#define STANDALONE_C_DIALECTS_H
+
+#include "mlir-c/IR.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+MLIR_DECLARE_CAPI_DIALECT_REGISTRATION(Standalone, standalone);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // STANDALONE_C_DIALECTS_H
diff --git a/include/Standalone/StandaloneDialect.td b/include/Standalone/StandaloneDialect.td
index a7fd789..1588601 100644
--- a/include/Standalone/StandaloneDialect.td
+++ b/include/Standalone/StandaloneDialect.td
@@ -30,7 +30,7 @@ def Standalone_Dialect : Dialect {
// Base standalone operation definition.
//===----------------------------------------------------------------------===//
-class Standalone_Op<string mnemonic, list<OpTrait> traits = []> :
+class Standalone_Op<string mnemonic, list<Trait> traits = []> :
Op<Standalone_Dialect, mnemonic, traits>;
#endif // STANDALONE_DIALECT
diff --git a/include/Standalone/StandaloneOps.h b/include/Standalone/StandaloneOps.h
index a56c286..a9006e0 100644
--- a/include/Standalone/StandaloneOps.h
+++ b/include/Standalone/StandaloneOps.h
@@ -12,6 +12,7 @@
#include "mlir/IR/BuiltinTypes.h"
#include "mlir/IR/Dialect.h"
#include "mlir/IR/OpDefinition.h"
+#include "mlir/Interfaces/InferTypeOpInterface.h"
#include "mlir/Interfaces/SideEffectInterfaces.h"
#define GET_OP_CLASSES
diff --git a/include/Standalone/StandaloneOps.td b/include/Standalone/StandaloneOps.td
index f6ba7a6..1098dc5 100644
--- a/include/Standalone/StandaloneOps.td
+++ b/include/Standalone/StandaloneOps.td
@@ -9,7 +9,8 @@
#ifndef STANDALONE_OPS
#define STANDALONE_OPS
-include "StandaloneDialect.td"
+include "Standalone/StandaloneDialect.td"
+include "mlir/Interfaces/InferTypeOpInterface.td"
include "mlir/Interfaces/SideEffectInterfaces.td"
def Standalone_FooOp : Standalone_Op<"foo", [NoSideEffect,
@@ -25,7 +26,7 @@ def Standalone_FooOp : Standalone_Op<"foo", [NoSideEffect,
Example:
```mlir
- %0 = constant 2 : i32
+ %0 = arith.constant 2 : i32
// Apply the foo operation to %0
%1 = standalone.foo %0 : i32
```
diff --git a/lib/CAPI/CMakeLists.txt b/lib/CAPI/CMakeLists.txt
new file mode 100644
index 0000000..3124f55
--- /dev/null
+++ b/lib/CAPI/CMakeLists.txt
@@ -0,0 +1,5 @@
+add_mlir_public_c_api_library(StandaloneCAPI
+ Dialects.cpp
+ LINK_LIBS PUBLIC
+ MLIRStandalone
+)
diff --git a/lib/CAPI/Dialects.cpp b/lib/CAPI/Dialects.cpp
new file mode 100644
index 0000000..98006e8
--- /dev/null
+++ b/lib/CAPI/Dialects.cpp
@@ -0,0 +1,15 @@
+//===- Dialects.cpp - CAPI for dialects -----------------------------------===//
+//
+// Part of the LLVM Project, 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "Standalone-c/Dialects.h"
+
+#include "Standalone/StandaloneDialect.h"
+#include "mlir/CAPI/Registration.h"
+
+MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(Standalone, standalone,
+ mlir::standalone::StandaloneDialect)
diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt
index da11071..d91434b 100644
--- a/lib/CMakeLists.txt
+++ b/lib/CMakeLists.txt
@@ -1 +1,2 @@
+add_subdirectory(CAPI)
add_subdirectory(Standalone)
diff --git a/lib/Standalone/CMakeLists.txt b/lib/Standalone/CMakeLists.txt
index c8b16b7..eadc695 100644
--- a/lib/Standalone/CMakeLists.txt
+++ b/lib/Standalone/CMakeLists.txt
@@ -10,4 +10,5 @@ add_mlir_dialect_library(MLIRStandalone
LINK_LIBS PUBLIC
MLIRIR
+ MLIRInferTypeOpInterface
)
diff --git a/llvm b/llvm
new file mode 160000
+Subproject ce82530cd03d884a2c9fa48e1f9eb931064b255
diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt
new file mode 100644
index 0000000..a8c4382
--- /dev/null
+++ b/python/CMakeLists.txt
@@ -0,0 +1,64 @@
+include(AddMLIRPython)
+
+# Specifies that all MLIR packages are co-located under the `mlir_standalone`
+# top level package (the API has been embedded in a relocatable way).
+# TODO: Add an upstream cmake param for this vs having a global here.
+add_compile_definitions("MLIR_PYTHON_PACKAGE_PREFIX=mlir_standalone.")
+
+
+################################################################################
+# Sources
+################################################################################
+
+declare_mlir_python_sources(StandalonePythonSources)
+
+declare_mlir_dialect_python_bindings(
+ ADD_TO_PARENT StandalonePythonSources
+ ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir_standalone"
+ TD_FILE dialects/StandaloneOps.td
+ SOURCES
+ dialects/standalone.py
+ DIALECT_NAME standalone)
+
+declare_mlir_python_extension(StandalonePythonSources.Extension
+ MODULE_NAME _standaloneDialects
+ ADD_TO_PARENT StandalonePythonSources
+ SOURCES
+ StandaloneExtension.cpp
+ EMBED_CAPI_LINK_LIBS
+ StandaloneCAPI
+)
+
+################################################################################
+# Common CAPI
+################################################################################
+
+add_mlir_python_common_capi_library(StandalonePythonCAPI
+ INSTALL_COMPONENT StandalonePythonModules
+ INSTALL_DESTINATION python_packages/standalone/mlir_standalone/_mlir_libs
+ OUTPUT_DIRECTORY "${MLIR_BINARY_DIR}/python_packages/standalone/mlir_standalone/_mlir_libs"
+ RELATIVE_INSTALL_ROOT "../../../.."
+ DECLARED_SOURCES
+ StandalonePythonSources
+ # TODO: Remove this in favor of showing fine grained registration once
+ # available.
+ MLIRPythonExtension.RegisterEverything
+ MLIRPythonSources.Core
+)
+
+################################################################################
+# Instantiation of all Python modules
+################################################################################
+
+add_mlir_python_modules(StandalonePythonModules
+ ROOT_PREFIX "${MLIR_BINARY_DIR}/python_packages/standalone/mlir_standalone"
+ INSTALL_PREFIX "python_packages/standalone/mlir_standalone"
+ DECLARED_SOURCES
+ StandalonePythonSources
+ # TODO: Remove this in favor of showing fine grained registration once
+ # available.
+ MLIRPythonExtension.RegisterEverything
+ MLIRPythonSources
+ COMMON_CAPI_LINK_LIBS
+ StandalonePythonCAPI
+ )
diff --git a/python/StandaloneExtension.cpp b/python/StandaloneExtension.cpp
new file mode 100644
index 0000000..4c2043a
--- /dev/null
+++ b/python/StandaloneExtension.cpp
@@ -0,0 +1,31 @@
+//===- StandaloneExtension.cpp - Extension module -------------------------===//
+//
+// Part of the LLVM Project, 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "Standalone-c/Dialects.h"
+#include "mlir/Bindings/Python/PybindAdaptors.h"
+
+namespace py = pybind11;
+using namespace mlir::python::adaptors;
+
+PYBIND11_MODULE(_standaloneDialects, m) {
+ //===--------------------------------------------------------------------===//
+ // standalone dialect
+ //===--------------------------------------------------------------------===//
+ auto standalone_m = m.def_submodule("standalone");
+
+ standalone_m.def(
+ "register_dialect",
+ [](MlirContext context, bool load) {
+ MlirDialectHandle handle = mlirGetDialectHandle__standalone__();
+ mlirDialectHandleRegisterDialect(handle, context);
+ if (load) {
+ mlirDialectHandleLoadDialect(handle, context);
+ }
+ },
+ py::arg("context") = py::none(), py::arg("load") = true);
+}
diff --git a/python/mlir_standalone/dialects/StandaloneOps.td b/python/mlir_standalone/dialects/StandaloneOps.td
new file mode 100644
index 0000000..6cfa6b7
--- /dev/null
+++ b/python/mlir_standalone/dialects/StandaloneOps.td
@@ -0,0 +1,15 @@
+//===-- StandaloneOps.td - Python bindings for standalone --*- tablegen -*-===//
+//
+// Part of the LLVM Project, 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 PYTHON_BINDINGS_STANDALONE_OPS
+#define PYTHON_BINDINGS_STANDALONE_OPS
+
+include "mlir/Bindings/Python/Attributes.td"
+include "Standalone/StandaloneOps.td"
+
+#endif
diff --git a/python/mlir_standalone/dialects/standalone.py b/python/mlir_standalone/dialects/standalone.py
new file mode 100644
index 0000000..c958b2a
--- /dev/null
+++ b/python/mlir_standalone/dialects/standalone.py
@@ -0,0 +1,6 @@
+# Part of the LLVM Project, 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
+
+from ._standalone_ops_gen import *
+from .._mlir_libs._standaloneDialects.standalone import *
diff --git a/standalone-opt/CMakeLists.txt b/standalone-opt/CMakeLists.txt
index 06bbb47..ae459aa 100644
--- a/standalone-opt/CMakeLists.txt
+++ b/standalone-opt/CMakeLists.txt
@@ -3,6 +3,7 @@ get_property(conversion_libs GLOBAL PROPERTY MLIR_CONVERSION_LIBS)
set(LIBS
${dialect_libs}
${conversion_libs}
+ MLIRArithmeticDialect
MLIROptLib
MLIRStandalone
)
diff --git a/standalone-opt/standalone-opt.cpp b/standalone-opt/standalone-opt.cpp
index 97a996a..e84628f 100644
--- a/standalone-opt/standalone-opt.cpp
+++ b/standalone-opt/standalone-opt.cpp
@@ -6,6 +6,7 @@
//
//===----------------------------------------------------------------------===//
+#include "mlir/Dialect/Arithmetic/IR/Arithmetic.h"
#include "mlir/IR/Dialect.h"
#include "mlir/IR/MLIRContext.h"
#include "mlir/InitAllDialects.h"
@@ -13,7 +14,7 @@
#include "mlir/Pass/Pass.h"
#include "mlir/Pass/PassManager.h"
#include "mlir/Support/FileUtilities.h"
-#include "mlir/Support/MlirOptMain.h"
+#include "mlir/Tools/mlir-opt/MlirOptMain.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/InitLLVM.h"
#include "llvm/Support/SourceMgr.h"
@@ -26,8 +27,8 @@ int main(int argc, char **argv) {
// TODO: Register standalone passes here.
mlir::DialectRegistry registry;
- registry.insert<mlir::standalone::StandaloneDialect>();
- registry.insert<mlir::StandardOpsDialect>();
+ registry.insert<mlir::standalone::StandaloneDialect,
+ mlir::arith::ArithmeticDialect, mlir::func::FuncDialect>();
// Add the following to include *all* MLIR Core dialects, or selectively
// include what you need like above. You only need to register dialects that
// will be *parsed* by the tool, not the one generated
diff --git a/standalone-translate/CMakeLists.txt b/standalone-translate/CMakeLists.txt
index 137f794..ff70c7c 100644
--- a/standalone-translate/CMakeLists.txt
+++ b/standalone-translate/CMakeLists.txt
@@ -16,8 +16,8 @@ target_link_libraries(standalone-translate
MLIRIR
MLIRParser
MLIRPass
- MLIRSPIRV
- MLIRTranslation
+ MLIRSPIRVDialect
+ MLIRTranslateLib
MLIRSupport
)
diff --git a/standalone-translate/standalone-translate.cpp b/standalone-translate/standalone-translate.cpp
index f2f0ac5..2c2f275 100644
--- a/standalone-translate/standalone-translate.cpp
+++ b/standalone-translate/standalone-translate.cpp
@@ -13,7 +13,7 @@
#include "mlir/InitAllTranslations.h"
#include "mlir/Support/LogicalResult.h"
-#include "mlir/Translation.h"
+#include "mlir/Tools/mlir-translate/MlirTranslateMain.h"
#include "Standalone/StandaloneDialect.h"
diff --git a/test/CAPI/CMakeLists.txt b/test/CAPI/CMakeLists.txt
new file mode 100644
index 0000000..eaa6cfc
--- /dev/null
+++ b/test/CAPI/CMakeLists.txt
@@ -0,0 +1,20 @@
+# Here we create a single aggregate shared library with the parts of the CAPI
+# that we want to bundle together. Then we link a simple C executable
+# against it to demonstrate that it does have the fully self contained
+# core MLIR library and our own standalone dialect.
+add_mlir_aggregate(StandaloneCAPITestLib
+ SHARED
+ EMBED_LIBS
+ MLIRCAPIIR
+ # TODO: Remove this in favor of showing fine grained dialect registration
+ # (once available).
+ MLIRCAPIRegisterEverything
+ StandaloneCAPI
+)
+
+add_llvm_executable(standalone-capi-test
+ standalone-capi-test.c
+)
+llvm_update_compile_flags(standalone-capi-test)
+target_link_libraries(standalone-capi-test
+ PRIVATE StandaloneCAPITestLib)
diff --git a/test/CAPI/lit.local.cfg b/test/CAPI/lit.local.cfg
new file mode 100644
index 0000000..f08a0de
--- /dev/null
+++ b/test/CAPI/lit.local.cfg
@@ -0,0 +1 @@
+config.suffixes.add('.c')
diff --git a/test/CAPI/standalone-capi-test.c b/test/CAPI/standalone-capi-test.c
new file mode 100644
index 0000000..54f3ca7
--- /dev/null
+++ b/test/CAPI/standalone-capi-test.c
@@ -0,0 +1,49 @@
+//===- standalone-cap-demo.c - Simple demo of C-API -----------------------===//
+//
+// Part of the LLVM Project, 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
+//
+//===----------------------------------------------------------------------===//
+
+// RUN: standalone-capi-test 2>&1 | FileCheck %s
+
+#include <stdio.h>
+
+#include "Standalone-c/Dialects.h"
+#include "mlir-c/IR.h"
+#include "mlir-c/RegisterEverything.h"
+
+static void registerAllUpstreamDialects(MlirContext ctx) {
+ MlirDialectRegistry registry = mlirDialectRegistryCreate();
+ mlirRegisterAllDialects(registry);
+ mlirContextAppendDialectRegistry(ctx, registry);
+ mlirDialectRegistryDestroy(registry);
+}
+
+int main(int argc, char **argv) {
+ MlirContext ctx = mlirContextCreate();
+ // TODO: Create the dialect handles for the builtin dialects and avoid this.
+ // This adds dozens of MB of binary size over just the standalone dialect.
+ registerAllUpstreamDialects(ctx);
+ mlirDialectHandleRegisterDialect(mlirGetDialectHandle__standalone__(), ctx);
+
+ MlirModule module = mlirModuleCreateParse(
+ ctx, mlirStringRefCreateFromCString("%0 = arith.constant 2 : i32\n"
+ "%1 = standalone.foo %0 : i32\n"));
+ if (mlirModuleIsNull(module)) {
+ printf("ERROR: Could not parse.\n");
+ mlirContextDestroy(ctx);
+ return 1;
+ }
+ MlirOperation op = mlirModuleGetOperation(module);
+
+ // CHECK: %[[C:.*]] = arith.constant 2 : i32
+ // CHECK: standalone.foo %[[C]] : i32
+ mlirOperationDump(op);
+
+ mlirModuleDestroy(module);
+ mlirContextDestroy(ctx);
+ return 0;
+}
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index 29da2b8..d47ba93 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -1,3 +1,7 @@
+llvm_canonicalize_cmake_booleans(
+ MLIR_ENABLE_BINDINGS_PYTHON
+)
+
configure_lit_site_cfg(
${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in
${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg.py
@@ -7,9 +11,13 @@ configure_lit_site_cfg(
set(STANDALONE_TEST_DEPENDS
FileCheck count not
+ standalone-capi-test
standalone-opt
standalone-translate
)
+if(MLIR_ENABLE_BINDINGS_PYTHON)
+ list(APPEND STANDALONE_TEST_DEPENDS StandalonePythonModules)
+endif()
add_lit_testsuite(check-standalone "Running the standalone regression tests"
${CMAKE_CURRENT_BINARY_DIR}
@@ -18,3 +26,5 @@ add_lit_testsuite(check-standalone "Running the standalone regression tests"
set_target_properties(check-standalone PROPERTIES FOLDER "Tests")
add_lit_testsuites(STANDALONE ${CMAKE_CURRENT_SOURCE_DIR} DEPENDS ${STANDALONE_TEST_DEPENDS})
+
+add_subdirectory(CAPI)
diff --git a/test/Standalone/dummy.mlir b/test/Standalone/dummy.mlir
index ada4280..cb688d2 100644
--- a/test/Standalone/dummy.mlir
+++ b/test/Standalone/dummy.mlir
@@ -2,8 +2,8 @@
module {
// CHECK-LABEL: func @bar()
- func @bar() {
- %0 = constant 1 : i32
+ func.func @bar() {
+ %0 = arith.constant 1 : i32
// CHECK: %{{.*}} = standalone.foo %{{.*}} : i32
%res = standalone.foo %0 : i32
return
diff --git a/test/lit.cfg.py b/test/lit.cfg.py
index 9fb5b54..a6a3d24 100644
--- a/test/lit.cfg.py
+++ b/test/lit.cfg.py
@@ -30,7 +30,6 @@ config.test_source_root = os.path.dirname(__file__)
config.test_exec_root = os.path.join(config.standalone_obj_root, 'test')
config.substitutions.append(('%PATH%', config.environment['PATH']))
-config.substitutions.append(('%shlibext', config.llvm_shlib_ext))
llvm_config.with_system_environment(
['HOME', 'INCLUDE', 'LIB', 'TMP', 'TEMP'])
@@ -42,9 +41,6 @@ llvm_config.use_default_substitutions()
# directories.
config.excludes = ['Inputs', 'Examples', 'CMakeLists.txt', 'README.txt', 'LICENSE.txt']
-# test_source_root: The root path where tests are located.
-config.test_source_root = os.path.dirname(__file__)
-
# test_exec_root: The root path where tests should be run.
config.test_exec_root = os.path.join(config.standalone_obj_root, 'test')
config.standalone_tools_dir = os.path.join(config.standalone_obj_root, 'bin')
@@ -54,8 +50,13 @@ llvm_config.with_environment('PATH', config.llvm_tools_dir, append_path=True)
tool_dirs = [config.standalone_tools_dir, config.llvm_tools_dir]
tools = [
+ 'standalone-capi-test',
'standalone-opt',
- 'standalone-translate'
+ 'standalone-translate',
]
llvm_config.add_tool_substitutions(tools, tool_dirs)
+
+llvm_config.with_environment('PYTHONPATH', [
+ os.path.join(config.mlir_obj_dir, 'python_packages', 'standalone'),
+], append_path=True)
diff --git a/test/lit.site.cfg.py.in b/test/lit.site.cfg.py.in
index 26fb8aa..8f9e557 100644
--- a/test/lit.site.cfg.py.in
+++ b/test/lit.site.cfg.py.in
@@ -1,49 +1,10 @@
@LIT_SITE_CFG_IN_HEADER@
-import sys
-
-config.host_triple = "@LLVM_HOST_TRIPLE@"
-config.target_triple = "@TARGET_TRIPLE@"
-config.llvm_src_root = "@LLVM_SOURCE_DIR@"
-config.llvm_obj_root = "@LLVM_BINARY_DIR@"
-config.llvm_tools_dir = "@LLVM_TOOLS_DIR@"
-config.llvm_lib_dir = "@LLVM_LIBS_DIR@"
-config.llvm_shlib_dir = "@SHLIBDIR@"
-config.llvm_shlib_ext = "@SHLIBEXT@"
-config.llvm_exe_ext = "@EXEEXT@"
-config.lit_tools_dir = "@LLVM_LIT_TOOLS_DIR@"
-config.python_executable = "@PYTHON_EXECUTABLE@"
-config.gold_executable = "@GOLD_EXECUTABLE@"
-config.ld64_executable = "@LD64_EXECUTABLE@"
-config.enable_shared = @ENABLE_SHARED@
-config.enable_assertions = @ENABLE_ASSERTIONS@
-config.targets_to_build = "@TARGETS_TO_BUILD@"
-config.native_target = "@LLVM_NATIVE_ARCH@"
-config.llvm_bindings = "@LLVM_BINDINGS@".split(' ')
-config.host_os = "@HOST_OS@"
-config.host_cc = "@HOST_CC@"
-config.host_cxx = "@HOST_CXX@"
-config.enable_libcxx = "@LLVM_ENABLE_LIBCXX@"
-# Note: ldflags can contain double-quoted paths, so must use single quotes here.
-config.host_ldflags = '@HOST_LDFLAGS@'
-config.llvm_use_sanitizer = "@LLVM_USE_SANITIZER@"
-config.llvm_host_triple = '@LLVM_HOST_TRIPLE@'
-config.host_arch = "@HOST_ARCH@"
-config.standalone_src_root = "@CMAKE_SOURCE_DIR@"
+config.llvm_tools_dir = lit_config.substitute("@LLVM_TOOLS_DIR@")
+config.mlir_obj_dir = "@MLIR_BINARY_DIR@"
+config.enable_bindings_python = @MLIR_ENABLE_BINDINGS_PYTHON@
config.standalone_obj_root = "@CMAKE_BINARY_DIR@"
-# Support substitution of the tools_dir with user parameters. This is
-# used when we can't determine the tool dir at configuration time.
-try:
- config.llvm_tools_dir = config.llvm_tools_dir % lit_config.params
- config.llvm_lib_dir = config.llvm_lib_dir % lit_config.params
- config.llvm_shlib_dir = config.llvm_shlib_dir % lit_config.params
-except KeyError:
- e = sys.exc_info()[1]
- key, = e.args
- lit_config.fatal("unable to find %r parameter, use '--param=%s=VALUE'" % (key,key))
-
-
import lit.llvm
lit.llvm.initialize(lit_config, config)
diff --git a/test/python/lit.local.cfg b/test/python/lit.local.cfg
new file mode 100644
index 0000000..b70b9d7
--- /dev/null
+++ b/test/python/lit.local.cfg
@@ -0,0 +1,4 @@
+config.suffixes.add('.py')
+
+if not config.enable_bindings_python:
+ config.unsupported = True
diff --git a/test/python/smoketest.py b/test/python/smoketest.py
new file mode 100644
index 0000000..0d8f41c
--- /dev/null
+++ b/test/python/smoketest.py
@@ -0,0 +1,17 @@
+# RUN: %python %s | FileCheck %s
+
+from mlir_standalone.ir import *
+from mlir_standalone.dialects import (
+ builtin as builtin_d,
+ standalone as standalone_d
+)
+
+with Context():
+ standalone_d.register_dialect()
+ module = Module.parse("""
+ %0 = arith.constant 2 : i32
+ %1 = standalone.foo %0 : i32
+ """)
+ # CHECK: %[[C:.*]] = arith.constant 2 : i32
+ # CHECK: standalone.foo %[[C]] : i32
+ print(str(module))