[llvm-branch-commits] [llvm] 8f933a4 - [openacc] Use TableGen enum for default clause value
via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Mon Dec 21 12:11:12 PST 2020
Author: Valentin Clement
Date: 2020-12-21T15:07:27-05:00
New Revision: 8f933a4e931dd1a66f19a81b33399cf7b407308f
URL: https://github.com/llvm/llvm-project/commit/8f933a4e931dd1a66f19a81b33399cf7b407308f
DIFF: https://github.com/llvm/llvm-project/commit/8f933a4e931dd1a66f19a81b33399cf7b407308f.diff
LOG: [openacc] Use TableGen enum for default clause value
Use the TableGen feature to have enum values for clauses.
Next step will be to extend the MLIR part used currently by OpenMP
to use the same enum on the dialect side.
This patch also add function that convert the enum to StringRef to be
used on the dump-parse-tree from flang.
Reviewed By: jdoerfert
Differential Revision: https://reviews.llvm.org/D93576
Added:
Modified:
flang/include/flang/Parser/dump-parse-tree.h
flang/include/flang/Parser/parse-tree.h
flang/lib/Parser/openacc-parsers.cpp
flang/lib/Parser/unparse.cpp
flang/lib/Semantics/resolve-directives.cpp
llvm/include/llvm/Frontend/OpenACC/ACC.td
llvm/test/TableGen/directive1.td
llvm/utils/TableGen/DirectiveEmitter.cpp
Removed:
################################################################################
diff --git a/flang/include/flang/Parser/dump-parse-tree.h b/flang/include/flang/Parser/dump-parse-tree.h
index 7e2d713c127f..f69dd149e0a3 100644
--- a/flang/include/flang/Parser/dump-parse-tree.h
+++ b/flang/include/flang/Parser/dump-parse-tree.h
@@ -68,7 +68,11 @@ class ParseTreeDumper {
#include "llvm/Frontend/OpenACC/ACC.cpp.inc"
NODE(parser, AccBindClause)
NODE(parser, AccDefaultClause)
- NODE_ENUM(parser::AccDefaultClause, Arg)
+ static std::string GetNodeName(const llvm::acc::DefaultValue &x) {
+ return llvm::Twine(
+ "llvm::acc::DefaultValue = ", llvm::acc::getOpenACCDefaultValueName(x))
+ .str();
+ }
NODE(parser, AccClauseList)
NODE(parser, AccCombinedDirective)
NODE(parser, AccDataModifier)
diff --git a/flang/include/flang/Parser/parse-tree.h b/flang/include/flang/Parser/parse-tree.h
index b9d88f6c66f8..59fa278e0029 100644
--- a/flang/include/flang/Parser/parse-tree.h
+++ b/flang/include/flang/Parser/parse-tree.h
@@ -3859,8 +3859,7 @@ struct AccBindClause {
};
struct AccDefaultClause {
- ENUM_CLASS(Arg, None, Present)
- WRAPPER_CLASS_BOILERPLATE(AccDefaultClause, Arg);
+ WRAPPER_CLASS_BOILERPLATE(AccDefaultClause, llvm::acc::DefaultValue);
CharBlock source;
};
diff --git a/flang/lib/Parser/openacc-parsers.cpp b/flang/lib/Parser/openacc-parsers.cpp
index 2447ed70b1a1..26cacc9135c8 100644
--- a/flang/lib/Parser/openacc-parsers.cpp
+++ b/flang/lib/Parser/openacc-parsers.cpp
@@ -171,9 +171,9 @@ TYPE_PARSER(sourced(construct<AccBindClause>(parenthesized(name))) ||
sourced(construct<AccBindClause>(parenthesized(scalarDefaultCharExpr))))
// 2.5.14 Default clause
-TYPE_PARSER(construct<AccDefaultClause>(
- parenthesized(first("NONE" >> pure(AccDefaultClause::Arg::None),
- "PRESENT" >> pure(AccDefaultClause::Arg::Present)))))
+TYPE_PARSER(construct<AccDefaultClause>(parenthesized(
+ first("NONE" >> pure(llvm::acc::DefaultValue::ACC_Default_none),
+ "PRESENT" >> pure(llvm::acc::DefaultValue::ACC_Default_present)))))
// SELF clause is either a simple optional condition for compute construct
// or a synonym of the HOST clause for the update directive 2.14.4 holding
diff --git a/flang/lib/Parser/unparse.cpp b/flang/lib/Parser/unparse.cpp
index b42b09ae723b..a027c8fc9af6 100644
--- a/flang/lib/Parser/unparse.cpp
+++ b/flang/lib/Parser/unparse.cpp
@@ -1850,10 +1850,10 @@ class UnparseVisitor {
}
void Unparse(const AccDefaultClause &x) {
switch (x.v) {
- case AccDefaultClause::Arg::None:
+ case llvm::acc::DefaultValue::ACC_Default_none:
Put("NONE");
break;
- case AccDefaultClause::Arg::Present:
+ case llvm::acc::DefaultValue::ACC_Default_present:
Put("PRESENT");
break;
}
diff --git a/flang/lib/Semantics/resolve-directives.cpp b/flang/lib/Semantics/resolve-directives.cpp
index 7ca42bac569a..a4297ab42540 100644
--- a/flang/lib/Semantics/resolve-directives.cpp
+++ b/flang/lib/Semantics/resolve-directives.cpp
@@ -638,10 +638,10 @@ void AccAttributeVisitor::PrivatizeAssociatedLoopIndex(
void AccAttributeVisitor::Post(const parser::AccDefaultClause &x) {
if (!dirContext_.empty()) {
switch (x.v) {
- case parser::AccDefaultClause::Arg::Present:
+ case llvm::acc::DefaultValue::ACC_Default_present:
SetContextDefaultDSA(Symbol::Flag::AccPresent);
break;
- case parser::AccDefaultClause::Arg::None:
+ case llvm::acc::DefaultValue::ACC_Default_none:
SetContextDefaultDSA(Symbol::Flag::AccNone);
break;
}
diff --git a/llvm/include/llvm/Frontend/OpenACC/ACC.td b/llvm/include/llvm/Frontend/OpenACC/ACC.td
index d5998845a839..d53d3132c969 100644
--- a/llvm/include/llvm/Frontend/OpenACC/ACC.td
+++ b/llvm/include/llvm/Frontend/OpenACC/ACC.td
@@ -80,8 +80,16 @@ def ACCC_Create : Clause<"create"> {
}
// 2.5.15
+def ACC_Default_none : ClauseVal<"none", 1, 0> { let isDefault = 1; }
+def ACC_Default_present : ClauseVal<"present", 0, 0> {}
+
def ACCC_Default : Clause<"default"> {
let flangClassValue = "AccDefaultClause";
+ let enumClauseValue = "DefaultValue";
+ let allowedClauseValues = [
+ ACC_Default_present,
+ ACC_Default_none
+ ];
}
// 2.14.3
diff --git a/llvm/test/TableGen/directive1.td b/llvm/test/TableGen/directive1.td
index 5d9be74e9fce..a63b4065f86a 100644
--- a/llvm/test/TableGen/directive1.td
+++ b/llvm/test/TableGen/directive1.td
@@ -95,6 +95,7 @@ def TDL_DirA : Directive<"dira"> {
// CHECK-NEXT: bool isAllowedClauseForDirective(Directive D, Clause C, unsigned Version);
// CHECK-EMPTY:
// CHECK-NEXT: AKind getAKind(StringRef);
+// CHECK-NEXT: llvm::StringRef getTdlAKindName(AKind);
// CHECK-EMPTY:
// CHECK-NEXT: } // namespace tdl
// CHECK-NEXT: } // namespace llvm
@@ -147,6 +148,18 @@ def TDL_DirA : Directive<"dira"> {
// IMPL-NEXT: .Default(TDLCV_valc);
// IMPL-NEXT: }
// IMPL-EMPTY:
+// IMPL-NEXT: llvm::StringRef llvm::tdl::getTdlAKindName(llvm::tdl::AKind x) {
+// IMPL-NEXT: switch (x) {
+// IMPL-NEXT: case TDLCV_vala:
+// IMPL-NEXT: return "vala";
+// IMPL-NEXT: case TDLCV_valb:
+// IMPL-NEXT: return "valb";
+// IMPL-NEXT: case TDLCV_valc:
+// IMPL-NEXT: return "valc";
+// IMPL-NEXT: }
+// IMPL-NEXT: llvm_unreachable("Invalid Tdl AKind kind");
+// IMPL-NEXT: }
+// IMPL-EMPTY:
// IMPL-NEXT: bool llvm::tdl::isAllowedClauseForDirective(Directive D, Clause C, unsigned Version) {
// IMPL-NEXT: assert(unsigned(D) <= llvm::tdl::Directive_enumSize);
// IMPL-NEXT: assert(unsigned(C) <= llvm::tdl::Clause_enumSize);
diff --git a/llvm/utils/TableGen/DirectiveEmitter.cpp b/llvm/utils/TableGen/DirectiveEmitter.cpp
index ff6050b07f52..6dee19389996 100644
--- a/llvm/utils/TableGen/DirectiveEmitter.cpp
+++ b/llvm/utils/TableGen/DirectiveEmitter.cpp
@@ -107,6 +107,12 @@ void GenerateEnumClauseVal(const std::vector<Record *> &Records,
EnumHelperFuncs += (llvm::Twine(EnumName) + llvm::Twine(" get") +
llvm::Twine(EnumName) + llvm::Twine("(StringRef);\n"))
.str();
+
+ EnumHelperFuncs +=
+ (llvm::Twine("llvm::StringRef get") + llvm::Twine(DirLang.getName()) +
+ llvm::Twine(EnumName) + llvm::Twine("Name(") +
+ llvm::Twine(EnumName) + llvm::Twine(");\n"))
+ .str();
}
}
}
@@ -336,6 +342,22 @@ void GenerateGetKindClauseVal(const DirectiveLanguage &DirLang,
}
OS << " .Default(" << DefaultName << ");\n";
OS << "}\n";
+
+ OS << "\n";
+ OS << "llvm::StringRef llvm::" << DirLang.getCppNamespace() << "::get"
+ << DirLang.getName() << EnumName
+ << "Name(llvm::" << DirLang.getCppNamespace() << "::" << EnumName
+ << " x) {\n";
+ OS << " switch (x) {\n";
+ for (const auto &CV : ClauseVals) {
+ ClauseVal CVal{CV};
+ OS << " case " << CV->getName() << ":\n";
+ OS << " return \"" << CVal.getFormattedName() << "\";\n";
+ }
+ OS << " }\n"; // switch
+ OS << " llvm_unreachable(\"Invalid " << DirLang.getName() << " "
+ << EnumName << " kind\");\n";
+ OS << "}\n";
}
}
More information about the llvm-branch-commits
mailing list