Changeset View
Changeset View
Standalone View
Standalone View
mlir/include/mlir/Dialect/SPIRV/TargetAndABI.h
- This file was copied to mlir/include/mlir/Dialect/SPIRV/SPIRVAttributes.h.
//===- TargetAndABI.h - SPIR-V target and ABI utilities --------*- C++ -*-===// | //===- TargetAndABI.h - SPIR-V target and ABI utilities --------*- C++ -*-===// | ||||
// | // | ||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||||
// See https://llvm.org/LICENSE.txt for license information. | // See https://llvm.org/LICENSE.txt for license information. | ||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||||
// | // | ||||
//===----------------------------------------------------------------------===// | //===----------------------------------------------------------------------===// | ||||
// | // | ||||
// This file declares utilities for SPIR-V target and shader interface ABI. | // This file declares utilities for SPIR-V target and shader interface ABI. | ||||
// | // | ||||
//===----------------------------------------------------------------------===// | //===----------------------------------------------------------------------===// | ||||
#ifndef MLIR_DIALECT_SPIRV_TARGETANDABI_H | #ifndef MLIR_DIALECT_SPIRV_TARGETANDABI_H | ||||
#define MLIR_DIALECT_SPIRV_TARGETANDABI_H | #define MLIR_DIALECT_SPIRV_TARGETANDABI_H | ||||
#include "mlir/IR/Attributes.h" | #include "mlir/Dialect/SPIRV/SPIRVAttributes.h" | ||||
#include "mlir/Support/LLVM.h" | #include "mlir/Support/LLVM.h" | ||||
namespace mlir { | namespace mlir { | ||||
class OpBuilder; | |||||
class Operation; | class Operation; | ||||
class Value; | |||||
// Pull in SPIR-V attribute definitions. | |||||
#include "mlir/Dialect/SPIRV/TargetAndABI.h.inc" | |||||
namespace spirv { | namespace spirv { | ||||
enum class Capability : uint32_t; | |||||
enum class Extension; | |||||
enum class StorageClass : uint32_t; | enum class StorageClass : uint32_t; | ||||
enum class Version : uint32_t; | |||||
namespace detail { | |||||
struct TargetEnvAttributeStorage; | |||||
struct VerCapExtAttributeStorage; | |||||
} // namespace detail | |||||
/// SPIR-V dialect-specific attribute kinds. | |||||
// TODO(antiagainst): move to a more suitable place if we have more attributes. | |||||
namespace AttrKind { | |||||
enum Kind { | |||||
TargetEnv = Attribute::FIRST_SPIRV_ATTR, /// Target environment | |||||
VerCapExt, /// (version, extension, capability) triple | |||||
}; | |||||
} // namespace AttrKind | |||||
/// An attribute that specifies the SPIR-V (version, capabilities, extensions) | |||||
/// triple. | |||||
class VerCapExtAttr | |||||
: public Attribute::AttrBase<VerCapExtAttr, Attribute, | |||||
detail::VerCapExtAttributeStorage> { | |||||
public: | |||||
using Base::Base; | |||||
/// Gets a VerCapExtAttr instance. | |||||
static VerCapExtAttr get(Version version, ArrayRef<Capability> capabilities, | |||||
ArrayRef<Extension> extensions, | |||||
MLIRContext *context); | |||||
static VerCapExtAttr get(IntegerAttr version, ArrayAttr capabilities, | |||||
ArrayAttr extensions); | |||||
/// Returns the attribute kind's name (without the 'spv.' prefix). | |||||
static StringRef getKindName(); | |||||
/// Returns the version. | |||||
Version getVersion(); | |||||
struct ext_iterator final | |||||
: public llvm::mapped_iterator<ArrayAttr::iterator, | |||||
Extension (*)(Attribute)> { | |||||
explicit ext_iterator(ArrayAttr::iterator it); | |||||
}; | |||||
using ext_range = llvm::iterator_range<ext_iterator>; | |||||
/// Returns the extensions. | |||||
ext_range getExtensions(); | |||||
/// Returns the extensions as a string array attribute. | |||||
ArrayAttr getExtensionsAttr(); | |||||
struct cap_iterator final | |||||
: public llvm::mapped_iterator<ArrayAttr::iterator, | |||||
Capability (*)(Attribute)> { | |||||
explicit cap_iterator(ArrayAttr::iterator it); | |||||
}; | |||||
using cap_range = llvm::iterator_range<cap_iterator>; | |||||
/// Returns the capabilities. | |||||
cap_range getCapabilities(); | |||||
/// Returns the capabilities as an integer array attribute. | |||||
ArrayAttr getCapabilitiesAttr(); | |||||
static bool kindof(unsigned kind) { return kind == AttrKind::VerCapExt; } | |||||
static LogicalResult verifyConstructionInvariants(Location loc, | |||||
IntegerAttr version, | |||||
ArrayAttr capabilities, | |||||
ArrayAttr extensions); | |||||
}; | |||||
/// An attribute that specifies the target version, allowed extensions and | |||||
/// capabilities, and resource limits. These information describles a SPIR-V | |||||
/// target environment. | |||||
class TargetEnvAttr | |||||
: public Attribute::AttrBase<TargetEnvAttr, Attribute, | |||||
detail::TargetEnvAttributeStorage> { | |||||
public: | |||||
using Base::Base; | |||||
/// Gets a TargetEnvAttr instance. | |||||
static TargetEnvAttr get(VerCapExtAttr triple, DictionaryAttr limits); | |||||
/// Returns the attribute kind's name (without the 'spv.' prefix). | |||||
static StringRef getKindName(); | |||||
/// Returns the (version, capabilities, extensions) triple attribute. | |||||
VerCapExtAttr getTripleAttr(); | |||||
/// Returns the target version. | |||||
Version getVersion(); | |||||
/// Returns the target extensions. | |||||
VerCapExtAttr::ext_range getExtensions(); | |||||
/// Returns the target extensions as a string array attribute. | |||||
ArrayAttr getExtensionsAttr(); | |||||
/// Returns the target capabilities. | |||||
VerCapExtAttr::cap_range getCapabilities(); | |||||
/// Returns the target capabilities as an integer array attribute. | |||||
ArrayAttr getCapabilitiesAttr(); | |||||
/// Returns the target resource limits. | |||||
ResourceLimitsAttr getResourceLimits(); | |||||
static bool kindof(unsigned kind) { return kind == AttrKind::TargetEnv; } | |||||
static LogicalResult verifyConstructionInvariants(Location loc, | |||||
VerCapExtAttr triple, | |||||
DictionaryAttr limits); | |||||
}; | |||||
/// Returns the attribute name for specifying argument ABI information. | /// Returns the attribute name for specifying argument ABI information. | ||||
StringRef getInterfaceVarABIAttrName(); | StringRef getInterfaceVarABIAttrName(); | ||||
/// Gets the InterfaceVarABIAttr given its fields. | /// Gets the InterfaceVarABIAttr given its fields. | ||||
InterfaceVarABIAttr getInterfaceVarABIAttr(unsigned descriptorSet, | InterfaceVarABIAttr getInterfaceVarABIAttr(unsigned descriptorSet, | ||||
unsigned binding, | unsigned binding, | ||||
StorageClass storageClass, | StorageClass storageClass, | ||||
▲ Show 20 Lines • Show All 42 Lines • Show Last 20 Lines |