Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/include/llvm/IR/Module.h
Line
Count
Source (jump to first uncovered line)
1
//===- llvm/Module.h - C++ class to represent a VM module -------*- 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
/// @file
10
/// Module.h This file contains the declarations for the Module class.
11
//
12
//===----------------------------------------------------------------------===//
13
14
#ifndef LLVM_IR_MODULE_H
15
#define LLVM_IR_MODULE_H
16
17
#include "llvm-c/Types.h"
18
#include "llvm/ADT/Optional.h"
19
#include "llvm/ADT/STLExtras.h"
20
#include "llvm/ADT/StringMap.h"
21
#include "llvm/ADT/StringRef.h"
22
#include "llvm/ADT/iterator_range.h"
23
#include "llvm/IR/Attributes.h"
24
#include "llvm/IR/Comdat.h"
25
#include "llvm/IR/DataLayout.h"
26
#include "llvm/IR/Function.h"
27
#include "llvm/IR/GlobalAlias.h"
28
#include "llvm/IR/GlobalIFunc.h"
29
#include "llvm/IR/GlobalVariable.h"
30
#include "llvm/IR/Metadata.h"
31
#include "llvm/IR/ProfileSummary.h"
32
#include "llvm/IR/SymbolTableListTraits.h"
33
#include "llvm/Support/CBindingWrapping.h"
34
#include "llvm/Support/CodeGen.h"
35
#include <cstddef>
36
#include <cstdint>
37
#include <iterator>
38
#include <memory>
39
#include <string>
40
#include <vector>
41
42
namespace llvm {
43
44
class Error;
45
class FunctionType;
46
class GVMaterializer;
47
class LLVMContext;
48
class MemoryBuffer;
49
class RandomNumberGenerator;
50
template <class PtrType> class SmallPtrSetImpl;
51
class StructType;
52
class VersionTuple;
53
54
/// A Module instance is used to store all the information related to an
55
/// LLVM module. Modules are the top level container of all other LLVM
56
/// Intermediate Representation (IR) objects. Each module directly contains a
57
/// list of globals variables, a list of functions, a list of libraries (or
58
/// other modules) this module depends on, a symbol table, and various data
59
/// about the target's characteristics.
60
///
61
/// A module maintains a GlobalValRefMap object that is used to hold all
62
/// constant references to global variables in the module.  When a global
63
/// variable is destroyed, it should have no entries in the GlobalValueRefMap.
64
/// The main container class for the LLVM Intermediate Representation.
65
class Module {
66
/// @name Types And Enumerations
67
/// @{
68
public:
69
  /// The type for the list of global variables.
70
  using GlobalListType = SymbolTableList<GlobalVariable>;
71
  /// The type for the list of functions.
72
  using FunctionListType = SymbolTableList<Function>;
73
  /// The type for the list of aliases.
74
  using AliasListType = SymbolTableList<GlobalAlias>;
75
  /// The type for the list of ifuncs.
76
  using IFuncListType = SymbolTableList<GlobalIFunc>;
77
  /// The type for the list of named metadata.
78
  using NamedMDListType = ilist<NamedMDNode>;
79
  /// The type of the comdat "symbol" table.
80
  using ComdatSymTabType = StringMap<Comdat>;
81
82
  /// The Global Variable iterator.
83
  using global_iterator = GlobalListType::iterator;
84
  /// The Global Variable constant iterator.
85
  using const_global_iterator = GlobalListType::const_iterator;
86
87
  /// The Function iterators.
88
  using iterator = FunctionListType::iterator;
89
  /// The Function constant iterator
90
  using const_iterator = FunctionListType::const_iterator;
91
92
  /// The Function reverse iterator.
93
  using reverse_iterator = FunctionListType::reverse_iterator;
94
  /// The Function constant reverse iterator.
95
  using const_reverse_iterator = FunctionListType::const_reverse_iterator;
96
97
  /// The Global Alias iterators.
98
  using alias_iterator = AliasListType::iterator;
99
  /// The Global Alias constant iterator
100
  using const_alias_iterator = AliasListType::const_iterator;
101
102
  /// The Global IFunc iterators.
103
  using ifunc_iterator = IFuncListType::iterator;
104
  /// The Global IFunc constant iterator
105
  using const_ifunc_iterator = IFuncListType::const_iterator;
106
107
  /// The named metadata iterators.
108
  using named_metadata_iterator = NamedMDListType::iterator;
109
  /// The named metadata constant iterators.
110
  using const_named_metadata_iterator = NamedMDListType::const_iterator;
111
112
  /// This enumeration defines the supported behaviors of module flags.
113
  enum ModFlagBehavior {
114
    /// Emits an error if two values disagree, otherwise the resulting value is
115
    /// that of the operands.
116
    Error = 1,
117
118
    /// Emits a warning if two values disagree. The result value will be the
119
    /// operand for the flag from the first module being linked.
120
    Warning = 2,
121
122
    /// Adds a requirement that another module flag be present and have a
123
    /// specified value after linking is performed. The value must be a metadata
124
    /// pair, where the first element of the pair is the ID of the module flag
125
    /// to be restricted, and the second element of the pair is the value the
126
    /// module flag should be restricted to. This behavior can be used to
127
    /// restrict the allowable results (via triggering of an error) of linking
128
    /// IDs with the **Override** behavior.
129
    Require = 3,
130
131
    /// Uses the specified value, regardless of the behavior or value of the
132
    /// other module. If both modules specify **Override**, but the values
133
    /// differ, an error will be emitted.
134
    Override = 4,
135
136
    /// Appends the two values, which are required to be metadata nodes.
137
    Append = 5,
138
139
    /// Appends the two values, which are required to be metadata
140
    /// nodes. However, duplicate entries in the second list are dropped
141
    /// during the append operation.
142
    AppendUnique = 6,
143
144
    /// Takes the max of the two values, which are required to be integers.
145
    Max = 7,
146
147
    // Markers:
148
    ModFlagBehaviorFirstVal = Error,
149
    ModFlagBehaviorLastVal = Max
150
  };
151
152
  /// Checks if Metadata represents a valid ModFlagBehavior, and stores the
153
  /// converted result in MFB.
154
  static bool isValidModFlagBehavior(Metadata *MD, ModFlagBehavior &MFB);
155
156
  struct ModuleFlagEntry {
157
    ModFlagBehavior Behavior;
158
    MDString *Key;
159
    Metadata *Val;
160
161
    ModuleFlagEntry(ModFlagBehavior B, MDString *K, Metadata *V)
162
56.9M
        : Behavior(B), Key(K), Val(V) {}
163
  };
164
165
/// @}
166
/// @name Member Variables
167
/// @{
168
private:
169
  LLVMContext &Context;           ///< The LLVMContext from which types and
170
                                  ///< constants are allocated.
171
  GlobalListType GlobalList;      ///< The Global Variables in the module
172
  FunctionListType FunctionList;  ///< The Functions in the module
173
  AliasListType AliasList;        ///< The Aliases in the module
174
  IFuncListType IFuncList;        ///< The IFuncs in the module
175
  NamedMDListType NamedMDList;    ///< The named metadata in the module
176
  std::string GlobalScopeAsm;     ///< Inline Asm at global scope.
177
  ValueSymbolTable *ValSymTab;    ///< Symbol table for values
178
  ComdatSymTabType ComdatSymTab;  ///< Symbol table for COMDATs
179
  std::unique_ptr<MemoryBuffer>
180
  OwnedMemoryBuffer;              ///< Memory buffer directly owned by this
181
                                  ///< module, for legacy clients only.
182
  std::unique_ptr<GVMaterializer>
183
  Materializer;                   ///< Used to materialize GlobalValues
184
  std::string ModuleID;           ///< Human readable identifier for the module
185
  std::string SourceFileName;     ///< Original source file name for module,
186
                                  ///< recorded in bitcode.
187
  std::string TargetTriple;       ///< Platform target triple Module compiled on
188
                                  ///< Format: (arch)(sub)-(vendor)-(sys0-(abi)
189
  void *NamedMDSymTab;            ///< NamedMDNode names.
190
  DataLayout DL;                  ///< DataLayout associated with the module
191
192
  friend class Constant;
193
194
/// @}
195
/// @name Constructors
196
/// @{
197
public:
198
  /// The Module constructor. Note that there is no default constructor. You
199
  /// must provide a name for the module upon construction.
200
  explicit Module(StringRef ModuleID, LLVMContext& C);
201
  /// The module destructor. This will dropAllReferences.
202
  ~Module();
203
204
/// @}
205
/// @name Module Level Accessors
206
/// @{
207
208
  /// Get the module identifier which is, essentially, the name of the module.
209
  /// @returns the module identifier as a string
210
1.49M
  const std::string &getModuleIdentifier() const { return ModuleID; }
211
212
  /// Returns the number of non-debug IR instructions in the module.
213
  /// This is equivalent to the sum of the IR instruction counts of each
214
  /// function contained in the module.
215
  unsigned getInstructionCount();
216
217
  /// Get the module's original source file name. When compiling from
218
  /// bitcode, this is taken from a bitcode record where it was recorded.
219
  /// For other compiles it is the same as the ModuleID, which would
220
  /// contain the source file name.
221
83.4k
  const std::string &getSourceFileName() const { return SourceFileName; }
222
223
  /// Get a short "name" for the module.
224
  ///
225
  /// This is useful for debugging or logging. It is essentially a convenience
226
  /// wrapper around getModuleIdentifier().
227
271k
  StringRef getName() const { return ModuleID; }
228
229
  /// Get the data layout string for the module's target platform. This is
230
  /// equivalent to getDataLayout()->getStringRepresentation().
231
29.7k
  const std::string &getDataLayoutStr() const {
232
29.7k
    return DL.getStringRepresentation();
233
29.7k
  }
234
235
  /// Get the data layout for the module's target platform.
236
  const DataLayout &getDataLayout() const;
237
238
  /// Get the target triple which is a string describing the target host.
239
  /// @returns a string containing the target triple.
240
664k
  const std::string &getTargetTriple() const { return TargetTriple; }
241
242
  /// Get the global data context.
243
  /// @returns LLVMContext - a container for LLVM's global information
244
75.6M
  LLVMContext &getContext() const { return Context; }
245
246
  /// Get any module-scope inline assembly blocks.
247
  /// @returns a string containing the module-scope inline assembly blocks.
248
89.7k
  const std::string &getModuleInlineAsm() const { return GlobalScopeAsm; }
249
250
  /// Get a RandomNumberGenerator salted for use with this module. The
251
  /// RNG can be seeded via -rng-seed=<uint64> and is salted with the
252
  /// ModuleID and the provided pass salt. The returned RNG should not
253
  /// be shared across threads or passes.
254
  ///
255
  /// A unique RNG per pass ensures a reproducible random stream even
256
  /// when other randomness consuming passes are added or removed. In
257
  /// addition, the random stream will be reproducible across LLVM
258
  /// versions when the pass does not change.
259
  std::unique_ptr<RandomNumberGenerator> createRNG(const Pass* P) const;
260
261
  /// Return true if size-info optimization remark is enabled, false
262
  /// otherwise.
263
61.5M
  bool shouldEmitInstrCountChangedRemark() {
264
61.5M
    return getContext().getDiagHandlerPtr()->isAnalysisRemarkEnabled(
265
61.5M
        "size-info");
266
61.5M
  }
267
268
  /// @}
269
  /// @name Module Level Mutators
270
  /// @{
271
272
  /// Set the module identifier.
273
72
  void setModuleIdentifier(StringRef ID) { ModuleID = ID; }
274
275
  /// Set the module's original source file name.
276
9.70k
  void setSourceFileName(StringRef Name) { SourceFileName = Name; }
277
278
  /// Set the data layout
279
  void setDataLayout(StringRef Desc);
280
  void setDataLayout(const DataLayout &Other);
281
282
  /// Set the target triple.
283
55.1k
  void setTargetTriple(StringRef T) { TargetTriple = T; }
284
285
  /// Set the module-scope inline assembly blocks.
286
  /// A trailing newline is added if the input doesn't have one.
287
494
  void setModuleInlineAsm(StringRef Asm) {
288
494
    GlobalScopeAsm = Asm;
289
494
    if (!GlobalScopeAsm.empty() && 
GlobalScopeAsm.back() != '\n'156
)
290
0
      GlobalScopeAsm += '\n';
291
494
  }
292
293
  /// Append to the module-scope inline assembly blocks.
294
  /// A trailing newline is added if the input doesn't have one.
295
1.68k
  void appendModuleInlineAsm(StringRef Asm) {
296
1.68k
    GlobalScopeAsm += Asm;
297
1.68k
    if (!GlobalScopeAsm.empty() && 
GlobalScopeAsm.back() != '\n'1.68k
)
298
1.67k
      GlobalScopeAsm += '\n';
299
1.68k
  }
300
301
/// @}
302
/// @name Generic Value Accessors
303
/// @{
304
305
  /// Return the global value in the module with the specified name, of
306
  /// arbitrary type. This method returns null if a global with the specified
307
  /// name is not found.
308
  GlobalValue *getNamedValue(StringRef Name) const;
309
310
  /// Return a unique non-zero ID for the specified metadata kind. This ID is
311
  /// uniqued across modules in the current LLVMContext.
312
  unsigned getMDKindID(StringRef Name) const;
313
314
  /// Populate client supplied SmallVector with the name for custom metadata IDs
315
  /// registered in this LLVMContext.
316
  void getMDKindNames(SmallVectorImpl<StringRef> &Result) const;
317
318
  /// Populate client supplied SmallVector with the bundle tags registered in
319
  /// this LLVMContext.  The bundle tags are ordered by increasing bundle IDs.
320
  /// \see LLVMContext::getOperandBundleTagID
321
  void getOperandBundleTags(SmallVectorImpl<StringRef> &Result) const;
322
323
  /// Return the type with the specified name, or null if there is none by that
324
  /// name.
325
  StructType *getTypeByName(StringRef Name) const;
326
327
  std::vector<StructType *> getIdentifiedStructTypes() const;
328
329
/// @}
330
/// @name Function Accessors
331
/// @{
332
333
  /// Look up the specified function in the module symbol table. Four
334
  /// possibilities:
335
  ///   1. If it does not exist, add a prototype for the function and return it.
336
  ///   2. Otherwise, if the existing function has the correct prototype, return
337
  ///      the existing function.
338
  ///   3. Finally, the function exists but has the wrong prototype: return the
339
  ///      function with a constantexpr cast to the right prototype.
340
  ///
341
  /// In all cases, the returned value is a FunctionCallee wrapper around the
342
  /// 'FunctionType *T' passed in, as well as a 'Value*' either of the Function or
343
  /// the bitcast to the function.
344
  FunctionCallee getOrInsertFunction(StringRef Name, FunctionType *T,
345
                                     AttributeList AttributeList);
346
347
  FunctionCallee getOrInsertFunction(StringRef Name, FunctionType *T);
348
349
  /// Look up the specified function in the module symbol table. If it does not
350
  /// exist, add a prototype for the function and return it. This function
351
  /// guarantees to return a constant of pointer to the specified function type
352
  /// or a ConstantExpr BitCast of that type if the named function has a
353
  /// different type. This version of the method takes a list of
354
  /// function arguments, which makes it easier for clients to use.
355
  template <typename... ArgsTy>
356
  FunctionCallee getOrInsertFunction(StringRef Name,
357
                                     AttributeList AttributeList, Type *RetTy,
358
93.2k
                                     ArgsTy... Args) {
359
93.2k
    SmallVector<Type*, sizeof...(ArgsTy)> ArgTys{Args...};
360
93.2k
    return getOrInsertFunction(Name,
361
93.2k
                               FunctionType::get(RetTy, ArgTys, false),
362
93.2k
                               AttributeList);
363
93.2k
  }
llvm::FunctionCallee llvm::Module::getOrInsertFunction<llvm::PointerType*>(llvm::StringRef, llvm::AttributeList, llvm::Type*, llvm::PointerType*)
Line
Count
Source
358
40.6k
                                     ArgsTy... Args) {
359
40.6k
    SmallVector<Type*, sizeof...(ArgsTy)> ArgTys{Args...};
360
40.6k
    return getOrInsertFunction(Name,
361
40.6k
                               FunctionType::get(RetTy, ArgTys, false),
362
40.6k
                               AttributeList);
363
40.6k
  }
llvm::FunctionCallee llvm::Module::getOrInsertFunction<llvm::Type*, llvm::Type*, llvm::Type*>(llvm::StringRef, llvm::AttributeList, llvm::Type*, llvm::Type*, llvm::Type*, llvm::Type*)
Line
Count
Source
358
6.56k
                                     ArgsTy... Args) {
359
6.56k
    SmallVector<Type*, sizeof...(ArgsTy)> ArgTys{Args...};
360
6.56k
    return getOrInsertFunction(Name,
361
6.56k
                               FunctionType::get(RetTy, ArgTys, false),
362
6.56k
                               AttributeList);
363
6.56k
  }
