[llvm] ed73375 - [tblgen][directive] Fix clause parser generation for list value

Valentin Clement via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 27 11:09:28 PDT 2023


Author: Valentin Clement
Date: 2023-06-27T11:09:23-07:00
New Revision: ed7337506e29622e24da3abb305cd4f7e01da644

URL: https://github.com/llvm/llvm-project/commit/ed7337506e29622e24da3abb305cd4f7e01da644
DIFF: https://github.com/llvm/llvm-project/commit/ed7337506e29622e24da3abb305cd4f7e01da644.diff

LOG: [tblgen][directive] Fix clause parser generation for list value

The clause parser generation was not taking into account the
`isValueList` flag. This patch updates the emitter to generate
the correct code.

Reviewed By: razvanlupusoru

Differential Revision: https://reviews.llvm.org/D153801

Added: 
    

Modified: 
    llvm/test/TableGen/directive1.td
    llvm/utils/TableGen/DirectiveEmitter.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/test/TableGen/directive1.td b/llvm/test/TableGen/directive1.td
index bc36b5f09ef9b..b249f2bf5fc68 100644
--- a/llvm/test/TableGen/directive1.td
+++ b/llvm/test/TableGen/directive1.td
@@ -33,6 +33,11 @@ def TDLC_ClauseB : Clause<"clauseb"> {
   let isDefault = 1;
 }
 
