| 1 | //===- TestOpenACCSupport.cpp - Test OpenACCSupport Analysis -------------===// |
|---|---|
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | // |
| 9 | // This file contains test passes for testing the OpenACCSupport analysis. |
| 10 | // |
| 11 | //===----------------------------------------------------------------------===// |
| 12 | |
| 13 | #include "mlir/Dialect/Func/IR/FuncOps.h" |
| 14 | #include "mlir/Dialect/MemRef/IR/MemRefDialect.h" |
| 15 | #include "mlir/Dialect/OpenACC/Analysis/OpenACCSupport.h" |
| 16 | #include "mlir/Dialect/OpenACC/OpenACC.h" |
| 17 | #include "mlir/Pass/Pass.h" |
| 18 | |
| 19 | using namespace mlir; |
| 20 | using namespace mlir::acc; |
| 21 | |
| 22 | namespace { |
| 23 | |
| 24 | struct TestOpenACCSupportPass |
| 25 | : public PassWrapper<TestOpenACCSupportPass, OperationPass<func::FuncOp>> { |
| 26 | MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestOpenACCSupportPass) |
| 27 | |
| 28 | StringRef getArgument() const override { return "test-acc-support"; } |
| 29 | |
| 30 | StringRef getDescription() const override { |
| 31 | return "Test OpenACCSupport analysis"; |
| 32 | } |
| 33 | |
| 34 | void runOnOperation() override; |
| 35 | |
| 36 | void getDependentDialects(DialectRegistry ®istry) const override { |
| 37 | registry.insert<acc::OpenACCDialect>(); |
| 38 | registry.insert<memref::MemRefDialect>(); |
| 39 | } |
| 40 | }; |
| 41 | |
| 42 | void TestOpenACCSupportPass::runOnOperation() { |
| 43 | auto func = getOperation(); |
| 44 | |
| 45 | // Get the OpenACCSupport analysis |
| 46 | OpenACCSupport &support = getAnalysis<OpenACCSupport>(); |
| 47 | |
| 48 | // Walk through operations looking for test attributes |
| 49 | func.walk(callback: [&](Operation *op) { |
| 50 | // Check for test.var_name attribute. This is the marker used to identify |
| 51 | // the operations that need to be tested for getVariableName. |
| 52 | if (op->hasDiscardableAttr(name: "test.var_name")) { |
| 53 | // For each result of this operation, try to get the variable name |
| 54 | for (auto result : op->getResults()) { |
| 55 | std::string foundName = support.getVariableName(v: result); |
| 56 | llvm::outs() << "op="<< *op << "\n\tgetVariableName=\""<< foundName |
| 57 | << "\"\n"; |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | // Check for test.recipe_name attribute. This is the marker used to identify |
| 62 | // the operations that need to be tested for getRecipeName. |
| 63 | if (auto recipeAttr = |
| 64 | op->getDiscardableAttrOfType<RecipeKindAttr>(name: "test.recipe_name")) { |
| 65 | RecipeKind kind = recipeAttr.getValue(); |
| 66 | // Get the type from the first result if available |
| 67 | if (op->getNumResults() > 0) { |
| 68 | Type type = op->getResult(idx: 0).getType(); |
| 69 | std::string recipeName = |
| 70 | support.getRecipeName(kind, type, var: op->getResult(idx: 0)); |
| 71 | llvm::outs() << "op="<< *op |
| 72 | << "\n\tgetRecipeName(kind="<< stringifyRecipeKind(kind) |
| 73 | << ", type="<< type << ")=\""<< recipeName << "\"\n"; |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | // Check for test.emit_nyi attribute. This is the marker used to |
| 78 | // test whether the not yet implemented case is reported correctly. |
| 79 | if (auto messageAttr = |
| 80 | op->getDiscardableAttrOfType<StringAttr>(name: "test.emit_nyi")) { |
| 81 | support.emitNYI(loc: op->getLoc(), message: messageAttr.getValue()); |
| 82 | } |
| 83 | }); |
| 84 | } |
| 85 | |
| 86 | } // namespace |
| 87 | |
| 88 | namespace mlir { |
| 89 | namespace test { |
| 90 | |
| 91 | void registerTestOpenACCSupportPass() { |
| 92 | PassRegistration<TestOpenACCSupportPass>(); |
| 93 | } |
| 94 | |
| 95 | } // namespace test |
| 96 | } // namespace mlir |
| 97 |