llvm::FunctionCallee llvm::Module::getOrInsertFunction<llvm::Type*>(llvm::StringRef, llvm::AttributeList, llvm::Type*, llvm::Type*)
Line
Count
Source
358
2.12k
                                     ArgsTy... Args) {
359
2.12k
    SmallVector<Type*, sizeof...(ArgsTy)> ArgTys{Args...};
360
2.12k
    return getOrInsertFunction(Name,
361
2.12k
                               FunctionType::get(RetTy, ArgTys, false),
362
2.12k
                               AttributeList);
363
2.12k
  }
llvm::FunctionCallee llvm::Module::getOrInsertFunction<>(llvm::StringRef, llvm::AttributeList, llvm::Type*)
Line
Count
Source
358
5.48k
                                     ArgsTy... Args) {
359
5.48k
    SmallVector<Type*, sizeof...(ArgsTy)> ArgTys{Args...};
360
5.48k
    return getOrInsertFunction(Name,
361
5.48k
                               FunctionType::get(RetTy, ArgTys, false),
362
5.48k
                               AttributeList);
363
5.48k
  }
llvm::FunctionCallee llvm::Module::getOrInsertFunction<llvm::IntegerType*, llvm::PointerType*, llvm::PointerType*>(llvm::StringRef, llvm::AttributeList, llvm::Type*, llvm::IntegerType*, llvm::PointerType*, llvm::PointerType*)
Line
Count
Source
358
8
                                     ArgsTy... Args) {
359
8
    SmallVector<Type*, sizeof...(ArgsTy)> ArgTys{Args...};
360
8
    return getOrInsertFunction(Name,
361
8
                               FunctionType::get(RetTy, ArgTys, false),
362
8
                               AttributeList);
363
8
  }
