aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYann Herklotz <git@yannherklotz.com>2021-09-28 14:50:44 +0100
committerYann Herklotz <git@yannherklotz.com>2021-09-28 14:50:44 +0100
commita08f79d3e01c92859e6b33f602b2be2bb8c52e61 (patch)
treeaa6fe94ea8b3ad841dbda0e354a88f8291d6973d
downloadgsa-mlir-a08f79d3e01c92859e6b33f602b2be2bb8c52e61.tar.gz
gsa-mlir-a08f79d3e01c92859e6b33f602b2be2bb8c52e61.zip
Add initial files
-rw-r--r--CMakeLists.txt35
-rw-r--r--README.md18
-rw-r--r--include/CMakeLists.txt1
-rw-r--r--include/Standalone/CMakeLists.txt3
-rw-r--r--include/Standalone/StandaloneDialect.h16
-rw-r--r--include/Standalone/StandaloneDialect.td36
-rw-r--r--include/Standalone/StandaloneOps.h20
-rw-r--r--include/Standalone/StandaloneOps.td42
-rw-r--r--lib/CMakeLists.txt1
-rw-r--r--lib/Standalone/CMakeLists.txt13
-rw-r--r--lib/Standalone/StandaloneDialect.cpp26
-rw-r--r--lib/Standalone/StandaloneOps.cpp14
-rw-r--r--standalone-opt/CMakeLists.txt14
-rw-r--r--standalone-opt/standalone-opt.cpp38
-rw-r--r--standalone-translate/CMakeLists.txt24
-rw-r--r--standalone-translate/standalone-translate.cpp27
-rw-r--r--test/CMakeLists.txt20
-rw-r--r--test/Standalone/dummy.mlir11
-rw-r--r--test/Standalone/standalone-opt.mlir3
-rw-r--r--test/Standalone/standalone-translate.mlir5
-rw-r--r--test/lit.cfg.py61
-rw-r--r--test/lit.site.cfg.py.in51
22 files changed, 479 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644
index 0000000..fc42e3e
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,35 @@
+cmake_minimum_required(VERSION 3.13.4)
+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")
+
+find_package(MLIR REQUIRED CONFIG)
+
+message(STATUS "Using MLIRConfig.cmake in: ${MLIR_DIR}")
+message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")
+
+set(LLVM_RUNTIME_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/bin)
+set(LLVM_LIBRARY_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/lib)
+set(MLIR_BINARY_DIR ${CMAKE_BINARY_DIR})
+
+list(APPEND CMAKE_MODULE_PATH "${MLIR_CMAKE_DIR}")
+list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_DIR}")
+include(TableGen)
+include(AddLLVM)
+include(AddMLIR)
+include(HandleLLVMOptions)
+
+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(test)
+add_subdirectory(standalone-opt)
+add_subdirectory(standalone-translate)
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..b1ca627
--- /dev/null
+++ b/README.md
@@ -0,0 +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.
+
+## Building
+
+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.
+
diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt
new file mode 100644
index 0000000..da11071
--- /dev/null
+++ b/include/CMakeLists.txt
@@ -0,0 +1 @@
+add_subdirectory(Standalone)
diff --git a/include/Standalone/CMakeLists.txt b/include/Standalone/CMakeLists.txt
new file mode 100644
index 0000000..8acf640
--- /dev/null
+++ b/include/Standalone/CMakeLists.txt
@@ -0,0 +1,3 @@
+add_mlir_dialect(StandaloneOps standalone)
+add_mlir_doc(StandaloneDialect StandaloneDialect Standalone/ -gen-dialect-doc)
+add_mlir_doc(StandaloneOps StandaloneOps Standalone/ -gen-op-doc)
diff --git a/include/Standalone/StandaloneDialect.h b/include/Standalone/StandaloneDialect.h
new file mode 100644
index 0000000..d3eb24c
--- /dev/null
+++ b/include/Standalone/StandaloneDialect.h
@@ -0,0 +1,16 @@
+//===- StandaloneDialect.h - Standalone dialect -----------------*- 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_STANDALONEDIALECT_H
+#define STANDALONE_STANDALONEDIALECT_H
+
+#include "mlir/IR/Dialect.h"
+
+#include "Standalone/StandaloneOpsDialect.h.inc"
+
+#endif // STANDALONE_STANDALONEDIALECT_H
diff --git a/include/Standalone/StandaloneDialect.td b/include/Standalone/StandaloneDialect.td
new file mode 100644
index 0000000..a7fd789
--- /dev/null
+++ b/include/Standalone/StandaloneDialect.td
@@ -0,0 +1,36 @@
+//===- StandaloneDialect.td - Standalone 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 STANDALONE_DIALECT
+#define STANDALONE_DIALECT
+
+include "mlir/IR/OpBase.td"
+
+//===----------------------------------------------------------------------===//
+// Standalone dialect definition.
+//===----------------------------------------------------------------------===//
+
+def Standalone_Dialect : Dialect {
+ let name = "standalone";
+ let summary = "A standalone out-of-tree MLIR dialect.";
+ let description = [{
+ This dialect is an example of an out-of-tree MLIR dialect designed to
+ illustrate the basic setup required to develop MLIR-based tools without
+ working inside of the LLVM source tree.
+ }];
+ let cppNamespace = "::mlir::standalone";
+}
+
+//===----------------------------------------------------------------------===//
+// Base standalone operation definition.
+//===----------------------------------------------------------------------===//
+
+class Standalone_Op<string mnemonic, list<OpTrait> traits = []> :
+ Op<Standalone_Dialect, mnemonic, traits>;
+
+#endif // STANDALONE_DIALECT
diff --git a/include/Standalone/StandaloneOps.h b/include/Standalone/StandaloneOps.h
new file mode 100644
index 0000000..a56c286
--- /dev/null
+++ b/include/Standalone/StandaloneOps.h
@@ -0,0 +1,20 @@
+//===- StandaloneOps.h - Standalone dialect ops -----------------*- 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_STANDALONEOPS_H
+#define STANDALONE_STANDALONEOPS_H
+
+#include "mlir/IR/BuiltinTypes.h"
+#include "mlir/IR/Dialect.h"
+#include "mlir/IR/OpDefinition.h"
+#include "mlir/Interfaces/SideEffectInterfaces.h"
+
+#define GET_OP_CLASSES
+#include "Standalone/StandaloneOps.h.inc"
+
+#endif // STANDALONE_STANDALONEOPS_H
diff --git a/include/Standalone/StandaloneOps.td b/include/Standalone/StandaloneOps.td
new file mode 100644
index 0000000..f6ba7a6
--- /dev/null
+++ b/include/Standalone/StandaloneOps.td
@@ -0,0 +1,42 @@
+//===- StandaloneOps.td - Standalone 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 STANDALONE_OPS
+#define STANDALONE_OPS
+
+include "StandaloneDialect.td"
+include "mlir/Interfaces/SideEffectInterfaces.td"
+
+def Standalone_FooOp : Standalone_Op<"foo", [NoSideEffect,
+ SameOperandsAndResultType]> {
+ let summary = "Illustrates how to define an operation.";
+ let description = [{
+ The `standalone.foo` operation illustrates how to define a new
+ operation in a dialect. It uses an operation trait to declare that it
+ has no side effects.
+
+ This operation takes an integer argument and returns an integer.
+
+ Example:
+
+ ```mlir
+ %0 = constant 2 : i32
+ // Apply the foo operation to %0
+ %1 = standalone.foo %0 : i32
+ ```
+ }];
+
+ let arguments = (ins I32:$input);
+ let results = (outs I32:$res);
+
+ let assemblyFormat = [{
+ $input attr-dict `:` type($input)
+ }];
+}
+
+#endif // STANDALONE_OPS
diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt
new file mode 100644
index 0000000..da11071
--- /dev/null
+++ b/lib/CMakeLists.txt
@@ -0,0 +1 @@
+add_subdirectory(Standalone)
diff --git a/lib/Standalone/CMakeLists.txt b/lib/Standalone/CMakeLists.txt
new file mode 100644
index 0000000..c8b16b7
--- /dev/null
+++ b/lib/Standalone/CMakeLists.txt
@@ -0,0 +1,13 @@
+add_mlir_dialect_library(MLIRStandalone
+ StandaloneDialect.cpp
+ StandaloneOps.cpp
+
+ ADDITIONAL_HEADER_DIRS
+ ${PROJECT_SOURCE_DIR}/include/Standalone
+
+ DEPENDS
+ MLIRStandaloneOpsIncGen
+
+ LINK_LIBS PUBLIC
+ MLIRIR
+ )
diff --git a/lib/Standalone/StandaloneDialect.cpp b/lib/Standalone/StandaloneDialect.cpp
new file mode 100644
index 0000000..cdd9337
--- /dev/null
+++ b/lib/Standalone/StandaloneDialect.cpp
@@ -0,0 +1,26 @@
+//===- StandaloneDialect.cpp - Standalone dialect ---------------*- 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "Standalone/StandaloneDialect.h"
+#include "Standalone/StandaloneOps.h"
+
+using namespace mlir;
+using namespace mlir::standalone;
+
+#include "Standalone/StandaloneOpsDialect.cpp.inc"
+
+//===----------------------------------------------------------------------===//
+// Standalone dialect.
+//===----------------------------------------------------------------------===//
+
+void StandaloneDialect::initialize() {
+ addOperations<
+#define GET_OP_LIST
+#include "Standalone/StandaloneOps.cpp.inc"
+ >();
+}
diff --git a/lib/Standalone/StandaloneOps.cpp b/lib/Standalone/StandaloneOps.cpp
new file mode 100644
index 0000000..497eb98
--- /dev/null
+++ b/lib/Standalone/StandaloneOps.cpp
@@ -0,0 +1,14 @@
+//===- StandaloneOps.cpp - Standalone dialect ops ---------------*- 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "Standalone/StandaloneOps.h"
+#include "Standalone/StandaloneDialect.h"
+#include "mlir/IR/OpImplementation.h"
+
+#define GET_OP_CLASSES
+#include "Standalone/StandaloneOps.cpp.inc"
diff --git a/standalone-opt/CMakeLists.txt b/standalone-opt/CMakeLists.txt
new file mode 100644
index 0000000..06bbb47
--- /dev/null
+++ b/standalone-opt/CMakeLists.txt
@@ -0,0 +1,14 @@
+get_property(dialect_libs GLOBAL PROPERTY MLIR_DIALECT_LIBS)
+get_property(conversion_libs GLOBAL PROPERTY MLIR_CONVERSION_LIBS)
+set(LIBS
+ ${dialect_libs}
+ ${conversion_libs}
+ MLIROptLib
+ MLIRStandalone
+ )
+add_llvm_executable(standalone-opt standalone-opt.cpp)
+
+llvm_update_compile_flags(standalone-opt)
+target_link_libraries(standalone-opt PRIVATE ${LIBS})
+
+mlir_check_all_link_libraries(standalone-opt)
diff --git a/standalone-opt/standalone-opt.cpp b/standalone-opt/standalone-opt.cpp
new file mode 100644
index 0000000..97a996a
--- /dev/null
+++ b/standalone-opt/standalone-opt.cpp
@@ -0,0 +1,38 @@
+//===- standalone-opt.cpp ---------------------------------------*- 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "mlir/IR/Dialect.h"
+#include "mlir/IR/MLIRContext.h"
+#include "mlir/InitAllDialects.h"
+#include "mlir/InitAllPasses.h"
+#include "mlir/Pass/Pass.h"
+#include "mlir/Pass/PassManager.h"
+#include "mlir/Support/FileUtilities.h"
+#include "mlir/Support/MlirOptMain.h"
+#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/InitLLVM.h"
+#include "llvm/Support/SourceMgr.h"
+#include "llvm/Support/ToolOutputFile.h"
+
+#include "Standalone/StandaloneDialect.h"
+
+int main(int argc, char **argv) {
+ mlir::registerAllPasses();
+ // TODO: Register standalone passes here.
+
+ mlir::DialectRegistry registry;
+ registry.insert<mlir::standalone::StandaloneDialect>();
+ registry.insert<mlir::StandardOpsDialect>();
+ // 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
+ // registerAllDialects(registry);
+
+ return mlir::asMainReturnCode(
+ mlir::MlirOptMain(argc, argv, "Standalone optimizer driver\n", registry));
+}
diff --git a/standalone-translate/CMakeLists.txt b/standalone-translate/CMakeLists.txt
new file mode 100644
index 0000000..137f794
--- /dev/null
+++ b/standalone-translate/CMakeLists.txt
@@ -0,0 +1,24 @@
+set(LLVM_LINK_COMPONENTS
+ Support
+ )
+
+get_property(dialect_libs GLOBAL PROPERTY MLIR_DIALECT_LIBS)
+get_property(translation_libs GLOBAL PROPERTY MLIR_TRANSLATION_LIBS)
+
+add_llvm_executable(standalone-translate
+ standalone-translate.cpp
+ )
+llvm_update_compile_flags(standalone-translate)
+target_link_libraries(standalone-translate
+ PRIVATE
+ ${dialect_libs}
+ ${translation_libs}
+ MLIRIR
+ MLIRParser
+ MLIRPass
+ MLIRSPIRV
+ MLIRTranslation
+ MLIRSupport
+ )
+
+mlir_check_link_libraries(standalone-translate)
diff --git a/standalone-translate/standalone-translate.cpp b/standalone-translate/standalone-translate.cpp
new file mode 100644
index 0000000..f2f0ac5
--- /dev/null
+++ b/standalone-translate/standalone-translate.cpp
@@ -0,0 +1,27 @@
+//===- standalone-translate.cpp ---------------------------------*- 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
+//
+//===----------------------------------------------------------------------===//
+//
+// This is a command line utility that translates a file from/to MLIR using one
+// of the registered translations.
+//
+//===----------------------------------------------------------------------===//
+
+#include "mlir/InitAllTranslations.h"
+#include "mlir/Support/LogicalResult.h"
+#include "mlir/Translation.h"
+
+#include "Standalone/StandaloneDialect.h"
+
+int main(int argc, char **argv) {
+ mlir::registerAllTranslations();
+
+ // TODO: Register standalone translations here.
+
+ return failed(
+ mlir::mlirTranslateMain(argc, argv, "MLIR Translation Testing Tool"));
+}
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
new file mode 100644
index 0000000..29da2b8
--- /dev/null
+++ b/test/CMakeLists.txt
@@ -0,0 +1,20 @@
+configure_lit_site_cfg(
+ ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in
+ ${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg.py
+ MAIN_CONFIG
+ ${CMAKE_CURRENT_SOURCE_DIR}/lit.cfg.py
+)
+
+set(STANDALONE_TEST_DEPENDS
+ FileCheck count not
+ standalone-opt
+ standalone-translate
+ )
+
+add_lit_testsuite(check-standalone "Running the standalone regression tests"
+ ${CMAKE_CURRENT_BINARY_DIR}
+ DEPENDS ${STANDALONE_TEST_DEPENDS}
+ )
+set_target_properties(check-standalone PROPERTIES FOLDER "Tests")
+
+add_lit_testsuites(STANDALONE ${CMAKE_CURRENT_SOURCE_DIR} DEPENDS ${STANDALONE_TEST_DEPENDS})
diff --git a/test/Standalone/dummy.mlir b/test/Standalone/dummy.mlir
new file mode 100644
index 0000000..ada4280
--- /dev/null
+++ b/test/Standalone/dummy.mlir
@@ -0,0 +1,11 @@
+// RUN: standalone-opt %s | standalone-opt | FileCheck %s
+
+module {
+ // CHECK-LABEL: func @bar()
+ func @bar() {
+ %0 = constant 1 : i32
+ // CHECK: %{{.*}} = standalone.foo %{{.*}} : i32
+ %res = standalone.foo %0 : i32
+ return
+ }
+}
diff --git a/test/Standalone/standalone-opt.mlir b/test/Standalone/standalone-opt.mlir
new file mode 100644
index 0000000..1a78a9d
--- /dev/null
+++ b/test/Standalone/standalone-opt.mlir
@@ -0,0 +1,3 @@
+// RUN: standalone-opt --show-dialects | FileCheck %s
+// CHECK: Available Dialects:
+// CHECK: standalone
diff --git a/test/Standalone/standalone-translate.mlir b/test/Standalone/standalone-translate.mlir
new file mode 100644
index 0000000..16d4978
--- /dev/null
+++ b/test/Standalone/standalone-translate.mlir
@@ -0,0 +1,5 @@
+// RUN: standalone-translate --help | FileCheck %s
+// CHECK: --deserialize-spirv
+// CHECK: --import-llvm
+// CHECK: --mlir-to-llvmir
+// CHECK: --serialize-spirv
diff --git a/test/lit.cfg.py b/test/lit.cfg.py
new file mode 100644
index 0000000..9fb5b54
--- /dev/null
+++ b/test/lit.cfg.py
@@ -0,0 +1,61 @@
+# -*- Python -*-
+
+import os
+import platform
+import re
+import subprocess
+import tempfile
+
+import lit.formats
+import lit.util
+
+from lit.llvm import llvm_config
+from lit.llvm.subst import ToolSubst
+from lit.llvm.subst import FindTool
+
+# Configuration file for the 'lit' test runner.
+
+# name: The name of this test suite.
+config.name = 'STANDALONE'
+
+config.test_format = lit.formats.ShTest(not llvm_config.use_lit_shell)
+
+# suffixes: A list of file extensions to treat as test files.
+config.suffixes = ['.mlir']
+
+# 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.substitutions.append(('%PATH%', config.environment['PATH']))
+config.substitutions.append(('%shlibext', config.llvm_shlib_ext))
+
+llvm_config.with_system_environment(
+ ['HOME', 'INCLUDE', 'LIB', 'TMP', 'TEMP'])
+
+llvm_config.use_default_substitutions()
+
+# excludes: A list of directories to exclude from the testsuite. The 'Inputs'
+# subdirectories contain auxiliary inputs for various tests in their parent
+# 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')
+
+# Tweak the PATH to include the tools dir.
+llvm_config.with_environment('PATH', config.llvm_tools_dir, append_path=True)
+
+tool_dirs = [config.standalone_tools_dir, config.llvm_tools_dir]
+tools = [
+ 'standalone-opt',
+ 'standalone-translate'
+]
+
+llvm_config.add_tool_substitutions(tools, tool_dirs)
diff --git a/test/lit.site.cfg.py.in b/test/lit.site.cfg.py.in
new file mode 100644
index 0000000..26fb8aa
--- /dev/null
+++ b/test/lit.site.cfg.py.in
@@ -0,0 +1,51 @@
+@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.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)
+
+# Let the main config do the real work.
+lit_config.load_config(config, "@CMAKE_SOURCE_DIR@/test/lit.cfg.py")