summaryrefslogtreecommitdiff
path: root/include/llvm/ProfileData/InstrProf.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/llvm/ProfileData/InstrProf.h')
-rw-r--r--include/llvm/ProfileData/InstrProf.h31
1 files changed, 18 insertions, 13 deletions
diff --git a/include/llvm/ProfileData/InstrProf.h b/include/llvm/ProfileData/InstrProf.h
index 0dbb2cf9f2696..573ea90cfd00b 100644
--- a/include/llvm/ProfileData/InstrProf.h
+++ b/include/llvm/ProfileData/InstrProf.h
@@ -410,7 +410,7 @@ uint64_t ComputeHash(StringRef K);
/// on how PGO name is formed.
class InstrProfSymtab {
public:
- typedef std::vector<std::pair<uint64_t, uint64_t>> AddrHashMap;
+ using AddrHashMap = std::vector<std::pair<uint64_t, uint64_t>>;
private:
StringRef Data;
@@ -450,11 +450,11 @@ public:
/// decls from module \c M. This interface is used by transformation
/// passes such as indirect function call promotion. Variable \c InLTO
/// indicates if this is called from LTO optimization passes.
- void create(Module &M, bool InLTO = false);
+ Error create(Module &M, bool InLTO = false);
/// Create InstrProfSymtab from a set of names iteratable from
/// \p IterRange. This interface is used by IndexedProfReader.
- template <typename NameIterRange> void create(const NameIterRange &IterRange);
+ template <typename NameIterRange> Error create(const NameIterRange &IterRange);
// If the symtab is created by a series of calls to \c addFuncName, \c
// finalizeSymtab needs to be called before looking up function names.
@@ -464,11 +464,14 @@ public:
/// Update the symtab by adding \p FuncName to the table. This interface
/// is used by the raw and text profile readers.
- void addFuncName(StringRef FuncName) {
+ Error addFuncName(StringRef FuncName) {
+ if (FuncName.empty())
+ return make_error<InstrProfError>(instrprof_error::malformed);
auto Ins = NameTab.insert(FuncName);
if (Ins.second)
MD5NameMap.push_back(std::make_pair(
IndexedInstrProf::ComputeHash(FuncName), Ins.first->getKey()));
+ return Error::success();
}
/// Map a function address to its name's MD5 hash. This interface
@@ -511,11 +514,13 @@ Error InstrProfSymtab::create(StringRef NameStrings) {
}
template <typename NameIterRange>
-void InstrProfSymtab::create(const NameIterRange &IterRange) {
+Error InstrProfSymtab::create(const NameIterRange &IterRange) {
for (auto Name : IterRange)
- addFuncName(Name);
+ if (Error E = addFuncName(Name))
+ return E;
finalizeSymtab();
+ return Error::success();
}
void InstrProfSymtab::finalizeSymtab() {
@@ -594,7 +599,7 @@ struct InstrProfRecord {
InstrProfRecord(StringRef Name, uint64_t Hash, std::vector<uint64_t> Counts)
: Name(Name), Hash(Hash), Counts(std::move(Counts)) {}
- typedef std::vector<std::pair<uint64_t, uint64_t>> ValueMapType;
+ using ValueMapType = std::vector<std::pair<uint64_t, uint64_t>>;
/// Return the number of value profile kinds with non-zero number
/// of profile sites.
@@ -668,8 +673,8 @@ struct InstrProfRecord {
private:
std::vector<InstrProfValueSiteRecord> IndirectCallSites;
std::vector<InstrProfValueSiteRecord> MemOPSizes;
- const std::vector<InstrProfValueSiteRecord> &
+ const std::vector<InstrProfValueSiteRecord> &
getValueSitesForKind(uint32_t ValueKind) const {
switch (ValueKind) {
case IPVK_IndirectCallTarget:
@@ -873,6 +878,11 @@ struct Summary {
// The number of Cutoff Entries (Summary::Entry) following summary fields.
uint64_t NumCutoffEntries;
+ Summary() = delete;
+ Summary(uint32_t Size) { memset(this, 0, Size); }
+
+ void operator delete(void *ptr) { ::operator delete(ptr); }
+
static uint32_t getSize(uint32_t NumSumFields, uint32_t NumCutoffEntries) {
return sizeof(Summary) + NumCutoffEntries * sizeof(Entry) +
NumSumFields * sizeof(uint64_t);
@@ -911,11 +921,6 @@ struct Summary {
ER.MinBlockCount = E.MinCount;
ER.NumBlocks = E.NumCounts;
}
-
- Summary(uint32_t Size) { memset(this, 0, Size); }
- void operator delete(void *ptr) { ::operator delete(ptr); }
-
- Summary() = delete;
};
inline std::unique_ptr<Summary> allocSummary(uint32_t TotalSize) {