brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.3 KiB · 7c8b084 Raw
96 lines · cpp
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-exception6//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/MemRef.h"15#include "mlir/Dialect/OpenACC/Analysis/OpenACCSupport.h"16#include "mlir/Dialect/OpenACC/OpenACC.h"17#include "mlir/Pass/Pass.h"18 19using namespace mlir;20using namespace mlir::acc;21 22namespace {23 24struct TestOpenACCSupportPass25    : 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 &registry) const override {37    registry.insert<acc::OpenACCDialect>();38    registry.insert<memref::MemRefDialect>();39  }40};41 42void TestOpenACCSupportPass::runOnOperation() {43  auto func = getOperation();44 45  // Get the OpenACCSupport analysis46  OpenACCSupport &support = getAnalysis<OpenACCSupport>();47 48  // Walk through operations looking for test attributes49  func.walk([&](Operation *op) {50    // Check for test.var_name attribute. This is the marker used to identify51    // the operations that need to be tested for getVariableName.52    if (op->hasAttr("test.var_name")) {53      // For each result of this operation, try to get the variable name54      for (auto result : op->getResults()) {55        std::string foundName = support.getVariableName(result);56        llvm::outs() << "op=" << *op << "\n\tgetVariableName=\"" << foundName57                     << "\"\n";58      }59    }60 61    // Check for test.recipe_name attribute. This is the marker used to identify62    // the operations that need to be tested for getRecipeName.63    if (auto recipeAttr =64            op->getAttrOfType<RecipeKindAttr>("test.recipe_name")) {65      RecipeKind kind = recipeAttr.getValue();66      // Get the type from the first result if available67      if (op->getNumResults() > 0) {68        Type type = op->getResult(0).getType();69        std::string recipeName =70            support.getRecipeName(kind, type, op->getResult(0));71        llvm::outs() << "op=" << *op72                     << "\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 to78    // test whether the not yet implemented case is reported correctly.79    if (auto messageAttr = op->getAttrOfType<StringAttr>("test.emit_nyi")) {80      support.emitNYI(op->getLoc(), messageAttr.getValue());81    }82  });83}84 85} // namespace86 87namespace mlir {88namespace test {89 90void registerTestOpenACCSupportPass() {91  PassRegistration<TestOpenACCSupportPass>();92}93 94} // namespace test95} // namespace mlir96