[PATCH] D126731: [pseudo] Eliminate dependencies from clang-pseudo-gen. NFC
Sam McCall via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue May 31 16:02:58 PDT 2022
sammccall created this revision.
sammccall added a reviewer: hokein.
Herald added a subscriber: mgorny.
Herald added a project: All.
sammccall requested review of this revision.
Herald added subscribers: cfe-commits, alextsao1999.
Herald added a project: clang-tools-extra.
ClangBasic dependency eliminated by replacing our usage of
tok::getPunctuatorSpelling etc with direct use of the *.def file.
Implicit dependencies on clang-tablegen-targets removed as we manage to avoid
any transitive tablegen deps.
After these changes, `ninja clean; ninja pseudo-gen` runs 169 actions only
(basically Support and Demangle).
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D126731
Files:
clang-tools-extra/pseudo/gen/CMakeLists.txt
clang-tools-extra/pseudo/lib/grammar/CMakeLists.txt
clang-tools-extra/pseudo/lib/grammar/Grammar.cpp
Index: clang-tools-extra/pseudo/lib/grammar/Grammar.cpp
===================================================================
--- clang-tools-extra/pseudo/lib/grammar/Grammar.cpp
+++ clang-tools-extra/pseudo/lib/grammar/Grammar.cpp
@@ -167,19 +167,16 @@
}
static llvm::ArrayRef<std::string> getTerminalNames() {
- static const std::vector<std::string> *TerminalNames = []() {
- static std::vector<std::string> TerminalNames;
- TerminalNames.reserve(NumTerminals);
- for (unsigned I = 0; I < NumTerminals; ++I) {
- tok::TokenKind K = static_cast<tok::TokenKind>(I);
- if (const auto *Punc = tok::getPunctuatorSpelling(K))
- TerminalNames.push_back(Punc);
- else
- TerminalNames.push_back(llvm::StringRef(tok::getTokenName(K)).upper());
- }
- return &TerminalNames;
+ static const auto &TerminalNames = []() {
+ auto &TerminalNames = *new std::array<std::string, NumTerminals>;
+#define PUNCTUATOR(Tok, Spelling) TerminalNames[tok::Tok] = Spelling;
+#define KEYWORD(Keyword, Condition) \
+ TerminalNames[tok::kw_##Keyword] = llvm::StringRef(#Keyword).upper();
+#define TOK(Tok) TerminalNames[tok::Tok] = llvm::StringRef(#Tok).upper();
+#include "clang/Basic/TokenKinds.def"
+ return TerminalNames;
}();
- return *TerminalNames;
+ return TerminalNames;
}
GrammarTable::GrammarTable() : Terminals(getTerminalNames()) {}
Index: clang-tools-extra/pseudo/lib/grammar/CMakeLists.txt
===================================================================
--- clang-tools-extra/pseudo/lib/grammar/CMakeLists.txt
+++ clang-tools-extra/pseudo/lib/grammar/CMakeLists.txt
@@ -1,18 +1,15 @@
set(LLVM_LINK_COMPONENTS Support)
-# This library intents to keep as minimal dependencies as possible, it is a base
-# library of the cxx generator, to avoid creating long dep paths in the build
-# graph.
+# This library is used by the clang-pseudo-gen tool which runs at build time.
+# Dependencies should be minimal to avoid long dep paths in the build graph.
+# It does use clangBasic headers (tok::TokenKind), but linking is not needed.
+# We have no transitive dependencies on tablegen files.
+list(REMOVE_ITEM LLVM_COMMON_DEPENDS clang-tablegen-targets)
add_clang_library(clangPseudoGrammar
Grammar.cpp
GrammarBNF.cpp
LRGraph.cpp
LRTable.cpp
LRTableBuild.cpp
-
- # FIXME: can we get rid of the clangBasic dependency? We need it for the
- # clang::tok::getTokenName and clang::tok::getPunctuatorSpelling functions, we
- # could consider remimplement these functions.
- LINK_LIBS
- clangBasic
)
+
Index: clang-tools-extra/pseudo/gen/CMakeLists.txt
===================================================================
--- clang-tools-extra/pseudo/gen/CMakeLists.txt
+++ clang-tools-extra/pseudo/gen/CMakeLists.txt
@@ -1,4 +1,5 @@
set(LLVM_LINK_COMPONENTS Support)
+list(REMOVE_ITEM LLVM_COMMON_DEPENDS clang-tablegen-targets)
add_clang_executable(pseudo-gen
Main.cpp
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D126731.433219.patch
Type: text/x-patch
Size: 2983 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220531/be246f5e/attachment.bin>
More information about the cfe-commits
mailing list