LLVM 23.0.0git
IRMover.h
Go to the documentation of this file.
1//===- IRMover.h ------------------------------------------------*- 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#ifndef LLVM_LINKER_IRMOVER_H
10#define LLVM_LINKER_IRMOVER_H
11
12#include "llvm/ADT/ArrayRef.h"
13#include "llvm/ADT/DenseMap.h"
14#include "llvm/ADT/DenseSet.h"
18#include <functional>
19
20namespace llvm {
21class Error;
22class GlobalValue;
23class Metadata;
24class MDNode;
25class NamedMDNode;
26class Module;
27class StructType;
28class TrackingMDRef;
29class Type;
30
31class IRMover {
32 struct StructTypeKeyInfo {
33 struct KeyTy {
37 LLVM_ABI KeyTy(const StructType *ST);
38 LLVM_ABI bool operator==(const KeyTy &that) const;
39 LLVM_ABI bool operator!=(const KeyTy &that) const;
40 };
41 LLVM_ABI static unsigned getHashValue(const KeyTy &Key);
42 LLVM_ABI static unsigned getHashValue(const StructType *ST);
43 LLVM_ABI static bool isEqual(const KeyTy &LHS, const StructType *RHS);
44 LLVM_ABI static bool isEqual(const StructType *LHS, const StructType *RHS);
45 };
46
47 /// Type of the Metadata map in \a ValueToValueMapTy.
49
50public:
52 // The set of opaque types is the composite module.
53 DenseSet<StructType *> OpaqueStructTypes;
54
55 // The set of identified but non opaque structures in the composite module.
57
58 public:
62 LLVM_ABI StructType *findNonOpaque(ArrayRef<Type *> ETypes, bool IsPacked);
63 LLVM_ABI bool hasType(StructType *Ty);
64 };
65
67
68 typedef std::function<void(GlobalValue &)> ValueAdder;
71
74
75 /// Move in the provide values in \p ValuesToLink from \p Src.
76 ///
77 /// - \p AddLazyFor is a call back that the IRMover will call when a global
78 /// value is referenced by one of the ValuesToLink (transitively) but was
79 /// not present in ValuesToLink. The GlobalValue and a ValueAdder callback
80 /// are passed as an argument, and the callback is expected to be called
81 /// if the GlobalValue needs to be added to the \p ValuesToLink and linked.
82 /// Pass nullptr if there's no work to be done in such cases.
83 /// - \p IsPerformingImport is true when this IR link is to perform ThinLTO
84 /// function importing from Src.
85 LLVM_ABI Error move(std::unique_ptr<Module> Src,
86 ArrayRef<GlobalValue *> ValuesToLink,
87 LazyCallback AddLazyFor, bool IsPerformingImport);
88 Module &getModule() { return Composite; }
89
90private:
91 Module &Composite;
92 IdentifiedStructTypeSet IdentifiedStructTypes;
93 MDMapT SharedMDs; ///< A Metadata map to use for all calls to \a move().
94 NamedMDNodesT NamedMDNodes; ///< Cache for IRMover::linkNamedMDNodes().
95};
96
97} // End llvm namespace
98
99#endif
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
#define LLVM_ABI
Definition Compiler.h:213
This file defines the DenseMap class.
This file defines the DenseSet and SmallDenseSet classes.
This file provides a collection of function (or more generally, callable) type erasure utilities supp...
#define P(N)
This file defines the SmallPtrSet class.
Value * RHS
Value * LHS
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
Implements a dense probed hash-table based set.
Definition DenseSet.h:289
Lightweight error class with error context and mandatory checking.
Definition Error.h:159
LLVM_ABI void addNonOpaque(StructType *Ty)
Definition IRMover.cpp:1634
LLVM_ABI bool hasType(StructType *Ty)
Definition IRMover.cpp:1660
LLVM_ABI void switchToNonOpaque(StructType *Ty)
Definition IRMover.cpp:1639
LLVM_ABI void addOpaque(StructType *Ty)
Definition IRMover.cpp:1647
LLVM_ABI StructType * findNonOpaque(ArrayRef< Type * > ETypes, bool IsPacked)
Definition IRMover.cpp:1653
LLVM_ABI IRMover(Module &M)
Definition IRMover.cpp:1667
LLVM_ABI Error move(std::unique_ptr< Module > Src, ArrayRef< GlobalValue * > ValuesToLink, LazyCallback AddLazyFor, bool IsPerformingImport)
Move in the provide values in ValuesToLink from Src.
Definition IRMover.cpp:1689
Module & getModule()
Definition IRMover.h:88
std::function< void(GlobalValue &)> ValueAdder
Definition IRMover.h:68
DenseMap< const NamedMDNode *, SmallPtrSet< const MDNode *, 8 > > NamedMDNodesT
Definition IRMover.h:72
llvm::unique_function< void(GlobalValue &GV, ValueAdder Add)> LazyCallback
Definition IRMover.h:69
Metadata node.
Definition Metadata.h:1069
Root of the metadata hierarchy.
Definition Metadata.h:64
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:67
A tuple of MDNodes.
Definition Metadata.h:1749
Class to represent struct types.
Tracking metadata reference.
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
unique_function is a type-erasing functor similar to std::function.
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ATTRIBUTE_VISIBILITY_DEFAULT AnalysisKey InnerAnalysisManagerProxy< AnalysisManagerT, IRUnitT, ExtraArgTs... >::Key
@ Add
Sum of integers.
LLVM_ABI KeyTy(ArrayRef< Type * > E, bool P)
Definition IRMover.cpp:1602
LLVM_ABI bool operator==(const KeyTy &that) const
Definition IRMover.cpp:1608
LLVM_ABI bool operator!=(const KeyTy &that) const
Definition IRMover.cpp:1612