Diego Novillo | de1ab26 | 2014-09-09 12:40:50 +0000 | [diff] [blame] | 1 | //===- SampleProfReader.cpp - Read LLVM sample profile data ---------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements the class that reads LLVM sample profiles. It |
Diego Novillo | bb5605c | 2015-10-14 18:36:30 +0000 | [diff] [blame] | 11 | // supports three file formats: text, binary and gcov. |
Diego Novillo | de1ab26 | 2014-09-09 12:40:50 +0000 | [diff] [blame] | 12 | // |
Diego Novillo | bb5605c | 2015-10-14 18:36:30 +0000 | [diff] [blame] | 13 | // The textual representation is useful for debugging and testing purposes. The |
| 14 | // binary representation is more compact, resulting in smaller file sizes. |
Diego Novillo | de1ab26 | 2014-09-09 12:40:50 +0000 | [diff] [blame] | 15 | // |
Diego Novillo | bb5605c | 2015-10-14 18:36:30 +0000 | [diff] [blame] | 16 | // The gcov encoding is the one generated by GCC's AutoFDO profile creation |
| 17 | // tool (https://github.com/google/autofdo) |
Diego Novillo | de1ab26 | 2014-09-09 12:40:50 +0000 | [diff] [blame] | 18 | // |
Diego Novillo | bb5605c | 2015-10-14 18:36:30 +0000 | [diff] [blame] | 19 | // All three encodings can be used interchangeably as an input sample profile. |
Diego Novillo | de1ab26 | 2014-09-09 12:40:50 +0000 | [diff] [blame] | 20 | // |
Diego Novillo | de1ab26 | 2014-09-09 12:40:50 +0000 | [diff] [blame] | 21 | //===----------------------------------------------------------------------===// |
| 22 | |
| 23 | #include "llvm/ProfileData/SampleProfReader.h" |
Diego Novillo | b93483d | 2015-10-16 18:54:35 +0000 | [diff] [blame] | 24 | #include "llvm/ADT/DenseMap.h" |
| 25 | #include "llvm/ADT/SmallVector.h" |
Diego Novillo | de1ab26 | 2014-09-09 12:40:50 +0000 | [diff] [blame] | 26 | #include "llvm/Support/Debug.h" |
| 27 | #include "llvm/Support/ErrorOr.h" |
Diego Novillo | c572e92 | 2014-10-30 18:00:06 +0000 | [diff] [blame] | 28 | #include "llvm/Support/LEB128.h" |
Diego Novillo | de1ab26 | 2014-09-09 12:40:50 +0000 | [diff] [blame] | 29 | #include "llvm/Support/LineIterator.h" |
Diego Novillo | c572e92 | 2014-10-30 18:00:06 +0000 | [diff] [blame] | 30 | #include "llvm/Support/MemoryBuffer.h" |
Diego Novillo | de1ab26 | 2014-09-09 12:40:50 +0000 | [diff] [blame] | 31 | |
Diego Novillo | c572e92 | 2014-10-30 18:00:06 +0000 | [diff] [blame] | 32 | using namespace llvm::sampleprof; |
Diego Novillo | de1ab26 | 2014-09-09 12:40:50 +0000 | [diff] [blame] | 33 | using namespace llvm; |
| 34 | |
Diego Novillo | d5336ae | 2014-11-01 00:56:55 +0000 | [diff] [blame] | 35 | /// \brief Dump the function profile for \p FName. |
Diego Novillo | de1ab26 | 2014-09-09 12:40:50 +0000 | [diff] [blame] | 36 | /// |
Diego Novillo | de1ab26 | 2014-09-09 12:40:50 +0000 | [diff] [blame] | 37 | /// \param FName Name of the function to print. |
Diego Novillo | d5336ae | 2014-11-01 00:56:55 +0000 | [diff] [blame] | 38 | /// \param OS Stream to emit the output to. |
| 39 | void SampleProfileReader::dumpFunctionProfile(StringRef FName, |
| 40 | raw_ostream &OS) { |
Diego Novillo | c572e92 | 2014-10-30 18:00:06 +0000 | [diff] [blame] | 41 | OS << "Function: " << FName << ": "; |
Diego Novillo | de1ab26 | 2014-09-09 12:40:50 +0000 | [diff] [blame] | 42 | Profiles[FName].print(OS); |
| 43 | } |
| 44 | |
Diego Novillo | d5336ae | 2014-11-01 00:56:55 +0000 | [diff] [blame] | 45 | /// \brief Dump all the function profiles found on stream \p OS. |
| 46 | void SampleProfileReader::dump(raw_ostream &OS) { |
| 47 | for (const auto &I : Profiles) |
| 48 | dumpFunctionProfile(I.getKey(), OS); |
Diego Novillo | de1ab26 | 2014-09-09 12:40:50 +0000 | [diff] [blame] | 49 | } |
| 50 | |
Dehao Chen | 6722688 | 2015-09-30 00:42:46 +0000 | [diff] [blame] | 51 | /// \brief Parse \p Input as function head. |
| 52 | /// |
| 53 | /// Parse one line of \p Input, and update function name in \p FName, |
| 54 | /// function's total sample count in \p NumSamples, function's entry |
| 55 | /// count in \p NumHeadSamples. |
| 56 | /// |
| 57 | /// \returns true if parsing is successful. |
| 58 | static bool ParseHead(const StringRef &Input, StringRef &FName, |
Diego Novillo | 38be333 | 2015-10-15 16:36:21 +0000 | [diff] [blame] | 59 | uint64_t &NumSamples, uint64_t &NumHeadSamples) { |
Dehao Chen | 6722688 | 2015-09-30 00:42:46 +0000 | [diff] [blame] | 60 | if (Input[0] == ' ') |
| 61 | return false; |
| 62 | size_t n2 = Input.rfind(':'); |
| 63 | size_t n1 = Input.rfind(':', n2 - 1); |
| 64 | FName = Input.substr(0, n1); |
| 65 | if (Input.substr(n1 + 1, n2 - n1 - 1).getAsInteger(10, NumSamples)) |
| 66 | return false; |
| 67 | if (Input.substr(n2 + 1).getAsInteger(10, NumHeadSamples)) |
| 68 | return false; |
| 69 | return true; |
| 70 | } |
| 71 | |
Dehao Chen | 1004241 | 2015-10-21 01:22:27 +0000 | [diff] [blame] | 72 | |
| 73 | /// \brief Returns true if line offset \p L is legal (only has 16 bits). |
| 74 | static bool isOffsetLegal(unsigned L) { |
| 75 | return (L & 0xffff) == L; |
| 76 | } |
| 77 | |
Dehao Chen | 6722688 | 2015-09-30 00:42:46 +0000 | [diff] [blame] | 78 | /// \brief Parse \p Input as line sample. |
| 79 | /// |
| 80 | /// \param Input input line. |
| 81 | /// \param IsCallsite true if the line represents an inlined callsite. |
| 82 | /// \param Depth the depth of the inline stack. |
| 83 | /// \param NumSamples total samples of the line/inlined callsite. |
| 84 | /// \param LineOffset line offset to the start of the function. |
| 85 | /// \param Discriminator discriminator of the line. |
| 86 | /// \param TargetCountMap map from indirect call target to count. |
| 87 | /// |
| 88 | /// returns true if parsing is successful. |
Diego Novillo | 38be333 | 2015-10-15 16:36:21 +0000 | [diff] [blame] | 89 | static bool ParseLine(const StringRef &Input, bool &IsCallsite, uint32_t &Depth, |
| 90 | uint64_t &NumSamples, uint32_t &LineOffset, |
| 91 | uint32_t &Discriminator, StringRef &CalleeName, |
| 92 | DenseMap<StringRef, uint64_t> &TargetCountMap) { |
Dehao Chen | 6722688 | 2015-09-30 00:42:46 +0000 | [diff] [blame] | 93 | for (Depth = 0; Input[Depth] == ' '; Depth++) |
| 94 | ; |
| 95 | if (Depth == 0) |
| 96 | return false; |
| 97 | |
| 98 | size_t n1 = Input.find(':'); |
| 99 | StringRef Loc = Input.substr(Depth, n1 - Depth); |
| 100 | size_t n2 = Loc.find('.'); |
| 101 | if (n2 == StringRef::npos) { |
Dehao Chen | 1004241 | 2015-10-21 01:22:27 +0000 | [diff] [blame] | 102 | if (Loc.getAsInteger(10, LineOffset) || !isOffsetLegal(LineOffset)) |
Dehao Chen | 6722688 | 2015-09-30 00:42:46 +0000 | [diff] [blame] | 103 | return false; |
| 104 | Discriminator = 0; |
| 105 | } else { |
| 106 | if (Loc.substr(0, n2).getAsInteger(10, LineOffset)) |
| 107 | return false; |
| 108 | if (Loc.substr(n2 + 1).getAsInteger(10, Discriminator)) |
| 109 | return false; |
| 110 | } |
| 111 | |
| 112 | StringRef Rest = Input.substr(n1 + 2); |
| 113 | if (Rest[0] >= '0' && Rest[0] <= '9') { |
| 114 | IsCallsite = false; |
| 115 | size_t n3 = Rest.find(' '); |
| 116 | if (n3 == StringRef::npos) { |
| 117 | if (Rest.getAsInteger(10, NumSamples)) |
| 118 | return false; |
| 119 | } else { |
| 120 | if (Rest.substr(0, n3).getAsInteger(10, NumSamples)) |
| 121 | return false; |
| 122 | } |
| 123 | while (n3 != StringRef::npos) { |
| 124 | n3 += Rest.substr(n3).find_first_not_of(' '); |
| 125 | Rest = Rest.substr(n3); |
| 126 | n3 = Rest.find(' '); |
| 127 | StringRef pair = Rest; |
| 128 | if (n3 != StringRef::npos) { |
| 129 | pair = Rest.substr(0, n3); |
| 130 | } |
Diego Novillo | 38be333 | 2015-10-15 16:36:21 +0000 | [diff] [blame] | 131 | size_t n4 = pair.find(':'); |
| 132 | uint64_t count; |
Dehao Chen | 6722688 | 2015-09-30 00:42:46 +0000 | [diff] [blame] | 133 | if (pair.substr(n4 + 1).getAsInteger(10, count)) |
| 134 | return false; |
| 135 | TargetCountMap[pair.substr(0, n4)] = count; |
| 136 | } |
| 137 | } else { |
| 138 | IsCallsite = true; |
Diego Novillo | 38be333 | 2015-10-15 16:36:21 +0000 | [diff] [blame] | 139 | size_t n3 = Rest.find_last_of(':'); |
Dehao Chen | 6722688 | 2015-09-30 00:42:46 +0000 | [diff] [blame] | 140 | CalleeName = Rest.substr(0, n3); |
| 141 | if (Rest.substr(n3 + 1).getAsInteger(10, NumSamples)) |
| 142 | return false; |
| 143 | } |
| 144 | return true; |
| 145 | } |
| 146 | |
Diego Novillo | de1ab26 | 2014-09-09 12:40:50 +0000 | [diff] [blame] | 147 | /// \brief Load samples from a text file. |
| 148 | /// |
| 149 | /// See the documentation at the top of the file for an explanation of |
| 150 | /// the expected format. |
| 151 | /// |
| 152 | /// \returns true if the file was loaded successfully, false otherwise. |
Diego Novillo | c572e92 | 2014-10-30 18:00:06 +0000 | [diff] [blame] | 153 | std::error_code SampleProfileReaderText::read() { |
| 154 | line_iterator LineIt(*Buffer, /*SkipBlanks=*/true, '#'); |
Diego Novillo | de1ab26 | 2014-09-09 12:40:50 +0000 | [diff] [blame] | 155 | |
Diego Novillo | aae1ed8 | 2015-10-08 19:40:37 +0000 | [diff] [blame] | 156 | InlineCallStack InlineStack; |
Dehao Chen | 6722688 | 2015-09-30 00:42:46 +0000 | [diff] [blame] | 157 | |
| 158 | for (; !LineIt.is_at_eof(); ++LineIt) { |
| 159 | if ((*LineIt)[(*LineIt).find_first_not_of(' ')] == '#') |
| 160 | continue; |
Diego Novillo | de1ab26 | 2014-09-09 12:40:50 +0000 | [diff] [blame] | 161 | // Read the header of each function. |
| 162 | // |
| 163 | // Note that for function identifiers we are actually expecting |
| 164 | // mangled names, but we may not always get them. This happens when |
| 165 | // the compiler decides not to emit the function (e.g., it was inlined |
| 166 | // and removed). In this case, the binary will not have the linkage |
| 167 | // name for the function, so the profiler will emit the function's |
| 168 | // unmangled name, which may contain characters like ':' and '>' in its |
| 169 | // name (member functions, templates, etc). |
| 170 | // |
| 171 | // The only requirement we place on the identifier, then, is that it |
| 172 | // should not begin with a number. |
Dehao Chen | 6722688 | 2015-09-30 00:42:46 +0000 | [diff] [blame] | 173 | if ((*LineIt)[0] != ' ') { |
Diego Novillo | 38be333 | 2015-10-15 16:36:21 +0000 | [diff] [blame] | 174 | uint64_t NumSamples, NumHeadSamples; |
Dehao Chen | 6722688 | 2015-09-30 00:42:46 +0000 | [diff] [blame] | 175 | StringRef FName; |
| 176 | if (!ParseHead(*LineIt, FName, NumSamples, NumHeadSamples)) { |
| 177 | reportError(LineIt.line_number(), |
| 178 | "Expected 'mangled_name:NUM:NUM', found " + *LineIt); |
| 179 | return sampleprof_error::malformed; |
| 180 | } |
| 181 | Profiles[FName] = FunctionSamples(); |
| 182 | FunctionSamples &FProfile = Profiles[FName]; |
| 183 | FProfile.addTotalSamples(NumSamples); |
| 184 | FProfile.addHeadSamples(NumHeadSamples); |
| 185 | InlineStack.clear(); |
| 186 | InlineStack.push_back(&FProfile); |
| 187 | } else { |
Diego Novillo | 38be333 | 2015-10-15 16:36:21 +0000 | [diff] [blame] | 188 | uint64_t NumSamples; |
Dehao Chen | 6722688 | 2015-09-30 00:42:46 +0000 | [diff] [blame] | 189 | StringRef FName; |
Diego Novillo | 38be333 | 2015-10-15 16:36:21 +0000 | [diff] [blame] | 190 | DenseMap<StringRef, uint64_t> TargetCountMap; |
Dehao Chen | 6722688 | 2015-09-30 00:42:46 +0000 | [diff] [blame] | 191 | bool IsCallsite; |
Diego Novillo | 38be333 | 2015-10-15 16:36:21 +0000 | [diff] [blame] | 192 | uint32_t Depth, LineOffset, Discriminator; |
Dehao Chen | 6722688 | 2015-09-30 00:42:46 +0000 | [diff] [blame] | 193 | if (!ParseLine(*LineIt, IsCallsite, Depth, NumSamples, LineOffset, |
| 194 | Discriminator, FName, TargetCountMap)) { |
Diego Novillo | 3376a78 | 2015-09-17 00:17:24 +0000 | [diff] [blame] | 195 | reportError(LineIt.line_number(), |
| 196 | "Expected 'NUM[.NUM]: NUM[ mangled_name:NUM]*', found " + |
| 197 | *LineIt); |
Diego Novillo | c572e92 | 2014-10-30 18:00:06 +0000 | [diff] [blame] | 198 | return sampleprof_error::malformed; |
Diego Novillo | de1ab26 | 2014-09-09 12:40:50 +0000 | [diff] [blame] | 199 | } |
Dehao Chen | 6722688 | 2015-09-30 00:42:46 +0000 | [diff] [blame] | 200 | if (IsCallsite) { |
| 201 | while (InlineStack.size() > Depth) { |
| 202 | InlineStack.pop_back(); |
Diego Novillo | c572e92 | 2014-10-30 18:00:06 +0000 | [diff] [blame] | 203 | } |
Dehao Chen | 6722688 | 2015-09-30 00:42:46 +0000 | [diff] [blame] | 204 | FunctionSamples &FSamples = InlineStack.back()->functionSamplesAt( |
| 205 | CallsiteLocation(LineOffset, Discriminator, FName)); |
| 206 | FSamples.addTotalSamples(NumSamples); |
| 207 | InlineStack.push_back(&FSamples); |
| 208 | } else { |
| 209 | while (InlineStack.size() > Depth) { |
| 210 | InlineStack.pop_back(); |
| 211 | } |
| 212 | FunctionSamples &FProfile = *InlineStack.back(); |
| 213 | for (const auto &name_count : TargetCountMap) { |
| 214 | FProfile.addCalledTargetSamples(LineOffset, Discriminator, |
| 215 | name_count.first, name_count.second); |
| 216 | } |
| 217 | FProfile.addBodySamples(LineOffset, Discriminator, NumSamples); |
Diego Novillo | c572e92 | 2014-10-30 18:00:06 +0000 | [diff] [blame] | 218 | } |
Diego Novillo | de1ab26 | 2014-09-09 12:40:50 +0000 | [diff] [blame] | 219 | } |
| 220 | } |
| 221 | |
Diego Novillo | c572e92 | 2014-10-30 18:00:06 +0000 | [diff] [blame] | 222 | return sampleprof_error::success; |
Diego Novillo | de1ab26 | 2014-09-09 12:40:50 +0000 | [diff] [blame] | 223 | } |
| 224 | |
Nathan Slingerland | 4f82366 | 2015-11-13 03:47:58 +0000 | [diff] [blame] | 225 | bool SampleProfileReaderText::hasFormat(const MemoryBuffer &Buffer) { |
| 226 | bool result = false; |
| 227 | |
| 228 | // Check that the first non-comment line is a valid function header. |
| 229 | line_iterator LineIt(Buffer, /*SkipBlanks=*/true, '#'); |
| 230 | if (!LineIt.is_at_eof()) { |
| 231 | if ((*LineIt)[0] != ' ') { |
| 232 | uint64_t NumSamples, NumHeadSamples; |
| 233 | StringRef FName; |
| 234 | result = ParseHead(*LineIt, FName, NumSamples, NumHeadSamples); |
| 235 | } |
| 236 | } |
| 237 | |
| 238 | return result; |
| 239 | } |
| 240 | |
Diego Novillo | d5336ae | 2014-11-01 00:56:55 +0000 | [diff] [blame] | 241 | template <typename T> ErrorOr<T> SampleProfileReaderBinary::readNumber() { |
Diego Novillo | c572e92 | 2014-10-30 18:00:06 +0000 | [diff] [blame] | 242 | unsigned NumBytesRead = 0; |
| 243 | std::error_code EC; |
| 244 | uint64_t Val = decodeULEB128(Data, &NumBytesRead); |
| 245 | |
| 246 | if (Val > std::numeric_limits<T>::max()) |
| 247 | EC = sampleprof_error::malformed; |
| 248 | else if (Data + NumBytesRead > End) |
| 249 | EC = sampleprof_error::truncated; |
| 250 | else |
| 251 | EC = sampleprof_error::success; |
| 252 | |
| 253 | if (EC) { |
Diego Novillo | 3376a78 | 2015-09-17 00:17:24 +0000 | [diff] [blame] | 254 | reportError(0, EC.message()); |
Diego Novillo | c572e92 | 2014-10-30 18:00:06 +0000 | [diff] [blame] | 255 | return EC; |
| 256 | } |
| 257 | |
| 258 | Data += NumBytesRead; |
| 259 | return static_cast<T>(Val); |
| 260 | } |
| 261 | |
| 262 | ErrorOr<StringRef> SampleProfileReaderBinary::readString() { |
| 263 | std::error_code EC; |
| 264 | StringRef Str(reinterpret_cast<const char *>(Data)); |
| 265 | if (Data + Str.size() + 1 > End) { |
| 266 | EC = sampleprof_error::truncated; |
Diego Novillo | 3376a78 | 2015-09-17 00:17:24 +0000 | [diff] [blame] | 267 | reportError(0, EC.message()); |
Diego Novillo | c572e92 | 2014-10-30 18:00:06 +0000 | [diff] [blame] | 268 | return EC; |
| 269 | } |
| 270 | |
| 271 | Data += Str.size() + 1; |
| 272 | return Str; |
| 273 | } |
| 274 | |
Diego Novillo | 760c5a8 | 2015-10-13 22:48:46 +0000 | [diff] [blame] | 275 | ErrorOr<StringRef> SampleProfileReaderBinary::readStringFromTable() { |
| 276 | std::error_code EC; |
Diego Novillo | 38be333 | 2015-10-15 16:36:21 +0000 | [diff] [blame] | 277 | auto Idx = readNumber<uint32_t>(); |
Diego Novillo | 760c5a8 | 2015-10-13 22:48:46 +0000 | [diff] [blame] | 278 | if (std::error_code EC = Idx.getError()) |
| 279 | return EC; |
| 280 | if (*Idx >= NameTable.size()) |
| 281 | return sampleprof_error::truncated_name_table; |
| 282 | return NameTable[*Idx]; |
| 283 | } |
| 284 | |
Diego Novillo | a7f1e8e | 2015-10-09 17:54:24 +0000 | [diff] [blame] | 285 | std::error_code |
| 286 | SampleProfileReaderBinary::readProfile(FunctionSamples &FProfile) { |
Diego Novillo | b93483d | 2015-10-16 18:54:35 +0000 | [diff] [blame] | 287 | auto NumSamples = readNumber<uint64_t>(); |
| 288 | if (std::error_code EC = NumSamples.getError()) |
Diego Novillo | a7f1e8e | 2015-10-09 17:54:24 +0000 | [diff] [blame] | 289 | return EC; |
Diego Novillo | b93483d | 2015-10-16 18:54:35 +0000 | [diff] [blame] | 290 | FProfile.addTotalSamples(*NumSamples); |
Diego Novillo | a7f1e8e | 2015-10-09 17:54:24 +0000 | [diff] [blame] | 291 | |
| 292 | // Read the samples in the body. |
Diego Novillo | 38be333 | 2015-10-15 16:36:21 +0000 | [diff] [blame] | 293 | auto NumRecords = readNumber<uint32_t>(); |
Diego Novillo | a7f1e8e | 2015-10-09 17:54:24 +0000 | [diff] [blame] | 294 | if (std::error_code EC = NumRecords.getError()) |
| 295 | return EC; |
| 296 | |
Diego Novillo | 38be333 | 2015-10-15 16:36:21 +0000 | [diff] [blame] | 297 | for (uint32_t I = 0; I < *NumRecords; ++I) { |
Diego Novillo | a7f1e8e | 2015-10-09 17:54:24 +0000 | [diff] [blame] | 298 | auto LineOffset = readNumber<uint64_t>(); |
| 299 | if (std::error_code EC = LineOffset.getError()) |
| 300 | return EC; |
| 301 | |
Dehao Chen | 1004241 | 2015-10-21 01:22:27 +0000 | [diff] [blame] | 302 | if (!isOffsetLegal(*LineOffset)) { |
| 303 | return std::error_code(); |
| 304 | } |
| 305 | |
Diego Novillo | a7f1e8e | 2015-10-09 17:54:24 +0000 | [diff] [blame] | 306 | auto Discriminator = readNumber<uint64_t>(); |
| 307 | if (std::error_code EC = Discriminator.getError()) |
| 308 | return EC; |
| 309 | |
| 310 | auto NumSamples = readNumber<uint64_t>(); |
| 311 | if (std::error_code EC = NumSamples.getError()) |
| 312 | return EC; |
| 313 | |
Diego Novillo | 38be333 | 2015-10-15 16:36:21 +0000 | [diff] [blame] | 314 | auto NumCalls = readNumber<uint32_t>(); |
Diego Novillo | a7f1e8e | 2015-10-09 17:54:24 +0000 | [diff] [blame] | 315 | if (std::error_code EC = NumCalls.getError()) |
| 316 | return EC; |
| 317 | |
Diego Novillo | 38be333 | 2015-10-15 16:36:21 +0000 | [diff] [blame] | 318 | for (uint32_t J = 0; J < *NumCalls; ++J) { |
Diego Novillo | 760c5a8 | 2015-10-13 22:48:46 +0000 | [diff] [blame] | 319 | auto CalledFunction(readStringFromTable()); |
Diego Novillo | a7f1e8e | 2015-10-09 17:54:24 +0000 | [diff] [blame] | 320 | if (std::error_code EC = CalledFunction.getError()) |
| 321 | return EC; |
| 322 | |
| 323 | auto CalledFunctionSamples = readNumber<uint64_t>(); |
| 324 | if (std::error_code EC = CalledFunctionSamples.getError()) |
| 325 | return EC; |
| 326 | |
| 327 | FProfile.addCalledTargetSamples(*LineOffset, *Discriminator, |
| 328 | *CalledFunction, *CalledFunctionSamples); |
| 329 | } |
| 330 | |
| 331 | FProfile.addBodySamples(*LineOffset, *Discriminator, *NumSamples); |
| 332 | } |
| 333 | |
| 334 | // Read all the samples for inlined function calls. |
Diego Novillo | 38be333 | 2015-10-15 16:36:21 +0000 | [diff] [blame] | 335 | auto NumCallsites = readNumber<uint32_t>(); |
Diego Novillo | a7f1e8e | 2015-10-09 17:54:24 +0000 | [diff] [blame] | 336 | if (std::error_code EC = NumCallsites.getError()) |
| 337 | return EC; |
| 338 | |
Diego Novillo | 38be333 | 2015-10-15 16:36:21 +0000 | [diff] [blame] | 339 | for (uint32_t J = 0; J < *NumCallsites; ++J) { |
Diego Novillo | a7f1e8e | 2015-10-09 17:54:24 +0000 | [diff] [blame] | 340 | auto LineOffset = readNumber<uint64_t>(); |
| 341 | if (std::error_code EC = LineOffset.getError()) |
| 342 | return EC; |
| 343 | |
| 344 | auto Discriminator = readNumber<uint64_t>(); |
| 345 | if (std::error_code EC = Discriminator.getError()) |
| 346 | return EC; |
| 347 | |
Diego Novillo | 760c5a8 | 2015-10-13 22:48:46 +0000 | [diff] [blame] | 348 | auto FName(readStringFromTable()); |
Diego Novillo | a7f1e8e | 2015-10-09 17:54:24 +0000 | [diff] [blame] | 349 | if (std::error_code EC = FName.getError()) |
| 350 | return EC; |
| 351 | |
| 352 | FunctionSamples &CalleeProfile = FProfile.functionSamplesAt( |
| 353 | CallsiteLocation(*LineOffset, *Discriminator, *FName)); |
| 354 | if (std::error_code EC = readProfile(CalleeProfile)) |
| 355 | return EC; |
| 356 | } |
| 357 | |
| 358 | return sampleprof_error::success; |
| 359 | } |
| 360 | |
Diego Novillo | c572e92 | 2014-10-30 18:00:06 +0000 | [diff] [blame] | 361 | std::error_code SampleProfileReaderBinary::read() { |
| 362 | while (!at_eof()) { |
Diego Novillo | b93483d | 2015-10-16 18:54:35 +0000 | [diff] [blame] | 363 | auto NumHeadSamples = readNumber<uint64_t>(); |
| 364 | if (std::error_code EC = NumHeadSamples.getError()) |
| 365 | return EC; |
| 366 | |
Diego Novillo | 760c5a8 | 2015-10-13 22:48:46 +0000 | [diff] [blame] | 367 | auto FName(readStringFromTable()); |
Diego Novillo | c572e92 | 2014-10-30 18:00:06 +0000 | [diff] [blame] | 368 | if (std::error_code EC = FName.getError()) |
| 369 | return EC; |
| 370 | |
| 371 | Profiles[*FName] = FunctionSamples(); |
| 372 | FunctionSamples &FProfile = Profiles[*FName]; |
| 373 | |
Diego Novillo | b93483d | 2015-10-16 18:54:35 +0000 | [diff] [blame] | 374 | FProfile.addHeadSamples(*NumHeadSamples); |
| 375 | |
Diego Novillo | a7f1e8e | 2015-10-09 17:54:24 +0000 | [diff] [blame] | 376 | if (std::error_code EC = readProfile(FProfile)) |
Diego Novillo | c572e92 | 2014-10-30 18:00:06 +0000 | [diff] [blame] | 377 | return EC; |
Diego Novillo | c572e92 | 2014-10-30 18:00:06 +0000 | [diff] [blame] | 378 | } |
| 379 | |
| 380 | return sampleprof_error::success; |
| 381 | } |
| 382 | |
| 383 | std::error_code SampleProfileReaderBinary::readHeader() { |
| 384 | Data = reinterpret_cast<const uint8_t *>(Buffer->getBufferStart()); |
| 385 | End = Data + Buffer->getBufferSize(); |
| 386 | |
| 387 | // Read and check the magic identifier. |
| 388 | auto Magic = readNumber<uint64_t>(); |
| 389 | if (std::error_code EC = Magic.getError()) |
| 390 | return EC; |
| 391 | else if (*Magic != SPMagic()) |
| 392 | return sampleprof_error::bad_magic; |
| 393 | |
| 394 | // Read the version number. |
| 395 | auto Version = readNumber<uint64_t>(); |
| 396 | if (std::error_code EC = Version.getError()) |
| 397 | return EC; |
| 398 | else if (*Version != SPVersion()) |
| 399 | return sampleprof_error::unsupported_version; |
| 400 | |
Diego Novillo | 760c5a8 | 2015-10-13 22:48:46 +0000 | [diff] [blame] | 401 | // Read the name table. |
Diego Novillo | 38be333 | 2015-10-15 16:36:21 +0000 | [diff] [blame] | 402 | auto Size = readNumber<uint32_t>(); |
Diego Novillo | 760c5a8 | 2015-10-13 22:48:46 +0000 | [diff] [blame] | 403 | if (std::error_code EC = Size.getError()) |
| 404 | return EC; |
| 405 | NameTable.reserve(*Size); |
Diego Novillo | 38be333 | 2015-10-15 16:36:21 +0000 | [diff] [blame] | 406 | for (uint32_t I = 0; I < *Size; ++I) { |
Diego Novillo | 760c5a8 | 2015-10-13 22:48:46 +0000 | [diff] [blame] | 407 | auto Name(readString()); |
| 408 | if (std::error_code EC = Name.getError()) |
| 409 | return EC; |
| 410 | NameTable.push_back(*Name); |
| 411 | } |
| 412 | |
Diego Novillo | c572e92 | 2014-10-30 18:00:06 +0000 | [diff] [blame] | 413 | return sampleprof_error::success; |
| 414 | } |
| 415 | |
| 416 | bool SampleProfileReaderBinary::hasFormat(const MemoryBuffer &Buffer) { |
| 417 | const uint8_t *Data = |
| 418 | reinterpret_cast<const uint8_t *>(Buffer.getBufferStart()); |
| 419 | uint64_t Magic = decodeULEB128(Data); |
| 420 | return Magic == SPMagic(); |
| 421 | } |
| 422 | |
Diego Novillo | 3376a78 | 2015-09-17 00:17:24 +0000 | [diff] [blame] | 423 | std::error_code SampleProfileReaderGCC::skipNextWord() { |
| 424 | uint32_t dummy; |
| 425 | if (!GcovBuffer.readInt(dummy)) |
| 426 | return sampleprof_error::truncated; |
| 427 | return sampleprof_error::success; |
| 428 | } |
| 429 | |
| 430 | template <typename T> ErrorOr<T> SampleProfileReaderGCC::readNumber() { |
| 431 | if (sizeof(T) <= sizeof(uint32_t)) { |
| 432 | uint32_t Val; |
| 433 | if (GcovBuffer.readInt(Val) && Val <= std::numeric_limits<T>::max()) |
| 434 | return static_cast<T>(Val); |
| 435 | } else if (sizeof(T) <= sizeof(uint64_t)) { |
| 436 | uint64_t Val; |
| 437 | if (GcovBuffer.readInt64(Val) && Val <= std::numeric_limits<T>::max()) |
| 438 | return static_cast<T>(Val); |
| 439 | } |
| 440 | |
| 441 | std::error_code EC = sampleprof_error::malformed; |
| 442 | reportError(0, EC.message()); |
| 443 | return EC; |
| 444 | } |
| 445 | |
| 446 | ErrorOr<StringRef> SampleProfileReaderGCC::readString() { |
| 447 | StringRef Str; |
| 448 | if (!GcovBuffer.readString(Str)) |
| 449 | return sampleprof_error::truncated; |
| 450 | return Str; |
| 451 | } |
| 452 | |
| 453 | std::error_code SampleProfileReaderGCC::readHeader() { |
| 454 | // Read the magic identifier. |
| 455 | if (!GcovBuffer.readGCDAFormat()) |
| 456 | return sampleprof_error::unrecognized_format; |
| 457 | |
| 458 | // Read the version number. Note - the GCC reader does not validate this |
| 459 | // version, but the profile creator generates v704. |
| 460 | GCOV::GCOVVersion version; |
| 461 | if (!GcovBuffer.readGCOVVersion(version)) |
| 462 | return sampleprof_error::unrecognized_format; |
| 463 | |
| 464 | if (version != GCOV::V704) |
| 465 | return sampleprof_error::unsupported_version; |
| 466 | |
| 467 | // Skip the empty integer. |
| 468 | if (std::error_code EC = skipNextWord()) |
| 469 | return EC; |
| 470 | |
| 471 | return sampleprof_error::success; |
| 472 | } |
| 473 | |
| 474 | std::error_code SampleProfileReaderGCC::readSectionTag(uint32_t Expected) { |
| 475 | uint32_t Tag; |
| 476 | if (!GcovBuffer.readInt(Tag)) |
| 477 | return sampleprof_error::truncated; |
| 478 | |
| 479 | if (Tag != Expected) |
| 480 | return sampleprof_error::malformed; |
| 481 | |
| 482 | if (std::error_code EC = skipNextWord()) |
| 483 | return EC; |
| 484 | |
| 485 | return sampleprof_error::success; |
| 486 | } |
| 487 | |
| 488 | std::error_code SampleProfileReaderGCC::readNameTable() { |
| 489 | if (std::error_code EC = readSectionTag(GCOVTagAFDOFileNames)) |
| 490 | return EC; |
| 491 | |
| 492 | uint32_t Size; |
| 493 | if (!GcovBuffer.readInt(Size)) |
| 494 | return sampleprof_error::truncated; |
| 495 | |
| 496 | for (uint32_t I = 0; I < Size; ++I) { |
| 497 | StringRef Str; |
| 498 | if (!GcovBuffer.readString(Str)) |
| 499 | return sampleprof_error::truncated; |
| 500 | Names.push_back(Str); |
| 501 | } |
| 502 | |
| 503 | return sampleprof_error::success; |
| 504 | } |
| 505 | |
| 506 | std::error_code SampleProfileReaderGCC::readFunctionProfiles() { |
| 507 | if (std::error_code EC = readSectionTag(GCOVTagAFDOFunction)) |
| 508 | return EC; |
| 509 | |
| 510 | uint32_t NumFunctions; |
| 511 | if (!GcovBuffer.readInt(NumFunctions)) |
| 512 | return sampleprof_error::truncated; |
| 513 | |
Diego Novillo | aae1ed8 | 2015-10-08 19:40:37 +0000 | [diff] [blame] | 514 | InlineCallStack Stack; |
Diego Novillo | 3376a78 | 2015-09-17 00:17:24 +0000 | [diff] [blame] | 515 | for (uint32_t I = 0; I < NumFunctions; ++I) |
Diego Novillo | aae1ed8 | 2015-10-08 19:40:37 +0000 | [diff] [blame] | 516 | if (std::error_code EC = readOneFunctionProfile(Stack, true, 0)) |
Diego Novillo | 3376a78 | 2015-09-17 00:17:24 +0000 | [diff] [blame] | 517 | return EC; |
| 518 | |
| 519 | return sampleprof_error::success; |
| 520 | } |
| 521 | |
Diego Novillo | aae1ed8 | 2015-10-08 19:40:37 +0000 | [diff] [blame] | 522 | std::error_code SampleProfileReaderGCC::readOneFunctionProfile( |
| 523 | const InlineCallStack &InlineStack, bool Update, uint32_t Offset) { |
Diego Novillo | 3376a78 | 2015-09-17 00:17:24 +0000 | [diff] [blame] | 524 | uint64_t HeadCount = 0; |
Diego Novillo | aae1ed8 | 2015-10-08 19:40:37 +0000 | [diff] [blame] | 525 | if (InlineStack.size() == 0) |
Diego Novillo | 3376a78 | 2015-09-17 00:17:24 +0000 | [diff] [blame] | 526 | if (!GcovBuffer.readInt64(HeadCount)) |
| 527 | return sampleprof_error::truncated; |
| 528 | |
| 529 | uint32_t NameIdx; |
| 530 | if (!GcovBuffer.readInt(NameIdx)) |
| 531 | return sampleprof_error::truncated; |
| 532 | |
| 533 | StringRef Name(Names[NameIdx]); |
| 534 | |
| 535 | uint32_t NumPosCounts; |
| 536 | if (!GcovBuffer.readInt(NumPosCounts)) |
| 537 | return sampleprof_error::truncated; |
| 538 | |
Diego Novillo | aae1ed8 | 2015-10-08 19:40:37 +0000 | [diff] [blame] | 539 | uint32_t NumCallsites; |
| 540 | if (!GcovBuffer.readInt(NumCallsites)) |
Diego Novillo | 3376a78 | 2015-09-17 00:17:24 +0000 | [diff] [blame] | 541 | return sampleprof_error::truncated; |
| 542 | |
Diego Novillo | aae1ed8 | 2015-10-08 19:40:37 +0000 | [diff] [blame] | 543 | FunctionSamples *FProfile = nullptr; |
| 544 | if (InlineStack.size() == 0) { |
| 545 | // If this is a top function that we have already processed, do not |
| 546 | // update its profile again. This happens in the presence of |
| 547 | // function aliases. Since these aliases share the same function |
| 548 | // body, there will be identical replicated profiles for the |
| 549 | // original function. In this case, we simply not bother updating |
| 550 | // the profile of the original function. |
| 551 | FProfile = &Profiles[Name]; |
| 552 | FProfile->addHeadSamples(HeadCount); |
| 553 | if (FProfile->getTotalSamples() > 0) |
Diego Novillo | 3376a78 | 2015-09-17 00:17:24 +0000 | [diff] [blame] | 554 | Update = false; |
Diego Novillo | aae1ed8 | 2015-10-08 19:40:37 +0000 | [diff] [blame] | 555 | } else { |
| 556 | // Otherwise, we are reading an inlined instance. The top of the |
| 557 | // inline stack contains the profile of the caller. Insert this |
| 558 | // callee in the caller's CallsiteMap. |
| 559 | FunctionSamples *CallerProfile = InlineStack.front(); |
| 560 | uint32_t LineOffset = Offset >> 16; |
| 561 | uint32_t Discriminator = Offset & 0xffff; |
| 562 | FProfile = &CallerProfile->functionSamplesAt( |
| 563 | CallsiteLocation(LineOffset, Discriminator, Name)); |
Diego Novillo | 3376a78 | 2015-09-17 00:17:24 +0000 | [diff] [blame] | 564 | } |
| 565 | |
| 566 | for (uint32_t I = 0; I < NumPosCounts; ++I) { |
| 567 | uint32_t Offset; |
| 568 | if (!GcovBuffer.readInt(Offset)) |
| 569 | return sampleprof_error::truncated; |
| 570 | |
| 571 | uint32_t NumTargets; |
| 572 | if (!GcovBuffer.readInt(NumTargets)) |
| 573 | return sampleprof_error::truncated; |
| 574 | |
| 575 | uint64_t Count; |
| 576 | if (!GcovBuffer.readInt64(Count)) |
| 577 | return sampleprof_error::truncated; |
| 578 | |
Diego Novillo | aae1ed8 | 2015-10-08 19:40:37 +0000 | [diff] [blame] | 579 | // The line location is encoded in the offset as: |
| 580 | // high 16 bits: line offset to the start of the function. |
| 581 | // low 16 bits: discriminator. |
| 582 | uint32_t LineOffset = Offset >> 16; |
| 583 | uint32_t Discriminator = Offset & 0xffff; |
Diego Novillo | 3376a78 | 2015-09-17 00:17:24 +0000 | [diff] [blame] | 584 | |
Diego Novillo | aae1ed8 | 2015-10-08 19:40:37 +0000 | [diff] [blame] | 585 | InlineCallStack NewStack; |
| 586 | NewStack.push_back(FProfile); |
| 587 | NewStack.insert(NewStack.end(), InlineStack.begin(), InlineStack.end()); |
| 588 | if (Update) { |
| 589 | // Walk up the inline stack, adding the samples on this line to |
| 590 | // the total sample count of the callers in the chain. |
| 591 | for (auto CallerProfile : NewStack) |
| 592 | CallerProfile->addTotalSamples(Count); |
| 593 | |
| 594 | // Update the body samples for the current profile. |
| 595 | FProfile->addBodySamples(LineOffset, Discriminator, Count); |
| 596 | } |
| 597 | |
| 598 | // Process the list of functions called at an indirect call site. |
| 599 | // These are all the targets that a function pointer (or virtual |
| 600 | // function) resolved at runtime. |
Diego Novillo | 3376a78 | 2015-09-17 00:17:24 +0000 | [diff] [blame] | 601 | for (uint32_t J = 0; J < NumTargets; J++) { |
| 602 | uint32_t HistVal; |
| 603 | if (!GcovBuffer.readInt(HistVal)) |
| 604 | return sampleprof_error::truncated; |
| 605 | |
| 606 | if (HistVal != HIST_TYPE_INDIR_CALL_TOPN) |
| 607 | return sampleprof_error::malformed; |
| 608 | |
| 609 | uint64_t TargetIdx; |
| 610 | if (!GcovBuffer.readInt64(TargetIdx)) |
| 611 | return sampleprof_error::truncated; |
| 612 | StringRef TargetName(Names[TargetIdx]); |
| 613 | |
| 614 | uint64_t TargetCount; |
| 615 | if (!GcovBuffer.readInt64(TargetCount)) |
| 616 | return sampleprof_error::truncated; |
| 617 | |
| 618 | if (Update) { |
| 619 | FunctionSamples &TargetProfile = Profiles[TargetName]; |
Diego Novillo | aae1ed8 | 2015-10-08 19:40:37 +0000 | [diff] [blame] | 620 | TargetProfile.addCalledTargetSamples(LineOffset, Discriminator, |
| 621 | TargetName, TargetCount); |
Diego Novillo | 3376a78 | 2015-09-17 00:17:24 +0000 | [diff] [blame] | 622 | } |
| 623 | } |
| 624 | } |
| 625 | |
Diego Novillo | aae1ed8 | 2015-10-08 19:40:37 +0000 | [diff] [blame] | 626 | // Process all the inlined callers into the current function. These |
| 627 | // are all the callsites that were inlined into this function. |
| 628 | for (uint32_t I = 0; I < NumCallsites; I++) { |
Diego Novillo | 3376a78 | 2015-09-17 00:17:24 +0000 | [diff] [blame] | 629 | // The offset is encoded as: |
| 630 | // high 16 bits: line offset to the start of the function. |
| 631 | // low 16 bits: discriminator. |
| 632 | uint32_t Offset; |
| 633 | if (!GcovBuffer.readInt(Offset)) |
| 634 | return sampleprof_error::truncated; |
Diego Novillo | aae1ed8 | 2015-10-08 19:40:37 +0000 | [diff] [blame] | 635 | InlineCallStack NewStack; |
| 636 | NewStack.push_back(FProfile); |
| 637 | NewStack.insert(NewStack.end(), InlineStack.begin(), InlineStack.end()); |
| 638 | if (std::error_code EC = readOneFunctionProfile(NewStack, Update, Offset)) |
Diego Novillo | 3376a78 | 2015-09-17 00:17:24 +0000 | [diff] [blame] | 639 | return EC; |
| 640 | } |
| 641 | |
| 642 | return sampleprof_error::success; |
| 643 | } |
| 644 | |
Diego Novillo | 3376a78 | 2015-09-17 00:17:24 +0000 | [diff] [blame] | 645 | /// \brief Read a GCC AutoFDO profile. |
| 646 | /// |
| 647 | /// This format is generated by the Linux Perf conversion tool at |
| 648 | /// https://github.com/google/autofdo. |
| 649 | std::error_code SampleProfileReaderGCC::read() { |
| 650 | // Read the string table. |
| 651 | if (std::error_code EC = readNameTable()) |
| 652 | return EC; |
| 653 | |
| 654 | // Read the source profile. |
| 655 | if (std::error_code EC = readFunctionProfiles()) |
| 656 | return EC; |
| 657 | |
Diego Novillo | 3376a78 | 2015-09-17 00:17:24 +0000 | [diff] [blame] | 658 | return sampleprof_error::success; |
| 659 | } |
| 660 | |
| 661 | bool SampleProfileReaderGCC::hasFormat(const MemoryBuffer &Buffer) { |
| 662 | StringRef Magic(reinterpret_cast<const char *>(Buffer.getBufferStart())); |
| 663 | return Magic == "adcg*704"; |
| 664 | } |
| 665 | |
Diego Novillo | c572e92 | 2014-10-30 18:00:06 +0000 | [diff] [blame] | 666 | /// \brief Prepare a memory buffer for the contents of \p Filename. |
Diego Novillo | de1ab26 | 2014-09-09 12:40:50 +0000 | [diff] [blame] | 667 | /// |
Diego Novillo | c572e92 | 2014-10-30 18:00:06 +0000 | [diff] [blame] | 668 | /// \returns an error code indicating the status of the buffer. |
Diego Novillo | fcd5560 | 2014-11-03 00:51:45 +0000 | [diff] [blame] | 669 | static ErrorOr<std::unique_ptr<MemoryBuffer>> |
| 670 | setupMemoryBuffer(std::string Filename) { |
Diego Novillo | c572e92 | 2014-10-30 18:00:06 +0000 | [diff] [blame] | 671 | auto BufferOrErr = MemoryBuffer::getFileOrSTDIN(Filename); |
| 672 | if (std::error_code EC = BufferOrErr.getError()) |
| 673 | return EC; |
Diego Novillo | fcd5560 | 2014-11-03 00:51:45 +0000 | [diff] [blame] | 674 | auto Buffer = std::move(BufferOrErr.get()); |
Diego Novillo | c572e92 | 2014-10-30 18:00:06 +0000 | [diff] [blame] | 675 | |
| 676 | // Sanity check the file. |
Diego Novillo | 38be333 | 2015-10-15 16:36:21 +0000 | [diff] [blame] | 677 | if (Buffer->getBufferSize() > std::numeric_limits<uint32_t>::max()) |
Diego Novillo | c572e92 | 2014-10-30 18:00:06 +0000 | [diff] [blame] | 678 | return sampleprof_error::too_large; |
| 679 | |
Diego Novillo | fcd5560 | 2014-11-03 00:51:45 +0000 | [diff] [blame] | 680 | return std::move(Buffer); |
Diego Novillo | c572e92 | 2014-10-30 18:00:06 +0000 | [diff] [blame] | 681 | } |
| 682 | |
| 683 | /// \brief Create a sample profile reader based on the format of the input file. |
| 684 | /// |
| 685 | /// \param Filename The file to open. |
| 686 | /// |
| 687 | /// \param Reader The reader to instantiate according to \p Filename's format. |
| 688 | /// |
| 689 | /// \param C The LLVM context to use to emit diagnostics. |
| 690 | /// |
| 691 | /// \returns an error code indicating the status of the created reader. |
Diego Novillo | fcd5560 | 2014-11-03 00:51:45 +0000 | [diff] [blame] | 692 | ErrorOr<std::unique_ptr<SampleProfileReader>> |
| 693 | SampleProfileReader::create(StringRef Filename, LLVMContext &C) { |
| 694 | auto BufferOrError = setupMemoryBuffer(Filename); |
| 695 | if (std::error_code EC = BufferOrError.getError()) |
Diego Novillo | c572e92 | 2014-10-30 18:00:06 +0000 | [diff] [blame] | 696 | return EC; |
| 697 | |
Diego Novillo | fcd5560 | 2014-11-03 00:51:45 +0000 | [diff] [blame] | 698 | auto Buffer = std::move(BufferOrError.get()); |
| 699 | std::unique_ptr<SampleProfileReader> Reader; |
Diego Novillo | c572e92 | 2014-10-30 18:00:06 +0000 | [diff] [blame] | 700 | if (SampleProfileReaderBinary::hasFormat(*Buffer)) |
| 701 | Reader.reset(new SampleProfileReaderBinary(std::move(Buffer), C)); |
Diego Novillo | 3376a78 | 2015-09-17 00:17:24 +0000 | [diff] [blame] | 702 | else if (SampleProfileReaderGCC::hasFormat(*Buffer)) |
| 703 | Reader.reset(new SampleProfileReaderGCC(std::move(Buffer), C)); |
Nathan Slingerland | 4f82366 | 2015-11-13 03:47:58 +0000 | [diff] [blame] | 704 | else if (SampleProfileReaderText::hasFormat(*Buffer)) |
Nathan Slingerland | 911ced6 | 2015-11-12 18:39:26 +0000 | [diff] [blame] | 705 | Reader.reset(new SampleProfileReaderText(std::move(Buffer), C)); |
Nathan Slingerland | 4f82366 | 2015-11-13 03:47:58 +0000 | [diff] [blame] | 706 | else |
| 707 | return sampleprof_error::unrecognized_format; |
Diego Novillo | c572e92 | 2014-10-30 18:00:06 +0000 | [diff] [blame] | 708 | |
Diego Novillo | fcd5560 | 2014-11-03 00:51:45 +0000 | [diff] [blame] | 709 | if (std::error_code EC = Reader->readHeader()) |
| 710 | return EC; |
| 711 | |
| 712 | return std::move(Reader); |
Diego Novillo | de1ab26 | 2014-09-09 12:40:50 +0000 | [diff] [blame] | 713 | } |