LLVM 19.0.0git
PGOCtxProfReader.h
Go to the documentation of this file.
1//===--- PGOCtxProfReader.h - Contextual profile reader ---------*- 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/// \file
10///
11/// Reader for contextual iFDO profile, which comes in bitstream format.
12///
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_PROFILEDATA_CTXINSTRPROFILEREADER_H
16#define LLVM_PROFILEDATA_CTXINSTRPROFILEREADER_H
17
18#include "llvm/ADT/DenseSet.h"
20#include "llvm/IR/GlobalValue.h"
22#include "llvm/Support/Error.h"
23#include <map>
24#include <vector>
25
26namespace llvm {
27/// The loaded contextual profile, suitable for mutation during IPO passes. We
28/// generally expect a fraction of counters and of callsites to be populated.
29/// We continue to model counters as vectors, but callsites are modeled as a map
30/// of a map. The expectation is that, typically, there is a small number of
31/// indirect targets (usually, 1 for direct calls); but potentially a large
32/// number of callsites, and, as inlining progresses, the callsite count of a
33/// caller will grow.
35public:
36 using CallTargetMapTy = std::map<GlobalValue::GUID, PGOContextualProfile>;
38
39private:
40 friend class PGOCtxProfileReader;
41 GlobalValue::GUID GUID = 0;
43 CallsiteMapTy Callsites;
44
47 : GUID(G), Counters(std::move(Counters)) {}
48
50 getOrEmplace(uint32_t Index, GlobalValue::GUID G,
51 SmallVectorImpl<uint64_t> &&Counters);
52
53public:
58
59 GlobalValue::GUID guid() const { return GUID; }
60 const SmallVectorImpl<uint64_t> &counters() const { return Counters; }
61 const CallsiteMapTy &callsites() const { return Callsites; }
62 CallsiteMapTy &callsites() { return Callsites; }
63
64 bool hasCallsite(uint32_t I) const {
65 return Callsites.find(I) != Callsites.end();
66 }
67
69 assert(hasCallsite(I) && "Callsite not found");
70 return Callsites.find(I)->second;
71 }
73};
74
76 BitstreamCursor &Cursor;
78 Error readMetadata();
79 Error wrongValue(const Twine &);
80 Error unsupported(const Twine &);
81
83 readContext(bool ExpectIndex);
84 bool canReadContext();
85
86public:
87 PGOCtxProfileReader(BitstreamCursor &Cursor) : Cursor(Cursor) {}
88
90};
91} // namespace llvm
92#endif
This file defines the DenseSet and SmallDenseSet classes.
#define I(x, y, z)
Definition: MD5.cpp:58
#define G(x, y, z)
Definition: MD5.cpp:56
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This represents a position within a bitcode file, implemented on top of a SimpleBitstreamCursor.
iterator find(const_arg_type_t< KeyT > Val)
Definition: DenseMap.h:155
iterator end()
Definition: DenseMap.h:84
Implements a dense probed hash-table based set.
Definition: DenseSet.h:271
Lightweight error class with error context and mandatory checking.
Definition: Error.h:160
Tagged union holding either a T or a Error.
Definition: Error.h:481
The loaded contextual profile, suitable for mutation during IPO passes.
GlobalValue::GUID guid() const
std::map< GlobalValue::GUID, PGOContextualProfile > CallTargetMapTy
PGOContextualProfile(PGOContextualProfile &&)=default
bool hasCallsite(uint32_t I) const
CallsiteMapTy & callsites()
const SmallVectorImpl< uint64_t > & counters() const
PGOContextualProfile & operator=(PGOContextualProfile &&)=default
void getContainedGuids(DenseSet< GlobalValue::GUID > &Guids) const
const CallsiteMapTy & callsites() const
PGOContextualProfile(const PGOContextualProfile &)=delete
const CallTargetMapTy & callsite(uint32_t I) const
PGOContextualProfile & operator=(const PGOContextualProfile &)=delete
Expected< std::map< GlobalValue::GUID, PGOContextualProfile > > loadContexts()
PGOCtxProfileReader(BitstreamCursor &Cursor)
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: SmallVector.h:586
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1209
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1849
Implement std::hash so that hash_code can be used in STL containers.
Definition: BitVector.h:858