LLVM  14.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"
26 #include "llvm/Transforms/IPO.h"
32 using namespace llvm;
33 
34 namespace {
35 
36 // Determine if a promotion alias should be created for a symbol name.
37 static bool allowPromotionAlias(const std::string &Name) {
38  // Promotion aliases are used only in inline assembly. It's safe to
39  // simply skip unusual names. Subset of MCAsmInfo::isAcceptableChar()
40  // and MCAsmInfoXCOFF::isAcceptableChar().
41  for (const char &C : Name) {
42  if (isAlnum(C) || C == '_' || C == '.')
43  continue;
44  return false;
45  }
46  return true;
47 }
48 
49 // Promote each local-linkage entity defined by ExportM and used by ImportM by
50 // changing visibility and appending the given ModuleId.
51 void promoteInternals(Module &ExportM, Module &ImportM, StringRef ModuleId,
52  SetVector<GlobalValue *> &PromoteExtra) {
54  for (auto &ExportGV : ExportM.global_values()) {
55  if (!ExportGV.hasLocalLinkage())
56  continue;
57 
58  auto Name = ExportGV.getName();
59  GlobalValue *ImportGV = nullptr;
60  if (!PromoteExtra.count(&ExportGV)) {
61  ImportGV = ImportM.getNamedValue(Name);
62  if (!ImportGV)
63  continue;
64  ImportGV->removeDeadConstantUsers();
65  if (ImportGV->use_empty()) {
66  ImportGV->eraseFromParent();
67  continue;
68  }
69  }
70 
71  std::string OldName = Name.str();
72  std::string NewName = (Name + ModuleId).str();
73 
74  if (const auto *C = ExportGV.getComdat())
75  if (C->getName() == Name)
76  RenamedComdats.try_emplace(C, ExportM.getOrInsertComdat(NewName));
77 
78  ExportGV.setName(NewName);
79  ExportGV.setLinkage(GlobalValue::ExternalLinkage);
80  ExportGV.setVisibility(GlobalValue::HiddenVisibility);
81 
82  if (ImportGV) {
83  ImportGV->setName(NewName);
85  }
86 
87  if (isa<Function>(&ExportGV) && allowPromotionAlias(OldName)) {
88  // Create a local alias with the original name to avoid breaking
89  // references from inline assembly.
90  std::string Alias = ".set " + 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 *TypeCheckedLoadFunc =
136  M.getFunction(Intrinsic::getName(Intrinsic::type_checked_load))) {
137  for (const Use &U : TypeCheckedLoadFunc->uses()) {
138  auto CI = cast<CallInst>(U.getUser());
139  ExternalizeTypeId(CI, 2);
140  }
141  }
142 
143  for (GlobalObject &GO : M.global_objects()) {
145  GO.getMetadata(LLVMContext::MD_type, MDs);
146 
147  GO.eraseMetadata(LLVMContext::MD_type);
148  for (auto MD : MDs) {
149  auto I = LocalToGlobal.find(MD->getOperand(1));
150  if (I == LocalToGlobal.end()) {
151  GO.addMetadata(LLVMContext::MD_type, *MD);
152  continue;
153  }
154  GO.addMetadata(
155  LLVMContext::MD_type,
156  *MDNode::get(M.getContext(), {MD->getOperand(0), I->second}));
157  }
158  }
159 }
160 
161 // Drop unused globals, and drop type information from function declarations.
162 // FIXME: If we made functions typeless then there would be no need to do this.
163 void simplifyExternals(Module &M) {
164  FunctionType *EmptyFT =
165  FunctionType::get(Type::getVoidTy(M.getContext()), false);
166 
168  if (F.isDeclaration() && F.use_empty()) {
169  F.eraseFromParent();
170  continue;
171  }
172 
173  if (!F.isDeclaration() || F.getFunctionType() == EmptyFT ||
174  // Changing the type of an intrinsic may invalidate the IR.
175  F.getName().startswith("llvm."))
176  continue;
177 
178  Function *NewF =
180  F.getAddressSpace(), "", &M);
181  NewF->copyAttributesFrom(&F);
182  // Only copy function attribtues.
183  NewF->setAttributes(AttributeList::get(M.getContext(),
185  F.getAttributes().getFnAttrs()));
186  NewF->takeName(&F);
187  F.replaceAllUsesWith(ConstantExpr::getBitCast(NewF, F.getType()));
188  F.eraseFromParent();
189  }
190 
191  for (GlobalVariable &GV : llvm::make_early_inc_range(M.globals())) {
192  if (GV.isDeclaration() && GV.use_empty()) {
193  GV.eraseFromParent();
194  continue;
195  }
196  }
197 }
198 
199 static void
200 filterModule(Module *M,
201  function_ref<bool(const GlobalValue *)> ShouldKeepDefinition) {
202  std::vector<GlobalValue *> V;
203  for (GlobalValue &GV : M->global_values())
204  if (!ShouldKeepDefinition(&GV))
205  V.push_back(&GV);
206 
207  for (GlobalValue *GV : V)
208  if (!convertToDeclaration(*GV))
209  GV->eraseFromParent();
210 }
211 
212 void forEachVirtualFunction(Constant *C, function_ref<void(Function *)> Fn) {
213  if (auto *F = dyn_cast<Function>(C))
214  return Fn(F);
215  if (isa<GlobalValue>(C))
216  return;
217  for (Value *Op : C->operands())
218  forEachVirtualFunction(cast<Constant>(Op), Fn);
219 }
220 
221 // Clone any @llvm[.compiler].used over to the new module and append
222 // values whose defs were cloned into that module.
223 static void cloneUsedGlobalVariables(const Module &SrcM, Module &DestM,
224  bool CompilerUsed) {
225  SmallVector<GlobalValue *, 4> Used, NewUsed;
226  // First collect those in the llvm[.compiler].used set.
227  collectUsedGlobalVariables(SrcM, Used, CompilerUsed);
228  // Next build a set of the equivalent values defined in DestM.
229  for (auto *V : Used) {
230  auto *GV = DestM.getNamedValue(V->getName());
231  if (GV && !GV->isDeclaration())
232  NewUsed.push_back(GV);
233  }
234  // Finally, add them to a llvm[.compiler].used variable in DestM.
235  if (CompilerUsed)
236  appendToCompilerUsed(DestM, NewUsed);
237  else
238  appendToUsed(DestM, NewUsed);
239 }
240 
241 // If it's possible to split M into regular and thin LTO parts, do so and write
242 // a multi-module bitcode file with the two parts to OS. Otherwise, write only a
243 // regular LTO bitcode file to OS.
244 void splitAndWriteThinLTOBitcode(
245  raw_ostream &OS, raw_ostream *ThinLinkOS,
246  function_ref<AAResults &(Function &)> AARGetter, Module &M) {
247  std::string ModuleId = getUniqueModuleId(&M);
248  if (ModuleId.empty()) {
249  // We couldn't generate a module ID for this module, write it out as a
250  // regular LTO module with an index for summary-based dead stripping.
251  ProfileSummaryInfo PSI(M);
252  M.addModuleFlag(Module::Error, "ThinLTO", uint32_t(0));
254  WriteBitcodeToFile(M, OS, /*ShouldPreserveUseListOrder=*/false, &Index);
255 
256  if (ThinLinkOS)
257  // We don't have a ThinLTO part, but still write the module to the
258  // ThinLinkOS if requested so that the expected output file is produced.
259  WriteBitcodeToFile(M, *ThinLinkOS, /*ShouldPreserveUseListOrder=*/false,
260  &Index);
261 
262  return;
263  }
264 
265  promoteTypeIds(M, ModuleId);
266 
267  // Returns whether a global or its associated global has attached type
268  // metadata. The former may participate in CFI or whole-program
269  // devirtualization, so they need to appear in the merged module instead of
270  // the thin LTO module. Similarly, globals that are associated with globals
271  // with type metadata need to appear in the merged module because they will
272  // reference the global's section directly.
273  auto HasTypeMetadata = [](const GlobalObject *GO) {
274  if (MDNode *MD = GO->getMetadata(LLVMContext::MD_associated))
275  if (auto *AssocVM = dyn_cast_or_null<ValueAsMetadata>(MD->getOperand(0)))
276  if (auto *AssocGO = dyn_cast<GlobalObject>(AssocVM->getValue()))
277  if (AssocGO->hasMetadata(LLVMContext::MD_type))
278  return true;
279  return GO->hasMetadata(LLVMContext::MD_type);
280  };
281 
282  // Collect the set of virtual functions that are eligible for virtual constant
283  // propagation. Each eligible function must not access memory, must return
284  // an integer of width <=64 bits, must take at least one argument, must not
285  // use its first argument (assumed to be "this") and all arguments other than
286  // the first one must be of <=64 bit integer type.
287  //
288  // Note that we test whether this copy of the function is readnone, rather
289  // than testing function attributes, which must hold for any copy of the
290  // function, even a less optimized version substituted at link time. This is
291  // sound because the virtual constant propagation optimizations effectively
292  // inline all implementations of the virtual function into each call site,
293  // rather than using function attributes to perform local optimization.
294  DenseSet<const Function *> EligibleVirtualFns;
295  // If any member of a comdat lives in MergedM, put all members of that
296  // comdat in MergedM to keep the comdat together.
297  DenseSet<const Comdat *> MergedMComdats;
298  for (GlobalVariable &GV : M.globals())
299  if (HasTypeMetadata(&GV)) {
300  if (const auto *C = GV.getComdat())
301  MergedMComdats.insert(C);
302  forEachVirtualFunction(GV.getInitializer(), [&](Function *F) {
303  auto *RT = dyn_cast<IntegerType>(F->getReturnType());
304  if (!RT || RT->getBitWidth() > 64 || F->arg_empty() ||
305  !F->arg_begin()->use_empty())
306  return;
307  for (auto &Arg : drop_begin(F->args())) {
308  auto *ArgT = dyn_cast<IntegerType>(Arg.getType());
309  if (!ArgT || ArgT->getBitWidth() > 64)
310  return;
311  }
312  if (!F->isDeclaration() &&
314  EligibleVirtualFns.insert(F);
315  });
316  }
317 
318  ValueToValueMapTy VMap;
319  std::unique_ptr<Module> MergedM(
320  CloneModule(M, VMap, [&](const GlobalValue *GV) -> bool {
321  if (const auto *C = GV->getComdat())
322  if (MergedMComdats.count(C))
323  return true;
324  if (auto *F = dyn_cast<Function>(GV))
325  return EligibleVirtualFns.count(F);
326  if (auto *GVar = dyn_cast_or_null<GlobalVariable>(GV->getBaseObject()))
327  return HasTypeMetadata(GVar);
328  return false;
329  }));
330  StripDebugInfo(*MergedM);
331  MergedM->setModuleInlineAsm("");
332 
333  // Clone any llvm.*used globals to ensure the included values are
334  // not deleted.
335  cloneUsedGlobalVariables(M, *MergedM, /*CompilerUsed*/ false);
336  cloneUsedGlobalVariables(M, *MergedM, /*CompilerUsed*/ true);
337 
338  for (Function &F : *MergedM)
339  if (!F.isDeclaration()) {
340  // Reset the linkage of all functions eligible for virtual constant
341  // propagation. The canonical definitions live in the thin LTO module so
342  // that they can be imported.
344  F.setComdat(nullptr);
345  }
346 
347  SetVector<GlobalValue *> CfiFunctions;
348  for (auto &F : M)
349  if ((!F.hasLocalLinkage() || F.hasAddressTaken()) && HasTypeMetadata(&F))
350  CfiFunctions.insert(&F);
351 
352  // Remove all globals with type metadata, globals with comdats that live in
353  // MergedM, and aliases pointing to such globals from the thin LTO module.
354  filterModule(&M, [&](const GlobalValue *GV) {
355  if (auto *GVar = dyn_cast_or_null<GlobalVariable>(GV->getBaseObject()))
356  if (HasTypeMetadata(GVar))
357  return false;
358  if (const auto *C = GV->getComdat())
359  if (MergedMComdats.count(C))
360  return false;
361  return true;
362  });
363 
364  promoteInternals(*MergedM, M, ModuleId, CfiFunctions);
365  promoteInternals(M, *MergedM, ModuleId, CfiFunctions);
366 
367  auto &Ctx = MergedM->getContext();
368  SmallVector<MDNode *, 8> CfiFunctionMDs;
369  for (auto V : CfiFunctions) {
370  Function &F = *cast<Function>(V);
372  F.getMetadata(LLVMContext::MD_type, Types);
373 
375  Elts.push_back(MDString::get(Ctx, F.getName()));
379  else if (F.hasExternalWeakLinkage())
381  else
383  Elts.push_back(ConstantAsMetadata::get(
385  append_range(Elts, Types);
386  CfiFunctionMDs.push_back(MDTuple::get(Ctx, Elts));
387  }
388 
389  if(!CfiFunctionMDs.empty()) {
390  NamedMDNode *NMD = MergedM->getOrInsertNamedMetadata("cfi.functions");
391  for (auto MD : CfiFunctionMDs)
392  NMD->addOperand(MD);
393  }
394 
395  SmallVector<MDNode *, 8> FunctionAliases;
396  for (auto &A : M.aliases()) {
397  if (!isa<Function>(A.getAliasee()))
398  continue;
399 
400  auto *F = cast<Function>(A.getAliasee());
401 
402  Metadata *Elts[] = {
403  MDString::get(Ctx, A.getName()),
404  MDString::get(Ctx, F->getName()),
406  ConstantInt::get(Type::getInt8Ty(Ctx), A.getVisibility())),
408  ConstantInt::get(Type::getInt8Ty(Ctx), A.isWeakForLinker())),
409  };
410 
411  FunctionAliases.push_back(MDTuple::get(Ctx, Elts));
412  }
413 
414  if (!FunctionAliases.empty()) {
415  NamedMDNode *NMD = MergedM->getOrInsertNamedMetadata("aliases");
416  for (auto MD : FunctionAliases)
417  NMD->addOperand(MD);
418  }
419 
420  SmallVector<MDNode *, 8> Symvers;
422  Function *F = M.getFunction(Name);
423  if (!F || F->use_empty())
424  return;
425 
426  Symvers.push_back(MDTuple::get(
427  Ctx, {MDString::get(Ctx, Name), MDString::get(Ctx, Alias)}));
428  });
429 
430  if (!Symvers.empty()) {
431  NamedMDNode *NMD = MergedM->getOrInsertNamedMetadata("symvers");
432  for (auto MD : Symvers)
433  NMD->addOperand(MD);
434  }
435 
436  simplifyExternals(*MergedM);
437 
438  // FIXME: Try to re-use BSI and PFI from the original module here.
439  ProfileSummaryInfo PSI(M);
441 
442  // Mark the merged module as requiring full LTO. We still want an index for
443  // it though, so that it can participate in summary-based dead stripping.
444  MergedM->addModuleFlag(Module::Error, "ThinLTO", uint32_t(0));
445  ModuleSummaryIndex MergedMIndex =
446  buildModuleSummaryIndex(*MergedM, nullptr, &PSI);
447 
448  SmallVector<char, 0> Buffer;
449 
450  BitcodeWriter W(Buffer);
451  // Save the module hash produced for the full bitcode, which will
452  // be used in the backends, and use that in the minimized bitcode
453  // produced for the full link.
454  ModuleHash ModHash = {{0}};
455  W.writeModule(M, /*ShouldPreserveUseListOrder=*/false, &Index,
456  /*GenerateHash=*/true, &ModHash);
457  W.writeModule(*MergedM, /*ShouldPreserveUseListOrder=*/false, &MergedMIndex);
458  W.writeSymtab();
459  W.writeStrtab();
460  OS << Buffer;
461 
462  // If a minimized bitcode module was requested for the thin link, only
463  // the information that is needed by thin link will be written in the
464  // given OS (the merged module will be written as usual).
465  if (ThinLinkOS) {
466  Buffer.clear();
467  BitcodeWriter W2(Buffer);
468  StripDebugInfo(M);
469  W2.writeThinLinkBitcode(M, Index, ModHash);
470  W2.writeModule(*MergedM, /*ShouldPreserveUseListOrder=*/false,
471  &MergedMIndex);
472  W2.writeSymtab();
473  W2.writeStrtab();
474  *ThinLinkOS << Buffer;
475  }
476 }
477 
478 // Check if the LTO Unit splitting has been enabled.
479 bool enableSplitLTOUnit(Module &M) {
480  bool EnableSplitLTOUnit = false;
481  if (auto *MD = mdconst::extract_or_null<ConstantInt>(
482  M.getModuleFlag("EnableSplitLTOUnit")))
483  EnableSplitLTOUnit = MD->getZExtValue();
484  return EnableSplitLTOUnit;
485 }
486 
487 // Returns whether this module needs to be split because it uses type metadata.
488 bool hasTypeMetadata(Module &M) {
489  for (auto &GO : M.global_objects()) {
490  if (GO.hasMetadata(LLVMContext::MD_type))
491  return true;
492  }
493  return false;
494 }
495 
496 void writeThinLTOBitcode(raw_ostream &OS, raw_ostream *ThinLinkOS,
497  function_ref<AAResults &(Function &)> AARGetter,
498  Module &M, const ModuleSummaryIndex *Index) {
499  std::unique_ptr<ModuleSummaryIndex> NewIndex = nullptr;
500  // See if this module has any type metadata. If so, we try to split it
501  // or at least promote type ids to enable WPD.
502  if (hasTypeMetadata(M)) {
503  if (enableSplitLTOUnit(M))
504  return splitAndWriteThinLTOBitcode(OS, ThinLinkOS, AARGetter, M);
505  // Promote type ids as needed for index-based WPD.
506  std::string ModuleId = getUniqueModuleId(&M);
507  if (!ModuleId.empty()) {
508  promoteTypeIds(M, ModuleId);
509  // Need to rebuild the index so that it contains type metadata
510  // for the newly promoted type ids.
511  // FIXME: Probably should not bother building the index at all
512  // in the caller of writeThinLTOBitcode (which does so via the
513  // ModuleSummaryIndexAnalysis pass), since we have to rebuild it
514  // anyway whenever there is type metadata (here or in
515  // splitAndWriteThinLTOBitcode). Just always build it once via the
516  // buildModuleSummaryIndex when Module(s) are ready.
517  ProfileSummaryInfo PSI(M);
518  NewIndex = std::make_unique<ModuleSummaryIndex>(
519  buildModuleSummaryIndex(M, nullptr, &PSI));
520  Index = NewIndex.get();
521  }
522  }
523 
524  // Write it out as an unsplit ThinLTO module.
525 
526  // Save the module hash produced for the full bitcode, which will
527  // be used in the backends, and use that in the minimized bitcode
528  // produced for the full link.
529  ModuleHash ModHash = {{0}};
530  WriteBitcodeToFile(M, OS, /*ShouldPreserveUseListOrder=*/false, Index,
531  /*GenerateHash=*/true, &ModHash);
532  // If a minimized bitcode module was requested for the thin link, only
533  // the information that is needed by thin link will be written in the
534  // given OS.
535  if (ThinLinkOS && Index)
536  WriteThinLinkBitcodeToFile(M, *ThinLinkOS, *Index, ModHash);
537 }
538 
539 class WriteThinLTOBitcode : public ModulePass {
540  raw_ostream &OS; // raw_ostream to print on
541  // The output stream on which to emit a minimized module for use
542  // just in the thin link, if requested.
543  raw_ostream *ThinLinkOS;
544 
545 public:
546  static char ID; // Pass identification, replacement for typeid
547  WriteThinLTOBitcode() : ModulePass(ID), OS(dbgs()), ThinLinkOS(nullptr) {
549  }
550 
551  explicit WriteThinLTOBitcode(raw_ostream &o, raw_ostream *ThinLinkOS)
552  : ModulePass(ID), OS(o), ThinLinkOS(ThinLinkOS) {
554  }
555 
556  StringRef getPassName() const override { return "ThinLTO Bitcode Writer"; }
557 
558  bool runOnModule(Module &M) override {
559  const ModuleSummaryIndex *Index =
560  &(getAnalysis<ModuleSummaryIndexWrapperPass>().getIndex());
561  writeThinLTOBitcode(OS, ThinLinkOS, LegacyAARGetter(*this), M, Index);
562  return true;
563  }
564  void getAnalysisUsage(AnalysisUsage &AU) const override {
565  AU.setPreservesAll();
569  }
570 };
571 } // anonymous namespace
572 
573 char WriteThinLTOBitcode::ID = 0;
574 INITIALIZE_PASS_BEGIN(WriteThinLTOBitcode, "write-thinlto-bitcode",
575  "Write ThinLTO Bitcode", false, true)
579 INITIALIZE_PASS_END(WriteThinLTOBitcode, "write-thinlto-bitcode",
580  "Write ThinLTO Bitcode", false, true)
581 
583  raw_ostream *ThinLinkOS) {
584  return new WriteThinLTOBitcode(Str, ThinLinkOS);
585 }
586 
591  writeThinLTOBitcode(OS, ThinLinkOS,
592  [&FAM](Function &F) -> AAResults & {
593  return FAM.getResult<AAManager>(F);
594  },
596  return PreservedAnalyses::all();
597 }
llvm::Module::global_values
iterator_range< global_value_iterator > global_values()
Definition: Module.cpp:424
llvm::PreservedAnalyses
A set of analyses that are preserved following a run of a transformation pass.
Definition: PassManager.h:155
llvm::Module::appendModuleInlineAsm
void appendModuleInlineAsm(StringRef Asm)
Append to the module-scope inline assembly blocks.
Definition: Module.h:312
llvm::AAManager
A manager for alias analyses.
Definition: AliasAnalysis.h:1233
ThinLTOBitcodeWriter.h
llvm::StripDebugInfo
bool StripDebugInfo(Module &M)
Strip debug info in the module if it exists.
Definition: DebugInfo.cpp:476
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
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:1396
llvm::ModulePass
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
Definition: Pass.h:238
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:779
INITIALIZE_PASS_BEGIN
INITIALIZE_PASS_BEGIN(WriteThinLTOBitcode, "write-thinlto-bitcode", "Write ThinLTO Bitcode", false, true) INITIALIZE_PASS_END(WriteThinLTOBitcode
llvm::GlobalValue::HiddenVisibility
@ HiddenVisibility
The GV is hidden.
Definition: GlobalValue.h:64
llvm::Function
Definition: Function.h:61
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:1168
llvm::RISCVFenceField::W
@ W
Definition: RISCVBaseInfo.h:194
FunctionImport.h
llvm::ModuleSummaryIndexAnalysis
Analysis pass to provide the ModuleSummaryIndex object.
Definition: ModuleSummaryAnalysis.h:44
llvm::Intrinsic::getName
StringRef getName(ID id)
Return the LLVM name for an intrinsic, such as "llvm.ppc.altivec.lvx".
Definition: Function.cpp:879
llvm::GlobalVariable
Definition: GlobalVariable.h:40
llvm::ConstantExpr::getBitCast
static Constant * getBitCast(Constant *C, Type *Ty, bool OnlyIfReduced=false)
Definition: Constants.cpp:2208
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:325
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:1040
FAM
FunctionAnalysisManager FAM
Definition: PassBuilderBindings.cpp:59
llvm::CFL_Definition
@ CFL_Definition
Definition: TypeMetadataUtils.h:31
Module.h
llvm::ConstantAsMetadata::get
static ConstantAsMetadata * get(Constant *C)
Definition: Metadata.h:419
llvm::Module::global_objects
iterator_range< global_object_iterator > global_objects()
Definition: Module.cpp:416
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:201
llvm::MDNode::get
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Definition: Metadata.h:1208
F
#define F(x, y, z)
Definition: MD5.cpp:56
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:778
llvm::dbgs
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:163
llvm::NamedMDNode::addOperand
void addOperand(MDNode *M)
Definition: Metadata.cpp:1130
llvm::initializeWriteThinLTOBitcodePass
void initializeWriteThinLTOBitcodePass(PassRegistry &)
llvm::PassRegistry::getPassRegistry
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
Definition: PassRegistry.cpp:31
llvm::ThinLTOBitcodeWriterPass::run
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)
Definition: ThinLTOBitcodeWriter.cpp:588
Constants.h
llvm::AAResults
Definition: AliasAnalysis.h:456
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:28
TypeMetadataUtils.h
llvm::AnalysisUsage
Represent the analysis usage information of a pass.
Definition: PassAnalysisSupport.h:47
bitcode
write thinlto bitcode
Definition: ThinLTOBitcodeWriter.cpp:579
llvm::Value::uses
iterator_range< use_iterator > uses()
Definition: Value.h:377
false
Definition: StackSlotColoring.cpp:142
llvm::appendToCompilerUsed
void appendToCompilerUsed(Module &M, ArrayRef< GlobalValue * > Values)
Adds global values to the llvm.compiler.used list.
Definition: ModuleUtils.cpp:110
llvm::CFL_WeakDeclaration
@ CFL_WeakDeclaration
Definition: TypeMetadataUtils.h:33
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:712
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:376
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:900
llvm::computeFunctionBodyMemoryAccess
MemoryAccessKind computeFunctionBodyMemoryAccess(Function &F, AAResults &AAR)
Returns the memory access properties of this copy of the function.
Definition: FunctionAttrs.cpp:235
llvm::Metadata
Root of the metadata hierarchy.
Definition: Metadata.h:62
llvm::Value::use_empty
bool use_empty() const
Definition: Value.h:345
INITIALIZE_PASS_END
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
Definition: PassSupport.h:58
llvm::ProfileSummaryInfo
Analysis providing profile information.
Definition: ProfileSummaryInfo.h:39
llvm::convertToDeclaration
bool convertToDeclaration(GlobalValue &GV)
Converts value GV to declaration, or replaces with a declaration if it is an alias.
Definition: FunctionImport.cpp:1009
llvm::function_ref
An efficient, type-erasing, non-owning reference to a callable.
Definition: STLExtras.h:168
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
Index
uint32_t Index
Definition: ELFObjHandler.cpp:84
llvm::TargetLibraryInfoWrapperPass
Definition: TargetLibraryInfo.h:463
ProfileSummaryInfo.h
INITIALIZE_PASS_DEPENDENCY
INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
IPO.h
llvm::DenseMap
Definition: DenseMap.h:714
DebugInfo.h
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:4844
I
#define I(x, y, z)
Definition: MD5.cpp:59
Cloning.h
llvm::appendToUsed
void appendToUsed(Module &M, ArrayRef< GlobalValue * > Values)
Adds global values to the llvm.used list.
Definition: ModuleUtils.cpp:106
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:576
llvm::Module::getOrInsertComdat
Comdat * getOrInsertComdat(StringRef Name)
Return the Comdat in the module with the specified name.
Definition: Module.cpp:585
llvm::MDString::get
static MDString * get(LLVMContext &Context, StringRef Str)
Definition: Metadata.cpp:473
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:138
llvm::MDTuple::get
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Definition: Metadata.h:1175
llvm::Module
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:67
llvm::MDNode
Metadata node.
Definition: Metadata.h:906
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:4639
ModuleSymbolTable.h
llvm::AssumptionCacheTracker
An immutable pass that tracks lazily created AssumptionCache objects.
Definition: AssumptionCache.h:200
llvm::Constant::removeDeadConstantUsers
void removeDeadConstantUsers() const
If there are any dead constant users dangling off of this constant, remove them.
Definition: Constants.cpp:741
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
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:1748
LowerTypeTests.h
llvm::GlobalValue::AvailableExternallyLinkage
@ AvailableExternallyLinkage
Available for inspection, not emission.
Definition: GlobalValue.h:49
llvm::Module::Error
@ Error
Emits an error if two values disagree, otherwise the resulting value is that of the operands.
Definition: Module.h:120
llvm::ValueMap< const Value *, WeakTrackingVH >
llvm::CallBase::setArgOperand
void setArgOperand(unsigned i, Value *v)
Definition: InstrTypes.h:1343
llvm::GlobalValue::eraseFromParent
void eraseFromParent()
This method unlinks 'this' from the containing module and deletes it.
Definition: Globals.cpp:86
llvm::DenseMapBase< DenseMap< KeyT, ValueT, DenseMapInfo< KeyT >, llvm::detail::DenseMapPair< KeyT, ValueT > >, KeyT, ValueT, DenseMapInfo< KeyT >, llvm::detail::DenseMapPair< KeyT, ValueT > >::empty
LLVM_NODISCARD bool empty() const
Definition: DenseMap.h:97
llvm::Twine
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:83
llvm::GraphProgram::Name
Name
Definition: GraphWriter.h:52
llvm::AnalysisUsage::setPreservesAll
void setPreservesAll()
Set by analyses that do not transform their input at all.
Definition: PassAnalysisSupport.h:130
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:170
llvm::MetadataAsValue::get
static MetadataAsValue * get(LLVMContext &Context, Metadata *MD)
Definition: Metadata.cpp:106
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:83
llvm::AMDGPU::SendMsg::Op
Op
Definition: SIDefines.h:321
llvm::PreservedAnalyses::all
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition: PassManager.h:161
llvm::GlobalValue::getComdat
const Comdat * getComdat() const
Definition: Globals.cpp:172
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:100
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:244
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:658
llvm::SmallVectorImpl::clear
void clear()
Definition: SmallVector.h:585
llvm::CfiFunctionLinkage
CfiFunctionLinkage
The type of CFI jumptable needed for a function.
Definition: TypeMetadataUtils.h:30
llvm::GlobalValue::getBaseObject
const GlobalObject * getBaseObject() const
Definition: Globals.cpp:283
llvm::GlobalValue::ExternalLinkage
@ ExternalLinkage
Externally visible function.
Definition: GlobalValue.h:48
llvm::MAK_ReadNone
@ MAK_ReadNone
Definition: FunctionAttrs.h:32
llvm::AttributeList::FunctionIndex
@ FunctionIndex
Definition: Attributes.h:402
llvm::Type::getVoidTy
static Type * getVoidTy(LLVMContext &C)
Definition: Type.cpp:186
Instructions.h
llvm::ModuleSummaryIndex
Class to hold module path string table and global value map, and encapsulate methods for operating on...
Definition: ModuleSummaryIndex.h:1028
ModuleUtils.h
llvm::CloneModule
std::unique_ptr< Module > CloneModule(const Module &M)
Return an exact copy of the specified module.
Definition: CloneModule.cpp:34
llvm::CallBase::getArgOperand
Value * getArgOperand(unsigned i) const
Definition: InstrTypes.h:1338
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::createWriteThinLTOBitcodePass
ModulePass * createWriteThinLTOBitcodePass(raw_ostream &Str, raw_ostream *ThinLinkOS=nullptr)
Write ThinLTO-ready bitcode to Str.
Definition: ThinLTOBitcodeWriter.cpp:582
llvm::AnalysisManager
A container for analyses that lazily runs them and caches their results.
Definition: InstructionSimplify.h:44
llvm::InnerAnalysisManagerProxy
An analysis over an "outer" IR unit that provides access to an analysis manager over an "inner" IR un...
Definition: PassManager.h:936
llvm::CallInst
This class represents a function call, abstracting a target machine's calling convention.
Definition: Instructions.h:1475
llvm::AnalysisUsage::addRequired
AnalysisUsage & addRequired()
Definition: PassAnalysisSupport.h:75
llvm::ModuleSummaryIndexWrapperPass
Legacy wrapper pass to provide the ModuleSummaryIndex object.
Definition: ModuleSummaryAnalysis.h:57
llvm::Value::takeName
void takeName(Value *V)
Transfer the name from V to this value.
Definition: Value.cpp:382
raw_ostream.h
llvm::SetVector
A vector that has set insertion semantics.
Definition: SetVector.h:40
true
basic Basic Alias true
Definition: BasicAliasAnalysis.cpp:1815
llvm::lowertypetests::isJumpTableCanonical
bool isJumpTableCanonical(Function *F)
Definition: LowerTypeTests.cpp:239
llvm::ModuleHash
std::array< uint32_t, 5 > ModuleHash
160 bits SHA1
Definition: ModuleSummaryIndex.h:983
llvm::Function::setAttributes
void setAttributes(AttributeList Attrs)
Set the attribute list for this Function.
Definition: Function.h:329
llvm::LegacyAARGetter
This class is a functor to be used in legacy module or SCC passes for computing AA results for a func...
Definition: BasicAliasAnalysis.h:271
llvm::GlobalValue::setVisibility
void setVisibility(VisibilityTypes V)
Definition: GlobalValue.h:235
InitializePasses.h
llvm::CFL_Declaration
@ CFL_Declaration
Definition: TypeMetadataUtils.h:32
llvm::Value
LLVM Value Representation.
Definition: Value.h:75
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:113
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:44
write
static void write(bool isBE, void *P, T V)
Definition: RuntimeDyldELF.cpp:37
Bitcode
write thinlto Write ThinLTO Bitcode
Definition: ThinLTOBitcodeWriter.cpp:580
llvm::Intrinsic::ID
unsigned ID
Definition: TargetTransformInfo.h:37
ScopedPrinter.h