MLIR 24.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
19#include "llvm/ADT/StringExtras.h"
20#include "llvm/ADT/Twine.h"
21#include "llvm/ADT/TypeSwitch.h"
22
23namespace mlir {
24namespace acc {
25#define GEN_PASS_DEF_ACCEMITREMARKSPRIVATE
26#include "mlir/Dialect/OpenACC/Transforms/Passes.h.inc"
27} // namespace acc
28} // namespace mlir
29
30#define DEBUG_TYPE "acc-emit-remarks-private"
31
32using namespace mlir;
33
34namespace {
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 getDependentDialects(DialectRegistry &registry) const override {
84 ACCEmitRemarksPrivateBase<ACCEmitRemarksPrivate>::getDependentDialects(
85 registry);
87 }
88
89 void runOnOperation() override {
90 func::FuncOp func = getOperation();
91
92 auto cachedAnalysis = getCachedParentAnalysis<acc::OpenACCSupport>();
93 acc::OpenACCSupport &accSupport = cachedAnalysis
94 ? cachedAnalysis->get()
95 : getAnalysis<acc::OpenACCSupport>();
96
97 func.walk([&](Operation *op) {
99 [&](auto constructOp) {
100 emitRemarksForACCOp(constructOp, accSupport);
101 });
102 });
103 }
104};
105} // namespace
#define DEBUG_TYPE
The DialectRegistry maps a dialect namespace to a constructor for the matching dialect.
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, VariableNameConfig config={})
Get the variable name for a given value.
#define ACC_COMPUTE_CONSTRUCT_AND_LOOP_OPS
Definition OpenACC.h:66
void registerAllExtensions(DialectRegistry &registry)
Register the standard OpenACC models for GPU, LLVM and MemRef IR.
Include the generated interface declarations.
llvm::TypeSwitch< T, ResultT > TypeSwitch
Definition LLVM.h:147