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