iter++;
}
}
+ void ControlTree::handleSelfLoopNode(Node *loopnode, ir::LabelIndex& whileLabel)
+ {
+ ir::BasicBlock *pbb = loopnode->getExit();
+ ir::BranchInstruction* pinsn = static_cast<ir::BranchInstruction *>(pbb->getLastInstruction());
+ ir::Register reg = pinsn->getPredicateIndex();
+ ir::BasicBlock::iterator it = pbb->end();
+ it--;
+ /* since this node is an while node, so we remove the BRA instruction at the bottom of the exit BB of 'node',
+ * and insert WHILE instead
+ */
+ pbb->erase(it);
+ whileLabel = pinsn->getLabelIndex();
+ ir::Instruction insn = ir::WHILE(whileLabel, reg);
+ ir::Instruction* p_new_insn = pbb->getParent().newInstruction(insn);
+ pbb->append(*p_new_insn);
+ pbb->whileLabel = whileLabel;
+ }
/* recursive mark the bbs' variable needEndif, the bbs all belong to node.*/
void ControlTree::markNeedIf(Node *node, bool status)
* structures */
while(rit != nodes.rend())
{
- if((*rit)->type() == IfThen || (*rit)->type() == IfElse)
+ if((*rit)->type() == IfThen || (*rit)->type() == IfElse|| (*rit)->type() == SelfLoop)
{
if(false == (*rit)->mark && (*rit)->canBeHandled)
{
*/
while(rit != nodes.rend())
{
- if(((*rit)->type() == IfThen || (*rit)->type() == IfElse || (*rit)->type() == Block) &&
+ if(((*rit)->type() == IfThen || (*rit)->type() == IfElse || (*rit)->type() == Block ||(*rit)->type() == SelfLoop) &&
(*rit)->canBeHandled && (*rit)->mark == true)
{
markStructuredNodes(*rit, false);
std::set<int> ns = getStructureBasicBlocksIndex(*rit, bbs);
- ir::BasicBlock *entry = (*it)->getEntry();
+ ir::BasicBlock *entry = (*rit)->getEntry();
int entryIndex = *(ns.begin());
for(size_t i=0; i<bbs.size(); ++i)
}
break;
+ case SelfLoop:
+ {
+ NodeList::iterator child_iter = (*it)->children.begin();
+ ir::LabelIndex whilelabel;
+ handleSelfLoopNode(*child_iter, whilelabel);
+ }
+ break;
+
default:
break;
}
* ignore the identification of cyclic regions. */
Node * ControlTree::cyclicRegionType(Node *node, NodeList &nset)
{
-#if 0
/* check for self-loop */
if(nset.size() == 1)
{
return insertNode(p);
}
}
-#endif
return NULL;
}
if(nset.find(entry) != nset.end())
entry = region;
}
+ // FIXME loop optimization is still buggy and under development, now disable it by default.
else
{
- /* We now only deal with acyclic regions at this moment. */
#if 0
reachUnder.clear();
nset.clear();
}
else
{
-#endif
post_ctr++;
- // }
+ }
+#else
+ post_ctr++;
+#endif
}
}
}
};
-#if 0
/* Self loop structure node */
class SelfLoopNode : public Node
{
return NULL;
}
};
-#endif
/* computes the control tree, and do the structure identification during the computation */
class ControlTree
bool pathBack(Node*, Node*);
/* check if there is a barrier in a basic block */
bool checkForBarrier(const ir::BasicBlock*);
+ /* insert while instruction at the proper position of Node */
+ void handleSelfLoopNode(Node *, ir::LabelIndex&);
/* mark all the BasicBlockNodes of the control tree node n as status */
void markStructuredNodes(Node *n, bool status);
/* mark all the ir::BasicBlocks' needEndIf of n as status */