21 #include "llvm/Support/Regex.h"
24 #define GEN_PASS_DEF_GPUNVVMATTACHTARGET
25 #include "mlir/Dialect/GPU/Transforms/Passes.h.inc"
32 struct NVVMAttachTarget
33 :
public impl::GpuNVVMAttachTargetBase<NVVMAttachTarget> {
36 DictionaryAttr getFlags(
OpBuilder &builder)
const;
38 void runOnOperation()
override;
41 registry.
insert<NVVM::NVVMDialect>();
46 DictionaryAttr NVVMAttachTarget::getFlags(
OpBuilder &builder)
const {
49 auto addFlag = [&](StringRef flag) {
61 void NVVMAttachTarget::runOnOperation() {
65 auto target = builder.
getAttr<NVVMTargetAttr>(
66 optLevel, triple, chip, features, getFlags(builder),
68 llvm::Regex matcher(moduleMatcher);
69 for (
Region ®ion : getOperation()->getRegions())
70 for (
Block &block : region.getBlocks())
71 for (
auto module : block.getOps<gpu::GPUModuleOp>()) {
73 if (!moduleMatcher.empty() && !matcher.match(module.getName()))
77 if (std::optional<ArrayAttr> attrs = module.getTargets())
78 targets.append(attrs->getValue().begin(), attrs->getValue().end());
79 targets.push_back(target);
81 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.