Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:44:11

0001 //===- IRMover.h ------------------------------------------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef LLVM_LINKER_IRMOVER_H
0010 #define LLVM_LINKER_IRMOVER_H
0011 
0012 #include "llvm/ADT/ArrayRef.h"
0013 #include "llvm/ADT/DenseSet.h"
0014 #include "llvm/ADT/FunctionExtras.h"
0015 #include <functional>
0016 
0017 namespace llvm {
0018 class Error;
0019 class GlobalValue;
0020 class Metadata;
0021 class Module;
0022 class StructType;
0023 class TrackingMDRef;
0024 class Type;
0025 
0026 class IRMover {
0027   struct StructTypeKeyInfo {
0028     struct KeyTy {
0029       ArrayRef<Type *> ETypes;
0030       bool IsPacked;
0031       KeyTy(ArrayRef<Type *> E, bool P);
0032       KeyTy(const StructType *ST);
0033       bool operator==(const KeyTy &that) const;
0034       bool operator!=(const KeyTy &that) const;
0035     };
0036     static StructType *getEmptyKey();
0037     static StructType *getTombstoneKey();
0038     static unsigned getHashValue(const KeyTy &Key);
0039     static unsigned getHashValue(const StructType *ST);
0040     static bool isEqual(const KeyTy &LHS, const StructType *RHS);
0041     static bool isEqual(const StructType *LHS, const StructType *RHS);
0042   };
0043 
0044   /// Type of the Metadata map in \a ValueToValueMapTy.
0045   typedef DenseMap<const Metadata *, TrackingMDRef> MDMapT;
0046 
0047 public:
0048   class IdentifiedStructTypeSet {
0049     // The set of opaque types is the composite module.
0050     DenseSet<StructType *> OpaqueStructTypes;
0051 
0052     // The set of identified but non opaque structures in the composite module.
0053     DenseSet<StructType *, StructTypeKeyInfo> NonOpaqueStructTypes;
0054 
0055   public:
0056     void addNonOpaque(StructType *Ty);
0057     void switchToNonOpaque(StructType *Ty);
0058     void addOpaque(StructType *Ty);
0059     StructType *findNonOpaque(ArrayRef<Type *> ETypes, bool IsPacked);
0060     bool hasType(StructType *Ty);
0061   };
0062 
0063   IRMover(Module &M);
0064 
0065   typedef std::function<void(GlobalValue &)> ValueAdder;
0066   using LazyCallback =
0067       llvm::unique_function<void(GlobalValue &GV, ValueAdder Add)>;
0068 
0069   /// Move in the provide values in \p ValuesToLink from \p Src.
0070   ///
0071   /// - \p AddLazyFor is a call back that the IRMover will call when a global
0072   ///   value is referenced by one of the ValuesToLink (transitively) but was
0073   ///   not present in ValuesToLink. The GlobalValue and a ValueAdder callback
0074   ///   are passed as an argument, and the callback is expected to be called
0075   ///   if the GlobalValue needs to be added to the \p ValuesToLink and linked.
0076   ///   Pass nullptr if there's no work to be done in such cases.
0077   /// - \p IsPerformingImport is true when this IR link is to perform ThinLTO
0078   ///   function importing from Src.
0079   Error move(std::unique_ptr<Module> Src, ArrayRef<GlobalValue *> ValuesToLink,
0080              LazyCallback AddLazyFor, bool IsPerformingImport);
0081   Module &getModule() { return Composite; }
0082 
0083 private:
0084   Module &Composite;
0085   IdentifiedStructTypeSet IdentifiedStructTypes;
0086   MDMapT SharedMDs; ///< A Metadata map to use for all calls to \a move().
0087 };
0088 
0089 } // End llvm namespace
0090 
0091 #endif