LLVM  15.0.0git
Attributor.cpp
Go to the documentation of this file.
1 //===- Attributor.cpp - Module-wide attribute deduction -------------------===//
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 //
9 // This file implements an interprocedural pass that deduces and/or propagates
10 // attributes. This is done in an abstract interpretation style fixpoint
11 // iteration. See the Attributor.h file comment and the class descriptions in
12 // that file for more information.
13 //
14 //===----------------------------------------------------------------------===//
15 
17 
19 #include "llvm/ADT/STLExtras.h"
20 #include "llvm/ADT/Statistic.h"
21 #include "llvm/ADT/TinyPtrVector.h"
28 #include "llvm/IR/Attributes.h"
29 #include "llvm/IR/Constant.h"
30 #include "llvm/IR/Constants.h"
31 #include "llvm/IR/GlobalValue.h"
32 #include "llvm/IR/GlobalVariable.h"
33 #include "llvm/IR/Instruction.h"
34 #include "llvm/IR/Instructions.h"
35 #include "llvm/IR/IntrinsicInst.h"
36 #include "llvm/IR/ValueHandle.h"
37 #include "llvm/InitializePasses.h"
38 #include "llvm/Support/Casting.h"
40 #include "llvm/Support/Debug.h"
48 
49 #ifdef EXPENSIVE_CHECKS
50 #include "llvm/IR/Verifier.h"
51 #endif
52 
53 #include <cassert>
54 #include <string>
55 
56 using namespace llvm;
57 
58 #define DEBUG_TYPE "attributor"
59 
60 DEBUG_COUNTER(ManifestDBGCounter, "attributor-manifest",
61  "Determine what attributes are manifested in the IR");
62 
63 STATISTIC(NumFnDeleted, "Number of function deleted");
64 STATISTIC(NumFnWithExactDefinition,
65  "Number of functions with exact definitions");
66 STATISTIC(NumFnWithoutExactDefinition,
67  "Number of functions without exact definitions");
68 STATISTIC(NumFnShallowWrappersCreated, "Number of shallow wrappers created");
69 STATISTIC(NumAttributesTimedOut,
70  "Number of abstract attributes timed out before fixpoint");
71 STATISTIC(NumAttributesValidFixpoint,
72  "Number of abstract attributes in a valid fixpoint state");
73 STATISTIC(NumAttributesManifested,
74  "Number of abstract attributes manifested in IR");
75 
76 // TODO: Determine a good default value.
77 //
78 // In the LLVM-TS and SPEC2006, 32 seems to not induce compile time overheads
79 // (when run with the first 5 abstract attributes). The results also indicate
80 // that we never reach 32 iterations but always find a fixpoint sooner.
81 //
82 // This will become more evolved once we perform two interleaved fixpoint
83 // iterations: bottom-up and top-down.
84 static cl::opt<unsigned>
85  SetFixpointIterations("attributor-max-iterations", cl::Hidden,
86  cl::desc("Maximal number of fixpoint iterations."),
87  cl::init(32));
88 
90  "attributor-max-initialization-chain-length", cl::Hidden,
91  cl::desc(
92  "Maximal number of chained initializations (to avoid stack overflows)"),
95 
97  "attributor-max-iterations-verify", cl::Hidden,
98  cl::desc("Verify that max-iterations is a tight bound for a fixpoint"),
99  cl::init(false));
100 
102  "attributor-annotate-decl-cs", cl::Hidden,
103  cl::desc("Annotate call sites of function declarations."), cl::init(false));
104 
105 static cl::opt<bool> EnableHeapToStack("enable-heap-to-stack-conversion",
106  cl::init(true), cl::Hidden);
107 
108 static cl::opt<bool>
109  AllowShallowWrappers("attributor-allow-shallow-wrappers", cl::Hidden,
110  cl::desc("Allow the Attributor to create shallow "
111  "wrappers for non-exact definitions."),
112  cl::init(false));
113 
114 static cl::opt<bool>
115  AllowDeepWrapper("attributor-allow-deep-wrappers", cl::Hidden,
116  cl::desc("Allow the Attributor to use IP information "
117  "derived from non-exact functions via cloning"),
118  cl::init(false));
119 
120 // These options can only used for debug builds.
121 #ifndef NDEBUG
123  SeedAllowList("attributor-seed-allow-list", cl::Hidden,
124  cl::desc("Comma seperated list of attribute names that are "
125  "allowed to be seeded."),
127 
129  "attributor-function-seed-allow-list", cl::Hidden,
130  cl::desc("Comma seperated list of function names that are "
131  "allowed to be seeded."),
133 #endif
134 
135 static cl::opt<bool>
136  DumpDepGraph("attributor-dump-dep-graph", cl::Hidden,
137  cl::desc("Dump the dependency graph to dot files."),
138  cl::init(false));
139 
141  "attributor-depgraph-dot-filename-prefix", cl::Hidden,
142  cl::desc("The prefix used for the CallGraph dot file names."));
143 
144 static cl::opt<bool> ViewDepGraph("attributor-view-dep-graph", cl::Hidden,
145  cl::desc("View the dependency graph."),
146  cl::init(false));
147 
148 static cl::opt<bool> PrintDependencies("attributor-print-dep", cl::Hidden,
149  cl::desc("Print attribute dependencies"),
150  cl::init(false));
151 
153  "attributor-enable-call-site-specific-deduction", cl::Hidden,
154  cl::desc("Allow the Attributor to do call site specific analysis"),
155  cl::init(false));
156 
157 static cl::opt<bool>
158  PrintCallGraph("attributor-print-call-graph", cl::Hidden,
159  cl::desc("Print Attributor's internal call graph"),
160  cl::init(false));
161 
162 static cl::opt<bool> SimplifyAllLoads("attributor-simplify-all-loads",
163  cl::Hidden,
164  cl::desc("Try to simplify all loads."),
165  cl::init(true));
166 
167 /// Logic operators for the change status enum class.
168 ///
169 ///{
171  return L == ChangeStatus::CHANGED ? L : R;
172 }
174  L = L | R;
175  return L;
176 }
178  return L == ChangeStatus::UNCHANGED ? L : R;
179 }
181  L = L & R;
182  return L;
183 }
184 ///}
185 
187  const AbstractAttribute &QueryingAA) {
188  // We are looking for volatile instructions or non-relaxed atomics.
189  if (const auto *CB = dyn_cast<CallBase>(&I)) {
190  if (CB->hasFnAttr(Attribute::NoSync))
191  return true;
192 
193  // Non-convergent and readnone imply nosync.
194  if (!CB->isConvergent() && !CB->mayReadOrWriteMemory())
195  return true;
196 
198  return true;
199 
200  const auto &NoSyncAA = A.getAAFor<AANoSync>(
202  return NoSyncAA.isAssumedNoSync();
203  }
204 
205  if (!I.mayReadOrWriteMemory())
206  return true;
207 
208  return !I.isVolatile() && !AANoSync::isNonRelaxedAtomic(&I);
209 }
210 
212  const Value &V, bool ForAnalysisOnly) {
213  // TODO: See the AAInstanceInfo class comment.
214  if (!ForAnalysisOnly)
215  return false;
216  auto &InstanceInfoAA = A.getAAFor<AAInstanceInfo>(
217  QueryingAA, IRPosition::value(V), DepClassTy::OPTIONAL);
218  return InstanceInfoAA.isAssumedUniqueForAnalysis();
219 }
220 
222  const TargetLibraryInfo *TLI) {
223  if (isa<AllocaInst>(Obj))
224  return UndefValue::get(&Ty);
225  if (Constant *Init = getInitialValueOfAllocation(&Obj, TLI, &Ty))
226  return Init;
227  auto *GV = dyn_cast<GlobalVariable>(&Obj);
228  if (!GV)
229  return nullptr;
230  if (!GV->hasLocalLinkage() && !(GV->isConstant() && GV->hasInitializer()))
231  return nullptr;
232  if (!GV->hasInitializer())
233  return UndefValue::get(&Ty);
234  return dyn_cast_or_null<Constant>(getWithType(*GV->getInitializer(), Ty));
235 }
236 
237 bool AA::isValidInScope(const Value &V, const Function *Scope) {
238  if (isa<Constant>(V))
239  return true;
240  if (auto *I = dyn_cast<Instruction>(&V))
241  return I->getFunction() == Scope;
242  if (auto *A = dyn_cast<Argument>(&V))
243  return A->getParent() == Scope;
244  return false;
245 }
246 
248  InformationCache &InfoCache) {
249  if (isa<Constant>(VAC.getValue()) || VAC.getValue() == VAC.getCtxI())
250  return true;
251  const Function *Scope = nullptr;
252  const Instruction *CtxI = VAC.getCtxI();
253  if (CtxI)
254  Scope = CtxI->getFunction();
255  if (auto *A = dyn_cast<Argument>(VAC.getValue()))
256  return A->getParent() == Scope;
257  if (auto *I = dyn_cast<Instruction>(VAC.getValue())) {
258  if (I->getFunction() == Scope) {
259  if (const DominatorTree *DT =
261  *Scope))
262  return DT->dominates(I, CtxI);
263  // Local dominance check mostly for the old PM passes.
264  if (CtxI && I->getParent() == CtxI->getParent())
265  return llvm::any_of(
266  make_range(I->getIterator(), I->getParent()->end()),
267  [&](const Instruction &AfterI) { return &AfterI == CtxI; });
268  }
269  }
270  return false;
271 }
272 
274  if (V.getType() == &Ty)
275  return &V;
276  if (isa<PoisonValue>(V))
277  return PoisonValue::get(&Ty);
278  if (isa<UndefValue>(V))
279  return UndefValue::get(&Ty);
280  if (auto *C = dyn_cast<Constant>(&V)) {
281  if (C->isNullValue())
282  return Constant::getNullValue(&Ty);
283  if (C->getType()->isPointerTy() && Ty.isPointerTy())
284  return ConstantExpr::getPointerCast(C, &Ty);
285  if (C->getType()->getPrimitiveSizeInBits() >= Ty.getPrimitiveSizeInBits()) {
286  if (C->getType()->isIntegerTy() && Ty.isIntegerTy())
287  return ConstantExpr::getTrunc(C, &Ty, /* OnlyIfReduced */ true);
288  if (C->getType()->isFloatingPointTy() && Ty.isFloatingPointTy())
289  return ConstantExpr::getFPTrunc(C, &Ty, /* OnlyIfReduced */ true);
290  }
291  }
292  return nullptr;
293 }
294 
297  const Optional<Value *> &B, Type *Ty) {
298  if (A == B)
299  return A;
300  if (!B.hasValue())
301  return A;
302  if (*B == nullptr)
303  return nullptr;
304  if (!A.hasValue())
305  return Ty ? getWithType(**B, *Ty) : nullptr;
306  if (*A == nullptr)
307  return nullptr;
308  if (!Ty)
309  Ty = (*A)->getType();
310  if (isa_and_nonnull<UndefValue>(*A))
311  return getWithType(**B, *Ty);
312  if (isa<UndefValue>(*B))
313  return A;
314  if (*A && *B && *A == getWithType(**B, *Ty))
315  return A;
316  return nullptr;
317 }
318 
319 template <bool IsLoad, typename Ty>
321  Attributor &A, Ty &I, SmallSetVector<Value *, 4> &PotentialCopies,
322  SmallSetVector<Instruction *, 4> &PotentialValueOrigins,
323  const AbstractAttribute &QueryingAA, bool &UsedAssumedInformation,
324  bool OnlyExact) {
325  LLVM_DEBUG(dbgs() << "Trying to determine the potential copies of " << I
326  << " (only exact: " << OnlyExact << ")\n";);
327 
328  Value &Ptr = *I.getPointerOperand();
329  SmallVector<Value *, 8> Objects;
330  if (!AA::getAssumedUnderlyingObjects(A, Ptr, Objects, QueryingAA, &I,
331  UsedAssumedInformation)) {
332  LLVM_DEBUG(
333  dbgs() << "Underlying objects stored into could not be determined\n";);
334  return false;
335  }
336 
337  // Containers to remember the pointer infos and new copies while we are not
338  // sure that we can find all of them. If we abort we want to avoid spurious
339  // dependences and potential copies in the provided container.
341  SmallVector<Value *> NewCopies;
342  SmallVector<Instruction *> NewCopyOrigins;
343 
344  const auto *TLI =
345  A.getInfoCache().getTargetLibraryInfoForFunction(*I.getFunction());
346  for (Value *Obj : Objects) {
347  LLVM_DEBUG(dbgs() << "Visit underlying object " << *Obj << "\n");
348  if (isa<UndefValue>(Obj))
349  continue;
350  if (isa<ConstantPointerNull>(Obj)) {
351  // A null pointer access can be undefined but any offset from null may
352  // be OK. We do not try to optimize the latter.
353  if (!NullPointerIsDefined(I.getFunction(),
354  Ptr.getType()->getPointerAddressSpace()) &&
355  A.getAssumedSimplified(Ptr, QueryingAA, UsedAssumedInformation) ==
356  Obj)
357  continue;
358  LLVM_DEBUG(
359  dbgs() << "Underlying object is a valid nullptr, giving up.\n";);
360  return false;
361  }
362  // TODO: Use assumed noalias return.
363  if (!isa<AllocaInst>(Obj) && !isa<GlobalVariable>(Obj) &&
364  !(IsLoad ? isAllocationFn(Obj, TLI) : isNoAliasCall(Obj))) {
365  LLVM_DEBUG(dbgs() << "Underlying object is not supported yet: " << *Obj
366  << "\n";);
367  return false;
368  }
369  if (auto *GV = dyn_cast<GlobalVariable>(Obj))
370  if (!GV->hasLocalLinkage() &&
371  !(GV->isConstant() && GV->hasInitializer())) {
372  LLVM_DEBUG(dbgs() << "Underlying object is global with external "
373  "linkage, not supported yet: "
374  << *Obj << "\n";);
375  return false;
376  }
377 
378  if (IsLoad) {
379  Value *InitialValue = AA::getInitialValueForObj(*Obj, *I.getType(), TLI);
380  if (!InitialValue)
381  return false;
382  NewCopies.push_back(InitialValue);
383  NewCopyOrigins.push_back(nullptr);
384  }
385 
386  auto CheckAccess = [&](const AAPointerInfo::Access &Acc, bool IsExact) {
387  if ((IsLoad && !Acc.isWrite()) || (!IsLoad && !Acc.isRead()))
388  return true;
389  if (IsLoad && Acc.isWrittenValueYetUndetermined())
390  return true;
391  if (OnlyExact && !IsExact &&
392  !isa_and_nonnull<UndefValue>(Acc.getWrittenValue())) {
393  LLVM_DEBUG(dbgs() << "Non exact access " << *Acc.getRemoteInst()
394  << ", abort!\n");
395  return false;
396  }
397  if (IsLoad) {
398  assert(isa<LoadInst>(I) && "Expected load or store instruction only!");
399  if (!Acc.isWrittenValueUnknown()) {
400  NewCopies.push_back(Acc.getWrittenValue());
401  NewCopyOrigins.push_back(Acc.getRemoteInst());
402  return true;
403  }
404  auto *SI = dyn_cast<StoreInst>(Acc.getRemoteInst());
405  if (!SI) {
406  LLVM_DEBUG(dbgs() << "Underlying object written through a non-store "
407  "instruction not supported yet: "
408  << *Acc.getRemoteInst() << "\n";);
409  return false;
410  }
411  NewCopies.push_back(SI->getValueOperand());
412  NewCopyOrigins.push_back(SI);
413  } else {
414  assert(isa<StoreInst>(I) && "Expected load or store instruction only!");
415  auto *LI = dyn_cast<LoadInst>(Acc.getRemoteInst());
416  if (!LI && OnlyExact) {
417  LLVM_DEBUG(dbgs() << "Underlying object read through a non-load "
418  "instruction not supported yet: "
419  << *Acc.getRemoteInst() << "\n";);
420  return false;
421  }
422  NewCopies.push_back(Acc.getRemoteInst());
423  }
424  return true;
425  };
426 
427  auto &PI = A.getAAFor<AAPointerInfo>(QueryingAA, IRPosition::value(*Obj),
429  if (!PI.forallInterferingAccesses(A, QueryingAA, I, CheckAccess)) {
430  LLVM_DEBUG(
431  dbgs()
432  << "Failed to verify all interfering accesses for underlying object: "
433  << *Obj << "\n");
434  return false;
435  }
436  PIs.push_back(&PI);
437  }
438 
439  // Only if we were successful collection all potential copies we record
440  // dependences (on non-fix AAPointerInfo AAs). We also only then modify the
441  // given PotentialCopies container.
442  for (auto *PI : PIs) {
443  if (!PI->getState().isAtFixpoint())
444  UsedAssumedInformation = true;
445  A.recordDependence(*PI, QueryingAA, DepClassTy::OPTIONAL);
446  }
447  PotentialCopies.insert(NewCopies.begin(), NewCopies.end());
448  PotentialValueOrigins.insert(NewCopyOrigins.begin(), NewCopyOrigins.end());
449 
450  return true;
451 }
452 
454  Attributor &A, LoadInst &LI, SmallSetVector<Value *, 4> &PotentialValues,
455  SmallSetVector<Instruction *, 4> &PotentialValueOrigins,
456  const AbstractAttribute &QueryingAA, bool &UsedAssumedInformation,
457  bool OnlyExact) {
458  return getPotentialCopiesOfMemoryValue</* IsLoad */ true>(
459  A, LI, PotentialValues, PotentialValueOrigins, QueryingAA,
460  UsedAssumedInformation, OnlyExact);
461 }
462 
464  Attributor &A, StoreInst &SI, SmallSetVector<Value *, 4> &PotentialCopies,
465  const AbstractAttribute &QueryingAA, bool &UsedAssumedInformation,
466  bool OnlyExact) {
467  SmallSetVector<Instruction *, 4> PotentialValueOrigins;
468  return getPotentialCopiesOfMemoryValue</* IsLoad */ false>(
469  A, SI, PotentialCopies, PotentialValueOrigins, QueryingAA,
470  UsedAssumedInformation, OnlyExact);
471 }
472 
474  const AbstractAttribute &QueryingAA,
475  bool RequireReadNone, bool &IsKnown) {
476 
479  const auto &MemLocAA =
480  A.getAAFor<AAMemoryLocation>(QueryingAA, IRP, DepClassTy::NONE);
481  if (MemLocAA.isAssumedReadNone()) {
482  IsKnown = MemLocAA.isKnownReadNone();
483  if (!IsKnown)
484  A.recordDependence(MemLocAA, QueryingAA, DepClassTy::OPTIONAL);
485  return true;
486  }
487  }
488 
489  const auto &MemBehaviorAA =
490  A.getAAFor<AAMemoryBehavior>(QueryingAA, IRP, DepClassTy::NONE);
491  if (MemBehaviorAA.isAssumedReadNone() ||
492  (!RequireReadNone && MemBehaviorAA.isAssumedReadOnly())) {
493  IsKnown = RequireReadNone ? MemBehaviorAA.isKnownReadNone()
494  : MemBehaviorAA.isKnownReadOnly();
495  if (!IsKnown)
496  A.recordDependence(MemBehaviorAA, QueryingAA, DepClassTy::OPTIONAL);
497  return true;
498  }
499 
500  return false;
501 }
502 
504  const AbstractAttribute &QueryingAA, bool &IsKnown) {
505  return isAssumedReadOnlyOrReadNone(A, IRP, QueryingAA,
506  /* RequireReadNone */ false, IsKnown);
507 }
509  const AbstractAttribute &QueryingAA, bool &IsKnown) {
510  return isAssumedReadOnlyOrReadNone(A, IRP, QueryingAA,
511  /* RequireReadNone */ true, IsKnown);
512 }
513 
514 static bool
516  const Instruction *ToI, const Function &ToFn,
517  const AbstractAttribute &QueryingAA,
518  std::function<bool(const Function &F)> GoBackwardsCB) {
519  LLVM_DEBUG(dbgs() << "[AA] isPotentiallyReachable @" << ToFn.getName()
520  << " from " << FromI << " [GBCB: " << bool(GoBackwardsCB)
521  << "]\n");
522 
525  Worklist.push_back(&FromI);
526 
527  const auto &NoRecurseAA = A.getAAFor<AANoRecurse>(
528  QueryingAA, IRPosition::function(ToFn), DepClassTy::OPTIONAL);
529  while (!Worklist.empty()) {
530  const Instruction *CurFromI = Worklist.pop_back_val();
531  if (!Visited.insert(CurFromI).second)
532  continue;
533 
534  const Function *FromFn = CurFromI->getFunction();
535  if (FromFn == &ToFn) {
536  if (!ToI)
537  return true;
538  LLVM_DEBUG(dbgs() << "[AA] check " << *ToI << " from " << *CurFromI
539  << " intraprocedurally\n");
540  const auto &ReachabilityAA = A.getAAFor<AAReachability>(
541  QueryingAA, IRPosition::function(ToFn), DepClassTy::OPTIONAL);
542  bool Result = ReachabilityAA.isAssumedReachable(A, *CurFromI, *ToI);
543  LLVM_DEBUG(dbgs() << "[AA] " << *CurFromI << " "
544  << (Result ? "can potentially " : "cannot ") << "reach "
545  << *ToI << " [Intra]\n");
546  if (Result)
547  return true;
548  if (NoRecurseAA.isAssumedNoRecurse())
549  continue;
550  }
551 
552  // TODO: If we can go arbitrarily backwards we will eventually reach an
553  // entry point that can reach ToI. Only once this takes a set of blocks
554  // through which we cannot go, or once we track internal functions not
555  // accessible from the outside, it makes sense to perform backwards analysis
556  // in the absence of a GoBackwardsCB.
557  if (!GoBackwardsCB) {
558  LLVM_DEBUG(dbgs() << "[AA] check @" << ToFn.getName() << " from "
559  << *CurFromI << " is not checked backwards, abort\n");
560  return true;
561  }
562 
563  // Check if the current instruction is already known to reach the ToFn.
564  const auto &FnReachabilityAA = A.getAAFor<AAFunctionReachability>(
565  QueryingAA, IRPosition::function(*FromFn), DepClassTy::OPTIONAL);
566  bool Result = FnReachabilityAA.instructionCanReach(
567  A, *CurFromI, ToFn, /* UseBackwards */ false);
568  LLVM_DEBUG(dbgs() << "[AA] " << *CurFromI << " in @" << FromFn->getName()
569  << " " << (Result ? "can potentially " : "cannot ")
570  << "reach @" << ToFn.getName() << " [FromFn]\n");
571  if (Result)
572  return true;
573 
574  // If we do not go backwards from the FromFn we are done here and so far we
575  // could not find a way to reach ToFn/ToI.
576  if (!GoBackwardsCB(*FromFn))
577  continue;
578 
579  LLVM_DEBUG(dbgs() << "Stepping backwards to the call sites of @"
580  << FromFn->getName() << "\n");
581 
582  auto CheckCallSite = [&](AbstractCallSite ACS) {
583  CallBase *CB = ACS.getInstruction();
584  if (!CB)
585  return false;
586 
587  if (isa<InvokeInst>(CB))
588  return false;
589 
591  Worklist.push_back(Inst);
592  return true;
593  };
594 
595  bool UsedAssumedInformation = false;
596  Result = !A.checkForAllCallSites(CheckCallSite, *FromFn,
597  /* RequireAllCallSites */ true,
598  &QueryingAA, UsedAssumedInformation);
599  if (Result) {
600  LLVM_DEBUG(dbgs() << "[AA] stepping back to call sites from " << *CurFromI
601  << " in @" << FromFn->getName()
602  << " failed, give up\n");
603  return true;
604  }
605 
606  LLVM_DEBUG(dbgs() << "[AA] stepped back to call sites from " << *CurFromI
607  << " in @" << FromFn->getName()
608  << " worklist size is: " << Worklist.size() << "\n");
609  }
610  return false;
611 }
612 
614  Attributor &A, const Instruction &FromI, const Instruction &ToI,
615  const AbstractAttribute &QueryingAA,
616  std::function<bool(const Function &F)> GoBackwardsCB) {
617  LLVM_DEBUG(dbgs() << "[AA] isPotentiallyReachable " << ToI << " from "
618  << FromI << " [GBCB: " << bool(GoBackwardsCB) << "]\n");
619  const Function *ToFn = ToI.getFunction();
620  return ::isPotentiallyReachable(A, FromI, &ToI, *ToFn, QueryingAA,
621  GoBackwardsCB);
622 }
623 
625  Attributor &A, const Instruction &FromI, const Function &ToFn,
626  const AbstractAttribute &QueryingAA,
627  std::function<bool(const Function &F)> GoBackwardsCB) {
628  return ::isPotentiallyReachable(A, FromI, /* ToI */ nullptr, ToFn, QueryingAA,
629  GoBackwardsCB);
630 }
631 
632 /// Return true if \p New is equal or worse than \p Old.
633 static bool isEqualOrWorse(const Attribute &New, const Attribute &Old) {
634  if (!Old.isIntAttribute())
635  return true;
636 
637  return Old.getValueAsInt() >= New.getValueAsInt();
638 }
639 
640 /// Return true if the information provided by \p Attr was added to the
641 /// attribute list \p Attrs. This is only the case if it was not already present
642 /// in \p Attrs at the position describe by \p PK and \p AttrIdx.
643 static bool addIfNotExistent(LLVMContext &Ctx, const Attribute &Attr,
644  AttributeList &Attrs, int AttrIdx,
645  bool ForceReplace = false) {
646 
647  if (Attr.isEnumAttribute()) {
649  if (Attrs.hasAttributeAtIndex(AttrIdx, Kind))
650  if (!ForceReplace &&
651  isEqualOrWorse(Attr, Attrs.getAttributeAtIndex(AttrIdx, Kind)))
652  return false;
653  Attrs = Attrs.addAttributeAtIndex(Ctx, AttrIdx, Attr);
654  return true;
655  }
656  if (Attr.isStringAttribute()) {
657  StringRef Kind = Attr.getKindAsString();
658  if (Attrs.hasAttributeAtIndex(AttrIdx, Kind))
659  if (!ForceReplace &&
660  isEqualOrWorse(Attr, Attrs.getAttributeAtIndex(AttrIdx, Kind)))
661  return false;
662  Attrs = Attrs.addAttributeAtIndex(Ctx, AttrIdx, Attr);
663  return true;
664  }
665  if (Attr.isIntAttribute()) {
667  if (Attrs.hasAttributeAtIndex(AttrIdx, Kind))
668  if (!ForceReplace &&
669  isEqualOrWorse(Attr, Attrs.getAttributeAtIndex(AttrIdx, Kind)))
670  return false;
671  Attrs = Attrs.removeAttributeAtIndex(Ctx, AttrIdx, Kind);
672  Attrs = Attrs.addAttributeAtIndex(Ctx, AttrIdx, Attr);
673  return true;
674  }
675 
676  llvm_unreachable("Expected enum or string attribute!");
677 }
678 
680  if (getPositionKind() == IRP_ARGUMENT)
681  return cast<Argument>(&getAnchorValue());
682 
683  // Not an Argument and no argument number means this is not a call site
684  // argument, thus we cannot find a callback argument to return.
685  int ArgNo = getCallSiteArgNo();
686  if (ArgNo < 0)
687  return nullptr;
688 
689  // Use abstract call sites to make the connection between the call site
690  // values and the ones in callbacks. If a callback was found that makes use
691  // of the underlying call site operand, we want the corresponding callback
692  // callee argument and not the direct callee argument.
693  Optional<Argument *> CBCandidateArg;
694  SmallVector<const Use *, 4> CallbackUses;
695  const auto &CB = cast<CallBase>(getAnchorValue());
696  AbstractCallSite::getCallbackUses(CB, CallbackUses);
697  for (const Use *U : CallbackUses) {
698  AbstractCallSite ACS(U);
699  assert(ACS && ACS.isCallbackCall());
700  if (!ACS.getCalledFunction())
701  continue;
702 
703  for (unsigned u = 0, e = ACS.getNumArgOperands(); u < e; u++) {
704 
705  // Test if the underlying call site operand is argument number u of the
706  // callback callee.
707  if (ACS.getCallArgOperandNo(u) != ArgNo)
708  continue;
709 
710  assert(ACS.getCalledFunction()->arg_size() > u &&
711  "ACS mapped into var-args arguments!");
712  if (CBCandidateArg) {
713  CBCandidateArg = nullptr;
714  break;
715  }
716  CBCandidateArg = ACS.getCalledFunction()->getArg(u);
717  }
718  }
719 
720  // If we found a unique callback candidate argument, return it.
721  if (CBCandidateArg.hasValue() && CBCandidateArg.getValue())
722  return CBCandidateArg.getValue();
723 
724  // If no callbacks were found, or none used the underlying call site operand
725  // exclusively, use the direct callee argument if available.
726  const Function *Callee = CB.getCalledFunction();
727  if (Callee && Callee->arg_size() > unsigned(ArgNo))
728  return Callee->getArg(ArgNo);
729 
730  return nullptr;
731 }
732 
735  if (getState().isAtFixpoint())
736  return HasChanged;
737 
738  LLVM_DEBUG(dbgs() << "[Attributor] Update: " << *this << "\n");
739 
740  HasChanged = updateImpl(A);
741 
742  LLVM_DEBUG(dbgs() << "[Attributor] Update " << HasChanged << " " << *this
743  << "\n");
744 
745  return HasChanged;
746 }
747 
750  const ArrayRef<Attribute> &DeducedAttrs,
751  bool ForceReplace) {
752  Function *ScopeFn = IRP.getAnchorScope();
754 
755  // In the following some generic code that will manifest attributes in
756  // DeducedAttrs if they improve the current IR. Due to the different
757  // annotation positions we use the underlying AttributeList interface.
758 
760  switch (PK) {
767  Attrs = ScopeFn->getAttributes();
768  break;
772  Attrs = cast<CallBase>(IRP.getAnchorValue()).getAttributes();
773  break;
774  }
775 
777  LLVMContext &Ctx = IRP.getAnchorValue().getContext();
778  for (const Attribute &Attr : DeducedAttrs) {
779  if (!addIfNotExistent(Ctx, Attr, Attrs, IRP.getAttrIdx(), ForceReplace))
780  continue;
781 
782  HasChanged = ChangeStatus::CHANGED;
783  }
784 
785  if (HasChanged == ChangeStatus::UNCHANGED)
786  return HasChanged;
787 
788  switch (PK) {
792  ScopeFn->setAttributes(Attrs);
793  break;
797  cast<CallBase>(IRP.getAnchorValue()).setAttributes(Attrs);
798  break;
801  break;
802  }
803 
804  return HasChanged;
805 }
806 
808 const IRPosition
810 
812  IRPositions.emplace_back(IRP);
813 
814  // Helper to determine if operand bundles on a call site are benin or
815  // potentially problematic. We handle only llvm.assume for now.
816  auto CanIgnoreOperandBundles = [](const CallBase &CB) {
817  return (isa<IntrinsicInst>(CB) &&
818  cast<IntrinsicInst>(CB).getIntrinsicID() == Intrinsic ::assume);
819  };
820 
821  const auto *CB = dyn_cast<CallBase>(&IRP.getAnchorValue());
822  switch (IRP.getPositionKind()) {
826  return;
829  IRPositions.emplace_back(IRPosition::function(*IRP.getAnchorScope()));
830  return;
832  assert(CB && "Expected call site!");
833  // TODO: We need to look at the operand bundles similar to the redirection
834  // in CallBase.
835  if (!CB->hasOperandBundles() || CanIgnoreOperandBundles(*CB))
836  if (const Function *Callee = CB->getCalledFunction())
837  IRPositions.emplace_back(IRPosition::function(*Callee));
838  return;
840  assert(CB && "Expected call site!");
841  // TODO: We need to look at the operand bundles similar to the redirection
842  // in CallBase.
843  if (!CB->hasOperandBundles() || CanIgnoreOperandBundles(*CB)) {
844  if (const Function *Callee = CB->getCalledFunction()) {
845  IRPositions.emplace_back(IRPosition::returned(*Callee));
846  IRPositions.emplace_back(IRPosition::function(*Callee));
847  for (const Argument &Arg : Callee->args())
848  if (Arg.hasReturnedAttr()) {
849  IRPositions.emplace_back(
850  IRPosition::callsite_argument(*CB, Arg.getArgNo()));
851  IRPositions.emplace_back(
852  IRPosition::value(*CB->getArgOperand(Arg.getArgNo())));
853  IRPositions.emplace_back(IRPosition::argument(Arg));
854  }
855  }
856  }
857  IRPositions.emplace_back(IRPosition::callsite_function(*CB));
858  return;
860  assert(CB && "Expected call site!");
861  // TODO: We need to look at the operand bundles similar to the redirection
862  // in CallBase.
863  if (!CB->hasOperandBundles() || CanIgnoreOperandBundles(*CB)) {
864  const Function *Callee = CB->getCalledFunction();
865  if (Callee) {
866  if (Argument *Arg = IRP.getAssociatedArgument())
867  IRPositions.emplace_back(IRPosition::argument(*Arg));
868  IRPositions.emplace_back(IRPosition::function(*Callee));
869  }
870  }
871  IRPositions.emplace_back(IRPosition::value(IRP.getAssociatedValue()));
872  return;
873  }
874  }
875 }
876 
878  bool IgnoreSubsumingPositions, Attributor *A) const {
880  for (const IRPosition &EquivIRP : SubsumingPositionIterator(*this)) {
881  for (Attribute::AttrKind AK : AKs)
882  if (EquivIRP.getAttrsFromIRAttr(AK, Attrs))
883  return true;
884  // The first position returned by the SubsumingPositionIterator is
885  // always the position itself. If we ignore subsuming positions we
886  // are done after the first iteration.
887  if (IgnoreSubsumingPositions)
888  break;
889  }
890  if (A)
891  for (Attribute::AttrKind AK : AKs)
892  if (getAttrsFromAssumes(AK, Attrs, *A))
893  return true;
894  return false;
895 }
896 
899  bool IgnoreSubsumingPositions, Attributor *A) const {
900  for (const IRPosition &EquivIRP : SubsumingPositionIterator(*this)) {
901  for (Attribute::AttrKind AK : AKs)
902  EquivIRP.getAttrsFromIRAttr(AK, Attrs);
903  // The first position returned by the SubsumingPositionIterator is
904  // always the position itself. If we ignore subsuming positions we
905  // are done after the first iteration.
906  if (IgnoreSubsumingPositions)
907  break;
908  }
909  if (A)
910  for (Attribute::AttrKind AK : AKs)
911  getAttrsFromAssumes(AK, Attrs, *A);
912 }
913 
914 bool IRPosition::getAttrsFromIRAttr(Attribute::AttrKind AK,
917  return false;
918 
919  AttributeList AttrList;
920  if (const auto *CB = dyn_cast<CallBase>(&getAnchorValue()))
921  AttrList = CB->getAttributes();
922  else
923  AttrList = getAssociatedFunction()->getAttributes();
924 
925  bool HasAttr = AttrList.hasAttributeAtIndex(getAttrIdx(), AK);
926  if (HasAttr)
927  Attrs.push_back(AttrList.getAttributeAtIndex(getAttrIdx(), AK));
928  return HasAttr;
929 }
930 
931 bool IRPosition::getAttrsFromAssumes(Attribute::AttrKind AK,
933  Attributor &A) const {
934  assert(getPositionKind() != IRP_INVALID && "Did expect a valid position!");
935  Value &AssociatedValue = getAssociatedValue();
936 
937  const Assume2KnowledgeMap &A2K =
938  A.getInfoCache().getKnowledgeMap().lookup({&AssociatedValue, AK});
939 
940  // Check if we found any potential assume use, if not we don't need to create
941  // explorer iterators.
942  if (A2K.empty())
943  return false;
944 
945  LLVMContext &Ctx = AssociatedValue.getContext();
946  unsigned AttrsSize = Attrs.size();
948  A.getInfoCache().getMustBeExecutedContextExplorer();
949  auto EIt = Explorer.begin(getCtxI()), EEnd = Explorer.end(getCtxI());
950  for (auto &It : A2K)
951  if (Explorer.findInContextOf(It.first, EIt, EEnd))
952  Attrs.push_back(Attribute::get(Ctx, AK, It.second.Max));
953  return AttrsSize != Attrs.size();
954 }
955 
956 void IRPosition::verify() {
957 #ifdef EXPENSIVE_CHECKS
958  switch (getPositionKind()) {
959  case IRP_INVALID:
960  assert((CBContext == nullptr) &&
961  "Invalid position must not have CallBaseContext!");
962  assert(!Enc.getOpaqueValue() &&
963  "Expected a nullptr for an invalid position!");
964  return;
965  case IRP_FLOAT:
966  assert((!isa<Argument>(&getAssociatedValue())) &&
967  "Expected specialized kind for argument values!");
968  return;
969  case IRP_RETURNED:
970  assert(isa<Function>(getAsValuePtr()) &&
971  "Expected function for a 'returned' position!");
972  assert(getAsValuePtr() == &getAssociatedValue() &&
973  "Associated value mismatch!");
974  return;
976  assert((CBContext == nullptr) &&
977  "'call site returned' position must not have CallBaseContext!");
978  assert((isa<CallBase>(getAsValuePtr())) &&
979  "Expected call base for 'call site returned' position!");
980  assert(getAsValuePtr() == &getAssociatedValue() &&
981  "Associated value mismatch!");
982  return;
983  case IRP_CALL_SITE:
984  assert((CBContext == nullptr) &&
985  "'call site function' position must not have CallBaseContext!");
986  assert((isa<CallBase>(getAsValuePtr())) &&
987  "Expected call base for 'call site function' position!");
988  assert(getAsValuePtr() == &getAssociatedValue() &&
989  "Associated value mismatch!");
990  return;
991  case IRP_FUNCTION:
992  assert(isa<Function>(getAsValuePtr()) &&
993  "Expected function for a 'function' position!");
994  assert(getAsValuePtr() == &getAssociatedValue() &&
995  "Associated value mismatch!");
996  return;
997  case IRP_ARGUMENT:
998  assert(isa<Argument>(getAsValuePtr()) &&
999  "Expected argument for a 'argument' position!");
1000  assert(getAsValuePtr() == &getAssociatedValue() &&
1001  "Associated value mismatch!");
1002  return;
1003  case IRP_CALL_SITE_ARGUMENT: {
1004  assert((CBContext == nullptr) &&
1005  "'call site argument' position must not have CallBaseContext!");
1006  Use *U = getAsUsePtr();
1007  (void)U; // Silence unused variable warning.
1008  assert(U && "Expected use for a 'call site argument' position!");
1009  assert(isa<CallBase>(U->getUser()) &&
1010  "Expected call base user for a 'call site argument' position!");
1011  assert(cast<CallBase>(U->getUser())->isArgOperand(U) &&
1012  "Expected call base argument operand for a 'call site argument' "
1013  "position");
1014  assert(cast<CallBase>(U->getUser())->getArgOperandNo(U) ==
1015  unsigned(getCallSiteArgNo()) &&
1016  "Argument number mismatch!");
1017  assert(U->get() == &getAssociatedValue() && "Associated value mismatch!");
1018  return;
1019  }
1020  }
1021 #endif
1022 }
1023 
1026  const AbstractAttribute &AA,
1027  bool &UsedAssumedInformation) {
1028  // First check all callbacks provided by outside AAs. If any of them returns
1029  // a non-null value that is different from the associated value, or None, we
1030  // assume it's simplified.
1031  for (auto &CB : SimplificationCallbacks.lookup(IRP)) {
1032  Optional<Value *> SimplifiedV = CB(IRP, &AA, UsedAssumedInformation);
1033  if (!SimplifiedV)
1034  return llvm::None;
1035  if (isa_and_nonnull<Constant>(*SimplifiedV))
1036  return cast<Constant>(*SimplifiedV);
1037  return nullptr;
1038  }
1039  if (auto *C = dyn_cast<Constant>(&IRP.getAssociatedValue()))
1040  return C;
1041  const auto &ValueSimplifyAA =
1042  getAAFor<AAValueSimplify>(AA, IRP, DepClassTy::NONE);
1043  Optional<Value *> SimplifiedV =
1044  ValueSimplifyAA.getAssumedSimplifiedValue(*this);
1045  bool IsKnown = ValueSimplifyAA.isAtFixpoint();
1046  UsedAssumedInformation |= !IsKnown;
1047  if (!SimplifiedV) {
1048  recordDependence(ValueSimplifyAA, AA, DepClassTy::OPTIONAL);
1049  return llvm::None;
1050  }
1051  if (isa_and_nonnull<UndefValue>(SimplifiedV.getValue())) {
1052  recordDependence(ValueSimplifyAA, AA, DepClassTy::OPTIONAL);
1053  return UndefValue::get(IRP.getAssociatedType());
1054  }
1055  Constant *CI = dyn_cast_or_null<Constant>(SimplifiedV.getValue());
1056  if (CI)
1057  CI = dyn_cast_or_null<Constant>(
1058  AA::getWithType(*CI, *IRP.getAssociatedType()));
1059  if (CI)
1060  recordDependence(ValueSimplifyAA, AA, DepClassTy::OPTIONAL);
1061  return CI;
1062 }
1063 
1066  const AbstractAttribute *AA,
1067  bool &UsedAssumedInformation) {
1068  // First check all callbacks provided by outside AAs. If any of them returns
1069  // a non-null value that is different from the associated value, or None, we
1070  // assume it's simplified.
1071  for (auto &CB : SimplificationCallbacks.lookup(IRP))
1072  return CB(IRP, AA, UsedAssumedInformation);
1073 
1074  // If no high-level/outside simplification occurred, use AAValueSimplify.
1075  const auto &ValueSimplifyAA =
1076  getOrCreateAAFor<AAValueSimplify>(IRP, AA, DepClassTy::NONE);
1077  Optional<Value *> SimplifiedV =
1078  ValueSimplifyAA.getAssumedSimplifiedValue(*this);
1079  bool IsKnown = ValueSimplifyAA.isAtFixpoint();
1080  UsedAssumedInformation |= !IsKnown;
1081  if (!SimplifiedV) {
1082  if (AA)
1083  recordDependence(ValueSimplifyAA, *AA, DepClassTy::OPTIONAL);
1084  return llvm::None;
1085  }
1086  if (*SimplifiedV == nullptr)
1087  return const_cast<Value *>(&IRP.getAssociatedValue());
1088  if (Value *SimpleV =
1089  AA::getWithType(**SimplifiedV, *IRP.getAssociatedType())) {
1090  if (AA)
1091  recordDependence(ValueSimplifyAA, *AA, DepClassTy::OPTIONAL);
1092  return SimpleV;
1093  }
1094  return const_cast<Value *>(&IRP.getAssociatedValue());
1095 }
1096 
1099  bool &UsedAssumedInformation) {
1100  if (!V)
1101  return V;
1102  if (*V == nullptr || isa<Constant>(*V))
1103  return V;
1104  if (auto *Arg = dyn_cast<Argument>(*V))
1105  if (CB.getCalledFunction() == Arg->getParent())
1106  if (!Arg->hasPointeeInMemoryValueAttr())
1107  return getAssumedSimplified(
1108  IRPosition::callsite_argument(CB, Arg->getArgNo()), AA,
1109  UsedAssumedInformation);
1110  return nullptr;
1111 }
1112 
1114  // The abstract attributes are allocated via the BumpPtrAllocator Allocator,
1115  // thus we cannot delete them. We can, and want to, destruct them though.
1116  for (auto &DepAA : DG.SyntheticRoot.Deps) {
1117  AbstractAttribute *AA = cast<AbstractAttribute>(DepAA.getPointer());
1118  AA->~AbstractAttribute();
1119  }
1120 }
1121 
1123  const AAIsDead *FnLivenessAA,
1124  bool &UsedAssumedInformation,
1125  bool CheckBBLivenessOnly, DepClassTy DepClass) {
1126  const IRPosition &IRP = AA.getIRPosition();
1127  if (!Functions.count(IRP.getAnchorScope()))
1128  return false;
1129  return isAssumedDead(IRP, &AA, FnLivenessAA, UsedAssumedInformation,
1130  CheckBBLivenessOnly, DepClass);
1131 }
1132 
1134  const AbstractAttribute *QueryingAA,
1135  const AAIsDead *FnLivenessAA,
1136  bool &UsedAssumedInformation,
1137  bool CheckBBLivenessOnly, DepClassTy DepClass) {
1138  Instruction *UserI = dyn_cast<Instruction>(U.getUser());
1139  if (!UserI)
1140  return isAssumedDead(IRPosition::value(*U.get()), QueryingAA, FnLivenessAA,
1141  UsedAssumedInformation, CheckBBLivenessOnly, DepClass);
1142 
1143  if (auto *CB = dyn_cast<CallBase>(UserI)) {
1144  // For call site argument uses we can check if the argument is
1145  // unused/dead.
1146  if (CB->isArgOperand(&U)) {
1147  const IRPosition &CSArgPos =
1148  IRPosition::callsite_argument(*CB, CB->getArgOperandNo(&U));
1149  return isAssumedDead(CSArgPos, QueryingAA, FnLivenessAA,
1150  UsedAssumedInformation, CheckBBLivenessOnly,
1151  DepClass);
1152  }
1153  } else if (ReturnInst *RI = dyn_cast<ReturnInst>(UserI)) {
1154  const IRPosition &RetPos = IRPosition::returned(*RI->getFunction());
1155  return isAssumedDead(RetPos, QueryingAA, FnLivenessAA,
1156  UsedAssumedInformation, CheckBBLivenessOnly, DepClass);
1157  } else if (PHINode *PHI = dyn_cast<PHINode>(UserI)) {
1158  BasicBlock *IncomingBB = PHI->getIncomingBlock(U);
1159  return isAssumedDead(*IncomingBB->getTerminator(), QueryingAA, FnLivenessAA,
1160  UsedAssumedInformation, CheckBBLivenessOnly, DepClass);
1161  } else if (StoreInst *SI = dyn_cast<StoreInst>(UserI)) {
1162  if (!CheckBBLivenessOnly && SI->getPointerOperand() != U.get()) {
1163  const IRPosition IRP = IRPosition::inst(*SI);
1164  const AAIsDead &IsDeadAA =
1165  getOrCreateAAFor<AAIsDead>(IRP, QueryingAA, DepClassTy::NONE);
1166  if (IsDeadAA.isRemovableStore()) {
1167  if (QueryingAA)
1168  recordDependence(IsDeadAA, *QueryingAA, DepClass);
1169  if (!IsDeadAA.isKnown(AAIsDead::IS_REMOVABLE))
1170  UsedAssumedInformation = true;
1171  return true;
1172  }
1173  }
1174  }
1175 
1176  return isAssumedDead(IRPosition::inst(*UserI), QueryingAA, FnLivenessAA,
1177  UsedAssumedInformation, CheckBBLivenessOnly, DepClass);
1178 }
1179 
1181  const AbstractAttribute *QueryingAA,
1182  const AAIsDead *FnLivenessAA,
1183  bool &UsedAssumedInformation,
1184  bool CheckBBLivenessOnly, DepClassTy DepClass) {
1185  const IRPosition::CallBaseContext *CBCtx =
1186  QueryingAA ? QueryingAA->getCallBaseContext() : nullptr;
1187 
1188  if (ManifestAddedBlocks.contains(I.getParent()))
1189  return false;
1190 
1191  if (!FnLivenessAA)
1192  FnLivenessAA =
1193  lookupAAFor<AAIsDead>(IRPosition::function(*I.getFunction(), CBCtx),
1194  QueryingAA, DepClassTy::NONE);
1195 
1196  // If we have a context instruction and a liveness AA we use it.
1197  if (FnLivenessAA &&
1198  FnLivenessAA->getIRPosition().getAnchorScope() == I.getFunction() &&
1199  (CheckBBLivenessOnly ? FnLivenessAA->isAssumedDead(I.getParent())
1200  : FnLivenessAA->isAssumedDead(&I))) {
1201  if (QueryingAA)
1202  recordDependence(*FnLivenessAA, *QueryingAA, DepClass);
1203  if (!FnLivenessAA->isKnownDead(&I))
1204  UsedAssumedInformation = true;
1205  return true;
1206  }
1207 
1208  if (CheckBBLivenessOnly)
1209  return false;
1210 
1211  const IRPosition IRP = IRPosition::inst(I, CBCtx);
1212  const AAIsDead &IsDeadAA =
1213  getOrCreateAAFor<AAIsDead>(IRP, QueryingAA, DepClassTy::NONE);
1214  // Don't check liveness for AAIsDead.
1215  if (QueryingAA == &IsDeadAA)
1216  return false;
1217 
1218  if (IsDeadAA.isAssumedDead()) {
1219  if (QueryingAA)
1220  recordDependence(IsDeadAA, *QueryingAA, DepClass);
1221  if (!IsDeadAA.isKnownDead())
1222  UsedAssumedInformation = true;
1223  return true;
1224  }
1225 
1226  return false;
1227 }
1228 
1230  const AbstractAttribute *QueryingAA,
1231  const AAIsDead *FnLivenessAA,
1232  bool &UsedAssumedInformation,
1233  bool CheckBBLivenessOnly, DepClassTy DepClass) {
1234  Instruction *CtxI = IRP.getCtxI();
1235  if (CtxI &&
1236  isAssumedDead(*CtxI, QueryingAA, FnLivenessAA, UsedAssumedInformation,
1237  /* CheckBBLivenessOnly */ true,
1238  CheckBBLivenessOnly ? DepClass : DepClassTy::OPTIONAL))
1239  return true;
1240 
1241  if (CheckBBLivenessOnly)
1242  return false;
1243 
1244  // If we haven't succeeded we query the specific liveness info for the IRP.
1245  const AAIsDead *IsDeadAA;
1247  IsDeadAA = &getOrCreateAAFor<AAIsDead>(
1248  IRPosition::callsite_returned(cast<CallBase>(IRP.getAssociatedValue())),
1249  QueryingAA, DepClassTy::NONE);
1250  else
1251  IsDeadAA = &getOrCreateAAFor<AAIsDead>(IRP, QueryingAA, DepClassTy::NONE);
1252  // Don't check liveness for AAIsDead.
1253  if (QueryingAA == IsDeadAA)
1254  return false;
1255 
1256  if (IsDeadAA->isAssumedDead()) {
1257  if (QueryingAA)
1258  recordDependence(*IsDeadAA, *QueryingAA, DepClass);
1259  if (!IsDeadAA->isKnownDead())
1260  UsedAssumedInformation = true;
1261  return true;
1262  }
1263 
1264  return false;
1265 }
1266 
1268  const AbstractAttribute *QueryingAA,
1269  const AAIsDead *FnLivenessAA,
1270  DepClassTy DepClass) {
1271  if (!FnLivenessAA)
1272  FnLivenessAA = lookupAAFor<AAIsDead>(IRPosition::function(*BB.getParent()),
1273  QueryingAA, DepClassTy::NONE);
1274  if (FnLivenessAA->isAssumedDead(&BB)) {
1275  if (QueryingAA)
1276  recordDependence(*FnLivenessAA, *QueryingAA, DepClass);
1277  return true;
1278  }
1279 
1280  return false;
1281 }
1282 
1284  function_ref<bool(const Use &, bool &)> Pred,
1285  const AbstractAttribute &QueryingAA, const Value &V,
1286  bool CheckBBLivenessOnly, DepClassTy LivenessDepClass,
1287  bool IgnoreDroppableUses,
1288  function_ref<bool(const Use &OldU, const Use &NewU)> EquivalentUseCB) {
1289 
1290  // Check the trivial case first as it catches void values.
1291  if (V.use_empty())
1292  return true;
1293 
1294  const IRPosition &IRP = QueryingAA.getIRPosition();
1297 
1298  for (const Use &U : V.uses())
1299  Worklist.push_back(&U);
1300 
1301  LLVM_DEBUG(dbgs() << "[Attributor] Got " << Worklist.size()
1302  << " initial uses to check\n");
1303 
1304  const Function *ScopeFn = IRP.getAnchorScope();
1305  const auto *LivenessAA =
1306  ScopeFn ? &getAAFor<AAIsDead>(QueryingAA, IRPosition::function(*ScopeFn),
1308  : nullptr;
1309 
1310  while (!Worklist.empty()) {
1311  const Use *U = Worklist.pop_back_val();
1312  if (isa<PHINode>(U->getUser()) && !Visited.insert(U).second)
1313  continue;
1314  LLVM_DEBUG({
1315  if (auto *Fn = dyn_cast<Function>(U->getUser()))
1316  dbgs() << "[Attributor] Check use: " << **U << " in " << Fn->getName()
1317  << "\n";
1318  else
1319  dbgs() << "[Attributor] Check use: " << **U << " in " << *U->getUser()
1320  << "\n";
1321  });
1322  bool UsedAssumedInformation = false;
1323  if (isAssumedDead(*U, &QueryingAA, LivenessAA, UsedAssumedInformation,
1324  CheckBBLivenessOnly, LivenessDepClass)) {
1325  LLVM_DEBUG(dbgs() << "[Attributor] Dead use, skip!\n");
1326  continue;
1327  }
1328  if (IgnoreDroppableUses && U->getUser()->isDroppable()) {
1329  LLVM_DEBUG(dbgs() << "[Attributor] Droppable user, skip!\n");
1330  continue;
1331  }
1332 
1333  if (auto *SI = dyn_cast<StoreInst>(U->getUser())) {
1334  if (&SI->getOperandUse(0) == U) {
1335  if (!Visited.insert(U).second)
1336  continue;
1337  SmallSetVector<Value *, 4> PotentialCopies;
1339  *this, *SI, PotentialCopies, QueryingAA, UsedAssumedInformation,
1340  /* OnlyExact */ true)) {
1341  LLVM_DEBUG(dbgs() << "[Attributor] Value is stored, continue with "
1342  << PotentialCopies.size()
1343  << " potential copies instead!\n");
1344  for (Value *PotentialCopy : PotentialCopies)
1345  for (const Use &CopyUse : PotentialCopy->uses()) {
1346  if (EquivalentUseCB && !EquivalentUseCB(*U, CopyUse)) {
1347  LLVM_DEBUG(dbgs() << "[Attributor] Potential copy was "
1348  "rejected by the equivalence call back: "
1349  << *CopyUse << "!\n");
1350  return false;
1351  }
1352  Worklist.push_back(&CopyUse);
1353  }
1354  continue;
1355  }
1356  }
1357  }
1358 
1359  bool Follow = false;
1360  if (!Pred(*U, Follow))
1361  return false;
1362  if (!Follow)
1363  continue;
1364  for (const Use &UU : U->getUser()->uses())
1365  Worklist.push_back(&UU);
1366  }
1367 
1368  return true;
1369 }
1370 
1372  const AbstractAttribute &QueryingAA,
1373  bool RequireAllCallSites,
1374  bool &UsedAssumedInformation) {
1375  // We can try to determine information from
1376  // the call sites. However, this is only possible all call sites are known,
1377  // hence the function has internal linkage.
1378  const IRPosition &IRP = QueryingAA.getIRPosition();
1379  const Function *AssociatedFunction = IRP.getAssociatedFunction();
1380  if (!AssociatedFunction) {
1381  LLVM_DEBUG(dbgs() << "[Attributor] No function associated with " << IRP
1382  << "\n");
1383  return false;
1384  }
1385 
1386  return checkForAllCallSites(Pred, *AssociatedFunction, RequireAllCallSites,
1387  &QueryingAA, UsedAssumedInformation);
1388 }
1389 
1391  const Function &Fn,
1392  bool RequireAllCallSites,
1393  const AbstractAttribute *QueryingAA,
1394  bool &UsedAssumedInformation) {
1395  if (RequireAllCallSites && !Fn.hasLocalLinkage()) {
1396  LLVM_DEBUG(
1397  dbgs()
1398  << "[Attributor] Function " << Fn.getName()
1399  << " has no internal linkage, hence not all call sites are known\n");
1400  return false;
1401  }
1402 
1404  for (unsigned u = 0; u < Uses.size(); ++u) {
1405  const Use &U = *Uses[u];
1406  LLVM_DEBUG({
1407  if (auto *Fn = dyn_cast<Function>(U))
1408  dbgs() << "[Attributor] Check use: " << Fn->getName() << " in "
1409  << *U.getUser() << "\n";
1410  else
1411  dbgs() << "[Attributor] Check use: " << *U << " in " << *U.getUser()
1412  << "\n";
1413  });
1414  if (isAssumedDead(U, QueryingAA, nullptr, UsedAssumedInformation,
1415  /* CheckBBLivenessOnly */ true)) {
1416  LLVM_DEBUG(dbgs() << "[Attributor] Dead use, skip!\n");
1417  continue;
1418  }
1419  if (ConstantExpr *CE = dyn_cast<ConstantExpr>(U.getUser())) {
1420  if (CE->isCast() && CE->getType()->isPointerTy()) {
1421  LLVM_DEBUG(
1422  dbgs() << "[Attributor] Use, is constant cast expression, add "
1423  << CE->getNumUses()
1424  << " uses of that expression instead!\n");
1425  for (const Use &CEU : CE->uses())
1426  Uses.push_back(&CEU);
1427  continue;
1428  }
1429  }
1430 
1431  AbstractCallSite ACS(&U);
1432  if (!ACS) {
1433  LLVM_DEBUG(dbgs() << "[Attributor] Function " << Fn.getName()
1434  << " has non call site use " << *U.get() << " in "
1435  << *U.getUser() << "\n");
1436  // BlockAddress users are allowed.
1437  if (isa<BlockAddress>(U.getUser()))
1438  continue;
1439  return false;
1440  }
1441 
1442  const Use *EffectiveUse =
1443  ACS.isCallbackCall() ? &ACS.getCalleeUseForCallback() : &U;
1444  if (!ACS.isCallee(EffectiveUse)) {
1445  if (!RequireAllCallSites) {
1446  LLVM_DEBUG(dbgs() << "[Attributor] User " << *EffectiveUse->getUser()
1447  << " is not a call of " << Fn.getName()
1448  << ", skip use\n");
1449  continue;
1450  }
1451  LLVM_DEBUG(dbgs() << "[Attributor] User " << *EffectiveUse->getUser()
1452  << " is an invalid use of " << Fn.getName() << "\n");
1453  return false;
1454  }
1455 
1456  // Make sure the arguments that can be matched between the call site and the
1457  // callee argee on their type. It is unlikely they do not and it doesn't
1458  // make sense for all attributes to know/care about this.
1459  assert(&Fn == ACS.getCalledFunction() && "Expected known callee");
1460  unsigned MinArgsParams =
1461  std::min(size_t(ACS.getNumArgOperands()), Fn.arg_size());
1462  for (unsigned u = 0; u < MinArgsParams; ++u) {
1463  Value *CSArgOp = ACS.getCallArgOperand(u);
1464  if (CSArgOp && Fn.getArg(u)->getType() != CSArgOp->getType()) {
1465  LLVM_DEBUG(
1466  dbgs() << "[Attributor] Call site / callee argument type mismatch ["
1467  << u << "@" << Fn.getName() << ": "
1468  << *Fn.getArg(u)->getType() << " vs. "
1469  << *ACS.getCallArgOperand(u)->getType() << "\n");
1470  return false;
1471  }
1472  }
1473 
1474  if (Pred(ACS))
1475  continue;
1476 
1477  LLVM_DEBUG(dbgs() << "[Attributor] Call site callback failed for "
1478  << *ACS.getInstruction() << "\n");
1479  return false;
1480  }
1481 
1482  return true;
1483 }
1484 
1485 bool Attributor::shouldPropagateCallBaseContext(const IRPosition &IRP) {
1486  // TODO: Maintain a cache of Values that are
1487  // on the pathway from a Argument to a Instruction that would effect the
1488  // liveness/return state etc.
1489  return EnableCallSiteSpecific;
1490 }
1491 
1493  function_ref<bool(Value &, const SmallSetVector<ReturnInst *, 4> &)> Pred,
1494  const AbstractAttribute &QueryingAA) {
1495 
1496  const IRPosition &IRP = QueryingAA.getIRPosition();
1497  // Since we need to provide return instructions we have to have an exact
1498  // definition.
1499  const Function *AssociatedFunction = IRP.getAssociatedFunction();
1500  if (!AssociatedFunction)
1501  return false;
1502 
1503  // If this is a call site query we use the call site specific return values
1504  // and liveness information.
1505  // TODO: use the function scope once we have call site AAReturnedValues.
1506  const IRPosition &QueryIRP = IRPosition::function(*AssociatedFunction);
1507  const auto &AARetVal =
1508  getAAFor<AAReturnedValues>(QueryingAA, QueryIRP, DepClassTy::REQUIRED);
1509  if (!AARetVal.getState().isValidState())
1510  return false;
1511 
1512  return AARetVal.checkForAllReturnedValuesAndReturnInsts(Pred);
1513 }
1514 
1516  function_ref<bool(Value &)> Pred, const AbstractAttribute &QueryingAA) {
1517 
1518  const IRPosition &IRP = QueryingAA.getIRPosition();
1519  const Function *AssociatedFunction = IRP.getAssociatedFunction();
1520  if (!AssociatedFunction)
1521  return false;
1522 
1523  // TODO: use the function scope once we have call site AAReturnedValues.
1524  const IRPosition &QueryIRP = IRPosition::function(
1525  *AssociatedFunction, QueryingAA.getCallBaseContext());
1526  const auto &AARetVal =
1527  getAAFor<AAReturnedValues>(QueryingAA, QueryIRP, DepClassTy::REQUIRED);
1528  if (!AARetVal.getState().isValidState())
1529  return false;
1530 
1531  return AARetVal.checkForAllReturnedValuesAndReturnInsts(
1532  [&](Value &RV, const SmallSetVector<ReturnInst *, 4> &) {
1533  return Pred(RV);
1534  });
1535 }
1536 
1538  Attributor *A, InformationCache::OpcodeInstMapTy &OpcodeInstMap,
1539  function_ref<bool(Instruction &)> Pred, const AbstractAttribute *QueryingAA,
1540  const AAIsDead *LivenessAA, const ArrayRef<unsigned> &Opcodes,
1541  bool &UsedAssumedInformation, bool CheckBBLivenessOnly = false,
1542  bool CheckPotentiallyDead = false) {
1543  for (unsigned Opcode : Opcodes) {
1544  // Check if we have instructions with this opcode at all first.
1545  auto *Insts = OpcodeInstMap.lookup(Opcode);
1546  if (!Insts)
1547  continue;
1548 
1549  for (Instruction *I : *Insts) {
1550  // Skip dead instructions.
1551  if (A && !CheckPotentiallyDead &&
1552  A->isAssumedDead(IRPosition::inst(*I), QueryingAA, LivenessAA,
1553  UsedAssumedInformation, CheckBBLivenessOnly)) {
1554  LLVM_DEBUG(dbgs() << "[Attributor] Instruction " << *I
1555  << " is potentially dead, skip!\n";);
1556  continue;
1557  }
1558 
1559  if (!Pred(*I))
1560  return false;
1561  }
1562  }
1563  return true;
1564 }
1565 
1567  const Function *Fn,
1568  const AbstractAttribute &QueryingAA,
1569  const ArrayRef<unsigned> &Opcodes,
1570  bool &UsedAssumedInformation,
1571  bool CheckBBLivenessOnly,
1572  bool CheckPotentiallyDead) {
1573  // Since we need to provide instructions we have to have an exact definition.
1574  if (!Fn || Fn->isDeclaration())
1575  return false;
1576 
1577  // TODO: use the function scope once we have call site AAReturnedValues.
1578  const IRPosition &QueryIRP = IRPosition::function(*Fn);
1579  const auto *LivenessAA =
1580  (CheckBBLivenessOnly || CheckPotentiallyDead)
1581  ? nullptr
1582  : &(getAAFor<AAIsDead>(QueryingAA, QueryIRP, DepClassTy::NONE));
1583 
1584  auto &OpcodeInstMap = InfoCache.getOpcodeInstMapForFunction(*Fn);
1585  if (!checkForAllInstructionsImpl(this, OpcodeInstMap, Pred, &QueryingAA,
1586  LivenessAA, Opcodes, UsedAssumedInformation,
1587  CheckBBLivenessOnly, CheckPotentiallyDead))
1588  return false;
1589 
1590  return true;
1591 }
1592 
1594  const AbstractAttribute &QueryingAA,
1595  const ArrayRef<unsigned> &Opcodes,
1596  bool &UsedAssumedInformation,
1597  bool CheckBBLivenessOnly,
1598  bool CheckPotentiallyDead) {
1599  const IRPosition &IRP = QueryingAA.getIRPosition();
1600  const Function *AssociatedFunction = IRP.getAssociatedFunction();
1601  return checkForAllInstructions(Pred, AssociatedFunction, QueryingAA, Opcodes,
1602  UsedAssumedInformation, CheckBBLivenessOnly,
1603  CheckPotentiallyDead);
1604 }
1605 
1607  function_ref<bool(Instruction &)> Pred, AbstractAttribute &QueryingAA,
1608  bool &UsedAssumedInformation) {
1609 
1610  const Function *AssociatedFunction =
1611  QueryingAA.getIRPosition().getAssociatedFunction();
1612  if (!AssociatedFunction)
1613  return false;
1614 
1615  // TODO: use the function scope once we have call site AAReturnedValues.
1616  const IRPosition &QueryIRP = IRPosition::function(*AssociatedFunction);
1617  const auto &LivenessAA =
1618  getAAFor<AAIsDead>(QueryingAA, QueryIRP, DepClassTy::NONE);
1619 
1620  for (Instruction *I :
1621  InfoCache.getReadOrWriteInstsForFunction(*AssociatedFunction)) {
1622  // Skip dead instructions.
1623  if (isAssumedDead(IRPosition::inst(*I), &QueryingAA, &LivenessAA,
1624  UsedAssumedInformation))
1625  continue;
1626 
1627  if (!Pred(*I))
1628  return false;
1629  }
1630 
1631  return true;
1632 }
1633 
1634 void Attributor::runTillFixpoint() {
1635  TimeTraceScope TimeScope("Attributor::runTillFixpoint");
1636  LLVM_DEBUG(dbgs() << "[Attributor] Identified and initialized "
1637  << DG.SyntheticRoot.Deps.size()
1638  << " abstract attributes.\n");
1639 
1640  // Now that all abstract attributes are collected and initialized we start
1641  // the abstract analysis.
1642 
1643  unsigned IterationCounter = 1;
1644  unsigned MaxIterations =
1646 
1648  SetVector<AbstractAttribute *> Worklist, InvalidAAs;
1649  Worklist.insert(DG.SyntheticRoot.begin(), DG.SyntheticRoot.end());
1650 
1651  do {
1652  // Remember the size to determine new attributes.
1653  size_t NumAAs = DG.SyntheticRoot.Deps.size();
1654  LLVM_DEBUG(dbgs() << "\n\n[Attributor] #Iteration: " << IterationCounter
1655  << ", Worklist size: " << Worklist.size() << "\n");
1656 
1657  // For invalid AAs we can fix dependent AAs that have a required dependence,
1658  // thereby folding long dependence chains in a single step without the need
1659  // to run updates.
1660  for (unsigned u = 0; u < InvalidAAs.size(); ++u) {
1661  AbstractAttribute *InvalidAA = InvalidAAs[u];
1662 
1663  // Check the dependences to fast track invalidation.
1664  LLVM_DEBUG(dbgs() << "[Attributor] InvalidAA: " << *InvalidAA << " has "
1665  << InvalidAA->Deps.size()
1666  << " required & optional dependences\n");
1667  while (!InvalidAA->Deps.empty()) {
1668  const auto &Dep = InvalidAA->Deps.back();
1669  InvalidAA->Deps.pop_back();
1670  AbstractAttribute *DepAA = cast<AbstractAttribute>(Dep.getPointer());
1671  if (Dep.getInt() == unsigned(DepClassTy::OPTIONAL)) {
1672  LLVM_DEBUG(dbgs() << " - recompute: " << *DepAA);
1673  Worklist.insert(DepAA);
1674  continue;
1675  }
1676  LLVM_DEBUG(dbgs() << " - invalidate: " << *DepAA);
1678  assert(DepAA->getState().isAtFixpoint() && "Expected fixpoint state!");
1679  if (!DepAA->getState().isValidState())
1680  InvalidAAs.insert(DepAA);
1681  else
1682  ChangedAAs.push_back(DepAA);
1683  }
1684  }
1685 
1686  // Add all abstract attributes that are potentially dependent on one that
1687  // changed to the work list.
1688  for (AbstractAttribute *ChangedAA : ChangedAAs)
1689  while (!ChangedAA->Deps.empty()) {
1690  Worklist.insert(
1691  cast<AbstractAttribute>(ChangedAA->Deps.back().getPointer()));
1692  ChangedAA->Deps.pop_back();
1693  }
1694 
1695  LLVM_DEBUG(dbgs() << "[Attributor] #Iteration: " << IterationCounter
1696  << ", Worklist+Dependent size: " << Worklist.size()
1697  << "\n");
1698 
1699  // Reset the changed and invalid set.
1700  ChangedAAs.clear();
1701  InvalidAAs.clear();
1702 
1703  // Update all abstract attribute in the work list and record the ones that
1704  // changed.
1705  for (AbstractAttribute *AA : Worklist) {
1706  const auto &AAState = AA->getState();
1707  if (!AAState.isAtFixpoint())
1708  if (updateAA(*AA) == ChangeStatus::CHANGED)
1709  ChangedAAs.push_back(AA);
1710 
1711  // Use the InvalidAAs vector to propagate invalid states fast transitively
1712  // without requiring updates.
1713  if (!AAState.isValidState())
1714  InvalidAAs.insert(AA);
1715  }
1716 
1717  // Add attributes to the changed set if they have been created in the last
1718  // iteration.
1719  ChangedAAs.append(DG.SyntheticRoot.begin() + NumAAs,
1720  DG.SyntheticRoot.end());
1721 
1722  // Reset the work list and repopulate with the changed abstract attributes.
1723  // Note that dependent ones are added above.
1724  Worklist.clear();
1725  Worklist.insert(ChangedAAs.begin(), ChangedAAs.end());
1726  Worklist.insert(QueryAAsAwaitingUpdate.begin(),
1727  QueryAAsAwaitingUpdate.end());
1728  QueryAAsAwaitingUpdate.clear();
1729 
1730  } while (!Worklist.empty() &&
1731  (IterationCounter++ < MaxIterations || VerifyMaxFixpointIterations));
1732 
1733  if (IterationCounter > MaxIterations && !Functions.empty()) {
1734  auto Remark = [&](OptimizationRemarkMissed ORM) {
1735  return ORM << "Attributor did not reach a fixpoint after "
1736  << ore::NV("Iterations", MaxIterations) << " iterations.";
1737  };
1738  Function *F = Functions.front();
1739  emitRemark<OptimizationRemarkMissed>(F, "FixedPoint", Remark);
1740  }
1741 
1742  LLVM_DEBUG(dbgs() << "\n[Attributor] Fixpoint iteration done after: "
1743  << IterationCounter << "/" << MaxIterations
1744  << " iterations\n");
1745 
1746  // Reset abstract arguments not settled in a sound fixpoint by now. This
1747  // happens when we stopped the fixpoint iteration early. Note that only the
1748  // ones marked as "changed" *and* the ones transitively depending on them
1749  // need to be reverted to a pessimistic state. Others might not be in a
1750  // fixpoint state but we can use the optimistic results for them anyway.
1752  for (unsigned u = 0; u < ChangedAAs.size(); u++) {
1753  AbstractAttribute *ChangedAA = ChangedAAs[u];
1754  if (!Visited.insert(ChangedAA).second)
1755  continue;
1756 
1757  AbstractState &State = ChangedAA->getState();
1758  if (!State.isAtFixpoint()) {
1760 
1761  NumAttributesTimedOut++;
1762  }
1763 
1764  while (!ChangedAA->Deps.empty()) {
1765  ChangedAAs.push_back(
1766  cast<AbstractAttribute>(ChangedAA->Deps.back().getPointer()));
1767  ChangedAA->Deps.pop_back();
1768  }
1769  }
1770 
1771  LLVM_DEBUG({
1772  if (!Visited.empty())
1773  dbgs() << "\n[Attributor] Finalized " << Visited.size()
1774  << " abstract attributes.\n";
1775  });
1776 
1777  if (VerifyMaxFixpointIterations && IterationCounter != MaxIterations) {
1778  errs() << "\n[Attributor] Fixpoint iteration done after: "
1779  << IterationCounter << "/" << MaxIterations << " iterations\n";
1780  llvm_unreachable("The fixpoint was not reached with exactly the number of "
1781  "specified iterations!");
1782  }
1783 }
1784 
1786  assert(AA.isQueryAA() &&
1787  "Non-query AAs should not be required to register for updates!");
1788  QueryAAsAwaitingUpdate.insert(&AA);
1789 }
1790 
1791 ChangeStatus Attributor::manifestAttributes() {
1792  TimeTraceScope TimeScope("Attributor::manifestAttributes");
1793  size_t NumFinalAAs = DG.SyntheticRoot.Deps.size();
1794 
1795  unsigned NumManifested = 0;
1796  unsigned NumAtFixpoint = 0;
1797  ChangeStatus ManifestChange = ChangeStatus::UNCHANGED;
1798  for (auto &DepAA : DG.SyntheticRoot.Deps) {
1799  AbstractAttribute *AA = cast<AbstractAttribute>(DepAA.getPointer());
1800  AbstractState &State = AA->getState();
1801 
1802  // If there is not already a fixpoint reached, we can now take the
1803  // optimistic state. This is correct because we enforced a pessimistic one
1804  // on abstract attributes that were transitively dependent on a changed one
1805  // already above.
1806  if (!State.isAtFixpoint())
1808 
1809  // We must not manifest Attributes that use Callbase info.
1810  if (AA->hasCallBaseContext())
1811  continue;
1812  // If the state is invalid, we do not try to manifest it.
1813  if (!State.isValidState())
1814  continue;
1815 
1816  if (AA->getCtxI() && !isRunOn(*AA->getAnchorScope()))
1817  continue;
1818 
1819  // Skip dead code.
1820  bool UsedAssumedInformation = false;
1821  if (isAssumedDead(*AA, nullptr, UsedAssumedInformation,
1822  /* CheckBBLivenessOnly */ true))
1823  continue;
1824  // Check if the manifest debug counter that allows skipping manifestation of
1825  // AAs
1826  if (!DebugCounter::shouldExecute(ManifestDBGCounter))
1827  continue;
1828  // Manifest the state and record if we changed the IR.
1829  ChangeStatus LocalChange = AA->manifest(*this);
1830  if (LocalChange == ChangeStatus::CHANGED && AreStatisticsEnabled())
1831  AA->trackStatistics();
1832  LLVM_DEBUG(dbgs() << "[Attributor] Manifest " << LocalChange << " : " << *AA
1833  << "\n");
1834 
1835  ManifestChange = ManifestChange | LocalChange;
1836 
1837  NumAtFixpoint++;
1838  NumManifested += (LocalChange == ChangeStatus::CHANGED);
1839  }
1840 
1841  (void)NumManifested;
1842  (void)NumAtFixpoint;
1843  LLVM_DEBUG(dbgs() << "\n[Attributor] Manifested " << NumManifested
1844  << " arguments while " << NumAtFixpoint
1845  << " were in a valid fixpoint state\n");
1846 
1847  NumAttributesManifested += NumManifested;
1848  NumAttributesValidFixpoint += NumAtFixpoint;
1849 
1850  (void)NumFinalAAs;
1851  if (NumFinalAAs != DG.SyntheticRoot.Deps.size()) {
1852  for (unsigned u = NumFinalAAs; u < DG.SyntheticRoot.Deps.size(); ++u)
1853  errs() << "Unexpected abstract attribute: "
1854  << cast<AbstractAttribute>(DG.SyntheticRoot.Deps[u].getPointer())
1855  << " :: "
1856  << cast<AbstractAttribute>(DG.SyntheticRoot.Deps[u].getPointer())
1857  ->getIRPosition()
1858  .getAssociatedValue()
1859  << "\n";
1860  llvm_unreachable("Expected the final number of abstract attributes to "
1861  "remain unchanged!");
1862  }
1863  return ManifestChange;
1864 }
1865 
1866 void Attributor::identifyDeadInternalFunctions() {
1867  // Early exit if we don't intend to delete functions.
1868  if (!Configuration.DeleteFns)
1869  return;
1870 
1871  // Identify dead internal functions and delete them. This happens outside
1872  // the other fixpoint analysis as we might treat potentially dead functions
1873  // as live to lower the number of iterations. If they happen to be dead, the
1874  // below fixpoint loop will identify and eliminate them.
1875  SmallVector<Function *, 8> InternalFns;
1876  for (Function *F : Functions)
1877  if (F->hasLocalLinkage())
1878  InternalFns.push_back(F);
1879 
1880  SmallPtrSet<Function *, 8> LiveInternalFns;
1881  bool FoundLiveInternal = true;
1882  while (FoundLiveInternal) {
1883  FoundLiveInternal = false;
1884  for (unsigned u = 0, e = InternalFns.size(); u < e; ++u) {
1885  Function *F = InternalFns[u];
1886  if (!F)
1887  continue;
1888 
1889  bool UsedAssumedInformation = false;
1891  [&](AbstractCallSite ACS) {
1893  return ToBeDeletedFunctions.count(Callee) ||
1894  (Functions.count(Callee) && Callee->hasLocalLinkage() &&
1895  !LiveInternalFns.count(Callee));
1896  },
1897  *F, true, nullptr, UsedAssumedInformation)) {
1898  continue;
1899  }
1900 
1901  LiveInternalFns.insert(F);
1902  InternalFns[u] = nullptr;
1903  FoundLiveInternal = true;
1904  }
1905  }
1906 
1907  for (unsigned u = 0, e = InternalFns.size(); u < e; ++u)
1908  if (Function *F = InternalFns[u])
1909  ToBeDeletedFunctions.insert(F);
1910 }
1911 
1912 ChangeStatus Attributor::cleanupIR() {
1913  TimeTraceScope TimeScope("Attributor::cleanupIR");
1914  // Delete stuff at the end to avoid invalid references and a nice order.
1915  LLVM_DEBUG(dbgs() << "\n[Attributor] Delete/replace at least "
1916  << ToBeDeletedFunctions.size() << " functions and "
1917  << ToBeDeletedBlocks.size() << " blocks and "
1918  << ToBeDeletedInsts.size() << " instructions and "
1919  << ToBeChangedValues.size() << " values and "
1920  << ToBeChangedUses.size() << " uses. To insert "
1921  << ToBeChangedToUnreachableInsts.size() << " unreachables."
1922  << "Preserve manifest added " << ManifestAddedBlocks.size()
1923  << " blocks\n");
1924 
1926  SmallVector<Instruction *, 32> TerminatorsToFold;
1927 
1928  auto ReplaceUse = [&](Use *U, Value *NewV) {
1929  Value *OldV = U->get();
1930 
1931  // If we plan to replace NewV we need to update it at this point.
1932  do {
1933  const auto &Entry = ToBeChangedValues.lookup(NewV);
1934  if (!Entry.first)
1935  break;
1936  NewV = Entry.first;
1937  } while (true);
1938 
1939  Instruction *I = dyn_cast<Instruction>(U->getUser());
1940  assert((!I || isRunOn(*I->getFunction())) &&
1941  "Cannot replace an instruction outside the current SCC!");
1942 
1943  // Do not replace uses in returns if the value is a must-tail call we will
1944  // not delete.
1945  if (auto *RI = dyn_cast_or_null<ReturnInst>(I)) {
1946  if (auto *CI = dyn_cast<CallInst>(OldV->stripPointerCasts()))
1947  if (CI->isMustTailCall() && !ToBeDeletedInsts.count(CI))
1948  return;
1949  // If we rewrite a return and the new value is not an argument, strip the
1950  // `returned` attribute as it is wrong now.
1951  if (!isa<Argument>(NewV))
1952  for (auto &Arg : RI->getFunction()->args())
1953  Arg.removeAttr(Attribute::Returned);
1954  }
1955 
1956  // Do not perform call graph altering changes outside the SCC.
1957  if (auto *CB = dyn_cast_or_null<CallBase>(I))
1958  if (CB->isCallee(U))
1959  return;
1960 
1961  LLVM_DEBUG(dbgs() << "Use " << *NewV << " in " << *U->getUser()
1962  << " instead of " << *OldV << "\n");
1963  U->set(NewV);
1964 
1965  if (Instruction *I = dyn_cast<Instruction>(OldV)) {
1966  CGModifiedFunctions.insert(I->getFunction());
1967  if (!isa<PHINode>(I) && !ToBeDeletedInsts.count(I) &&
1969  DeadInsts.push_back(I);
1970  }
1971  if (isa<UndefValue>(NewV) && isa<CallBase>(U->getUser())) {
1972  auto *CB = cast<CallBase>(U->getUser());
1973  if (CB->isArgOperand(U)) {
1974  unsigned Idx = CB->getArgOperandNo(U);
1975  CB->removeParamAttr(Idx, Attribute::NoUndef);
1976  Function *Fn = CB->getCalledFunction();
1977  if (Fn && Fn->arg_size() > Idx)
1978  Fn->removeParamAttr(Idx, Attribute::NoUndef);
1979  }
1980  }
1981  if (isa<Constant>(NewV) && isa<BranchInst>(U->getUser())) {
1982  Instruction *UserI = cast<Instruction>(U->getUser());
1983  if (isa<UndefValue>(NewV)) {
1984  ToBeChangedToUnreachableInsts.insert(UserI);
1985  } else {
1986  TerminatorsToFold.push_back(UserI);
1987  }
1988  }
1989  };
1990 
1991  for (auto &It : ToBeChangedUses) {
1992  Use *U = It.first;
1993  Value *NewV = It.second;
1994  ReplaceUse(U, NewV);
1995  }
1996 
1998  for (auto &It : ToBeChangedValues) {
1999  Value *OldV = It.first;
2000  auto &Entry = It.second;
2001  Value *NewV = Entry.first;
2002  Uses.clear();
2003  for (auto &U : OldV->uses())
2004  if (Entry.second || !U.getUser()->isDroppable())
2005  Uses.push_back(&U);
2006  for (Use *U : Uses) {
2007  if (auto *I = dyn_cast<Instruction>(U->getUser()))
2008  if (!isRunOn(*I->getFunction()))
2009  continue;
2010  ReplaceUse(U, NewV);
2011  }
2012  }
2013 
2014  for (auto &V : InvokeWithDeadSuccessor)
2015  if (InvokeInst *II = dyn_cast_or_null<InvokeInst>(V)) {
2016  assert(isRunOn(*II->getFunction()) &&
2017  "Cannot replace an invoke outside the current SCC!");
2018  bool UnwindBBIsDead = II->hasFnAttr(Attribute::NoUnwind);
2019  bool NormalBBIsDead = II->hasFnAttr(Attribute::NoReturn);
2020  bool Invoke2CallAllowed =
2021  !AAIsDead::mayCatchAsynchronousExceptions(*II->getFunction());
2022  assert((UnwindBBIsDead || NormalBBIsDead) &&
2023  "Invoke does not have dead successors!");
2024  BasicBlock *BB = II->getParent();
2025  BasicBlock *NormalDestBB = II->getNormalDest();
2026  if (UnwindBBIsDead) {
2027  Instruction *NormalNextIP = &NormalDestBB->front();
2028  if (Invoke2CallAllowed) {
2029  changeToCall(II);
2030  NormalNextIP = BB->getTerminator();
2031  }
2032  if (NormalBBIsDead)
2033  ToBeChangedToUnreachableInsts.insert(NormalNextIP);
2034  } else {
2035  assert(NormalBBIsDead && "Broken invariant!");
2036  if (!NormalDestBB->getUniquePredecessor())
2037  NormalDestBB = SplitBlockPredecessors(NormalDestBB, {BB}, ".dead");
2038  ToBeChangedToUnreachableInsts.insert(&NormalDestBB->front());
2039  }
2040  }
2041  for (Instruction *I : TerminatorsToFold) {
2042  assert(isRunOn(*I->getFunction()) &&
2043  "Cannot replace a terminator outside the current SCC!");
2044  CGModifiedFunctions.insert(I->getFunction());
2045  ConstantFoldTerminator(I->getParent());
2046  }
2047  for (auto &V : ToBeChangedToUnreachableInsts)
2048  if (Instruction *I = dyn_cast_or_null<Instruction>(V)) {
2049  assert(isRunOn(*I->getFunction()) &&
2050  "Cannot replace an instruction outside the current SCC!");
2051  CGModifiedFunctions.insert(I->getFunction());
2053  }
2054 
2055  for (auto &V : ToBeDeletedInsts) {
2056  if (Instruction *I = dyn_cast_or_null<Instruction>(V)) {
2057  if (auto *CB = dyn_cast<CallBase>(I)) {
2058  assert(isRunOn(*I->getFunction()) &&
2059  "Cannot delete an instruction outside the current SCC!");
2060  if (!isa<IntrinsicInst>(CB))
2061  Configuration.CGUpdater.removeCallSite(*CB);
2062  }
2063  I->dropDroppableUses();
2064  CGModifiedFunctions.insert(I->getFunction());
2065  if (!I->getType()->isVoidTy())
2066  I->replaceAllUsesWith(UndefValue::get(I->getType()));
2067  if (!isa<PHINode>(I) && isInstructionTriviallyDead(I))
2068  DeadInsts.push_back(I);
2069  else
2070  I->eraseFromParent();
2071  }
2072  }
2073 
2074  llvm::erase_if(DeadInsts, [&](WeakTrackingVH I) { return !I; });
2075 
2076  LLVM_DEBUG({
2077  dbgs() << "[Attributor] DeadInsts size: " << DeadInsts.size() << "\n";
2078  for (auto &I : DeadInsts)
2079  if (I)
2080  dbgs() << " - " << *I << "\n";
2081  });
2082 
2084 
2085  if (unsigned NumDeadBlocks = ToBeDeletedBlocks.size()) {
2086  SmallVector<BasicBlock *, 8> ToBeDeletedBBs;
2087  ToBeDeletedBBs.reserve(NumDeadBlocks);
2088  for (BasicBlock *BB : ToBeDeletedBlocks) {
2089  assert(isRunOn(*BB->getParent()) &&
2090  "Cannot delete a block outside the current SCC!");
2091  CGModifiedFunctions.insert(BB->getParent());
2092  // Do not delete BBs added during manifests of AAs.
2093  if (ManifestAddedBlocks.contains(BB))
2094  continue;
2095  ToBeDeletedBBs.push_back(BB);
2096  }
2097  // Actually we do not delete the blocks but squash them into a single
2098  // unreachable but untangling branches that jump here is something we need
2099  // to do in a more generic way.
2100  detachDeadBlocks(ToBeDeletedBBs, nullptr);
2101  }
2102 
2103  identifyDeadInternalFunctions();
2104 
2105  // Rewrite the functions as requested during manifest.
2106  ChangeStatus ManifestChange = rewriteFunctionSignatures(CGModifiedFunctions);
2107 
2108  for (Function *Fn : CGModifiedFunctions)
2109  if (!ToBeDeletedFunctions.count(Fn) && Functions.count(Fn))
2110  Configuration.CGUpdater.reanalyzeFunction(*Fn);
2111 
2112  for (Function *Fn : ToBeDeletedFunctions) {
2113  if (!Functions.count(Fn))
2114  continue;
2115  Configuration.CGUpdater.removeFunction(*Fn);
2116  }
2117 
2118  if (!ToBeChangedUses.empty())
2119  ManifestChange = ChangeStatus::CHANGED;
2120 
2121  if (!ToBeChangedToUnreachableInsts.empty())
2122  ManifestChange = ChangeStatus::CHANGED;
2123 
2124  if (!ToBeDeletedFunctions.empty())
2125  ManifestChange = ChangeStatus::CHANGED;
2126 
2127  if (!ToBeDeletedBlocks.empty())
2128  ManifestChange = ChangeStatus::CHANGED;
2129 
2130  if (!ToBeDeletedInsts.empty())
2131  ManifestChange = ChangeStatus::CHANGED;
2132 
2133  if (!InvokeWithDeadSuccessor.empty())
2134  ManifestChange = ChangeStatus::CHANGED;
2135 
2136  if (!DeadInsts.empty())
2137  ManifestChange = ChangeStatus::CHANGED;
2138 
2139  NumFnDeleted += ToBeDeletedFunctions.size();
2140 
2141  LLVM_DEBUG(dbgs() << "[Attributor] Deleted " << ToBeDeletedFunctions.size()
2142  << " functions after manifest.\n");
2143 
2144 #ifdef EXPENSIVE_CHECKS
2145  for (Function *F : Functions) {
2146  if (ToBeDeletedFunctions.count(F))
2147  continue;
2148  assert(!verifyFunction(*F, &errs()) && "Module verification failed!");
2149  }
2150 #endif
2151 
2152  return ManifestChange;
2153 }
2154 
2156  TimeTraceScope TimeScope("Attributor::run");
2157  AttributorCallGraph ACallGraph(*this);
2158 
2159  if (PrintCallGraph)
2160  ACallGraph.populateAll();
2161 
2162  Phase = AttributorPhase::UPDATE;
2163  runTillFixpoint();
2164 
2165  // dump graphs on demand
2166  if (DumpDepGraph)
2167  DG.dumpGraph();
2168 
2169  if (ViewDepGraph)
2170  DG.viewGraph();
2171 
2172  if (PrintDependencies)
2173  DG.print();
2174 
2175  Phase = AttributorPhase::MANIFEST;
2176  ChangeStatus ManifestChange = manifestAttributes();
2177 
2178  Phase = AttributorPhase::CLEANUP;
2179  ChangeStatus CleanupChange = cleanupIR();
2180 
2181  if (PrintCallGraph)
2182  ACallGraph.print();
2183 
2184  return ManifestChange | CleanupChange;
2185 }
2186 
2187 ChangeStatus Attributor::updateAA(AbstractAttribute &AA) {
2188  TimeTraceScope TimeScope(
2189  AA.getName() + std::to_string(AA.getIRPosition().getPositionKind()) +
2190  "::updateAA");
2191  assert(Phase == AttributorPhase::UPDATE &&
2192  "We can update AA only in the update stage!");
2193 
2194  // Use a new dependence vector for this update.
2195  DependenceVector DV;
2196  DependenceStack.push_back(&DV);
2197 
2198  auto &AAState = AA.getState();
2200  bool UsedAssumedInformation = false;
2201  if (!isAssumedDead(AA, nullptr, UsedAssumedInformation,
2202  /* CheckBBLivenessOnly */ true))
2203  CS = AA.update(*this);
2204 
2205  if (!AA.isQueryAA() && DV.empty()) {
2206  // If the attribute did not query any non-fix information, the state
2207  // will not change and we can indicate that right away.
2208  AAState.indicateOptimisticFixpoint();
2209  }
2210 
2211  if (!AAState.isAtFixpoint())
2212  rememberDependences();
2213 
2214  // Verify the stack was used properly, that is we pop the dependence vector we
2215  // put there earlier.
2216  DependenceVector *PoppedDV = DependenceStack.pop_back_val();
2217  (void)PoppedDV;
2218  assert(PoppedDV == &DV && "Inconsistent usage of the dependence stack!");
2219 
2220  return CS;
2221 }
2222 
2224  assert(!F.isDeclaration() && "Cannot create a wrapper around a declaration!");
2225 
2226  Module &M = *F.getParent();
2227  LLVMContext &Ctx = M.getContext();
2228  FunctionType *FnTy = F.getFunctionType();
2229 
2230  Function *Wrapper =
2231  Function::Create(FnTy, F.getLinkage(), F.getAddressSpace(), F.getName());
2232  F.setName(""); // set the inside function anonymous
2233  M.getFunctionList().insert(F.getIterator(), Wrapper);
2234 
2235  F.setLinkage(GlobalValue::InternalLinkage);
2236 
2237  F.replaceAllUsesWith(Wrapper);
2238  assert(F.use_empty() && "Uses remained after wrapper was created!");
2239 
2240  // Move the COMDAT section to the wrapper.
2241  // TODO: Check if we need to keep it for F as well.
2242  Wrapper->setComdat(F.getComdat());
2243  F.setComdat(nullptr);
2244 
2245  // Copy all metadata and attributes but keep them on F as well.
2247  F.getAllMetadata(MDs);
2248  for (auto MDIt : MDs)
2249  Wrapper->addMetadata(MDIt.first, *MDIt.second);
2250  Wrapper->setAttributes(F.getAttributes());
2251 
2252  // Create the call in the wrapper.
2253  BasicBlock *EntryBB = BasicBlock::Create(Ctx, "entry", Wrapper);
2254 
2256  Argument *FArgIt = F.arg_begin();
2257  for (Argument &Arg : Wrapper->args()) {
2258  Args.push_back(&Arg);
2259  Arg.setName((FArgIt++)->getName());
2260  }
2261 
2262  CallInst *CI = CallInst::Create(&F, Args, "", EntryBB);
2263  CI->setTailCall(true);
2264  CI->addFnAttr(Attribute::NoInline);
2265  ReturnInst::Create(Ctx, CI->getType()->isVoidTy() ? nullptr : CI, EntryBB);
2266 
2267  NumFnShallowWrappersCreated++;
2268 }
2269 
2271  if (F.isDeclaration() || F.hasLocalLinkage() ||
2272  GlobalValue::isInterposableLinkage(F.getLinkage()))
2273  return false;
2274  return true;
2275 }
2276 
2278  if (!AllowDeepWrapper && !Force)
2279  return nullptr;
2280  if (!isInternalizable(F))
2281  return nullptr;
2282 
2283  SmallPtrSet<Function *, 2> FnSet = {&F};
2284  DenseMap<Function *, Function *> InternalizedFns;
2285  internalizeFunctions(FnSet, InternalizedFns);
2286 
2287  return InternalizedFns[&F];
2288 }
2289 
2292  for (Function *F : FnSet)
2294  return false;
2295 
2296  FnMap.clear();
2297  // Generate the internalized version of each function.
2298  for (Function *F : FnSet) {
2299  Module &M = *F->getParent();
2300  FunctionType *FnTy = F->getFunctionType();
2301 
2302  // Create a copy of the current function
2303  Function *Copied =
2304  Function::Create(FnTy, F->getLinkage(), F->getAddressSpace(),
2305  F->getName() + ".internalized");
2306  ValueToValueMapTy VMap;
2307  auto *NewFArgIt = Copied->arg_begin();
2308  for (auto &Arg : F->args()) {
2309  auto ArgName = Arg.getName();
2310  NewFArgIt->setName(ArgName);
2311  VMap[&Arg] = &(*NewFArgIt++);
2312  }
2314 
2315  // Copy the body of the original function to the new one
2316  CloneFunctionInto(Copied, F, VMap,
2318 
2319  // Set the linakage and visibility late as CloneFunctionInto has some
2320  // implicit requirements.
2323 
2324  // Copy metadata
2326  F->getAllMetadata(MDs);
2327  for (auto MDIt : MDs)
2328  if (!Copied->hasMetadata())
2329  Copied->addMetadata(MDIt.first, *MDIt.second);
2330 
2331  M.getFunctionList().insert(F->getIterator(), Copied);
2332  Copied->setDSOLocal(true);
2333  FnMap[F] = Copied;
2334  }
2335 
2336  // Replace all uses of the old function with the new internalized function
2337  // unless the caller is a function that was just internalized.
2338  for (Function *F : FnSet) {
2339  auto &InternalizedFn = FnMap[F];
2340  auto IsNotInternalized = [&](Use &U) -> bool {
2341  if (auto *CB = dyn_cast<CallBase>(U.getUser()))
2342  return !FnMap.lookup(CB->getCaller());
2343  return false;
2344  };
2345  F->replaceUsesWithIf(InternalizedFn, IsNotInternalized);
2346  }
2347 
2348  return true;
2349 }
2350 
2352  Argument &Arg, ArrayRef<Type *> ReplacementTypes) {
2353 
2354  if (!Configuration.RewriteSignatures)
2355  return false;
2356 
2357  Function *Fn = Arg.getParent();
2358  auto CallSiteCanBeChanged = [Fn](AbstractCallSite ACS) {
2359  // Forbid the call site to cast the function return type. If we need to
2360  // rewrite these functions we need to re-create a cast for the new call site
2361  // (if the old had uses).
2362  if (!ACS.getCalledFunction() ||
2363  ACS.getInstruction()->getType() !=
2365  return false;
2366  if (ACS.getCalledOperand()->getType() != Fn->getType())
2367  return false;
2368  // Forbid must-tail calls for now.
2369  return !ACS.isCallbackCall() && !ACS.getInstruction()->isMustTailCall();
2370  };
2371 
2372  // Avoid var-arg functions for now.
2373  if (Fn->isVarArg()) {
2374  LLVM_DEBUG(dbgs() << "[Attributor] Cannot rewrite var-args functions\n");
2375  return false;
2376  }
2377 
2378  // Avoid functions with complicated argument passing semantics.
2379  AttributeList FnAttributeList = Fn->getAttributes();
2380  if (FnAttributeList.hasAttrSomewhere(Attribute::Nest) ||
2381  FnAttributeList.hasAttrSomewhere(Attribute::StructRet) ||
2382  FnAttributeList.hasAttrSomewhere(Attribute::InAlloca) ||
2383  FnAttributeList.hasAttrSomewhere(Attribute::Preallocated)) {
2384  LLVM_DEBUG(
2385  dbgs() << "[Attributor] Cannot rewrite due to complex attribute\n");
2386  return false;
2387  }
2388 
2389  // Avoid callbacks for now.
2390  bool UsedAssumedInformation = false;
2391  if (!checkForAllCallSites(CallSiteCanBeChanged, *Fn, true, nullptr,
2392  UsedAssumedInformation)) {
2393  LLVM_DEBUG(dbgs() << "[Attributor] Cannot rewrite all call sites\n");
2394  return false;
2395  }
2396 
2397  auto InstPred = [](Instruction &I) {
2398  if (auto *CI = dyn_cast<CallInst>(&I))
2399  return !CI->isMustTailCall();
2400  return true;
2401  };
2402 
2403  // Forbid must-tail calls for now.
2404  // TODO:
2405  auto &OpcodeInstMap = InfoCache.getOpcodeInstMapForFunction(*Fn);
2406  if (!checkForAllInstructionsImpl(nullptr, OpcodeInstMap, InstPred, nullptr,
2407  nullptr, {Instruction::Call},
2408  UsedAssumedInformation)) {
2409  LLVM_DEBUG(dbgs() << "[Attributor] Cannot rewrite due to instructions\n");
2410  return false;
2411  }
2412 
2413  return true;
2414 }
2415 
2417  Argument &Arg, ArrayRef<Type *> ReplacementTypes,
2420  LLVM_DEBUG(dbgs() << "[Attributor] Register new rewrite of " << Arg << " in "
2421  << Arg.getParent()->getName() << " with "
2422  << ReplacementTypes.size() << " replacements\n");
2423  assert(isValidFunctionSignatureRewrite(Arg, ReplacementTypes) &&
2424  "Cannot register an invalid rewrite");
2425 
2426  Function *Fn = Arg.getParent();
2428  ArgumentReplacementMap[Fn];
2429  if (ARIs.empty())
2430  ARIs.resize(Fn->arg_size());
2431 
2432  // If we have a replacement already with less than or equal new arguments,
2433  // ignore this request.
2434  std::unique_ptr<ArgumentReplacementInfo> &ARI = ARIs[Arg.getArgNo()];
2435  if (ARI && ARI->getNumReplacementArgs() <= ReplacementTypes.size()) {
2436  LLVM_DEBUG(dbgs() << "[Attributor] Existing rewrite is preferred\n");
2437  return false;
2438  }
2439 
2440  // If we have a replacement already but we like the new one better, delete
2441  // the old.
2442  ARI.reset();
2443 
2444  LLVM_DEBUG(dbgs() << "[Attributor] Register new rewrite of " << Arg << " in "
2445  << Arg.getParent()->getName() << " with "
2446  << ReplacementTypes.size() << " replacements\n");
2447 
2448  // Remember the replacement.
2449  ARI.reset(new ArgumentReplacementInfo(*this, Arg, ReplacementTypes,
2450  std::move(CalleeRepairCB),
2451  std::move(ACSRepairCB)));
2452 
2453  return true;
2454 }
2455 
2456 bool Attributor::shouldSeedAttribute(AbstractAttribute &AA) {
2457  bool Result = true;
2458 #ifndef NDEBUG
2459  if (SeedAllowList.size() != 0)
2460  Result = llvm::is_contained(SeedAllowList, AA.getName());
2461  Function *Fn = AA.getAnchorScope();
2462  if (FunctionSeedAllowList.size() != 0 && Fn)
2464 #endif
2465  return Result;
2466 }
2467 
2468 ChangeStatus Attributor::rewriteFunctionSignatures(
2469  SmallSetVector<Function *, 8> &ModifiedFns) {
2471 
2472  for (auto &It : ArgumentReplacementMap) {
2473  Function *OldFn = It.getFirst();
2474 
2475  // Deleted functions do not require rewrites.
2476  if (!Functions.count(OldFn) || ToBeDeletedFunctions.count(OldFn))
2477  continue;
2478 
2480  It.getSecond();
2481  assert(ARIs.size() == OldFn->arg_size() && "Inconsistent state!");
2482 
2483  SmallVector<Type *, 16> NewArgumentTypes;
2484  SmallVector<AttributeSet, 16> NewArgumentAttributes;
2485 
2486  // Collect replacement argument types and copy over existing attributes.
2487  AttributeList OldFnAttributeList = OldFn->getAttributes();
2488  for (Argument &Arg : OldFn->args()) {
2489  if (const std::unique_ptr<ArgumentReplacementInfo> &ARI =
2490  ARIs[Arg.getArgNo()]) {
2491  NewArgumentTypes.append(ARI->ReplacementTypes.begin(),
2492  ARI->ReplacementTypes.end());
2493  NewArgumentAttributes.append(ARI->getNumReplacementArgs(),
2494  AttributeSet());
2495  } else {
2496  NewArgumentTypes.push_back(Arg.getType());
2497  NewArgumentAttributes.push_back(
2498  OldFnAttributeList.getParamAttrs(Arg.getArgNo()));
2499  }
2500  }
2501 
2502  uint64_t LargestVectorWidth = 0;
2503  for (auto *I : NewArgumentTypes)
2504  if (auto *VT = dyn_cast<llvm::VectorType>(I))
2505  LargestVectorWidth = std::max(
2506  LargestVectorWidth, VT->getPrimitiveSizeInBits().getKnownMinSize());
2507 
2508  FunctionType *OldFnTy = OldFn->getFunctionType();
2509  Type *RetTy = OldFnTy->getReturnType();
2510 
2511  // Construct the new function type using the new arguments types.
2512  FunctionType *NewFnTy =
2513  FunctionType::get(RetTy, NewArgumentTypes, OldFnTy->isVarArg());
2514 
2515  LLVM_DEBUG(dbgs() << "[Attributor] Function rewrite '" << OldFn->getName()
2516  << "' from " << *OldFn->getFunctionType() << " to "
2517  << *NewFnTy << "\n");
2518 
2519  // Create the new function body and insert it into the module.
2520  Function *NewFn = Function::Create(NewFnTy, OldFn->getLinkage(),
2521  OldFn->getAddressSpace(), "");
2522  Functions.insert(NewFn);
2523  OldFn->getParent()->getFunctionList().insert(OldFn->getIterator(), NewFn);
2524  NewFn->takeName(OldFn);
2525  NewFn->copyAttributesFrom(OldFn);
2526 
2527  // Patch the pointer to LLVM function in debug info descriptor.
2528  NewFn->setSubprogram(OldFn->getSubprogram());
2529  OldFn->setSubprogram(nullptr);
2530 
2531  // Recompute the parameter attributes list based on the new arguments for
2532  // the function.
2533  LLVMContext &Ctx = OldFn->getContext();
2535  Ctx, OldFnAttributeList.getFnAttrs(), OldFnAttributeList.getRetAttrs(),
2536  NewArgumentAttributes));
2537  AttributeFuncs::updateMinLegalVectorWidthAttr(*NewFn, LargestVectorWidth);
2538 
2539  // Since we have now created the new function, splice the body of the old
2540  // function right into the new function, leaving the old rotting hulk of the
2541  // function empty.
2542  NewFn->getBasicBlockList().splice(NewFn->begin(),
2543  OldFn->getBasicBlockList());
2544 
2545  // Fixup block addresses to reference new function.
2546  SmallVector<BlockAddress *, 8u> BlockAddresses;
2547  for (User *U : OldFn->users())
2548  if (auto *BA = dyn_cast<BlockAddress>(U))
2549  BlockAddresses.push_back(BA);
2550  for (auto *BA : BlockAddresses)
2551  BA->replaceAllUsesWith(BlockAddress::get(NewFn, BA->getBasicBlock()));
2552 
2553  // Set of all "call-like" instructions that invoke the old function mapped
2554  // to their new replacements.
2556 
2557  // Callback to create a new "call-like" instruction for a given one.
2558  auto CallSiteReplacementCreator = [&](AbstractCallSite ACS) {
2559  CallBase *OldCB = cast<CallBase>(ACS.getInstruction());
2560  const AttributeList &OldCallAttributeList = OldCB->getAttributes();
2561 
2562  // Collect the new argument operands for the replacement call site.
2563  SmallVector<Value *, 16> NewArgOperands;
2564  SmallVector<AttributeSet, 16> NewArgOperandAttributes;
2565  for (unsigned OldArgNum = 0; OldArgNum < ARIs.size(); ++OldArgNum) {
2566  unsigned NewFirstArgNum = NewArgOperands.size();
2567  (void)NewFirstArgNum; // only used inside assert.
2568  if (const std::unique_ptr<ArgumentReplacementInfo> &ARI =
2569  ARIs[OldArgNum]) {
2570  if (ARI->ACSRepairCB)
2571  ARI->ACSRepairCB(*ARI, ACS, NewArgOperands);
2572  assert(ARI->getNumReplacementArgs() + NewFirstArgNum ==
2573  NewArgOperands.size() &&
2574  "ACS repair callback did not provide as many operand as new "
2575  "types were registered!");
2576  // TODO: Exose the attribute set to the ACS repair callback
2577  NewArgOperandAttributes.append(ARI->ReplacementTypes.size(),
2578  AttributeSet());
2579  } else {
2580  NewArgOperands.push_back(ACS.getCallArgOperand(OldArgNum));
2581  NewArgOperandAttributes.push_back(
2582  OldCallAttributeList.getParamAttrs(OldArgNum));
2583  }
2584  }
2585 
2586  assert(NewArgOperands.size() == NewArgOperandAttributes.size() &&
2587  "Mismatch # argument operands vs. # argument operand attributes!");
2588  assert(NewArgOperands.size() == NewFn->arg_size() &&
2589  "Mismatch # argument operands vs. # function arguments!");
2590 
2591  SmallVector<OperandBundleDef, 4> OperandBundleDefs;
2592  OldCB->getOperandBundlesAsDefs(OperandBundleDefs);
2593 
2594  // Create a new call or invoke instruction to replace the old one.
2595  CallBase *NewCB;
2596  if (InvokeInst *II = dyn_cast<InvokeInst>(OldCB)) {
2597  NewCB =
2598  InvokeInst::Create(NewFn, II->getNormalDest(), II->getUnwindDest(),
2599  NewArgOperands, OperandBundleDefs, "", OldCB);
2600  } else {
2601  auto *NewCI = CallInst::Create(NewFn, NewArgOperands, OperandBundleDefs,
2602  "", OldCB);
2603  NewCI->setTailCallKind(cast<CallInst>(OldCB)->getTailCallKind());
2604  NewCB = NewCI;
2605  }
2606 
2607  // Copy over various properties and the new attributes.
2608  NewCB->copyMetadata(*OldCB, {LLVMContext::MD_prof, LLVMContext::MD_dbg});
2609  NewCB->setCallingConv(OldCB->getCallingConv());
2610  NewCB->takeName(OldCB);
2612  Ctx, OldCallAttributeList.getFnAttrs(),
2613  OldCallAttributeList.getRetAttrs(), NewArgOperandAttributes));
2614 
2616  LargestVectorWidth);
2617 
2618  CallSitePairs.push_back({OldCB, NewCB});
2619  return true;
2620  };
2621 
2622  // Use the CallSiteReplacementCreator to create replacement call sites.
2623  bool UsedAssumedInformation = false;
2624  bool Success = checkForAllCallSites(CallSiteReplacementCreator, *OldFn,
2625  true, nullptr, UsedAssumedInformation);
2626  (void)Success;
2627  assert(Success && "Assumed call site replacement to succeed!");
2628 
2629  // Rewire the arguments.
2630  Argument *OldFnArgIt = OldFn->arg_begin();
2631  Argument *NewFnArgIt = NewFn->arg_begin();
2632  for (unsigned OldArgNum = 0; OldArgNum < ARIs.size();
2633  ++OldArgNum, ++OldFnArgIt) {
2634  if (const std::unique_ptr<ArgumentReplacementInfo> &ARI =
2635  ARIs[OldArgNum]) {
2636  if (ARI->CalleeRepairCB)
2637  ARI->CalleeRepairCB(*ARI, *NewFn, NewFnArgIt);
2638  if (ARI->ReplacementTypes.empty())
2639  OldFnArgIt->replaceAllUsesWith(
2640  PoisonValue::get(OldFnArgIt->getType()));
2641  NewFnArgIt += ARI->ReplacementTypes.size();
2642  } else {
2643  NewFnArgIt->takeName(&*OldFnArgIt);
2644  OldFnArgIt->replaceAllUsesWith(&*NewFnArgIt);
2645  ++NewFnArgIt;
2646  }
2647  }
2648 
2649  // Eliminate the instructions *after* we visited all of them.
2650  for (auto &CallSitePair : CallSitePairs) {
2651  CallBase &OldCB = *CallSitePair.first;
2652  CallBase &NewCB = *CallSitePair.second;
2653  assert(OldCB.getType() == NewCB.getType() &&
2654  "Cannot handle call sites with different types!");
2655  ModifiedFns.insert(OldCB.getFunction());
2656  Configuration.CGUpdater.replaceCallSite(OldCB, NewCB);
2657  OldCB.replaceAllUsesWith(&NewCB);
2658  OldCB.eraseFromParent();
2659  }
2660 
2661  // Replace the function in the call graph (if any).
2662  Configuration.CGUpdater.replaceFunctionWith(*OldFn, *NewFn);
2663 
2664  // If the old function was modified and needed to be reanalyzed, the new one
2665  // does now.
2666  if (ModifiedFns.remove(OldFn))
2667  ModifiedFns.insert(NewFn);
2668 
2669  Changed = ChangeStatus::CHANGED;
2670  }
2671 
2672  return Changed;
2673 }
2674 
2675 void InformationCache::initializeInformationCache(const Function &CF,
2676  FunctionInfo &FI) {
2677  // As we do not modify the function here we can remove the const
2678  // withouth breaking implicit assumptions. At the end of the day, we could
2679  // initialize the cache eagerly which would look the same to the users.
2680  Function &F = const_cast<Function &>(CF);
2681 
2682  // Walk all instructions to find interesting instructions that might be
2683  // queried by abstract attributes during their initialization or update.
2684  // This has to happen before we create attributes.
2685 
2687 
2688  // Add \p V to the assume uses map which track the number of uses outside of
2689  // "visited" assumes. If no outside uses are left the value is added to the
2690  // assume only use vector.
2691  auto AddToAssumeUsesMap = [&](const Value &V) -> void {
2693  if (auto *I = dyn_cast<Instruction>(&V))
2694  Worklist.push_back(I);
2695  while (!Worklist.empty()) {
2696  const Instruction *I = Worklist.pop_back_val();
2697  Optional<short> &NumUses = AssumeUsesMap[I];
2698  if (!NumUses.hasValue())
2699  NumUses = I->getNumUses();
2700  NumUses = NumUses.getValue() - /* this assume */ 1;
2701  if (NumUses.getValue() != 0)
2702  continue;
2703  AssumeOnlyValues.insert(I);
2704  for (const Value *Op : I->operands())
2705  if (auto *OpI = dyn_cast<Instruction>(Op))
2706  Worklist.push_back(OpI);
2707  }
2708  };
2709 
2710  for (Instruction &I : instructions(&F)) {
2711  bool IsInterestingOpcode = false;
2712 
2713  // To allow easy access to all instructions in a function with a given
2714  // opcode we store them in the InfoCache. As not all opcodes are interesting
2715  // to concrete attributes we only cache the ones that are as identified in
2716  // the following switch.
2717  // Note: There are no concrete attributes now so this is initially empty.
2718  switch (I.getOpcode()) {
2719  default:
2720  assert(!isa<CallBase>(&I) &&
2721  "New call base instruction type needs to be known in the "
2722  "Attributor.");
2723  break;
2724  case Instruction::Call:
2725  // Calls are interesting on their own, additionally:
2726  // For `llvm.assume` calls we also fill the KnowledgeMap as we find them.
2727  // For `must-tail` calls we remember the caller and callee.
2728  if (auto *Assume = dyn_cast<AssumeInst>(&I)) {
2729  fillMapFromAssume(*Assume, KnowledgeMap);
2730  AddToAssumeUsesMap(*Assume->getArgOperand(0));
2731  } else if (cast<CallInst>(I).isMustTailCall()) {
2732  FI.ContainsMustTailCall = true;
2733  if (const Function *Callee = cast<CallInst>(I).getCalledFunction())
2734  getFunctionInfo(*Callee).CalledViaMustTail = true;
2735  }
2737  case Instruction::CallBr:
2738  case Instruction::Invoke:
2739  case Instruction::CleanupRet:
2740  case Instruction::CatchSwitch:
2741  case Instruction::AtomicRMW:
2742  case Instruction::AtomicCmpXchg:
2743  case Instruction::Br:
2744  case Instruction::Resume:
2745  case Instruction::Ret:
2746  case Instruction::Load:
2747  // The alignment of a pointer is interesting for loads.
2748  case Instruction::Store:
2749  // The alignment of a pointer is interesting for stores.
2750  case Instruction::Alloca:
2751  case Instruction::AddrSpaceCast:
2752  IsInterestingOpcode = true;
2753  }
2754  if (IsInterestingOpcode) {
2755  auto *&Insts = FI.OpcodeInstMap[I.getOpcode()];
2756  if (!Insts)
2757  Insts = new (Allocator) InstructionVectorTy();
2758  Insts->push_back(&I);
2759  }
2760  if (I.mayReadOrWriteMemory())
2761  FI.RWInsts.push_back(&I);
2762  }
2763 
2764  if (F.hasFnAttribute(Attribute::AlwaysInline) &&
2766  InlineableFunctions.insert(&F);
2767 }
2768 
2770  return AG.getAnalysis<AAManager>(F);
2771 }
2772 
2773 InformationCache::FunctionInfo::~FunctionInfo() {
2774  // The instruction vectors are allocated using a BumpPtrAllocator, we need to
2775  // manually destroy them.
2776  for (auto &It : OpcodeInstMap)
2777  It.getSecond()->~InstructionVectorTy();
2778 }
2779 
2781  const AbstractAttribute &ToAA,
2782  DepClassTy DepClass) {
2783  if (DepClass == DepClassTy::NONE)
2784  return;
2785  // If we are outside of an update, thus before the actual fixpoint iteration
2786  // started (= when we create AAs), we do not track dependences because we will
2787  // put all AAs into the initial worklist anyway.
2788  if (DependenceStack.empty())
2789  return;
2790  if (FromAA.getState().isAtFixpoint())
2791  return;
2792  DependenceStack.back()->push_back({&FromAA, &ToAA, DepClass});
2793 }
2794 
2795 void Attributor::rememberDependences() {
2796  assert(!DependenceStack.empty() && "No dependences to remember!");
2797 
2798  for (DepInfo &DI : *DependenceStack.back()) {
2799  assert((DI.DepClass == DepClassTy::REQUIRED ||
2800  DI.DepClass == DepClassTy::OPTIONAL) &&
2801  "Expected required or optional dependence (1 bit)!");
2802  auto &DepAAs = const_cast<AbstractAttribute &>(*DI.FromAA).Deps;
2803  DepAAs.push_back(AbstractAttribute::DepTy(
2804  const_cast<AbstractAttribute *>(DI.ToAA), unsigned(DI.DepClass)));
2805  }
2806 }
2807 
2809  if (!VisitedFunctions.insert(&F).second)
2810  return;
2811  if (F.isDeclaration())
2812  return;
2813 
2814  // In non-module runs we need to look at the call sites of a function to
2815  // determine if it is part of a must-tail call edge. This will influence what
2816  // attributes we can derive.
2817  InformationCache::FunctionInfo &FI = InfoCache.getFunctionInfo(F);
2818  if (!isModulePass() && !FI.CalledViaMustTail) {
2819  for (const Use &U : F.uses())
2820  if (const auto *CB = dyn_cast<CallBase>(U.getUser()))
2821  if (CB->isCallee(&U) && CB->isMustTailCall())
2822  FI.CalledViaMustTail = true;
2823  }
2824 
2826 
2827  // Check for dead BasicBlocks in every function.
2828  // We need dead instruction detection because we do not want to deal with
2829  // broken IR in which SSA rules do not apply.
2830  getOrCreateAAFor<AAIsDead>(FPos);
2831 
2832  // Every function might be "will-return".
2833  getOrCreateAAFor<AAWillReturn>(FPos);
2834 
2835  // Every function might contain instructions that cause "undefined behavior".
2836  getOrCreateAAFor<AAUndefinedBehavior>(FPos);
2837 
2838  // Every function can be nounwind.
2839  getOrCreateAAFor<AANoUnwind>(FPos);
2840 
2841  // Every function might be marked "nosync"
2842  getOrCreateAAFor<AANoSync>(FPos);
2843 
2844  // Every function might be "no-free".
2845  getOrCreateAAFor<AANoFree>(FPos);
2846 
2847  // Every function might be "no-return".
2848  getOrCreateAAFor<AANoReturn>(FPos);
2849 
2850  // Every function might be "no-recurse".
2851  getOrCreateAAFor<AANoRecurse>(FPos);
2852 
2853  // Every function might be "readnone/readonly/writeonly/...".
2854  getOrCreateAAFor<AAMemoryBehavior>(FPos);
2855 
2856  // Every function can be "readnone/argmemonly/inaccessiblememonly/...".
2857  getOrCreateAAFor<AAMemoryLocation>(FPos);
2858 
2859  // Every function can track active assumptions.
2860  getOrCreateAAFor<AAAssumptionInfo>(FPos);
2861 
2862  // Every function might be applicable for Heap-To-Stack conversion.
2863  if (EnableHeapToStack)
2864  getOrCreateAAFor<AAHeapToStack>(FPos);
2865 
2866  // Return attributes are only appropriate if the return type is non void.
2867  Type *ReturnType = F.getReturnType();
2868  if (!ReturnType->isVoidTy()) {
2869  // Argument attribute "returned" --- Create only one per function even
2870  // though it is an argument attribute.
2871  getOrCreateAAFor<AAReturnedValues>(FPos);
2872 
2873  IRPosition RetPos = IRPosition::returned(F);
2874 
2875  // Every returned value might be dead.
2876  getOrCreateAAFor<AAIsDead>(RetPos);
2877 
2878  // Every function might be simplified.
2879  bool UsedAssumedInformation = false;
2880  getAssumedSimplified(RetPos, nullptr, UsedAssumedInformation);
2881 
2882  // Every returned value might be marked noundef.
2883  getOrCreateAAFor<AANoUndef>(RetPos);
2884 
2885  if (ReturnType->isPointerTy()) {
2886 
2887  // Every function with pointer return type might be marked align.
2888  getOrCreateAAFor<AAAlign>(RetPos);
2889 
2890  // Every function with pointer return type might be marked nonnull.
2891  getOrCreateAAFor<AANonNull>(RetPos);
2892 
2893  // Every function with pointer return type might be marked noalias.
2894  getOrCreateAAFor<AANoAlias>(RetPos);
2895 
2896  // Every function with pointer return type might be marked
2897  // dereferenceable.
2898  getOrCreateAAFor<AADereferenceable>(RetPos);
2899  }
2900  }
2901 
2902  for (Argument &Arg : F.args()) {
2904 
2905  // Every argument might be simplified. We have to go through the Attributor
2906  // interface though as outside AAs can register custom simplification
2907  // callbacks.
2908  bool UsedAssumedInformation = false;
2909  getAssumedSimplified(ArgPos, /* AA */ nullptr, UsedAssumedInformation);
2910 
2911  // Every argument might be dead.
2912  getOrCreateAAFor<AAIsDead>(ArgPos);
2913 
2914  // Every argument might be marked noundef.
2915  getOrCreateAAFor<AANoUndef>(ArgPos);
2916 
2917  if (Arg.getType()->isPointerTy()) {
2918  // Every argument with pointer type might be marked nonnull.
2919  getOrCreateAAFor<AANonNull>(ArgPos);
2920 
2921  // Every argument with pointer type might be marked noalias.
2922  getOrCreateAAFor<AANoAlias>(ArgPos);
2923 
2924  // Every argument with pointer type might be marked dereferenceable.
2925  getOrCreateAAFor<AADereferenceable>(ArgPos);
2926 
2927  // Every argument with pointer type might be marked align.
2928  getOrCreateAAFor<AAAlign>(ArgPos);
2929 
2930  // Every argument with pointer type might be marked nocapture.
2931  getOrCreateAAFor<AANoCapture>(ArgPos);
2932 
2933  // Every argument with pointer type might be marked
2934  // "readnone/readonly/writeonly/..."
2935  getOrCreateAAFor<AAMemoryBehavior>(ArgPos);
2936 
2937  // Every argument with pointer type might be marked nofree.
2938  getOrCreateAAFor<AANoFree>(ArgPos);
2939 
2940  // Every argument with pointer type might be privatizable (or promotable)
2941  getOrCreateAAFor<AAPrivatizablePtr>(ArgPos);
2942  }
2943  }
2944 
2945  auto CallSitePred = [&](Instruction &I) -> bool {
2946  auto &CB = cast<CallBase>(I);
2947  IRPosition CBInstPos = IRPosition::inst(CB);
2949 
2950  // Call sites might be dead if they do not have side effects and no live
2951  // users. The return value might be dead if there are no live users.
2952  getOrCreateAAFor<AAIsDead>(CBInstPos);
2953 
2954  Function *Callee = CB.getCalledFunction();
2955  // TODO: Even if the callee is not known now we might be able to simplify
2956  // the call/callee.
2957  if (!Callee)
2958  return true;
2959 
2960  // Every call site can track active assumptions.
2961  getOrCreateAAFor<AAAssumptionInfo>(CBFnPos);
2962 
2963  // Skip declarations except if annotations on their call sites were
2964  // explicitly requested.
2965  if (!AnnotateDeclarationCallSites && Callee->isDeclaration() &&
2966  !Callee->hasMetadata(LLVMContext::MD_callback))
2967  return true;
2968 
2969  if (!Callee->getReturnType()->isVoidTy() && !CB.use_empty()) {
2970 
2972  bool UsedAssumedInformation = false;
2973  getAssumedSimplified(CBRetPos, nullptr, UsedAssumedInformation);
2974  }
2975 
2976  for (int I = 0, E = CB.arg_size(); I < E; ++I) {
2977 
2978  IRPosition CBArgPos = IRPosition::callsite_argument(CB, I);
2979 
2980  // Every call site argument might be dead.
2981  getOrCreateAAFor<AAIsDead>(CBArgPos);
2982 
2983  // Call site argument might be simplified. We have to go through the
2984  // Attributor interface though as outside AAs can register custom
2985  // simplification callbacks.
2986  bool UsedAssumedInformation = false;
2987  getAssumedSimplified(CBArgPos, /* AA */ nullptr, UsedAssumedInformation);
2988 
2989  // Every call site argument might be marked "noundef".
2990  getOrCreateAAFor<AANoUndef>(CBArgPos);
2991 
2992  if (!CB.getArgOperand(I)->getType()->isPointerTy())
2993  continue;
2994 
2995  // Call site argument attribute "non-null".
2996  getOrCreateAAFor<AANonNull>(CBArgPos);
2997 
2998  // Call site argument attribute "nocapture".
2999  getOrCreateAAFor<AANoCapture>(CBArgPos);
3000 
3001  // Call site argument attribute "no-alias".
3002  getOrCreateAAFor<AANoAlias>(CBArgPos);
3003 
3004  // Call site argument attribute "dereferenceable".
3005  getOrCreateAAFor<AADereferenceable>(CBArgPos);
3006 
3007  // Call site argument attribute "align".
3008  getOrCreateAAFor<AAAlign>(CBArgPos);
3009 
3010  // Call site argument attribute
3011  // "readnone/readonly/writeonly/..."
3012  getOrCreateAAFor<AAMemoryBehavior>(CBArgPos);
3013 
3014  // Call site argument attribute "nofree".
3015  getOrCreateAAFor<AANoFree>(CBArgPos);
3016  }
3017  return true;
3018  };
3019 
3020  auto &OpcodeInstMap = InfoCache.getOpcodeInstMapForFunction(F);
3021  bool Success;
3022  bool UsedAssumedInformation = false;
3024  nullptr, OpcodeInstMap, CallSitePred, nullptr, nullptr,
3025  {(unsigned)Instruction::Invoke, (unsigned)Instruction::CallBr,
3026  (unsigned)Instruction::Call},
3027  UsedAssumedInformation);
3028  (void)Success;
3029  assert(Success && "Expected the check call to be successful!");
3030 
3031  auto LoadStorePred = [&](Instruction &I) -> bool {
3032  if (isa<LoadInst>(I)) {
3033  getOrCreateAAFor<AAAlign>(
3034  IRPosition::value(*cast<LoadInst>(I).getPointerOperand()));
3035  if (SimplifyAllLoads)
3037  UsedAssumedInformation);
3038  } else {
3039  auto &SI = cast<StoreInst>(I);
3040  getOrCreateAAFor<AAIsDead>(IRPosition::inst(I));
3041  getAssumedSimplified(IRPosition::value(*SI.getValueOperand()), nullptr,
3042  UsedAssumedInformation);
3043  getOrCreateAAFor<AAAlign>(IRPosition::value(*SI.getPointerOperand()));
3044  }
3045  return true;
3046  };
3048  nullptr, OpcodeInstMap, LoadStorePred, nullptr, nullptr,
3049  {(unsigned)Instruction::Load, (unsigned)Instruction::Store},
3050  UsedAssumedInformation);
3051  (void)Success;
3052  assert(Success && "Expected the check call to be successful!");
3053 }
3054 
3055 /// Helpers to ease debugging through output streams and print calls.
3056 ///
3057 ///{
3059  return OS << (S == ChangeStatus::CHANGED ? "changed" : "unchanged");
3060 }
3061 
3063  switch (AP) {
3065  return OS << "inv";
3066  case IRPosition::IRP_FLOAT:
3067  return OS << "flt";
3069  return OS << "fn_ret";
3071  return OS << "cs_ret";
3073  return OS << "fn";
3075  return OS << "cs";
3077  return OS << "arg";
3079  return OS << "cs_arg";
3080  }
3081  llvm_unreachable("Unknown attribute position!");
3082 }
3083 
3085  const Value &AV = Pos.getAssociatedValue();
3086  OS << "{" << Pos.getPositionKind() << ":" << AV.getName() << " ["
3087  << Pos.getAnchorValue().getName() << "@" << Pos.getCallSiteArgNo() << "]";
3088 
3089  if (Pos.hasCallBaseContext())
3090  OS << "[cb_context:" << *Pos.getCallBaseContext() << "]";
3091  return OS << "}";
3092 }
3093 
3095  OS << "range-state(" << S.getBitWidth() << ")<";
3096  S.getKnown().print(OS);
3097  OS << " / ";
3098  S.getAssumed().print(OS);
3099  OS << ">";
3100 
3101  return OS << static_cast<const AbstractState &>(S);
3102 }
3103 
3105  return OS << (!S.isValidState() ? "top" : (S.isAtFixpoint() ? "fix" : ""));
3106 }
3107 
3109  AA.print(OS);
3110  return OS;
3111 }
3112 
3115  OS << "set-state(< {";
3116  if (!S.isValidState())
3117  OS << "full-set";
3118  else {
3119  for (auto &It : S.getAssumedSet())
3120  OS << It << ", ";
3121  if (S.undefIsContained())
3122  OS << "undef ";
3123  }
3124  OS << "} >)";
3125 
3126  return OS;
3127 }
3128 
3130  OS << "[";
3131  OS << getName();
3132  OS << "] for CtxI ";
3133 
3134  if (auto *I = getCtxI()) {
3135  OS << "'";
3136  I->print(OS);
3137  OS << "'";
3138  } else
3139  OS << "<<null inst>>";
3140 
3141  OS << " at position " << getIRPosition() << " with state " << getAsStr()
3142  << '\n';
3143 }
3144 
3146  print(OS);
3147 
3148  for (const auto &DepAA : Deps) {
3149  auto *AA = DepAA.getPointer();
3150  OS << " updates ";
3151  AA->print(OS);
3152  }
3153 
3154  OS << '\n';
3155 }
3156 
3158  const AAPointerInfo::Access &Acc) {
3159  OS << " [" << Acc.getKind() << "] " << *Acc.getRemoteInst();
3160  if (Acc.getLocalInst() != Acc.getRemoteInst())
3161  OS << " via " << *Acc.getLocalInst();
3162  if (Acc.getContent()) {
3163  if (*Acc.getContent())
3164  OS << " [" << **Acc.getContent() << "]";
3165  else
3166  OS << " [ <unknown> ]";
3167  }
3168  return OS;
3169 }
3170 ///}
3171 
3172 /// ----------------------------------------------------------------------------
3173 /// Pass (Manager) Boilerplate
3174 /// ----------------------------------------------------------------------------
3175 
3177  SetVector<Function *> &Functions,
3178  AnalysisGetter &AG,
3179  CallGraphUpdater &CGUpdater,
3180  bool DeleteFns, bool IsModulePass) {
3181  if (Functions.empty())
3182  return false;
3183 
3184  LLVM_DEBUG({
3185  dbgs() << "[Attributor] Run on module with " << Functions.size()
3186  << " functions:\n";
3187  for (Function *Fn : Functions)
3188  dbgs() << " - " << Fn->getName() << "\n";
3189  });
3190 
3191  // Create an Attributor and initially empty information cache that is filled
3192  // while we identify default attribute opportunities.
3193  AttributorConfig AC(CGUpdater);
3194  AC.IsModulePass = IsModulePass;
3195  AC.DeleteFns = DeleteFns;
3196  Attributor A(Functions, InfoCache, AC);
3197 
3198  // Create shallow wrappers for all functions that are not IPO amendable
3200  for (Function *F : Functions)
3201  if (!A.isFunctionIPOAmendable(*F))
3203 
3204  // Internalize non-exact functions
3205  // TODO: for now we eagerly internalize functions without calculating the
3206  // cost, we need a cost interface to determine whether internalizing
3207  // a function is "benefitial"
3208  if (AllowDeepWrapper) {
3209  unsigned FunSize = Functions.size();
3210  for (unsigned u = 0; u < FunSize; u++) {
3211  Function *F = Functions[u];
3212  if (!F->isDeclaration() && !F->isDefinitionExact() && F->getNumUses() &&
3213  !GlobalValue::isInterposableLinkage(F->getLinkage())) {
3215  assert(NewF && "Could not internalize function.");
3216  Functions.insert(NewF);
3217 
3218  // Update call graph
3219  CGUpdater.replaceFunctionWith(*F, *NewF);
3220  for (const Use &U : NewF->uses())
3221  if (CallBase *CB = dyn_cast<CallBase>(U.getUser())) {
3222  auto *CallerF = CB->getCaller();
3223  CGUpdater.reanalyzeFunction(*CallerF);
3224  }
3225  }
3226  }
3227  }
3228 
3229  for (Function *F : Functions) {
3230  if (F->hasExactDefinition())
3231  NumFnWithExactDefinition++;
3232  else
3233  NumFnWithoutExactDefinition++;
3234 
3235  // We look at internal functions only on-demand but if any use is not a
3236  // direct call or outside the current set of analyzed functions, we have
3237  // to do it eagerly.
3238  if (F->hasLocalLinkage()) {
3239  if (llvm::all_of(F->uses(), [&Functions](const Use &U) {
3240  const auto *CB = dyn_cast<CallBase>(U.getUser());
3241  return CB && CB->isCallee(&U) &&
3242  Functions.count(const_cast<Function *>(CB->getCaller()));
3243  }))
3244  continue;
3245  }
3246 
3247  // Populate the Attributor with abstract attribute opportunities in the
3248  // function and the information cache with IR information.
3249  A.identifyDefaultAbstractAttributes(*F);
3250  }
3251 
3252  ChangeStatus Changed = A.run();
3253 
3254  LLVM_DEBUG(dbgs() << "[Attributor] Done with " << Functions.size()
3255  << " functions, result: " << Changed << ".\n");
3256  return Changed == ChangeStatus::CHANGED;
3257 }
3258 
3259 void AADepGraph::viewGraph() { llvm::ViewGraph(this, "Dependency Graph"); }
3260 
3262  static std::atomic<int> CallTimes;
3263  std::string Prefix;
3264 
3265  if (!DepGraphDotFileNamePrefix.empty())
3267  else
3268  Prefix = "dep_graph";
3269  std::string Filename =
3270  Prefix + "_" + std::to_string(CallTimes.load()) + ".dot";
3271 
3272  outs() << "Dependency graph dump to " << Filename << ".\n";
3273 
3274  std::error_code EC;
3275 
3276  raw_fd_ostream File(Filename, EC, sys::fs::OF_TextWithCRLF);
3277  if (!EC)
3278  llvm::WriteGraph(File, this);
3279 
3280  CallTimes++;
3281 }
3282 
3284  for (auto DepAA : SyntheticRoot.Deps)
3285  cast<AbstractAttribute>(DepAA.getPointer())->printWithDeps(outs());
3286 }
3287 
3291  AnalysisGetter AG(FAM);
3292 
3293  SetVector<Function *> Functions;
3294  for (Function &F : M)
3295  Functions.insert(&F);
3296 
3297  CallGraphUpdater CGUpdater;
3299  InformationCache InfoCache(M, AG, Allocator, /* CGSCC */ nullptr);
3300  if (runAttributorOnFunctions(InfoCache, Functions, AG, CGUpdater,
3301  /* DeleteFns */ true, /* IsModulePass */ true)) {
3302  // FIXME: Think about passes we will preserve and add them here.
3303  return PreservedAnalyses::none();
3304  }
3305  return PreservedAnalyses::all();
3306 }
3307 
3310  LazyCallGraph &CG,
3311  CGSCCUpdateResult &UR) {
3313  AM.getResult<FunctionAnalysisManagerCGSCCProxy>(C, CG).getManager();
3314  AnalysisGetter AG(FAM);
3315 
3316  SetVector<Function *> Functions;
3317  for (LazyCallGraph::Node &N : C)
3318  Functions.insert(&N.getFunction());
3319 
3320  if (Functions.empty())
3321  return PreservedAnalyses::all();
3322 
3323  Module &M = *Functions.back()->getParent();
3324  CallGraphUpdater CGUpdater;
3325  CGUpdater.initialize(CG, C, AM, UR);
3327  InformationCache InfoCache(M, AG, Allocator, /* CGSCC */ &Functions);
3328  if (runAttributorOnFunctions(InfoCache, Functions, AG, CGUpdater,
3329  /* DeleteFns */ false,
3330  /* IsModulePass */ false)) {
3331  // FIXME: Think about passes we will preserve and add them here.
3332  PreservedAnalyses PA;
3334  return PA;
3335  }
3336  return PreservedAnalyses::all();
3337 }
3338 
3339 namespace llvm {
3340 
3341 template <> struct GraphTraits<AADepGraphNode *> {
3345 
3346  static NodeRef getEntryNode(AADepGraphNode *DGN) { return DGN; }
3347  static NodeRef DepGetVal(DepTy &DT) { return DT.getPointer(); }
3348 
3349  using ChildIteratorType =
3352 
3353  static ChildIteratorType child_begin(NodeRef N) { return N->child_begin(); }
3354 
3355  static ChildIteratorType child_end(NodeRef N) { return N->child_end(); }
3356 };
3357 
3358 template <>
3360  static NodeRef getEntryNode(AADepGraph *DG) { return DG->GetEntryNode(); }
3361 
3362  using nodes_iterator =
3364 
3365  static nodes_iterator nodes_begin(AADepGraph *DG) { return DG->begin(); }
3366 
3367  static nodes_iterator nodes_end(AADepGraph *DG) { return DG->end(); }
3368 };
3369 
3370 template <> struct DOTGraphTraits<AADepGraph *> : public DefaultDOTGraphTraits {
3372 
3373  static std::string getNodeLabel(const AADepGraphNode *Node,
3374  const AADepGraph *DG) {
3375  std::string AAString;
3376  raw_string_ostream O(AAString);
3377  Node->print(O);
3378  return AAString;
3379  }
3380 };
3381 
3382 } // end namespace llvm
3383 
3384 namespace {
3385 
3386 struct AttributorLegacyPass : public ModulePass {
3387  static char ID;
3388 
3389  AttributorLegacyPass() : ModulePass(ID) {
3391  }
3392 
3393  bool runOnModule(Module &M) override {
3394  if (skipModule(M))
3395  return false;
3396 
3397  AnalysisGetter AG;
3398  SetVector<Function *> Functions;
3399  for (Function &F : M)
3400  Functions.insert(&F);
3401 
3402  CallGraphUpdater CGUpdater;
3404  InformationCache InfoCache(M, AG, Allocator, /* CGSCC */ nullptr);
3405  return runAttributorOnFunctions(InfoCache, Functions, AG, CGUpdater,
3406  /* DeleteFns*/ true,
3407  /* IsModulePass */ true);
3408  }
3409 
3410  void getAnalysisUsage(AnalysisUsage &AU) const override {
3411  // FIXME: Think about passes we will preserve and add them here.
3413  }
3414 };
3415 
3416 struct AttributorCGSCCLegacyPass : public CallGraphSCCPass {
3417  static char ID;
3418 
3419  AttributorCGSCCLegacyPass() : CallGraphSCCPass(ID) {
3421  }
3422 
3423  bool runOnSCC(CallGraphSCC &SCC) override {
3424  if (skipSCC(SCC))
3425  return false;
3426 
3427  SetVector<Function *> Functions;
3428  for (CallGraphNode *CGN : SCC)
3429  if (Function *Fn = CGN->getFunction())
3430  if (!Fn->isDeclaration())
3431  Functions.insert(Fn);
3432 
3433  if (Functions.empty())
3434  return false;
3435 
3436  AnalysisGetter AG;
3437  CallGraph &CG = const_cast<CallGraph &>(SCC.getCallGraph());
3438  CallGraphUpdater CGUpdater;
3439  CGUpdater.initialize(CG, SCC);
3440  Module &M = *Functions.back()->getParent();
3442  InformationCache InfoCache(M, AG, Allocator, /* CGSCC */ &Functions);
3443  return runAttributorOnFunctions(InfoCache, Functions, AG, CGUpdater,
3444  /* DeleteFns */ false,
3445  /* IsModulePass */ false);
3446  }
3447 
3448  void getAnalysisUsage(AnalysisUsage &AU) const override {
3449  // FIXME: Think about passes we will preserve and add them here.
3452  }
3453 };
3454 
3455 } // end anonymous namespace
3456 
3457 Pass *llvm::createAttributorLegacyPass() { return new AttributorLegacyPass(); }
3459  return new AttributorCGSCCLegacyPass();
3460 }
3461 
3462 char AttributorLegacyPass::ID = 0;
3464 
3465 INITIALIZE_PASS_BEGIN(AttributorLegacyPass, "attributor",
3466  "Deduce and propagate attributes", false, false)
3468 INITIALIZE_PASS_END(AttributorLegacyPass, "attributor",
3470 INITIALIZE_PASS_BEGIN(AttributorCGSCCLegacyPass, "attributor-cgscc",
3471  "Deduce and propagate attributes (CGSCC pass)", false,
3472  false)
3475 INITIALIZE_PASS_END(AttributorCGSCCLegacyPass, "attributor-cgscc",
3476  "Deduce and propagate attributes (CGSCC pass)", false,
3477  false)
llvm::AA::isValidAtPosition
bool isValidAtPosition(const ValueAndContext &VAC, InformationCache &InfoCache)
Return true if the value of VAC is a valid at the position of VAC, that is a constant,...
Definition: Attributor.cpp:247
llvm::AAIsDead::isKnownDead
virtual bool isKnownDead() const =0
Returns true if the underlying value is known dead.
llvm::PreservedAnalyses
A set of analyses that are preserved following a run of a transformation pass.
Definition: PassManager.h:152
llvm::CallGraphUpdater
Wrapper to unify "old style" CallGraph and "new style" LazyCallGraph.
Definition: CallGraphUpdater.h:29
llvm::GraphTraits< AADepGraphNode * >::getEntryNode
static NodeRef getEntryNode(AADepGraphNode *DGN)
Definition: Attributor.cpp:3346
llvm::RecursivelyDeleteTriviallyDeadInstructions
bool RecursivelyDeleteTriviallyDeadInstructions(Value *V, const TargetLibraryInfo *TLI=nullptr, MemorySSAUpdater *MSSAU=nullptr, std::function< void(Value *)> AboutToDeleteCallback=std::function< void(Value *)>())
If the specified value is a trivially dead instruction, delete it.
Definition: Local.cpp:517
llvm::Argument
This class represents an incoming formal argument to a Function.
Definition: Argument.h:28
llvm::AANoSync::isAssumedNoSync
bool isAssumedNoSync() const
Returns true if "nosync" is assumed.
Definition: Attributor.h:3120
llvm::AAManager
A manager for alias analyses.
Definition: AliasAnalysis.h:1303
llvm::IRPosition::function
static const IRPosition function(const Function &F, const CallBaseContext *CBContext=nullptr)
Create a position describing the function scope of F.
Definition: Attributor.h:450
Attrs
Function Attrs
Definition: README_ALTIVEC.txt:215
llvm::OptimizationRemarkMissed
Diagnostic information for missed-optimization remarks.
Definition: DiagnosticInfo.h:735
llvm::AbstractCallSite::getCalledOperand
Value * getCalledOperand() const
Return the pointer to function that is being called.
Definition: AbstractCallSite.h:210
getName
static StringRef getName(Value *V)
Definition: ProvenanceAnalysisEvaluator.cpp:42
llvm::initializeAttributorLegacyPassPass
void initializeAttributorLegacyPassPass(PassRegistry &)
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:17
llvm::Attribute::isEnumAttribute
bool isEnumAttribute() const
Return true if the attribute is an Attribute::AttrKind type.
Definition: Attributes.cpp:260
llvm::GraphTraits< AADepGraphNode * >::child_end
static ChildIteratorType child_end(NodeRef N)
Definition: Attributor.cpp:3355
llvm::CallBase::getOperandBundlesAsDefs
void getOperandBundlesAsDefs(SmallVectorImpl< OperandBundleDef > &Defs) const
Return the list of operand bundles attached to this instruction as a vector of OperandBundleDefs.
Definition: Instructions.cpp:396
llvm::InvokeInst::Create
static InvokeInst * Create(FunctionType *Ty, Value *Func, BasicBlock *IfNormal, BasicBlock *IfException, ArrayRef< Value * > Args, const Twine &NameStr, Instruction *InsertBefore=nullptr)
Definition: Instructions.h:3807
llvm::Function::args
iterator_range< arg_iterator > args()
Definition: Function.h:765
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::make_range
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
Definition: iterator_range.h:53
llvm::TimeTraceScope
The TimeTraceScope is a helper class to call the begin and end functions of the time trace profiler.
Definition: TimeProfiler.h:67
llvm::CallInst::setTailCall
void setTailCall(bool IsTc=true)
Definition: Instructions.h:1668
llvm::ReturnInst
Return a value (possibly void), from a function.
Definition: Instructions.h:3004
llvm::WeakTrackingVH
Value handle that is nullable, but tries to track the Value.
Definition: ValueHandle.h:204
llvm::IRPosition::getCallBaseContext
const CallBaseContext * getCallBaseContext() const
Get the call base context from the position.
Definition: Attributor.h:744
llvm::Attributor::checkForAllUses
bool checkForAllUses(function_ref< bool(const Use &, bool &)> Pred, const AbstractAttribute &QueryingAA, const Value &V, bool CheckBBLivenessOnly=false, DepClassTy LivenessDepClass=DepClassTy::OPTIONAL, bool IgnoreDroppableUses=true, function_ref< bool(const Use &OldU, const Use &NewU)> EquivalentUseCB=nullptr)
Check Pred on all (transitive) uses of V.
Definition: Attributor.cpp:1283
FileSystem.h
llvm::IRPosition::getAssociatedFunction
Function * getAssociatedFunction() const
Return the associated function, if any.
Definition: Attributor.h:538
llvm::AbstractCallSite::getCallbackUses
static void getCallbackUses(const CallBase &CB, SmallVectorImpl< const Use * > &CallbackUses)
Add operand uses of CB that represent callback uses into CallbackUses.
Definition: AbstractCallSite.cpp:34
llvm::AttributeList::hasAttrSomewhere
bool hasAttrSomewhere(Attribute::AttrKind Kind, unsigned *Index=nullptr) const
Return true if the specified attribute is set for at least one parameter or for the return value.
Definition: Attributes.cpp:1413
llvm::GraphTraits< AADepGraph * >::nodes_begin
static nodes_iterator nodes_begin(AADepGraph *DG)
Definition: Attributor.cpp:3365
llvm::ModulePass
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
Definition: Pass.h:248
IntrinsicInst.h
llvm::Type::isPointerTy
bool isPointerTy() const
True if this is an instance of PointerType.
Definition: Type.h:218
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:780
llvm::cl::Prefix
@ Prefix
Definition: CommandLine.h:160
llvm::Function::getBasicBlockList
const BasicBlockListType & getBasicBlockList() const
Get the underlying elements of the Function...
Definition: Function.h:703
llvm::Attributor::ArgumentReplacementInfo
Helper struct used in the communication between an abstract attribute (AA) that wants to change the s...
Definition: Attributor.h:1825
llvm::Instruction::getNextNonDebugInstruction
const Instruction * getNextNonDebugInstruction(bool SkipPseudoOp=false) const
Return a pointer to the next non-debug instruction in the same basic block as 'this',...
Definition: Instruction.cpp:740
EnableHeapToStack
static cl::opt< bool > EnableHeapToStack("enable-heap-to-stack-conversion", cl::init(true), cl::Hidden)
llvm::GlobalValue::getLinkage
LinkageTypes getLinkage() const
Definition: GlobalValue.h:509
llvm::Function
Definition: Function.h:60
getFunction
static Function * getFunction(Constant *C)
Definition: Evaluator.cpp:233
llvm::cl::location
LocationClass< Ty > location(Ty &L)
Definition: CommandLine.h:447
llvm::Attribute
Definition: Attributes.h:65
llvm::DenseMapBase::lookup
ValueT lookup(const_arg_type_t< KeyT > Val) const
lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...
Definition: DenseMap.h:199
llvm::CallGraphUpdater::replaceCallSite
bool replaceCallSite(CallBase &OldCS, CallBase &NewCS)
Replace OldCS with the new call site NewCS.
Definition: CallGraphUpdater.cpp:145
llvm::AbstractAttribute::update
ChangeStatus update(Attributor &A)
Hook for the Attributor to trigger an update of the internal state.
Definition: Attributor.cpp:733
llvm::AAMemoryLocation::isKnownReadNone
bool isKnownReadNone() const
Return true if we know that the associated functions has no observable accesses.
Definition: Attributor.h:4121
llvm::raw_string_ostream
A raw_ostream that writes to an std::string.
Definition: raw_ostream.h:632
llvm::SetVector< T, SmallVector< T, N >, SmallDenseSet< T, N > >::size
size_type size() const
Determine the number of elements in the SetVector.
Definition: SetVector.h:77
llvm::Attribute::get
static Attribute get(LLVMContext &Context, AttrKind Kind, uint64_t Val=0)
Return a uniquified Attribute object.
Definition: Attributes.cpp:90
llvm::AANoRecurse
An abstract attribute for norecurse.
Definition: Attributor.h:3182
llvm::AAReachability
An abstract interface to determine reachability of point A to B.
Definition: Attributor.h:3280
llvm::AANoSync::isNoSyncIntrinsic
static bool isNoSyncIntrinsic(const Instruction *I)
Helper function specific for intrinsics which are potentially volatile.
Definition: AttributorAttributes.cpp:2015
llvm::AAPointerInfo::Access
An access description.
Definition: Attributor.h:4843
llvm::SmallVector< Value *, 8 >
Statistic.h
Wrapper
amdgpu aa AMDGPU Address space based Alias Analysis Wrapper
Definition: AMDGPUAliasAnalysis.cpp:31
llvm::IRPosition::value
static const IRPosition value(const Value &V, const CallBaseContext *CBContext=nullptr)
Create a position describing the value of V.
Definition: Attributor.h:431
llvm::AANoSync::isNonRelaxedAtomic
static bool isNonRelaxedAtomic(const Instruction *I)
Helper function used to determine whether an instruction is non-relaxed atomic.
Definition: AttributorAttributes.cpp:1979
llvm::Function::getSubprogram
DISubprogram * getSubprogram() const
Get the attached subprogram.
Definition: Metadata.cpp:1571
llvm::GraphTraits< AADepGraph * >::getEntryNode
static NodeRef getEntryNode(AADepGraph *DG)
Definition: Attributor.cpp:3360
llvm::cl::CommaSeparated
@ CommaSeparated
Definition: CommandLine.h:165
llvm::Use::get
Value * get() const
Definition: Use.h:66
llvm::AbstractAttribute::getName
virtual const std::string getName() const =0
This function should return the name of the AbstractAttribute.
llvm::erase_if
void erase_if(Container &C, UnaryPredicate P)
Provide a container algorithm similar to C++ Library Fundamentals v2's erase_if which is equivalent t...
Definition: STLExtras.h:1807
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::SubsumingPositionIterator::SubsumingPositionIterator
SubsumingPositionIterator(const IRPosition &IRP)
Definition: Attributor.cpp:811
Local.h
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:1050
llvm::CallGraph
The basic data container for the call graph of a Module of IR.
Definition: CallGraph.h:72
llvm::DominatorTree
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
Definition: Dominators.h:166
FAM
FunctionAnalysisManager FAM
Definition: PassBuilderBindings.cpp:59
llvm::IRPosition::getAttrs
void getAttrs(ArrayRef< Attribute::AttrKind > AKs, SmallVectorImpl< Attribute > &Attrs, bool IgnoreSubsumingPositions=false, Attributor *A=nullptr) const
Return the attributes of any kind in AKs existing in the IR at a position that will affect this one.
Definition: Attributor.cpp:897
llvm::verifyFunction
bool verifyFunction(const Function &F, raw_ostream *OS=nullptr)
Check a function for errors, useful for use when debugging a pass.
Definition: Verifier.cpp:6150
llvm::AADepGraph::dumpGraph
void dumpGraph()
Dump graph to file.
Definition: Attributor.cpp:3261
llvm::cl::Hidden
@ Hidden
Definition: CommandLine.h:139
llvm::detachDeadBlocks
void detachDeadBlocks(ArrayRef< BasicBlock * > BBs, SmallVectorImpl< DominatorTree::UpdateType > *Updates, bool KeepOneInputPHIs=false)
Replace contents of every block in BBs with single unreachable instruction.
Definition: BasicBlockUtils.cpp:60
llvm::Attributor::isRunOn
bool isRunOn(Function &Fn) const
Return true if we derive attributes for Fn.
Definition: Attributor.h:1537
llvm::PreservedAnalyses::none
static PreservedAnalyses none()
Convenience factory function for the empty preserved set.
Definition: PassManager.h:155
llvm::Function::getContext
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function.
Definition: Function.cpp:319
llvm::Function::arg_size
size_t arg_size() const
Definition: Function.h:774
llvm::AbstractState::indicatePessimisticFixpoint
virtual ChangeStatus indicatePessimisticFixpoint()=0
Indicate that the abstract state should converge to the pessimistic state.
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
MemoryBuiltins.h
llvm::AttributeList
Definition: Attributes.h:425
llvm::CallBase::getAttributes
AttributeList getAttributes() const
Return the parameter attributes for this call.
Definition: InstrTypes.h:1474
llvm::IRPosition::getAssociatedType
Type * getAssociatedType() const
Return the type this abstract attribute is associated with.
Definition: Attributor.h:602
llvm::AttributeList::getFnAttrs
AttributeSet getFnAttrs() const
The function attributes are returned.
Definition: Attributes.cpp:1388
checkForAllInstructionsImpl
static bool checkForAllInstructionsImpl(Attributor *A, InformationCache::OpcodeInstMapTy &OpcodeInstMap, function_ref< bool(Instruction &)> Pred, const AbstractAttribute *QueryingAA, const AAIsDead *LivenessAA, const ArrayRef< unsigned > &Opcodes, bool &UsedAssumedInformation, bool CheckBBLivenessOnly=false, bool CheckPotentiallyDead=false)
Definition: Attributor.cpp:1537
INITIALIZE_PASS_BEGIN
INITIALIZE_PASS_BEGIN(AttributorLegacyPass, "attributor", "Deduce and propagate attributes", false, false) INITIALIZE_PASS_END(AttributorLegacyPass
llvm::InformationCache
Data structure to hold cached (LLVM-IR) information.
Definition: Attributor.h:976
llvm::CallBase::isMustTailCall
bool isMustTailCall() const
Tests if this call site must be tail call optimized.
Definition: Instructions.cpp:298
llvm::AttributorConfig
Configuration for the Attributor.
Definition: Attributor.h:1222
llvm::Optional
Definition: APInt.h:33
llvm::isInlineViable
InlineResult isInlineViable(Function &Callee)
Minimal filter to detect invalid constructs for inlining.
Definition: InlineCost.cpp:2969
llvm::InformationCache::getAAResultsForFunction
AAResults * getAAResultsForFunction(const Function &F)
Return AliasAnalysis Result for function F.
Definition: Attributor.cpp:2769
llvm::GlobalValue::DefaultVisibility
@ DefaultVisibility
The GV is visible.
Definition: GlobalValue.h:63
llvm::mapped_iterator
Definition: STLExtras.h:298
llvm::SmallPtrSet
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
Definition: SmallPtrSet.h:450
llvm::AADepGraph::SyntheticRoot
AADepGraphNode SyntheticRoot
There is no root node for the dependency graph.
Definition: Attributor.h:383
llvm::AAPointerInfo::Access::getRemoteInst
Instruction * getRemoteInst() const
Return the actual instruction that causes the access.
Definition: Attributor.h:4884
llvm::CloneFunctionChangeType::LocalChangesOnly
@ LocalChangesOnly
llvm::Attributor::recordDependence
void recordDependence(const AbstractAttribute &FromAA, const AbstractAttribute &ToAA, DepClassTy DepClass)
Explicitly record a dependence from FromAA to ToAA, that is if FromAA changes ToAA should be updated ...
Definition: Attributor.cpp:2780
llvm::ore::NV
DiagnosticInfoOptimizationBase::Argument NV
Definition: OptimizationRemarkEmitter.h:136
isMustTailCall
static bool isMustTailCall(Value *V)
Definition: InstructionCombining.cpp:3050
llvm::Attributor::run
ChangeStatus run()
Run the analyses until a fixpoint is reached or enforced (timeout).
Definition: Attributor.cpp:2155
llvm::max
Expected< ExpressionValue > max(const ExpressionValue &Lhs, const ExpressionValue &Rhs)
Definition: FileCheck.cpp:337
llvm::errs
raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
Definition: raw_ostream.cpp:893
llvm::IRPosition::IRP_ARGUMENT
@ IRP_ARGUMENT
An attribute for a function argument.
Definition: Attributor.h:421
llvm::AADepGraphNode::end
aaiterator end()
Definition: Attributor.h:355
llvm::Attributor::~Attributor
~Attributor()
Definition: Attributor.cpp:1113
llvm::AAPointerInfo::Access::isWrittenValueUnknown
bool isWrittenValueUnknown() const
Return true if the value written cannot be determined at all.
Definition: Attributor.h:4890
llvm::IRPosition::IRP_RETURNED
@ IRP_RETURNED
An attribute for the function return value.
Definition: Attributor.h:417
llvm::Instruction::copyMetadata
void copyMetadata(const Instruction &SrcInst, ArrayRef< unsigned > WL=ArrayRef< unsigned >())
Copy metadata from SrcInst to this instruction.
Definition: Instruction.cpp:841
attributes
Deduce and propagate attributes
Definition: Attributor.cpp:3469
llvm::MipsISD::Ret
@ Ret
Definition: MipsISelLowering.h:119
llvm::ViewGraph
void ViewGraph(const GraphType &G, const Twine &Name, bool ShortNames=false, const Twine &Title="", GraphProgram::Name Program=GraphProgram::DOT)
ViewGraph - Emit a dot graph, run 'dot', run gv on the postscript file, then cleanup.
Definition: GraphWriter.h:427
llvm::createAttributorLegacyPass
Pass * createAttributorLegacyPass()
Definition: Attributor.cpp:3457
llvm::Attributor::checkForAllReturnedValues
bool checkForAllReturnedValues(function_ref< bool(Value &)> Pred, const AbstractAttribute &QueryingAA)
Check Pred on all values potentially returned by the function associated with QueryingAA.
Definition: Attributor.cpp:1515
llvm::changeToCall
CallInst * changeToCall(InvokeInst *II, DomTreeUpdater *DTU=nullptr)
This function converts the specified invoek into a normall call.
Definition: Local.cpp:2187
STLExtras.h
llvm::AbstractCallSite
AbstractCallSite.
Definition: AbstractCallSite.h:50
llvm::SmallVectorImpl::pop_back_val
LLVM_NODISCARD T pop_back_val()
Definition: SmallVector.h:654
llvm::AAFunctionReachability
An abstract Attribute for computing reachability between functions.
Definition: Attributor.h:4785
llvm::Type::isFloatingPointTy
bool isFloatingPointTy() const
Return true if this is one of the six floating-point types.
Definition: Type.h:163
and
We currently generate a but we really shouldn eax ecx xorl edx divl ecx eax divl ecx movl eax ret A similar code sequence works for division We currently compile i32 v2 eax eax jo LBB1_2 and
Definition: README.txt:1271
llvm::IRPosition::hasCallBaseContext
bool hasCallBaseContext() const
Check if the position has any call base context.
Definition: Attributor.h:747
llvm::AbstractCallSite::getNumArgOperands
unsigned getNumArgOperands() const
Return the number of parameters of the callee.
Definition: AbstractCallSite.h:154
llvm::AAIsDead::mayCatchAsynchronousExceptions
static bool mayCatchAsynchronousExceptions(const Function &F)
Determine if F might catch asynchronous exceptions.
Definition: Attributor.h:3476
llvm::InformationCache::InstructionVectorTy
SmallVector< Instruction *, 8 > InstructionVectorTy
A vector type to hold instructions.
Definition: Attributor.h:1068
llvm::IRPosition::IRP_FLOAT
@ IRP_FLOAT
A position that is not associated with a spot suitable for attributes.
Definition: Attributor.h:415
llvm::GlobalValue::setDSOLocal
void setDSOLocal(bool Local)
Definition: GlobalValue.h:285
MustExecute.h
llvm::MaxInitializationChainLength
unsigned MaxInitializationChainLength
The value passed to the line option that defines the maximal initialization chain length.
Definition: Attributor.cpp:94
LLVM_DEBUG
#define LLVM_DEBUG(X)
Definition: Debug.h:101
AnnotateDeclarationCallSites
static cl::opt< bool > AnnotateDeclarationCallSites("attributor-annotate-decl-cs", cl::Hidden, cl::desc("Annotate call sites of function declarations."), cl::init(false))
llvm::Function::addAttributeAtIndex
void addAttributeAtIndex(unsigned i, Attribute Attr)
adds the attribute to the list of attributes.
Definition: Function.cpp:531
F
#define F(x, y, z)
Definition: MD5.cpp:55
llvm::FunctionType::isVarArg
bool isVarArg() const
Definition: DerivedTypes.h:123
llvm::ConstantExpr::getPointerCast
static Constant * getPointerCast(Constant *C, Type *Ty)
Create a BitCast, AddrSpaceCast, or a PtrToInt cast constant expression.
Definition: Constants.cpp:2078
Uses
SmallPtrSet< MachineInstr *, 2 > Uses
Definition: ARMLowOverheadLoops.cpp:585
DumpDepGraph
static cl::opt< bool > DumpDepGraph("attributor-dump-dep-graph", cl::Hidden, cl::desc("Dump the dependency graph to dot files."), cl::init(false))
llvm::BasicBlock
LLVM Basic Block Representation.
Definition: BasicBlock.h:55
AliasAnalysis.h
llvm::Optional::hasValue
constexpr bool hasValue() const
Definition: Optional.h:312
PointerIntPair.h
llvm::createAttributorCGSCCLegacyPass
Pass * createAttributorCGSCCLegacyPass()
Definition: Attributor.cpp:3458
llvm::dbgs
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:163
llvm::AAMemoryBehavior::isKnownReadNone
bool isKnownReadNone() const
Return true if we know that the underlying value is not read or accessed in its respective scope.
Definition: Attributor.h:4043
FunctionSeedAllowList
static cl::list< std::string > FunctionSeedAllowList("attributor-function-seed-allow-list", cl::Hidden, cl::desc("Comma seperated list of function names that are " "allowed to be seeded."), cl::CommaSeparated)
llvm::isAllocationFn
bool isAllocationFn(const Value *V, const TargetLibraryInfo *TLI)
Tests if a value is a call or invoke to a library function that allocates or reallocates memory (eith...
Definition: MemoryBuiltins.cpp:272
llvm::Attributor::checkForAllCallSites
bool checkForAllCallSites(function_ref< bool(AbstractCallSite)> Pred, const AbstractAttribute &QueryingAA, bool RequireAllCallSites, bool &UsedAssumedInformation)
Check Pred on all function call sites.
Definition: Attributor.cpp:1371
llvm::AttributorConfig::DeleteFns
bool DeleteFns
Flag to determine if we can delete functions or keep dead ones around.
Definition: Attributor.h:1236
Arg
amdgpu Simplify well known AMD library false FunctionCallee Value * Arg
Definition: AMDGPULibCalls.cpp:186
Instruction.h
CommandLine.h
llvm::SPII::Load
@ Load
Definition: SparcInstrInfo.h:32
llvm::SetVector< T, SmallVector< T, N >, SmallDenseSet< T, N > >::remove
bool remove(const value_type &X)
Remove an item from the set vector.
Definition: SetVector.h:157
llvm::Attribute::getValueAsInt
uint64_t getValueAsInt() const
Return the attribute's value as an integer.
Definition: Attributes.cpp:283
llvm::AttributeList::hasAttributeAtIndex
bool hasAttributeAtIndex(unsigned Index, Attribute::AttrKind Kind) const
Return true if the attribute exists at the given index.
Definition: Attributes.cpp:1392
llvm::DenseMapInfo
An information struct used to provide DenseMap with the various necessary components for a given valu...
Definition: APInt.h:34
llvm::all_of
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1617
llvm::operator&=
bool operator&=(SparseBitVector< ElementSize > *LHS, const SparseBitVector< ElementSize > &RHS)
Definition: SparseBitVector.h:835
llvm::AreStatisticsEnabled
bool AreStatisticsEnabled()
Check if statistics are enabled.
Definition: Statistic.cpp:138
llvm::GraphTraits< AADepGraphNode * >::child_begin
static ChildIteratorType child_begin(NodeRef N)
Definition: Attributor.cpp:3353
GlobalValue.h
llvm::isNoAliasCall
bool isNoAliasCall(const Value *V)
Return true if this pointer is returned by a noalias function.
Definition: AliasAnalysis.cpp:962
llvm::AAIsDead::IS_REMOVABLE
@ IS_REMOVABLE
Definition: Attributor.h:3423
llvm::CallGraphSCC
CallGraphSCC - This is a single SCC that a CallGraphSCCPass is run on.
Definition: CallGraphSCCPass.h:87
llvm::PassRegistry::getPassRegistry
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
Definition: PassRegistry.cpp:31
llvm::LazyCallGraph::SCC
An SCC of the call graph.
Definition: LazyCallGraph.h:419
llvm::GlobalValue::isDeclaration
bool isDeclaration() const
Return true if the primary definition of this global value is outside of the current translation unit...
Definition: Globals.cpp:264
llvm::outs
raw_fd_ostream & outs()
This returns a reference to a raw_fd_ostream for standard output.
Definition: raw_ostream.cpp:885
llvm::AAMemoryBehavior
An abstract interface for memory access kind related attributes (readnone/readonly/writeonly).
Definition: Attributor.h:4024
Constants.h
llvm::AAResults
Definition: AliasAnalysis.h:511
llvm::ChangeStatus
ChangeStatus
{
Definition: Attributor.h:313
llvm::AAPointerInfo::Access::getWrittenValue
Value * getWrittenValue() const
Return the value writen, if any.
Definition: Attributor.h:4900
E
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
llvm::CallGraphUpdater::removeCallSite
void removeCallSite(CallBase &CS)
Remove the call site CS from the call graph.
Definition: CallGraphUpdater.cpp:162
llvm::SmallVectorImpl::append
void append(in_iter in_start, in_iter in_end)
Add the specified range to the end of the SmallVector.
Definition: SmallVector.h:667
llvm::AbstractAttribute::getState
virtual StateType & getState()=0
Return the internal abstract state for inspection.
llvm::User
Definition: User.h:44
llvm::IRPosition::inst
static const IRPosition inst(const Instruction &I, const CallBaseContext *CBContext=nullptr)
Create a position describing the instruction I.
Definition: Attributor.h:443
AllowShallowWrappers
static cl::opt< bool > AllowShallowWrappers("attributor-allow-shallow-wrappers", cl::Hidden, cl::desc("Allow the Attributor to create shallow " "wrappers for non-exact definitions."), cl::init(false))
PrintCallGraph
static cl::opt< bool > PrintCallGraph("attributor-print-call-graph", cl::Hidden, cl::desc("Print Attributor's internal call graph"), cl::init(false))
C
(vector float) vec_cmpeq(*A, *B) C
Definition: README_ALTIVEC.txt:86
llvm::ARM_PROC::A
@ A
Definition: ARMBaseInfo.h:34
llvm::AbstractAttribute::printWithDeps
virtual void printWithDeps(raw_ostream &OS) const
Definition: Attributor.cpp:3145
llvm::CallBase::getCalledFunction
Function * getCalledFunction() const
Returns the function called, or null if this is an indirect function invocation or the function signa...
Definition: InstrTypes.h:1396
llvm::AttributorCallGraph
Definition: Attributor.h:4682
llvm::CallBase::setAttributes
void setAttributes(AttributeList A)
Set the parameter attributes for this call.
Definition: InstrTypes.h:1478
llvm::AA::ValueAndContext
Definition: Attributor.h:160
llvm::CallInst::Create
static CallInst * Create(FunctionType *Ty, Value *F, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Definition: Instructions.h:1504
llvm::AnalysisUsage
Represent the analysis usage information of a pass.
Definition: PassAnalysisSupport.h:47
AllowDeepWrapper
static cl::opt< bool > AllowDeepWrapper("attributor-allow-deep-wrappers", cl::Hidden, cl::desc("Allow the Attributor to use IP information " "derived from non-exact functions via cloning"), cl::init(false))
llvm::AADepGraph::GetEntryNode
AADepGraphNode * GetEntryNode()
Definition: Attributor.h:384
llvm::AADepGraph::print
void print()
Print dependency graph.
Definition: Attributor.cpp:3283
llvm::AAMemoryLocation
An abstract interface for all memory location attributes (readnone/argmemonly/inaccessiblememonly/ina...
Definition: Attributor.h:4087
llvm::Value::uses
iterator_range< use_iterator > uses()
Definition: Value.h:376
false
Definition: StackSlotColoring.cpp:141
llvm::AANoSync
Definition: Attributor.h:3114
llvm::isPotentiallyReachable
bool isPotentiallyReachable(const Instruction *From, const Instruction *To, const SmallPtrSetImpl< BasicBlock * > *ExclusionSet=nullptr, const DominatorTree *DT=nullptr, const LoopInfo *LI=nullptr)
Determine whether instruction 'To' is reachable from 'From', without passing through any blocks in Ex...
Definition: CFG.cpp:232
B
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
DepGraphDotFileNamePrefix
static cl::opt< std::string > DepGraphDotFileNamePrefix("attributor-depgraph-dot-filename-prefix", cl::Hidden, cl::desc("The prefix used for the CallGraph dot file names."))
pass
modulo schedule Modulo Schedule test pass
Definition: ModuloSchedule.cpp:2123
llvm::Attributor::checkForAllInstructions
bool checkForAllInstructions(function_ref< bool(Instruction &)> Pred, const Function *Fn, const AbstractAttribute &QueryingAA, const ArrayRef< unsigned > &Opcodes, bool &UsedAssumedInformation, bool CheckBBLivenessOnly=false, bool CheckPotentiallyDead=false)
Check Pred on all instructions in Fn with an opcode present in Opcodes.
Definition: Attributor.cpp:1566
llvm::IRPosition::hasAttr
bool hasAttr(ArrayRef< Attribute::AttrKind > AKs, bool IgnoreSubsumingPositions=false, Attributor *A=nullptr) const
TODO: Figure out if the attribute related helper functions should live here or somewhere else.
Definition: Attributor.cpp:877
llvm::AbstractState::isValidState
virtual bool isValidState() const =0
Return if this abstract state is in a valid state.
llvm::Instruction
Definition: Instruction.h:42
llvm::DebugCounter::shouldExecute
static bool shouldExecute(unsigned CounterName)
Definition: DebugCounter.h:74
llvm::CallBase::addFnAttr
void addFnAttr(Attribute::AttrKind Kind)
Adds the attribute to the function.
Definition: InstrTypes.h:1506
llvm::IRPosition::getPositionKind
Kind getPositionKind() const
Return the associated position kind.
Definition: Attributor.h:647
llvm::IRPosition::getCtxI
Instruction * getCtxI() const
Return the context instruction, if any.
Definition: Attributor.h:579
llvm::DepClassTy::OPTIONAL
@ OPTIONAL
The target may be valid if the source is not.
llvm::AttributeList::getAttributes
AttributeSet getAttributes(unsigned Index) const
The attributes for the specified index are returned.
Definition: Attributes.cpp:1501
llvm::STATISTIC
STATISTIC(NumFunctions, "Total number of functions")
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:711
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:54
llvm::Function::removeParamAttr
void removeParamAttr(unsigned ArgNo, Attribute::AttrKind Kind)
removes the attribute from the list of attributes.
Definition: Function.cpp:607
llvm::GlobalObject::addMetadata
void addMetadata(unsigned KindID, MDNode &MD)
Add a metadata attachment.
Definition: Metadata.cpp:1298
llvm::InlineResult::isSuccess
bool isSuccess() const
Definition: InlineCost.h:173
llvm::IntegerRangeState
State for an integer range.
Definition: Attributor.h:2541
llvm::SmallVectorImpl::resize
void resize(size_type N)
Definition: SmallVector.h:619
llvm::operator<<
raw_ostream & operator<<(raw_ostream &OS, const APFixedPoint &FX)
Definition: APFixedPoint.h:230
llvm::UndefValue::get
static UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
Definition: Constants.cpp:1777
llvm::PotentialValuesState
A class for a set state.
Definition: Attributor.h:4321
llvm::Use::getUser
User * getUser() const
Returns the User that contains this Use.
Definition: Use.h:72
llvm::Attribute::getKindAsString
StringRef getKindAsString() const
Return the attribute's kind as a string.
Definition: Attributes.cpp:297
llvm::CallGraphNode
A node in the call graph for a module.
Definition: CallGraph.h:166
llvm::Attribute::isStringAttribute
bool isStringAttribute() const
Return true if the attribute is a string (target-dependent) attribute.
Definition: Attributes.cpp:268
llvm::SplitBlockPredecessors
BasicBlock * SplitBlockPredecessors(BasicBlock *BB, ArrayRef< BasicBlock * > Preds, const char *Suffix, DominatorTree *DT, LoopInfo *LI=nullptr, MemorySSAUpdater *MSSAU=nullptr, bool PreserveLCSSA=false)
This method introduces at least one new basic block into the function and moves some of the predecess...
Definition: BasicBlockUtils.cpp:1176
llvm::AbstractCallSite::getInstruction
CallBase * getInstruction() const
Return the underlying instruction.
Definition: AbstractCallSite.h:112
llvm::GraphTraits< AADepGraph * >::nodes_end
static nodes_iterator nodes_end(AADepGraph *DG)
Definition: Attributor.cpp:3367
llvm::AA::getPotentialCopiesOfStoredValue
bool getPotentialCopiesOfStoredValue(Attributor &A, StoreInst &SI, SmallSetVector< Value *, 4 > &PotentialCopies, const AbstractAttribute &QueryingAA, bool &UsedAssumedInformation, bool OnlyExact=false)
Collect all potential values of the one stored by SI into PotentialCopies.
Definition: Attributor.cpp:463
llvm::GlobalValue::InternalLinkage
@ InternalLinkage
Rename collisions when linking (static functions).
Definition: GlobalValue.h:55
llvm::MCID::Call
@ Call
Definition: MCInstrDesc.h:155
llvm::SPII::Store
@ Store
Definition: SparcInstrInfo.h:33
llvm::CallBase::getCallingConv
CallingConv::ID getCallingConv() const
Definition: InstrTypes.h:1455
llvm::SetVector::empty
bool empty() const
Determine if the SetVector is empty or not.
Definition: SetVector.h:72
llvm::None
const NoneType None
Definition: None.h:24
llvm::IRPosition::EmptyKey
static const IRPosition EmptyKey
Special DenseMap key values.
Definition: Attributor.h:752
llvm::lltok::Kind
Kind
Definition: LLToken.h:18
llvm::MustBeExecutedContextExplorer::findInContextOf
bool findInContextOf(const Instruction *I, const Instruction *PP)
Helper to look for I in the context of PP.
Definition: MustExecute.h:470
llvm::Value::use_empty
bool use_empty() const
Definition: Value.h:344
llvm::CallingConv::ID
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition: CallingConv.h:24
llvm::AbstractState::isAtFixpoint
virtual bool isAtFixpoint() const =0
Return if this abstract state is fixed, thus does not need to be updated if information changes as it...
llvm::AnalysisGetter::getAnalysis
Analysis::Result * getAnalysis(const Function &F)
Definition: Attributor.h:951
llvm::AADepGraphNode::Deps
TinyPtrVector< DepTy > Deps
Set of dependency graph nodes which should be updated if this one is updated.
Definition: Attributor.h:339
llvm::AbstractAttribute::getAsStr
virtual const std::string getAsStr() const =0
This function should return the "summarized" assumed state as string.
llvm::CallBase::getCaller
Function * getCaller()
Helper to get the caller (the parent function).
Definition: Instructions.cpp:282
INITIALIZE_PASS_END
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
Definition: PassSupport.h:58
llvm::sys::fs::OF_TextWithCRLF
@ OF_TextWithCRLF
The file should be opened in text mode and use a carriage linefeed '\r '.
Definition: FileSystem.h:770
llvm::DOTGraphTraits
DOTGraphTraits - Template class that can be specialized to customize how graphs are converted to 'dot...
Definition: DOTGraphTraits.h:166
llvm::AttributorCGSCCPass::run
PreservedAnalyses run(LazyCallGraph::SCC &C, CGSCCAnalysisManager &AM, LazyCallGraph &CG, CGSCCUpdateResult &UR)
Definition: Attributor.cpp:3308
llvm::AttributorCallGraph::print
void print()
Definition: AttributorAttributes.cpp:10238
llvm::Function::getAttributes
AttributeList getAttributes() const
Return the attribute list for this Function.
Definition: Function.h:314
llvm::ChangeStatus::UNCHANGED
@ UNCHANGED
llvm::InvokeInst
Invoke instruction.
Definition: Instructions.h:3763
llvm::AA::isValidInScope
bool isValidInScope(const Value &V, const Function *Scope)
Return true if V is a valid value in Scope, that is a constant or an instruction/argument of Scope.
Definition: Attributor.cpp:237
llvm::AA::isPotentiallyReachable
bool isPotentiallyReachable(Attributor &A, const Instruction &FromI, const Instruction &ToI, const AbstractAttribute &QueryingAA, std::function< bool(const Function &F)> GoBackwardsCB=nullptr)
Return true if ToI is potentially reachable from FromI.
Definition: Attributor.cpp:613
llvm::Type::isIntegerTy
bool isIntegerTy() const
True if this is an instance of IntegerType.
Definition: Type.h:191
llvm::function_ref
An efficient, type-erasing, non-owning reference to a callable.
Definition: STLFunctionalExtras.h:36
llvm::AAPointerInfo::Access::getKind
AccessKind getKind() const
Return the access kind.
Definition: Attributor.h:4871
llvm::PointerIntPair::getPointer
PointerTy getPointer() const
Definition: PointerIntPair.h:60
llvm::Attributor::createShallowWrapper
static void createShallowWrapper(Function &F)
Create a shallow wrapper for F such that F has internal linkage afterwards.
Definition: Attributor.cpp:2223
llvm::HighlightColor::Remark
@ Remark
llvm::AttributorPass::run
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)
Definition: Attributor.cpp:3288
PrintDependencies
static cl::opt< bool > PrintDependencies("attributor-print-dep", cl::Hidden, cl::desc("Print attribute dependencies"), cl::init(false))
llvm::ConstantExpr::getTrunc
static Constant * getTrunc(Constant *C, Type *Ty, bool OnlyIfReduced=false)
Definition: Constants.cpp:2128
llvm::cl::opt
Definition: CommandLine.h:1392
Attributor.h
llvm::Function::setSubprogram
void setSubprogram(DISubprogram *SP)
Set the attached subprogram.
Definition: Metadata.cpp:1567
llvm::RISCVFenceField::O
@ O
Definition: RISCVBaseInfo.h:239
llvm::IRPosition::callsite_argument
static const IRPosition callsite_argument(const CallBase &CB, unsigned ArgNo)
Create a position describing the argument of CB at position ArgNo.
Definition: Attributor.h:480
llvm::instructions
inst_range instructions(Function *F)
Definition: InstIterator.h:133
llvm::Function::getAttributeAtIndex
Attribute getAttributeAtIndex(unsigned i, Attribute::AttrKind Kind) const
gets the attribute from the list of attributes.
Definition: Function.cpp:642
llvm::StoreInst
An instruction for storing to memory.
Definition: Instructions.h:297
llvm::Attributor::ArgumentReplacementInfo::ACSRepairCBTy
std::function< void(const ArgumentReplacementInfo &, AbstractCallSite, SmallVectorImpl< Value * > &)> ACSRepairCBTy
Abstract call site (ACS) repair callback type.
Definition: Attributor.h:1848
llvm::AttributeList::getRetAttrs
AttributeSet getRetAttrs() const
The attributes for the ret value are returned.
Definition: Attributes.cpp:1384
llvm::getInitialValueOfAllocation
Constant * getInitialValueOfAllocation(const Value *V, const TargetLibraryInfo *TLI, Type *Ty)
If this is a call to an allocation function that initializes memory to a fixed value,...
Definition: MemoryBuiltins.cpp:423
llvm::Constant
This is an important base class in LLVM.
Definition: Constant.h:41
llvm::Instruction::eraseFromParent
SymbolTableList< Instruction >::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
Definition: Instruction.cpp:77
llvm::NONE
@ NONE
Do not track a dependence between source and target.
llvm::AttributorConfig::CGUpdater
CallGraphUpdater & CGUpdater
Helper to update an underlying call graph and to delete functions.
Definition: Attributor.h:1249
llvm::operator|
APInt operator|(APInt a, const APInt &b)
Definition: APInt.h:2022
llvm::Function::getReturnType
Type * getReturnType() const
Returns the type of the ret val.
Definition: Function.h:180
llvm::AbstractAttribute
Base struct for all "concrete attribute" deductions.
Definition: Attributor.h:2895
llvm::DenseMapBase< DenseMap< KeyT, ValueT, DenseMapInfo< KeyT >, llvm::detail::DenseMapPair< KeyT, ValueT > >, KeyT, ValueT, DenseMapInfo< KeyT >, llvm::detail::DenseMapPair< KeyT, ValueT > >::clear
void clear()
Definition: DenseMap.h:112
llvm::CallGraphSCCPass::getAnalysisUsage
void getAnalysisUsage(AnalysisUsage &Info) const override
getAnalysisUsage - For this class, we declare that we require and preserve the call graph.
Definition: CallGraphSCCPass.cpp:658
llvm::getPointerOperand
const Value * getPointerOperand(const Value *V)
A helper function that returns the pointer operand of a load, store or GEP instruction.
Definition: Instructions.h:5331
llvm::Attributor::getAssumedConstant
Optional< Constant * > getAssumedConstant(const IRPosition &IRP, const AbstractAttribute &AA, bool &UsedAssumedInformation)
If IRP is assumed to be a constant, return it, if it is unclear yet, return None, otherwise return nu...
Definition: Attributor.cpp:1025
llvm::InformationCache::getOpcodeInstMapForFunction
OpcodeInstMapTy & getOpcodeInstMapForFunction(const Function &F)
Return the map that relates "interesting" opcodes with all instructions with that opcode in F.
Definition: Attributor.h:1075
llvm::TargetLibraryInfoWrapperPass
Definition: TargetLibraryInfo.h:468
uint64_t
llvm::DepClassTy::REQUIRED
@ REQUIRED
The target cannot be valid if the source is not.
llvm::GlobalValue::getParent
Module * getParent()
Get the module that this global value is contained inside of...
Definition: GlobalValue.h:620
INITIALIZE_PASS_DEPENDENCY
INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
llvm::PreservedAnalyses::preserve
void preserve()
Mark an analysis as preserved.
Definition: PassManager.h:173
llvm::AttributorConfig::RewriteSignatures
bool RewriteSignatures
Flag to determine if we rewrite function signatures.
Definition: Attributor.h:1239
llvm::AAPointerInfo::Access::getContent
Optional< Value * > getContent() const
Return the written value which can be llvm::null if it is not yet determined.
Definition: Attributor.h:4904
llvm::BumpPtrAllocatorImpl
Allocate memory in an ever growing pool, as if by bump-pointer.
Definition: Allocator.h:63
move
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
Definition: README.txt:546
llvm::LLVMContext
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:68
llvm::IRPosition::IRP_FUNCTION
@ IRP_FUNCTION
An attribute for a function (scope).
Definition: Attributor.h:419
llvm::numbers::e
constexpr double e
Definition: MathExtras.h:57
llvm::IRPosition::getAnchorValue
Value & getAnchorValue() const
Return the value this abstract attribute is anchored with.
Definition: Attributor.h:524
DEBUG_COUNTER
DEBUG_COUNTER(ManifestDBGCounter, "attributor-manifest", "Determine what attributes are manifested in the IR")
llvm::DenseMap
Definition: DenseMap.h:716
llvm::Attributor::registerFunctionSignatureRewrite
bool registerFunctionSignatureRewrite(Argument &Arg, ArrayRef< Type * > ReplacementTypes, ArgumentReplacementInfo::CalleeRepairCBTy &&CalleeRepairCB, ArgumentReplacementInfo::ACSRepairCBTy &&ACSRepairCB)
Register a rewrite for a function signature.
Definition: Attributor.cpp:2416
llvm::CallGraphWrapperPass
The ModulePass which wraps up a CallGraph and the logic to build it.
Definition: CallGraph.h:336
llvm::fillMapFromAssume
void fillMapFromAssume(AssumeInst &Assume, RetainedKnowledgeMap &Result)
Insert into the map all the informations contained in the operand bundles of the llvm....
Definition: AssumeBundleQueries.cpp:70
llvm::Attribute::getKindAsEnum
Attribute::AttrKind getKindAsEnum() const
Return the attribute's kind as an enum (Attribute::AttrKind).
Definition: Attributes.cpp:276
I
#define I(x, y, z)
Definition: MD5.cpp:58
getCalledFunction
static const Function * getCalledFunction(const Value *V, bool &IsNoBuiltin)
Definition: MemoryBuiltins.cpp:160
Cloning.h
llvm::IRPosition::getAssociatedValue
Value & getAssociatedValue() const
Return the value this abstract attribute is associated with.
Definition: Attributor.h:593
llvm::AA::getWithType
Value * getWithType(Value &V, Type &Ty)
Try to convert V to type Ty without introducing new instructions.
Definition: Attributor.cpp:273
llvm::Attribute::AttrKind
AttrKind
This enumeration lists the attributes that can be associated with parameters, function results,...
Definition: Attributes.h:84
llvm::cl::init
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:432
llvm::IRPosition::getAssociatedArgument
Argument * getAssociatedArgument() const
Return the associated argument, if any.
Definition: Attributor.cpp:679
propagate
static void propagate(InstantiatedValue From, InstantiatedValue To, MatchState State, ReachabilitySet &ReachSet, std::vector< WorkListItem > &WorkList)
Definition: CFLAndersAliasAnalysis.cpp:596
llvm::is_contained
bool is_contained(R &&Range, const E &Element)
Wrapper function around std::find to detect if an element exists in a container.
Definition: STLExtras.h:1682
llvm::GlobalValue::setLinkage
void setLinkage(LinkageTypes LT)
Definition: GlobalValue.h:502
llvm::IRPosition::getAttrIdx
unsigned getAttrIdx() const
Return the index in the attribute list for this position.
Definition: Attributor.h:627
llvm::AAIsDead
An abstract interface for liveness abstract attribute.
Definition: Attributor.h:3415
llvm::MustBeExecutedContextExplorer::begin
iterator & begin(const Instruction *PP)
Return an iterator to explore the context around PP.
Definition: MustExecute.h:420
llvm::Function::Create
static Function * Create(FunctionType *Ty, LinkageTypes Linkage, unsigned AddrSpace, const Twine &N="", Module *M=nullptr)
Definition: Function.h:137
llvm::AbstractState
An interface to query the internal state of an abstract attribute.
Definition: Attributor.h:2218
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::AADepGraph::end
iterator end()
Definition: Attributor.h:387
llvm::Optional::getValue
constexpr const T & getValue() const &
Definition: Optional.h:306
SI
StandardInstrumentations SI(Debug, VerifyEach)
llvm::GlobalValue::hasLocalLinkage
bool hasLocalLinkage() const
Definition: GlobalValue.h:493
InlineCost.h
llvm::WriteGraph
raw_ostream & WriteGraph(raw_ostream &O, const GraphType &G, bool ShortNames=false, const Twine &Title="")
Definition: GraphWriter.h:359
llvm::IRPosition
Helper to describe and deal with positions in the LLVM-IR.
Definition: Attributor.h:407
function
print Print MemDeps of function
Definition: MemDepPrinter.cpp:82
llvm::Type::isVoidTy
bool isVoidTy() const
Return true if this is 'void'.
Definition: Type.h:139
addIfNotExistent
static bool addIfNotExistent(LLVMContext &Ctx, const Attribute &Attr, AttributeList &Attrs, int AttrIdx, bool ForceReplace=false)
Return true if the information provided by Attr was added to the attribute list Attrs.
Definition: Attributor.cpp:643
llvm::DOTGraphTraits< AADepGraph * >::getNodeLabel
static std::string getNodeLabel(const AADepGraphNode *Node, const AADepGraph *DG)
Definition: Attributor.cpp:3373
llvm::Module
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
llvm::AbstractCallSite::getCalleeUseForCallback
const Use & getCalleeUseForCallback() const
Return the use of the callee value in the underlying instruction.
Definition: AbstractCallSite.h:202
TinyPtrVector.h
llvm::Attributor::checkForAllReadWriteInstructions
bool checkForAllReadWriteInstructions(function_ref< bool(Instruction &)> Pred, AbstractAttribute &QueryingAA, bool &UsedAssumedInformation)
Check Pred on all Read/Write instructions.
Definition: Attributor.cpp:1606
llvm::MustBeExecutedContextExplorer
A "must be executed context" for a given program point PP is the set of instructions,...
Definition: MustExecute.h:386
llvm::LazyCallGraph::Node
A node in the call graph.
Definition: LazyCallGraph.h:315
llvm::SmallPtrSetImpl::count
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
Definition: SmallPtrSet.h:383
llvm::ARM::WinEH::ReturnType
ReturnType
Definition: ARMWinEH.h:25
llvm::Function::getFunction
const Function & getFunction() const
Definition: Function.h:135
llvm::User::isDroppable
bool isDroppable() const
A droppable user is a user for which uses can be dropped without affecting correctness and should be ...
Definition: User.cpp:115
llvm::AbstractCallSite::isCallbackCall
bool isCallbackCall() const
Return true if this ACS represents a callback call.
Definition: AbstractCallSite.h:125
llvm::AAPointerInfo::Access::isWrittenValueYetUndetermined
bool isWrittenValueYetUndetermined() const
Return true if the value written is not known yet.
Definition: Attributor.h:4887
llvm::SetVector< T, SmallVector< T, N >, SmallDenseSet< T, N > >::insert
bool insert(const value_type &X)
Insert a new element into the SetVector.
Definition: SetVector.h:141
llvm::AA::isAssumedReadNone
bool isAssumedReadNone(Attributor &A, const IRPosition &IRP, const AbstractAttribute &QueryingAA, bool &IsKnown)
Return true if IRP is readnone.
Definition: Attributor.cpp:508
llvm::AMDGPU::CPol::SCC
@ SCC
Definition: SIDefines.h:304
llvm::Attributor::identifyDefaultAbstractAttributes
void identifyDefaultAbstractAttributes(Function &F)
Determine opportunities to derive 'default' attributes in F and create abstract attribute objects for...
Definition: Attributor.cpp:2808
llvm::IRPosition::IRP_CALL_SITE_RETURNED
@ IRP_CALL_SITE_RETURNED
An attribute for a call site return value.
Definition: Attributor.h:418
llvm::make_pointer_range
iterator_range< pointer_iterator< WrappedIteratorT > > make_pointer_range(RangeT &&Range)
Definition: iterator.h:363
llvm::AA::getPotentiallyLoadedValues
bool getPotentiallyLoadedValues(Attributor &A, LoadInst &LI, SmallSetVector< Value *, 4 > &PotentialValues, SmallSetVector< Instruction *, 4 > &PotentialValueOrigins, const AbstractAttribute &QueryingAA, bool &UsedAssumedInformation, bool OnlyExact=false)
Collect all potential values LI could read into PotentialValues.
Definition: Attributor.cpp:453
llvm::MustBeExecutedContextExplorer::end
iterator & end()
Return an universal end iterator.
Definition: MustExecute.h:434
llvm::ArrayRef
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: APInt.h:32
llvm::isInstructionTriviallyDead
bool isInstructionTriviallyDead(Instruction *I, const TargetLibraryInfo *TLI=nullptr)
Return true if the result produced by the instruction is not used, and the instruction will return.
Definition: Local.cpp:395
llvm::CGSCC
@ CGSCC
Definition: Attributor.h:5035
llvm::AA::isDynamicallyUnique
bool isDynamicallyUnique(Attributor &A, const AbstractAttribute &QueryingAA, const Value &V, bool ForAnalysisOnly=true)
Return true if V is dynamically unique, that is, there are no two "instances" of V at runtime with di...
Definition: Attributor.cpp:211
llvm::IRPosition::IRP_INVALID
@ IRP_INVALID
An invalid position.
Definition: Attributor.h:414
llvm::min
Expected< ExpressionValue > min(const ExpressionValue &Lhs, const ExpressionValue &Rhs)
Definition: FileCheck.cpp:357
llvm::any_of
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1624
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
llvm::AttributorCallGraph::populateAll
void populateAll() const
Force populate the entire call graph.
Definition: Attributor.h:4695
llvm::AA::getAssumedUnderlyingObjects
bool getAssumedUnderlyingObjects(Attributor &A, const Value &Ptr, SmallVectorImpl< Value * > &Objects, const AbstractAttribute &QueryingAA, const Instruction *CtxI, bool &UsedAssumedInformation, AA::ValueScope VS=Interprocedural)
Collect all potential underlying objects of Ptr at position CtxI in Objects.
Definition: AttributorAttributes.cpp:459
llvm_unreachable
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:143
llvm::operator|=
bool operator|=(SparseBitVector< ElementSize > &LHS, const SparseBitVector< ElementSize > *RHS)
Definition: SparseBitVector.h:823
llvm::Value::getType
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:255
llvm::BasicBlock::getUniquePredecessor
const BasicBlock * getUniquePredecessor() const
Return the predecessor of this block if it has a unique predecessor block.
Definition: BasicBlock.cpp:269
llvm::AAPointerInfo
An abstract interface for struct information.
Definition: Attributor.h:4833
llvm::Instruction::getFunction
const Function * getFunction() const
Return the function this instruction belongs to.
Definition: Instruction.cpp:69
llvm::IRAttributeManifest::manifestAttrs
static ChangeStatus manifestAttrs(Attributor &A, const IRPosition &IRP, const ArrayRef< Attribute > &DeducedAttrs, bool ForceReplace=false)
Definition: Attributor.cpp:749
llvm::Value::replaceAllUsesWith
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
Definition: Value.cpp:529
llvm::BasicBlock::Create
static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)
Creates a new BasicBlock.
Definition: BasicBlock.h:97
MaxInitializationChainLengthX
static cl::opt< unsigned, true > MaxInitializationChainLengthX("attributor-max-initialization-chain-length", cl::Hidden, cl::desc("Maximal number of chained initializations (to avoid stack overflows)"), cl::location(MaxInitializationChainLength), cl::init(1024))
llvm::Value::getContext
LLVMContext & getContext() const
All values hold a context through their type.
Definition: Value.cpp:991
llvm::ilist_node_impl::getIterator
self_iterator getIterator()
Definition: ilist_node.h:82
isEqualOrWorse
static bool isEqualOrWorse(const Attribute &New, const Attribute &Old)
Return true if New is equal or worse than Old.
Definition: Attributor.cpp:633
llvm::GlobalObject::hasMetadata
bool hasMetadata() const
Return true if this value has any metadata attached to it.
Definition: Value.h:588
llvm::AttributeFuncs::updateMinLegalVectorWidthAttr
void updateMinLegalVectorWidthAttr(Function &Fn, uint64_t Width)
Update min-legal-vector-width if it is in Attribute and less than Width.
Definition: Attributes.cpp:2068
S
add sub stmia L5 ldr r0 bl L_printf $stub Instead of a and a wouldn t it be better to do three moves *Return an aggregate type is even return S
Definition: README.txt:210
VerifyMaxFixpointIterations
static cl::opt< bool > VerifyMaxFixpointIterations("attributor-max-iterations-verify", cl::Hidden, cl::desc("Verify that max-iterations is a tight bound for a fixpoint"), cl::init(false))
attributor
attributor
Definition: Attributor.cpp:3468
llvm::ChangeStatus::CHANGED
@ CHANGED
llvm::Module::getFunctionList
const FunctionListType & getFunctionList() const
Get the Module's list of functions (constant).
Definition: Module.h:559
llvm::Attributor::isInternalizable
static bool isInternalizable(Function &F)
Returns true if the function F can be internalized.
Definition: Attributor.cpp:2270
CallGraphSCCPass.h
llvm::AbstractState::indicateOptimisticFixpoint
virtual ChangeStatus indicateOptimisticFixpoint()=0
Indicate that the abstract state should converge to the optimistic state.
LLVM_FALLTHROUGH
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
Definition: Compiler.h:280
llvm::Value::getName
StringRef getName() const
Return a constant reference to the value's name.
Definition: Value.cpp:305
llvm::ValueMap< const Value *, WeakTrackingVH >
llvm::LoadInst
An instruction for reading from memory.
Definition: Instructions.h:173
ValueHandle.h
llvm::raw_fd_ostream
A raw_ostream that writes to a file descriptor.
Definition: raw_ostream.h:444
llvm::Attributor::internalizeFunction
static Function * internalizeFunction(Function &F, bool Force=false)
Make another copy of the function F such that the copied version has internal linkage afterwards and ...
Definition: Attributor.cpp:2277
llvm::AAPointerInfo::Access::isWrite
bool isWrite() const
Return true if this is a write access.
Definition: Attributor.h:4877
llvm::Init
Definition: Record.h:281
llvm::IRPosition::IRP_CALL_SITE_ARGUMENT
@ IRP_CALL_SITE_ARGUMENT
An attribute for a call site argument.
Definition: Attributor.h:422
llvm::Function::begin
iterator begin()
Definition: Function.h:726
llvm::Value::stripPointerCasts
const Value * stripPointerCasts() const
Strip off pointer casts, all-zero GEPs and address space casts.
Definition: Value.cpp:682
llvm::SmallPtrSetImplBase::size
size_type size() const
Definition: SmallPtrSet.h:93
llvm::AA::ValueAndContext::getCtxI
const Instruction * getCtxI() const
Definition: Attributor.h:167
llvm::InformationCache::getReadOrWriteInstsForFunction
InstructionVectorTy & getReadOrWriteInstsForFunction(const Function &F)
Return the instructions in F that may read or write memory.
Definition: Attributor.h:1080
llvm::BasicBlock::front
const Instruction & front() const
Definition: BasicBlock.h:309
llvm::DenseMapBase::empty
LLVM_NODISCARD bool empty() const
Definition: DenseMap.h:98
llvm::IRPosition::getAnchorScope
Function * getAnchorScope() const
Return the Function surrounding the anchor value.
Definition: Attributor.h:567
Callee
amdgpu Simplify well known AMD library false FunctionCallee Callee
Definition: AMDGPULibCalls.cpp:186
llvm::SetVector::clear
void clear()
Completely clear the SetVector.
Definition: SetVector.h:220
getPotentialCopiesOfMemoryValue
static bool getPotentialCopiesOfMemoryValue(Attributor &A, Ty &I, SmallSetVector< Value *, 4 > &PotentialCopies, SmallSetVector< Instruction *, 4 > &PotentialValueOrigins, const AbstractAttribute &QueryingAA, bool &UsedAssumedInformation, bool OnlyExact)
Definition: Attributor.cpp:320
llvm::operator&
APInt operator&(APInt a, const APInt &b)
Definition: APInt.h:2002
Attributes.h
llvm::Attributor::isValidFunctionSignatureRewrite
bool isValidFunctionSignatureRewrite(Argument &Arg, ArrayRef< Type * > ReplacementTypes)
Check if we can rewrite a function signature.
Definition: Attributor.cpp:2351
llvm::AA::isAssumedReadOnly
bool isAssumedReadOnly(Attributor &A, const IRPosition &IRP, const AbstractAttribute &QueryingAA, bool &IsKnown)
Return true if IRP is readonly.
Definition: Attributor.cpp:503
llvm::AAIsDead::isRemovableStore
virtual bool isRemovableStore() const
Return true if the underlying value is a store that is known to be removable.
Definition: Attributor.h:3455
Constant.h
llvm::CGSCCUpdateResult
Support structure for SCC passes to communicate updates the call graph back to the CGSCC pass manager...
Definition: CGSCCPassManager.h:232
llvm::ConstantFoldTerminator
bool ConstantFoldTerminator(BasicBlock *BB, bool DeleteDeadConditions=false, const TargetLibraryInfo *TLI=nullptr, DomTreeUpdater *DTU=nullptr)
If a terminator instruction is predicated on a constant value, convert it into an unconditional branc...
Definition: Local.cpp:125
Verifier.h
llvm::ConstantExpr
A constant value that is initialized with an expression using other constant values.
Definition: Constants.h:972
llvm::SPIRV::LoopControl::MaxIterations
@ MaxIterations
llvm::IRPosition::IRP_CALL_SITE
@ IRP_CALL_SITE
An attribute for a call site (function scope).
Definition: Attributor.h:420
GraphWriter.h
llvm::IRPosition::getCallSiteArgNo
int getCallSiteArgNo() const
Return the call site argument number of the associated value if it is an argument or call site argume...
Definition: Attributor.h:622
EnableCallSiteSpecific
static cl::opt< bool > EnableCallSiteSpecific("attributor-enable-call-site-specific-deduction", cl::Hidden, cl::desc("Allow the Attributor to do call site specific analysis"), cl::init(false))
llvm::Constant::getNullValue
static Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
Definition: Constants.cpp:350
llvm::Function::removeAttributeAtIndex
void removeAttributeAtIndex(unsigned i, Attribute::AttrKind Kind)
removes the attribute from the list of attributes.
Definition: Function.cpp:575
llvm::GlobalValue::isInterposableLinkage
static bool isInterposableLinkage(LinkageTypes Linkage)
Whether the definition of this global may be replaced by something non-equivalent at link time.
Definition: GlobalValue.h:390
llvm::AMDGPU::SendMsg::Op
Op
Definition: SIDefines.h:345
llvm::PreservedAnalyses::all
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition: PassManager.h:158
llvm::Function::getArg
Argument * getArg(unsigned i) const
Definition: Function.h:759
GlobalVariable.h
llvm::GraphTraits< AADepGraphNode * >
Definition: Attributor.cpp:3341
llvm::CallGraphUpdater::replaceFunctionWith
void replaceFunctionWith(Function &OldFn, Function &NewFn)
Replace OldFn in the call graph (and SCC) with NewFn.
Definition: CallGraphUpdater.cpp:125
Success
#define Success
Definition: AArch64Disassembler.cpp:280
llvm::AA::isNoSyncInst
bool isNoSyncInst(Attributor &A, const Instruction &I, const AbstractAttribute &QueryingAA)
Return true if I is a nosync instruction.
Definition: Attributor.cpp:186
Casting.h
llvm::TinyPtrVector::iterator
EltTy * iterator
Definition: TinyPtrVector.h:180
llvm::CallGraphSCCPass
Definition: CallGraphSCCPass.h:34
llvm::DepClassTy
DepClassTy
Definition: Attributor.h:323
DebugCounter.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::TargetLibraryInfo
Provides information about what library functions are available for the current target.
Definition: TargetLibraryInfo.h:222
llvm::Attributor
The fixpoint analysis framework that orchestrates the attribute deduction.
Definition: Attributor.h:1295
llvm::ReturnInst::Create
static ReturnInst * Create(LLVMContext &C, Value *retVal=nullptr, Instruction *InsertBefore=nullptr)
Definition: Instructions.h:3031
llvm::AAPointerInfo::Access::getLocalInst
Instruction * getLocalInst() const
Return the instruction that causes the access with respect to the local scope of the associated attri...
Definition: Attributor.h:4881
llvm::PointerIntPair::getOpaqueValue
void * getOpaqueValue() const
Definition: PointerIntPair.h:92
llvm::Function::getFunctionType
FunctionType * getFunctionType() const
Returns the FunctionType for me.
Definition: Function.h:175
llvm::IRPosition::argument
static const IRPosition argument(const Argument &Arg, const CallBaseContext *CBContext=nullptr)
Create a position describing the argument Arg.
Definition: Attributor.h:464
llvm::SetVector::front
const T & front() const
Return the first element of the SetVector.
Definition: SetVector.h:122
llvm::AttributeList::getAttributeAtIndex
Attribute getAttributeAtIndex(unsigned Index, Attribute::AttrKind Kind) const
Return the attribute object that exists at the given index.
Definition: Attributes.cpp:1418
llvm::IRPosition::callsite_function
static const IRPosition callsite_function(const CallBase &CB)
Create a position describing the function scope of CB.
Definition: Attributor.h:470
llvm::AbstractAttribute::print
void print(raw_ostream &OS) const override
Helper functions, for debug purposes only.
Definition: Attributor.cpp:3129
llvm::ConstantExpr::getFPTrunc
static Constant * getFPTrunc(Constant *C, Type *Ty, bool OnlyIfReduced=false)
Definition: Constants.cpp:2170
isSimple
static bool isSimple(Instruction *I)
Definition: SLPVectorizer.cpp:664
llvm::Function::arg_begin
arg_iterator arg_begin()
Definition: Function.h:741
llvm::AADepGraphNode::begin
aaiterator begin()
Definition: Attributor.h:354
llvm::AA::combineOptionalValuesInAAValueLatice
Optional< Value * > combineOptionalValuesInAAValueLatice(const Optional< Value * > &A, const Optional< Value * > &B, Type *Ty)
Return the combination of A and B such that the result is a possible value of both.
Definition: Attributor.cpp:296
llvm::GraphTraits< AADepGraphNode * >::ChildEdgeIteratorType
TinyPtrVector< DepTy >::iterator ChildEdgeIteratorType
Definition: Attributor.cpp:3351
llvm::GlobalValue::getAddressSpace
unsigned getAddressSpace() const
Definition: Globals.cpp:121
llvm::AADepGraph
The data structure for the dependency graph.
Definition: Attributor.h:371
AA
llvm::AADepGraphNode
}
Definition: Attributor.h:331
CallGraph.h
cgscc
Deduce and propagate false attributor cgscc
Definition: Attributor.cpp:3475
llvm::DominatorTreeAnalysis
Analysis pass which computes a DominatorTree.
Definition: Dominators.h:267
llvm::Function::isVarArg
bool isVarArg() const
isVarArg - Return true if this function takes a variable number of arguments.
Definition: Function.h:188
llvm::changeToUnreachable
unsigned changeToUnreachable(Instruction *I, bool PreserveLCSSA=false, DomTreeUpdater *DTU=nullptr, MemorySSAUpdater *MSSAU=nullptr)
Insert an unreachable instruction before the specified instruction, making it and the rest of the cod...
Definition: Local.cpp:2122
llvm::Pass
Pass interface - Implemented by all 'passes'.
Definition: Pass.h:91
llvm::CallGraphUpdater::removeFunction
void removeFunction(Function &Fn)
Remove Fn from the call graph.
Definition: CallGraphUpdater.cpp:109
llvm::GlobalValue::PrivateLinkage
@ PrivateLinkage
Like Internal, but omit from symbol table.
Definition: GlobalValue.h:56
Instructions.h
llvm::InformationCache::getAnalysisResultForFunction
AP::Result * getAnalysisResultForFunction(const Function &F)
Return the analysis result from a pass AP for function F.
Definition: Attributor.h:1110
llvm::PointerIntPair
PointerIntPair - This class implements a pair of a pointer and small integer.
Definition: PointerIntPair.h:46
llvm::AttributeSet
Definition: Attributes.h:290
llvm::DOTGraphTraits< AADepGraph * >::DOTGraphTraits
DOTGraphTraits(bool isSimple=false)
Definition: Attributor.cpp:3371
llvm::AADepGraph::begin
iterator begin()
Definition: Attributor.h:386
isPotentiallyReachable
static bool isPotentiallyReachable(Attributor &A, const Instruction &FromI, const Instruction *ToI, const Function &ToFn, const AbstractAttribute &QueryingAA, std::function< bool(const Function &F)> GoBackwardsCB)
Definition: Attributor.cpp:515
llvm::IRPosition::TombstoneKey
static const IRPosition TombstoneKey
Definition: Attributor.h:753
llvm::BitIntegerState::isKnown
bool isKnown(base_t BitsEncoding) const
Return true if the bits set in BitsEncoding are "known bits".
Definition: Attributor.h:2363
llvm::AbstractAttribute::updateImpl
virtual ChangeStatus updateImpl(Attributor &A)=0
The actual update/transfer function which has to be implemented by the derived classes.
Allocator
Basic Register Allocator
Definition: RegAllocBasic.cpp:142
llvm::AA::getInitialValueForObj
Constant * getInitialValueForObj(Value &Obj, Type &Ty, const TargetLibraryInfo *TLI)
Return the initial value of Obj with type Ty if that is a constant.
Definition: Attributor.cpp:221
llvm::SmallPtrSetImplBase::empty
LLVM_NODISCARD bool empty() const
Definition: SmallPtrSet.h:92
N
#define N
llvm::Instruction::getParent
const BasicBlock * getParent() const
Definition: Instruction.h:91
llvm::to_string
std::string to_string(const T &Value)
Definition: ScopedPrinter.h:85
llvm::BlockAddress::get
static BlockAddress * get(Function *F, BasicBlock *BB)
Return a BlockAddress for the specified function and basic block.
Definition: Constants.cpp:1815
llvm::ArrayRef::size
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:164
llvm::AbstractCallSite::isCallee
bool isCallee(Value::const_user_iterator UI) const
Return true if UI is the use that defines the callee of this ACS.
Definition: AbstractCallSite.h:132
llvm::AnalysisGetter
Wrapper for FunctoinAnalysisManager.
Definition: Attributor.h:949
llvm::GraphTraits< AADepGraphNode * >::DepGetVal
static NodeRef DepGetVal(DepTy &DT)
Definition: Attributor.cpp:3347
llvm::Attributor::isAssumedDead
bool isAssumedDead(const AbstractAttribute &AA, const AAIsDead *LivenessAA, bool &UsedAssumedInformation, bool CheckBBLivenessOnly=false, DepClassTy DepClass=DepClassTy::OPTIONAL)
Return true if AA (or its context instruction) is assumed dead.
Definition: Attributor.cpp:1122
llvm::AAIsDead::isAssumedDead
virtual bool isAssumedDead() const =0
The query functions are protected such that other attributes need to go through the Attributor interf...
llvm::PHINode
Definition: Instructions.h:2651
llvm::BasicBlock::getTerminator
const Instruction * getTerminator() const LLVM_READONLY
Returns the terminator instruction if the block is well formed or null if the block is not well forme...
Definition: BasicBlock.h:119
llvm::Attributor::translateArgumentToCallSiteContent
Optional< Value * > translateArgumentToCallSiteContent(Optional< Value * > V, CallBase &CB, const AbstractAttribute &AA, bool &UsedAssumedInformation)
Translate V from the callee context into the call site context.
Definition: Attributor.cpp:1097
llvm::Attributor::getAssumedSimplified
Optional< Value * > getAssumedSimplified(const IRPosition &IRP, const AbstractAttribute &AA, bool &UsedAssumedInformation)
If V is assumed simplified, return it, if it is unclear yet, return None, otherwise return nullptr.
Definition: Attributor.h:1665
llvm::SmallVectorImpl
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: APFloat.h:42
llvm::DefaultDOTGraphTraits
DefaultDOTGraphTraits - This class provides the default implementations of all of the DOTGraphTraits ...
Definition: DOTGraphTraits.h:28
llvm::Attribute::isIntAttribute
bool isIntAttribute() const
Return true if the attribute is an integer attribute.
Definition: Attributes.cpp:264
llvm::SubsumingPositionIterator
A visitor class for IR positions.
Definition: Attributor.h:938
llvm::CallBase
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
Definition: InstrTypes.h:1174
llvm::Attributor::registerForUpdate
void registerForUpdate(AbstractAttribute &AA)
Allows a query AA to request an update if a new query was received.
Definition: Attributor.cpp:1785
llvm::GlobalValue::getType
PointerType * getType() const
Global values are always pointers.
Definition: GlobalValue.h:276
llvm::SmallPtrSetImpl
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
Definition: SmallPtrSet.h:344
llvm::SmallSetVector
A SetVector that performs no allocations if smaller than a certain size.
Definition: SetVector.h:307
llvm::SetVector::back
const T & back() const
Return the last element of the SetVector.
Definition: SetVector.h:128
llvm::IRPosition::Kind
Kind
The positions we distinguish in the IR.
Definition: Attributor.h:413
llvm::AnalysisManager
A container for analyses that lazily runs them and caches their results.
Definition: InstructionSimplify.h:42
llvm::Attributor::ArgumentReplacementInfo::CalleeRepairCBTy
std::function< void(const ArgumentReplacementInfo &, Function &, Function::arg_iterator)> CalleeRepairCBTy
Callee repair callback type.
Definition: Attributor.h:1834
llvm::InnerAnalysisManagerProxy
An analysis over an "outer" IR unit that provides access to an analysis manager over an "inner" IR un...
Definition: PassManager.h:937
llvm::CallInst
This class represents a function call, abstracting a target machine's calling convention.
Definition: Instructions.h:1461
llvm::initializeAttributorCGSCCLegacyPassPass
void initializeAttributorCGSCCLegacyPassPass(PassRegistry &)
llvm::CloneFunctionInto
void CloneFunctionInto(Function *NewFunc, const Function *OldFunc, ValueToValueMapTy &VMap, CloneFunctionChangeType Changes, SmallVectorImpl< ReturnInst * > &Returns, const char *NameSuffix="", ClonedCodeInfo *CodeInfo=nullptr, ValueMapTypeRemapper *TypeMapper=nullptr, ValueMaterializer *Materializer=nullptr)
Clone OldFunc into NewFunc, transforming the old arguments into references to VMap values.
Definition: CloneFunction.cpp:81
BB
Common register allocation spilling lr str ldr sxth r3 ldr mla r4 can lr mov lr str ldr sxth r3 mla r4 and then merge mul and lr str ldr sxth r3 mla r4 It also increase the likelihood the store may become dead bb27 Successors according to LLVM BB
Definition: README.txt:39
llvm::AAInstanceInfo
An abstract interface to track if a value leaves it's defining function instance.
Definition: Attributor.h:3739
SeedAllowList
static cl::list< std::string > SeedAllowList("attributor-seed-allow-list", cl::Hidden, cl::desc("Comma seperated list of attribute names that are " "allowed to be seeded."), cl::CommaSeparated)
llvm::AnalysisUsage::addRequired
AnalysisUsage & addRequired()
Definition: PassAnalysisSupport.h:75
llvm::GraphTraits
Definition: GraphTraits.h:37
ViewDepGraph
static cl::opt< bool > ViewDepGraph("attributor-view-dep-graph", cl::Hidden, cl::desc("View the dependency graph."), cl::init(false))
llvm::Value::takeName
void takeName(Value *V)
Transfer the name from V to this value.
Definition: Value.cpp:378
llvm::AMDGPU::HSAMD::Kernel::Key::Args
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
Definition: AMDGPUMetadata.h:394
llvm::AAInstanceInfo::isAssumedUniqueForAnalysis
bool isAssumedUniqueForAnalysis() const
Return true if we assume that the underlying value is unique in its scope wrt.
Definition: Attributor.h:3753
llvm::cl::desc
Definition: CommandLine.h:405
llvm::Attributor::checkForAllReturnedValuesAndReturnInsts
bool checkForAllReturnedValuesAndReturnInsts(function_ref< bool(Value &, const SmallSetVector< ReturnInst *, 4 > &)> Pred, const AbstractAttribute &QueryingAA)
Check Pred on all values potentially returned by F.
Definition: Attributor.cpp:1492
llvm::LazyCallGraph
A lazily constructed view of the call graph of a module.
Definition: LazyCallGraph.h:110
llvm::AbstractAttribute::getIRPosition
const IRPosition & getIRPosition() const
Return an IR position, see struct IRPosition.
Definition: Attributor.h:2934
raw_ostream.h
llvm::NullPointerIsDefined
bool NullPointerIsDefined(const Function *F, unsigned AS=0)
Check whether null pointer dereferencing is considered undefined behavior for a given function or an ...
Definition: Function.cpp:2047
llvm::AbstractCallSite::getCalledFunction
Function * getCalledFunction() const
Return the function being called if this is a direct call, otherwise return null (if it's an indirect...
Definition: AbstractCallSite.h:218
llvm::CallGraphUpdater::initialize
void initialize(CallGraph &CG, CallGraphSCC &SCC)
Initializers for usage outside of a CGSCC pass, inside a CGSCC pass in the old and new pass manager (...
Definition: CallGraphUpdater.h:63
llvm::CallGraphUpdater::reanalyzeFunction
void reanalyzeFunction(Function &Fn)
After an CGSCC pass changes a function in ways that affect the call graph, this method can be called ...
Definition: CallGraphUpdater.cpp:89
llvm::SetVector
A vector that has set insertion semantics.
Definition: SetVector.h:40
llvm::AttributeList::getParamAttrs
AttributeSet getParamAttrs(unsigned ArgNo) const
The attributes for the argument or parameter at the given index are returned.
Definition: Attributes.cpp:1380
llvm::SmallVectorImpl::reserve
void reserve(size_type N)
Definition: SmallVector.h:644
llvm::IRPosition::callsite_returned
static const IRPosition callsite_returned(const CallBase &CB)
Create a position describing the returned value of CB.
Definition: Attributor.h:475
llvm::FunctionAnalysisManagerCGSCCProxy
A proxy from a FunctionAnalysisManager to an SCC.
Definition: CGSCCPassManager.h:392
BasicBlockUtils.h
llvm::AbstractCallSite::getCallArgOperand
Value * getCallArgOperand(Argument &Arg) const
Return the operand of the underlying instruction associated with Arg.
Definition: AbstractCallSite.h:177
llvm::Attributor::isModulePass
bool isModulePass() const
Return true if this is a module pass, false otherwise.
Definition: Attributor.h:1534
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:240
llvm::AttributorConfig::MaxFixpointIterations
Optional< unsigned > MaxFixpointIterations
Maximum number of iterations to run until fixpoint.
Definition: Attributor.h:1255
llvm::Optional::value_or
constexpr T value_or(U &&alt) const &
Definition: Optional.h:318
InitializePasses.h
llvm::AAPointerInfo::Access::isRead
bool isRead() const
Return true if this is a read access.
Definition: Attributor.h:4874
llvm::FunctionType::getReturnType
Type * getReturnType() const
Definition: DerivedTypes.h:124
llvm::Value
LLVM Value Representation.
Definition: Value.h:74
Debug.h
llvm::AA::ValueAndContext::getValue
Value * getValue() const
Definition: Attributor.h:166
llvm::Value::users
iterator_range< user_iterator > users()
Definition: Value.h:421
isAssumedReadOnlyOrReadNone
static bool isAssumedReadOnlyOrReadNone(Attributor &A, const IRPosition &IRP, const AbstractAttribute &QueryingAA, bool RequireReadNone, bool &IsKnown)
Definition: Attributor.cpp:473
runAttributorOnFunctions
static bool runAttributorOnFunctions(InformationCache &InfoCache, SetVector< Function * > &Functions, AnalysisGetter &AG, CallGraphUpdater &CGUpdater, bool DeleteFns, bool IsModulePass)
}
Definition: Attributor.cpp:3176
llvm::AADepGraph::viewGraph
void viewGraph()
Definition: Attributor.cpp:3259
llvm::AbstractCallSite::getCallArgOperandNo
int getCallArgOperandNo(Argument &Arg) const
Return the operand index of the underlying instruction associated with Arg.
Definition: AbstractCallSite.h:163
llvm::IRPosition::returned
static const IRPosition returned(const Function &F, const CallBaseContext *CBContext=nullptr)
Create a position describing the returned value of F.
Definition: Attributor.h:457
SimplifyAllLoads
static cl::opt< bool > SimplifyAllLoads("attributor-simplify-all-loads", cl::Hidden, cl::desc("Try to simplify all loads."), cl::init(true))
llvm::CallBase::setCallingConv
void setCallingConv(CallingConv::ID CC)
Definition: InstrTypes.h:1459
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
llvm::Type::getPrimitiveSizeInBits
TypeSize getPrimitiveSizeInBits() const LLVM_READONLY
Return the basic size of this type if it is a primitive type.
Definition: Type.cpp:164
llvm::Attributor::internalizeFunctions
static bool internalizeFunctions(SmallPtrSetImpl< Function * > &FnSet, DenseMap< Function *, Function * > &FnMap)
Make copies of each function in the set FnSet such that the copied version has internal linkage after...
Definition: Attributor.cpp:2290
llvm::Function::size
size_t size() const
Definition: Function.h:731
llvm::SmallPtrSetImpl::insert
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
Definition: SmallPtrSet.h:365
llvm::Intrinsic::ID
unsigned ID
Definition: TargetTransformInfo.h:38
SetFixpointIterations
static cl::opt< unsigned > SetFixpointIterations("attributor-max-iterations", cl::Hidden, cl::desc("Maximal number of fixpoint iterations."), cl::init(32))
llvm::PoisonValue::get
static PoisonValue * get(Type *T)
Static factory methods - Return an 'poison' object of the specified type.
Definition: Constants.cpp:1796
llvm::cl::list
Definition: CommandLine.h:1601