IRMover.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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 "llvm/ADT/FunctionExtras.h"
  18. #include <functional>
  19. namespace llvm {
  20. class Error;
  21. class GlobalValue;
  22. class Metadata;
  23. class Module;
  24. class StructType;
  25. class TrackingMDRef;
  26. class Type;
  27. class IRMover {
  28. struct StructTypeKeyInfo {
  29. struct KeyTy {
  30. ArrayRef<Type *> ETypes;
  31. bool IsPacked;
  32. KeyTy(ArrayRef<Type *> E, bool P);
  33. KeyTy(const StructType *ST);
  34. bool operator==(const KeyTy &that) const;
  35. bool operator!=(const KeyTy &that) const;
  36. };
  37. static StructType *getEmptyKey();
  38. static StructType *getTombstoneKey();
  39. static unsigned getHashValue(const KeyTy &Key);
  40. static unsigned getHashValue(const StructType *ST);
  41. static bool isEqual(const KeyTy &LHS, const StructType *RHS);
  42. static bool isEqual(const StructType *LHS, const StructType *RHS);
  43. };
  44. /// Type of the Metadata map in \a ValueToValueMapTy.
  45. typedef DenseMap<const Metadata *, TrackingMDRef> MDMapT;
  46. public:
  47. class IdentifiedStructTypeSet {
  48. // The set of opaque types is the composite module.
  49. DenseSet<StructType *> OpaqueStructTypes;
  50. // The set of identified but non opaque structures in the composite module.
  51. DenseSet<StructType *, StructTypeKeyInfo> NonOpaqueStructTypes;
  52. public:
  53. void addNonOpaque(StructType *Ty);
  54. void switchToNonOpaque(StructType *Ty);
  55. void addOpaque(StructType *Ty);
  56. StructType *findNonOpaque(ArrayRef<Type *> ETypes, bool IsPacked);
  57. bool hasType(StructType *Ty);
  58. };
  59. IRMover(Module &M);
  60. typedef std::function<void(GlobalValue &)> ValueAdder;
  61. using LazyCallback =
  62. llvm::unique_function<void(GlobalValue &GV, ValueAdder Add)>;
  63. /// Move in the provide values in \p ValuesToLink from \p Src.
  64. ///
  65. /// - \p AddLazyFor is a call back that the IRMover will call when a global
  66. /// value is referenced by one of the ValuesToLink (transitively) but was
  67. /// not present in ValuesToLink. The GlobalValue and a ValueAdder callback
  68. /// are passed as an argument, and the callback is expected to be called
  69. /// if the GlobalValue needs to be added to the \p ValuesToLink and linked.
  70. /// Pass nullptr if there's no work to be done in such cases.
  71. /// - \p IsPerformingImport is true when this IR link is to perform ThinLTO
  72. /// function importing from Src.
  73. Error move(std::unique_ptr<Module> Src, ArrayRef<GlobalValue *> ValuesToLink,
  74. LazyCallback AddLazyFor, bool IsPerformingImport);
  75. Module &getModule() { return Composite; }
  76. private:
  77. Module &Composite;
  78. IdentifiedStructTypeSet IdentifiedStructTypes;
  79. MDMapT SharedMDs; ///< A Metadata map to use for all calls to \a move().
  80. };
  81. } // End llvm namespace
  82. #endif
  83. #ifdef __GNUC__
  84. #pragma GCC diagnostic pop
  85. #endif