LLVM: include/llvm/ProfileData/SampleProfWriter.h Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12#ifndef LLVM_PROFILEDATA_SAMPLEPROFWRITER_H

13#define LLVM_PROFILEDATA_SAMPLEPROFWRITER_H

14

21#include

22#include

23#include

24#include <system_error>

25

26namespace llvm {

27namespace sampleprof {

28

31

32

33

36};

37

38

39

40

41

43protected:

46

47public:

48

49

50

51

54

56

57

58

59

60

61

62

63

64

65 virtual void Erase(size_t CurrentOutputSize) = 0;

66};

67

69 std::vector SortedFunctions;

70

71public:

74

75

76

77

78

79

80

81

82

83

84

85 void Erase(size_t CurrentOutputSize) override;

86};

87

88

90public:

92

93

94

95

97

98

99

100

102

103

104

105

106

107 template

109 size_t OutputSizeLimit) {

112 }

113

115

116

117

118

121

122

123

126

132

133protected:

136

137

139

140

142

144 size_t OutputSizeLimit,

146

147

148

149

151

152

154

155

156 std::unique_ptr Summary;

157

158

160

161

163};

164

165

167public:

169

170protected:

173

177 }

178

180 MarkFlatProfiles = true;

181 }

182

183private:

184

185

186

187 unsigned Indent = 0;

188

189

190

191

192

193 bool MarkFlatProfiles = false;

194

198};

199

200

202public:

205

207

208protected:

218 std::set &V);

219

221

225

226private:

230};

231

234};

235

236const std::array<SmallVector<SecHdrTableEntry, 8>, NumOfLayout>

238

239

240

241

242

243

244

252

255

256

259

260

265};

266

269public:

271

275

276

278 UseMD5 = true;

280

281

283 }

284

285

286

287

290 }

291

293 ProfSymList = PSL;

294 };

295

298 }

299

302#ifndef NDEBUG

303

305 assert(Entry.Flags == 0 &&

306 "resetSecLayout has to be called before any flag setting");

307 }

308#endif

311 }

312

313protected:

317 template

320 if (Entry.Type == Type)

322 }

323 }

324 template

327 }

328

330

331

333

335

336

338

339

340

343

344

349

352

353

357

359

360

361

362

365

366

367

368

370

371private:

372 void allocSecHdrTable();

373 std::error_code writeSecHdrTable();

374 std::error_code writeHeader(const SampleProfileMap &ProfileMap) override;

375 std::error_code compressAndOutput();

376

377

378

379

380

381

382

383

384

385 std::unique_ptr<raw_ostream> LocalBufStream;

386

388

389

391

392

393

394

395 std::vector SecHdrTable;

396

397

398

400

401 bool UseMD5 = false;

402

403

404

406

408};

409

411public:

414

415private:

416 std::error_code writeDefaultLayout(const SampleProfileMap &ProfileMap);

417 std::error_code writeCtxSplitLayout(const SampleProfileMap &ProfileMap);

418

419 std::error_code writeSections(const SampleProfileMap &ProfileMap) override;

420

421 std::error_code writeCustomSection(SecType Type) override {

423 };

424

425 void verifySecLayout(SectionLayout SL) override {

427 "Unsupported layout");

428 }

429};

430

431}

432}

433

434#endif

Provides ErrorOr smart pointer.

This file implements a map that provides insertion order iteration.

assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())

Represents either an error or a value T.

This class implements a map that also provides access to all stored values in a deterministic order.

This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.

StringRef - Represent a constant reference to a string, i.e.

The instances of the Type class are immutable: once they are created, they are never changed.

This class implements an extremely fast bulk output stream that can only output to a stream.

void Erase(size_t CurrentOutputSize) override

In this default implementation, functions with fewest samples are dropped first.

This class represents a function that is read from a sample profile.

When writing a profile with size limit, user may want to use a different strategy to reduce function ...

virtual void Erase(size_t CurrentOutputSize)=0

SampleProfileWriter::writeWithSizeLimit() calls this after every write iteration if the output size s...

virtual ~FunctionPruningStrategy()=default

FunctionPruningStrategy(SampleProfileMap &ProfileMap, size_t OutputSizeLimit)

ProfileMap A reference to the original profile map.

SampleProfileMap & ProfileMap

Representation of the samples collected for a function.

ProfileSymbolList records the list of function symbols shown up in the binary used to generate the pr...

This class provides operator overloads to the map container using MD5 as the key type,...

Sample-based profile writer (binary format).

SampleProfileWriterBinary(std::unique_ptr< raw_ostream > &OS)

void stablizeNameTable(MapVector< FunctionId, uint32_t > &NameTable, std::set< FunctionId > &V)

virtual void addContext(const SampleContext &Context)

virtual std::error_code writeNameTable()

virtual std::error_code writeMagicIdent(SampleProfileFormat Format)

std::error_code writeSummary()

MapVector< FunctionId, uint32_t > NameTable

void addNames(const FunctionSamples &S)

virtual std::error_code writeContextIdx(const SampleContext &Context)

