21 #include "llvm/Support/Regex.h"
24 #define GEN_PASS_DEF_GPUROCDLATTACHTARGET
25 #include "mlir/Dialect/GPU/Transforms/Passes.h.inc"
32 struct ROCDLAttachTarget
33 :
public impl::GpuROCDLAttachTargetBase<ROCDLAttachTarget> {
36 DictionaryAttr getFlags(
OpBuilder &builder)
const;
38 void runOnOperation()
override;
41 registry.
insert<ROCDL::ROCDLDialect>();
46 DictionaryAttr ROCDLAttachTarget::getFlags(
OpBuilder &builder)
const {
49 auto addFlag = [&](StringRef flag) {
59 addFlag(
"finite_only");
61 addFlag(
"unsafe_math");
63 addFlag(
"unsafe_sqrt");
69 void ROCDLAttachTarget::runOnOperation() {
73 auto target = builder.
getAttr<ROCDLTargetAttr>(
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()))
85 if (std::optional<ArrayAttr> attrs = module.getTargets())
86 targets.append(attrs->getValue().begin(), attrs->getValue().end());
87 targets.push_back(target);
89 targets.erase(llvm::unique(targets), targets.end());
static MLIRContext * getContext(OpFoldResult val)
Block represents an ordered list of Operations.
ArrayAttr getArrayAttr(ArrayRef< Attribute > value)
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.
The DialectRegistry maps a dialect namespace to a constructor for the matching dialect.
This class helps build Operations.
This class contains a list of basic blocks and a link to the parent operation it is attached to.
Include the generated interface declarations.