24template <
typename... Ts>
Error error(
char const *Fmt,
const Ts &...Vals) {
30 std::make_error_code(std::errc::illegal_byte_sequence));
36 return error(
"Unknown record entry ({}).", AbbrevID);
40 return error(
"Unexpected record entry ({}).", RecordName);
44 return error(
"Malformed record entry ({}).", RecordName);
48 return error(
"Unexpected subblock ({}).", Code);
54 return Next.takeError();
60 return error(
"Expected subblock, but got unexpected record.");
62 return error(
"Expected subblock, but got unexpected end of bitstream.");
70 return MaybeBlockID.takeError();
72 return error(
"Expected {} block, but got unexpected block ({}).",
BlockName,
101 "Unsupported remark container version (expected: {}, read: {}). "
102 "Please upgrade/downgrade your toolchain to read this container.",
115 "Unsupported remark version in container (expected: {}, read: {}). "
116 "Please upgrade/downgrade your toolchain to read this container.",
204 std::array<char, 4> Result;
205 for (
unsigned I = 0;
I < 4; ++
I)
209 return R.takeError();
213 return error(
"Unknown magic number: expecting {}, got {}.",
221 return Next.takeError();
225 "Error while parsing BLOCKINFO_BLOCK: expecting [ENTER_SUBBLOCK, "
226 "BLOCKINFO_BLOCK, ...].");
229 Stream.ReadBlockInfoBlock();
233 if (!*MaybeBlockInfo)
234 return error(
"Missing BLOCKINFO_BLOCK.");
255 while (!
Stream.AtEndOfStream()) {
258 return MaybeBlockID.takeError();
262 return error(
"Unexpected block between meta blocks.");
271 if (
Stream.AtEndOfStream())
286 return MaybeBlockID.takeError();
295 StringRef Buf, std::optional<StringRef> ExternalFilePrependPath) {
296 auto Parser = std::make_unique<BitstreamRemarkParser>(Buf);
298 if (ExternalFilePrependPath)
299 Parser->ExternalFilePrependPath = std::string(*ExternalFilePrependPath);
301 return std::move(Parser);
320 "Container is non-empty, but does not contain any remarks blocks.");
330 return processRemark();
336 if (
Error E = processCommonMeta())
341 return processExternalFilePath();
343 return processFileContainerMeta();
348Error BitstreamRemarkParser::processCommonMeta() {
350 if (!Helper.Container)
351 return Helper.error(
"Missing container info.");
352 auto &Container = *Helper.Container;
356 return Helper.error(
"Invalid container type.");
361Error BitstreamRemarkParser::processFileContainerMeta() {
362 if (
Error E = processRemarkVersion())
364 if (
Error E = processStrTab())
369Error BitstreamRemarkParser::processStrTab() {
371 if (!Helper.StrTabBuf)
372 return Helper.error(
"Missing string table.");
374 StrTab.emplace(*Helper.StrTabBuf);
378Error BitstreamRemarkParser::processRemarkVersion() {
380 if (!Helper.RemarkVersion)
381 return Helper.error(
"Missing remark version.");
386Error BitstreamRemarkParser::processExternalFilePath() {
388 if (!Helper.ExternalFilePath)
389 return Helper.error(
"Missing external file path.");
397 ErrorOr<std::unique_ptr<MemoryBuffer>> BufferOrErr =
399 if (std::error_code EC = BufferOrErr.
getError())
415 "Wrong container type in external file.");
420Expected<std::unique_ptr<Remark>> BitstreamRemarkParser::processRemark() {
422 std::unique_ptr<Remark>
Result = std::make_unique<Remark>();
426 return Helper.error(
"Missing string table.");
429 return Helper.error(
"Missing remark type.");
432 if (*Helper.Type >
static_cast<uint8_t
>(
Type::Last))
433 return Helper.error(
"Unknown remark type.");
435 R.RemarkType =
static_cast<Type>(*Helper.Type);
437 if (!Helper.RemarkNameIdx)
438 return Helper.error(
"Missing remark name.");
440 if (Expected<StringRef> RemarkName = (*
StrTab)[*Helper.RemarkNameIdx])
441 R.RemarkName = *RemarkName;
443 return RemarkName.takeError();
445 if (!Helper.PassNameIdx)
446 return Helper.error(
"Missing remark pass.");
448 if (Expected<StringRef>
PassName = (*
StrTab)[*Helper.PassNameIdx])
453 if (!Helper.FunctionNameIdx)
454 return Helper.error(
"Missing remark function name.");
456 if (Expected<StringRef> FunctionName = (*
StrTab)[*Helper.FunctionNameIdx])
457 R.FunctionName = *FunctionName;
459 return FunctionName.takeError();
462 Expected<StringRef> SourceFileName =
463 (*StrTab)[Helper.Loc->SourceFileNameIdx];
467 R.Loc->SourceFilePath = *SourceFileName;
468 R.Loc->SourceLine = Helper.Loc->SourceLine;
469 R.Loc->SourceColumn = Helper.Loc->SourceColumn;
473 R.Hotness = *Helper.Hotness;
475 for (
const BitstreamRemarkParserHelper::Argument &Arg : Helper.Args) {
477 return Helper.error(
"Missing key in remark argument.");
479 return Helper.error(
"Missing value in remark argument.");
482 auto &RArg =
R.Args.emplace_back();
487 return Key.takeError();
492 return Value.takeError();
495 if (Expected<StringRef> SourceFileName =
498 RArg.Loc->SourceFilePath = *SourceFileName;
499 RArg.Loc->SourceLine = Arg.
Loc->SourceLine;
500 RArg.Loc->SourceColumn = Arg.
Loc->SourceColumn;
506 return std::move(Result);
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static const char PassName[]
This represents a position within a bitcode file, implemented on top of a SimpleBitstreamCursor.
Expected< BitstreamEntry > advance(unsigned Flags=0)
Advance the current bitstream, returning the next entry in the stream.
std::error_code getError() const
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
Tagged union holding either a T or a Error.
Error takeError()
Take ownership of the stored error.
static ErrorOr< std::unique_ptr< MemoryBuffer > > getFile(const Twine &Filename, bool IsText=false, bool RequiresNullTerminator=true, bool IsVolatile=false, std::optional< Align > Alignment=std::nullopt)
Open the specified file as a MemoryBuffer, returning a new MemoryBuffer if successful,...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
A raw_ostream that writes to an std::string.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ BLOCKINFO_BLOCK_ID
BLOCKINFO_BLOCK is used to define metadata about blocks, for example, standard abbrevs that should be...
LLVM_ABI void append(SmallVectorImpl< char > &path, const Twine &a, const Twine &b="", const Twine &c="", const Twine &d="")
Append to path.
This is an optimization pass for GlobalISel generic memory operations.
FunctionAddr VTableAddr Value
Error createFileError(const Twine &F, Error E)
Concatenate a source file path and/or name with an Error.
auto formatv(bool Validate, const char *Fmt, Ts &&...Vals)
LLVM_ATTRIBUTE_VISIBILITY_DEFAULT AnalysisKey InnerAnalysisManagerProxy< AnalysisManagerT, IRUnitT, ExtraArgTs... >::Key
Error make_error(ArgTs &&... Args)
Make a Error instance representing failure using the given error info type.
FunctionAddr VTableAddr Next