1 //===-- Bitcode/Reader/MetadataLoader.h - Load Metadatas -------*- C++ -*-====//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This class handles loading Metadatas.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_LIB_BITCODE_READER_METADATALOADER_H
15 #define LLVM_LIB_BITCODE_READER_METADATALOADER_H
17 #include "llvm/ADT/SmallVector.h"
18 #include "llvm/Support/Error.h"
24 class BitcodeReaderValueList
;
25 class BitstreamCursor
;
35 /// Helper class that handles loading Metadatas and keeping them available.
36 class MetadataLoader
{
37 class MetadataLoaderImpl
;
38 std::unique_ptr
<MetadataLoaderImpl
> Pimpl
;
39 Error
parseMetadata(bool ModuleLevel
);
43 MetadataLoader(BitstreamCursor
&Stream
, Module
&TheModule
,
44 BitcodeReaderValueList
&ValueList
, bool IsImporting
,
45 std::function
<Type
*(unsigned)> getTypeByID
);
46 MetadataLoader
&operator=(MetadataLoader
&&);
47 MetadataLoader(MetadataLoader
&&);
49 // Parse a module metadata block
50 Error
parseModuleMetadata() { return parseMetadata(true); }
52 // Parse a function metadata block
53 Error
parseFunctionMetadata() { return parseMetadata(false); }
55 /// Set the mode to strip TBAA metadata on load.
56 void setStripTBAA(bool StripTBAA
= true);
58 /// Return true if the Loader is stripping TBAA metadata.
59 bool isStrippingTBAA();
61 // Return true there are remaining unresolved forward references.
62 bool hasFwdRefs() const;
64 /// Return the given metadata, creating a replaceable forward reference if
66 Metadata
*getMetadataFwdRefOrLoad(unsigned Idx
);
68 MDNode
*getMDNodeFwdRefOrNull(unsigned Idx
);
70 /// Return the DISubprogram metadata for a Function if any, null otherwise.
71 DISubprogram
*lookupSubprogramForFunction(Function
*F
);
73 /// Parse a `METADATA_ATTACHMENT` block for a function.
74 Error
parseMetadataAttachment(
75 Function
&F
, const SmallVectorImpl
<Instruction
*> &InstructionList
);
77 /// Parse a `METADATA_KIND` block for the current module.
78 Error
parseMetadataKinds();
80 unsigned size() const;
81 void shrinkTo(unsigned N
);
83 /// Perform bitcode upgrades on llvm.dbg.* calls.
84 void upgradeDebugIntrinsics(Function
&F
);
88 #endif // LLVM_LIB_BITCODE_READER_METADATALOADER_H