[AMDGPU][AsmParser][NFC] Translate parsed MIMG instructions to MCInsts automatically.
[llvm-project.git] / llvm / lib / Bitcode / Reader / MetadataLoader.h
blobfbee7e49f8dff14a6c0534a75fcc3da52f251ed8
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.
11 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_LIB_BITCODE_READER_METADATALOADER_H
14 #define LLVM_LIB_BITCODE_READER_METADATALOADER_H
16 #include "llvm/Support/Error.h"
18 #include <functional>
19 #include <memory>
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;
32 typedef std::function<Type *(unsigned)> GetTypeByIDTy;
34 typedef std::function<unsigned(unsigned, unsigned)> GetContainedTypeIDTy;
36 typedef std::function<void(Metadata **, unsigned, GetTypeByIDTy,
37 GetContainedTypeIDTy)>
38 MDTypeCallbackTy;
40 struct MetadataLoaderCallbacks {
41 GetTypeByIDTy GetTypeByID;
42 GetContainedTypeIDTy GetContainedTypeID;
43 std::optional<MDTypeCallbackTy> MDType;
46 /// Helper class that handles loading Metadatas and keeping them available.
47 class MetadataLoader {
48 class MetadataLoaderImpl;
49 std::unique_ptr<MetadataLoaderImpl> Pimpl;
50 Error parseMetadata(bool ModuleLevel);
52 public:
53 ~MetadataLoader();
54 MetadataLoader(BitstreamCursor &Stream, Module &TheModule,
55 BitcodeReaderValueList &ValueList, bool IsImporting,
56 MetadataLoaderCallbacks Callbacks);
57 MetadataLoader &operator=(MetadataLoader &&);
58 MetadataLoader(MetadataLoader &&);
60 // Parse a module metadata block
61 Error parseModuleMetadata() { return parseMetadata(true); }
63 // Parse a function metadata block
64 Error parseFunctionMetadata() { return parseMetadata(false); }
66 /// Set the mode to strip TBAA metadata on load.
67 void setStripTBAA(bool StripTBAA = true);
69 /// Return true if the Loader is stripping TBAA metadata.
70 bool isStrippingTBAA();
72 // Return true there are remaining unresolved forward references.
73 bool hasFwdRefs() const;
75 /// Return the given metadata, creating a replaceable forward reference if
76 /// necessary.
77 Metadata *getMetadataFwdRefOrLoad(unsigned Idx);
79 /// Return the DISubprogram metadata for a Function if any, null otherwise.
80 DISubprogram *lookupSubprogramForFunction(Function *F);
82 /// Parse a `METADATA_ATTACHMENT` block for a function.
83 Error parseMetadataAttachment(Function &F,
84 ArrayRef<Instruction *> InstructionList);
86 /// Parse a `METADATA_KIND` block for the current module.
87 Error parseMetadataKinds();
89 unsigned size() const;
90 void shrinkTo(unsigned N);
92 /// Perform bitcode upgrades on llvm.dbg.* calls.
93 void upgradeDebugIntrinsics(Function &F);
97 #endif // LLVM_LIB_BITCODE_READER_METADATALOADER_H