Path: blob/main/contrib/llvm-project/llvm/lib/Bitcode/Reader/MetadataLoader.h
35291 views
//===-- Bitcode/Reader/MetadataLoader.h - Load Metadatas -------*- C++ -*-====//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// This class handles loading Metadatas.9//10//===----------------------------------------------------------------------===//1112#ifndef LLVM_LIB_BITCODE_READER_METADATALOADER_H13#define LLVM_LIB_BITCODE_READER_METADATALOADER_H1415#include "llvm/Support/Error.h"1617#include <functional>18#include <memory>1920namespace llvm {21class BasicBlock;22class BitcodeReaderValueList;23class BitstreamCursor;24class DISubprogram;25class Function;26class Instruction;27class Metadata;28class Module;29class Type;30template <typename T> class ArrayRef;3132typedef std::function<Type *(unsigned)> GetTypeByIDTy;3334typedef std::function<unsigned(unsigned, unsigned)> GetContainedTypeIDTy;3536typedef std::function<void(Metadata **, unsigned, GetTypeByIDTy,37GetContainedTypeIDTy)>38MDTypeCallbackTy;3940struct MetadataLoaderCallbacks {41GetTypeByIDTy GetTypeByID;42GetContainedTypeIDTy GetContainedTypeID;43std::optional<MDTypeCallbackTy> MDType;44};4546/// Helper class that handles loading Metadatas and keeping them available.47class MetadataLoader {48class MetadataLoaderImpl;49std::unique_ptr<MetadataLoaderImpl> Pimpl;50Error parseMetadata(bool ModuleLevel);5152public:53~MetadataLoader();54MetadataLoader(BitstreamCursor &Stream, Module &TheModule,55BitcodeReaderValueList &ValueList, bool IsImporting,56MetadataLoaderCallbacks Callbacks);57MetadataLoader &operator=(MetadataLoader &&);58MetadataLoader(MetadataLoader &&);5960// Parse a module metadata block61Error parseModuleMetadata() { return parseMetadata(true); }6263// Parse a function metadata block64Error parseFunctionMetadata() { return parseMetadata(false); }6566/// Set the mode to strip TBAA metadata on load.67void setStripTBAA(bool StripTBAA = true);6869/// Return true if the Loader is stripping TBAA metadata.70bool isStrippingTBAA();7172// Return true there are remaining unresolved forward references.73bool hasFwdRefs() const;7475/// Return the given metadata, creating a replaceable forward reference if76/// necessary.77Metadata *getMetadataFwdRefOrLoad(unsigned Idx);7879/// Return the DISubprogram metadata for a Function if any, null otherwise.80DISubprogram *lookupSubprogramForFunction(Function *F);8182/// Parse a `METADATA_ATTACHMENT` block for a function.83Error parseMetadataAttachment(Function &F,84ArrayRef<Instruction *> InstructionList);8586/// Parse a `METADATA_KIND` block for the current module.87Error parseMetadataKinds();8889unsigned size() const;90void shrinkTo(unsigned N);9192/// Perform bitcode upgrades on llvm.dbg.* calls.93void upgradeDebugIntrinsics(Function &F);94};95}9697#endif // LLVM_LIB_BITCODE_READER_METADATALOADER_H9899100