21#include "llvm/Support/Regex.h"
24#define GEN_PASS_DEF_GPUROCDLATTACHTARGET
25#include "mlir/Dialect/GPU/Transforms/Passes.h.inc"
32struct ROCDLAttachTarget
36 DictionaryAttr getFlags(OpBuilder &builder)
const;
38 void runOnOperation()
override;
40 void getDependentDialects(DialectRegistry ®istry)
const override {
41 registry.
insert<ROCDL::ROCDLDialect>();
46DictionaryAttr ROCDLAttachTarget::getFlags(
OpBuilder &builder)
const {
48 SmallVector<NamedAttribute, 6> flags;
49 auto addFlag = [&](StringRef flag) {
59 addFlag(
"finite_only");
61 addFlag(
"unsafe_math");
63 addFlag(
"unsafe_sqrt");
69void ROCDLAttachTarget::runOnOperation() {
71 ArrayRef<std::string> libs(linkLibs);
72 SmallVector<StringRef> filesToLink(libs);
74 optLevel, triple, chip, features, abiVersion, getFlags(builder),
76 llvm::Regex matcher(moduleMatcher);
77 for (Region ®ion : getOperation()->getRegions())
78 for (
Block &block : region.getBlocks())
79 for (
auto module : block.getOps<gpu::GPUModuleOp>()) {
81 if (!moduleMatcher.empty() && !matcher.match(module.getName()))
84 SmallVector<Attribute> targets;
85 if (std::optional<ArrayAttr> attrs = module.getTargets())
86 targets.append(attrs->getValue().begin(), attrs->getValue().end());
89 targets.erase(llvm::unique(targets), targets.end());
91 module.setTargetsAttr(builder.getArrayAttr(targets));
DictionaryAttr getDictionaryAttr(ArrayRef< NamedAttribute > value)
NamedAttribute getNamedAttr(StringRef name, Attribute val)
ArrayAttr getStrArrayAttr(ArrayRef< StringRef > values)
Attr getAttr(Args &&...args)
Get or construct an instance of the attribute Attr with provided arguments.
This class helps build Operations.
Include the generated interface declarations.