LLVM  9.0.0svn
ThinLTOBitcodeWriter.cpp
Go to the documentation of this file.
1 //===- ThinLTOBitcodeWriter.cpp - Bitcode writing pass for ThinLTO --------===//
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 
15 #include "llvm/IR/Constants.h"
16 #include "llvm/IR/DebugInfo.h"
17 #include "llvm/IR/Intrinsics.h"
18 #include "llvm/IR/Module.h"
19 #include "llvm/IR/PassManager.h"
21 #include "llvm/Pass.h"
24 #include "llvm/Transforms/IPO.h"
29 using namespace llvm;
30 
31 namespace {
32 
33 // Promote each local-linkage entity defined by ExportM and used by ImportM by
34 // changing visibility and appending the given ModuleId.
35 void promoteInternals(Module &ExportM, Module &ImportM, StringRef ModuleId,
36  SetVector<GlobalValue *> &PromoteExtra) {
38  for (auto &ExportGV : ExportM.global_values()) {
39  if (!ExportGV.hasLocalLinkage())
40  continue;
41 
42  auto Name = ExportGV.getName();
43  GlobalValue *ImportGV = nullptr;
44  if (!PromoteExtra.count(&ExportGV)) {
45  ImportGV = ImportM.getNamedValue(Name);
46  if (!ImportGV)
47  continue;
48  ImportGV->removeDeadConstantUsers();
49  if (ImportGV->use_empty()) {
50  ImportGV->eraseFromParent();
51  continue;
52  }
53  }
54 
55  std::string NewName = (Name + ModuleId).str();
56 
57  if (const auto *C = ExportGV.getComdat())
58  if (C->getName() == Name)
59  RenamedComdats.try_emplace(C, ExportM.getOrInsertComdat(NewName));
60 
61  ExportGV.setName(NewName);
62  ExportGV.setLinkage(GlobalValue::ExternalLinkage);
63  ExportGV.setVisibility(GlobalValue::HiddenVisibility);
64 
65  if (ImportGV) {
66  ImportGV->setName(NewName);
68  }
69  }
70 
71  if (!RenamedComdats.empty())
72  for (auto &GO : ExportM.global_objects())
73  if (auto *C = GO.getComdat()) {
74  auto Replacement = RenamedComdats.find(C);
75  if (Replacement != RenamedComdats.end())
76  GO.setComdat(Replacement->second);
77  }
78 }
79 
80 // Promote all internal (i.e. distinct) type ids used by the module by replacing
81 // them with external type ids formed using the module id.
82 //
83 // Note that this needs to be done before we clone the module because each clone
84 // will receive its own set of distinct metadata nodes.
85 void promoteTypeIds(Module &M, StringRef ModuleId) {
87  auto ExternalizeTypeId = [&](CallInst *CI, unsigned ArgNo) {
88  Metadata *MD =
89  cast<MetadataAsValue>(CI->getArgOperand(ArgNo))->getMetadata();
90 
91  if (isa<MDNode>(MD) && cast<MDNode>(MD)->isDistinct()) {
92  Metadata *&GlobalMD = LocalToGlobal[MD];
93  if (!GlobalMD) {
94  std::string NewName = (Twine(LocalToGlobal.size()) + ModuleId).str();
95  GlobalMD = MDString::get(M.getContext(), NewName);
96  }
97 
98  CI->setArgOperand(ArgNo,
99  MetadataAsValue::get(M.getContext(), GlobalMD));
100  }
101  };
102 
103  if (Function *TypeTestFunc =
104  M.getFunction(Intrinsic::getName(Intrinsic::type_test))) {
105  for (const Use &U : TypeTestFunc->uses()) {
106  auto CI = cast<CallInst>(U.getUser());
107  ExternalizeTypeId(CI, 1);
108  }
109  }
110 
111  if (Function *TypeCheckedLoadFunc =
112  M.getFunction(Intrinsic::getName(Intrinsic::type_checked_load))) {
113  for (const Use &U : TypeCheckedLoadFunc->uses()) {
114  auto CI = cast<CallInst>(U.getUser());
115  ExternalizeTypeId(CI, 2);
116  }
117  }
118 
119  for (GlobalObject &GO : M.global_objects()) {
121  GO.getMetadata(LLVMContext::MD_type, MDs);
122 
123  GO.eraseMetadata(LLVMContext::MD_type);
124  for (auto MD : MDs) {
125  auto I = LocalToGlobal.find(MD->getOperand(1));
126  if (I == LocalToGlobal.end()) {
127  GO.addMetadata(LLVMContext::MD_type, *MD);
128  continue;
129  }
130  GO.addMetadata(
132  *MDNode::get(M.getContext(), {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  F.getAddressSpace(), "", &M);
158  NewF->setVisibility(F.getVisibility());
159  NewF->takeName(&F);
161  F.eraseFromParent();
162  }
163 
164  for (auto I = M.global_begin(), E = M.global_end(); I != E;) {
165  GlobalVariable &GV = *I++;
166  if (GV.isDeclaration() && GV.use_empty()) {
167  GV.eraseFromParent();
168  continue;
169  }
170  }
171 }
172 
173 static void
174 filterModule(Module *M,
175  function_ref<bool(const GlobalValue *)> ShouldKeepDefinition) {
176  std::vector<GlobalValue *> V;
177  for (GlobalValue &GV : M->global_values())
178  if (!ShouldKeepDefinition(&GV))
179  V.push_back(&GV);
180 
181  for (GlobalValue *GV : V)
182  if (!convertToDeclaration(*GV))
183  GV->eraseFromParent();
184 }
185 
186 void forEachVirtualFunction(Constant *C, function_ref<void(Function *)> Fn) {
187  if (auto *F = dyn_cast<Function>(C))
188  return Fn(F);
189  if (isa<GlobalValue>(C))
190  return;
191  for (Value *Op : C->operands())
192  forEachVirtualFunction(cast<Constant>(Op), Fn);
193 }
194 
195 // If it's possible to split M into regular and thin LTO parts, do so and write
196 // a multi-module bitcode file with the two parts to OS. Otherwise, write only a
197 // regular LTO bitcode file to OS.
198 void splitAndWriteThinLTOBitcode(
199  raw_ostream &OS, raw_ostream *ThinLinkOS,
200  function_ref<AAResults &(Function &)> AARGetter, Module &M) {
201  std::string ModuleId = getUniqueModuleId(&M);
202  if (ModuleId.empty()) {
203  // We couldn't generate a module ID for this module, write it out as a
204  // regular LTO module with an index for summary-based dead stripping.
205  ProfileSummaryInfo PSI(M);
206  M.addModuleFlag(Module::Error, "ThinLTO", uint32_t(0));
208  WriteBitcodeToFile(M, OS, /*ShouldPreserveUseListOrder=*/false, &Index);
209 
210  if (ThinLinkOS)
211  // We don't have a ThinLTO part, but still write the module to the
212  // ThinLinkOS if requested so that the expected output file is produced.
213  WriteBitcodeToFile(M, *ThinLinkOS, /*ShouldPreserveUseListOrder=*/false,
214  &Index);
215 
216  return;
217  }
218 
219  promoteTypeIds(M, ModuleId);
220 
221  // Returns whether a global has attached type metadata. Such globals may
222  // participate in CFI or whole-program devirtualization, so they need to
223  // appear in the merged module instead of the thin LTO module.
224  auto HasTypeMetadata = [](const GlobalObject *GO) {
225  return GO->hasMetadata(LLVMContext::MD_type);
226  };
227 
228  // Collect the set of virtual functions that are eligible for virtual constant
229  // propagation. Each eligible function must not access memory, must return
230  // an integer of width <=64 bits, must take at least one argument, must not
231  // use its first argument (assumed to be "this") and all arguments other than
232  // the first one must be of <=64 bit integer type.
233  //
234  // Note that we test whether this copy of the function is readnone, rather
235  // than testing function attributes, which must hold for any copy of the
236  // function, even a less optimized version substituted at link time. This is
237  // sound because the virtual constant propagation optimizations effectively
238  // inline all implementations of the virtual function into each call site,
239  // rather than using function attributes to perform local optimization.
240  DenseSet<const Function *> EligibleVirtualFns;
241  // If any member of a comdat lives in MergedM, put all members of that
242  // comdat in MergedM to keep the comdat together.
243  DenseSet<const Comdat *> MergedMComdats;
244  for (GlobalVariable &GV : M.globals())
245  if (HasTypeMetadata(&GV)) {
246  if (const auto *C = GV.getComdat())
247  MergedMComdats.insert(C);
248  forEachVirtualFunction(GV.getInitializer(), [&](Function *F) {
249  auto *RT = dyn_cast<IntegerType>(F->getReturnType());
250  if (!RT || RT->getBitWidth() > 64 || F->arg_empty() ||
251  !F->arg_begin()->use_empty())
252  return;
253  for (auto &Arg : make_range(std::next(F->arg_begin()), F->arg_end())) {
254  auto *ArgT = dyn_cast<IntegerType>(Arg.getType());
255  if (!ArgT || ArgT->getBitWidth() > 64)
256  return;
257  }
258  if (!F->isDeclaration() &&
259  computeFunctionBodyMemoryAccess(*F, AARGetter(*F)) == MAK_ReadNone)
260  EligibleVirtualFns.insert(F);
261  });
262  }
263 
264  ValueToValueMapTy VMap;
265  std::unique_ptr<Module> MergedM(
266  CloneModule(M, VMap, [&](const GlobalValue *GV) -> bool {
267  if (const auto *C = GV->getComdat())
268  if (MergedMComdats.count(C))
269  return true;
270  if (auto *F = dyn_cast<Function>(GV))
271  return EligibleVirtualFns.count(F);
272  if (auto *GVar = dyn_cast_or_null<GlobalVariable>(GV->getBaseObject()))
273  return HasTypeMetadata(GVar);
274  return false;
275  }));
276  StripDebugInfo(*MergedM);
277  MergedM->setModuleInlineAsm("");
278 
279  for (Function &F : *MergedM)
280  if (!F.isDeclaration()) {
281  // Reset the linkage of all functions eligible for virtual constant
282  // propagation. The canonical definitions live in the thin LTO module so
283  // that they can be imported.
285  F.setComdat(nullptr);
286  }
287 
288  SetVector<GlobalValue *> CfiFunctions;
289  for (auto &F : M)
290  if ((!F.hasLocalLinkage() || F.hasAddressTaken()) && HasTypeMetadata(&F))
291  CfiFunctions.insert(&F);
292 
293  // Remove all globals with type metadata, globals with comdats that live in
294  // MergedM, and aliases pointing to such globals from the thin LTO module.
295  filterModule(&M, [&](const GlobalValue *GV) {
296  if (auto *GVar = dyn_cast_or_null<GlobalVariable>(GV->getBaseObject()))
297  if (HasTypeMetadata(GVar))
298  return false;
299  if (const auto *C = GV->getComdat())
300  if (MergedMComdats.count(C))
301  return false;
302  return true;
303  });
304 
305  promoteInternals(*MergedM, M, ModuleId, CfiFunctions);
306  promoteInternals(M, *MergedM, ModuleId, CfiFunctions);
307 
308  auto &Ctx = MergedM->getContext();
309  SmallVector<MDNode *, 8> CfiFunctionMDs;
310  for (auto V : CfiFunctions) {
311  Function &F = *cast<Function>(V);
314 
316  Elts.push_back(MDString::get(Ctx, F.getName()));
317  CfiFunctionLinkage Linkage;
318  if (!F.isDeclarationForLinker())
319  Linkage = CFL_Definition;
320  else if (F.isWeakForLinker())
321  Linkage = CFL_WeakDeclaration;
322  else
323  Linkage = CFL_Declaration;
325  llvm::ConstantInt::get(Type::getInt8Ty(Ctx), Linkage)));
326  for (auto Type : Types)
327  Elts.push_back(Type);
328  CfiFunctionMDs.push_back(MDTuple::get(Ctx, Elts));
329  }
330 
331  if(!CfiFunctionMDs.empty()) {
332  NamedMDNode *NMD = MergedM->getOrInsertNamedMetadata("cfi.functions");
333  for (auto MD : CfiFunctionMDs)
334  NMD->addOperand(MD);
335  }
336 
337  SmallVector<MDNode *, 8> FunctionAliases;
338  for (auto &A : M.aliases()) {
339  if (!isa<Function>(A.getAliasee()))
340  continue;
341 
342  auto *F = cast<Function>(A.getAliasee());
343 
344  Metadata *Elts[] = {
345  MDString::get(Ctx, A.getName()),
346  MDString::get(Ctx, F->getName()),
348  ConstantInt::get(Type::getInt8Ty(Ctx), A.getVisibility())),
350  ConstantInt::get(Type::getInt8Ty(Ctx), A.isWeakForLinker())),
351  };
352 
353  FunctionAliases.push_back(MDTuple::get(Ctx, Elts));
354  }
355 
356  if (!FunctionAliases.empty()) {
357  NamedMDNode *NMD = MergedM->getOrInsertNamedMetadata("aliases");
358  for (auto MD : FunctionAliases)
359  NMD->addOperand(MD);
360  }
361 
362  SmallVector<MDNode *, 8> Symvers;
364  Function *F = M.getFunction(Name);
365  if (!F || F->use_empty())
366  return;
367 
368  Symvers.push_back(MDTuple::get(
369  Ctx, {MDString::get(Ctx, Name), MDString::get(Ctx, Alias)}));
370  });
371 
372  if (!Symvers.empty()) {
373  NamedMDNode *NMD = MergedM->getOrInsertNamedMetadata("symvers");
374  for (auto MD : Symvers)
375  NMD->addOperand(MD);
376  }
377 
378  simplifyExternals(*MergedM);
379 
380  // FIXME: Try to re-use BSI and PFI from the original module here.
381  ProfileSummaryInfo PSI(M);
382  ModuleSummaryIndex Index = buildModuleSummaryIndex(M, nullptr, &PSI);
383 
384  // Mark the merged module as requiring full LTO. We still want an index for
385  // it though, so that it can participate in summary-based dead stripping.
386  MergedM->addModuleFlag(Module::Error, "ThinLTO", uint32_t(0));
387  ModuleSummaryIndex MergedMIndex =
388  buildModuleSummaryIndex(*MergedM, nullptr, &PSI);
389 
390  SmallVector<char, 0> Buffer;
391 
392  BitcodeWriter W(Buffer);
393  // Save the module hash produced for the full bitcode, which will
394  // be used in the backends, and use that in the minimized bitcode
395  // produced for the full link.
396  ModuleHash ModHash = {{0}};
397  W.writeModule(M, /*ShouldPreserveUseListOrder=*/false, &Index,
398  /*GenerateHash=*/true, &ModHash);
399  W.writeModule(*MergedM, /*ShouldPreserveUseListOrder=*/false, &MergedMIndex);
400  W.writeSymtab();
401  W.writeStrtab();
402  OS << Buffer;
403 
404  // If a minimized bitcode module was requested for the thin link, only
405  // the information that is needed by thin link will be written in the
406  // given OS (the merged module will be written as usual).
407  if (ThinLinkOS) {
408  Buffer.clear();
409  BitcodeWriter W2(Buffer);
410  StripDebugInfo(M);
411  W2.writeThinLinkBitcode(M, Index, ModHash);
412  W2.writeModule(*MergedM, /*ShouldPreserveUseListOrder=*/false,
413  &MergedMIndex);
414  W2.writeSymtab();
415  W2.writeStrtab();
416  *ThinLinkOS << Buffer;
417  }
418 }
419 
420 // Returns whether this module needs to be split because splitting is
421 // enabled and it uses type metadata.
422 bool requiresSplit(Module &M) {
423  // First check if the LTO Unit splitting has been enabled.
424  bool EnableSplitLTOUnit = false;
425  if (auto *MD = mdconst::extract_or_null<ConstantInt>(
426  M.getModuleFlag("EnableSplitLTOUnit")))
427  EnableSplitLTOUnit = MD->getZExtValue();
428  if (!EnableSplitLTOUnit)
429  return false;
430 
431  // Module only needs to be split if it contains type metadata.
432  for (auto &GO : M.global_objects()) {
433  if (GO.hasMetadata(LLVMContext::MD_type))
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  // Split module if splitting is enabled and it contains any type metadata.
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:242
const Function & getFunction() const
Definition: Function.h:133
bool isDeclarationForLinker() const
Definition: GlobalValue.h:533
uint64_t CallInst * C
ModulePass * createWriteThinLTOBitcodePass(raw_ostream &Str, raw_ostream *ThinLinkOS=nullptr)
Write ThinLTO-ready bitcode to Str.
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata *> MDs)
Definition: Metadata.h:1132
iterator_range< use_iterator > uses()
Definition: Value.h:354
bool hasLocalLinkage() const
Definition: GlobalValue.h:445
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:776
const Constant * getInitializer() const
getInitializer - Return the initializer for this global variable.
This class represents lattice values for constants.
Definition: AllocatorList.h:23
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:65
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
static MDString * get(LLVMContext &Context, StringRef Str)
Definition: Metadata.cpp:453
This is the interface to build a ModuleSummaryIndex for a module.
LLVM_NODISCARD bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
Definition: StringRef.h:256
Implements a dense probed hash-table based set.
Definition: DenseSet.h:249
Available for inspection, not emission.
Definition: GlobalValue.h:49
Analysis providing profile information.
void addOperand(MDNode *M)
Definition: Metadata.cpp:1086
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.
bool convertToDeclaration(GlobalValue &GV)
Converts value GV to declaration, or replaces with a declaration if it is an alias.
An efficient, type-erasing, non-owning reference to a callable.
Definition: STLExtras.h:116
CfiFunctionLinkage
The type of CFI jumptable needed for a function.
Externally visible function.
Definition: GlobalValue.h:48
arg_iterator arg_end()
Definition: Function.h:696
void setArgOperand(unsigned i, Value *v)
Definition: InstrTypes.h:1246
F(f)
block Block Frequency true
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.
iterator_range< global_object_iterator > global_objects()
Definition: Module.h:662
Value * getArgOperand(unsigned i) const
Definition: InstrTypes.h:1241
AnalysisUsage & addRequired()
#define INITIALIZE_PASS_DEPENDENCY(depName)
Definition: PassSupport.h:50
A tuple of MDNodes.
Definition: Metadata.h:1325
StringRef getName(ID id)
Return the LLVM name for an intrinsic, such as "llvm.ppc.altivec.lvx".
Definition: Function.cpp:638
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:80
LLVMContext & getContext() const
Get the global data context.
Definition: Module.h:244
A Use represents the edge between a Value definition and its users.
Definition: Use.h:55
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:1440
std::array< uint32_t, 5 > ModuleHash
160 bits SHA1
void setName(const Twine &Name)
Change the name of the value.
Definition: Value.cpp:285
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...
global_iterator global_begin()
Definition: Module.h:581
Class to represent function types.
Definition: DerivedTypes.h:103
bool insert(const value_type &X)
Insert a new element into the SetVector.
Definition: SetVector.h:141
bool arg_empty() const
Definition: Function.h:715
void setComdat(Comdat *C)
Definition: GlobalObject.h:102
bool StripDebugInfo(Module &M)
Strip debug info in the module if it exists.
Definition: DebugInfo.cpp:350
GlobalValue * getNamedValue(StringRef Name) const
Return the global value in the module with the specified name, of arbitrary type. ...
Definition: Module.cpp:113
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
Definition: Value.cpp:429
void takeName(Value *V)
Transfer the name from V to this value.
Definition: Value.cpp:291
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:409
size_type count(const key_type &key) const
Count the number of elements of a given key in the SetVector.
Definition: SetVector.h:210
void removeDeadConstantUsers() const
If there are any dead constant users dangling off of this constant, remove them.
Definition: Constants.cpp:546
static bool isWeakForLinker(LinkageTypes Linkage)
Whether the definition of this global may be replaced at link time.
Definition: GlobalValue.h:379
static MetadataAsValue * get(LLVMContext &Context, Metadata *MD)
Definition: Metadata.cpp:105
static Constant * getBitCast(Constant *C, Type *Ty, bool OnlyIfReduced=false)
Definition: Constants.cpp:1782
std::unique_ptr< Module > CloneModule(const Module &M)
Return an exact copy of the specified module.
Definition: CloneModule.cpp:34
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata *> MDs)
Definition: Metadata.h:1165
Type * getReturnType() const
Returns the type of the ret val.
Definition: Function.h:168
static Function * Create(FunctionType *Ty, LinkageTypes Linkage, unsigned AddrSpace, const Twine &N="", Module *M=nullptr)
Definition: Function.h:135
static void CollectAsmSymvers(const Module &M, function_ref< void(StringRef, StringRef)> AsmSymver)
Parse inline ASM and collect the symvers directives that are defined in the current module...
Emits an error if two values disagree, otherwise the resulting value is that of the operands...
Definition: Module.h:116
A set of analyses that are preserved following a run of a transformation pass.
Definition: PassManager.h:153
VisibilityTypes getVisibility() const
Definition: GlobalValue.h:236
write thinlto Write ThinLTO Bitcode
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:45
Metadata * getModuleFlag(StringRef Key) const
Return the corresponding value if Key appears in module flags, otherwise return null.
Definition: Module.cpp:310
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This is an important base class in LLVM.
Definition: Constant.h:41
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 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.
void eraseFromParent()
eraseFromParent - This method unlinks &#39;this&#39; from the containing module and deletes it...
Definition: Globals.cpp:380
Represent the analysis usage information of a pass.
static Type * getVoidTy(LLVMContext &C)
Definition: Type.cpp:160
void addModuleFlag(ModFlagBehavior Behavior, StringRef Key, Metadata *Val)
Add a module-level flag to the module-level flags metadata.
Definition: Module.cpp:337
unsigned getAddressSpace() const
Definition: Globals.cpp:111
amdgpu Simplify well known AMD library false FunctionCallee Value * Arg
static FunctionType * get(Type *Result, ArrayRef< Type *> Params, bool isVarArg)
This static method is the primary way of constructing a FunctionType.
Definition: Type.cpp:296
op_range operands()
Definition: User.h:237
arg_iterator arg_begin()
Definition: Function.h:687
Class to represent integer types.
Definition: DerivedTypes.h:40
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...
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:482
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:583
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
void initializeWriteThinLTOBitcodePass(PassRegistry &)
This is a &#39;vector&#39; (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:837
Module.h This file contains the declarations for the Module class.
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:631
void setLinkage(LinkageTypes LT)
Definition: GlobalValue.h:454
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:174
FunctionType * getFunctionType() const
Returns the FunctionType for me.
Definition: Function.h:163
const Comdat * getComdat() const
Definition: Globals.cpp:171
void setPreservesAll()
Set by analyses that do not transform their input at all.
const Comdat * getComdat() const
Definition: GlobalObject.h:100
void eraseFromParent()
This method unlinks &#39;this&#39; from the containing module and deletes it.
Definition: Globals.cpp:85
iterator end()
Definition: Module.h:600
LLVM_NODISCARD bool empty() const
Definition: SmallVector.h:55
StringRef getName() const
Return a constant reference to the value&#39;s name.
Definition: Value.cpp:214
#define I(x, y, z)
Definition: MD5.cpp:58
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
Definition: Pass.h:224
iterator begin()
Definition: Module.h:598
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:332
void eraseFromParent()
eraseFromParent - This method unlinks &#39;this&#39; from the containing module and deletes it...
Definition: Function.cpp:226
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:282
bool isDeclaration() const
Return true if the primary definition of this global value is outside of the current translation unit...
Definition: Globals.cpp:227
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:1340
LLVM Value Representation.
Definition: Value.h:72
A vector that has set insertion semantics.
Definition: SetVector.h:40
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:45
iterator_range< global_iterator > globals()
Definition: Module.h:587
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:48
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.
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:688
Root of the metadata hierarchy.
Definition: Metadata.h:57
static IntegerType * getInt8Ty(LLVMContext &C)
Definition: Type.cpp:173
bool use_empty() const
Definition: Value.h:322
PointerType * getType() const
Global values are always pointers.
Definition: GlobalValue.h:277
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:1044