brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.3 KiB · 35f092c Raw
111 lines · cpp
1//===- TestRecipePopulate.cpp - Test Recipe Population -------------------===//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 createAndPopulate methods10// of the recipe operations.11//12//===----------------------------------------------------------------------===//13 14#include "mlir/Dialect/Arith/IR/Arith.h"15#include "mlir/Dialect/Func/IR/FuncOps.h"16#include "mlir/Dialect/MemRef/IR/MemRef.h"17#include "mlir/Dialect/OpenACC/OpenACC.h"18#include "mlir/IR/Builders.h"19#include "mlir/Pass/Pass.h"20#include "llvm/Support/CommandLine.h"21 22using namespace mlir;23using namespace mlir::acc;24 25namespace {26 27struct TestRecipePopulatePass28    : public PassWrapper<TestRecipePopulatePass, OperationPass<ModuleOp>> {29  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestRecipePopulatePass)30 31  TestRecipePopulatePass() = default;32  TestRecipePopulatePass(const TestRecipePopulatePass &pass)33      : PassWrapper(pass) {34    recipeType = pass.recipeType;35  }36 37  Pass::Option<std::string> recipeType{38      *this, "recipe-type",39      llvm::cl::desc("Recipe type: private or firstprivate"),40      llvm::cl::init("private")};41 42  StringRef getArgument() const override { return "test-acc-recipe-populate"; }43 44  StringRef getDescription() const override {45    return "Test OpenACC recipe population";46  }47 48  void runOnOperation() override;49 50  void getDependentDialects(DialectRegistry &registry) const override {51    registry.insert<acc::OpenACCDialect>();52    registry.insert<arith::ArithDialect>();53    registry.insert<memref::MemRefDialect>();54  }55};56 57void TestRecipePopulatePass::runOnOperation() {58  auto module = getOperation();59  OpBuilder builder(&getContext());60 61  // Collect all test variables62  SmallVector<std::tuple<Operation *, Value, std::string>> testVars;63 64  module.walk([&](Operation *op) {65    if (auto varName = op->getAttrOfType<StringAttr>("test.var")) {66      for (auto result : op->getResults()) {67        testVars.push_back({op, result, varName.str()});68      }69    }70  });71 72  // Generate recipes at module level73  builder.setInsertionPoint(&module.getBodyRegion().front(),74                            module.getBodyRegion().front().begin());75 76  for (auto [op, var, varName] : testVars) {77    Location loc = op->getLoc();78 79    std::string recipeName = recipeType.getValue() + "_" + varName;80    ValueRange bounds; // No bounds for memref tests81 82    if (recipeType == "private") {83      auto recipe = PrivateRecipeOp::createAndPopulate(84          builder, loc, recipeName, var.getType(), varName, bounds);85 86      if (!recipe) {87        op->emitError("Failed to create private recipe for ") << varName;88      }89    } else if (recipeType == "firstprivate") {90      auto recipe = FirstprivateRecipeOp::createAndPopulate(91          builder, loc, recipeName, var.getType(), varName, bounds);92 93      if (!recipe) {94        op->emitError("Failed to create firstprivate recipe for ") << varName;95      }96    }97  }98}99 100} // namespace101 102namespace mlir {103namespace test {104 105void registerTestRecipePopulatePass() {106  PassRegistration<TestRecipePopulatePass>();107}108 109} // namespace test110} // namespace mlir111