21#include "llvm/Support/Regex.h"
24#define GEN_PASS_DEF_GPUNVVMATTACHTARGET
25#include "mlir/Dialect/GPU/Transforms/NVVM/Passes.h.inc"
32struct NVVMAttachTarget
36 DictionaryAttr
getFlags(OpBuilder &builder)
const;
38 void runOnOperation()
override;
40 void getDependentDialects(DialectRegistry ®istry)
const override {
41 registry.
insert<NVVM::NVVMDialect>();
46DictionaryAttr NVVMAttachTarget::getFlags(
OpBuilder &builder)
const {
49 auto addFlag = [&](StringRef flag) {
57 addFlag(
"collect-compiler-diagnostics");
64 for (
const char *opt :
options.second) {
65 nvvmOptionAttrs.emplace_back(
66 mlir::StringAttr::get(builder.
getContext(), StringRef(opt)));
70 mlir::ArrayAttr::get(builder.
getContext(), nvvmOptionAttrs)));
79void NVVMAttachTarget::runOnOperation() {
87 auto target = NVVMTargetAttr::getChecked(
89 StringRef(chip), StringRef(features),
getFlags(builder),
91 static_cast<bool>(verifyTarget));
96 for (
Block &block : region.getBlocks())
97 for (
auto module : block.getOps<gpu::GPUModuleOp>()) {
99 if (!
moduleMatcher.empty() && !matcher.match(module.getName()))
103 if (std::optional<ArrayAttr> attrs = module.getTargets())
104 targets.append(attrs->getValue().begin(), attrs->getValue().end());
105 targets.push_back(
target);
107 targets.erase(llvm::unique(targets), targets.end());
109 module.setTargetsAttr(builder.getArrayAttr(targets));
static llvm::ManagedStatic< PassManagerOptions > options
static arith::FastMathFlags getFlags(arith::FastMathFlagsAttr fastmath)
Returns the flags held by fastmath, or none if it is null.
Block represents an ordered list of Operations.
MLIRContext * getContext() const
DictionaryAttr getDictionaryAttr(ArrayRef< NamedAttribute > value)
NamedAttribute getNamedAttr(StringRef name, Attribute val)
ArrayAttr getStrArrayAttr(ArrayRef< StringRef > values)
This class helps build Operations.
OpT getOperation()
Return the current operation being transformed.
void signalPassFailure()
Signal that some invariant was broken when running.
This class contains a list of basic blocks and a link to the parent operation it is attached to.
std::pair< llvm::BumpPtrAllocator, SmallVector< const char * > > tokenizeCmdOptions() const
Returns a tokenization of the command line options.
::mlir::Pass::Option< std::string > moduleMatcher
::mlir::Pass::Option< std::string > cmdOptions
::mlir::Pass::Option< bool > ftzFlag
::mlir::Pass::Option< bool > fastFlag
::mlir::Pass::ListOption< std::string > linkLibs
::mlir::Pass::Option< bool > compilerDiagnosticsFlag
Include the generated interface declarations.
InFlightDiagnostic emitError(Location loc)
Utility method to emit an error message using this location.