LLVM 24.0.0git
llvm::LoopSplitUtils Class Reference

Splits a counted loop into a chain of per-partition sub-loops. More...

#include "llvm/Transforms/Utils/LoopSplitUtils.h"

Classes

struct  SplitState
 Per-split() scratch shared by the phase helpers; lives for one split() call. More...

Public Member Functions

LLVM_ABI LoopSplitUtils (Loop *L, LoopInfo *LI, ScalarEvolution *SE, DominatorTree *DT)
LLVM_ABI bool isLegal ()
 Analyze L and return true if it is a counted loop this utility can split: a bottom-tested single-exit loop in LCSSA form with a unique unit-step integer induction and a computable trip count.
LLVM_ABI PHINodegetInductionVariable () const
 Return the loop's induction variable. Valid only after isLegal() succeeds.
LLVM_ABI void addPartition (const SCEV *Start, const SCEV *End)
 Append an inclusive partition range [Start, End] in iteration order.
LLVM_ABI void avoidPartitionGuard (unsigned PartitionIndex)
 Suppress the entry guard for partition PartitionIndex (already added).
LLVM_ABI unsigned getNumPartitions () const
LLVM_ABI bool split ()
 Perform the split.
LLVM_ABI ValuegetPartitionValue (Value *V, unsigned PartitionIndex) const
 Return the counterpart of original-loop value V in partition PartitionIndex (0-based).
LLVM_ABI const ValueToValueMapTygetPartitionValueMap (unsigned PartitionIndex) const
 Return the original-to-clone value map for the partition at PartitionIndex, for callers that want to remap many values.

Detailed Description

Splits a counted loop into a chain of per-partition sub-loops.

Usage:

LoopSplitUtils LSU(L, LI, SE, DT);
if (!LSU.isLegal())
return false;
LSU.addPartition(S0, E0); // one call per partition, in order
LSU.addPartition(S1, E1);
LSU.split();
constexpr LLT S1
LLVM_ABI LoopSplitUtils(Loop *L, LoopInfo *LI, ScalarEvolution *SE, DominatorTree *DT)

Definition at line 41 of file LoopSplitUtils.h.

Constructor & Destructor Documentation

◆ LoopSplitUtils()

LLVM_ABI llvm::LoopSplitUtils::LoopSplitUtils ( Loop * L,
LoopInfo * LI,
ScalarEvolution * SE,
DominatorTree * DT )
inline

Definition at line 43 of file LoopSplitUtils.h.

References LLVM_ABI.

Member Function Documentation

◆ addPartition()

void LoopSplitUtils::addPartition ( const SCEV * Start,
const SCEV * End )

Append an inclusive partition range [Start, End] in iteration order.

Partitions must tile the whole space: first Start = induction start, each later Start = previous End +/- step, last End = induction end (desc: S >= E).

Bounds must be loop-invariant and representable in the induction type without wrapping: a Start +/- offset that wraps past TYPE_MAX/MIN/0 looks in-range and silently miscompiles. See LoopSplitUtils.cpp for the rationale.

Every partition is guarded by default; use avoidPartitionGuard() to opt out.

Definition at line 119 of file LoopSplitUtils.cpp.

Referenced by splitLoop().

◆ avoidPartitionGuard()

void LoopSplitUtils::avoidPartitionGuard ( unsigned PartitionIndex)

Suppress the entry guard for partition PartitionIndex (already added).

Use only for a partition the caller can prove runs at least once; for a runtime- empty partition this is incorrect and yields one spurious iteration.

Definition at line 124 of file LoopSplitUtils.cpp.

References assert().

Referenced by splitLoop().

◆ getInductionVariable()

LLVM_ABI PHINode * llvm::LoopSplitUtils::getInductionVariable ( ) const
inline

Return the loop's induction variable. Valid only after isLegal() succeeds.

Definition at line 54 of file LoopSplitUtils.h.

References LLVM_ABI.

Referenced by splitLoop().

◆ getNumPartitions()

LLVM_ABI unsigned llvm::LoopSplitUtils::getNumPartitions ( ) const
inline

Definition at line 78 of file LoopSplitUtils.h.

References LLVM_ABI.

Referenced by getPartitionValue(), split(), and splitLoop().

◆ getPartitionValue()

Value * LoopSplitUtils::getPartitionValue ( Value * V,
unsigned PartitionIndex ) const

Return the counterpart of original-loop value V in partition PartitionIndex (0-based).

Partition 0 maps values to themselves; a later partition returns the clone, or null if not cloned. Valid only after split().

Definition at line 139 of file LoopSplitUtils.cpp.

References assert(), getNumPartitions(), getPartitionValueMap(), and llvm::ValueMap< KeyT, ValueT, Config >::lookup().

Referenced by splitLoop().

◆ getPartitionValueMap()

const ValueToValueMapTy * LoopSplitUtils::getPartitionValueMap ( unsigned PartitionIndex) const

Return the original-to-clone value map for the partition at PartitionIndex, for callers that want to remap many values.

Null for partition 0 (identity) and for any partition that was not cloned.

Definition at line 132 of file LoopSplitUtils.cpp.

Referenced by getPartitionValue().

◆ isLegal()

bool LoopSplitUtils::isLegal ( )

Analyze L and return true if it is a counted loop this utility can split: a bottom-tested single-exit loop in LCSSA form with a unique unit-step integer induction and a computable trip count.

Must succeed before split().

Definition at line 209 of file LoopSplitUtils.cpp.

References analyzeInduction(), computeSignedness(), llvm::dbgs(), DEBUG_TYPE, llvm::SCEVAddRecExpr::evaluateAtIteration(), llvm::ilist_detail::node_parent_access< NodeTy, ParentTy >::getParent(), llvm::SCEVAddRecExpr::getStart(), llvm::SCEV::getType(), llvm::isa(), LLVM_DEBUG, and llvm::Signed.

Referenced by splitLoop().

◆ split()


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