llvm::FunctionCallee llvm::Module::getOrInsertFunction<llvm::PointerType*, llvm::PointerType*>(llvm::StringRef, llvm::AttributeList, llvm::Type*, llvm::PointerType*, llvm::PointerType*)
Line
Count
Source
358
379
                                     ArgsTy... Args) {
359
379
    SmallVector<Type*, sizeof...(ArgsTy)> ArgTys{Args...};
360
379
    return getOrInsertFunction(Name,
361
379
                               FunctionType::get(RetTy, ArgTys, false),
362
379
                               AttributeList);
363
379
  }
llvm::FunctionCallee llvm::Module::getOrInsertFunction<llvm::Type*, llvm::Type*>(llvm::StringRef, llvm::AttributeList, llvm::Type*, llvm::Type*, llvm::Type*)
Line
Count
Source
358
3.83k
                                     ArgsTy... Args) {
359
3.83k
    SmallVector<Type*, sizeof...(ArgsTy)> ArgTys{Args...};
360
3.83k
    return getOrInsertFunction(Name,
361
3.83k
                               FunctionType::get(RetTy, ArgTys, false),
362
3.83k
                               AttributeList);
363
3.83k
  }
llvm::FunctionCallee llvm::Module::getOrInsertFunction<llvm::PointerType*, llvm::PointerType*, llvm::Type*>(llvm::StringRef, llvm::AttributeList, llvm::Type*, llvm::PointerType*, llvm::PointerType*, llvm::Type*)
Line
Count
Source
358
3.71k
                                     ArgsTy... Args) {
359
3.71k
    SmallVector<Type*, sizeof...(ArgsTy)> ArgTys{Args...};
360
3.71k
    return getOrInsertFunction(Name,
361
3.71k
                               FunctionType::get(RetTy, ArgTys, false),
362
3.71k
                               AttributeList);
363
3.71k
  }
llvm::FunctionCallee llvm::Module::getOrInsertFunction<llvm::PointerType*, llvm::IntegerType*, llvm::Type*>(llvm::StringRef, llvm::AttributeList, llvm::Type*, llvm::PointerType*, llvm::IntegerType*, llvm::Type*)
Line
Count
Source
358
1.86k
                                     ArgsTy... Args) {
359
1.86k
    SmallVector<Type*, sizeof...(ArgsTy)> ArgTys{Args...};
360
1.86k
    return getOrInsertFunction(Name,
361
1.86k
                               FunctionType::get(RetTy, ArgTys, false),
362
1.86k
                               AttributeList);
363
1.86k
  }
llvm::FunctionCallee llvm::Module::getOrInsertFunction<llvm::IntegerType*>(llvm::StringRef, llvm::AttributeList, llvm::Type*, llvm::IntegerType*)
Line
Count
Source
358
1.96k
                                     ArgsTy... Args) {
359
1.96k
    SmallVector<Type*, sizeof...(ArgsTy)> ArgTys{Args...};
360
1.96k
    return getOrInsertFunction(Name,
361
1.96k
                               FunctionType::get(RetTy, ArgTys, false),
362
1.96k
                               AttributeList);
363
1.96k
  }
llvm::FunctionCallee llvm::Module::getOrInsertFunction<llvm::PointerType*, llvm::Type*>(llvm::StringRef, llvm::AttributeList, llvm::Type*, llvm::PointerType*, llvm::Type*)
Line
Count
Source
358
1.06k
                                     ArgsTy... Args) {
359
1.06k
    SmallVector<Type*, sizeof...(ArgsTy)> ArgTys{Args...};
360
1.06k
    return getOrInsertFunction(Name,
361
1.06k
                               FunctionType::get(RetTy, ArgTys, false),
362
1.06k
                               AttributeList);
363
1.06k
  }
llvm::FunctionCallee llvm::Module::getOrInsertFunction<llvm::PointerType*, llvm::IntegerType*>(llvm::StringRef, llvm::AttributeList, llvm::Type*, llvm::PointerType*, llvm::IntegerType*)
Line
Count
Source
358
136
                                     ArgsTy... Args) {
359
136
    SmallVector<Type*, sizeof...(ArgsTy)> ArgTys{Args...};
360
136
    return getOrInsertFunction(Name,
361
136
                               FunctionType::get(RetTy, ArgTys, false),
362
136
                               AttributeList);
363
136
  }
llvm::FunctionCallee llvm::Module::getOrInsertFunction<llvm::PointerType*, llvm::Type*, llvm::PointerType*>(llvm::StringRef, llvm::AttributeList, llvm::Type*, llvm::PointerType*, llvm::Type*, llvm::PointerType*)
Line
Count
Source
358
68
                                     ArgsTy... Args) {
359
68
    SmallVector<Type*, sizeof...(ArgsTy)> ArgTys{Args...};
360
68
    return getOrInsertFunction(Name,
361
68
                               FunctionType::get(RetTy, ArgTys, false),
362
68
                               AttributeList);
363
68
  }
llvm::FunctionCallee llvm::Module::getOrInsertFunction<llvm::IntegerType*, llvm::IntegerType*>(llvm::StringRef, llvm::AttributeList, llvm::Type*, llvm::IntegerType*, llvm::IntegerType*)
Line
Count
Source
358
1.88k
                                     ArgsTy... Args) {
359
1.88k
    SmallVector<Type*, sizeof...(ArgsTy)> ArgTys{Args...};
360
1.88k
    return getOrInsertFunction(Name,
361
1.88k
                               FunctionType::get(RetTy, ArgTys, false),
362
1.88k
                               AttributeList);
363
1.88k
  }
llvm::FunctionCallee llvm::Module::getOrInsertFunction<llvm::IntegerType*, llvm::PointerType*, llvm::IntegerType*>(llvm::StringRef, llvm::AttributeList, llvm::Type*, llvm::IntegerType*, llvm::PointerType*, llvm::IntegerType*)
Line
Count
Source
358
1.75k
                                     ArgsTy... Args) {
359
1.75k
    SmallVector<Type*, sizeof...(ArgsTy)> ArgTys{Args...};
360
1.75k
    return getOrInsertFunction(Name,
361
1.75k
                               FunctionType::get(RetTy, ArgTys, false),
362
1.75k
                               AttributeList);
363
1.75k
  }
llvm::FunctionCallee llvm::Module::getOrInsertFunction<llvm::PointerType*, llvm::Type*, llvm::PointerType*, llvm::Type*>(llvm::StringRef, llvm::AttributeList, llvm::Type*, llvm::PointerType*, llvm::Type*, llvm::PointerType*, llvm::Type*)
Line
Count
Source
358
439
                                     ArgsTy... Args) {
359
439
    SmallVector<Type*, sizeof...(ArgsTy)> ArgTys{Args...};
360
439
    return getOrInsertFunction(Name,
361
439
                               FunctionType::get(RetTy, ArgTys, false),
362
439
                               AttributeList);
363
439
  }
llvm::FunctionCallee llvm::Module::getOrInsertFunction<llvm::Type*, llvm::IntegerType*>(llvm::StringRef, llvm::AttributeList, llvm::Type*, llvm::Type*, llvm::IntegerType*)
Line
Count
Source
358
1.87k
                                     ArgsTy... Args) {
359
1.87k
    SmallVector<Type*, sizeof...(ArgsTy)> ArgTys{Args...};
360
1.87k
    return getOrInsertFunction(Name,
361
1.87k
                               FunctionType::get(RetTy, ArgTys, false),
362
1.87k
                               AttributeList);
363
1.87k
  }
llvm::FunctionCallee llvm::Module::getOrInsertFunction<llvm::Type*, llvm::Type*, llvm::IntegerType*>(llvm::StringRef, llvm::AttributeList, llvm::Type*, llvm::Type*, llvm::Type*, llvm::IntegerType*)
Line
Count
Source
358
14.8k
                                     ArgsTy... Args) {
359
14.8k
    SmallVector<Type*, sizeof...(ArgsTy)> ArgTys{Args...};
360
14.8k
    return getOrInsertFunction(Name,
361
14.8k
                               FunctionType::get(RetTy, ArgTys, false),
362
14.8k
                               AttributeList);
363
14.8k
  }
llvm::FunctionCallee llvm::Module::getOrInsertFunction<llvm::Type*, llvm::Type*, llvm::Type*, llvm::IntegerType*, llvm::IntegerType*>(llvm::StringRef, llvm::AttributeList, llvm::Type*, llvm::Type*, llvm::Type*, llvm::Type*, llvm::IntegerType*, llvm::IntegerType*)
Line
Count
Source
358
1.85k
                                     ArgsTy... Args) {
359
1.85k
    SmallVector<Type*, sizeof...(ArgsTy)> ArgTys{Args...};
360
1.85k
    return getOrInsertFunction(Name,
361
1.85k
                               FunctionType::get(RetTy, ArgTys, false),
362
1.85k
                               AttributeList);
363
1.85k
  }
llvm::FunctionCallee llvm::Module::getOrInsertFunction<llvm::PointerType*, llvm::PointerType*, llvm::IntegerType*, llvm::IntegerType*>(llvm::StringRef, llvm::AttributeList, llvm::Type*, llvm::PointerType*, llvm::PointerType*, llvm::IntegerType*, llvm::IntegerType*)
Line
Count
Source
358
34
                                     ArgsTy... Args) {
359
34
    SmallVector<Type*, sizeof...(ArgsTy)> ArgTys{Args...};
360
34
    return getOrInsertFunction(Name,
361
34
                               FunctionType::get(RetTy, ArgTys, false),
362
34
                               AttributeList);
363
34
  }
llvm::FunctionCallee llvm::Module::getOrInsertFunction<llvm::IntegerType*, llvm::Type*>(llvm::StringRef, llvm::AttributeList, llvm::Type*, llvm::IntegerType*, llvm::Type*)
Line
Count
Source
358
341
                                     ArgsTy... Args) {
359
341
    SmallVector<Type*, sizeof...(ArgsTy)> ArgTys{Args...};
360
341
    return getOrInsertFunction(Name,
361
341
                               FunctionType::get(RetTy, ArgTys, false),
362
341
                               AttributeList);
363
341
  }
llvm::FunctionCallee llvm::Module::getOrInsertFunction<llvm::PointerType*, llvm::IntegerType*, llvm::IntegerType*, llvm::Type*>(llvm::StringRef, llvm::AttributeList, llvm::Type*, llvm::PointerType*, llvm::IntegerType*, llvm::IntegerType*, llvm::Type*)
Line
Count
Source
358
2.35k
                                     ArgsTy... Args) {
359
2.35k
    SmallVector<Type*, sizeof...(ArgsTy)> ArgTys{Args...};
360
2.35k
    return getOrInsertFunction(Name,
361
2.35k
                               FunctionType::get(RetTy, ArgTys, false),
362
2.35k
                               AttributeList);
363
2.35k
  }
364
365
  /// Same as above, but without the attributes.
366
  template <typename... ArgsTy>
367
  FunctionCallee getOrInsertFunction(StringRef Name, Type *RetTy,
368
62.8k
                                     ArgsTy... Args) {
369
62.8k
    return getOrInsertFunction(Name, AttributeList{}, RetTy, Args...);
370
62.8k
  }
llvm::FunctionCallee llvm::Module::getOrInsertFunction<llvm::PointerType*>(llvm::StringRef, llvm::Type*, llvm::PointerType*)
Line
Count
Source
368
32.5k
                                     ArgsTy... Args) {
369
32.5k
    return getOrInsertFunction(Name, AttributeList{}, RetTy, Args...);
370
32.5k
  }
llvm::FunctionCallee llvm::Module::getOrInsertFunction<llvm::Type*, llvm::Type*, llvm::Type*>(llvm::StringRef, llvm::Type*, llvm::Type*, llvm::Type*, llvm::Type*)
Line
Count
Source
368
6.56k
                                     ArgsTy... Args) {
369
6.56k
    return getOrInsertFunction(Name, AttributeList{}, RetTy, Args...);
370
6.56k
  }
llvm::FunctionCallee llvm::Module::getOrInsertFunction<>(llvm::StringRef, llvm::Type*)
Line
Count
Source
368
4.36k
                                     ArgsTy... Args) {
369
4.36k
    return getOrInsertFunction(Name, AttributeList{}, RetTy, Args...);
370
4.36k
  }
