LLVM  14.0.0git
BitstreamRemarkParser.cpp
Go to the documentation of this file.
1 //===- BitstreamRemarkParser.cpp ------------------------------------------===//
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 // This file provides utility methods used by clients that want to use the
10 // parser for remark diagnostics in LLVM.
11 //
12 //===----------------------------------------------------------------------===//
13 
15 #include "BitstreamRemarkParser.h"
17 #include "llvm/Support/Path.h"
18 
19 using namespace llvm;
20 using namespace llvm::remarks;
21 
22 static Error unknownRecord(const char *BlockName, unsigned RecordID) {
23  return createStringError(
24  std::make_error_code(std::errc::illegal_byte_sequence),
25  "Error while parsing %s: unknown record entry (%lu).", BlockName,
26  RecordID);
27 }
28 
29 static Error malformedRecord(const char *BlockName, const char *RecordName) {
30  return createStringError(
31  std::make_error_code(std::errc::illegal_byte_sequence),
32  "Error while parsing %s: malformed record entry (%s).", BlockName,
33  RecordName);
34 }
35 
37  BitstreamCursor &Stream, BitstreamBlockInfo &BlockInfo)
38  : Stream(Stream), BlockInfo(BlockInfo) {}
39 
40 /// Parse a record and fill in the fields in the parser.
41 static Error parseRecord(BitstreamMetaParserHelper &Parser, unsigned Code) {
42  BitstreamCursor &Stream = Parser.Stream;
43  // Note: 2 is used here because it's the max number of fields we have per
44  // record.
46  StringRef Blob;
47  Expected<unsigned> RecordID = Stream.readRecord(Code, Record, &Blob);
48  if (!RecordID)
49  return RecordID.takeError();
50 
51  switch (*RecordID) {
53  if (Record.size() != 2)
54  return malformedRecord("BLOCK_META", "RECORD_META_CONTAINER_INFO");
55  Parser.ContainerVersion = Record[0];
56  Parser.ContainerType = Record[1];
57  break;
58  }
60  if (Record.size() != 1)
61  return malformedRecord("BLOCK_META", "RECORD_META_REMARK_VERSION");
62  Parser.RemarkVersion = Record[0];
63  break;
64  }
65  case RECORD_META_STRTAB: {
66  if (Record.size() != 0)
67  return malformedRecord("BLOCK_META", "RECORD_META_STRTAB");
68  Parser.StrTabBuf = Blob;
69  break;
70  }
72  if (Record.size() != 0)
73  return malformedRecord("BLOCK_META", "RECORD_META_EXTERNAL_FILE");
74  Parser.ExternalFilePath = Blob;
75  break;
76  }
77  default:
78  return unknownRecord("BLOCK_META", *RecordID);
79  }
80  return Error::success();
81 }
82 
84  BitstreamCursor &Stream)
85  : Stream(Stream) {}
86 
87 /// Parse a record and fill in the fields in the parser.
88 static Error parseRecord(BitstreamRemarkParserHelper &Parser, unsigned Code) {
89  BitstreamCursor &Stream = Parser.Stream;
90  // Note: 5 is used here because it's the max number of fields we have per
91  // record.
93  StringRef Blob;
94  Expected<unsigned> RecordID = Stream.readRecord(Code, Record, &Blob);
95  if (!RecordID)
96  return RecordID.takeError();
97 
98  switch (*RecordID) {
99  case RECORD_REMARK_HEADER: {
100  if (Record.size() != 4)
101  return malformedRecord("BLOCK_REMARK", "RECORD_REMARK_HEADER");
102  Parser.Type = Record[0];
103  Parser.RemarkNameIdx = Record[1];
104  Parser.PassNameIdx = Record[2];
105  Parser.FunctionNameIdx = Record[3];
106  break;
107  }
109  if (Record.size() != 3)
110  return malformedRecord("BLOCK_REMARK", "RECORD_REMARK_DEBUG_LOC");
111  Parser.SourceFileNameIdx = Record[0];
112  Parser.SourceLine = Record[1];
113  Parser.SourceColumn = Record[2];
114  break;
115  }
116  case RECORD_REMARK_HOTNESS: {
117  if (Record.size() != 1)
118  return malformedRecord("BLOCK_REMARK", "RECORD_REMARK_HOTNESS");
119  Parser.Hotness = Record[0];
120  break;
121  }
123  if (Record.size() != 5)
124  return malformedRecord("BLOCK_REMARK", "RECORD_REMARK_ARG_WITH_DEBUGLOC");
125  // Create a temporary argument. Use that as a valid memory location for this
126  // argument entry.
127  Parser.TmpArgs.emplace_back();
128  Parser.TmpArgs.back().KeyIdx = Record[0];
129  Parser.TmpArgs.back().ValueIdx = Record[1];
130  Parser.TmpArgs.back().SourceFileNameIdx = Record[2];
131  Parser.TmpArgs.back().SourceLine = Record[3];
132  Parser.TmpArgs.back().SourceColumn = Record[4];
133  Parser.Args =
135  break;
136  }
138  if (Record.size() != 2)
139  return malformedRecord("BLOCK_REMARK",
140  "RECORD_REMARK_ARG_WITHOUT_DEBUGLOC");
141  // Create a temporary argument. Use that as a valid memory location for this
142  // argument entry.
143  Parser.TmpArgs.emplace_back();
144  Parser.TmpArgs.back().KeyIdx = Record[0];
145  Parser.TmpArgs.back().ValueIdx = Record[1];
146  Parser.Args =
148  break;
149  }
150  default:
151  return unknownRecord("BLOCK_REMARK", *RecordID);
152  }
153  return Error::success();
154 }
155 
156 template <typename T>
157 static Error parseBlock(T &ParserHelper, unsigned BlockID,
158  const char *BlockName) {
159  BitstreamCursor &Stream = ParserHelper.Stream;
160  Expected<BitstreamEntry> Next = Stream.advance();
161  if (!Next)
162  return Next.takeError();
163  if (Next->Kind != BitstreamEntry::SubBlock || Next->ID != BlockID)
164  return createStringError(
165  std::make_error_code(std::errc::illegal_byte_sequence),
166  "Error while parsing %s: expecting [ENTER_SUBBLOCK, %s, ...].",
167  BlockName, BlockName);
168  if (Stream.EnterSubBlock(BlockID))
169  return createStringError(
170  std::make_error_code(std::errc::illegal_byte_sequence),
171  "Error while entering %s.", BlockName);
172 
173  // Stop when there is nothing to read anymore or when we encounter an
174  // END_BLOCK.
175  while (!Stream.AtEndOfStream()) {
176  Next = Stream.advance();
177  if (!Next)
178  return Next.takeError();
179  switch (Next->Kind) {
181  return Error::success();
184  return createStringError(
185  std::make_error_code(std::errc::illegal_byte_sequence),
186  "Error while parsing %s: expecting records.", BlockName);
188  if (Error E = parseRecord(ParserHelper, Next->ID))
189  return E;
190  continue;
191  }
192  }
193  // If we're here, it means we didn't get an END_BLOCK yet, but we're at the
194  // end of the stream. In this case, error.
195  return createStringError(
196  std::make_error_code(std::errc::illegal_byte_sequence),
197  "Error while parsing %s: unterminated block.", BlockName);
198 }
199 
201  return parseBlock(*this, META_BLOCK_ID, "META_BLOCK");
202 }
203 
205  return parseBlock(*this, REMARK_BLOCK_ID, "REMARK_BLOCK");
206 }
207 
209  : Stream(Buffer) {}
210 
212  std::array<char, 4> Result;
213  for (unsigned i = 0; i < 4; ++i)
214  if (Expected<unsigned> R = Stream.Read(8))
215  Result[i] = *R;
216  else
217  return R.takeError();
218  return Result;
219 }
220 
223  if (!Next)
224  return Next.takeError();
225  if (Next->Kind != BitstreamEntry::SubBlock ||
226  Next->ID != llvm::bitc::BLOCKINFO_BLOCK_ID)
227  return createStringError(
228  std::make_error_code(std::errc::illegal_byte_sequence),
229  "Error while parsing BLOCKINFO_BLOCK: expecting [ENTER_SUBBLOCK, "
230  "BLOCKINFO_BLOCK, ...].");
231 
232  Expected<Optional<BitstreamBlockInfo>> MaybeBlockInfo =
234  if (!MaybeBlockInfo)
235  return MaybeBlockInfo.takeError();
236 
237  if (!*MaybeBlockInfo)
238  return createStringError(
239  std::make_error_code(std::errc::illegal_byte_sequence),
240  "Error while parsing BLOCKINFO_BLOCK.");
241 
242  BlockInfo = **MaybeBlockInfo;
243 
245  return Error::success();
246 }
247 
248 static Expected<bool> isBlock(BitstreamCursor &Stream, unsigned BlockID) {
249  bool Result = false;
250  uint64_t PreviousBitNo = Stream.GetCurrentBitNo();
251  Expected<BitstreamEntry> Next = Stream.advance();
252  if (!Next)
253  return Next.takeError();
254  switch (Next->Kind) {
256  // Check for the block id.
257  Result = Next->ID == BlockID;
258  break;
260  return createStringError(
261  std::make_error_code(std::errc::illegal_byte_sequence),
262  "Unexpected error while parsing bitstream.");
263  default:
264  Result = false;
265  break;
266  }
267  if (Error E = Stream.JumpToBit(PreviousBitNo))
268  return std::move(E);
269  return Result;
270 }
271 
273  return isBlock(Stream, META_BLOCK_ID);
274 }
275 
277  return isBlock(Stream, META_BLOCK_ID);
278 }
279 
282  return createStringError(std::make_error_code(std::errc::invalid_argument),
283  "Unknown magic number: expecting %s, got %.4s.",
285  return Error::success();
286 }
287 
290  if (!MagicNumber)
291  return MagicNumber.takeError();
293  StringRef(MagicNumber->data(), MagicNumber->size())))
294  return E;
295  if (Error E = Helper.parseBlockInfoBlock())
296  return E;
297  Expected<bool> isMetaBlock = Helper.isMetaBlock();
298  if (!isMetaBlock)
299  return isMetaBlock.takeError();
300  if (!*isMetaBlock)
301  return createStringError(
302  std::make_error_code(std::errc::illegal_byte_sequence),
303  "Expecting META_BLOCK after the BLOCKINFO_BLOCK.");
304  return Error::success();
305 }
306 
310  Optional<StringRef> ExternalFilePrependPath) {
311  BitstreamParserHelper Helper(Buf);
313  if (!MagicNumber)
314  return MagicNumber.takeError();
315 
317  StringRef(MagicNumber->data(), MagicNumber->size())))
318  return std::move(E);
319 
320  auto Parser =
321  StrTab ? std::make_unique<BitstreamRemarkParser>(Buf, std::move(*StrTab))
322  : std::make_unique<BitstreamRemarkParser>(Buf);
323 
324  if (ExternalFilePrependPath)
325  Parser->ExternalFilePrependPath = std::string(*ExternalFilePrependPath);
326 
327  return std::move(Parser);
328 }
329 
332  return make_error<EndOfFileError>();
333 
334  if (!ReadyToParseRemarks) {
335  if (Error E = parseMeta())
336  return std::move(E);
337  ReadyToParseRemarks = true;
338  }
339 
340  return parseRemark();
341 }
342 
344  // Advance and to the meta block.
346  return E;
347 
350  if (Error E = MetaHelper.parse())
351  return E;
352 
353  if (Error E = processCommonMeta(MetaHelper))
354  return E;
355 
356  switch (ContainerType) {
358  return processStandaloneMeta(MetaHelper);
360  return processSeparateRemarksFileMeta(MetaHelper);
362  return processSeparateRemarksMetaMeta(MetaHelper);
363  }
364  llvm_unreachable("Unknown BitstreamRemarkContainerType enum");
365 }
366 
367 Error BitstreamRemarkParser::processCommonMeta(
368  BitstreamMetaParserHelper &Helper) {
371  else
372  return createStringError(
373  std::make_error_code(std::errc::illegal_byte_sequence),
374  "Error while parsing BLOCK_META: missing container version.");
375 
376  if (Optional<uint8_t> Type = Helper.ContainerType) {
377  // Always >= BitstreamRemarkContainerType::First since it's unsigned.
378  if (*Type > static_cast<uint8_t>(BitstreamRemarkContainerType::Last))
379  return createStringError(
380  std::make_error_code(std::errc::illegal_byte_sequence),
381  "Error while parsing BLOCK_META: invalid container type.");
382 
383  ContainerType = static_cast<BitstreamRemarkContainerType>(*Type);
384  } else
385  return createStringError(
386  std::make_error_code(std::errc::illegal_byte_sequence),
387  "Error while parsing BLOCK_META: missing container type.");
388 
389  return Error::success();
390 }
391 
393  Optional<StringRef> StrTabBuf) {
394  if (!StrTabBuf)
395  return createStringError(
396  std::make_error_code(std::errc::illegal_byte_sequence),
397  "Error while parsing BLOCK_META: missing string table.");
398  // Parse and assign the string table.
399  P.StrTab.emplace(*StrTabBuf);
400  return Error::success();
401 }
402 
404  Optional<uint64_t> RemarkVersion) {
405  if (!RemarkVersion)
406  return createStringError(
407  std::make_error_code(std::errc::illegal_byte_sequence),
408  "Error while parsing BLOCK_META: missing remark version.");
409  P.RemarkVersion = *RemarkVersion;
410  return Error::success();
411 }
412 
413 Error BitstreamRemarkParser::processExternalFilePath(
414  Optional<StringRef> ExternalFilePath) {
415  if (!ExternalFilePath)
416  return createStringError(
417  std::make_error_code(std::errc::illegal_byte_sequence),
418  "Error while parsing BLOCK_META: missing external file path.");
419 
421  sys::path::append(FullPath, *ExternalFilePath);
422 
423  // External file: open the external file, parse it, check if its metadata
424  // matches the one from the separate metadata, then replace the current parser
425  // with the one parsing the remarks.
427  MemoryBuffer::getFile(FullPath);
428  if (std::error_code EC = BufferOrErr.getError())
429  return createFileError(FullPath, EC);
430 
431  TmpRemarkBuffer = std::move(*BufferOrErr);
432 
433  // Don't try to parse the file if it's empty.
434  if (TmpRemarkBuffer->getBufferSize() == 0)
435  return make_error<EndOfFileError>();
436 
437  // Create a separate parser used for parsing the separate file.
439  // Advance and check until we can parse the meta block.
441  return E;
442  // Parse the meta from the separate file.
443  // Note: here we overwrite the BlockInfo with the one from the file. This will
444  // be used to parse the rest of the file.
445  BitstreamMetaParserHelper SeparateMetaHelper(ParserHelper.Stream,
447  if (Error E = SeparateMetaHelper.parse())
448  return E;
449 
450  uint64_t PreviousContainerVersion = ContainerVersion;
451  if (Error E = processCommonMeta(SeparateMetaHelper))
452  return E;
453 
455  return createStringError(
456  std::make_error_code(std::errc::illegal_byte_sequence),
457  "Error while parsing external file's BLOCK_META: wrong container "
458  "type.");
459 
460  if (PreviousContainerVersion != ContainerVersion)
461  return createStringError(
462  std::make_error_code(std::errc::illegal_byte_sequence),
463  "Error while parsing external file's BLOCK_META: mismatching versions: "
464  "original meta: %lu, external file meta: %lu.",
465  PreviousContainerVersion, ContainerVersion);
466 
467  // Process the meta from the separate file.
468  return processSeparateRemarksFileMeta(SeparateMetaHelper);
469 }
470 
471 Error BitstreamRemarkParser::processStandaloneMeta(
472  BitstreamMetaParserHelper &Helper) {
473  if (Error E = processStrTab(*this, Helper.StrTabBuf))
474  return E;
475  return processRemarkVersion(*this, Helper.RemarkVersion);
476 }
477 
478 Error BitstreamRemarkParser::processSeparateRemarksFileMeta(
479  BitstreamMetaParserHelper &Helper) {
480  return processRemarkVersion(*this, Helper.RemarkVersion);
481 }
482 
483 Error BitstreamRemarkParser::processSeparateRemarksMetaMeta(
484  BitstreamMetaParserHelper &Helper) {
485  if (Error E = processStrTab(*this, Helper.StrTabBuf))
486  return E;
487  return processExternalFilePath(Helper.ExternalFilePath);
488 }
489 
492  if (Error E = RemarkHelper.parse())
493  return std::move(E);
494 
495  return processRemark(RemarkHelper);
496 }
497 
499 BitstreamRemarkParser::processRemark(BitstreamRemarkParserHelper &Helper) {
500  std::unique_ptr<Remark> Result = std::make_unique<Remark>();
501  Remark &R = *Result;
502 
503  if (StrTab == None)
504  return createStringError(
505  std::make_error_code(std::errc::invalid_argument),
506  "Error while parsing BLOCK_REMARK: missing string table.");
507 
508  if (!Helper.Type)
509  return createStringError(
510  std::make_error_code(std::errc::illegal_byte_sequence),
511  "Error while parsing BLOCK_REMARK: missing remark type.");
512 
513  // Always >= Type::First since it's unsigned.
514  if (*Helper.Type > static_cast<uint8_t>(Type::Last))
515  return createStringError(
516  std::make_error_code(std::errc::illegal_byte_sequence),
517  "Error while parsing BLOCK_REMARK: unknown remark type.");
518 
519  R.RemarkType = static_cast<Type>(*Helper.Type);
520 
521  if (!Helper.RemarkNameIdx)
522  return createStringError(
523  std::make_error_code(std::errc::illegal_byte_sequence),
524  "Error while parsing BLOCK_REMARK: missing remark name.");
525 
526  if (Expected<StringRef> RemarkName = (*StrTab)[*Helper.RemarkNameIdx])
527  R.RemarkName = *RemarkName;
528  else
529  return RemarkName.takeError();
530 
531  if (!Helper.PassNameIdx)
532  return createStringError(
533  std::make_error_code(std::errc::illegal_byte_sequence),
534  "Error while parsing BLOCK_REMARK: missing remark pass.");
535 
537  R.PassName = *PassName;
538  else
539  return PassName.takeError();
540 
541  if (!Helper.FunctionNameIdx)
542  return createStringError(
543  std::make_error_code(std::errc::illegal_byte_sequence),
544  "Error while parsing BLOCK_REMARK: missing remark function name.");
545  if (Expected<StringRef> FunctionName = (*StrTab)[*Helper.FunctionNameIdx])
546  R.FunctionName = *FunctionName;
547  else
548  return FunctionName.takeError();
549 
550  if (Helper.SourceFileNameIdx && Helper.SourceLine && Helper.SourceColumn) {
551  Expected<StringRef> SourceFileName = (*StrTab)[*Helper.SourceFileNameIdx];
552  if (!SourceFileName)
553  return SourceFileName.takeError();
554  R.Loc.emplace();
555  R.Loc->SourceFilePath = *SourceFileName;
556  R.Loc->SourceLine = *Helper.SourceLine;
557  R.Loc->SourceColumn = *Helper.SourceColumn;
558  }
559 
560  if (Helper.Hotness)
561  R.Hotness = *Helper.Hotness;
562 
563  if (!Helper.Args)
564  return std::move(Result);
565 
566  for (const BitstreamRemarkParserHelper::Argument &Arg : *Helper.Args) {
567  if (!Arg.KeyIdx)
568  return createStringError(
569  std::make_error_code(std::errc::illegal_byte_sequence),
570  "Error while parsing BLOCK_REMARK: missing key in remark argument.");
571  if (!Arg.ValueIdx)
572  return createStringError(
573  std::make_error_code(std::errc::illegal_byte_sequence),
574  "Error while parsing BLOCK_REMARK: missing value in remark "
575  "argument.");
576 
577  // We have at least a key and a value, create an entry.
578  R.Args.emplace_back();
579 
580  if (Expected<StringRef> Key = (*StrTab)[*Arg.KeyIdx])
581  R.Args.back().Key = *Key;
582  else
583  return Key.takeError();
584 
585  if (Expected<StringRef> Value = (*StrTab)[*Arg.ValueIdx])
586  R.Args.back().Val = *Value;
587  else
588  return Value.takeError();
589 
590  if (Arg.SourceFileNameIdx && Arg.SourceLine && Arg.SourceColumn) {
591  if (Expected<StringRef> SourceFileName =
592  (*StrTab)[*Arg.SourceFileNameIdx]) {
593  R.Args.back().Loc.emplace();
594  R.Args.back().Loc->SourceFilePath = *SourceFileName;
595  R.Args.back().Loc->SourceLine = *Arg.SourceLine;
596  R.Args.back().Loc->SourceColumn = *Arg.SourceColumn;
597  } else
598  return SourceFileName.takeError();
599  }
600  }
601 
602  return std::move(Result);
603 }
i
i
Definition: README.txt:29
llvm::remarks::BitstreamRemarkParserHelper::parse
Error parse()
Parse the REMARK_BLOCK and fill the available entries.
Definition: BitstreamRemarkParser.cpp:204
MemoryBuffer.h
llvm::remarks::BitstreamParserHelper
Helper to parse any bitstream remark container.
Definition: BitstreamRemarkParser.h:89
malformedRecord
static Error malformedRecord(const char *BlockName, const char *RecordName)
Definition: BitstreamRemarkParser.cpp:29
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
llvm::remarks::BitstreamRemarkParser::parseMeta
Error parseMeta()
Parse and process the metadata of the buffer.
Definition: BitstreamRemarkParser.cpp:343
llvm::remarks::BitstreamMetaParserHelper::BitstreamMetaParserHelper
BitstreamMetaParserHelper(BitstreamCursor &Stream, BitstreamBlockInfo &BlockInfo)
Continue parsing with Stream.
Definition: BitstreamRemarkParser.cpp:36
llvm::remarks::BitstreamMetaParserHelper::StrTabBuf
Optional< StringRef > StrTabBuf
Definition: BitstreamRemarkParser.h:38
llvm::remarks::BitstreamMetaParserHelper::RemarkVersion
Optional< uint64_t > RemarkVersion
Definition: BitstreamRemarkParser.h:40
T
P
This currently compiles esp xmm0 movsd esp eax eax esp ret We should use not the dag combiner This is because dagcombine2 needs to be able to see through the X86ISD::Wrapper which DAGCombine can t really do The code for turning x load into a single vector load is target independent and should be moved to the dag combiner The code for turning x load into a vector load can only handle a direct load from a global or a direct load from the stack It should be generalized to handle any load from P
Definition: README-SSE.txt:411
llvm::BitstreamEntry::EndBlock
@ EndBlock
Definition: BitstreamReader.h:310
llvm::remarks::RECORD_META_CONTAINER_INFO
@ RECORD_META_CONTAINER_INFO
Definition: BitstreamRemarkContainer.h:77
llvm::BitstreamBlockInfo
This class maintains the abbreviations read from a block info block.
Definition: BitstreamReader.h:38
llvm::SmallVector
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1168
parseRecord
static Error parseRecord(BitstreamMetaParserHelper &Parser, unsigned Code)
Parse a record and fill in the fields in the parser.
Definition: BitstreamRemarkParser.cpp:41
Path.h
llvm::remarks::BitstreamMetaParserHelper
Helper to parse a META_BLOCK for a bitstream remark container.
Definition: BitstreamRemarkParser.h:29
isBlock
static Expected< bool > isBlock(BitstreamCursor &Stream, unsigned BlockID)
Definition: BitstreamRemarkParser.cpp:248
llvm::remarks::RECORD_REMARK_DEBUG_LOC
@ RECORD_REMARK_DEBUG_LOC
Definition: BitstreamRemarkContainer.h:83
llvm::Error::success
static ErrorSuccess success()
Create a success value.
Definition: Error.h:331
llvm::remarks::BitstreamMetaParserHelper::parse
Error parse()
Parse the META_BLOCK and fill the available entries.
Definition: BitstreamRemarkParser.cpp:200
llvm::BitstreamCursor
This represents a position within a bitcode file, implemented on top of a SimpleBitstreamCursor.
Definition: BitstreamReader.h:340
llvm::remarks::BitstreamParserHelper::atEndOfStream
bool atEndOfStream()
Return true if the parser reached the end of the stream.
Definition: BitstreamRemarkParser.h:108
llvm::Optional
Definition: APInt.h:33
llvm::bitc::BLOCKINFO_BLOCK_ID
@ BLOCKINFO_BLOCK_ID
BLOCKINFO_BLOCK is used to define metadata about blocks, for example, standard abbrevs that should be...
Definition: BitCodes.h:71
llvm::BitstreamCursor::JumpToBit
Error JumpToBit(uint64_t BitNo)
Reset the stream to the specified bit number.
Definition: BitstreamReader.h:131
llvm::BitstreamEntry::Record
@ Record
Definition: BitstreamReader.h:313
parseBlock
static Error parseBlock(T &ParserHelper, unsigned BlockID, const char *BlockName)
Definition: BitstreamRemarkParser.cpp:157
llvm::remarks::BitstreamParserHelper::BitstreamParserHelper
BitstreamParserHelper(StringRef Buffer)
Start parsing at Buffer.
Definition: BitstreamRemarkParser.cpp:208
llvm::Expected
Tagged union holding either a T or a Error.
Definition: APFloat.h:42
llvm::BitstreamEntry::SubBlock
@ SubBlock
Definition: BitstreamReader.h:312
unknownRecord
static Error unknownRecord(const char *BlockName, unsigned RecordID)
Definition: BitstreamRemarkParser.cpp:22
llvm::sys::path::append
void append(SmallVectorImpl< char > &path, const Twine &a, const Twine &b="", const Twine &c="", const Twine &d="")
Append to path.
Definition: Path.cpp:454
Arg
amdgpu Simplify well known AMD library false FunctionCallee Value * Arg
Definition: AMDGPULibCalls.cpp:206
llvm::remarks::RECORD_REMARK_ARG_WITH_DEBUGLOC
@ RECORD_REMARK_ARG_WITH_DEBUGLOC
Definition: BitstreamRemarkContainer.h:85
llvm::BitstreamEntry::Error
@ Error
Definition: BitstreamReader.h:309
llvm::MemoryBuffer::getFile
static ErrorOr< std::unique_ptr< MemoryBuffer > > getFile(const Twine &Filename, bool IsText=false, bool RequiresNullTerminator=true, bool IsVolatile=false)
Open the specified file as a MemoryBuffer, returning a new MemoryBuffer if successful,...
Definition: MemoryBuffer.cpp:246
llvm::remarks::BitstreamRemarkParserHelper::Type
Optional< uint8_t > Type
The parsed content: depending on the remark, some fields might be empty.
Definition: BitstreamRemarkParser.h:58
llvm::remarks::BitstreamRemarkParserHelper::TmpArgs
SmallVector< Argument, 8 > TmpArgs
Avoid re-allocating a vector every time.
Definition: BitstreamRemarkParser.h:75
llvm::createFileError
Error createFileError(const Twine &F, Error E)
Concatenate a source file path and/or name with an Error.
Definition: Error.h:1312
llvm::remarks::BitstreamRemarkParserHelper::SourceColumn
Optional< uint32_t > SourceColumn
Definition: BitstreamRemarkParser.h:64
E
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
llvm::BitstreamCursor::setBlockInfo
void setBlockInfo(BitstreamBlockInfo *BI)
Set the block info to be used by this BitstreamCursor to interpret abbreviated records.
Definition: BitstreamReader.h:554
llvm::remarks::BitstreamRemarkParser::ReadyToParseRemarks
bool ReadyToParseRemarks
Wether the parser is ready to parse remarks.
Definition: BitstreamRemarkParser.h:42
llvm::AMDGPU::PALMD::Key
Key
PAL metadata keys.
Definition: AMDGPUMetadata.h:481
llvm::remarks::BitstreamRemarkParserHelper::Stream
BitstreamCursor & Stream
The Bitstream reader.
Definition: BitstreamRemarkParser.h:56
llvm::ErrorOr::getError
std::error_code getError() const
Definition: ErrorOr.h:153
llvm::remarks::BitstreamParserHelper::parseBlockInfoBlock
Error parseBlockInfoBlock()
Parse the block info block containing all the abbrevs.
Definition: BitstreamRemarkParser.cpp:221
llvm::remarks::RECORD_META_EXTERNAL_FILE
@ RECORD_META_EXTERNAL_FILE
Definition: BitstreamRemarkContainer.h:80
llvm::remarks::BitstreamRemarkParser::ContainerVersion
uint64_t ContainerVersion
The common metadata used to decide how to parse the buffer.
Definition: BitstreamRemarkParser.h:37
advanceToMetaBlock
static Error advanceToMetaBlock(BitstreamParserHelper &Helper)
Definition: BitstreamRemarkParser.cpp:288
llvm::remarks::BitstreamParserHelper::BlockInfo
BitstreamBlockInfo BlockInfo
The block info block.
Definition: BitstreamRemarkParser.h:93
llvm::IndexedInstrProf::Version
const uint64_t Version
Definition: InstrProf.h:991
llvm::remarks::Remark
A remark type used for both emission and parsing.
Definition: Remark.h:67
llvm::BitstreamCursor::EnterSubBlock
Error EnterSubBlock(unsigned BlockID, unsigned *NumWordsP=nullptr)
Having read the ENTER_SUBBLOCK abbrevid, and enter the block.
Definition: BitstreamReader.cpp:21
llvm::SmallString
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
Definition: SmallString.h:25
llvm::remarks
Definition: AsmPrinter.h:77
llvm::remarks::BitstreamRemarkParserHelper
Helper to parse a REMARK_BLOCK for a bitstream remark container.
Definition: BitstreamRemarkParser.h:54
llvm::remarks::RECORD_REMARK_HEADER
@ RECORD_REMARK_HEADER
Definition: BitstreamRemarkContainer.h:82
llvm::remarks::BitstreamRemarkParserHelper::SourceFileNameIdx
Optional< uint64_t > SourceFileNameIdx
Definition: BitstreamRemarkParser.h:62
llvm::BitstreamCursor::GetCurrentBitNo
uint64_t GetCurrentBitNo() const
Return the bit # of the bit we are reading.
Definition: BitstreamReader.h:121
llvm::remarks::BitstreamMetaParserHelper::ContainerType
Optional< uint8_t > ContainerType
Definition: BitstreamRemarkParser.h:37
uint64_t
llvm::remarks::BitstreamRemarkContainerType::Standalone
@ Standalone
Everything is emitted together.
BitstreamRemarkParser.h
llvm::BitstreamCursor::Read
Expected< word_t > Read(unsigned NumBits)
Definition: BitstreamReader.h:190
move
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
Definition: README.txt:546
llvm::remarks::BitstreamRemarkParser
Parses and holds the state of the latest parsed remark.
Definition: BitstreamRemarkParser.h:28
llvm::remarks::RECORD_REMARK_HOTNESS
@ RECORD_REMARK_HOTNESS
Definition: BitstreamRemarkContainer.h:84
llvm::remarks::BitstreamRemarkParserHelper::RemarkNameIdx
Optional< uint64_t > RemarkNameIdx
Definition: BitstreamRemarkParser.h:59
llvm::remarks::BitstreamRemarkContainerType::Last
@ Last
llvm::BitstreamCursor::ReadBlockInfoBlock
Expected< Optional< BitstreamBlockInfo > > ReadBlockInfoBlock(bool ReadBlockInfoNames=false)
Read and return a block info block from the bitstream.
Definition: BitstreamReader.cpp:404
llvm::remarks::BitstreamRemarkParser::next
Expected< std::unique_ptr< Remark > > next() override
If no error occurs, this returns a valid Remark object.
Definition: BitstreamRemarkParser.cpp:330
llvm::remarks::BitstreamRemarkParser::parseRemark
Expected< std::unique_ptr< Remark > > parseRemark()
Parse a Bitstream remark.
Definition: BitstreamRemarkParser.cpp:490
llvm::Record
Definition: Record.h:1472
llvm::remarks::BitstreamRemarkContainerType::SeparateRemarksMeta
@ SeparateRemarksMeta
The metadata emitted separately.
processStrTab
static Error processStrTab(BitstreamRemarkParser &P, Optional< StringRef > StrTabBuf)
Definition: BitstreamRemarkParser.cpp:392
llvm::remarks::BitstreamParserHelper::Stream
BitstreamCursor Stream
The Bitstream reader.
Definition: BitstreamRemarkParser.h:91
llvm::remarks::META_BLOCK_ID
@ META_BLOCK_ID
The metadata block is mandatory.
Definition: BitstreamRemarkContainer.h:64
llvm::remarks::RECORD_META_STRTAB
@ RECORD_META_STRTAB
Definition: BitstreamRemarkContainer.h:79
llvm::BitstreamCursor::readRecord
Expected< unsigned > readRecord(unsigned AbbrevID, SmallVectorImpl< uint64_t > &Vals, StringRef *Blob=nullptr)
Definition: BitstreamReader.cpp:205
llvm::remarks::Type
Type
The type of the remark.
Definition: Remark.h:54
llvm::remarks::REMARK_BLOCK_ID
@ REMARK_BLOCK_ID
One remark entry is represented using a REMARK_BLOCK.
Definition: BitstreamRemarkContainer.h:67
llvm::BitstreamCursor::AtEndOfStream
bool AtEndOfStream()
Definition: BitstreamReader.h:116
llvm::remarks::BitstreamParserHelper::isMetaBlock
Expected< bool > isMetaBlock()
Return true if the next block is a META_BLOCK.
Definition: BitstreamRemarkParser.cpp:272
llvm::remarks::BitstreamRemarkParser::ParserHelper
BitstreamParserHelper ParserHelper
The buffer to parse.
Definition: BitstreamRemarkParser.h:30
llvm::ArrayRef
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: APInt.h:32
llvm::remarks::ContainerMagic
constexpr StringLiteral ContainerMagic("RMRK")
The magic number used for identifying remark blocks.
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
llvm::remarks::RECORD_REMARK_ARG_WITHOUT_DEBUGLOC
@ RECORD_REMARK_ARG_WITHOUT_DEBUGLOC
Definition: BitstreamRemarkContainer.h:86
validateMagicNumber
static Error validateMagicNumber(StringRef MagicNumber)
Definition: BitstreamRemarkParser.cpp:280
llvm_unreachable
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:136
llvm::BitstreamCursor::advance
Expected< BitstreamEntry > advance(unsigned Flags=0)
Advance the current bitstream, returning the next entry in the stream.
Definition: BitstreamReader.h:400
llvm::remarks::BitstreamMetaParserHelper::Stream
BitstreamCursor & Stream
The Bitstream reader.
Definition: BitstreamRemarkParser.h:31
llvm::remarks::BitstreamMetaParserHelper::ExternalFilePath
Optional< StringRef > ExternalFilePath
Definition: BitstreamRemarkParser.h:39
llvm::remarks::BitstreamRemarkParser::ContainerType
BitstreamRemarkContainerType ContainerType
Definition: BitstreamRemarkParser.h:39
llvm::remarks::BitstreamRemarkParserHelper::PassNameIdx
Optional< uint64_t > PassNameIdx
Definition: BitstreamRemarkParser.h:60
llvm::remarks::BitstreamRemarkParserHelper::BitstreamRemarkParserHelper
BitstreamRemarkParserHelper(BitstreamCursor &Stream)
Continue parsing with Stream.
Definition: BitstreamRemarkParser.cpp:83
llvm::remarks::BitstreamRemarkParser::StrTab
Optional< ParsedStringTable > StrTab
The string table used for parsing strings.
Definition: BitstreamRemarkParser.h:32
llvm::make_error_code
std::error_code make_error_code(BitcodeError E)
Definition: BitcodeReader.h:270
llvm::remarks::RECORD_META_REMARK_VERSION
@ RECORD_META_REMARK_VERSION
Definition: BitstreamRemarkContainer.h:78
llvm::remarks::BitstreamRemarkParserHelper::SourceLine
Optional< uint32_t > SourceLine
Definition: BitstreamRemarkParser.h:63
llvm::createStringError
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
Definition: Error.h:1231
llvm::remarks::Type::Last
@ Last
llvm::remarks::BitstreamMetaParserHelper::ContainerVersion
Optional< uint64_t > ContainerVersion
The parsed content: depending on the container type, some fields might be empty.
Definition: BitstreamRemarkParser.h:36
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:157
llvm::XCOFF::MagicNumber
MagicNumber
Definition: XCOFF.h:42
llvm::remarks::BitstreamRemarkParserHelper::Argument
Definition: BitstreamRemarkParser.h:66
llvm::remarks::BitstreamRemarkParserHelper::Args
Optional< ArrayRef< Argument > > Args
Definition: BitstreamRemarkParser.h:73
llvm::TargetStackID::Value
Value
Definition: TargetFrameLowering.h:27
llvm::remarks::RemarkParser::ExternalFilePrependPath
std::string ExternalFilePrependPath
Path to prepend when opening an external remark file.
Definition: RemarkParser.h:43
llvm::Expected::takeError
Error takeError()
Take ownership of the stored error.
Definition: Error.h:589
llvm::remarks::BitstreamRemarkParser::TmpRemarkBuffer
std::unique_ptr< MemoryBuffer > TmpRemarkBuffer
Temporary remark buffer used when the remarks are stored separately.
Definition: BitstreamRemarkParser.h:34
llvm::remarks::BitstreamRemarkParserHelper::FunctionNameIdx
Optional< uint64_t > FunctionNameIdx
Definition: BitstreamRemarkParser.h:61
llvm::ErrorOr
Represents either an error or a value T.
Definition: ErrorOr.h:56
processRemarkVersion
static Error processRemarkVersion(BitstreamRemarkParser &P, Optional< uint64_t > RemarkVersion)
Definition: BitstreamRemarkParser.cpp:403
llvm::remarks::BitstreamParserHelper::parseMagic
Expected< std::array< char, 4 > > parseMagic()
Parse the magic number.
Definition: BitstreamRemarkParser.cpp:211
llvm::remarks::BitstreamParserHelper::isRemarkBlock
Expected< bool > isRemarkBlock()
Return true if the next block is a REMARK_BLOCK.
Definition: BitstreamRemarkParser.cpp:276
llvm::remarks::createBitstreamParserFromMeta
Expected< std::unique_ptr< BitstreamRemarkParser > > createBitstreamParserFromMeta(StringRef Buf, Optional< ParsedStringTable > StrTab=None, Optional< StringRef > ExternalFilePrependPath=None)
Definition: BitstreamRemarkParser.cpp:308
llvm::StringRef::data
const LLVM_NODISCARD char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
Definition: StringRef.h:149
llvm::remarks::BitstreamRemarkParserHelper::Hotness
Optional< uint64_t > Hotness
Definition: BitstreamRemarkParser.h:65
llvm::remarks::BitstreamRemarkContainerType::SeparateRemarksFile
@ SeparateRemarksFile
The remarks emitted separately.
llvm::Value
LLVM Value Representation.
Definition: Value.h:75
PassName
static const char PassName[]
Definition: X86LowerAMXIntrinsics.cpp:669
llvm::remarks::BitstreamRemarkContainerType
BitstreamRemarkContainerType
Type of the remark container.
Definition: BitstreamRemarkContainer.h:35