LLVM  3.7.0
Classes | Public Types | Public Member Functions | Static Public Member Functions | List of all members
llvm::RecurrenceDescriptor Class Reference

The RecurrenceDescriptor is used to identify recurrences variables in a loop. More...

#include <LoopUtils.h>

Classes

class  InstDesc
 This POD struct holds information about a potential recurrence operation. More...
 

Public Types

enum  RecurrenceKind {
  RK_NoRecurrence, RK_IntegerAdd, RK_IntegerMult, RK_IntegerOr,
  RK_IntegerAnd, RK_IntegerXor, RK_IntegerMinMax, RK_FloatAdd,
  RK_FloatMult, RK_FloatMinMax
}
 This enum represents the kinds of recurrences that we support. More...
 
enum  MinMaxRecurrenceKind {
  MRK_Invalid, MRK_UIntMin, MRK_UIntMax, MRK_SIntMin,
  MRK_SIntMax, MRK_FloatMin, MRK_FloatMax
}
 

Public Member Functions

 RecurrenceDescriptor ()
 
 RecurrenceDescriptor (Value *Start, Instruction *Exit, RecurrenceKind K, MinMaxRecurrenceKind MK)
 
RecurrenceKind getRecurrenceKind ()
 
MinMaxRecurrenceKind getMinMaxRecurrenceKind ()
 
TrackingVH< ValuegetRecurrenceStartValue ()
 
InstructiongetLoopExitInstr ()
 

Static Public Member Functions

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'. More...
 
static bool hasMultipleUsesOf (Instruction *I, SmallPtrSetImpl< Instruction * > &Insts)
 Returns true if instuction I has multiple uses in Insts. More...
 
static bool areAllUsesIn (Instruction *I, SmallPtrSetImpl< Instruction * > &Set)
 Returns true if all uses of the instruction I is within the Set. More...
 
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). More...
 
static ConstantgetRecurrenceIdentity (RecurrenceKind K, Type *Tp)
 Returns identity corresponding to the RecurrenceKind. More...
 
static unsigned getRecurrenceBinOp (RecurrenceKind Kind)
 Returns the opcode of binary operation corresponding to the RecurrenceKind. More...
 
static ValuecreateMinMaxOp (IRBuilder<> &Builder, MinMaxRecurrenceKind RK, Value *Left, Value *Right)
 Returns a Min/Max operation corresponding to MinMaxRecurrenceKind. More...
 
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. More...
 
static bool isReductionPHI (PHINode *Phi, Loop *TheLoop, RecurrenceDescriptor &RedDes)
 Returns true if Phi is a reduction in TheLoop. More...
 

Detailed Description

The RecurrenceDescriptor is used to identify recurrences variables in a loop.

Reduction is a special case of recurrence that has uses of the recurrence variable outside the loop. The method isReductionPHI identifies reductions that are basic recurrences.

Basic recurrences are defined as the summation, product, OR, AND, XOR, min, or max of a set of terms. For example: for(i=0; i<n; i++) { total += array[i]; } is a summation of array elements. Basic recurrences are a special case of chains of recurrences (CR). See ScalarEvolution for CR references. This struct holds information about recurrence variables.

Definition at line 58 of file LoopUtils.h.

Member Enumeration Documentation

Enumerator
MRK_Invalid 
MRK_UIntMin 
MRK_UIntMax 
MRK_SIntMin 
MRK_SIntMax 
MRK_FloatMin 
MRK_FloatMax 

Definition at line 76 of file LoopUtils.h.

This enum represents the kinds of recurrences that we support.

Enumerator
RK_NoRecurrence 

Not a recurrence.

RK_IntegerAdd 

Sum of integers.

RK_IntegerMult 

Product of integers.

RK_IntegerOr 

Bitwise or logical OR of numbers.

RK_IntegerAnd 

Bitwise or logical AND of numbers.

RK_IntegerXor 

Bitwise or logical XOR of numbers.

RK_IntegerMinMax 

Min/max implemented in terms of select(cmp()).

RK_FloatAdd 

Sum of floats.

RK_FloatMult 

Product of floats.

RK_FloatMinMax 

Min/max implemented in terms of select(cmp()).

Definition at line 62 of file LoopUtils.h.

Constructor & Destructor Documentation

llvm::RecurrenceDescriptor::RecurrenceDescriptor ( )
inline

Definition at line 86 of file LoopUtils.h.

llvm::RecurrenceDescriptor::RecurrenceDescriptor ( Value Start,
Instruction Exit,
RecurrenceKind  K,
MinMaxRecurrenceKind  MK 
)
inline

Definition at line 90 of file LoopUtils.h.

Member Function Documentation

bool RecurrenceDescriptor::AddReductionVar ( PHINode Phi,
RecurrenceKind  Kind,
Loop TheLoop,
bool  HasFunNoNaNAttr,
RecurrenceDescriptor RedDes 
)
static
bool RecurrenceDescriptor::areAllUsesIn ( Instruction I,
SmallPtrSetImpl< Instruction * > &  Set 
)
static

Returns true if all uses of the instruction I is within the Set.

Definition at line 29 of file LoopUtils.cpp.

References llvm::SmallPtrSetImpl< PtrType >::count(), llvm::User::op_begin(), and llvm::User::op_end().

Value * RecurrenceDescriptor::createMinMaxOp ( IRBuilder<> &  Builder,
MinMaxRecurrenceKind  RK,
Value Left,
Value Right 
)
static
Instruction* llvm::RecurrenceDescriptor::getLoopExitInstr ( )
inline

Definition at line 168 of file LoopUtils.h.

MinMaxRecurrenceKind llvm::RecurrenceDescriptor::getMinMaxRecurrenceKind ( )
inline

Definition at line 164 of file LoopUtils.h.

unsigned RecurrenceDescriptor::getRecurrenceBinOp ( RecurrenceKind  Kind)
static

Returns the opcode of binary operation corresponding to the RecurrenceKind.

This function translates the recurrence kind to an LLVM binary operator.

Definition at line 393 of file LoopUtils.cpp.

References llvm::APIntOps::And(), llvm_unreachable, llvm::APIntOps::Or(), and llvm::APIntOps::Xor().

Constant * RecurrenceDescriptor::getRecurrenceIdentity ( RecurrenceKind  K,
Type Tp 
)
static

Returns identity corresponding to the RecurrenceKind.

This function returns the identity element (or neutral element) for the operation K.

Definition at line 367 of file LoopUtils.cpp.

References llvm::ConstantInt::get(), llvm::ConstantFP::get(), and llvm_unreachable.

RecurrenceKind llvm::RecurrenceDescriptor::getRecurrenceKind ( )
inline

Definition at line 162 of file LoopUtils.h.

TrackingVH<Value> llvm::RecurrenceDescriptor::getRecurrenceStartValue ( )
inline

Definition at line 166 of file LoopUtils.h.

bool RecurrenceDescriptor::hasMultipleUsesOf ( Instruction I,
SmallPtrSetImpl< Instruction * > &  Insts 
)
static

Returns true if instuction I has multiple uses in Insts.

Definition at line 301 of file LoopUtils.cpp.

References llvm::SmallPtrSetImpl< PtrType >::count(), llvm::User::op_begin(), and llvm::User::op_end().

RecurrenceDescriptor::InstDesc RecurrenceDescriptor::isMinMaxSelectCmpPattern ( Instruction I,
InstDesc Prev 
)
static

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).

Returns true if the instruction is a Select(ICmp(X, Y), X, Y) instruction pattern corresponding to a min(X, Y) or max(X, Y).

Definition at line 214 of file LoopUtils.cpp.

References llvm::dyn_cast(), llvm::RecurrenceDescriptor::InstDesc::getMinMaxKind(), llvm::User::getOperand(), llvm::Value::hasOneUse(), llvm::PatternMatch::m_OrdFMax(), llvm::PatternMatch::m_OrdFMin(), llvm::PatternMatch::m_SMax(), llvm::PatternMatch::m_SMin(), llvm::PatternMatch::m_UMax(), llvm::PatternMatch::m_UMin(), llvm::PatternMatch::m_UnordFMax(), llvm::PatternMatch::m_UnordFMin(), llvm::PatternMatch::m_Value(), llvm::MCID::Select, and llvm::Value::user_begin().

RecurrenceDescriptor::InstDesc RecurrenceDescriptor::isRecurrenceInstr ( Instruction I,
RecurrenceKind  Kind,
InstDesc Prev,
bool  HasFunNoNaNAttr 
)
static

Returns a struct describing if the instruction 'I' can be a recurrence variable of type 'Kind'.

If the recurrence is a min/max pattern of select(icmp()) this function advances the instruction pointer 'I' from the compare instruction to the select instruction and stores this pointer in 'PatternLastInst' member of the returned struct.

Definition at line 263 of file LoopUtils.cpp.

References llvm::APIntOps::And(), llvm::RecurrenceDescriptor::InstDesc::getMinMaxKind(), llvm::Instruction::getOpcode(), llvm::Value::getType(), llvm::Instruction::hasUnsafeAlgebra(), llvm::Type::isFloatingPointTy(), llvm::APIntOps::Or(), llvm::TargetOpcode::PHI, llvm::MCID::Select, and llvm::APIntOps::Xor().

bool RecurrenceDescriptor::isReductionPHI ( PHINode Phi,
Loop TheLoop,
RecurrenceDescriptor RedDes 
)
static

The documentation for this class was generated from the following files: