From 1615878de41ae139f6aaf480cc98ffac47ced50c Mon Sep 17 00:00:00 2001 From: "Mei, Yijie" Date: Thu, 9 May 2024 10:18:13 +0800 Subject: [PATCH 1/7] [tests] Add example MLIR-unittest in lit --- .github/workflows/build-llvm.yml | 2 +- CMakeLists.txt | 1 + test/CMakeLists.txt | 8 ++++ test/gc-dialects/Unit/lit.cfg.py | 50 ++++++++++++++++++++++++ test/gc-dialects/Unit/lit.site.cfg.py.in | 12 ++++++ unittests/CMakeLists.txt | 18 +++++++++ unittests/Example/CMakeLists.txt | 6 +++ unittests/Example/Example.cpp | 14 +++++++ 8 files changed, 110 insertions(+), 1 deletion(-) create mode 100644 test/gc-dialects/Unit/lit.cfg.py create mode 100644 test/gc-dialects/Unit/lit.site.cfg.py.in create mode 100644 unittests/CMakeLists.txt create mode 100644 unittests/Example/CMakeLists.txt create mode 100644 unittests/Example/Example.cpp diff --git a/.github/workflows/build-llvm.yml b/.github/workflows/build-llvm.yml index b1844eee0..bc225a829 100644 --- a/.github/workflows/build-llvm.yml +++ b/.github/workflows/build-llvm.yml @@ -26,7 +26,7 @@ jobs: run: | mkdir llvm-install cmake -G Ninja llvm -B build -DCMAKE_INSTALL_PREFIX=llvm-install \ - -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_ASSERTIONS=true -DLLVM_ENABLE_PROJECTS="mlir" -DLLVM_TARGETS_TO_BUILD="X86" -DLLVM_INSTALL_UTILS=true -DCMAKE_EXPORT_COMPILE_COMMANDS=ON + -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_ASSERTIONS=true -DLLVM_ENABLE_PROJECTS="mlir" -DLLVM_TARGETS_TO_BUILD="X86" -DLLVM_INSTALL_UTILS=true -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DLLVM_INSTALL_GTEST=ON cmake --build build --target install cd llvm-install tar -zcf ../llvm.tgz . diff --git a/CMakeLists.txt b/CMakeLists.txt index 1752a7132..2e29ebf1f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -55,4 +55,5 @@ set(GC_LIB_LINKED_LIBS ) target_link_libraries(graph_compiler PRIVATE ${GC_LIB_LINKED_LIBS}) +add_subdirectory(unittests) add_subdirectory(test) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 98c7c8c44..0dad7d086 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -18,10 +18,18 @@ configure_lit_site_cfg( ${CMAKE_CURRENT_SOURCE_DIR}/lit.cfg.py ) +configure_lit_site_cfg( + ${CMAKE_CURRENT_SOURCE_DIR}/gc-dialects/Unit/lit.site.cfg.py.in + ${CMAKE_CURRENT_BINARY_DIR}/gc-dialects/Unit/lit.site.cfg.py + MAIN_CONFIG + ${CMAKE_CURRENT_SOURCE_DIR}/gc-dialects/Unit/lit.cfg.py +) + set(GC_OPT_TEST_DEPENDS FileCheck count not # mlir-gen gc-opt + GCUnitTests ) add_lit_testsuite(gc-check "Running the regression tests" diff --git a/test/gc-dialects/Unit/lit.cfg.py b/test/gc-dialects/Unit/lit.cfg.py new file mode 100644 index 000000000..f95297685 --- /dev/null +++ b/test/gc-dialects/Unit/lit.cfg.py @@ -0,0 +1,50 @@ +# -*- Python -*- + +# Configuration file for the 'lit' test runner. + +import os +import subprocess + +import lit.formats + +# name: The name of this test suite. +config.name = "GC-Unit" + +# suffixes: A list of file extensions to treat as test files. +config.suffixes = [] + +# test_source_root: The root path where tests are located. +# test_exec_root: The root path where tests should be run. +config.test_exec_root = os.path.join(config.gc_obj_root, "unittests") +config.test_source_root = config.test_exec_root + +# testFormat: The test format to use to interpret tests. +config.test_format = lit.formats.GoogleTest(config.llvm_build_mode, "Tests") + +# Propagate the temp directory. Windows requires this because it uses \Windows\ +# if none of these are present. +if "TMP" in os.environ: + config.environment["TMP"] = os.environ["TMP"] +if "TEMP" in os.environ: + config.environment["TEMP"] = os.environ["TEMP"] + +# Propagate HOME as it can be used to override incorrect homedir in passwd +# that causes the tests to fail. +if "HOME" in os.environ: + config.environment["HOME"] = os.environ["HOME"] + +# Propagate sanitizer options. +for var in [ + "ASAN_SYMBOLIZER_PATH", + "HWASAN_SYMBOLIZER_PATH", + "MSAN_SYMBOLIZER_PATH", + "TSAN_SYMBOLIZER_PATH", + "UBSAN_SYMBOLIZER_PATH", + "ASAN_OPTIONS", + "HWASAN_OPTIONS", + "MSAN_OPTIONS", + "TSAN_OPTIONS", + "UBSAN_OPTIONS", +]: + if var in os.environ: + config.environment[var] = os.environ[var] diff --git a/test/gc-dialects/Unit/lit.site.cfg.py.in b/test/gc-dialects/Unit/lit.site.cfg.py.in new file mode 100644 index 000000000..ef35f8a0d --- /dev/null +++ b/test/gc-dialects/Unit/lit.site.cfg.py.in @@ -0,0 +1,12 @@ +@LIT_SITE_CFG_IN_HEADER@ + +import sys + +config.llvm_tools_dir = lit_config.substitute("@LLVM_TOOLS_DIR@") +config.llvm_build_mode = lit_config.substitute("@LLVM_BUILD_MODE@") +config.mlir_obj_root = "@MLIR_BINARY_DIR@" +config.gc_src_root = "@CMAKE_SOURCE_DIR@" +config.gc_obj_root = "@CMAKE_BINARY_DIR@" + +# Let the main config do the real work. +lit_config.load_config(config, "@CMAKE_SOURCE_DIR@/test/gc-dialects/Unit/lit.cfg.py") diff --git a/unittests/CMakeLists.txt b/unittests/CMakeLists.txt new file mode 100644 index 000000000..949595fca --- /dev/null +++ b/unittests/CMakeLists.txt @@ -0,0 +1,18 @@ +if (NOT GC_TEST_ENABLE) + message(STATUS "The unittests are not enabled.") + return() +endif () + +add_definitions(-DMLIR_INCLUDE_TESTS) +add_custom_target(GCUnitTests) +set_target_properties(GCUnitTests PROPERTIES FOLDER "MLIR GC Tests") + +# To silence warning caused by Wundef. +add_definitions(-DGTEST_NO_LLVM_SUPPORT=0) + +function(add_mlir_unittest test_dirname) + add_unittest(GCUnitTests ${test_dirname} ${ARGN}) +endfunction() + +add_subdirectory(Example) + diff --git a/unittests/Example/CMakeLists.txt b/unittests/Example/CMakeLists.txt new file mode 100644 index 000000000..2439010b5 --- /dev/null +++ b/unittests/Example/CMakeLists.txt @@ -0,0 +1,6 @@ +add_mlir_unittest(GCExampleTests + Example.cpp +) +target_link_libraries(GCExampleTests + PRIVATE + MLIRLinalgx) diff --git a/unittests/Example/Example.cpp b/unittests/Example/Example.cpp new file mode 100644 index 000000000..030f0682f --- /dev/null +++ b/unittests/Example/Example.cpp @@ -0,0 +1,14 @@ +//===- Example.cpp - Tests for Example ------------------------------------===// +// +// 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 "gtest/gtest.h" +#include "gc-dialects/Linalgx/LinalgxDialect.h" + +TEST(example, HelloWorld) { + ASSERT_EQ(mlir::linalgx::LinalgxDialect::getDialectNamespace(), "linalgx"); +} From d1225c06e383b1f1dab5c1f6a7e94068d287a8a6 Mon Sep 17 00:00:00 2001 From: "Mei, Yijie" Date: Thu, 9 May 2024 10:22:42 +0800 Subject: [PATCH 2/7] format --- unittests/Example/Example.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unittests/Example/Example.cpp b/unittests/Example/Example.cpp index 030f0682f..9a1b27a45 100644 --- a/unittests/Example/Example.cpp +++ b/unittests/Example/Example.cpp @@ -6,8 +6,8 @@ // //===----------------------------------------------------------------------===// -#include "gtest/gtest.h" #include "gc-dialects/Linalgx/LinalgxDialect.h" +#include "gtest/gtest.h" TEST(example, HelloWorld) { ASSERT_EQ(mlir::linalgx::LinalgxDialect::getDialectNamespace(), "linalgx"); From 30706049f048961cdc1be044c067f94cd4722795 Mon Sep 17 00:00:00 2001 From: "Mei, Yijie" Date: Thu, 9 May 2024 13:24:47 +0800 Subject: [PATCH 3/7] stash --- docs/EasyBuilder.md | 345 +++++++++++++++ include/gc-dialects/Arith/Utils/EasyBuild.h | 453 ++++++++++++++++++++ 2 files changed, 798 insertions(+) create mode 100644 docs/EasyBuilder.md create mode 100644 include/gc-dialects/Arith/Utils/EasyBuild.h diff --git a/docs/EasyBuilder.md b/docs/EasyBuilder.md new file mode 100644 index 000000000..f9f018977 --- /dev/null +++ b/docs/EasyBuilder.md @@ -0,0 +1,345 @@ +# Easy builder for building IR in C++ + +Sometimes in the transformations of MLIR, developers may need to use C++ to +build complex IR. For example, developers may expand math operators `exp` to +polynormial expressions when mathematical approximation is allowed. This may +result in tens of calls to `builder.create(loc, ...)` in the expansion pass +implementation. Another example is that when a pass expands and tiles a `matmul` +operation, the developer may need to write lines of code to create `scf.for` and +`scf.if`, and manipulate the insertion point for the `OpBuilder` to create IR +with complex control flow to schedule the tile based on thread-id and cache +size. One can imagine that the C++ code to accomplish the above task will be +verbose and hard to read. The easy-builder utilities are introduced to +make it easier to develop C++ code building complex IR. Easy-builder is not +designed to replace the `OpBuilder`. Instead, it is built upon that, and serves +as supplementary IR builder for complex cases, like heavily using `arith` and +`scf` operations. + +An example code to build IR `(x+y-10)/(x-y+1)`, where `x` and `y` are unsigned +16-bit integers: + +```C++ +OpBuilder builder = ...; +Value x = ...; +Value y = ...; +Location loc = ...; + +// start of easy-build +EasyBuilder b{builder, loc}; +EBUnsigned wx = b.wrap(x); +EBUnsigned wy = b.wrap(y); +EBUnsigned result = (wx + wy - uint16_t(10)) / (wx - wy + uint16_t(1)); +``` + +The `result` above can be implicitly converted to `Value` type. + +In contrast, the code using `OpBuilder` to do the same task will have more lines +of code and less readablity: + +```C++ +OpBuilder builder = ...; +Value x = ...; +Value y = ...; +Location loc = ...; + +auto x_p_y = builder.create(loc, x, y); +auto v10 = builder.create(loc, 10, /*width*/16); +auto x_p_y_m10 = builder.create(loc, x_p_y, v10); +auto x_m_y = builder.create(loc, x, y); +auto v1 = builder.create(loc, 1, /*width*/16); +auto x_m_y_p1 = builder.create(loc, x_m_y, v1); +Value result = builder.create(loc, x_p_y_m10, x_m_y_p1); +``` + +[TOC] + +## Overall Design + +There are some observations on the C++ code for IR creation in MLIR transforms: + +1. Consecutive calls to `builder.create(loc, ...)` often use the same + `OpBuilder` and `Location`. Many mutations in the MLIR passes are to expand + an operation into a sequence of operations. So expanded operations will share + the same builder and the same location of the original operation. +2. There is currently no C++ operator overloading on MLIR's `Value` class. + Developers have to break a long arithmatical expression into calls to the + `create<..>` function. +3. It would be helpful if MLIR provides helper functions to convert C++ types + (like `uint16_t` and `OpFoldResult`) into `Value`. +4. C++ RAII and use of macros could be helpful for building + structured-control-flow IR (not just `scf` operations). + +Easy-build is designed to improve the `OpBuilder` in the above aspects. It is +also extendable for different dialects and operations - developers can extend +easy-builder for a new dialect with reasonable efforts. + +Easy-build provides `EBValue` class ("EB" here stands for "easy-build") as a +wrapper for MLIR's `Value` objects. `EBValue` also stores the reference to the +`OpBuilder` and `Location`. An `EBValue` is self-contained for creating new +operations based on it. This enables C++ operator overloading on `EBValue`. Note +that it is hard to implement operator overloading on MLIR's `Value` to build new +operation, because it lacks information of the `OpBuilder` and `Location` of the +new operation to create. + +## Design details + +Most of easy-build's APIs are defined in `mlir::easybuild` namespace. This +section will introduc the key data structures of easy-build. + +### EasyBuildState + +This class holds the "states" of an easy-builder. It contains the a `Location` +object, a reference to the `OpBuilder` and other configurations of an an +easy-builder. A shared-ptr to a `EasyBuildState` is attached to every non-empty +`EBValue`. Further creation of new operations based on a `EBValue` should use +the `OpBuilder` and `Location` in the referenced `EasyBuildState`. The newly +created `EBValue` should hold a shared-ptr to the same `EasyBuildState` of its +operands. + +```c++ +struct EasyBuildState { + OpBuilder &builder; + Location loc; + ... +}; +``` + +### EBValue + +This class is essentially a `mlir::Value` with shared-ptr to `EasyBuildState`. +`EBValue` is a general base class for any values and itself does not enable C++ +operator overloading for IR creation. However, developers can inherit this class +to restrict the `Value` to be held in a `EBValue` and enable some specific +IR-building utilities. In the example at the beginning of this document, a +subclass `EBUnsigned` is used to hold `Value` of "unsigned integer". The line +`EBUnsigned wx = b.wrap(x);` converts `x` of `Value` to +`EBUnsigned`. If `x`'s type is not compatible to `EBUnsigned`, a runtime +assertion failure may occur. Easy-build for `arith` dialects enables operator +overloads for `EBUnsigned` like: + +```c++ +EBUnsigned operator+(EBUnsigned a, EBUnsigned b) { + return EBUnsigned {a.builder, + a.builder->builder.template create(a.builder->loc, + a.v, b.v)}; +} +``` + +The created `EBUnsigned` should share the same `EasyBuildState` pointer of the +operands. + +An `EBValue` object can be implictly be converted to `Value`: + +```c++ +EBValue wrapped = ...; +Value v = wrapped; +``` + +Please refer to sections [Easy-build for arith dialect](#Easy-build-for-arith-dialect) +for the subclasses of `EBValue` for arith operations. See also +[Extending easy-build for dialects](#Extending-easy-build-for-dialects) for +extending `EBValue` for a new dialect. + +### EasyBuilder + +The `EasyBuilder` is a utility class for + +1. creating an initial `EasyBuildState` object +2. wrapping `Value`, C++ numerical values (e.g. `uint32_t`, `float`) or + `OpFoldResult` into `EBValue` or its subclasses, and setting the shared-ptr + `EasyBuildState` of the created values. +3. setting `Location` for the next created operation + +The use of easy-build usually starts from creating an EasyBuilder. The +constructor of it will internally create an `EasyBuildState` object with the +given `OpBuilder` and `Location`. + +#### Wrapping various values to EBValue + +To convert various types of C++ values to `EBValue` or its subclasses, +`EasyBuilder` provides a template function `EasyBuilder::wrap(V)` to convert +C++ type `V` into `T`, which is a subclass of `EBValue`. The result `EBValue` or +its subclasses's should hold a shared-ptr pointing to the `EasyBuildState` of +this `EasyBuilder`. `EasyBuilder::wrap` may introduce runtime type checking for +the input value (implementation provided by the class `T`). When the convertion +fails, an assertion failure may happen at the runtime. An example of such case +is when we try to wrap a `memref` typed `Value` to `EBUnsigned`, the convertion +should fail, because `memref` are not arithmetic values. + +`EasyBuilder` provides a similar function `EasyBuilder::wrapOrFail(V)` which +returns `FailureOr`. It has similar functionality of `wrap()`, except that it +returns `failure()` when the convertion fails, instead of triggering an runtime +abortion. + +```C++ +#include "mlir/Dialect/Arith/Utils/EasyBuild.h" + +EasyBuilder b {...}; +Value v = builder.create(...); +EBFloatPoint u1 = b.wrap(v); // OK +FailureOr u1 = b.wrapOrFail(v); +assert(failed(u1)); // convertion should fail +``` + +`EasyBuilder` overrides `operator()` to provide convenience converter for +general `Value` to `EBValue` and arithmetic C++ values to the corresponding +subclass of `EBValue`: + +```C++ +#include "mlir/Dialect/Arith/Utils/EasyBuild.h" + +EasyBuilder b {...}; +Value v = ...; +EBValue v1 = b(v); // wrap Value to base class EBValue +EBUnsigned u1 = b(uint32_t(2)); // creating arith.constant of i32 +EBFloatPoint u1 = b(2.0f); // creating arith.constant of f32 +``` + +#### Setting source location + +Users can set the `Location` to be used in the `OpBuilder::create` after a call +to `EasyBuilder::setLoc()`. New operations related to a `EasyBuildState` will be +created with the new `Location` set by `EasyBuilder::setLoc()`. The previously +created operations' location before calling `setLoc()` will not be changed. + +#### Creating operations using EBValues as inputs + +Developers can call the template member function `F(...)` of +`EasyBuilder` to create a new operation of type `TOp` and wrap the result to +type `TValue`, which is `EBValue` or its subclasses. This method is used to +generate general operations for `EBValue`s. The operation will be created with +the current `OpBuilder` and `Location` of the `EasyBuilder`. For example, to +create an `mydialect::MyOp` operation with given `EBValue` as operands and get +the single result value of the operation as `EBUnsigned`: + +```c++ +EasyBuilder b {...}; +EBValue v1 = ...; +EBUnsigned v2 = b.F(v1); +``` + +## Typical workflow for using easy-build + +To use easy-build, a developer may first include the easy-build header and +optionally include the header for the subclass of `EBValue` for a dialect. + +```C++ +#include "mlir/IR/EasyBuild.h" +#include "mlir/Dialect/Arith/Utils/EasyBuild.h" +``` + +Then in the code building the IR, create a `EasyBuilder` with an existing +`OpBuilder` and `Location`: + +```c++ +using namespace easybuild; +Operation* originOp = ...; +OpBuilder builder {originOp}; +Location loc = originOp->getLoc(); +EasyBuilder b {builder, loc}; +``` + +Wrap `Value` or other C++ values to `EBValue` or its subclasses: + +```c++ +auto input1 = b.wrap(originOp->getOperand(0)); +auto input2 = b.wrap(originOp->getOperand(1)); +``` + +Generate operations via the wrapped values. The insert point and `Location` is +defined by the `OpBuilder` inside of `EasyBuildState`. The results can be used +as `Value`: + +```c++ +Value result = input1 + input2; +``` + +## Easy-build for arith dialect + +Subclasses of `EBValue` have been defined for `arith` operations, including +`EBUnsigned`, `EBSigned` and `EBFloatPoint`. These subclasses can accept +`EasyBuilder::wrap()` of input values of types of corresponding scalar types, or +their vector or tensor type. `EBUnsigned` accepts scalar, vector or tensor of +unsigned or signless integer-or-index-typed `Value`. `EBUnsigned` accepts +scalar, vector or tensor of signed or signless integer-typed `Value`. +`EBFloatPoint` accepts scalar, vector or tensor of float-point-typed `Value`. + +Developers can also wrap C++ arithmetic types (e.g. `uint32_t`, `float`) to the +corresponding `EBUnsigned`, `EBSigned` or `EBFloatPoint` type, via +`EasyBuilder::operator()`. A call to such function will generate an +`arith.constant` operation at the current insertion point. + +Similarly, `EBUnsigned`, `EBSigned` and `EBFloatPoint` enables +`EasyBuilder::wrap()` to convert from `OpFoldResult`. + +```c++ +OpFoldResult f = ...; +auto input1 = b.wrap(f); +``` + +If `OpFoldResult` contains a `Value`, `wrap` will try to convert the +extracted value to `EBUnsigned`. If it contains a constant as `Attr`, +`wrap` will create an `arith.constant` based on the type of the +`Attr`. + +Some of the C++ operators are enabled for `EBUnsigned`, `EBSigned` and +`EBFloatPoint` classes, include arithmetic `+ - * / % `, logical `& | ^`, +integer-shifting `>> <<` and comparison `> >= < <= == !=`. Using these C++ +operators will create the corresponding `arith` operations at the current +`OpBuilder` in the `EasyBuildState` of the `EBValue`. Signed and Unsigned +integers are distinguished, so that they will emit different operations for the +arith operations that is sensitive to the signess, like `divsi` or `divui`. + +## Easy-build for general structured-control-flow + +TBD + +## Extending easy-build for dialects + +To extend easy-build for new dialects or operations, developers usually need to +create a new class to inherit the `EBValue` class and define utility helper +functions for that new class. The definition of a subclass of `EBValue` should +be operation-centric. That is, the developer of a subclass of `EBValue` should +consider which operations are designed to be applied on it, instead of +considering the data type of the `Value` first. For example, when adding support +for `arith` operations, we find that the operations of it can fall into three +categories: unsigned int, signed int and float point. Thus `EBUnsigned`, +`EBSigned` and `EBFloatPoint` classes are introduced. + +The developer needs to implement the `wrapOrFail` static member function in the +subclass, to enable converting values to it via `EasyBuilder::wrap<>()`. An +example for implementing a hypothesis subclass `EBMyFloatPoint` can be: + +```c++ +struct EBMyFloatPoint : EBValue { + static FailureOr wrapOrFail(const impl::StatePtr &state, + Value v) { + ... + } + static FailureOr wrapOrFail(const impl::StatePtr &state, + const OpFoldResult &v) { + ... + } + + using EBValue::EBValue; +}; +``` + +Developers can implement the utility functions to help to build the IR: + +```c++ +inline EBMyFloatPoint sin(EBMyFloatPoint input) { + std::shared_ptr state = input.builder; + OpBuilder& builder = state->builder; + return EBMyFloatPoint{ state, + builder.create(state->loc, input) }; +} + +inline EBMyFloatPoint operator+(EBMyFloatPoint a, EBMyFloatPoint b) { + std::shared_ptr state = a.builder; + OpBuilder& builder = state->builder; + return EBMyFloatPoint{ state, + builder.create(state->loc, a, b) }; +} +``` + diff --git a/include/gc-dialects/Arith/Utils/EasyBuild.h b/include/gc-dialects/Arith/Utils/EasyBuild.h new file mode 100644 index 000000000..15d421caa --- /dev/null +++ b/include/gc-dialects/Arith/Utils/EasyBuild.h @@ -0,0 +1,453 @@ +//===- EasyBuild.h - Easy Arith IR Builder utilities ------------*- C++ -*-===// +// +// 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 +// +//===----------------------------------------------------------------------===// +// +// This header file defines prototypes for various transformation utilities for +// the Arith dialect. These are not passes by themselves but are used +// either by passes, optimization sequences, or in turn by other transformation +// utilities. +// +//===----------------------------------------------------------------------===// + +#ifndef GC_DIALECT_ARITH_UTILS_EASYBUILD_H +#define GC_DIALECT_ARITH_UTILS_EASYBUILD_H +#include "mlir/Dialect/Arith/IR/Arith.h" +#include "mlir/IR/Builders.h" +#include "mlir/IR/EasyBuild.h" +#include +#include +#include + +namespace mlir { +namespace easybuild { + +namespace impl { + +template +struct ToFloatType {}; + +template <> +struct ToFloatType<4> { + using type = Float32Type; +}; +template <> +struct ToFloatType<8> { + using type = Float64Type; +}; + +inline Type getElementType(Value v) { + auto type = v.getType(); + if (type.isa() || type.isa()) { + type = type.cast().getElementType(); + } + return type; +} + +} // namespace impl + +struct EBUnsigned; + +struct EBArithValue : public EBValue { + template + static T toIndex(const impl::StatePtr &state, uint64_t v); + + template + static auto wrapOrFail(const impl::StatePtr &state, T &&v); + + template + static auto wrap(const impl::StatePtr &state, T &&v) { + auto ret = wrapOrFail(state, std::forward(v)); + if (failed(ret)) { + llvm_unreachable("Bad wrap"); + } + return *ret; + } + +protected: + using EBValue::EBValue; +}; + +struct EBUnsigned : public EBArithValue { + static FailureOr wrapOrFail(const impl::StatePtr &state, + Value v) { + auto type = impl::getElementType(v); + if (type.isUnsignedInteger() || type.isSignlessInteger() || + type.isIndex()) { + return EBUnsigned{state, v}; + } + return failure(); + } + static FailureOr wrapOrFail(const impl::StatePtr &state, + const OpFoldResult &v) { + if (v.is()) { + return wrapOrFail(state, v.get()); + } + auto attr = v.get(); + if (auto val = attr.dyn_cast()) { + if (val.getType().isIndex()) + return EBUnsigned{state, state->builder.create( + state->loc, val.getInt())}; + else + return EBUnsigned{state, state->builder.create( + state->loc, val.getInt(), val.getType())}; + } + return failure(); + } + friend struct EBArithValue; + friend struct OperatorHandlers; + +protected: + using EBArithValue::EBArithValue; +}; + +struct EBSigned : EBArithValue { + static FailureOr wrapOrFail(const impl::StatePtr &state, Value v) { + auto type = impl::getElementType(v); + if (type.isSignedInteger() || type.isSignlessInteger()) { + return EBSigned{state, v}; + } + return failure(); + } + static FailureOr wrapOrFail(const impl::StatePtr &state, + const OpFoldResult &v) { + if (v.is()) { + return wrapOrFail(state, v.get()); + } + auto attr = v.get(); + if (auto val = attr.dyn_cast()) + return EBSigned{state, state->builder.create( + state->loc, val.getInt(), val.getType())}; + return failure(); + } + friend struct EBArithValue; + friend struct OperatorHandlers; + +protected: + using EBArithValue::EBArithValue; +}; + +struct EBFloatPoint : EBArithValue { + static FailureOr wrapOrFail(const impl::StatePtr &state, + Value v) { + auto type = impl::getElementType(v); + if (type.isa()) { + return EBFloatPoint{state, v}; + } + return failure(); + } + static FailureOr wrapOrFail(const impl::StatePtr &state, + const OpFoldResult &v) { + if (v.is()) { + return wrapOrFail(state, v.get()); + } + auto attr = v.get(); + if (auto val = attr.dyn_cast()) + return EBFloatPoint{state, state->builder.create( + state->loc, val.getValue(), + val.getType().cast())}; + return failure(); + } + friend struct EBArithValue; + friend struct OperatorHandlers; + +protected: + using EBArithValue::EBArithValue; +}; + +template +inline T EBArithValue::toIndex(const impl::StatePtr &state, uint64_t v) { + return EBUnsigned{ + state, state->builder.create(state->loc, v)}; +} + +template +inline auto EBArithValue::wrapOrFail(const impl::StatePtr &state, T &&v) { + using DT = std::decay_t; + static_assert(std::is_arithmetic_v
, "Expecting arithmetic types"); + if constexpr (std::is_same_v) { + if (state->u64AsIndex) { + return FailureOr{toIndex(state, v)}; + } + } + + if constexpr (std::is_same_v) { + return FailureOr{ + EBUnsigned{state, state->builder.create( + state->loc, static_cast(v), 1)}}; + } else if constexpr (std::is_integral_v
) { + if constexpr (!std::is_signed_v
) { + return FailureOr{EBUnsigned{ + state, state->builder.create( + state->loc, static_cast(v), sizeof(T) * 8)}}; + } else { + return FailureOr{EBSigned{ + state, state->builder.create( + state->loc, static_cast(v), sizeof(T) * 8)}}; + } + } else { + using DType = typename impl::ToFloatType::type; + return FailureOr{ + EBFloatPoint{state, state->builder.create( + state->loc, APFloat{v}, + DType::get(state->builder.getContext()))}}; + } +} + +struct OperatorHandlers { + template + static V handleBinary(const V &a, const V &b) { + assert(a.builder == b.builder); + return {a.builder, + a.builder->builder.template create(a.builder->loc, a.v, b.v)}; + } + + template + static V handleBinaryConst(const V &a, const T2 &b) { + return handleBinary(a, EBArithValue::wrap(a.builder, b)); + } + + template + static V handleBinaryConst(const T2 &a, const V &b) { + return handleBinary(EBArithValue::wrap(b.builder, a), b); + } + + template + static EBUnsigned handleCmp(const V &a, const V &b, Pred predicate) { + assert(a.builder == b.builder); + return {a.builder, a.builder->builder.template create( + a.builder->loc, predicate, a.v, b.v)}; + } + + template + static EBUnsigned handleCmpConst(const V &a, const T2 &b, Pred predicate) { + return handleCmp(a, EBArithValue::wrap(a.builder, b), predicate); + } + + template + static EBUnsigned handleCmpConst(const T2 &a, const V &b, Pred predicate) { + return handleCmp(EBArithValue::wrap(b.builder, a), b, predicate); + } + + template + static T create(const impl::StatePtr &state, Args &&...v) { + return {state, + state->builder.create(state->loc, std::forward(v)...)}; + } +}; + +#define DEF_EASYBUILD_BINARY_OPERATOR_FOR_TYPE(OP, OPCLASS, TYPE) \ + inline TYPE operator OP(const TYPE &a, const TYPE &b) { \ + return OperatorHandlers::handleBinary(a, b); \ + } \ + template \ + inline TYPE operator OP(const TYPE &a, T b) { \ + return OperatorHandlers::handleBinaryConst(a, b); \ + } \ + template \ + inline TYPE operator OP(T a, const TYPE &b) { \ + return OperatorHandlers::handleBinaryConst(a, b); \ + } + +#define DEF_EASYBUILD_BINARY_OPERATOR(OP, SIGNED, UNSIGNED, FLOAT) \ + DEF_EASYBUILD_BINARY_OPERATOR_FOR_TYPE(OP, SIGNED, EBSigned) \ + DEF_EASYBUILD_BINARY_OPERATOR_FOR_TYPE(OP, UNSIGNED, EBUnsigned) \ + DEF_EASYBUILD_BINARY_OPERATOR_FOR_TYPE(OP, FLOAT, EBFloatPoint) + +DEF_EASYBUILD_BINARY_OPERATOR(+, arith::AddIOp, arith::AddIOp, arith::AddFOp) +DEF_EASYBUILD_BINARY_OPERATOR(-, arith::SubIOp, arith::SubIOp, arith::SubFOp) +DEF_EASYBUILD_BINARY_OPERATOR(*, arith::MulIOp, arith::MulIOp, arith::MulFOp) +DEF_EASYBUILD_BINARY_OPERATOR(/, arith::DivSIOp, arith::DivUIOp, arith::DivFOp) +DEF_EASYBUILD_BINARY_OPERATOR(%, arith::RemSIOp, arith::RemUIOp, arith::RemFOp) + +#undef DEF_EASYBUILD_BINARY_OPERATOR +#define DEF_EASYBUILD_BINARY_OPERATOR_FOR_INT(OP, SIGNED, UNSIGNED) \ + DEF_EASYBUILD_BINARY_OPERATOR_FOR_TYPE(OP, SIGNED, EBSigned) \ + DEF_EASYBUILD_BINARY_OPERATOR_FOR_TYPE(OP, UNSIGNED, EBUnsigned) + +DEF_EASYBUILD_BINARY_OPERATOR_FOR_INT(>>, arith::ShRSIOp, arith::ShRUIOp) +DEF_EASYBUILD_BINARY_OPERATOR_FOR_INT(<<, arith::ShLIOp, arith::ShLIOp) +DEF_EASYBUILD_BINARY_OPERATOR_FOR_INT(&, arith::AndIOp, arith::AndIOp) +DEF_EASYBUILD_BINARY_OPERATOR_FOR_INT(|, arith::OrIOp, arith::OrIOp) +DEF_EASYBUILD_BINARY_OPERATOR_FOR_INT(^, arith::XOrIOp, arith::XOrIOp) + +#undef DEF_EASYBUILD_BINARY_OPERATOR_FOR_INT +#undef DEF_EASYBUILD_BINARY_OPERATOR_FOR_TYPE + +inline EBFloatPoint operator-(const EBFloatPoint &a) { + return OperatorHandlers::create(a.builder, a.v); +} + +#define DEF_EASYBUILD_CMP_OPERATOR(OP, OPCLASS, TYPE, PRED) \ + EBUnsigned operator OP(const TYPE &a, const TYPE &b) { \ + return OperatorHandlers::handleCmp(a, b, PRED); \ + } \ + template \ + EBUnsigned operator OP(const TYPE &a, T b) { \ + return OperatorHandlers::handleCmpConst(a, b, PRED); \ + } \ + template \ + EBUnsigned operator OP(T a, const TYPE &b) { \ + return OperatorHandlers::handleCmpConst(a, b, PRED); \ + } + +DEF_EASYBUILD_CMP_OPERATOR(<, arith::CmpIOp, EBUnsigned, + arith::CmpIPredicate::ult) +DEF_EASYBUILD_CMP_OPERATOR(<=, arith::CmpIOp, EBUnsigned, + arith::CmpIPredicate::ule) +DEF_EASYBUILD_CMP_OPERATOR(>, arith::CmpIOp, EBUnsigned, + arith::CmpIPredicate::ugt) +DEF_EASYBUILD_CMP_OPERATOR(>=, arith::CmpIOp, EBUnsigned, + arith::CmpIPredicate::uge) +DEF_EASYBUILD_CMP_OPERATOR(==, arith::CmpIOp, EBUnsigned, + arith::CmpIPredicate::eq) +DEF_EASYBUILD_CMP_OPERATOR(!=, arith::CmpIOp, EBUnsigned, + arith::CmpIPredicate::ne) + +DEF_EASYBUILD_CMP_OPERATOR(<, arith::CmpIOp, EBSigned, + arith::CmpIPredicate::slt) +DEF_EASYBUILD_CMP_OPERATOR(<=, arith::CmpIOp, EBSigned, + arith::CmpIPredicate::sle) +DEF_EASYBUILD_CMP_OPERATOR(>, arith::CmpIOp, EBSigned, + arith::CmpIPredicate::sgt) +DEF_EASYBUILD_CMP_OPERATOR(>=, arith::CmpIOp, EBSigned, + arith::CmpIPredicate::sge) +DEF_EASYBUILD_CMP_OPERATOR(==, arith::CmpIOp, EBSigned, + arith::CmpIPredicate::eq) +DEF_EASYBUILD_CMP_OPERATOR(!=, arith::CmpIOp, EBSigned, + arith::CmpIPredicate::ne) + +DEF_EASYBUILD_CMP_OPERATOR(<, arith::CmpFOp, EBFloatPoint, + arith::CmpFPredicate::OLT) +DEF_EASYBUILD_CMP_OPERATOR(<=, arith::CmpFOp, EBFloatPoint, + arith::CmpFPredicate::OLE) +DEF_EASYBUILD_CMP_OPERATOR(>, arith::CmpFOp, EBFloatPoint, + arith::CmpFPredicate::OGT) +DEF_EASYBUILD_CMP_OPERATOR(>=, arith::CmpFOp, EBFloatPoint, + arith::CmpFPredicate::OGE) +DEF_EASYBUILD_CMP_OPERATOR(==, arith::CmpFOp, EBFloatPoint, + arith::CmpFPredicate::OEQ) +DEF_EASYBUILD_CMP_OPERATOR(!=, arith::CmpFOp, EBFloatPoint, + arith::CmpFPredicate::ONE) + +#undef DEF_EASYBUILD_CMP_OPERATOR + +namespace arithops { +inline EBFloatPoint castIntToFP(Type type, const EBSigned &v) { + return OperatorHandlers::create(v.builder, + type, v); +} + +inline EBFloatPoint castIntToFP(Type type, const EBUnsigned &v) { + return OperatorHandlers::create(v.builder, + type, v); +} + +template +inline T castFPToInt(const EBFloatPoint &v) { + if constexpr (std::is_same_v) { + return OperatorHandlers::create(v.builder, v); + } else { + static_assert(std::is_same_v, + "Expecting EBUnsigned or EBSigned"); + return OperatorHandlers::create(v.builder, v); + } +} + +inline EBSigned ceildiv(const EBSigned &a, const EBSigned &b) { + return OperatorHandlers::create(a.builder, a, + b); +} + +inline EBUnsigned ceildiv(const EBUnsigned &a, const EBUnsigned &b) { + return OperatorHandlers::create(a.builder, a, + b); +} + +inline EBSigned floordiv(const EBSigned &a, const EBSigned &b) { + return OperatorHandlers::create(a.builder, a, + b); +} + +inline EBSigned extend(Type type, const EBSigned &a) { + return OperatorHandlers::create(a.builder, type, a); +} + +inline EBUnsigned extend(Type type, const EBUnsigned &a) { + return OperatorHandlers::create(a.builder, type, + a); +} + +inline EBFloatPoint extend(Type type, const EBFloatPoint &a) { + return OperatorHandlers::create(a.builder, type, + a); +} + +inline EBSigned trunc(Type type, const EBSigned &a) { + return OperatorHandlers::create(a.builder, type, + a); +} + +inline EBFloatPoint trunc(Type type, const EBFloatPoint &a) { + return OperatorHandlers::create(a.builder, + type, a); +} + +template +inline T select(const EBUnsigned &pred, const T &trueValue, + const T &falseValue) { + static_assert(std::is_base_of_v, + "Expecting T to be a subclass of EBArithValue"); + return OperatorHandlers::create(pred.builder, pred, + trueValue, falseValue); +} + +template +inline TyTo bitcast(Type type, const TyFrom &v) { + return OperatorHandlers::create(v.builder, type, v); +} + +inline EBSigned min(const EBSigned &a, const EBSigned &b) { + return OperatorHandlers::create(a.builder, a, b); +} + +inline EBSigned max(const EBSigned &a, const EBSigned &b) { + return OperatorHandlers::create(a.builder, a, b); +} + +inline EBUnsigned min(const EBUnsigned &a, const EBUnsigned &b) { + return OperatorHandlers::create(a.builder, a, b); +} + +inline EBUnsigned max(const EBUnsigned &a, const EBUnsigned &b) { + return OperatorHandlers::create(a.builder, a, b); +} + +inline EBFloatPoint minnum(const EBFloatPoint &a, const EBFloatPoint &b) { + return OperatorHandlers::create(a.builder, a, + b); +} + +inline EBFloatPoint maxnum(const EBFloatPoint &a, const EBFloatPoint &b) { + return OperatorHandlers::create(a.builder, a, + b); +} + +inline EBFloatPoint minimum(const EBFloatPoint &a, const EBFloatPoint &b) { + return OperatorHandlers::create(a.builder, a, + b); +} + +inline EBFloatPoint maximum(const EBFloatPoint &a, const EBFloatPoint &b) { + return OperatorHandlers::create(a.builder, a, + b); +} + +} // namespace arithops + +} // namespace easybuild +} // namespace mlir +#endif From 74f943cd6f956f8a78827fb537fe9e4aebb0b441 Mon Sep 17 00:00:00 2001 From: "Mei, Yijie" Date: Thu, 9 May 2024 13:43:09 +0800 Subject: [PATCH 4/7] re-struct the directories --- include/CMakeLists.txt | 2 +- include/gc-dialects/Linalgx/CMakeLists.txt | 3 --- include/gc-dialects/Microkernel/CMakeLists.txt | 3 --- include/gc-dialects/OnednnGraph/CMakeLists.txt | 3 --- include/gc/CMakeLists.txt | 2 ++ include/gc/Dialects/CMakeLists.txt | 3 +++ include/gc/Dialects/Linalgx/CMakeLists.txt | 3 +++ .../{gc-dialects => gc/Dialects}/Linalgx/LinalgxDialect.h | 2 +- .../{gc-dialects => gc/Dialects}/Linalgx/LinalgxDialect.td | 0 include/{gc-dialects => gc/Dialects}/Linalgx/LinalgxOps.h | 2 +- include/{gc-dialects => gc/Dialects}/Linalgx/LinalgxOps.td | 0 include/gc/Dialects/Microkernel/CMakeLists.txt | 3 +++ .../Dialects}/Microkernel/MicrokernelDialect.h | 2 +- .../Dialects}/Microkernel/MicrokernelDialect.td | 0 .../Dialects}/Microkernel/MicrokernelOps.h | 2 +- .../Dialects}/Microkernel/MicrokernelOps.td | 0 include/gc/Dialects/OnednnGraph/CMakeLists.txt | 3 +++ .../Dialects}/OnednnGraph/OnednnGraphDialect.h | 2 +- .../Dialects}/OnednnGraph/OnednnGraphDialect.td | 0 .../Dialects}/OnednnGraph/OnednnGraphOps.h | 2 +- .../Dialects}/OnednnGraph/OnednnGraphOps.td | 0 include/{gc-dialects => gc/Transforms}/CMakeLists.txt | 4 ---- include/{gc-dialects => gc/Transforms}/Passes.h | 4 ++-- include/{gc-dialects => gc/Transforms}/Passes.td | 0 lib/CMakeLists.txt | 2 +- lib/gc/CMakeLists.txt | 2 ++ lib/{gc-dialects => gc/Dialects}/CMakeLists.txt | 2 -- lib/{gc-dialects => gc/Dialects}/Linalgx/CMakeLists.txt | 2 +- lib/{gc-dialects => gc/Dialects}/Linalgx/LinalgxDialect.cpp | 6 +++--- lib/{gc-dialects => gc/Dialects}/Linalgx/LinalgxOps.cpp | 6 +++--- lib/{gc-dialects => gc/Dialects}/Microkernel/CMakeLists.txt | 2 +- .../Dialects}/Microkernel/MicrokernelDialect.cpp | 6 +++--- .../Dialects}/Microkernel/MicrokernelOps.cpp | 6 +++--- lib/{gc-dialects => gc/Dialects}/OnednnGraph/CMakeLists.txt | 2 +- .../Dialects}/OnednnGraph/OnednnGraphDialect.cpp | 6 +++--- .../Dialects}/OnednnGraph/OnednnGraphOps.cpp | 6 +++--- lib/{gc-dialects => gc}/Transforms/CMakeLists.txt | 2 +- lib/{gc-dialects => gc}/Transforms/TileNamed.cpp | 4 ++-- src/gc-opt.cpp | 2 +- 39 files changed, 51 insertions(+), 50 deletions(-) delete mode 100644 include/gc-dialects/Linalgx/CMakeLists.txt delete mode 100644 include/gc-dialects/Microkernel/CMakeLists.txt delete mode 100644 include/gc-dialects/OnednnGraph/CMakeLists.txt create mode 100644 include/gc/CMakeLists.txt create mode 100644 include/gc/Dialects/CMakeLists.txt create mode 100644 include/gc/Dialects/Linalgx/CMakeLists.txt rename include/{gc-dialects => gc/Dialects}/Linalgx/LinalgxDialect.h (90%) rename include/{gc-dialects => gc/Dialects}/Linalgx/LinalgxDialect.td (100%) rename include/{gc-dialects => gc/Dialects}/Linalgx/LinalgxOps.h (91%) rename include/{gc-dialects => gc/Dialects}/Linalgx/LinalgxOps.td (100%) create mode 100644 include/gc/Dialects/Microkernel/CMakeLists.txt rename include/{gc-dialects => gc/Dialects}/Microkernel/MicrokernelDialect.h (89%) rename include/{gc-dialects => gc/Dialects}/Microkernel/MicrokernelDialect.td (100%) rename include/{gc-dialects => gc/Dialects}/Microkernel/MicrokernelOps.h (90%) rename include/{gc-dialects => gc/Dialects}/Microkernel/MicrokernelOps.td (100%) create mode 100644 include/gc/Dialects/OnednnGraph/CMakeLists.txt rename include/{gc-dialects => gc/Dialects}/OnednnGraph/OnednnGraphDialect.h (89%) rename include/{gc-dialects => gc/Dialects}/OnednnGraph/OnednnGraphDialect.td (100%) rename include/{gc-dialects => gc/Dialects}/OnednnGraph/OnednnGraphOps.h (90%) rename include/{gc-dialects => gc/Dialects}/OnednnGraph/OnednnGraphOps.td (100%) rename include/{gc-dialects => gc/Transforms}/CMakeLists.txt (71%) rename include/{gc-dialects => gc/Transforms}/Passes.h (88%) rename include/{gc-dialects => gc/Transforms}/Passes.td (100%) create mode 100644 lib/gc/CMakeLists.txt rename lib/{gc-dialects => gc/Dialects}/CMakeLists.txt (74%) rename lib/{gc-dialects => gc/Dialects}/Linalgx/CMakeLists.txt (77%) rename lib/{gc-dialects => gc/Dialects}/Linalgx/LinalgxDialect.cpp (78%) rename lib/{gc-dialects => gc/Dialects}/Linalgx/LinalgxOps.cpp (75%) rename lib/{gc-dialects => gc/Dialects}/Microkernel/CMakeLists.txt (78%) rename lib/{gc-dialects => gc/Dialects}/Microkernel/MicrokernelDialect.cpp (75%) rename lib/{gc-dialects => gc/Dialects}/Microkernel/MicrokernelOps.cpp (72%) rename lib/{gc-dialects => gc/Dialects}/OnednnGraph/CMakeLists.txt (78%) rename lib/{gc-dialects => gc/Dialects}/OnednnGraph/OnednnGraphDialect.cpp (75%) rename lib/{gc-dialects => gc/Dialects}/OnednnGraph/OnednnGraphOps.cpp (72%) rename lib/{gc-dialects => gc}/Transforms/CMakeLists.txt (84%) rename lib/{gc-dialects => gc}/Transforms/TileNamed.cpp (95%) diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt index 13ce82681..49854749f 100644 --- a/include/CMakeLists.txt +++ b/include/CMakeLists.txt @@ -1 +1 @@ -add_subdirectory(gc-dialects) \ No newline at end of file +add_subdirectory(gc) \ No newline at end of file diff --git a/include/gc-dialects/Linalgx/CMakeLists.txt b/include/gc-dialects/Linalgx/CMakeLists.txt deleted file mode 100644 index c24886bef..000000000 --- a/include/gc-dialects/Linalgx/CMakeLists.txt +++ /dev/null @@ -1,3 +0,0 @@ -add_mlir_dialect(LinalgxOps linalgx) -add_mlir_doc(LinalgxOps LinalgxOps gc-dialects/Linalgx/ -gen-op-doc) -add_mlir_doc(LinalgxDialect LinalgxDialect gc-dialects/Linalgx/ -gen-dialect-doc) diff --git a/include/gc-dialects/Microkernel/CMakeLists.txt b/include/gc-dialects/Microkernel/CMakeLists.txt deleted file mode 100644 index 41c21b22d..000000000 --- a/include/gc-dialects/Microkernel/CMakeLists.txt +++ /dev/null @@ -1,3 +0,0 @@ -add_mlir_dialect(MicrokernelOps microkernel) -add_mlir_doc(MicrokernelOps MicrokernelOps gc-dialects/Microkernel/ -gen-op-doc) -add_mlir_doc(MicrokernelDialect MicrokernelDialect gc-dialects/Microkernel/ -gen-dialect-doc) diff --git a/include/gc-dialects/OnednnGraph/CMakeLists.txt b/include/gc-dialects/OnednnGraph/CMakeLists.txt deleted file mode 100644 index 2e67f86f1..000000000 --- a/include/gc-dialects/OnednnGraph/CMakeLists.txt +++ /dev/null @@ -1,3 +0,0 @@ -add_mlir_dialect(OnednnGraphOps onednn_graph) -add_mlir_doc(OnednnGraphOps OnednnGraphOps gc-dialects/OnednnGraph/ -gen-op-doc) -add_mlir_doc(OnednnGraphDialect OnednnGraphDialect gc-dialects/OnednnGraph/ -gen-dialect-doc) diff --git a/include/gc/CMakeLists.txt b/include/gc/CMakeLists.txt new file mode 100644 index 000000000..fed04555e --- /dev/null +++ b/include/gc/CMakeLists.txt @@ -0,0 +1,2 @@ +add_subdirectory(Dialects) +add_subdirectory(Transforms) \ No newline at end of file diff --git a/include/gc/Dialects/CMakeLists.txt b/include/gc/Dialects/CMakeLists.txt new file mode 100644 index 000000000..ffeda0aa7 --- /dev/null +++ b/include/gc/Dialects/CMakeLists.txt @@ -0,0 +1,3 @@ +add_subdirectory(OnednnGraph) +add_subdirectory(Microkernel) +add_subdirectory(Linalgx) \ No newline at end of file diff --git a/include/gc/Dialects/Linalgx/CMakeLists.txt b/include/gc/Dialects/Linalgx/CMakeLists.txt new file mode 100644 index 000000000..e7b096056 --- /dev/null +++ b/include/gc/Dialects/Linalgx/CMakeLists.txt @@ -0,0 +1,3 @@ +add_mlir_dialect(LinalgxOps linalgx) +add_mlir_doc(LinalgxOps LinalgxOps gc/Dialects/Linalgx/ -gen-op-doc) +add_mlir_doc(LinalgxDialect LinalgxDialect gc/Dialects/Linalgx/ -gen-dialect-doc) diff --git a/include/gc-dialects/Linalgx/LinalgxDialect.h b/include/gc/Dialects/Linalgx/LinalgxDialect.h similarity index 90% rename from include/gc-dialects/Linalgx/LinalgxDialect.h rename to include/gc/Dialects/Linalgx/LinalgxDialect.h index 6a2f14177..9479cfbd5 100644 --- a/include/gc-dialects/Linalgx/LinalgxDialect.h +++ b/include/gc/Dialects/Linalgx/LinalgxDialect.h @@ -11,6 +11,6 @@ #include "mlir/IR/Dialect.h" -#include "gc-dialects/Linalgx/LinalgxOpsDialect.h.inc" +#include "gc/Dialects/Linalgx/LinalgxOpsDialect.h.inc" #endif // GC_DIALECTS_LINALGXDIALECT_H diff --git a/include/gc-dialects/Linalgx/LinalgxDialect.td b/include/gc/Dialects/Linalgx/LinalgxDialect.td similarity index 100% rename from include/gc-dialects/Linalgx/LinalgxDialect.td rename to include/gc/Dialects/Linalgx/LinalgxDialect.td diff --git a/include/gc-dialects/Linalgx/LinalgxOps.h b/include/gc/Dialects/Linalgx/LinalgxOps.h similarity index 91% rename from include/gc-dialects/Linalgx/LinalgxOps.h rename to include/gc/Dialects/Linalgx/LinalgxOps.h index c6a5c164d..ef6ba751d 100644 --- a/include/gc-dialects/Linalgx/LinalgxOps.h +++ b/include/gc/Dialects/Linalgx/LinalgxOps.h @@ -12,6 +12,6 @@ #include "mlir/IR/OpDefinition.h" #define GET_OP_CLASSES -#include "gc-dialects/Linalgx/LinalgxOps.h.inc" +#include "gc/Dialects/Linalgx/LinalgxOps.h.inc" #endif // GC_DIALECTS_LINALGXOPS_H diff --git a/include/gc-dialects/Linalgx/LinalgxOps.td b/include/gc/Dialects/Linalgx/LinalgxOps.td similarity index 100% rename from include/gc-dialects/Linalgx/LinalgxOps.td rename to include/gc/Dialects/Linalgx/LinalgxOps.td diff --git a/include/gc/Dialects/Microkernel/CMakeLists.txt b/include/gc/Dialects/Microkernel/CMakeLists.txt new file mode 100644 index 000000000..908da1295 --- /dev/null +++ b/include/gc/Dialects/Microkernel/CMakeLists.txt @@ -0,0 +1,3 @@ +add_mlir_dialect(MicrokernelOps microkernel) +add_mlir_doc(MicrokernelOps MicrokernelOps gc/Dialects/Microkernel/ -gen-op-doc) +add_mlir_doc(MicrokernelDialect MicrokernelDialect gc/Dialects/Microkernel/ -gen-dialect-doc) diff --git a/include/gc-dialects/Microkernel/MicrokernelDialect.h b/include/gc/Dialects/Microkernel/MicrokernelDialect.h similarity index 89% rename from include/gc-dialects/Microkernel/MicrokernelDialect.h rename to include/gc/Dialects/Microkernel/MicrokernelDialect.h index 0401e57b6..efbbeb9ce 100644 --- a/include/gc-dialects/Microkernel/MicrokernelDialect.h +++ b/include/gc/Dialects/Microkernel/MicrokernelDialect.h @@ -11,6 +11,6 @@ #include "mlir/IR/Dialect.h" -#include "gc-dialects/Microkernel/MicrokernelOpsDialect.h.inc" +#include "gc/Dialects/Microkernel/MicrokernelOpsDialect.h.inc" #endif // GC_DIALECTS_MICROKERNELDIALECT_H diff --git a/include/gc-dialects/Microkernel/MicrokernelDialect.td b/include/gc/Dialects/Microkernel/MicrokernelDialect.td similarity index 100% rename from include/gc-dialects/Microkernel/MicrokernelDialect.td rename to include/gc/Dialects/Microkernel/MicrokernelDialect.td diff --git a/include/gc-dialects/Microkernel/MicrokernelOps.h b/include/gc/Dialects/Microkernel/MicrokernelOps.h similarity index 90% rename from include/gc-dialects/Microkernel/MicrokernelOps.h rename to include/gc/Dialects/Microkernel/MicrokernelOps.h index 517d0d6f7..cab3f725a 100644 --- a/include/gc-dialects/Microkernel/MicrokernelOps.h +++ b/include/gc/Dialects/Microkernel/MicrokernelOps.h @@ -12,6 +12,6 @@ #include "mlir/IR/OpDefinition.h" #define GET_OP_CLASSES -#include "gc-dialects/Microkernel/MicrokernelOps.h.inc" +#include "gc/Dialects/Microkernel/MicrokernelOps.h.inc" #endif // GC_DIALECTS_MICROKERNELOPS_H diff --git a/include/gc-dialects/Microkernel/MicrokernelOps.td b/include/gc/Dialects/Microkernel/MicrokernelOps.td similarity index 100% rename from include/gc-dialects/Microkernel/MicrokernelOps.td rename to include/gc/Dialects/Microkernel/MicrokernelOps.td diff --git a/include/gc/Dialects/OnednnGraph/CMakeLists.txt b/include/gc/Dialects/OnednnGraph/CMakeLists.txt new file mode 100644 index 000000000..9923af336 --- /dev/null +++ b/include/gc/Dialects/OnednnGraph/CMakeLists.txt @@ -0,0 +1,3 @@ +add_mlir_dialect(OnednnGraphOps onednn_graph) +add_mlir_doc(OnednnGraphOps OnednnGraphOps gc/Dialects/OnednnGraph/ -gen-op-doc) +add_mlir_doc(OnednnGraphDialect OnednnGraphDialect gc/Dialects/OnednnGraph/ -gen-dialect-doc) diff --git a/include/gc-dialects/OnednnGraph/OnednnGraphDialect.h b/include/gc/Dialects/OnednnGraph/OnednnGraphDialect.h similarity index 89% rename from include/gc-dialects/OnednnGraph/OnednnGraphDialect.h rename to include/gc/Dialects/OnednnGraph/OnednnGraphDialect.h index d016f430e..5f9ca3a17 100644 --- a/include/gc-dialects/OnednnGraph/OnednnGraphDialect.h +++ b/include/gc/Dialects/OnednnGraph/OnednnGraphDialect.h @@ -11,6 +11,6 @@ #include "mlir/IR/Dialect.h" -#include "gc-dialects/OnednnGraph/OnednnGraphOpsDialect.h.inc" +#include "gc/Dialects/OnednnGraph/OnednnGraphOpsDialect.h.inc" #endif // GC_DIALECTS_ONEDNNGRAPHDIALECT_H diff --git a/include/gc-dialects/OnednnGraph/OnednnGraphDialect.td b/include/gc/Dialects/OnednnGraph/OnednnGraphDialect.td similarity index 100% rename from include/gc-dialects/OnednnGraph/OnednnGraphDialect.td rename to include/gc/Dialects/OnednnGraph/OnednnGraphDialect.td diff --git a/include/gc-dialects/OnednnGraph/OnednnGraphOps.h b/include/gc/Dialects/OnednnGraph/OnednnGraphOps.h similarity index 90% rename from include/gc-dialects/OnednnGraph/OnednnGraphOps.h rename to include/gc/Dialects/OnednnGraph/OnednnGraphOps.h index dbbbece31..71f56ff9a 100644 --- a/include/gc-dialects/OnednnGraph/OnednnGraphOps.h +++ b/include/gc/Dialects/OnednnGraph/OnednnGraphOps.h @@ -12,6 +12,6 @@ #include "mlir/IR/OpDefinition.h" #define GET_OP_CLASSES -#include "gc-dialects/OnednnGraph/OnednnGraphOps.h.inc" +#include "gc/Dialects/OnednnGraph/OnednnGraphOps.h.inc" #endif // GC_DIALECTS_ONEDNNGRAPHOPS_H diff --git a/include/gc-dialects/OnednnGraph/OnednnGraphOps.td b/include/gc/Dialects/OnednnGraph/OnednnGraphOps.td similarity index 100% rename from include/gc-dialects/OnednnGraph/OnednnGraphOps.td rename to include/gc/Dialects/OnednnGraph/OnednnGraphOps.td diff --git a/include/gc-dialects/CMakeLists.txt b/include/gc/Transforms/CMakeLists.txt similarity index 71% rename from include/gc-dialects/CMakeLists.txt rename to include/gc/Transforms/CMakeLists.txt index 065525ff2..190e6ce75 100644 --- a/include/gc-dialects/CMakeLists.txt +++ b/include/gc/Transforms/CMakeLists.txt @@ -1,7 +1,3 @@ -add_subdirectory(OnednnGraph) -add_subdirectory(Microkernel) -add_subdirectory(Linalgx) - set(LLVM_TARGET_DEFINITIONS Passes.td) mlir_tablegen(Passes.h.inc -gen-pass-decls -name GraphCompiler) add_public_tablegen_target(GraphCompilerPassIncGen) diff --git a/include/gc-dialects/Passes.h b/include/gc/Transforms/Passes.h similarity index 88% rename from include/gc-dialects/Passes.h rename to include/gc/Transforms/Passes.h index 13ee8b443..243a6f4f6 100644 --- a/include/gc-dialects/Passes.h +++ b/include/gc/Transforms/Passes.h @@ -15,10 +15,10 @@ namespace mlir { namespace gc { #define GEN_PASS_DECL -#include "gc-dialects/Passes.h.inc" +#include "gc/Transforms/Passes.h.inc" #define GEN_PASS_REGISTRATION -#include "gc-dialects/Passes.h.inc" +#include "gc/Transforms/Passes.h.inc" } // namespace gc } // namespace mlir diff --git a/include/gc-dialects/Passes.td b/include/gc/Transforms/Passes.td similarity index 100% rename from include/gc-dialects/Passes.td rename to include/gc/Transforms/Passes.td diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 13ce82681..49854749f 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -1 +1 @@ -add_subdirectory(gc-dialects) \ No newline at end of file +add_subdirectory(gc) \ No newline at end of file diff --git a/lib/gc/CMakeLists.txt b/lib/gc/CMakeLists.txt new file mode 100644 index 000000000..fed04555e --- /dev/null +++ b/lib/gc/CMakeLists.txt @@ -0,0 +1,2 @@ +add_subdirectory(Dialects) +add_subdirectory(Transforms) \ No newline at end of file diff --git a/lib/gc-dialects/CMakeLists.txt b/lib/gc/Dialects/CMakeLists.txt similarity index 74% rename from lib/gc-dialects/CMakeLists.txt rename to lib/gc/Dialects/CMakeLists.txt index 8ecd77d06..a880ff2ed 100644 --- a/lib/gc-dialects/CMakeLists.txt +++ b/lib/gc/Dialects/CMakeLists.txt @@ -1,5 +1,3 @@ add_subdirectory(Linalgx) add_subdirectory(Microkernel) add_subdirectory(OnednnGraph) - -add_subdirectory(Transforms) diff --git a/lib/gc-dialects/Linalgx/CMakeLists.txt b/lib/gc/Dialects/Linalgx/CMakeLists.txt similarity index 77% rename from lib/gc-dialects/Linalgx/CMakeLists.txt rename to lib/gc/Dialects/Linalgx/CMakeLists.txt index 427d7cbed..6c86d6bc3 100644 --- a/lib/gc-dialects/Linalgx/CMakeLists.txt +++ b/lib/gc/Dialects/Linalgx/CMakeLists.txt @@ -3,7 +3,7 @@ add_mlir_dialect_library(MLIRLinalgx LinalgxOps.cpp ADDITIONAL_HEADER_DIRS - ${PROJECT_SOURCE_DIR}/include/gc-dialects/Linalgx + ${PROJECT_SOURCE_DIR}/include/gc/Dialects/Linalgx DEPENDS MLIRLinalgxOpsIncGen diff --git a/lib/gc-dialects/Linalgx/LinalgxDialect.cpp b/lib/gc/Dialects/Linalgx/LinalgxDialect.cpp similarity index 78% rename from lib/gc-dialects/Linalgx/LinalgxDialect.cpp rename to lib/gc/Dialects/Linalgx/LinalgxDialect.cpp index 47b66de85..def676325 100644 --- a/lib/gc-dialects/Linalgx/LinalgxDialect.cpp +++ b/lib/gc/Dialects/Linalgx/LinalgxDialect.cpp @@ -6,8 +6,8 @@ // //===----------------------------------------------------------------------===// -#include "gc-dialects/Linalgx/LinalgxDialect.h" -#include "gc-dialects/Linalgx/LinalgxOps.h" +#include "gc/Dialects/Linalgx/LinalgxDialect.h" +#include "gc/Dialects/Linalgx/LinalgxOps.h" using namespace mlir; using namespace mlir::linalgx; @@ -15,6 +15,6 @@ using namespace mlir::linalgx; void LinalgxDialect::initialize() { addOperations< #define GET_OP_LIST -#include "gc-dialects/Linalgx/LinalgxOps.cpp.inc" +#include "gc/Dialects/Linalgx/LinalgxOps.cpp.inc" >(); } diff --git a/lib/gc-dialects/Linalgx/LinalgxOps.cpp b/lib/gc/Dialects/Linalgx/LinalgxOps.cpp similarity index 75% rename from lib/gc-dialects/Linalgx/LinalgxOps.cpp rename to lib/gc/Dialects/Linalgx/LinalgxOps.cpp index cbc83d4a4..f485838c7 100644 --- a/lib/gc-dialects/Linalgx/LinalgxOps.cpp +++ b/lib/gc/Dialects/Linalgx/LinalgxOps.cpp @@ -6,9 +6,9 @@ // //===----------------------------------------------------------------------===// -#include "gc-dialects/Linalgx/LinalgxOps.h" -#include "gc-dialects/Linalgx/LinalgxDialect.h" +#include "gc/Dialects/Linalgx/LinalgxOps.h" +#include "gc/Dialects/Linalgx/LinalgxDialect.h" #include "mlir/IR/OpImplementation.h" #define GET_OP_CLASSES -#include "gc-dialects/Linalgx/LinalgxOps.cpp.inc" +#include "gc/Dialects/Linalgx/LinalgxOps.cpp.inc" diff --git a/lib/gc-dialects/Microkernel/CMakeLists.txt b/lib/gc/Dialects/Microkernel/CMakeLists.txt similarity index 78% rename from lib/gc-dialects/Microkernel/CMakeLists.txt rename to lib/gc/Dialects/Microkernel/CMakeLists.txt index 8534d346c..68f2977ef 100644 --- a/lib/gc-dialects/Microkernel/CMakeLists.txt +++ b/lib/gc/Dialects/Microkernel/CMakeLists.txt @@ -3,7 +3,7 @@ add_mlir_dialect_library(MLIRMicrokernel MicrokernelOps.cpp ADDITIONAL_HEADER_DIRS - ${PROJECT_SOURCE_DIR}/include/gc-dialects/Microkernel + ${PROJECT_SOURCE_DIR}/include/gc/Dialects/Microkernel DEPENDS MLIRMicrokernelOpsIncGen diff --git a/lib/gc-dialects/Microkernel/MicrokernelDialect.cpp b/lib/gc/Dialects/Microkernel/MicrokernelDialect.cpp similarity index 75% rename from lib/gc-dialects/Microkernel/MicrokernelDialect.cpp rename to lib/gc/Dialects/Microkernel/MicrokernelDialect.cpp index c4024b012..d785bc94c 100644 --- a/lib/gc-dialects/Microkernel/MicrokernelDialect.cpp +++ b/lib/gc/Dialects/Microkernel/MicrokernelDialect.cpp @@ -6,8 +6,8 @@ // //===----------------------------------------------------------------------===// -#include "gc-dialects/Microkernel/MicrokernelDialect.h" -#include "gc-dialects/Microkernel/MicrokernelOps.h" +#include "gc/Dialects/Microkernel/MicrokernelDialect.h" +#include "gc/Dialects/Microkernel/MicrokernelOps.h" using namespace mlir; using namespace mlir::microkernel; @@ -15,6 +15,6 @@ using namespace mlir::microkernel; void MicrokernelDialect::initialize() { addOperations< #define GET_OP_LIST -#include "gc-dialects/Microkernel/MicrokernelOps.cpp.inc" +#include "gc/Dialects/Microkernel/MicrokernelOps.cpp.inc" >(); } diff --git a/lib/gc-dialects/Microkernel/MicrokernelOps.cpp b/lib/gc/Dialects/Microkernel/MicrokernelOps.cpp similarity index 72% rename from lib/gc-dialects/Microkernel/MicrokernelOps.cpp rename to lib/gc/Dialects/Microkernel/MicrokernelOps.cpp index c56ed239c..f38024413 100644 --- a/lib/gc-dialects/Microkernel/MicrokernelOps.cpp +++ b/lib/gc/Dialects/Microkernel/MicrokernelOps.cpp @@ -6,9 +6,9 @@ // //===----------------------------------------------------------------------===// -#include "gc-dialects/Microkernel/MicrokernelOps.h" -#include "gc-dialects/Microkernel/MicrokernelDialect.h" +#include "gc/Dialects/Microkernel/MicrokernelOps.h" +#include "gc/Dialects/Microkernel/MicrokernelDialect.h" #include "mlir/IR/OpImplementation.h" #define GET_OP_CLASSES -#include "gc-dialects/Microkernel/MicrokernelOps.cpp.inc" +#include "gc/Dialects/Microkernel/MicrokernelOps.cpp.inc" diff --git a/lib/gc-dialects/OnednnGraph/CMakeLists.txt b/lib/gc/Dialects/OnednnGraph/CMakeLists.txt similarity index 78% rename from lib/gc-dialects/OnednnGraph/CMakeLists.txt rename to lib/gc/Dialects/OnednnGraph/CMakeLists.txt index c576892f1..39352ca0c 100644 --- a/lib/gc-dialects/OnednnGraph/CMakeLists.txt +++ b/lib/gc/Dialects/OnednnGraph/CMakeLists.txt @@ -3,7 +3,7 @@ add_mlir_dialect_library(MLIROnednnGraph OnednnGraphOps.cpp ADDITIONAL_HEADER_DIRS - ${PROJECT_SOURCE_DIR}/include/gc-dialects/OnednnGraph + ${PROJECT_SOURCE_DIR}/include/gc/Dialects/OnednnGraph DEPENDS MLIROnednnGraphOpsIncGen diff --git a/lib/gc-dialects/OnednnGraph/OnednnGraphDialect.cpp b/lib/gc/Dialects/OnednnGraph/OnednnGraphDialect.cpp similarity index 75% rename from lib/gc-dialects/OnednnGraph/OnednnGraphDialect.cpp rename to lib/gc/Dialects/OnednnGraph/OnednnGraphDialect.cpp index d854f98bc..70e15dc30 100644 --- a/lib/gc-dialects/OnednnGraph/OnednnGraphDialect.cpp +++ b/lib/gc/Dialects/OnednnGraph/OnednnGraphDialect.cpp @@ -6,8 +6,8 @@ // //===----------------------------------------------------------------------===// -#include "gc-dialects/OnednnGraph/OnednnGraphDialect.h" -#include "gc-dialects/OnednnGraph/OnednnGraphOps.h" +#include "gc/Dialects/OnednnGraph/OnednnGraphDialect.h" +#include "gc/Dialects/OnednnGraph/OnednnGraphOps.h" using namespace mlir; using namespace mlir::onednn_graph; @@ -15,6 +15,6 @@ using namespace mlir::onednn_graph; void OnednnGraphDialect::initialize() { addOperations< #define GET_OP_LIST -#include "gc-dialects/OnednnGraph/OnednnGraphOps.cpp.inc" +#include "gc/Dialects/OnednnGraph/OnednnGraphOps.cpp.inc" >(); } diff --git a/lib/gc-dialects/OnednnGraph/OnednnGraphOps.cpp b/lib/gc/Dialects/OnednnGraph/OnednnGraphOps.cpp similarity index 72% rename from lib/gc-dialects/OnednnGraph/OnednnGraphOps.cpp rename to lib/gc/Dialects/OnednnGraph/OnednnGraphOps.cpp index 1b2c7f932..88ceeea45 100644 --- a/lib/gc-dialects/OnednnGraph/OnednnGraphOps.cpp +++ b/lib/gc/Dialects/OnednnGraph/OnednnGraphOps.cpp @@ -6,9 +6,9 @@ // //===----------------------------------------------------------------------===// -#include "gc-dialects/OnednnGraph/OnednnGraphOps.h" -#include "gc-dialects/OnednnGraph/OnednnGraphDialect.h" +#include "gc/Dialects/OnednnGraph/OnednnGraphOps.h" +#include "gc/Dialects/OnednnGraph/OnednnGraphDialect.h" #include "mlir/IR/OpImplementation.h" #define GET_OP_CLASSES -#include "gc-dialects/OnednnGraph/OnednnGraphOps.cpp.inc" +#include "gc/Dialects/OnednnGraph/OnednnGraphOps.cpp.inc" diff --git a/lib/gc-dialects/Transforms/CMakeLists.txt b/lib/gc/Transforms/CMakeLists.txt similarity index 84% rename from lib/gc-dialects/Transforms/CMakeLists.txt rename to lib/gc/Transforms/CMakeLists.txt index ace2c8528..df8a14d01 100644 --- a/lib/gc-dialects/Transforms/CMakeLists.txt +++ b/lib/gc/Transforms/CMakeLists.txt @@ -2,7 +2,7 @@ add_mlir_library(GCPasses TileNamed.cpp ADDITIONAL_HEADER_DIRS - ${PROJECT_SOURCE_DIR}/include/gc-dialects + ${PROJECT_SOURCE_DIR}/include DEPENDS GraphCompilerPassIncGen diff --git a/lib/gc-dialects/Transforms/TileNamed.cpp b/lib/gc/Transforms/TileNamed.cpp similarity index 95% rename from lib/gc-dialects/Transforms/TileNamed.cpp rename to lib/gc/Transforms/TileNamed.cpp index 51112f28d..7d0e8c531 100644 --- a/lib/gc-dialects/Transforms/TileNamed.cpp +++ b/lib/gc/Transforms/TileNamed.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include "gc-dialects/Passes.h" +#include "gc/Transforms/Passes.h" #include "mlir/Dialect/Affine/IR/AffineOps.h" #include "mlir/Dialect/Func/IR/FuncOps.h" #include "mlir/Dialect/Linalg/IR/Linalg.h" @@ -22,7 +22,7 @@ using namespace mlir; namespace mlir { namespace gc { #define GEN_PASS_DEF_TILELINALGNAMED -#include "gc-dialects/Passes.h.inc" +#include "gc/Transforms/Passes.h.inc" } // namespace gc } // namespace mlir diff --git a/src/gc-opt.cpp b/src/gc-opt.cpp index d42478cd8..72a25abf5 100644 --- a/src/gc-opt.cpp +++ b/src/gc-opt.cpp @@ -17,7 +17,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include "gc-dialects/Passes.h" +#include "gc/Transforms/Passes.h" #include "mlir/InitAllDialects.h" #include "mlir/InitAllPasses.h" #include "mlir/Tools/mlir-opt/MlirOptMain.h" From 7cb96b438a5d67ebe6b9846c51ec17c2cb5783e5 Mon Sep 17 00:00:00 2001 From: "Mei, Yijie" Date: Thu, 9 May 2024 13:52:06 +0800 Subject: [PATCH 5/7] rename --- include/gc/CMakeLists.txt | 2 +- include/gc/{Dialects => Dialect}/CMakeLists.txt | 0 include/gc/Dialect/Linalgx/CMakeLists.txt | 3 +++ include/gc/{Dialects => Dialect}/Linalgx/LinalgxDialect.h | 2 +- include/gc/{Dialects => Dialect}/Linalgx/LinalgxDialect.td | 0 include/gc/{Dialects => Dialect}/Linalgx/LinalgxOps.h | 2 +- include/gc/{Dialects => Dialect}/Linalgx/LinalgxOps.td | 0 include/gc/Dialect/Microkernel/CMakeLists.txt | 3 +++ .../{Dialects => Dialect}/Microkernel/MicrokernelDialect.h | 2 +- .../{Dialects => Dialect}/Microkernel/MicrokernelDialect.td | 0 .../gc/{Dialects => Dialect}/Microkernel/MicrokernelOps.h | 2 +- .../gc/{Dialects => Dialect}/Microkernel/MicrokernelOps.td | 0 include/gc/Dialect/OnednnGraph/CMakeLists.txt | 3 +++ .../{Dialects => Dialect}/OnednnGraph/OnednnGraphDialect.h | 2 +- .../{Dialects => Dialect}/OnednnGraph/OnednnGraphDialect.td | 0 .../gc/{Dialects => Dialect}/OnednnGraph/OnednnGraphOps.h | 2 +- .../gc/{Dialects => Dialect}/OnednnGraph/OnednnGraphOps.td | 0 include/gc/Dialects/Linalgx/CMakeLists.txt | 3 --- include/gc/Dialects/Microkernel/CMakeLists.txt | 3 --- include/gc/Dialects/OnednnGraph/CMakeLists.txt | 3 --- lib/gc/CMakeLists.txt | 2 +- lib/gc/{Dialects => Dialect}/CMakeLists.txt | 0 lib/gc/{Dialects => Dialect}/Linalgx/CMakeLists.txt | 2 +- lib/gc/{Dialects => Dialect}/Linalgx/LinalgxDialect.cpp | 6 +++--- lib/gc/{Dialects => Dialect}/Linalgx/LinalgxOps.cpp | 6 +++--- lib/gc/{Dialects => Dialect}/Microkernel/CMakeLists.txt | 2 +- .../Microkernel/MicrokernelDialect.cpp | 6 +++--- lib/gc/{Dialects => Dialect}/Microkernel/MicrokernelOps.cpp | 6 +++--- lib/gc/{Dialects => Dialect}/OnednnGraph/CMakeLists.txt | 2 +- .../OnednnGraph/OnednnGraphDialect.cpp | 6 +++--- lib/gc/{Dialects => Dialect}/OnednnGraph/OnednnGraphOps.cpp | 6 +++--- 31 files changed, 38 insertions(+), 38 deletions(-) rename include/gc/{Dialects => Dialect}/CMakeLists.txt (100%) create mode 100644 include/gc/Dialect/Linalgx/CMakeLists.txt rename include/gc/{Dialects => Dialect}/Linalgx/LinalgxDialect.h (90%) rename include/gc/{Dialects => Dialect}/Linalgx/LinalgxDialect.td (100%) rename include/gc/{Dialects => Dialect}/Linalgx/LinalgxOps.h (91%) rename include/gc/{Dialects => Dialect}/Linalgx/LinalgxOps.td (100%) create mode 100644 include/gc/Dialect/Microkernel/CMakeLists.txt rename include/gc/{Dialects => Dialect}/Microkernel/MicrokernelDialect.h (89%) rename include/gc/{Dialects => Dialect}/Microkernel/MicrokernelDialect.td (100%) rename include/gc/{Dialects => Dialect}/Microkernel/MicrokernelOps.h (90%) rename include/gc/{Dialects => Dialect}/Microkernel/MicrokernelOps.td (100%) create mode 100644 include/gc/Dialect/OnednnGraph/CMakeLists.txt rename include/gc/{Dialects => Dialect}/OnednnGraph/OnednnGraphDialect.h (89%) rename include/gc/{Dialects => Dialect}/OnednnGraph/OnednnGraphDialect.td (100%) rename include/gc/{Dialects => Dialect}/OnednnGraph/OnednnGraphOps.h (90%) rename include/gc/{Dialects => Dialect}/OnednnGraph/OnednnGraphOps.td (100%) delete mode 100644 include/gc/Dialects/Linalgx/CMakeLists.txt delete mode 100644 include/gc/Dialects/Microkernel/CMakeLists.txt delete mode 100644 include/gc/Dialects/OnednnGraph/CMakeLists.txt rename lib/gc/{Dialects => Dialect}/CMakeLists.txt (100%) rename lib/gc/{Dialects => Dialect}/Linalgx/CMakeLists.txt (77%) rename lib/gc/{Dialects => Dialect}/Linalgx/LinalgxDialect.cpp (78%) rename lib/gc/{Dialects => Dialect}/Linalgx/LinalgxOps.cpp (75%) rename lib/gc/{Dialects => Dialect}/Microkernel/CMakeLists.txt (78%) rename lib/gc/{Dialects => Dialect}/Microkernel/MicrokernelDialect.cpp (75%) rename lib/gc/{Dialects => Dialect}/Microkernel/MicrokernelOps.cpp (72%) rename lib/gc/{Dialects => Dialect}/OnednnGraph/CMakeLists.txt (78%) rename lib/gc/{Dialects => Dialect}/OnednnGraph/OnednnGraphDialect.cpp (75%) rename lib/gc/{Dialects => Dialect}/OnednnGraph/OnednnGraphOps.cpp (72%) diff --git a/include/gc/CMakeLists.txt b/include/gc/CMakeLists.txt index fed04555e..db67942f3 100644 --- a/include/gc/CMakeLists.txt +++ b/include/gc/CMakeLists.txt @@ -1,2 +1,2 @@ -add_subdirectory(Dialects) +add_subdirectory(Dialect) add_subdirectory(Transforms) \ No newline at end of file diff --git a/include/gc/Dialects/CMakeLists.txt b/include/gc/Dialect/CMakeLists.txt similarity index 100% rename from include/gc/Dialects/CMakeLists.txt rename to include/gc/Dialect/CMakeLists.txt diff --git a/include/gc/Dialect/Linalgx/CMakeLists.txt b/include/gc/Dialect/Linalgx/CMakeLists.txt new file mode 100644 index 000000000..ed0e683e2 --- /dev/null +++ b/include/gc/Dialect/Linalgx/CMakeLists.txt @@ -0,0 +1,3 @@ +add_mlir_dialect(LinalgxOps linalgx) +add_mlir_doc(LinalgxOps LinalgxOps gc/Dialect/Linalgx/ -gen-op-doc) +add_mlir_doc(LinalgxDialect LinalgxDialect gc/Dialect/Linalgx/ -gen-dialect-doc) diff --git a/include/gc/Dialects/Linalgx/LinalgxDialect.h b/include/gc/Dialect/Linalgx/LinalgxDialect.h similarity index 90% rename from include/gc/Dialects/Linalgx/LinalgxDialect.h rename to include/gc/Dialect/Linalgx/LinalgxDialect.h index 9479cfbd5..7d9446ffe 100644 --- a/include/gc/Dialects/Linalgx/LinalgxDialect.h +++ b/include/gc/Dialect/Linalgx/LinalgxDialect.h @@ -11,6 +11,6 @@ #include "mlir/IR/Dialect.h" -#include "gc/Dialects/Linalgx/LinalgxOpsDialect.h.inc" +#include "gc/Dialect/Linalgx/LinalgxOpsDialect.h.inc" #endif // GC_DIALECTS_LINALGXDIALECT_H diff --git a/include/gc/Dialects/Linalgx/LinalgxDialect.td b/include/gc/Dialect/Linalgx/LinalgxDialect.td similarity index 100% rename from include/gc/Dialects/Linalgx/LinalgxDialect.td rename to include/gc/Dialect/Linalgx/LinalgxDialect.td diff --git a/include/gc/Dialects/Linalgx/LinalgxOps.h b/include/gc/Dialect/Linalgx/LinalgxOps.h similarity index 91% rename from include/gc/Dialects/Linalgx/LinalgxOps.h rename to include/gc/Dialect/Linalgx/LinalgxOps.h index ef6ba751d..d014da630 100644 --- a/include/gc/Dialects/Linalgx/LinalgxOps.h +++ b/include/gc/Dialect/Linalgx/LinalgxOps.h @@ -12,6 +12,6 @@ #include "mlir/IR/OpDefinition.h" #define GET_OP_CLASSES -#include "gc/Dialects/Linalgx/LinalgxOps.h.inc" +#include "gc/Dialect/Linalgx/LinalgxOps.h.inc" #endif // GC_DIALECTS_LINALGXOPS_H diff --git a/include/gc/Dialects/Linalgx/LinalgxOps.td b/include/gc/Dialect/Linalgx/LinalgxOps.td similarity index 100% rename from include/gc/Dialects/Linalgx/LinalgxOps.td rename to include/gc/Dialect/Linalgx/LinalgxOps.td diff --git a/include/gc/Dialect/Microkernel/CMakeLists.txt b/include/gc/Dialect/Microkernel/CMakeLists.txt new file mode 100644 index 000000000..4d8f855e0 --- /dev/null +++ b/include/gc/Dialect/Microkernel/CMakeLists.txt @@ -0,0 +1,3 @@ +add_mlir_dialect(MicrokernelOps microkernel) +add_mlir_doc(MicrokernelOps MicrokernelOps gc/Dialect/Microkernel/ -gen-op-doc) +add_mlir_doc(MicrokernelDialect MicrokernelDialect gc/Dialect/Microkernel/ -gen-dialect-doc) diff --git a/include/gc/Dialects/Microkernel/MicrokernelDialect.h b/include/gc/Dialect/Microkernel/MicrokernelDialect.h similarity index 89% rename from include/gc/Dialects/Microkernel/MicrokernelDialect.h rename to include/gc/Dialect/Microkernel/MicrokernelDialect.h index efbbeb9ce..71b368655 100644 --- a/include/gc/Dialects/Microkernel/MicrokernelDialect.h +++ b/include/gc/Dialect/Microkernel/MicrokernelDialect.h @@ -11,6 +11,6 @@ #include "mlir/IR/Dialect.h" -#include "gc/Dialects/Microkernel/MicrokernelOpsDialect.h.inc" +#include "gc/Dialect/Microkernel/MicrokernelOpsDialect.h.inc" #endif // GC_DIALECTS_MICROKERNELDIALECT_H diff --git a/include/gc/Dialects/Microkernel/MicrokernelDialect.td b/include/gc/Dialect/Microkernel/MicrokernelDialect.td similarity index 100% rename from include/gc/Dialects/Microkernel/MicrokernelDialect.td rename to include/gc/Dialect/Microkernel/MicrokernelDialect.td diff --git a/include/gc/Dialects/Microkernel/MicrokernelOps.h b/include/gc/Dialect/Microkernel/MicrokernelOps.h similarity index 90% rename from include/gc/Dialects/Microkernel/MicrokernelOps.h rename to include/gc/Dialect/Microkernel/MicrokernelOps.h index cab3f725a..ca36f4c02 100644 --- a/include/gc/Dialects/Microkernel/MicrokernelOps.h +++ b/include/gc/Dialect/Microkernel/MicrokernelOps.h @@ -12,6 +12,6 @@ #include "mlir/IR/OpDefinition.h" #define GET_OP_CLASSES -#include "gc/Dialects/Microkernel/MicrokernelOps.h.inc" +#include "gc/Dialect/Microkernel/MicrokernelOps.h.inc" #endif // GC_DIALECTS_MICROKERNELOPS_H diff --git a/include/gc/Dialects/Microkernel/MicrokernelOps.td b/include/gc/Dialect/Microkernel/MicrokernelOps.td similarity index 100% rename from include/gc/Dialects/Microkernel/MicrokernelOps.td rename to include/gc/Dialect/Microkernel/MicrokernelOps.td diff --git a/include/gc/Dialect/OnednnGraph/CMakeLists.txt b/include/gc/Dialect/OnednnGraph/CMakeLists.txt new file mode 100644 index 000000000..7e7c7eb68 --- /dev/null +++ b/include/gc/Dialect/OnednnGraph/CMakeLists.txt @@ -0,0 +1,3 @@ +add_mlir_dialect(OnednnGraphOps onednn_graph) +add_mlir_doc(OnednnGraphOps OnednnGraphOps gc/Dialect/OnednnGraph/ -gen-op-doc) +add_mlir_doc(OnednnGraphDialect OnednnGraphDialect gc/Dialect/OnednnGraph/ -gen-dialect-doc) diff --git a/include/gc/Dialects/OnednnGraph/OnednnGraphDialect.h b/include/gc/Dialect/OnednnGraph/OnednnGraphDialect.h similarity index 89% rename from include/gc/Dialects/OnednnGraph/OnednnGraphDialect.h rename to include/gc/Dialect/OnednnGraph/OnednnGraphDialect.h index 5f9ca3a17..7f128cb64 100644 --- a/include/gc/Dialects/OnednnGraph/OnednnGraphDialect.h +++ b/include/gc/Dialect/OnednnGraph/OnednnGraphDialect.h @@ -11,6 +11,6 @@ #include "mlir/IR/Dialect.h" -#include "gc/Dialects/OnednnGraph/OnednnGraphOpsDialect.h.inc" +#include "gc/Dialect/OnednnGraph/OnednnGraphOpsDialect.h.inc" #endif // GC_DIALECTS_ONEDNNGRAPHDIALECT_H diff --git a/include/gc/Dialects/OnednnGraph/OnednnGraphDialect.td b/include/gc/Dialect/OnednnGraph/OnednnGraphDialect.td similarity index 100% rename from include/gc/Dialects/OnednnGraph/OnednnGraphDialect.td rename to include/gc/Dialect/OnednnGraph/OnednnGraphDialect.td diff --git a/include/gc/Dialects/OnednnGraph/OnednnGraphOps.h b/include/gc/Dialect/OnednnGraph/OnednnGraphOps.h similarity index 90% rename from include/gc/Dialects/OnednnGraph/OnednnGraphOps.h rename to include/gc/Dialect/OnednnGraph/OnednnGraphOps.h index 71f56ff9a..ad86d908c 100644 --- a/include/gc/Dialects/OnednnGraph/OnednnGraphOps.h +++ b/include/gc/Dialect/OnednnGraph/OnednnGraphOps.h @@ -12,6 +12,6 @@ #include "mlir/IR/OpDefinition.h" #define GET_OP_CLASSES -#include "gc/Dialects/OnednnGraph/OnednnGraphOps.h.inc" +#include "gc/Dialect/OnednnGraph/OnednnGraphOps.h.inc" #endif // GC_DIALECTS_ONEDNNGRAPHOPS_H diff --git a/include/gc/Dialects/OnednnGraph/OnednnGraphOps.td b/include/gc/Dialect/OnednnGraph/OnednnGraphOps.td similarity index 100% rename from include/gc/Dialects/OnednnGraph/OnednnGraphOps.td rename to include/gc/Dialect/OnednnGraph/OnednnGraphOps.td diff --git a/include/gc/Dialects/Linalgx/CMakeLists.txt b/include/gc/Dialects/Linalgx/CMakeLists.txt deleted file mode 100644 index e7b096056..000000000 --- a/include/gc/Dialects/Linalgx/CMakeLists.txt +++ /dev/null @@ -1,3 +0,0 @@ -add_mlir_dialect(LinalgxOps linalgx) -add_mlir_doc(LinalgxOps LinalgxOps gc/Dialects/Linalgx/ -gen-op-doc) -add_mlir_doc(LinalgxDialect LinalgxDialect gc/Dialects/Linalgx/ -gen-dialect-doc) diff --git a/include/gc/Dialects/Microkernel/CMakeLists.txt b/include/gc/Dialects/Microkernel/CMakeLists.txt deleted file mode 100644 index 908da1295..000000000 --- a/include/gc/Dialects/Microkernel/CMakeLists.txt +++ /dev/null @@ -1,3 +0,0 @@ -add_mlir_dialect(MicrokernelOps microkernel) -add_mlir_doc(MicrokernelOps MicrokernelOps gc/Dialects/Microkernel/ -gen-op-doc) -add_mlir_doc(MicrokernelDialect MicrokernelDialect gc/Dialects/Microkernel/ -gen-dialect-doc) diff --git a/include/gc/Dialects/OnednnGraph/CMakeLists.txt b/include/gc/Dialects/OnednnGraph/CMakeLists.txt deleted file mode 100644 index 9923af336..000000000 --- a/include/gc/Dialects/OnednnGraph/CMakeLists.txt +++ /dev/null @@ -1,3 +0,0 @@ -add_mlir_dialect(OnednnGraphOps onednn_graph) -add_mlir_doc(OnednnGraphOps OnednnGraphOps gc/Dialects/OnednnGraph/ -gen-op-doc) -add_mlir_doc(OnednnGraphDialect OnednnGraphDialect gc/Dialects/OnednnGraph/ -gen-dialect-doc) diff --git a/lib/gc/CMakeLists.txt b/lib/gc/CMakeLists.txt index fed04555e..db67942f3 100644 --- a/lib/gc/CMakeLists.txt +++ b/lib/gc/CMakeLists.txt @@ -1,2 +1,2 @@ -add_subdirectory(Dialects) +add_subdirectory(Dialect) add_subdirectory(Transforms) \ No newline at end of file diff --git a/lib/gc/Dialects/CMakeLists.txt b/lib/gc/Dialect/CMakeLists.txt similarity index 100% rename from lib/gc/Dialects/CMakeLists.txt rename to lib/gc/Dialect/CMakeLists.txt diff --git a/lib/gc/Dialects/Linalgx/CMakeLists.txt b/lib/gc/Dialect/Linalgx/CMakeLists.txt similarity index 77% rename from lib/gc/Dialects/Linalgx/CMakeLists.txt rename to lib/gc/Dialect/Linalgx/CMakeLists.txt index 6c86d6bc3..65957f316 100644 --- a/lib/gc/Dialects/Linalgx/CMakeLists.txt +++ b/lib/gc/Dialect/Linalgx/CMakeLists.txt @@ -3,7 +3,7 @@ add_mlir_dialect_library(MLIRLinalgx LinalgxOps.cpp ADDITIONAL_HEADER_DIRS - ${PROJECT_SOURCE_DIR}/include/gc/Dialects/Linalgx + ${PROJECT_SOURCE_DIR}/include/gc/Dialect/Linalgx DEPENDS MLIRLinalgxOpsIncGen diff --git a/lib/gc/Dialects/Linalgx/LinalgxDialect.cpp b/lib/gc/Dialect/Linalgx/LinalgxDialect.cpp similarity index 78% rename from lib/gc/Dialects/Linalgx/LinalgxDialect.cpp rename to lib/gc/Dialect/Linalgx/LinalgxDialect.cpp index def676325..e2267f609 100644 --- a/lib/gc/Dialects/Linalgx/LinalgxDialect.cpp +++ b/lib/gc/Dialect/Linalgx/LinalgxDialect.cpp @@ -6,8 +6,8 @@ // //===----------------------------------------------------------------------===// -#include "gc/Dialects/Linalgx/LinalgxDialect.h" -#include "gc/Dialects/Linalgx/LinalgxOps.h" +#include "gc/Dialect/Linalgx/LinalgxDialect.h" +#include "gc/Dialect/Linalgx/LinalgxOps.h" using namespace mlir; using namespace mlir::linalgx; @@ -15,6 +15,6 @@ using namespace mlir::linalgx; void LinalgxDialect::initialize() { addOperations< #define GET_OP_LIST -#include "gc/Dialects/Linalgx/LinalgxOps.cpp.inc" +#include "gc/Dialect/Linalgx/LinalgxOps.cpp.inc" >(); } diff --git a/lib/gc/Dialects/Linalgx/LinalgxOps.cpp b/lib/gc/Dialect/Linalgx/LinalgxOps.cpp similarity index 75% rename from lib/gc/Dialects/Linalgx/LinalgxOps.cpp rename to lib/gc/Dialect/Linalgx/LinalgxOps.cpp index f485838c7..9c57a2973 100644 --- a/lib/gc/Dialects/Linalgx/LinalgxOps.cpp +++ b/lib/gc/Dialect/Linalgx/LinalgxOps.cpp @@ -6,9 +6,9 @@ // //===----------------------------------------------------------------------===// -#include "gc/Dialects/Linalgx/LinalgxOps.h" -#include "gc/Dialects/Linalgx/LinalgxDialect.h" +#include "gc/Dialect/Linalgx/LinalgxOps.h" +#include "gc/Dialect/Linalgx/LinalgxDialect.h" #include "mlir/IR/OpImplementation.h" #define GET_OP_CLASSES -#include "gc/Dialects/Linalgx/LinalgxOps.cpp.inc" +#include "gc/Dialect/Linalgx/LinalgxOps.cpp.inc" diff --git a/lib/gc/Dialects/Microkernel/CMakeLists.txt b/lib/gc/Dialect/Microkernel/CMakeLists.txt similarity index 78% rename from lib/gc/Dialects/Microkernel/CMakeLists.txt rename to lib/gc/Dialect/Microkernel/CMakeLists.txt index 68f2977ef..e6d911a3b 100644 --- a/lib/gc/Dialects/Microkernel/CMakeLists.txt +++ b/lib/gc/Dialect/Microkernel/CMakeLists.txt @@ -3,7 +3,7 @@ add_mlir_dialect_library(MLIRMicrokernel MicrokernelOps.cpp ADDITIONAL_HEADER_DIRS - ${PROJECT_SOURCE_DIR}/include/gc/Dialects/Microkernel + ${PROJECT_SOURCE_DIR}/include/gc/Dialect/Microkernel DEPENDS MLIRMicrokernelOpsIncGen diff --git a/lib/gc/Dialects/Microkernel/MicrokernelDialect.cpp b/lib/gc/Dialect/Microkernel/MicrokernelDialect.cpp similarity index 75% rename from lib/gc/Dialects/Microkernel/MicrokernelDialect.cpp rename to lib/gc/Dialect/Microkernel/MicrokernelDialect.cpp index d785bc94c..7d3da6b45 100644 --- a/lib/gc/Dialects/Microkernel/MicrokernelDialect.cpp +++ b/lib/gc/Dialect/Microkernel/MicrokernelDialect.cpp @@ -6,8 +6,8 @@ // //===----------------------------------------------------------------------===// -#include "gc/Dialects/Microkernel/MicrokernelDialect.h" -#include "gc/Dialects/Microkernel/MicrokernelOps.h" +#include "gc/Dialect/Microkernel/MicrokernelDialect.h" +#include "gc/Dialect/Microkernel/MicrokernelOps.h" using namespace mlir; using namespace mlir::microkernel; @@ -15,6 +15,6 @@ using namespace mlir::microkernel; void MicrokernelDialect::initialize() { addOperations< #define GET_OP_LIST -#include "gc/Dialects/Microkernel/MicrokernelOps.cpp.inc" +#include "gc/Dialect/Microkernel/MicrokernelOps.cpp.inc" >(); } diff --git a/lib/gc/Dialects/Microkernel/MicrokernelOps.cpp b/lib/gc/Dialect/Microkernel/MicrokernelOps.cpp similarity index 72% rename from lib/gc/Dialects/Microkernel/MicrokernelOps.cpp rename to lib/gc/Dialect/Microkernel/MicrokernelOps.cpp index f38024413..9b9200e93 100644 --- a/lib/gc/Dialects/Microkernel/MicrokernelOps.cpp +++ b/lib/gc/Dialect/Microkernel/MicrokernelOps.cpp @@ -6,9 +6,9 @@ // //===----------------------------------------------------------------------===// -#include "gc/Dialects/Microkernel/MicrokernelOps.h" -#include "gc/Dialects/Microkernel/MicrokernelDialect.h" +#include "gc/Dialect/Microkernel/MicrokernelOps.h" +#include "gc/Dialect/Microkernel/MicrokernelDialect.h" #include "mlir/IR/OpImplementation.h" #define GET_OP_CLASSES -#include "gc/Dialects/Microkernel/MicrokernelOps.cpp.inc" +#include "gc/Dialect/Microkernel/MicrokernelOps.cpp.inc" diff --git a/lib/gc/Dialects/OnednnGraph/CMakeLists.txt b/lib/gc/Dialect/OnednnGraph/CMakeLists.txt similarity index 78% rename from lib/gc/Dialects/OnednnGraph/CMakeLists.txt rename to lib/gc/Dialect/OnednnGraph/CMakeLists.txt index 39352ca0c..4571697b3 100644 --- a/lib/gc/Dialects/OnednnGraph/CMakeLists.txt +++ b/lib/gc/Dialect/OnednnGraph/CMakeLists.txt @@ -3,7 +3,7 @@ add_mlir_dialect_library(MLIROnednnGraph OnednnGraphOps.cpp ADDITIONAL_HEADER_DIRS - ${PROJECT_SOURCE_DIR}/include/gc/Dialects/OnednnGraph + ${PROJECT_SOURCE_DIR}/include/gc/Dialect/OnednnGraph DEPENDS MLIROnednnGraphOpsIncGen diff --git a/lib/gc/Dialects/OnednnGraph/OnednnGraphDialect.cpp b/lib/gc/Dialect/OnednnGraph/OnednnGraphDialect.cpp similarity index 75% rename from lib/gc/Dialects/OnednnGraph/OnednnGraphDialect.cpp rename to lib/gc/Dialect/OnednnGraph/OnednnGraphDialect.cpp index 70e15dc30..434fa8a57 100644 --- a/lib/gc/Dialects/OnednnGraph/OnednnGraphDialect.cpp +++ b/lib/gc/Dialect/OnednnGraph/OnednnGraphDialect.cpp @@ -6,8 +6,8 @@ // //===----------------------------------------------------------------------===// -#include "gc/Dialects/OnednnGraph/OnednnGraphDialect.h" -#include "gc/Dialects/OnednnGraph/OnednnGraphOps.h" +#include "gc/Dialect/OnednnGraph/OnednnGraphDialect.h" +#include "gc/Dialect/OnednnGraph/OnednnGraphOps.h" using namespace mlir; using namespace mlir::onednn_graph; @@ -15,6 +15,6 @@ using namespace mlir::onednn_graph; void OnednnGraphDialect::initialize() { addOperations< #define GET_OP_LIST -#include "gc/Dialects/OnednnGraph/OnednnGraphOps.cpp.inc" +#include "gc/Dialect/OnednnGraph/OnednnGraphOps.cpp.inc" >(); } diff --git a/lib/gc/Dialects/OnednnGraph/OnednnGraphOps.cpp b/lib/gc/Dialect/OnednnGraph/OnednnGraphOps.cpp similarity index 72% rename from lib/gc/Dialects/OnednnGraph/OnednnGraphOps.cpp rename to lib/gc/Dialect/OnednnGraph/OnednnGraphOps.cpp index 88ceeea45..b5f1dadca 100644 --- a/lib/gc/Dialects/OnednnGraph/OnednnGraphOps.cpp +++ b/lib/gc/Dialect/OnednnGraph/OnednnGraphOps.cpp @@ -6,9 +6,9 @@ // //===----------------------------------------------------------------------===// -#include "gc/Dialects/OnednnGraph/OnednnGraphOps.h" -#include "gc/Dialects/OnednnGraph/OnednnGraphDialect.h" +#include "gc/Dialect/OnednnGraph/OnednnGraphOps.h" +#include "gc/Dialect/OnednnGraph/OnednnGraphDialect.h" #include "mlir/IR/OpImplementation.h" #define GET_OP_CLASSES -#include "gc/Dialects/OnednnGraph/OnednnGraphOps.cpp.inc" +#include "gc/Dialect/OnednnGraph/OnednnGraphOps.cpp.inc" From 9f916168258325971706309407ffac2464c3f64d Mon Sep 17 00:00:00 2001 From: "Mei, Yijie" Date: Thu, 9 May 2024 14:01:14 +0800 Subject: [PATCH 6/7] Add code --- .../Dialect}/Arith/Utils/EasyBuild.h | 33 +- include/gc/IR/EasyBuild.h | 100 +++ unittests/CMakeLists.txt | 2 +- unittests/Dialect/Arith/CMakeLists.txt | 6 + unittests/Dialect/Arith/EasyBuildTest.cpp | 635 ++++++++++++++++++ unittests/Dialect/CMakeLists.txt | 1 + unittests/Example/CMakeLists.txt | 6 - unittests/Example/Example.cpp | 14 - 8 files changed, 755 insertions(+), 42 deletions(-) rename include/{gc-dialects => gc/Dialect}/Arith/Utils/EasyBuild.h (94%) create mode 100644 include/gc/IR/EasyBuild.h create mode 100644 unittests/Dialect/Arith/CMakeLists.txt create mode 100644 unittests/Dialect/Arith/EasyBuildTest.cpp create mode 100644 unittests/Dialect/CMakeLists.txt delete mode 100644 unittests/Example/CMakeLists.txt delete mode 100644 unittests/Example/Example.cpp diff --git a/include/gc-dialects/Arith/Utils/EasyBuild.h b/include/gc/Dialect/Arith/Utils/EasyBuild.h similarity index 94% rename from include/gc-dialects/Arith/Utils/EasyBuild.h rename to include/gc/Dialect/Arith/Utils/EasyBuild.h index 15d421caa..2a3c21483 100644 --- a/include/gc-dialects/Arith/Utils/EasyBuild.h +++ b/include/gc/Dialect/Arith/Utils/EasyBuild.h @@ -13,11 +13,11 @@ // //===----------------------------------------------------------------------===// -#ifndef GC_DIALECT_ARITH_UTILS_EASYBUILD_H -#define GC_DIALECT_ARITH_UTILS_EASYBUILD_H +#ifndef MLIR_DIALECT_ARITH_UTILS_EASYBUILD_H +#define MLIR_DIALECT_ARITH_UTILS_EASYBUILD_H +#include "gc/IR/EasyBuild.h" #include "mlir/Dialect/Arith/IR/Arith.h" #include "mlir/IR/Builders.h" -#include "mlir/IR/EasyBuild.h" #include #include #include @@ -27,15 +27,12 @@ namespace easybuild { namespace impl { -template -struct ToFloatType {}; +template struct ToFloatType {}; -template <> -struct ToFloatType<4> { +template <> struct ToFloatType<4> { using type = Float32Type; }; -template <> -struct ToFloatType<8> { +template <> struct ToFloatType<8> { using type = Float64Type; }; @@ -58,8 +55,7 @@ struct EBArithValue : public EBValue { template static auto wrapOrFail(const impl::StatePtr &state, T &&v); - template - static auto wrap(const impl::StatePtr &state, T &&v) { + template static auto wrap(const impl::StatePtr &state, T &&v) { auto ret = wrapOrFail(state, std::forward(v)); if (failed(ret)) { llvm_unreachable("Bad wrap"); @@ -243,12 +239,10 @@ struct OperatorHandlers { inline TYPE operator OP(const TYPE &a, const TYPE &b) { \ return OperatorHandlers::handleBinary(a, b); \ } \ - template \ - inline TYPE operator OP(const TYPE &a, T b) { \ + template inline TYPE operator OP(const TYPE &a, T b) { \ return OperatorHandlers::handleBinaryConst(a, b); \ } \ - template \ - inline TYPE operator OP(T a, const TYPE &b) { \ + template inline TYPE operator OP(T a, const TYPE &b) { \ return OperatorHandlers::handleBinaryConst(a, b); \ } @@ -285,12 +279,10 @@ inline EBFloatPoint operator-(const EBFloatPoint &a) { EBUnsigned operator OP(const TYPE &a, const TYPE &b) { \ return OperatorHandlers::handleCmp(a, b, PRED); \ } \ - template \ - EBUnsigned operator OP(const TYPE &a, T b) { \ + template EBUnsigned operator OP(const TYPE &a, T b) { \ return OperatorHandlers::handleCmpConst(a, b, PRED); \ } \ - template \ - EBUnsigned operator OP(T a, const TYPE &b) { \ + template EBUnsigned operator OP(T a, const TYPE &b) { \ return OperatorHandlers::handleCmpConst(a, b, PRED); \ } @@ -346,8 +338,7 @@ inline EBFloatPoint castIntToFP(Type type, const EBUnsigned &v) { type, v); } -template -inline T castFPToInt(const EBFloatPoint &v) { +template inline T castFPToInt(const EBFloatPoint &v) { if constexpr (std::is_same_v) { return OperatorHandlers::create(v.builder, v); } else { diff --git a/include/gc/IR/EasyBuild.h b/include/gc/IR/EasyBuild.h new file mode 100644 index 000000000..1f8f2b4e2 --- /dev/null +++ b/include/gc/IR/EasyBuild.h @@ -0,0 +1,100 @@ +//===- EasyBuild.h - Easy IR Builder utilities -----------------*- C++ -*-===// +// +// 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 +// +//===----------------------------------------------------------------------===// +// +// This header file defines prototypes for various transformation utilities for +// the Arith dialect. These are not passes by themselves but are used +// either by passes, optimization sequences, or in turn by other transformation +// utilities. +// +//===----------------------------------------------------------------------===// + +#ifndef MLIR_IR_EASYBUILD_H +#define MLIR_IR_EASYBUILD_H +#include "mlir/IR/Builders.h" +#include +#include +#include + +namespace mlir { +namespace easybuild { + +namespace impl { +struct EasyBuildState { + OpBuilder &builder; + Location loc; + bool u64AsIndex; + EasyBuildState(OpBuilder &builder, Location loc, bool u64AsIndex) + : builder{builder}, loc{loc}, u64AsIndex{u64AsIndex} {} +}; + +using StatePtr = std::shared_ptr; + +} // namespace impl + +struct EBValue { + std::shared_ptr builder; + Value v; + EBValue() = default; + EBValue(const impl::StatePtr &builder, Value v) : builder{builder}, v{v} {} + Value get() const { return v; } + operator Value() const { return v; } + + static FailureOr wrapOrFail(const impl::StatePtr& state, Value v) { + return EBValue{state, v}; + } +}; + +struct EBArithValue; + +struct EasyBuilder { + std::shared_ptr builder; + EasyBuilder(OpBuilder &builder, Location loc, bool u64AsIndex = false) + : builder{ + std::make_shared(builder, loc, u64AsIndex)} {} + EasyBuilder(const std::shared_ptr &builder) + : builder{builder} {} + void setLoc(const Location &l) { builder->loc = l; } + + template + auto wrapOrFail(V &&v) { + return W::wrapOrFail(builder, std::forward(v)); + } + + template + auto wrap(V &&v) { + auto ret = wrapOrFail(std::forward(v)); + if (failed(ret)) { + llvm_unreachable("wrap failed!"); + } + return *ret; + } + + template + auto operator()(V &&v) { + if constexpr (std::is_convertible_v) { + return EBValue{builder, std::forward(v)}; + } else { + return wrap(std::forward(v)); + } + } + + template + auto toIndex(uint64_t v) const { + return W::toIndex(builder, v); + } + + template + auto F(Args &&...v) { + return wrap( + builder->builder.create(builder->loc, std::forward(v)...)); + } +}; + +} // namespace easybuild +} // namespace mlir +#endif diff --git a/unittests/CMakeLists.txt b/unittests/CMakeLists.txt index 949595fca..f9086b6e5 100644 --- a/unittests/CMakeLists.txt +++ b/unittests/CMakeLists.txt @@ -14,5 +14,5 @@ function(add_mlir_unittest test_dirname) add_unittest(GCUnitTests ${test_dirname} ${ARGN}) endfunction() -add_subdirectory(Example) +add_subdirectory(Dialect) diff --git a/unittests/Dialect/Arith/CMakeLists.txt b/unittests/Dialect/Arith/CMakeLists.txt new file mode 100644 index 000000000..e9776f11e --- /dev/null +++ b/unittests/Dialect/Arith/CMakeLists.txt @@ -0,0 +1,6 @@ +add_mlir_unittest(MLIRArithTests + EasyBuildTest.cpp) +target_link_libraries(MLIRArithTests + PRIVATE + MLIRFuncDialect + MLIRArithDialect) diff --git a/unittests/Dialect/Arith/EasyBuildTest.cpp b/unittests/Dialect/Arith/EasyBuildTest.cpp new file mode 100644 index 000000000..07eb31c5a --- /dev/null +++ b/unittests/Dialect/Arith/EasyBuildTest.cpp @@ -0,0 +1,635 @@ +//===- EasyBuildTest.cpp - Tests Arith Op Easy builders -------------------===// +// +// 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 "gc/Dialect/Arith/Utils/EasyBuild.h" +#include "mlir/Dialect/Func/IR/FuncOps.h" +#include "gtest/gtest.h" + +using namespace mlir; +using namespace mlir::easybuild; + +namespace { +class ArithTest : public ::testing::Test { +protected: + ArithTest() { + context.getOrLoadDialect(); + context.getOrLoadDialect(); + } + + mlir::MLIRContext context; +}; +} // namespace + +TEST_F(ArithTest, EasyBuildConst) { + OpBuilder builder{&context}; + auto loc = builder.getUnknownLoc(); + EasyBuilder b{builder, loc}; + auto func = builder.create(loc, "funcname", + FunctionType::get(&context, {}, {})); + + builder.setInsertionPointToStart(func.addEntryBlock()); + auto i1 = b(true); + i1 = b(false); + auto i8 = b(int8_t(3)); + i8 = b(int8_t(-3)); + auto u8 = b(uint8_t(33)); + + auto i16 = b(int16_t(33)); + i16 = b(int16_t(-33)); + auto u16 = b(uint16_t(33)); + + auto i32 = b(int32_t(33)); + i32 = b(int32_t(-33)); + auto u32 = b(uint32_t(33)); + + auto i64 = b(int64_t(33)); + i64 = b(int64_t(-33)); + auto u64 = b(uint64_t(33)); + + auto idx = b.toIndex(23); + + { + EasyBuilder b2{builder, loc, /*u64AsIndex*/ true}; + auto idx2 = b(uint64_t(33)); + } + builder.create(loc); + std::string out; + llvm::raw_string_ostream os{out}; + os << func; + + const char *expected = + R"mlir(func.func @funcname() { + %true = arith.constant true + %false = arith.constant false + %c3_i8 = arith.constant 3 : i8 + %c-3_i8 = arith.constant -3 : i8 + %c33_i8 = arith.constant 33 : i8 + %c33_i16 = arith.constant 33 : i16 + %c-33_i16 = arith.constant -33 : i16 + %c33_i16_0 = arith.constant 33 : i16 + %c33_i32 = arith.constant 33 : i32 + %c-33_i32 = arith.constant -33 : i32 + %c33_i32_1 = arith.constant 33 : i32 + %c33_i64 = arith.constant 33 : i64 + %c-33_i64 = arith.constant -33 : i64 + %c33_i64_2 = arith.constant 33 : i64 + %c23 = arith.constant 23 : index + %c33_i64_3 = arith.constant 33 : i64 + return +})mlir"; + ASSERT_EQ(out, expected); +} + +#define SKIP_IF_UNEXPECTED_FP_SIZE() \ + if constexpr (sizeof(float) != 4 || sizeof(double) != 8) { \ + GTEST_SKIP(); \ + } + +TEST_F(ArithTest, EasyBuildFloatConst) { + SKIP_IF_UNEXPECTED_FP_SIZE() + OpBuilder builder{&context}; + auto loc = builder.getUnknownLoc(); + EasyBuilder b{builder, loc}; + auto func = builder.create(loc, "funcname", + FunctionType::get(&context, {}, {})); + + builder.setInsertionPointToStart(func.addEntryBlock()); + auto a = b(1.0f); + auto a2 = b(1.0); + builder.create(loc); + std::string out; + llvm::raw_string_ostream os{out}; + os << func; + const char *expected = + R"mlir(func.func @funcname() { + %cst = arith.constant 1.000000e+00 : f32 + %cst_0 = arith.constant 1.000000e+00 : f64 + return +})mlir"; + ASSERT_EQ(out, expected); +} + +template +static std::string composeIR(MLIRContext *context, T1 &&getA, T2 &&getB) { + OpBuilder builder{context}; + auto loc = builder.getUnknownLoc(); + EasyBuilder b{builder, loc}; + auto func = builder.create( + loc, "funcname", FunctionType::get(builder.getContext(), {}, {})); + builder.setInsertionPointToStart(func.addEntryBlock()); + auto A = getA(b); + auto B = getB(b); + auto v1 = A + B; + v1 = A - B; + v1 = A * B; + v1 = A / B; + v1 = A % B; + v1 = A >> B; + v1 = A << B; + v1 = A & B; + v1 = A | B; + v1 = A ^ B; + auto cmp = A < B; + cmp = cmp & (A <= B); + cmp = cmp & (A > B); + cmp = cmp & (A >= B); + cmp = cmp ^ (A == B); + cmp = cmp ^ (A != B); + builder.create(loc); + + std::string out; + llvm::raw_string_ostream os{out}; + os << func; + return out; +} + +// check X+Y, where both X and Y are WrappedValues +TEST_F(ArithTest, EasyBuildSignedOperatorsBothValues) { + auto out = composeIR( + &context, [](EasyBuilder b) { return b(int32_t(33)); }, + [](EasyBuilder b) { return b(int32_t(31)); }); + const char *signedExpected = + R"mlir(func.func @funcname() { + %c33_i32 = arith.constant 33 : i32 + %c31_i32 = arith.constant 31 : i32 + %0 = arith.addi %c33_i32, %c31_i32 : i32 + %1 = arith.subi %c33_i32, %c31_i32 : i32 + %2 = arith.muli %c33_i32, %c31_i32 : i32 + %3 = arith.divsi %c33_i32, %c31_i32 : i32 + %4 = arith.remsi %c33_i32, %c31_i32 : i32 + %5 = arith.shrsi %c33_i32, %c31_i32 : i32 + %6 = arith.shli %c33_i32, %c31_i32 : i32 + %7 = arith.andi %c33_i32, %c31_i32 : i32 + %8 = arith.ori %c33_i32, %c31_i32 : i32 + %9 = arith.xori %c33_i32, %c31_i32 : i32 + %10 = arith.cmpi slt, %c33_i32, %c31_i32 : i32 + %11 = arith.cmpi sle, %c33_i32, %c31_i32 : i32 + %12 = arith.andi %10, %11 : i1 + %13 = arith.cmpi sgt, %c33_i32, %c31_i32 : i32 + %14 = arith.andi %12, %13 : i1 + %15 = arith.cmpi sge, %c33_i32, %c31_i32 : i32 + %16 = arith.andi %14, %15 : i1 + %17 = arith.cmpi eq, %c33_i32, %c31_i32 : i32 + %18 = arith.xori %16, %17 : i1 + %19 = arith.cmpi ne, %c33_i32, %c31_i32 : i32 + %20 = arith.xori %18, %19 : i1 + return +})mlir"; + ASSERT_EQ(out, signedExpected); +} + +// check X+Y, where X is compile-time value (like 1) and Y is WrappedValue +TEST_F(ArithTest, EasyBuildSignedOperatorsLHSConst) { + auto out = composeIR( + &context, [](EasyBuilder b) { return int32_t(33); }, + [](EasyBuilder b) { return b(int32_t(31)); }); + const char *signedExpected = + R"mlir(func.func @funcname() { + %c31_i32 = arith.constant 31 : i32 + %c33_i32 = arith.constant 33 : i32 + %0 = arith.addi %c33_i32, %c31_i32 : i32 + %c33_i32_0 = arith.constant 33 : i32 + %1 = arith.subi %c33_i32_0, %c31_i32 : i32 + %c33_i32_1 = arith.constant 33 : i32 + %2 = arith.muli %c33_i32_1, %c31_i32 : i32 + %c33_i32_2 = arith.constant 33 : i32 + %3 = arith.divsi %c33_i32_2, %c31_i32 : i32 + %c33_i32_3 = arith.constant 33 : i32 + %4 = arith.remsi %c33_i32_3, %c31_i32 : i32 + %c33_i32_4 = arith.constant 33 : i32 + %5 = arith.shrsi %c33_i32_4, %c31_i32 : i32 + %c33_i32_5 = arith.constant 33 : i32 + %6 = arith.shli %c33_i32_5, %c31_i32 : i32 + %c33_i32_6 = arith.constant 33 : i32 + %7 = arith.andi %c33_i32_6, %c31_i32 : i32 + %c33_i32_7 = arith.constant 33 : i32 + %8 = arith.ori %c33_i32_7, %c31_i32 : i32 + %c33_i32_8 = arith.constant 33 : i32 + %9 = arith.xori %c33_i32_8, %c31_i32 : i32 + %c33_i32_9 = arith.constant 33 : i32 + %10 = arith.cmpi slt, %c33_i32_9, %c31_i32 : i32 + %c33_i32_10 = arith.constant 33 : i32 + %11 = arith.cmpi sle, %c33_i32_10, %c31_i32 : i32 + %12 = arith.andi %10, %11 : i1 + %c33_i32_11 = arith.constant 33 : i32 + %13 = arith.cmpi sgt, %c33_i32_11, %c31_i32 : i32 + %14 = arith.andi %12, %13 : i1 + %c33_i32_12 = arith.constant 33 : i32 + %15 = arith.cmpi sge, %c33_i32_12, %c31_i32 : i32 + %16 = arith.andi %14, %15 : i1 + %c33_i32_13 = arith.constant 33 : i32 + %17 = arith.cmpi eq, %c33_i32_13, %c31_i32 : i32 + %18 = arith.xori %16, %17 : i1 + %c33_i32_14 = arith.constant 33 : i32 + %19 = arith.cmpi ne, %c33_i32_14, %c31_i32 : i32 + %20 = arith.xori %18, %19 : i1 + return +})mlir"; + ASSERT_EQ(out, signedExpected); +} + +// check X+Y, where Y is compile-time value (like 1) and X is WrappedValue +TEST_F(ArithTest, EasyBuildSignedOperatorsRHSConst) { + auto out = composeIR( + &context, [](EasyBuilder b) { return b(int32_t(33)); }, + [](EasyBuilder b) { return int32_t(31); }); + const char *signedExpected = + R"mlir(func.func @funcname() { + %c33_i32 = arith.constant 33 : i32 + %c31_i32 = arith.constant 31 : i32 + %0 = arith.addi %c33_i32, %c31_i32 : i32 + %c31_i32_0 = arith.constant 31 : i32 + %1 = arith.subi %c33_i32, %c31_i32_0 : i32 + %c31_i32_1 = arith.constant 31 : i32 + %2 = arith.muli %c33_i32, %c31_i32_1 : i32 + %c31_i32_2 = arith.constant 31 : i32 + %3 = arith.divsi %c33_i32, %c31_i32_2 : i32 + %c31_i32_3 = arith.constant 31 : i32 + %4 = arith.remsi %c33_i32, %c31_i32_3 : i32 + %c31_i32_4 = arith.constant 31 : i32 + %5 = arith.shrsi %c33_i32, %c31_i32_4 : i32 + %c31_i32_5 = arith.constant 31 : i32 + %6 = arith.shli %c33_i32, %c31_i32_5 : i32 + %c31_i32_6 = arith.constant 31 : i32 + %7 = arith.andi %c33_i32, %c31_i32_6 : i32 + %c31_i32_7 = arith.constant 31 : i32 + %8 = arith.ori %c33_i32, %c31_i32_7 : i32 + %c31_i32_8 = arith.constant 31 : i32 + %9 = arith.xori %c33_i32, %c31_i32_8 : i32 + %c31_i32_9 = arith.constant 31 : i32 + %10 = arith.cmpi slt, %c33_i32, %c31_i32_9 : i32 + %c31_i32_10 = arith.constant 31 : i32 + %11 = arith.cmpi sle, %c33_i32, %c31_i32_10 : i32 + %12 = arith.andi %10, %11 : i1 + %c31_i32_11 = arith.constant 31 : i32 + %13 = arith.cmpi sgt, %c33_i32, %c31_i32_11 : i32 + %14 = arith.andi %12, %13 : i1 + %c31_i32_12 = arith.constant 31 : i32 + %15 = arith.cmpi sge, %c33_i32, %c31_i32_12 : i32 + %16 = arith.andi %14, %15 : i1 + %c31_i32_13 = arith.constant 31 : i32 + %17 = arith.cmpi eq, %c33_i32, %c31_i32_13 : i32 + %18 = arith.xori %16, %17 : i1 + %c31_i32_14 = arith.constant 31 : i32 + %19 = arith.cmpi ne, %c33_i32, %c31_i32_14 : i32 + %20 = arith.xori %18, %19 : i1 + return +})mlir"; + ASSERT_EQ(out, signedExpected); +} + +// check X+Y, where both X and Y are WrappedValues +TEST_F(ArithTest, EasyBuildUnsignedOperatorsBothValues) { + auto out = composeIR( + &context, [](EasyBuilder b) { return b(uint32_t(33)); }, + [](EasyBuilder b) { return b(uint32_t(31)); }); + const char *unsignedExpected = + R"mlir(func.func @funcname() { + %c33_i32 = arith.constant 33 : i32 + %c31_i32 = arith.constant 31 : i32 + %0 = arith.addi %c33_i32, %c31_i32 : i32 + %1 = arith.subi %c33_i32, %c31_i32 : i32 + %2 = arith.muli %c33_i32, %c31_i32 : i32 + %3 = arith.divui %c33_i32, %c31_i32 : i32 + %4 = arith.remui %c33_i32, %c31_i32 : i32 + %5 = arith.shrui %c33_i32, %c31_i32 : i32 + %6 = arith.shli %c33_i32, %c31_i32 : i32 + %7 = arith.andi %c33_i32, %c31_i32 : i32 + %8 = arith.ori %c33_i32, %c31_i32 : i32 + %9 = arith.xori %c33_i32, %c31_i32 : i32 + %10 = arith.cmpi ult, %c33_i32, %c31_i32 : i32 + %11 = arith.cmpi ule, %c33_i32, %c31_i32 : i32 + %12 = arith.andi %10, %11 : i1 + %13 = arith.cmpi ugt, %c33_i32, %c31_i32 : i32 + %14 = arith.andi %12, %13 : i1 + %15 = arith.cmpi uge, %c33_i32, %c31_i32 : i32 + %16 = arith.andi %14, %15 : i1 + %17 = arith.cmpi eq, %c33_i32, %c31_i32 : i32 + %18 = arith.xori %16, %17 : i1 + %19 = arith.cmpi ne, %c33_i32, %c31_i32 : i32 + %20 = arith.xori %18, %19 : i1 + return +})mlir"; + ASSERT_EQ(out, unsignedExpected); +} + +// check X+Y, where X is compile-time value (like 1) and Y is WrappedValue +TEST_F(ArithTest, EasyBuildUnsignedOperatorsLHSConst) { + auto out = composeIR( + &context, [](EasyBuilder b) { return uint32_t(33); }, + [](EasyBuilder b) { return b(uint32_t(31)); }); + const char *unsignedExpected = + R"mlir(func.func @funcname() { + %c31_i32 = arith.constant 31 : i32 + %c33_i32 = arith.constant 33 : i32 + %0 = arith.addi %c33_i32, %c31_i32 : i32 + %c33_i32_0 = arith.constant 33 : i32 + %1 = arith.subi %c33_i32_0, %c31_i32 : i32 + %c33_i32_1 = arith.constant 33 : i32 + %2 = arith.muli %c33_i32_1, %c31_i32 : i32 + %c33_i32_2 = arith.constant 33 : i32 + %3 = arith.divui %c33_i32_2, %c31_i32 : i32 + %c33_i32_3 = arith.constant 33 : i32 + %4 = arith.remui %c33_i32_3, %c31_i32 : i32 + %c33_i32_4 = arith.constant 33 : i32 + %5 = arith.shrui %c33_i32_4, %c31_i32 : i32 + %c33_i32_5 = arith.constant 33 : i32 + %6 = arith.shli %c33_i32_5, %c31_i32 : i32 + %c33_i32_6 = arith.constant 33 : i32 + %7 = arith.andi %c33_i32_6, %c31_i32 : i32 + %c33_i32_7 = arith.constant 33 : i32 + %8 = arith.ori %c33_i32_7, %c31_i32 : i32 + %c33_i32_8 = arith.constant 33 : i32 + %9 = arith.xori %c33_i32_8, %c31_i32 : i32 + %c33_i32_9 = arith.constant 33 : i32 + %10 = arith.cmpi ult, %c33_i32_9, %c31_i32 : i32 + %c33_i32_10 = arith.constant 33 : i32 + %11 = arith.cmpi ule, %c33_i32_10, %c31_i32 : i32 + %12 = arith.andi %10, %11 : i1 + %c33_i32_11 = arith.constant 33 : i32 + %13 = arith.cmpi ugt, %c33_i32_11, %c31_i32 : i32 + %14 = arith.andi %12, %13 : i1 + %c33_i32_12 = arith.constant 33 : i32 + %15 = arith.cmpi uge, %c33_i32_12, %c31_i32 : i32 + %16 = arith.andi %14, %15 : i1 + %c33_i32_13 = arith.constant 33 : i32 + %17 = arith.cmpi eq, %c33_i32_13, %c31_i32 : i32 + %18 = arith.xori %16, %17 : i1 + %c33_i32_14 = arith.constant 33 : i32 + %19 = arith.cmpi ne, %c33_i32_14, %c31_i32 : i32 + %20 = arith.xori %18, %19 : i1 + return +})mlir"; + ASSERT_EQ(out, unsignedExpected); +} + +// check X+Y, where Y is compile-time value (like 1) and X is WrappedValue +TEST_F(ArithTest, EasyBuildUnsignedOperatorsRHSConst) { + auto out = composeIR( + &context, [](EasyBuilder b) { return b(uint32_t(33)); }, + [](EasyBuilder b) { return uint32_t(31); }); + const char *unsignedExpected = + R"mlir(func.func @funcname() { + %c33_i32 = arith.constant 33 : i32 + %c31_i32 = arith.constant 31 : i32 + %0 = arith.addi %c33_i32, %c31_i32 : i32 + %c31_i32_0 = arith.constant 31 : i32 + %1 = arith.subi %c33_i32, %c31_i32_0 : i32 + %c31_i32_1 = arith.constant 31 : i32 + %2 = arith.muli %c33_i32, %c31_i32_1 : i32 + %c31_i32_2 = arith.constant 31 : i32 + %3 = arith.divui %c33_i32, %c31_i32_2 : i32 + %c31_i32_3 = arith.constant 31 : i32 + %4 = arith.remui %c33_i32, %c31_i32_3 : i32 + %c31_i32_4 = arith.constant 31 : i32 + %5 = arith.shrui %c33_i32, %c31_i32_4 : i32 + %c31_i32_5 = arith.constant 31 : i32 + %6 = arith.shli %c33_i32, %c31_i32_5 : i32 + %c31_i32_6 = arith.constant 31 : i32 + %7 = arith.andi %c33_i32, %c31_i32_6 : i32 + %c31_i32_7 = arith.constant 31 : i32 + %8 = arith.ori %c33_i32, %c31_i32_7 : i32 + %c31_i32_8 = arith.constant 31 : i32 + %9 = arith.xori %c33_i32, %c31_i32_8 : i32 + %c31_i32_9 = arith.constant 31 : i32 + %10 = arith.cmpi ult, %c33_i32, %c31_i32_9 : i32 + %c31_i32_10 = arith.constant 31 : i32 + %11 = arith.cmpi ule, %c33_i32, %c31_i32_10 : i32 + %12 = arith.andi %10, %11 : i1 + %c31_i32_11 = arith.constant 31 : i32 + %13 = arith.cmpi ugt, %c33_i32, %c31_i32_11 : i32 + %14 = arith.andi %12, %13 : i1 + %c31_i32_12 = arith.constant 31 : i32 + %15 = arith.cmpi uge, %c33_i32, %c31_i32_12 : i32 + %16 = arith.andi %14, %15 : i1 + %c31_i32_13 = arith.constant 31 : i32 + %17 = arith.cmpi eq, %c33_i32, %c31_i32_13 : i32 + %18 = arith.xori %16, %17 : i1 + %c31_i32_14 = arith.constant 31 : i32 + %19 = arith.cmpi ne, %c33_i32, %c31_i32_14 : i32 + %20 = arith.xori %18, %19 : i1 + return +})mlir"; + ASSERT_EQ(out, unsignedExpected); +} + +template +static std::string composeFPIR(MLIRContext *context, T1 &&getA, T2 &&getB) { + OpBuilder builder{context}; + auto loc = builder.getUnknownLoc(); + EasyBuilder b{builder, loc}; + auto func = builder.create( + loc, "funcname", FunctionType::get(builder.getContext(), {}, {})); + builder.setInsertionPointToStart(func.addEntryBlock()); + auto A = getA(b); + auto B = getB(b); + auto v1 = A + B; + v1 = A - B; + v1 = A * B; + v1 = A / B; + v1 = A % B; + (void)-A; + auto cmp = A < B; + cmp = cmp & (A <= B); + cmp = cmp & (A > B); + cmp = cmp & (A >= B); + cmp = cmp ^ (A == B); + cmp = cmp ^ (A != B); + builder.create(loc); + + std::string out; + llvm::raw_string_ostream os{out}; + os << func; + return out; +} + +// check X+Y, where both X and Y are WrappedValues +TEST_F(ArithTest, EasyBuildFloatOperatorsValues) { + SKIP_IF_UNEXPECTED_FP_SIZE() + auto out = composeFPIR( + &context, [](EasyBuilder b) { return b(33.0f); }, + [](EasyBuilder b) { return b(31.0f); }); + const char *expected = + R"mlir(func.func @funcname() { + %cst = arith.constant 3.300000e+01 : f32 + %cst_0 = arith.constant 3.100000e+01 : f32 + %0 = arith.addf %cst, %cst_0 : f32 + %1 = arith.subf %cst, %cst_0 : f32 + %2 = arith.mulf %cst, %cst_0 : f32 + %3 = arith.divf %cst, %cst_0 : f32 + %4 = arith.remf %cst, %cst_0 : f32 + %5 = arith.negf %cst : f32 + %6 = arith.cmpf olt, %cst, %cst_0 : f32 + %7 = arith.cmpf ole, %cst, %cst_0 : f32 + %8 = arith.andi %6, %7 : i1 + %9 = arith.cmpf ogt, %cst, %cst_0 : f32 + %10 = arith.andi %8, %9 : i1 + %11 = arith.cmpf oge, %cst, %cst_0 : f32 + %12 = arith.andi %10, %11 : i1 + %13 = arith.cmpf oeq, %cst, %cst_0 : f32 + %14 = arith.xori %12, %13 : i1 + %15 = arith.cmpf one, %cst, %cst_0 : f32 + %16 = arith.xori %14, %15 : i1 + return +})mlir"; + ASSERT_EQ(out, expected); +} + +// check X+Y, where X is compile-time value (like 1) and Y is WrappedValue +TEST_F(ArithTest, EasyBuildFloatOperatorsLHSConst) { + SKIP_IF_UNEXPECTED_FP_SIZE() + auto out = composeFPIR( + &context, [](EasyBuilder b) { return 33.0f; }, + [](EasyBuilder b) { return b(31.0f); }); + const char *expected = + R"mlir(func.func @funcname() { + %cst = arith.constant 3.100000e+01 : f32 + %cst_0 = arith.constant 3.300000e+01 : f32 + %0 = arith.addf %cst_0, %cst : f32 + %cst_1 = arith.constant 3.300000e+01 : f32 + %1 = arith.subf %cst_1, %cst : f32 + %cst_2 = arith.constant 3.300000e+01 : f32 + %2 = arith.mulf %cst_2, %cst : f32 + %cst_3 = arith.constant 3.300000e+01 : f32 + %3 = arith.divf %cst_3, %cst : f32 + %cst_4 = arith.constant 3.300000e+01 : f32 + %4 = arith.remf %cst_4, %cst : f32 + %cst_5 = arith.constant 3.300000e+01 : f32 + %5 = arith.cmpf olt, %cst_5, %cst : f32 + %cst_6 = arith.constant 3.300000e+01 : f32 + %6 = arith.cmpf ole, %cst_6, %cst : f32 + %7 = arith.andi %5, %6 : i1 + %cst_7 = arith.constant 3.300000e+01 : f32 + %8 = arith.cmpf ogt, %cst_7, %cst : f32 + %9 = arith.andi %7, %8 : i1 + %cst_8 = arith.constant 3.300000e+01 : f32 + %10 = arith.cmpf oge, %cst_8, %cst : f32 + %11 = arith.andi %9, %10 : i1 + %cst_9 = arith.constant 3.300000e+01 : f32 + %12 = arith.cmpf oeq, %cst_9, %cst : f32 + %13 = arith.xori %11, %12 : i1 + %cst_10 = arith.constant 3.300000e+01 : f32 + %14 = arith.cmpf one, %cst_10, %cst : f32 + %15 = arith.xori %13, %14 : i1 + return +})mlir"; + ASSERT_EQ(out, expected); +} + +// check X+Y, where Y is compile-time value (like 1) and X is WrappedValue +TEST_F(ArithTest, EasyBuildFloatOperatorsRHSConst) { + SKIP_IF_UNEXPECTED_FP_SIZE() + auto out = composeFPIR( + &context, [](EasyBuilder b) { return b(33.0f); }, + [](EasyBuilder b) { return 31.0f; }); + const char *expected = + R"mlir(func.func @funcname() { + %cst = arith.constant 3.300000e+01 : f32 + %cst_0 = arith.constant 3.100000e+01 : f32 + %0 = arith.addf %cst, %cst_0 : f32 + %cst_1 = arith.constant 3.100000e+01 : f32 + %1 = arith.subf %cst, %cst_1 : f32 + %cst_2 = arith.constant 3.100000e+01 : f32 + %2 = arith.mulf %cst, %cst_2 : f32 + %cst_3 = arith.constant 3.100000e+01 : f32 + %3 = arith.divf %cst, %cst_3 : f32 + %cst_4 = arith.constant 3.100000e+01 : f32 + %4 = arith.remf %cst, %cst_4 : f32 + %5 = arith.negf %cst : f32 + %cst_5 = arith.constant 3.100000e+01 : f32 + %6 = arith.cmpf olt, %cst, %cst_5 : f32 + %cst_6 = arith.constant 3.100000e+01 : f32 + %7 = arith.cmpf ole, %cst, %cst_6 : f32 + %8 = arith.andi %6, %7 : i1 + %cst_7 = arith.constant 3.100000e+01 : f32 + %9 = arith.cmpf ogt, %cst, %cst_7 : f32 + %10 = arith.andi %8, %9 : i1 + %cst_8 = arith.constant 3.100000e+01 : f32 + %11 = arith.cmpf oge, %cst, %cst_8 : f32 + %12 = arith.andi %10, %11 : i1 + %cst_9 = arith.constant 3.100000e+01 : f32 + %13 = arith.cmpf oeq, %cst, %cst_9 : f32 + %14 = arith.xori %12, %13 : i1 + %cst_10 = arith.constant 3.100000e+01 : f32 + %15 = arith.cmpf one, %cst, %cst_10 : f32 + %16 = arith.xori %14, %15 : i1 + return +})mlir"; + ASSERT_EQ(out, expected); +} + +// check wrap() +TEST_F(ArithTest, EasyBuildCheckWrap) { + OpBuilder builder{&context}; + auto loc = builder.getUnknownLoc(); + EasyBuilder b{builder, loc}; + auto func = builder.create( + loc, "funcname", + FunctionType::get(&context, + {MemRefType::get({100}, IntegerType::get(&context, 16)), + IntegerType::get(&context, 16)}, + {})); + + builder.setInsertionPointToStart(func.addEntryBlock()); + // arg0 is of memref type + auto arg0 = func.getArgument(0); + EBValue wb = b(arg0); // check that it is ok to wrap generic value to EBValue + auto expectedFail = b.wrapOrFail(arg0); + ASSERT_TRUE(failed(expectedFail)); + + auto arg1 = func.getArgument(1); + auto expectedFail1 = b.wrapOrFail(arg1); + ASSERT_TRUE(failed(expectedFail1)); + auto expectedOK1 = b.wrapOrFail(arg1); + ASSERT_TRUE(succeeded(expectedOK1)); + EBUnsigned u = b.wrap(arg1); + + OpFoldResult foldresult = arg1; + expectedFail1 = b.wrapOrFail(foldresult); + ASSERT_TRUE(failed(expectedFail1)); + expectedOK1 = b.wrapOrFail(foldresult); + ASSERT_TRUE(succeeded(expectedOK1)); + u = b.wrap(foldresult); + + foldresult = builder.getIndexAttr(123); + expectedFail1 = b.wrapOrFail(foldresult); + ASSERT_TRUE(failed(expectedFail1)); + expectedOK1 = b.wrapOrFail(foldresult); + ASSERT_TRUE(succeeded(expectedOK1)); + u = b.wrap(foldresult); +} + +TEST_F(ArithTest, EasyBuildCheckOpCall) { + OpBuilder builder{&context}; + auto loc = builder.getUnknownLoc(); + EasyBuilder b{builder, loc}; + auto func = builder.create( + loc, "funcname", + FunctionType::get(&context, {IntegerType::get(&context, 16)}, {})); + + builder.setInsertionPointToStart(func.addEntryBlock()); + + auto arg0 = func.getArgument(0); + auto v = b.wrap(arg0); + auto v2 = b.F(v, b(uint16_t(1))); + v2 = b.F(v2, b(uint16_t(100))); + builder.create(loc); + + const char *expected = + R"mlir(func.func @funcname(%arg0: i16) { + %c1_i16 = arith.constant 1 : i16 + %0 = arith.minui %arg0, %c1_i16 : i16 + %c100_i16 = arith.constant 100 : i16 + %1 = arith.maxui %0, %c100_i16 : i16 + return +})mlir"; + std::string out; + llvm::raw_string_ostream os{out}; + os << func; + ASSERT_EQ(out, expected); +} diff --git a/unittests/Dialect/CMakeLists.txt b/unittests/Dialect/CMakeLists.txt new file mode 100644 index 000000000..42445996f --- /dev/null +++ b/unittests/Dialect/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(Arith) \ No newline at end of file diff --git a/unittests/Example/CMakeLists.txt b/unittests/Example/CMakeLists.txt deleted file mode 100644 index 2439010b5..000000000 --- a/unittests/Example/CMakeLists.txt +++ /dev/null @@ -1,6 +0,0 @@ -add_mlir_unittest(GCExampleTests - Example.cpp -) -target_link_libraries(GCExampleTests - PRIVATE - MLIRLinalgx) diff --git a/unittests/Example/Example.cpp b/unittests/Example/Example.cpp deleted file mode 100644 index 9a1b27a45..000000000 --- a/unittests/Example/Example.cpp +++ /dev/null @@ -1,14 +0,0 @@ -//===- Example.cpp - Tests for Example ------------------------------------===// -// -// 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 "gc-dialects/Linalgx/LinalgxDialect.h" -#include "gtest/gtest.h" - -TEST(example, HelloWorld) { - ASSERT_EQ(mlir::linalgx::LinalgxDialect::getDialectNamespace(), "linalgx"); -} From 5eff092bd6a75bc01259e525b6764ebc3bea2d2b Mon Sep 17 00:00:00 2001 From: "Mei, Yijie" Date: Fri, 10 May 2024 11:00:16 +0800 Subject: [PATCH 7/7] update header --- include/gc/Dialect/Arith/Utils/EasyBuild.h | 7 +++--- include/gc/IR/EasyBuild.h | 26 +++++++++------------- 2 files changed, 13 insertions(+), 20 deletions(-) diff --git a/include/gc/Dialect/Arith/Utils/EasyBuild.h b/include/gc/Dialect/Arith/Utils/EasyBuild.h index 2a3c21483..2a45ffcee 100644 --- a/include/gc/Dialect/Arith/Utils/EasyBuild.h +++ b/include/gc/Dialect/Arith/Utils/EasyBuild.h @@ -6,10 +6,9 @@ // //===----------------------------------------------------------------------===// // -// This header file defines prototypes for various transformation utilities for -// the Arith dialect. These are not passes by themselves but are used -// either by passes, optimization sequences, or in turn by other transformation -// utilities. +// This header file defines the easy-build utilities for arith dialects. It +// provides the utility functions, classes and operators to make it easir to +// program arith dialect operations in C++ // //===----------------------------------------------------------------------===// diff --git a/include/gc/IR/EasyBuild.h b/include/gc/IR/EasyBuild.h index 1f8f2b4e2..da3da952d 100644 --- a/include/gc/IR/EasyBuild.h +++ b/include/gc/IR/EasyBuild.h @@ -1,4 +1,4 @@ -//===- EasyBuild.h - Easy IR Builder utilities -----------------*- C++ -*-===// +//===- EasyBuild.h - Easy IR Builder utilities ------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -6,10 +6,8 @@ // //===----------------------------------------------------------------------===// // -// This header file defines prototypes for various transformation utilities for -// the Arith dialect. These are not passes by themselves but are used -// either by passes, optimization sequences, or in turn by other transformation -// utilities. +// This header file defines the easy-build utilities core data structures for +// building IR. // //===----------------------------------------------------------------------===// @@ -44,7 +42,7 @@ struct EBValue { Value get() const { return v; } operator Value() const { return v; } - static FailureOr wrapOrFail(const impl::StatePtr& state, Value v) { + static FailureOr wrapOrFail(const impl::StatePtr &state, Value v) { return EBValue{state, v}; } }; @@ -60,13 +58,11 @@ struct EasyBuilder { : builder{builder} {} void setLoc(const Location &l) { builder->loc = l; } - template - auto wrapOrFail(V &&v) { + template auto wrapOrFail(V &&v) { return W::wrapOrFail(builder, std::forward(v)); } - template - auto wrap(V &&v) { + template auto wrap(V &&v) { auto ret = wrapOrFail(std::forward(v)); if (failed(ret)) { llvm_unreachable("wrap failed!"); @@ -74,17 +70,15 @@ struct EasyBuilder { return *ret; } - template - auto operator()(V &&v) { + template auto operator()(V &&v) { if constexpr (std::is_convertible_v) { - return EBValue{builder, std::forward(v)}; + return EBValue{builder, std::forward(v)}; } else { - return wrap(std::forward(v)); + return wrap(std::forward(v)); } } - template - auto toIndex(uint64_t v) const { + template auto toIndex(uint64_t v) const { return W::toIndex(builder, v); }