[Beignet] [PATCH 06/18] Backend: Add the debug info to IF ELSE instructions.
junyan.he at inbox.com
junyan.he at inbox.com
Thu Dec 24 03:01:58 PST 2015
From: Junyan He <junyan.he at linux.intel.com>
Signed-off-by: Junyan He <junyan.he at linux.intel.com>
---
backend/src/ir/structurizer.cpp | 55 +++++++++++++++++++++++++++++------------
backend/src/ir/structurizer.hpp | 6 ++---
2 files changed, 42 insertions(+), 19 deletions(-)
diff --git a/backend/src/ir/structurizer.cpp b/backend/src/ir/structurizer.cpp
index 749cb94..8208734 100644
--- a/backend/src/ir/structurizer.cpp
+++ b/backend/src/ir/structurizer.cpp
@@ -112,25 +112,29 @@ namespace ir {
}
}
+ static DebugInfo getIfDBGInfo(Block *ifblock) {
+ BasicBlock *pbb = ifblock->getExit();
+ BranchInstruction* pinsn = static_cast<BranchInstruction *>(pbb->getLastInstruction());
+ return pinsn->DBGInfo;
+ }
+
void CFGStructurizer::handleIfBlock(Block *block, LabelIndex& matchingEndifLabel, LabelIndex& matchingElseLabel)
{
BasicBlock *pbb = block->getExit();
BranchInstruction* pinsn = static_cast<BranchInstruction *>(pbb->getLastInstruction());
Register reg = pinsn->getPredicateIndex();
- BasicBlock::iterator it = pbb->end();
- it--;
/* since this block is an if block, so we remove the BRA instruction at the bottom of the exit BB of 'block',
* and insert IF instead
*/
- it->remove();
Instruction insn = IF(matchingElseLabel, reg, block->inversePredicate);
Instruction* p_new_insn = pbb->getParent().newInstruction(insn);
- pbb->append(*p_new_insn);
+ p_new_insn->DBGInfo = pinsn->DBGInfo;
+ p_new_insn->replace(pinsn);
pbb->matchingEndifLabel = matchingEndifLabel;
pbb->matchingElseLabel = matchingElseLabel;
}
- void CFGStructurizer::handleThenBlock(Block * block, LabelIndex& endiflabel)
+ void CFGStructurizer::handleThenBlock(Block * block, LabelIndex& endiflabel, DebugInfo dbgInfo)
{
BasicBlock *pbb = block->getExit();
BasicBlock::iterator it = pbb->end();
@@ -142,6 +146,7 @@ namespace ir {
Instruction insn = ENDIF(endiflabel);
Instruction* p_new_insn = pbb->getParent().newInstruction(insn);
+ p_new_insn->DBGInfo = dbgInfo;
// we need to insert ENDIF before the BRA(if exists).
bool append_bra = false;
if((*it).getOpcode() == OP_BRA)
@@ -154,13 +159,15 @@ namespace ir {
pbb->append(*p_last_insn);
}
- void CFGStructurizer::handleThenBlock2(Block *block, Block *elseblock, LabelIndex elseBBLabel)
+ void CFGStructurizer::handleThenBlock2(Block *block,
+ Block *elseblock, LabelIndex elseBBLabel, DebugInfo dbgInfo)
{
BasicBlock *pbb = block->getExit();
BasicBlock::iterator it = pbb->end();
it--;
- if((*it).getOpcode() == OP_BRA)
+ if((*it).getOpcode() == OP_BRA) {
it->remove();
+ }
if(block->getExit()->getNextBlock() == elseblock->getEntry())
return;
@@ -168,13 +175,15 @@ namespace ir {
// Add an unconditional jump to 'else' block
Instruction insn = BRA(elseBBLabel);
Instruction* p_new_insn = pbb->getParent().newInstruction(insn);
+ p_new_insn->DBGInfo = dbgInfo;
pbb->append(*p_new_insn);
}
- void CFGStructurizer::handleElseBlock(Block * block, LabelIndex& elselabel, LabelIndex& endiflabel)
+ void CFGStructurizer::handleElseBlock(Block * block,
+ LabelIndex& elselabel, LabelIndex& endiflabel, DebugInfo dbgInfo)
{
// to insert ENDIF properly
- handleThenBlock(block, endiflabel);
+ handleThenBlock(block, endiflabel, dbgInfo);
BasicBlock *pbb = block->getEntry();
BasicBlock::iterator it = pbb->begin();
@@ -186,6 +195,7 @@ namespace ir {
// insert ELSE properly
Instruction insn = ELSE(endiflabel);
Instruction* p_new_insn = pbb->getParent().newInstruction(insn);
+ p_new_insn->DBGInfo = dbgInfo;
pbb->insertAt(it, *p_new_insn);
}
@@ -321,7 +331,8 @@ namespace ir {
{
BasicBlock::iterator it= bbs[i]->end();
it--;
- it->remove();
+
+ bbs[i]->erase(it);
if (bbs[i]->hasExtraBra)
bbs[i]->hasExtraBra = false;
@@ -345,10 +356,16 @@ namespace ir {
{
BlockList::iterator child_iter = (*it)->children.end();
LabelIndex endiflabel;
+ BlockList::iterator then_block;
+ BlockList::iterator if_block;
+
child_iter--;
- handleThenBlock(*child_iter, endiflabel); // this call would pass out the proper endiflabel for handleIfBlock's use.
+ then_block = child_iter;
child_iter--;
- handleIfBlock(*child_iter, endiflabel, endiflabel);
+ if_block = child_iter;
+ DebugInfo dbgInfo = getIfDBGInfo(*if_block);
+ handleThenBlock(*then_block, endiflabel, dbgInfo); // this call would pass out the proper endiflabel for handleIfBlock's use.
+ handleIfBlock(*if_block, endiflabel, endiflabel);
}
break;
@@ -357,15 +374,21 @@ namespace ir {
BlockList::iterator child_iter = (*it)->children.end();
LabelIndex endiflabel;
LabelIndex elselabel;
+ BlockList::iterator then_block;
+ BlockList::iterator if_block;
BlockList::iterator else_block;
child_iter--;
else_block= child_iter;
- handleElseBlock(*child_iter, elselabel, endiflabel);
- LabelIndex elseBBLabel = (*child_iter)->getEntry()->getLabelIndex();
child_iter--;
- handleThenBlock2(*child_iter, *else_block, elseBBLabel);
+ then_block= child_iter;
child_iter--;
- handleIfBlock(*child_iter, endiflabel, elselabel);
+ if_block= child_iter;
+ DebugInfo dbgInfo = getIfDBGInfo(*if_block);
+
+ handleElseBlock(*else_block, elselabel, endiflabel, dbgInfo);
+ LabelIndex elseBBLabel = (*child_iter)->getEntry()->getLabelIndex();
+ handleThenBlock2(*then_block, *else_block, elseBBLabel, dbgInfo);
+ handleIfBlock(*if_block, endiflabel, elselabel);
}
break;
diff --git a/backend/src/ir/structurizer.hpp b/backend/src/ir/structurizer.hpp
index 09b2a7f..0c7f944 100644
--- a/backend/src/ir/structurizer.hpp
+++ b/backend/src/ir/structurizer.hpp
@@ -220,9 +220,9 @@ namespace ir {
void markNeedEndif(Block *block, bool status);
void markStructuredBlocks(Block *block, bool status);
void handleIfBlock(Block *block, LabelIndex& matchingEndifLabel, LabelIndex& matchingElseLabel);
- void handleThenBlock(Block * block, LabelIndex& endiflabel);
- void handleThenBlock2(Block *block, Block *elseblock, LabelIndex elseBBLabel);
- void handleElseBlock(Block * block, LabelIndex& elselabel, LabelIndex& endiflabel);
+ void handleThenBlock(Block * block, LabelIndex& endiflabel, DebugInfo dbgInfo);
+ void handleThenBlock2(Block *block, Block *elseblock, LabelIndex elseBBLabel, DebugInfo dbgInfo);
+ void handleElseBlock(Block * block, LabelIndex& elselabel, LabelIndex& endiflabel, DebugInfo dbgInfo);
void handleStructuredBlocks();
void getStructureSequence(Block *block, std::vector<BasicBlock*> &seq);
std::set<int> getStructureBasicBlocksIndex(Block* block, std::vector<BasicBlock *> &bbs);
--
1.9.1
More information about the Beignet
mailing list