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,
99 "Unsupported remark container version (expected: {}, read: {}). "
100 "Please upgrade/downgrade your toolchain to read this container.",
113 "Unsupported remark version in container (expected: {}, read: {}). "
114 "Please upgrade/downgrade your toolchain to read this container.",
202 std::array<char, 4> Result;
203 for (
unsigned I = 0;
I < 4; ++
I)
207 return R.takeError();
211 return error(
"Unknown magic number: expecting {}, got {}.",
219 return Next.takeError();
223 "Error while parsing BLOCKINFO_BLOCK: expecting [ENTER_SUBBLOCK, "
224 "BLOCKINFO_BLOCK, ...].");
227 Stream.ReadBlockInfoBlock();
231 if (!*MaybeBlockInfo)
232 return error(
"Missing BLOCKINFO_BLOCK.");
253 while (!
Stream.AtEndOfStream()) {
256 return MaybeBlockID.takeError();
260 return error(
"Unexpected block between meta blocks.");
269 if (
Stream.AtEndOfStream())
284 return MaybeBlockID.takeError();
293 StringRef Buf, std::optional<StringRef> ExternalFilePrependPath) {
294 auto Parser = std::make_unique<BitstreamRemarkParser>(Buf);
296 if (ExternalFilePrependPath)
297 Parser->ExternalFilePrependPath = std::string(*ExternalFilePrependPath);
299 return std::move(Parser);
318 "Container is non-empty, but does not contain any remarks blocks.");
328 return processRemark();
334 if (
Error E = processCommonMeta())
339 return processExternalFilePath();
341 return processFileContainerMeta();
346Error BitstreamRemarkParser::processCommonMeta() {
348 if (!Helper.Container)
349 return Helper.error(
"Missing container info.");
350 auto &Container = *Helper.Container;
354 return Helper.error(
"Invalid container type.");
359Error BitstreamRemarkParser::processFileContainerMeta() {
360 if (
Error E = processRemarkVersion())
362 if (
Error E = processStrTab())
367Error BitstreamRemarkParser::processStrTab() {
369 if (!Helper.StrTabBuf)
370 return Helper.error(
"Missing string table.");
372 StrTab.emplace(*Helper.StrTabBuf);
376Error BitstreamRemarkParser::processRemarkVersion() {
378 if (!Helper.RemarkVersion)
379 return Helper.error(
"Missing remark version.");
384Error BitstreamRemarkParser::processExternalFilePath() {
386 if (!Helper.ExternalFilePath)
387 return Helper.error(
"Missing external file path.");
395 ErrorOr<std::unique_ptr<MemoryBuffer>> BufferOrErr =
397 if (std::error_code EC = BufferOrErr.
getError())
413 "Wrong container type in external file.");
418Expected<std::unique_ptr<Remark>> BitstreamRemarkParser::processRemark() {
420 std::unique_ptr<Remark>
Result = std::make_unique<Remark>();
424 return Helper.error(
"Missing string table.");
427 return Helper.error(
"Missing remark type.");
431 *Helper.Type >
static_cast<uint8_t
>(
Type::Last))
432 return Helper.error(
"Unknown remark type.");
434 R.RemarkType =
static_cast<Type>(*Helper.Type);
436 if (!Helper.RemarkNameIdx)
437 return Helper.error(
"Missing remark name.");
439 if (Expected<StringRef> RemarkName = (*
StrTab)[*Helper.RemarkNameIdx])
440 R.RemarkName = *RemarkName;
442 return RemarkName.takeError();
444 if (!Helper.PassNameIdx)
445 return Helper.error(
"Missing remark pass.");
447 if (Expected<StringRef>
PassName = (*
StrTab)[*Helper.PassNameIdx])
452 if (!Helper.FunctionNameIdx)
453 return Helper.error(
"Missing remark function name.");
455 if (Expected<StringRef> FunctionName = (*
StrTab)[*Helper.FunctionNameIdx])
456 R.FunctionName = *FunctionName;
458 return FunctionName.takeError();
461 Expected<StringRef> SourceFileName =
462 (*StrTab)[Helper.Loc->SourceFileNameIdx];
466 R.Loc->SourceFilePath = *SourceFileName;
467 R.Loc->SourceLine = Helper.Loc->SourceLine;
468 R.Loc->SourceColumn = Helper.Loc->SourceColumn;
472 R.Hotness = *Helper.Hotness;
474 for (
const BitstreamRemarkParserHelper::Argument &Arg : Helper.Args) {
476 return Helper.error(
"Missing key in remark argument.");
478 return Helper.error(
"Missing value in remark argument.");
481 auto &RArg =
R.Args.emplace_back();
486 return Key.takeError();
491 return Value.takeError();
494 if (Expected<StringRef> SourceFileName =
497 RArg.Loc->SourceFilePath = *SourceFileName;
498 RArg.Loc->SourceLine = Arg.
Loc->SourceLine;
499 RArg.Loc->SourceColumn = Arg.
Loc->SourceColumn;
505 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.
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.
Error createFileError(const Twine &F, Error E)
Concatenate a source file path and/or name with an Error.
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Value
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.
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Next