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) {
58 if (!cmdOptions.empty()) {
62 for (
const char *opt :
options.second) {
63 nvvmOptionAttrs.emplace_back(
77 void NVVMAttachTarget::runOnOperation() {
81 auto target = builder.
getAttr<NVVMTargetAttr>(
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()))
93 if (std::optional<ArrayAttr> attrs = module.getTargets())
94 targets.append(attrs->getValue().begin(), attrs->getValue().end());
95 targets.push_back(target);
97 targets.erase(llvm::unique(targets), targets.end());
static MLIRContext * getContext(OpFoldResult val)
static llvm::ManagedStatic< PassManagerOptions > options
Block represents an ordered list of Operations.
MLIRContext * getContext() const
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.
std::pair< llvm::BumpPtrAllocator, SmallVector< const char * > > tokenizeCmdOptions() const
Returns a tokenization of the command line options.
Include the generated interface declarations.
auto get(MLIRContext *context, Ts &&...params)
Helper method that injects context only if needed, this helps unify some of the attribute constructio...