LLVM  12.0.0git
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"
20 #include "llvm/InitializePasses.h"
22 #include "llvm/Pass.h"
25 #include "llvm/Transforms/IPO.h"
31 using namespace llvm;
32 
33 namespace {
34 
35 // Promote each local-linkage entity defined by ExportM and used by ImportM by
36 // changing visibility and appending the given ModuleId.
37 void promoteInternals(Module &ExportM, Module &ImportM, StringRef ModuleId,
38  SetVector<GlobalValue *> &PromoteExtra) {
40  for (auto &ExportGV : ExportM.global_values()) {
41  if (!ExportGV.hasLocalLinkage())
42  continue;
43 
44  auto Name = ExportGV.getName();
45  GlobalValue *ImportGV = nullptr;
46  if (!PromoteExtra.count(&ExportGV)) {
47  ImportGV = ImportM.getNamedValue(Name);
48  if (!ImportGV)
49  continue;
50  ImportGV->removeDeadConstantUsers();
51  if (ImportGV->use_empty()) {
52  ImportGV->eraseFromParent();
53  continue;
54  }
55  }
56 
57  std::string NewName = (Name + ModuleId).str();
58 
59  if (const auto *C = ExportGV.getComdat())
60  if (C->getName() == Name)
61  RenamedComdats.try_emplace(C, ExportM.getOrInsertComdat(NewName));
62 
63  ExportGV.setName(NewName);
64  ExportGV.setLinkage(GlobalValue::ExternalLinkage);
65  ExportGV.setVisibility(GlobalValue::HiddenVisibility);
66 
67  if (ImportGV) {
68  ImportGV->setName(NewName);
70  }
71  }
72 
73  if (!RenamedComdats.empty())
74  for (auto &GO : ExportM.global_objects())
75  if (auto *C = GO.getComdat()) {
76  auto Replacement = RenamedComdats.find(C);
77  if (Replacement != RenamedComdats.end())
78  GO.setComdat(Replacement->second);
79  }
80 }
81 
82 // Promote all internal (i.e. distinct) type ids used by the module by replacing
83 // them with external type ids formed using the module id.
84 //
85 // Note that this needs to be done before we clone the module because each clone
86 // will receive its own set of distinct metadata nodes.
87 void promoteTypeIds(Module &M, StringRef ModuleId) {
89  auto ExternalizeTypeId = [&](CallInst *CI, unsigned ArgNo) {
90  Metadata *MD =
91  cast<MetadataAsValue>(CI->getArgOperand(ArgNo))->getMetadata();
92 
93  if (isa<MDNode>(MD) && cast<MDNode>(MD)->isDistinct()) {
94  Metadata *&GlobalMD = LocalToGlobal[MD];
95  if (!GlobalMD) {
96  std::string NewName = (Twine(LocalToGlobal.size()) + ModuleId).str();
97  GlobalMD = MDString::get(M.getContext(), NewName);
98  }
99 
100  CI->setArgOperand(ArgNo,
101  MetadataAsValue::get(M.getContext(), GlobalMD));
102  }
103  };
104 
105  if (Function *TypeTestFunc =
106  M.getFunction(Intrinsic::getName(Intrinsic::type_test))) {
107  for (const Use &U : TypeTestFunc->uses()) {
108  auto CI = cast<CallInst>(U.getUser());
109  ExternalizeTypeId(CI, 1);
110  }
111  }
112 
113  if (Function *TypeCheckedLoadFunc =
114  M.getFunction(Intrinsic::getName(Intrinsic::type_checked_load))) {
115  for (const Use &U : TypeCheckedLoadFunc->uses()) {
116  auto CI = cast<CallInst>(U.getUser());
117  ExternalizeTypeId(CI, 2);
118  }
119  }
120 
121  for (GlobalObject &GO : M.global_objects()) {
123  GO.getMetadata(LLVMContext::MD_type, MDs);
124 
125  GO.eraseMetadata(LLVMContext::MD_type);
126  for (auto MD : MDs) {
127  auto I = LocalToGlobal.find(MD->getOperand(1));
128  if (I == LocalToGlobal.end()) {
129  GO.addMetadata(LLVMContext::MD_type, *MD);
130  continue;
131  }
132  GO.addMetadata(
133  LLVMContext::MD_type,
134  *MDNode::get(M.getContext(), {MD->getOperand(0), I->second}));
135  }
136  }
137 }
138 
139 // Drop unused globals, and drop type information from function declarations.
140 // FIXME: If we made functions typeless then there would be no need to do this.
141 void simplifyExternals(Module &M) {
142  FunctionType *EmptyFT =
144 
145  for (auto I = M.begin(), E = M.end(); I != E;) {
146  Function &F = *I++;
147  if (F.isDeclaration() && F.use_empty()) {
148  F.eraseFromParent();
149  continue;
150  }
151 
152  if (!F.isDeclaration() || F.getFunctionType() == EmptyFT ||
153  // Changing the type of an intrinsic may invalidate the IR.
154  F.getName().startswith("llvm."))
155  continue;
156 
157  Function *NewF =
159  F.getAddressSpace(), "", &M);
160  NewF->setVisibility(F.getVisibility());
161  NewF->takeName(&F);
163  F.eraseFromParent();
164  }
165 
166  for (auto I = M.global_begin(), E = M.global_end(); I != E;) {
167  GlobalVariable &GV = *I++;
168  if (GV.isDeclaration() && GV.use_empty()) {
169  GV.eraseFromParent();
170  continue;
171  }
172  }
173 }
174 
175 static void
176 filterModule(Module *M,
177  function_ref<bool(const GlobalValue *)> ShouldKeepDefinition) {
178  std::vector<GlobalValue *> V;
179  for (GlobalValue &GV : M->global_values())
180  if (!ShouldKeepDefinition(&GV))
181  V.push_back(&GV);
182 
183  for (GlobalValue *GV : V)
184  if (!convertToDeclaration(*GV))
185  GV->eraseFromParent();
186 }
187 
188 void forEachVirtualFunction(Constant *C, function_ref<void(Function *)> Fn) {
189  if (auto *F = dyn_cast<Function>(C))
190  return Fn(F);
191  if (isa<GlobalValue>(C))
192  return;
193  for (Value *Op : C->operands())
194  forEachVirtualFunction(cast<Constant>(Op), Fn);
195 }
196 
197 // If it's possible to split M into regular and thin LTO parts, do so and write
198 // a multi-module bitcode file with the two parts to OS. Otherwise, write only a
199 // regular LTO bitcode file to OS.
200 void splitAndWriteThinLTOBitcode(
201  raw_ostream &OS, raw_ostream *ThinLinkOS,
202  function_ref<AAResults &(Function &)> AARGetter, Module &M) {
203  std::string ModuleId = getUniqueModuleId(&M);
204  if (ModuleId.empty()) {
205  // We couldn't generate a module ID for this module, write it out as a
206  // regular LTO module with an index for summary-based dead stripping.
207  ProfileSummaryInfo PSI(M);
208  M.addModuleFlag(Module::Error, "ThinLTO", uint32_t(0));
210  WriteBitcodeToFile(M, OS, /*ShouldPreserveUseListOrder=*/false, &Index);
211 
212  if (ThinLinkOS)
213  // We don't have a ThinLTO part, but still write the module to the
214  // ThinLinkOS if requested so that the expected output file is produced.
215  WriteBitcodeToFile(M, *ThinLinkOS, /*ShouldPreserveUseListOrder=*/false,
216  &Index);
217 
218  return;
219  }
220 
221  promoteTypeIds(M, ModuleId);
222 
223  // Returns whether a global or its associated global has attached type
224  // metadata. The former may participate in CFI or whole-program
225  // devirtualization, so they need to appear in the merged module instead of
226  // the thin LTO module. Similarly, globals that are associated with globals
227  // with type metadata need to appear in the merged module because they will
228  // reference the global's section directly.
229  auto HasTypeMetadata = [](const GlobalObject *GO) {
230  if (MDNode *MD = GO->getMetadata(LLVMContext::MD_associated))
231  if (auto *AssocVM = dyn_cast_or_null<ValueAsMetadata>(MD->getOperand(0)))
232  if (auto *AssocGO = dyn_cast<GlobalObject>(AssocVM->getValue()))
233  if (AssocGO->hasMetadata(LLVMContext::MD_type))
234  return true;
235  return GO->hasMetadata(LLVMContext::MD_type);
236  };
237 
238  // Collect the set of virtual functions that are eligible for virtual constant
239  // propagation. Each eligible function must not access memory, must return
240  // an integer of width <=64 bits, must take at least one argument, must not
241  // use its first argument (assumed to be "this") and all arguments other than
242  // the first one must be of <=64 bit integer type.
243  //
244  // Note that we test whether this copy of the function is readnone, rather
245  // than testing function attributes, which must hold for any copy of the
246  // function, even a less optimized version substituted at link time. This is
247  // sound because the virtual constant propagation optimizations effectively
248  // inline all implementations of the virtual function into each call site,
249  // rather than using function attributes to perform local optimization.
250  DenseSet<const Function *> EligibleVirtualFns;
251  // If any member of a comdat lives in MergedM, put all members of that
252  // comdat in MergedM to keep the comdat together.
253  DenseSet<const Comdat *> MergedMComdats;
254  for (GlobalVariable &GV : M.globals())
255  if (HasTypeMetadata(&GV)) {
256  if (const auto *C = GV.getComdat())
257  MergedMComdats.insert(C);
258  forEachVirtualFunction(GV.getInitializer(), [&](Function *F) {
259  auto *RT = dyn_cast<IntegerType>(F->getReturnType());
260  if (!RT || RT->getBitWidth() > 64 || F->arg_empty() ||
261  !F->arg_begin()->use_empty())
262  return;
263  for (auto &Arg : make_range(std::next(F->arg_begin()), F->arg_end())) {
264  auto *ArgT = dyn_cast<IntegerType>(Arg.getType());
265  if (!ArgT || ArgT->getBitWidth() > 64)
266  return;
267  }
268  if (!F->isDeclaration() &&
269  computeFunctionBodyMemoryAccess(*F, AARGetter(*F)) == MAK_ReadNone)
270  EligibleVirtualFns.insert(F);
271  });
272  }
273 
274  ValueToValueMapTy VMap;
275  std::unique_ptr<Module> MergedM(
276  CloneModule(M, VMap, [&](const GlobalValue *GV) -> bool {
277  if (const auto *C = GV->getComdat())
278  if (MergedMComdats.count(C))
279  return true;
280  if (auto *F = dyn_cast<Function>(GV))
281  return EligibleVirtualFns.count(F);
282  if (auto *GVar = dyn_cast_or_null<GlobalVariable>(GV->getBaseObject()))
283  return HasTypeMetadata(GVar);
284  return false;
285  }));
286  StripDebugInfo(*MergedM);
287  MergedM->setModuleInlineAsm("");
288 
289  for (Function &F : *MergedM)
290  if (!F.isDeclaration()) {
291  // Reset the linkage of all functions eligible for virtual constant
292  // propagation. The canonical definitions live in the thin LTO module so
293  // that they can be imported.
295  F.setComdat(nullptr);
296  }
297 
298  SetVector<GlobalValue *> CfiFunctions;
299  for (auto &F : M)
300  if ((!F.hasLocalLinkage() || F.hasAddressTaken()) && HasTypeMetadata(&F))
301  CfiFunctions.insert(&F);
302 
303  // Remove all globals with type metadata, globals with comdats that live in
304  // MergedM, and aliases pointing to such globals from the thin LTO module.
305  filterModule(&M, [&](const GlobalValue *GV) {
306  if (auto *GVar = dyn_cast_or_null<GlobalVariable>(GV->getBaseObject()))
307  if (HasTypeMetadata(GVar))
308  return false;
309  if (const auto *C = GV->getComdat())
310  if (MergedMComdats.count(C))
311  return false;
312  return true;
313  });
314 
315  promoteInternals(*MergedM, M, ModuleId, CfiFunctions);
316  promoteInternals(M, *MergedM, ModuleId, CfiFunctions);
317 
318  auto &Ctx = MergedM->getContext();
319  SmallVector<MDNode *, 8> CfiFunctionMDs;
320  for (auto V : CfiFunctions) {
321  Function &F = *cast<Function>(V);
323  F.getMetadata(LLVMContext::MD_type, Types);
324 
326  Elts.push_back(MDString::get(Ctx, F.getName()));
329  Linkage = CFL_Definition;
330  else if (F.hasExternalWeakLinkage())
331  Linkage = CFL_WeakDeclaration;
332  else
333  Linkage = CFL_Declaration;
335  llvm::ConstantInt::get(Type::getInt8Ty(Ctx), Linkage)));
336  for (auto Type : Types)
337  Elts.push_back(Type);
338  CfiFunctionMDs.push_back(MDTuple::get(Ctx, Elts));
339  }
340 
341  if(!CfiFunctionMDs.empty()) {
342  NamedMDNode *NMD = MergedM->getOrInsertNamedMetadata("cfi.functions");
343  for (auto MD : CfiFunctionMDs)
344  NMD->addOperand(MD);
345  }
346 
347  SmallVector<MDNode *, 8> FunctionAliases;
348  for (auto &A : M.aliases()) {
349  if (!isa<Function>(A.getAliasee()))
350  continue;
351 
352  auto *F = cast<Function>(A.getAliasee());
353 
354  Metadata *Elts[] = {
355  MDString::get(Ctx, A.getName()),
356  MDString::get(Ctx, F->getName()),
358  ConstantInt::get(Type::getInt8Ty(Ctx), A.getVisibility())),
360  ConstantInt::get(Type::getInt8Ty(Ctx), A.isWeakForLinker())),
361  };
362 
363  FunctionAliases.push_back(MDTuple::get(Ctx, Elts));
364  }
365 
366  if (!FunctionAliases.empty()) {
367  NamedMDNode *NMD = MergedM->getOrInsertNamedMetadata("aliases");
368  for (auto MD : FunctionAliases)
369  NMD->addOperand(MD);
370  }
371 
372  SmallVector<MDNode *, 8> Symvers;
374  Function *F = M.getFunction(Name);
375  if (!F || F->use_empty())
376  return;
377 
378  Symvers.push_back(MDTuple::get(
379  Ctx, {MDString::get(Ctx, Name), MDString::get(Ctx, Alias)}));
380  });
381 
382  if (!Symvers.empty()) {
383  NamedMDNode *NMD = MergedM->getOrInsertNamedMetadata("symvers");
384  for (auto MD : Symvers)
385  NMD->addOperand(MD);
386  }
387 
388  simplifyExternals(*MergedM);
389 
390  // FIXME: Try to re-use BSI and PFI from the original module here.
391  ProfileSummaryInfo PSI(M);
392  ModuleSummaryIndex Index = buildModuleSummaryIndex(M, nullptr, &PSI);
393 
394  // Mark the merged module as requiring full LTO. We still want an index for
395  // it though, so that it can participate in summary-based dead stripping.
396  MergedM->addModuleFlag(Module::Error, "ThinLTO", uint32_t(0));
397  ModuleSummaryIndex MergedMIndex =
398  buildModuleSummaryIndex(*MergedM, nullptr, &PSI);
399 
400  SmallVector<char, 0> Buffer;
401 
402  BitcodeWriter W(Buffer);
403  // Save the module hash produced for the full bitcode, which will
404  // be used in the backends, and use that in the minimized bitcode
405  // produced for the full link.
406  ModuleHash ModHash = {{0}};
407  W.writeModule(M, /*ShouldPreserveUseListOrder=*/false, &Index,
408  /*GenerateHash=*/true, &ModHash);
409  W.writeModule(*MergedM, /*ShouldPreserveUseListOrder=*/false, &MergedMIndex);
410  W.writeSymtab();
411  W.writeStrtab();
412  OS << Buffer;
413 
414  // If a minimized bitcode module was requested for the thin link, only
415  // the information that is needed by thin link will be written in the
416  // given OS (the merged module will be written as usual).
417  if (ThinLinkOS) {
418  Buffer.clear();
419  BitcodeWriter W2(Buffer);
420  StripDebugInfo(M);
421  W2.writeThinLinkBitcode(M, Index, ModHash);
422  W2.writeModule(*MergedM, /*ShouldPreserveUseListOrder=*/false,
423  &MergedMIndex);
424  W2.writeSymtab();
425  W2.writeStrtab();
426  *ThinLinkOS << Buffer;
427  }
428 }
429 
430 // Check if the LTO Unit splitting has been enabled.
431 bool enableSplitLTOUnit(Module &M) {
432  bool EnableSplitLTOUnit = false;
433  if (auto *MD = mdconst::extract_or_null<ConstantInt>(
434  M.getModuleFlag("EnableSplitLTOUnit")))
435  EnableSplitLTOUnit = MD->getZExtValue();
436  return EnableSplitLTOUnit;
437 }
438 
439 // Returns whether this module needs to be split because it uses type metadata.
440 bool hasTypeMetadata(Module &M) {
441  for (auto &GO : M.global_objects()) {
442  if (GO.hasMetadata(LLVMContext::MD_type))
443  return true;
444  }
445  return false;
446 }
447 
448 void writeThinLTOBitcode(raw_ostream &OS, raw_ostream *ThinLinkOS,
449  function_ref<AAResults &(Function &)> AARGetter,
450  Module &M, const ModuleSummaryIndex *Index) {
451  std::unique_ptr<ModuleSummaryIndex> NewIndex = nullptr;
452  // See if this module has any type metadata. If so, we try to split it
453  // or at least promote type ids to enable WPD.
454  if (hasTypeMetadata(M)) {
455  if (enableSplitLTOUnit(M))
456  return splitAndWriteThinLTOBitcode(OS, ThinLinkOS, AARGetter, M);
457  // Promote type ids as needed for index-based WPD.
458  std::string ModuleId = getUniqueModuleId(&M);
459  if (!ModuleId.empty()) {
460  promoteTypeIds(M, ModuleId);
461  // Need to rebuild the index so that it contains type metadata
462  // for the newly promoted type ids.
463  // FIXME: Probably should not bother building the index at all
464  // in the caller of writeThinLTOBitcode (which does so via the
465  // ModuleSummaryIndexAnalysis pass), since we have to rebuild it
466  // anyway whenever there is type metadata (here or in
467  // splitAndWriteThinLTOBitcode). Just always build it once via the
468  // buildModuleSummaryIndex when Module(s) are ready.
469  ProfileSummaryInfo PSI(M);
470  NewIndex = std::make_unique<ModuleSummaryIndex>(
471  buildModuleSummaryIndex(M, nullptr, &PSI));
472  Index = NewIndex.get();
473  }
474  }
475 
476  // Write it out as an unsplit ThinLTO module.
477 
478  // Save the module hash produced for the full bitcode, which will
479  // be used in the backends, and use that in the minimized bitcode
480  // produced for the full link.
481  ModuleHash ModHash = {{0}};
482  WriteBitcodeToFile(M, OS, /*ShouldPreserveUseListOrder=*/false, Index,
483  /*GenerateHash=*/true, &ModHash);
484  // If a minimized bitcode module was requested for the thin link, only
485  // the information that is needed by thin link will be written in the
486  // given OS.
487  if (ThinLinkOS && Index)
488  WriteThinLinkBitcodeToFile(M, *ThinLinkOS, *Index, ModHash);
489 }
490 
491 class WriteThinLTOBitcode : public ModulePass {
492  raw_ostream &OS; // raw_ostream to print on
493  // The output stream on which to emit a minimized module for use
494  // just in the thin link, if requested.
495  raw_ostream *ThinLinkOS;
496 
497 public:
498  static char ID; // Pass identification, replacement for typeid
499  WriteThinLTOBitcode() : ModulePass(ID), OS(dbgs()), ThinLinkOS(nullptr) {
501  }
502 
503  explicit WriteThinLTOBitcode(raw_ostream &o, raw_ostream *ThinLinkOS)
504  : ModulePass(ID), OS(o), ThinLinkOS(ThinLinkOS) {
506  }
507 
508  StringRef getPassName() const override { return "ThinLTO Bitcode Writer"; }
509 
510  bool runOnModule(Module &M) override {
511  const ModuleSummaryIndex *Index =
512  &(getAnalysis<ModuleSummaryIndexWrapperPass>().getIndex());
513  writeThinLTOBitcode(OS, ThinLinkOS, LegacyAARGetter(*this), M, Index);
514  return true;
515  }
516  void getAnalysisUsage(AnalysisUsage &AU) const override {
517  AU.setPreservesAll();
521  }
522 };
523 } // anonymous namespace
524 
525 char WriteThinLTOBitcode::ID = 0;
526 INITIALIZE_PASS_BEGIN(WriteThinLTOBitcode, "write-thinlto-bitcode",
527  "Write ThinLTO Bitcode", false, true)
531 INITIALIZE_PASS_END(WriteThinLTOBitcode, "write-thinlto-bitcode",
532  "Write ThinLTO Bitcode", false, true)
533 
535  raw_ostream *ThinLinkOS) {
536  return new WriteThinLTOBitcode(Str, ThinLinkOS);
537 }
538 
542  AM.getResult<FunctionAnalysisManagerModuleProxy>(M).getManager();
543  writeThinLTOBitcode(OS, ThinLinkOS,
544  [&FAM](Function &F) -> AAResults & {
545  return FAM.getResult<AAManager>(F);
546  },
548  return PreservedAnalyses::all();
549 }
void setVisibility(VisibilityTypes V)
Definition: GlobalValue.h:235
const Function & getFunction() const
Definition: Function.h:135
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:1139
iterator_range< use_iterator > uses()
Definition: Value.h:373
LLVM_NODISCARD std::enable_if_t< !is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type > dyn_cast(const Y &Val)
Definition: Casting.h:334
bool hasLocalLinkage() const
Definition: GlobalValue.h:445
ModuleSummaryIndex buildModuleSummaryIndex(const Module &M, std::function< BlockFrequencyInfo *(const Function &F)> GetBFICallback, ProfileSummaryInfo *PSI, std::function< const StackSafetyInfo *(const Function &F)> GetSSICallback=[](const Function &F) -> const StackSafetyInfo *{ return nullptr;})
Direct function to compute a ModuleSummaryIndex from a given module.
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:769
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:67
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:289
Implements a dense probed hash-table based set.
Definition: DenseSet.h:255
Available for inspection, not emission.
Definition: GlobalValue.h:49
Analysis providing profile information.
void addOperand(MDNode *M)
Definition: Metadata.cpp:1088
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:176
CfiFunctionLinkage
The type of CFI jumptable needed for a function.
Externally visible function.
Definition: GlobalValue.h:48
arg_iterator arg_end()
Definition: Function.h:729
void setArgOperand(unsigned i, Value *v)
Definition: InstrTypes.h:1264
Metadata node.
Definition: Metadata.h:870
F(f)
bool hasExternalWeakLinkage() const
Definition: GlobalValue.h:446
MemoryAccessKind computeFunctionBodyMemoryAccess(Function &F, AAResults &AAR)
Returns the memory access properties of this copy of the function.
Analysis pass to provide the ModuleSummaryIndex object.
Value * getArgOperand(unsigned i) const
Definition: InstrTypes.h:1259
AnalysisUsage & addRequired()
A tuple of MDNodes.
Definition: Metadata.h:1330
StringRef getName(ID id)
Return the LLVM name for an intrinsic, such as "llvm.ppc.altivec.lvx".
Definition: Function.cpp:701
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:253
A Use represents the edge between a Value definition and its users.
Definition: Use.h:44
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:1443
std::array< uint32_t, 5 > ModuleHash
160 bits SHA1
void setName(const Twine &Name)
Change the name of the value.
Definition: Value.cpp:342
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:592
Class to represent function types.
Definition: DerivedTypes.h:108
bool insert(const value_type &X)
Insert a new element into the SetVector.
Definition: SetVector.h:141
bool arg_empty() const
Definition: Function.h:754
void setComdat(Comdat *C)
Definition: GlobalObject.h:128
bool StripDebugInfo(Module &M)
Strip debug info in the module if it exists.
Definition: DebugInfo.cpp:358
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:486
void takeName(Value *V)
Transfer the name from V to this value.
Definition: Value.cpp:348
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:410
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:681
static MetadataAsValue * get(LLVMContext &Context, Metadata *MD)
Definition: Metadata.cpp:105
static Constant * getBitCast(Constant *C, Type *Ty, bool OnlyIfReduced=false)
Definition: Constants.cpp:2025
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:1172
Type * getReturnType() const
Returns the type of the ret val.
Definition: Function.h:170
static Function * Create(FunctionType *Ty, LinkageTypes Linkage, unsigned AddrSpace, const Twine &N="", Module *M=nullptr)
Definition: Function.h:137
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:120
A set of analyses that are preserved following a run of a transformation pass.
Definition: PassManager.h:154
VisibilityTypes getVisibility() const
Definition: GlobalValue.h:229
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
Metadata * getModuleFlag(StringRef Key) const
Return the corresponding value if Key appears in module flags, otherwise return null.
Definition: Module.cpp:321
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:170
void addModuleFlag(ModFlagBehavior Behavior, StringRef Key, Metadata *Val)
Add a module-level flag to the module-level flags metadata.
Definition: Module.cpp:348
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:311
op_range operands()
Definition: User.h:242
arg_iterator arg_begin()
Definition: Function.h:720
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:526
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition: PassManager.h:160
INITIALIZE_PASS_END(RegBankSelect, DEBUG_TYPE, "Assign register bank of generic virtual registers", false, false) RegBankSelect
global_iterator global_end()
Definition: Module.h:594
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:883
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:786
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:165
const Comdat * getComdat() const
Definition: Globals.cpp:171
void setPreservesAll()
Set by analyses that do not transform their input at all.
bool hasAddressTaken(const User **=nullptr, bool IgnoreCallbackUses=false) const
hasAddressTaken - returns true if there are any uses of this function other than direct calls or invo...
Definition: Function.cpp:1490
const Comdat * getComdat() const
Definition: GlobalObject.h:126
basic Basic Alias true
void eraseFromParent()
This method unlinks &#39;this&#39; from the containing module and deletes it.
Definition: Globals.cpp:86
iterator end()
Definition: Module.h:612
StringRef getName() const
Return a constant reference to the value&#39;s name.
Definition: Value.cpp:270
#define I(x, y, z)
Definition: MD5.cpp:59
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
Definition: Pass.h:224
iterator begin()
Definition: Module.h:610
bool isJumpTableCanonical(Function *F)
void eraseFromParent()
eraseFromParent - This method unlinks &#39;this&#39; from the containing module and deletes it...
Definition: Function.cpp:273
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:97
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
LLVM Value Representation.
Definition: Value.h:74
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:46
iterator_range< global_iterator > globals()
Definition: Module.h:599
iterator_range< global_object_iterator > global_objects()
Definition: Module.cpp:412
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:57
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
Root of the metadata hierarchy.
Definition: Metadata.h:58
static IntegerType * getInt8Ty(LLVMContext &C)
Definition: Type.cpp:184
bool use_empty() const
Definition: Value.h:341
PointerType * getType() const
Global values are always pointers.
Definition: GlobalValue.h:271
Legacy wrapper pass to provide the ModuleSummaryIndex object.
INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
iterator_range< global_value_iterator > global_values()
Definition: Module.cpp:420
An analysis over an "outer" IR unit that provides access to an analysis manager over an "inner" IR un...
Definition: PassManager.h:953