+def TDLC_ClauseC : Clause<"clausec"> {
+  let flangClass = "IntExpr";
+  let isValueList = 1;
+}
+
 def TDL_DirA : Directive<"dira"> {
   let allowedClauses = [
     VersionedClause<TDLC_ClauseA>,
@@ -63,12 +68,14 @@ def TDL_DirA : Directive<"dira"> {
 // CHECK-NEXT:  enum class Clause {
 // CHECK-NEXT:    TDLC_clausea,
 // CHECK-NEXT:    TDLC_clauseb,
+// CHECK-NEXT:    TDLC_clausec,
 // CHECK-NEXT:  };
 // CHECK-EMPTY:
-// CHECK-NEXT:  static constexpr std::size_t Clause_enumSize = 2;
+// CHECK-NEXT:  static constexpr std::size_t Clause_enumSize = 3;
 // CHECK-EMPTY:
 // CHECK-NEXT:  constexpr auto TDLC_clausea = llvm::tdl::Clause::TDLC_clausea;
 // CHECK-NEXT:  constexpr auto TDLC_clauseb = llvm::tdl::Clause::TDLC_clauseb;
+// CHECK-NEXT:  constexpr auto TDLC_clausec = llvm::tdl::Clause::TDLC_clausec;
 // CHECK-EMPTY:
 // CHECK-NEXT:  enum class AKind {
 // CHECK-NEXT:    TDLCV_vala=1,
@@ -147,6 +154,7 @@ def TDL_DirA : Directive<"dira"> {
 // IMPL-EMPTY:
 // IMPL-NEXT:  EMPTY_CLASS(Clausea);
 // IMPL-NEXT:  WRAPPER_CLASS(Clauseb, std::optional<IntExpr>);
+// IMPL-NEXT:  WRAPPER_CLASS(Clausec, std::list<IntExpr>);
 // IMPL-EMPTY:
 // IMPL-NEXT:  #endif // GEN_FLANG_CLAUSE_PARSER_CLASSES
 // IMPL-EMPTY:
@@ -155,6 +163,7 @@ def TDL_DirA : Directive<"dira"> {
 // IMPL-EMPTY:
 // IMPL-NEXT:  Clausea
 // IMPL-NEXT:  , Clauseb
+// IMPL-NEXT:  , Clausec
 // IMPL-EMPTY:
 // IMPL-NEXT:  #endif // GEN_FLANG_CLAUSE_PARSER_CLASSES_LIST
 // IMPL-EMPTY:
@@ -163,6 +172,7 @@ def TDL_DirA : Directive<"dira"> {
 // IMPL-EMPTY:
 // IMPL-NEXT:  NODE(TdlClause, Clausea)
 // IMPL-NEXT:  NODE(TdlClause, Clauseb)
+// IMPL-NEXT:  NODE(TdlClause, Clausec)
 // IMPL-EMPTY:
 // IMPL-NEXT:  #endif // GEN_FLANG_DUMP_PARSE_TREE_CLAUSES
 // IMPL-EMPTY:
@@ -174,6 +184,12 @@ def TDL_DirA : Directive<"dira"> {
 // IMPL-NEXT:    Word("CLAUSEB");
 // IMPL-NEXT:    Walk("(", x.v, ")");
 // IMPL-NEXT:  }
+// IMPL-NEXT:  void Unparse(const TdlClause::Clausec &x) {
+// IMPL-NEXT:    Word("CLAUSEC");
+// IMPL-NEXT:    Put("(");
+// IMPL-NEXT:    Walk(x.v, ",");
+// IMPL-NEXT:    Put(")");
+// IMPL-NEXT:  }
 // IMPL-EMPTY:
 // IMPL-NEXT:  #endif // GEN_FLANG_CLAUSE_UNPARSE
 // IMPL-EMPTY:
@@ -182,6 +198,7 @@ def TDL_DirA : Directive<"dira"> {
 // IMPL-EMPTY:
 // IMPL-NEXT:  void Enter(const parser::TdlClause::Clausea &);
 // IMPL-NEXT:  void Enter(const parser::TdlClause::Clauseb &);
+// IMPL-NEXT:  void Enter(const parser::TdlClause::Clausec &);
 // IMPL-EMPTY:
 // IMPL-NEXT:  #endif // GEN_FLANG_CLAUSE_CHECK_ENTER
 // IMPL-EMPTY:
@@ -192,6 +209,8 @@ def TDL_DirA : Directive<"dira"> {
 // IMPL-NEXT:    return llvm::tdl::Clause::TDLC_clausea;
 // IMPL-NEXT:  if constexpr (std::is_same_v<A, parser::TdlClause::Clauseb>)
 // IMPL-NEXT:    return llvm::tdl::Clause::TDLC_clauseb;
+// IMPL-NEXT:  if constexpr (std::is_same_v<A, parser::TdlClause::Clausec>)
+// IMPL-NEXT:    return llvm::tdl::Clause::TDLC_clausec;
 // IMPL-NEXT:  llvm_unreachable("Invalid Tdl Parser clause");
 // IMPL-EMPTY:
 // IMPL-NEXT:  #endif // GEN_FLANG_CLAUSE_PARSER_KIND_MAP
@@ -200,6 +219,7 @@ def TDL_DirA : Directive<"dira"> {
 // IMPL-NEXT: #undef GEN_FLANG_CLAUSES_PARSER
 // IMPL-EMPTY:
 // IMPL-NEXT:  TYPE_PARSER(
+// IMPL-NEXT:    "clausec" >> construct<TdlClause>(construct<TdlClause::Clausec>(parenthesized(nonemptyList(Parser<IntExpr>{})))) || 
 // IMPL-NEXT:    "clauseb" >> construct<TdlClause>(construct<TdlClause::Clauseb>(maybe(parenthesized(Parser<IntExpr>{})))) ||
 // IMPL-NEXT:    "clausea" >> construct<TdlClause>(construct<TdlClause::Clausea>())
 // IMPL-NEXT:  )
@@ -234,6 +254,7 @@ def TDL_DirA : Directive<"dira"> {
 // IMPL-EMPTY:
 // IMPL-NEXT:  __CLAUSE_NO_CLASS(clausea)
 // IMPL-NEXT:  __CLAUSE_NO_CLASS(clauseb)
+// IMPL-NEXT:  __CLAUSE_NO_CLASS(clausec)
 // IMPL-EMPTY:
 // IMPL-NEXT:  #undef __IMPLICIT_CLAUSE_NO_CLASS
 // IMPL-NEXT:  #undef __IMPLICIT_CLAUSE_CLASS
@@ -266,6 +287,7 @@ def TDL_DirA : Directive<"dira"> {
 // IMPL-NEXT:    return llvm::StringSwitch<Clause>(Str)
 // IMPL-NEXT:      .Case("clausea",TDLC_clausea)
 // IMPL-NEXT:      .Case("clauseb",TDLC_clauseb)
+// IMPL-NEXT:      .Case("clausec",TDLC_clausec)
 // IMPL-NEXT:      .Default(TDLC_clauseb);
 // IMPL-NEXT:  }
 // IMPL-EMPTY:
@@ -275,6 +297,8 @@ def TDL_DirA : Directive<"dira"> {
 // IMPL-NEXT:        return "clausea";
 // IMPL-NEXT:      case TDLC_clauseb:
 // IMPL-NEXT:        return "clauseb";
+// IMPL-NEXT:      case TDLC_clausec:
+// IMPL-NEXT:        return "clausec";
 // IMPL-NEXT:    }
 // IMPL-NEXT:    llvm_unreachable("Invalid Tdl Clause kind");
 // IMPL-NEXT:  }

diff  --git a/llvm/utils/TableGen/DirectiveEmitter.cpp b/llvm/utils/TableGen/DirectiveEmitter.cpp
index 9d2860743308f..67033c6290ca0 100644
--- a/llvm/utils/TableGen/DirectiveEmitter.cpp
+++ b/llvm/utils/TableGen/DirectiveEmitter.cpp
@@ -720,6 +720,8 @@ static void GenerateFlangClausesParser(const DirectiveLanguage &DirLang,
     if (Clause.isValueOptional())
       OS << "maybe(";
     OS << "parenthesized(";
+    if (Clause.isValueList())
+      OS << "nonemptyList(";
 
     if (!Clause.getPrefix().empty())
       OS << "\"" << Clause.getPrefix() << ":\" >> ";
@@ -740,6 +742,8 @@ static void GenerateFlangClausesParser(const DirectiveLanguage &DirLang,
     OS << Parser;
     if (!Clause.getPrefix().empty() && Clause.isPrefixOptional())
       OS << " || " << Parser;
+    if (Clause.isValueList()) // close nonemptyList(.
+      OS << ")";
     OS << ")"; // close parenthesized(.
 
     if (Clause.isValueOptional()) // close maybe(.


        


More information about the llvm-commits mailing list