IRMover.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- IRMover.h ------------------------------------------------*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #ifndef LLVM_LINKER_IRMOVER_H
  14. #define LLVM_LINKER_IRMOVER_H
  15. #include "llvm/ADT/ArrayRef.h"
  16. #include "llvm/ADT/DenseSet.h"
  17. #include <functional>
  18. namespace llvm {
  19. class Error;
  20. class GlobalValue;
  21. class Metadata;
  22. class Module;
  23. class StructType;
  24. class TrackingMDRef;
  25. class Type;
  26. class IRMover {
  27. struct StructTypeKeyInfo {
  28. struct KeyTy {
  29. ArrayRef<Type *> ETypes;
  30. bool IsPacked;
  31. KeyTy(ArrayRef<Type *> E, bool P);
  32. KeyTy(const StructType *ST);
  33. bool operator==(const KeyTy &that) const;
  34. bool operator!=(const KeyTy &that) const;
  35. };
  36. static StructType *getEmptyKey();
  37. static StructType *getTombstoneKey();
  38. static unsigned getHashValue(const KeyTy &Key);
  39. static unsigned getHashValue(const StructType *ST);
  40. static bool isEqual(const KeyTy &LHS, const StructType *RHS);
  41. static bool isEqual(const StructType *LHS, const StructType *RHS);
  42. };
  43. /// Type of the Metadata map in \a ValueToValueMapTy.
  44. typedef DenseMap<const Metadata *, TrackingMDRef> MDMapT;
  45. public:
  46. class IdentifiedStructTypeSet {
  47. // The set of opaque types is the composite module.
  48. DenseSet<StructType *> OpaqueStructTypes;
  49. // The set of identified but non opaque structures in the composite module.
  50. DenseSet<StructType *, StructTypeKeyInfo> NonOpaqueStructTypes;
  51. public:
  52. void addNonOpaque(StructType *Ty);
  53. void switchToNonOpaque(StructType *Ty);
  54. void addOpaque(StructType *Ty);
  55. StructType *findNonOpaque(ArrayRef<Type *> ETypes, bool IsPacked);
  56. bool hasType(StructType *Ty);
  57. };
  58. IRMover(Module &M);
  59. typedef std::function<void(GlobalValue &)> ValueAdder;
  60. /// Move in the provide values in \p ValuesToLink from \p Src.
  61. ///
  62. /// - \p AddLazyFor is a call back that the IRMover will call when a global
  63. /// value is referenced by one of the ValuesToLink (transitively) but was
  64. /// not present in ValuesToLink. The GlobalValue and a ValueAdder callback
  65. /// are passed as an argument, and the callback is expected to be called
  66. /// if the GlobalValue needs to be added to the \p ValuesToLink and linked.
  67. /// - \p IsPerformingImport is true when this IR link is to perform ThinLTO
  68. /// function importing from Src.
  69. Error move(std::unique_ptr<Module> Src, ArrayRef<GlobalValue *> ValuesToLink,
  70. std::function<void(GlobalValue &GV, ValueAdder Add)> AddLazyFor,
  71. bool IsPerformingImport);
  72. Module &getModule() { return Composite; }
  73. private:
  74. Module &Composite;
  75. IdentifiedStructTypeSet IdentifiedStructTypes;
  76. MDMapT SharedMDs; ///< A Metadata map to use for all calls to \a move().
  77. };
  78. } // End llvm namespace
  79. #endif
  80. #ifdef __GNUC__
  81. #pragma GCC diagnostic pop
  82. #endif