21#include "llvm/Support/Regex.h"
24#define GEN_PASS_DEF_GPUNVVMATTACHTARGET
25#include "mlir/Dialect/GPU/Transforms/Passes.h.inc"
32struct NVVMAttachTarget
36 DictionaryAttr getFlags(OpBuilder &builder)
const;
38 void runOnOperation()
override;
40 void getDependentDialects(DialectRegistry ®istry)
const override {
41 registry.
insert<NVVM::NVVMDialect>();
46DictionaryAttr NVVMAttachTarget::getFlags(
OpBuilder &builder)
const {
48 SmallVector<NamedAttribute, 3> flags;
49 auto addFlag = [&](StringRef flag) {
58 if (!cmdOptions.empty()) {
61 llvm::SmallVector<mlir::Attribute> nvvmOptionAttrs;
62 for (
const char *opt :
options.second) {
63 nvvmOptionAttrs.emplace_back(
64 mlir::StringAttr::get(builder.
getContext(), StringRef(opt)));
68 mlir::ArrayAttr::get(builder.
getContext(), nvvmOptionAttrs)));
77void NVVMAttachTarget::runOnOperation() {
79 ArrayRef<std::string> libs(linkLibs);
80 SmallVector<StringRef> filesToLink(libs);
82 optLevel, triple, chip, features, getFlags(builder),
84 llvm::Regex matcher(moduleMatcher);
85 for (Region ®ion : getOperation()->getRegions())
86 for (
Block &block : region.getBlocks())
87 for (
auto module : block.getOps<gpu::GPUModuleOp>()) {
89 if (!moduleMatcher.empty() && !matcher.match(module.getName()))
92 SmallVector<Attribute> targets;
93 if (std::optional<ArrayAttr> attrs = module.getTargets())
94 targets.append(attrs->getValue().begin(), attrs->getValue().end());
97 targets.erase(llvm::unique(targets), targets.end());
99 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.