blob: 351857e342ca64323256ca68f51331efe7d646a9 [file] [log] [blame]
Mehdi Aminief27db82016-12-12 19:34:26 +00001//===-- Bitcode/Reader/MetadataLoader.h - Load Metadatas -------*- C++ -*-====//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This class handles loading Metadatas.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_LIB_BITCODE_READER_METADATALOADER_H
15#define LLVM_LIB_BITCODE_READER_METADATALOADER_H
16
17#include "llvm/ADT/SmallVector.h"
18#include "llvm/Support/Error.h"
19
20#include <functional>
21#include <memory>
22
23namespace llvm {
24class BitcodeReaderValueList;
25class BitstreamCursor;
26class DISubprogram;
27class Error;
28class Function;
29class Instruction;
30class Metadata;
31class MDNode;
32class Module;
33class Type;
34
35/// Helper class that handles loading Metadatas and keeping them available.
36class MetadataLoader {
37 class MetadataLoaderImpl;
38 std::unique_ptr<MetadataLoaderImpl> Pimpl;
Teresa Johnsona61f5e32016-12-16 21:25:01 +000039 /// True if metadata is being parsed for a module being ThinLTO imported.
40 bool IsImporting = false;
Mehdi Aminief27db82016-12-12 19:34:26 +000041 Error parseMetadata(bool ModuleLevel);
42
43public:
44 ~MetadataLoader();
45 MetadataLoader(BitstreamCursor &Stream, Module &TheModule,
Teresa Johnsona61f5e32016-12-16 21:25:01 +000046 BitcodeReaderValueList &ValueList, bool IsImporting,
Mehdi Aminief27db82016-12-12 19:34:26 +000047 std::function<Type *(unsigned)> getTypeByID);
48 MetadataLoader &operator=(MetadataLoader &&);
49 MetadataLoader(MetadataLoader &&);
50
51 // Parse a module metadata block
52 Error parseModuleMetadata() { return parseMetadata(true); }
53
54 // Parse a function metadata block
55 Error parseFunctionMetadata() { return parseMetadata(false); }
56
Mehdi Amini86623052016-12-16 19:16:29 +000057 /// Set the mode to strip TBAA metadata on load.
58 void setStripTBAA(bool StripTBAA = true);
59
60 /// Return true if the Loader is stripping TBAA metadata.
61 bool isStrippingTBAA();
62
Mehdi Aminief27db82016-12-12 19:34:26 +000063 // Return true there are remaining unresolved forward references.
64 bool hasFwdRefs() const;
65
66 /// Return the given metadata, creating a replaceable forward reference if
67 /// necessary.
68 Metadata *getMetadataFwdRef(unsigned Idx);
69
70 MDNode *getMDNodeFwdRefOrNull(unsigned Idx);
71
72 /// Return the DISubprogra metadata for a Function if any, null otherwise.
73 DISubprogram *lookupSubprogramForFunction(Function *F);
74
75 /// Parse a `METADATA_ATTACHMENT` block for a function.
76 Error parseMetadataAttachment(
77 Function &F, const SmallVectorImpl<Instruction *> &InstructionList);
78
79 /// Parse a `METADATA_KIND` block for the current module.
80 Error parseMetadataKinds();
81
82 unsigned size() const;
83 void shrinkTo(unsigned N);
84};
85}
86
87#endif // LLVM_LIB_BITCODE_READER_METADATALOADER_H