LLVM  4.0.0
CorrelatedValuePropagation.cpp
Go to the documentation of this file.
1 //===- CorrelatedValuePropagation.cpp - Propagate CFG-derived info --------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements the Correlated Value Propagation pass.
11 //
12 //===----------------------------------------------------------------------===//
13 
15 #include "llvm/Transforms/Scalar.h"
16 #include "llvm/ADT/Statistic.h"
20 #include "llvm/IR/CFG.h"
21 #include "llvm/IR/ConstantRange.h"
22 #include "llvm/IR/Constants.h"
23 #include "llvm/IR/Function.h"
24 #include "llvm/IR/Instructions.h"
25 #include "llvm/IR/Module.h"
26 #include "llvm/Pass.h"
27 #include "llvm/Support/Debug.h"
30 using namespace llvm;
31 
32 #define DEBUG_TYPE "correlated-value-propagation"
33 
34 STATISTIC(NumPhis, "Number of phis propagated");
35 STATISTIC(NumSelects, "Number of selects propagated");
36 STATISTIC(NumMemAccess, "Number of memory access targets propagated");
37 STATISTIC(NumCmps, "Number of comparisons propagated");
38 STATISTIC(NumReturns, "Number of return values propagated");
39 STATISTIC(NumDeadCases, "Number of switch cases removed");
40 STATISTIC(NumSDivs, "Number of sdiv converted to udiv");
41 STATISTIC(NumAShrs, "Number of ashr converted to lshr");
42 STATISTIC(NumSRems, "Number of srem converted to urem");
43 
44 static cl::opt<bool> DontProcessAdds("cvp-dont-process-adds", cl::init(true));
45 
46 namespace {
47  class CorrelatedValuePropagation : public FunctionPass {
48  public:
49  static char ID;
50  CorrelatedValuePropagation(): FunctionPass(ID) {
52  }
53 
54  bool runOnFunction(Function &F) override;
55 
56  void getAnalysisUsage(AnalysisUsage &AU) const override {
59  }
60  };
61 }
62 
64 INITIALIZE_PASS_BEGIN(CorrelatedValuePropagation, "correlated-propagation",
65  "Value Propagation", false, false)
67 INITIALIZE_PASS_END(CorrelatedValuePropagation, "correlated-propagation",
68  "Value Propagation", false, false)
69 
70 // Public interface to the Value Propagation pass
72  return new CorrelatedValuePropagation();
73 }
74 
75 static bool processSelect(SelectInst *S, LazyValueInfo *LVI) {
76  if (S->getType()->isVectorTy()) return false;
77  if (isa<Constant>(S->getOperand(0))) return false;
78 
79  Constant *C = LVI->getConstant(S->getOperand(0), S->getParent(), S);
80  if (!C) return false;
81 
83  if (!CI) return false;
84 
85  Value *ReplaceWith = S->getOperand(1);
86  Value *Other = S->getOperand(2);
87  if (!CI->isOne()) std::swap(ReplaceWith, Other);
88  if (ReplaceWith == S) ReplaceWith = UndefValue::get(S->getType());
89 
90  S->replaceAllUsesWith(ReplaceWith);
91  S->eraseFromParent();
92 
93  ++NumSelects;
94 
95  return true;
96 }
97 
98 static bool processPHI(PHINode *P, LazyValueInfo *LVI) {
99  bool Changed = false;
100 
101  BasicBlock *BB = P->getParent();
102  for (unsigned i = 0, e = P->getNumIncomingValues(); i < e; ++i) {
103  Value *Incoming = P->getIncomingValue(i);
104  if (isa<Constant>(Incoming)) continue;
105 
106  Value *V = LVI->getConstantOnEdge(Incoming, P->getIncomingBlock(i), BB, P);
107 
108  // Look if the incoming value is a select with a scalar condition for which
109  // LVI can tells us the value. In that case replace the incoming value with
110  // the appropriate value of the select. This often allows us to remove the
111  // select later.
112  if (!V) {
113  SelectInst *SI = dyn_cast<SelectInst>(Incoming);
114  if (!SI) continue;
115 
116  Value *Condition = SI->getCondition();
117  if (!Condition->getType()->isVectorTy()) {
118  if (Constant *C = LVI->getConstantOnEdge(
119  Condition, P->getIncomingBlock(i), BB, P)) {
120  if (C->isOneValue()) {
121  V = SI->getTrueValue();
122  } else if (C->isZeroValue()) {
123  V = SI->getFalseValue();
124  }
125  // Once LVI learns to handle vector types, we could also add support
126  // for vector type constants that are not all zeroes or all ones.
127  }
128  }
129 
130  // Look if the select has a constant but LVI tells us that the incoming
131  // value can never be that constant. In that case replace the incoming
132  // value with the other value of the select. This often allows us to
133  // remove the select later.
134  if (!V) {
136  if (!C) continue;
137 
138  if (LVI->getPredicateOnEdge(ICmpInst::ICMP_EQ, SI, C,
139  P->getIncomingBlock(i), BB, P) !=
141  continue;
142  V = SI->getTrueValue();
143  }
144 
145  DEBUG(dbgs() << "CVP: Threading PHI over " << *SI << '\n');
146  }
147 
148  P->setIncomingValue(i, V);
149  Changed = true;
150  }
151 
152  // FIXME: Provide TLI, DT, AT to SimplifyInstruction.
153  const DataLayout &DL = BB->getModule()->getDataLayout();
154  if (Value *V = SimplifyInstruction(P, DL)) {
155  P->replaceAllUsesWith(V);
156  P->eraseFromParent();
157  Changed = true;
158  }
159 
160  if (Changed)
161  ++NumPhis;
162 
163  return Changed;
164 }
165 
167  Value *Pointer = nullptr;
168  if (LoadInst *L = dyn_cast<LoadInst>(I))
169  Pointer = L->getPointerOperand();
170  else
171  Pointer = cast<StoreInst>(I)->getPointerOperand();
172 
173  if (isa<Constant>(Pointer)) return false;
174 
175  Constant *C = LVI->getConstant(Pointer, I->getParent(), I);
176  if (!C) return false;
177 
178  ++NumMemAccess;
179  I->replaceUsesOfWith(Pointer, C);
180  return true;
181 }
182 
183 /// See if LazyValueInfo's ability to exploit edge conditions or range
184 /// information is sufficient to prove this comparison. Even for local
185 /// conditions, this can sometimes prove conditions instcombine can't by
186 /// exploiting range information.
187 static bool processCmp(CmpInst *C, LazyValueInfo *LVI) {
188  Value *Op0 = C->getOperand(0);
189  Constant *Op1 = dyn_cast<Constant>(C->getOperand(1));
190  if (!Op1) return false;
191 
192  // As a policy choice, we choose not to waste compile time on anything where
193  // the comparison is testing local values. While LVI can sometimes reason
194  // about such cases, it's not its primary purpose. We do make sure to do
195  // the block local query for uses from terminator instructions, but that's
196  // handled in the code for each terminator.
197  auto *I = dyn_cast<Instruction>(Op0);
198  if (I && I->getParent() == C->getParent())
199  return false;
200 
201  LazyValueInfo::Tristate Result =
202  LVI->getPredicateAt(C->getPredicate(), Op0, Op1, C);
203  if (Result == LazyValueInfo::Unknown) return false;
204 
205  ++NumCmps;
206  if (Result == LazyValueInfo::True)
208  else
210  C->eraseFromParent();
211 
212  return true;
213 }
214 
215 /// Simplify a switch instruction by removing cases which can never fire. If the
216 /// uselessness of a case could be determined locally then constant propagation
217 /// would already have figured it out. Instead, walk the predecessors and
218 /// statically evaluate cases based on information available on that edge. Cases
219 /// that cannot fire no matter what the incoming edge can safely be removed. If
220 /// a case fires on every incoming edge then the entire switch can be removed
221 /// and replaced with a branch to the case destination.
222 static bool processSwitch(SwitchInst *SI, LazyValueInfo *LVI) {
223  Value *Cond = SI->getCondition();
224  BasicBlock *BB = SI->getParent();
225 
226  // If the condition was defined in same block as the switch then LazyValueInfo
227  // currently won't say anything useful about it, though in theory it could.
228  if (isa<Instruction>(Cond) && cast<Instruction>(Cond)->getParent() == BB)
229  return false;
230 
231  // If the switch is unreachable then trying to improve it is a waste of time.
232  pred_iterator PB = pred_begin(BB), PE = pred_end(BB);
233  if (PB == PE) return false;
234 
235  // Analyse each switch case in turn. This is done in reverse order so that
236  // removing a case doesn't cause trouble for the iteration.
237  bool Changed = false;
238  for (SwitchInst::CaseIt CI = SI->case_end(), CE = SI->case_begin(); CI-- != CE;
239  ) {
240  ConstantInt *Case = CI.getCaseValue();
241 
242  // Check to see if the switch condition is equal to/not equal to the case
243  // value on every incoming edge, equal/not equal being the same each time.
245  for (pred_iterator PI = PB; PI != PE; ++PI) {
246  // Is the switch condition equal to the case value?
248  Cond, Case, *PI,
249  BB, SI);
250  // Give up on this case if nothing is known.
251  if (Value == LazyValueInfo::Unknown) {
252  State = LazyValueInfo::Unknown;
253  break;
254  }
255 
256  // If this was the first edge to be visited, record that all other edges
257  // need to give the same result.
258  if (PI == PB) {
259  State = Value;
260  continue;
261  }
262 
263  // If this case is known to fire for some edges and known not to fire for
264  // others then there is nothing we can do - give up.
265  if (Value != State) {
266  State = LazyValueInfo::Unknown;
267  break;
268  }
269  }
270 
271  if (State == LazyValueInfo::False) {
272  // This case never fires - remove it.
273  CI.getCaseSuccessor()->removePredecessor(BB);
274  SI->removeCase(CI); // Does not invalidate the iterator.
275 
276  // The condition can be modified by removePredecessor's PHI simplification
277  // logic.
278  Cond = SI->getCondition();
279 
280  ++NumDeadCases;
281  Changed = true;
282  } else if (State == LazyValueInfo::True) {
283  // This case always fires. Arrange for the switch to be turned into an
284  // unconditional branch by replacing the switch condition with the case
285  // value.
286  SI->setCondition(Case);
287  NumDeadCases += SI->getNumCases();
288  Changed = true;
289  break;
290  }
291  }
292 
293  if (Changed)
294  // If the switch has been simplified to the point where it can be replaced
295  // by a branch then do so now.
297 
298  return Changed;
299 }
300 
301 /// Infer nonnull attributes for the arguments at the specified callsite.
302 static bool processCallSite(CallSite CS, LazyValueInfo *LVI) {
303  SmallVector<unsigned, 4> Indices;
304  unsigned ArgNo = 0;
305 
306  for (Value *V : CS.args()) {
307  PointerType *Type = dyn_cast<PointerType>(V->getType());
308  // Try to mark pointer typed parameters as non-null. We skip the
309  // relatively expensive analysis for constants which are obviously either
310  // null or non-null to start with.
311  if (Type && !CS.paramHasAttr(ArgNo + 1, Attribute::NonNull) &&
312  !isa<Constant>(V) &&
316  Indices.push_back(ArgNo + 1);
317  ArgNo++;
318  }
319 
320  assert(ArgNo == CS.arg_size() && "sanity check");
321 
322  if (Indices.empty())
323  return false;
324 
325  AttributeSet AS = CS.getAttributes();
326  LLVMContext &Ctx = CS.getInstruction()->getContext();
327  AS = AS.addAttribute(Ctx, Indices, Attribute::get(Ctx, Attribute::NonNull));
328  CS.setAttributes(AS);
329 
330  return true;
331 }
332 
333 // Helper function to rewrite srem and sdiv. As a policy choice, we choose not
334 // to waste compile time on anything where the operands are local defs. While
335 // LVI can sometimes reason about such cases, it's not its primary purpose.
336 static bool hasLocalDefs(BinaryOperator *SDI) {
337  for (Value *O : SDI->operands()) {
338  auto *I = dyn_cast<Instruction>(O);
339  if (I && I->getParent() == SDI->getParent())
340  return true;
341  }
342  return false;
343 }
344 
346  Constant *Zero = ConstantInt::get(SDI->getType(), 0);
347  for (Value *O : SDI->operands()) {
348  auto Result = LVI->getPredicateAt(ICmpInst::ICMP_SGE, O, Zero, SDI);
349  if (Result != LazyValueInfo::True)
350  return false;
351  }
352  return true;
353 }
354 
355 static bool processSRem(BinaryOperator *SDI, LazyValueInfo *LVI) {
356  if (SDI->getType()->isVectorTy() || hasLocalDefs(SDI) ||
357  !hasPositiveOperands(SDI, LVI))
358  return false;
359 
360  ++NumSRems;
361  auto *BO = BinaryOperator::CreateURem(SDI->getOperand(0), SDI->getOperand(1),
362  SDI->getName(), SDI);
363  SDI->replaceAllUsesWith(BO);
364  SDI->eraseFromParent();
365  return true;
366 }
367 
368 /// See if LazyValueInfo's ability to exploit edge conditions or range
369 /// information is sufficient to prove the both operands of this SDiv are
370 /// positive. If this is the case, replace the SDiv with a UDiv. Even for local
371 /// conditions, this can sometimes prove conditions instcombine can't by
372 /// exploiting range information.
373 static bool processSDiv(BinaryOperator *SDI, LazyValueInfo *LVI) {
374  if (SDI->getType()->isVectorTy() || hasLocalDefs(SDI) ||
375  !hasPositiveOperands(SDI, LVI))
376  return false;
377 
378  ++NumSDivs;
379  auto *BO = BinaryOperator::CreateUDiv(SDI->getOperand(0), SDI->getOperand(1),
380  SDI->getName(), SDI);
381  BO->setIsExact(SDI->isExact());
382  SDI->replaceAllUsesWith(BO);
383  SDI->eraseFromParent();
384 
385  return true;
386 }
387 
388 static bool processAShr(BinaryOperator *SDI, LazyValueInfo *LVI) {
389  if (SDI->getType()->isVectorTy() || hasLocalDefs(SDI))
390  return false;
391 
392  Constant *Zero = ConstantInt::get(SDI->getType(), 0);
393  if (LVI->getPredicateAt(ICmpInst::ICMP_SGE, SDI->getOperand(0), Zero, SDI) !=
395  return false;
396 
397  ++NumAShrs;
398  auto *BO = BinaryOperator::CreateLShr(SDI->getOperand(0), SDI->getOperand(1),
399  SDI->getName(), SDI);
400  BO->setIsExact(SDI->isExact());
401  SDI->replaceAllUsesWith(BO);
402  SDI->eraseFromParent();
403 
404  return true;
405 }
406 
407 static bool processAdd(BinaryOperator *AddOp, LazyValueInfo *LVI) {
408  typedef OverflowingBinaryOperator OBO;
409 
410  if (DontProcessAdds)
411  return false;
412 
413  if (AddOp->getType()->isVectorTy() || hasLocalDefs(AddOp))
414  return false;
415 
416  bool NSW = AddOp->hasNoSignedWrap();
417  bool NUW = AddOp->hasNoUnsignedWrap();
418  if (NSW && NUW)
419  return false;
420 
421  BasicBlock *BB = AddOp->getParent();
422 
423  Value *LHS = AddOp->getOperand(0);
424  Value *RHS = AddOp->getOperand(1);
425 
426  ConstantRange LRange = LVI->getConstantRange(LHS, BB, AddOp);
427 
428  // Initialize RRange only if we need it. If we know that guaranteed no wrap
429  // range for the given LHS range is empty don't spend time calculating the
430  // range for the RHS.
432  auto LazyRRange = [&] () {
433  if (!RRange)
434  RRange = LVI->getConstantRange(RHS, BB, AddOp);
435  return RRange.getValue();
436  };
437 
438  bool Changed = false;
439  if (!NUW) {
440  ConstantRange NUWRange =
442  OBO::NoUnsignedWrap);
443  if (!NUWRange.isEmptySet()) {
444  bool NewNUW = NUWRange.contains(LazyRRange());
445  AddOp->setHasNoUnsignedWrap(NewNUW);
446  Changed |= NewNUW;
447  }
448  }
449  if (!NSW) {
450  ConstantRange NSWRange =
452  OBO::NoSignedWrap);
453  if (!NSWRange.isEmptySet()) {
454  bool NewNSW = NSWRange.contains(LazyRRange());
455  AddOp->setHasNoSignedWrap(NewNSW);
456  Changed |= NewNSW;
457  }
458  }
459 
460  return Changed;
461 }
462 
464  if (Constant *C = LVI->getConstant(V, At->getParent(), At))
465  return C;
466 
467  // TODO: The following really should be sunk inside LVI's core algorithm, or
468  // at least the outer shims around such.
469  auto *C = dyn_cast<CmpInst>(V);
470  if (!C) return nullptr;
471 
472  Value *Op0 = C->getOperand(0);
473  Constant *Op1 = dyn_cast<Constant>(C->getOperand(1));
474  if (!Op1) return nullptr;
475 
476  LazyValueInfo::Tristate Result =
477  LVI->getPredicateAt(C->getPredicate(), Op0, Op1, At);
478  if (Result == LazyValueInfo::Unknown)
479  return nullptr;
480 
481  return (Result == LazyValueInfo::True) ?
482  ConstantInt::getTrue(C->getContext()) :
483  ConstantInt::getFalse(C->getContext());
484 }
485 
486 static bool runImpl(Function &F, LazyValueInfo *LVI) {
487  bool FnChanged = false;
488 
489  // Visiting in a pre-order depth-first traversal causes us to simplify early
490  // blocks before querying later blocks (which require us to analyze early
491  // blocks). Eagerly simplifying shallow blocks means there is strictly less
492  // work to do for deep blocks. This also means we don't visit unreachable
493  // blocks.
494  for (BasicBlock *BB : depth_first(&F.getEntryBlock())) {
495  bool BBChanged = false;
496  for (BasicBlock::iterator BI = BB->begin(), BE = BB->end(); BI != BE;) {
497  Instruction *II = &*BI++;
498  switch (II->getOpcode()) {
499  case Instruction::Select:
500  BBChanged |= processSelect(cast<SelectInst>(II), LVI);
501  break;
502  case Instruction::PHI:
503  BBChanged |= processPHI(cast<PHINode>(II), LVI);
504  break;
505  case Instruction::ICmp:
506  case Instruction::FCmp:
507  BBChanged |= processCmp(cast<CmpInst>(II), LVI);
508  break;
509  case Instruction::Load:
510  case Instruction::Store:
511  BBChanged |= processMemAccess(II, LVI);
512  break;
513  case Instruction::Call:
514  case Instruction::Invoke:
515  BBChanged |= processCallSite(CallSite(II), LVI);
516  break;
517  case Instruction::SRem:
518  BBChanged |= processSRem(cast<BinaryOperator>(II), LVI);
519  break;
520  case Instruction::SDiv:
521  BBChanged |= processSDiv(cast<BinaryOperator>(II), LVI);
522  break;
523  case Instruction::AShr:
524  BBChanged |= processAShr(cast<BinaryOperator>(II), LVI);
525  break;
526  case Instruction::Add:
527  BBChanged |= processAdd(cast<BinaryOperator>(II), LVI);
528  break;
529  }
530  }
531 
532  Instruction *Term = BB->getTerminator();
533  switch (Term->getOpcode()) {
534  case Instruction::Switch:
535  BBChanged |= processSwitch(cast<SwitchInst>(Term), LVI);
536  break;
537  case Instruction::Ret: {
538  auto *RI = cast<ReturnInst>(Term);
539  // Try to determine the return value if we can. This is mainly here to
540  // simplify the writing of unit tests, but also helps to enable IPO by
541  // constant folding the return values of callees.
542  auto *RetVal = RI->getReturnValue();
543  if (!RetVal) break; // handle "ret void"
544  if (isa<Constant>(RetVal)) break; // nothing to do
545  if (auto *C = getConstantAt(RetVal, RI, LVI)) {
546  ++NumReturns;
547  RI->replaceUsesOfWith(RetVal, C);
548  BBChanged = true;
549  }
550  }
551  };
552 
553  FnChanged |= BBChanged;
554  }
555 
556  return FnChanged;
557 }
558 
559 bool CorrelatedValuePropagation::runOnFunction(Function &F) {
560  if (skipFunction(F))
561  return false;
562 
563  LazyValueInfo *LVI = &getAnalysis<LazyValueInfoWrapperPass>().getLVI();
564  return runImpl(F, LVI);
565 }
566 
569 
571  bool Changed = runImpl(F, LVI);
572 
573  // FIXME: We need to invalidate LVI to avoid PR28400. Is there a better
574  // solution?
576 
577  if (!Changed)
578  return PreservedAnalyses::all();
580  PA.preserve<GlobalsAA>();
581  return PA;
582 }
Legacy wrapper pass to provide the GlobalsAAResult object.
MachineLoop * L
Pass interface - Implemented by all 'passes'.
Definition: Pass.h:81
SymbolTableList< Instruction >::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
Definition: Instruction.cpp:76
void push_back(const T &Elt)
Definition: SmallVector.h:211
A parsed version of the target data layout string in and methods for querying it. ...
Definition: DataLayout.h:102
static ConstantInt * getFalse(LLVMContext &Context)
Definition: Constants.cpp:513
CaseIt case_end()
Returns a read/write iterator that points one past the last in the SwitchInst.
This class is the base class for the comparison instructions.
Definition: InstrTypes.h:870
static bool runImpl(Function &F, LazyValueInfo *LVI)
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
ConstantRange getConstantRange(Value *V, BasicBlock *BB, Instruction *CxtI=nullptr)
Return the ConstantRange constraint that is known to hold for the specified value at the end of the s...
STATISTIC(NumFunctions,"Total number of functions")
size_t i
Wrapper around LazyValueInfo.
This is the interface for a simple mod/ref and alias analysis over globals.
void setAttributes(AttributeSet PAL)
Definition: CallSite.h:328
CaseIt case_begin()
Returns a read/write iterator that points to the first case in the SwitchInst.
INITIALIZE_PASS_BEGIN(CorrelatedValuePropagation,"correlated-propagation","Value Propagation", false, false) INITIALIZE_PASS_END(CorrelatedValuePropagation
static bool processAShr(BinaryOperator *SDI, LazyValueInfo *LVI)
An instruction for reading from memory.
Definition: Instructions.h:164
unsigned arg_size() const
Definition: CallSite.h:211
StringRef getName() const
Return a constant reference to the value's name.
Definition: Value.cpp:191
AnalysisUsage & addRequired()
#define INITIALIZE_PASS_DEPENDENCY(depName)
Definition: PassSupport.h:53
Constant * getConstant(Value *V, BasicBlock *BB, Instruction *CxtI=nullptr)
Determine whether the specified value is known to be a constant at the end of the specified block...
static Value * getPointerOperand(Instruction &Inst)
This class represents the LLVM 'select' instruction.
static bool hasPositiveOperands(BinaryOperator *SDI, LazyValueInfo *LVI)
static cl::opt< bool > DontProcessAdds("cvp-dont-process-adds", cl::init(true))
const Module * getModule() const
Return the module owning the function this basic block belongs to, or nullptr it the function does no...
Definition: BasicBlock.cpp:116
bool ConstantFoldTerminator(BasicBlock *BB, bool DeleteDeadConditions=false, const TargetLibraryInfo *TLI=nullptr)
If a terminator instruction is predicated on a constant value, convert it into an unconditional branc...
Definition: Local.cpp:68
static bool processSelect(SelectInst *S, LazyValueInfo *LVI)
ELFYAML::ELF_STO Other
Definition: ELFYAML.cpp:662
LLVM_NODISCARD bool empty() const
Definition: SmallVector.h:60
#define F(x, y, z)
Definition: MD5.cpp:51
bool contains(const APInt &Val) const
Return true if the specified value is in the set.
const T & getValue() const LLVM_LVALUE_FUNCTION
Definition: Optional.h:121
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
Definition: Value.cpp:401
int Switch(int a)
Definition: Switch2Test.cpp:11
Class to represent pointers.
Definition: DerivedTypes.h:443
unsigned getNumIncomingValues() const
Return the number of incoming edges.
void replaceUsesOfWith(Value *From, Value *To)
Replace uses of one Value with another.
Definition: User.cpp:24
Pass * createCorrelatedValuePropagationPass()
#define P(N)
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:395
iterator_range< IterTy > args() const
Definition: CallSite.h:207
A set of analyses that are preserved following a run of a transformation pass.
Definition: PassManager.h:107
static ConstantPointerNull * get(PointerType *T)
Static factory methods - Return objects of the specified value.
Definition: Constants.cpp:1323
static bool processSwitch(SwitchInst *SI, LazyValueInfo *LVI)
Simplify a switch instruction by removing cases which can never fire.
Constant * getConstantOnEdge(Value *V, BasicBlock *FromBB, BasicBlock *ToBB, Instruction *CxtI=nullptr)
Determine whether the specified value is known to be a constant on the specified edge.
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs...ExtraArgs)
Get the result of an analysis pass for a given IR unit.
Definition: PassManager.h:653
static bool processPHI(PHINode *P, LazyValueInfo *LVI)
static bool processSDiv(BinaryOperator *SDI, LazyValueInfo *LVI)
See if LazyValueInfo's ability to exploit edge conditions or range information is sufficient to prove...
LLVM Basic Block Representation.
Definition: BasicBlock.h:51
bool isExact() const
Determine whether the exact flag is set.
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:45
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:48
bool isVectorTy() const
True if this is an instance of VectorType.
Definition: Type.h:219
AttributeSet addAttribute(LLVMContext &C, unsigned Index, Attribute::AttrKind Kind) const
Add an attribute to the attribute set at the given index.
Definition: Attributes.cpp:753
This is an important base class in LLVM.
Definition: Constant.h:42
const Value * getCondition() const
This file contains the declarations for the subclasses of Constant, which represent the different fla...
bool hasNoSignedWrap() const
Determine whether the no signed wrap flag is set.
Interval::pred_iterator pred_begin(Interval *I)
pred_begin/pred_end - define methods so that Intervals may be used just like BasicBlocks can with the...
Definition: Interval.h:116
static bool processAdd(BinaryOperator *AddOp, LazyValueInfo *LVI)
Represent the analysis usage information of a pass.
BasicBlock * getIncomingBlock(unsigned i) const
Return incoming basic block number i.
Analysis pass providing a never-invalidated alias analysis result.
Utility class for integer arithmetic operators which may exhibit overflow - Add, Sub, and Mul.
Definition: Operator.h:75
INITIALIZE_PASS_END(RegBankSelect, DEBUG_TYPE,"Assign register bank of generic virtual registers", false, false) RegBankSelect
FunctionPass class - This class is used to implement most global optimizations.
Definition: Pass.h:298
Value * getOperand(unsigned i) const
Definition: User.h:145
Interval::pred_iterator pred_end(Interval *I)
Definition: Interval.h:119
op_range operands()
Definition: User.h:213
Predicate getPredicate() const
Return the predicate for this instruction.
Definition: InstrTypes.h:960
bool isEmptySet() const
Return true if this set contains no members.
static UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
Definition: Constants.cpp:1337
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition: PassManager.h:113
LLVMContext & getContext() const
All values hold a context through their type.
Definition: Value.cpp:654
const Value * getTrueValue() const
static bool processSRem(BinaryOperator *SDI, LazyValueInfo *LVI)
Tristate
This is used to return true/false/dunno results.
Definition: LazyValueInfo.h:61
Tristate getPredicateOnEdge(unsigned Pred, Value *V, Constant *C, BasicBlock *FromBB, BasicBlock *ToBB, Instruction *CxtI=nullptr)
Determine whether the specified value comparison with a constant is known to be true or false on the ...
AttributeSet getAttributes() const
getAttributes/setAttributes - get or set the parameter attributes of the call.
Definition: CallSite.h:325
Tristate getPredicateAt(unsigned Pred, Value *V, Constant *C, Instruction *CxtI)
Determine whether the specified value comparison with a constant is known to be true or false at the ...
void setHasNoSignedWrap(bool b=true)
Set or clear the nsw flag on this instruction, which must be an operator which supports this flag...
Iterator for intrusive lists based on ilist_node.
This is the shared class of boolean and integer constants.
Definition: Constants.h:88
void initializeCorrelatedValuePropagationPass(PassRegistry &)
InstrTy * getInstruction() const
Definition: CallSite.h:93
bool hasNoUnsignedWrap() const
Determine whether the no unsigned wrap flag is set.
Value * getIncomingValue(unsigned i) const
Return incoming value number x.
Module.h This file contains the declarations for the Module class.
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:230
This class represents a range of values.
Definition: ConstantRange.h:45
void invalidate(IRUnitT &IR)
Invalidate a specific analysis pass for an IR module.
Definition: PassManager.h:722
static Constant * get(Type *Ty, uint64_t V, bool isSigned=false)
If Ty is a vector type, return a Constant with a splat of the given value.
Definition: Constants.cpp:558
const BasicBlock & getEntryBlock() const
Definition: Function.h:519
static ConstantInt * getTrue(LLVMContext &Context)
Definition: Constants.cpp:506
static GCRegistry::Add< ShadowStackGC > C("shadow-stack","Very portable GC for uncooperative code generators")
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:132
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
Definition: BitVector.h:586
static bool hasLocalDefs(BinaryOperator *SDI)
Value * getCondition() const
static bool processCallSite(CallSite CS, LazyValueInfo *LVI)
Infer nonnull attributes for the arguments at the specified callsite.
correlated propagation
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
Definition: Module.cpp:384
void setCondition(Value *V)
#define I(x, y, z)
Definition: MD5.cpp:54
bool paramHasAttr(unsigned i, Attribute::AttrKind Kind) const
Return true if the call or the callee has the given attribute.
Definition: CallSite.h:359
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
Definition: Casting.h:287
void preserve()
Mark an analysis as preserved.
Definition: PassManager.h:120
static volatile int Zero
static bool processMemAccess(Instruction *I, LazyValueInfo *LVI)
static Attribute get(LLVMContext &Context, AttrKind Kind, uint64_t Val=0)
Return a uniquified Attribute object.
Definition: Attributes.cpp:64
void removeCase(CaseIt i)
This method removes the specified case and its successor from the switch instruction.
unsigned getNumCases() const
Return the number of 'cases' in this switch instruction, excluding the default case.
correlated Value false
iterator_range< df_iterator< T > > depth_first(const T &G)
void setHasNoUnsignedWrap(bool b=true)
Set or clear the nsw flag on this instruction, which must be an operator which supports this flag...
Multiway switch.
This pass computes, caches, and vends lazy value constraint information.
Definition: LazyValueInfo.h:32
static ConstantRange makeGuaranteedNoWrapRegion(Instruction::BinaryOps BinOp, const ConstantRange &Other, unsigned NoWrapKind)
Return the largest range containing all X such that "X BinOpC Y" is guaranteed not to wrap (overflow)...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LLVM Value Representation.
Definition: Value.h:71
unsigned getOpcode() const
Returns a member of one of the enums like Instruction::Add.
Definition: Instruction.h:111
static const Function * getParent(const Value *V)
#define DEBUG(X)
Definition: Debug.h:100
correlated Value Propagation
const Value * getFalseValue() const
static Constant * getConstantAt(Value *V, Instruction *At, LazyValueInfo *LVI)
A container for analyses that lazily runs them and caches their results.
Value * SimplifyInstruction(Instruction *I, const DataLayout &DL, const TargetLibraryInfo *TLI=nullptr, const DominatorTree *DT=nullptr, AssumptionCache *AC=nullptr)
See if we can compute a simplified version of this instruction.
void setIncomingValue(unsigned i, Value *V)
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
static bool processCmp(CmpInst *C, LazyValueInfo *LVI)
See if LazyValueInfo's ability to exploit edge conditions or range information is sufficient to prove...
const BasicBlock * getParent() const
Definition: Instruction.h:62
bool isOne() const
This is just a convenience method to make client code smaller for a common case.
Definition: Constants.h:206
signed greater or equal
Definition: InstrTypes.h:908
Analysis to compute lazy value information.