diff options
Diffstat (limited to 'llvm/tools')
-rw-r--r-- | llvm/tools/llvm-config/llvm-config.cpp | 123 | ||||
-rw-r--r-- | llvm/tools/llvm-xray/func-id-helper.h | 6 | ||||
-rw-r--r-- | llvm/tools/llvm-xray/trie-node.h | 2 | ||||
-rw-r--r-- | llvm/tools/llvm-xray/xray-account.cpp | 33 | ||||
-rw-r--r-- | llvm/tools/llvm-xray/xray-account.h | 6 | ||||
-rw-r--r-- | llvm/tools/llvm-xray/xray-color-helper.h | 7 | ||||
-rw-r--r-- | llvm/tools/llvm-xray/xray-converter.cpp | 32 | ||||
-rw-r--r-- | llvm/tools/llvm-xray/xray-converter.h | 6 | ||||
-rw-r--r-- | llvm/tools/llvm-xray/xray-extract.cpp | 12 | ||||
-rw-r--r-- | llvm/tools/llvm-xray/xray-graph-diff.cpp | 4 | ||||
-rw-r--r-- | llvm/tools/llvm-xray/xray-graph-diff.h | 6 | ||||
-rw-r--r-- | llvm/tools/llvm-xray/xray-graph.cpp | 9 | ||||
-rw-r--r-- | llvm/tools/llvm-xray/xray-graph.h | 6 | ||||
-rw-r--r-- | llvm/tools/llvm-xray/xray-registry.cpp | 9 | ||||
-rw-r--r-- | llvm/tools/llvm-xray/xray-registry.h | 6 | ||||
-rw-r--r-- | llvm/tools/llvm-xray/xray-stacks.cpp | 9 | ||||
-rw-r--r-- | llvm/tools/opt/NewPMDriver.cpp | 30 | ||||
-rw-r--r-- | llvm/tools/opt/NewPMDriver.h | 4 | ||||
-rw-r--r-- | llvm/tools/opt/opt.cpp | 8 | ||||
-rw-r--r-- | llvm/tools/opt/optdriver.cpp | 42 |
20 files changed, 159 insertions, 201 deletions
diff --git a/llvm/tools/llvm-config/llvm-config.cpp b/llvm/tools/llvm-config/llvm-config.cpp index 7f8c55a..020b1b5 100644 --- a/llvm/tools/llvm-config/llvm-config.cpp +++ b/llvm/tools/llvm-config/llvm-config.cpp @@ -76,7 +76,7 @@ enum LinkMode { /// libraries. /// \param GetComponentNames - Get the component names instead of the /// library name. -static void VisitComponent(const std::string &Name, +static void visitComponent(const std::string &Name, const StringMap<AvailableComponent *> &ComponentMap, std::set<AvailableComponent *> &VisitedComponents, std::vector<std::string> &RequiredLibs, @@ -89,9 +89,8 @@ static void VisitComponent(const std::string &Name, AvailableComponent *AC = ComponentMap.lookup(Name); if (!AC) { errs() << "Can't find component: '" << Name << "' in the map. Available components are: "; - for (const auto &Component : ComponentMap) { + for (const auto &Component : ComponentMap) errs() << "'" << Component.first() << "' "; - } errs() << "\n"; report_fatal_error("abort"); } @@ -108,9 +107,11 @@ static void VisitComponent(const std::string &Name, return; // Otherwise, visit all the dependencies. - for (unsigned i = 0; AC->RequiredLibraries[i]; ++i) { - VisitComponent(AC->RequiredLibraries[i], ComponentMap, VisitedComponents, - RequiredLibs, IncludeNonInstalled, GetComponentNames, + for (const char *Lib : AC->RequiredLibraries) { + if (!Lib) + break; + visitComponent(Lib, ComponentMap, VisitedComponents, RequiredLibs, + IncludeNonInstalled, GetComponentNames, GetComponentLibraryPath, Missing, DirSep); } @@ -118,17 +119,17 @@ static void VisitComponent(const std::string &Name, // not populated by llvm-build, but later in the process and loaded from // ExtensionDependencies.inc. if (Name == "extensions") { - for (auto const &AvailableExtension : AvailableExtensions) { - for (const char *const *Iter = &AvailableExtension.RequiredLibraries[0]; - *Iter; ++Iter) { - AvailableComponent *AC = ComponentMap.lookup(*Iter); - if (!AC) { - RequiredLibs.push_back(*Iter); - } else { - VisitComponent(*Iter, ComponentMap, VisitedComponents, RequiredLibs, + for (const ExtensionDescriptor &AvailableExtension : AvailableExtensions) { + for (const char *Lib : AvailableExtension.RequiredLibraries) { + if (!Lib) + break; + AvailableComponent *AC = ComponentMap.lookup(Lib); + if (!AC) + RequiredLibs.push_back(Lib); + else + visitComponent(Lib, ComponentMap, VisitedComponents, RequiredLibs, IncludeNonInstalled, GetComponentNames, GetComponentLibraryPath, Missing, DirSep); - } } } } @@ -159,11 +160,13 @@ static void VisitComponent(const std::string &Name, /// \param IncludeNonInstalled - Whether non-installed components should be /// reported. /// \param GetComponentNames - True if one would prefer the component names. -static std::vector<std::string> ComputeLibsForComponents( - const std::vector<StringRef> &Components, bool IncludeNonInstalled, - bool GetComponentNames, const std::function<std::string(const StringRef &)> - *GetComponentLibraryPath, - std::vector<std::string> *Missing, const std::string &DirSep) { +static std::vector<std::string> +computeLibsForComponents(ArrayRef<StringRef> Components, + bool IncludeNonInstalled, bool GetComponentNames, + const std::function<std::string(const StringRef &)> + *GetComponentLibraryPath, + std::vector<std::string> *Missing, + const std::string &DirSep) { std::vector<std::string> RequiredLibs; std::set<AvailableComponent *> VisitedComponents; @@ -173,18 +176,17 @@ static std::vector<std::string> ComputeLibsForComponents( ComponentMap[AC.Name] = &AC; // Visit the components. - for (unsigned i = 0, e = Components.size(); i != e; ++i) { + for (StringRef Component : Components) { // Users are allowed to provide mixed case component names. - std::string ComponentLower = Components[i].lower(); + std::string ComponentLower = Component.lower(); // Validate that the user supplied a valid component name. if (!ComponentMap.count(ComponentLower)) { - llvm::errs() << "llvm-config: unknown component name: " << Components[i] - << "\n"; + errs() << "llvm-config: unknown component name: " << Component << "\n"; exit(1); } - VisitComponent(ComponentLower, ComponentMap, VisitedComponents, + visitComponent(ComponentLower, ComponentMap, VisitedComponents, RequiredLibs, IncludeNonInstalled, GetComponentNames, GetComponentLibraryPath, Missing, DirSep); } @@ -196,8 +198,6 @@ static std::vector<std::string> ComputeLibsForComponents( return RequiredLibs; } -/* *** */ - static void usage(bool ExitWithFailure = true) { errs() << "\ usage: llvm-config <OPTION>... [<COMPONENT>...]\n\ @@ -244,18 +244,18 @@ Typical components:\n\ } /// Compute the path to the main executable. -std::string GetExecutablePath(const char *Argv0) { +static std::string getExecutablePath(const char *Argv0) { // This just needs to be some symbol in the binary; C++ doesn't // allow taking the address of ::main however. - void *P = (void *)(intptr_t)GetExecutablePath; - return llvm::sys::fs::getMainExecutable(Argv0, P); + void *P = (void *)(intptr_t)getExecutablePath; + return sys::fs::getMainExecutable(Argv0, P); } /// Expand the semi-colon delimited LLVM_DYLIB_COMPONENTS into /// the full list of components. -std::vector<std::string> GetAllDyLibComponents(const bool IsInDevelopmentTree, - const bool GetComponentNames, - const std::string &DirSep) { +static std::vector<std::string> +getAllDyLibComponents(const bool IsInDevelopmentTree, + const bool GetComponentNames, const std::string &DirSep) { std::vector<StringRef> DyLibComponents; StringRef DyLibComponentsStr(LLVM_DYLIB_COMPONENTS); @@ -263,15 +263,14 @@ std::vector<std::string> GetAllDyLibComponents(const bool IsInDevelopmentTree, while (true) { const size_t NextOffset = DyLibComponentsStr.find(';', Offset); DyLibComponents.push_back(DyLibComponentsStr.substr(Offset, NextOffset-Offset)); - if (NextOffset == std::string::npos) { + if (NextOffset == std::string::npos) break; - } Offset = NextOffset + 1; } assert(!DyLibComponents.empty()); - return ComputeLibsForComponents(DyLibComponents, + return computeLibsForComponents(DyLibComponents, /*IncludeNonInstalled=*/IsInDevelopmentTree, GetComponentNames, nullptr, nullptr, DirSep); } @@ -288,7 +287,7 @@ int main(int argc, char **argv) { // tree. bool IsInDevelopmentTree; enum { CMakeStyle, CMakeBuildModeStyle } DevelopmentTreeLayout; - llvm::SmallString<256> CurrentPath(GetExecutablePath(argv[0])); + SmallString<256> CurrentPath(getExecutablePath(argv[0])); std::string CurrentExecPrefix; std::string ActiveObjRoot; @@ -453,13 +452,12 @@ int main(int argc, char **argv) { StringRef &Out) { if (Lib.starts_with(StaticPrefix) || Lib.starts_with(SharedPrefix)) { unsigned FromEnd; - if (Lib.ends_with(StaticExt)) { + if (Lib.ends_with(StaticExt)) FromEnd = StaticExt.size() + 1; - } else if (Lib.ends_with(SharedExt)) { + else if (Lib.ends_with(SharedExt)) FromEnd = SharedExt.size() + 1; - } else { + else FromEnd = 0; - } if (FromEnd != 0) { unsigned FromStart = Lib.starts_with(SharedPrefix) @@ -496,11 +494,10 @@ int main(int argc, char **argv) { /// Get the full path for a possibly shared component library. auto GetComponentLibraryPath = [&](const StringRef &Name, const bool Shared) { auto LibFileName = GetComponentLibraryFileName(Name, Shared); - if (Shared) { + if (Shared) return (SharedDir + DirSep + LibFileName).str(); - } else { + else return (StaticDir + DirSep + LibFileName).str(); - } }; raw_ostream &OS = outs(); @@ -555,20 +552,14 @@ int main(int argc, char **argv) { llvm::replace(path, '/', '\\'); if (DyLibExists && !sys::fs::exists(path)) { Components = - GetAllDyLibComponents(IsInDevelopmentTree, true, DirSep); + getAllDyLibComponents(IsInDevelopmentTree, true, DirSep); llvm::sort(Components); break; } } } - for (unsigned I = 0; I < Components.size(); ++I) { - if (I) { - OS << ' '; - } - - OS << Components[I]; - } + interleave(Components, OS, " "); OS << '\n'; } else if (Arg == "--targets-built") { OS << LLVM_TARGETS_BUILT << '\n'; @@ -633,7 +624,7 @@ int main(int argc, char **argv) { return GetComponentLibraryPath(Name, LinkMode == LinkModeShared); }; std::vector<std::string> MissingLibs; - std::vector<std::string> RequiredLibs = ComputeLibsForComponents( + std::vector<std::string> RequiredLibs = computeLibsForComponents( Components, /*IncludeNonInstalled=*/IsInDevelopmentTree, false, &GetComponentLibraryPathFunction, &MissingLibs, DirSep); @@ -666,11 +657,10 @@ int main(int argc, char **argv) { if (PrintSharedMode) { std::unordered_set<std::string> FullDyLibComponents; std::vector<std::string> DyLibComponents = - GetAllDyLibComponents(IsInDevelopmentTree, false, DirSep); + getAllDyLibComponents(IsInDevelopmentTree, false, DirSep); - for (auto &Component : DyLibComponents) { + for (auto &Component : DyLibComponents) FullDyLibComponents.insert(Component); - } DyLibComponents.clear(); for (auto &Lib : RequiredLibs) { @@ -681,13 +671,11 @@ int main(int argc, char **argv) { } FullDyLibComponents.clear(); - if (LinkMode == LinkModeShared) { + if (LinkMode == LinkModeShared) OS << "shared\n"; - return 0; - } else { + else OS << "static\n"; - return 0; - } + return 0; } if (PrintLibs || PrintLibNames || PrintLibFiles) { @@ -716,17 +704,10 @@ int main(int argc, char **argv) { } }; - if (LinkMode == LinkModeShared && LinkDyLib) { + if (LinkMode == LinkModeShared && LinkDyLib) PrintForLib(DyLibName); - } else { - for (unsigned i = 0, e = RequiredLibs.size(); i != e; ++i) { - auto Lib = RequiredLibs[i]; - if (i) - OS << ' '; - - PrintForLib(Lib); - } - } + else + interleave(RequiredLibs, OS, PrintForLib, " "); OS << '\n'; } diff --git a/llvm/tools/llvm-xray/func-id-helper.h b/llvm/tools/llvm-xray/func-id-helper.h index d99fb7c..d1a6628 100644 --- a/llvm/tools/llvm-xray/func-id-helper.h +++ b/llvm/tools/llvm-xray/func-id-helper.h @@ -17,8 +17,7 @@ #include "llvm/DebugInfo/Symbolize/Symbolize.h" #include <unordered_map> -namespace llvm { -namespace xray { +namespace llvm::xray { // This class consolidates common operations related to Function IDs. class FuncIdConversionHelper { @@ -45,7 +44,6 @@ public: std::string FileLineAndColumn(int32_t FuncId) const; }; -} // namespace xray -} // namespace llvm +} // namespace llvm::xray #endif // LLVM_TOOLS_LLVM_XRAY_FUNC_ID_HELPER_H diff --git a/llvm/tools/llvm-xray/trie-node.h b/llvm/tools/llvm-xray/trie-node.h index 7bff814..b42b029 100644 --- a/llvm/tools/llvm-xray/trie-node.h +++ b/llvm/tools/llvm-xray/trie-node.h @@ -21,6 +21,7 @@ #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SmallVector.h" +namespace llvm { /// A type to represent a trie of invocations. It is useful to construct a /// graph of these nodes from reading an XRay trace, such that each function /// call can be placed in a larger context. @@ -87,5 +88,6 @@ mergeTrieNodes(const TrieNode<T> &Left, const TrieNode<T> &Right, return Node; } +} // namespace llvm #endif // LLVM_TOOLS_LLVM_XRAY_STACK_TRIE_H diff --git a/llvm/tools/llvm-xray/xray-account.cpp b/llvm/tools/llvm-xray/xray-account.cpp index 24a3552..5168aa1 100644 --- a/llvm/tools/llvm-xray/xray-account.cpp +++ b/llvm/tools/llvm-xray/xray-account.cpp @@ -118,18 +118,16 @@ static cl::opt<std::string> static cl::alias AccountInstrMap2("m", cl::aliasopt(AccountInstrMap), cl::desc("Alias for -instr_map")); -namespace { - -template <class T, class U> void setMinMax(std::pair<T, T> &MM, U &&V) { +template <class T, class U> static void setMinMax(std::pair<T, T> &MM, U &&V) { if (MM.first == 0 || MM.second == 0) MM = std::make_pair(std::forward<U>(V), std::forward<U>(V)); else MM = std::make_pair(std::min(MM.first, V), std::max(MM.second, V)); } -template <class T> T diff(T L, T R) { return std::max(L, R) - std::min(L, R); } - -} // namespace +template <class T> static T diff(T L, T R) { + return std::max(L, R) - std::min(L, R); +} using RecursionStatus = LatencyAccountant::FunctionStack::RecursionStatus; RecursionStatus &RecursionStatus::operator++() { @@ -143,6 +141,7 @@ RecursionStatus &RecursionStatus::operator++() { true); // Storage |= INT_MIN return *this; } + RecursionStatus &RecursionStatus::operator--() { auto Depth = Bitfield::get<RecursionStatus::Depth>(Storage); assert(Depth > 0); @@ -153,6 +152,7 @@ RecursionStatus &RecursionStatus::operator--() { Bitfield::set<RecursionStatus::IsRecursive>(Storage, false); // Storage = 0 return *this; } + bool RecursionStatus::isRecursive() const { return Bitfield::get<RecursionStatus::IsRecursive>(Storage); // Storage s< 0 } @@ -270,8 +270,9 @@ struct ResultRow { std::string DebugInfo; std::string Function; }; +} // namespace -ResultRow getStats(MutableArrayRef<uint64_t> Timings) { +static ResultRow getStats(MutableArrayRef<uint64_t> Timings) { assert(!Timings.empty()); ResultRow R; R.Sum = std::accumulate(Timings.begin(), Timings.end(), 0.0); @@ -296,8 +297,6 @@ ResultRow getStats(MutableArrayRef<uint64_t> Timings) { return R; } -} // namespace - using TupleType = std::tuple<int32_t, uint64_t, ResultRow>; template <typename F> @@ -417,11 +416,8 @@ void LatencyAccountant::exportStatsAsCSV(raw_ostream &OS, }); } -using namespace llvm::xray; - -namespace llvm { -template <> struct format_provider<llvm::xray::RecordTypes> { - static void format(const llvm::xray::RecordTypes &T, raw_ostream &Stream, +template <> struct llvm::format_provider<RecordTypes> { + static void format(const RecordTypes &T, raw_ostream &Stream, StringRef Style) { switch (T) { case RecordTypes::ENTER: @@ -445,7 +441,6 @@ template <> struct format_provider<llvm::xray::RecordTypes> { } } }; -} // namespace llvm static CommandRegistration Unused(&Account, []() -> Error { InstrumentationMap Map; @@ -468,10 +463,10 @@ static CommandRegistration Unused(&Account, []() -> Error { const auto &FunctionAddresses = Map.getFunctionAddresses(); symbolize::LLVMSymbolizer Symbolizer; - llvm::xray::FuncIdConversionHelper FuncIdHelper(AccountInstrMap, Symbolizer, - FunctionAddresses); - xray::LatencyAccountant FCA(FuncIdHelper, AccountRecursiveCallsOnly, - AccountDeduceSiblingCalls); + FuncIdConversionHelper FuncIdHelper(AccountInstrMap, Symbolizer, + FunctionAddresses); + LatencyAccountant FCA(FuncIdHelper, AccountRecursiveCallsOnly, + AccountDeduceSiblingCalls); auto TraceOrErr = loadTraceFile(AccountInput); if (!TraceOrErr) return joinErrors( diff --git a/llvm/tools/llvm-xray/xray-account.h b/llvm/tools/llvm-xray/xray-account.h index 0f24f93..c4e20731af 100644 --- a/llvm/tools/llvm-xray/xray-account.h +++ b/llvm/tools/llvm-xray/xray-account.h @@ -21,8 +21,7 @@ #include "llvm/Support/raw_ostream.h" #include "llvm/XRay/XRayRecord.h" -namespace llvm { -namespace xray { +namespace llvm::xray { class LatencyAccountant { public: @@ -107,7 +106,6 @@ private: template <class F> void exportStats(const XRayFileHeader &Header, F fn) const; }; -} // namespace xray -} // namespace llvm +} // namespace llvm::xray #endif // LLVM_TOOLS_LLVM_XRAY_XRAY_ACCOUNT_H diff --git a/llvm/tools/llvm-xray/xray-color-helper.h b/llvm/tools/llvm-xray/xray-color-helper.h index 3141e90..ae95c92 100644 --- a/llvm/tools/llvm-xray/xray-color-helper.h +++ b/llvm/tools/llvm-xray/xray-color-helper.h @@ -16,8 +16,7 @@ #include "llvm/ADT/ArrayRef.h" #include <tuple> -namespace llvm { -namespace xray { +namespace llvm::xray { /// The color helper class it a healper class which allows you to easily get a /// color in a gradient. This is used to color-code edges in XRay-Graph tools. @@ -82,6 +81,6 @@ public: // Convert a tuple to a string static std::string getColorString(std::tuple<uint8_t, uint8_t, uint8_t> t); }; -} // namespace xray -} // namespace llvm +} // namespace llvm::xray + #endif diff --git a/llvm/tools/llvm-xray/xray-converter.cpp b/llvm/tools/llvm-xray/xray-converter.cpp index 34832eb..0f45fef 100644 --- a/llvm/tools/llvm-xray/xray-converter.cpp +++ b/llvm/tools/llvm-xray/xray-converter.cpp @@ -176,13 +176,14 @@ struct StackIdData { // unique ID. SmallVector<TrieNode<StackIdData> *, 4> siblings; }; +} // namespace using StackTrieNode = TrieNode<StackIdData>; // A helper function to find the sibling nodes for an encountered function in a // thread of execution. Relies on the invariant that each time a new node is // traversed in a thread, sibling bidirectional pointers are maintained. -SmallVector<StackTrieNode *, 4> +static SmallVector<StackTrieNode *, 4> findSiblings(StackTrieNode *parent, int32_t FnId, uint32_t TId, const DenseMap<uint32_t, SmallVector<StackTrieNode *, 4>> &StackRootsByThreadId) { @@ -213,7 +214,7 @@ findSiblings(StackTrieNode *parent, int32_t FnId, uint32_t TId, // StackTrie representing the function call stack. If no node exists, creates // the node. Assigns unique IDs to stacks newly encountered among all threads // and keeps sibling links up to when creating new nodes. -StackTrieNode *findOrCreateStackNode( +static StackTrieNode *findOrCreateStackNode( StackTrieNode *Parent, int32_t FuncId, uint32_t TId, DenseMap<uint32_t, SmallVector<StackTrieNode *, 4>> &StackRootsByThreadId, DenseMap<unsigned, StackTrieNode *> &StacksByStackId, unsigned *id_counter, @@ -244,12 +245,13 @@ StackTrieNode *findOrCreateStackNode( return CurrentStack; } -void writeTraceViewerRecord(uint16_t Version, raw_ostream &OS, int32_t FuncId, - uint32_t TId, uint32_t PId, bool Symbolize, - const FuncIdConversionHelper &FuncIdHelper, - double EventTimestampUs, - const StackTrieNode &StackCursor, - StringRef FunctionPhenotype) { +static void writeTraceViewerRecord(uint16_t Version, raw_ostream &OS, + int32_t FuncId, uint32_t TId, uint32_t PId, + bool Symbolize, + const FuncIdConversionHelper &FuncIdHelper, + double EventTimestampUs, + const StackTrieNode &StackCursor, + StringRef FunctionPhenotype) { OS << " "; if (Version >= 3) { OS << llvm::formatv( @@ -269,8 +271,6 @@ void writeTraceViewerRecord(uint16_t Version, raw_ostream &OS, int32_t FuncId, } } -} // namespace - void TraceConverter::exportAsChromeTraceEventFormat(const Trace &Records, raw_ostream &OS) { const auto &FH = Records.getFileHeader(); @@ -364,9 +364,6 @@ void TraceConverter::exportAsChromeTraceEventFormat(const Trace &Records, OS << "}\n"; // Close the JSON entry. } -namespace llvm { -namespace xray { - static CommandRegistration Unused(&Convert, []() -> Error { // FIXME: Support conversion to BINARY when upgrading XRay trace versions. InstrumentationMap Map; @@ -386,9 +383,9 @@ static CommandRegistration Unused(&Convert, []() -> Error { if (Demangle.getPosition() < NoDemangle.getPosition()) SymbolizerOpts.Demangle = false; symbolize::LLVMSymbolizer Symbolizer(SymbolizerOpts); - llvm::xray::FuncIdConversionHelper FuncIdHelper(ConvertInstrMap, Symbolizer, - FunctionAddresses); - llvm::xray::TraceConverter TC(FuncIdHelper, ConvertSymbolize); + FuncIdConversionHelper FuncIdHelper(ConvertInstrMap, Symbolizer, + FunctionAddresses); + TraceConverter TC(FuncIdHelper, ConvertSymbolize); std::error_code EC; raw_fd_ostream OS(ConvertOutput, EC, ConvertOutputFormat == ConvertFormats::BINARY @@ -420,6 +417,3 @@ static CommandRegistration Unused(&Convert, []() -> Error { } return Error::success(); }); - -} // namespace xray -} // namespace llvm diff --git a/llvm/tools/llvm-xray/xray-converter.h b/llvm/tools/llvm-xray/xray-converter.h index db6d2b1..0f8efa4 100644 --- a/llvm/tools/llvm-xray/xray-converter.h +++ b/llvm/tools/llvm-xray/xray-converter.h @@ -17,8 +17,7 @@ #include "llvm/XRay/Trace.h" #include "llvm/XRay/XRayRecord.h" -namespace llvm { -namespace xray { +namespace llvm::xray { class TraceConverter { FuncIdConversionHelper &FuncIdHelper; @@ -37,7 +36,6 @@ public: void exportAsChromeTraceEventFormat(const Trace &Records, raw_ostream &OS); }; -} // namespace xray -} // namespace llvm +} // namespace llvm::xray #endif // LLVM_TOOLS_LLVM_XRAY_XRAY_CONVERTER_H diff --git a/llvm/tools/llvm-xray/xray-extract.cpp b/llvm/tools/llvm-xray/xray-extract.cpp index 52767a0..70fe011 100644 --- a/llvm/tools/llvm-xray/xray-extract.cpp +++ b/llvm/tools/llvm-xray/xray-extract.cpp @@ -52,10 +52,8 @@ static cl::opt<bool> NoDemangle("no-demangle", cl::desc("don't demangle symbols"), cl::sub(Extract)); -namespace { - -void exportAsYAML(const InstrumentationMap &Map, raw_ostream &OS, - FuncIdConversionHelper &FH) { +static void exportAsYAML(const InstrumentationMap &Map, raw_ostream &OS, + FuncIdConversionHelper &FH) { // First we translate the sleds into the YAMLXRaySledEntry objects in a deque. std::vector<YAMLXRaySledEntry> YAMLSleds; auto Sleds = Map.sleds(); @@ -72,8 +70,6 @@ void exportAsYAML(const InstrumentationMap &Map, raw_ostream &OS, Out << YAMLSleds; } -} // namespace - static CommandRegistration Unused(&Extract, []() -> Error { auto InstrumentationMapOrError = loadInstrumentationMap(ExtractInput); if (!InstrumentationMapOrError) @@ -94,8 +90,8 @@ static CommandRegistration Unused(&Extract, []() -> Error { if (Demangle.getPosition() < NoDemangle.getPosition()) opts.Demangle = false; symbolize::LLVMSymbolizer Symbolizer(opts); - llvm::xray::FuncIdConversionHelper FuncIdHelper(ExtractInput, Symbolizer, - FunctionAddresses); + FuncIdConversionHelper FuncIdHelper(ExtractInput, Symbolizer, + FunctionAddresses); exportAsYAML(*InstrumentationMapOrError, OS, FuncIdHelper); return Error::success(); }); diff --git a/llvm/tools/llvm-xray/xray-graph-diff.cpp b/llvm/tools/llvm-xray/xray-graph-diff.cpp index b5c63ab..66799091 100644 --- a/llvm/tools/llvm-xray/xray-graph-diff.cpp +++ b/llvm/tools/llvm-xray/xray-graph-diff.cpp @@ -236,6 +236,7 @@ Expected<GraphDiffRenderer> GraphDiffRenderer::Factory::getGraphDiffRenderer() { return R; } + // Returns the Relative change With respect to LeftStat between LeftStat // and RightStat. static double statRelDiff(const GraphDiffRenderer::TimeStat &LeftStat, @@ -363,9 +364,8 @@ void GraphDiffRenderer::exportGraphAsDOT(raw_ostream &OS, StatType EdgeLabel, StringMap<int32_t> VertexNo; int i = 0; - for (const auto &V : G.vertices()) { + for (const auto &V : G.vertices()) VertexNo[V.first] = i++; - } ColorHelper H(ColorHelper::DivergingScheme::PiYG); diff --git a/llvm/tools/llvm-xray/xray-graph-diff.h b/llvm/tools/llvm-xray/xray-graph-diff.h index c2b2a93..709f1bf 100644 --- a/llvm/tools/llvm-xray/xray-graph-diff.h +++ b/llvm/tools/llvm-xray/xray-graph-diff.h @@ -17,8 +17,7 @@ #include "xray-graph.h" #include "llvm/XRay/Graph.h" -namespace llvm { -namespace xray { +namespace llvm::xray { // This class creates a graph representing the difference between two // xray-graphs And allows you to print it to a dot file, with optional color @@ -66,7 +65,6 @@ public: const GraphT &getGraph() { return G; } }; -} // namespace xray -} // namespace llvm +} // namespace llvm::xray #endif diff --git a/llvm/tools/llvm-xray/xray-graph.cpp b/llvm/tools/llvm-xray/xray-graph.cpp index a97aacf..71d3029 100644 --- a/llvm/tools/llvm-xray/xray-graph.cpp +++ b/llvm/tools/llvm-xray/xray-graph.cpp @@ -153,7 +153,9 @@ static cl::opt<GraphRenderer::StatType> GraphVertexColorType( static cl::alias GraphVertexColorType2("b", cl::aliasopt(GraphVertexColorType), cl::desc("Alias for -edge-label")); -template <class T> T diff(T L, T R) { return std::max(L, R) - std::min(L, R); } +template <class T> static T diff(T L, T R) { + return std::max(L, R) - std::min(L, R); +} // Updates the statistics for a GraphRenderer::TimeStat static void updateStat(GraphRenderer::TimeStat &S, int64_t L) { @@ -459,10 +461,9 @@ Expected<GraphRenderer> GraphRenderer::Factory::getGraphRenderer() { symbolize::LLVMSymbolizer Symbolizer; const auto &Header = Trace.getFileHeader(); - llvm::xray::FuncIdConversionHelper FuncIdHelper(InstrMap, Symbolizer, - FunctionAddresses); + FuncIdConversionHelper FuncIdHelper(InstrMap, Symbolizer, FunctionAddresses); - xray::GraphRenderer GR(FuncIdHelper, DeduceSiblingCalls); + GraphRenderer GR(FuncIdHelper, DeduceSiblingCalls); for (const auto &Record : Trace) { auto E = GR.accountRecord(Record); if (!E) diff --git a/llvm/tools/llvm-xray/xray-graph.h b/llvm/tools/llvm-xray/xray-graph.h index 23372d4..fd96449 100644 --- a/llvm/tools/llvm-xray/xray-graph.h +++ b/llvm/tools/llvm-xray/xray-graph.h @@ -28,8 +28,7 @@ #include "llvm/XRay/Trace.h" #include "llvm/XRay/XRayRecord.h" -namespace llvm { -namespace xray { +namespace llvm::xray { /// A class encapsulating the logic related to analyzing XRay traces, producting /// Graphs from them and then exporting those graphs for review. @@ -225,7 +224,6 @@ inline GraphRenderer::TimeStat operator/(const GraphRenderer::TimeStat &A, A.Pct90 / B.Pct90, A.Pct99 / B.Pct99, A.Max / B.Max, A.Sum / B.Sum}; } -} // namespace xray -} // namespace llvm +} // namespace llvm::xray #endif // XRAY_GRAPH_H diff --git a/llvm/tools/llvm-xray/xray-registry.cpp b/llvm/tools/llvm-xray/xray-registry.cpp index 34ac07e..ae18f8d 100644 --- a/llvm/tools/llvm-xray/xray-registry.cpp +++ b/llvm/tools/llvm-xray/xray-registry.cpp @@ -13,8 +13,8 @@ #include <unordered_map> -namespace llvm { -namespace xray { +using namespace llvm; +using namespace xray; using HandlerType = std::function<Error()>; @@ -31,12 +31,9 @@ CommandRegistration::CommandRegistration(cl::SubCommand *SC, getCommands()[SC] = Command; } -HandlerType dispatch(cl::SubCommand *SC) { +HandlerType xray::dispatch(cl::SubCommand *SC) { auto It = getCommands().find(SC); assert(It != getCommands().end() && "Attempting to dispatch on un-registered SubCommand."); return It->second; } - -} // namespace xray -} // namespace llvm diff --git a/llvm/tools/llvm-xray/xray-registry.h b/llvm/tools/llvm-xray/xray-registry.h index d6fae78..3921a42 100644 --- a/llvm/tools/llvm-xray/xray-registry.h +++ b/llvm/tools/llvm-xray/xray-registry.h @@ -15,8 +15,7 @@ #include "llvm/Support/CommandLine.h" #include "llvm/Support/Error.h" -namespace llvm { -namespace xray { +namespace llvm::xray { // Use |CommandRegistration| as a global initialiser that registers a function // and associates it with |SC|. This requires that a command has not been @@ -34,7 +33,6 @@ struct CommandRegistration { // Requires that |SC| is not null and has an associated function to it. std::function<Error()> dispatch(cl::SubCommand *SC); -} // namespace xray -} // namespace llvm +} // namespace llvm::xray #endif // TOOLS_LLVM_XRAY_XRAY_REGISTRY_H diff --git a/llvm/tools/llvm-xray/xray-stacks.cpp b/llvm/tools/llvm-xray/xray-stacks.cpp index b11d732..8101cad 100644 --- a/llvm/tools/llvm-xray/xray-stacks.cpp +++ b/llvm/tools/llvm-xray/xray-stacks.cpp @@ -107,6 +107,8 @@ static cl::opt<AggregationType> RequestedAggregation( "of all callees.")), cl::sub(Stack), cl::init(AggregationType::TOTAL_TIME)); +namespace { + /// A helper struct to work with formatv and XRayRecords. Makes it easier to /// use instrumentation map names or addresses in formatted output. struct format_xray_record : public FormatAdapter<XRayRecord> { @@ -252,10 +254,9 @@ private: /// maintain an index of unique functions, and provide a means of iterating /// through all the instrumented call stacks which we know about. -namespace { struct StackDuration { - llvm::SmallVector<int64_t, 4> TerminalDurations; - llvm::SmallVector<int64_t, 4> IntermediateDurations; + SmallVector<int64_t, 4> TerminalDurations; + SmallVector<int64_t, 4> IntermediateDurations; }; } // namespace @@ -310,6 +311,7 @@ std::size_t GetValueForStack(const StackTrieNode *Node) { return 0; } +namespace { class StackTrie { // Avoid the magic number of 4 propagated through the code with an alias. // We use this SmallVector to track the root nodes in a call graph. @@ -649,6 +651,7 @@ public: OS << "\n"; } }; +} // namespace static std::string CreateErrorMessage(StackTrie::AccountRecordStatus Error, const XRayRecord &Record, diff --git a/llvm/tools/opt/NewPMDriver.cpp b/llvm/tools/opt/NewPMDriver.cpp index c19fc19..a383415 100644 --- a/llvm/tools/opt/NewPMDriver.cpp +++ b/llvm/tools/opt/NewPMDriver.cpp @@ -45,32 +45,30 @@ using namespace llvm; using namespace opt_tool; -namespace llvm { -cl::opt<bool> DebugifyEach( +cl::opt<bool> llvm::DebugifyEach( "debugify-each", cl::desc("Start each pass with debugify and end it with check-debugify")); -cl::opt<std::string> - DebugifyExport("debugify-export", - cl::desc("Export per-pass debugify statistics to this file"), - cl::value_desc("filename")); +cl::opt<std::string> llvm::DebugifyExport( + "debugify-export", + cl::desc("Export per-pass debugify statistics to this file"), + cl::value_desc("filename")); -cl::opt<bool> VerifyEachDebugInfoPreserve( +cl::opt<bool> llvm::VerifyEachDebugInfoPreserve( "verify-each-debuginfo-preserve", cl::desc("Start each pass with collecting and end it with checking of " "debug info preservation.")); +cl::opt<std::string> llvm::VerifyDIPreserveExport( + "verify-di-preserve-export", + cl::desc("Export debug info preservation failures into " + "specified (JSON) file (should be abs path as we use" + " append mode to insert new JSON objects)"), + cl::value_desc("filename"), cl::init("")); + static cl::opt<bool> EnableLoopFusion("enable-loopfusion", cl::init(false), cl::Hidden, cl::desc("Enable the LoopFuse Pass")); -cl::opt<std::string> - VerifyDIPreserveExport("verify-di-preserve-export", - cl::desc("Export debug info preservation failures into " - "specified (JSON) file (should be abs path as we use" - " append mode to insert new JSON objects)"), - cl::value_desc("filename"), cl::init("")); - -} // namespace llvm enum class DebugLogging { None, Normal, Verbose, Quiet }; @@ -356,7 +354,7 @@ bool llvm::runPassPipeline( ToolOutputFile *Out, ToolOutputFile *ThinLTOLinkOut, ToolOutputFile *OptRemarkFile, StringRef PassPipeline, ArrayRef<PassPlugin> PassPlugins, - ArrayRef<std::function<void(llvm::PassBuilder &)>> PassBuilderCallbacks, + ArrayRef<std::function<void(PassBuilder &)>> PassBuilderCallbacks, OutputKind OK, VerifierKind VK, bool ShouldPreserveAssemblyUseListOrder, bool ShouldPreserveBitcodeUseListOrder, bool EmitSummaryIndex, bool EmitModuleHash, bool EnableDebugify, bool VerifyDIPreserve, diff --git a/llvm/tools/opt/NewPMDriver.h b/llvm/tools/opt/NewPMDriver.h index 6c21d6c..042d5d4 100644 --- a/llvm/tools/opt/NewPMDriver.h +++ b/llvm/tools/opt/NewPMDriver.h @@ -52,7 +52,7 @@ enum PGOKind { SampleUse }; enum CSPGOKind { NoCSPGO, CSInstrGen, CSInstrUse }; -} +} // namespace opt_tool void printPasses(raw_ostream &OS); @@ -70,7 +70,7 @@ bool runPassPipeline( ToolOutputFile *Out, ToolOutputFile *ThinLinkOut, ToolOutputFile *OptRemarkFile, StringRef PassPipeline, ArrayRef<PassPlugin> PassPlugins, - ArrayRef<std::function<void(llvm::PassBuilder &)>> PassBuilderCallbacks, + ArrayRef<std::function<void(PassBuilder &)>> PassBuilderCallbacks, opt_tool::OutputKind OK, opt_tool::VerifierKind VK, bool ShouldPreserveAssemblyUseListOrder, bool ShouldPreserveBitcodeUseListOrder, bool EmitSummaryIndex, diff --git a/llvm/tools/opt/opt.cpp b/llvm/tools/opt/opt.cpp index fc8bd665..ad0f8f4a 100644 --- a/llvm/tools/opt/opt.cpp +++ b/llvm/tools/opt/opt.cpp @@ -14,12 +14,14 @@ #include "llvm/ADT/ArrayRef.h" #include <functional> +using namespace llvm; + namespace llvm { class PassBuilder; } -extern "C" int optMain(int argc, char **argv, - llvm::ArrayRef<std::function<void(llvm::PassBuilder &)>> - PassBuilderCallbacks); +extern "C" int +optMain(int argc, char **argv, + ArrayRef<std::function<void(PassBuilder &)>> PassBuilderCallbacks); int main(int argc, char **argv) { return optMain(argc, argv, {}); } diff --git a/llvm/tools/opt/optdriver.cpp b/llvm/tools/opt/optdriver.cpp index 2ac8de7..f70db31 100644 --- a/llvm/tools/opt/optdriver.cpp +++ b/llvm/tools/opt/optdriver.cpp @@ -296,23 +296,25 @@ static CodeGenOptLevel GetCodeGenOptLevel() { return static_cast<CodeGenOptLevel>(unsigned(CodeGenOptLevelCL)); } +namespace { struct TimeTracerRAII { TimeTracerRAII(StringRef ProgramName) { if (TimeTrace) timeTraceProfilerInitialize(TimeTraceGranularity, ProgramName); } ~TimeTracerRAII() { - if (TimeTrace) { - if (auto E = timeTraceProfilerWrite(TimeTraceFile, OutputFilename)) { - handleAllErrors(std::move(E), [&](const StringError &SE) { - errs() << SE.getMessage() << "\n"; - }); - return; - } - timeTraceProfilerCleanup(); + if (!TimeTrace) + return; + if (auto E = timeTraceProfilerWrite(TimeTraceFile, OutputFilename)) { + handleAllErrors(std::move(E), [&](const StringError &SE) { + errs() << SE.getMessage() << "\n"; + }); + return; } + timeTraceProfilerCleanup(); } }; +} // namespace // For use in NPM transition. Currently this contains most codegen-specific // passes. Remove passes from here when porting to the NPM. @@ -377,10 +379,10 @@ static bool shouldPinPassToLegacyPM(StringRef Pass) { "callbrprepare", "scalarizer", }; - for (const auto &P : PassNamePrefix) + for (StringLiteral P : PassNamePrefix) if (Pass.starts_with(P)) return true; - for (const auto &P : PassNameContain) + for (StringLiteral P : PassNameContain) if (Pass.contains(P)) return true; return llvm::is_contained(PassNameExact, Pass); @@ -388,7 +390,7 @@ static bool shouldPinPassToLegacyPM(StringRef Pass) { // For use in NPM transition. static bool shouldForceLegacyPM() { - for (const auto &P : PassList) { + for (const PassInfo *P : PassList) { StringRef Arg = P->getPassArgument(); if (shouldPinPassToLegacyPM(Arg)) return true; @@ -399,9 +401,9 @@ static bool shouldForceLegacyPM() { //===----------------------------------------------------------------------===// // main for opt // -extern "C" int optMain( - int argc, char **argv, - ArrayRef<std::function<void(llvm::PassBuilder &)>> PassBuilderCallbacks) { +extern "C" int +optMain(int argc, char **argv, + ArrayRef<std::function<void(PassBuilder &)>> PassBuilderCallbacks) { InitLLVM X(argc, argv); // Enable debug stream buffering. @@ -673,7 +675,7 @@ extern "C" int optMain( else { // Disable individual builtin functions in TargetLibraryInfo. LibFunc F; - for (auto &FuncName : DisableBuiltins) { + for (const std::string &FuncName : DisableBuiltins) { if (TLII.getLibFunc(FuncName, F)) TLII.setUnavailable(F); else { @@ -683,7 +685,7 @@ extern "C" int optMain( } } - for (auto &FuncName : EnableBuiltins) { + for (const std::string &FuncName : EnableBuiltins) { if (TLII.getLibFunc(FuncName, F)) TLII.setAvailable(F); else { @@ -814,9 +816,8 @@ extern "C" int optMain( Passes.add(TPC); } - // Create a new optimization pass for each one specified on the command line - for (unsigned i = 0; i < PassList.size(); ++i) { - const PassInfo *PassInf = PassList[i]; + // Create a new optimization pass for each one specified on the command line. + for (const PassInfo *PassInf : PassList) { if (PassInf->getNormalCtor()) { Pass *P = PassInf->getNormalCtor()(); if (P) { @@ -826,9 +827,10 @@ extern "C" int optMain( if (VerifyEach) Passes.add(createVerifierPass()); } - } else + } else { errs() << argv[0] << ": cannot create pass: " << PassInf->getPassName() << "\n"; + } } // Check that the module is well formed on completion of optimization |