MLIR 23.0.0git
ACCEmitRemarksPrivate.cpp
Go to the documentation of this file.
1//===- ACCEmitRemarksPrivate.cpp - Emit OpenACC privatization remarks ----===//
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 pass emits remarks describing the private and firstprivate variables
10// associated with OpenACC compute and loop constructs.
11//
12//===----------------------------------------------------------------------===//
13
18#include "llvm/ADT/StringExtras.h"
19#include "llvm/ADT/Twine.h"
20#include "llvm/ADT/TypeSwitch.h"
21
22namespace mlir {
23namespace acc {
24#define GEN_PASS_DEF_ACCEMITREMARKSPRIVATE
25#include "mlir/Dialect/OpenACC/Transforms/Passes.h.inc"
26} // namespace acc
27} // namespace mlir
28
29#define DEBUG_TYPE "acc-emit-remarks-private"
30
31using namespace mlir;
32
33namespace {
34
35template <typename OpTy>
36static void reportPrivatization(Operation *accOp, ValueRange operands,
37 acc::OpenACCSupport &accSupport,
38 StringRef clause) {
39 SmallVector<std::string> implicitNames;
40 SmallVector<std::string> explicitNames;
41 for (Value operand : operands) {
42 auto op = cast<OpTy>(operand.getDefiningOp());
43 std::string varName = accSupport.getVariableName(op.getAccVar());
44 (op.getImplicit() ? implicitNames : explicitNames)
45 .push_back(varName.empty() ? "<unknown>" : varName);
46 }
47
48 if (!implicitNames.empty())
49 accSupport.emitRemark(
50 accOp,
51 [clause, names = std::move(implicitNames)]() {
52 return (Twine("Generating implicit ") + clause + "(" +
53 llvm::join(names, ",") + ")")
54 .str();
55 },
57
58 if (!explicitNames.empty())
59 accSupport.emitRemark(
60 accOp,
61 [clause, names = std::move(explicitNames)]() {
62 return (Twine("Generating ") + clause + "(" + llvm::join(names, ",") +
63 ")")
64 .str();
65 },
67}
68
69template <typename OpTy>
70static void emitRemarksForACCOp(OpTy accOp, acc::OpenACCSupport &accSupport) {
71 reportPrivatization<acc::FirstprivateOp>(
72 accOp, accOp.getFirstprivateOperands(), accSupport, "firstprivate");
73 reportPrivatization<acc::PrivateOp>(accOp, accOp.getPrivateOperands(),
74 accSupport, "private");
75}
76
77class ACCEmitRemarksPrivate
78 : public acc::impl::ACCEmitRemarksPrivateBase<ACCEmitRemarksPrivate> {
79public:
80 using ACCEmitRemarksPrivateBase<
81 ACCEmitRemarksPrivate>::ACCEmitRemarksPrivateBase;
82
83 void runOnOperation() override {
84 func::FuncOp func = getOperation();
85
86 auto cachedAnalysis = getCachedParentAnalysis<acc::OpenACCSupport>();
87 acc::OpenACCSupport &accSupport = cachedAnalysis
88 ? cachedAnalysis->get()
89 : getAnalysis<acc::OpenACCSupport>();
90
91 func.walk([&](Operation *op) {
93 [&](auto constructOp) {
94 emitRemarksForACCOp(constructOp, accSupport);
95 });
96 });
97 }
98};
99
100} // namespace
#define DEBUG_TYPE
Operation is the basic unit of execution within MLIR.
Definition Operation.h:87
This class provides an abstraction over the different types of ranges over Values.
Definition ValueRange.h:389
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
Definition Value.h:96
remark::detail::InFlightRemark emitRemark(Operation *op, std::function< std::string()> messageFn, llvm::StringRef category="openacc")
Emit an OpenACC remark with lazy message generation.
std::string getVariableName(Value v)
Get the variable name for a given value.
#define ACC_COMPUTE_CONSTRUCT_AND_LOOP_OPS
Definition OpenACC.h:65
Include the generated interface declarations.
llvm::TypeSwitch< T, ResultT > TypeSwitch
Definition LLVM.h:139