003 File Manager
Current Path:
/usr/src/contrib/llvm-project/llvm/lib/Support
usr
/
src
/
contrib
/
llvm-project
/
llvm
/
lib
/
Support
/
📁
..
📄
AArch64TargetParser.cpp
(8 KB)
📄
ABIBreak.cpp
(811 B)
📄
AMDGPUMetadata.cpp
(9.37 KB)
📄
APFloat.cpp
(155.26 KB)
📄
APInt.cpp
(98.08 KB)
📄
APSInt.cpp
(1.44 KB)
📄
ARMAttributeParser.cpp
(13.94 KB)
📄
ARMBuildAttrs.cpp
(3.45 KB)
📄
ARMTargetParser.cpp
(18.09 KB)
📄
ARMWinEH.cpp
(1.08 KB)
📄
Allocator.cpp
(1.35 KB)
📄
Atomic.cpp
(1.6 KB)
📄
BinaryStreamError.cpp
(1.76 KB)
📄
BinaryStreamReader.cpp
(5.24 KB)
📄
BinaryStreamRef.cpp
(4.76 KB)
📄
BinaryStreamWriter.cpp
(3.36 KB)
📄
BlockFrequency.cpp
(2.12 KB)
📄
BranchProbability.cpp
(3.44 KB)
📄
BuryPointer.cpp
(1.11 KB)
📄
COM.cpp
(737 B)
📄
COPYRIGHT.regex
(2.65 KB)
📄
CRC.cpp
(5.23 KB)
📄
CachePruning.cpp
(10.33 KB)
📄
Chrono.cpp
(3.17 KB)
📄
CodeGenCoverage.cpp
(3.61 KB)
📄
CommandLine.cpp
(89.06 KB)
📄
Compression.cpp
(3.84 KB)
📄
ConvertUTF.cpp
(27.27 KB)
📄
ConvertUTFWrapper.cpp
(8.66 KB)
📄
CrashRecoveryContext.cpp
(15.45 KB)
📄
DAGDeltaAlgorithm.cpp
(12.47 KB)
📄
DJB.cpp
(2.71 KB)
📄
DataExtractor.cpp
(7.25 KB)
📄
Debug.cpp
(5.64 KB)
📄
DebugCounter.cpp
(4.95 KB)
📄
DeltaAlgorithm.cpp
(3.41 KB)
📄
DynamicLibrary.cpp
(6.25 KB)
📄
ELFAttributeParser.cpp
(7.27 KB)
📄
ELFAttributes.cpp
(1.27 KB)
📄
Errno.cpp
(2.18 KB)
📄
Error.cpp
(4.72 KB)
📄
ErrorHandling.cpp
(11.08 KB)
📄
ExtensibleRTTI.cpp
(446 B)
📄
FileCheck.cpp
(95.77 KB)
📄
FileCheckImpl.h
(34.14 KB)
📄
FileCollector.cpp
(9.01 KB)
📄
FileOutputBuffer.cpp
(6.62 KB)
📄
FileUtilities.cpp
(10.81 KB)
📄
FoldingSet.cpp
(15.89 KB)
📄
FormatVariadic.cpp
(5.17 KB)
📄
FormattedStream.cpp
(5.29 KB)
📄
GlobPattern.cpp
(5 KB)
📄
GraphWriter.cpp
(9.21 KB)
📄
Hashing.cpp
(1.16 KB)
📄
Host.cpp
(51.63 KB)
📄
InitLLVM.cpp
(1.92 KB)
📄
IntEqClasses.cpp
(2.18 KB)
📄
IntervalMap.cpp
(4.4 KB)
📄
ItaniumManglingCanonicalizer.cpp
(10.77 KB)
📄
JSON.cpp
(19.1 KB)
📄
KnownBits.cpp
(3.78 KB)
📄
LEB128.cpp
(1.19 KB)
📄
LineIterator.cpp
(2.61 KB)
📄
Locale.cpp
(377 B)
📄
LockFileManager.cpp
(10.64 KB)
📄
LowLevelType.cpp
(2.09 KB)
📄
MD5.cpp
(8.99 KB)
📄
ManagedStatic.cpp
(2.37 KB)
📄
MathExtras.cpp
(913 B)
📄
MemAlloc.cpp
(1.01 KB)
📄
Memory.cpp
(1.57 KB)
📄
MemoryBuffer.cpp
(18.99 KB)
📄
NativeFormatting.cpp
(7.54 KB)
📄
OptimizedStructLayout.cpp
(16.7 KB)
📄
Optional.cpp
(530 B)
📄
Parallel.cpp
(5.08 KB)
📄
Path.cpp
(36.52 KB)
📄
PluginLoader.cpp
(1.63 KB)
📄
PrettyStackTrace.cpp
(10.33 KB)
📄
Process.cpp
(3.27 KB)
📄
Program.cpp
(3.54 KB)
📄
RISCVAttributeParser.cpp
(2.06 KB)
📄
RISCVAttributes.cpp
(970 B)
📄
RWMutex.cpp
(3.23 KB)
📄
RandomNumberGenerator.cpp
(2.86 KB)
📄
Regex.cpp
(6.38 KB)
📄
SHA1.cpp
(10.43 KB)
📄
ScaledNumber.cpp
(9.09 KB)
📄
ScopedPrinter.cpp
(1.19 KB)
📄
Signals.cpp
(8.35 KB)
📄
Signposts.cpp
(3.24 KB)
📄
SmallPtrSet.cpp
(9.21 KB)
📄
SmallVector.cpp
(3.99 KB)
📄
SourceMgr.cpp
(20.08 KB)
📄
SpecialCaseList.cpp
(7.48 KB)
📄
Statistic.cpp
(8.85 KB)
📄
StringExtras.cpp
(4.34 KB)
📄
StringMap.cpp
(9.31 KB)
📄
StringRef.cpp
(17.41 KB)
📄
StringSaver.cpp
(882 B)
📄
SuffixTree.cpp
(7.23 KB)
📄
SymbolRemappingReader.cpp
(2.94 KB)
📄
SystemUtils.cpp
(1.06 KB)
📄
TarWriter.cpp
(7.23 KB)
📄
TargetParser.cpp
(9.86 KB)
📄
TargetRegistry.cpp
(4.6 KB)
📄
ThreadLocal.cpp
(1.68 KB)
📄
ThreadPool.cpp
(4.4 KB)
📄
Threading.cpp
(4.55 KB)
📄
TimeProfiler.cpp
(11.63 KB)
📄
Timer.cpp
(14.14 KB)
📄
ToolOutputFile.cpp
(1.83 KB)
📄
TrigramIndex.cpp
(3.24 KB)
📄
Triple.cpp
(53.17 KB)
📄
Twine.cpp
(4.6 KB)
📄
Unicode.cpp
(20.14 KB)
📄
UnicodeCaseFold.cpp
(15.32 KB)
📁
Unix
📄
Valgrind.cpp
(1.6 KB)
📄
VersionTuple.cpp
(2.74 KB)
📄
VirtualFileSystem.cpp
(74.17 KB)
📄
Watchdog.cpp
(738 B)
📁
Windows
📄
WithColor.cpp
(4.35 KB)
📄
X86TargetParser.cpp
(27.21 KB)
📄
YAMLParser.cpp
(68.53 KB)
📄
YAMLTraits.cpp
(28.37 KB)
📄
Z3Solver.cpp
(31.44 KB)
📄
circular_raw_ostream.cpp
(1.3 KB)
📄
raw_os_ostream.cpp
(995 B)
📄
raw_ostream.cpp
(28.97 KB)
📄
regcomp.c
(39.42 KB)
📄
regengine.inc
(26.49 KB)
📄
regerror.c
(4.42 KB)
📄
regex2.h
(6.82 KB)
📄
regex_impl.h
(3.63 KB)
📄
regexec.c
(5.71 KB)
📄
regfree.c
(2.49 KB)
📄
regstrlcpy.c
(1.56 KB)
📄
regutils.h
(2.25 KB)
📄
xxhash.cpp
(4.07 KB)
Editing: Statistic.cpp
//===-- Statistic.cpp - Easy way to expose stats information --------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // // This file implements the 'Statistic' class, which is designed to be an easy // way to expose various success metrics from passes. These statistics are // printed at the end of a run, when the -stats command line option is enabled // on the command line. // // This is useful for reporting information like the number of instructions // simplified, optimized or removed by various transformations, like this: // // static Statistic NumInstEliminated("GCSE", "Number of instructions killed"); // // Later, in the code: ++NumInstEliminated; // //===----------------------------------------------------------------------===// #include "llvm/ADT/Statistic.h" #include "llvm/ADT/StringExtras.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/Compiler.h" #include "llvm/Support/Debug.h" #include "llvm/Support/Format.h" #include "llvm/Support/ManagedStatic.h" #include "llvm/Support/Mutex.h" #include "llvm/Support/Timer.h" #include "llvm/Support/YAMLTraits.h" #include "llvm/Support/raw_ostream.h" #include <algorithm> #include <cstring> using namespace llvm; /// -stats - Command line option to cause transformations to emit stats about /// what they did. /// static cl::opt<bool> EnableStats( "stats", cl::desc("Enable statistics output from program (available with Asserts)"), cl::Hidden); static cl::opt<bool> StatsAsJSON("stats-json", cl::desc("Display statistics as json data"), cl::Hidden); static bool Enabled; static bool PrintOnExit; namespace { /// This class is used in a ManagedStatic so that it is created on demand (when /// the first statistic is bumped) and destroyed only when llvm_shutdown is /// called. We print statistics from the destructor. /// This class is also used to look up statistic values from applications that /// use LLVM. class StatisticInfo { std::vector<TrackingStatistic *> Stats; friend void llvm::PrintStatistics(); friend void llvm::PrintStatistics(raw_ostream &OS); friend void llvm::PrintStatisticsJSON(raw_ostream &OS); /// Sort statistics by debugtype,name,description. void sort(); public: using const_iterator = std::vector<TrackingStatistic *>::const_iterator; StatisticInfo(); ~StatisticInfo(); void addStatistic(TrackingStatistic *S) { Stats.push_back(S); } const_iterator begin() const { return Stats.begin(); } const_iterator end() const { return Stats.end(); } iterator_range<const_iterator> statistics() const { return {begin(), end()}; } void reset(); }; } // end anonymous namespace static ManagedStatic<StatisticInfo> StatInfo; static ManagedStatic<sys::SmartMutex<true> > StatLock; /// RegisterStatistic - The first time a statistic is bumped, this method is /// called. void TrackingStatistic::RegisterStatistic() { // If stats are enabled, inform StatInfo that this statistic should be // printed. // llvm_shutdown calls destructors while holding the ManagedStatic mutex. // These destructors end up calling PrintStatistics, which takes StatLock. // Since dereferencing StatInfo and StatLock can require taking the // ManagedStatic mutex, doing so with StatLock held would lead to a lock // order inversion. To avoid that, we dereference the ManagedStatics first, // and only take StatLock afterwards. if (!Initialized.load(std::memory_order_relaxed)) { sys::SmartMutex<true> &Lock = *StatLock; StatisticInfo &SI = *StatInfo; sys::SmartScopedLock<true> Writer(Lock); // Check Initialized again after acquiring the lock. if (Initialized.load(std::memory_order_relaxed)) return; if (EnableStats || Enabled) SI.addStatistic(this); // Remember we have been registered. Initialized.store(true, std::memory_order_release); } } StatisticInfo::StatisticInfo() { // Ensure timergroup lists are created first so they are destructed after us. TimerGroup::ConstructTimerLists(); } // Print information when destroyed, iff command line option is specified. StatisticInfo::~StatisticInfo() { if (EnableStats || PrintOnExit) llvm::PrintStatistics(); } void llvm::EnableStatistics(bool DoPrintOnExit) { Enabled = true; PrintOnExit = DoPrintOnExit; } bool llvm::AreStatisticsEnabled() { return Enabled || EnableStats; } void StatisticInfo::sort() { llvm::stable_sort( Stats, [](const TrackingStatistic *LHS, const TrackingStatistic *RHS) { if (int Cmp = std::strcmp(LHS->getDebugType(), RHS->getDebugType())) return Cmp < 0; if (int Cmp = std::strcmp(LHS->getName(), RHS->getName())) return Cmp < 0; return std::strcmp(LHS->getDesc(), RHS->getDesc()) < 0; }); } void StatisticInfo::reset() { sys::SmartScopedLock<true> Writer(*StatLock); // Tell each statistic that it isn't registered so it has to register // again. We're holding the lock so it won't be able to do so until we're // finished. Once we've forced it to re-register (after we return), then zero // the value. for (auto *Stat : Stats) { // Value updates to a statistic that complete before this statement in the // iteration for that statistic will be lost as intended. Stat->Initialized = false; Stat->Value = 0; } // Clear the registration list and release the lock once we're done. Any // pending updates from other threads will safely take effect after we return. // That might not be what the user wants if they're measuring a compilation // but it's their responsibility to prevent concurrent compilations to make // a single compilation measurable. Stats.clear(); } void llvm::PrintStatistics(raw_ostream &OS) { StatisticInfo &Stats = *StatInfo; // Figure out how long the biggest Value and Name fields are. unsigned MaxDebugTypeLen = 0, MaxValLen = 0; for (size_t i = 0, e = Stats.Stats.size(); i != e; ++i) { MaxValLen = std::max(MaxValLen, (unsigned)utostr(Stats.Stats[i]->getValue()).size()); MaxDebugTypeLen = std::max(MaxDebugTypeLen, (unsigned)std::strlen(Stats.Stats[i]->getDebugType())); } Stats.sort(); // Print out the statistics header... OS << "===" << std::string(73, '-') << "===\n" << " ... Statistics Collected ...\n" << "===" << std::string(73, '-') << "===\n\n"; // Print all of the statistics. for (size_t i = 0, e = Stats.Stats.size(); i != e; ++i) OS << format("%*u %-*s - %s\n", MaxValLen, Stats.Stats[i]->getValue(), MaxDebugTypeLen, Stats.Stats[i]->getDebugType(), Stats.Stats[i]->getDesc()); OS << '\n'; // Flush the output stream. OS.flush(); } void llvm::PrintStatisticsJSON(raw_ostream &OS) { sys::SmartScopedLock<true> Reader(*StatLock); StatisticInfo &Stats = *StatInfo; Stats.sort(); // Print all of the statistics. OS << "{\n"; const char *delim = ""; for (const TrackingStatistic *Stat : Stats.Stats) { OS << delim; assert(yaml::needsQuotes(Stat->getDebugType()) == yaml::QuotingType::None && "Statistic group/type name is simple."); assert(yaml::needsQuotes(Stat->getName()) == yaml::QuotingType::None && "Statistic name is simple"); OS << "\t\"" << Stat->getDebugType() << '.' << Stat->getName() << "\": " << Stat->getValue(); delim = ",\n"; } // Print timers. TimerGroup::printAllJSONValues(OS, delim); OS << "\n}\n"; OS.flush(); } void llvm::PrintStatistics() { #if LLVM_ENABLE_STATS sys::SmartScopedLock<true> Reader(*StatLock); StatisticInfo &Stats = *StatInfo; // Statistics not enabled? if (Stats.Stats.empty()) return; // Get the stream to write to. std::unique_ptr<raw_ostream> OutStream = CreateInfoOutputFile(); if (StatsAsJSON) PrintStatisticsJSON(*OutStream); else PrintStatistics(*OutStream); #else // Check if the -stats option is set instead of checking // !Stats.Stats.empty(). In release builds, Statistics operators // do nothing, so stats are never Registered. if (EnableStats) { // Get the stream to write to. std::unique_ptr<raw_ostream> OutStream = CreateInfoOutputFile(); (*OutStream) << "Statistics are disabled. " << "Build with asserts or with -DLLVM_FORCE_ENABLE_STATS\n"; } #endif } const std::vector<std::pair<StringRef, unsigned>> llvm::GetStatistics() { sys::SmartScopedLock<true> Reader(*StatLock); std::vector<std::pair<StringRef, unsigned>> ReturnStats; for (const auto &Stat : StatInfo->statistics()) ReturnStats.emplace_back(Stat->getName(), Stat->getValue()); return ReturnStats; } void llvm::ResetStatistics() { StatInfo->reset(); }
Upload File
Create Folder