[PATCH] D12046: AMDGPU: Use DFS to avoid second loop over function

Daniel Berlin via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 14 20:29:11 PDT 2015


Do you actually use Visited outside of the iterator (It's not visible
in this patch if you do)?
If not, you should just use depth_first, not depth_first_ext.


On Fri, Aug 14, 2015 at 5:17 PM, Matt Arsenault via llvm-commits
<llvm-commits at lists.llvm.org> wrote:
> arsenm created this revision.
> arsenm added a reviewer: tstellarAMD.
> arsenm added a subscriber: llvm-commits.
> Herald added a subscriber: MatzeB.
>
> http://reviews.llvm.org/D12046
>
> Files:
>   lib/Target/AMDGPU/SIFixSGPRLiveRanges.cpp
>
> Index: lib/Target/AMDGPU/SIFixSGPRLiveRanges.cpp
> ===================================================================
> --- lib/Target/AMDGPU/SIFixSGPRLiveRanges.cpp
> +++ lib/Target/AMDGPU/SIFixSGPRLiveRanges.cpp
> @@ -47,6 +47,7 @@
>  #include "AMDGPU.h"
>  #include "SIInstrInfo.h"
>  #include "SIRegisterInfo.h"
> +#include "llvm/ADT/DepthFirstIterator.h"
>  #include "llvm/CodeGen/LiveIntervalAnalysis.h"
>  #include "llvm/CodeGen/LiveVariables.h"
>  #include "llvm/CodeGen/MachineFunctionPass.h"
> @@ -129,10 +130,14 @@
>    MachinePostDominatorTree *PDT = &getAnalysis<MachinePostDominatorTree>();
>    std::vector<std::pair<unsigned, LiveRange *>> SGPRLiveRanges;
>
> +  MachineBasicBlock *Entry = MF.begin();
> +  SmallPtrSet<MachineBasicBlock *, 16> Visited;
>
> -  // First pass, collect all live intervals for SGPRs
> -  for (const MachineBasicBlock &MBB : MF) {
> -    for (const MachineInstr &MI : MBB) {
> +  // Use a depth first order so that in SSA, we encounter all defs before
> +  // uses. Once the defs of the block have been found, attempt to insert
> +  // SGPR_USE instructions in successor blocks if required.
> +  for (MachineBasicBlock *MBB : depth_first_ext(Entry, Visited)) {
> +    for (const MachineInstr &MI : *MBB) {
>        for (const MachineOperand &MO : MI.defs()) {
>          if (MO.isImplicit())
>            continue;
> @@ -142,29 +147,23 @@
>              // Only consider defs that are live outs. We don't care about def /
>              // use within the same block.
>              LiveRange &LR = LIS->getInterval(Def);
> -            if (LIS->isLiveOutOfMBB(LR, &MBB))
> +            if (LIS->isLiveOutOfMBB(LR, MBB))
>                SGPRLiveRanges.push_back(std::make_pair(Def, &LR));
>            }
>          } else if (TRI->isSGPRClass(TRI->getPhysRegClass(Def))) {
> -            SGPRLiveRanges.push_back(
> -                std::make_pair(Def, &LIS->getRegUnit(Def)));
> +          SGPRLiveRanges.push_back(std::make_pair(Def, &LIS->getRegUnit(Def)));
>          }
>        }
>      }
> -  }
>
> -  // Second pass fix the intervals
> -  for (MachineFunction::iterator BI = MF.begin(), BE = MF.end();
> -                                                  BI != BE; ++BI) {
> -    MachineBasicBlock &MBB = *BI;
> -    if (MBB.succ_size() < 2)
> +    if (MBB->succ_size() < 2)
>        continue;
>
>      // We have structured control flow, so the number of successors should be
>      // two.
> -    assert(MBB.succ_size() == 2);
> -    MachineBasicBlock *SuccA = *MBB.succ_begin();
> -    MachineBasicBlock *SuccB = *(++MBB.succ_begin());
> +    assert(MBB->succ_size() == 2);
> +    MachineBasicBlock *SuccA = *MBB->succ_begin();
> +    MachineBasicBlock *SuccB = *(++MBB->succ_begin());
>      MachineBasicBlock *NCD = PDT->findNearestCommonDominator(SuccA, SuccB);
>
>      if (!NCD)
>
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>


More information about the llvm-commits mailing list