diff --git a/mlir/include/mlir/Dialect/SPIRV/CMakeLists.txt b/mlir/include/mlir/Dialect/SPIRV/CMakeLists.txt --- a/mlir/include/mlir/Dialect/SPIRV/CMakeLists.txt +++ b/mlir/include/mlir/Dialect/SPIRV/CMakeLists.txt @@ -19,7 +19,7 @@ mlir_tablegen(SPIRVOpUtils.inc -gen-spirv-op-utils) add_public_tablegen_target(MLIRSPIRVOpUtilsGen) -set(LLVM_TARGET_DEFINITIONS SPIRVLowering.td) -mlir_tablegen(SPIRVLowering.h.inc -gen-struct-attr-decls) -mlir_tablegen(SPIRVLowering.cpp.inc -gen-struct-attr-defs) -add_public_tablegen_target(MLIRSPIRVLoweringStructGen) +set(LLVM_TARGET_DEFINITIONS TargetAndABI.td) +mlir_tablegen(TargetAndABI.h.inc -gen-struct-attr-decls) +mlir_tablegen(TargetAndABI.cpp.inc -gen-struct-attr-defs) +add_public_tablegen_target(MLIRSPIRVTargetAndABIIncGen) diff --git a/mlir/include/mlir/Dialect/SPIRV/SPIRVLowering.h b/mlir/include/mlir/Dialect/SPIRV/SPIRVLowering.h --- a/mlir/include/mlir/Dialect/SPIRV/SPIRVLowering.h +++ b/mlir/include/mlir/Dialect/SPIRV/SPIRVLowering.h @@ -13,11 +13,8 @@ #ifndef MLIR_DIALECT_SPIRV_SPIRVLOWERING_H #define MLIR_DIALECT_SPIRV_SPIRVLOWERING_H -#include "mlir/Dialect/SPIRV/SPIRVOps.h" -#include "mlir/IR/Attributes.h" -#include "mlir/Support/StringExtras.h" +#include "mlir/Dialect/SPIRV/TargetAndABI.h" #include "mlir/Transforms/DialectConversion.h" -#include "llvm/ADT/SetVector.h" namespace mlir { @@ -50,36 +47,18 @@ SPIRVTypeConverter &typeConverter; }; -#include "mlir/Dialect/SPIRV/SPIRVLowering.h.inc" - namespace spirv { +enum class BuiltIn : uint32_t; + /// Returns a value that represents a builtin variable value within the SPIR-V /// module. -Value getBuiltinVariableValue(Operation *op, spirv::BuiltIn builtin, +Value getBuiltinVariableValue(Operation *op, BuiltIn builtin, OpBuilder &builder); -/// Attribute name for specifying argument ABI information. -StringRef getInterfaceVarABIAttrName(); - -/// Get the InterfaceVarABIAttr given its fields. -InterfaceVarABIAttr getInterfaceVarABIAttr(unsigned descriptorSet, - unsigned binding, - spirv::StorageClass storageClass, - MLIRContext *context); - -/// Attribute name for specifying entry point information. -StringRef getEntryPointABIAttrName(); - -/// Get the EntryPointABIAttr given its fields. -EntryPointABIAttr getEntryPointABIAttr(ArrayRef localSize, - MLIRContext *context); - /// Sets the InterfaceVarABIAttr and EntryPointABIAttr for a function and its -/// arguments -LogicalResult setABIAttrs(FuncOp funcOp, - spirv::EntryPointABIAttr entryPointInfo, - ArrayRef argABIInfo); - +/// arguments. +LogicalResult setABIAttrs(FuncOp funcOp, EntryPointABIAttr entryPointInfo, + ArrayRef argABIInfo); } // namespace spirv } // namespace mlir diff --git a/mlir/include/mlir/Dialect/SPIRV/TargetAndABI.h b/mlir/include/mlir/Dialect/SPIRV/TargetAndABI.h new file mode 100644 --- /dev/null +++ b/mlir/include/mlir/Dialect/SPIRV/TargetAndABI.h @@ -0,0 +1,48 @@ +//===- TargetAndABI.h - SPIR-V target and ABI utilities --------*- C++ -*-===// +// +// Part of the MLIR 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 file declares utilities for SPIR-V target and shader interface ABI. +// +//===----------------------------------------------------------------------===// + +#ifndef MLIR_DIALECT_SPIRV_TARGETANDABI_H +#define MLIR_DIALECT_SPIRV_TARGETANDABI_H + +#include "mlir/IR/Attributes.h" +#include "mlir/Support/LLVM.h" + +namespace mlir { +class OpBuilder; +class Operation; +class Value; + +// Pull in SPIR-V attribute definitions. +#include "mlir/Dialect/SPIRV/TargetAndABI.h.inc" + +namespace spirv { +enum class StorageClass : uint32_t; + +/// Attribute name for specifying argument ABI information. +StringRef getInterfaceVarABIAttrName(); + +/// Get the InterfaceVarABIAttr given its fields. +InterfaceVarABIAttr getInterfaceVarABIAttr(unsigned descriptorSet, + unsigned binding, + StorageClass storageClass, + MLIRContext *context); + +/// Attribute name for specifying entry point information. +StringRef getEntryPointABIAttrName(); + +/// Get the EntryPointABIAttr given its fields. +EntryPointABIAttr getEntryPointABIAttr(ArrayRef localSize, + MLIRContext *context); +} // namespace spirv +} // namespace mlir + +#endif // MLIR_DIALECT_SPIRV_TARGETANDABI_H diff --git a/mlir/include/mlir/Dialect/SPIRV/SPIRVLowering.td b/mlir/include/mlir/Dialect/SPIRV/TargetAndABI.td rename from mlir/include/mlir/Dialect/SPIRV/SPIRVLowering.td rename to mlir/include/mlir/Dialect/SPIRV/TargetAndABI.td diff --git a/mlir/lib/Dialect/SPIRV/CMakeLists.txt b/mlir/lib/Dialect/SPIRV/CMakeLists.txt --- a/mlir/lib/Dialect/SPIRV/CMakeLists.txt +++ b/mlir/lib/Dialect/SPIRV/CMakeLists.txt @@ -9,6 +9,7 @@ SPIRVOps.cpp SPIRVLowering.cpp SPIRVTypes.cpp + TargetAndABI.cpp ADDITIONAL_HEADER_DIRS ${MLIR_MAIN_INCLUDE_DIR}/mlir/SPIRV @@ -18,9 +19,9 @@ MLIRSPIRVAvailabilityIncGen MLIRSPIRVCanonicalizationIncGen MLIRSPIRVEnumsIncGen - MLIRSPIRVLoweringStructGen MLIRSPIRVOpsIncGen - MLIRSPIRVOpUtilsGen) + MLIRSPIRVOpUtilsGen + MLIRSPIRVTargetAndABIIncGen) target_link_libraries(MLIRSPIRV MLIRIR diff --git a/mlir/lib/Dialect/SPIRV/SPIRVLowering.cpp b/mlir/lib/Dialect/SPIRV/SPIRVLowering.cpp --- a/mlir/lib/Dialect/SPIRV/SPIRVLowering.cpp +++ b/mlir/lib/Dialect/SPIRV/SPIRVLowering.cpp @@ -9,53 +9,16 @@ // This file implements utilities used to lower to SPIR-V dialect. // //===----------------------------------------------------------------------===// + #include "mlir/Dialect/SPIRV/SPIRVLowering.h" #include "mlir/Dialect/SPIRV/LayoutUtils.h" #include "mlir/Dialect/SPIRV/SPIRVDialect.h" +#include "mlir/Dialect/SPIRV/SPIRVOps.h" #include "llvm/ADT/Sequence.h" using namespace mlir; //===----------------------------------------------------------------------===// -// Attributes for ABI -//===----------------------------------------------------------------------===// - -// Pull in the attributes needed for lowering. -namespace mlir { -#include "mlir/Dialect/SPIRV/SPIRVLowering.cpp.inc" -} - -StringRef mlir::spirv::getInterfaceVarABIAttrName() { - return "spirv.interface_var_abi"; -} - -mlir::spirv::InterfaceVarABIAttr -mlir::spirv::getInterfaceVarABIAttr(unsigned descriptorSet, unsigned binding, - spirv::StorageClass storageClass, - MLIRContext *context) { - Type i32Type = IntegerType::get(32, context); - return mlir::spirv::InterfaceVarABIAttr::get( - IntegerAttr::get(i32Type, descriptorSet), - IntegerAttr::get(i32Type, binding), - IntegerAttr::get(i32Type, static_cast(storageClass)), context); -} - -StringRef mlir::spirv::getEntryPointABIAttrName() { - return "spirv.entry_point_abi"; -} - -mlir::spirv::EntryPointABIAttr -mlir::spirv::getEntryPointABIAttr(ArrayRef localSize, - MLIRContext *context) { - assert(localSize.size() == 3); - return mlir::spirv::EntryPointABIAttr::get( - DenseElementsAttr::get( - VectorType::get(3, IntegerType::get(32, context)), localSize) - .cast(), - context); -} - -//===----------------------------------------------------------------------===// // Type Conversion //===----------------------------------------------------------------------===// diff --git a/mlir/lib/Dialect/SPIRV/TargetAndABI.cpp b/mlir/lib/Dialect/SPIRV/TargetAndABI.cpp new file mode 100644 --- /dev/null +++ b/mlir/lib/Dialect/SPIRV/TargetAndABI.cpp @@ -0,0 +1,47 @@ +//===- SPIRVLowering.cpp - Standard to SPIR-V dialect conversion--===// +// +// Part of the MLIR 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/SPIRV/TargetAndABI.h" +#include "mlir/Dialect/SPIRV/SPIRVTypes.h" +#include "mlir/IR/Operation.h" + +using namespace mlir; + +namespace mlir { +#include "mlir/Dialect/SPIRV/TargetAndABI.cpp.inc" +} + +StringRef mlir::spirv::getInterfaceVarABIAttrName() { + return "spirv.interface_var_abi"; +} + +mlir::spirv::InterfaceVarABIAttr +mlir::spirv::getInterfaceVarABIAttr(unsigned descriptorSet, unsigned binding, + spirv::StorageClass storageClass, + MLIRContext *context) { + Type i32Type = IntegerType::get(32, context); + return mlir::spirv::InterfaceVarABIAttr::get( + IntegerAttr::get(i32Type, descriptorSet), + IntegerAttr::get(i32Type, binding), + IntegerAttr::get(i32Type, static_cast(storageClass)), context); +} + +StringRef mlir::spirv::getEntryPointABIAttrName() { + return "spirv.entry_point_abi"; +} + +mlir::spirv::EntryPointABIAttr +mlir::spirv::getEntryPointABIAttr(ArrayRef localSize, + MLIRContext *context) { + assert(localSize.size() == 3); + return mlir::spirv::EntryPointABIAttr::get( + DenseElementsAttr::get( + VectorType::get(3, IntegerType::get(32, context)), localSize) + .cast(), + context); +} diff --git a/mlir/lib/Dialect/SPIRV/Transforms/LowerABIAttributesPass.cpp b/mlir/lib/Dialect/SPIRV/Transforms/LowerABIAttributesPass.cpp --- a/mlir/lib/Dialect/SPIRV/Transforms/LowerABIAttributesPass.cpp +++ b/mlir/lib/Dialect/SPIRV/Transforms/LowerABIAttributesPass.cpp @@ -15,8 +15,10 @@ #include "mlir/Dialect/SPIRV/Passes.h" #include "mlir/Dialect/SPIRV/SPIRVDialect.h" #include "mlir/Dialect/SPIRV/SPIRVLowering.h" +#include "mlir/Dialect/SPIRV/SPIRVOps.h" #include "mlir/Dialect/StandardOps/Ops.h" #include "mlir/Transforms/DialectConversion.h" +#include "llvm/ADT/SetVector.h" using namespace mlir;