LLVM 20.0.0git |
Class to represented the control flow structure of an OpenMP canonical loop.More...
#include "llvm/Frontend/OpenMP/OMPIRBuilder.h"
Public Member Functions | |
bool | isValid ()const |
Returns whether this object currently represents the IR of a loop. | |
BasicBlock * | getPreheader ()const |
The preheader ensures that there is only a single edge entering the loop. | |
BasicBlock * | getHeader ()const |
The header is the entry for each iteration. | |
BasicBlock * | getCond ()const |
The condition block computes whether there is another loop iteration. | |
BasicBlock * | getBody ()const |
The body block is the single entry for a loop iteration and not controlled byCanonicalLoopInfo. | |
BasicBlock * | getLatch ()const |
Reaching the latch indicates the end of the loop body code. | |
BasicBlock * | getExit ()const |
Reaching the exit indicates no more iterations are being executed. | |
BasicBlock * | getAfter ()const |
The after block is intended for clean-up code such as lifetime end markers. | |
Value * | getTripCount ()const |
Returns thellvm::Value containing the number of loop iterations. | |
Instruction * | getIndVar ()const |
Returns the instruction representing the current logical induction variable. | |
Type * | getIndVarType ()const |
Return the type of the induction variable (and the trip count). | |
OpenMPIRBuilder::InsertPointTy | getPreheaderIP ()const |
Return the insertion point for user code before the loop. | |
OpenMPIRBuilder::InsertPointTy | getBodyIP ()const |
Return the insertion point for user code in the body. | |
OpenMPIRBuilder::InsertPointTy | getAfterIP ()const |
Return the insertion point for user code after the loop. | |
Function * | getFunction ()const |
void | assertOK ()const |
Consistency self-check. | |
void | invalidate () |
Invalidate this loop. | |
Friends | |
class | OpenMPIRBuilder |
Class to represented the control flow structure of an OpenMP canonical loop.
The control-flow structure is standardized for easy consumption by directives associated with loops. For instance, the worksharing-loop construct may change this control flow such that each loop iteration is executed on only one thread. The constraints of a canonical loop in brief are:
Keep in mind thatCanonicalLoopInfo is meant to only describe a repeated execution of a loop body that satifies these constraints. It does NOT represent arbitrary SESE regions that happen to contain a loop. Do not useCanonicalLoopInfo for such purposes.
The control flow can be described as follows:
Preheader |
/-> Header | | | Cond—\ | | | | Body | | | | | | <...> | | | | | --Latch | | Exit | After
The loop is thought to start at PreheaderIP (at the Preheader's terminator, including) and end at AfterIP (at the After's first instruction, excluding). That is, instructions in the Preheader and After blocks (except the Preheader's terminator) are out ofCanonicalLoopInfo's control and may have side-effects. Typically, the Preheader is used to compute the loop's trip count. The instructions from BodyIP (at the Body block's first instruction, excluding) until the Latch are also considered outsideCanonicalLoopInfo's control and thus can have side-effects. The body block is the single entry point into the loop body, which may contain arbitrary control flow as long as all control paths eventually branch to the Latch block.
TODO: Consider adding another standardizedBasicBlock between Body CFG and Latch to guarantee that there is only a single edge to the latch. It would make loop transformations easier to not needing to consider multiple predecessors of the latch (See redirectAllPredecessorsTo) and would give us an equivalant to PreheaderIP, AfterIP and BodyIP for inserting code that executes after each body iteration.
There must be no loop-carried dependencies through llvm::Values. This is equivalant to that the Latch has noPHINode and the Header's onlyPHINode is for the induction variable.
All code in Header, Cond, Latch and Exit (plus the terminator of the Preheader) areCanonicalLoopInfo's responsibility and their build-up checked byassertOK(). They are expected to not be modified unless explicitly modifying theCanonicalLoopInfo through a methods that applies a OpenMP loop-associated construct such as applyWorkshareLoop, tileLoops, unrollLoop, etc. These methods usually invalidate theCanonicalLoopInfo and re-use its basic blocks. After invalidation, theCanonicalLoopInfo must not be used anymore as its underlying control flow may not exist anymore. Loop-transformation methods such as tileLoops, collapseLoops and unrollLoop may also return a newCanonicalLoopInfo that can be passed to other loop-associated construct implementing methods. These loop-transforming methods may either create a newCanonicalLoopInfo usually using createLoopSkeleton and invalidate the inputCanonicalLoopInfo, or reuse and modify one of the inputCanonicalLoopInfo and return it as representing the modified loop. What is done is an implementation detail of transformation-implementing method and callers should always assume that theCanonicalLoopInfo passed to it is invalidated and a new object is returned. ReturnedCanonicalLoopInfo have the same structure and guarantees as the one created by createCanonicalLoop, such that transforming methods do not have to special case where theCanonicalLoopInfo originated from.
Generally, methods consumingCanonicalLoopInfo do not need anOpenMPIRBuilder::InsertPointTy as argument, but use the locations of theCanonicalLoopInfo to insert new or modify existing instructions. Unless documented otherwise, methods consumingCanonicalLoopInfo do not invalidate any InsertPoint that is outsideCanonicalLoopInfo's control. Specifically, any InsertPoint in the Preheader, After or Block can still be used after calling such a method.
TODO: Provide mechanisms for exception handling and cancellation points.
Defined outsideOpenMPIRBuilder because nested classes cannot be forward-declared, e.g. to avoid having to include the entireOMPIRBuilder.h.
Definition at line3512 of fileOMPIRBuilder.h.
void CanonicalLoopInfo::assertOK | ( | ) | const |
Consistency self-check.
Definition at line9892 of fileOMPIRBuilder.cpp.
ReferencesAfter,assert(),Cond,llvm::BasicBlock::front(),getOpcode(),llvm::User::getOperand(),getParent(),llvm::BasicBlock::getSinglePredecessor(),llvm::BasicBlock::getSingleSuccessor(),llvm::BasicBlock::getTerminator(),llvm::Value::getType(),llvm::CmpInst::ICMP_ULT,isValid(),isZero(),llvm::size(), andllvm::successors().
Referenced byllvm::OpenMPIRBuilder::createCanonicalLoop(), andllvm::OpenMPIRBuilder::createLoopSkeleton().
| inline |
The after block is intended for clean-up code such as lifetime end markers.
It is separate from the exit block to ensure, analogous to the preheader, it having just a single entry edge and being free from PHI nodes should there be multiple loop exits (such as from break statements/cancellations).
Definition at line3605 of fileOMPIRBuilder.h.
Referencesassert(), andisValid().
Referenced byllvm::OpenMPIRBuilder::collapseLoops(),llvm::OpenMPIRBuilder::createCanonicalLoop(),getAfterIP(), andllvm::OpenMPIRBuilder::tileLoops().
| inline |
Return the insertion point for user code after the loop.
Definition at line3650 of fileOMPIRBuilder.h.
ReferencesAfter,assert(),getAfter(), andisValid().
| inline |
The body block is the single entry for a loop iteration and not controlled byCanonicalLoopInfo.
It can contain arbitrary control flow but must eventually branch to theLatch
block.
Definition at line3581 of fileOMPIRBuilder.h.
Referencesassert(),Cond, andisValid().
Referenced byllvm::OpenMPIRBuilder::collapseLoops(),getBodyIP(),llvm::OpenMPIRBuilder::tileLoops(), andworkshareLoopTargetCallback().
| inline |
Return the insertion point for user code in the body.
Definition at line3643 of fileOMPIRBuilder.h.
Referencesassert(),llvm::BasicBlock::begin(),getBody(), andisValid().
Referenced byllvm::OpenMPIRBuilder::createCanonicalLoop().
| inline |
The condition block computes whether there is another loop iteration.
If yes, branches to the body; otherwise to the exit block.
Definition at line3573 of fileOMPIRBuilder.h.
Referencesassert(),Cond, andisValid().
Referenced byllvm::OpenMPIRBuilder::applySimd().
| inline |
Reaching the exit indicates no more iterations are being executed.
Definition at line3595 of fileOMPIRBuilder.h.
Referencesassert(), andisValid().
Referenced byllvm::OpenMPIRBuilder::tileLoops(), andworkshareLoopTargetCallback().
| inline |
Definition at line3656 of fileOMPIRBuilder.h.
Referencesassert(), andisValid().
Referenced byllvm::OpenMPIRBuilder::applySimd(), andcomputeHeuristicUnrollFactor().
| inline |
The header is the entry for each iteration.
In the canonical control flow, it only contains thePHINode for the induction variable.
Definition at line3566 of fileOMPIRBuilder.h.
Referencesassert(), andisValid().
Referenced byllvm::OpenMPIRBuilder::applySimd(),computeHeuristicUnrollFactor(), andworkshareLoopTargetCallback().
| inline |
Returns the instruction representing the current logical induction variable.
Always unsigned, always starting at 0 with an increment of one.
Definition at line3622 of fileOMPIRBuilder.h.
Referencesassert(), andisValid().
Referenced byllvm::OpenMPIRBuilder::createCanonicalLoop(),getIndVarType(), andllvm::OpenMPIRBuilder::tileLoops().
| inline |
Return the type of the induction variable (and the trip count).
Definition at line3630 of fileOMPIRBuilder.h.
Referencesassert(),getIndVar(),llvm::Value::getType(), andisValid().
| inline |
Reaching the latch indicates the end of the loop body code.
In the canonical control flow, it only contains the increment of the induction variable.
Definition at line3589 of fileOMPIRBuilder.h.
Referencesassert(), andisValid().
Referenced byllvm::OpenMPIRBuilder::applySimd(),llvm::OpenMPIRBuilder::collapseLoops(), andllvm::OpenMPIRBuilder::tileLoops().
BasicBlock * CanonicalLoopInfo::getPreheader | ( | ) | const |
The preheader ensures that there is only a single edge entering the loop.
Code that must be execute before any loop iteration can be emitted here, such as computing the loop trip count and begin lifetime markers. Code in the preheader is not considered part of the canonical loop.
Definition at line9838 of fileOMPIRBuilder.cpp.
Referencesassert(),isValid(),llvm_unreachable, andllvm::predecessors().
Referenced byllvm::OpenMPIRBuilder::collapseLoops(),llvm::OpenMPIRBuilder::createCanonicalLoop(),getPreheaderIP(),llvm::OpenMPIRBuilder::tileLoops(), andworkshareLoopTargetCallback().
| inline |
Return the insertion point for user code before the loop.
Definition at line3636 of fileOMPIRBuilder.h.
Referencesassert(),llvm::BasicBlock::end(),getPreheader(), andisValid().
Referenced byllvm::OpenMPIRBuilder::collapseLoops(), andllvm::OpenMPIRBuilder::tileLoops().
| inline |
Returns thellvm::Value containing the number of loop iterations.
It must be valid in the preheader and always interpreted as an unsigned integer of any bit-width.
Definition at line3613 of fileOMPIRBuilder.h.
Referencesassert(),Cond,llvm::User::getOperand(), andisValid().
Referenced byworkshareLoopTargetCallback().
void CanonicalLoopInfo::invalidate | ( | ) |
Invalidate this loop.
That is, the underlying IR does not fulfill the requirements of an OpenMP canonical loop anymore.
Definition at line9986 of fileOMPIRBuilder.cpp.
ReferencesCond.
Referenced byworkshareLoopTargetCallback().
| inline |
Returns whether this object currently represents the IR of a loop.
If returning false, it may have been consumed by a loop transformation or not been intialized. Do not use in this case;
Definition at line3556 of fileOMPIRBuilder.h.
Referenced bygetAfter(),getAfterIP(),getBody(),getBodyIP(),getCond(),getExit(),getFunction(),getHeader(),getIndVar(),getIndVarType(),getLatch(),getPreheaderIP(), andgetTripCount().
| friend |
Definition at line3513 of fileOMPIRBuilder.h.