MLIR 22.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/// Collects all data clauses that dominate the compute construct.
71/// This includes data clauses from:
72/// - The compute construct itself
73/// - Enclosing data constructs
74/// - Applicable declare directives (those that dominate and post-dominate)
75/// This is used to determine if a variable is already covered by an existing
76/// data clause.
77/// \param computeConstructOp The compute construct operation
78/// \param domInfo Dominance information
79/// \param postDomInfo Post-dominance information
80/// \return Vector of data clause values that dominate the compute construct
81llvm::SmallVector<mlir::Value>
82getDominatingDataClauses(mlir::Operation *computeConstructOp,
83 mlir::DominanceInfo &domInfo,
84 mlir::PostDominanceInfo &postDomInfo);
85
86/// Emit an OpenACC remark for the given operation with the given message.
87///
88/// \param op The operation to emit the remark for.
89/// \param message The remark message.
90/// \param category Optional category for the remark. Defaults to "openacc".
91/// \return An in-flight remark object that can be used to append
92/// additional information to the remark.
93remark::detail::InFlightRemark emitRemark(mlir::Operation *op,
94 const llvm::Twine &message,
95 llvm::StringRef category = "openacc");
96
97} // namespace acc
98} // namespace mlir
99
100#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...
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...
remark::detail::InFlightRemark emitRemark(Operation *op, const Twine &message, llvm::StringRef category)
bool isOnlyUsedByReductionClauses(mlir::Value val, mlir::Region &region)
Returns true if this value is only used by acc.reduction operations in the 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 isValidSymbolUse(Operation *user, SymbolRefAttr symbol, Operation **definingOpPtr)
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.