LLVM  15.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"
16 #include "llvm/Remarks/Remark.h"
18 #include "llvm/Support/Path.h"
19 
20 using namespace llvm;
21 using namespace llvm::remarks;
22 
23 static Error unknownRecord(const char *BlockName, unsigned RecordID) {
24  return createStringError(
25  std::make_error_code(std::errc::illegal_byte_sequence),
26  "Error while parsing %s: unknown record entry (%lu).", BlockName,
27  RecordID);
28 }
29 
30 static Error malformedRecord(const char *BlockName, const char *RecordName) {
31  return createStringError(
32  std::make_error_code(std::errc::illegal_byte_sequence),
33  "Error while parsing %s: malformed record entry (%s).", BlockName,
34  RecordName);
35 }
36 
38  BitstreamCursor &Stream, BitstreamBlockInfo &BlockInfo)
39  : Stream(Stream), BlockInfo(BlockInfo) {}
40 
41 /// Parse a record and fill in the fields in the parser.
42 static Error parseRecord(BitstreamMetaParserHelper &Parser, unsigned Code) {
43  BitstreamCursor &Stream = Parser.Stream;
44  // Note: 2 is used here because it's the max number of fields we have per
45  // record.
47  StringRef Blob;
48  Expected<unsigned> RecordID = Stream.readRecord(Code, Record, &Blob);
49  if (!RecordID)
50  return RecordID.takeError();
51 
52  switch (*RecordID) {
54  if (Record.size() != 2)
55  return malformedRecord("BLOCK_META", "RECORD_META_CONTAINER_INFO");
56  Parser.ContainerVersion = Record[0];
57  Parser.ContainerType = Record[1];
58  break;
59  }
61  if (Record.size() != 1)
62  return malformedRecord("BLOCK_META", "RECORD_META_REMARK_VERSION");
63  Parser.RemarkVersion = Record[0];
64  break;
65  }
66  case RECORD_META_STRTAB: {
67  if (Record.size() != 0)
68  return malformedRecord("BLOCK_META", "RECORD_META_STRTAB");
69  Parser.StrTabBuf = Blob;
70  break;
71  }
73  if (Record.size() != 0)
74  return malformedRecord("BLOCK_META", "RECORD_META_EXTERNAL_FILE");
75  Parser.ExternalFilePath = Blob;
76  break;
77  }
78  default:
79  return unknownRecord("BLOCK_META", *RecordID);
80  }
81  return Error::success();
82 }
83 
85  BitstreamCursor &Stream)
86  : Stream(Stream) {}
87 
88 /// Parse a record and fill in the fields in the parser.
89 static Error parseRecord(BitstreamRemarkParserHelper &Parser, unsigned Code) {
90  BitstreamCursor &Stream = Parser.Stream;
91  // Note: 5 is used here because it's the max number of fields we have per
92  // record.
94  StringRef Blob;
95  Expected<unsigned> RecordID = Stream.readRecord(Code, Record, &Blob);
96  if (!RecordID)
97  return RecordID.takeError();
98 
99  switch (*RecordID) {
100  case RECORD_REMARK_HEADER: {
101  if (Record.size() != 4)
102  return malformedRecord("BLOCK_REMARK", "RECORD_REMARK_HEADER");
103  Parser.Type = Record[0];
104  Parser.RemarkNameIdx = Record[1];
105  Parser.PassNameIdx = Record[2];
106  Parser.FunctionNameIdx = Record[3];
107  break;
108  }
110  if (Record.size() != 3)
111  return malformedRecord("BLOCK_REMARK", "RECORD_REMARK_DEBUG_LOC");
112  Parser.SourceFileNameIdx = Record[0];
113  Parser.SourceLine = Record[1];
114  Parser.SourceColumn = Record[2];
115  break;
116  }
117  case RECORD_REMARK_HOTNESS: {
118  if (Record.size() != 1)
119  return malformedRecord("BLOCK_REMARK", "RECORD_REMARK_HOTNESS");
120  Parser.Hotness = Record[0];
121  break;
122  }
124  if (Record.size() != 5)
125  return malformedRecord("BLOCK_REMARK", "RECORD_REMARK_ARG_WITH_DEBUGLOC");
126  // Create a temporary argument. Use that as a valid memory location for this
127  // argument entry.
128  Parser.TmpArgs.emplace_back();
129  Parser.TmpArgs.back().KeyIdx = Record[0];
130  Parser.TmpArgs.back().ValueIdx = Record[1];
131  Parser.TmpArgs.back().SourceFileNameIdx = Record[2];
132  Parser.TmpArgs.back().SourceLine = Record[3];
133  Parser.TmpArgs.back().SourceColumn = Record[4];
134  Parser.Args =
136  break;
137  }
139  if (Record.size() != 2)
140  return malformedRecord("BLOCK_REMARK",
141  "RECORD_REMARK_ARG_WITHOUT_DEBUGLOC");
142  // Create a temporary argument. Use that as a valid memory location for this
143  // argument entry.
144  Parser.TmpArgs.emplace_back();
145  Parser.TmpArgs.back().KeyIdx = Record[0];
146  Parser.TmpArgs.back().ValueIdx = Record[1];
147  Parser.Args =
149  break;
150  }
151  default:
152  return unknownRecord("BLOCK_REMARK", *RecordID);
153  }
154  return Error::success();
155 }
156 
157 template <typename T>
158 static Error parseBlock(T &ParserHelper, unsigned BlockID,
159  const char *BlockName) {
160  BitstreamCursor &Stream = ParserHelper.Stream;
161  Expected<BitstreamEntry> Next = Stream.advance();
162  if (!Next)
163  return Next.takeError();
164  if (Next->Kind != BitstreamEntry::SubBlock || Next->ID != BlockID)
165  return createStringError(
166  std::make_error_code(std::errc::illegal_byte_sequence),
167  "Error while parsing %s: expecting [ENTER_SUBBLOCK, %s, ...].",
168  BlockName, BlockName);
169  if (Stream.EnterSubBlock(BlockID))
170  return createStringError(
171  std::make_error_code(std::errc::illegal_byte_sequence),
172  "Error while entering %s.", BlockName);
173 
174  // Stop when there is nothing to read anymore or when we encounter an
175  // END_BLOCK.
176  while (!Stream.AtEndOfStream()) {
177  Next = Stream.advance();
178  if (!Next)
179  return Next.takeError();
180  switch (Next->Kind) {
182  return Error::success();
185  return createStringError(
186  std::make_error_code(std::errc::illegal_byte_sequence),
187  "Error while parsing %s: expecting records.", BlockName);
189  if (Error E = parseRecord(ParserHelper, Next->ID))
190  return E;
191  continue;
192  }
193  }
194  // If we're here, it means we didn't get an END_BLOCK yet, but we're at the
195  // end of the stream. In this case, error.
196  return createStringError(
197  std::make_error_code(std::errc::illegal_byte_sequence),
198  "Error while parsing %s: unterminated block.", BlockName);
199 }
200 
202  return parseBlock(*this, META_BLOCK_ID, "META_BLOCK");
203 }
204 
206  return parseBlock(*this, REMARK_BLOCK_ID, "REMARK_BLOCK");
207 }
208 
210  : Stream(Buffer) {}
211 
213  std::array<char, 4> Result;
214  for (unsigned i = 0; i < 4; ++i)
215  if (Expected<unsigned> R = Stream.Read(8))
216  Result[i] = *R;
217  else
218  return R.takeError();
219  return Result;
220 }
221 
224  if (!Next)
225  return Next.takeError();
226  if (Next->Kind != BitstreamEntry::SubBlock ||
227  Next->ID != llvm::bitc::BLOCKINFO_BLOCK_ID)
228  return createStringError(
229  std::make_error_code(std::errc::illegal_byte_sequence),
230  "Error while parsing BLOCKINFO_BLOCK: expecting [ENTER_SUBBLOCK, "
231  "BLOCKINFO_BLOCK, ...].");
232 
233  Expected<Optional<BitstreamBlockInfo>> MaybeBlockInfo =
235  if (!MaybeBlockInfo)
236  return MaybeBlockInfo.takeError();
237 
238  if (!*MaybeBlockInfo)
239  return createStringError(
240  std::make_error_code(std::errc::illegal_byte_sequence),
241  "Error while parsing BLOCKINFO_BLOCK.");
242 
243  BlockInfo = **MaybeBlockInfo;
244 
246  return Error::success();
247 }
248 
249 static Expected<bool> isBlock(BitstreamCursor &Stream, unsigned BlockID) {
250  bool Result = false;
251  uint64_t PreviousBitNo = Stream.GetCurrentBitNo();
252  Expected<BitstreamEntry> Next = Stream.advance();
253  if (!Next)
254  return Next.takeError();
255  switch (Next->Kind) {
257  // Check for the block id.
258  Result = Next->ID == BlockID;
259  break;
261  return createStringError(
262  std::make_error_code(std::errc::illegal_byte_sequence),
263  "Unexpected error while parsing bitstream.");
264  default:
265  Result = false;
266  break;
267  }
268  if (Error E = Stream.JumpToBit(PreviousBitNo))
269  return std::move(E);
270  return Result;
271 }
272 
274  return isBlock(Stream, META_BLOCK_ID);
275 }
276 
278  return isBlock(Stream, META_BLOCK_ID);
279 }
280 
283  return createStringError(std::make_error_code(std::errc::invalid_argument),
284  "Unknown magic number: expecting %s, got %.4s.",
286  return Error::success();
287 }
288 
291  if (!MagicNumber)
292  return MagicNumber.takeError();
294  StringRef(MagicNumber->data(), MagicNumber->size())))
295  return E;
296  if (Error E = Helper.parseBlockInfoBlock())
297  return E;
298  Expected<bool> isMetaBlock = Helper.isMetaBlock();
299  if (!isMetaBlock)
300  return isMetaBlock.takeError();
301  if (!*isMetaBlock)
302  return createStringError(
303  std::make_error_code(std::errc::illegal_byte_sequence),
304  "Expecting META_BLOCK after the BLOCKINFO_BLOCK.");
305  return Error::success();
306 }
307 
311  Optional<StringRef> ExternalFilePrependPath) {
312  BitstreamParserHelper Helper(Buf);
314  if (!MagicNumber)
315  return MagicNumber.takeError();
316 
318  StringRef(MagicNumber->data(), MagicNumber->size())))
319  return std::move(E);
320 
321  auto Parser =
322  StrTab ? std::make_unique<BitstreamRemarkParser>(Buf, std::move(*StrTab))
323  : std::make_unique<BitstreamRemarkParser>(Buf);
324 
325  if (ExternalFilePrependPath)
326  Parser->ExternalFilePrependPath = std::string(*ExternalFilePrependPath);
327 
328  return std::move(Parser);
329 }
330 
333  return make_error<EndOfFileError>();
334 
335  if (!ReadyToParseRemarks) {
336  if (Error E = parseMeta())
337  return std::move(E);
338  ReadyToParseRemarks = true;
339  }
340 
341  return parseRemark();
342 }
343 
345  // Advance and to the meta block.
347  return E;
348 
351  if (Error E = MetaHelper.parse())
352  return E;
353 
354  if (Error E = processCommonMeta(MetaHelper))
355  return E;
356 
357  switch (ContainerType) {
359  return processStandaloneMeta(MetaHelper);
361  return processSeparateRemarksFileMeta(MetaHelper);
363  return processSeparateRemarksMetaMeta(MetaHelper);
364  }
365  llvm_unreachable("Unknown BitstreamRemarkContainerType enum");
366 }
367 
368 Error BitstreamRemarkParser::processCommonMeta(
369  BitstreamMetaParserHelper &Helper) {
372  else
373  return createStringError(
374  std::make_error_code(std::errc::illegal_byte_sequence),
375  "Error while parsing BLOCK_META: missing container version.");
376 
377  if (Optional<uint8_t> Type = Helper.ContainerType) {
378  // Always >= BitstreamRemarkContainerType::First since it's unsigned.
379  if (*Type > static_cast<uint8_t>(BitstreamRemarkContainerType::Last))
380  return createStringError(
381  std::make_error_code(std::errc::illegal_byte_sequence),
382  "Error while parsing BLOCK_META: invalid container type.");
383 
384  ContainerType = static_cast<BitstreamRemarkContainerType>(*Type);
385  } else
386  return createStringError(
387  std::make_error_code(std::errc::illegal_byte_sequence),
388  "Error while parsing BLOCK_META: missing container type.");
389 
390  return Error::success();
391 }
392 
394  Optional<StringRef> StrTabBuf) {
395  if (!StrTabBuf)
396  return createStringError(
397  std::make_error_code(std::errc::illegal_byte_sequence),
398  "Error while parsing BLOCK_META: missing string table.");
399  // Parse and assign the string table.
400  P.StrTab.emplace(*StrTabBuf);
401  return Error::success();
402 }
403 
405  Optional<uint64_t> RemarkVersion) {
406  if (!RemarkVersion)
407  return createStringError(
408  std::make_error_code(std::errc::illegal_byte_sequence),
409  "Error while parsing BLOCK_META: missing remark version.");
410  P.RemarkVersion = *RemarkVersion;
411  return Error::success();
412 }
413 
414 Error BitstreamRemarkParser::processExternalFilePath(
415  Optional<StringRef> ExternalFilePath) {
416  if (!ExternalFilePath)
417  return createStringError(
418  std::make_error_code(std::errc::illegal_byte_sequence),
419  "Error while parsing BLOCK_META: missing external file path.");
420 
422  sys::path::append(FullPath, *ExternalFilePath);
423 
424  // External file: open the external file, parse it, check if its metadata
425  // matches the one from the separate metadata, then replace the current parser
426  // with the one parsing the remarks.
428  MemoryBuffer::getFile(FullPath);
429  if (std::error_code EC = BufferOrErr.getError())
430  return createFileError(FullPath, EC);
431 
432  TmpRemarkBuffer = std::move(*BufferOrErr);
433 
434  // Don't try to parse the file if it's empty.
435  if (TmpRemarkBuffer->getBufferSize() == 0)
436  return make_error<EndOfFileError>();
437 
438  // Create a separate parser used for parsing the separate file.
440  // Advance and check until we can parse the meta block.
442  return E;
443  // Parse the meta from the separate file.
444  // Note: here we overwrite the BlockInfo with the one from the file. This will
445  // be used to parse the rest of the file.
446  BitstreamMetaParserHelper SeparateMetaHelper(ParserHelper.Stream,
448  if (Error E = SeparateMetaHelper.parse())
449  return E;
450 
451  uint64_t PreviousContainerVersion = ContainerVersion;
452  if (Error E = processCommonMeta(SeparateMetaHelper))
453  return E;
454 
456  return createStringError(
457  std::make_error_code(std::errc::illegal_byte_sequence),
458  "Error while parsing external file's BLOCK_META: wrong container "
459  "type.");
460 
461  if (PreviousContainerVersion != ContainerVersion)
462  return createStringError(
463  std::make_error_code(std::errc::illegal_byte_sequence),
464  "Error while parsing external file's BLOCK_META: mismatching versions: "
465  "original meta: %lu, external file meta: %lu.",
466  PreviousContainerVersion, ContainerVersion);
467 
468  // Process the meta from the separate file.
469  return processSeparateRemarksFileMeta(SeparateMetaHelper);
470 }
471 
472 Error BitstreamRemarkParser::processStandaloneMeta(
473  BitstreamMetaParserHelper &Helper) {
474  if (Error E = processStrTab(*this, Helper.StrTabBuf))
475  return E;
476  return processRemarkVersion(*this, Helper.RemarkVersion);
477 }
478 
479 Error BitstreamRemarkParser::processSeparateRemarksFileMeta(
480  BitstreamMetaParserHelper &Helper) {
481  return processRemarkVersion(*this, Helper.RemarkVersion);
482 }
483 
484 Error BitstreamRemarkParser::processSeparateRemarksMetaMeta(
485  BitstreamMetaParserHelper &Helper) {
486  if (Error E = processStrTab(*this, Helper.StrTabBuf))
487  return E;
488  return processExternalFilePath(Helper.ExternalFilePath);
489 }
490 
493  if (Error E = RemarkHelper.parse())
494  return std::move(E);
495 
496  return processRemark(RemarkHelper);
497 }
498 
500 BitstreamRemarkParser::processRemark(BitstreamRemarkParserHelper &Helper) {
501  std::unique_ptr<Remark> Result = std::make_unique<Remark>();
502  Remark &R = *Result;
503 
504  if (StrTab == None)
505  return createStringError(
506  std::make_error_code(std::errc::invalid_argument),
507  "Error while parsing BLOCK_REMARK: missing string table.");
508 
509  if (!Helper.Type)
510  return createStringError(
511  std::make_error_code(std::errc::illegal_byte_sequence),
512  "Error while parsing BLOCK_REMARK: missing remark type.");
513 
514  // Always >= Type::First since it's unsigned.
515  if (*Helper.Type > static_cast<uint8_t>(Type::Last))
516  return createStringError(
517  std::make_error_code(std::errc::illegal_byte_sequence),
518  "Error while parsing BLOCK_REMARK: unknown remark type.");
519 
520  R.RemarkType = static_cast<Type>(*Helper.Type);
521 
522  if (!Helper.RemarkNameIdx)
523  return createStringError(
524  std::make_error_code(std::errc::illegal_byte_sequence),
525  "Error while parsing BLOCK_REMARK: missing remark name.");
526 
527  if (Expected<StringRef> RemarkName = (*StrTab)[*Helper.RemarkNameIdx])
528  R.RemarkName = *RemarkName;
529  else
530  return RemarkName.takeError();
531 
532  if (!Helper.PassNameIdx)
533  return createStringError(
534  std::make_error_code(std::errc::illegal_byte_sequence),
535  "Error while parsing BLOCK_REMARK: missing remark pass.");
536 
538  R.PassName = *PassName;
539  else
540  return PassName.takeError();
541 
542  if (!Helper.FunctionNameIdx)
543  return createStringError(
544  std::make_error_code(std::errc::illegal_byte_sequence),
545  "Error while parsing BLOCK_REMARK: missing remark function name.");
546  if (Expected<StringRef> FunctionName = (*StrTab)[*Helper.FunctionNameIdx])
547  R.FunctionName = *FunctionName;
548  else
549  return FunctionName.takeError();
550 
551  if (Helper.SourceFileNameIdx && Helper.SourceLine && Helper.SourceColumn) {
552  Expected<StringRef> SourceFileName = (*StrTab)[*Helper.SourceFileNameIdx];
553  if (!SourceFileName)
554  return SourceFileName.takeError();
555  R.Loc.emplace();
556  R.Loc->SourceFilePath = *SourceFileName;
557  R.Loc->SourceLine = *Helper.SourceLine;
558  R.Loc->SourceColumn = *Helper.SourceColumn;
559  }
560 
561  if (Helper.Hotness)
562  R.Hotness = *Helper.Hotness;
563 
564  if (!Helper.Args)
565  return std::move(Result);
566 
567  for (const BitstreamRemarkParserHelper::Argument &Arg : *Helper.Args) {
568  if (!Arg.KeyIdx)
569  return createStringError(
570  std::make_error_code(std::errc::illegal_byte_sequence),
571  "Error while parsing BLOCK_REMARK: missing key in remark argument.");
572  if (!Arg.ValueIdx)
573  return createStringError(
574  std::make_error_code(std::errc::illegal_byte_sequence),
575  "Error while parsing BLOCK_REMARK: missing value in remark "
576  "argument.");
577 
578  // We have at least a key and a value, create an entry.
579  R.Args.emplace_back();
580 
581  if (Expected<StringRef> Key = (*StrTab)[*Arg.KeyIdx])
582  R.Args.back().Key = *Key;
583  else
584  return Key.takeError();
585 
586  if (Expected<StringRef> Value = (*StrTab)[*Arg.ValueIdx])
587  R.Args.back().Val = *Value;
588  else
589  return Value.takeError();
590 
591  if (Arg.SourceFileNameIdx && Arg.SourceLine && Arg.SourceColumn) {
592  if (Expected<StringRef> SourceFileName =
593  (*StrTab)[*Arg.SourceFileNameIdx]) {
594  R.Args.back().Loc.emplace();
595  R.Args.back().Loc->SourceFilePath = *SourceFileName;
596  R.Args.back().Loc->SourceLine = *Arg.SourceLine;
597  R.Args.back().Loc->SourceColumn = *Arg.SourceColumn;
598  } else
599  return SourceFileName.takeError();
600  }
601  }
602 
603  return std::move(Result);
604 }
i
i
Definition: README.txt:29
llvm::remarks::BitstreamRemarkParserHelper::parse
Error parse()
Parse the REMARK_BLOCK and fill the available entries.
Definition: BitstreamRemarkParser.cpp:205
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:30
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:17
llvm::remarks::BitstreamRemarkParser::parseMeta
Error parseMeta()
Parse and process the metadata of the buffer.
Definition: BitstreamRemarkParser.cpp:344
llvm::remarks::BitstreamMetaParserHelper::BitstreamMetaParserHelper
BitstreamMetaParserHelper(BitstreamCursor &Stream, BitstreamBlockInfo &BlockInfo)
Continue parsing with Stream.
Definition: BitstreamRemarkParser.cpp:37
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::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:36
llvm::SmallVector
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1185
parseRecord
static Error parseRecord(BitstreamMetaParserHelper &Parser, unsigned Code)
Parse a record and fill in the fields in the parser.
Definition: BitstreamRemarkParser.cpp:42
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:249
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:329
llvm::remarks::BitstreamMetaParserHelper::parse
Error parse()
Parse the META_BLOCK and fill the available entries.
Definition: BitstreamRemarkParser.cpp:201
llvm::BitstreamCursor
This represents a position within a bitcode file, implemented on top of a SimpleBitstreamCursor.
Definition: BitstreamReader.h:358
llvm::remarks::BitstreamParserHelper::atEndOfStream
bool atEndOfStream()
Return true if the parser reached the end of the stream.
Definition: BitstreamRemarkParser.h:108
llvm::BitstreamEntry::Record
@ Record
Definition: BitstreamReader.h:331
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: BitCodeEnums.h:69
parseBlock
static Error parseBlock(T &ParserHelper, unsigned BlockID, const char *BlockName)
Definition: BitstreamRemarkParser.cpp:158
llvm::remarks::BitstreamParserHelper::BitstreamParserHelper
BitstreamParserHelper(StringRef Buffer)
Start parsing at Buffer.
Definition: BitstreamRemarkParser.cpp:209
llvm::Expected
Tagged union holding either a T or a Error.
Definition: APFloat.h:41
unknownRecord
static Error unknownRecord(const char *BlockName, unsigned RecordID)
Definition: BitstreamRemarkParser.cpp:23
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:456
Arg
amdgpu Simplify well known AMD library false FunctionCallee Value * Arg
Definition: AMDGPULibCalls.cpp:186
llvm::remarks::RECORD_REMARK_ARG_WITH_DEBUGLOC
@ RECORD_REMARK_ARG_WITH_DEBUGLOC
Definition: BitstreamRemarkContainer.h:85
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:239
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:1320
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:573
llvm::remarks::BitstreamRemarkParser::ReadyToParseRemarks
bool ReadyToParseRemarks
Wether the parser is ready to parse remarks.
Definition: BitstreamRemarkParser.h:44
llvm::AMDGPU::PALMD::Key
Key
PAL metadata keys.
Definition: AMDGPUMetadata.h:486
llvm::remarks::BitstreamRemarkParserHelper::Stream
BitstreamCursor & Stream
The Bitstream reader.
Definition: BitstreamRemarkParser.h:56
Remark.h
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:222
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:39
advanceToMetaBlock
static Error advanceToMetaBlock(BitstreamParserHelper &Helper)
Definition: BitstreamRemarkParser.cpp:289
llvm::remarks::BitstreamParserHelper::BlockInfo
BitstreamBlockInfo BlockInfo
The block info block.
Definition: BitstreamRemarkParser.h:93
llvm::IndexedInstrProf::Version
const uint64_t Version
Definition: InstrProf.h:1027
llvm::remarks::Remark
A remark type used for both emission and parsing.
Definition: Remark.h:67
llvm::SmallString
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
Definition: SmallString.h:26
llvm::remarks
Definition: AsmPrinter.h:76
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::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:186
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:30
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::BitstreamEntry::EndBlock
@ EndBlock
Definition: BitstreamReader.h:328
llvm::BitstreamCursor::ReadBlockInfoBlock
Expected< Optional< BitstreamBlockInfo > > ReadBlockInfoBlock(bool ReadBlockInfoNames=false)
Read and return a block info block from the bitstream.
Definition: BitstreamReader.cpp:421
llvm::remarks::BitstreamRemarkParser::next
Expected< std::unique_ptr< Remark > > next() override
If no error occurs, this returns a valid Remark object.
Definition: BitstreamRemarkParser.cpp:331
llvm::remarks::BitstreamRemarkParser::parseRemark
Expected< std::unique_ptr< Remark > > parseRemark()
Parse a Bitstream remark.
Definition: BitstreamRemarkParser.cpp:491
llvm::Record
Definition: Record.h:1543
llvm::remarks::BitstreamRemarkContainerType::SeparateRemarksMeta
@ SeparateRemarksMeta
The metadata emitted separately.
processStrTab
static Error processStrTab(BitstreamRemarkParser &P, Optional< StringRef > StrTabBuf)
Definition: BitstreamRemarkParser.cpp:393
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::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::remarks::BitstreamParserHelper::isMetaBlock
Expected< bool > isMetaBlock()
Return true if the next block is a META_BLOCK.
Definition: BitstreamRemarkParser.cpp:273
llvm::remarks::BitstreamRemarkParser::ParserHelper
BitstreamParserHelper ParserHelper
The buffer to parse.
Definition: BitstreamRemarkParser.h:32
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::BitstreamEntry::Error
@ Error
Definition: BitstreamReader.h:327
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:281
llvm_unreachable
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:143
llvm::BitstreamCursor::advance
Expected< BitstreamEntry > advance(unsigned Flags=0)
Advance the current bitstream, returning the next entry in the stream.
Definition: BitstreamReader.h:418
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:41
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:84
llvm::remarks::BitstreamRemarkParser::StrTab
Optional< ParsedStringTable > StrTab
The string table used for parsing strings.
Definition: BitstreamRemarkParser.h:34
llvm::BitstreamEntry::SubBlock
@ SubBlock
Definition: BitstreamReader.h:330
llvm::make_error_code
std::error_code make_error_code(BitcodeError E)
Definition: BitcodeReader.h:271
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:1239
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:155
llvm::XCOFF::MagicNumber
MagicNumber
Definition: XCOFF.h:44
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:597
llvm::remarks::BitstreamRemarkParser::TmpRemarkBuffer
std::unique_ptr< MemoryBuffer > TmpRemarkBuffer
Temporary remark buffer used when the remarks are stored separately.
Definition: BitstreamRemarkParser.h:36
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:404
llvm::remarks::BitstreamParserHelper::parseMagic
Expected< std::array< char, 4 > > parseMagic()
Parse the magic number.
Definition: BitstreamRemarkParser.cpp:212
llvm::remarks::BitstreamParserHelper::isRemarkBlock
Expected< bool > isRemarkBlock()
Return true if the next block is a REMARK_BLOCK.
Definition: BitstreamRemarkParser.cpp:277
llvm::remarks::createBitstreamParserFromMeta
Expected< std::unique_ptr< BitstreamRemarkParser > > createBitstreamParserFromMeta(StringRef Buf, Optional< ParsedStringTable > StrTab=None, Optional< StringRef > ExternalFilePrependPath=None)
Definition: BitstreamRemarkParser.cpp:309
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:74
PassName
static const char PassName[]
Definition: X86LowerAMXIntrinsics.cpp:671
llvm::remarks::BitstreamRemarkContainerType
BitstreamRemarkContainerType
Type of the remark container.
Definition: BitstreamRemarkContainer.h:35