[openmp] Base of tablegen generated OpenMP common declaration
Summary:
As discussed previously when landing patch for OpenMP in Flang, the idea is
to share common part of the OpenMP declaration between the different Frontend.
While doing this it was thought that moving to tablegen instead of Macros will also
give a cleaner and more powerful way of generating these declaration.
This first part of a future series of patches is setting up the base .td file for
DirectiveLanguage as well as the OpenMP version of it. The base file is meant to
be used by other directive language such as OpenACC.
In this first patch, the Directive and Clause enums are generated with tablegen
instead of the macros on OMPConstants.h. The next pacth will extend this
to other enum and move the Flang frontend to use it.
Reviewers: jdoerfert, DavidTruby, fghanim, ABataev, jdenny, hfinkel, jhuber6, kiranchandramohan, kiranktp
Reviewed By: jdoerfert, jdenny
Subscribers: arphaman, martong, cfe-commits, mgorny, yaxunl, hiraditya, guansong, jfb, sstefan1, aaron.ballman, llvm-commits
Tags: #llvm, #openmp, #clang
Differential Revision: https://reviews.llvm.org/D81736
2020-06-23 15:29:50 +02:00
|
|
|
//===- 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.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2020-07-22 18:28:04 +02:00
|
|
|
#include "llvm/TableGen/DirectiveEmitter.h"
|
[openmp] Base of tablegen generated OpenMP common declaration
Summary:
As discussed previously when landing patch for OpenMP in Flang, the idea is
to share common part of the OpenMP declaration between the different Frontend.
While doing this it was thought that moving to tablegen instead of Macros will also
give a cleaner and more powerful way of generating these declaration.
This first part of a future series of patches is setting up the base .td file for
DirectiveLanguage as well as the OpenMP version of it. The base file is meant to
be used by other directive language such as OpenACC.
In this first patch, the Directive and Clause enums are generated with tablegen
instead of the macros on OMPConstants.h. The next pacth will extend this
to other enum and move the Flang frontend to use it.
Reviewers: jdoerfert, DavidTruby, fghanim, ABataev, jdenny, hfinkel, jhuber6, kiranchandramohan, kiranktp
Reviewed By: jdoerfert, jdenny
Subscribers: arphaman, martong, cfe-commits, mgorny, yaxunl, hiraditya, guansong, jfb, sstefan1, aaron.ballman, llvm-commits
Tags: #llvm, #openmp, #clang
Differential Revision: https://reviews.llvm.org/D81736
2020-06-23 15:29:50 +02:00
|
|
|
#include "llvm/ADT/STLExtras.h"
|
|
|
|
#include "llvm/ADT/SmallVector.h"
|
[flang][openmp] Check clauses allowed semantic with tablegen generated map
Summary:
This patch is enabling the generation of clauses enum sets for semantics check in Flang through
tablegen. Enum sets and directive - sets map is generated by the new tablegen infrsatructure for OpenMP
and other directive languages.
The semantic checks for OpenMP are modified to use this newly generated map.
Reviewers: DavidTruby, sscalpone, kiranchandramohan, ichoyjx, jdoerfert
Reviewed By: DavidTruby, ichoyjx
Subscribers: mgorny, yaxunl, hiraditya, guansong, sstefan1, aaron.ballman, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D83326
2020-07-11 18:42:05 +02:00
|
|
|
#include "llvm/ADT/StringSet.h"
|
[openmp] Base of tablegen generated OpenMP common declaration
Summary:
As discussed previously when landing patch for OpenMP in Flang, the idea is
to share common part of the OpenMP declaration between the different Frontend.
While doing this it was thought that moving to tablegen instead of Macros will also
give a cleaner and more powerful way of generating these declaration.
This first part of a future series of patches is setting up the base .td file for
DirectiveLanguage as well as the OpenMP version of it. The base file is meant to
be used by other directive language such as OpenACC.
In this first patch, the Directive and Clause enums are generated with tablegen
instead of the macros on OMPConstants.h. The next pacth will extend this
to other enum and move the Flang frontend to use it.
Reviewers: jdoerfert, DavidTruby, fghanim, ABataev, jdenny, hfinkel, jhuber6, kiranchandramohan, kiranktp
Reviewed By: jdoerfert, jdenny
Subscribers: arphaman, martong, cfe-commits, mgorny, yaxunl, hiraditya, guansong, jfb, sstefan1, aaron.ballman, llvm-commits
Tags: #llvm, #openmp, #clang
Differential Revision: https://reviews.llvm.org/D81736
2020-06-23 15:29:50 +02:00
|
|
|
#include "llvm/TableGen/Error.h"
|
|
|
|
#include "llvm/TableGen/Record.h"
|
|
|
|
#include "llvm/TableGen/TableGenBackend.h"
|
|
|
|
|
[openmp] Move Directive and Clause helper function to tablegen
Summary:
Follow up to D81736. Move getOpenMPDirectiveKind, getOpenMPClauseKind, getOpenMPDirectiveName and
getOpenMPClauseName to the new tablegen code generation. The code is generated in a new file named OMP.cpp.inc
Reviewers: jdoerfert, jdenny, thakis
Reviewed By: jdoerfert, jdenny
Subscribers: mgorny, yaxunl, hiraditya, guansong, sstefan1, llvm-commits, thakis
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D82405
2020-06-30 20:36:37 +02:00
|
|
|
using namespace llvm;
|
|
|
|
|
[flang][openmp] Check clauses allowed semantic with tablegen generated map
Summary:
This patch is enabling the generation of clauses enum sets for semantics check in Flang through
tablegen. Enum sets and directive - sets map is generated by the new tablegen infrsatructure for OpenMP
and other directive languages.
The semantic checks for OpenMP are modified to use this newly generated map.
Reviewers: DavidTruby, sscalpone, kiranchandramohan, ichoyjx, jdoerfert
Reviewed By: DavidTruby, ichoyjx
Subscribers: mgorny, yaxunl, hiraditya, guansong, sstefan1, aaron.ballman, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D83326
2020-07-11 18:42:05 +02:00
|
|
|
namespace {
|
|
|
|
// Simple RAII helper for defining ifdef-undef-endif scopes.
|
|
|
|
class IfDefScope {
|
|
|
|
public:
|
|
|
|
IfDefScope(StringRef Name, raw_ostream &OS) : Name(Name), OS(OS) {
|
|
|
|
OS << "#ifdef " << Name << "\n"
|
|
|
|
<< "#undef " << Name << "\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
~IfDefScope() { OS << "\n#endif // " << Name << "\n\n"; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
StringRef Name;
|
|
|
|
raw_ostream &OS;
|
|
|
|
};
|
|
|
|
} // end anonymous namespace
|
|
|
|
|
[openmp] Base of tablegen generated OpenMP common declaration
Summary:
As discussed previously when landing patch for OpenMP in Flang, the idea is
to share common part of the OpenMP declaration between the different Frontend.
While doing this it was thought that moving to tablegen instead of Macros will also
give a cleaner and more powerful way of generating these declaration.
This first part of a future series of patches is setting up the base .td file for
DirectiveLanguage as well as the OpenMP version of it. The base file is meant to
be used by other directive language such as OpenACC.
In this first patch, the Directive and Clause enums are generated with tablegen
instead of the macros on OMPConstants.h. The next pacth will extend this
to other enum and move the Flang frontend to use it.
Reviewers: jdoerfert, DavidTruby, fghanim, ABataev, jdenny, hfinkel, jhuber6, kiranchandramohan, kiranktp
Reviewed By: jdoerfert, jdenny
Subscribers: arphaman, martong, cfe-commits, mgorny, yaxunl, hiraditya, guansong, jfb, sstefan1, aaron.ballman, llvm-commits
Tags: #llvm, #openmp, #clang
Differential Revision: https://reviews.llvm.org/D81736
2020-06-23 15:29:50 +02:00
|
|
|
namespace llvm {
|
[openmp] Move Directive and Clause helper function to tablegen
Summary:
Follow up to D81736. Move getOpenMPDirectiveKind, getOpenMPClauseKind, getOpenMPDirectiveName and
getOpenMPClauseName to the new tablegen code generation. The code is generated in a new file named OMP.cpp.inc
Reviewers: jdoerfert, jdenny, thakis
Reviewed By: jdoerfert, jdenny
Subscribers: mgorny, yaxunl, hiraditya, guansong, sstefan1, llvm-commits, thakis
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D82405
2020-06-30 20:36:37 +02:00
|
|
|
|
|
|
|
// Generate enum class
|
|
|
|
void GenerateEnumClass(const std::vector<Record *> &Records, raw_ostream &OS,
|
2020-07-29 02:45:21 +02:00
|
|
|
StringRef Enum, StringRef Prefix,
|
2020-11-03 17:12:14 +01:00
|
|
|
const DirectiveLanguage &DirLang) {
|
[openmp] Move Directive and Clause helper function to tablegen
Summary:
Follow up to D81736. Move getOpenMPDirectiveKind, getOpenMPClauseKind, getOpenMPDirectiveName and
getOpenMPClauseName to the new tablegen code generation. The code is generated in a new file named OMP.cpp.inc
Reviewers: jdoerfert, jdenny, thakis
Reviewed By: jdoerfert, jdenny
Subscribers: mgorny, yaxunl, hiraditya, guansong, sstefan1, llvm-commits, thakis
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D82405
2020-06-30 20:36:37 +02:00
|
|
|
OS << "\n";
|
|
|
|
OS << "enum class " << Enum << " {\n";
|
|
|
|
for (const auto &R : Records) {
|
2020-07-29 02:45:21 +02:00
|
|
|
BaseRecord Rec{R};
|
|
|
|
OS << " " << Prefix << Rec.getFormattedName() << ",\n";
|
[openmp] Move Directive and Clause helper function to tablegen
Summary:
Follow up to D81736. Move getOpenMPDirectiveKind, getOpenMPClauseKind, getOpenMPDirectiveName and
getOpenMPClauseName to the new tablegen code generation. The code is generated in a new file named OMP.cpp.inc
Reviewers: jdoerfert, jdenny, thakis
Reviewed By: jdoerfert, jdenny
Subscribers: mgorny, yaxunl, hiraditya, guansong, sstefan1, llvm-commits, thakis
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D82405
2020-06-30 20:36:37 +02:00
|
|
|
}
|
|
|
|
OS << "};\n";
|
|
|
|
OS << "\n";
|
|
|
|
OS << "static constexpr std::size_t " << Enum
|
|
|
|
<< "_enumSize = " << Records.size() << ";\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.
|
2020-07-29 02:45:21 +02:00
|
|
|
if (DirLang.hasMakeEnumAvailableInNamespace()) {
|
[openmp] Move Directive and Clause helper function to tablegen
Summary:
Follow up to D81736. Move getOpenMPDirectiveKind, getOpenMPClauseKind, getOpenMPDirectiveName and
getOpenMPClauseName to the new tablegen code generation. The code is generated in a new file named OMP.cpp.inc
Reviewers: jdoerfert, jdenny, thakis
Reviewed By: jdoerfert, jdenny
Subscribers: mgorny, yaxunl, hiraditya, guansong, sstefan1, llvm-commits, thakis
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D82405
2020-06-30 20:36:37 +02:00
|
|
|
OS << "\n";
|
|
|
|
for (const auto &R : Records) {
|
2020-07-29 02:45:21 +02:00
|
|
|
BaseRecord Rec{R};
|
|
|
|
OS << "constexpr auto " << Prefix << Rec.getFormattedName() << " = "
|
|
|
|
<< "llvm::" << DirLang.getCppNamespace() << "::" << Enum
|
|
|
|
<< "::" << Prefix << Rec.getFormattedName() << ";\n";
|
[openmp] Move Directive and Clause helper function to tablegen
Summary:
Follow up to D81736. Move getOpenMPDirectiveKind, getOpenMPClauseKind, getOpenMPDirectiveName and
getOpenMPClauseName to the new tablegen code generation. The code is generated in a new file named OMP.cpp.inc
Reviewers: jdoerfert, jdenny, thakis
Reviewed By: jdoerfert, jdenny
Subscribers: mgorny, yaxunl, hiraditya, guansong, sstefan1, llvm-commits, thakis
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D82405
2020-06-30 20:36:37 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-22 18:28:04 +02:00
|
|
|
// Generate enums for values that clauses can take.
|
|
|
|
// Also generate function declarations for get<Enum>Name(StringRef Str).
|
|
|
|
void GenerateEnumClauseVal(const std::vector<Record *> &Records,
|
2020-11-03 17:12:14 +01:00
|
|
|
raw_ostream &OS, const DirectiveLanguage &DirLang,
|
2020-07-22 18:28:04 +02:00
|
|
|
std::string &EnumHelperFuncs) {
|
|
|
|
for (const auto &R : Records) {
|
|
|
|
Clause C{R};
|
|
|
|
const auto &ClauseVals = C.getClauseVals();
|
|
|
|
if (ClauseVals.size() <= 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
const auto &EnumName = C.getEnumName();
|
|
|
|
if (EnumName.size() == 0) {
|
|
|
|
PrintError("enumClauseValue field not set in Clause" +
|
|
|
|
C.getFormattedName() + ".");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
OS << "\n";
|
|
|
|
OS << "enum class " << EnumName << " {\n";
|
|
|
|
for (const auto &CV : ClauseVals) {
|
|
|
|
ClauseVal CVal{CV};
|
|
|
|
OS << " " << CV->getName() << "=" << CVal.getValue() << ",\n";
|
|
|
|
}
|
|
|
|
OS << "};\n";
|
|
|
|
|
|
|
|
if (DirLang.hasMakeEnumAvailableInNamespace()) {
|
|
|
|
OS << "\n";
|
|
|
|
for (const auto &CV : ClauseVals) {
|
|
|
|
OS << "constexpr auto " << CV->getName() << " = "
|
|
|
|
<< "llvm::" << DirLang.getCppNamespace() << "::" << EnumName
|
|
|
|
<< "::" << CV->getName() << ";\n";
|
|
|
|
}
|
|
|
|
EnumHelperFuncs += (llvm::Twine(EnumName) + llvm::Twine(" get") +
|
|
|
|
llvm::Twine(EnumName) + llvm::Twine("(StringRef);\n"))
|
|
|
|
.str();
|
2020-12-21 21:06:55 +01:00
|
|
|
|
|
|
|
EnumHelperFuncs +=
|
|
|
|
(llvm::Twine("llvm::StringRef get") + llvm::Twine(DirLang.getName()) +
|
|
|
|
llvm::Twine(EnumName) + llvm::Twine("Name(") +
|
|
|
|
llvm::Twine(EnumName) + llvm::Twine(");\n"))
|
|
|
|
.str();
|
2020-07-22 18:28:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-28 20:11:47 +01:00
|
|
|
bool HasDuplicateClauses(const std::vector<Record *> &Clauses,
|
|
|
|
const Directive &Directive,
|
|
|
|
llvm::StringSet<> &CrtClauses) {
|
2020-11-06 04:19:21 +01:00
|
|
|
bool HasError = false;
|
2020-10-28 20:11:47 +01:00
|
|
|
for (const auto &C : Clauses) {
|
|
|
|
VersionedClause VerClause{C};
|
|
|
|
const auto insRes = CrtClauses.insert(VerClause.getClause().getName());
|
|
|
|
if (!insRes.second) {
|
|
|
|
PrintError("Clause " + VerClause.getClause().getRecordName() +
|
|
|
|
" already defined on directive " + Directive.getRecordName());
|
2020-11-06 04:19:21 +01:00
|
|
|
HasError = true;
|
2020-10-28 20:11:47 +01:00
|
|
|
}
|
|
|
|
}
|
2020-11-06 04:19:21 +01:00
|
|
|
return HasError;
|
2020-10-28 20:11:47 +01:00
|
|
|
}
|
|
|
|
|
2020-11-05 22:21:15 +01:00
|
|
|
// Check for duplicate clauses in lists. Clauses cannot appear twice in the
|
|
|
|
// three allowed list. Also, since required implies allowed, clauses cannot
|
|
|
|
// appear in both the allowedClauses and requiredClauses lists.
|
2020-10-28 20:11:47 +01:00
|
|
|
bool HasDuplicateClausesInDirectives(const std::vector<Record *> &Directives) {
|
2020-11-06 04:19:21 +01:00
|
|
|
bool HasDuplicate = false;
|
2020-10-28 20:11:47 +01:00
|
|
|
for (const auto &D : Directives) {
|
|
|
|
Directive Dir{D};
|
|
|
|
llvm::StringSet<> Clauses;
|
2020-11-05 22:21:15 +01:00
|
|
|
// Check for duplicates in the three allowed lists.
|
2020-10-28 20:11:47 +01:00
|
|
|
if (HasDuplicateClauses(Dir.getAllowedClauses(), Dir, Clauses) ||
|
|
|
|
HasDuplicateClauses(Dir.getAllowedOnceClauses(), Dir, Clauses) ||
|
2020-11-05 22:21:15 +01:00
|
|
|
HasDuplicateClauses(Dir.getAllowedExclusiveClauses(), Dir, Clauses)) {
|
2020-11-06 04:19:21 +01:00
|
|
|
HasDuplicate = true;
|
2020-11-05 22:21:15 +01:00
|
|
|
}
|
|
|
|
// Check for duplicate between allowedClauses and required
|
|
|
|
Clauses.clear();
|
|
|
|
if (HasDuplicateClauses(Dir.getAllowedClauses(), Dir, Clauses) ||
|
2020-10-28 20:11:47 +01:00
|
|
|
HasDuplicateClauses(Dir.getRequiredClauses(), Dir, Clauses)) {
|
2020-11-06 04:19:21 +01:00
|
|
|
HasDuplicate = true;
|
2020-10-28 20:11:47 +01:00
|
|
|
}
|
2020-11-06 04:19:21 +01:00
|
|
|
if (HasDuplicate)
|
2020-11-05 22:21:15 +01:00
|
|
|
PrintFatalError("One or more clauses are defined multiple times on"
|
|
|
|
" directive " +
|
|
|
|
Dir.getRecordName());
|
2020-10-28 20:11:47 +01:00
|
|
|
}
|
2020-11-05 22:21:15 +01:00
|
|
|
|
2020-11-06 04:19:21 +01:00
|
|
|
return HasDuplicate;
|
2020-10-28 20:11:47 +01:00
|
|
|
}
|
[openmp] Base of tablegen generated OpenMP common declaration
Summary:
As discussed previously when landing patch for OpenMP in Flang, the idea is
to share common part of the OpenMP declaration between the different Frontend.
While doing this it was thought that moving to tablegen instead of Macros will also
give a cleaner and more powerful way of generating these declaration.
This first part of a future series of patches is setting up the base .td file for
DirectiveLanguage as well as the OpenMP version of it. The base file is meant to
be used by other directive language such as OpenACC.
In this first patch, the Directive and Clause enums are generated with tablegen
instead of the macros on OMPConstants.h. The next pacth will extend this
to other enum and move the Flang frontend to use it.
Reviewers: jdoerfert, DavidTruby, fghanim, ABataev, jdenny, hfinkel, jhuber6, kiranchandramohan, kiranktp
Reviewed By: jdoerfert, jdenny
Subscribers: arphaman, martong, cfe-commits, mgorny, yaxunl, hiraditya, guansong, jfb, sstefan1, aaron.ballman, llvm-commits
Tags: #llvm, #openmp, #clang
Differential Revision: https://reviews.llvm.org/D81736
2020-06-23 15:29:50 +02:00
|
|
|
|
2020-10-28 20:11:47 +01:00
|
|
|
// Check consitency of records. Return true if an error has been detected.
|
|
|
|
// Return false if the records are valid.
|
2020-11-06 04:19:21 +01:00
|
|
|
bool DirectiveLanguage::HasValidityErrors() const {
|
2020-11-03 17:12:14 +01:00
|
|
|
if (getDirectiveLanguages().size() != 1) {
|
2020-11-05 22:21:15 +01:00
|
|
|
PrintFatalError("A single definition of DirectiveLanguage is needed.");
|
2020-10-28 20:11:47 +01:00
|
|
|
return true;
|
[openmp] Base of tablegen generated OpenMP common declaration
Summary:
As discussed previously when landing patch for OpenMP in Flang, the idea is
to share common part of the OpenMP declaration between the different Frontend.
While doing this it was thought that moving to tablegen instead of Macros will also
give a cleaner and more powerful way of generating these declaration.
This first part of a future series of patches is setting up the base .td file for
DirectiveLanguage as well as the OpenMP version of it. The base file is meant to
be used by other directive language such as OpenACC.
In this first patch, the Directive and Clause enums are generated with tablegen
instead of the macros on OMPConstants.h. The next pacth will extend this
to other enum and move the Flang frontend to use it.
Reviewers: jdoerfert, DavidTruby, fghanim, ABataev, jdenny, hfinkel, jhuber6, kiranchandramohan, kiranktp
Reviewed By: jdoerfert, jdenny
Subscribers: arphaman, martong, cfe-commits, mgorny, yaxunl, hiraditya, guansong, jfb, sstefan1, aaron.ballman, llvm-commits
Tags: #llvm, #openmp, #clang
Differential Revision: https://reviews.llvm.org/D81736
2020-06-23 15:29:50 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 17:12:14 +01:00
|
|
|
return HasDuplicateClausesInDirectives(getDirectives());
|
2020-10-28 20:11:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Generate the declaration section for the enumeration in the directive
|
|
|
|
// language
|
|
|
|
void EmitDirectivesDecl(RecordKeeper &Records, raw_ostream &OS) {
|
2020-11-03 17:12:14 +01:00
|
|
|
const auto DirLang = DirectiveLanguage{Records};
|
2020-11-06 04:19:21 +01:00
|
|
|
if (DirLang.HasValidityErrors())
|
2020-10-28 20:11:47 +01:00
|
|
|
return;
|
|
|
|
|
2020-07-29 02:45:21 +02:00
|
|
|
OS << "#ifndef LLVM_" << DirLang.getName() << "_INC\n";
|
|
|
|
OS << "#define LLVM_" << DirLang.getName() << "_INC\n";
|
|
|
|
|
|
|
|
if (DirLang.hasEnableBitmaskEnumInNamespace())
|
[openmp] Move Directive and Clause helper function to tablegen
Summary:
Follow up to D81736. Move getOpenMPDirectiveKind, getOpenMPClauseKind, getOpenMPDirectiveName and
getOpenMPClauseName to the new tablegen code generation. The code is generated in a new file named OMP.cpp.inc
Reviewers: jdoerfert, jdenny, thakis
Reviewed By: jdoerfert, jdenny
Subscribers: mgorny, yaxunl, hiraditya, guansong, sstefan1, llvm-commits, thakis
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D82405
2020-06-30 20:36:37 +02:00
|
|
|
OS << "\n#include \"llvm/ADT/BitmaskEnum.h\"\n";
|
[openmp] Base of tablegen generated OpenMP common declaration
Summary:
As discussed previously when landing patch for OpenMP in Flang, the idea is
to share common part of the OpenMP declaration between the different Frontend.
While doing this it was thought that moving to tablegen instead of Macros will also
give a cleaner and more powerful way of generating these declaration.
This first part of a future series of patches is setting up the base .td file for
DirectiveLanguage as well as the OpenMP version of it. The base file is meant to
be used by other directive language such as OpenACC.
In this first patch, the Directive and Clause enums are generated with tablegen
instead of the macros on OMPConstants.h. The next pacth will extend this
to other enum and move the Flang frontend to use it.
Reviewers: jdoerfert, DavidTruby, fghanim, ABataev, jdenny, hfinkel, jhuber6, kiranchandramohan, kiranktp
Reviewed By: jdoerfert, jdenny
Subscribers: arphaman, martong, cfe-commits, mgorny, yaxunl, hiraditya, guansong, jfb, sstefan1, aaron.ballman, llvm-commits
Tags: #llvm, #openmp, #clang
Differential Revision: https://reviews.llvm.org/D81736
2020-06-23 15:29:50 +02:00
|
|
|
|
[openmp] Move Directive and Clause helper function to tablegen
Summary:
Follow up to D81736. Move getOpenMPDirectiveKind, getOpenMPClauseKind, getOpenMPDirectiveName and
getOpenMPClauseName to the new tablegen code generation. The code is generated in a new file named OMP.cpp.inc
Reviewers: jdoerfert, jdenny, thakis
Reviewed By: jdoerfert, jdenny
Subscribers: mgorny, yaxunl, hiraditya, guansong, sstefan1, llvm-commits, thakis
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D82405
2020-06-30 20:36:37 +02:00
|
|
|
OS << "\n";
|
[openmp] Base of tablegen generated OpenMP common declaration
Summary:
As discussed previously when landing patch for OpenMP in Flang, the idea is
to share common part of the OpenMP declaration between the different Frontend.
While doing this it was thought that moving to tablegen instead of Macros will also
give a cleaner and more powerful way of generating these declaration.
This first part of a future series of patches is setting up the base .td file for
DirectiveLanguage as well as the OpenMP version of it. The base file is meant to
be used by other directive language such as OpenACC.
In this first patch, the Directive and Clause enums are generated with tablegen
instead of the macros on OMPConstants.h. The next pacth will extend this
to other enum and move the Flang frontend to use it.
Reviewers: jdoerfert, DavidTruby, fghanim, ABataev, jdenny, hfinkel, jhuber6, kiranchandramohan, kiranktp
Reviewed By: jdoerfert, jdenny
Subscribers: arphaman, martong, cfe-commits, mgorny, yaxunl, hiraditya, guansong, jfb, sstefan1, aaron.ballman, llvm-commits
Tags: #llvm, #openmp, #clang
Differential Revision: https://reviews.llvm.org/D81736
2020-06-23 15:29:50 +02:00
|
|
|
OS << "namespace llvm {\n";
|
[openmp] Move Directive and Clause helper function to tablegen
Summary:
Follow up to D81736. Move getOpenMPDirectiveKind, getOpenMPClauseKind, getOpenMPDirectiveName and
getOpenMPClauseName to the new tablegen code generation. The code is generated in a new file named OMP.cpp.inc
Reviewers: jdoerfert, jdenny, thakis
Reviewed By: jdoerfert, jdenny
Subscribers: mgorny, yaxunl, hiraditya, guansong, sstefan1, llvm-commits, thakis
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D82405
2020-06-30 20:36:37 +02:00
|
|
|
OS << "class StringRef;\n";
|
[openmp] Base of tablegen generated OpenMP common declaration
Summary:
As discussed previously when landing patch for OpenMP in Flang, the idea is
to share common part of the OpenMP declaration between the different Frontend.
While doing this it was thought that moving to tablegen instead of Macros will also
give a cleaner and more powerful way of generating these declaration.
This first part of a future series of patches is setting up the base .td file for
DirectiveLanguage as well as the OpenMP version of it. The base file is meant to
be used by other directive language such as OpenACC.
In this first patch, the Directive and Clause enums are generated with tablegen
instead of the macros on OMPConstants.h. The next pacth will extend this
to other enum and move the Flang frontend to use it.
Reviewers: jdoerfert, DavidTruby, fghanim, ABataev, jdenny, hfinkel, jhuber6, kiranchandramohan, kiranktp
Reviewed By: jdoerfert, jdenny
Subscribers: arphaman, martong, cfe-commits, mgorny, yaxunl, hiraditya, guansong, jfb, sstefan1, aaron.ballman, llvm-commits
Tags: #llvm, #openmp, #clang
Differential Revision: https://reviews.llvm.org/D81736
2020-06-23 15:29:50 +02:00
|
|
|
|
|
|
|
// Open namespaces defined in the directive language
|
|
|
|
llvm::SmallVector<StringRef, 2> Namespaces;
|
2020-07-29 02:45:21 +02:00
|
|
|
llvm::SplitString(DirLang.getCppNamespace(), Namespaces, "::");
|
[openmp] Base of tablegen generated OpenMP common declaration
Summary:
As discussed previously when landing patch for OpenMP in Flang, the idea is
to share common part of the OpenMP declaration between the different Frontend.
While doing this it was thought that moving to tablegen instead of Macros will also
give a cleaner and more powerful way of generating these declaration.
This first part of a future series of patches is setting up the base .td file for
DirectiveLanguage as well as the OpenMP version of it. The base file is meant to
be used by other directive language such as OpenACC.
In this first patch, the Directive and Clause enums are generated with tablegen
instead of the macros on OMPConstants.h. The next pacth will extend this
to other enum and move the Flang frontend to use it.
Reviewers: jdoerfert, DavidTruby, fghanim, ABataev, jdenny, hfinkel, jhuber6, kiranchandramohan, kiranktp
Reviewed By: jdoerfert, jdenny
Subscribers: arphaman, martong, cfe-commits, mgorny, yaxunl, hiraditya, guansong, jfb, sstefan1, aaron.ballman, llvm-commits
Tags: #llvm, #openmp, #clang
Differential Revision: https://reviews.llvm.org/D81736
2020-06-23 15:29:50 +02:00
|
|
|
for (auto Ns : Namespaces)
|
|
|
|
OS << "namespace " << Ns << " {\n";
|
|
|
|
|
2020-07-29 02:45:21 +02:00
|
|
|
if (DirLang.hasEnableBitmaskEnumInNamespace())
|
[openmp] Move Directive and Clause helper function to tablegen
Summary:
Follow up to D81736. Move getOpenMPDirectiveKind, getOpenMPClauseKind, getOpenMPDirectiveName and
getOpenMPClauseName to the new tablegen code generation. The code is generated in a new file named OMP.cpp.inc
Reviewers: jdoerfert, jdenny, thakis
Reviewed By: jdoerfert, jdenny
Subscribers: mgorny, yaxunl, hiraditya, guansong, sstefan1, llvm-commits, thakis
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D82405
2020-06-30 20:36:37 +02:00
|
|
|
OS << "\nLLVM_ENABLE_BITMASK_ENUMS_IN_NAMESPACE();\n";
|
[openmp] Base of tablegen generated OpenMP common declaration
Summary:
As discussed previously when landing patch for OpenMP in Flang, the idea is
to share common part of the OpenMP declaration between the different Frontend.
While doing this it was thought that moving to tablegen instead of Macros will also
give a cleaner and more powerful way of generating these declaration.
This first part of a future series of patches is setting up the base .td file for
DirectiveLanguage as well as the OpenMP version of it. The base file is meant to
be used by other directive language such as OpenACC.
In this first patch, the Directive and Clause enums are generated with tablegen
instead of the macros on OMPConstants.h. The next pacth will extend this
to other enum and move the Flang frontend to use it.
Reviewers: jdoerfert, DavidTruby, fghanim, ABataev, jdenny, hfinkel, jhuber6, kiranchandramohan, kiranktp
Reviewed By: jdoerfert, jdenny
Subscribers: arphaman, martong, cfe-commits, mgorny, yaxunl, hiraditya, guansong, jfb, sstefan1, aaron.ballman, llvm-commits
Tags: #llvm, #openmp, #clang
Differential Revision: https://reviews.llvm.org/D81736
2020-06-23 15:29:50 +02:00
|
|
|
|
|
|
|
// Emit Directive enumeration
|
2020-11-03 17:12:14 +01:00
|
|
|
GenerateEnumClass(DirLang.getDirectives(), OS, "Directive",
|
|
|
|
DirLang.getDirectivePrefix(), DirLang);
|
[openmp] Move Directive and Clause helper function to tablegen
Summary:
Follow up to D81736. Move getOpenMPDirectiveKind, getOpenMPClauseKind, getOpenMPDirectiveName and
getOpenMPClauseName to the new tablegen code generation. The code is generated in a new file named OMP.cpp.inc
Reviewers: jdoerfert, jdenny, thakis
Reviewed By: jdoerfert, jdenny
Subscribers: mgorny, yaxunl, hiraditya, guansong, sstefan1, llvm-commits, thakis
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D82405
2020-06-30 20:36:37 +02:00
|
|
|
|
|
|
|
// Emit Clause enumeration
|
2020-11-03 17:12:14 +01:00
|
|
|
GenerateEnumClass(DirLang.getClauses(), OS, "Clause",
|
|
|
|
DirLang.getClausePrefix(), DirLang);
|
[openmp] Move Directive and Clause helper function to tablegen
Summary:
Follow up to D81736. Move getOpenMPDirectiveKind, getOpenMPClauseKind, getOpenMPDirectiveName and
getOpenMPClauseName to the new tablegen code generation. The code is generated in a new file named OMP.cpp.inc
Reviewers: jdoerfert, jdenny, thakis
Reviewed By: jdoerfert, jdenny
Subscribers: mgorny, yaxunl, hiraditya, guansong, sstefan1, llvm-commits, thakis
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D82405
2020-06-30 20:36:37 +02:00
|
|
|
|
2020-07-22 18:28:04 +02:00
|
|
|
// Emit ClauseVal enumeration
|
|
|
|
std::string EnumHelperFuncs;
|
2020-11-03 17:12:14 +01:00
|
|
|
GenerateEnumClauseVal(DirLang.getClauses(), OS, DirLang, EnumHelperFuncs);
|
2020-07-22 18:28:04 +02:00
|
|
|
|
[openmp] Move Directive and Clause helper function to tablegen
Summary:
Follow up to D81736. Move getOpenMPDirectiveKind, getOpenMPClauseKind, getOpenMPDirectiveName and
getOpenMPClauseName to the new tablegen code generation. The code is generated in a new file named OMP.cpp.inc
Reviewers: jdoerfert, jdenny, thakis
Reviewed By: jdoerfert, jdenny
Subscribers: mgorny, yaxunl, hiraditya, guansong, sstefan1, llvm-commits, thakis
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D82405
2020-06-30 20:36:37 +02:00
|
|
|
// Generic function signatures
|
|
|
|
OS << "\n";
|
|
|
|
OS << "// Enumeration helper functions\n";
|
2020-07-29 02:45:21 +02:00
|
|
|
OS << "Directive get" << DirLang.getName()
|
[openmp] Move Directive and Clause helper function to tablegen
Summary:
Follow up to D81736. Move getOpenMPDirectiveKind, getOpenMPClauseKind, getOpenMPDirectiveName and
getOpenMPClauseName to the new tablegen code generation. The code is generated in a new file named OMP.cpp.inc
Reviewers: jdoerfert, jdenny, thakis
Reviewed By: jdoerfert, jdenny
Subscribers: mgorny, yaxunl, hiraditya, guansong, sstefan1, llvm-commits, thakis
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D82405
2020-06-30 20:36:37 +02:00
|
|
|
<< "DirectiveKind(llvm::StringRef Str);\n";
|
|
|
|
OS << "\n";
|
2020-07-29 02:45:21 +02:00
|
|
|
OS << "llvm::StringRef get" << DirLang.getName()
|
[openmp] Move Directive and Clause helper function to tablegen
Summary:
Follow up to D81736. Move getOpenMPDirectiveKind, getOpenMPClauseKind, getOpenMPDirectiveName and
getOpenMPClauseName to the new tablegen code generation. The code is generated in a new file named OMP.cpp.inc
Reviewers: jdoerfert, jdenny, thakis
Reviewed By: jdoerfert, jdenny
Subscribers: mgorny, yaxunl, hiraditya, guansong, sstefan1, llvm-commits, thakis
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D82405
2020-06-30 20:36:37 +02:00
|
|
|
<< "DirectiveName(Directive D);\n";
|
|
|
|
OS << "\n";
|
2020-07-29 02:45:21 +02:00
|
|
|
OS << "Clause get" << DirLang.getName()
|
|
|
|
<< "ClauseKind(llvm::StringRef Str);\n";
|
[openmp] Move Directive and Clause helper function to tablegen
Summary:
Follow up to D81736. Move getOpenMPDirectiveKind, getOpenMPClauseKind, getOpenMPDirectiveName and
getOpenMPClauseName to the new tablegen code generation. The code is generated in a new file named OMP.cpp.inc
Reviewers: jdoerfert, jdenny, thakis
Reviewed By: jdoerfert, jdenny
Subscribers: mgorny, yaxunl, hiraditya, guansong, sstefan1, llvm-commits, thakis
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D82405
2020-06-30 20:36:37 +02:00
|
|
|
OS << "\n";
|
2020-07-29 02:45:21 +02:00
|
|
|
OS << "llvm::StringRef get" << DirLang.getName() << "ClauseName(Clause C);\n";
|
[openmp] Move Directive and Clause helper function to tablegen
Summary:
Follow up to D81736. Move getOpenMPDirectiveKind, getOpenMPClauseKind, getOpenMPDirectiveName and
getOpenMPClauseName to the new tablegen code generation. The code is generated in a new file named OMP.cpp.inc
Reviewers: jdoerfert, jdenny, thakis
Reviewed By: jdoerfert, jdenny
Subscribers: mgorny, yaxunl, hiraditya, guansong, sstefan1, llvm-commits, thakis
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D82405
2020-06-30 20:36:37 +02:00
|
|
|
OS << "\n";
|
2020-07-07 04:19:43 +02:00
|
|
|
OS << "/// Return true if \\p C is a valid clause for \\p D in version \\p "
|
|
|
|
<< "Version.\n";
|
|
|
|
OS << "bool isAllowedClauseForDirective(Directive D, "
|
|
|
|
<< "Clause C, unsigned Version);\n";
|
|
|
|
OS << "\n";
|
2020-07-22 18:28:04 +02:00
|
|
|
if (EnumHelperFuncs.length() > 0) {
|
|
|
|
OS << EnumHelperFuncs;
|
|
|
|
OS << "\n";
|
|
|
|
}
|
[openmp] Move Directive and Clause helper function to tablegen
Summary:
Follow up to D81736. Move getOpenMPDirectiveKind, getOpenMPClauseKind, getOpenMPDirectiveName and
getOpenMPClauseName to the new tablegen code generation. The code is generated in a new file named OMP.cpp.inc
Reviewers: jdoerfert, jdenny, thakis
Reviewed By: jdoerfert, jdenny
Subscribers: mgorny, yaxunl, hiraditya, guansong, sstefan1, llvm-commits, thakis
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D82405
2020-06-30 20:36:37 +02:00
|
|
|
|
|
|
|
// Closing namespaces
|
|
|
|
for (auto Ns : llvm::reverse(Namespaces))
|
|
|
|
OS << "} // namespace " << Ns << "\n";
|
|
|
|
|
|
|
|
OS << "} // namespace llvm\n";
|
|
|
|
|
2020-07-29 02:45:21 +02:00
|
|
|
OS << "#endif // LLVM_" << DirLang.getName() << "_INC\n";
|
[openmp] Move Directive and Clause helper function to tablegen
Summary:
Follow up to D81736. Move getOpenMPDirectiveKind, getOpenMPClauseKind, getOpenMPDirectiveName and
getOpenMPClauseName to the new tablegen code generation. The code is generated in a new file named OMP.cpp.inc
Reviewers: jdoerfert, jdenny, thakis
Reviewed By: jdoerfert, jdenny
Subscribers: mgorny, yaxunl, hiraditya, guansong, sstefan1, llvm-commits, thakis
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D82405
2020-06-30 20:36:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Generate function implementation for get<Enum>Name(StringRef Str)
|
|
|
|
void GenerateGetName(const std::vector<Record *> &Records, raw_ostream &OS,
|
2020-11-03 17:12:14 +01:00
|
|
|
StringRef Enum, const DirectiveLanguage &DirLang,
|
2020-07-29 02:45:21 +02:00
|
|
|
StringRef Prefix) {
|
[openmp] Move Directive and Clause helper function to tablegen
Summary:
Follow up to D81736. Move getOpenMPDirectiveKind, getOpenMPClauseKind, getOpenMPDirectiveName and
getOpenMPClauseName to the new tablegen code generation. The code is generated in a new file named OMP.cpp.inc
Reviewers: jdoerfert, jdenny, thakis
Reviewed By: jdoerfert, jdenny
Subscribers: mgorny, yaxunl, hiraditya, guansong, sstefan1, llvm-commits, thakis
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D82405
2020-06-30 20:36:37 +02:00
|
|
|
OS << "\n";
|
2020-07-29 02:45:21 +02:00
|
|
|
OS << "llvm::StringRef llvm::" << DirLang.getCppNamespace() << "::get"
|
|
|
|
<< DirLang.getName() << Enum << "Name(" << Enum << " Kind) {\n";
|
[openmp] Move Directive and Clause helper function to tablegen
Summary:
Follow up to D81736. Move getOpenMPDirectiveKind, getOpenMPClauseKind, getOpenMPDirectiveName and
getOpenMPClauseName to the new tablegen code generation. The code is generated in a new file named OMP.cpp.inc
Reviewers: jdoerfert, jdenny, thakis
Reviewed By: jdoerfert, jdenny
Subscribers: mgorny, yaxunl, hiraditya, guansong, sstefan1, llvm-commits, thakis
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D82405
2020-06-30 20:36:37 +02:00
|
|
|
OS << " switch (Kind) {\n";
|
|
|
|
for (const auto &R : Records) {
|
2020-07-29 02:45:21 +02:00
|
|
|
BaseRecord Rec{R};
|
|
|
|
OS << " case " << Prefix << Rec.getFormattedName() << ":\n";
|
[openmp] Move Directive and Clause helper function to tablegen
Summary:
Follow up to D81736. Move getOpenMPDirectiveKind, getOpenMPClauseKind, getOpenMPDirectiveName and
getOpenMPClauseName to the new tablegen code generation. The code is generated in a new file named OMP.cpp.inc
Reviewers: jdoerfert, jdenny, thakis
Reviewed By: jdoerfert, jdenny
Subscribers: mgorny, yaxunl, hiraditya, guansong, sstefan1, llvm-commits, thakis
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D82405
2020-06-30 20:36:37 +02:00
|
|
|
OS << " return \"";
|
2020-07-29 02:45:21 +02:00
|
|
|
if (Rec.getAlternativeName().empty())
|
|
|
|
OS << Rec.getName();
|
[openmp] Move Directive and Clause helper function to tablegen
Summary:
Follow up to D81736. Move getOpenMPDirectiveKind, getOpenMPClauseKind, getOpenMPDirectiveName and
getOpenMPClauseName to the new tablegen code generation. The code is generated in a new file named OMP.cpp.inc
Reviewers: jdoerfert, jdenny, thakis
Reviewed By: jdoerfert, jdenny
Subscribers: mgorny, yaxunl, hiraditya, guansong, sstefan1, llvm-commits, thakis
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D82405
2020-06-30 20:36:37 +02:00
|
|
|
else
|
2020-07-29 02:45:21 +02:00
|
|
|
OS << Rec.getAlternativeName();
|
[openmp] Move Directive and Clause helper function to tablegen
Summary:
Follow up to D81736. Move getOpenMPDirectiveKind, getOpenMPClauseKind, getOpenMPDirectiveName and
getOpenMPClauseName to the new tablegen code generation. The code is generated in a new file named OMP.cpp.inc
Reviewers: jdoerfert, jdenny, thakis
Reviewed By: jdoerfert, jdenny
Subscribers: mgorny, yaxunl, hiraditya, guansong, sstefan1, llvm-commits, thakis
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D82405
2020-06-30 20:36:37 +02:00
|
|
|
OS << "\";\n";
|
[openmp] Base of tablegen generated OpenMP common declaration
Summary:
As discussed previously when landing patch for OpenMP in Flang, the idea is
to share common part of the OpenMP declaration between the different Frontend.
While doing this it was thought that moving to tablegen instead of Macros will also
give a cleaner and more powerful way of generating these declaration.
This first part of a future series of patches is setting up the base .td file for
DirectiveLanguage as well as the OpenMP version of it. The base file is meant to
be used by other directive language such as OpenACC.
In this first patch, the Directive and Clause enums are generated with tablegen
instead of the macros on OMPConstants.h. The next pacth will extend this
to other enum and move the Flang frontend to use it.
Reviewers: jdoerfert, DavidTruby, fghanim, ABataev, jdenny, hfinkel, jhuber6, kiranchandramohan, kiranktp
Reviewed By: jdoerfert, jdenny
Subscribers: arphaman, martong, cfe-commits, mgorny, yaxunl, hiraditya, guansong, jfb, sstefan1, aaron.ballman, llvm-commits
Tags: #llvm, #openmp, #clang
Differential Revision: https://reviews.llvm.org/D81736
2020-06-23 15:29:50 +02:00
|
|
|
}
|
[openmp] Move Directive and Clause helper function to tablegen
Summary:
Follow up to D81736. Move getOpenMPDirectiveKind, getOpenMPClauseKind, getOpenMPDirectiveName and
getOpenMPClauseName to the new tablegen code generation. The code is generated in a new file named OMP.cpp.inc
Reviewers: jdoerfert, jdenny, thakis
Reviewed By: jdoerfert, jdenny
Subscribers: mgorny, yaxunl, hiraditya, guansong, sstefan1, llvm-commits, thakis
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D82405
2020-06-30 20:36:37 +02:00
|
|
|
OS << " }\n"; // switch
|
2020-07-29 02:45:21 +02:00
|
|
|
OS << " llvm_unreachable(\"Invalid " << DirLang.getName() << " " << Enum
|
[openmp] Move Directive and Clause helper function to tablegen
Summary:
Follow up to D81736. Move getOpenMPDirectiveKind, getOpenMPClauseKind, getOpenMPDirectiveName and
getOpenMPClauseName to the new tablegen code generation. The code is generated in a new file named OMP.cpp.inc
Reviewers: jdoerfert, jdenny, thakis
Reviewed By: jdoerfert, jdenny
Subscribers: mgorny, yaxunl, hiraditya, guansong, sstefan1, llvm-commits, thakis
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D82405
2020-06-30 20:36:37 +02:00
|
|
|
<< " kind\");\n";
|
|
|
|
OS << "}\n";
|
|
|
|
}
|
[openmp] Base of tablegen generated OpenMP common declaration
Summary:
As discussed previously when landing patch for OpenMP in Flang, the idea is
to share common part of the OpenMP declaration between the different Frontend.
While doing this it was thought that moving to tablegen instead of Macros will also
give a cleaner and more powerful way of generating these declaration.
This first part of a future series of patches is setting up the base .td file for
DirectiveLanguage as well as the OpenMP version of it. The base file is meant to
be used by other directive language such as OpenACC.
In this first patch, the Directive and Clause enums are generated with tablegen
instead of the macros on OMPConstants.h. The next pacth will extend this
to other enum and move the Flang frontend to use it.
Reviewers: jdoerfert, DavidTruby, fghanim, ABataev, jdenny, hfinkel, jhuber6, kiranchandramohan, kiranktp
Reviewed By: jdoerfert, jdenny
Subscribers: arphaman, martong, cfe-commits, mgorny, yaxunl, hiraditya, guansong, jfb, sstefan1, aaron.ballman, llvm-commits
Tags: #llvm, #openmp, #clang
Differential Revision: https://reviews.llvm.org/D81736
2020-06-23 15:29:50 +02:00
|
|
|
|
[openmp] Move Directive and Clause helper function to tablegen
Summary:
Follow up to D81736. Move getOpenMPDirectiveKind, getOpenMPClauseKind, getOpenMPDirectiveName and
getOpenMPClauseName to the new tablegen code generation. The code is generated in a new file named OMP.cpp.inc
Reviewers: jdoerfert, jdenny, thakis
Reviewed By: jdoerfert, jdenny
Subscribers: mgorny, yaxunl, hiraditya, guansong, sstefan1, llvm-commits, thakis
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D82405
2020-06-30 20:36:37 +02:00
|
|
|
// Generate function implementation for get<Enum>Kind(StringRef Str)
|
|
|
|
void GenerateGetKind(const std::vector<Record *> &Records, raw_ostream &OS,
|
2020-11-03 17:12:14 +01:00
|
|
|
StringRef Enum, const DirectiveLanguage &DirLang,
|
2020-07-29 02:45:21 +02:00
|
|
|
StringRef Prefix, bool ImplicitAsUnknown) {
|
[openmp] Base of tablegen generated OpenMP common declaration
Summary:
As discussed previously when landing patch for OpenMP in Flang, the idea is
to share common part of the OpenMP declaration between the different Frontend.
While doing this it was thought that moving to tablegen instead of Macros will also
give a cleaner and more powerful way of generating these declaration.
This first part of a future series of patches is setting up the base .td file for
DirectiveLanguage as well as the OpenMP version of it. The base file is meant to
be used by other directive language such as OpenACC.
In this first patch, the Directive and Clause enums are generated with tablegen
instead of the macros on OMPConstants.h. The next pacth will extend this
to other enum and move the Flang frontend to use it.
Reviewers: jdoerfert, DavidTruby, fghanim, ABataev, jdenny, hfinkel, jhuber6, kiranchandramohan, kiranktp
Reviewed By: jdoerfert, jdenny
Subscribers: arphaman, martong, cfe-commits, mgorny, yaxunl, hiraditya, guansong, jfb, sstefan1, aaron.ballman, llvm-commits
Tags: #llvm, #openmp, #clang
Differential Revision: https://reviews.llvm.org/D81736
2020-06-23 15:29:50 +02:00
|
|
|
|
2021-01-09 03:39:55 +01:00
|
|
|
auto DefaultIt = llvm::find_if(
|
|
|
|
Records, [](Record *R) { return R->getValueAsBit("isDefault") == true; });
|
[openmp] Move Directive and Clause helper function to tablegen
Summary:
Follow up to D81736. Move getOpenMPDirectiveKind, getOpenMPClauseKind, getOpenMPDirectiveName and
getOpenMPClauseName to the new tablegen code generation. The code is generated in a new file named OMP.cpp.inc
Reviewers: jdoerfert, jdenny, thakis
Reviewed By: jdoerfert, jdenny
Subscribers: mgorny, yaxunl, hiraditya, guansong, sstefan1, llvm-commits, thakis
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D82405
2020-06-30 20:36:37 +02:00
|
|
|
|
|
|
|
if (DefaultIt == Records.end()) {
|
2020-07-22 18:28:04 +02:00
|
|
|
PrintError("At least one " + Enum + " must be defined as default.");
|
[openmp] Move Directive and Clause helper function to tablegen
Summary:
Follow up to D81736. Move getOpenMPDirectiveKind, getOpenMPClauseKind, getOpenMPDirectiveName and
getOpenMPClauseName to the new tablegen code generation. The code is generated in a new file named OMP.cpp.inc
Reviewers: jdoerfert, jdenny, thakis
Reviewed By: jdoerfert, jdenny
Subscribers: mgorny, yaxunl, hiraditya, guansong, sstefan1, llvm-commits, thakis
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D82405
2020-06-30 20:36:37 +02:00
|
|
|
return;
|
[openmp] Base of tablegen generated OpenMP common declaration
Summary:
As discussed previously when landing patch for OpenMP in Flang, the idea is
to share common part of the OpenMP declaration between the different Frontend.
While doing this it was thought that moving to tablegen instead of Macros will also
give a cleaner and more powerful way of generating these declaration.
This first part of a future series of patches is setting up the base .td file for
DirectiveLanguage as well as the OpenMP version of it. The base file is meant to
be used by other directive language such as OpenACC.
In this first patch, the Directive and Clause enums are generated with tablegen
instead of the macros on OMPConstants.h. The next pacth will extend this
to other enum and move the Flang frontend to use it.
Reviewers: jdoerfert, DavidTruby, fghanim, ABataev, jdenny, hfinkel, jhuber6, kiranchandramohan, kiranktp
Reviewed By: jdoerfert, jdenny
Subscribers: arphaman, martong, cfe-commits, mgorny, yaxunl, hiraditya, guansong, jfb, sstefan1, aaron.ballman, llvm-commits
Tags: #llvm, #openmp, #clang
Differential Revision: https://reviews.llvm.org/D81736
2020-06-23 15:29:50 +02:00
|
|
|
}
|
|
|
|
|
2020-07-29 02:45:21 +02:00
|
|
|
BaseRecord DefaultRec{(*DefaultIt)};
|
[openmp] Base of tablegen generated OpenMP common declaration
Summary:
As discussed previously when landing patch for OpenMP in Flang, the idea is
to share common part of the OpenMP declaration between the different Frontend.
While doing this it was thought that moving to tablegen instead of Macros will also
give a cleaner and more powerful way of generating these declaration.
This first part of a future series of patches is setting up the base .td file for
DirectiveLanguage as well as the OpenMP version of it. The base file is meant to
be used by other directive language such as OpenACC.
In this first patch, the Directive and Clause enums are generated with tablegen
instead of the macros on OMPConstants.h. The next pacth will extend this
to other enum and move the Flang frontend to use it.
Reviewers: jdoerfert, DavidTruby, fghanim, ABataev, jdenny, hfinkel, jhuber6, kiranchandramohan, kiranktp
Reviewed By: jdoerfert, jdenny
Subscribers: arphaman, martong, cfe-commits, mgorny, yaxunl, hiraditya, guansong, jfb, sstefan1, aaron.ballman, llvm-commits
Tags: #llvm, #openmp, #clang
Differential Revision: https://reviews.llvm.org/D81736
2020-06-23 15:29:50 +02:00
|
|
|
|
[openmp] Move Directive and Clause helper function to tablegen
Summary:
Follow up to D81736. Move getOpenMPDirectiveKind, getOpenMPClauseKind, getOpenMPDirectiveName and
getOpenMPClauseName to the new tablegen code generation. The code is generated in a new file named OMP.cpp.inc
Reviewers: jdoerfert, jdenny, thakis
Reviewed By: jdoerfert, jdenny
Subscribers: mgorny, yaxunl, hiraditya, guansong, sstefan1, llvm-commits, thakis
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D82405
2020-06-30 20:36:37 +02:00
|
|
|
OS << "\n";
|
2020-07-29 02:45:21 +02:00
|
|
|
OS << Enum << " llvm::" << DirLang.getCppNamespace() << "::get"
|
|
|
|
<< DirLang.getName() << Enum << "Kind(llvm::StringRef Str) {\n";
|
[openmp] Move Directive and Clause helper function to tablegen
Summary:
Follow up to D81736. Move getOpenMPDirectiveKind, getOpenMPClauseKind, getOpenMPDirectiveName and
getOpenMPClauseName to the new tablegen code generation. The code is generated in a new file named OMP.cpp.inc
Reviewers: jdoerfert, jdenny, thakis
Reviewed By: jdoerfert, jdenny
Subscribers: mgorny, yaxunl, hiraditya, guansong, sstefan1, llvm-commits, thakis
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D82405
2020-06-30 20:36:37 +02:00
|
|
|
OS << " return llvm::StringSwitch<" << Enum << ">(Str)\n";
|
[openmp] Base of tablegen generated OpenMP common declaration
Summary:
As discussed previously when landing patch for OpenMP in Flang, the idea is
to share common part of the OpenMP declaration between the different Frontend.
While doing this it was thought that moving to tablegen instead of Macros will also
give a cleaner and more powerful way of generating these declaration.
This first part of a future series of patches is setting up the base .td file for
DirectiveLanguage as well as the OpenMP version of it. The base file is meant to
be used by other directive language such as OpenACC.
In this first patch, the Directive and Clause enums are generated with tablegen
instead of the macros on OMPConstants.h. The next pacth will extend this
to other enum and move the Flang frontend to use it.
Reviewers: jdoerfert, DavidTruby, fghanim, ABataev, jdenny, hfinkel, jhuber6, kiranchandramohan, kiranktp
Reviewed By: jdoerfert, jdenny
Subscribers: arphaman, martong, cfe-commits, mgorny, yaxunl, hiraditya, guansong, jfb, sstefan1, aaron.ballman, llvm-commits
Tags: #llvm, #openmp, #clang
Differential Revision: https://reviews.llvm.org/D81736
2020-06-23 15:29:50 +02:00
|
|
|
|
[openmp] Move Directive and Clause helper function to tablegen
Summary:
Follow up to D81736. Move getOpenMPDirectiveKind, getOpenMPClauseKind, getOpenMPDirectiveName and
getOpenMPClauseName to the new tablegen code generation. The code is generated in a new file named OMP.cpp.inc
Reviewers: jdoerfert, jdenny, thakis
Reviewed By: jdoerfert, jdenny
Subscribers: mgorny, yaxunl, hiraditya, guansong, sstefan1, llvm-commits, thakis
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D82405
2020-06-30 20:36:37 +02:00
|
|
|
for (const auto &R : Records) {
|
2020-07-29 02:45:21 +02:00
|
|
|
BaseRecord Rec{R};
|
[openmp] Move Directive and Clause helper function to tablegen
Summary:
Follow up to D81736. Move getOpenMPDirectiveKind, getOpenMPClauseKind, getOpenMPDirectiveName and
getOpenMPClauseName to the new tablegen code generation. The code is generated in a new file named OMP.cpp.inc
Reviewers: jdoerfert, jdenny, thakis
Reviewed By: jdoerfert, jdenny
Subscribers: mgorny, yaxunl, hiraditya, guansong, sstefan1, llvm-commits, thakis
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D82405
2020-06-30 20:36:37 +02:00
|
|
|
if (ImplicitAsUnknown && R->getValueAsBit("isImplicit")) {
|
2020-07-29 02:45:21 +02:00
|
|
|
OS << " .Case(\"" << Rec.getName() << "\"," << Prefix
|
|
|
|
<< DefaultRec.getFormattedName() << ")\n";
|
[openmp] Move Directive and Clause helper function to tablegen
Summary:
Follow up to D81736. Move getOpenMPDirectiveKind, getOpenMPClauseKind, getOpenMPDirectiveName and
getOpenMPClauseName to the new tablegen code generation. The code is generated in a new file named OMP.cpp.inc
Reviewers: jdoerfert, jdenny, thakis
Reviewed By: jdoerfert, jdenny
Subscribers: mgorny, yaxunl, hiraditya, guansong, sstefan1, llvm-commits, thakis
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D82405
2020-06-30 20:36:37 +02:00
|
|
|
} else {
|
2020-07-29 02:45:21 +02:00
|
|
|
OS << " .Case(\"" << Rec.getName() << "\"," << Prefix
|
|
|
|
<< Rec.getFormattedName() << ")\n";
|
[openmp] Base of tablegen generated OpenMP common declaration
Summary:
As discussed previously when landing patch for OpenMP in Flang, the idea is
to share common part of the OpenMP declaration between the different Frontend.
While doing this it was thought that moving to tablegen instead of Macros will also
give a cleaner and more powerful way of generating these declaration.
This first part of a future series of patches is setting up the base .td file for
DirectiveLanguage as well as the OpenMP version of it. The base file is meant to
be used by other directive language such as OpenACC.
In this first patch, the Directive and Clause enums are generated with tablegen
instead of the macros on OMPConstants.h. The next pacth will extend this
to other enum and move the Flang frontend to use it.
Reviewers: jdoerfert, DavidTruby, fghanim, ABataev, jdenny, hfinkel, jhuber6, kiranchandramohan, kiranktp
Reviewed By: jdoerfert, jdenny
Subscribers: arphaman, martong, cfe-commits, mgorny, yaxunl, hiraditya, guansong, jfb, sstefan1, aaron.ballman, llvm-commits
Tags: #llvm, #openmp, #clang
Differential Revision: https://reviews.llvm.org/D81736
2020-06-23 15:29:50 +02:00
|
|
|
}
|
|
|
|
}
|
2020-07-29 02:45:21 +02:00
|
|
|
OS << " .Default(" << Prefix << DefaultRec.getFormattedName() << ");\n";
|
2020-07-07 04:19:43 +02:00
|
|
|
OS << "}\n";
|
|
|
|
}
|
|
|
|
|
2020-07-22 18:28:04 +02:00
|
|
|
// Generate function implementation for get<ClauseVal>Kind(StringRef Str)
|
2020-11-03 17:12:14 +01:00
|
|
|
void GenerateGetKindClauseVal(const DirectiveLanguage &DirLang,
|
|
|
|
raw_ostream &OS) {
|
|
|
|
for (const auto &R : DirLang.getClauses()) {
|
2020-07-22 18:28:04 +02:00
|
|
|
Clause C{R};
|
|
|
|
const auto &ClauseVals = C.getClauseVals();
|
|
|
|
if (ClauseVals.size() <= 0)
|
|
|
|
continue;
|
|
|
|
|
2021-01-09 03:39:55 +01:00
|
|
|
auto DefaultIt = llvm::find_if(ClauseVals, [](Record *CV) {
|
|
|
|
return CV->getValueAsBit("isDefault") == true;
|
|
|
|
});
|
2020-07-22 18:28:04 +02:00
|
|
|
|
|
|
|
if (DefaultIt == ClauseVals.end()) {
|
|
|
|
PrintError("At least one val in Clause " + C.getFormattedName() +
|
|
|
|
" must be defined as default.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const auto DefaultName = (*DefaultIt)->getName();
|
|
|
|
|
|
|
|
const auto &EnumName = C.getEnumName();
|
|
|
|
if (EnumName.size() == 0) {
|
|
|
|
PrintError("enumClauseValue field not set in Clause" +
|
|
|
|
C.getFormattedName() + ".");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
OS << "\n";
|
2020-11-03 17:12:14 +01:00
|
|
|
OS << EnumName << " llvm::" << DirLang.getCppNamespace() << "::get"
|
|
|
|
<< EnumName << "(llvm::StringRef Str) {\n";
|
2020-07-22 18:28:04 +02:00
|
|
|
OS << " return llvm::StringSwitch<" << EnumName << ">(Str)\n";
|
|
|
|
for (const auto &CV : ClauseVals) {
|
|
|
|
ClauseVal CVal{CV};
|
|
|
|
OS << " .Case(\"" << CVal.getFormattedName() << "\"," << CV->getName()
|
|
|
|
<< ")\n";
|
|
|
|
}
|
|
|
|
OS << " .Default(" << DefaultName << ");\n";
|
|
|
|
OS << "}\n";
|
2020-12-21 21:06:55 +01:00
|
|
|
|
|
|
|
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";
|
2020-07-22 18:28:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-09 01:54:34 +02:00
|
|
|
void GenerateCaseForVersionedClauses(const std::vector<Record *> &Clauses,
|
|
|
|
raw_ostream &OS, StringRef DirectiveName,
|
2020-11-03 17:12:14 +01:00
|
|
|
const DirectiveLanguage &DirLang,
|
[flang][openmp] Check clauses allowed semantic with tablegen generated map
Summary:
This patch is enabling the generation of clauses enum sets for semantics check in Flang through
tablegen. Enum sets and directive - sets map is generated by the new tablegen infrsatructure for OpenMP
and other directive languages.
The semantic checks for OpenMP are modified to use this newly generated map.
Reviewers: DavidTruby, sscalpone, kiranchandramohan, ichoyjx, jdoerfert
Reviewed By: DavidTruby, ichoyjx
Subscribers: mgorny, yaxunl, hiraditya, guansong, sstefan1, aaron.ballman, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D83326
2020-07-11 18:42:05 +02:00
|
|
|
llvm::StringSet<> &Cases) {
|
2020-07-07 04:19:43 +02:00
|
|
|
for (const auto &C : Clauses) {
|
2020-07-29 02:45:21 +02:00
|
|
|
VersionedClause VerClause{C};
|
|
|
|
|
|
|
|
const auto ClauseFormattedName = VerClause.getClause().getFormattedName();
|
|
|
|
|
|
|
|
if (Cases.find(ClauseFormattedName) == Cases.end()) {
|
|
|
|
Cases.insert(ClauseFormattedName);
|
|
|
|
OS << " case " << DirLang.getClausePrefix() << ClauseFormattedName
|
|
|
|
<< ":\n";
|
|
|
|
OS << " return " << VerClause.getMinVersion()
|
|
|
|
<< " <= Version && " << VerClause.getMaxVersion() << " >= Version;\n";
|
[flang][openmp] Check clauses allowed semantic with tablegen generated map
Summary:
This patch is enabling the generation of clauses enum sets for semantics check in Flang through
tablegen. Enum sets and directive - sets map is generated by the new tablegen infrsatructure for OpenMP
and other directive languages.
The semantic checks for OpenMP are modified to use this newly generated map.
Reviewers: DavidTruby, sscalpone, kiranchandramohan, ichoyjx, jdoerfert
Reviewed By: DavidTruby, ichoyjx
Subscribers: mgorny, yaxunl, hiraditya, guansong, sstefan1, aaron.ballman, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D83326
2020-07-11 18:42:05 +02:00
|
|
|
}
|
2020-07-07 04:19:43 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Generate the isAllowedClauseForDirective function implementation.
|
2020-11-03 17:12:14 +01:00
|
|
|
void GenerateIsAllowedClause(const DirectiveLanguage &DirLang,
|
|
|
|
raw_ostream &OS) {
|
2020-07-07 04:19:43 +02:00
|
|
|
OS << "\n";
|
2020-07-29 02:45:21 +02:00
|
|
|
OS << "bool llvm::" << DirLang.getCppNamespace()
|
|
|
|
<< "::isAllowedClauseForDirective("
|
2020-07-07 04:19:43 +02:00
|
|
|
<< "Directive D, Clause C, unsigned Version) {\n";
|
2020-07-29 02:45:21 +02:00
|
|
|
OS << " assert(unsigned(D) <= llvm::" << DirLang.getCppNamespace()
|
2020-07-07 04:19:43 +02:00
|
|
|
<< "::Directive_enumSize);\n";
|
2020-07-29 02:45:21 +02:00
|
|
|
OS << " assert(unsigned(C) <= llvm::" << DirLang.getCppNamespace()
|
2020-07-07 04:19:43 +02:00
|
|
|
<< "::Clause_enumSize);\n";
|
|
|
|
|
2020-07-09 01:54:34 +02:00
|
|
|
OS << " switch (D) {\n";
|
|
|
|
|
2020-11-03 17:12:14 +01:00
|
|
|
for (const auto &D : DirLang.getDirectives()) {
|
2020-07-29 02:45:21 +02:00
|
|
|
Directive Dir{D};
|
2020-07-09 01:54:34 +02:00
|
|
|
|
2020-07-29 02:45:21 +02:00
|
|
|
OS << " case " << DirLang.getDirectivePrefix() << Dir.getFormattedName()
|
2020-07-09 01:54:34 +02:00
|
|
|
<< ":\n";
|
2020-07-29 02:45:21 +02:00
|
|
|
if (Dir.getAllowedClauses().size() == 0 &&
|
|
|
|
Dir.getAllowedOnceClauses().size() == 0 &&
|
|
|
|
Dir.getAllowedExclusiveClauses().size() == 0 &&
|
|
|
|
Dir.getRequiredClauses().size() == 0) {
|
2020-07-11 02:57:00 +02:00
|
|
|
OS << " return false;\n";
|
|
|
|
} else {
|
|
|
|
OS << " switch (C) {\n";
|
2020-07-09 01:54:34 +02:00
|
|
|
|
[flang][openmp] Check clauses allowed semantic with tablegen generated map
Summary:
This patch is enabling the generation of clauses enum sets for semantics check in Flang through
tablegen. Enum sets and directive - sets map is generated by the new tablegen infrsatructure for OpenMP
and other directive languages.
The semantic checks for OpenMP are modified to use this newly generated map.
Reviewers: DavidTruby, sscalpone, kiranchandramohan, ichoyjx, jdoerfert
Reviewed By: DavidTruby, ichoyjx
Subscribers: mgorny, yaxunl, hiraditya, guansong, sstefan1, aaron.ballman, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D83326
2020-07-11 18:42:05 +02:00
|
|
|
llvm::StringSet<> Cases;
|
|
|
|
|
2020-07-29 02:45:21 +02:00
|
|
|
GenerateCaseForVersionedClauses(Dir.getAllowedClauses(), OS,
|
|
|
|
Dir.getName(), DirLang, Cases);
|
2020-07-07 04:19:43 +02:00
|
|
|
|
2020-07-29 02:45:21 +02:00
|
|
|
GenerateCaseForVersionedClauses(Dir.getAllowedOnceClauses(), OS,
|
|
|
|
Dir.getName(), DirLang, Cases);
|
[flang][openmp] Check clauses allowed semantic with tablegen generated map
Summary:
This patch is enabling the generation of clauses enum sets for semantics check in Flang through
tablegen. Enum sets and directive - sets map is generated by the new tablegen infrsatructure for OpenMP
and other directive languages.
The semantic checks for OpenMP are modified to use this newly generated map.
Reviewers: DavidTruby, sscalpone, kiranchandramohan, ichoyjx, jdoerfert
Reviewed By: DavidTruby, ichoyjx
Subscribers: mgorny, yaxunl, hiraditya, guansong, sstefan1, aaron.ballman, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D83326
2020-07-11 18:42:05 +02:00
|
|
|
|
2020-07-29 02:45:21 +02:00
|
|
|
GenerateCaseForVersionedClauses(Dir.getAllowedExclusiveClauses(), OS,
|
|
|
|
Dir.getName(), DirLang, Cases);
|
2020-07-07 04:19:43 +02:00
|
|
|
|
2020-07-29 02:45:21 +02:00
|
|
|
GenerateCaseForVersionedClauses(Dir.getRequiredClauses(), OS,
|
|
|
|
Dir.getName(), DirLang, Cases);
|
2020-07-09 01:54:34 +02:00
|
|
|
|
2020-07-11 02:57:00 +02:00
|
|
|
OS << " default:\n";
|
|
|
|
OS << " return false;\n";
|
|
|
|
OS << " }\n"; // End of clauses switch
|
|
|
|
}
|
2020-07-09 01:54:34 +02:00
|
|
|
OS << " break;\n";
|
2020-07-07 04:19:43 +02:00
|
|
|
}
|
2020-07-09 01:54:34 +02:00
|
|
|
|
|
|
|
OS << " }\n"; // End of directives switch
|
2020-07-29 02:45:21 +02:00
|
|
|
OS << " llvm_unreachable(\"Invalid " << DirLang.getName()
|
2020-07-09 01:54:34 +02:00
|
|
|
<< " Directive kind\");\n";
|
|
|
|
OS << "}\n"; // End of function isAllowedClauseForDirective
|
[openmp] Move Directive and Clause helper function to tablegen
Summary:
Follow up to D81736. Move getOpenMPDirectiveKind, getOpenMPClauseKind, getOpenMPDirectiveName and
getOpenMPClauseName to the new tablegen code generation. The code is generated in a new file named OMP.cpp.inc
Reviewers: jdoerfert, jdenny, thakis
Reviewed By: jdoerfert, jdenny
Subscribers: mgorny, yaxunl, hiraditya, guansong, sstefan1, llvm-commits, thakis
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D82405
2020-06-30 20:36:37 +02:00
|
|
|
}
|
[openmp] Base of tablegen generated OpenMP common declaration
Summary:
As discussed previously when landing patch for OpenMP in Flang, the idea is
to share common part of the OpenMP declaration between the different Frontend.
While doing this it was thought that moving to tablegen instead of Macros will also
give a cleaner and more powerful way of generating these declaration.
This first part of a future series of patches is setting up the base .td file for
DirectiveLanguage as well as the OpenMP version of it. The base file is meant to
be used by other directive language such as OpenACC.
In this first patch, the Directive and Clause enums are generated with tablegen
instead of the macros on OMPConstants.h. The next pacth will extend this
to other enum and move the Flang frontend to use it.
Reviewers: jdoerfert, DavidTruby, fghanim, ABataev, jdenny, hfinkel, jhuber6, kiranchandramohan, kiranktp
Reviewed By: jdoerfert, jdenny
Subscribers: arphaman, martong, cfe-commits, mgorny, yaxunl, hiraditya, guansong, jfb, sstefan1, aaron.ballman, llvm-commits
Tags: #llvm, #openmp, #clang
Differential Revision: https://reviews.llvm.org/D81736
2020-06-23 15:29:50 +02:00
|
|
|
|
[flang][openmp] Check clauses allowed semantic with tablegen generated map
Summary:
This patch is enabling the generation of clauses enum sets for semantics check in Flang through
tablegen. Enum sets and directive - sets map is generated by the new tablegen infrsatructure for OpenMP
and other directive languages.
The semantic checks for OpenMP are modified to use this newly generated map.
Reviewers: DavidTruby, sscalpone, kiranchandramohan, ichoyjx, jdoerfert
Reviewed By: DavidTruby, ichoyjx
Subscribers: mgorny, yaxunl, hiraditya, guansong, sstefan1, aaron.ballman, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D83326
2020-07-11 18:42:05 +02:00
|
|
|
// Generate a simple enum set with the give clauses.
|
|
|
|
void GenerateClauseSet(const std::vector<Record *> &Clauses, raw_ostream &OS,
|
2020-07-29 02:45:21 +02:00
|
|
|
StringRef ClauseSetPrefix, Directive &Dir,
|
2020-11-03 17:12:14 +01:00
|
|
|
const DirectiveLanguage &DirLang) {
|
[flang][openmp] Check clauses allowed semantic with tablegen generated map
Summary:
This patch is enabling the generation of clauses enum sets for semantics check in Flang through
tablegen. Enum sets and directive - sets map is generated by the new tablegen infrsatructure for OpenMP
and other directive languages.
The semantic checks for OpenMP are modified to use this newly generated map.
Reviewers: DavidTruby, sscalpone, kiranchandramohan, ichoyjx, jdoerfert
Reviewed By: DavidTruby, ichoyjx
Subscribers: mgorny, yaxunl, hiraditya, guansong, sstefan1, aaron.ballman, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D83326
2020-07-11 18:42:05 +02:00
|
|
|
|
|
|
|
OS << "\n";
|
2020-07-29 02:45:21 +02:00
|
|
|
OS << " static " << DirLang.getClauseEnumSetClass() << " " << ClauseSetPrefix
|
|
|
|
<< DirLang.getDirectivePrefix() << Dir.getFormattedName() << " {\n";
|
[flang][openmp] Check clauses allowed semantic with tablegen generated map
Summary:
This patch is enabling the generation of clauses enum sets for semantics check in Flang through
tablegen. Enum sets and directive - sets map is generated by the new tablegen infrsatructure for OpenMP
and other directive languages.
The semantic checks for OpenMP are modified to use this newly generated map.
Reviewers: DavidTruby, sscalpone, kiranchandramohan, ichoyjx, jdoerfert
Reviewed By: DavidTruby, ichoyjx
Subscribers: mgorny, yaxunl, hiraditya, guansong, sstefan1, aaron.ballman, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D83326
2020-07-11 18:42:05 +02:00
|
|
|
|
|
|
|
for (const auto &C : Clauses) {
|
2020-07-29 02:45:21 +02:00
|
|
|
VersionedClause VerClause{C};
|
|
|
|
OS << " llvm::" << DirLang.getCppNamespace()
|
|
|
|
<< "::Clause::" << DirLang.getClausePrefix()
|
|
|
|
<< VerClause.getClause().getFormattedName() << ",\n";
|
[flang][openmp] Check clauses allowed semantic with tablegen generated map
Summary:
This patch is enabling the generation of clauses enum sets for semantics check in Flang through
tablegen. Enum sets and directive - sets map is generated by the new tablegen infrsatructure for OpenMP
and other directive languages.
The semantic checks for OpenMP are modified to use this newly generated map.
Reviewers: DavidTruby, sscalpone, kiranchandramohan, ichoyjx, jdoerfert
Reviewed By: DavidTruby, ichoyjx
Subscribers: mgorny, yaxunl, hiraditya, guansong, sstefan1, aaron.ballman, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D83326
2020-07-11 18:42:05 +02:00
|
|
|
}
|
|
|
|
OS << " };\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
// Generate an enum set for the 4 kinds of clauses linked to a directive.
|
2020-11-03 17:12:14 +01:00
|
|
|
void GenerateDirectiveClauseSets(const DirectiveLanguage &DirLang,
|
|
|
|
raw_ostream &OS) {
|
[flang][openmp] Check clauses allowed semantic with tablegen generated map
Summary:
This patch is enabling the generation of clauses enum sets for semantics check in Flang through
tablegen. Enum sets and directive - sets map is generated by the new tablegen infrsatructure for OpenMP
and other directive languages.
The semantic checks for OpenMP are modified to use this newly generated map.
Reviewers: DavidTruby, sscalpone, kiranchandramohan, ichoyjx, jdoerfert
Reviewed By: DavidTruby, ichoyjx
Subscribers: mgorny, yaxunl, hiraditya, guansong, sstefan1, aaron.ballman, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D83326
2020-07-11 18:42:05 +02:00
|
|
|
|
|
|
|
IfDefScope Scope("GEN_FLANG_DIRECTIVE_CLAUSE_SETS", OS);
|
|
|
|
|
|
|
|
OS << "\n";
|
|
|
|
OS << "namespace llvm {\n";
|
|
|
|
|
|
|
|
// Open namespaces defined in the directive language.
|
|
|
|
llvm::SmallVector<StringRef, 2> Namespaces;
|
2020-07-29 02:45:21 +02:00
|
|
|
llvm::SplitString(DirLang.getCppNamespace(), Namespaces, "::");
|
[flang][openmp] Check clauses allowed semantic with tablegen generated map
Summary:
This patch is enabling the generation of clauses enum sets for semantics check in Flang through
tablegen. Enum sets and directive - sets map is generated by the new tablegen infrsatructure for OpenMP
and other directive languages.
The semantic checks for OpenMP are modified to use this newly generated map.
Reviewers: DavidTruby, sscalpone, kiranchandramohan, ichoyjx, jdoerfert
Reviewed By: DavidTruby, ichoyjx
Subscribers: mgorny, yaxunl, hiraditya, guansong, sstefan1, aaron.ballman, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D83326
2020-07-11 18:42:05 +02:00
|
|
|
for (auto Ns : Namespaces)
|
|
|
|
OS << "namespace " << Ns << " {\n";
|
|
|
|
|
2020-11-03 17:12:14 +01:00
|
|
|
for (const auto &D : DirLang.getDirectives()) {
|
2020-07-29 02:45:21 +02:00
|
|
|
Directive Dir{D};
|
[flang][openmp] Check clauses allowed semantic with tablegen generated map
Summary:
This patch is enabling the generation of clauses enum sets for semantics check in Flang through
tablegen. Enum sets and directive - sets map is generated by the new tablegen infrsatructure for OpenMP
and other directive languages.
The semantic checks for OpenMP are modified to use this newly generated map.
Reviewers: DavidTruby, sscalpone, kiranchandramohan, ichoyjx, jdoerfert
Reviewed By: DavidTruby, ichoyjx
Subscribers: mgorny, yaxunl, hiraditya, guansong, sstefan1, aaron.ballman, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D83326
2020-07-11 18:42:05 +02:00
|
|
|
|
|
|
|
OS << "\n";
|
2020-07-29 02:45:21 +02:00
|
|
|
OS << " // Sets for " << Dir.getName() << "\n";
|
|
|
|
|
|
|
|
GenerateClauseSet(Dir.getAllowedClauses(), OS, "allowedClauses_", Dir,
|
|
|
|
DirLang);
|
|
|
|
GenerateClauseSet(Dir.getAllowedOnceClauses(), OS, "allowedOnceClauses_",
|
|
|
|
Dir, DirLang);
|
|
|
|
GenerateClauseSet(Dir.getAllowedExclusiveClauses(), OS,
|
|
|
|
"allowedExclusiveClauses_", Dir, DirLang);
|
|
|
|
GenerateClauseSet(Dir.getRequiredClauses(), OS, "requiredClauses_", Dir,
|
|
|
|
DirLang);
|
[flang][openmp] Check clauses allowed semantic with tablegen generated map
Summary:
This patch is enabling the generation of clauses enum sets for semantics check in Flang through
tablegen. Enum sets and directive - sets map is generated by the new tablegen infrsatructure for OpenMP
and other directive languages.
The semantic checks for OpenMP are modified to use this newly generated map.
Reviewers: DavidTruby, sscalpone, kiranchandramohan, ichoyjx, jdoerfert
Reviewed By: DavidTruby, ichoyjx
Subscribers: mgorny, yaxunl, hiraditya, guansong, sstefan1, aaron.ballman, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D83326
2020-07-11 18:42:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Closing namespaces
|
|
|
|
for (auto Ns : llvm::reverse(Namespaces))
|
|
|
|
OS << "} // namespace " << Ns << "\n";
|
|
|
|
|
|
|
|
OS << "} // namespace llvm\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
// Generate a map of directive (key) with DirectiveClauses struct as values.
|
|
|
|
// The struct holds the 4 sets of enumeration for the 4 kinds of clauses
|
|
|
|
// allowances (allowed, allowed once, allowed exclusive and required).
|
2020-11-03 17:12:14 +01:00
|
|
|
void GenerateDirectiveClauseMap(const DirectiveLanguage &DirLang,
|
|
|
|
raw_ostream &OS) {
|
[flang][openmp] Check clauses allowed semantic with tablegen generated map
Summary:
This patch is enabling the generation of clauses enum sets for semantics check in Flang through
tablegen. Enum sets and directive - sets map is generated by the new tablegen infrsatructure for OpenMP
and other directive languages.
The semantic checks for OpenMP are modified to use this newly generated map.
Reviewers: DavidTruby, sscalpone, kiranchandramohan, ichoyjx, jdoerfert
Reviewed By: DavidTruby, ichoyjx
Subscribers: mgorny, yaxunl, hiraditya, guansong, sstefan1, aaron.ballman, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D83326
2020-07-11 18:42:05 +02:00
|
|
|
|
|
|
|
IfDefScope Scope("GEN_FLANG_DIRECTIVE_CLAUSE_MAP", OS);
|
|
|
|
|
|
|
|
OS << "\n";
|
2020-08-05 20:20:26 +02:00
|
|
|
OS << "{\n";
|
[flang][openmp] Check clauses allowed semantic with tablegen generated map
Summary:
This patch is enabling the generation of clauses enum sets for semantics check in Flang through
tablegen. Enum sets and directive - sets map is generated by the new tablegen infrsatructure for OpenMP
and other directive languages.
The semantic checks for OpenMP are modified to use this newly generated map.
Reviewers: DavidTruby, sscalpone, kiranchandramohan, ichoyjx, jdoerfert
Reviewed By: DavidTruby, ichoyjx
Subscribers: mgorny, yaxunl, hiraditya, guansong, sstefan1, aaron.ballman, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D83326
2020-07-11 18:42:05 +02:00
|
|
|
|
2020-11-03 17:12:14 +01:00
|
|
|
for (const auto &D : DirLang.getDirectives()) {
|
2020-07-29 02:45:21 +02:00
|
|
|
Directive Dir{D};
|
|
|
|
OS << " {llvm::" << DirLang.getCppNamespace()
|
|
|
|
<< "::Directive::" << DirLang.getDirectivePrefix()
|
|
|
|
<< Dir.getFormattedName() << ",\n";
|
[flang][openmp] Check clauses allowed semantic with tablegen generated map
Summary:
This patch is enabling the generation of clauses enum sets for semantics check in Flang through
tablegen. Enum sets and directive - sets map is generated by the new tablegen infrsatructure for OpenMP
and other directive languages.
The semantic checks for OpenMP are modified to use this newly generated map.
Reviewers: DavidTruby, sscalpone, kiranchandramohan, ichoyjx, jdoerfert
Reviewed By: DavidTruby, ichoyjx
Subscribers: mgorny, yaxunl, hiraditya, guansong, sstefan1, aaron.ballman, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D83326
2020-07-11 18:42:05 +02:00
|
|
|
OS << " {\n";
|
2020-07-29 02:45:21 +02:00
|
|
|
OS << " llvm::" << DirLang.getCppNamespace() << "::allowedClauses_"
|
|
|
|
<< DirLang.getDirectivePrefix() << Dir.getFormattedName() << ",\n";
|
|
|
|
OS << " llvm::" << DirLang.getCppNamespace() << "::allowedOnceClauses_"
|
|
|
|
<< DirLang.getDirectivePrefix() << Dir.getFormattedName() << ",\n";
|
|
|
|
OS << " llvm::" << DirLang.getCppNamespace()
|
|
|
|
<< "::allowedExclusiveClauses_" << DirLang.getDirectivePrefix()
|
|
|
|
<< Dir.getFormattedName() << ",\n";
|
|
|
|
OS << " llvm::" << DirLang.getCppNamespace() << "::requiredClauses_"
|
|
|
|
<< DirLang.getDirectivePrefix() << Dir.getFormattedName() << ",\n";
|
[flang][openmp] Check clauses allowed semantic with tablegen generated map
Summary:
This patch is enabling the generation of clauses enum sets for semantics check in Flang through
tablegen. Enum sets and directive - sets map is generated by the new tablegen infrsatructure for OpenMP
and other directive languages.
The semantic checks for OpenMP are modified to use this newly generated map.
Reviewers: DavidTruby, sscalpone, kiranchandramohan, ichoyjx, jdoerfert
Reviewed By: DavidTruby, ichoyjx
Subscribers: mgorny, yaxunl, hiraditya, guansong, sstefan1, aaron.ballman, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D83326
2020-07-11 18:42:05 +02:00
|
|
|
OS << " }\n";
|
|
|
|
OS << " },\n";
|
|
|
|
}
|
|
|
|
|
2020-08-05 20:20:26 +02:00
|
|
|
OS << "}\n";
|
[flang][openmp] Check clauses allowed semantic with tablegen generated map
Summary:
This patch is enabling the generation of clauses enum sets for semantics check in Flang through
tablegen. Enum sets and directive - sets map is generated by the new tablegen infrsatructure for OpenMP
and other directive languages.
The semantic checks for OpenMP are modified to use this newly generated map.
Reviewers: DavidTruby, sscalpone, kiranchandramohan, ichoyjx, jdoerfert
Reviewed By: DavidTruby, ichoyjx
Subscribers: mgorny, yaxunl, hiraditya, guansong, sstefan1, aaron.ballman, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D83326
2020-07-11 18:42:05 +02:00
|
|
|
}
|
|
|
|
|
2020-08-11 16:43:56 +02:00
|
|
|
// Generate classes entry for Flang clauses in the Flang parse-tree
|
|
|
|
// If the clause as a non-generic class, no entry is generated.
|
|
|
|
// If the clause does not hold a value, an EMPTY_CLASS is used.
|
|
|
|
// If the clause class is generic then a WRAPPER_CLASS is used. When the value
|
|
|
|
// is optional, the value class is wrapped into a std::optional.
|
2020-11-03 17:12:14 +01:00
|
|
|
void GenerateFlangClauseParserClass(const DirectiveLanguage &DirLang,
|
2020-08-11 16:43:56 +02:00
|
|
|
raw_ostream &OS) {
|
|
|
|
|
|
|
|
IfDefScope Scope("GEN_FLANG_CLAUSE_PARSER_CLASSES", OS);
|
|
|
|
|
|
|
|
OS << "\n";
|
|
|
|
|
2020-11-03 17:12:14 +01:00
|
|
|
for (const auto &C : DirLang.getClauses()) {
|
2020-08-11 16:43:56 +02:00
|
|
|
Clause Clause{C};
|
2021-01-19 16:28:09 +01:00
|
|
|
if (!Clause.getFlangClass().empty()) {
|
2020-08-17 20:22:01 +02:00
|
|
|
OS << "WRAPPER_CLASS(" << Clause.getFormattedParserClassName() << ", ";
|
|
|
|
if (Clause.isValueOptional() && Clause.isValueList()) {
|
2021-01-19 16:28:09 +01:00
|
|
|
OS << "std::optional<std::list<" << Clause.getFlangClass() << ">>";
|
2020-08-17 20:22:01 +02:00
|
|
|
} else if (Clause.isValueOptional()) {
|
2021-01-19 16:28:09 +01:00
|
|
|
OS << "std::optional<" << Clause.getFlangClass() << ">";
|
2020-08-17 20:22:01 +02:00
|
|
|
} else if (Clause.isValueList()) {
|
2021-01-19 16:28:09 +01:00
|
|
|
OS << "std::list<" << Clause.getFlangClass() << ">";
|
2020-08-11 16:43:56 +02:00
|
|
|
} else {
|
2021-01-19 16:28:09 +01:00
|
|
|
OS << Clause.getFlangClass();
|
2020-08-11 16:43:56 +02:00
|
|
|
}
|
|
|
|
} else {
|
2020-08-17 20:22:01 +02:00
|
|
|
OS << "EMPTY_CLASS(" << Clause.getFormattedParserClassName();
|
2020-08-11 16:43:56 +02:00
|
|
|
}
|
2020-08-17 20:22:01 +02:00
|
|
|
OS << ");\n";
|
2020-08-11 16:43:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Generate a list of the different clause classes for Flang.
|
2020-11-03 17:12:14 +01:00
|
|
|
void GenerateFlangClauseParserClassList(const DirectiveLanguage &DirLang,
|
2020-08-11 16:43:56 +02:00
|
|
|
raw_ostream &OS) {
|
|
|
|
|
|
|
|
IfDefScope Scope("GEN_FLANG_CLAUSE_PARSER_CLASSES_LIST", OS);
|
|
|
|
|
|
|
|
OS << "\n";
|
2020-11-03 17:12:14 +01:00
|
|
|
llvm::interleaveComma(DirLang.getClauses(), OS, [&](Record *C) {
|
2020-08-11 16:43:56 +02:00
|
|
|
Clause Clause{C};
|
2021-01-19 16:28:09 +01:00
|
|
|
OS << Clause.getFormattedParserClassName() << "\n";
|
2020-08-11 16:43:56 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// Generate dump node list for the clauses holding a generic class name.
|
2020-11-03 17:12:14 +01:00
|
|
|
void GenerateFlangClauseDump(const DirectiveLanguage &DirLang,
|
2020-08-11 16:43:56 +02:00
|
|
|
raw_ostream &OS) {
|
|
|
|
|
|
|
|
IfDefScope Scope("GEN_FLANG_DUMP_PARSE_TREE_CLAUSES", OS);
|
|
|
|
|
|
|
|
OS << "\n";
|
2020-11-03 17:12:14 +01:00
|
|
|
for (const auto &C : DirLang.getClauses()) {
|
2020-08-11 16:43:56 +02:00
|
|
|
Clause Clause{C};
|
|
|
|
OS << "NODE(" << DirLang.getFlangClauseBaseClass() << ", "
|
|
|
|
<< Clause.getFormattedParserClassName() << ")\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-17 20:22:01 +02:00
|
|
|
// Generate Unparse functions for clauses classes in the Flang parse-tree
|
|
|
|
// If the clause is a non-generic class, no entry is generated.
|
2020-11-03 17:12:14 +01:00
|
|
|
void GenerateFlangClauseUnparse(const DirectiveLanguage &DirLang,
|
2020-08-17 20:22:01 +02:00
|
|
|
raw_ostream &OS) {
|
|
|
|
|
|
|
|
IfDefScope Scope("GEN_FLANG_CLAUSE_UNPARSE", OS);
|
|
|
|
|
|
|
|
OS << "\n";
|
|
|
|
|
2020-11-03 17:12:14 +01:00
|
|
|
for (const auto &C : DirLang.getClauses()) {
|
2020-08-17 20:22:01 +02:00
|
|
|
Clause Clause{C};
|
2021-01-19 16:28:09 +01:00
|
|
|
if (!Clause.getFlangClass().empty()) {
|
2020-08-17 20:22:01 +02:00
|
|
|
if (Clause.isValueOptional() && Clause.getDefaultValue().empty()) {
|
|
|
|
OS << "void Unparse(const " << DirLang.getFlangClauseBaseClass()
|
|
|
|
<< "::" << Clause.getFormattedParserClassName() << " &x) {\n";
|
|
|
|
OS << " Word(\"" << Clause.getName().upper() << "\");\n";
|
|
|
|
|
|
|
|
OS << " Walk(\"(\", x.v, \")\");\n";
|
|
|
|
OS << "}\n";
|
|
|
|
} else if (Clause.isValueOptional()) {
|
|
|
|
OS << "void Unparse(const " << DirLang.getFlangClauseBaseClass()
|
|
|
|
<< "::" << Clause.getFormattedParserClassName() << " &x) {\n";
|
|
|
|
OS << " Word(\"" << Clause.getName().upper() << "\");\n";
|
|
|
|
OS << " Put(\"(\");\n";
|
|
|
|
OS << " if (x.v.has_value())\n";
|
|
|
|
if (Clause.isValueList())
|
|
|
|
OS << " Walk(x.v, \",\");\n";
|
|
|
|
else
|
|
|
|
OS << " Walk(x.v);\n";
|
|
|
|
OS << " else\n";
|
|
|
|
OS << " Put(\"" << Clause.getDefaultValue() << "\");\n";
|
|
|
|
OS << " Put(\")\");\n";
|
|
|
|
OS << "}\n";
|
|
|
|
} else {
|
|
|
|
OS << "void Unparse(const " << DirLang.getFlangClauseBaseClass()
|
|
|
|
<< "::" << Clause.getFormattedParserClassName() << " &x) {\n";
|
|
|
|
OS << " Word(\"" << Clause.getName().upper() << "\");\n";
|
|
|
|
OS << " Put(\"(\");\n";
|
|
|
|
if (Clause.isValueList())
|
|
|
|
OS << " Walk(x.v, \",\");\n";
|
|
|
|
else
|
|
|
|
OS << " Walk(x.v);\n";
|
|
|
|
OS << " Put(\")\");\n";
|
|
|
|
OS << "}\n";
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
OS << "void Before(const " << DirLang.getFlangClauseBaseClass()
|
|
|
|
<< "::" << Clause.getFormattedParserClassName() << " &) { Word(\""
|
|
|
|
<< Clause.getName().upper() << "\"); }\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-01 19:33:07 +01:00
|
|
|
// Generate check in the Enter functions for clauses classes.
|
|
|
|
void GenerateFlangClauseCheckPrototypes(const DirectiveLanguage &DirLang,
|
|
|
|
raw_ostream &OS) {
|
|
|
|
|
|
|
|
IfDefScope Scope("GEN_FLANG_CLAUSE_CHECK_ENTER", OS);
|
|
|
|
|
|
|
|
OS << "\n";
|
|
|
|
for (const auto &C : DirLang.getClauses()) {
|
|
|
|
Clause Clause{C};
|
|
|
|
OS << "void Enter(const parser::" << DirLang.getFlangClauseBaseClass()
|
|
|
|
<< "::" << Clause.getFormattedParserClassName() << " &);\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-14 13:42:30 +01:00
|
|
|
// Generate the mapping for clauses between the parser class and the
|
|
|
|
// corresponding clause Kind
|
|
|
|
void GenerateFlangClauseParserKindMap(const DirectiveLanguage &DirLang,
|
|
|
|
raw_ostream &OS) {
|
|
|
|
|
|
|
|
IfDefScope Scope("GEN_FLANG_CLAUSE_PARSER_KIND_MAP", OS);
|
|
|
|
|
|
|
|
OS << "\n";
|
|
|
|
for (const auto &C : DirLang.getClauses()) {
|
|
|
|
Clause Clause{C};
|
|
|
|
OS << "if constexpr (std::is_same_v<A, parser::"
|
|
|
|
<< DirLang.getFlangClauseBaseClass()
|
|
|
|
<< "::" << Clause.getFormattedParserClassName();
|
|
|
|
OS << ">)\n";
|
|
|
|
OS << " return llvm::" << DirLang.getCppNamespace()
|
|
|
|
<< "::Clause::" << DirLang.getClausePrefix() << Clause.getFormattedName()
|
|
|
|
<< ";\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
OS << "llvm_unreachable(\"Invalid " << DirLang.getName()
|
|
|
|
<< " Parser clause\");\n";
|
|
|
|
}
|
|
|
|
|
2020-12-22 15:59:50 +01:00
|
|
|
// Generate the implementation section for the enumeration in the directive
|
[openmp] Move Directive and Clause helper function to tablegen
Summary:
Follow up to D81736. Move getOpenMPDirectiveKind, getOpenMPClauseKind, getOpenMPDirectiveName and
getOpenMPClauseName to the new tablegen code generation. The code is generated in a new file named OMP.cpp.inc
Reviewers: jdoerfert, jdenny, thakis
Reviewed By: jdoerfert, jdenny
Subscribers: mgorny, yaxunl, hiraditya, guansong, sstefan1, llvm-commits, thakis
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D82405
2020-06-30 20:36:37 +02:00
|
|
|
// language
|
2020-11-03 17:12:14 +01:00
|
|
|
void EmitDirectivesFlangImpl(const DirectiveLanguage &DirLang,
|
|
|
|
raw_ostream &OS) {
|
[flang][openmp] Check clauses allowed semantic with tablegen generated map
Summary:
This patch is enabling the generation of clauses enum sets for semantics check in Flang through
tablegen. Enum sets and directive - sets map is generated by the new tablegen infrsatructure for OpenMP
and other directive languages.
The semantic checks for OpenMP are modified to use this newly generated map.
Reviewers: DavidTruby, sscalpone, kiranchandramohan, ichoyjx, jdoerfert
Reviewed By: DavidTruby, ichoyjx
Subscribers: mgorny, yaxunl, hiraditya, guansong, sstefan1, aaron.ballman, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D83326
2020-07-11 18:42:05 +02:00
|
|
|
|
2020-11-03 17:12:14 +01:00
|
|
|
GenerateDirectiveClauseSets(DirLang, OS);
|
[flang][openmp] Check clauses allowed semantic with tablegen generated map
Summary:
This patch is enabling the generation of clauses enum sets for semantics check in Flang through
tablegen. Enum sets and directive - sets map is generated by the new tablegen infrsatructure for OpenMP
and other directive languages.
The semantic checks for OpenMP are modified to use this newly generated map.
Reviewers: DavidTruby, sscalpone, kiranchandramohan, ichoyjx, jdoerfert
Reviewed By: DavidTruby, ichoyjx
Subscribers: mgorny, yaxunl, hiraditya, guansong, sstefan1, aaron.ballman, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D83326
2020-07-11 18:42:05 +02:00
|
|
|
|
2020-11-03 17:12:14 +01:00
|
|
|
GenerateDirectiveClauseMap(DirLang, OS);
|
2020-08-11 16:43:56 +02:00
|
|
|
|
2020-11-03 17:12:14 +01:00
|
|
|
GenerateFlangClauseParserClass(DirLang, OS);
|
2020-08-11 16:43:56 +02:00
|
|
|
|
2020-11-03 17:12:14 +01:00
|
|
|
GenerateFlangClauseParserClassList(DirLang, OS);
|
2020-08-11 16:43:56 +02:00
|
|
|
|
2020-11-03 17:12:14 +01:00
|
|
|
GenerateFlangClauseDump(DirLang, OS);
|
2020-08-17 20:22:01 +02:00
|
|
|
|
2020-11-03 17:12:14 +01:00
|
|
|
GenerateFlangClauseUnparse(DirLang, OS);
|
2021-02-01 19:33:07 +01:00
|
|
|
|
|
|
|
GenerateFlangClauseCheckPrototypes(DirLang, OS);
|
2021-03-14 13:42:30 +01:00
|
|
|
|
|
|
|
GenerateFlangClauseParserKindMap(DirLang, OS);
|
[flang][openmp] Check clauses allowed semantic with tablegen generated map
Summary:
This patch is enabling the generation of clauses enum sets for semantics check in Flang through
tablegen. Enum sets and directive - sets map is generated by the new tablegen infrsatructure for OpenMP
and other directive languages.
The semantic checks for OpenMP are modified to use this newly generated map.
Reviewers: DavidTruby, sscalpone, kiranchandramohan, ichoyjx, jdoerfert
Reviewed By: DavidTruby, ichoyjx
Subscribers: mgorny, yaxunl, hiraditya, guansong, sstefan1, aaron.ballman, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D83326
2020-07-11 18:42:05 +02:00
|
|
|
}
|
|
|
|
|
2020-12-17 20:07:29 +01:00
|
|
|
void GenerateClauseClassMacro(const DirectiveLanguage &DirLang,
|
|
|
|
raw_ostream &OS) {
|
|
|
|
// Generate macros style information for legacy code in clang
|
|
|
|
IfDefScope Scope("GEN_CLANG_CLAUSE_CLASS", OS);
|
|
|
|
|
|
|
|
OS << "\n";
|
|
|
|
|
|
|
|
OS << "#ifndef CLAUSE\n";
|
|
|
|
OS << "#define CLAUSE(Enum, Str, Implicit)\n";
|
|
|
|
OS << "#endif\n";
|
|
|
|
OS << "#ifndef CLAUSE_CLASS\n";
|
|
|
|
OS << "#define CLAUSE_CLASS(Enum, Str, Class)\n";
|
|
|
|
OS << "#endif\n";
|
|
|
|
OS << "#ifndef CLAUSE_NO_CLASS\n";
|
|
|
|
OS << "#define CLAUSE_NO_CLASS(Enum, Str)\n";
|
|
|
|
OS << "#endif\n";
|
|
|
|
OS << "\n";
|
|
|
|
OS << "#define __CLAUSE(Name, Class) \\\n";
|
|
|
|
OS << " CLAUSE(" << DirLang.getClausePrefix()
|
|
|
|
<< "##Name, #Name, /* Implicit */ false) \\\n";
|
|
|
|
OS << " CLAUSE_CLASS(" << DirLang.getClausePrefix()
|
|
|
|
<< "##Name, #Name, Class)\n";
|
|
|
|
OS << "#define __CLAUSE_NO_CLASS(Name) \\\n";
|
|
|
|
OS << " CLAUSE(" << DirLang.getClausePrefix()
|
|
|
|
<< "##Name, #Name, /* Implicit */ false) \\\n";
|
|
|
|
OS << " CLAUSE_NO_CLASS(" << DirLang.getClausePrefix() << "##Name, #Name)\n";
|
|
|
|
OS << "#define __IMPLICIT_CLAUSE_CLASS(Name, Str, Class) \\\n";
|
|
|
|
OS << " CLAUSE(" << DirLang.getClausePrefix()
|
|
|
|
<< "##Name, Str, /* Implicit */ true) \\\n";
|
|
|
|
OS << " CLAUSE_CLASS(" << DirLang.getClausePrefix()
|
|
|
|
<< "##Name, Str, Class)\n";
|
|
|
|
OS << "#define __IMPLICIT_CLAUSE_NO_CLASS(Name, Str) \\\n";
|
|
|
|
OS << " CLAUSE(" << DirLang.getClausePrefix()
|
|
|
|
<< "##Name, Str, /* Implicit */ true) \\\n";
|
|
|
|
OS << " CLAUSE_NO_CLASS(" << DirLang.getClausePrefix() << "##Name, Str)\n";
|
|
|
|
OS << "\n";
|
|
|
|
|
|
|
|
for (const auto &R : DirLang.getClauses()) {
|
|
|
|
Clause C{R};
|
|
|
|
if (C.getClangClass().empty()) { // NO_CLASS
|
|
|
|
if (C.isImplicit()) {
|
|
|
|
OS << "__IMPLICIT_CLAUSE_NO_CLASS(" << C.getFormattedName() << ", \""
|
|
|
|
<< C.getFormattedName() << "\")\n";
|
|
|
|
} else {
|
|
|
|
OS << "__CLAUSE_NO_CLASS(" << C.getFormattedName() << ")\n";
|
|
|
|
}
|
|
|
|
} else { // CLASS
|
|
|
|
if (C.isImplicit()) {
|
|
|
|
OS << "__IMPLICIT_CLAUSE_CLASS(" << C.getFormattedName() << ", \""
|
|
|
|
<< C.getFormattedName() << "\", " << C.getClangClass() << ")\n";
|
|
|
|
} else {
|
|
|
|
OS << "__CLAUSE(" << C.getFormattedName() << ", " << C.getClangClass()
|
|
|
|
<< ")\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
OS << "\n";
|
|
|
|
OS << "#undef __IMPLICIT_CLAUSE_NO_CLASS\n";
|
|
|
|
OS << "#undef __IMPLICIT_CLAUSE_CLASS\n";
|
|
|
|
OS << "#undef __CLAUSE\n";
|
|
|
|
OS << "#undef CLAUSE_NO_CLASS\n";
|
|
|
|
OS << "#undef CLAUSE_CLASS\n";
|
|
|
|
OS << "#undef CLAUSE\n";
|
|
|
|
}
|
|
|
|
|
2021-03-23 14:10:04 +01:00
|
|
|
// Generate the implemenation for the enumeration in the directive
|
[flang][openmp] Check clauses allowed semantic with tablegen generated map
Summary:
This patch is enabling the generation of clauses enum sets for semantics check in Flang through
tablegen. Enum sets and directive - sets map is generated by the new tablegen infrsatructure for OpenMP
and other directive languages.
The semantic checks for OpenMP are modified to use this newly generated map.
Reviewers: DavidTruby, sscalpone, kiranchandramohan, ichoyjx, jdoerfert
Reviewed By: DavidTruby, ichoyjx
Subscribers: mgorny, yaxunl, hiraditya, guansong, sstefan1, aaron.ballman, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D83326
2020-07-11 18:42:05 +02:00
|
|
|
// language. This code can be included in library.
|
2021-03-23 14:10:04 +01:00
|
|
|
void EmitDirectivesBasicImpl(const DirectiveLanguage &DirLang,
|
|
|
|
raw_ostream &OS) {
|
|
|
|
IfDefScope Scope("GEN_DIRECTIVES_IMPL", OS);
|
2020-07-11 02:11:11 +02:00
|
|
|
|
[openmp] Move Directive and Clause helper function to tablegen
Summary:
Follow up to D81736. Move getOpenMPDirectiveKind, getOpenMPClauseKind, getOpenMPDirectiveName and
getOpenMPClauseName to the new tablegen code generation. The code is generated in a new file named OMP.cpp.inc
Reviewers: jdoerfert, jdenny, thakis
Reviewed By: jdoerfert, jdenny
Subscribers: mgorny, yaxunl, hiraditya, guansong, sstefan1, llvm-commits, thakis
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D82405
2020-06-30 20:36:37 +02:00
|
|
|
// getDirectiveKind(StringRef Str)
|
2020-11-03 17:12:14 +01:00
|
|
|
GenerateGetKind(DirLang.getDirectives(), OS, "Directive", DirLang,
|
2020-07-29 02:45:21 +02:00
|
|
|
DirLang.getDirectivePrefix(), /*ImplicitAsUnknown=*/false);
|
[openmp] Move Directive and Clause helper function to tablegen
Summary:
Follow up to D81736. Move getOpenMPDirectiveKind, getOpenMPClauseKind, getOpenMPDirectiveName and
getOpenMPClauseName to the new tablegen code generation. The code is generated in a new file named OMP.cpp.inc
Reviewers: jdoerfert, jdenny, thakis
Reviewed By: jdoerfert, jdenny
Subscribers: mgorny, yaxunl, hiraditya, guansong, sstefan1, llvm-commits, thakis
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D82405
2020-06-30 20:36:37 +02:00
|
|
|
|
|
|
|
// getDirectiveName(Directive Kind)
|
2020-11-03 17:12:14 +01:00
|
|
|
GenerateGetName(DirLang.getDirectives(), OS, "Directive", DirLang,
|
2020-07-29 02:45:21 +02:00
|
|
|
DirLang.getDirectivePrefix());
|
[openmp] Move Directive and Clause helper function to tablegen
Summary:
Follow up to D81736. Move getOpenMPDirectiveKind, getOpenMPClauseKind, getOpenMPDirectiveName and
getOpenMPClauseName to the new tablegen code generation. The code is generated in a new file named OMP.cpp.inc
Reviewers: jdoerfert, jdenny, thakis
Reviewed By: jdoerfert, jdenny
Subscribers: mgorny, yaxunl, hiraditya, guansong, sstefan1, llvm-commits, thakis
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D82405
2020-06-30 20:36:37 +02:00
|
|
|
|
|
|
|
// getClauseKind(StringRef Str)
|
2020-11-03 17:12:14 +01:00
|
|
|
GenerateGetKind(DirLang.getClauses(), OS, "Clause", DirLang,
|
|
|
|
DirLang.getClausePrefix(),
|
2020-07-29 02:45:21 +02:00
|
|
|
/*ImplicitAsUnknown=*/true);
|
[openmp] Move Directive and Clause helper function to tablegen
Summary:
Follow up to D81736. Move getOpenMPDirectiveKind, getOpenMPClauseKind, getOpenMPDirectiveName and
getOpenMPClauseName to the new tablegen code generation. The code is generated in a new file named OMP.cpp.inc
Reviewers: jdoerfert, jdenny, thakis
Reviewed By: jdoerfert, jdenny
Subscribers: mgorny, yaxunl, hiraditya, guansong, sstefan1, llvm-commits, thakis
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D82405
2020-06-30 20:36:37 +02:00
|
|
|
|
|
|
|
// getClauseName(Clause Kind)
|
2020-11-03 17:12:14 +01:00
|
|
|
GenerateGetName(DirLang.getClauses(), OS, "Clause", DirLang,
|
|
|
|
DirLang.getClausePrefix());
|
2020-07-07 04:19:43 +02:00
|
|
|
|
2020-07-22 18:28:04 +02:00
|
|
|
// get<ClauseVal>Kind(StringRef Str)
|
2020-11-03 17:12:14 +01:00
|
|
|
GenerateGetKindClauseVal(DirLang, OS);
|
2020-07-22 18:28:04 +02:00
|
|
|
|
[flang][openmp] Check clauses allowed semantic with tablegen generated map
Summary:
This patch is enabling the generation of clauses enum sets for semantics check in Flang through
tablegen. Enum sets and directive - sets map is generated by the new tablegen infrsatructure for OpenMP
and other directive languages.
The semantic checks for OpenMP are modified to use this newly generated map.
Reviewers: DavidTruby, sscalpone, kiranchandramohan, ichoyjx, jdoerfert
Reviewed By: DavidTruby, ichoyjx
Subscribers: mgorny, yaxunl, hiraditya, guansong, sstefan1, aaron.ballman, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D83326
2020-07-11 18:42:05 +02:00
|
|
|
// isAllowedClauseForDirective(Directive D, Clause C, unsigned Version)
|
2020-11-03 17:12:14 +01:00
|
|
|
GenerateIsAllowedClause(DirLang, OS);
|
[openmp] Base of tablegen generated OpenMP common declaration
Summary:
As discussed previously when landing patch for OpenMP in Flang, the idea is
to share common part of the OpenMP declaration between the different Frontend.
While doing this it was thought that moving to tablegen instead of Macros will also
give a cleaner and more powerful way of generating these declaration.
This first part of a future series of patches is setting up the base .td file for
DirectiveLanguage as well as the OpenMP version of it. The base file is meant to
be used by other directive language such as OpenACC.
In this first patch, the Directive and Clause enums are generated with tablegen
instead of the macros on OMPConstants.h. The next pacth will extend this
to other enum and move the Flang frontend to use it.
Reviewers: jdoerfert, DavidTruby, fghanim, ABataev, jdenny, hfinkel, jhuber6, kiranchandramohan, kiranktp
Reviewed By: jdoerfert, jdenny
Subscribers: arphaman, martong, cfe-commits, mgorny, yaxunl, hiraditya, guansong, jfb, sstefan1, aaron.ballman, llvm-commits
Tags: #llvm, #openmp, #clang
Differential Revision: https://reviews.llvm.org/D81736
2020-06-23 15:29:50 +02:00
|
|
|
}
|
[openmp] Move Directive and Clause helper function to tablegen
Summary:
Follow up to D81736. Move getOpenMPDirectiveKind, getOpenMPClauseKind, getOpenMPDirectiveName and
getOpenMPClauseName to the new tablegen code generation. The code is generated in a new file named OMP.cpp.inc
Reviewers: jdoerfert, jdenny, thakis
Reviewed By: jdoerfert, jdenny
Subscribers: mgorny, yaxunl, hiraditya, guansong, sstefan1, llvm-commits, thakis
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D82405
2020-06-30 20:36:37 +02:00
|
|
|
|
2021-03-23 14:10:04 +01:00
|
|
|
// Generate the implemenation section for the enumeration in the directive
|
|
|
|
// language.
|
|
|
|
void EmitDirectivesImpl(RecordKeeper &Records, raw_ostream &OS) {
|
|
|
|
const auto DirLang = DirectiveLanguage{Records};
|
|
|
|
if (DirLang.HasValidityErrors())
|
|
|
|
return;
|
|
|
|
|
|
|
|
EmitDirectivesFlangImpl(DirLang, OS);
|
|
|
|
|
|
|
|
GenerateClauseClassMacro(DirLang, OS);
|
|
|
|
|
|
|
|
EmitDirectivesBasicImpl(DirLang, OS);
|
|
|
|
}
|
|
|
|
|
[openmp] Base of tablegen generated OpenMP common declaration
Summary:
As discussed previously when landing patch for OpenMP in Flang, the idea is
to share common part of the OpenMP declaration between the different Frontend.
While doing this it was thought that moving to tablegen instead of Macros will also
give a cleaner and more powerful way of generating these declaration.
This first part of a future series of patches is setting up the base .td file for
DirectiveLanguage as well as the OpenMP version of it. The base file is meant to
be used by other directive language such as OpenACC.
In this first patch, the Directive and Clause enums are generated with tablegen
instead of the macros on OMPConstants.h. The next pacth will extend this
to other enum and move the Flang frontend to use it.
Reviewers: jdoerfert, DavidTruby, fghanim, ABataev, jdenny, hfinkel, jhuber6, kiranchandramohan, kiranktp
Reviewed By: jdoerfert, jdenny
Subscribers: arphaman, martong, cfe-commits, mgorny, yaxunl, hiraditya, guansong, jfb, sstefan1, aaron.ballman, llvm-commits
Tags: #llvm, #openmp, #clang
Differential Revision: https://reviews.llvm.org/D81736
2020-06-23 15:29:50 +02:00
|
|
|
} // namespace llvm
|