63 ProgramPass(data), codeGenerator_(NULL), irm_(NULL),
64 diamonds_(0), diamonds2_(0), triangles1_(0), triangles2_(0),
65 grAborts_(0), grDefAborts_(0), grUseAborts_(0),
66 loopAborts_(0), uncondAborts_(0) , sizeAborts_(0), succAborts_(0),
67 diamondSizeLimit_(-1), triangleSizeLimit1_(-1),
68 triangleSizeLimit2_(-1) {
89 float diamondOperations =
91 pow((ma.
fuILP()*2), -2) +
113 <<
"if-conversion thresholds:" << std::endl
126 return std::string(
"Simple if converter");
154 if (bblocks == NULL) {
164 "Converted: " << std::endl <<
165 "\tDiamonds: " <<
diamonds_ << std::endl <<
166 "\tDiamonds(2): " <<
diamonds2_ << std::endl <<
170 "Aborts: " << std::endl <<
176 "\tSucc unknown aborts: " <<
succAborts_ << std::endl;
235 for (
int i = 0; i < cfg.
nodeCount(); i++) {
244 std::pair<BasicBlockNode*,BasicBlockNode*> nodes =
250 if (fallThruNode == NULL || jumpDestNode == NULL ||
291 if (candidates == NULL) {
303 jumpMove = &jumpIns->
move(0);
330 if (rg == NULL || candidates->
invg_ == NULL) {
343 *candidates->
grFile_, lastToConvert)) {
370 *candidates->
grFile_, lastToConvert)) {
385 for (
auto o: outEdges) {
386 if (!o->isJumpEdge() &&
439 for (ControlFlowGraph::EdgeSet::iterator i = outEdges.begin();
440 i != outEdges.end(); i++) {
449 (*i)->edgePredicate(), eType);
524 bool isLastUncondJump =
false;
527 for (
int i = 0; i < last.
moveCount(); i++) {
530 isLastUncondJump =
true;
553 for (
int i = 0; i < ins.
moveCount(); i++) {
564 std::map<ProgramOperationPtr,ProgramOperationPtr>& poMapping) {
570 std::map<ProgramOperationPtr,ProgramOperationPtr>::iterator i =
573 if (i == poMapping.end()) {
577 poMapping[po] = newPO;
591 std::map<ProgramOperationPtr,ProgramOperationPtr> poMapping;
597 for (
int i = 0; i < ins.
moveCount(); i++) {
599 if (!(move.
isJump() && removeJumps)) {
600 auto moveCopy = move.
copy();
601 if (moveCopy->source().isFUPort()) {
609 newPO->addOutputNode(*mn);
613 if (moveCopy->destination().isFUPort()) {
616 moveCopy->destination()),
620 newPO->addInputNode(*mn);
625 if (!moveCopy->isReturn() && mg != NULL) {
626 moveCopy->setGuard(mg->
copy());
646 bool ignoreLastInstruction) {
649 int iCount = ignoreLastInstruction ?
652 for (
int i = 0; i < iCount; i++) {
655 for (
int j = 0; j < ins.
moveCount(); j++) {
727 std::pair<BasicBlockNode*,BasicBlockNode*>
731 if (succs.size() == 1) {
732 return std::pair<BasicBlockNode*,BasicBlockNode*>(*succs.begin(),NULL);
734 if (succs.size() != 2) {
736 <<
"Warning: Successor cound of node: " << node.
toString()
737 <<
" is: " << succs.size() << std::endl;
738 cfg.
writeToDotFile(
"IfConverterInvalidNumberOfSuccessors_cfg.dot");
742 return std::pair<BasicBlockNode*,BasicBlockNode*>(NULL,NULL);
745 assert(succs.size() == 2);
751 if (!jumpMove->
isJump()) {
752 return std::pair<BasicBlockNode*,BasicBlockNode*>(NULL,NULL);
757 if (jumpIns == NULL ||
760 return std::pair<BasicBlockNode*,BasicBlockNode*>(NULL,NULL);
762 jumpMove = &jumpIns->
move(0);
765 return std::pair<BasicBlockNode*,BasicBlockNode*>(NULL,NULL);
770 return std::pair<BasicBlockNode*,BasicBlockNode*>(
774 return std::pair<BasicBlockNode*,BasicBlockNode*>(
799 &jdSucc != &ftSucc ||
805 if (&jdSucc == &bbn) {
818 bool keepFt = (cfg.
inDegree(fallThruNode) != 1);
819 bool keepJd = (cfg.
inDegree(jumpDestNode) != 1);
822 if (keepFt || keepJd) {
829 bbn, fallThruNode, jumpDestNode,
830 jumpDestNode, NULL, &jdSucc, NULL,
831 false, !keepFt, !keepJd);
835 std::pair<BasicBlockNode*,BasicBlockNode*> succ =
838 if (succ.first == NULL) {
843 bool keepJoin = (keepJd | keepFt) || cfg.
inDegree(jdSucc) > 2 ||
853 for (ControlFlowGraph::EdgeSet::iterator i = joinOutEdges.begin();
854 i != joinOutEdges.end(); i++) {
860 bbn, fallThruNode, jumpDestNode, jumpDestNode,
861 NULL, &jdSucc, NULL,
false, !keepFt, !keepJd);
867 bbn, fallThruNode, jumpDestNode, jdSucc, &jdSucc,
868 succ.first, succ.second, !keepJoin, !keepFt, !keepJd);
884 if (&jdSucc != &fallThruNode || jdse.
isBackEdge()) {
889 std::pair<BasicBlockNode*,BasicBlockNode*> succ =
892 bool keepJd = (cfg.
inDegree(jumpDestNode) != 1);
893 bool keepFt = keepJd|(cfg.
inDegree(fallThruNode) > 2);
897 if (keepFt || keepJd) {
902 if ((succ.first != NULL && succ.first->nodeID() < bbn.
nodeID()) ||
903 (succ.second != NULL && succ.second->nodeID() < bbn.
nodeID())) {
916 if (succ.first == NULL) {
918 bbn, fallThruNode, jumpDestNode, fallThruNode,
919 NULL, succ.first, succ.second, !keepFt,
923 bbn, fallThruNode, jumpDestNode, fallThruNode,
924 &fallThruNode, succ.first, succ.second, !keepFt,
943 &cfg.
headNode(e) != &jumpDestNode) {
948 std::pair<BasicBlockNode*,BasicBlockNode*> succ =
951 bool keepFt = (cfg.
inDegree(fallThruNode) != 1);
952 bool keepJd = keepFt|(cfg.
inDegree(jumpDestNode) > 2);
972 bbn, fallThruNode, jumpDestNode, fallThruNode, NULL,
973 &jumpDestNode, NULL,
false,
true,
false);
976 if ((succ.first != NULL && succ.first->nodeID() < bbn.
nodeID()) ||
977 (succ.second != NULL && succ.second->nodeID() < bbn.
nodeID())) {
981 if (succ.first == NULL) {
984 bbn, fallThruNode, jumpDestNode, jumpDestNode,
985 NULL, succ.first, succ.second, !keepJd,
990 bbn, fallThruNode, jumpDestNode, jumpDestNode,
991 &jumpDestNode, succ.first, succ.second, !keepJd,
1020 bool removeJoin,
bool removeFT,
bool removeJd) :
1021 firstNode_(firstNode), fallThruNode_(fallThruNode),
1022 jumpDestNode_(jumpDestNode), lastNode_(lastNode),
1023 joinNode_(joinNode), succNode1_(succNode1),
1024 succNode2_(succNode2),
1025 firstBB_(firstNode.basicBlock()), fallThruBB_(fallThruNode.basicBlock()),
1026 jumpDestBB_(jumpDestNode.basicBlock()),
1027 lastBB_(lastNode.basicBlock()),
1028 joinBB_(joinNode == NULL ? NULL : &joinNode->basicBlock()),
1029 removeJoin_(removeJoin), removeFt_(removeFT), removeJd_(removeJd),
1031 guard_(NULL), invg_(NULL), grIndex_(-1), grFile_(NULL) {}
1038 if (guard_ != NULL) {
1041 if (invg_ != NULL) {