27#include "llvm/ADT/StringExtras.h"
28#include "llvm/ADT/StringRef.h"
29#include "llvm/ADT/TypeSwitch.h"
30#include "llvm/Support/ErrorHandling.h"
31#include "llvm/Support/raw_ostream.h"
36#include "mlir/Dialect/LLVMIR/ROCDLOpsDialect.cpp.inc"
37#include "mlir/Dialect/LLVMIR/ROCDLOpsEnums.cpp.inc"
44struct ROCDLInlinerInterface final : DialectInlinerInterface {
45 using DialectInlinerInterface::DialectInlinerInterface;
46 bool isLegalToInline(Operation *, Region *,
bool, IRMapping &)
const final {
53void ROCDLDialect::initialize() {
56#include "mlir/Dialect/LLVMIR/ROCDLOps.cpp.inc"
60#define GET_ATTRDEF_LIST
61#include "mlir/Dialect/LLVMIR/ROCDLOpsAttributes.cpp.inc"
65 allowUnknownOperations();
66 addInterfaces<ROCDLInlinerInterface>();
67 declarePromisedInterface<gpu::TargetAttrInterface, ROCDLTargetAttr>();
71BufferOOBModeModuleFlagAttr::getModuleFlagBehavior()
const {
72 return LLVM::ModFlagBehavior::Max;
75StringAttr BufferOOBModeModuleFlagAttr::getModuleFlagKey()
const {
77 ROCDLDialect::getModuleFlagKeyBufferOOBModeName());
80Attribute BufferOOBModeModuleFlagAttr::getModuleFlagValue()
const {
81 return BufferOOBModeAttr::get(
getContext(), getValue());
85TBufferOOBModeModuleFlagAttr::getModuleFlagBehavior()
const {
86 return LLVM::ModFlagBehavior::Max;
89StringAttr TBufferOOBModeModuleFlagAttr::getModuleFlagKey()
const {
91 ROCDLDialect::getModuleFlagKeyTBufferOOBModeName());
94Attribute TBufferOOBModeModuleFlagAttr::getModuleFlagValue()
const {
95 return BufferOOBModeAttr::get(
getContext(), getValue());
98LogicalResult ROCDLDialect::verifyOperationAttribute(
Operation *op,
101 if (kernelAttrName.getName() == attr.
getName()) {
102 if (!isa<LLVM::LLVMFuncOp>(op)) {
103 return op->
emitError() <<
"'" << kernelAttrName.getName()
104 <<
"' attribute attached to unexpected op";
114template <
typename EnumAttrT,
typename EnumT>
124 cachePolicy = EnumAttrT::get(parser.
getContext(), *parsed);
134 if (failed(*rawValueParseResult))
137 IntegerAttr::get(IntegerType::get(parser.
getContext(), 32), rawValue);
141 StringRef policyFamily;
144 &policyFamily, {
"pre_gfx12",
"gfx942",
"gfx12",
"gfx12_atomic"}))) {
146 <<
"expected cache policy family 'pre_gfx12', 'gfx942', 'gfx12', "
147 "'gfx12_atomic', or a 32-bit integer";
150 if (policyFamily ==
"pre_gfx12")
152 parser, cachePolicy);
153 if (policyFamily ==
"gfx942")
155 parser, cachePolicy);
156 if (policyFamily ==
"gfx12")
158 parser, cachePolicy);
160 Gfx12AtomicCachePolicy>(parser, cachePolicy);
163template <
typename EnumAttrT>
166 printer << family <<
"<" << cachePolicy.getValue() <<
">";
172 .Case<IntegerAttr>([&](IntegerAttr rawPolicy) {
173 printer << rawPolicy.getValue().getZExtValue();
175 .Case<PreGfx12CachePolicyAttr>([&](PreGfx12CachePolicyAttr policy) {
178 .Case<Gfx942CachePolicyAttr>([&](Gfx942CachePolicyAttr policy) {
181 .Case<Gfx12CachePolicyAttr>([&](Gfx12CachePolicyAttr policy) {
184 .Case<Gfx12AtomicCachePolicyAttr>([&](Gfx12AtomicCachePolicyAttr policy) {
187 .DefaultUnreachable(
"unknown ROCDL cache policy attribute");
195 int optLevel, StringRef triple, StringRef chip,
196 StringRef features, StringRef abiVersion,
198 if (optLevel < 0 || optLevel > 3) {
199 emitError() <<
"The optimization level must be a number between 0 and 3.";
202 if (triple.empty()) {
203 emitError() <<
"The target triple cannot be empty.";
207 emitError() <<
"The target chip cannot be empty.";
210 if (abiVersion !=
"400" && abiVersion !=
"500" && abiVersion !=
"600") {
211 emitError() <<
"Invalid ABI version, it must be `400`, `500` or '600'.";
214 if (files && !llvm::all_of(files, [](::mlir::Attribute attr) {
215 return mlir::isa_and_nonnull<StringAttr>(attr);
217 emitError() <<
"All the elements in the `link` array must be strings.";
223#define GET_OP_CLASSES
224#include "mlir/Dialect/LLVMIR/ROCDLOps.cpp.inc"
226#define GET_ATTRDEF_CLASSES
227#include "mlir/Dialect/LLVMIR/ROCDLOpsAttributes.cpp.inc"
static bool isLegalToInline(InlinerInterface &interface, Region *src, Region *insertRegion, bool shouldCloneInlinedRegion, IRMapping &valueMapping)
Utility to check that all of the operations within 'src' can be inlined.
static ParseResult parseCachePolicyEnum(OpAsmParser &parser, Attribute &cachePolicy)
static ParseResult parseCachePolicy(OpAsmParser &parser, Attribute &cachePolicy)
static void printCachePolicyEnum(OpAsmPrinter &printer, EnumAttrT cachePolicy, StringRef family)
static void printCachePolicy(OpAsmPrinter &printer, Operation *, Attribute cachePolicy)
virtual OptionalParseResult parseOptionalInteger(APInt &result)=0
Parse an optional integer value from the stream.
virtual ParseResult parseOptionalKeyword(StringRef keyword)=0
Parse the given keyword if present.
MLIRContext * getContext() const
virtual InFlightDiagnostic emitError(SMLoc loc, const Twine &message={})=0
Emit a diagnostic at the specified location and return failure.
virtual ParseResult parseLess()=0
Parse a '<' token.
virtual SMLoc getCurrentLocation()=0
Get the location of the next token and store it into the argument.
virtual ParseResult parseGreater()=0
Parse a '>' token.
Attributes are known-constant values of operations.
This class represents a diagnostic that is inflight and set to be reported.
NamedAttribute represents a combination of a name and an Attribute value.
StringAttr getName() const
Return the name of the attribute.
The OpAsmParser has methods for interacting with the asm parser: parsing things from it,...
This is a pure-virtual base class that exposes the asmprinter hooks necessary to implement a custom p...
Operation is the basic unit of execution within MLIR.
InFlightDiagnostic emitError(const Twine &message={})
Emit an error about fatal conditions with this operation, reporting up to any diagnostic handlers tha...
This class implements Optional functionality for ParseResult.
bool has_value() const
Returns true if we contain a valid ParseResult value.
Include the generated interface declarations.
InFlightDiagnostic emitError(Location loc)
Utility method to emit an error message using this location.
llvm::function_ref< Fn > function_ref
Provide a template class that can be specialized by users to dispatch to parsers.