[#llvm-Loop-LoopBounds] = xref:llvm.adoc[llvm]::xref:llvm/Loop.adoc[Loop]::LoopBounds :relfileprefix: ../../ :mrdocs: Utilities for the induction variable bounds of a loop. == Synopsis Declared in `<llvm/Analysis/LoopInfo.h>` [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- struct LoopBounds; ---- == Description Below are some utilities to get the loop guard, loop bounds and induction variable, and to check if a given phinode is an auxiliary induction variable, if the loop is guarded, and if the loop is canonical. Here is an example: [,cpp] ---- for (int i = lb; i < ub; i+=step) --- pseudo LLVMIR --- beforeloop: guardcmp = (lb < ub) if (guardcmp) goto preheader; else goto afterloop preheader: loop: i_1 = phi[{lb, preheader}, {i_2, latch}] i_2 = i_1 + step latch: cmp = (i_2 < ub) if (cmp) goto loop exit: afterloop: ---- * getBounds * getInitialIVValue ‐‐> lb * getStepInst ‐‐> i_2 = i_1 + step * getStepValue ‐‐> step * getFinalIVValue ‐‐> ub * getCanonicalPredicate ‐‐> '<' * getDirection ‐‐> Increasing * getInductionVariable ‐‐> i_1 * isAuxiliaryInductionVariable(x) ‐‐> true if x == i_1 * getLoopGuardBranch() ‐‐> `if (guardcmp) goto preheader; else goto afterloop` * isGuarded() ‐‐> true * isCanonical ‐‐> false == Enums [cols="1,4"] |=== | Name| Description | xref:llvm/Loop/LoopBounds/Direction.adoc[`Direction`] | Direction of the induction variable across loop iterations. |=== == Member Functions [cols="1,4"] |=== | Name| Description | xref:llvm/Loop/LoopBounds/getCanonicalPredicate.adoc[`getCanonicalPredicate`] | Return the canonical predicate for the latch compare instruction, if able to be calcuated. Else BAD_ICMP_PREDICATE. | xref:llvm/Loop/LoopBounds/getDirection.adoc[`getDirection`] | Get the direction of the loop. | xref:llvm/Loop/LoopBounds/getFinalIVValue.adoc[`getFinalIVValue`] | Get the final value of the loop induction variable. | xref:llvm/Loop/LoopBounds/getInitialIVValue.adoc[`getInitialIVValue`] | Get the initial value of the loop induction variable. | xref:llvm/Loop/LoopBounds/getStepInst.adoc[`getStepInst`] | Get the instruction that updates the loop induction variable. | xref:llvm/Loop/LoopBounds/getStepValue.adoc[`getStepValue`] | Get the step that the loop induction variable gets updated by in each loop iteration. Return nullptr if not found. |=== == Static Member Functions [cols="1,4"] |=== | Name| Description | xref:llvm/Loop/LoopBounds/getBounds.adoc[`getBounds`] | Return LoopBounds for `IndVar` when its initial, step, and final values can be found; otherwise return std::nullopt. |=== [.small]#Created with https://www.mrdocs.com[MrDocs]#