13#include "llvm/ADT/TypeSwitch.h"
14#include "llvm/Support/Casting.h"
19 if (mlir::isa<ACC_COMPUTE_CONSTRUCT_OPS>(parentOp))
26template <
typename OpTy>
31 if (!region.
isAncestor(user->getParentRegion()))
33 return mlir::isa<OpTy>(user);
36 return llvm::all_of(val.
getUsers(), checkIfUsedOnlyByOpInside);
49std::optional<mlir::acc::ClauseDefaultValue>
51 std::optional<mlir::acc::ClauseDefaultValue> defaultAttr;
58 while (!defaultAttr.has_value() && currOp) {
61 std::optional<mlir::acc::ClauseDefaultValue>>(currOp)
62 .Case<ACC_COMPUTE_CONSTRUCT_OPS, mlir::acc::DataOp>(
63 [&](
auto op) {
return op.getDefaultAttr(); })
64 .Default([&](
Operation *) {
return std::nullopt; });
72 mlir::acc::VariableTypeCategory typeCategory =
73 mlir::acc::VariableTypeCategory::uncategorized;
74 if (
auto mappableTy = dyn_cast<mlir::acc::MappableType>(var.
getType()))
75 typeCategory = mappableTy.getTypeCategory(var);
76 else if (
auto pointerLikeTy =
77 dyn_cast<mlir::acc::PointerLikeType>(var.
getType()))
78 typeCategory = pointerLikeTy.getPointeeTypeCategory(
80 pointerLikeTy.getElementType());
90 if (
auto varNameAttr =
92 return varNameAttr.getName().str();
95 if (isa<ACC_DATA_ENTRY_OPS>(definingOp))
100 if (
auto viewOp = dyn_cast<ViewLikeOpInterface>(definingOp)) {
101 current = viewOp.getViewSource();
113 assert(kind == mlir::acc::RecipeKind::private_recipe ||
114 kind == mlir::acc::RecipeKind::firstprivate_recipe ||
115 kind == mlir::acc::RecipeKind::reduction_recipe);
116 if (!llvm::isa<mlir::acc::PointerLikeType, mlir::acc::MappableType>(type))
119 std::string recipeName;
120 llvm::raw_string_ostream ss(recipeName);
121 ss << (kind == mlir::acc::RecipeKind::private_recipe ?
"privatization_"
122 : kind == mlir::acc::RecipeKind::firstprivate_recipe
123 ?
"firstprivatization_"
132 for (
char &c : recipeName) {
133 if (!std::isalnum(
static_cast<unsigned char>(c)) && c !=
'.' && c !=
'_') {
138 else if (c ==
'(' || c ==
')' || c ==
'[' || c ==
']' || c ==
'{' ||
139 c ==
'}' || c ==
'<' || c ==
'>')
150 if (
auto partialEntityAccessOp =
151 dyn_cast<PartialEntityAccessOpInterface>(val.
getDefiningOp())) {
152 if (!partialEntityAccessOp.isCompleteView())
153 return partialEntityAccessOp.getBaseEntity();
static bool isOnlyUsedByOpClauses(mlir::Value val, mlir::Region ®ion)
Operation is the basic unit of execution within MLIR.
Operation * getParentOp()
Returns the closest surrounding operation that contains this operation or nullptr if this is a top-le...
This class contains a list of basic blocks and a link to the parent operation it is attached to.
bool isAncestor(Region *other)
Return true if this region is ancestor of the other region.
Operation * getParentOp()
Return the parent operation this region is attached to.
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
void print(raw_ostream &os) const
Print the current type.
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
Type getType() const
Return the type of this value.
user_range getUsers() const
Operation * getDefiningOp() const
If this value is the result of an operation, return the operation that defines it.
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 ®ion)
Returns true if this value is only used by acc.reduction operations in the region.
std::optional< llvm::StringRef > getVarName(mlir::Operation *accOp)
Used to obtain the name from an acc operation.
mlir::Operation * getEnclosingComputeOp(mlir::Region ®ion)
Used to obtain the enclosing compute construct operation that contains the provided region.
static constexpr StringLiteral getVarNameAttrName()
std::string getRecipeName(mlir::acc::RecipeKind kind, mlir::Type type)
Get the recipe name for a given recipe kind and type.
mlir::Value getBaseEntity(mlir::Value val)
bool isOnlyUsedByPrivateClauses(mlir::Value val, mlir::Region ®ion)
Returns true if this value is only used by acc.private operations in the region.
std::conditional_t< std::is_same_v< Ty, mlir::Type >, mlir::Value, detail::TypedValue< Ty > > TypedValue
If Ty is mlir::Type this will select Value instead of having a wrapper around it.