clementval updated this revision to Diff 270481.
clementval added a comment.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Keep same ordering than OMPKinds.def + add dependency


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D81736/new/

https://reviews.llvm.org/D81736

Files:
  clang/lib/Tooling/CMakeLists.txt
  llvm/include/llvm/CMakeLists.txt
  llvm/include/llvm/Frontend/Directive/DirectiveBase.td
  llvm/include/llvm/Frontend/OpenMP/CMakeLists.txt
  llvm/include/llvm/Frontend/OpenMP/OMP.td
  llvm/include/llvm/Frontend/OpenMP/OMPConstants.h
  llvm/lib/Frontend/OpenMP/CMakeLists.txt
  llvm/test/TableGen/directive.td
  llvm/utils/TableGen/CMakeLists.txt
  llvm/utils/TableGen/DirectiveEmitter.cpp
  llvm/utils/TableGen/TableGen.cpp
  llvm/utils/TableGen/TableGenBackends.h

Index: llvm/utils/TableGen/TableGenBackends.h
===================================================================
--- llvm/utils/TableGen/TableGenBackends.h
+++ llvm/utils/TableGen/TableGenBackends.h
@@ -90,6 +90,7 @@
 void EmitRegisterBank(RecordKeeper &RK, raw_ostream &OS);
 void EmitExegesis(RecordKeeper &RK, raw_ostream &OS);
 void EmitAutomata(RecordKeeper &RK, raw_ostream &OS);
+void EmitDirectives(RecordKeeper &RK, raw_ostream &OS);
 
 } // End llvm namespace
 
Index: llvm/utils/TableGen/TableGen.cpp
===================================================================
--- llvm/utils/TableGen/TableGen.cpp
+++ llvm/utils/TableGen/TableGen.cpp
@@ -54,6 +54,7 @@
   GenRegisterBank,
   GenExegesis,
   GenAutomata,
+  GenDirectives,
 };
 
 namespace llvm {
@@ -128,7 +129,9 @@
                    "Generate registers bank descriptions"),
         clEnumValN(GenExegesis, "gen-exegesis",
                    "Generate llvm-exegesis tables"),
-        clEnumValN(GenAutomata, "gen-automata", "Generate generic automata")));
+        clEnumValN(GenAutomata, "gen-automata", "Generate generic automata"),
+        clEnumValN(GenDirectives, "gen-directive-decls",
+                   "Generate directive related declaration code")));
 
 cl::OptionCategory PrintEnumsCat("Options for -print-enums");
 cl::opt<std::string> Class("class", cl::desc("Print Enum list for this class"),
@@ -253,6 +256,8 @@
   case GenAutomata:
     EmitAutomata(Records, OS);
     break;
+  case GenDirectives:
+    EmitDirectives(Records, OS);
   }
 
   return false;
Index: llvm/utils/TableGen/DirectiveEmitter.cpp
===================================================================
--- /dev/null
+++ llvm/utils/TableGen/DirectiveEmitter.cpp
@@ -0,0 +1,103 @@
+//===- DirectiveEmitter.cpp - Directive Language Emitter ------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// DirectiveEmitter uses the descriptions of directives and clauses to construct
+// common code declarations to be used in Frontends.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/StringExtras.h"
+#include "llvm/TableGen/Error.h"
+#include "llvm/TableGen/Record.h"
+#include "llvm/TableGen/TableGenBackend.h"
+
+namespace llvm {
+void EmitDirectives(RecordKeeper &Records, raw_ostream &OS) {
+
+  const auto &directiveLanguages =
+      Records.getAllDerivedDefinitions("DirectiveLanguage");
+
+  if (directiveLanguages.size() != 1) {
+    PrintError("A single definition of DirectiveLanguage is needed.");
+    return;
+  }
+
+  const auto &directiveLanguage = directiveLanguages[0];
+  StringRef directivePrefix =
+      directiveLanguage->getValueAsString("directivePrefix");
+  StringRef clausePrefix = directiveLanguage->getValueAsString("clausePrefix");
+  StringRef cppNamespace = directiveLanguage->getValueAsString("cppNamespace");
+  bool makeEnumAvailableInNamespace =
+      directiveLanguage->getValueAsBit("makeEnumAvailableInNamespace");
+  bool enableBitmaskEnumInNamespace =
+      directiveLanguage->getValueAsBit("enableBitmaskEnumInNamespace");
+
+  if (enableBitmaskEnumInNamespace)
+    OS << "#include \"llvm/ADT/BitmaskEnum.h\"\n";
+
+  OS << "namespace llvm {\n";
+
+  // Open namespaces defined in the directive language
+  llvm::SmallVector<StringRef, 2> namespaces;
+  llvm::SplitString(cppNamespace, namespaces, "::");
+  for (auto ns : namespaces)
+    OS << "namespace " << ns << " {\n";
+
+  if (enableBitmaskEnumInNamespace)
+    OS << "LLVM_ENABLE_BITMASK_ENUMS_IN_NAMESPACE();\n";
+
+  // Emit Directive enumeration
+  OS << "enum class Directive {\n";
+  const auto &directives = Records.getAllDerivedDefinitions("Directive");
+  for (const auto &d : directives) {
+    const auto name = d->getValueAsString("name");
+    std::string n = name.str();
+    std::replace(n.begin(), n.end(), ' ', '_');
+    OS << directivePrefix << n << ",\n";
+  }
+  OS << "};\n";
+
+  // Emit Clause enumeration
+  OS << "enum class Clause {\n";
+  const auto &clauses = Records.getAllDerivedDefinitions("Clause");
+  for (const auto &c : clauses) {
+    const auto name = c->getValueAsString("name");
+    OS << clausePrefix << name << ",\n";
+  }
+  OS << "};\n";
+
+  // Make the enum values available in the defined namespace. This allows us to
+  // write something like Enum_X if we have a `using namespace <cppNamespace>`.
+  // At the same time we do not loose the strong type guarantees of the enum
+  // class, that is we cannot pass an unsigned as Directive without an explicit
+  // cast.
+  if (makeEnumAvailableInNamespace) {
+    for (const auto &d : directives) {
+      const auto name = d->getValueAsString("name");
+      std::string n = name.str();
+      std::replace(n.begin(), n.end(), ' ', '_');
+      OS << "constexpr auto " << directivePrefix << n << " = " << cppNamespace
+         << "::Directive::" << directivePrefix << n << ";\n";
+    }
+
+    for (const auto &c : clauses) {
+      const auto name = c->getValueAsString("name");
+      OS << "constexpr auto " << clausePrefix << name << " = " << cppNamespace
+         << "::Clause::" << clausePrefix << name << ";\n";
+    }
+  }
+
+  // Closing namespaces
+  for (auto ns : llvm::reverse(namespaces))
+    OS << "} // namespace " << ns << "\n";
+
+  OS << "} // namespace llvm\n";
+}
+} // namespace llvm
Index: llvm/utils/TableGen/CMakeLists.txt
===================================================================
--- llvm/utils/TableGen/CMakeLists.txt
+++ llvm/utils/TableGen/CMakeLists.txt
@@ -23,6 +23,7 @@
   DAGISelMatcher.cpp
   DFAEmitter.cpp
   DFAPacketizerEmitter.cpp
