blob: fe2b202732499c63ed2053a67882eaa1f6815386 [file] [log] [blame]
Mehdi Aminief27db82016-12-12 19:34:26 +00001//===-- Bitcode/Reader/MetadataLoader.h - Load Metadatas -------*- C++ -*-====//
2//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// 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
Mehdi Aminief27db82016-12-12 19:34:26 +00006//
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/ADT/SmallVector.h"
17#include "llvm/Support/Error.h"
18
19#include <functional>
20#include <memory>
21
22namespace llvm {
23class BitcodeReaderValueList;
24class BitstreamCursor;
25class DISubprogram;
26class Error;
27class Function;
28class Instruction;
29class Metadata;
30class MDNode;
31class Module;
32class Type;
33
34/// Helper class that handles loading Metadatas and keeping them available.
35class MetadataLoader {
36 class MetadataLoaderImpl;
37 std::unique_ptr<MetadataLoaderImpl> Pimpl;
38 Error parseMetadata(bool ModuleLevel);
39
40public:
41 ~MetadataLoader();
42 MetadataLoader(BitstreamCursor &Stream, Module &TheModule,
Teresa Johnsona61f5e32016-12-16 21:25:01 +000043 BitcodeReaderValueList &ValueList, bool IsImporting,
Mehdi Aminief27db82016-12-12 19:34:26 +000044 std::function<Type *(unsigned)> getTypeByID);
45 MetadataLoader &operator=(MetadataLoader &&);
46 MetadataLoader(MetadataLoader &&);
47
48 // Parse a module metadata block
49 Error parseModuleMetadata() { return parseMetadata(true); }
50
51 // Parse a function metadata block
52 Error parseFunctionMetadata() { return parseMetadata(false); }
53
Mehdi Amini86623052016-12-16 19:16:29 +000054 /// Set the mode to strip TBAA metadata on load.
55 void setStripTBAA(bool StripTBAA = true);
56
57 /// Return true if the Loader is stripping TBAA metadata.
58 bool isStrippingTBAA();
59
Mehdi Aminief27db82016-12-12 19:34:26 +000060 // Return true there are remaining unresolved forward references.
61 bool hasFwdRefs() const;
62
63 /// Return the given metadata, creating a replaceable forward reference if
64 /// necessary.
Mehdi Amini3bb4d012017-01-20 20:29:16 +000065 Metadata *getMetadataFwdRefOrLoad(unsigned Idx);
Mehdi Aminief27db82016-12-12 19:34:26 +000066
Xin Tong77931ca2018-08-06 05:03:21 +000067 /// Return the DISubprogram metadata for a Function if any, null otherwise.
Mehdi Aminief27db82016-12-12 19:34:26 +000068 DISubprogram *lookupSubprogramForFunction(Function *F);
69
70 /// Parse a `METADATA_ATTACHMENT` block for a function.
71 Error parseMetadataAttachment(
72 Function &F, const SmallVectorImpl<Instruction *> &InstructionList);
73
74 /// Parse a `METADATA_KIND` block for the current module.
75 Error parseMetadataKinds();
76
77 unsigned size() const;
78 void shrinkTo(unsigned N);
Adrian Prantl6825fb62017-04-18 01:21:53 +000079
80 /// Perform bitcode upgrades on llvm.dbg.* calls.
81 void upgradeDebugIntrinsics(Function &F);
Mehdi Aminief27db82016-12-12 19:34:26 +000082};
83}
84
85#endif // LLVM_LIB_BITCODE_READER_METADATALOADER_H