================ @@ -148,6 +169,110 @@ static void verifyClause(Record *op, Record *clause) { "or explicitly skipping this field."); } +/// Translate the type of an OpenMP clause's argument to its corresponding +/// representation for clause operand structures. +/// +/// All kinds of values are represented as `mlir::Value` fields, whereas +/// attributes are represented based on their `storageType`. +/// +/// \param[in] init The `DefInit` object representing the argument. +/// \param[out] rank Number of levels of array nesting associated with the +/// type. +/// +/// \return the name of the base type to represent elements of the argument +/// type. +static StringRef translateArgumentType(Init *init, int &rank) { + Record *def = cast<DefInit>(init)->getDef(); + bool isAttr = false, isValue = false; + + for (auto [sc, _] : def->getSuperClasses()) { + std::string scName = sc->getNameInitAsString(); + if (scName == "OptionalAttr") + return translateArgumentType(def->getValue("baseAttr")->getValue(), rank); + + if (scName == "TypedArrayAttrBase") { + ++rank; + return translateArgumentType(def->getValue("elementAttr")->getValue(), + rank); + } + + if (scName == "ElementsAttrBase") { + rank += def->getValueAsInt("rank"); + return def->getValueAsString("elementReturnType").trim(); + } + + if (scName == "Attr") + isAttr = true; + else if (scName == "TypeConstraint") + isValue = true; + else if (scName == "Variadic") + ++rank; + } + + if (isValue) { + assert(!isAttr); + return "::mlir::Value"; + } + + assert(isAttr); ---------------- Meinersbur wrote:
[nit] Add description on why `isAttr` is required here. It is not used on the next line. https://github.com/llvm/llvm-project/pull/99508 _______________________________________________ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits