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