Coverage Report

Created: 2017-10-03 07:32

/Users/buildslave/jenkins/sharedspace/clang-stage2-coverage-R@2/llvm/lib/IR/Module.cpp
Line
Count
Source (jump to first uncovered line)
1
//===- Module.cpp - Implement the Module class ----------------------------===//
2
//
3
//                     The LLVM Compiler Infrastructure
4
//
5
// This file is distributed under the University of Illinois Open Source
6
// License. See LICENSE.TXT for details.
7
//
8
//===----------------------------------------------------------------------===//
9
//
10
// This file implements the Module class for the IR library.
11
//
12
//===----------------------------------------------------------------------===//
13
14
#include "llvm/IR/Module.h"
15
#include "SymbolTableListTraitsImpl.h"
16
#include "llvm/ADT/SmallPtrSet.h"
17
#include "llvm/ADT/SmallString.h"
18
#include "llvm/ADT/SmallVector.h"
19
#include "llvm/ADT/StringMap.h"
20
#include "llvm/ADT/StringRef.h"
21
#include "llvm/ADT/Twine.h"
22
#include "llvm/IR/Attributes.h"
23
#include "llvm/IR/Comdat.h"
24
#include "llvm/IR/Constants.h"
25
#include "llvm/IR/DataLayout.h"
26
#include "llvm/IR/DebugInfoMetadata.h"
27
#include "llvm/IR/DerivedTypes.h"
28
#include "llvm/IR/Function.h"
29
#include "llvm/IR/GVMaterializer.h"
30
#include "llvm/IR/GlobalAlias.h"
31
#include "llvm/IR/GlobalIFunc.h"
32
#include "llvm/IR/GlobalValue.h"
33
#include "llvm/IR/GlobalVariable.h"
34
#include "llvm/IR/LLVMContext.h"
35
#include "llvm/IR/Metadata.h"
36
#include "llvm/IR/SymbolTableListTraits.h"
37
#include "llvm/IR/Type.h"
38
#include "llvm/IR/TypeFinder.h"
39
#include "llvm/IR/Value.h"
40
#include "llvm/IR/ValueSymbolTable.h"
41
#include "llvm/Pass.h"
42
#include "llvm/Support/Casting.h"
43
#include "llvm/Support/CodeGen.h"
44
#include "llvm/Support/Error.h"
45
#include "llvm/Support/MemoryBuffer.h"
46
#include "llvm/Support/Path.h"
47
#include "llvm/Support/RandomNumberGenerator.h"
48
#include <algorithm>
49
#include <cassert>
50
#include <cstdint>
51
#include <memory>
52
#include <utility>
53
#include <vector>
54
55
using namespace llvm;
56
57
//===----------------------------------------------------------------------===//
58
// Methods to implement the globals and functions lists.
59
//
60
61
// Explicit instantiations of SymbolTableListTraits since some of the methods
62
// are not in the public header file.
63
template class llvm::SymbolTableListTraits<Function>;
64
template class llvm::SymbolTableListTraits<GlobalVariable>;
65
template class llvm::SymbolTableListTraits<GlobalAlias>;
66
template class llvm::SymbolTableListTraits<GlobalIFunc>;
67
68
//===----------------------------------------------------------------------===//
69
// Primitive Module methods.
70
//
71
72
Module::Module(StringRef MID, LLVMContext &C)
73
53.6k
    : Context(C), Materializer(), ModuleID(MID), SourceFileName(MID), DL("") {
74
53.6k
  ValSymTab = new ValueSymbolTable();
75
53.6k
  NamedMDSymTab = new StringMap<NamedMDNode *>();
76
53.6k
  Context.addModule(this);
77
53.6k
}
78
79
36.2k
Module::~Module() {
80
36.2k
  Context.removeModule(this);
81
36.2k
  dropAllReferences();
82
36.2k
  GlobalList.clear();
83
36.2k
  FunctionList.clear();
84
36.2k
  AliasList.clear();
85
36.2k
  IFuncList.clear();
86
36.2k
  NamedMDList.clear();
87
36.2k
  delete ValSymTab;
88
36.2k
  delete static_cast<StringMap<NamedMDNode *> *>(NamedMDSymTab);
89
36.2k
}
90
91
2
std::unique_ptr<RandomNumberGenerator> Module::createRNG(const Pass* P) const {
92
2
  SmallString<32> Salt(P->getPassName());
93
2
94
2
  // This RNG is guaranteed to produce the same random stream only
95
2
  // when the Module ID and thus the input filename is the same. This
96
2
  // might be problematic if the input filename extension changes
97
2
  // (e.g. from .c to .bc or .ll).
98
2
  //
99
2
  // We could store this salt in NamedMetadata, but this would make
100
2
  // the parameter non-const. This would unfortunately make this
101
2
  // interface unusable by any Machine passes, since they only have a
102
2
  // const reference to their IR Module. Alternatively we can always
103
2
  // store salt metadata from the Module constructor.
104
2
  Salt += sys::path::filename(getModuleIdentifier());
105
2
106
2
  return std::unique_ptr<RandomNumberGenerator>(new RandomNumberGenerator(Salt));
107
2
}
108
109
/// getNamedValue - Return the first global value in the module with
110
/// the specified name, of arbitrary type.  This method returns null
111
/// if a global with the specified name is not found.
112
84.5M
GlobalValue *Module::getNamedValue(StringRef Name) const {
113
84.5M
  return cast_or_null<GlobalValue>(getValueSymbolTable().lookup(Name));
114
84.5M
}
115
116
/// getMDKindID - Return a unique non-zero ID for the specified metadata kind.
117
/// This ID is uniqued across modules in the current LLVMContext.
118
258k
unsigned Module::getMDKindID(StringRef Name) const {
119
258k
  return Context.getMDKindID(Name);
120
258k
}
121
122
/// getMDKindNames - Populate client supplied SmallVector with the name for
123
/// custom metadata IDs registered in this LLVMContext.   ID #0 is not used,
124
/// so it is filled in as an empty string.
125
3.22k
void Module::getMDKindNames(SmallVectorImpl<StringRef> &Result) const {
126
3.22k
  return Context.getMDKindNames(Result);
127
3.22k
}
128
129
3.22k
void Module::getOperandBundleTags(SmallVectorImpl<StringRef> &Result) const {
130
3.22k
  return Context.getOperandBundleTags(Result);
131
3.22k
}
132
133
//===----------------------------------------------------------------------===//
134
// Methods for easy access to the functions in the module.
135
//
136
137
// getOrInsertFunction - Look up the specified function in the module symbol
138
// table.  If it does not exist, add a prototype for the function and return
139
// it.  This is nice because it allows most passes to get away with not handling
140
// the symbol table directly for this common task.
141
//
142
Constant *Module::getOrInsertFunction(StringRef Name, FunctionType *Ty,
143
3.71M
                                      AttributeList AttributeList) {
144
3.71M
  // See if we have a definition for the specified function already.
145
3.71M
  GlobalValue *F = getNamedValue(Name);
146
3.71M
  if (
!F3.71M
) {
147
119k
    // Nope, add it
148
119k
    Function *New = Function::Create(Ty, GlobalVariable::ExternalLinkage, Name);
149
119k
    if (!New->isIntrinsic())       // Intrinsics get attrs set on construction
150
19.1k
      New->setAttributes(AttributeList);
151
119k
    FunctionList.push_back(New);
152
119k
    return New;                    // Return the new prototype.
153
119k
  }
154
3.59M
155
3.59M
  // If the function exists but has the wrong type, return a bitcast to the
156
3.59M
  // right type.
157
3.59M
  
if (3.59M
F->getType() != PointerType::getUnqual(Ty)3.59M
)
158
5
    return ConstantExpr::getBitCast(F, PointerType::getUnqual(Ty));
159
3.59M
160
3.59M
  // Otherwise, we just found the existing function or a prototype.
161
3.59M
  return F;
162
3.59M
}
163
164
Constant *Module::getOrInsertFunction(StringRef Name,
165
3.61M
                                      FunctionType *Ty) {
166
3.61M
  return getOrInsertFunction(Name, Ty, AttributeList());
167
3.61M
}
168
169
// getFunction - Look up the specified function in the module symbol table.
170
// If it does not exist, return null.
171
//
172
76.9M
Function *Module::getFunction(StringRef Name) const {
173
76.9M
  return dyn_cast_or_null<Function>(getNamedValue(Name));
174
76.9M
}
175
176
//===----------------------------------------------------------------------===//
177
// Methods for easy access to the global variables in the module.
178
//
179
180
/// getGlobalVariable - Look up the specified global variable in the module
181
/// symbol table.  If it does not exist, return null.  The type argument
182
/// should be the underlying type of the global, i.e., it should not have
183
/// the top-level PointerType, which represents the address of the global.
184
/// If AllowLocal is set to true, this function will return types that
185
/// have an local. By default, these types are not returned.
186
///
187
GlobalVariable *Module::getGlobalVariable(StringRef Name,
188
225k
                                          bool AllowLocal) const {
189
225k
  if (GlobalVariable *Result =
190
225k
      dyn_cast_or_null<GlobalVariable>(getNamedValue(Name)))
191
22.6k
    
if (22.6k
AllowLocal || 22.6k
!Result->hasLocalLinkage()4.14k
)
192
22.6k
      return Result;
193
203k
  return nullptr;
194
203k
}
195
196
/// getOrInsertGlobal - Look up the specified global in the module symbol table.
197
///   1. If it does not exist, add a declaration of the global and return it.
198
///   2. Else, the global exists but has the wrong type: return the function
199
///      with a constantexpr cast to the right type.
200
///   3. Finally, if the existing global is the correct declaration, return the
201
///      existing global.
202
7.33k
Constant *Module::getOrInsertGlobal(StringRef Name, Type *Ty) {
203
7.33k
  // See if we have a definition for the specified global already.
204
7.33k
  GlobalVariable *GV = dyn_cast_or_null<GlobalVariable>(getNamedValue(Name));
205
7.33k
  if (
!GV7.33k
) {
206
2.86k
    // Nope, add it
207
2.86k
    GlobalVariable *New =
208
2.86k
      new GlobalVariable(*this, Ty, false, GlobalVariable::ExternalLinkage,
209
2.86k
                         nullptr, Name);
210
2.86k
     return New;                    // Return the new declaration.
211
2.86k
  }
212
4.46k
213
4.46k
  // If the variable exists but has the wrong type, return a bitcast to the
214
4.46k
  // right type.
215
4.46k
  Type *GVTy = GV->getType();
216
4.46k
  PointerType *PTy = PointerType::get(Ty, GVTy->getPointerAddressSpace());
217
4.46k
  if (GVTy != PTy)
218
74
    return ConstantExpr::getBitCast(GV, PTy);
219
4.39k
220
4.39k
  // Otherwise, we just found the existing function or a prototype.
221
4.39k
  return GV;
222
4.39k
}
223
224
//===----------------------------------------------------------------------===//
225
// Methods for easy access to the global variables in the module.
226
//
227
228
// getNamedAlias - Look up the specified global in the module symbol table.
229
// If it does not exist, return null.
230
//
231
5
GlobalAlias *Module::getNamedAlias(StringRef Name) const {
232
5
  return dyn_cast_or_null<GlobalAlias>(getNamedValue(Name));
233
5
}
234
235
0
GlobalIFunc *Module::getNamedIFunc(StringRef Name) const {
236
0
  return dyn_cast_or_null<GlobalIFunc>(getNamedValue(Name));
237
0
}
238
239
/// getNamedMetadata - Return the first NamedMDNode in the module with the
240
/// specified name. This method returns null if a NamedMDNode with the
241
/// specified name is not found.
242
4.50M
NamedMDNode *Module::getNamedMetadata(const Twine &Name) const {
243
4.50M
  SmallString<256> NameData;
244
4.50M
  StringRef NameRef = Name.toStringRef(NameData);
245
4.50M
  return static_cast<StringMap<NamedMDNode*> *>(NamedMDSymTab)->lookup(NameRef);
246
4.50M
}
247
248
/// getOrInsertNamedMetadata - Return the first named MDNode in the module
249
/// with the specified name. This method returns a new NamedMDNode if a
250
/// NamedMDNode with the specified name is not found.
251
69.8k
NamedMDNode *Module::getOrInsertNamedMetadata(StringRef Name) {
252
69.8k
  NamedMDNode *&NMD =
253
69.8k
    (*static_cast<StringMap<NamedMDNode *> *>(NamedMDSymTab))[Name];
254
69.8k
  if (
!NMD69.8k
) {
255
52.5k
    NMD = new NamedMDNode(Name);
256
52.5k
    NMD->setParent(this);
257
52.5k
    NamedMDList.push_back(NMD);
258
52.5k
  }
259
69.8k
  return NMD;
260
69.8k
}
261
262
/// eraseNamedMetadata - Remove the given NamedMDNode from this module and
263
/// delete it.
264
142
void Module::eraseNamedMetadata(NamedMDNode *NMD) {
265
142
  static_cast<StringMap<NamedMDNode *> *>(NamedMDSymTab)->erase(NMD->getName());
266
142
  NamedMDList.erase(NMD->getIterator());
267
142
}
268
269
9.52M
bool Module::isValidModFlagBehavior(Metadata *MD, ModFlagBehavior &MFB) {
270
9.52M
  if (ConstantInt *
Behavior9.52M
= mdconst::dyn_extract_or_null<ConstantInt>(MD)) {
271
9.52M
    uint64_t Val = Behavior->getLimitedValue();
272
9.52M
    if (
Val >= ModFlagBehaviorFirstVal && 9.52M
Val <= ModFlagBehaviorLastVal9.52M
) {
273
9.52M
      MFB = static_cast<ModFlagBehavior>(Val);
274
9.52M
      return true;
275
9.52M
    }
276
6
  }
277
6
  return false;
278
6
}
279
280
/// getModuleFlagsMetadata - Returns the module flags in the provided vector.
281
void Module::
282
4.09M
getModuleFlagsMetadata(SmallVectorImpl<ModuleFlagEntry> &Flags) const {
283
4.09M
  const NamedMDNode *ModFlags = getModuleFlagsMetadata();
284
4.09M
  if (
!ModFlags4.09M
)
return419k
;
285
3.67M
286
3.67M
  
for (const MDNode *Flag : ModFlags->operands()) 3.67M
{
287
9.50M
    ModFlagBehavior MFB;
288
9.50M
    if (Flag->getNumOperands() >= 3 &&
289
9.50M
        isValidModFlagBehavior(Flag->getOperand(0), MFB) &&
290
9.50M
        
dyn_cast_or_null<MDString>(Flag->getOperand(1))9.50M
) {
291
9.50M
      // Check the operands of the MDNode before accessing the operands.
292
9.50M
      // The verifier will actually catch these failures.
293
9.50M
      MDString *Key = cast<MDString>(Flag->getOperand(1));
294
9.50M
      Metadata *Val = Flag->getOperand(2);
295
9.50M
      Flags.push_back(ModuleFlagEntry(MFB, Key, Val));
296
9.50M
    }
297
9.50M
  }
298
4.09M
}
299
300
/// Return the corresponding value if Key appears in module flags, otherwise
301
/// return null.
302
4.06M
Metadata *Module::getModuleFlag(StringRef Key) const {
303
4.06M
  SmallVector<Module::ModuleFlagEntry, 8> ModuleFlags;
304
4.06M
  getModuleFlagsMetadata(ModuleFlags);
305
9.45M
  for (const ModuleFlagEntry &MFE : ModuleFlags) {
306
9.45M
    if (Key == MFE.Key->getString())
307
4.03k
      return MFE.Val;
308
4.06M
  }
309
4.06M
  return nullptr;
310
4.06M
}
311
312
/// getModuleFlagsMetadata - Returns the NamedMDNode in the module that
313
/// represents module-level flags. This method returns null if there are no
314
/// module-level flags.
315
4.21M
NamedMDNode *Module::getModuleFlagsMetadata() const {
316
4.21M
  return getNamedMetadata("llvm.module.flags");
317
4.21M
}
318
319
/// getOrInsertModuleFlagsMetadata - Returns the NamedMDNode in the module that
320
/// represents module-level flags. If module-level flags aren't found, it
321
/// creates the named metadata that contains them.
322
30.8k
NamedMDNode *Module::getOrInsertModuleFlagsMetadata() {
323
30.8k
  return getOrInsertNamedMetadata("llvm.module.flags");
324
30.8k
}
325
326
/// addModuleFlag - Add a module-level flag to the module-level flags
327
/// metadata. It will create the module-level flags named metadata if it doesn't
328
/// already exist.
329
void Module::addModuleFlag(ModFlagBehavior Behavior, StringRef Key,
330
30.6k
                           Metadata *Val) {
331
30.6k
  Type *Int32Ty = Type::getInt32Ty(Context);
332
30.6k
  Metadata *Ops[3] = {
333
30.6k
      ConstantAsMetadata::get(ConstantInt::get(Int32Ty, Behavior)),
334
30.6k
      MDString::get(Context, Key), Val};
335
30.6k
  getOrInsertModuleFlagsMetadata()->addOperand(MDNode::get(Context, Ops));
336
30.6k
}
337
void Module::addModuleFlag(ModFlagBehavior Behavior, StringRef Key,
338
29.8k
                           Constant *Val) {
339
29.8k
  addModuleFlag(Behavior, Key, ConstantAsMetadata::get(Val));
340
29.8k
}
341
void Module::addModuleFlag(ModFlagBehavior Behavior, StringRef Key,
342
29.8k
                           uint32_t Val) {
343
29.8k
  Type *Int32Ty = Type::getInt32Ty(Context);
344
29.8k
  addModuleFlag(Behavior, Key, ConstantInt::get(Int32Ty, Val));
345
29.8k
}
346
1
void Module::addModuleFlag(MDNode *Node) {
347
1
  assert(Node->getNumOperands() == 3 &&
348
1
         "Invalid number of operands for module flag!");
349
1
  assert(mdconst::hasa<ConstantInt>(Node->getOperand(0)) &&
350
1
         isa<MDString>(Node->getOperand(1)) &&
351
1
         "Invalid operand types for module flag!");
352
1
  getOrInsertModuleFlagsMetadata()->addOperand(Node);
353
1
}
354
355
15.4k
void Module::setDataLayout(StringRef Desc) {
356
15.4k
  DL.reset(Desc);
357
15.4k
}
358
359
54.2k
void Module::setDataLayout(const DataLayout &Other) { DL = Other; }
360
361
725M
const DataLayout &Module::getDataLayout() const { return DL; }
362
363
3.05k
DICompileUnit *Module::debug_compile_units_iterator::operator*() const {
364
3.05k
  return cast<DICompileUnit>(CUs->getOperand(Idx));
365
3.05k
}
366
4.64k
DICompileUnit *Module::debug_compile_units_iterator::operator->() const {
367
4.64k
  return cast<DICompileUnit>(CUs->getOperand(Idx));
368
4.64k
}
369
370
140k
void Module::debug_compile_units_iterator::SkipNoDebugCUs() {
371
140k
  while (
CUs && 140k
(Idx < CUs->getNumOperands())13.5k
&&
372
4.64k
         ((*this)->getEmissionKind() == DICompileUnit::NoDebug))
373
67
    ++Idx;
374
140k
}
375
376
//===----------------------------------------------------------------------===//
377
// Methods to control the materialization of GlobalValues in the Module.
378
//
379
11.0k
void Module::setMaterializer(GVMaterializer *GVM) {
380
11.0k
  assert(!Materializer &&
381
11.0k
         "Module already has a GVMaterializer.  Call materializeAll"
382
11.0k
         " to clear it out before setting another one.");
383
11.0k
  Materializer.reset(GVM);
384
11.0k
}
385
386
836k
Error Module::materialize(GlobalValue *GV) {
387
836k
  if (!Materializer)
388
835k
    return Error::success();
389
723
390
723
  return Materializer->materialize(GV);
391
723
}
392
393
10.4k
Error Module::materializeAll() {
394
10.4k
  if (!Materializer)
395
38
    return Error::success();
396
10.4k
  std::unique_ptr<GVMaterializer> M = std::move(Materializer);
397
10.4k
  return M->materializeModule();
398
10.4k
}
399
400
895
Error Module::materializeMetadata() {
401
895
  if (!Materializer)
402
414
    return Error::success();
403
481
  return Materializer->materializeMetadata();
404
481
}
405
406
//===----------------------------------------------------------------------===//
407
// Other module related stuff.
408
//
409
410
887
std::vector<StructType *> Module::getIdentifiedStructTypes() const {
411
887
  // If we have a materializer, it is possible that some unread function
412
887
  // uses a type that is currently not visible to a TypeFinder, so ask
413
887
  // the materializer which types it created.
414
887
  if (Materializer)
415
489
    return Materializer->getIdentifiedStructTypes();
416
398
417
398
  std::vector<StructType *> Ret;
418
398
  TypeFinder SrcStructTypes;
419
398
  SrcStructTypes.run(*this, true);
420
398
  Ret.assign(SrcStructTypes.begin(), SrcStructTypes.end());
421
398
  return Ret;
422
398
}
423
424
// dropAllReferences() - This function causes all the subelements to "let go"
425
// of all references that they are maintaining.  This allows one to 'delete' a
426
// whole module at a time, even though there may be circular references... first
427
// all references are dropped, and all use counts go to zero.  Then everything
428
// is deleted for real.  Note that no operations are valid on an object that
429
// has "dropped all references", except operator delete.
430
//
431
36.2k
void Module::dropAllReferences() {
432
36.2k
  for (Function &F : *this)
433
363k
    F.dropAllReferences();
434
36.2k
435
36.2k
  for (GlobalVariable &GV : globals())
436
80.8k
    GV.dropAllReferences();
437
36.2k
438
36.2k
  for (GlobalAlias &GA : aliases())
439
2.06k
    GA.dropAllReferences();
440
36.2k
441
36.2k
  for (GlobalIFunc &GIF : ifuncs())
442
83
    GIF.dropAllReferences();
443
36.2k
}
444
445
823
unsigned Module::getNumberRegisterParameters() const {
446
823
  auto *Val =
447
823
      cast_or_null<ConstantAsMetadata>(getModuleFlag("NumRegisterParameters"));
448
823
  if (!Val)
449
677
    return 0;
450
146
  return cast<ConstantInt>(Val->getValue())->getZExtValue();
451
146
}
452
453
33.1k
unsigned Module::getDwarfVersion() const {
454
33.1k
  auto *Val = cast_or_null<ConstantAsMetadata>(getModuleFlag("Dwarf Version"));
455
33.1k
  if (!Val)
456
31.8k
    return 0;
457
1.25k
  return cast<ConstantInt>(Val->getValue())->getZExtValue();
458
1.25k
}
459
460
33.1k
unsigned Module::getCodeViewFlag() const {
461
33.1k
  auto *Val = cast_or_null<ConstantAsMetadata>(getModuleFlag("CodeView"));
462
33.1k
  if (!Val)
463
33.0k
    return 0;
464
99
  return cast<ConstantInt>(Val->getValue())->getZExtValue();
465
99
}
466
467
16.6k
Comdat *Module::getOrInsertComdat(StringRef Name) {
468
16.6k
  auto &Entry = *ComdatSymTab.insert(std::make_pair(Name, Comdat())).first;
469
16.6k
  Entry.second.Name = &Entry;
470
16.6k
  return &Entry.second;
471
16.6k
}
472
473
65.5k
PICLevel::Level Module::getPICLevel() const {
474
65.5k
  auto *Val = cast_or_null<ConstantAsMetadata>(getModuleFlag("PIC Level"));
475
65.5k
476
65.5k
  if (!Val)
477
65.1k
    return PICLevel::NotPIC;
478
447
479
447
  return static_cast<PICLevel::Level>(
480
447
      cast<ConstantInt>(Val->getValue())->getZExtValue());
481
447
}
482
483
7.44k
void Module::setPICLevel(PICLevel::Level PL) {
484
7.44k
  addModuleFlag(ModFlagBehavior::Max, "PIC Level", PL);
485
7.44k
}
486
487
6.45k
PIELevel::Level Module::getPIELevel() const {
488
6.45k
  auto *Val = cast_or_null<ConstantAsMetadata>(getModuleFlag("PIE Level"));
489
6.45k
490
6.45k
  if (!Val)
491
6.30k
    return PIELevel::Default;
492
153
493
153
  return static_cast<PIELevel::Level>(
494
153
      cast<ConstantInt>(Val->getValue())->getZExtValue());
495
153
}
496
497
13
void Module::setPIELevel(PIELevel::Level PL) {
498
13
  addModuleFlag(ModFlagBehavior::Max, "PIE Level", PL);
499
13
}
500
501
131
void Module::setProfileSummary(Metadata *M) {
502
131
  addModuleFlag(ModFlagBehavior::Error, "ProfileSummary", M);
503
131
}
504
505
3.21M
Metadata *Module::getProfileSummary() {
506
3.21M
  return getModuleFlag("ProfileSummary");
507
3.21M
}
508
509
903
void Module::setOwnedMemoryBuffer(std::unique_ptr<MemoryBuffer> MB) {
510
903
  OwnedMemoryBuffer = std::move(MB);
511
903
}
512
513
GlobalVariable *llvm::collectUsedGlobalVariables(
514
78.1k
    const Module &M, SmallPtrSetImpl<GlobalValue *> &Set, bool CompilerUsed) {
515
78.1k
  const char *Name = CompilerUsed ? 
"llvm.compiler.used"38.3k
:
"llvm.used"39.8k
;
516
78.1k
  GlobalVariable *GV = M.getGlobalVariable(Name);
517
78.1k
  if (
!GV || 78.1k
!GV->hasInitializer()799
)
518
77.3k
    return GV;
519
797
520
797
  const ConstantArray *Init = cast<ConstantArray>(GV->getInitializer());
521
4.16k
  for (Value *Op : Init->operands()) {
522
4.16k
    GlobalValue *G = cast<GlobalValue>(Op->stripPointerCastsNoFollowAliases());
523
4.16k
    Set.insert(G);
524
4.16k
  }
525
78.1k
  return GV;
526
78.1k
}