llvm::FunctionCallee llvm::Module::getOrInsertFunction<llvm::Type*>(llvm::StringRef, llvm::Type*, llvm::Type*)
Line
Count
Source
368
2.08k
                                     ArgsTy... Args) {
369
2.08k
    return getOrInsertFunction(Name, AttributeList{}, RetTy, Args...);
370
2.08k
  }
llvm::FunctionCallee llvm::Module::getOrInsertFunction<llvm::IntegerType*, llvm::PointerType*, llvm::PointerType*>(llvm::StringRef, llvm::Type*, llvm::IntegerType*, llvm::PointerType*, llvm::PointerType*)
Line
Count
Source
368
8
                                     ArgsTy... Args) {
369
8
    return getOrInsertFunction(Name, AttributeList{}, RetTy, Args...);
370
8
  }
llvm::FunctionCallee llvm::Module::getOrInsertFunction<llvm::PointerType*, llvm::PointerType*>(llvm::StringRef, llvm::Type*, llvm::PointerType*, llvm::PointerType*)
Line
Count
Source
368
8
                                     ArgsTy... Args) {
369
8
    return getOrInsertFunction(Name, AttributeList{}, RetTy, Args...);
370
8
  }
llvm::FunctionCallee llvm::Module::getOrInsertFunction<llvm::Type*, llvm::Type*>(llvm::StringRef, llvm::Type*, llvm::Type*, llvm::Type*)
Line
Count
Source
368
3.71k
                                     ArgsTy... Args) {
369
3.71k
    return getOrInsertFunction(Name, AttributeList{}, RetTy, Args...);
370
3.71k
  }
llvm::FunctionCallee llvm::Module::getOrInsertFunction<llvm::PointerType*, llvm::PointerType*, llvm::Type*>(llvm::StringRef, llvm::Type*, llvm::PointerType*, llvm::PointerType*, llvm::Type*)
Line
Count
Source
368
2.97k
                                     ArgsTy... Args) {
369
2.97k
    return getOrInsertFunction(Name, AttributeList{}, RetTy, Args...);
370
2.97k
  }
llvm::FunctionCallee llvm::Module::getOrInsertFunction<llvm::PointerType*, llvm::IntegerType*, llvm::Type*>(llvm::StringRef, llvm::Type*, llvm::PointerType*, llvm::IntegerType*, llvm::Type*)
Line
Count
Source
368
1.48k
                                     ArgsTy... Args) {
369
1.48k
    return getOrInsertFunction(Name, AttributeList{}, RetTy, Args...);
370
1.48k
  }
llvm::FunctionCallee llvm::Module::getOrInsertFunction<llvm::IntegerType*>(llvm::StringRef, llvm::Type*, llvm::IntegerType*)
Line
Count
Source
368
1.18k
                                     ArgsTy... Args) {
369
1.18k
    return getOrInsertFunction(Name, AttributeList{}, RetTy, Args...);
370
1.18k
  }
llvm::FunctionCallee llvm::Module::getOrInsertFunction<llvm::PointerType*, llvm::Type*>(llvm::StringRef, llvm::Type*, llvm::PointerType*, llvm::Type*)
Line
Count
Source
368
1.06k
                                     ArgsTy... Args) {
369
1.06k
    return getOrInsertFunction(Name, AttributeList{}, RetTy, Args...);
370
1.06k
  }
llvm::FunctionCallee llvm::Module::getOrInsertFunction<llvm::PointerType*, llvm::IntegerType*>(llvm::StringRef, llvm::Type*, llvm::PointerType*, llvm::IntegerType*)
Line
Count
Source
368
136
                                     ArgsTy... Args) {
369
136
    return getOrInsertFunction(Name, AttributeList{}, RetTy, Args...);
370
136
  }
llvm::FunctionCallee llvm::Module::getOrInsertFunction<llvm::PointerType*, llvm::Type*, llvm::PointerType*>(llvm::StringRef, llvm::Type*, llvm::PointerType*, llvm::Type*, llvm::PointerType*)
Line
Count
Source
368
68
                                     ArgsTy... Args) {
369
68
    return getOrInsertFunction(Name, AttributeList{}, RetTy, Args...);
370
68
  }
llvm::FunctionCallee llvm::Module::getOrInsertFunction<llvm::IntegerType*, llvm::IntegerType*>(llvm::StringRef, llvm::Type*, llvm::IntegerType*, llvm::IntegerType*)
Line
Count
Source
368
1.75k
                                     ArgsTy... Args) {
369
1.75k
    return getOrInsertFunction(Name, AttributeList{}, RetTy, Args...);
370
1.75k
  }
llvm::FunctionCallee llvm::Module::getOrInsertFunction<llvm::IntegerType*, llvm::PointerType*, llvm::IntegerType*>(llvm::StringRef, llvm::Type*, llvm::IntegerType*, llvm::PointerType*, llvm::IntegerType*)
Line
Count
Source
368
1.75k
                                     ArgsTy... Args) {
369
1.75k
    return getOrInsertFunction(Name, AttributeList{}, RetTy, Args...);
370
1.75k
  }
llvm::FunctionCallee llvm::Module::getOrInsertFunction<llvm::PointerType*, llvm::Type*, llvm::PointerType*, llvm::Type*>(llvm::StringRef, llvm::Type*, llvm::PointerType*, llvm::Type*, llvm::PointerType*, llvm::Type*)
Line
Count
Source
368
439
                                     ArgsTy... Args) {
369
439
    return getOrInsertFunction(Name, AttributeList{}, RetTy, Args...);
370
439
  }
llvm::FunctionCallee llvm::Module::getOrInsertFunction<llvm::IntegerType*, llvm::Type*>(llvm::StringRef, llvm::Type*, llvm::IntegerType*, llvm::Type*)
Line
Count
Source
368
341
                                     ArgsTy... Args) {
369
341
    return getOrInsertFunction(Name, AttributeList{}, RetTy, Args...);
370
341
  }
llvm::FunctionCallee llvm::Module::getOrInsertFunction<llvm::PointerType*, llvm::IntegerType*, llvm::IntegerType*, llvm::Type*>(llvm::StringRef, llvm::Type*, llvm::PointerType*, llvm::IntegerType*, llvm::IntegerType*, llvm::Type*)
Line
Count
Source
368
2.35k
                                     ArgsTy... Args) {
369
2.35k
    return getOrInsertFunction(Name, AttributeList{}, RetTy, Args...);
370
2.35k
  }
llvm::FunctionCallee llvm::Module::getOrInsertFunction<llvm::Type*, llvm::IntegerType*>(llvm::StringRef, llvm::Type*, llvm::Type*, llvm::IntegerType*)
Line
Count
Source
368
21
                                     ArgsTy... Args) {
369
21
    return getOrInsertFunction(Name, AttributeList{}, RetTy, Args...);
370
21
  }
371
372
  // Avoid an incorrect ordering that'd otherwise compile incorrectly.
373
  template <typename... ArgsTy>
374
  FunctionCallee
375
  getOrInsertFunction(StringRef Name, AttributeList AttributeList,
376
                      FunctionType *Invalid, ArgsTy... Args) = delete;
377
378
  /// Look up the specified function in the module symbol table. If it does not
379
  /// exist, return null.
380
  Function *getFunction(StringRef Name) const;
381
382
/// @}
383
/// @name Global Variable Accessors
384
/// @{
385
386
  /// Look up the specified global variable in the module symbol table. If it
387
  /// does not exist, return null. If AllowInternal is set to true, this
388
  /// function will return types that have InternalLinkage. By default, these
389
  /// types are not returned.
390
93.5k
  GlobalVariable *getGlobalVariable(StringRef Name) const {
391
93.5k
    return getGlobalVariable(Name, false);
392
93.5k
  }
