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