|
LLVM 24.0.0git
|
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 PHINode * | getInductionVariable () 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 Value * | getPartitionValue (Value *V, unsigned PartitionIndex) const |
Return the counterpart of original-loop value V in partition PartitionIndex (0-based). | |
| LLVM_ABI const ValueToValueMapTy * | getPartitionValueMap (unsigned PartitionIndex) const |
Return the original-to-clone value map for the partition at PartitionIndex, for callers that want to remap many values. | |
Splits a counted loop into a chain of per-partition sub-loops.
Usage:
Definition at line 41 of file LoopSplitUtils.h.
|
inline |
Definition at line 43 of file LoopSplitUtils.h.
References LLVM_ABI.
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().
| 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().
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().
Definition at line 78 of file LoopSplitUtils.h.
References LLVM_ABI.
Referenced by getPartitionValue(), split(), and splitLoop().
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().
| 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().
| 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().
| bool LoopSplitUtils::split | ( | ) |
Perform the split.
Requires a successful isLegal() and at least two partitions. Returns true if the loop was rewritten.
Definition at line 280 of file LoopSplitUtils.cpp.
References assert(), buildEntryGuard(), llvm::cast(), DEBUG_TYPE, llvm::LoopSplitUtils::SplitState::Descending, llvm::formDedicatedExitBlocks(), getNumPartitions(), llvm::LoopSplitUtils::SplitState::Induction, llvm::LoopSplitUtils::SplitState::LatchComparesPHI, llvm::SCEVExpanderCleaner::markResultUsed(), and llvm::LoopSplitUtils::SplitState::OuterLoop.
Referenced by splitLoop().