Mehdi Amini | ef27db8 | 2016-12-12 19:34:26 +0000 | [diff] [blame] | 1 | //===-- 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 | |
| 23 | namespace llvm { |
| 24 | class BitcodeReaderValueList; |
| 25 | class BitstreamCursor; |
| 26 | class DISubprogram; |
| 27 | class Error; |
| 28 | class Function; |
| 29 | class Instruction; |
| 30 | class Metadata; |
| 31 | class MDNode; |
| 32 | class Module; |
| 33 | class Type; |
| 34 | |
| 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); |
| 40 | |
| 41 | public: |
| 42 | ~MetadataLoader(); |
| 43 | MetadataLoader(BitstreamCursor &Stream, Module &TheModule, |
Teresa Johnson | a61f5e3 | 2016-12-16 21:25:01 +0000 | [diff] [blame] | 44 | BitcodeReaderValueList &ValueList, bool IsImporting, |
Mehdi Amini | ef27db8 | 2016-12-12 19:34:26 +0000 | [diff] [blame] | 45 | std::function<Type *(unsigned)> getTypeByID); |
| 46 | MetadataLoader &operator=(MetadataLoader &&); |
| 47 | MetadataLoader(MetadataLoader &&); |
| 48 | |
| 49 | // Parse a module metadata block |
| 50 | Error parseModuleMetadata() { return parseMetadata(true); } |
| 51 | |
| 52 | // Parse a function metadata block |
| 53 | Error parseFunctionMetadata() { return parseMetadata(false); } |
| 54 | |
Mehdi Amini | 8662305 | 2016-12-16 19:16:29 +0000 | [diff] [blame] | 55 | /// Set the mode to strip TBAA metadata on load. |
| 56 | void setStripTBAA(bool StripTBAA = true); |
| 57 | |
| 58 | /// Return true if the Loader is stripping TBAA metadata. |
| 59 | bool isStrippingTBAA(); |
| 60 | |
Mehdi Amini | ef27db8 | 2016-12-12 19:34:26 +0000 | [diff] [blame] | 61 | // Return true there are remaining unresolved forward references. |
| 62 | bool hasFwdRefs() const; |
| 63 | |
| 64 | /// Return the given metadata, creating a replaceable forward reference if |
| 65 | /// necessary. |
Mehdi Amini | 3bb4d01 | 2017-01-20 20:29:16 +0000 | [diff] [blame] | 66 | Metadata *getMetadataFwdRefOrLoad(unsigned Idx); |
Mehdi Amini | ef27db8 | 2016-12-12 19:34:26 +0000 | [diff] [blame] | 67 | |
| 68 | MDNode *getMDNodeFwdRefOrNull(unsigned Idx); |
| 69 | |
| 70 | /// Return the DISubprogra metadata for a Function if any, null otherwise. |
| 71 | DISubprogram *lookupSubprogramForFunction(Function *F); |
| 72 | |
| 73 | /// Parse a `METADATA_ATTACHMENT` block for a function. |
| 74 | Error parseMetadataAttachment( |
| 75 | Function &F, const SmallVectorImpl<Instruction *> &InstructionList); |
| 76 | |
| 77 | /// Parse a `METADATA_KIND` block for the current module. |
| 78 | Error parseMetadataKinds(); |
| 79 | |
| 80 | unsigned size() const; |
| 81 | void shrinkTo(unsigned N); |
Adrian Prantl | 6825fb6 | 2017-04-18 01:21:53 +0000 | [diff] [blame] | 82 | |
| 83 | /// Perform bitcode upgrades on llvm.dbg.* calls. |
| 84 | void upgradeDebugIntrinsics(Function &F); |
Mehdi Amini | ef27db8 | 2016-12-12 19:34:26 +0000 | [diff] [blame] | 85 | }; |
| 86 | } |
| 87 | |
| 88 | #endif // LLVM_LIB_BITCODE_READER_METADATALOADER_H |