LLVM  3.7.0
LoopUtils.cpp
Go to the documentation of this file.
1 //===-- LoopUtils.cpp - Loop Utility functions -------------------------===//
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 defines common loop utility functions.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "llvm/Analysis/LoopInfo.h"
15 #include "llvm/IR/Instructions.h"
16 #include "llvm/IR/PatternMatch.h"
17 #include "llvm/IR/ValueHandle.h"
18 #include "llvm/Support/Debug.h"
21 #include "llvm/IR/Module.h"
23 
24 using namespace llvm;
25 using namespace llvm::PatternMatch;
26 
27 #define DEBUG_TYPE "loop-utils"
28 
31  for (User::op_iterator Use = I->op_begin(), E = I->op_end(); Use != E; ++Use)
32  if (!Set.count(dyn_cast<Instruction>(*Use)))
33  return false;
34  return true;
35 }
36 
38  Loop *TheLoop, bool HasFunNoNaNAttr,
39  RecurrenceDescriptor &RedDes) {
40  if (Phi->getNumIncomingValues() != 2)
41  return false;
42 
43  // Reduction variables are only found in the loop header block.
44  if (Phi->getParent() != TheLoop->getHeader())
45  return false;
46 
47  // Obtain the reduction start value from the value that comes from the loop
48  // preheader.
49  Value *RdxStart = Phi->getIncomingValueForBlock(TheLoop->getLoopPreheader());
50 
51  // ExitInstruction is the single value which is used outside the loop.
52  // We only allow for a single reduction value to be used outside the loop.
53  // This includes users of the reduction, variables (which form a cycle
54  // which ends in the phi node).
55  Instruction *ExitInstruction = nullptr;
56  // Indicates that we found a reduction operation in our scan.
57  bool FoundReduxOp = false;
58 
59  // We start with the PHI node and scan for all of the users of this
60  // instruction. All users must be instructions that can be used as reduction
61  // variables (such as ADD). We must have a single out-of-block user. The cycle
62  // must include the original PHI.
63  bool FoundStartPHI = false;
64 
65  // To recognize min/max patterns formed by a icmp select sequence, we store
66  // the number of instruction we saw from the recognized min/max pattern,
67  // to make sure we only see exactly the two instructions.
68  unsigned NumCmpSelectPatternInst = 0;
69  InstDesc ReduxDesc(false, nullptr);
70 
71  SmallPtrSet<Instruction *, 8> VisitedInsts;
73  Worklist.push_back(Phi);
74  VisitedInsts.insert(Phi);
75 
76  // A value in the reduction can be used:
77  // - By the reduction:
78  // - Reduction operation:
79  // - One use of reduction value (safe).
80  // - Multiple use of reduction value (not safe).
81  // - PHI:
82  // - All uses of the PHI must be the reduction (safe).
83  // - Otherwise, not safe.
84  // - By one instruction outside of the loop (safe).
85  // - By further instructions outside of the loop (not safe).
86  // - By an instruction that is not part of the reduction (not safe).
87  // This is either:
88  // * An instruction type other than PHI or the reduction operation.
89  // * A PHI in the header other than the initial PHI.
90  while (!Worklist.empty()) {
91  Instruction *Cur = Worklist.back();
92  Worklist.pop_back();
93 
94  // No Users.
95  // If the instruction has no users then this is a broken chain and can't be
96  // a reduction variable.
97  if (Cur->use_empty())
98  return false;
99 
100  bool IsAPhi = isa<PHINode>(Cur);
101 
102  // A header PHI use other than the original PHI.
103  if (Cur != Phi && IsAPhi && Cur->getParent() == Phi->getParent())
104  return false;
105 
106  // Reductions of instructions such as Div, and Sub is only possible if the
107  // LHS is the reduction variable.
108  if (!Cur->isCommutative() && !IsAPhi && !isa<SelectInst>(Cur) &&
109  !isa<ICmpInst>(Cur) && !isa<FCmpInst>(Cur) &&
110  !VisitedInsts.count(dyn_cast<Instruction>(Cur->getOperand(0))))
111  return false;
112 
113  // Any reduction instruction must be of one of the allowed kinds.
114  ReduxDesc = isRecurrenceInstr(Cur, Kind, ReduxDesc, HasFunNoNaNAttr);
115  if (!ReduxDesc.isRecurrence())
116  return false;
117 
118  // A reduction operation must only have one use of the reduction value.
119  if (!IsAPhi && Kind != RK_IntegerMinMax && Kind != RK_FloatMinMax &&
120  hasMultipleUsesOf(Cur, VisitedInsts))
121  return false;
122 
123  // All inputs to a PHI node must be a reduction value.
124  if (IsAPhi && Cur != Phi && !areAllUsesIn(Cur, VisitedInsts))
125  return false;
126 
127  if (Kind == RK_IntegerMinMax &&
128  (isa<ICmpInst>(Cur) || isa<SelectInst>(Cur)))
129  ++NumCmpSelectPatternInst;
130  if (Kind == RK_FloatMinMax && (isa<FCmpInst>(Cur) || isa<SelectInst>(Cur)))
131  ++NumCmpSelectPatternInst;
132 
133  // Check whether we found a reduction operator.
134  FoundReduxOp |= !IsAPhi;
135 
136  // Process users of current instruction. Push non-PHI nodes after PHI nodes
137  // onto the stack. This way we are going to have seen all inputs to PHI
138  // nodes once we get to them.
141  for (User *U : Cur->users()) {
142  Instruction *UI = cast<Instruction>(U);
143 
144  // Check if we found the exit user.
145  BasicBlock *Parent = UI->getParent();
146  if (!TheLoop->contains(Parent)) {
147  // Exit if you find multiple outside users or if the header phi node is
148  // being used. In this case the user uses the value of the previous
149  // iteration, in which case we would loose "VF-1" iterations of the
150  // reduction operation if we vectorize.
151  if (ExitInstruction != nullptr || Cur == Phi)
152  return false;
153 
154  // The instruction used by an outside user must be the last instruction
155  // before we feed back to the reduction phi. Otherwise, we loose VF-1
156  // operations on the value.
157  if (std::find(Phi->op_begin(), Phi->op_end(), Cur) == Phi->op_end())
158  return false;
159 
160  ExitInstruction = Cur;
161  continue;
162  }
163 
164  // Process instructions only once (termination). Each reduction cycle
165  // value must only be used once, except by phi nodes and min/max
166  // reductions which are represented as a cmp followed by a select.
167  InstDesc IgnoredVal(false, nullptr);
168  if (VisitedInsts.insert(UI).second) {
169  if (isa<PHINode>(UI))
170  PHIs.push_back(UI);
171  else
172  NonPHIs.push_back(UI);
173  } else if (!isa<PHINode>(UI) &&
174  ((!isa<FCmpInst>(UI) && !isa<ICmpInst>(UI) &&
175  !isa<SelectInst>(UI)) ||
176  !isMinMaxSelectCmpPattern(UI, IgnoredVal).isRecurrence()))
177  return false;
178 
179  // Remember that we completed the cycle.
180  if (UI == Phi)
181  FoundStartPHI = true;
182  }
183  Worklist.append(PHIs.begin(), PHIs.end());
184  Worklist.append(NonPHIs.begin(), NonPHIs.end());
185  }
186 
187  // This means we have seen one but not the other instruction of the
188  // pattern or more than just a select and cmp.
189  if ((Kind == RK_IntegerMinMax || Kind == RK_FloatMinMax) &&
190  NumCmpSelectPatternInst != 2)
191  return false;
192 
193  if (!FoundStartPHI || !FoundReduxOp || !ExitInstruction)
194  return false;
195 
196  // We found a reduction var if we have reached the original phi node and we
197  // only have a single instruction with out-of-loop users.
198 
199  // The ExitInstruction(Instruction which is allowed to have out-of-loop users)
200  // is saved as part of the RecurrenceDescriptor.
201 
202  // Save the description of this reduction variable.
203  RecurrenceDescriptor RD(RdxStart, ExitInstruction, Kind,
204  ReduxDesc.getMinMaxKind());
205 
206  RedDes = RD;
207 
208  return true;
209 }
210 
211 /// Returns true if the instruction is a Select(ICmp(X, Y), X, Y) instruction
212 /// pattern corresponding to a min(X, Y) or max(X, Y).
215 
216  assert((isa<ICmpInst>(I) || isa<FCmpInst>(I) || isa<SelectInst>(I)) &&
217  "Expect a select instruction");
218  Instruction *Cmp = nullptr;
219  SelectInst *Select = nullptr;
220 
221  // We must handle the select(cmp()) as a single instruction. Advance to the
222  // select.
223  if ((Cmp = dyn_cast<ICmpInst>(I)) || (Cmp = dyn_cast<FCmpInst>(I))) {
224  if (!Cmp->hasOneUse() || !(Select = dyn_cast<SelectInst>(*I->user_begin())))
225  return InstDesc(false, I);
226  return InstDesc(Select, Prev.getMinMaxKind());
227  }
228 
229  // Only handle single use cases for now.
230  if (!(Select = dyn_cast<SelectInst>(I)))
231  return InstDesc(false, I);
232  if (!(Cmp = dyn_cast<ICmpInst>(I->getOperand(0))) &&
233  !(Cmp = dyn_cast<FCmpInst>(I->getOperand(0))))
234  return InstDesc(false, I);
235  if (!Cmp->hasOneUse())
236  return InstDesc(false, I);
237 
238  Value *CmpLeft;
239  Value *CmpRight;
240 
241  // Look for a min/max pattern.
242  if (m_UMin(m_Value(CmpLeft), m_Value(CmpRight)).match(Select))
243  return InstDesc(Select, MRK_UIntMin);
244  else if (m_UMax(m_Value(CmpLeft), m_Value(CmpRight)).match(Select))
245  return InstDesc(Select, MRK_UIntMax);
246  else if (m_SMax(m_Value(CmpLeft), m_Value(CmpRight)).match(Select))
247  return InstDesc(Select, MRK_SIntMax);
248  else if (m_SMin(m_Value(CmpLeft), m_Value(CmpRight)).match(Select))
249  return InstDesc(Select, MRK_SIntMin);
250  else if (m_OrdFMin(m_Value(CmpLeft), m_Value(CmpRight)).match(Select))
251  return InstDesc(Select, MRK_FloatMin);
252  else if (m_OrdFMax(m_Value(CmpLeft), m_Value(CmpRight)).match(Select))
253  return InstDesc(Select, MRK_FloatMax);
254  else if (m_UnordFMin(m_Value(CmpLeft), m_Value(CmpRight)).match(Select))
255  return InstDesc(Select, MRK_FloatMin);
256  else if (m_UnordFMax(m_Value(CmpLeft), m_Value(CmpRight)).match(Select))
257  return InstDesc(Select, MRK_FloatMax);
258 
259  return InstDesc(false, I);
260 }
261 
264  InstDesc &Prev, bool HasFunNoNaNAttr) {
265  bool FP = I->getType()->isFloatingPointTy();
266  bool FastMath = FP && I->hasUnsafeAlgebra();
267  switch (I->getOpcode()) {
268  default:
269  return InstDesc(false, I);
270  case Instruction::PHI:
271  if (FP &&
272  (Kind != RK_FloatMult && Kind != RK_FloatAdd && Kind != RK_FloatMinMax))
273  return InstDesc(false, I);
274  return InstDesc(I, Prev.getMinMaxKind());
275  case Instruction::Sub:
276  case Instruction::Add:
277  return InstDesc(Kind == RK_IntegerAdd, I);
278  case Instruction::Mul:
279  return InstDesc(Kind == RK_IntegerMult, I);
280  case Instruction::And:
281  return InstDesc(Kind == RK_IntegerAnd, I);
282  case Instruction::Or:
283  return InstDesc(Kind == RK_IntegerOr, I);
284  case Instruction::Xor:
285  return InstDesc(Kind == RK_IntegerXor, I);
286  case Instruction::FMul:
287  return InstDesc(Kind == RK_FloatMult && FastMath, I);
288  case Instruction::FSub:
289  case Instruction::FAdd:
290  return InstDesc(Kind == RK_FloatAdd && FastMath, I);
291  case Instruction::FCmp:
292  case Instruction::ICmp:
293  case Instruction::Select:
294  if (Kind != RK_IntegerMinMax &&
295  (!HasFunNoNaNAttr || Kind != RK_FloatMinMax))
296  return InstDesc(false, I);
297  return isMinMaxSelectCmpPattern(I, Prev);
298  }
299 }
300 
303  unsigned NumUses = 0;
304  for (User::op_iterator Use = I->op_begin(), E = I->op_end(); Use != E;
305  ++Use) {
306  if (Insts.count(dyn_cast<Instruction>(*Use)))
307  ++NumUses;
308  if (NumUses > 1)
309  return true;
310  }
311 
312  return false;
313 }
315  RecurrenceDescriptor &RedDes) {
316 
317  bool HasFunNoNaNAttr = false;
318  BasicBlock *Header = TheLoop->getHeader();
319  Function &F = *Header->getParent();
320  if (F.hasFnAttribute("no-nans-fp-math"))
321  HasFunNoNaNAttr =
322  F.getFnAttribute("no-nans-fp-math").getValueAsString() == "true";
323 
324  if (AddReductionVar(Phi, RK_IntegerAdd, TheLoop, HasFunNoNaNAttr, RedDes)) {
325  DEBUG(dbgs() << "Found an ADD reduction PHI." << *Phi << "\n");
326  return true;
327  }
328  if (AddReductionVar(Phi, RK_IntegerMult, TheLoop, HasFunNoNaNAttr, RedDes)) {
329  DEBUG(dbgs() << "Found a MUL reduction PHI." << *Phi << "\n");
330  return true;
331  }
332  if (AddReductionVar(Phi, RK_IntegerOr, TheLoop, HasFunNoNaNAttr, RedDes)) {
333  DEBUG(dbgs() << "Found an OR reduction PHI." << *Phi << "\n");
334  return true;
335  }
336  if (AddReductionVar(Phi, RK_IntegerAnd, TheLoop, HasFunNoNaNAttr, RedDes)) {
337  DEBUG(dbgs() << "Found an AND reduction PHI." << *Phi << "\n");
338  return true;
339  }
340  if (AddReductionVar(Phi, RK_IntegerXor, TheLoop, HasFunNoNaNAttr, RedDes)) {
341  DEBUG(dbgs() << "Found a XOR reduction PHI." << *Phi << "\n");
342  return true;
343  }
344  if (AddReductionVar(Phi, RK_IntegerMinMax, TheLoop, HasFunNoNaNAttr,
345  RedDes)) {
346  DEBUG(dbgs() << "Found a MINMAX reduction PHI." << *Phi << "\n");
347  return true;
348  }
349  if (AddReductionVar(Phi, RK_FloatMult, TheLoop, HasFunNoNaNAttr, RedDes)) {
350  DEBUG(dbgs() << "Found an FMult reduction PHI." << *Phi << "\n");
351  return true;
352  }
353  if (AddReductionVar(Phi, RK_FloatAdd, TheLoop, HasFunNoNaNAttr, RedDes)) {
354  DEBUG(dbgs() << "Found an FAdd reduction PHI." << *Phi << "\n");
355  return true;
356  }
357  if (AddReductionVar(Phi, RK_FloatMinMax, TheLoop, HasFunNoNaNAttr, RedDes)) {
358  DEBUG(dbgs() << "Found an float MINMAX reduction PHI." << *Phi << "\n");
359  return true;
360  }
361  // Not a reduction of known type.
362  return false;
363 }
364 
365 /// This function returns the identity element (or neutral element) for
366 /// the operation K.
368  Type *Tp) {
369  switch (K) {
370  case RK_IntegerXor:
371  case RK_IntegerAdd:
372  case RK_IntegerOr:
373  // Adding, Xoring, Oring zero to a number does not change it.
374  return ConstantInt::get(Tp, 0);
375  case RK_IntegerMult:
376  // Multiplying a number by 1 does not change it.
377  return ConstantInt::get(Tp, 1);
378  case RK_IntegerAnd:
379  // AND-ing a number with an all-1 value does not change it.
380  return ConstantInt::get(Tp, -1, true);
381  case RK_FloatMult:
382  // Multiplying a number by 1 does not change it.
383  return ConstantFP::get(Tp, 1.0L);
384  case RK_FloatAdd:
385  // Adding zero to a number does not change it.
386  return ConstantFP::get(Tp, 0.0L);
387  default:
388  llvm_unreachable("Unknown recurrence kind");
389  }
390 }
391 
392 /// This function translates the recurrence kind to an LLVM binary operator.
394  switch (Kind) {
395  case RK_IntegerAdd:
396  return Instruction::Add;
397  case RK_IntegerMult:
398  return Instruction::Mul;
399  case RK_IntegerOr:
400  return Instruction::Or;
401  case RK_IntegerAnd:
402  return Instruction::And;
403  case RK_IntegerXor:
404  return Instruction::Xor;
405  case RK_FloatMult:
406  return Instruction::FMul;
407  case RK_FloatAdd:
408  return Instruction::FAdd;
409  case RK_IntegerMinMax:
410  return Instruction::ICmp;
411  case RK_FloatMinMax:
412  return Instruction::FCmp;
413  default:
414  llvm_unreachable("Unknown recurrence operation");
415  }
416 }
417 
420  Value *Left, Value *Right) {
422  switch (RK) {
423  default:
424  llvm_unreachable("Unknown min/max recurrence kind");
425  case MRK_UIntMin:
426  P = CmpInst::ICMP_ULT;
427  break;
428  case MRK_UIntMax:
429  P = CmpInst::ICMP_UGT;
430  break;
431  case MRK_SIntMin:
432  P = CmpInst::ICMP_SLT;
433  break;
434  case MRK_SIntMax:
435  P = CmpInst::ICMP_SGT;
436  break;
437  case MRK_FloatMin:
438  P = CmpInst::FCMP_OLT;
439  break;
440  case MRK_FloatMax:
441  P = CmpInst::FCMP_OGT;
442  break;
443  }
444 
445  Value *Cmp;
446  if (RK == MRK_FloatMin || RK == MRK_FloatMax)
447  Cmp = Builder.CreateFCmp(P, Left, Right, "rdx.minmax.cmp");
448  else
449  Cmp = Builder.CreateICmp(P, Left, Right, "rdx.minmax.cmp");
450 
451  Value *Select = Builder.CreateSelect(Cmp, Left, Right, "rdx.minmax.select");
452  return Select;
453 }
454 
456  ConstantInt *&StepValue) {
457  Type *PhiTy = Phi->getType();
458  // We only handle integer and pointer inductions variables.
459  if (!PhiTy->isIntegerTy() && !PhiTy->isPointerTy())
460  return false;
461 
462  // Check that the PHI is consecutive.
463  const SCEV *PhiScev = SE->getSCEV(Phi);
464  const SCEVAddRecExpr *AR = dyn_cast<SCEVAddRecExpr>(PhiScev);
465  if (!AR) {
466  DEBUG(dbgs() << "LV: PHI is not a poly recurrence.\n");
467  return false;
468  }
469 
470  const SCEV *Step = AR->getStepRecurrence(*SE);
471  // Calculate the pointer stride and check if it is consecutive.
472  const SCEVConstant *C = dyn_cast<SCEVConstant>(Step);
473  if (!C)
474  return false;
475 
476  ConstantInt *CV = C->getValue();
477  if (PhiTy->isIntegerTy()) {
478  StepValue = CV;
479  return true;
480  }
481 
482  assert(PhiTy->isPointerTy() && "The PHI must be a pointer");
483  Type *PointerElementType = PhiTy->getPointerElementType();
484  // The pointer stride cannot be determined if the pointer element type is not
485  // sized.
486  if (!PointerElementType->isSized())
487  return false;
488 
489  const DataLayout &DL = Phi->getModule()->getDataLayout();
490  int64_t Size = static_cast<int64_t>(DL.getTypeAllocSize(PointerElementType));
491  if (!Size)
492  return false;
493 
494  int64_t CVSize = CV->getSExtValue();
495  if (CVSize % Size)
496  return false;
497  StepValue = ConstantInt::getSigned(CV->getType(), CVSize / Size);
498  return true;
499 }
MaxMin_match< ICmpInst, LHS, RHS, umin_pred_ty > m_UMin(const LHS &L, const RHS &R)
A parsed version of the target data layout string in and methods for querying it. ...
Definition: DataLayout.h:104
IntegerType * getType() const
getType - Specialize the getType() method to always return an IntegerType, which reduces the amount o...
Definition: Constants.h:140
class_match< Value > m_Value()
Match an arbitrary value and ignore it.
Definition: PatternMatch.h:64
Value * CreateICmp(CmpInst::Predicate P, Value *LHS, Value *RHS, const Twine &Name="")
Definition: IRBuilder.h:1442
ScalarEvolution - This class is the main scalar evolution driver.
bool isInductionPHI(PHINode *, ScalarEvolution *, ConstantInt *&)
Checks if the given PHINode in a loop header is an induction variable.
Definition: LoopUtils.cpp:455
size_type count(PtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
Definition: SmallPtrSet.h:276
unsigned less than
Definition: InstrTypes.h:722
static bool isReductionPHI(PHINode *Phi, Loop *TheLoop, RecurrenceDescriptor &RedDes)
Returns true if Phi is a reduction in TheLoop.
Definition: LoopUtils.cpp:314
0 1 0 0 True if ordered and less than
Definition: InstrTypes.h:703
const SCEV * getStepRecurrence(ScalarEvolution &SE) const
getStepRecurrence - This method constructs and returns the recurrence indicating how much this expres...
const Function * getParent() const
Return the enclosing method, or null if none.
Definition: BasicBlock.h:111
Attribute getFnAttribute(Attribute::AttrKind Kind) const
Return the attribute for the given attribute kind.
Definition: Function.h:225
F(f)
MaxMin_match< FCmpInst, LHS, RHS, ufmax_pred_ty > m_UnordFMax(const LHS &L, const RHS &R)
Match an 'unordered' floating point maximum function.
static InstDesc isRecurrenceInstr(Instruction *I, RecurrenceKind Kind, InstDesc &Prev, bool HasFunNoNaNAttr)
Returns a struct describing if the instruction 'I' can be a recurrence variable of type 'Kind'...
Definition: LoopUtils.cpp:263
op_iterator op_begin()
Definition: User.h:183
BlockT * getHeader() const
Definition: LoopInfo.h:96
Type * getPointerElementType() const
Definition: Type.h:366
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
Definition: SmallPtrSet.h:242
SelectInst - This class represents the LLVM 'select' instruction.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:98
A Use represents the edge between a Value definition and its users.
Definition: Use.h:69
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
Definition: IRBuilder.h:517
static InstDesc isMinMaxSelectCmpPattern(Instruction *I, InstDesc &Prev)
Returns a struct describing if the instruction if the instruction is a Select(ICmp(X, Y), X, Y) instruction pattern corresponding to a min(X, Y) or max(X, Y).
Definition: LoopUtils.cpp:214
MaxMin_match< FCmpInst, LHS, RHS, ufmin_pred_ty > m_UnordFMin(const LHS &L, const RHS &R)
Match an 'unordered' floating point minimum function.
Value * CreateFCmp(CmpInst::Predicate P, Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:1449
SCEVAddRecExpr - This node represents a polynomial recurrence on the trip count of the specified loop...
bool LLVM_ATTRIBUTE_UNUSED_RESULT empty() const
Definition: SmallVector.h:57
This instruction compares its operands according to the predicate given to the constructor.
MaxMin_match< FCmpInst, LHS, RHS, ofmin_pred_ty > m_OrdFMin(const LHS &L, const RHS &R)
Match an 'ordered' floating point minimum function.
bool hasUnsafeAlgebra() const
Determine whether the unsafe-algebra flag is set.
MaxMin_match< ICmpInst, LHS, RHS, smin_pred_ty > m_SMin(const LHS &L, const RHS &R)
static bool areAllUsesIn(Instruction *I, SmallPtrSetImpl< Instruction * > &Set)
Returns true if all uses of the instruction I is within the Set.
Definition: LoopUtils.cpp:29
bool isFloatingPointTy() const
isFloatingPointTy - Return true if this is one of the six floating point types
Definition: Type.h:159
This POD struct holds information about a potential recurrence operation.
Definition: LoopUtils.h:95
static bool hasMultipleUsesOf(Instruction *I, SmallPtrSetImpl< Instruction * > &Insts)
Returns true if instuction I has multiple uses in Insts.
Definition: LoopUtils.cpp:301
unsigned getNumIncomingValues() const
getNumIncomingValues - Return the number of incoming edges
static bool AddReductionVar(PHINode *Phi, RecurrenceKind Kind, Loop *TheLoop, bool HasFunNoNaNAttr, RecurrenceDescriptor &RedDes)
Returns true if Phi is a reduction of type Kind and adds it to the RecurrenceDescriptor.
Definition: LoopUtils.cpp:37
#define P(N)
MaxMin_match< ICmpInst, LHS, RHS, umax_pred_ty > m_UMax(const LHS &L, const RHS &R)
BlockT * getLoopPreheader() const
getLoopPreheader - If there is a preheader for this loop, return it.
Definition: LoopInfoImpl.h:108
LLVM Basic Block Representation.
Definition: BasicBlock.h:65
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:45
This is an important base class in LLVM.
Definition: Constant.h:41
APInt Or(const APInt &LHS, const APInt &RHS)
Bitwise OR function for APInt.
Definition: APInt.h:1895
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:264
APInt Xor(const APInt &LHS, const APInt &RHS)
Bitwise XOR function for APInt.
Definition: APInt.h:1900
op_iterator op_end()
Definition: User.h:185
bool contains(const LoopT *L) const
contains - Return true if the specified loop is contained within in this loop.
Definition: LoopInfo.h:105
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
Definition: InstrTypes.h:697
Value * getOperand(unsigned i) const
Definition: User.h:118
bool isCommutative() const
isCommutative - Return true if the instruction is commutative:
Definition: Instruction.h:327
void append(in_iter in_start, in_iter in_end)
Add the specified range to the end of the SmallVector.
Definition: SmallVector.h:416
bool isPointerTy() const
isPointerTy - True if this is an instance of PointerType.
Definition: Type.h:217
static unsigned getRecurrenceBinOp(RecurrenceKind Kind)
Returns the opcode of binary operation corresponding to the RecurrenceKind.
Definition: LoopUtils.cpp:393
signed greater than
Definition: InstrTypes.h:724
The RecurrenceDescriptor is used to identify recurrences variables in a loop.
Definition: LoopUtils.h:58
0 0 1 0 True if ordered and greater than
Definition: InstrTypes.h:701
MinMaxRecurrenceKind getMinMaxKind()
Definition: LoopUtils.h:106
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
Definition: SmallPtrSet.h:299
This is the shared class of boolean and integer constants.
Definition: Constants.h:47
uint64_t getTypeAllocSize(Type *Ty) const
Returns the offset in bytes between successive objects of the specified type, including alignment pad...
Definition: DataLayout.h:388
const Module * getModule() const
Return the module owning the function this instruction belongs to or nullptr it the function does not...
Definition: Instruction.cpp:57
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:861
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:222
signed less than
Definition: InstrTypes.h:726
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:582
static ConstantInt * getSigned(IntegerType *Ty, int64_t V)
Return a ConstantInt with the specified value for the specified type.
Definition: Constants.cpp:597
ConstantInt * getValue() const
static Constant * get(Type *Ty, double V)
get() - This returns a ConstantFP, or a vector containing a splat of a ConstantFP, for the specified value in the specified type.
Definition: Constants.cpp:652
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:123
static Constant * getRecurrenceIdentity(RecurrenceKind K, Type *Tp)
Returns identity corresponding to the RecurrenceKind.
Definition: LoopUtils.cpp:367
Value * getIncomingValueForBlock(const BasicBlock *BB) const
bool isIntegerTy() const
isIntegerTy - True if this is an instance of IntegerType.
Definition: Type.h:193
Value * CreateSelect(Value *C, Value *True, Value *False, const Twine &Name="")
Definition: IRBuilder.h:1482
iterator_range< user_iterator > users()
Definition: Value.h:300
static Value * createMinMaxOp(IRBuilder<> &Builder, MinMaxRecurrenceKind RK, Value *Left, Value *Right)
Returns a Min/Max operation corresponding to MinMaxRecurrenceKind.
Definition: LoopUtils.cpp:418
LLVM_ATTRIBUTE_UNUSED_RESULT 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:285
APInt And(const APInt &LHS, const APInt &RHS)
Bitwise AND function for APInt.
Definition: APInt.h:1890
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
Definition: Module.cpp:372
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
Definition: Function.h:217
SCEV - This class represents an analyzed expression in the program.
#define I(x, y, z)
Definition: MD5.cpp:54
bool hasOneUse() const
Return true if there is exactly one user of this value.
Definition: Value.h:311
MaxMin_match< ICmpInst, LHS, RHS, smax_pred_ty > m_SMax(const LHS &L, const RHS &R)
StringRef getValueAsString() const
Return the attribute's value as a string.
Definition: Attributes.cpp:140
bool use_empty() const
Definition: Value.h:275
user_iterator user_begin()
Definition: Value.h:294
const ARM::ArchExtKind Kind
MaxMin_match< FCmpInst, LHS, RHS, ofmax_pred_ty > m_OrdFMax(const LHS &L, const RHS &R)
Match an 'ordered' floating point maximum function.
LLVM Value Representation.
Definition: Value.h:69
const SCEV * getSCEV(Value *V)
getSCEV - Return a SCEV expression for the full generality of the specified expression.
unsigned getOpcode() const
getOpcode() returns a member of one of the enums like Instruction::Add.
Definition: Instruction.h:112
#define DEBUG(X)
Definition: Debug.h:92
unsigned greater than
Definition: InstrTypes.h:720
int64_t getSExtValue() const
Return the constant as a 64-bit integer value after it has been sign extended as appropriate for the ...
Definition: Constants.h:125
const BasicBlock * getParent() const
Definition: Instruction.h:72
RecurrenceKind
This enum represents the kinds of recurrences that we support.
Definition: LoopUtils.h:62
SCEVConstant - This class represents a constant integer value.