393
394
  GlobalVariable *getGlobalVariable(StringRef Name, bool AllowInternal) const;
395
396
  GlobalVariable *getGlobalVariable(StringRef Name,
397
131k
                                    bool AllowInternal = false) {
398
131k
    return static_cast<const Module *>(this)->getGlobalVariable(Name,
399
131k
                                                                AllowInternal);
400
131k
  }
401
402
  /// Return the global variable in the module with the specified name, of
403
  /// arbitrary type. This method returns null if a global with the specified
404
  /// name is not found.
405
34.9k
  const GlobalVariable *getNamedGlobal(StringRef Name) const {
406
34.9k
    return getGlobalVariable(Name, true);
407
34.9k
  }
408
33.8k
  GlobalVariable *getNamedGlobal(StringRef Name) {
409
33.8k
    return const_cast<GlobalVariable *>(
410
33.8k
                       static_cast<const Module *>(this)->getNamedGlobal(Name));
411
33.8k
  }
412
413
  /// Look up the specified global in the module symbol table.
414
  /// If it does not exist, invoke a callback to create a declaration of the
415
  /// global and return it. The global is constantexpr casted to the expected
416
  /// type if necessary.
417
  Constant *
418
  getOrInsertGlobal(StringRef Name, Type *Ty,
419
                    function_ref<GlobalVariable *()> CreateGlobalCallback);
420
421
  /// Look up the specified global in the module symbol table. If required, this
422
  /// overload constructs the global variable using its constructor's defaults.
423
  Constant *getOrInsertGlobal(StringRef Name, Type *Ty);
424
425
/// @}
426
/// @name Global Alias Accessors
427
/// @{
428
429
  /// Return the global alias in the module with the specified name, of
430
  /// arbitrary type. This method returns null if a global with the specified
431
  /// name is not found.
432
  GlobalAlias *getNamedAlias(StringRef Name) const;
433
434
/// @}
435
/// @name Global IFunc Accessors
436
/// @{
437
438
  /// Return the global ifunc in the module with the specified name, of
439
  /// arbitrary type. This method returns null if a global with the specified
440
  /// name is not found.
441
  GlobalIFunc *getNamedIFunc(StringRef Name) const;
442
443
/// @}
444
/// @name Named Metadata Accessors
445
/// @{
446
447
  /// Return the first NamedMDNode in the module with the specified name. This
448
  /// method returns null if a NamedMDNode with the specified name is not found.
449
  NamedMDNode *getNamedMetadata(const Twine &Name) const;
450
451
  /// Return the named MDNode in the module with the specified name. This method
452
  /// returns a new NamedMDNode if a NamedMDNode with the specified name is not
453
  /// found.
454
  NamedMDNode *getOrInsertNamedMetadata(StringRef Name);
455
456
  /// Remove the given NamedMDNode from this module and delete it.
457
  void eraseNamedMetadata(NamedMDNode *NMD);
458
459
/// @}
460
/// @name Comdat Accessors
461
/// @{
462
463
  /// Return the Comdat in the module with the specified name. It is created
464
  /// if it didn't already exist.
465
  Comdat *getOrInsertComdat(StringRef Name);
466
467
/// @}
468
/// @name Module Flags Accessors
469
/// @{
470
471
  /// Returns the module flags in the provided vector.
472
  void getModuleFlagsMetadata(SmallVectorImpl<ModuleFlagEntry> &Flags) const;
473
474
  /// Return the corresponding value if Key appears in module flags, otherwise
475
  /// return null.
476
  Metadata *getModuleFlag(StringRef Key) const;
477
478
  /// Returns the NamedMDNode in the module that represents module-level flags.
479
  /// This method returns null if there are no module-level flags.
480
  NamedMDNode *getModuleFlagsMetadata() const;
481
482
  /// Returns the NamedMDNode in the module that represents module-level flags.
483
  /// If module-level flags aren't found, it creates the named metadata that
484
  /// contains them.
485
  NamedMDNode *getOrInsertModuleFlagsMetadata();
486
487
  /// Add a module-level flag to the module-level flags metadata. It will create
488
  /// the module-level flags named metadata if it doesn't already exist.
489
  void addModuleFlag(ModFlagBehavior Behavior, StringRef Key, Metadata *Val);
490
  void addModuleFlag(ModFlagBehavior Behavior, StringRef Key, Constant *Val);
491
  void addModuleFlag(ModFlagBehavior Behavior, StringRef Key, uint32_t Val);
492
  void addModuleFlag(MDNode *Node);
493
494
/// @}
495
/// @name Materialization
496
/// @{
497
498
  /// Sets the GVMaterializer to GVM. This module must not yet have a
499
  /// Materializer. To reset the materializer for a module that already has one,
500
  /// call materializeAll first. Destroying this module will destroy
501
  /// its materializer without materializing any more GlobalValues. Without
502
  /// destroying the Module, there is no way to detach or destroy a materializer
503
  /// without materializing all the GVs it controls, to avoid leaving orphan
504
  /// unmaterialized GVs.
505
  void setMaterializer(GVMaterializer *GVM);
506
  /// Retrieves the GVMaterializer, if any, for this Module.
507
279k
  GVMaterializer *getMaterializer() const { return Materializer.get(); }
508
232k
  bool isMaterialized() const { return !getMaterializer(); }
509
510
  /// Make sure the GlobalValue is fully read.
511
  llvm::Error materialize(GlobalValue *GV);
512
513
  /// Make sure all GlobalValues in this Module are fully read and clear the
514
  /// Materializer.
515
  llvm::Error materializeAll();
516
517
  llvm::Error materializeMetadata();
518
519
/// @}
520
/// @name Direct access to the globals list, functions list, and symbol table
521
/// @{
522
523
  /// Get the Module's list of global variables (constant).
524
0
  const GlobalListType   &getGlobalList() const       { return GlobalList; }
525
  /// Get the Module's list of global variables.
526
650k
  GlobalListType         &getGlobalList()             { return GlobalList; }
527
528
778k
  static GlobalListType Module::*getSublistAccess(GlobalVariable*) {
529
778k
    return &Module::GlobalList;
530
778k
  }
531
532
  /// Get the Module's list of functions (constant).
533
0
  const FunctionListType &getFunctionList() const     { return FunctionList; }
534
  /// Get the Module's list of functions.
535
3.26M
  FunctionListType       &getFunctionList()           { return FunctionList; }
536
3.98M
  static FunctionListType Module::*getSublistAccess(Function*) {
537
3.98M
    return &Module::FunctionList;
538
3.98M
  }
539
540
  /// Get the Module's list of aliases (constant).
541
0
  const AliasListType    &getAliasList() const        { return AliasList; }
542
  /// Get the Module's list of aliases.
543
4.96k
  AliasListType          &getAliasList()              { return AliasList; }
544
545
6.63k
  static AliasListType Module::*getSublistAccess(GlobalAlias*) {
546
6.63k
    return &Module::AliasList;
547
6.63k
  }
548
549
  /// Get the Module's list of ifuncs (constant).
550
0
  const IFuncListType    &getIFuncList() const        { return IFuncList; }
551
  /// Get the Module's list of ifuncs.
552
154
  IFuncListType          &getIFuncList()              { return IFuncList; }
553
554
296
  static IFuncListType Module::*getSublistAccess(GlobalIFunc*) {
555
296
    return &Module::IFuncList;
556
296
  }
557
558
  /// Get the Module's list of named metadata (constant).
559
0
  const NamedMDListType  &getNamedMDList() const      { return NamedMDList; }
560
  /// Get the Module's list of named metadata.
561
15
  NamedMDListType        &getNamedMDList()            { return NamedMDList; }
562
563
0
  static NamedMDListType Module::*getSublistAccess(NamedMDNode*) {
564
0
    return &Module::NamedMDList;
565
0
  }
566
567
  /// Get the symbol table of global variable and function identifiers
