13#include "llvm/ADT/STLExtras.h"
14#include "llvm/ADT/SmallVector.h"
15#include "llvm/ADT/StringExtras.h"
16#include "llvm/ADT/StringRef.h"
17#include "llvm/Support/FileSystem.h"
18#include "llvm/Support/ManagedStatic.h"
19#include "llvm/Support/raw_ostream.h"
27 std::vector<UnsignedEPStat *> ExplicitlySetStats;
28 std::vector<UnsignedMaxEPStat *> MaxStats;
29 std::vector<CounterEPStat *> CounterStats;
31 bool IsLocked =
false;
34 const Decl *EntryPoint;
37 std::vector<std::optional<unsigned>> ExplicitlySetStatValues;
41 std::vector<unsigned> MaxOrCountStatValues;
43 void dumpAsCSV(llvm::raw_ostream &
OS)
const;
46 std::vector<Snapshot> Snapshots;
47 std::string EscapedCPPFileName;
54template <
typename Callback>
void enumerateStatVectors(
const Callback &Fn) {
63void clearSnapshots(
void *) {
StatsRegistry->Snapshots.clear(); }
71 constexpr std::array AllowedSpecialChars = {
72 '+',
'-',
'_',
'=',
':',
'(',
')',
'@',
'!',
'~',
73 '$',
'%',
'^',
'&',
'*',
'\'',
';',
'<',
'>',
'/'};
74 for (
unsigned char C : M->
name()) {
75 if (!std::isalnum(
C) && !llvm::is_contained(AllowedSpecialChars,
C)) {
76 llvm::errs() <<
"Stat name \"" << M->
name() <<
"\" contains character '"
77 <<
C <<
"' (" <<
static_cast<int>(
C)
78 <<
") that is not allowed.";
79 assert(
false &&
"The Stat name contains unallowed character");
87 return L->
name() < R->name();
90 [CmpByNames](
auto &Stats) { llvm::sort(Stats, CmpByNames); });
92 [](
const auto &Stats) { llvm::for_each(Stats,
checkStatName); });
95 llvm::printEscapedString(CPPFileName,
OS);
103 auto ByName = [Name](
const EntryPointStat *M) {
return M->name() == Name; };
105 enumerateStatVectors([ByName, &Result](
const auto &Stats) {
106 Result = Result || llvm::any_of(Stats, ByName);
118 : EntryPointStat(Name) {
125 : EntryPointStat(Name) {
132 std::vector<std::optional<unsigned>> Result;
135 Result.push_back(M->value());
142 std::vector<unsigned> Result;
147 Result.push_back(M->value());
151 Result.push_back(M->value());
158 std::vector<llvm::StringLiteral> Ret;
160 enumerateStatVectors([GetName, &Ret](
const auto &Stats) {
161 transform(Stats, std::back_inserter(Ret), GetName);
169 assert(
false &&
"This should never fail");
172 return llvm::toStringRef(Buf).str();
175void Registry::Snapshot::dumpAsCSV(llvm::raw_ostream &
OS)
const {
176 auto PrintAsUnsignOpt = [&
OS](std::optional<unsigned> U) {
177 OS << (U.has_value() ? std::to_string(*U) :
"");
179 auto CommaIfNeeded = [&
OS](
const auto &Vec1,
const auto &Vec2) {
180 if (!Vec1.empty() && !Vec2.empty())
183 auto PrintAsUnsigned = [&
OS](
unsigned U) {
OS << U; };
186 llvm::printEscapedString(
getUSR(EntryPoint),
OS);
189 llvm::printEscapedString(
192 llvm::interleave(ExplicitlySetStatValues,
OS, PrintAsUnsignOpt,
",");
193 CommaIfNeeded(ExplicitlySetStatValues, MaxOrCountStatValues);
194 llvm::interleave(MaxOrCountStatValues,
OS, PrintAsUnsigned,
",");
201 std::move(ExplicitlySetValues),
202 std::move(MaxOrCounterValues)});
207 llvm::raw_fd_ostream
File(
FileName, EC, llvm::sys::fs::OF_Text);
214 OS <<
"USR,File,DebugName,";
218 std::vector<std::string> Rows;
222 llvm::raw_string_ostream RowOs(Row);
223 Snapshot.dumpAsCSV(RowOs);
225 Rows.push_back(RowOs.str());
228 for (
const auto &Row : Rows) {
This file defines AnalysisDeclContext, a class that manages the analysis context data for context sen...
static void checkStatName(const EntryPointStat *M)
static llvm::ManagedStatic< Registry > StatsRegistry
static std::vector< unsigned > consumeMaxAndCounterStats()
static std::vector< llvm::StringLiteral > getStatNames()
static bool isRegistered(llvm::StringLiteral Name)
static std::vector< std::optional< unsigned > > consumeExplicitlySetStats()
static std::string getUSR(const Decl *D)
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
void AddDeallocation(void(*Callback)(void *), void *Data) const
Add a deallocation callback that will be invoked when the ASTContext is destroyed.
static std::string getFunctionName(const Decl *D)
Decl - This represents one declaration (or definition), e.g.
CounterEPStat(llvm::StringLiteral Name)
static void dumpStatsAsCSV(llvm::raw_ostream &OS)
static void lockRegistry(llvm::StringRef CPPFileName, ASTContext &Ctx)
static void takeSnapshot(const Decl *EntryPoint)
llvm::StringLiteral name() const
EntryPointStat(llvm::StringLiteral Name)
UnsignedEPStat(llvm::StringLiteral Name)
UnsignedMaxEPStat(llvm::StringLiteral Name)
@ OS
Indicates that the tracking object is a descendant of a referenced-counted OSObject,...
bool generateUSRForDecl(const Decl *D, SmallVectorImpl< char > &Buf)
Generate a USR for a Decl, including the USR prefix.
std::variant< struct RequiresDecl, struct HeaderDecl, struct UmbrellaDirDecl, struct ModuleDecl, struct ExcludeDecl, struct ExportDecl, struct ExportAsDecl, struct ExternModuleDecl, struct UseDecl, struct LinkDecl, struct ConfigMacrosDecl, struct ConflictDecl > Decl
All declarations that can appear in a module declaration.
The JSON file list parser is used to communicate input to InstallAPI.