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