diff --git a/mlir/include/mlir/Dialect/CMakeLists.txt b/mlir/include/mlir/Dialect/CMakeLists.txt --- a/mlir/include/mlir/Dialect/CMakeLists.txt +++ b/mlir/include/mlir/Dialect/CMakeLists.txt @@ -1,6 +1,6 @@ +add_subdirectory(Affine) add_subdirectory(AMDGPU) add_subdirectory(AMX) -add_subdirectory(Affine) add_subdirectory(Arith) add_subdirectory(ArmNeon) add_subdirectory(ArmSME) @@ -15,11 +15,11 @@ add_subdirectory(GPU) add_subdirectory(Index) add_subdirectory(IRDL) -add_subdirectory(LLVMIR) add_subdirectory(Linalg) -add_subdirectory(MLProgram) +add_subdirectory(LLVMIR) add_subdirectory(Math) add_subdirectory(MemRef) +add_subdirectory(MLProgram) add_subdirectory(NVGPU) add_subdirectory(OpenACC) add_subdirectory(OpenMP) @@ -27,12 +27,13 @@ add_subdirectory(PDLInterp) add_subdirectory(Quant) add_subdirectory(SCF) -add_subdirectory(SPIRV) add_subdirectory(Shape) add_subdirectory(SparseTensor) +add_subdirectory(SPIRV) add_subdirectory(Tensor) add_subdirectory(Tosa) add_subdirectory(Transform) +add_subdirectory(Ub) add_subdirectory(Utils) add_subdirectory(Vector) add_subdirectory(X86Vector) diff --git a/mlir/include/mlir/Dialect/Ub/CMakeLists.txt b/mlir/include/mlir/Dialect/Ub/CMakeLists.txt new file mode 100644 --- /dev/null +++ b/mlir/include/mlir/Dialect/Ub/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(IR) diff --git a/mlir/include/mlir/Dialect/Ub/IR/CMakeLists.txt b/mlir/include/mlir/Dialect/Ub/IR/CMakeLists.txt new file mode 100644 --- /dev/null +++ b/mlir/include/mlir/Dialect/Ub/IR/CMakeLists.txt @@ -0,0 +1,8 @@ +set(LLVM_TARGET_DEFINITIONS UbOps.td) +mlir_tablegen(UbOps.h.inc -gen-op-decls) +mlir_tablegen(UbOps.cpp.inc -gen-op-defs) +mlir_tablegen(UbOpsDialect.h.inc -gen-dialect-decls) +mlir_tablegen(UbOpsDialect.cpp.inc -gen-dialect-defs) +add_public_tablegen_target(MLIRUbOpsIncGen) + +add_mlir_doc(FuncOps UbOps Dialects/ -gen-op-doc) diff --git a/mlir/include/mlir/Dialect/Ub/IR/UbOps.h b/mlir/include/mlir/Dialect/Ub/IR/UbOps.h new file mode 100644 --- /dev/null +++ b/mlir/include/mlir/Dialect/Ub/IR/UbOps.h @@ -0,0 +1,21 @@ +//===- FuncOps.h - Ub Dialect Operations ----------------------*--- 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 +// +//===----------------------------------------------------------------------===// + +#ifndef MLIR_DIALECT_UB_IR_OPS_H +#define MLIR_DIALECT_UB_IR_OPS_H + +#include "mlir/IR/Dialect.h" +#include "mlir/IR/OpImplementation.h" +#include "mlir/Interfaces/SideEffectInterfaces.h" + +#define GET_OP_CLASSES +#include "mlir/Dialect/Ub/IR/UbOps.h.inc" + +#include "mlir/Dialect/Ub/IR/UbOpsDialect.h.inc" + +#endif // MLIR_DIALECT_UB_IR_OPS_H diff --git a/mlir/include/mlir/Dialect/Ub/IR/UbOps.td b/mlir/include/mlir/Dialect/Ub/IR/UbOps.td new file mode 100644 --- /dev/null +++ b/mlir/include/mlir/Dialect/Ub/IR/UbOps.td @@ -0,0 +1,40 @@ +//===- FuncOps.td - Ub operation definitions ---------------*- tablegen -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef MLIR_DIALECT_UB_IR_UBOPS_TD +#define MLIR_DIALECT_UB_IR_UBOPS_TD + +include "mlir/Interfaces/SideEffectInterfaces.td" + +def Ub_Dialect : Dialect { + let name = "ub"; + let cppNamespace = "::mlir::ub"; +} + +// Base class for Func dialect ops. +class Ub_Op traits = []> : + Op; + +//===----------------------------------------------------------------------===// +// PoisonOp +//===----------------------------------------------------------------------===// + +def PoisonOp : Ub_Op<"poison", [Pure]> { + let summary = "A poison value is a result of an erroneous operation."; + let description = [{ + In order to facilitate speculative execution, many instructions do not + invoke immediate undefined behavior when provided with illegal operands, + and return a poison value instead. + }]; + + let results = (outs AnyType:$result); + + let assemblyFormat = "attr-dict `:` type($result)"; +} + +#endif // MLIR_DIALECT_UB_IR_UBOPS_TD diff --git a/mlir/include/mlir/InitAllDialects.h b/mlir/include/mlir/InitAllDialects.h --- a/mlir/include/mlir/InitAllDialects.h +++ b/mlir/include/mlir/InitAllDialects.h @@ -79,6 +79,7 @@ #include "mlir/Dialect/Tosa/IR/TosaOps.h" #include "mlir/Dialect/Transform/IR/TransformDialect.h" #include "mlir/Dialect/Transform/PDLExtension/PDLExtension.h" +#include "mlir/Dialect/Ub/IR/UbOps.h" #include "mlir/Dialect/Vector/IR/VectorOps.h" #include "mlir/Dialect/Vector/TransformOps/VectorTransformOps.h" #include "mlir/Dialect/Vector/Transforms/BufferizableOpInterfaceImpl.h" @@ -93,10 +94,12 @@ // clang-format off registry.insert(); // clang-format on diff --git a/mlir/lib/Dialect/CMakeLists.txt b/mlir/lib/Dialect/CMakeLists.txt --- a/mlir/lib/Dialect/CMakeLists.txt +++ b/mlir/lib/Dialect/CMakeLists.txt @@ -1,11 +1,11 @@ add_subdirectory(Affine) add_subdirectory(AMDGPU) +add_subdirectory(AMX) add_subdirectory(Arith) add_subdirectory(ArmNeon) add_subdirectory(ArmSME) add_subdirectory(ArmSVE) add_subdirectory(Async) -add_subdirectory(AMX) add_subdirectory(Bufferization) add_subdirectory(Complex) add_subdirectory(ControlFlow) @@ -33,6 +33,7 @@ add_subdirectory(Tensor) add_subdirectory(Tosa) add_subdirectory(Transform) +add_subdirectory(Ub) add_subdirectory(Utils) add_subdirectory(Vector) add_subdirectory(X86Vector) diff --git a/mlir/lib/Dialect/Ub/CMakeLists.txt b/mlir/lib/Dialect/Ub/CMakeLists.txt new file mode 100644 --- /dev/null +++ b/mlir/lib/Dialect/Ub/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(IR) diff --git a/mlir/lib/Dialect/Ub/IR/CMakeLists.txt b/mlir/lib/Dialect/Ub/IR/CMakeLists.txt new file mode 100644 --- /dev/null +++ b/mlir/lib/Dialect/Ub/IR/CMakeLists.txt @@ -0,0 +1,12 @@ +add_mlir_dialect_library(MLIRUbDialect + UbOps.cpp + + ADDITIONAL_HEADER_DIRS + ${MLIR_MAIN_INCLUDE_DIR}/mlir/Dialect/Ub + + DEPENDS + MLIRUbOpsIncGen + + LINK_LIBS PUBLIC + MLIRIR + ) diff --git a/mlir/lib/Dialect/Ub/IR/UbOps.cpp b/mlir/lib/Dialect/Ub/IR/UbOps.cpp new file mode 100644 --- /dev/null +++ b/mlir/lib/Dialect/Ub/IR/UbOps.cpp @@ -0,0 +1,28 @@ +//===- FuncOps.cpp - Ub Dialect Operations --------------------------------===// +// +// 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 "mlir/Dialect/Ub/IR/UbOps.h" + +#include "mlir/Dialect/Ub/IR/UbOpsDialect.cpp.inc" + +using namespace mlir; +using namespace mlir::ub; + +//===----------------------------------------------------------------------===// +// UbDialect +//===----------------------------------------------------------------------===// + +void UbDialect::initialize() { + addOperations< +#define GET_OP_LIST +#include "mlir/Dialect/Ub/IR/UbOps.cpp.inc" + >(); +} + +#define GET_OP_CLASSES +#include "mlir/Dialect/Ub/IR/UbOps.cpp.inc" diff --git a/mlir/test/Dialect/Ub/ops.mlir b/mlir/test/Dialect/Ub/ops.mlir new file mode 100644 --- /dev/null +++ b/mlir/test/Dialect/Ub/ops.mlir @@ -0,0 +1,12 @@ +// RUN: mlir-opt %s | FileCheck %s +// Verify the printed output can be parsed. +// RUN: mlir-opt %s | mlir-opt | FileCheck %s +// Verify the generic form can be parsed. +// RUN: mlir-opt -mlir-print-op-generic %s | mlir-opt | FileCheck %s + +// CHECK-LABEL: func @poison() +// CHECK: %{{.*}} = ub.poison : i32 +func.func @poison() -> i32 { + %0 = ub.poison : i32 + return %0 : i32 +}