From 375d767b5408cb2ba33185921f382c5f1115bce3 Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Wed, 3 Apr 2013 16:24:09 +0000 Subject: [PATCH] R600: Simplify data structure and add DEBUG to R600ControlFlowFinalizer git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@178665 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Target/R600/R600ControlFlowFinalizer.cpp | 41 ++++++++++---------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/lib/Target/R600/R600ControlFlowFinalizer.cpp b/lib/Target/R600/R600ControlFlowFinalizer.cpp index 5c30601e0ad..01dd22718ca 100644 --- a/lib/Target/R600/R600ControlFlowFinalizer.cpp +++ b/lib/Target/R600/R600ControlFlowFinalizer.cpp @@ -12,6 +12,10 @@ /// computing their address on the fly ; it also sets STACK_SIZE info. //===----------------------------------------------------------------------===// +#define DEBUG_TYPE "r600cf" +#include "llvm/Support/Debug.h" +#include "llvm/Support/raw_ostream.h" + #include "AMDGPU.h" #include "R600Defines.h" #include "R600InstrInfo.h" @@ -87,14 +91,7 @@ private: return I; } void CounterPropagateAddr(MachineInstr *MI, unsigned Addr) const { - switch (MI->getOpcode()) { - case AMDGPU::WHILE_LOOP: - MI->getOperand(0).setImm(Addr + 1); - break; - default: - MI->getOperand(0).setImm(Addr); - break; - } + MI->getOperand(0).setImm(Addr + MI->getOperand(0).getImm()); } void CounterPropagateAddr(std::set MIs, unsigned Addr) const { @@ -123,7 +120,7 @@ public: MachineBasicBlock &MBB = *MB; unsigned CfCount = 0; std::vector > > LoopStack; - std::vector > IfThenElseStack; + std::vector IfThenElseStack; R600MachineFunctionInfo *MFI = MF.getInfo(); if (MFI->ShaderType == 1) { BuildMI(MBB, MBB.begin(), MBB.findDebugLoc(MBB.begin()), @@ -133,6 +130,7 @@ public: for (MachineBasicBlock::iterator I = MBB.begin(), E = MBB.end(); I != E;) { if (isFetch(I)) { + DEBUG(dbgs() << CfCount << ":"; I->dump();); I = MakeFetchClause(MBB, I, 0); CfCount++; continue; @@ -145,6 +143,7 @@ public: CurrentStack++; MaxStack = std::max(MaxStack, CurrentStack); case AMDGPU::CF_ALU: + DEBUG(dbgs() << CfCount << ":"; MI->dump();); CfCount++; break; case AMDGPU::WHILELOOP: { @@ -152,7 +151,7 @@ public: MaxStack = std::max(MaxStack, CurrentStack); MachineInstr *MIb = BuildMI(MBB, MI, MBB.findDebugLoc(MI), TII->get(AMDGPU::WHILE_LOOP)) - .addImm(0); + .addImm(2); std::pair > Pair(CfCount, std::set()); Pair.second.insert(MIb); @@ -178,34 +177,36 @@ public: TII->get(AMDGPU::CF_JUMP)) .addImm(0) .addImm(0); - std::pair Pair(CfCount, MIb); - IfThenElseStack.push_back(Pair); + IfThenElseStack.push_back(MIb); + DEBUG(dbgs() << CfCount << ":"; MIb->dump();); MI->eraseFromParent(); CfCount++; break; } case AMDGPU::ELSE: { - std::pair Pair = IfThenElseStack.back(); + MachineInstr * JumpInst = IfThenElseStack.back(); IfThenElseStack.pop_back(); - CounterPropagateAddr(Pair.second, CfCount); + CounterPropagateAddr(JumpInst, CfCount); MachineInstr *MIb = BuildMI(MBB, MI, MBB.findDebugLoc(MI), TII->get(AMDGPU::CF_ELSE)) .addImm(0) .addImm(1); - std::pair NewPair(CfCount, MIb); - IfThenElseStack.push_back(NewPair); + DEBUG(dbgs() << CfCount << ":"; MIb->dump();); + IfThenElseStack.push_back(MIb); MI->eraseFromParent(); CfCount++; break; } case AMDGPU::ENDIF: { CurrentStack--; - std::pair Pair = IfThenElseStack.back(); + MachineInstr *IfOrElseInst = IfThenElseStack.back(); IfThenElseStack.pop_back(); - CounterPropagateAddr(Pair.second, CfCount + 1); - BuildMI(MBB, MI, MBB.findDebugLoc(MI), TII->get(AMDGPU::POP)) + CounterPropagateAddr(IfOrElseInst, CfCount); + MachineInstr *MIb = BuildMI(MBB, MI, MBB.findDebugLoc(MI), + TII->get(AMDGPU::POP)) .addImm(CfCount + 1) .addImm(1); + DEBUG(dbgs() << CfCount << ":"; MIb->dump();); MI->eraseFromParent(); CfCount++; break; @@ -229,7 +230,7 @@ public: case AMDGPU::CONTINUE: { MachineInstr *MIb = BuildMI(MBB, MI, MBB.findDebugLoc(MI), TII->get(AMDGPU::CF_CONTINUE)) - .addImm(CfCount); + .addImm(0); LoopStack.back().second.insert(MIb); MI->eraseFromParent(); CfCount++;