#include "mlir/Dialect/Func/IR/FuncOps.h"
#include "mlir/Dialect/MemRef/IR/MemRef.h"
#include "mlir/Dialect/OpenACC/Analysis/OpenACCSupport.h"
#include "mlir/Dialect/OpenACC/OpenACC.h"
#include "mlir/Pass/Pass.h"
using namespace mlir;
using namespace mlir::acc;
namespace {
struct TestOpenACCSupportPass
: public PassWrapper<TestOpenACCSupportPass, OperationPass<func::FuncOp>> {
MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestOpenACCSupportPass)
StringRef getArgument() const override { return "test-acc-support"; }
StringRef getDescription() const override {
return "Test OpenACCSupport analysis";
}
void runOnOperation() override;
void getDependentDialects(DialectRegistry ®istry) const override {
registry.insert<acc::OpenACCDialect>();
registry.insert<memref::MemRefDialect>();
}
};
void TestOpenACCSupportPass::runOnOperation() {
auto func = getOperation();
OpenACCSupport &support = getAnalysis<OpenACCSupport>();
func.walk([&](Operation *op) {
if (op->hasAttr("test.var_name")) {
for (auto result : op->getResults()) {
std::string foundName = support.getVariableName(result);
llvm::outs() << "op=" << *op << "\n\tgetVariableName=\"" << foundName
<< "\"\n";
}
}
if (auto recipeAttr =
op->getAttrOfType<RecipeKindAttr>("test.recipe_name")) {
RecipeKind kind = recipeAttr.getValue();
if (op->getNumResults() > 0) {
Type type = op->getResult(0).getType();
std::string recipeName =
support.getRecipeName(kind, type, op->getResult(0));
llvm::outs() << "op=" << *op
<< "\n\tgetRecipeName(kind=" << stringifyRecipeKind(kind)
<< ", type=" << type << ")=\"" << recipeName << "\"\n";
}
}
if (auto messageAttr = op->getAttrOfType<StringAttr>("test.emit_nyi")) {
support.emitNYI(op->getLoc(), messageAttr.getValue());
}
});
}
}
namespace mlir {
namespace test {
void registerTestOpenACCSupportPass() {
PassRegistration<TestOpenACCSupportPass>();
}
}
}