LLVM  7.0.0svn
ThinLTOBitcodeWriter.cpp
Go to the documentation of this file.
1 //===- ThinLTOBitcodeWriter.cpp - Bitcode writing pass for ThinLTO --------===//
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 
16 #include "llvm/IR/Constants.h"
17 #include "llvm/IR/DebugInfo.h"
18 #include "llvm/IR/Intrinsics.h"
19 #include "llvm/IR/Module.h"
20 #include "llvm/IR/PassManager.h"
21 #include "llvm/Pass.h"
24 #include "llvm/Transforms/IPO.h"
28 using namespace llvm;
29 
30 namespace {
31 
32 // Promote each local-linkage entity defined by ExportM and used by ImportM by
33 // changing visibility and appending the given ModuleId.
34 void promoteInternals(Module &ExportM, Module &ImportM, StringRef ModuleId,
35  SetVector<GlobalValue *> &PromoteExtra) {
37  for (auto &ExportGV : ExportM.global_values()) {
38  if (!ExportGV.hasLocalLinkage())
39  continue;
40 
41  auto Name = ExportGV.getName();
42  GlobalValue *ImportGV = nullptr;
43  if (!PromoteExtra.count(&ExportGV)) {
44  ImportGV = ImportM.getNamedValue(Name);
45  if (!ImportGV)
46  continue;
47  ImportGV->removeDeadConstantUsers();
48  if (ImportGV->use_empty()) {
49  ImportGV->eraseFromParent();
50  continue;
51  }
52  }
53 
54  std::string NewName = (Name + ModuleId).str();
55 
56  if (const auto *C = ExportGV.getComdat())
57  if (C->getName() == Name)
58  RenamedComdats.try_emplace(C, ExportM.getOrInsertComdat(NewName));
59 
60  ExportGV.setName(NewName);
61  ExportGV.setLinkage(GlobalValue::ExternalLinkage);
62  ExportGV.setVisibility(GlobalValue::HiddenVisibility);
63 
64  if (ImportGV) {
65  ImportGV->setName(NewName);
67  }
68  }
69 
70  if (!RenamedComdats.empty())
71  for (auto &GO : ExportM.global_objects())
72  if (auto *C = GO.getComdat()) {
73  auto Replacement = RenamedComdats.find(C);
74  if (Replacement != RenamedComdats.end())
75  GO.setComdat(Replacement->second);
76  }
77 }
78 
79 // Promote all internal (i.e. distinct) type ids used by the module by replacing
80 // them with external type ids formed using the module id.
81 //
82 // Note that this needs to be done before we clone the module because each clone
83 // will receive its own set of distinct metadata nodes.
84 void promoteTypeIds(Module &M, StringRef ModuleId) {
86  auto ExternalizeTypeId = [&](CallInst *CI, unsigned ArgNo) {
87  Metadata *MD =
88  cast<MetadataAsValue>(CI->getArgOperand(ArgNo))->getMetadata();
89 
90  if (isa<MDNode>(MD) && cast<MDNode>(MD)->isDistinct()) {
91  Metadata *&GlobalMD = LocalToGlobal[MD];
92  if (!GlobalMD) {
93  std::string NewName = (Twine(LocalToGlobal.size()) + ModuleId).str();
94  GlobalMD = MDString::get(M.getContext(), NewName);
95  }
96 
97  CI->setArgOperand(ArgNo,
98  MetadataAsValue::get(M.getContext(), GlobalMD));
99  }
100  };
101 
102  if (Function *TypeTestFunc =
103  M.getFunction(Intrinsic::getName(Intrinsic::type_test))) {
104  for (const Use &U : TypeTestFunc->uses()) {
105  auto CI = cast<CallInst>(U.getUser());
106  ExternalizeTypeId(CI, 1);
107  }
108  }
109 
110  if (Function *TypeCheckedLoadFunc =
111  M.getFunction(Intrinsic::getName(Intrinsic::type_checked_load))) {
112  for (const Use &U : TypeCheckedLoadFunc->uses()) {
113  auto CI = cast<CallInst>(U.getUser());
114  ExternalizeTypeId(CI, 2);
115  }
116  }
117 
118  for (GlobalObject &GO : M.global_objects()) {
120  GO.getMetadata(LLVMContext::MD_type, MDs);
121 
122  GO.eraseMetadata(LLVMContext::MD_type);
123  for (auto MD : MDs) {
124  auto I = LocalToGlobal.find(MD->getOperand(1));
125  if (I == LocalToGlobal.end()) {
126  GO.addMetadata(LLVMContext::MD_type, *MD);
127  continue;
128  }
129  GO.addMetadata(
131  *MDNode::get(M.getContext(),
132  ArrayRef<Metadata *>{MD->getOperand(0), I->second}));
133  }
134  }
135 }
136 
137 // Drop unused globals, and drop type information from function declarations.
138 // FIXME: If we made functions typeless then there would be no need to do this.
139 void simplifyExternals(Module &M) {
140  FunctionType *EmptyFT =
142 
143  for (auto I = M.begin(), E = M.end(); I != E;) {
144  Function &F = *I++;
145  if (F.isDeclaration() && F.use_empty()) {
146  F.eraseFromParent();
147  continue;
148  }
149 
150  if (!F.isDeclaration() || F.getFunctionType() == EmptyFT ||
151  // Changing the type of an intrinsic may invalidate the IR.
152  F.getName().startswith("llvm."))
153  continue;
154 
155  Function *NewF =
157  NewF->setVisibility(F.getVisibility());
158  NewF->takeName(&F);
160  F.eraseFromParent();
161  }
162 
163  for (auto I = M.global_begin(), E = M.global_end(); I != E;) {
164  GlobalVariable &GV = *I++;
165  if (GV.isDeclaration() && GV.use_empty()) {
166  GV.eraseFromParent();
167  continue;
168  }
169  }
170 }
171 
172 void filterModule(
173  Module *M, function_ref<bool(const GlobalValue *)> ShouldKeepDefinition) {
174  for (Module::alias_iterator I = M->alias_begin(), E = M->alias_end();
175  I != E;) {
176  GlobalAlias *GA = &*I++;
177  if (ShouldKeepDefinition(GA))
178  continue;
179 
180  GlobalObject *GO;
181  if (GA->getValueType()->isFunctionTy())
182  GO = Function::Create(cast<FunctionType>(GA->getValueType()),
184  else
185  GO = new GlobalVariable(
186  *M, GA->getValueType(), false, GlobalValue::ExternalLinkage,
187  nullptr, "", nullptr,
188  GA->getThreadLocalMode(), GA->getType()->getAddressSpace());
189  GO->takeName(GA);
190  GA->replaceAllUsesWith(GO);
191  GA->eraseFromParent();
192  }
193 
194  for (Function &F : *M) {
195  if (ShouldKeepDefinition(&F))
196  continue;
197 
198  F.deleteBody();
199  F.setComdat(nullptr);
200  F.clearMetadata();
201  }
202 
203  for (GlobalVariable &GV : M->globals()) {
204  if (ShouldKeepDefinition(&GV))
205  continue;
206 
207  GV.setInitializer(nullptr);
209  GV.setComdat(nullptr);
210  GV.clearMetadata();
211  }
212 }
213 
214 void forEachVirtualFunction(Constant *C, function_ref<void(Function *)> Fn) {
215  if (auto *F = dyn_cast<Function>(C))
216  return Fn(F);
217  if (isa<GlobalValue>(C))
218  return;
219  for (Value *Op : C->operands())
220  forEachVirtualFunction(cast<Constant>(Op), Fn);
221 }
222 
223 // If it's possible to split M into regular and thin LTO parts, do so and write
224 // a multi-module bitcode file with the two parts to OS. Otherwise, write only a
225 // regular LTO bitcode file to OS.
226 void splitAndWriteThinLTOBitcode(
227  raw_ostream &OS, raw_ostream *ThinLinkOS,
228  function_ref<AAResults &(Function &)> AARGetter, Module &M) {
229  std::string ModuleId = getUniqueModuleId(&M);
230  if (ModuleId.empty()) {
231  // We couldn't generate a module ID for this module, just write it out as a
232  // regular LTO module.
233  WriteBitcodeToFile(&M, OS);
234  if (ThinLinkOS)
235  // We don't have a ThinLTO part, but still write the module to the
236  // ThinLinkOS if requested so that the expected output file is produced.
237  WriteBitcodeToFile(&M, *ThinLinkOS);
238  return;
239  }
240 
241  promoteTypeIds(M, ModuleId);
242 
243  // Returns whether a global has attached type metadata. Such globals may
244  // participate in CFI or whole-program devirtualization, so they need to
245  // appear in the merged module instead of the thin LTO module.
246  auto HasTypeMetadata = [&](const GlobalObject *GO) {
249  return !MDs.empty();
250  };
251 
252  // Collect the set of virtual functions that are eligible for virtual constant
253  // propagation. Each eligible function must not access memory, must return
254  // an integer of width <=64 bits, must take at least one argument, must not
255  // use its first argument (assumed to be "this") and all arguments other than
256  // the first one must be of <=64 bit integer type.
257  //
258  // Note that we test whether this copy of the function is readnone, rather
259  // than testing function attributes, which must hold for any copy of the
260  // function, even a less optimized version substituted at link time. This is
261  // sound because the virtual constant propagation optimizations effectively
262  // inline all implementations of the virtual function into each call site,
263  // rather than using function attributes to perform local optimization.
264  std::set<const Function *> EligibleVirtualFns;
265  // If any member of a comdat lives in MergedM, put all members of that
266  // comdat in MergedM to keep the comdat together.
267  DenseSet<const Comdat *> MergedMComdats;
268  for (GlobalVariable &GV : M.globals())
269  if (HasTypeMetadata(&GV)) {
270  if (const auto *C = GV.getComdat())
271  MergedMComdats.insert(C);
272  forEachVirtualFunction(GV.getInitializer(), [&](Function *F) {
273  auto *RT = dyn_cast<IntegerType>(F->getReturnType());
274  if (!RT || RT->getBitWidth() > 64 || F->arg_empty() ||
275  !F->arg_begin()->use_empty())
276  return;
277  for (auto &Arg : make_range(std::next(F->arg_begin()), F->arg_end())) {
278  auto *ArgT = dyn_cast<IntegerType>(Arg.getType());
279  if (!ArgT || ArgT->getBitWidth() > 64)
280  return;
281  }
282  if (!F->isDeclaration() &&
283  computeFunctionBodyMemoryAccess(*F, AARGetter(*F)) == MAK_ReadNone)
284  EligibleVirtualFns.insert(F);
285  });
286  }
287 
288  ValueToValueMapTy VMap;
289  std::unique_ptr<Module> MergedM(
290  CloneModule(&M, VMap, [&](const GlobalValue *GV) -> bool {
291  if (const auto *C = GV->getComdat())
292  if (MergedMComdats.count(C))
293  return true;
294  if (auto *F = dyn_cast<Function>(GV))
295  return EligibleVirtualFns.count(F);
296  if (auto *GVar = dyn_cast_or_null<GlobalVariable>(GV->getBaseObject()))
297  return HasTypeMetadata(GVar);
298  return false;
299  }));
300  StripDebugInfo(*MergedM);
301 
302  for (Function &F : *MergedM)
303  if (!F.isDeclaration()) {
304  // Reset the linkage of all functions eligible for virtual constant
305  // propagation. The canonical definitions live in the thin LTO module so
306  // that they can be imported.
308  F.setComdat(nullptr);
309  }
310 
311  SetVector<GlobalValue *> CfiFunctions;
312  for (auto &F : M)
313  if ((!F.hasLocalLinkage() || F.hasAddressTaken()) && HasTypeMetadata(&F))
314  CfiFunctions.insert(&F);
315 
316  // Remove all globals with type metadata, globals with comdats that live in
317  // MergedM, and aliases pointing to such globals from the thin LTO module.
318  filterModule(&M, [&](const GlobalValue *GV) {
319  if (auto *GVar = dyn_cast_or_null<GlobalVariable>(GV->getBaseObject()))
320  if (HasTypeMetadata(GVar))
321  return false;
322  if (const auto *C = GV->getComdat())
323  if (MergedMComdats.count(C))
324  return false;
325  return true;
326  });
327 
328  promoteInternals(*MergedM, M, ModuleId, CfiFunctions);
329  promoteInternals(M, *MergedM, ModuleId, CfiFunctions);
330 
331  SmallVector<MDNode *, 8> CfiFunctionMDs;
332  for (auto V : CfiFunctions) {
333  Function &F = *cast<Function>(V);
336 
337  auto &Ctx = MergedM->getContext();
339  Elts.push_back(MDString::get(Ctx, F.getName()));
340  CfiFunctionLinkage Linkage;
341  if (!F.isDeclarationForLinker())
342  Linkage = CFL_Definition;
343  else if (F.isWeakForLinker())
344  Linkage = CFL_WeakDeclaration;
345  else
346  Linkage = CFL_Declaration;
348  llvm::ConstantInt::get(Type::getInt8Ty(Ctx), Linkage)));
349  for (auto Type : Types)
350  Elts.push_back(Type);
351  CfiFunctionMDs.push_back(MDTuple::get(Ctx, Elts));
352  }
353 
354  if(!CfiFunctionMDs.empty()) {
355  NamedMDNode *NMD = MergedM->getOrInsertNamedMetadata("cfi.functions");
356  for (auto MD : CfiFunctionMDs)
357  NMD->addOperand(MD);
358  }
359 
360  SmallVector<MDNode *, 8> FunctionAliases;
361  for (auto &A : M.aliases()) {
362  if (!isa<Function>(A.getAliasee()))
363  continue;
364 
365  auto *F = cast<Function>(A.getAliasee());
366  auto &Ctx = MergedM->getContext();
368 
369  Elts.push_back(MDString::get(Ctx, A.getName()));
370  Elts.push_back(MDString::get(Ctx, F->getName()));
372  llvm::ConstantInt::get(Type::getInt8Ty(Ctx), A.getVisibility())));
374  llvm::ConstantInt::get(Type::getInt8Ty(Ctx), A.isWeakForLinker())));
375 
376  FunctionAliases.push_back(MDTuple::get(Ctx, Elts));
377  }
378 
379  if (!FunctionAliases.empty()) {
380  NamedMDNode *NMD = MergedM->getOrInsertNamedMetadata("aliases");
381  for (auto MD : FunctionAliases)
382  NMD->addOperand(MD);
383  }
384 
385  simplifyExternals(*MergedM);
386 
387  // FIXME: Try to re-use BSI and PFI from the original module here.
388  ProfileSummaryInfo PSI(M);
389  ModuleSummaryIndex Index = buildModuleSummaryIndex(M, nullptr, &PSI);
390 
391  // Mark the merged module as requiring full LTO. We still want an index for
392  // it though, so that it can participate in summary-based dead stripping.
393  MergedM->addModuleFlag(Module::Error, "ThinLTO", uint32_t(0));
394  ModuleSummaryIndex MergedMIndex =
395  buildModuleSummaryIndex(*MergedM, nullptr, &PSI);
396 
397  SmallVector<char, 0> Buffer;
398 
399  BitcodeWriter W(Buffer);
400  // Save the module hash produced for the full bitcode, which will
401  // be used in the backends, and use that in the minimized bitcode
402  // produced for the full link.
403  ModuleHash ModHash = {{0}};
404  W.writeModule(&M, /*ShouldPreserveUseListOrder=*/false, &Index,
405  /*GenerateHash=*/true, &ModHash);
406  W.writeModule(MergedM.get(), /*ShouldPreserveUseListOrder=*/false,
407  &MergedMIndex);
408  W.writeSymtab();
409  W.writeStrtab();
410  OS << Buffer;
411 
412  // If a minimized bitcode module was requested for the thin link, only
413  // the information that is needed by thin link will be written in the
414  // given OS (the merged module will be written as usual).
415  if (ThinLinkOS) {
416  Buffer.clear();
417  BitcodeWriter W2(Buffer);
418  StripDebugInfo(M);
419  W2.writeThinLinkBitcode(&M, Index, ModHash);
420  W2.writeModule(MergedM.get(), /*ShouldPreserveUseListOrder=*/false,
421  &MergedMIndex);
422  W2.writeSymtab();
423  W2.writeStrtab();
424  *ThinLinkOS << Buffer;
425  }
426 }
427 
428 // Returns whether this module needs to be split because it uses type metadata.
429 bool requiresSplit(Module &M) {
431  for (auto &GO : M.global_objects()) {
433  if (!MDs.empty())
434  return true;
435  }
436 
437  return false;
438 }
439 
440 void writeThinLTOBitcode(raw_ostream &OS, raw_ostream *ThinLinkOS,
441  function_ref<AAResults &(Function &)> AARGetter,
442  Module &M, const ModuleSummaryIndex *Index) {
443  // See if this module has any type metadata. If so, we need to split it.
444  if (requiresSplit(M))
445  return splitAndWriteThinLTOBitcode(OS, ThinLinkOS, AARGetter, M);
446 
447  // Otherwise we can just write it out as a regular module.
448 
449  // Save the module hash produced for the full bitcode, which will
450  // be used in the backends, and use that in the minimized bitcode
451  // produced for the full link.
452  ModuleHash ModHash = {{0}};
453  WriteBitcodeToFile(&M, OS, /*ShouldPreserveUseListOrder=*/false, Index,
454  /*GenerateHash=*/true, &ModHash);
455  // If a minimized bitcode module was requested for the thin link, only
456  // the information that is needed by thin link will be written in the
457  // given OS.
458  if (ThinLinkOS && Index)
459  WriteThinLinkBitcodeToFile(&M, *ThinLinkOS, *Index, ModHash);
460 }
461 
462 class WriteThinLTOBitcode : public ModulePass {
463  raw_ostream &OS; // raw_ostream to print on
464  // The output stream on which to emit a minimized module for use
465  // just in the thin link, if requested.
466  raw_ostream *ThinLinkOS;
467 
468 public:
469  static char ID; // Pass identification, replacement for typeid
470  WriteThinLTOBitcode() : ModulePass(ID), OS(dbgs()), ThinLinkOS(nullptr) {
472  }
473 
474  explicit WriteThinLTOBitcode(raw_ostream &o, raw_ostream *ThinLinkOS)
475  : ModulePass(ID), OS(o), ThinLinkOS(ThinLinkOS) {
477  }
478 
479  StringRef getPassName() const override { return "ThinLTO Bitcode Writer"; }
480 
481  bool runOnModule(Module &M) override {
482  const ModuleSummaryIndex *Index =
483  &(getAnalysis<ModuleSummaryIndexWrapperPass>().getIndex());
484  writeThinLTOBitcode(OS, ThinLinkOS, LegacyAARGetter(*this), M, Index);
485  return true;
486  }
487  void getAnalysisUsage(AnalysisUsage &AU) const override {
488  AU.setPreservesAll();
492  }
493 };
494 } // anonymous namespace
495 
496 char WriteThinLTOBitcode::ID = 0;
497 INITIALIZE_PASS_BEGIN(WriteThinLTOBitcode, "write-thinlto-bitcode",
498  "Write ThinLTO Bitcode", false, true)
502 INITIALIZE_PASS_END(WriteThinLTOBitcode, "write-thinlto-bitcode",
503  "Write ThinLTO Bitcode", false, true)
504 
506  raw_ostream *ThinLinkOS) {
507  return new WriteThinLTOBitcode(Str, ThinLinkOS);
508 }
509 
513  AM.getResult<FunctionAnalysisManagerModuleProxy>(M).getManager();
514  writeThinLTOBitcode(OS, ThinLinkOS,
515  [&FAM](Function &F) -> AAResults & {
516  return FAM.getResult<AAManager>(F);
517  },
519  return PreservedAnalyses::all();
520 }
void setVisibility(VisibilityTypes V)
Definition: GlobalValue.h:232
bool isDeclarationForLinker() const
Definition: GlobalValue.h:519
uint64_t CallInst * C
ModulePass * createWriteThinLTOBitcodePass(raw_ostream &Str, raw_ostream *ThinLinkOS=nullptr)
Write ThinLTO-ready bitcode to Str.
ThreadLocalMode getThreadLocalMode() const
Definition: GlobalValue.h:249
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata *> MDs)
Definition: Metadata.h:1131
iterator_range< use_iterator > uses()
Definition: Value.h:360
bool hasLocalLinkage() const
Definition: GlobalValue.h:430
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
Definition: PassManager.h:687
const Constant * getInitializer() const
getInitializer - Return the initializer for this global variable.
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:63
static MDString * get(LLVMContext &Context, StringRef Str)
Definition: Metadata.cpp:446
This is the interface to build a ModuleSummaryIndex for a module.
Implements a dense probed hash-table based set.
Definition: DenseSet.h:221
Available for inspection, not emission.
Definition: GlobalValue.h:50
Analysis providing profile information.
void addOperand(MDNode *M)
Definition: Metadata.cpp:1079
This class represents a function call, abstracting a target machine&#39;s calling convention.
write thinlto bitcode
An immutable pass that tracks lazily created AssumptionCache objects.
An efficient, type-erasing, non-owning reference to a callable.
Definition: STLExtras.h:89
CfiFunctionLinkage
The type of CFI jumptable needed for a function.
Externally visible function.
Definition: GlobalValue.h:49
arg_iterator arg_end()
Definition: Function.h:658
F(f)
MemoryAccessKind computeFunctionBodyMemoryAccess(Function &F, AAResults &AAR)
Returns the memory access properties of this copy of the function.
Analysis pass to provide the ModuleSummaryIndex object.
ModuleSummaryIndex buildModuleSummaryIndex(const Module &M, std::function< BlockFrequencyInfo *(const Function &F)> GetBFICallback, ProfileSummaryInfo *PSI)
Direct function to compute a ModuleSummaryIndex from a given module.
void eraseFromParent()
eraseFromParent - This method unlinks &#39;this&#39; from the containing module and deletes it...
Definition: Globals.cpp:433
iterator_range< global_object_iterator > global_objects()
Definition: Module.h:636
AnalysisUsage & addRequired()
#define INITIALIZE_PASS_DEPENDENCY(depName)
Definition: PassSupport.h:51
A tuple of MDNodes.
Definition: Metadata.h:1323
StringRef getName(ID id)
Return the LLVM name for an intrinsic, such as "llvm.ppc.altivec.lvx".
Definition: Function.cpp:591
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
void setInitializer(Constant *InitVal)
setInitializer - Sets the initializer for this global variable, removing any existing initializer if ...
Definition: Globals.cpp:340
LLVMContext & getContext() const
Get the global data context.
Definition: Module.h:237
A Use represents the edge between a Value definition and its users.
Definition: Use.h:56
This class is a functor to be used in legacy module or SCC passes for computing AA results for a func...
MDNode * getMetadata(unsigned KindID) const
Get the current metadata attachments for the given kind, if any.
Definition: Metadata.cpp:1431
std::array< uint32_t, 5 > ModuleHash
160 bits SHA1
void setName(const Twine &Name)
Change the name of the value.
Definition: Value.cpp:295
global_iterator global_begin()
Definition: Module.h:555
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
Definition: StringRef.h:267
Class to represent function types.
Definition: DerivedTypes.h:103
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:245
bool insert(const value_type &X)
Insert a new element into the SetVector.
Definition: SetVector.h:142
bool arg_empty() const
Definition: Function.h:677
LLVMContext & getContext() const
Definition: Metadata.h:922
void setComdat(Comdat *C)
Definition: GlobalObject.h:103
bool StripDebugInfo(Module &M)
Strip debug info in the module if it exists.
Definition: DebugInfo.cpp:331
GlobalValue * getNamedValue(StringRef Name) const
Return the global value in the module with the specified name, of arbitrary type. ...
Definition: Module.cpp:112
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:33
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
Definition: Value.cpp:439
void takeName(Value *V)
Transfer the name from V to this value.
Definition: Value.cpp:301
Class to hold module path string table and global value map, and encapsulate methods for operating on...
static ConstantAsMetadata * get(Constant *C)
Definition: Metadata.h:408
size_type count(const key_type &key) const
Count the number of elements of a given key in the SetVector.
Definition: SetVector.h:211
void removeDeadConstantUsers() const
If there are any dead constant users dangling off of this constant, remove them.
Definition: Constants.cpp:474
static bool isWeakForLinker(LinkageTypes Linkage)
Whether the definition of this global may be replaced at link time.
Definition: GlobalValue.h:364
static MetadataAsValue * get(LLVMContext &Context, Metadata *MD)
Definition: Metadata.cpp:106
static Constant * getBitCast(Constant *C, Type *Ty, bool OnlyIfReduced=false)
Definition: Constants.cpp:1677
void WriteBitcodeToFile(const Module *M, raw_ostream &Out, bool ShouldPreserveUseListOrder=false, const ModuleSummaryIndex *Index=nullptr, bool GenerateHash=false, ModuleHash *ModHash=nullptr)
Write the specified module to the specified raw output stream.
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata *> MDs)
Definition: Metadata.h:1164
Type * getReturnType() const
Returns the type of the ret val.
Definition: Function.h:150
Emits an error if two values disagree, otherwise the resulting value is that of the operands...
Definition: Module.h:114
A set of analyses that are preserved following a run of a transformation pass.
Definition: PassManager.h:153
VisibilityTypes getVisibility() const
Definition: GlobalValue.h:226
alias_iterator alias_end()
Definition: Module.h:596
write thinlto Write ThinLTO Bitcode
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:46
void deleteBody()
deleteBody - This method deletes the body of the function, and converts the linkage to external...
Definition: Function.h:587
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This is an important base class in LLVM.
Definition: Constant.h:42
This file contains the declarations for the subclasses of Constant, which represent the different fla...
A manager for alias analyses.
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)
void eraseFromParent()
eraseFromParent - This method unlinks &#39;this&#39; from the containing module and deletes it...
Definition: Globals.cpp:336
Represent the analysis usage information of a pass.
static Type * getVoidTy(LLVMContext &C)
Definition: Type.cpp:161
static FunctionType * get(Type *Result, ArrayRef< Type *> Params, bool isVarArg)
This static method is the primary way of constructing a FunctionType.
Definition: Type.cpp:297
op_range operands()
Definition: User.h:222
unsigned getAddressSpace() const
Return the address space of the Pointer type.
Definition: DerivedTypes.h:495
arg_iterator arg_begin()
Definition: Function.h:649
Class to represent integer types.
Definition: DerivedTypes.h:40
std::unique_ptr< Module > CloneModule(const Module *M)
Return an exact copy of the specified module.
Definition: CloneModule.cpp:35
std::string getUniqueModuleId(Module *M)
Produce a unique identifier for this module by taking the MD5 sum of the names of the module&#39;s strong...
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function. ...
Definition: Function.cpp:194
static void write(bool isBE, void *P, T V)
Comdat * getOrInsertComdat(StringRef Name)
Return the Comdat in the module with the specified name.
Definition: Module.cpp:467
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition: PassManager.h:159
INITIALIZE_PASS_END(RegBankSelect, DEBUG_TYPE, "Assign register bank of generic virtual registers", false, false) RegBankSelect
global_iterator global_end()
Definition: Module.h:557
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
Iterator for intrusive lists based on ilist_node.
void initializeWriteThinLTOBitcodePass(PassRegistry &)
void WriteThinLinkBitcodeToFile(const Module *M, raw_ostream &Out, const ModuleSummaryIndex &Index, const ModuleHash &ModHash)
Write the specified thin link bitcode file (i.e., the minimized bitcode file) to the given raw output...
This is a &#39;vector&#39; (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:862
Module.h This file contains the declarations for the Module class.
alias_iterator alias_begin()
Definition: Module.h:594
static Constant * get(Type *Ty, uint64_t V, bool isSigned=false)
If Ty is a vector type, return a Constant with a splat of the given value.
Definition: Constants.cpp:559
void setLinkage(LinkageTypes LT)
Definition: GlobalValue.h:439
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:132
Function * getFunction(StringRef Name) const
Look up the specified function in the module symbol table.
Definition: Module.cpp:172
FunctionType * getFunctionType() const
Returns the FunctionType for me.
Definition: Function.h:145
const Comdat * getComdat() const
Definition: Globals.cpp:166
void setPreservesAll()
Set by analyses that do not transform their input at all.
amdgpu Simplify well known AMD library false Value Value * Arg
const Comdat * getComdat() const
Definition: GlobalObject.h:101
Basic Alias true
void eraseFromParent()
This method unlinks &#39;this&#39; from the containing module and deletes it.
Definition: Globals.cpp:85
bool isFunctionTy() const
True if this is an instance of FunctionType.
Definition: Type.h:212
iterator end()
Definition: Module.h:574
LLVM_NODISCARD bool empty() const
Definition: SmallVector.h:61
Value * getArgOperand(unsigned i) const
getArgOperand/setArgOperand - Return/set the i-th call argument.
StringRef getName() const
Return a constant reference to the value&#39;s name.
Definition: Value.cpp:224
#define I(x, y, z)
Definition: MD5.cpp:58
void setArgOperand(unsigned i, Value *v)
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
Definition: Pass.h:225
iterator begin()
Definition: Module.h:572
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
Definition: Casting.h:323
Type * getValueType() const
Definition: GlobalValue.h:270
void eraseFromParent()
eraseFromParent - This method unlinks &#39;this&#39; from the containing module and deletes it...
Definition: Function.cpp:202
size_type count(const_arg_type_t< ValueT > V) const
Return 1 if the specified key is in the set, 0 otherwise.
Definition: DenseSet.h:91
Provides passes for computing function attributes based on interprocedural analyses.
const GlobalObject * getBaseObject() const
Definition: Globals.cpp:256
bool isDeclaration() const
Return true if the primary definition of this global value is outside of the current translation unit...
Definition: Globals.cpp:201
bool hasAddressTaken(const User **=nullptr) const
hasAddressTaken - returns true if there are any uses of this function other than direct calls or invo...
Definition: Function.cpp:1213
LLVM Value Representation.
Definition: Value.h:73
A vector that has set insertion semantics.
Definition: SetVector.h:41
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:44
iterator_range< global_iterator > globals()
Definition: Module.h:561
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
This is the interface for LLVM&#39;s primary stateless and local alias analysis.
A container for analyses that lazily runs them and caches their results.
static Function * Create(FunctionType *Ty, LinkageTypes Linkage, const Twine &N="", Module *M=nullptr)
Definition: Function.h:136
This header defines various interfaces for pass management in LLVM.
INITIALIZE_PASS_BEGIN(WriteThinLTOBitcode, "write-thinlto-bitcode", "Write ThinLTO Bitcode", false, true) INITIALIZE_PASS_END(WriteThinLTOBitcode
iterator_range< global_value_iterator > global_values()
Definition: Module.h:662
Root of the metadata hierarchy.
Definition: Metadata.h:58
static IntegerType * getInt8Ty(LLVMContext &C)
Definition: Type.cpp:174
bool use_empty() const
Definition: Value.h:328
PointerType * getType() const
Global values are always pointers.
Definition: GlobalValue.h:268
Legacy wrapper pass to provide the ModuleSummaryIndex object.
An analysis over an "outer" IR unit that provides access to an analysis manager over an "inner" IR un...
Definition: PassManager.h:946