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
This commit is contained in:
Vincent Lejeune 2013-04-03 16:24:09 +00:00
parent 795ecc3669
commit 375d767b54

View File

@ -12,6 +12,10 @@
/// computing their address on the fly ; it also sets STACK_SIZE info. /// 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 "AMDGPU.h"
#include "R600Defines.h" #include "R600Defines.h"
#include "R600InstrInfo.h" #include "R600InstrInfo.h"
@ -87,14 +91,7 @@ private:
return I; return I;
} }
void CounterPropagateAddr(MachineInstr *MI, unsigned Addr) const { void CounterPropagateAddr(MachineInstr *MI, unsigned Addr) const {
switch (MI->getOpcode()) { MI->getOperand(0).setImm(Addr + MI->getOperand(0).getImm());
case AMDGPU::WHILE_LOOP:
MI->getOperand(0).setImm(Addr + 1);
break;
default:
MI->getOperand(0).setImm(Addr);
break;
}
} }
void CounterPropagateAddr(std::set<MachineInstr *> MIs, unsigned Addr) void CounterPropagateAddr(std::set<MachineInstr *> MIs, unsigned Addr)
const { const {
@ -123,7 +120,7 @@ public:
MachineBasicBlock &MBB = *MB; MachineBasicBlock &MBB = *MB;
unsigned CfCount = 0; unsigned CfCount = 0;
std::vector<std::pair<unsigned, std::set<MachineInstr *> > > LoopStack; std::vector<std::pair<unsigned, std::set<MachineInstr *> > > LoopStack;
std::vector<std::pair<unsigned, MachineInstr *> > IfThenElseStack; std::vector<MachineInstr * > IfThenElseStack;
R600MachineFunctionInfo *MFI = MF.getInfo<R600MachineFunctionInfo>(); R600MachineFunctionInfo *MFI = MF.getInfo<R600MachineFunctionInfo>();
if (MFI->ShaderType == 1) { if (MFI->ShaderType == 1) {
BuildMI(MBB, MBB.begin(), MBB.findDebugLoc(MBB.begin()), BuildMI(MBB, MBB.begin(), MBB.findDebugLoc(MBB.begin()),
@ -133,6 +130,7 @@ public:
for (MachineBasicBlock::iterator I = MBB.begin(), E = MBB.end(); for (MachineBasicBlock::iterator I = MBB.begin(), E = MBB.end();
I != E;) { I != E;) {
if (isFetch(I)) { if (isFetch(I)) {
DEBUG(dbgs() << CfCount << ":"; I->dump(););
I = MakeFetchClause(MBB, I, 0); I = MakeFetchClause(MBB, I, 0);
CfCount++; CfCount++;
continue; continue;
@ -145,6 +143,7 @@ public:
CurrentStack++; CurrentStack++;
MaxStack = std::max(MaxStack, CurrentStack); MaxStack = std::max(MaxStack, CurrentStack);
case AMDGPU::CF_ALU: case AMDGPU::CF_ALU:
DEBUG(dbgs() << CfCount << ":"; MI->dump(););
CfCount++; CfCount++;
break; break;
case AMDGPU::WHILELOOP: { case AMDGPU::WHILELOOP: {
@ -152,7 +151,7 @@ public:
MaxStack = std::max(MaxStack, CurrentStack); MaxStack = std::max(MaxStack, CurrentStack);
MachineInstr *MIb = BuildMI(MBB, MI, MBB.findDebugLoc(MI), MachineInstr *MIb = BuildMI(MBB, MI, MBB.findDebugLoc(MI),
TII->get(AMDGPU::WHILE_LOOP)) TII->get(AMDGPU::WHILE_LOOP))
.addImm(0); .addImm(2);
std::pair<unsigned, std::set<MachineInstr *> > Pair(CfCount, std::pair<unsigned, std::set<MachineInstr *> > Pair(CfCount,
std::set<MachineInstr *>()); std::set<MachineInstr *>());
Pair.second.insert(MIb); Pair.second.insert(MIb);
@ -178,34 +177,36 @@ public:
TII->get(AMDGPU::CF_JUMP)) TII->get(AMDGPU::CF_JUMP))
.addImm(0) .addImm(0)
.addImm(0); .addImm(0);
std::pair<unsigned, MachineInstr *> Pair(CfCount, MIb); IfThenElseStack.push_back(MIb);
IfThenElseStack.push_back(Pair); DEBUG(dbgs() << CfCount << ":"; MIb->dump(););
MI->eraseFromParent(); MI->eraseFromParent();
CfCount++; CfCount++;
break; break;
} }
case AMDGPU::ELSE: { case AMDGPU::ELSE: {
std::pair<unsigned, MachineInstr *> Pair = IfThenElseStack.back(); MachineInstr * JumpInst = IfThenElseStack.back();
IfThenElseStack.pop_back(); IfThenElseStack.pop_back();
CounterPropagateAddr(Pair.second, CfCount); CounterPropagateAddr(JumpInst, CfCount);
MachineInstr *MIb = BuildMI(MBB, MI, MBB.findDebugLoc(MI), MachineInstr *MIb = BuildMI(MBB, MI, MBB.findDebugLoc(MI),
TII->get(AMDGPU::CF_ELSE)) TII->get(AMDGPU::CF_ELSE))
.addImm(0) .addImm(0)
.addImm(1); .addImm(1);
std::pair<unsigned, MachineInstr *> NewPair(CfCount, MIb); DEBUG(dbgs() << CfCount << ":"; MIb->dump(););
IfThenElseStack.push_back(NewPair); IfThenElseStack.push_back(MIb);
MI->eraseFromParent(); MI->eraseFromParent();
CfCount++; CfCount++;
break; break;
} }
case AMDGPU::ENDIF: { case AMDGPU::ENDIF: {
CurrentStack--; CurrentStack--;
std::pair<unsigned, MachineInstr *> Pair = IfThenElseStack.back(); MachineInstr *IfOrElseInst = IfThenElseStack.back();
IfThenElseStack.pop_back(); IfThenElseStack.pop_back();
CounterPropagateAddr(Pair.second, CfCount + 1); CounterPropagateAddr(IfOrElseInst, CfCount);
BuildMI(MBB, MI, MBB.findDebugLoc(MI), TII->get(AMDGPU::POP)) MachineInstr *MIb = BuildMI(MBB, MI, MBB.findDebugLoc(MI),
TII->get(AMDGPU::POP))
.addImm(CfCount + 1) .addImm(CfCount + 1)
.addImm(1); .addImm(1);
DEBUG(dbgs() << CfCount << ":"; MIb->dump(););
MI->eraseFromParent(); MI->eraseFromParent();
CfCount++; CfCount++;
break; break;
@ -229,7 +230,7 @@ public:
case AMDGPU::CONTINUE: { case AMDGPU::CONTINUE: {
MachineInstr *MIb = BuildMI(MBB, MI, MBB.findDebugLoc(MI), MachineInstr *MIb = BuildMI(MBB, MI, MBB.findDebugLoc(MI),
TII->get(AMDGPU::CF_CONTINUE)) TII->get(AMDGPU::CF_CONTINUE))
.addImm(CfCount); .addImm(0);
LoopStack.back().second.insert(MIb); LoopStack.back().second.insert(MIb);
MI->eraseFromParent(); MI->eraseFromParent();
CfCount++; CfCount++;