std::error_code writeSample(const FunctionSamples &S) override

Write samples of a top-level function to a binary file.

std::error_code writeHeader(const SampleProfileMap &ProfileMap) override

Write a file header for the profile file.

virtual MapVector< FunctionId, uint32_t > & getNameTable()

std::error_code writeBody(const FunctionSamples &S)

std::error_code writeNameIdx(FunctionId FName)

void addName(FunctionId FName)

std::error_code writeNameTableSection(const SampleProfileMap &ProfileMap)

void setUseCtxSplitLayout() override

SmallVector< SecHdrTableEntry, 8 > SectionHdrLayout

void setUseMD5() override

std::error_code writeFuncMetadata(const SampleProfileMap &Profiles)

void setToCompressSection(SecType Type)

virtual std::error_code writeCustomSection(SecType Type)=0

virtual std::error_code writeOneSection(SecType Type, uint32_t LayoutIdx, const SampleProfileMap &ProfileMap)

std::error_code writeFuncOffsetTable()

std::error_code writeCSNameTableSection()

std::error_code writeCSNameIdx(const SampleContext &Context)

virtual void verifySecLayout(SectionLayout SL)=0

void setProfileSymbolList(ProfileSymbolList *PSL) override

void setPartialProfile() override

virtual std::error_code writeSections(const SampleProfileMap &ProfileMap)=0

std::error_code writeNameTable() override

void resetSecLayout(SectionLayout SL)

void addSectionFlag(SecType Type, SecFlagType Flag)

std::error_code writeProfileSymbolListSection()

uint64_t markSectionStart(SecType Type, uint32_t LayoutIdx)

Return the current position and prepare to use it as the start position of a section given the sectio...

void addContext(const SampleContext &Context) override

std::error_code addNewSection(SecType Sec, uint32_t LayoutIdx, uint64_t SectionStart)

Add a new section into section header table given the section type Type, its position LayoutIdx in Se...

void setToCompressAllSections() override

void addSectionFlag(uint32_t SectionIdx, SecFlagType Flag)

uint64_t SecLBRProfileStart

std::error_code write(const SampleProfileMap &ProfileMap) override

Write all the sample profiles in the given map of samples.

std::error_code writeContextIdx(const SampleContext &Context) override

std::error_code writeSample(const FunctionSamples &S) override

Write samples of a top-level function to a binary file.

SampleProfileWriterExtBinary(std::unique_ptr< raw_ostream > &OS)

Sample-based profile writer (text format).

SampleProfileWriterText(std::unique_ptr< raw_ostream > &OS)

std::error_code writeHeader(const SampleProfileMap &ProfileMap) override

Write a file header for the profile file.

void setUseCtxSplitLayout() override

std::error_code writeSample(const FunctionSamples &S) override

Write samples to a text file.

Sample-based profile writer. Base class.

virtual void setUseCtxSplitLayout()

SampleProfileWriter(std::unique_ptr< raw_ostream > &OS)

std::unique_ptr< ProfileSummary > Summary

Profile summary.

virtual std::error_code writeSample(const FunctionSamples &S)=0

Write sample profiles in S.

SampleProfileFormat Format

Profile format.

std::error_code writeWithSizeLimitInternal(SampleProfileMap &ProfileMap, size_t OutputSizeLimit, FunctionPruningStrategy *Strategy)

raw_ostream & getOutputStream()

void computeSummary(const SampleProfileMap &ProfileMap)

Compute summary for this profile.

virtual void setPartialProfile()

virtual std::error_code writeFuncProfiles(const SampleProfileMap &ProfileMap)

std::unique_ptr< raw_ostream > OutputStream

Output stream where to emit the profile to.

virtual void setToCompressAllSections()

std::error_code writeWithSizeLimit(SampleProfileMap &ProfileMap, size_t OutputSizeLimit)

Write sample profiles up to given size limit, using the pruning strategy to drop some functions if ne...

virtual void setProfileSymbolList(ProfileSymbolList *PSL)

size_t LineCount

For writeWithSizeLimit in text mode, each newline takes 1 additional byte on Windows when actually wr...

static ErrorOr< std::unique_ptr< SampleProfileWriter > > create(StringRef Filename, SampleProfileFormat Format)

Profile writer factory.

virtual std::error_code writeHeader(const SampleProfileMap &ProfileMap)=0

Write a file header for the profile file.

virtual ~SampleProfileWriter()=default

virtual std::error_code write(const SampleProfileMap &ProfileMap)

Write all the sample profiles in the given map of samples.

static void addSecFlag(SecHdrTableEntry &Entry, SecFlagType Flag)

const std::array< SmallVector< SecHdrTableEntry, 8 >, NumOfLayout > ExtBinaryHdrLayoutTable

@ SecFlagPartial

SecFlagPartial means the profile is for common/shared code.

This is an optimization pass for GlobalISel generic memory operations.

OutputIt move(R &&Range, OutputIt Out)

Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.

Implement std::hash so that hash_code can be used in STL containers.