[llvm-branch-commits] [mlir] [MLIR][OpenMP] Automate operand structure definition (PR #99508)
Sergio Afonso via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Fri Jul 19 07:02:56 PDT 2024
================
@@ -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);
----------------
skatrak wrote:
It's because it had to be either a value or an attribute. `isValue` is checked before, returning early, so here we know for sure it must be an attribute (otherwise we somehow stumbled into an argument that isn't either of those things). I'll add a message to the assert.
https://github.com/llvm/llvm-project/pull/99508
More information about the llvm-branch-commits
mailing list