+  DirectiveEmitter.cpp
   DisassemblerEmitter.cpp
   ExegesisEmitter.cpp
   FastISelEmitter.cpp
Index: llvm/test/TableGen/directive.td
===================================================================
--- /dev/null
+++ llvm/test/TableGen/directive.td
@@ -0,0 +1,34 @@
+// RUN: llvm-tblgen -gen-directive-decls -I %p/../../include %s | FileCheck %s
+
+include "llvm/Frontend/Directive/DirectiveBase.td"
+
+def TestDirectiveLanguage : DirectiveLanguage {
+  let name = "tdl";
+
+  let cppNamespace = "tdl";
+  let directivePrefix = "TDLD_";
+  let clausePrefix = "TDLC_";
+  let makeEnumAvailableInNamespace = 1;
+}
+
+def TDLC_ClauseA : Clause<"clausea"> {}
+def TDLC_ClauseB : Clause<"clauseb"> {}
+
+def TDL_DirA : Directive<"dira"> {
+  let allowedClauses = [TDLC_ClauseA, TDLC_ClauseB];
+}
+
+// CHECK: namespace llvm {
+// CHECK-NEXT: namespace tdl {
+// CHECK-NEXT: enum class Directive {
+// CHECK-NEXT: TDLD_dira,
+// CHECK-NEXT: }
+// CHECK-NEXT: enum class Clause {
+// CHECK-NEXT: TDLC_clausea,
+// CHECK-NEXT: TDLC_clauseb,
+// CHECK-NEXT: }
+// CHECK-NEXT: constexpr auto TDLD_dira = tdl::Directive::TDLD_dira;
+// CHECK-NEXT: constexpr auto TDLC_clausea = tdl::Clause::TDLC_clausea;
+// CHECK-NEXT: constexpr auto TDLC_clauseb = tdl::Clause::TDLC_clauseb;
+// CHECK-NEXT: }
+// CHECK-NEXT: }
Index: llvm/lib/Frontend/OpenMP/CMakeLists.txt
===================================================================
--- llvm/lib/Frontend/OpenMP/CMakeLists.txt
+++ llvm/lib/Frontend/OpenMP/CMakeLists.txt
@@ -9,4 +9,5 @@
 
   DEPENDS
   intrinsics_gen
+  omp_gen
   )
Index: llvm/include/llvm/Frontend/OpenMP/OMPConstants.h
===================================================================
--- llvm/include/llvm/Frontend/OpenMP/OMPConstants.h
+++ llvm/include/llvm/Frontend/OpenMP/OMPConstants.h
@@ -15,6 +15,7 @@
 #define LLVM_OPENMP_CONSTANTS_H
 
 #include "llvm/ADT/BitmaskEnum.h"
