29#include "llvm/ADT/StringRef.h"
30#include "llvm/ADT/TypeSwitch.h"
31#include "llvm/Support/ErrorHandling.h"
32#include "llvm/Support/raw_ostream.h"
41#include "mlir/Dialect/LLVMIR/ROCDLOpsDialect.cpp.inc"
42#include "mlir/Dialect/LLVMIR/ROCDLOpsEnums.cpp.inc"
49struct ROCDLInlinerInterface final : DialectInlinerInterface {
50 using DialectInlinerInterface::DialectInlinerInterface;
51 bool isLegalToInline(Operation *, Region *,
bool, IRMapping &)
const final {
58void ROCDLDialect::initialize() {
60 allowUnknownOperations();
61 addInterfaces<ROCDLInlinerInterface>();
62 declarePromisedInterface<gpu::TargetAttrInterface, ROCDLTargetAttr>();
66BufferOOBModeModuleFlagAttr::getModuleFlagBehavior()
const {
67 return LLVM::ModFlagBehavior::Max;
70StringAttr BufferOOBModeModuleFlagAttr::getModuleFlagKey()
const {
72 ROCDLDialect::getModuleFlagKeyBufferOOBModeName());
75Attribute BufferOOBModeModuleFlagAttr::getModuleFlagValue()
const {
76 return BufferOOBModeAttr::get(
getContext(), getValue());
80TBufferOOBModeModuleFlagAttr::getModuleFlagBehavior()
const {
81 return LLVM::ModFlagBehavior::Max;
84StringAttr TBufferOOBModeModuleFlagAttr::getModuleFlagKey()
const {
86 ROCDLDialect::getModuleFlagKeyTBufferOOBModeName());
89Attribute TBufferOOBModeModuleFlagAttr::getModuleFlagValue()
const {
90 return BufferOOBModeAttr::get(
getContext(), getValue());
93LogicalResult ROCDLDialect::verifyOperationAttribute(
Operation *op,
96 if (kernelAttrName.getName() == attr.
getName()) {
97 if (!isa<LLVM::LLVMFuncOp>(op)) {
98 return op->
emitError() <<
"'" << kernelAttrName.getName()
99 <<
"' attribute attached to unexpected op";
103 if (attr.
getName() == xnackAttrName.getName() ||
104 attr.
getName() == srameccAttrName.getName()) {
107 << attr.
getName() <<
" is only supported on modules";
108 if (!isa<BoolAttr>(attr.
getValue()))
118template <
typename EnumAttrT,
typename EnumT>
128 cachePolicy = EnumAttrT::get(parser.
getContext(), *parsed);
138 if (failed(*rawValueParseResult))
141 IntegerAttr::get(IntegerType::get(parser.
getContext(), 32), rawValue);
145 StringRef policyFamily;
148 &policyFamily, {
"pre_gfx12",
"gfx942",
"gfx12",
"gfx12_atomic"}))) {
150 <<
"expected cache policy family 'pre_gfx12', 'gfx942', 'gfx12', "
151 "'gfx12_atomic', or a 32-bit integer";
154 if (policyFamily ==
"pre_gfx12")
156 parser, cachePolicy);
157 if (policyFamily ==
"gfx942")
159 parser, cachePolicy);
160 if (policyFamily ==
"gfx12")
162 parser, cachePolicy);
164 Gfx12AtomicCachePolicy>(parser, cachePolicy);
167template <
typename EnumAttrT>
170 printer << family <<
"<" << cachePolicy.getValue() <<
">";
176 .Case<IntegerAttr>([&](IntegerAttr rawPolicy) {
177 printer << rawPolicy.getValue().getZExtValue();
179 .Case<PreGfx12CachePolicyAttr>([&](PreGfx12CachePolicyAttr policy) {
182 .Case<Gfx942CachePolicyAttr>([&](Gfx942CachePolicyAttr policy) {
185 .Case<Gfx12CachePolicyAttr>([&](Gfx12CachePolicyAttr policy) {
188 .Case<Gfx12AtomicCachePolicyAttr>([&](Gfx12AtomicCachePolicyAttr policy) {
191 .DefaultUnreachable(
"unknown ROCDL cache policy attribute");
199 int optLevel, StringRef triple, StringRef chip,
200 StringRef features, StringRef abiVersion,
201 DictionaryAttr flags, ArrayAttr files) {
202 if (optLevel < 0 || optLevel > 3) {
203 emitError() <<
"The optimization level must be a number between 0 and 3.";
206 if (triple.empty()) {
207 emitError() <<
"The target triple cannot be empty.";
211 emitError() <<
"The target chip cannot be empty.";
214 if (abiVersion !=
"400" && abiVersion !=
"500" && abiVersion !=
"600") {
215 emitError() <<
"Invalid ABI version, it must be `400`, `500` or '600'.";
218 if (files && !llvm::all_of(files, [](::mlir::Attribute attr) {
219 return mlir::isa_and_nonnull<StringAttr>(attr);
221 emitError() <<
"All the elements in the `link` array must be strings.";
227#define GET_ATTRDEF_CLASSES
228#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 void printCachePolicyEnum(OpAsmPrinter &printer, EnumAttrT cachePolicy, StringRef family)
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.
Attribute getValue() const
Return the value 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.
bool satisfiesLLVMModule(Operation *op)
LLVM requires some operations to be inside of a Module operation.
ParseResult parseCachePolicy(OpAsmParser &parser, Attribute &cachePolicy)
void printCachePolicy(OpAsmPrinter &printer, Operation *, Attribute cachePolicy)
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.