blob: 029d75660a73ffdc18c27106f1d439cd90b7d880 [file] [log] [blame]
Justin Bognerb9bd7f82014-03-21 17:46:22 +00001//=-- InstrProfWriter.cpp - Instrumented profiling writer -------------------=//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file contains support for writing profiling data for clang's
11// instrumentation based PGO and coverage.
12//
13//===----------------------------------------------------------------------===//
14
15#include "llvm/ProfileData/InstrProfWriter.h"
Eugene Zelenkocdc71612016-08-11 17:20:18 +000016#include "llvm/ADT/StringRef.h"
17#include "llvm/IR/ProfileSummary.h"
18#include "llvm/ProfileData/ProfileCommon.h"
Justin Bognerb7aa2632014-04-18 21:48:40 +000019#include "llvm/Support/EndianStream.h"
Eugene Zelenkocdc71612016-08-11 17:20:18 +000020#include "llvm/Support/MemoryBuffer.h"
Justin Bognerb7aa2632014-04-18 21:48:40 +000021#include "llvm/Support/OnDiskHashTable.h"
Eugene Zelenkocdc71612016-08-11 17:20:18 +000022#include "llvm/Support/raw_ostream.h"
23#include <algorithm>
24#include <string>
Reid Kleckner437b1b32015-11-20 19:29:40 +000025#include <tuple>
Eugene Zelenkocdc71612016-08-11 17:20:18 +000026#include <utility>
27#include <vector>
Justin Bognerb7aa2632014-04-18 21:48:40 +000028
Justin Bognerb9bd7f82014-03-21 17:46:22 +000029using namespace llvm;
30
Xinliang David Lib6066382016-01-15 19:01:04 +000031// A struct to define how the data stream should be patched. For Indexed
32// profiling, only uint64_t data type is needed.
33struct PatchItem {
34 uint64_t Pos; // Where to patch.
35 uint64_t *D; // Pointer to an array of source data.
36 int N; // Number of elements in \c D array.
37};
38
39namespace llvm {
Eugene Zelenkocdc71612016-08-11 17:20:18 +000040
Xinliang David Lib6066382016-01-15 19:01:04 +000041// A wrapper class to abstract writer stream with support of bytes
42// back patching.
Xinliang David Li285d7bd2016-01-15 19:22:41 +000043class ProfOStream {
Xinliang David Lib6066382016-01-15 19:01:04 +000044
Xinliang David Li285d7bd2016-01-15 19:22:41 +000045public:
Xinliang David Lib6066382016-01-15 19:01:04 +000046 ProfOStream(llvm::raw_fd_ostream &FD) : IsFDOStream(true), OS(FD), LE(FD) {}
47 ProfOStream(llvm::raw_string_ostream &STR)
48 : IsFDOStream(false), OS(STR), LE(STR) {}
49
50 uint64_t tell() { return OS.tell(); }
51 void write(uint64_t V) { LE.write<uint64_t>(V); }
Eugene Zelenkocdc71612016-08-11 17:20:18 +000052
Xinliang David Lib6066382016-01-15 19:01:04 +000053 // \c patch can only be called when all data is written and flushed.
54 // For raw_string_ostream, the patch is done on the target string
55 // directly and it won't be reflected in the stream's internal buffer.
56 void patch(PatchItem *P, int NItems) {
57 using namespace support;
58 if (IsFDOStream) {
59 llvm::raw_fd_ostream &FDOStream = static_cast<llvm::raw_fd_ostream &>(OS);
60 for (int K = 0; K < NItems; K++) {
61 FDOStream.seek(P[K].Pos);
62 for (int I = 0; I < P[K].N; I++)
63 write(P[K].D[I]);
64 }
65 } else {
66 llvm::raw_string_ostream &SOStream =
67 static_cast<llvm::raw_string_ostream &>(OS);
68 std::string &Data = SOStream.str(); // with flush
69 for (int K = 0; K < NItems; K++) {
70 for (int I = 0; I < P[K].N; I++) {
71 uint64_t Bytes = endian::byte_swap<uint64_t, little>(P[K].D[I]);
72 Data.replace(P[K].Pos + I * sizeof(uint64_t), sizeof(uint64_t),
73 (const char *)&Bytes, sizeof(uint64_t));
74 }
75 }
76 }
77 }
Eugene Zelenkocdc71612016-08-11 17:20:18 +000078
Xinliang David Lib6066382016-01-15 19:01:04 +000079 // If \c OS is an instance of \c raw_fd_ostream, this field will be
80 // true. Otherwise, \c OS will be an raw_string_ostream.
81 bool IsFDOStream;
82 raw_ostream &OS;
83 support::endian::Writer<support::little> LE;
84};
Xinliang David Lib6066382016-01-15 19:01:04 +000085
Xinliang David Lie1574f02016-01-22 20:25:56 +000086class InstrProfRecordWriterTrait {
Justin Bognerb7aa2632014-04-18 21:48:40 +000087public:
88 typedef StringRef key_type;
89 typedef StringRef key_type_ref;
90
Justin Bogner9e9a0572015-09-29 22:13:58 +000091 typedef const InstrProfWriter::ProfilingData *const data_type;
92 typedef const InstrProfWriter::ProfilingData *const data_type_ref;
Justin Bognerb7aa2632014-04-18 21:48:40 +000093
94 typedef uint64_t hash_value_type;
95 typedef uint64_t offset_type;
96
Xinliang David Lie1574f02016-01-22 20:25:56 +000097 support::endianness ValueProfDataEndianness;
Easwaran Ramane5a17e32016-05-19 21:07:12 +000098 InstrProfSummaryBuilder *SummaryBuilder;
Xinliang David Lie1574f02016-01-22 20:25:56 +000099
100 InstrProfRecordWriterTrait() : ValueProfDataEndianness(support::little) {}
Justin Bognerb7aa2632014-04-18 21:48:40 +0000101 static hash_value_type ComputeHash(key_type_ref K) {
Xinliang David Li49ee76d2015-12-18 22:22:12 +0000102 return IndexedInstrProf::ComputeHash(K);
Justin Bognerb7aa2632014-04-18 21:48:40 +0000103 }
104
105 static std::pair<offset_type, offset_type>
106 EmitKeyDataLength(raw_ostream &Out, key_type_ref K, data_type_ref V) {
107 using namespace llvm::support;
108 endian::Writer<little> LE(Out);
109
Justin Bognere8081712014-04-19 00:33:15 +0000110 offset_type N = K.size();
Justin Bognerb7aa2632014-04-18 21:48:40 +0000111 LE.write<offset_type>(N);
112
Justin Bogner821d7472014-08-01 22:50:07 +0000113 offset_type M = 0;
Justin Bogner9e9a0572015-09-29 22:13:58 +0000114 for (const auto &ProfileData : *V) {
Xinliang David Li2004f002015-11-02 05:08:23 +0000115 const InstrProfRecord &ProfRecord = ProfileData.second;
Justin Bogner9e9a0572015-09-29 22:13:58 +0000116 M += sizeof(uint64_t); // The function hash
117 M += sizeof(uint64_t); // The size of the Counts vector
Xinliang David Li2004f002015-11-02 05:08:23 +0000118 M += ProfRecord.Counts.size() * sizeof(uint64_t);
Justin Bogner9e9a0572015-09-29 22:13:58 +0000119
120 // Value data
Xinliang David Li99556872015-11-17 23:00:40 +0000121 M += ValueProfData::getSize(ProfileData.second);
Justin Bogner9e9a0572015-09-29 22:13:58 +0000122 }
Justin Bognerb7aa2632014-04-18 21:48:40 +0000123 LE.write<offset_type>(M);
124
125 return std::make_pair(N, M);
126 }
127
Xinliang David Lie1574f02016-01-22 20:25:56 +0000128 void EmitKey(raw_ostream &Out, key_type_ref K, offset_type N) {
Justin Bognerb7aa2632014-04-18 21:48:40 +0000129 Out.write(K.data(), N);
130 }
131
Xinliang David Lie1574f02016-01-22 20:25:56 +0000132 void EmitData(raw_ostream &Out, key_type_ref, data_type_ref V, offset_type) {
Justin Bognerb7aa2632014-04-18 21:48:40 +0000133 using namespace llvm::support;
134 endian::Writer<little> LE(Out);
Justin Bogner9e9a0572015-09-29 22:13:58 +0000135 for (const auto &ProfileData : *V) {
Xinliang David Li2004f002015-11-02 05:08:23 +0000136 const InstrProfRecord &ProfRecord = ProfileData.second;
Easwaran Ramane5a17e32016-05-19 21:07:12 +0000137 SummaryBuilder->addRecord(ProfRecord);
Xinliang David Li2004f002015-11-02 05:08:23 +0000138
Justin Bogner9e9a0572015-09-29 22:13:58 +0000139 LE.write<uint64_t>(ProfileData.first); // Function hash
Xinliang David Li2004f002015-11-02 05:08:23 +0000140 LE.write<uint64_t>(ProfRecord.Counts.size());
Xinliang David Li6aa216c2015-11-06 07:54:21 +0000141 for (uint64_t I : ProfRecord.Counts)
142 LE.write<uint64_t>(I);
Justin Bogner9e9a0572015-09-29 22:13:58 +0000143
Justin Bogner9e9a0572015-09-29 22:13:58 +0000144 // Write value data
Xinliang David Li99556872015-11-17 23:00:40 +0000145 std::unique_ptr<ValueProfData> VDataPtr =
146 ValueProfData::serializeFrom(ProfileData.second);
Xinliang David Liee415892015-11-10 00:24:45 +0000147 uint32_t S = VDataPtr->getSize();
Xinliang David Li46ad3632016-01-22 19:53:31 +0000148 VDataPtr->swapBytesFromHost(ValueProfDataEndianness);
Xinliang David Liee415892015-11-10 00:24:45 +0000149 Out.write((const char *)VDataPtr.get(), S);
Justin Bogner821d7472014-08-01 22:50:07 +0000150 }
Justin Bognerb7aa2632014-04-18 21:48:40 +0000151 }
152};
Eugene Zelenkocdc71612016-08-11 17:20:18 +0000153
154} // end namespace llvm
Justin Bognerb7aa2632014-04-18 21:48:40 +0000155
Vedant Kumar00dab222016-01-29 22:54:45 +0000156InstrProfWriter::InstrProfWriter(bool Sparse)
Rong Xu33c76c02016-02-10 17:18:30 +0000157 : Sparse(Sparse), FunctionData(), ProfileKind(PF_Unknown),
Xinliang David Lie1574f02016-01-22 20:25:56 +0000158 InfoObj(new InstrProfRecordWriterTrait()) {}
159
160InstrProfWriter::~InstrProfWriter() { delete InfoObj; }
161
Xinliang David Li46ad3632016-01-22 19:53:31 +0000162// Internal interface for testing purpose only.
163void InstrProfWriter::setValueProfDataEndianness(
164 support::endianness Endianness) {
Xinliang David Lie1574f02016-01-22 20:25:56 +0000165 InfoObj->ValueProfDataEndianness = Endianness;
Xinliang David Liee415892015-11-10 00:24:45 +0000166}
Eugene Zelenkocdc71612016-08-11 17:20:18 +0000167
Vedant Kumar00dab222016-01-29 22:54:45 +0000168void InstrProfWriter::setOutputSparse(bool Sparse) {
169 this->Sparse = Sparse;
170}
Xinliang David Liee415892015-11-10 00:24:45 +0000171
Vedant Kumar9152fd12016-05-19 03:54:45 +0000172Error InstrProfWriter::addRecord(InstrProfRecord &&I, uint64_t Weight) {
Justin Bogner9e9a0572015-09-29 22:13:58 +0000173 auto &ProfileDataMap = FunctionData[I.Name];
174
Nathan Slingerlanda7318292015-11-20 19:12:43 +0000175 bool NewFunc;
176 ProfilingData::iterator Where;
177 std::tie(Where, NewFunc) =
178 ProfileDataMap.insert(std::make_pair(I.Hash, InstrProfRecord()));
179 InstrProfRecord &Dest = Where->second;
Nathan Slingerlandaa5702d2015-12-02 18:19:24 +0000180
Nathan Slingerlanda7318292015-11-20 19:12:43 +0000181 if (NewFunc) {
Justin Bogner821d7472014-08-01 22:50:07 +0000182 // We've never seen a function with this name and hash, add it.
Nathan Slingerlanda7318292015-11-20 19:12:43 +0000183 Dest = std::move(I);
Xinliang David Li60057282015-12-20 08:46:18 +0000184 // Fix up the name to avoid dangling reference.
185 Dest.Name = FunctionData.find(Dest.Name)->getKey();
Xinliang David Li51dc04c2016-01-08 03:49:59 +0000186 if (Weight > 1)
Vedant Kumar42369db2016-05-11 19:42:19 +0000187 Dest.scale(Weight);
Nathan Slingerlanda7318292015-11-20 19:12:43 +0000188 } else {
189 // We're updating a function we've seen before.
Vedant Kumar42369db2016-05-11 19:42:19 +0000190 Dest.merge(I, Weight);
Justin Bognerb9bd7f82014-03-21 17:46:22 +0000191 }
192
Xinliang David Li062cde92016-01-08 05:45:21 +0000193 Dest.sortValueData();
194
Vedant Kumar9152fd12016-05-19 03:54:45 +0000195 return Dest.takeError();
Justin Bognerb9bd7f82014-03-21 17:46:22 +0000196}
197
Vedant Kumare3a0bf52016-07-19 01:17:20 +0000198Error InstrProfWriter::mergeRecordsFromWriter(InstrProfWriter &&IPW) {
199 for (auto &I : IPW.FunctionData)
200 for (auto &Func : I.getValue())
201 if (Error E = addRecord(std::move(Func.second), 1))
202 return E;
203 return Error::success();
204}
205
Vedant Kumar00dab222016-01-29 22:54:45 +0000206bool InstrProfWriter::shouldEncodeData(const ProfilingData &PD) {
207 if (!Sparse)
208 return true;
209 for (const auto &Func : PD) {
210 const InstrProfRecord &IPR = Func.second;
David Majnemer0a16c222016-08-11 21:15:00 +0000211 if (any_of(IPR.Counts, [](uint64_t Count) { return Count > 0; }))
Vedant Kumar00dab222016-01-29 22:54:45 +0000212 return true;
213 }
214 return false;
215}
216
Xinliang David Li6c93ee82016-02-03 04:08:18 +0000217static void setSummary(IndexedInstrProf::Summary *TheSummary,
Easwaran Raman7cefdb82016-05-19 21:53:28 +0000218 ProfileSummary &PS) {
Xinliang David Li6c93ee82016-02-03 04:08:18 +0000219 using namespace IndexedInstrProf;
220 std::vector<ProfileSummaryEntry> &Res = PS.getDetailedSummary();
221 TheSummary->NumSummaryFields = Summary::NumKinds;
222 TheSummary->NumCutoffEntries = Res.size();
223 TheSummary->set(Summary::MaxFunctionCount, PS.getMaxFunctionCount());
Easwaran Raman7cefdb82016-05-19 21:53:28 +0000224 TheSummary->set(Summary::MaxBlockCount, PS.getMaxCount());
225 TheSummary->set(Summary::MaxInternalBlockCount, PS.getMaxInternalCount());
Xinliang David Li6c93ee82016-02-03 04:08:18 +0000226 TheSummary->set(Summary::TotalBlockCount, PS.getTotalCount());
Easwaran Raman7cefdb82016-05-19 21:53:28 +0000227 TheSummary->set(Summary::TotalNumBlocks, PS.getNumCounts());
Xinliang David Li6c93ee82016-02-03 04:08:18 +0000228 TheSummary->set(Summary::TotalNumFunctions, PS.getNumFunctions());
229 for (unsigned I = 0; I < Res.size(); I++)
230 TheSummary->setEntry(I, Res[I]);
231}
232
Xinliang David Lib6066382016-01-15 19:01:04 +0000233void InstrProfWriter::writeImpl(ProfOStream &OS) {
Xinliang David Lie1574f02016-01-22 20:25:56 +0000234 OnDiskChainedHashTableGenerator<InstrProfRecordWriterTrait> Generator;
Xinliang David Li6c93ee82016-02-03 04:08:18 +0000235
236 using namespace IndexedInstrProf;
Easwaran Ramane5a17e32016-05-19 21:07:12 +0000237 InstrProfSummaryBuilder ISB(ProfileSummaryBuilder::DefaultCutoffs);
238 InfoObj->SummaryBuilder = &ISB;
Xinliang David Li6c93ee82016-02-03 04:08:18 +0000239
Justin Bognerb7aa2632014-04-18 21:48:40 +0000240 // Populate the hash table generator.
Justin Bogner821d7472014-08-01 22:50:07 +0000241 for (const auto &I : FunctionData)
Vedant Kumar00dab222016-01-29 22:54:45 +0000242 if (shouldEncodeData(I.getValue()))
243 Generator.insert(I.getKey(), &I.getValue());
Justin Bognerb7aa2632014-04-18 21:48:40 +0000244 // Write the header.
Xinliang David Lidab183ed2015-10-18 01:02:29 +0000245 IndexedInstrProf::Header Header;
246 Header.Magic = IndexedInstrProf::Magic;
Xinliang David Lia6b2c4f2016-01-14 02:47:01 +0000247 Header.Version = IndexedInstrProf::ProfVersion::CurrentVersion;
Rong Xu33c76c02016-02-10 17:18:30 +0000248 if (ProfileKind == PF_IRLevel)
249 Header.Version |= VARIANT_MASK_IR_PROF;
Xinliang David Li6c93ee82016-02-03 04:08:18 +0000250 Header.Unused = 0;
Xinliang David Lidab183ed2015-10-18 01:02:29 +0000251 Header.HashType = static_cast<uint64_t>(IndexedInstrProf::HashType);
252 Header.HashOffset = 0;
253 int N = sizeof(IndexedInstrProf::Header) / sizeof(uint64_t);
254
Xinliang David Li3c882882016-02-03 06:24:11 +0000255 // Only write out all the fields except 'HashOffset'. We need
Xinliang David Lidab183ed2015-10-18 01:02:29 +0000256 // to remember the offset of that field to allow back patching
257 // later.
258 for (int I = 0; I < N - 1; I++)
Xinliang David Lib6066382016-01-15 19:01:04 +0000259 OS.write(reinterpret_cast<uint64_t *>(&Header)[I]);
Justin Bognerb7aa2632014-04-18 21:48:40 +0000260
Xinliang David Li6c93ee82016-02-03 04:08:18 +0000261 // Save the location of Header.HashOffset field in \c OS.
262 uint64_t HashTableStartFieldOffset = OS.tell();
Xinliang David Lidab183ed2015-10-18 01:02:29 +0000263 // Reserve the space for HashOffset field.
Xinliang David Lib6066382016-01-15 19:01:04 +0000264 OS.write(0);
Xinliang David Li6c93ee82016-02-03 04:08:18 +0000265
266 // Reserve space to write profile summary data.
Easwaran Ramane5a17e32016-05-19 21:07:12 +0000267 uint32_t NumEntries = ProfileSummaryBuilder::DefaultCutoffs.size();
Xinliang David Li6c93ee82016-02-03 04:08:18 +0000268 uint32_t SummarySize = Summary::getSize(Summary::NumKinds, NumEntries);
269 // Remember the summary offset.
270 uint64_t SummaryOffset = OS.tell();
271 for (unsigned I = 0; I < SummarySize / sizeof(uint64_t); I++)
272 OS.write(0);
273
Justin Bognerb7aa2632014-04-18 21:48:40 +0000274 // Write the hash table.
Xinliang David Lie1574f02016-01-22 20:25:56 +0000275 uint64_t HashTableStart = Generator.Emit(OS.OS, *InfoObj);
Justin Bognerb7aa2632014-04-18 21:48:40 +0000276
Xinliang David Li6c93ee82016-02-03 04:08:18 +0000277 // Allocate space for data to be serialized out.
278 std::unique_ptr<IndexedInstrProf::Summary> TheSummary =
279 IndexedInstrProf::allocSummary(SummarySize);
280 // Compute the Summary and copy the data to the data
281 // structure to be serialized out (to disk or buffer).
Benjamin Kramer38de59e2016-05-20 09:18:37 +0000282 std::unique_ptr<ProfileSummary> PS = ISB.getSummary();
Easwaran Raman7cefdb82016-05-19 21:53:28 +0000283 setSummary(TheSummary.get(), *PS);
Eugene Zelenkocdc71612016-08-11 17:20:18 +0000284 InfoObj->SummaryBuilder = nullptr;
Xinliang David Li6c93ee82016-02-03 04:08:18 +0000285
Xinliang David Lib6066382016-01-15 19:01:04 +0000286 // Now do the final patch:
Xinliang David Li6c93ee82016-02-03 04:08:18 +0000287 PatchItem PatchItems[] = {
288 // Patch the Header.HashOffset field.
289 {HashTableStartFieldOffset, &HashTableStart, 1},
290 // Patch the summary data.
291 {SummaryOffset, reinterpret_cast<uint64_t *>(TheSummary.get()),
292 (int)(SummarySize / sizeof(uint64_t))}};
Xinliang David Lib6066382016-01-15 19:01:04 +0000293 OS.patch(PatchItems, sizeof(PatchItems) / sizeof(*PatchItems));
Justin Bogner2b6c5372015-02-18 01:58:17 +0000294}
295
296void InstrProfWriter::write(raw_fd_ostream &OS) {
297 // Write the hash table.
Xinliang David Lib6066382016-01-15 19:01:04 +0000298 ProfOStream POS(OS);
299 writeImpl(POS);
300}
Justin Bogner2b6c5372015-02-18 01:58:17 +0000301
Xinliang David Lib6066382016-01-15 19:01:04 +0000302std::unique_ptr<MemoryBuffer> InstrProfWriter::writeBuffer() {
303 std::string Data;
304 llvm::raw_string_ostream OS(Data);
305 ProfOStream POS(OS);
306 // Write the hash table.
307 writeImpl(POS);
308 // Return this in an aligned memory buffer.
309 return MemoryBuffer::getMemBufferCopy(Data);
Justin Bogner2b6c5372015-02-18 01:58:17 +0000310}
311
Xinliang David Lie3bf4fd32015-12-14 18:44:01 +0000312static const char *ValueProfKindStr[] = {
313#define VALUE_PROF_KIND(Enumerator, Value) #Enumerator,
314#include "llvm/ProfileData/InstrProfData.inc"
315};
316
Xinliang David Li6f7c19a2015-11-23 20:47:38 +0000317void InstrProfWriter::writeRecordInText(const InstrProfRecord &Func,
Xinliang David Lia716cc52015-12-20 06:22:13 +0000318 InstrProfSymtab &Symtab,
Xinliang David Li6f7c19a2015-11-23 20:47:38 +0000319 raw_fd_ostream &OS) {
Xinliang David Lic6676832015-11-23 22:31:22 +0000320 OS << Func.Name << "\n";
321 OS << "# Func Hash:\n" << Func.Hash << "\n";
Xinliang David Lie3bf4fd32015-12-14 18:44:01 +0000322 OS << "# Num Counters:\n" << Func.Counts.size() << "\n";
Xinliang David Lic6676832015-11-23 22:31:22 +0000323 OS << "# Counter Values:\n";
Xinliang David Li6f7c19a2015-11-23 20:47:38 +0000324 for (uint64_t Count : Func.Counts)
325 OS << Count << "\n";
326
Xinliang David Lie3bf4fd32015-12-14 18:44:01 +0000327 uint32_t NumValueKinds = Func.getNumValueKinds();
328 if (!NumValueKinds) {
329 OS << "\n";
330 return;
331 }
332
333 OS << "# Num Value Kinds:\n" << Func.getNumValueKinds() << "\n";
334 for (uint32_t VK = 0; VK < IPVK_Last + 1; VK++) {
335 uint32_t NS = Func.getNumValueSites(VK);
336 if (!NS)
337 continue;
338 OS << "# ValueKind = " << ValueProfKindStr[VK] << ":\n" << VK << "\n";
339 OS << "# NumValueSites:\n" << NS << "\n";
340 for (uint32_t S = 0; S < NS; S++) {
341 uint32_t ND = Func.getNumValueDataForSite(VK, S);
342 OS << ND << "\n";
343 std::unique_ptr<InstrProfValueData[]> VD = Func.getValueForSite(VK, S);
344 for (uint32_t I = 0; I < ND; I++) {
345 if (VK == IPVK_IndirectCallTarget)
Xinliang David Lia716cc52015-12-20 06:22:13 +0000346 OS << Symtab.getFuncName(VD[I].Value) << ":" << VD[I].Count << "\n";
Xinliang David Lie3bf4fd32015-12-14 18:44:01 +0000347 else
348 OS << VD[I].Value << ":" << VD[I].Count << "\n";
349 }
350 }
351 }
352
Xinliang David Li6f7c19a2015-11-23 20:47:38 +0000353 OS << "\n";
354}
355
356void InstrProfWriter::writeText(raw_fd_ostream &OS) {
Rong Xu33c76c02016-02-10 17:18:30 +0000357 if (ProfileKind == PF_IRLevel)
358 OS << "# IR level Instrumentation Flag\n:ir\n";
Xinliang David Lia716cc52015-12-20 06:22:13 +0000359 InstrProfSymtab Symtab;
360 for (const auto &I : FunctionData)
Vedant Kumar00dab222016-01-29 22:54:45 +0000361 if (shouldEncodeData(I.getValue()))
362 Symtab.addFuncName(I.getKey());
Xinliang David Lia716cc52015-12-20 06:22:13 +0000363 Symtab.finalizeSymtab();
364
Xinliang David Li6f7c19a2015-11-23 20:47:38 +0000365 for (const auto &I : FunctionData)
Vedant Kumar00dab222016-01-29 22:54:45 +0000366 if (shouldEncodeData(I.getValue()))
367 for (const auto &Func : I.getValue())
368 writeRecordInText(Func.second, Symtab, OS);
Xinliang David Li6f7c19a2015-11-23 20:47:38 +0000369}