MetadataLoader.h 2.6 KB

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