21#include "llvm/Support/Regex.h"
24#define GEN_PASS_DEF_GPUXEVMATTACHTARGET
25#include "mlir/Dialect/GPU/Transforms/Passes.h.inc"
32struct XeVMAttachTarget
36 DictionaryAttr getFlags(OpBuilder &builder)
const;
38 void runOnOperation()
override;
40 void getDependentDialects(DialectRegistry ®istry)
const override {
41 registry.
insert<xevm::XeVMDialect>();
46DictionaryAttr XeVMAttachTarget::getFlags(
OpBuilder &builder)
const {
47 SmallVector<NamedAttribute, 3> flags;
49 if (!cmdOptions.empty()) {
50 std::pair<llvm::BumpPtrAllocator, SmallVector<const char *>>
options =
53 llvm::SmallVector<mlir::Attribute> xevmOptionAttrs;
54 for (
const char *opt :
options.second) {
55 xevmOptionAttrs.emplace_back(
56 mlir::StringAttr::get(builder.
getContext(), StringRef(opt)));
60 mlir::ArrayAttr::get(builder.
getContext(), xevmOptionAttrs)));
69void XeVMAttachTarget::runOnOperation() {
71 ArrayRef<std::string> libs(linkLibs);
72 SmallVector<StringRef> filesToLink(libs);
74 optLevel, triple, chip, 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));
static llvm::ManagedStatic< PassManagerOptions > options
MLIRContext * getContext() const
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.
std::pair< llvm::BumpPtrAllocator, SmallVector< const char * > > tokenizeCmdOptions() const
Returns a tokenization of the command line options.
Include the generated interface declarations.