1 //===-- Bitcode/Reader/MetadataLoader.h - Load Metadatas -------*- C++ -*-====//
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
7 //===----------------------------------------------------------------------===//
9 // This class handles loading Metadatas.
11 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_LIB_BITCODE_READER_METADATALOADER_H
14 #define LLVM_LIB_BITCODE_READER_METADATALOADER_H
16 #include "llvm/ADT/SmallVector.h"
17 #include "llvm/Support/Error.h"
23 class BitcodeReaderValueList
;
24 class BitstreamCursor
;
34 /// Helper class that handles loading Metadatas and keeping them available.
35 class MetadataLoader
{
36 class MetadataLoaderImpl
;
37 std::unique_ptr
<MetadataLoaderImpl
> Pimpl
;
38 Error
parseMetadata(bool ModuleLevel
);
42 MetadataLoader(BitstreamCursor
&Stream
, Module
&TheModule
,
43 BitcodeReaderValueList
&ValueList
, bool IsImporting
,
44 std::function
<Type
*(unsigned)> getTypeByID
);
45 MetadataLoader
&operator=(MetadataLoader
&&);
46 MetadataLoader(MetadataLoader
&&);
48 // Parse a module metadata block
49 Error
parseModuleMetadata() { return parseMetadata(true); }
51 // Parse a function metadata block
52 Error
parseFunctionMetadata() { return parseMetadata(false); }
54 /// Set the mode to strip TBAA metadata on load.
55 void setStripTBAA(bool StripTBAA
= true);
57 /// Return true if the Loader is stripping TBAA metadata.
58 bool isStrippingTBAA();
60 // Return true there are remaining unresolved forward references.
61 bool hasFwdRefs() const;
63 /// Return the given metadata, creating a replaceable forward reference if
65 Metadata
*getMetadataFwdRefOrLoad(unsigned Idx
);
67 /// Return the DISubprogram metadata for a Function if any, null otherwise.
68 DISubprogram
*lookupSubprogramForFunction(Function
*F
);
70 /// Parse a `METADATA_ATTACHMENT` block for a function.
71 Error
parseMetadataAttachment(
72 Function
&F
, const SmallVectorImpl
<Instruction
*> &InstructionList
);
74 /// Parse a `METADATA_KIND` block for the current module.
75 Error
parseMetadataKinds();
77 unsigned size() const;
78 void shrinkTo(unsigned N
);
80 /// Perform bitcode upgrades on llvm.dbg.* calls.
81 void upgradeDebugIntrinsics(Function
&F
);
85 #endif // LLVM_LIB_BITCODE_READER_METADATALOADER_H