18#include "llvm/ADT/STLExtras.h"
24#include "mlir/Dialect/LLVMIR/NVVMOpsEnums.cpp.inc"
30unsigned NVVMMemorySpaceAttr::getAddressSpace()
const {
31 return static_cast<unsigned>(getValue());
34bool NVVMMemorySpaceAttr::isValidLoad(
35 Type type, ptr::AtomicOrdering ordering, std::optional<int64_t> alignment,
36 const ::mlir::DataLayout *dataLayout,
42bool NVVMMemorySpaceAttr::isValidStore(
43 Type type, ptr::AtomicOrdering ordering, std::optional<int64_t> alignment,
44 const ::mlir::DataLayout *dataLayout,
50bool NVVMMemorySpaceAttr::isValidAtomicOp(
51 ptr::AtomicBinOp op,
Type type, ptr::AtomicOrdering ordering,
52 std::optional<int64_t> alignment, const ::mlir::DataLayout *dataLayout,
55 assert(
false &&
"unimplemented, see TODO in the source.");
59bool NVVMMemorySpaceAttr::isValidAtomicXchg(
60 Type type, ptr::AtomicOrdering successOrdering,
61 ptr::AtomicOrdering failureOrdering, std::optional<int64_t> alignment,
62 const ::mlir::DataLayout *dataLayout,
65 assert(
false &&
"unimplemented, see TODO in the source.");
69bool NVVMMemorySpaceAttr::isValidAddrSpaceCast(
73 assert(
false &&
"unimplemented, see TODO in the source.");
77bool NVVMMemorySpaceAttr::isValidPtrIntCast(
82 assert(
false &&
"unimplemented, see TODO in the source.");
91 int optLevel, StringRef triple, StringRef chip,
92 StringRef features, DictionaryAttr flags,
94 if (optLevel < 0 || optLevel > 3) {
95 emitError() <<
"The optimization level must be a number between 0 and 3.";
99 emitError() <<
"The target triple cannot be empty.";
103 emitError() <<
"The target chip cannot be empty.";
106 if (files && !llvm::all_of(files, [](::mlir::Attribute attr) {
107 return mlir::isa_and_nonnull<StringAttr>(attr);
109 emitError() <<
"All the elements in the `link` array must be strings.";
115LogicalResult NVVMTargetAttr::verifyTarget(
Operation *gpuModule) {
116 if (!getVerifyTarget())
119 auto gpuModuleOp = llvm::dyn_cast<gpu::GPUModuleOp>(gpuModule);
122 "NVVM target attribute must be attached to a GPU module");
125 std::optional<unsigned> targetFullSmVersion =
127 if (!targetFullSmVersion)
129 <<
"invalid NVVM target chip \"" << getChip()
130 <<
"\", expected sm_<version>[a|f]";
134 "Minimum NVVM target SM version is sm_20");
138 ->
walk([&](Operation *op) {
139 if (
auto reqOp = llvm::dyn_cast<NVVM::RequiresSMInterface>(op)) {
140 const NVVMCheckSMVersion requirement =
141 reqOp.getRequiredMinSMVersion();
143 op->
emitOpError() <<
"is not supported on " << getChip();
155#define GET_ATTRDEF_CLASSES
156#include "mlir/Dialect/LLVMIR/NVVMOpsAttributes.cpp.inc"
162void NVVMDialect::registerAttributes() {
164#define GET_ATTRDEF_LIST
165#include "mlir/Dialect/LLVMIR/NVVMOpsAttributes.cpp.inc"
This class represents a diagnostic that is inflight and set to be reported.
Operation is the basic unit of execution within MLIR.
Location getLoc()
The source location the operation was defined or derived from.
InFlightDiagnostic emitOpError(const Twine &message={})
Emit an error with the op name prefixed, like "'dim' op " which is convenient for verifiers.
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
static WalkResult advance()
static WalkResult interrupt()
bool isValidLoadStoreImpl(Type type, ptr::AtomicOrdering ordering, std::optional< int64_t > alignment, const ::mlir::DataLayout *dataLayout, function_ref< InFlightDiagnostic()> emitError)
Checks whether the given type is an LLVM type that can be loaded or stored.
void walk(Operation *op, function_ref< void(Region *)> callback, WalkOrder order)
Walk all of the regions, blocks, or operations nested under (and including) the given operation.
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
static bool isMinimumSMVersion(unsigned fullSmVersion)
static std::optional< unsigned > getTargetFullSmVersionFromStr(StringRef smVersionString)
bool isCompatibleWith(const unsigned &targetFullSmVersion) const