20#include "llvm/Support/Regex.h"
23#define GEN_PASS_DEF_GPUXEVMATTACHTARGET
24#include "mlir/Dialect/GPU/Transforms/XeVM/Passes.h.inc"
31struct XeVMAttachTarget
32 :
public mlir::impl::GpuXeVMAttachTargetBase<XeVMAttachTarget> {
35 DictionaryAttr
getFlags(OpBuilder &builder)
const;
37 void runOnOperation()
override;
39 void getDependentDialects(DialectRegistry ®istry)
const override {
40 registry.
insert<xevm::XeVMDialect>();
45DictionaryAttr XeVMAttachTarget::getFlags(
OpBuilder &builder)
const {
46 SmallVector<NamedAttribute, 3> flags;
48 if (!cmdOptions.empty()) {
49 std::pair<llvm::BumpPtrAllocator, SmallVector<const char *>>
options =
52 llvm::SmallVector<mlir::Attribute> xevmOptionAttrs;
53 for (
const char *opt :
options.second) {
54 xevmOptionAttrs.emplace_back(
55 mlir::StringAttr::get(builder.
getContext(), StringRef(opt)));
59 mlir::ArrayAttr::get(builder.
getContext(), xevmOptionAttrs)));
68void XeVMAttachTarget::runOnOperation() {
70 ArrayRef<std::string> libs(linkLibs);
71 SmallVector<StringRef> filesToLink(libs);
73 optLevel, triple, chip,
getFlags(builder),
75 llvm::Regex matcher(moduleMatcher);
76 for (Region ®ion : getOperation()->getRegions())
77 for (
Block &block : region.getBlocks())
78 for (
auto module : block.getOps<gpu::GPUModuleOp>()) {
80 if (!moduleMatcher.empty() && !matcher.match(module.getName()))
83 SmallVector<Attribute> targets;
84 if (std::optional<ArrayAttr> attrs = module.getTargets())
85 targets.append(attrs->getValue().begin(), attrs->getValue().end());
88 targets.erase(llvm::unique(targets), targets.end());
90 module.setTargetsAttr(builder.getArrayAttr(targets));
static llvm::ManagedStatic< PassManagerOptions > options
static arith::FastMathFlags getFlags(arith::FastMathFlagsAttr fastmath)
Returns the flags held by fastmath, or none if it is null.
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.