forked from OSchip/llvm-project
[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
This commit is contained in:
parent
0f8224c210
commit
8f933a4e93
|
@ -68,7 +68,11 @@ public:
|
|||
#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)
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -1850,10 +1850,10 @@ public:
|
|||
}
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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";
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue