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

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

197

198

199

200

201

202

203

204

205

206

207

208

209

210

211

212

213

214

215

216

217

218

219

220

221

222

223

224

225#ifndef LLVM_PROFILEDATA_SAMPLEPROFREADER_H

226#define LLVM_PROFILEDATA_SAMPLEPROFREADER_H

227

241#include

242#include

243#include

244#include

245#include

246#include <system_error>

247#include

248

249namespace llvm {

250

253

254namespace vfs {

256}

257

259

261

262

263

264

266public:

268 std::unique_ptr SRR,

270 : Buffer(std::move(B)), Remappings(std::move(SRR)), Reader(R) {

271 assert(Remappings && "Remappings cannot be nullptr");

272 }

273

274

275

279

280

281

285

286

288

290

291

292 void insert(StringRef FunctionName) { Remappings->insert(FunctionName); }

293

294

295

297 return Remappings->lookup(FunctionName);

298 }

299

300

301

303

304private:

305

306 std::unique_ptr Buffer;

307 std::unique_ptr Remappings;

308

309

310

312

314

315

316 bool RemappingApplied = false;

317};

318

319

320

321

322

323

324

325

326

327

328

329

330

331

332

333

334

335

336

337

338

339

340

341

342

343

344

345

347public:

351

353

354

356

357

358

359

363

364

365

368 return 0xFFFFFFFF;

371 }

372

373

375 if (std::error_code EC = readImpl())

376 return EC;

381 }

382

383

393

394

396

397

400

401

402

403

404

406

407

409

410

412

413

421

422

426 return &It->second;

427

431 Fname = R->second.stringRef();

434 return &It->second;

435 }

436 }

437

439 if (auto NameInProfile = Remapper->lookUpNameInProfile(Fname)) {

442 return &It->second;

443 }

444 }

445 return nullptr;

446 }

447

448

450

451

454 LineNumber, Msg));

455 }

456

457

458

459

464

465

466

467

472

473

475

477

478

480

481

483

484

486

487

489

490

492

494 return nullptr;

495 };

496

497

498

499 virtual std::vector *getNameTable() { return nullptr; }

501

502

504

505

506

508

509

511

512

514

516

518

523

524protected:

525

526

527

528

529

531

532

534

535

536 std::unique_ptr Buffer;

537

538

539 std::unique_ptr Summary;

540

541

542 static std::unique_ptr

544 return std::move(Reader.Summary);

545 }

546

547

549

550

551

552

557

558 std::unique_ptr Remapper;

559

560

561

562

565

566

567

568 std::unordered_map<uint64_t, std::pair<const uint8_t *, const uint8_t *>>

570

572

573

575

576

578

579

581

582

584

585

587

588

590

591

592

594

595

597

598

599

600

602

603

604

606

607

608

610

611

612

614};

615

617public:

620

621

623

624

625 std::error_code readImpl() override;

626

627

628 static bool hasFormat(const MemoryBuffer &Buffer);

629

630

632

633private:

634

635

636 std::list CSNameTable;

637};

638

640public:

644

645

646 std::error_code readHeader() override;

647

648

649 std::error_code readImpl() override;

650

651

652

656

657protected:

658

659

660

661

662

663

664 template ErrorOr readNumber();

665

666

667

668 template ErrorOr readUnencodedNumber();

669

670

671

672

673

674

675

677

678

679 template inline ErrorOr<size_t> readStringIndex(T &Table);

680

681

682 std::error_code readFuncProfile(const uint8_t *Start);

683 std::error_code readFuncProfile(const uint8_t *Start,

685

686

688

689

690 std::error_code readMagicIdent();

691

692

693 std::error_code readSummary();

694

695

696 std::error_code readNameTable();

697

698

700

701

702

704

705

706

708

709

710 std::error_code readCallsiteVTableProf(FunctionSamples &FProfile);

711

712

713

714

715 std::error_code readVTableTypeCountMap(TypeCountMap &M);

716

717

719

720

722

723

725

726

727

729

730

731

732

734

735

736

737

738

740

741private:

742 std::error_code readSummaryEntry(std::vector &Entries);

743 virtual std::error_code verifySPMagic(uint64_t Magic) = 0;

744};

745

747private:

748 std::error_code verifySPMagic(uint64_t Magic) override;

749

750public:

754

755

756 static bool hasFormat(const MemoryBuffer &Buffer);

757};

758

759

760

761

762

763

764

765

766

767

768

769

770

771

772

773

774

775

776

777

780private:

781 std::error_code decompressSection(const uint8_t *SecStart,

783 const uint8_t *&DecompressBuf,

784 uint64_t &DecompressBufSize);

785

787

788protected:

792

802 std::error_code readNameTableSec(bool IsMD5, bool FixedLengthMD5);

805

806 std::error_code readHeader() override;

810

812

813

814

816

818

819

820

821

823

824

825

827

828

830

831public:

835

836

837 std::error_code readImpl() override;

838

839

841

844

845

846

847 bool collectFuncsFromModule() override;

848

852

853private:

854

855

856

857

860};

861

864private:

865 std::error_code verifySPMagic(uint64_t Magic) override;

866 std::error_code readCustomSection(const SecHdrTableEntry &Entry) override {

867

870 };

871

872public:

876

877

878 static bool hasFormat(const MemoryBuffer &Buffer);

879};

880

882

883

884

895

897public:

901

902

903 std::error_code readHeader() override;

904

905

906 std::error_code readImpl() override;

907

908

909 static bool hasFormat(const MemoryBuffer &Buffer);

910

911protected:

912 std::error_code readNameTable();

913 std::error_code readOneFunctionProfile(const InlineCallStack &InlineStack,

915 std::error_code readFunctionProfiles();

916 std::error_code skipNextWord();

917 template ErrorOr readNumber();

919

920

922

923

925

926

927 std::vectorstd::string Names;

928

929

932};

933

934}

935

936}

937

938#endif

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

static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")

Provides ErrorOr smart pointer.

This file defines the SmallVector class.

static StringRef readString(WasmObjectFile::ReadContext &Ctx)

Implements a dense probed hash-table based set.

Diagnostic information for the sample profiler.

Represents either an error or a value T.

Tagged union holding either a T or a Error.

GCOVBuffer - A wrapper around MemoryBuffer to provide GCOV specific read operations.

This is an important class for using LLVM in a threaded context.

This interface provides simple read-only access to a block of memory, and provides simple methods for...

A Module instance is used to store all the information related to an LLVM module.

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.

Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...

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

std::pair< iterator, bool > insert(const ValueT &V)

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

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

Representation of the samples collected for a function.

static StringRef getCanonicalFnName(const Function &F)

Return the canonical name for a function, taking into account suffix elision policy attributes.

static LLVM_ABI bool UseMD5

Whether the profile uses MD5 to represent string.

This class is a wrapper to associative container MapT<KeyT, ValueT> using the hash value of the origi...

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

const uint8_t * Data

Points to the current location in the buffer.

Definition SampleProfReader.h:718

std::vector< FunctionId > NameTable

Function name table.

Definition SampleProfReader.h:724

const uint64_t * MD5SampleContextStart

The starting address of the table of MD5 values of sample contexts.

Definition SampleProfReader.h:739

std::vector< SampleContextFrameVector > CSNameTable

CSNameTable is used to save full context vectors.

Definition SampleProfReader.h:728

SampleProfileReaderBinary(std::unique_ptr< MemoryBuffer > B, LLVMContext &C, SampleProfileFormat Format=SPF_None)

Definition SampleProfReader.h:641

std::vector< uint64_t > MD5SampleContextTable

Table to cache MD5 values of sample contexts corresponding to readSampleContextFromTable(),...

Definition SampleProfReader.h:733

const uint8_t * End

Points to the end of the buffer.

Definition SampleProfReader.h:721

std::vector< FunctionId > * getNameTable() override

It includes all the names that have samples either in outline instance or inline instance.

Definition SampleProfReader.h:653

std::error_code readFuncOffsetTable()

std::vector< SecHdrTableEntry > SecHdrTable

Definition SampleProfReader.h:789

std::error_code readCSNameTableSec()

virtual std::error_code readCustomSection(const SecHdrTableEntry &Entry)=0

std::vector< std::pair< SampleContext, uint64_t > > FuncOffsetList

The list version of FuncOffsetTable.

Definition SampleProfReader.h:826

DenseSet< StringRef > FuncsToUse

The set containing the functions to use when compiling a module.

Definition SampleProfReader.h:829

std::unique_ptr< ProfileSymbolList > ProfSymList

Definition SampleProfReader.h:817

std::error_code readSecHdrTable()

std::error_code readFuncProfiles()

bool useFuncOffsetList() const

Determine which container readFuncOffsetTable() should populate, the list FuncOffsetList or the map F...

std::error_code readNameTableSec(bool IsMD5, bool FixedLengthMD5)

std::error_code readSecHdrTableEntry(uint64_t Idx)

std::unique_ptr< ProfileSymbolList > getProfileSymbolList() override

Definition SampleProfReader.h:849

std::error_code readFuncMetadata(bool ProfileHasAttribute, DenseSet< FunctionSamples * > &Profiles)

virtual std::error_code readOneSection(const uint8_t *Start, uint64_t Size, const SecHdrTableEntry &Entry)

std::error_code verifySPMagic(uint64_t Magic) override=0

SampleProfileReaderExtBinaryBase(std::unique_ptr< MemoryBuffer > B, LLVMContext &C, SampleProfileFormat Format)

Definition SampleProfReader.h:832

DenseMap< hash_code, uint64_t > FuncOffsetTable

The table mapping from a function context's MD5 to the offset of its FunctionSample towards file star...

Definition SampleProfReader.h:822

std::error_code readHeader() override

Read and validate the file header.

std::error_code readProfileSymbolList()

SampleProfileReaderExtBinary(std::unique_ptr< MemoryBuffer > B, LLVMContext &C, SampleProfileFormat Format=SPF_Ext_Binary)

Definition SampleProfReader.h:873

GCOVBuffer GcovBuffer

GCOV buffer containing the profile.

Definition SampleProfReader.h:924

std::vector< std::string > Names

Function names in this profile.

Definition SampleProfReader.h:927

SampleProfileReaderGCC(std::unique_ptr< MemoryBuffer > B, LLVMContext &C)

Definition SampleProfReader.h:898

static const uint32_t GCOVTagAFDOFunction

Definition SampleProfReader.h:931

static const uint32_t GCOVTagAFDOFileNames

GCOV tags used to separate sections in the profile file.

Definition SampleProfReader.h:930

SampleProfileReaderItaniumRemapper remaps the profile data from a sample profile data reader,...

Definition SampleProfReader.h:265

bool exist(StringRef FunctionName)

Query whether there is equivalent in the remapper which has been inserted.

Definition SampleProfReader.h:296

static LLVM_ABI ErrorOr< std::unique_ptr< SampleProfileReaderItaniumRemapper > > create(StringRef Filename, vfs::FileSystem &FS, SampleProfileReader &Reader, LLVMContext &C)

Create a remapper from the given remapping file.

LLVM_ABI void applyRemapping(LLVMContext &Ctx)

Apply remappings to the profile read by Reader.

SampleProfileReaderItaniumRemapper(std::unique_ptr< MemoryBuffer > B, std::unique_ptr< SymbolRemappingReader > SRR, SampleProfileReader &R)

Definition SampleProfReader.h:267

bool hasApplied()

Definition SampleProfReader.h:289

void insert(StringRef FunctionName)

Insert function name into remapper.

Definition SampleProfReader.h:292

LLVM_ABI std::optional< StringRef > lookUpNameInProfile(StringRef FunctionName)

Return the equivalent name in the profile for FunctionName if it exists.

SampleProfileReaderRawBinary(std::unique_ptr< MemoryBuffer > B, LLVMContext &C, SampleProfileFormat Format=SPF_Binary)

Definition SampleProfReader.h:751

SampleProfileReaderText(std::unique_ptr< MemoryBuffer > B, LLVMContext &C)

Definition SampleProfReader.h:618

void setProfileUseMD5() override

Text format sample profile does not support MD5 for now.

Definition SampleProfReader.h:631

std::error_code readHeader() override

Read and validate the file header.

Definition SampleProfReader.h:622

Sample-based profile reader.

Definition SampleProfReader.h:346

uint32_t MaskedBitFrom

Zero out the discriminator bits higher than bit MaskedBitFrom (0 based).

Definition SampleProfReader.h:605

std::pair< const uint8_t *, const uint8_t * > ProfileSecRange

Definition SampleProfReader.h:571

bool ReadVTableProf

