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 "llvm/ADT/SmallVector.h"
14
15namespace mlir {
16class DominanceInfo;
18namespace acc {
19
20/// Used to obtain the enclosing compute construct operation that contains
21/// the provided `region`. Returns nullptr if no compute construct operation
22/// is found. The returned operation is one of types defined by
23/// `ACC_COMPUTE_CONSTRUCT_OPS`.
24mlir::Operation *getEnclosingComputeOp(mlir::Region &region);
25
26/// Returns true if this value is only used by `acc.private` operations in the
27/// `region`.
28bool isOnlyUsedByPrivateClauses(mlir::Value val, mlir::Region &region);
29
30/// Returns true if this value is only used by `acc.reduction` operations in
31/// the `region`.
32bool isOnlyUsedByReductionClauses(mlir::Value val, mlir::Region &region);
33
34/// Looks for an OpenACC default attribute on the current operation `op` or in
35/// a parent operation which encloses `op`. This is useful because OpenACC
36/// specification notes that a visible default clause is the nearest default
37/// clause appearing on the compute construct or a lexically containing data
38/// construct.
39std::optional<ClauseDefaultValue> getDefaultAttr(mlir::Operation *op);
40
41/// Get the type category of an OpenACC variable.
42mlir::acc::VariableTypeCategory getTypeCategory(mlir::Value var);
43
44/// Attempts to extract the variable name from a value by walking through
45/// view-like operations until an `acc.var_name` attribute is found. Returns
46/// empty string if no name is found.
47std::string getVariableName(mlir::Value v);
48
49/// Get the recipe name for a given recipe kind and type.
50/// Returns an empty string if not possible to generate a recipe name.
51std::string getRecipeName(mlir::acc::RecipeKind kind, mlir::Type type);
52
53// Get the base entity from partial entity access. This is used for getting
54// the base `struct` from an operation that only accesses a field or the
55// base `array` from an operation that only accesses a subarray.
56mlir::Value getBaseEntity(mlir::Value val);
57
58/// Check if a symbol use is valid for use in an OpenACC region.
59/// This includes looking for various attributes such as `acc.routine_info`
60/// and `acc.declare` attributes.
61/// \param user The operation using the symbol
62/// \param symbol The symbol reference being used
63/// \param definingOpPtr Optional output parameter to receive the defining op
64/// \return true if the symbol use is valid, false otherwise
65bool isValidSymbolUse(mlir::Operation *user, mlir::SymbolRefAttr symbol,
66 mlir::Operation **definingOpPtr = nullptr);
67
68/// Collects all data clauses that dominate the compute construct.
69/// This includes data clauses from:
70/// - The compute construct itself
71/// - Enclosing data constructs
72/// - Applicable declare directives (those that dominate and post-dominate)
73/// This is used to determine if a variable is already covered by an existing
74/// data clause.
75/// \param computeConstructOp The compute construct operation
76/// \param domInfo Dominance information
77/// \param postDomInfo Post-dominance information
78/// \return Vector of data clause values that dominate the compute construct
79llvm::SmallVector<mlir::Value>
80getDominatingDataClauses(mlir::Operation *computeConstructOp,
81 mlir::DominanceInfo &domInfo,
82 mlir::PostDominanceInfo &postDomInfo);
83
84} // namespace acc
85} // namespace mlir
86
87#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...
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.