forked from OSchip/llvm-project
[mlir][spirv] NFC: Move shader ABI attributes to a new file
This allows us to include the definitions of these attributes in other files without pulling in all dependencies for lowering. Reviewed By: mravishankar Differential Revision: https://reviews.llvm.org/D72054
This commit is contained in:
parent
5d38b2610f
commit
0359e1d6be
|
@ -19,7 +19,7 @@ set(LLVM_TARGET_DEFINITIONS SPIRVBase.td)
|
|||
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)
|
||||
|
|
|
@ -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 @@ protected:
|
|||
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<int32_t> localSize,
|
||||
MLIRContext *context);
|
||||
|
||||
/// Sets the InterfaceVarABIAttr and EntryPointABIAttr for a function and its
|
||||
/// arguments
|
||||
LogicalResult setABIAttrs(FuncOp funcOp,
|
||||
spirv::EntryPointABIAttr entryPointInfo,
|
||||
ArrayRef<spirv::InterfaceVarABIAttr> argABIInfo);
|
||||
|
||||
/// arguments.
|
||||
LogicalResult setABIAttrs(FuncOp funcOp, EntryPointABIAttr entryPointInfo,
|
||||
ArrayRef<InterfaceVarABIAttr> argABIInfo);
|
||||
} // namespace spirv
|
||||
} // namespace mlir
|
||||
|
||||
|
|
|
@ -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<int32_t> localSize,
|
||||
MLIRContext *context);
|
||||
} // namespace spirv
|
||||
} // namespace mlir
|
||||
|
||||
#endif // MLIR_DIALECT_SPIRV_TARGETANDABI_H
|
|
@ -9,6 +9,7 @@ add_llvm_library(MLIRSPIRV
|
|||
SPIRVOps.cpp
|
||||
SPIRVLowering.cpp
|
||||
SPIRVTypes.cpp
|
||||
TargetAndABI.cpp
|
||||
|
||||
ADDITIONAL_HEADER_DIRS
|
||||
${MLIR_MAIN_INCLUDE_DIR}/mlir/SPIRV
|
||||
|
@ -18,9 +19,9 @@ add_dependencies(MLIRSPIRV
|
|||
MLIRSPIRVAvailabilityIncGen
|
||||
MLIRSPIRVCanonicalizationIncGen
|
||||
MLIRSPIRVEnumsIncGen
|
||||
MLIRSPIRVLoweringStructGen
|
||||
MLIRSPIRVOpsIncGen
|
||||
MLIRSPIRVOpUtilsGen)
|
||||
MLIRSPIRVOpUtilsGen
|
||||
MLIRSPIRVTargetAndABIIncGen)
|
||||
|
||||
target_link_libraries(MLIRSPIRV
|
||||
MLIRIR
|
||||
|
|
|
@ -9,52 +9,15 @@
|
|||
// 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<int64_t>(storageClass)), context);
|
||||
}
|
||||
|
||||
StringRef mlir::spirv::getEntryPointABIAttrName() {
|
||||
return "spirv.entry_point_abi";
|
||||
}
|
||||
|
||||
mlir::spirv::EntryPointABIAttr
|
||||
mlir::spirv::getEntryPointABIAttr(ArrayRef<int32_t> localSize,
|
||||
MLIRContext *context) {
|
||||
assert(localSize.size() == 3);
|
||||
return mlir::spirv::EntryPointABIAttr::get(
|
||||
DenseElementsAttr::get<int32_t>(
|
||||
VectorType::get(3, IntegerType::get(32, context)), localSize)
|
||||
.cast<DenseIntElementsAttr>(),
|
||||
context);
|
||||
}
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// Type Conversion
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
|
|
@ -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<int64_t>(storageClass)), context);
|
||||
}
|
||||
|
||||
StringRef mlir::spirv::getEntryPointABIAttrName() {
|
||||
return "spirv.entry_point_abi";
|
||||
}
|
||||
|
||||
mlir::spirv::EntryPointABIAttr
|
||||
mlir::spirv::getEntryPointABIAttr(ArrayRef<int32_t> localSize,
|
||||
MLIRContext *context) {
|
||||
assert(localSize.size() == 3);
|
||||
return mlir::spirv::EntryPointABIAttr::get(
|
||||
DenseElementsAttr::get<int32_t>(
|
||||
VectorType::get(3, IntegerType::get(32, context)), localSize)
|
||||
.cast<DenseIntElementsAttr>(),
|
||||
context);
|
||||
}
|
|
@ -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;
|
||||
|
||||
|
|
Loading…
Reference in New Issue