If true, the profile has vtable profiles and reader should decode them to parse profiles correctly.

Definition SampleProfReader.h:593

bool ProfileIsPreInlined

Whether function profile contains ShouldBeInlined contexts.

Definition SampleProfReader.h:583

std::unordered_map< uint64_t, std::pair< const uint8_t *, const uint8_t * > > FuncMetadataIndex

Definition SampleProfReader.h:569

SampleProfileMap & getProfiles()

Return all the profiles.

Definition SampleProfReader.h:449

uint32_t CSProfileCount

Number of context-sensitive profiles.

Definition SampleProfReader.h:586

static LLVM_ABI ErrorOr< std::unique_ptr< SampleProfileReader > > create(StringRef Filename, LLVMContext &C, vfs::FileSystem &FS, FSDiscriminatorPass P=FSDiscriminatorPass::Base, StringRef RemapFilename="")

Create a sample profile reader appropriate to the file format.

bool profileIsProbeBased() const

Whether input profile is based on pseudo probes.

Definition SampleProfReader.h:482

FunctionSamples * getSamplesFor(const Function &F)

Return the samples collected for function F.

Definition SampleProfReader.h:414

LLVM_ABI void dump(raw_ostream &OS=dbgs())

Print all the profiles on stream OS.

bool useMD5() const

Return whether names in the profile are all MD5 numbers.

Definition SampleProfReader.h:503

const Module * M

The current module being compiled if SampleProfileReader is used by compiler.

Definition SampleProfReader.h:601

std::unique_ptr< MemoryBuffer > Buffer

Memory buffer holding the profile file.

Definition SampleProfReader.h:536

std::unique_ptr< SampleProfileReaderItaniumRemapper > Remapper

Definition SampleProfReader.h:558

bool ProfileHasAttribute

Whether the profile has attribute metadata.

Definition SampleProfReader.h:574

bool SkipFlatProf

If SkipFlatProf is true, skip functions marked with !Flat in text mode or sections with SecFlagFlat f...

Definition SampleProfReader.h:613

bool profileIsPreInlined() const

Whether input profile contains ShouldBeInlined contexts.

Definition SampleProfReader.h:488

std::error_code read()

The interface to read sample profiles from the associated file.

Definition SampleProfReader.h:374

bool profileIsFS() const

Whether input profile is flow-sensitive.

Definition SampleProfReader.h:491

MemoryBuffer * getBuffer() const

Definition SampleProfReader.h:476

const HashKeyMap< std::unordered_map, FunctionId, FunctionId > * FuncNameToProfNameMap

Definition SampleProfReader.h:564

virtual ~SampleProfileReader()=default

SampleProfileReaderItaniumRemapper * getRemapper()

Definition SampleProfReader.h:515

bool ProfileIsCS

Whether function profiles are context-sensitive flat profiles.

Definition SampleProfReader.h:580

std::error_code read(const DenseSet< StringRef > &FuncsToUse)

Read sample profiles for the given functions.

Definition SampleProfReader.h:384

bool ProfileIsMD5

Whether the profile uses MD5 for Sample Contexts and function names.

Definition SampleProfReader.h:609

void setModule(const Module *Mod)

Definition SampleProfReader.h:517

static std::unique_ptr< ProfileSummary > takeSummary(SampleProfileReader &Reader)

Take ownership of the summary of this reader.

Definition SampleProfReader.h:543

ProfileSummary & getSummary() const

Return the profile summary.

Definition SampleProfReader.h:474

SampleProfileFormat Format

The format of sample.

Definition SampleProfReader.h:596

SampleProfileReader(std::unique_ptr< MemoryBuffer > B, LLVMContext &C, SampleProfileFormat Format=SPF_None)

Definition SampleProfReader.h:348

std::unique_ptr< ProfileSummary > Summary

Profile summary information.

Definition SampleProfReader.h:539

virtual bool hasUniqSuffix()

Return whether any name in the profile contains ".__uniq." suffix.

Definition SampleProfReader.h:513

LLVM_ABI void computeSummary()

Compute summary for this profile.

uint32_t getDiscriminatorMask() const

Get the bitmask the discriminators: For FS profiles, return the bit mask for this pass.

Definition SampleProfReader.h:366

virtual bool dumpSectionInfo(raw_ostream &OS=dbgs())

Definition SampleProfReader.h:500