568
76.4M
  const ValueSymbolTable &getValueSymbolTable() const { return *ValSymTab; }
569
  /// Get the Module's symbol table of global variable and function identifiers.
570
5.00M
  ValueSymbolTable       &getValueSymbolTable()       { return *ValSymTab; }
571
572
  /// Get the Module's symbol table for COMDATs (constant).
573
110k
  const ComdatSymTabType &getComdatSymbolTable() const { return ComdatSymTab; }
574
  /// Get the Module's symbol table for COMDATs.
575
3.15k
  ComdatSymTabType &getComdatSymbolTable() { return ComdatSymTab; }
576
577
/// @}
578
/// @name Global Variable Iteration
579
/// @{
580
581
590k
  global_iterator       global_begin()       { return GlobalList.begin(); }
582
351k
  const_global_iterator global_begin() const { return GlobalList.begin(); }
583
590k
  global_iterator       global_end  ()       { return GlobalList.end(); }
584
351k
  const_global_iterator global_end  () const { return GlobalList.end(); }
585
24.8k
  bool                  global_empty() const { return GlobalList.empty(); }
586
587
501k
  iterator_range<global_iterator> globals() {
588
501k
    return make_range(global_begin(), global_end());
589
501k
  }
590
350k
  iterator_range<const_global_iterator> globals() const {
591
350k
    return make_range(global_begin(), global_end());
592
350k
  }
593
594
/// @}
595
/// @name Function Iteration
596
/// @{
597
598
1.25M
  iterator                begin()       { return FunctionList.begin(); }
599
383k
  const_iterator          begin() const { return FunctionList.begin(); }
600
1.30M
  iterator                end  ()       { return FunctionList.end();   }
601
383k
  const_iterator          end  () const { return FunctionList.end();   }
602
0
  reverse_iterator        rbegin()      { return FunctionList.rbegin(); }
603
3.63k
  const_reverse_iterator  rbegin() const{ return FunctionList.rbegin(); }
604
0
  reverse_iterator        rend()        { return FunctionList.rend(); }
605
3.63k
  const_reverse_iterator  rend() const  { return FunctionList.rend(); }
606
2.51k
  size_t                  size() const  { return FunctionList.size(); }
607
8.63k
  bool                    empty() const { return FunctionList.empty(); }
608
609
131k
  iterator_range<iterator> functions() {
610
131k
    return make_range(begin(), end());
611
131k
  }
612
81.7k
  iterator_range<const_iterator> functions() const {
613
81.7k
    return make_range(begin(), end());
614
81.7k
  }
615
616
/// @}
617
/// @name Alias Iteration
618
/// @{
619
620
297k
  alias_iterator       alias_begin()            { return AliasList.begin(); }
621
221k
  const_alias_iterator alias_begin() const      { return AliasList.begin(); }
622
297k
  alias_iterator       alias_end  ()            { return AliasList.end();   }
623
221k
  const_alias_iterator alias_end  () const      { return AliasList.end();   }
624
258
  size_t               alias_size () const      { return AliasList.size();  }
625
19.8k
  bool                 alias_empty() const      { return AliasList.empty(); }
626
627
251k
  iterator_range<alias_iterator> aliases() {
628
251k
    return make_range(alias_begin(), alias_end());
629
251k
  }
630
221k
  iterator_range<const_alias_iterator> aliases() const {
631
221k
    return make_range(alias_begin(), alias_end());
632
221k
  }
633
634
/// @}
635
/// @name IFunc Iteration
636
/// @{
637
638
172k
  ifunc_iterator       ifunc_begin()            { return IFuncList.begin(); }
639
85.8k
  const_ifunc_iterator ifunc_begin() const      { return IFuncList.begin(); }
640
172k
  ifunc_iterator       ifunc_end  ()            { return IFuncList.end();   }
641
85.8k
  const_ifunc_iterator ifunc_end  () const      { return IFuncList.end();   }
642
0
  size_t               ifunc_size () const      { return IFuncList.size();  }
643
19.8k
  bool                 ifunc_empty() const      { return IFuncList.empty(); }
644
645
172k
  iterator_range<ifunc_iterator> ifuncs() {
646
172k
    return make_range(ifunc_begin(), ifunc_end());
647
172k
  }
648
85.8k
  iterator_range<const_ifunc_iterator> ifuncs() const {
649
85.8k
    return make_range(ifunc_begin(), ifunc_end());
650
85.8k
  }
651
652
  /// @}
653
  /// @name Convenience iterators
654
  /// @{
655
656
  using global_object_iterator =
657
      concat_iterator<GlobalObject, iterator, global_iterator>;
658
  using const_global_object_iterator =
659
      concat_iterator<const GlobalObject, const_iterator,
660
                      const_global_iterator>;
661
662
63.9k
  iterator_range<global_object_iterator> global_objects() {
663
63.9k
    return concat<GlobalObject>(functions(), globals());
664
63.9k
  }
665
81.6k
  iterator_range<const_global_object_iterator> global_objects() const {
666
81.6k
    return concat<const GlobalObject>(functions(), globals());
667
81.6k
  }
668
669
0
  global_object_iterator global_object_begin() {
670
0
    return global_objects().begin();
671
0
  }
672
0
  global_object_iterator global_object_end() { return global_objects().end(); }
673
674
0
  const_global_object_iterator global_object_begin() const {
675
0
    return global_objects().begin();
676
0
  }
677
0
  const_global_object_iterator global_object_end() const {
678
0
    return global_objects().end();
679
0
  }
680
681
  using global_value_iterator =
682
      concat_iterator<GlobalValue, iterator, global_iterator, alias_iterator,
683
                      ifunc_iterator>;
684
  using const_global_value_iterator =
685
      concat_iterator<const GlobalValue, const_iterator, const_global_iterator,
686
                      const_alias_iterator, const_ifunc_iterator>;
687
688
24.1k
  iterator_range<global_value_iterator> global_values() {
689
24.1k
    return concat<GlobalValue>(functions(), globals(), aliases(), ifuncs());
690
24.1k
  }
691
74
  iterator_range<const_global_value_iterator> global_values() const {
692
74
    return concat<const GlobalValue>(functions(), globals(), aliases(),
693
74
                                     ifuncs());
694
74
  }
695
696
0
  global_value_iterator global_value_begin() { return global_values().begin(); }
697
0
  global_value_iterator global_value_end() { return global_values().end(); }
698
699
0
  const_global_value_iterator global_value_begin() const {
700
0
    return global_values().begin();
701
0
  }
702
0
  const_global_value_iterator global_value_end() const {
703
0
    return global_values().end();
704
0
  }
705
706
  /// @}
707
  /// @name Named Metadata Iteration
708
  /// @{
709
710
46.1k
  named_metadata_iterator named_metadata_begin() { return NamedMDList.begin(); }
711
192k
  const_named_metadata_iterator named_metadata_begin() const {
712
192k
    return NamedMDList.begin();
713
192k
  }
714
715
46.1k
  named_metadata_iterator named_metadata_end() { return NamedMDList.end(); }
716
192k
  const_named_metadata_iterator named_metadata_end() const {
717
192k
    return NamedMDList.end();
718
192k
  }
719
720
  size_t named_metadata_size() const { return NamedMDList.size();  }
721
24.8k
  bool named_metadata_empty() const { return NamedMDList.empty(); }
722
723
1.12k
  iterator_range<named_metadata_iterator> named_metadata() {
724
1.12k
    return make_range(named_metadata_begin(), named_metadata_end());
725
1.12k
  }
726
191k
  iterator_range<const_named_metadata_iterator> named_metadata() const {
727
191k
    return make_range(named_metadata_begin(), named_metadata_end());
728
191k
  }
729
730
  /// An iterator for DICompileUnits that skips those marked NoDebug.
731
  class debug_compile_units_iterator
