MLIR 23.0.0git
OpenACCUtils.h
Go to the documentation of this file.
1//===- OpenACCUtils.h - OpenACC Utilities -----------------------*- C++ -*-===//
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#ifndef MLIR_DIALECT_OPENACC_OPENACCUTILS_H_
10#define MLIR_DIALECT_OPENACC_OPENACCUTILS_H_
11
13#include "mlir/IR/Remarks.h"
14#include "llvm/ADT/SmallVector.h"
15#include "llvm/ADT/StringRef.h"
16
17namespace mlir {
18class DominanceInfo;
20namespace acc {
21
22/// Used to obtain the enclosing compute construct operation that contains
23/// the provided `region`. Returns nullptr if no compute construct operation
24/// is found. The returned operation is one of types defined by
25/// `ACC_COMPUTE_CONSTRUCT_OPS`.
26mlir::Operation *getEnclosingComputeOp(mlir::Region &region);
27
28/// Returns true if this value is only used by `acc.private` operations in the
29/// `region`.
30bool isOnlyUsedByPrivateClauses(mlir::Value val, mlir::Region &region);
31
32/// Returns true if this value is only used by `acc.reduction` operations in
33/// the `region`.
34bool isOnlyUsedByReductionClauses(mlir::Value val, mlir::Region &region);
35
36/// Looks for an OpenACC default attribute on the current operation `op` or in
37/// a parent operation which encloses `op`. This is useful because OpenACC
38/// specification notes that a visible default clause is the nearest default
39/// clause appearing on the compute construct or a lexically containing data
40/// construct.
41std::optional<ClauseDefaultValue> getDefaultAttr(mlir::Operation *op);
42
43/// Get the type category of an OpenACC variable.
44mlir::acc::VariableTypeCategory getTypeCategory(mlir::Value var);
45
46/// Attempts to extract the variable name from a value by walking through
47/// view-like operations until an `acc.var_name` attribute is found. Returns
48/// empty string if no name is found.
49std::string getVariableName(mlir::Value v);
50
51/// Get the recipe name for a given recipe kind and type.
52/// Returns an empty string if not possible to generate a recipe name.
53std::string getRecipeName(mlir::acc::RecipeKind kind, mlir::Type type);
54
55// Get the base entity from partial entity access. This is used for getting
56// the base `struct` from an operation that only accesses a field or the
57// base `array` from an operation that only accesses a subarray.
58mlir::Value getBaseEntity(mlir::Value val);
59
60/// Check if a symbol use is valid for use in an OpenACC region.
61/// This includes looking for various attributes such as `acc.routine_info`
62/// and `acc.declare` attributes.
63/// \param user The operation using the symbol
64/// \param symbol The symbol reference being used
65/// \param definingOpPtr Optional output parameter to receive the defining op
66/// \return true if the symbol use is valid, false otherwise
67bool isValidSymbolUse(mlir::Operation *user, mlir::SymbolRefAttr symbol,
68 mlir::Operation **definingOpPtr = nullptr);
69
70/// Check if a value represents device data.
71/// This checks if the value represents device data via the
72/// MappableType, PointerLikeType, and GlobalVariableOpInterface interfaces.
73/// \param val The value to check
74/// \return true if the value is device data, false otherwise
75bool isDeviceValue(mlir::Value val);
76
77/// Check if a value use is valid in an OpenACC region.
78/// This is true if:
79/// - The value is produced by an ACC data entry operation
80/// - The value is device data
81/// - The value is only used by private clauses in the region
82/// \param val The value to check
83/// \param region The OpenACC region
84/// \return true if the value use is valid, false otherwise
85bool isValidValueUse(mlir::Value val, mlir::Region &region);
86
87/// Collects all data clauses that dominate the compute construct.
88/// This includes data clauses from:
89/// - The compute construct itself
90/// - Enclosing data constructs
91/// - Applicable declare directives (those that dominate and post-dominate)
92/// This is used to determine if a variable is already covered by an existing
93/// data clause.
94/// \param computeConstructOp The compute construct operation
95/// \param domInfo Dominance information
96/// \param postDomInfo Post-dominance information
97/// \return Vector of data clause values that dominate the compute construct
98llvm::SmallVector<mlir::Value>
99getDominatingDataClauses(mlir::Operation *computeConstructOp,
100 mlir::DominanceInfo &domInfo,
101 mlir::PostDominanceInfo &postDomInfo);
102
103/// Emit an OpenACC remark for the given operation with the given message.
104///
105/// \param op The operation to emit the remark for.
106/// \param message The remark message.
107/// \param category Optional category for the remark. Defaults to "openacc".
108/// \return An in-flight remark object that can be used to append
109/// additional information to the remark.
110remark::detail::InFlightRemark emitRemark(mlir::Operation *op,
111 const llvm::Twine &message,
112 llvm::StringRef category = "openacc");
113
114} // namespace acc
115} // namespace mlir
116
117#endif // MLIR_DIALECT_OPENACC_OPENACCUTILS_H_
A class for computing basic dominance information.
Definition Dominance.h:140
A class for computing basic postdominance information.
Definition Dominance.h:204
mlir::acc::VariableTypeCategory getTypeCategory(mlir::Value var)
Get the type category of an OpenACC variable.
std::string getVariableName(mlir::Value v)
Attempts to extract the variable name from a value by walking through view-like operations until an a...
bool isValidSymbolUse(mlir::Operation *user, mlir::SymbolRefAttr symbol, mlir::Operation **definingOpPtr=nullptr)
Check if a symbol use is valid for use in an OpenACC region.
std::optional< ClauseDefaultValue > getDefaultAttr(mlir::Operation *op)
Looks for an OpenACC default attribute on the current operation op or in a parent operation which enc...
bool isOnlyUsedByReductionClauses(mlir::Value val, mlir::Region &region)
Returns true if this value is only used by acc.reduction operations in the region.
remark::detail::InFlightRemark emitRemark(mlir::Operation *op, const llvm::Twine &message, llvm::StringRef category="openacc")
Emit an OpenACC remark for the given operation with the given message.
bool isValidValueUse(mlir::Value val, mlir::Region &region)
Check if a value use is valid in an OpenACC region.
mlir::Operation * getEnclosingComputeOp(mlir::Region &region)
Used to obtain the enclosing compute construct operation that contains the provided region.
llvm::SmallVector< mlir::Value > getDominatingDataClauses(mlir::Operation *computeConstructOp, mlir::DominanceInfo &domInfo, mlir::PostDominanceInfo &postDomInfo)
Collects all data clauses that dominate the compute construct.
std::string getRecipeName(mlir::acc::RecipeKind kind, mlir::Type type)
Get the recipe name for a given recipe kind and type.
bool isDeviceValue(mlir::Value val)
Check if a value represents device data.
mlir::Value getBaseEntity(mlir::Value val)
bool isOnlyUsedByPrivateClauses(mlir::Value val, mlir::Region &region)
Returns true if this value is only used by acc.private operations in the region.
Include the generated interface declarations.