LLVM  16.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/Instructions.h"
18 #include "llvm/IR/Intrinsics.h"
19 #include "llvm/IR/Module.h"
20 #include "llvm/IR/PassManager.h"
21 #include "llvm/InitializePasses.h"
23 #include "llvm/Pass.h"
25 #include "llvm/Transforms/IPO.h"
31 using namespace llvm;
32 
33 namespace {
34 
35 // Determine if a promotion alias should be created for a symbol name.
36 static bool allowPromotionAlias(const std::string &Name) {
37  // Promotion aliases are used only in inline assembly. It's safe to
38  // simply skip unusual names. Subset of MCAsmInfo::isAcceptableChar()
39  // and MCAsmInfoXCOFF::isAcceptableChar().
40  for (const char &C : Name) {
41  if (isAlnum(C) || C == '_' || C == '.')
42  continue;
43  return false;
44  }
45  return true;
46 }
47 
48 // Promote each local-linkage entity defined by ExportM and used by ImportM by
49 // changing visibility and appending the given ModuleId.
50 void promoteInternals(Module &ExportM, Module &ImportM, StringRef ModuleId,
51  SetVector<GlobalValue *> &PromoteExtra) {
53  for (auto &ExportGV : ExportM.global_values()) {
54  if (!ExportGV.hasLocalLinkage())
55  continue;
56 
57  auto Name = ExportGV.getName();
58  GlobalValue *ImportGV = nullptr;
59  if (!PromoteExtra.count(&ExportGV)) {
60  ImportGV = ImportM.getNamedValue(Name);
61  if (!ImportGV)
62  continue;
63  ImportGV->removeDeadConstantUsers();
64  if (ImportGV->use_empty()) {
65  ImportGV->eraseFromParent();
66  continue;
67  }
68  }
69 
70  std::string OldName = Name.str();
71  std::string NewName = (Name + ModuleId).str();
72 
73  if (const auto *C = ExportGV.getComdat())
74  if (C->getName() == Name)
75  RenamedComdats.try_emplace(C, ExportM.getOrInsertComdat(NewName));
76 
77  ExportGV.setName(NewName);
78  ExportGV.setLinkage(GlobalValue::ExternalLinkage);
79  ExportGV.setVisibility(GlobalValue::HiddenVisibility);
80 
81  if (ImportGV) {
82  ImportGV->setName(NewName);
84  }
85 
86  if (isa<Function>(&ExportGV) && allowPromotionAlias(OldName)) {
87  // Create a local alias with the original name to avoid breaking
88  // references from inline assembly.
89  std::string Alias =
90  ".lto_set_conditional " + OldName + "," + NewName + "\n";
91  ExportM.appendModuleInlineAsm(Alias);
92  }
93  }
94 
95  if (!RenamedComdats.empty())
96  for (auto &GO : ExportM.global_objects())
97  if (auto *C = GO.getComdat()) {
98  auto Replacement = RenamedComdats.find(C);
99  if (Replacement != RenamedComdats.end())
100  GO.setComdat(Replacement->second);
101  }
102 }
103 
104 // Promote all internal (i.e. distinct) type ids used by the module by replacing
105 // them with external type ids formed using the module id.
106 //
107 // Note that this needs to be done before we clone the module because each clone
108 // will receive its own set of distinct metadata nodes.
109 void promoteTypeIds(Module &M, StringRef ModuleId) {
110  DenseMap<Metadata *, Metadata *> LocalToGlobal;
111  auto ExternalizeTypeId = [&](CallInst *CI, unsigned ArgNo) {
112  Metadata *MD =
113  cast<MetadataAsValue>(CI->getArgOperand(ArgNo))->getMetadata();
114 
115  if (isa<MDNode>(MD) && cast<MDNode>(MD)->isDistinct()) {
116  Metadata *&GlobalMD = LocalToGlobal[MD];
117  if (!GlobalMD) {
118  std::string NewName = (Twine(LocalToGlobal.size()) + ModuleId).str();
119  GlobalMD = MDString::get(M.getContext(), NewName);
120  }
121 
122  CI->setArgOperand(ArgNo,
123  MetadataAsValue::get(M.getContext(), GlobalMD));
124  }
125  };
126 
127  if (Function *TypeTestFunc =
128  M.getFunction(Intrinsic::getName(Intrinsic::type_test))) {
129  for (const Use &U : TypeTestFunc->uses()) {
130  auto CI = cast<CallInst>(U.getUser());
131  ExternalizeTypeId(CI, 1);
132  }
133  }
134 
135  if (Function *PublicTypeTestFunc =
136  M.getFunction(Intrinsic::getName(Intrinsic::public_type_test))) {
137  for (const Use &U : PublicTypeTestFunc->uses()) {
138  auto CI = cast<CallInst>(U.getUser());
139  ExternalizeTypeId(CI, 1);
140  }
141  }
142 
143  if (Function *TypeCheckedLoadFunc =
144  M.getFunction(Intrinsic::getName(Intrinsic::type_checked_load))) {
145  for (const Use &U : TypeCheckedLoadFunc->uses()) {
146  auto CI = cast<CallInst>(U.getUser());
147  ExternalizeTypeId(CI, 2);
148  }
149  }
150 
151  for (GlobalObject &GO : M.global_objects()) {
153  GO.getMetadata(LLVMContext::MD_type, MDs);
154 
155  GO.eraseMetadata(LLVMContext::MD_type);
156  for (auto *MD : MDs) {
157  auto I = LocalToGlobal.find(MD->getOperand(1));
158  if (I == LocalToGlobal.end()) {
159  GO.addMetadata(LLVMContext::MD_type, *MD);
160  continue;
161  }
162  GO.addMetadata(
163  LLVMContext::MD_type,
164  *MDNode::get(M.getContext(), {MD->getOperand(0), I->second}));
165  }
166  }
167 }
168 
169 // Drop unused globals, and drop type information from function declarations.
170 // FIXME: If we made functions typeless then there would be no need to do this.
171 void simplifyExternals(Module &M) {
172  FunctionType *EmptyFT =
173  FunctionType::get(Type::getVoidTy(M.getContext()), false);
174 
176  if (F.isDeclaration() && F.use_empty()) {
177  F.eraseFromParent();
178  continue;
179  }
180 
181  if (!F.isDeclaration() || F.getFunctionType() == EmptyFT ||
182  // Changing the type of an intrinsic may invalidate the IR.
183  F.getName().startswith("llvm."))
184  continue;
185 
186  Function *NewF =
188  F.getAddressSpace(), "", &M);
189  NewF->copyAttributesFrom(&F);
190  // Only copy function attribtues.
191  NewF->setAttributes(AttributeList::get(M.getContext(),
193  F.getAttributes().getFnAttrs()));
194  NewF->takeName(&F);
195  F.replaceAllUsesWith(ConstantExpr::getBitCast(NewF, F.getType()));
196  F.eraseFromParent();
197  }
198 
199  for (GlobalVariable &GV : llvm::make_early_inc_range(M.globals())) {
200  if (GV.isDeclaration() && GV.use_empty()) {
201  GV.eraseFromParent();
202  continue;
203  }
204  }
205 }
206 
207 static void
208 filterModule(Module *M,
209  function_ref<bool(const GlobalValue *)> ShouldKeepDefinition) {
210  std::vector<GlobalValue *> V;
211  for (GlobalValue &GV : M->global_values())
212  if (!ShouldKeepDefinition(&GV))
213  V.push_back(&GV);
214 
215  for (GlobalValue *GV : V)
216  if (!convertToDeclaration(*GV))
217  GV->eraseFromParent();
218 }
219 
220 void forEachVirtualFunction(Constant *C, function_ref<void(Function *)> Fn) {
221  if (auto *F = dyn_cast<Function>(C))
222  return Fn(F);
223  if (isa<GlobalValue>(C))
224  return;
225  for (Value *Op : C->operands())
226  forEachVirtualFunction(cast<Constant>(Op), Fn);
227 }
228 
229 // Clone any @llvm[.compiler].used over to the new module and append
230 // values whose defs were cloned into that module.
231 static void cloneUsedGlobalVariables(const Module &SrcM, Module &DestM,
232  bool CompilerUsed) {
234  // First collect those in the llvm[.compiler].used set.
235  collectUsedGlobalVariables(SrcM, Used, CompilerUsed);
236  // Next build a set of the equivalent values defined in DestM.
237  for (auto *V : Used) {
238  auto *GV = DestM.getNamedValue(V->getName());
239  if (GV && !GV->isDeclaration())
240  NewUsed.push_back(GV);
241  }
242  // Finally, add them to a llvm[.compiler].used variable in DestM.
243  if (CompilerUsed)
244  appendToCompilerUsed(DestM, NewUsed);
245  else
246  appendToUsed(DestM, NewUsed);
247 }
248 
249 // If it's possible to split M into regular and thin LTO parts, do so and write
250 // a multi-module bitcode file with the two parts to OS. Otherwise, write only a
251 // regular LTO bitcode file to OS.
252 void splitAndWriteThinLTOBitcode(
253  raw_ostream &OS, raw_ostream *ThinLinkOS,
254  function_ref<AAResults &(Function &)> AARGetter, Module &M) {
255  std::string ModuleId = getUniqueModuleId(&M);
256  if (ModuleId.empty()) {
257  // We couldn't generate a module ID for this module, write it out as a
258  // regular LTO module with an index for summary-based dead stripping.
259  ProfileSummaryInfo PSI(M);
260  M.addModuleFlag(Module::Error, "ThinLTO", uint32_t(0));
262  WriteBitcodeToFile(M, OS, /*ShouldPreserveUseListOrder=*/false, &Index);
263 
264  if (ThinLinkOS)
265  // We don't have a ThinLTO part, but still write the module to the
266  // ThinLinkOS if requested so that the expected output file is produced.
267  WriteBitcodeToFile(M, *ThinLinkOS, /*ShouldPreserveUseListOrder=*/false,
268  &Index);
269 
270  return;
271  }
272 
273  promoteTypeIds(M, ModuleId);
274 
275  // Returns whether a global or its associated global has attached type
276  // metadata. The former may participate in CFI or whole-program
277  // devirtualization, so they need to appear in the merged module instead of
278  // the thin LTO module. Similarly, globals that are associated with globals
279  // with type metadata need to appear in the merged module because they will
280  // reference the global's section directly.
281  auto HasTypeMetadata = [](const GlobalObject *GO) {
282  if (MDNode *MD = GO->getMetadata(LLVMContext::MD_associated))
283  if (auto *AssocVM = dyn_cast_or_null<ValueAsMetadata>(MD->getOperand(0)))
284  if (auto *AssocGO = dyn_cast<GlobalObject>(AssocVM->getValue()))
285  if (AssocGO->hasMetadata(LLVMContext::MD_type))
286  return true;
287  return GO->hasMetadata(LLVMContext::MD_type);
288  };
289 
290  // Collect the set of virtual functions that are eligible for virtual constant
291  // propagation. Each eligible function must not access memory, must return
292  // an integer of width <=64 bits, must take at least one argument, must not
293  // use its first argument (assumed to be "this") and all arguments other than
294  // the first one must be of <=64 bit integer type.
295  //
296  // Note that we test whether this copy of the function is readnone, rather
297  // than testing function attributes, which must hold for any copy of the
298  // function, even a less optimized version substituted at link time. This is
299  // sound because the virtual constant propagation optimizations effectively
300  // inline all implementations of the virtual function into each call site,
301  // rather than using function attributes to perform local optimization.
302  DenseSet<const Function *> EligibleVirtualFns;
303  // If any member of a comdat lives in MergedM, put all members of that
304  // comdat in MergedM to keep the comdat together.
305  DenseSet<const Comdat *> MergedMComdats;
306  for (GlobalVariable &GV : M.globals())
307  if (HasTypeMetadata(&GV)) {
308  if (const auto *C = GV.getComdat())
309  MergedMComdats.insert(C);
310  forEachVirtualFunction(GV.getInitializer(), [&](Function *F) {
311  auto *RT = dyn_cast<IntegerType>(F->getReturnType());
312  if (!RT || RT->getBitWidth() > 64 || F->arg_empty() ||
313  !F->arg_begin()->use_empty())
314  return;
315  for (auto &Arg : drop_begin(F->args())) {
316  auto *ArgT = dyn_cast<IntegerType>(Arg.getType());
317  if (!ArgT || ArgT->getBitWidth() > 64)
318  return;
319  }
320  if (!F->isDeclaration() &&
321  computeFunctionBodyMemoryAccess(*F, AARGetter(*F))
322  .doesNotAccessMemory())
323  EligibleVirtualFns.insert(F);
324  });
325  }
326 
327  ValueToValueMapTy VMap;
328  std::unique_ptr<Module> MergedM(
329  CloneModule(M, VMap, [&](const GlobalValue *GV) -> bool {
330  if (const auto *C = GV->getComdat())
331  if (MergedMComdats.count(C))
332  return true;
333  if (auto *F = dyn_cast<Function>(GV))
334  return EligibleVirtualFns.count(F);
335  if (auto *GVar =
336  dyn_cast_or_null<GlobalVariable>(GV->getAliaseeObject()))
337  return HasTypeMetadata(GVar);
338  return false;
339  }));
340  StripDebugInfo(*MergedM);
341  MergedM->setModuleInlineAsm("");
342 
343  // Clone any llvm.*used globals to ensure the included values are
344  // not deleted.
345  cloneUsedGlobalVariables(M, *MergedM, /*CompilerUsed*/ false);
346  cloneUsedGlobalVariables(M, *MergedM, /*CompilerUsed*/ true);
347 
348  for (Function &F : *MergedM)
349  if (!F.isDeclaration()) {
350  // Reset the linkage of all functions eligible for virtual constant
351  // propagation. The canonical definitions live in the thin LTO module so
352  // that they can be imported.
354  F.setComdat(nullptr);
355  }
356 
357  SetVector<GlobalValue *> CfiFunctions;
358  for (auto &F : M)
359  if ((!F.hasLocalLinkage() || F.hasAddressTaken()) && HasTypeMetadata(&F))
360  CfiFunctions.insert(&F);
361 
362  // Remove all globals with type metadata, globals with comdats that live in
363  // MergedM, and aliases pointing to such globals from the thin LTO module.
364  filterModule(&M, [&](const GlobalValue *GV) {
365  if (auto *GVar = dyn_cast_or_null<GlobalVariable>(GV->getAliaseeObject()))
366  if (HasTypeMetadata(GVar))
367  return false;
368  if (const auto *C = GV->getComdat())
369  if (MergedMComdats.count(C))
370  return false;
371  return true;
372  });
373 
374  promoteInternals(*MergedM, M, ModuleId, CfiFunctions);
375  promoteInternals(M, *MergedM, ModuleId, CfiFunctions);
376 
377  auto &Ctx = MergedM->getContext();
378  SmallVector<MDNode *, 8> CfiFunctionMDs;
379  for (auto *V : CfiFunctions) {
380  Function &F = *cast<Function>(V);
382  F.getMetadata(LLVMContext::MD_type, Types);
383 
385  Elts.push_back(MDString::get(Ctx, F.getName()));
389  else if (F.hasExternalWeakLinkage())
391  else
393  Elts.push_back(ConstantAsMetadata::get(
394  llvm::ConstantInt::get(Type::getInt8Ty(Ctx), Linkage)));
395  append_range(Elts, Types);
396  CfiFunctionMDs.push_back(MDTuple::get(Ctx, Elts));
397  }
398 
399  if(!CfiFunctionMDs.empty()) {
400  NamedMDNode *NMD = MergedM->getOrInsertNamedMetadata("cfi.functions");
401  for (auto *MD : CfiFunctionMDs)
402  NMD->addOperand(MD);
403  }
404 
405  SmallVector<MDNode *, 8> FunctionAliases;
406  for (auto &A : M.aliases()) {
407  if (!isa<Function>(A.getAliasee()))
408  continue;
409 
410  auto *F = cast<Function>(A.getAliasee());
411 
412  Metadata *Elts[] = {
413  MDString::get(Ctx, A.getName()),
414  MDString::get(Ctx, F->getName()),
416  ConstantInt::get(Type::getInt8Ty(Ctx), A.getVisibility())),
418  ConstantInt::get(Type::getInt8Ty(Ctx), A.isWeakForLinker())),
419  };
420 
421  FunctionAliases.push_back(MDTuple::get(Ctx, Elts));
422  }
423 
424  if (!FunctionAliases.empty()) {
425  NamedMDNode *NMD = MergedM->getOrInsertNamedMetadata("aliases");
426  for (auto *MD : FunctionAliases)
427  NMD->addOperand(MD);
428  }
429 
430  SmallVector<MDNode *, 8> Symvers;
432  Function *F = M.getFunction(Name);
433  if (!F || F->use_empty())
434  return;
435 
436  Symvers.push_back(MDTuple::get(
437  Ctx, {MDString::get(Ctx, Name), MDString::get(Ctx, Alias)}));
438  });
439 
440  if (!Symvers.empty()) {
441  NamedMDNode *NMD = MergedM->getOrInsertNamedMetadata("symvers");
442  for (auto *MD : Symvers)
443  NMD->addOperand(MD);
444  }
445 
446  simplifyExternals(*MergedM);
447 
448  // FIXME: Try to re-use BSI and PFI from the original module here.
449  ProfileSummaryInfo PSI(M);
451 
452  // Mark the merged module as requiring full LTO. We still want an index for
453  // it though, so that it can participate in summary-based dead stripping.
454  MergedM->addModuleFlag(Module::Error, "ThinLTO", uint32_t(0));
455  ModuleSummaryIndex MergedMIndex =
456  buildModuleSummaryIndex(*MergedM, nullptr, &PSI);
457 
458  SmallVector<char, 0> Buffer;
459 
460  BitcodeWriter W(Buffer);
461  // Save the module hash produced for the full bitcode, which will
462  // be used in the backends, and use that in the minimized bitcode
463  // produced for the full link.
464  ModuleHash ModHash = {{0}};
465  W.writeModule(M, /*ShouldPreserveUseListOrder=*/false, &Index,
466  /*GenerateHash=*/true, &ModHash);
467  W.writeModule(*MergedM, /*ShouldPreserveUseListOrder=*/false, &MergedMIndex);
468  W.writeSymtab();
469  W.writeStrtab();
470  OS << Buffer;
471 
472  // If a minimized bitcode module was requested for the thin link, only
473  // the information that is needed by thin link will be written in the
474  // given OS (the merged module will be written as usual).
475  if (ThinLinkOS) {
476  Buffer.clear();
477  BitcodeWriter W2(Buffer);
478  StripDebugInfo(M);
479  W2.writeThinLinkBitcode(M, Index, ModHash);
480  W2.writeModule(*MergedM, /*ShouldPreserveUseListOrder=*/false,
481  &MergedMIndex);
482  W2.writeSymtab();
483  W2.writeStrtab();
484  *ThinLinkOS << Buffer;
485  }
486 }
487 
488 // Check if the LTO Unit splitting has been enabled.
489 bool enableSplitLTOUnit(Module &M) {
490  bool EnableSplitLTOUnit = false;
491  if (auto *MD = mdconst::extract_or_null<ConstantInt>(
492  M.getModuleFlag("EnableSplitLTOUnit")))
493  EnableSplitLTOUnit = MD->getZExtValue();
494  return EnableSplitLTOUnit;
495 }
496 
497 // Returns whether this module needs to be split because it uses type metadata.
498 bool hasTypeMetadata(Module &M) {
499  for (auto &GO : M.global_objects()) {
500  if (GO.hasMetadata(LLVMContext::MD_type))
501  return true;
502  }
503  return false;
504 }
505 
506 void writeThinLTOBitcode(raw_ostream &OS, raw_ostream *ThinLinkOS,
507  function_ref<AAResults &(Function &)> AARGetter,
508  Module &M, const ModuleSummaryIndex *Index) {
509  std::unique_ptr<ModuleSummaryIndex> NewIndex = nullptr;
510  // See if this module has any type metadata. If so, we try to split it
511  // or at least promote type ids to enable WPD.
512  if (hasTypeMetadata(M)) {
513  if (enableSplitLTOUnit(M))
514  return splitAndWriteThinLTOBitcode(OS, ThinLinkOS, AARGetter, M);
515  // Promote type ids as needed for index-based WPD.
516  std::string ModuleId = getUniqueModuleId(&M);
517  if (!ModuleId.empty()) {
518  promoteTypeIds(M, ModuleId);
519  // Need to rebuild the index so that it contains type metadata
520  // for the newly promoted type ids.
521  // FIXME: Probably should not bother building the index at all
522  // in the caller of writeThinLTOBitcode (which does so via the
523  // ModuleSummaryIndexAnalysis pass), since we have to rebuild it
524  // anyway whenever there is type metadata (here or in
525  // splitAndWriteThinLTOBitcode). Just always build it once via the
526  // buildModuleSummaryIndex when Module(s) are ready.
527  ProfileSummaryInfo PSI(M);
528  NewIndex = std::make_unique<ModuleSummaryIndex>(
529  buildModuleSummaryIndex(M, nullptr, &PSI));
530  Index = NewIndex.get();
531  }
532  }
533 
534  // Write it out as an unsplit ThinLTO module.
535 
536  // Save the module hash produced for the full bitcode, which will
537  // be used in the backends, and use that in the minimized bitcode
538  // produced for the full link.
539  ModuleHash ModHash = {{0}};
540  WriteBitcodeToFile(M, OS, /*ShouldPreserveUseListOrder=*/false, Index,
541  /*GenerateHash=*/true, &ModHash);
542  // If a minimized bitcode module was requested for the thin link, only
543  // the information that is needed by thin link will be written in the
544  // given OS.
545  if (ThinLinkOS && Index)
546  writeThinLinkBitcodeToFile(M, *ThinLinkOS, *Index, ModHash);
547 }
548 
549 } // anonymous namespace
550 
555  writeThinLTOBitcode(OS, ThinLinkOS,
556  [&FAM](Function &F) -> AAResults & {
557  return FAM.getResult<AAManager>(F);
558  },
560  return PreservedAnalyses::all();
561 }
llvm::Module::global_values
iterator_range< global_value_iterator > global_values()
Definition: Module.cpp:422
llvm::PreservedAnalyses
A set of analyses that are preserved following a run of a transformation pass.
Definition: PassManager.h:152
llvm::Module::appendModuleInlineAsm
void appendModuleInlineAsm(StringRef Asm)
Append to the module-scope inline assembly blocks.
Definition: Module.h:313
llvm::AAManager
A manager for alias analyses.
Definition: AliasAnalysis.h:876
ThinLTOBitcodeWriter.h
llvm::StripDebugInfo
bool StripDebugInfo(Module &M)
Strip debug info in the module if it exists.
Definition: DebugInfo.cpp:499
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
M
We currently emits eax Perhaps this is what we really should generate is Is imull three or four cycles eax eax The current instruction priority is based on pattern complexity The former is more complex because it folds a load so the latter will not be emitted Perhaps we should use AddedComplexity to give LEA32r a higher priority We should always try to match LEA first since the LEA matching code does some estimate to determine whether the match is profitable if we care more about code then imull is better It s two bytes shorter than movl leal On a Pentium M
Definition: README.txt:252
llvm::NamedMDNode
A tuple of MDNodes.
Definition: Metadata.h:1588
llvm::AnalysisManager::getResult
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
Definition: PassManager.h:774
llvm::GlobalValue::HiddenVisibility
@ HiddenVisibility
The GV is hidden.
Definition: GlobalValue.h:64
llvm::Function
Definition: Function.h:60
Pass.h
llvm::SmallVector
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1199
llvm::RISCVFenceField::W
@ W
Definition: RISCVBaseInfo.h:266
FunctionImport.h
llvm::ModuleSummaryIndexAnalysis
Analysis pass to provide the ModuleSummaryIndex object.
Definition: ModuleSummaryAnalysis.h:45
llvm::Intrinsic::getName
StringRef getName(ID id)
Return the LLVM name for an intrinsic, such as "llvm.ppc.altivec.lvx".
Definition: Function.cpp:942
llvm::GlobalVariable
Definition: GlobalVariable.h:39
llvm::ConstantExpr::getBitCast
static Constant * getBitCast(Constant *C, Type *Ty, bool OnlyIfReduced=false)
Definition: Constants.cpp:2202
llvm::FunctionType::get
static FunctionType * get(Type *Result, ArrayRef< Type * > Params, bool isVarArg)
This static method is the primary way of constructing a FunctionType.
Definition: Type.cpp:361
llvm::AttributeList::get
static AttributeList get(LLVMContext &C, ArrayRef< std::pair< unsigned, Attribute >> Attrs)
Create an AttributeList with the specified parameters in it.
Definition: Attributes.cpp:1131
FAM
FunctionAnalysisManager FAM
Definition: PassBuilderBindings.cpp:59
llvm::CFL_Definition
@ CFL_Definition
Definition: TypeMetadataUtils.h:32
llvm::ZeroCallUsedRegs::ZeroCallUsedRegsKind::Used
@ Used
Module.h
llvm::ConstantAsMetadata::get
static ConstantAsMetadata * get(Constant *C)
Definition: Metadata.h:420
llvm::Module::global_objects
iterator_range< global_object_iterator > global_objects()
Definition: Module.cpp:414
ModuleSummaryAnalysis.h
llvm::detail::DenseSetImpl< ValueT, DenseMap< ValueT, detail::DenseSetEmpty, DenseMapInfo< ValueT >, detail::DenseSetPair< ValueT > >, DenseMapInfo< ValueT > >::insert
std::pair< iterator, bool > insert(const ValueT &V)
Definition: DenseSet.h:206
BasicAliasAnalysis.h
llvm::detail::DenseSetImpl< ValueT, DenseMap< ValueT, detail::DenseSetEmpty, DenseMapInfo< ValueT >, detail::DenseSetPair< ValueT > >, DenseMapInfo< ValueT > >::count
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
llvm::Type::getInt8Ty
static IntegerType * getInt8Ty(LLVMContext &C)
Definition: Type.cpp:237
llvm::MDNode::get
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Definition: Metadata.h:1400
F
#define F(x, y, z)
Definition: MD5.cpp:55
llvm::collectUsedGlobalVariables
GlobalVariable * collectUsedGlobalVariables(const Module &M, SmallVectorImpl< GlobalValue * > &Vec, bool CompilerUsed)
Given "llvm.used" or "llvm.compiler.used" as a global name, collect the initializer elements of that ...
Definition: Module.cpp:801
llvm::NamedMDNode::addOperand
void addOperand(MDNode *M)
Definition: Metadata.cpp:1222
llvm::ThinLTOBitcodeWriterPass::run
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)
Definition: ThinLTOBitcodeWriter.cpp:552
Constants.h
llvm::AAResults
Definition: AliasAnalysis.h:294
BitcodeWriter.h
Intrinsics.h
C
(vector float) vec_cmpeq(*A, *B) C
Definition: README_ALTIVEC.txt:86
llvm::ARM_PROC::A
@ A
Definition: ARMBaseInfo.h:34
llvm::GlobalObject
Definition: GlobalObject.h:27
TypeMetadataUtils.h
llvm::Value::uses
iterator_range< use_iterator > uses()
Definition: Value.h:376
llvm::dwarf::Index
Index
Definition: Dwarf.h:472
llvm::appendToCompilerUsed
void appendToCompilerUsed(Module &M, ArrayRef< GlobalValue * > Values)
Adds global values to the llvm.compiler.used list.
Definition: ModuleUtils.cpp:111
llvm::CFL_WeakDeclaration
@ CFL_WeakDeclaration
Definition: TypeMetadataUtils.h:34
llvm::Function::copyAttributesFrom
void copyAttributesFrom(const Function *Src)
copyAttributesFrom - copy all additional attributes (those not needed to create a Function) from the ...
Definition: Function.cpp:715
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
llvm::Value::setName
void setName(const Twine &Name)
Change the name of the value.
Definition: Value.cpp:375
llvm::ConstantInt::get
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:879
llvm::Metadata
Root of the metadata hierarchy.
Definition: Metadata.h:62
llvm::Value::use_empty
bool use_empty() const
Definition: Value.h:344
llvm::computeFunctionBodyMemoryAccess
MemoryEffects computeFunctionBodyMemoryAccess(Function &F, AAResults &AAR)
Returns the memory access properties of this copy of the function.
Definition: FunctionAttrs.cpp:233
llvm::ProfileSummaryInfo
Analysis providing profile information.
Definition: ProfileSummaryInfo.h:40
llvm::convertToDeclaration
bool convertToDeclaration(GlobalValue &GV)
Converts value GV to declaration, or replaces with a declaration if it is an alias.
Definition: FunctionImport.cpp:1016
llvm::function_ref
An efficient, type-erasing, non-owning reference to a callable.
Definition: STLFunctionalExtras.h:36
llvm::DenseSet
Implements a dense probed hash-table based set.
Definition: DenseSet.h:268
llvm::GlobalValue
Definition: GlobalValue.h:44
llvm::Constant
This is an important base class in LLVM.
Definition: Constant.h:41
ProfileSummaryInfo.h
IPO.h
llvm::DenseMap
Definition: DenseMap.h:714
DebugInfo.h
I
#define I(x, y, z)
Definition: MD5.cpp:58
Cloning.h
llvm::appendToUsed
void appendToUsed(Module &M, ArrayRef< GlobalValue * > Values)
Adds global values to the llvm.used list.
Definition: ModuleUtils.cpp:107
llvm::make_early_inc_range
iterator_range< early_inc_iterator_impl< detail::IterOfRange< RangeT > > > make_early_inc_range(RangeT &&Range)
Make a range that does early increment to allow mutation of the underlying range without disrupting i...
Definition: STLExtras.h:716
llvm::Module::getOrInsertComdat
Comdat * getOrInsertComdat(StringRef Name)
Return the Comdat in the module with the specified name.
Definition: Module.cpp:583
llvm::MDString::get
static MDString * get(LLVMContext &Context, StringRef Str)
Definition: Metadata.cpp:498
llvm::DenseMapBase< DenseMap< KeyT, ValueT, DenseMapInfo< KeyT >, llvm::detail::DenseMapPair< KeyT, ValueT > >, KeyT, ValueT, DenseMapInfo< KeyT >, llvm::detail::DenseMapPair< KeyT, ValueT > >::find
iterator find(const_arg_type_t< KeyT > Val)
Definition: DenseMap.h:150
llvm::BitcodeWriter
Definition: BitcodeWriter.h:32
llvm::Function::Create
static Function * Create(FunctionType *Ty, LinkageTypes Linkage, unsigned AddrSpace, const Twine &N="", Module *M=nullptr)
Definition: Function.h:137
llvm::MDTuple::get
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Definition: Metadata.h:1357
llvm::Module
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
llvm::MDNode
Metadata node.
Definition: Metadata.h:944
llvm::DenseMapBase< DenseMap< KeyT, ValueT, DenseMapInfo< KeyT >, llvm::detail::DenseMapPair< KeyT, ValueT > >, KeyT, ValueT, DenseMapInfo< KeyT >, llvm::detail::DenseMapPair< KeyT, ValueT > >::empty
bool empty() const
Definition: DenseMap.h:98
llvm::SetVector::insert
bool insert(const value_type &X)
Insert a new element into the SetVector.
Definition: SetVector.h:141
llvm::WriteBitcodeToFile
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.
Definition: BitcodeWriter.cpp:4865
ModuleSymbolTable.h
llvm::Constant::removeDeadConstantUsers
void removeDeadConstantUsers() const
If there are any dead constant users dangling off of this constant, remove them.
Definition: Constants.cpp:702
llvm::logicalview::LVCompareKind::Types
@ Types
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
if
if(llvm_vc STREQUAL "") set(fake_version_inc "$
Definition: CMakeLists.txt:14
uint32_t
llvm::append_range
void append_range(Container &C, Range &&R)
Wrapper function to append a range to a container.
Definition: STLExtras.h:2013
LowerTypeTests.h
llvm::GlobalValue::AvailableExternallyLinkage
@ AvailableExternallyLinkage
Available for inspection, not emission.
Definition: GlobalValue.h:49
llvm::GlobalValue::getAliaseeObject
const GlobalObject * getAliaseeObject() const
Definition: Globals.cpp:360
llvm::Module::Error
@ Error
Emits an error if two values disagree, otherwise the resulting value is that of the operands.
Definition: Module.h:118
llvm::ValueMap< const Value *, WeakTrackingVH >
llvm::CallBase::setArgOperand
void setArgOperand(unsigned i, Value *v)
Definition: InstrTypes.h:1347
llvm::GlobalValue::eraseFromParent
void eraseFromParent()
This method unlinks 'this' from the containing module and deletes it.
Definition: Globals.cpp:88
llvm::Twine
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
llvm::GraphProgram::Name
Name
Definition: GraphWriter.h:50
llvm::ModuleSymbolTable::CollectAsmSymvers
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.
Definition: ModuleSymbolTable.cpp:167
llvm::MetadataAsValue::get
static MetadataAsValue * get(LLVMContext &Context, Metadata *MD)
Definition: Metadata.cpp:103
llvm::DenseMapBase< DenseMap< KeyT, ValueT, DenseMapInfo< KeyT >, llvm::detail::DenseMapPair< KeyT, ValueT > >, KeyT, ValueT, DenseMapInfo< KeyT >, llvm::detail::DenseMapPair< KeyT, ValueT > >::end
iterator end()
Definition: DenseMap.h:84
llvm::AMDGPU::SendMsg::Op
Op
Definition: SIDefines.h:348
llvm::PreservedAnalyses::all
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition: PassManager.h:158
llvm::GlobalValue::getComdat
const Comdat * getComdat() const
Definition: Globals.cpp:176
llvm::DenseMapBase< DenseMap< KeyT, ValueT, DenseMapInfo< KeyT >, llvm::detail::DenseMapPair< KeyT, ValueT > >, KeyT, ValueT, DenseMapInfo< KeyT >, llvm::detail::DenseMapPair< KeyT, ValueT > >::size
unsigned size() const
Definition: DenseMap.h:99
PassManager.h
llvm::SetVector::count
size_type count(const key_type &key) const
Count the number of elements of a given key in the SetVector.
Definition: SetVector.h:215
llvm::getUniqueModuleId
std::string getUniqueModuleId(Module *M)
Produce a unique identifier for this module by taking the MD5 sum of the names of the module's strong...
Definition: ModuleUtils.cpp:210
llvm::buildModuleSummaryIndex
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.
Definition: ModuleSummaryAnalysis.cpp:737
llvm::SmallVectorImpl::clear
void clear()
Definition: SmallVector.h:614
llvm::CfiFunctionLinkage
CfiFunctionLinkage
The type of CFI jumptable needed for a function.
Definition: TypeMetadataUtils.h:31
llvm::writeThinLinkBitcodeToFile
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...
Definition: BitcodeWriter.cpp:5070
llvm::GlobalValue::ExternalLinkage
@ ExternalLinkage
Externally visible function.
Definition: GlobalValue.h:48
llvm::AttributeList::FunctionIndex
@ FunctionIndex
Definition: Attributes.h:434
llvm::Type::getVoidTy
static Type * getVoidTy(LLVMContext &C)
Definition: Type.cpp:222
Instructions.h
llvm::ModuleSummaryIndex
Class to hold module path string table and global value map, and encapsulate methods for operating on...
Definition: ModuleSummaryIndex.h:1199
ModuleUtils.h
llvm::CloneModule
std::unique_ptr< Module > CloneModule(const Module &M)
Return an exact copy of the specified module.
Definition: CloneModule.cpp:37
llvm::CallBase::getArgOperand
Value * getArgOperand(unsigned i) const
Definition: InstrTypes.h:1342
llvm::DenseMapBase< DenseMap< KeyT, ValueT, DenseMapInfo< KeyT >, llvm::detail::DenseMapPair< KeyT, ValueT > >, KeyT, ValueT, DenseMapInfo< KeyT >, llvm::detail::DenseMapPair< KeyT, ValueT > >::try_emplace
std::pair< iterator, bool > try_emplace(KeyT &&Key, Ts &&... Args)
Definition: DenseMap.h:222
llvm::AnalysisManager
A container for analyses that lazily runs them and caches their results.
Definition: InstructionSimplify.h:42
llvm::InnerAnalysisManagerProxy
An analysis over an "outer" IR unit that provides access to an analysis manager over an "inner" IR un...
Definition: PassManager.h:931
llvm::CallInst
This class represents a function call, abstracting a target machine's calling convention.
Definition: Instructions.h:1474
llvm::Value::takeName
void takeName(Value *V)
Transfer the name from V to this value.
Definition: Value.cpp:381
raw_ostream.h
llvm::SetVector
A vector that has set insertion semantics.
Definition: SetVector.h:40
llvm::lowertypetests::isJumpTableCanonical
bool isJumpTableCanonical(Function *F)
Definition: LowerTypeTests.cpp:240
llvm::ModuleHash
std::array< uint32_t, 5 > ModuleHash
160 bits SHA1
Definition: ModuleSummaryIndex.h:1154
llvm::Function::setAttributes
void setAttributes(AttributeList Attrs)
Set the attribute list for this Function.
Definition: Function.h:317
llvm::GlobalValue::setVisibility
void setVisibility(VisibilityTypes V)
Definition: GlobalValue.h:250
InitializePasses.h
llvm::CFL_Declaration
@ CFL_Declaration
Definition: TypeMetadataUtils.h:33
llvm::Value
LLVM Value Representation.
Definition: Value.h:74
FunctionAttrs.h
llvm::Module::getNamedValue
GlobalValue * getNamedValue(StringRef Name) const
Return the global value in the module with the specified name, of arbitrary type.
Definition: Module.cpp:111
llvm::FunctionType
Class to represent function types.
Definition: DerivedTypes.h:103
llvm::Use
A Use represents the edge between a Value definition and its users.
Definition: Use.h:43