SampleProfileFormat getFormat() const

Return the profile format.

Definition SampleProfReader.h:479

virtual void setProfileUseMD5()

Force the profile to use MD5 in Sample contexts, even if function names are present.

Definition SampleProfReader.h:507

void setDiscriminatorMaskedBitFrom(FSDiscriminatorPass P)

Set the bits for FS discriminators.

Definition SampleProfReader.h:360

virtual std::error_code read(const DenseSet< StringRef > &FuncsToUse, SampleProfileMap &Profiles)

Read sample profiles for the given functions and write them to the given profile map.

Definition SampleProfReader.h:553

void setFuncNameToProfNameMap(const HashKeyMap< std::unordered_map, FunctionId, FunctionId > &FPMap)

Definition SampleProfReader.h:519

virtual std::vector< FunctionId > * getNameTable()

It includes all the names that have samples either in outline instance or inline instance.

Definition SampleProfReader.h:499

bool profileIsCS() const

Whether input profile is fully context-sensitive.

Definition SampleProfReader.h:485

bool ProfileIsFS

Whether the function profiles use FS discriminators.

Definition SampleProfReader.h:589

virtual bool collectFuncsFromModule()

Collect functions with definitions in Module M.

Definition SampleProfReader.h:405

FunctionSamples * getSamplesFor(StringRef Fname)

Return the samples collected for function F.

Definition SampleProfReader.h:423

LLVM_ABI void dumpJson(raw_ostream &OS=dbgs())

Print all the profiles on stream OS in the JSON format.

SampleProfileMap Profiles

Map every function to its associated profile.

Definition SampleProfReader.h:530

virtual std::error_code readHeader()=0

Read and validate the file header.

void setSkipFlatProf(bool Skip)

Don't read profile without context if the flag is set.

Definition SampleProfReader.h:510

LLVM_ABI void dumpFunctionProfile(const FunctionSamples &FS, raw_ostream &OS=dbgs())

Print the profile for FunctionSamples on stream OS.

bool ProfileIsProbeBased

Whether samples are collected based on pseudo probes.

Definition SampleProfReader.h:577

void reportError(int64_t LineNumber, const Twine &Msg) const

Report a parse error message.

Definition SampleProfReader.h:452

virtual std::unique_ptr< ProfileSymbolList > getProfileSymbolList()

Definition SampleProfReader.h:493

LLVMContext & Ctx

LLVM context used to emit diagnostics.

Definition SampleProfReader.h:533

virtual std::error_code readImpl()=0

The implementaion to read sample profiles from the associated file.

The virtual file system interface.

@ C

The default llvm calling convention, compatible with C.

HistType

Definition SampleProfReader.h:885

@ HIST_TYPE_SINGLE_VALUE

Definition SampleProfReader.h:888

@ HIST_TYPE_INTERVAL

Definition SampleProfReader.h:886

@ HIST_TYPE_INDIR_CALL

Definition SampleProfReader.h:890

@ HIST_TYPE_INDIR_CALL_TOPN

Definition SampleProfReader.h:893

@ HIST_TYPE_AVERAGE

Definition SampleProfReader.h:891

@ HIST_TYPE_POW2

Definition SampleProfReader.h:887

@ HIST_TYPE_IOR

Definition SampleProfReader.h:892

@ HIST_TYPE_CONST_DELTA

Definition SampleProfReader.h:889

std::map< FunctionId, uint64_t > TypeCountMap

Key represents type of a C++ polymorphic class type by its vtable and value represents its counter.

SmallVector< FunctionSamples *, 10 > InlineCallStack

Definition SampleProfReader.h:881

This is an optimization pass for GlobalISel generic memory operations.

static unsigned getFSPassBitEnd(sampleprof::FSDiscriminatorPass P)

decltype(auto) get(const PointerIntPair< PointerTy, IntBits, IntType, PtrTraits, Info > &Pair)

LLVM_ABI raw_ostream & dbgs()

dbgs() - This returns a reference to a raw_ostream for debugging messages.

@ Mod

The access may modify the value stored in memory.

static unsigned getN1Bits(int N)

OutputIt move(R &&Range, OutputIt Out)

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

BumpPtrAllocatorImpl<> BumpPtrAllocator

The standard BumpPtrAllocator which just uses the default template parameters.

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