29#include "llvm/ADT/StringExtras.h"
30#include "llvm/ADT/StringRef.h"
31#include "llvm/ADT/TypeSwitch.h"
32#include "llvm/Support/ErrorHandling.h"
33#include "llvm/Support/raw_ostream.h"
38#include "mlir/Dialect/LLVMIR/ROCDLOpsDialect.cpp.inc"
39#include "mlir/Dialect/LLVMIR/ROCDLOpsEnums.cpp.inc"
46struct ROCDLInlinerInterface final : DialectInlinerInterface {
47 using DialectInlinerInterface::DialectInlinerInterface;
48 bool isLegalToInline(Operation *, Region *,
bool, IRMapping &)
const final {
55void ROCDLDialect::initialize() {
56 registerROCDLDialectOperations(
this);
59#define GET_ATTRDEF_LIST
60#include "mlir/Dialect/LLVMIR/ROCDLOpsAttributes.cpp.inc"
64 allowUnknownOperations();
65 addInterfaces<ROCDLInlinerInterface>();
66 declarePromisedInterface<gpu::TargetAttrInterface, ROCDLTargetAttr>();
70BufferOOBModeModuleFlagAttr::getModuleFlagBehavior()
const {
71 return LLVM::ModFlagBehavior::Max;
74StringAttr BufferOOBModeModuleFlagAttr::getModuleFlagKey()
const {
76 ROCDLDialect::getModuleFlagKeyBufferOOBModeName());
79Attribute BufferOOBModeModuleFlagAttr::getModuleFlagValue()
const {
80 return BufferOOBModeAttr::get(
getContext(), getValue());
84TBufferOOBModeModuleFlagAttr::getModuleFlagBehavior()
const {
85 return LLVM::ModFlagBehavior::Max;
88StringAttr TBufferOOBModeModuleFlagAttr::getModuleFlagKey()
const {
90 ROCDLDialect::getModuleFlagKeyTBufferOOBModeName());
93Attribute TBufferOOBModeModuleFlagAttr::getModuleFlagValue()
const {
94 return BufferOOBModeAttr::get(
getContext(), getValue());
97LogicalResult ROCDLDialect::verifyOperationAttribute(
Operation *op,
100 if (kernelAttrName.getName() == attr.
getName()) {
101 if (!isa<LLVM::LLVMFuncOp>(op)) {
102 return op->
emitError() <<
"'" << kernelAttrName.getName()
103 <<
"' attribute attached to unexpected op";
113template <
typename EnumAttrT,
typename EnumT>
123 cachePolicy = EnumAttrT::get(parser.
getContext(), *parsed);
133 if (failed(*rawValueParseResult))
136 IntegerAttr::get(IntegerType::get(parser.
getContext(), 32), rawValue);
140 StringRef policyFamily;
143 &policyFamily, {
"pre_gfx12",
"gfx942",
"gfx12",
"gfx12_atomic"}))) {
145 <<
"expected cache policy family 'pre_gfx12', 'gfx942', 'gfx12', "
146 "'gfx12_atomic', or a 32-bit integer";
149 if (policyFamily ==
"pre_gfx12")
151 parser, cachePolicy);
152 if (policyFamily ==
"gfx942")
154 parser, cachePolicy);
155 if (policyFamily ==
"gfx12")
157 parser, cachePolicy);
159 Gfx12AtomicCachePolicy>(parser, cachePolicy);
162template <
typename EnumAttrT>
165 printer << family <<
"<" << cachePolicy.getValue() <<
">";
171 .Case<IntegerAttr>([&](IntegerAttr rawPolicy) {
172 printer << rawPolicy.getValue().getZExtValue();
174 .Case<PreGfx12CachePolicyAttr>([&](PreGfx12CachePolicyAttr policy) {
177 .Case<Gfx942CachePolicyAttr>([&](Gfx942CachePolicyAttr policy) {
180 .Case<Gfx12CachePolicyAttr>([&](Gfx12CachePolicyAttr policy) {
183 .Case<Gfx12AtomicCachePolicyAttr>([&](Gfx12AtomicCachePolicyAttr policy) {
186 .DefaultUnreachable(
"unknown ROCDL cache policy attribute");
194 int optLevel, StringRef triple, StringRef chip,
195 StringRef features, StringRef abiVersion,
196 DictionaryAttr flags, ArrayAttr files) {
197 if (optLevel < 0 || optLevel > 3) {
198 emitError() <<
"The optimization level must be a number between 0 and 3.";
201 if (triple.empty()) {
202 emitError() <<
"The target triple cannot be empty.";
206 emitError() <<
"The target chip cannot be empty.";
209 if (abiVersion !=
"400" && abiVersion !=
"500" && abiVersion !=
"600") {
210 emitError() <<
"Invalid ABI version, it must be `400`, `500` or '600'.";
213 if (files && !llvm::all_of(files, [](::mlir::Attribute attr) {
214 return mlir::isa_and_nonnull<StringAttr>(attr);
216 emitError() <<
"All the elements in the `link` array must be strings.";
222#define GET_ATTRDEF_CLASSES
223#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.
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.
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.