LLVM  17.0.0git
MetadataLoader.h
Go to the documentation of this file.
1 //===-- Bitcode/Reader/MetadataLoader.h - Load Metadatas -------*- C++ -*-====//
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 class handles loading Metadatas.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef LLVM_LIB_BITCODE_READER_METADATALOADER_H
14 #define LLVM_LIB_BITCODE_READER_METADATALOADER_H
15 
16 #include "llvm/Support/Error.h"
17 
18 #include <functional>
19 #include <memory>
20 
21 namespace llvm {
22 class BitcodeReaderValueList;
23 class BitstreamCursor;
24 class DISubprogram;
25 class Function;
26 class Instruction;
27 class Metadata;
28 class Module;
29 class Type;
30 template <typename T> class ArrayRef;
31 
32 typedef std::function<Type *(unsigned)> GetTypeByIDTy;
33 
34 typedef std::function<unsigned(unsigned, unsigned)> GetContainedTypeIDTy;
35 
36 typedef std::function<void(Metadata **, unsigned, GetTypeByIDTy,
39 
43  std::optional<MDTypeCallbackTy> MDType;
44 };
45 
46 /// Helper class that handles loading Metadatas and keeping them available.
48  class MetadataLoaderImpl;
49  std::unique_ptr<MetadataLoaderImpl> Pimpl;
50  Error parseMetadata(bool ModuleLevel);
51 
52 public:
54  MetadataLoader(BitstreamCursor &Stream, Module &TheModule,
55  BitcodeReaderValueList &ValueList, bool IsImporting,
56  MetadataLoaderCallbacks Callbacks);
59 
60  // Parse a module metadata block
62 
63  // Parse a function metadata block
65 
66  /// Set the mode to strip TBAA metadata on load.
67  void setStripTBAA(bool StripTBAA = true);
68 
69  /// Return true if the Loader is stripping TBAA metadata.
70  bool isStrippingTBAA();
71 
72  // Return true there are remaining unresolved forward references.
73  bool hasFwdRefs() const;
74 
75  /// Return the given metadata, creating a replaceable forward reference if
76  /// necessary.
77  Metadata *getMetadataFwdRefOrLoad(unsigned Idx);
78 
79  /// Return the DISubprogram metadata for a Function if any, null otherwise.
81 
82  /// Parse a `METADATA_ATTACHMENT` block for a function.
84  ArrayRef<Instruction *> InstructionList);
85 
86  /// Parse a `METADATA_KIND` block for the current module.
88 
89  unsigned size() const;
90  void shrinkTo(unsigned N);
91 
92  /// Perform bitcode upgrades on llvm.dbg.* calls.
94 };
95 }
96 
97 #endif // LLVM_LIB_BITCODE_READER_METADATALOADER_H
llvm::MetadataLoader::lookupSubprogramForFunction
DISubprogram * lookupSubprogramForFunction(Function *F)
Return the DISubprogram metadata for a Function if any, null otherwise.
Definition: MetadataLoader.cpp:2390
llvm::MetadataLoader::MetadataLoaderImpl
Definition: MetadataLoader.cpp:403
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
llvm::Function
Definition: Function.h:59
llvm::MetadataLoader::parseMetadataKinds
Error parseMetadataKinds()
Parse a METADATA_KIND block for the current module.
Definition: MetadataLoader.cpp:2399
llvm::MetadataLoader::parseMetadataAttachment
Error parseMetadataAttachment(Function &F, ArrayRef< Instruction * > InstructionList)
Parse a METADATA_ATTACHMENT block for a function.
Definition: MetadataLoader.cpp:2394
Error.h
llvm::MetadataLoader::operator=
MetadataLoader & operator=(MetadataLoader &&)
Definition: MetadataLoader.cpp:2363
llvm::BitstreamCursor
This represents a position within a bitcode file, implemented on top of a SimpleBitstreamCursor.
Definition: BitstreamReader.h:358
llvm::MetadataLoader::shrinkTo
void shrinkTo(unsigned N)
Definition: MetadataLoader.cpp:2410
F
#define F(x, y, z)
Definition: MD5.cpp:55
llvm::MetadataLoader::MetadataLoader
MetadataLoader(BitstreamCursor &Stream, Module &TheModule, BitcodeReaderValueList &ValueList, bool IsImporting, MetadataLoaderCallbacks Callbacks)
Definition: MetadataLoader.cpp:2371
llvm::MetadataLoader::hasFwdRefs
bool hasFwdRefs() const
Definition: MetadataLoader.cpp:2382
llvm::MetadataLoaderCallbacks
Definition: MetadataLoader.h:40
llvm::MetadataLoader::size
unsigned size() const
Definition: MetadataLoader.cpp:2409
llvm::Metadata
Root of the metadata hierarchy.
Definition: Metadata.h:61
parseMetadata
static bool parseMetadata(const StringRef &Input, uint64_t &FunctionHash, uint32_t &Attributes)
Parse Input that contains metadata.
Definition: SampleProfReader.cpp:180
llvm::MetadataLoader
Helper class that handles loading Metadatas and keeping them available.
Definition: MetadataLoader.h:47
llvm::BitcodeReaderValueList
Definition: ValueList.h:28
llvm::MetadataLoader::~MetadataLoader
~MetadataLoader()
llvm::MetadataLoaderCallbacks::GetContainedTypeID
GetContainedTypeIDTy GetContainedTypeID
Definition: MetadataLoader.h:42
TemplateParamKind::Type
@ Type
llvm::GetContainedTypeIDTy
std::function< unsigned(unsigned, unsigned)> GetContainedTypeIDTy
Definition: BitcodeReader.h:49
llvm::MDTypeCallbackTy
std::function< void(Metadata **, unsigned, GetTypeByIDTy, GetContainedTypeIDTy)> MDTypeCallbackTy
Definition: BitcodeReader.h:57
function
print Print MemDeps of function
Definition: MemDepPrinter.cpp:82
llvm::Module
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
llvm::MetadataLoader::isStrippingTBAA
bool isStrippingTBAA()
Return true if the Loader is stripping TBAA metadata.
Definition: MetadataLoader.cpp:2407
llvm::ArrayRef
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: APInt.h:33
llvm::MetadataLoader::parseModuleMetadata
Error parseModuleMetadata()
Definition: MetadataLoader.h:61
llvm::MetadataLoaderCallbacks::MDType
std::optional< MDTypeCallbackTy > MDType
Definition: MetadataLoader.h:43
Module
Machine Check Debug Module
Definition: MachineCheckDebugify.cpp:122
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:156
llvm::MetadataLoaderCallbacks::GetTypeByID
GetTypeByIDTy GetTypeByID
Definition: MetadataLoader.h:41
llvm::MetadataLoader::setStripTBAA
void setStripTBAA(bool StripTBAA=true)
Set the mode to strip TBAA metadata on load.
Definition: MetadataLoader.cpp:2403
llvm::MetadataLoader::parseFunctionMetadata
Error parseFunctionMetadata()
Definition: MetadataLoader.h:64
llvm::MetadataLoader::upgradeDebugIntrinsics
void upgradeDebugIntrinsics(Function &F)
Perform bitcode upgrades on llvm.dbg.* calls.
Definition: MetadataLoader.cpp:2412
N
#define N
LineType::Metadata
@ Metadata
llvm::DISubprogram
Subprogram description.
Definition: DebugInfoMetadata.h:1851
llvm::ArrayRef
ArrayRef(const T &OneElt) -> ArrayRef< T >
llvm::MetadataLoader::getMetadataFwdRefOrLoad
Metadata * getMetadataFwdRefOrLoad(unsigned Idx)
Return the given metadata, creating a replaceable forward reference if necessary.
Definition: MetadataLoader.cpp:2386
llvm::codeview::PublicSymFlags::Function
@ Function
llvm::GetTypeByIDTy
std::function< Type *(unsigned)> GetTypeByIDTy
Definition: BitcodeReader.h:47