+#include "llvm/Frontend/OpenMP/OMP.inc"
 
 namespace llvm {
 class Type;
@@ -28,26 +29,6 @@
 namespace omp {
 LLVM_ENABLE_BITMASK_ENUMS_IN_NAMESPACE();
 
-/// IDs for all OpenMP directives.
-enum class Directive {
-#define OMP_DIRECTIVE(Enum, ...) Enum,
-#include "llvm/Frontend/OpenMP/OMPKinds.def"
-};
-
-/// IDs for all OpenMP clauses.
-enum class Clause {
-#define OMP_CLAUSE(Enum, ...) Enum,
-#include "llvm/Frontend/OpenMP/OMPKinds.def"
-};
-
-/// Make the enum values available in the llvm::omp namespace. This allows us to
-/// write something like OMPD_parallel if we have a `using namespace omp`. At
-/// the same time we do not loose the strong type guarantees of the enum class,
-/// that is we cannot pass an unsigned as Directive without an explicit cast.
-#define OMP_DIRECTIVE(Enum, ...) constexpr auto Enum = omp::Directive::Enum;
-#define OMP_CLAUSE(Enum, ...) constexpr auto Enum = omp::Clause::Enum;
-#include "llvm/Frontend/OpenMP/OMPKinds.def"
-
 /// IDs for all omp runtime library (RTL) functions.
 enum class RuntimeFunction {
 #define OMP_RTL(Enum, ...) Enum,
Index: llvm/include/llvm/Frontend/OpenMP/OMP.td
===================================================================
--- /dev/null
+++ llvm/include/llvm/Frontend/OpenMP/OMP.td
@@ -0,0 +1,496 @@
+//===-- OMP.td - OpenMP directive definition file ----------*- tablegen -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This is the definition file for OpenMP directives and clauses.
+//
+//===----------------------------------------------------------------------===//
+
+include "llvm/Frontend/Directive/DirectiveBase.td"
+
+//===----------------------------------------------------------------------===//
+// Definition of general OpenMP information
+//===----------------------------------------------------------------------===//
+
+def OpenMP : DirectiveLanguage {
+  let name = "OpenMP";
+  let cppNamespace = "omp"; // final namespace will be llvm::omp
+  let directivePrefix = "OMPD_";
+  let clausePrefix = "OMPC_";
+  let makeEnumAvailableInNamespace = 1;
+  let enableBitmaskEnumInNamespace = 1;
+}
+
+//===----------------------------------------------------------------------===//
+// Definition of OpenMP clauses
+//===----------------------------------------------------------------------===//
+
+def OMPC_Allocator : Clause<"allocator"> {
+  let clangClass = "OMPAllocatorClause";
+}
+def OMPC_If : Clause<"if"> { let clangClass = "OMPIfClause"; }
+def OMPC_Final : Clause<"final"> { let clangClass = "OMPFinalClause"; }
+def OMPC_NumThreads : Clause<"num_threads"> {
+  let clangClass = "OMPNumThreadsClause";
+}
+def OMPC_SafeLen : Clause<"safelen"> { let clangClass = "OMPSafelenClause"; }
+def OMPC_SimdLen : Clause<"simdlen"> { let clangClass = "OMPSimdlenClause"; }
+def OMPC_Collapse : Clause<"collapse"> { let clangClass = "OMPCollapseClause"; }
+def OMPC_Default : Clause<"default"> { let clangClass = "OMPDefaultClause"; }
+def OMPC_Private : Clause<"private"> { let clangClass = "OMPPrivateClause"; }
+def OMPC_FirstPrivate : Clause<"firstprivate"> {
+  let clangClass = "OMPFirstprivateClause";
+}
+def OMPC_LastPrivate : Clause<"lastprivate"> {
+  let clangClass = "OMPLastprivateClause";
+}
+def OMPC_Shared : Clause<"shared"> { let clangClass = "OMPSharedClause"; }
+def OMPC_Reduction : Clause<"reduction"> {
+  let clangClass = "OMPReductionClause";
+}
+def OMPC_Linear : Clause<"linear"> { let clangClass = "OMPLinearClause"; }
+def OMPC_Aligned : Clause<"aligned"> { let clangClass = "OMPAlignedClause"; }
+def OMPC_Copyin : Clause<"copyin"> { let clangClass = "OMPCopyinClause"; }
+def OMPC_CopyPrivate : Clause<"copyprivate"> {
+  let clangClass = "OMPCopyprivateClause";
+}
+def OMPC_ProcBind : Clause<"proc_bind"> {
+  let clangClass = "OMPProcBindClause";
+}
+def OMPC_Schedule : Clause<"schedule"> { let clangClass = "OMPScheduleClause"; }
+def OMPC_Ordered : Clause<"ordered"> { let clangClass = "OMPOrderedClause"; }
+def OMPC_NoWait : Clause<"nowait"> { let clangClass = "OMPNowaitClause"; }
+def OMPC_Untied : Clause<"untied"> { let clangClass = "OMPUntiedClause"; }
+def OMPC_Mergeable : Clause<"mergeable"> {
+  let clangClass = "OMPMergeableClause";
+}
+def OMPC_Read : Clause<"read"> { let clangClass = "OMPReadClause"; }
+def OMPC_Write : Clause<"write"> { let clangClass = "OMPWriteClause"; }
+def OMPC_Update : Clause<"update"> { let clangClass = "OMPUpdateClause"; }
+def OMPC_Capture : Clause<"capture"> { let clangClass = "OMPCaptureClause"; }
+def OMPC_SeqCst : Clause<"seq_cst"> { let clangClass = "OMPSeqCstClause"; }
+def OMPC_AcqRel : Clause<"acq_rel"> { let clangClass = "OMPAcqRelClause"; }
+def OMPC_Acquire : Clause<"acquire"> { let clangClass = "OMPAcquireClause"; }
+def OMPC_Release : Clause<"release"> { let clangClass = "OMPReleaseClause"; }
+def OMPC_Relaxed : Clause<"relaxed"> { let clangClass = "OMPRelaxedClause"; }
+def OMPC_Depend : Clause<"depend"> { let clangClass = "OMPDependClause"; }
+def OMPC_Device : Clause<"device"> { let clangClass = "OMPDeviceClause"; }
+def OMPC_Threads : Clause<"threads"> { let clangClass = "OMPThreadsClause"; }
+def OMPC_Simd : Clause<"simd"> { let clangClass = "OMPSIMDClause"; }
+def OMPC_Map : Clause<"map"> { let clangClass = "OMPMapClause"; }
+def OMPC_NumTeams : Clause<"num_teams"> {
+  let clangClass = "OMPNumTeamsClause";
+}
+def OMPC_ThreadLimit : Clause<"thread_limit"> {
+  let clangClass = "OMPThreadLimitClause";
+}
+def OMPC_Priority : Clause<"priority"> {
+  let clangClass = "OMPPriorityClause";
+}
+def OMPC_GrainSize : Clause<"grainsize"> {
+  let clangClass = "OMPGrainsizeClause";
+}
+def OMPC_NoGroup : Clause<"nogroup"> {
+  let clangClass = "OMPNogroupClause";
+}
+def OMPC_NumTasks : Clause<"num_tasks"> {
+  let clangClass = "OMPNumTasksClause";
+}
+def OMPC_Hint : Clause<"hint"> {
+  let clangClass = "OMPHintClause";
+}
+def OMPC_DistSchedule : Clause<"dist_schedule"> {
+  let clangClass = "OMPDistScheduleClause";
+}
+def OMPC_DefaultMap : Clause<"defaultmap"> {
+  let clangClass = "OMPDefaultmapClause";
+}
+def OMPC_To : Clause<"to"> {
+  let clangClass = "OMPToClause";
+}
+def OMPC_From : Clause<"from"> { let clangClass = "OMPFromClause"; }
+def OMPC_UseDevicePtr : Clause<"use_device_ptr"> {
+  let clangClass = "OMPUseDevicePtrClause";
+}
+def OMPC_IsDevicePtr : Clause<"is_device_ptr"> {
+  let clangClass = "OMPIsDevicePtrClause";
+}
+def OMPC_TaskReduction : Clause<"task_reduction"> {
+  let clangClass = "OMPTaskReductionClause";
+}
+def OMPC_InReduction : Clause<"in_reduction"> {
+  let clangClass = "OMPInReductionClause";
+}
+def OMPC_UnifiedAddress : Clause<"unified_address"> {
+  let clangClass = "OMPUnifiedAddressClause";
+}
+def OMPC_UnifiedSharedMemory : Clause<"unified_shared_memory"> {
+  let clangClass = "OMPUnifiedSharedMemoryClause";
+}
+def OMPC_ReverseOffload : Clause<"reverse_offload"> {
+  let clangClass = "OMPReverseOffloadClause";
+}
+def OMPC_DynamicAllocators : Clause<"dynamic_allocators"> {
+  let clangClass = "OMPDynamicAllocatorsClause";
+}
+def OMPC_AtomicDefaultMemOrder : Clause<"atomic_default_mem_order"> {
+  let clangClass = "OMPAtomicDefaultMemOrderClause";
+}
+def OMPC_Allocate : Clause<"allocate"> {
+  let clangClass = "OMPAllocateClause";
+}
+def OMPC_NonTemporal : Clause<"nontemporal"> {
+  let clangClass = "OMPNontemporalClause";
+}
+def OMPC_Order : Clause<"order"> {
+  let clangClass = "OMPOrderClause";
+}
+def OMPC_Destroy : Clause<"destroy"> {
+  let clangClass = "OMPDestroyClause";
+}
+def OMPC_Detach : Clause<"detach"> {
+  let clangClass = "OMPDetachClause";
+}
+def OMPC_Inclusive : Clause<"inclusive"> {
+  let clangClass = "OMPInclusiveClause";
+}
+def OMPC_Exclusive : Clause<"exclusive"> {
+  let clangClass = "OMPExclusiveClause";
+}
+def OMPC_UsesAllocators : Clause<"uses_allocators"> {
+  let clangClass = "OMPUsesAllocatorsClause";
+}
+def OMPC_Affinity : Clause<"affinity"> {
+  let clangClass = "OMPAffinityClause";
+}
+def OMPC_UseDeviceAddr : Clause<"use_device_addr"> {
+  let clangClass = "OMPUseDeviceAddrClause";
+}
+def OMPC_Uniform : Clause<"uniform"> {}
+def OMPC_DeviceType : Clause<"device_type"> {}
+def OMPC_Match : Clause<"match"> {}
+def OMPC_Depobj : Clause<"depobj"> {
+  let clangClass = "OMPDepobjClause";
+  let isImplicit = 1;
+}
+def OMPC_Flush : Clause<"flush"> {
+  let clangClass = "OMPFlushClause";
+  let isImplicit = 1;
+}
+def OMPC_ThreadPrivate : Clause<"threadprivate"> {
+  // threadprivate or thread local
+  let isImplicit = 1;
+}
+def OMPC_Unknown : Clause<"unknown"> {
+  let isImplicit = 1;
+}
+
+//===----------------------------------------------------------------------===//
+// Definition of OpenMP directives
+//===----------------------------------------------------------------------===//
+
+def OMP_ThreadPrivate : Directive<"threadprivate"> {}
+def OMP_Parallel : Directive<"parallel"> {
+  let allowedClauses = [OMPC_If, OMPC_NumThreads, OMPC_Default, OMPC_ProcBind,
+      OMPC_Private, OMPC_FirstPrivate, OMPC_Shared, OMPC_Reduction, OMPC_Copyin,
+      OMPC_Allocate];
+}
+def OMP_Task : Directive<"task"> {
+  let allowedClauses = [OMPC_If, OMPC_Final, OMPC_Default, OMPC_Private,
+      OMPC_FirstPrivate, OMPC_Shared, OMPC_Untied, OMPC_Mergeable, OMPC_Depend,
+      OMPC_Priority, OMPC_InReduction, OMPC_Allocate, OMPC_Detach,
+      OMPC_Affinity];
+}
+def OMP_Simd : Directive<"simd"> {
+  let allowedClauses = [OMPC_Private, OMPC_LastPrivate, OMPC_Linear,
+      OMPC_Aligned, OMPC_SafeLen, OMPC_SimdLen, OMPC_Collapse, OMPC_Reduction,
+      OMPC_Allocate, OMPC_If, OMPC_NonTemporal, OMPC_Order];
+}
+def OMP_For : Directive<"for"> {
+  let allowedClauses = [OMPC_Private, OMPC_LastPrivate, OMPC_FirstPrivate,
+      OMPC_Reduction, OMPC_Collapse, OMPC_Schedule, OMPC_Ordered, OMPC_NoWait,
+      OMPC_Linear, OMPC_Allocate, OMPC_Order];
+}
+def OMP_Sections : Directive<"sections"> {
+  let allowedClauses = [OMPC_Private, OMPC_LastPrivate, OMPC_FirstPrivate,
+      OMPC_Reduction, OMPC_NoWait, OMPC_Allocate];
+}
+def OMP_Section : Directive<"section"> {}
+def OMP_Single : Directive<"single"> {
+  let allowedClauses = [OMPC_Private, OMPC_FirstPrivate, OMPC_CopyPrivate,
+      OMPC_NoWait, OMPC_Allocate];
+}
+def OMP_Master : Directive<"master"> {}
+def OMP_Critical : Directive<"critical"> {
+  let allowedClauses = [OMPC_Hint];
+}
+def OMP_TaskYield : Directive<"taskyield"> {}
+def OMP_Barrier : Directive<"barrier"> {}
+def OMP_TaskWait : Directive<"taskwait"> {}
+def OMP_TaskGroup : Directive<"taskgroup"> {
+  let allowedClauses = [OMPC_TaskReduction, OMPC_Allocate];
+}
+def OMP_Flush : Directive<"flush"> {
+  let allowedClauses = [OMPC_AcqRel, OMPC_Acquire, OMPC_Release, OMPC_Flush];
+}
+def OMP_Ordered : Directive<"ordered"> {
+  let allowedClauses = [OMPC_Threads, OMPC_Simd, OMPC_Depend];
+}
+def OMP_Atomic : Directive<"atomic"> {
+  let allowedClauses = [OMPC_Read, OMPC_Write, OMPC_Update, OMPC_Capture,
+      OMPC_SeqCst, OMPC_AcqRel, OMPC_Acquire, OMPC_Release, OMPC_Relaxed,
+      OMPC_Hint];
+}
+def OMP_Target : Directive<"target"> {
+  let allowedClauses = [OMPC_If, OMPC_Device, OMPC_Map, OMPC_Private,
+      OMPC_NoWait, OMPC_Depend, OMPC_DefaultMap, OMPC_FirstPrivate,
+      OMPC_IsDevicePtr, OMPC_Reduction, OMPC_Allocate, OMPC_UsesAllocators];
+}
+def OMP_Teams : Directive<"teams"> {
+  let allowedClauses = [OMPC_Default, OMPC_Private, OMPC_FirstPrivate,
+      OMPC_Shared, OMPC_Reduction, OMPC_NumTeams, OMPC_ThreadLimit,
+      OMPC_Allocate];
+}
+def OMP_Cancel : Directive<"cancel"> {
+  let allowedClauses = [OMPC_If];
+}
+def OMP_Requires : Directive<"requires"> {
+  let allowedClauses = [OMPC_UnifiedAddress, OMPC_UnifiedSharedMemory,
+      OMPC_ReverseOffload, OMPC_DynamicAllocators, OMPC_AtomicDefaultMemOrder];
+}
+def OMP_TargetData : Directive<"target data"> {
+  let allowedClauses = [OMPC_If, OMPC_Device, OMPC_Map, OMPC_UseDevicePtr,
+      OMPC_UseDevicePtr];
+}
+def OMP_TargetEnterData : Directive<"target enter data"> {
+  let allowedClauses = [OMPC_If, OMPC_Device, OMPC_Map, OMPC_NoWait,
+      OMPC_Depend];
+}
+def OMP_TargetExitData : Directive<"target exit data"> {
+  let allowedClauses = [OMPC_If, OMPC_Device, OMPC_Map, OMPC_NoWait,
+      OMPC_Depend];
+}
+def OMP_TargetParallel : Directive<"target parallel"> {
+  let allowedClauses = [OMPC_If, OMPC_Device, OMPC_Map, OMPC_NoWait,
+      OMPC_Depend, OMPC_Private, OMPC_FirstPrivate, OMPC_DefaultMap,
+      OMPC_NumThreads, OMPC_Default, OMPC_ProcBind, OMPC_Shared, OMPC_Reduction,
+      OMPC_IsDevicePtr, OMPC_Allocator, OMPC_UsesAllocators];
+}
+def OMP_TargetParallelFor : Directive<"target parallel for"> {
+  let allowedClauses = [OMPC_If, OMPC_Device, OMPC_Map, OMPC_Private,
+      OMPC_FirstPrivate, OMPC_LastPrivate, OMPC_NoWait, OMPC_Depend,
+      OMPC_DefaultMap, OMPC_NumThreads, OMPC_DefaultMap, OMPC_ProcBind,
+      OMPC_Shared, OMPC_Reduction, OMPC_Collapse, OMPC_Schedule, OMPC_Ordered,
+      OMPC_Linear, OMPC_IsDevicePtr, OMPC_Allocator, OMPC_Order,
+      OMPC_UsesAllocators];
+}
+def OMP_TargetUpdate : Directive<"target update"> {
+  let allowedClauses = [OMPC_If, OMPC_Device, OMPC_To, OMPC_From, OMPC_NoWait,
+      OMPC_Depend];
+}
+def OMP_ParallelFor : Directive<"parallel for"> {
+  let allowedClauses = [OMPC_If, OMPC_NumThreads, OMPC_Default, OMPC_ProcBind,
+      OMPC_Private, OMPC_FirstPrivate, OMPC_Shared, OMPC_Reduction, OMPC_Copyin,
+      OMPC_LastPrivate, OMPC_Collapse, OMPC_Schedule, OMPC_Ordered, OMPC_Linear,
+      OMPC_Allocate, OMPC_Order];
+}
+def OMP_ParallelForSimd : Directive<"parallel for simd"> {
+  let allowedClauses = [OMPC_If, OMPC_NumThreads, OMPC_Default, OMPC_ProcBind,
+      OMPC_Private, OMPC_FirstPrivate, OMPC_Shared, OMPC_Reduction, OMPC_Copyin,
+      OMPC_LastPrivate, OMPC_Collapse, OMPC_Schedule, OMPC_SafeLen,
+      OMPC_SimdLen, OMPC_Linear, OMPC_Aligned, OMPC_Ordered, OMPC_Allocate,
+      OMPC_NonTemporal, OMPC_Order];
+}
+def OMP_ParallelMaster : Directive<"parallel master"> {
+  let allowedClauses = [OMPC_If, OMPC_NumThreads, OMPC_Default, OMPC_Private,
+      OMPC_FirstPrivate, OMPC_Shared, OMPC_Copyin, OMPC_Reduction,
+      OMPC_ProcBind, OMPC_Allocate];
+}
+def OMP_ParallelSections : Directive<"parallel sections"> {
+  let allowedClauses = [OMPC_If, OMPC_NumThreads, OMPC_Default, OMPC_ProcBind,
+      OMPC_Private, OMPC_FirstPrivate, OMPC_Shared, OMPC_Reduction, OMPC_Copyin,
+      OMPC_LastPrivate, OMPC_Allocate];
+}
+def OMP_ForSimd : Directive<"for simd"> {
+  let allowedClauses = [OMPC_Private, OMPC_FirstPrivate, OMPC_LastPrivate,
+      OMPC_Reduction, OMPC_Schedule, OMPC_Collapse, OMPC_NoWait, OMPC_SafeLen,
+      OMPC_SimdLen, OMPC_Linear, OMPC_Aligned, OMPC_Ordered, OMPC_Allocate,
+      OMPC_If, OMPC_NonTemporal, OMPC_Order];
+}
+def OMP_CancellationPoint : Directive<"cancellation point"> {}
+def OMP_DeclareReduction : Directive<"declare reduction"> {}
+def OMP_DeclareMapper : Directive<"declare mapper"> {
+  let allowedClauses = [OMPC_Map];
+}
+def OMP_DeclareSimd : Directive<"declare simd"> {}
+def OMP_TaskLoop : Directive<"taskloop"> {
+  let allowedClauses = [OMPC_If, OMPC_Shared, OMPC_Private, OMPC_FirstPrivate,
+      OMPC_LastPrivate, OMPC_Default, OMPC_Collapse, OMPC_Final, OMPC_Untied,
+      OMPC_Mergeable, OMPC_Priority, OMPC_GrainSize, OMPC_NoGroup,
+      OMPC_NumTasks, OMPC_Reduction, OMPC_InReduction, OMPC_Allocate];
+}
+def OMP_TaskLoopSimd : Directive<"taskloop simd"> {
+  let allowedClauses = [OMPC_If, OMPC_Shared, OMPC_Private, OMPC_FirstPrivate,
+      OMPC_LastPrivate, OMPC_Default, OMPC_Collapse, OMPC_Final, OMPC_Untied,
+      OMPC_Mergeable, OMPC_Priority, OMPC_Linear, OMPC_Aligned, OMPC_SafeLen,
+      OMPC_SimdLen, OMPC_GrainSize, OMPC_NoGroup, OMPC_NumTasks, OMPC_Reduction,
+      OMPC_InReduction, OMPC_Allocator, OMPC_NonTemporal, OMPC_Order];
+}
+def OMP_Distribute : Directive<"distribute"> {
+  let allowedClauses = [OMPC_Private, OMPC_FirstPrivate, OMPC_LastPrivate,
+      OMPC_Collapse, OMPC_DistSchedule, OMPC_Allocate];
+}
+def OMP_DeclareTarget : Directive<"declare target"> {}
+def OMP_EndDeclareTarget : Directive<"end declare target"> {}
+def OMP_DistributeParallelFor : Directive<"distribute parallel for"> {
+  let allowedClauses = [OMPC_FirstPrivate, OMPC_LastPrivate, OMPC_Collapse,
+      OMPC_DistSchedule, OMPC_If, OMPC_NumThreads, OMPC_Default, OMPC_ProcBind,
+      OMPC_Private, OMPC_Shared, OMPC_Reduction, OMPC_Copyin, OMPC_Schedule,
+      OMPC_Allocate, OMPC_Order];
+}
+def OMP_DistributeParallelForSimd : Directive<"distribute parallel for simd"> {
+  let allowedClauses = [OMPC_FirstPrivate, OMPC_LastPrivate, OMPC_Collapse,
+      OMPC_DistSchedule, OMPC_If, OMPC_NumThreads, OMPC_Default, OMPC_ProcBind,
+      OMPC_Private, OMPC_Shared, OMPC_Reduction, OMPC_Copyin, OMPC_Schedule,
+      OMPC_Linear, OMPC_Aligned, OMPC_SafeLen, OMPC_SimdLen, OMPC_Allocate,
+      OMPC_NonTemporal, OMPC_Order];
+}
+def OMP_DistributeSimd : Directive<"distribute simd"> {
+  let allowedClauses = [OMPC_Private, OMPC_FirstPrivate, OMPC_LastPrivate,
+      OMPC_Collapse, OMPC_DistSchedule, OMPC_Linear, OMPC_Aligned, OMPC_SafeLen,
+      OMPC_SimdLen, OMPC_Reduction, OMPC_Allocate, OMPC_If, OMPC_NonTemporal,
+      OMPC_Order];
+}
+def OMP_TargetParallelForSimd : Directive<"target parallel for simd"> {
+  let allowedClauses = [OMPC_If, OMPC_Device, OMPC_Map, OMPC_Private,
+      OMPC_FirstPrivate, OMPC_LastPrivate, OMPC_NoWait, OMPC_Depend,
+      OMPC_DefaultMap, OMPC_NumThreads, OMPC_Default, OMPC_ProcBind,
+      OMPC_Shared, OMPC_Reduction, OMPC_Collapse, OMPC_Schedule, OMPC_Ordered,
+      OMPC_Linear, OMPC_SafeLen, OMPC_SimdLen, OMPC_Aligned, OMPC_IsDevicePtr,
+      OMPC_Allocate, OMPC_NonTemporal, OMPC_Order, OMPC_UsesAllocators];
+}
+def OMP_TargetSimd : Directive<"target simd"> {
+  let allowedClauses = [OMPC_If, OMPC_Device, OMPC_Map, OMPC_Private,
+      OMPC_NoWait, OMPC_Depend, OMPC_DefaultMap, OMPC_FirstPrivate,
+      OMPC_IsDevicePtr, OMPC_LastPrivate, OMPC_Linear, OMPC_Aligned,
+      OMPC_SafeLen, OMPC_SimdLen, OMPC_Collapse, OMPC_Reduction, OMPC_Allocate,
+      OMPC_NonTemporal, OMPC_Order, OMPC_UsesAllocators];
+}
+def OMP_TeamsDistribute : Directive<"teams distribute"> {
+  let allowedClauses = [OMPC_Default, OMPC_Private, OMPC_FirstPrivate,
+      OMPC_Shared, OMPC_Reduction, OMPC_NumTeams, OMPC_ThreadLimit,
+      OMPC_LastPrivate, OMPC_Collapse, OMPC_DistSchedule, OMPC_Allocate];
+}
+def OMP_TeamsDistributeSimd : Directive<"teams distribute simd"> {
+  let allowedClauses = [OMPC_Default, OMPC_Private, OMPC_FirstPrivate,
+      OMPC_Shared, OMPC_Reduction, OMPC_NumTeams, OMPC_ThreadLimit,
+      OMPC_LastPrivate, OMPC_Collapse, OMPC_DistSchedule, OMPC_Linear,
+      OMPC_Aligned, OMPC_SafeLen, OMPC_SimdLen, OMPC_Allocate, OMPC_If,
+      OMPC_NonTemporal, OMPC_Order];
+}
+def OMP_TeamsDistributeParallelForSimd :
+    Directive<"teams distribute parallel for simd"> {
+  let allowedClauses = [OMPC_FirstPrivate, OMPC_LastPrivate, OMPC_Collapse,
+      OMPC_DistSchedule, OMPC_If, OMPC_NumThreads, OMPC_Default, OMPC_ProcBind,
+      OMPC_Private, OMPC_Shared, OMPC_Reduction, OMPC_Schedule, OMPC_Linear,
+      OMPC_Aligned, OMPC_SafeLen, OMPC_SimdLen, OMPC_NumTeams, OMPC_ThreadLimit,
+      OMPC_Allocate, OMPC_NonTemporal, OMPC_Order];
+}
+def OMP_TeamsDistributeParallelFor :
+    Directive<"teams distribute parallel for"> {
+  let allowedClauses = [OMPC_FirstPrivate, OMPC_LastPrivate, OMPC_Collapse,
+      OMPC_DistSchedule, OMPC_If, OMPC_NumThreads, OMPC_Default, OMPC_ProcBind,
+      OMPC_Private, OMPC_Shared, OMPC_Reduction, OMPC_Schedule, OMPC_NumTeams,
+      OMPC_ThreadLimit, OMPC_Copyin, OMPC_Allocate, OMPC_Order];
+}
+def OMP_TargetTeams : Directive<"target teams"> {
+  let allowedClauses = [OMPC_If, OMPC_Device, OMPC_Map, OMPC_Private,
+      OMPC_NoWait, OMPC_Depend, OMPC_DefaultMap, OMPC_FirstPrivate,
+      OMPC_IsDevicePtr, OMPC_Default, OMPC_Shared, OMPC_Reduction,
+      OMPC_NumTeams, OMPC_ThreadLimit, OMPC_Allocate, OMPC_UsesAllocators];
+}
+def OMP_TargetTeamsDistribute : Directive<"target teams distribute"> {
+  let allowedClauses = [OMPC_If, OMPC_Device, OMPC_Map, OMPC_Private,
+      OMPC_NoWait, OMPC_Depend, OMPC_DefaultMap, OMPC_FirstPrivate,
+      OMPC_IsDevicePtr, OMPC_Default, OMPC_Shared, OMPC_Reduction,
+      OMPC_NumTeams, OMPC_ThreadLimit, OMPC_LastPrivate, OMPC_Collapse,
+      OMPC_DistSchedule, OMPC_Allocate, OMPC_UsesAllocators];
+}
+def OMP_TargetTeamsDistributeParallelFor :
+    Directive<"target teams distribute parallel for"> {
+  let allowedClauses = [OMPC_If, OMPC_Device, OMPC_Map, OMPC_Private,
+      OMPC_NoWait, OMPC_Depend, OMPC_DefaultMap, OMPC_FirstPrivate,
+      OMPC_IsDevicePtr, OMPC_Default, OMPC_Shared, OMPC_Reduction,
+      OMPC_NumTeams, OMPC_ThreadLimit, OMPC_LastPrivate, OMPC_Collapse,
+      OMPC_DistSchedule, OMPC_NumThreads, OMPC_ProcBind, OMPC_Schedule,
+      OMPC_Allocate, OMPC_Order, OMPC_UsesAllocators];
+}
+def OMP_TargetTeamsDistributeParallelForSimd :
+    Directive<"target teams distribute parallel for simd"> {
+  let allowedClauses = [OMPC_If, OMPC_Device, OMPC_Map, OMPC_Private,
+      OMPC_NoWait, OMPC_Depend, OMPC_DefaultMap, OMPC_FirstPrivate,
+      OMPC_IsDevicePtr, OMPC_Default, OMPC_Shared, OMPC_Reduction,
+      OMPC_NumTeams, OMPC_ThreadLimit, OMPC_LastPrivate, OMPC_Collapse,
+      OMPC_DistSchedule, OMPC_NumThreads, OMPC_ProcBind, OMPC_Schedule,
+      OMPC_Linear, OMPC_Aligned, OMPC_SafeLen, OMPC_SimdLen, OMPC_Allocate,
+      OMPC_NonTemporal, OMPC_Order, OMPC_UsesAllocators];
+}
+def OMP_TargetTeamsDistributeSimd :
+    Directive<"target teams distribute simd"> {
+  let allowedClauses = [OMPC_If, OMPC_Device, OMPC_Map, OMPC_Private,
+      OMPC_NoWait, OMPC_Depend, OMPC_DefaultMap, OMPC_FirstPrivate,
+      OMPC_LastPrivate, OMPC_IsDevicePtr, OMPC_Shared, OMPC_Reduction,
+      OMPC_NumTeams, OMPC_ThreadLimit, OMPC_Collapse, OMPC_DistSchedule,
+      OMPC_Linear, OMPC_Aligned, OMPC_SafeLen, OMPC_SimdLen, OMPC_Allocate,
+      OMPC_NonTemporal, OMPC_Order, OMPC_UsesAllocators];
+}
+def OMP_Allocate : Directive<"allocate"> {
+  let allowedClauses = [OMPC_Allocator];
+}
+def OMP_DeclareVariant : Directive<"declare variant"> {
+  let allowedClauses = [OMPC_Match];
+}
+def OMP_MasterTaskloop : Directive<"master taskloop"> {
+  let allowedClauses = [
+      OMPC_If, OMPC_Shared, OMPC_Private, OMPC_FirstPrivate, OMPC_LastPrivate,
+      OMPC_Default, OMPC_Collapse, OMPC_Final, OMPC_Untied, OMPC_Mergeable,
+      OMPC_Priority, OMPC_GrainSize, OMPC_NoGroup, OMPC_NumTasks,
+      OMPC_Reduction, OMPC_InReduction, OMPC_Allocate];
+}
+def OMP_ParallelMasterTaskloop :
+    Directive<"parallel master taskloop"> {
+  let allowedClauses = [OMPC_If, OMPC_Shared, OMPC_Private, OMPC_FirstPrivate,
+      OMPC_LastPrivate, OMPC_Default, OMPC_Collapse, OMPC_Final, OMPC_Untied,
+      OMPC_Mergeable, OMPC_Priority, OMPC_GrainSize, OMPC_NoGroup,
+      OMPC_NumTasks, OMPC_Reduction, OMPC_Allocate, OMPC_NumThreads,
+      OMPC_ProcBind, OMPC_Copyin];
+}
+def OMP_MasterTaskloopSimd : Directive<"master taskloop simd"> {
+  let allowedClauses = [OMPC_If, OMPC_Shared, OMPC_Private, OMPC_FirstPrivate,
+      OMPC_LastPrivate, OMPC_DefaultMap, OMPC_Collapse, OMPC_Final, OMPC_Untied,
+      OMPC_Mergeable, OMPC_Priority, OMPC_Linear, OMPC_Aligned, OMPC_SafeLen,
+      OMPC_SimdLen, OMPC_GrainSize, OMPC_NoGroup, OMPC_NumTasks, OMPC_Reduction,
+      OMPC_InReduction, OMPC_Allocate, OMPC_NonTemporal, OMPC_Order];
+}
+def OMP_ParallelMasterTaskloopSimd :
+    Directive<"parallel master taskloop simd"> {
+  let allowedClauses = [OMPC_If, OMPC_Shared, OMPC_Private, OMPC_FirstPrivate,
+      OMPC_LastPrivate, OMPC_Default, OMPC_Collapse, OMPC_Final, OMPC_Untied,
+      OMPC_Mergeable, OMPC_Priority, OMPC_GrainSize, OMPC_NoGroup,
+      OMPC_NumTasks, OMPC_Reduction, OMPC_Allocate, OMPC_NumThreads,
+      OMPC_ProcBind, OMPC_Copyin, OMPC_Linear, OMPC_Aligned, OMPC_SafeLen,
+      OMPC_SimdLen, OMPC_NonTemporal, OMPC_Order];
+}
+def OMP_Depobj : Directive<"depobj"> {
+  let allowedClauses = [OMPC_Depend, OMPC_Destroy, OMPC_Update, OMPC_Depobj];
+}
+def OMP_Scan : Directive<"scan"> {
+  let allowedClauses = [OMPC_Inclusive, OMPC_Exclusive];
+}
+def OMP_BeginDeclareVariant : Directive<"begin declare variant"> {}
+def OMP_EndDeclareVariant : Directive<"end declare variant"> {}
+def OMP_Unknown : Directive<"unknown"> {}
Index: llvm/include/llvm/Frontend/OpenMP/CMakeLists.txt
===================================================================
--- /dev/null
+++ llvm/include/llvm/Frontend/OpenMP/CMakeLists.txt
@@ -0,0 +1,3 @@
+set(LLVM_TARGET_DEFINITIONS OMP.td)
+tablegen(LLVM OMP.inc --gen-directive-decls)
+add_public_tablegen_target(omp_gen)
Index: llvm/include/llvm/Frontend/Directive/DirectiveBase.td
===================================================================
--- /dev/null
+++ llvm/include/llvm/Frontend/Directive/DirectiveBase.td
@@ -0,0 +1,69 @@
+//===-- DirectiveBase.td - Base directive definition file --*- tablegen -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This is the base definition file directives and clauses.
+//
+//===----------------------------------------------------------------------===//
+
+
+// General information about the directive language
+class DirectiveLanguage {
+  // Name of the directive language such as omp or acc.
+  string name = ?;
+
+  // The C++ namespace that code of this directive language should be placed
+  // into. This namespace is nested in llvm namespace.
+  //
+  // By default, uses the name of the dialect as the only namespace. To avoid
+  // placing in any namespace, use "". To specify nested namespaces, use "::"
+  // as the delimiter, e.g., given "A::B", ops will be placed in
+  // `namespace A { namespace B { <directives-clauses> } }`.
+  string cppNamespace = name;
+
+  // Optional prefix used for the generation of the enumerator in the Directive
+  // enum.
+  string directivePrefix = "";
+
+  // Optional prefix used for the generation of the enumerator in the Clause
+  // enum.
+  string clausePrefix = "";
+
+  // Make the enum values available in the namespace. This allows us to
+  // write something like Enum_X if we have a `using namespace cppNamespace`.
+  bit makeEnumAvailableInNamespace = 0;
+
+  // Generate include and macro to enable LLVM BitmaskEnum
+  bit enableBitmaskEnumInNamespace = 0;
+}
+
+// Information about a specific clause
+class Clause<string c> {
+  // Name of the clause
+  string name = c;
+
+  // Optional class holding value of the clause in clang AST
+  string clangClass = ?;
+
+  // Is clause implicit?
+  bit isImplicit = 0;
+}
+
+// Information about a specific directive
+class Directive<string d> {
+  // Name of the directive. Can be composite directive sepearted by whitespace.
+  string name = d;
+
+  // List of allowed clauses for the directive.
+  list<Clause> allowedClauses = ?;
+
+  // List of clauses that are allowed to appear only once.
+  list<Clause> allowedOnceClauses = ?;
+
+  // List of clauses that are required.
+  list<Clause> requiredClauses = ?;
+}
Index: llvm/include/llvm/CMakeLists.txt
===================================================================
--- llvm/include/llvm/CMakeLists.txt
+++ llvm/include/llvm/CMakeLists.txt
@@ -1,5 +1,6 @@
 add_subdirectory(IR)
 add_subdirectory(Support)
+add_subdirectory(Frontend/OpenMP)
 
 # If we're doing an out-of-tree build, copy a module map for generated
 # header files into the build area.
Index: clang/lib/Tooling/CMakeLists.txt
===================================================================
--- clang/lib/Tooling/CMakeLists.txt
+++ clang/lib/Tooling/CMakeLists.txt
@@ -31,6 +31,7 @@
 
   DEPENDS
   ClangDriverOptions
+  omp_gen
 
   LINK_LIBS
   clangAST
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to