diff options
Diffstat (limited to 'mlir/lib/Dialect/OpenACC/Utils/OpenACCUtils.cpp')
| -rw-r--r-- | mlir/lib/Dialect/OpenACC/Utils/OpenACCUtils.cpp | 39 | 
1 files changed, 39 insertions, 0 deletions
| diff --git a/mlir/lib/Dialect/OpenACC/Utils/OpenACCUtils.cpp b/mlir/lib/Dialect/OpenACC/Utils/OpenACCUtils.cpp index 89adda82..660c313 100644 --- a/mlir/lib/Dialect/OpenACC/Utils/OpenACCUtils.cpp +++ b/mlir/lib/Dialect/OpenACC/Utils/OpenACCUtils.cpp @@ -11,6 +11,7 @@  #include "mlir/Dialect/OpenACC/OpenACC.h"  #include "mlir/Interfaces/ViewLikeInterface.h"  #include "llvm/ADT/TypeSwitch.h" +#include "llvm/Support/Casting.h"  mlir::Operation *mlir::acc::getEnclosingComputeOp(mlir::Region ®ion) {    mlir::Operation *parentOp = region.getParentOp(); @@ -106,3 +107,41 @@ std::string mlir::acc::getVariableName(mlir::Value v) {    return "";  } + +std::string mlir::acc::getRecipeName(mlir::acc::RecipeKind kind, +                                     mlir::Type type) { +  assert(kind == mlir::acc::RecipeKind::private_recipe || +         kind == mlir::acc::RecipeKind::firstprivate_recipe || +         kind == mlir::acc::RecipeKind::reduction_recipe); +  if (!llvm::isa<mlir::acc::PointerLikeType, mlir::acc::MappableType>(type)) +    return ""; + +  std::string recipeName; +  llvm::raw_string_ostream ss(recipeName); +  ss << (kind == mlir::acc::RecipeKind::private_recipe ? "privatization_" +         : kind == mlir::acc::RecipeKind::firstprivate_recipe +             ? "firstprivatization_" +             : "reduction_"); + +  // Print the type using its dialect-defined textual format. +  type.print(ss); +  ss.flush(); + +  // Replace invalid characters (anything that's not a letter, number, or +  // period) since this needs to be a valid MLIR identifier. +  for (char &c : recipeName) { +    if (!std::isalnum(static_cast<unsigned char>(c)) && c != '.' && c != '_') { +      if (c == '?') +        c = 'U'; +      else if (c == '*') +        c = 'Z'; +      else if (c == '(' || c == ')' || c == '[' || c == ']' || c == '{' || +               c == '}' || c == '<' || c == '>') +        c = '_'; +      else +        c = 'X'; +    } +  } + +  return recipeName; +} | 
