LLVM 19.0.0git
OutputAggregator.h
Go to the documentation of this file.
1//===- DwarfTransformer.h ---------------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_DEBUGINFO_GSYM_OUTPUTAGGREGATOR_H
10#define LLVM_DEBUGINFO_GSYM_OUTPUTAGGREGATOR_H
11
12#include "llvm/ADT/StringRef.h"
14
15#include <map>
16#include <string>
17
18namespace llvm {
19
20class raw_ostream;
21
22namespace gsym {
23
25protected:
26 // A std::map is preferable over an llvm::StringMap for presenting results
27 // in a predictable order.
28 std::map<std::string, unsigned> Aggregation;
30
31public:
33
34 size_t GetNumCategories() const { return Aggregation.size(); }
35
36 void Report(StringRef s, std::function<void(raw_ostream &o)> detailCallback) {
37 Aggregation[std::string(s)]++;
38 if (GetOS())
39 detailCallback(*Out);
40 }
41
43 std::function<void(StringRef, unsigned)> handleCounts) const {
44 for (auto &&[name, count] : Aggregation)
45 handleCounts(name, count);
46 }
47
48 raw_ostream *GetOS() const { return Out; }
49
50 // You can just use the stream, and if it's null, nothing happens.
51 // Don't do a lot of stuff like this, but it's convenient for silly stuff.
52 // It doesn't work with things that have custom insertion operators, though.
53 template <typename T> OutputAggregator &operator<<(T &&value) {
54 if (Out != nullptr)
55 *Out << value;
56 return *this;
57 }
58
59 // For multi-threaded usage, we can collect stuff in another aggregator,
60 // then merge it in here
61 void Merge(const OutputAggregator &other) {
62 for (auto &&[name, count] : other.Aggregation) {
63 auto it = Aggregation.find(name);
64 if (it == Aggregation.end())
65 Aggregation.emplace(name, count);
66 else
67 it->second += count;
68 }
69 }
70};
71
72} // namespace gsym
73} // namespace llvm
74
75#endif // LLVM_DEBUGINFO_GSYM_OUTPUTAGGREGATOR_H
Given that RA is a live value
static const char * name
Definition: SMEABIPass.cpp:49
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
void Report(StringRef s, std::function< void(raw_ostream &o)> detailCallback)
OutputAggregator(raw_ostream *out)
OutputAggregator & operator<<(T &&value)
void EnumerateResults(std::function< void(StringRef, unsigned)> handleCounts) const
std::map< std::string, unsigned > Aggregation
raw_ostream * GetOS() const
void Merge(const OutputAggregator &other)
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
auto count(R &&Range, const E &Element)
Wrapper function around std::count to count the number of times an element Element occurs in the give...
Definition: STLExtras.h:1914