[llvm] c1bd1ee - Rework "llvm-tblgen: Anonymize some functions.", llvmorg-17-init-2668-gc45e90cf152d
NAKAMURA Takumi via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 20 06:23:24 PST 2023
Author: NAKAMURA Takumi
Date: 2023-02-20T23:20:43+09:00
New Revision: c1bd1eed8e995ccdbf8c1dec0b0d26e48dee27b1
URL: https://github.com/llvm/llvm-project/commit/c1bd1eed8e995ccdbf8c1dec0b0d26e48dee27b1
DIFF: https://github.com/llvm/llvm-project/commit/c1bd1eed8e995ccdbf8c1dec0b0d26e48dee27b1.diff
LOG: Rework "llvm-tblgen: Anonymize some functions.", llvmorg-17-init-2668-gc45e90cf152d
Anonymous namespace should be applied only to class definitions.
Added:
Modified:
llvm/utils/TableGen/DirectiveEmitter.cpp
llvm/utils/TableGen/InstrDocsEmitter.cpp
Removed:
################################################################################
diff --git a/llvm/utils/TableGen/DirectiveEmitter.cpp b/llvm/utils/TableGen/DirectiveEmitter.cpp
index d4ef9f577b2c2..a65c71690b097 100644
--- a/llvm/utils/TableGen/DirectiveEmitter.cpp
+++ b/llvm/utils/TableGen/DirectiveEmitter.cpp
@@ -37,11 +37,12 @@ class IfDefScope {
StringRef Name;
raw_ostream &OS;
};
+} // namespace
// Generate enum class
-void GenerateEnumClass(const std::vector<Record *> &Records, raw_ostream &OS,
- StringRef Enum, StringRef Prefix,
- const DirectiveLanguage &DirLang) {
+static void GenerateEnumClass(const std::vector<Record *> &Records,
+ raw_ostream &OS, StringRef Enum, StringRef Prefix,
+ const DirectiveLanguage &DirLang) {
OS << "\n";
OS << "enum class " << Enum << " {\n";
for (const auto &R : Records) {
@@ -71,9 +72,10 @@ void GenerateEnumClass(const std::vector<Record *> &Records, raw_ostream &OS,
// 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,
- raw_ostream &OS, const DirectiveLanguage &DirLang,
- std::string &EnumHelperFuncs) {
+static void GenerateEnumClauseVal(const std::vector<Record *> &Records,
+ raw_ostream &OS,
+ const DirectiveLanguage &DirLang,
+ std::string &EnumHelperFuncs) {
for (const auto &R : Records) {
Clause C{R};
const auto &ClauseVals = C.getClauseVals();
@@ -115,9 +117,9 @@ void GenerateEnumClauseVal(const std::vector<Record *> &Records,
}
}
-bool HasDuplicateClauses(const std::vector<Record *> &Clauses,
- const Directive &Directive,
- llvm::StringSet<> &CrtClauses) {
+static bool HasDuplicateClauses(const std::vector<Record *> &Clauses,
+ const Directive &Directive,
+ llvm::StringSet<> &CrtClauses) {
bool HasError = false;
for (const auto &C : Clauses) {
VersionedClause VerClause{C};
@@ -134,7 +136,8 @@ bool HasDuplicateClauses(const std::vector<Record *> &Clauses,
// 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.
-bool HasDuplicateClausesInDirectives(const std::vector<Record *> &Directives) {
+static bool
+HasDuplicateClausesInDirectives(const std::vector<Record *> &Directives) {
bool HasDuplicate = false;
for (const auto &D : Directives) {
Directive Dir{D};
@@ -160,8 +163,6 @@ bool HasDuplicateClausesInDirectives(const std::vector<Record *> &Directives) {
return HasDuplicate;
}
-} // namespace
-
// Check consitency of records. Return true if an error has been detected.
// Return false if the records are valid.
bool DirectiveLanguage::HasValidityErrors() const {
@@ -248,12 +249,11 @@ void EmitDirectivesDecl(RecordKeeper &Records, raw_ostream &OS) {
} // namespace llvm
-namespace {
-
// Generate function implementation for get<Enum>Name(StringRef Str)
-void GenerateGetName(const std::vector<Record *> &Records, raw_ostream &OS,
- StringRef Enum, const DirectiveLanguage &DirLang,
- StringRef Prefix) {
+static void GenerateGetName(const std::vector<Record *> &Records,
+ raw_ostream &OS, StringRef Enum,
+ const DirectiveLanguage &DirLang,
+ StringRef Prefix) {
OS << "\n";
OS << "llvm::StringRef llvm::" << DirLang.getCppNamespace() << "::get"
<< DirLang.getName() << Enum << "Name(" << Enum << " Kind) {\n";
@@ -275,9 +275,10 @@ void GenerateGetName(const std::vector<Record *> &Records, raw_ostream &OS,
}
// Generate function implementation for get<Enum>Kind(StringRef Str)
-void GenerateGetKind(const std::vector<Record *> &Records, raw_ostream &OS,
- StringRef Enum, const DirectiveLanguage &DirLang,
- StringRef Prefix, bool ImplicitAsUnknown) {
+static void GenerateGetKind(const std::vector<Record *> &Records,
+ raw_ostream &OS, StringRef Enum,
+ const DirectiveLanguage &DirLang, StringRef Prefix,
+ bool ImplicitAsUnknown) {
auto DefaultIt = llvm::find_if(
Records, [](Record *R) { return R->getValueAsBit("isDefault") == true; });
@@ -309,8 +310,8 @@ void GenerateGetKind(const std::vector<Record *> &Records, raw_ostream &OS,
}
// Generate function implementation for get<ClauseVal>Kind(StringRef Str)
-void GenerateGetKindClauseVal(const DirectiveLanguage &DirLang,
- raw_ostream &OS) {
+static void GenerateGetKindClauseVal(const DirectiveLanguage &DirLang,
+ raw_ostream &OS) {
for (const auto &R : DirLang.getClauses()) {
Clause C{R};
const auto &ClauseVals = C.getClauseVals();
@@ -365,10 +366,11 @@ void GenerateGetKindClauseVal(const DirectiveLanguage &DirLang,
}
}
-void GenerateCaseForVersionedClauses(const std::vector<Record *> &Clauses,
- raw_ostream &OS, StringRef DirectiveName,
- const DirectiveLanguage &DirLang,
- llvm::StringSet<> &Cases) {
+static void
+GenerateCaseForVersionedClauses(const std::vector<Record *> &Clauses,
+ raw_ostream &OS, StringRef DirectiveName,
+ const DirectiveLanguage &DirLang,
+ llvm::StringSet<> &Cases) {
for (const auto &C : Clauses) {
VersionedClause VerClause{C};
@@ -384,8 +386,8 @@ void GenerateCaseForVersionedClauses(const std::vector<Record *> &Clauses,
}
// Generate the isAllowedClauseForDirective function implementation.
-void GenerateIsAllowedClause(const DirectiveLanguage &DirLang,
- raw_ostream &OS) {
+static void GenerateIsAllowedClause(const DirectiveLanguage &DirLang,
+ raw_ostream &OS) {
OS << "\n";
OS << "bool llvm::" << DirLang.getCppNamespace()
<< "::isAllowedClauseForDirective("
@@ -438,9 +440,10 @@ void GenerateIsAllowedClause(const DirectiveLanguage &DirLang,
}
// Generate a simple enum set with the give clauses.
-void GenerateClauseSet(const std::vector<Record *> &Clauses, raw_ostream &OS,
- StringRef ClauseSetPrefix, Directive &Dir,
- const DirectiveLanguage &DirLang) {
+static void GenerateClauseSet(const std::vector<Record *> &Clauses,
+ raw_ostream &OS, StringRef ClauseSetPrefix,
+ Directive &Dir,
+ const DirectiveLanguage &DirLang) {
OS << "\n";
OS << " static " << DirLang.getClauseEnumSetClass() << " " << ClauseSetPrefix
@@ -456,8 +459,8 @@ void GenerateClauseSet(const std::vector<Record *> &Clauses, raw_ostream &OS,
}
// Generate an enum set for the 4 kinds of clauses linked to a directive.
-void GenerateDirectiveClauseSets(const DirectiveLanguage &DirLang,
- raw_ostream &OS) {
+static void GenerateDirectiveClauseSets(const DirectiveLanguage &DirLang,
+ raw_ostream &OS) {
IfDefScope Scope("GEN_FLANG_DIRECTIVE_CLAUSE_SETS", OS);
@@ -496,8 +499,8 @@ void GenerateDirectiveClauseSets(const DirectiveLanguage &DirLang,
// 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).
-void GenerateDirectiveClauseMap(const DirectiveLanguage &DirLang,
- raw_ostream &OS) {
+static void GenerateDirectiveClauseMap(const DirectiveLanguage &DirLang,
+ raw_ostream &OS) {
IfDefScope Scope("GEN_FLANG_DIRECTIVE_CLAUSE_MAP", OS);
@@ -531,8 +534,8 @@ void GenerateDirectiveClauseMap(const DirectiveLanguage &DirLang,
// 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.
-void GenerateFlangClauseParserClass(const DirectiveLanguage &DirLang,
- raw_ostream &OS) {
+static void GenerateFlangClauseParserClass(const DirectiveLanguage &DirLang,
+ raw_ostream &OS) {
IfDefScope Scope("GEN_FLANG_CLAUSE_PARSER_CLASSES", OS);
@@ -559,8 +562,8 @@ void GenerateFlangClauseParserClass(const DirectiveLanguage &DirLang,
}
// Generate a list of the
diff erent clause classes for Flang.
-void GenerateFlangClauseParserClassList(const DirectiveLanguage &DirLang,
- raw_ostream &OS) {
+static void GenerateFlangClauseParserClassList(const DirectiveLanguage &DirLang,
+ raw_ostream &OS) {
IfDefScope Scope("GEN_FLANG_CLAUSE_PARSER_CLASSES_LIST", OS);
@@ -572,8 +575,8 @@ void GenerateFlangClauseParserClassList(const DirectiveLanguage &DirLang,
}
// Generate dump node list for the clauses holding a generic class name.
-void GenerateFlangClauseDump(const DirectiveLanguage &DirLang,
- raw_ostream &OS) {
+static void GenerateFlangClauseDump(const DirectiveLanguage &DirLang,
+ raw_ostream &OS) {
IfDefScope Scope("GEN_FLANG_DUMP_PARSE_TREE_CLAUSES", OS);
@@ -587,8 +590,8 @@ void GenerateFlangClauseDump(const DirectiveLanguage &DirLang,
// Generate Unparse functions for clauses classes in the Flang parse-tree
// If the clause is a non-generic class, no entry is generated.
-void GenerateFlangClauseUnparse(const DirectiveLanguage &DirLang,
- raw_ostream &OS) {
+static void GenerateFlangClauseUnparse(const DirectiveLanguage &DirLang,
+ raw_ostream &OS) {
IfDefScope Scope("GEN_FLANG_CLAUSE_UNPARSE", OS);
@@ -639,8 +642,8 @@ void GenerateFlangClauseUnparse(const DirectiveLanguage &DirLang,
}
// Generate check in the Enter functions for clauses classes.
-void GenerateFlangClauseCheckPrototypes(const DirectiveLanguage &DirLang,
- raw_ostream &OS) {
+static void GenerateFlangClauseCheckPrototypes(const DirectiveLanguage &DirLang,
+ raw_ostream &OS) {
IfDefScope Scope("GEN_FLANG_CLAUSE_CHECK_ENTER", OS);
@@ -654,8 +657,8 @@ void GenerateFlangClauseCheckPrototypes(const DirectiveLanguage &DirLang,
// Generate the mapping for clauses between the parser class and the
// corresponding clause Kind
-void GenerateFlangClauseParserKindMap(const DirectiveLanguage &DirLang,
- raw_ostream &OS) {
+static void GenerateFlangClauseParserKindMap(const DirectiveLanguage &DirLang,
+ raw_ostream &OS) {
IfDefScope Scope("GEN_FLANG_CLAUSE_PARSER_KIND_MAP", OS);
@@ -675,15 +678,15 @@ void GenerateFlangClauseParserKindMap(const DirectiveLanguage &DirLang,
<< " Parser clause\");\n";
}
-bool compareClauseName(Record *R1, Record *R2) {
+static bool compareClauseName(Record *R1, Record *R2) {
Clause C1{R1};
Clause C2{R2};
return (C1.getName() > C2.getName());
}
// Generate the parser for the clauses.
-void GenerateFlangClausesParser(const DirectiveLanguage &DirLang,
- raw_ostream &OS) {
+static void GenerateFlangClausesParser(const DirectiveLanguage &DirLang,
+ raw_ostream &OS) {
std::vector<Record *> Clauses = DirLang.getClauses();
// Sort clauses in reverse alphabetical order so with clauses with same
// beginning, the longer option is tried before.
@@ -756,8 +759,8 @@ void GenerateFlangClausesParser(const DirectiveLanguage &DirLang,
// Generate the implementation section for the enumeration in the directive
// language
-void EmitDirectivesFlangImpl(const DirectiveLanguage &DirLang,
- raw_ostream &OS) {
+static void EmitDirectivesFlangImpl(const DirectiveLanguage &DirLang,
+ raw_ostream &OS) {
GenerateDirectiveClauseSets(DirLang, OS);
@@ -778,8 +781,8 @@ void EmitDirectivesFlangImpl(const DirectiveLanguage &DirLang,
GenerateFlangClausesParser(DirLang, OS);
}
-void GenerateClauseClassMacro(const DirectiveLanguage &DirLang,
- raw_ostream &OS) {
+static void GenerateClauseClassMacro(const DirectiveLanguage &DirLang,
+ raw_ostream &OS) {
// Generate macros style information for legacy code in clang
IfDefScope Scope("GEN_CLANG_CLAUSE_CLASS", OS);
@@ -874,8 +877,6 @@ void EmitDirectivesBasicImpl(const DirectiveLanguage &DirLang,
GenerateIsAllowedClause(DirLang, OS);
}
-} // namespace
-
namespace llvm {
// Generate the implemenation section for the enumeration in the directive
diff --git a/llvm/utils/TableGen/InstrDocsEmitter.cpp b/llvm/utils/TableGen/InstrDocsEmitter.cpp
index ca39927664de1..7476422025fd9 100644
--- a/llvm/utils/TableGen/InstrDocsEmitter.cpp
+++ b/llvm/utils/TableGen/InstrDocsEmitter.cpp
@@ -28,18 +28,17 @@
using namespace llvm;
-namespace {
-
-void writeTitle(StringRef Str, raw_ostream &OS, char Kind = '-') {
- OS << std::string(Str.size(), Kind) << "\n" << Str << "\n"
+static void writeTitle(StringRef Str, raw_ostream &OS, char Kind = '-') {
+ OS << std::string(Str.size(), Kind) << "\n"
+ << Str << "\n"
<< std::string(Str.size(), Kind) << "\n";
}
-void writeHeader(StringRef Str, raw_ostream &OS, char Kind = '-') {
+static void writeHeader(StringRef Str, raw_ostream &OS, char Kind = '-') {
OS << Str << "\n" << std::string(Str.size(), Kind) << "\n";
}
-std::string escapeForRST(StringRef Str) {
+static std::string escapeForRST(StringRef Str) {
std::string Result;
Result.reserve(Str.size() + 4);
for (char C : Str) {
@@ -55,8 +54,6 @@ std::string escapeForRST(StringRef Str) {
return Result;
}
-} // namespace
-
namespace llvm {
void EmitInstrDocs(RecordKeeper &RK, raw_ostream &OS) {
More information about the llvm-commits
mailing list