732
      : public std::iterator<std::input_iterator_tag, DICompileUnit *> {
733
    NamedMDNode *CUs;
734
    unsigned Idx;
735
736
    void SkipNoDebugCUs();
737
738
  public:
739
    explicit debug_compile_units_iterator(NamedMDNode *CUs, unsigned Idx)
740
227k
        : CUs(CUs), Idx(Idx) {
741
227k
      SkipNoDebugCUs();
742
227k
    }
743
744
10.6k
    debug_compile_units_iterator &operator++() {
745
10.6k
      ++Idx;
746
10.6k
      SkipNoDebugCUs();
747
10.6k
      return *this;
748
10.6k
    }
749
750
0
    debug_compile_units_iterator operator++(int) {
751
0
      debug_compile_units_iterator T(*this);
752
0
      ++Idx;
753
0
      return T;
754
0
    }
755
756
38.5k
    bool operator==(const debug_compile_units_iterator &I) const {
757
38.5k
      return Idx == I.Idx;
758
38.5k
    }
759
760
85.7k
    bool operator!=(const debug_compile_units_iterator &I) const {
761
85.7k
      return Idx != I.Idx;
762
85.7k
    }
763
764
    DICompileUnit *operator*() const;
765
    DICompileUnit *operator->() const;
766
  };
767
768
35.7k
  debug_compile_units_iterator debug_compile_units_begin() const {
769
35.7k
    auto *CUs = getNamedMetadata("llvm.dbg.cu");
770
35.7k
    return debug_compile_units_iterator(CUs, 0);
771
35.7k
  }
772
773
35.7k
  debug_compile_units_iterator debug_compile_units_end() const {
774
35.7k
    auto *CUs = getNamedMetadata("llvm.dbg.cu");
775
35.7k
    return debug_compile_units_iterator(CUs, CUs ? 
CUs->getNumOperands()3.26k
:
032.5k
);
776
35.7k
  }
777
778
  /// Return an iterator for all DICompileUnits listed in this Module's
779
  /// llvm.dbg.cu named metadata node and aren't explicitly marked as
780
  /// NoDebug.
781
77.8k
  iterator_range<debug_compile_units_iterator> debug_compile_units() const {
782
77.8k
    auto *CUs = getNamedMetadata("llvm.dbg.cu");
783
77.8k
    return make_range(
784
77.8k
        debug_compile_units_iterator(CUs, 0),
785
77.8k
        debug_compile_units_iterator(CUs, CUs ? 
CUs->getNumOperands()10.3k
:
067.5k
));
786
77.8k
  }
787
/// @}
788
789
  /// Destroy ConstantArrays in LLVMContext if they are not used.
790
  /// ConstantArrays constructed during linking can cause quadratic memory
791
  /// explosion. Releasing all unused constants can cause a 20% LTO compile-time
792
  /// slowdown for a large application.
793
  ///
794
  /// NOTE: Constants are currently owned by LLVMContext. This can then only
795
  /// be called where all uses of the LLVMContext are understood.
796
  void dropTriviallyDeadConstantArrays();
797
798
/// @name Utility functions for printing and dumping Module objects
799
/// @{
800
801
  /// Print the module to an output stream with an optional
802
  /// AssemblyAnnotationWriter.  If \c ShouldPreserveUseListOrder, then include
803
  /// uselistorder directives so that use-lists can be recreated when reading
804
  /// the assembly.
805
  void print(raw_ostream &OS, AssemblyAnnotationWriter *AAW,
806
             bool ShouldPreserveUseListOrder = false,
807
             bool IsForDebug = false) const;
808
809
  /// Dump the module to stderr (for debugging).
810
  void dump() const;
811
812
  /// This function causes all the subinstructions to "let go" of all references
813
  /// that they are maintaining.  This allows one to 'delete' a whole class at
814
  /// a time, even though there may be circular references... first all
815
  /// references are dropped, and all use counts go to zero.  Then everything
816
  /// is delete'd for real.  Note that no operations are valid on an object
817
  /// that has "dropped all references", except operator delete.
818
  void dropAllReferences();
819
820
/// @}
821
/// @name Utility functions for querying Debug information.
822
/// @{
823
824
  /// Returns the Number of Register ParametersDwarf Version by checking
825
  /// module flags.
826
  unsigned getNumberRegisterParameters() const;
827
828
  /// Returns the Dwarf Version by checking module flags.
829
  unsigned getDwarfVersion() const;
830
831
  /// Returns the CodeView Version by checking module flags.
832
  /// Returns zero if not present in module.
833
  unsigned getCodeViewFlag() const;
834
835
/// @}
836
/// @name Utility functions for querying and setting PIC level
837
/// @{
838
839
  /// Returns the PIC level (small or large model)
840
  PICLevel::Level getPICLevel() const;
841
842
  /// Set the PIC level (small or large model)
843
  void setPICLevel(PICLevel::Level PL);
844
/// @}
845
846
/// @}
847
/// @name Utility functions for querying and setting PIE level
848
/// @{
849
850
  /// Returns the PIE level (small or large model)
851
  PIELevel::Level getPIELevel() const;
852
853
  /// Set the PIE level (small or large model)
854
  void setPIELevel(PIELevel::Level PL);
855
/// @}
856
857
  /// @}
858
  /// @name Utility function for querying and setting code model
859
  /// @{
860
861
  /// Returns the code model (tiny, small, kernel, medium or large model)
862
  Optional<CodeModel::Model> getCodeModel() const;
863
864
  /// Set the code model (tiny, small, kernel, medium or large)
865
  void setCodeModel(CodeModel::Model CL);
866
  /// @}
867
868
  /// @name Utility functions for querying and setting PGO summary
869
  /// @{
870
871
  /// Attach profile summary metadata to this module.
872
  void setProfileSummary(Metadata *M, ProfileSummary::Kind Kind);
873
874
  /// Returns profile summary metadata. When IsCS is true, use the context
875
  /// sensitive profile summary.
876
  Metadata *getProfileSummary(bool IsCS);
877
  /// @}
878
879
  /// Returns true if PLT should be avoided for RTLib calls.
880
  bool getRtLibUseGOT() const;
881
882
  /// Set that PLT should be avoid for RTLib calls.
883
  void setRtLibUseGOT();
884
885
  /// @name Utility functions for querying and setting the build SDK version
886
  /// @{
887
888
  /// Attach a build SDK version metadata to this module.
889
  void setSDKVersion(const VersionTuple &V);
890
891
  /// Get the build SDK version metadata.
892
  ///
893
  /// An empty version is returned if no such metadata is attached.
894
  VersionTuple getSDKVersion() const;
895
  /// @}
896
897
  /// Take ownership of the given memory buffer.
898
  void setOwnedMemoryBuffer(std::unique_ptr<MemoryBuffer> MB);
899
};
900
901
/// Given "llvm.used" or "llvm.compiler.used" as a global name, collect
902
/// the initializer elements of that global in Set and return the global itself.
903
GlobalVariable *collectUsedGlobalVariables(const Module &M,
904
                                           SmallPtrSetImpl<GlobalValue *> &Set,
905
                                           bool CompilerUsed);
906
907
/// An raw_ostream inserter for modules.
908
8
inline raw_ostream &operator<<(raw_ostream &O, const Module &M) {
909
8
  M.print(O, nullptr);
910
8
  return O;
911
8
}
912
913
// Create wrappers for C Binding types (see CBindingWrapping.h).
914
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Module, LLVMModuleRef)
915
916
/* LLVMModuleProviderRef exists for historical reasons, but now just holds a
917
 * Module.
918
 */
919
0
inline Module *unwrap(LLVMModuleProviderRef MP) {
920
0
  return reinterpret_cast<Module*>(MP);
921
0
}
922
923
} // end namespace llvm
924
925
#endif // LLVM_IR_MODULE_H