18#include "llvm/Support/Regex.h"
25#define GEN_PASS_DEF_GPUATTACHSELECTOBJECTPASS
26#include "mlir/Dialect/GPU/Transforms/Passes.h.inc"
30class GpuAttachSelectObjectPass
34 void runOnOperation()
final;
38void GpuAttachSelectObjectPass::runOnOperation() {
39 if (priority > std::numeric_limits<uint16_t>::max()) {
40 getOperation()->emitError()
41 <<
"Invalid priority specified: " << priority.getValue()
42 <<
" (expected a value in the range [0, 65535])";
43 return signalPassFailure();
46 if (priority == SelectObjectAttr::kDefaultPriority)
50 llvm::Regex matcher(moduleMatcher);
51 for (Region ®ion : getOperation()->getRegions()) {
52 for (
Block &block : region.getBlocks()) {
53 for (GPUModuleOp module : block.getOps<GPUModuleOp>()) {
55 if (!moduleMatcher.empty() && !matcher.match(module.getName()))
59 Attribute handler =
module.getOffloadingHandlerAttr();
60 auto selectObject = dyn_cast_or_null<SelectObjectAttr>(handler);
61 if (handler && !selectObject)
64 selectObject.getPriority() != SelectObjectAttr::kDefaultPriority)
68 selectObject ? selectObject.getTarget() : Attribute();
70 target = builder.getI64IntegerAttr(0);
71 module.setOffloadingHandlerAttr(
72 SelectObjectAttr::get(&getContext(), target, priority));
Include the generated interface declarations.