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. 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 22 namespace llvm { 23 class BitcodeReaderValueList; 24 class BitstreamCursor; 25 class DISubprogram; 26 class Error; 27 class Function; 28 class Instruction; 29 class Metadata; 30 class Module; 31 class Type; 32 33 /// Helper class that handles loading Metadatas and keeping them available. 34 class MetadataLoader { 35 class MetadataLoaderImpl; 36 std::unique_ptr<MetadataLoaderImpl> Pimpl; 37 Error parseMetadata(bool ModuleLevel); 38 39 public: 40 ~MetadataLoader(); 41 MetadataLoader(BitstreamCursor &Stream, Module &TheModule, 42 BitcodeReaderValueList &ValueList, bool IsImporting, 43 std::function<Type *(unsigned)> getTypeByID); 44 MetadataLoader &operator=(MetadataLoader &&); 45 MetadataLoader(MetadataLoader &&); 46 47 // Parse a module metadata block 48 Error parseModuleMetadata() { return parseMetadata(true); } 49 50 // Parse a function metadata block 51 Error parseFunctionMetadata() { return parseMetadata(false); } 52 53 /// Set the mode to strip TBAA metadata on load. 54 void setStripTBAA(bool StripTBAA = true); 55 56 /// Return true if the Loader is stripping TBAA metadata. 57 bool isStrippingTBAA(); 58 59 // Return true there are remaining unresolved forward references. 60 bool hasFwdRefs() const; 61 62 /// Return the given metadata, creating a replaceable forward reference if 63 /// necessary. 64 Metadata *getMetadataFwdRefOrLoad(unsigned Idx); 65 66 /// Return the DISubprogram metadata for a Function if any, null otherwise. 67 DISubprogram *lookupSubprogramForFunction(Function *F); 68 69 /// Parse a `METADATA_ATTACHMENT` block for a function. 70 Error parseMetadataAttachment( 71 Function &F, const SmallVectorImpl<Instruction *> &InstructionList); 72 73 /// Parse a `METADATA_KIND` block for the current module. 74 Error parseMetadataKinds(); 75 76 unsigned size() const; 77 void shrinkTo(unsigned N); 78 79 /// Perform bitcode upgrades on llvm.dbg.* calls. 80 void upgradeDebugIntrinsics(Function &F); 81 }; 82 } 83 84 #endif // LLVM_LIB_BITCODE_READER_METADATALOADER_H 85