LLVM 24.0.0git
llvm::AMDGPU::LoopFinder Class Reference

Helper class that detects loops which require us to lower an i1 COPY into bitwise manipulation. More...

Public Member Functions

 LoopFinder (MachineDominatorTree &DT, MachinePostDominatorTree &PDT)
void initialize (MachineBasicBlock &MBB)
unsigned findLoop (MachineBasicBlock *PostDom)
 Check whether a backward edge can be reached without going through the given PostDom of the def block.
void addLoopEntries (unsigned LoopLevel, MachineIDFSSAUpdater &SSAUpdater, MachineRegisterInfo &MRI, MachineRegisterInfo::VRegAttrs LaneMaskRegAttrs, ArrayRef< AMDGPU::Incoming > Incomings={})
 Add undef values dominating the loop and the optionally given additional blocks, so that the SSA updater doesn't have to search all the way to the function entry.

Detailed Description

Helper class that detects loops which require us to lower an i1 COPY into bitwise manipulation.

Unfortunately, we cannot use LoopInfo because LoopInfo does not distinguish between loops with the same header. Consider this example:

A-+-+ | | | B-+ | | | C—+

A is the header of a loop containing A, B, and C as far as LoopInfo is concerned. However, an i1 COPY in B that is used in C must be lowered to bitwise operations to combine results from different loop iterations when B has a divergent branch (since by default we will compile this code such that threads in a wave are merged at the entry of C).

The following rule is implemented to determine whether bitwise operations are required: use the bitwise lowering for a def in block B if a backward edge to B is reachable without going through the nearest common post-dominator of B and all uses of the def.

TODO: This rule is conservative because it does not check whether the relevant branches are actually divergent.

The class is designed to cache the CFG traversal so that it can be re-used for multiple defs within the same basic block.

TODO: We could use region analysis to quickly skip over SESE regions during the traversal.

Definition at line 218 of file SILowerI1Copies.cpp.

Constructor & Destructor Documentation

◆ LoopFinder()

llvm::AMDGPU::LoopFinder::LoopFinder ( MachineDominatorTree & DT,
MachinePostDominatorTree & PDT )
inline

Definition at line 244 of file SILowerI1Copies.cpp.

Member Function Documentation

◆ addLoopEntries()

void llvm::AMDGPU::LoopFinder::addLoopEntries ( unsigned LoopLevel,
MachineIDFSSAUpdater & SSAUpdater,
MachineRegisterInfo & MRI,
MachineRegisterInfo::VRegAttrs LaneMaskRegAttrs,
ArrayRef< AMDGPU::Incoming > Incomings = {} )
inline

Add undef values dominating the loop and the optionally given additional blocks, so that the SSA updater doesn't have to search all the way to the function entry.

Definition at line 284 of file SILowerI1Copies.cpp.

Referenced by llvm::AMDGPU::PhiLoweringHelper::mergeIncomingLaneMasks().

◆ findLoop()

unsigned llvm::AMDGPU::LoopFinder::findLoop ( MachineBasicBlock * PostDom)
inline

Check whether a backward edge can be reached without going through the given PostDom of the def block.

Return the level of PostDom if a loop was found, or 0 otherwise.

Definition at line 262 of file SILowerI1Copies.cpp.

References llvm::DomTreeNodeBase< NodeT >::getBlock(), and llvm::DomTreeNodeBase< NodeT >::getIDom().

Referenced by llvm::AMDGPU::PhiLoweringHelper::mergeIncomingLaneMasks().

◆ initialize()

void llvm::AMDGPU::LoopFinder::initialize ( MachineBasicBlock & MBB)
inline

Definition at line 247 of file SILowerI1Copies.cpp.

References MBB.

Referenced by llvm::AMDGPU::PhiLoweringHelper::mergeIncomingLaneMasks().


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