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

22#include

23#include

24#include

25#include <system_error>

26

27namespace llvm {

29

38

39

40

41

42

44protected:

47

48public:

49

50

51

52

55

57

58

59

60

61

62

63

64

65

66 virtual void Erase(size_t CurrentOutputSize) = 0;

67};

68

70 std::vector SortedFunctions;

71

72public:

75

76

77

78

79

80

81

82

83

84

85

86 void Erase(size_t CurrentOutputSize) override;

87};

88

89

91public:

93

94

95

96

98

99

100

101

103

104

105

106

107

108 template

110 size_t OutputSizeLimit) {

113 }

114

116

117

118

119

122

123

124

127

133

134protected:

137

138

140

141

143

145 size_t OutputSizeLimit,

147

148

149

150

152

153

155

156

157 std::unique_ptr Summary;

158

159

161

162

164};

165

166

168public:

170

171protected:

174

179

181 MarkFlatProfiles = true;

182 }

183

184private:

185

186

187

188 unsigned Indent = 0;

189

190

191

192

193

194 bool MarkFlatProfiles = false;

195

199};

200

201

203public:

206

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

208

209protected:

212 virtual std::error_code writeNameTable();

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

214 std::error_code writeSummary();

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

216 std::error_code writeNameIdx(FunctionId FName);

219 std::set &V);

220

222

226

227

228 std::error_code

231

233

234private:

238};

239

243

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

246

247

248

249

250

251

252

260

263

264

267

268

273};

274

276 : public SampleProfileWriterBinary {

278public:

280

284

285

287 UseMD5 = true;

289

290

292 }

293

294

295

296

300

302 ProfSymList = PSL;

303 };

304

308

311#ifndef NDEBUG

312

314 assert(Entry.Flags == 0 &&

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

316 }

317#endif

320 }

321

322protected:

324 std::error_code addNewSection(SecType Sec, uint32_t LayoutIdx,

326 template

329 if (Entry.Type == Type)

331 }

332 }

333 template

337

338 void addContext(const SampleContext &Context) override;

339

340

342

344

345

347

348

349

352

353

358

361

362

366

368

369

370

371

374

375

376

377

379

380private:

381 void allocSecHdrTable();

382 std::error_code writeSecHdrTable();

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

384 std::error_code compressAndOutput();

385

386

387

388

389

390

391

392

393

394 std::unique_ptr<raw_ostream> LocalBufStream;

395

397

398

400

401

402

403

404 std::vector SecHdrTable;

405

406

407

409

410 bool UseMD5 = false;

411

412

413

415

417};

418

421public:

423

424private:

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

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

427

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

429

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

432 };

433

434 void verifySecLayout(SectionLayout SL) override {

436 "Unsupported layout");

437 }

438};

439

440}

441}

442

443#endif

assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")

Provides ErrorOr smart pointer.

This file implements a map that provides insertion order iteration.

static void write(bool isBE, void *P, T V)

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.

DefaultFunctionPruningStrategy(SampleProfileMap &ProfileMap, size_t OutputSizeLimit)

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 ...

Definition SampleProfWriter.h:43

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.

Definition SampleProfWriter.h:53

SampleProfileMap & ProfileMap

Definition SampleProfWriter.h:45

size_t OutputSizeLimit

Definition SampleProfWriter.h:46

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,...

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

Definition SampleProfWriter.h:204

virtual void addContext(const SampleContext &Context)

bool WriteVTableProf

Definition SampleProfWriter.h:232

MapVector< FunctionId, uint32_t > NameTable

Definition SampleProfWriter.h:221

void addNames(const FunctionSamples &S)

std::error_code writeCallsiteVTableProf(const CallsiteTypeMap &CallsiteTypeMap, raw_ostream &OS)

Write CallsiteTypeMap to the output stream OS.

virtual MapVector< FunctionId, uint32_t > & getNameTable()

Definition SampleProfWriter.h:210

void addName(FunctionId FName)

Definition SampleProfWriter.h:276

std::error_code writeNameTableSection(const SampleProfileMap &ProfileMap)

void setUseCtxSplitLayout() override

Definition SampleProfWriter.h:305

SmallVector< SecHdrTableEntry, 8 > SectionHdrLayout

Definition SampleProfWriter.h:372

void setUseMD5() override

Definition SampleProfWriter.h:286

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

Definition SampleProfWriter.h:301

void setPartialProfile() override

Definition SampleProfWriter.h:297

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

std::error_code writeNameTable() override

void resetSecLayout(SectionLayout SL)

Definition SampleProfWriter.h:309

void addSectionFlag(SecType Type, SecFlagType Flag)

Definition SampleProfWriter.h:327

std::error_code writeProfileSymbolListSection()

SectionLayout SecLayout

Definition SampleProfWriter.h:367

void setToCompressAllSections() override

void addSectionFlag(uint32_t SectionIdx, SecFlagType Flag)

Definition SampleProfWriter.h:334

uint64_t SecLBRProfileStart

Definition SampleProfWriter.h:378

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)

Definition SampleProfWriter.h:240

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

Definition SampleProfWriter.h:172

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

Write a file header for the profile file.

Definition SampleProfWriter.h:175

void setUseCtxSplitLayout() override

Definition SampleProfWriter.h:180

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

Write samples to a text file.

virtual void setUseCtxSplitLayout()

Definition SampleProfWriter.h:132

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

Definition SampleProfWriter.h:135

std::unique_ptr< ProfileSummary > Summary

Profile summary.

Definition SampleProfWriter.h:157

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

Write sample profiles in S.

SampleProfileFormat Format

Profile format.

Definition SampleProfWriter.h:163

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

raw_ostream & getOutputStream()

Definition SampleProfWriter.h:115

void computeSummary(const SampleProfileMap &ProfileMap)

Compute summary for this profile.

virtual void setPartialProfile()

Definition SampleProfWriter.h:131

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

std::unique_ptr< raw_ostream > OutputStream

Output stream where to emit the profile to.

Definition SampleProfWriter.h:154

virtual void setToCompressAllSections()

Definition SampleProfWriter.h:129

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...

Definition SampleProfWriter.h:109

virtual void setProfileSymbolList(ProfileSymbolList *PSL)

Definition SampleProfWriter.h:128

virtual void setUseMD5()

Definition SampleProfWriter.h:130

size_t LineCount

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

Definition SampleProfWriter.h:151

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

static void addSecFlag(SecHdrTableEntry &Entry, SecFlagType Flag)

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

Definition SampleProfWriter.h:245

@ SecFlagPartial

SecFlagPartial means the profile is for common/shared code.

SectionLayout

Definition SampleProfWriter.h:30

@ CtxSplitLayout

Definition SampleProfWriter.h:35

@ DefaultLayout

Definition SampleProfWriter.h:31

@ NumOfLayout

Definition SampleProfWriter.h:36

std::map< LineLocation, TypeCountMap > CallsiteTypeMap

This is an optimization pass for GlobalISel generic memory operations.

class LLVM_GSL_OWNER SmallVector

Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...

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.