79 std::set<TCEString> allParamRegs,
84 allParamRegs_(allParamRegs), cycleGrouping_(true),
85 dotProgramOperationNodes_(
false),
86 machine_(NULL), delaySlots_(0), rrCost_(3), ownedBBN_(ownedBBN),
87 procedureDDG_(containsProcedure),
88 registerAntidependenceLevel_(antidependenceLevel),
89 edgeWeightHeuristics_(EWH_HEURISTIC) {
101 for (
int i = 0; i < nc; i++) {
102 delete &
node(i,
false);
128 for (
unsigned int i = 0; i <
childGraphs_.size(); i++) {
187 std::map<const MoveNode*, BasicBlockNode*>::const_iterator iter =
190 TCEString msg =
"MoveNode not in DDG!: ";
194 return *iter->second;
205 std::map<const MoveNode*, BasicBlockNode*>::iterator iter =
208 TCEString msg =
"MoveNode not in DDG!: ";
212 return *iter->second;
258 for (
int i = 0; i <
inDegree(mn); i++) {
261 if (result == NULL) {
279 for (
int i = 0; i <
outDegree(mn); i++) {
282 if (result == NULL) {
389 const MoveNode& moveNode,
unsigned int ii,
bool ignoreRegWaRs,
390 bool ignoreRegWaWs,
bool ignoreGuards,
bool ignoreFuDeps,
391 bool ignoreSameOperationEdges,
bool assumeBypassing)
const {
395 " setMachine() must be called before this");
399 for (EdgeSet::const_iterator i = edges.begin(); i != edges.end(); ++i) {
412 if (ignoreSameOperationEdges &&
418 if (&tail == &moveNode) {
431 int effTailCycle = tail.
cycle();
456 if (assumeBypassing) {
482 effTailCycle = effTailCycle - latency + 1;
490 effTailCycle += latency;
496 "ii should not be 0 if we have an loop edge");
499 minCycle = std::max(effTailCycle, minCycle);
510 if (trigger ==
nullptr || trigger == &moveNode) {
544 const MoveNode& moveNode,
unsigned int ii,
bool ignoreRegAntideps,
545 bool ignoreUnscheduledSuccessors,
bool ignoreGuards,
bool ignoreFuDeps,
546 bool ignoreSameOperationEdges)
const {
550 " setMachine() must be called before this");
554 int maxCycle = INT_MAX;
555 for (EdgeSet::const_iterator i = edges.begin();
556 i != edges.end(); ++i) {
568 if (ignoreSameOperationEdges &&
574 if (&head == &moveNode) {
581 int effHeadCycle = head.
cycle();
621 effHeadCycle = effHeadCycle + latency - 1;
636 effHeadCycle -= latency;
642 "ii should not be 0 if we have an loop edge");
645 maxCycle = std::min(effHeadCycle, maxCycle);
648 if (!ignoreUnscheduledSuccessors) {
673 maxCycle = std::min(maxCycle, inputMove.
cycle());
676 maxCycle = std::min(maxCycle, inputMove.
cycle()-1);
683 maxCycle = std::min(maxCycle, inputMove.
cycle()-1);
724 for (NodeSet::iterator i = guardDefs.begin();
725 i != guardDefs.end(); i++) {
726 if (last == NULL || last->
cycle() < (*i)->cycle()) {
747 for (EdgeSet::iterator i = inputEdges.begin();
748 i != inputEdges.end(); i++) {
769 int lastCycleToTest)
const {
787 if (&rf == currentRF &&
788 source.
index() == registerIndex &&
789 n.
cycle() > lastCycle &&
790 n.
cycle() <= lastCycleToTest) {
791 lastCycle = n.
cycle();
810 int registerIndex,
int firstCycleToTest)
const {
812 int firstCycle = INT_MAX;
828 if (&rf == currentRF &&
829 source.
index() == registerIndex &&
830 n.
cycle() < firstCycle &&
831 n.
cycle() >= firstCycleToTest) {
832 firstCycle = n.
cycle();
850 int firstCycle = INT_MAX;
862 if (&rf == currentRF &&
863 destination.
index() == registerIndex &&
864 n.
cycle() < firstCycle) {
865 firstCycle = n.
cycle();
894 bool sourceGPR = source.
isGPR();
896 if (sourceImmReg || sourceGPR) {
903 if (&rf == currentRF && source.
index() == registerIndex) {
907 if (n.
cycle() > lastCycle) {
908 lastCycle = n.
cycle();
915 if (destination.
isGPR()) {
918 if (&rf == currentRF && destination.
index() == registerIndex) {
922 if (n.
cycle() > lastCycle) {
923 lastCycle = n.
cycle();
946 if (n.
cycle() > lastCycle) {
947 lastCycle = n.
cycle();
984 int firstCycle = INT_MAX;
985 for (
int i =
nodeCount()-1; i >= 0; --i) {
993 bool sourceGPR = source.
isGPR();
995 if (sourceImmReg || sourceGPR) {
1002 if (&rf == currentRF && source.
index() == registerIndex) {
1006 if (n.
cycle() < firstCycle) {
1007 firstCycle = n.
cycle();
1014 if (destination.
isGPR()) {
1017 if (&rf == currentRF && destination.
index() == registerIndex) {
1021 if (n.
cycle() < firstCycle) {
1022 firstCycle = n.
cycle();
1045 if (n.
cycle() < firstCycle) {
1046 firstCycle = n.
cycle();
1084 int killCycle = lastKill == NULL ? -1 : lastKill->
cycle();
1089 for (
int i = 0; i < nodeCounter; ++i) {
1103 if (&rf == currentRF &&
1104 source.
index() == registerIndex) {
1105 if (n.
cycle() > killCycle) {
1106 lastReads.insert(&n);
1125 int killCycle = firstKill == NULL ? -1 : firstKill->
cycle();
1143 if (&rf == currentRF &&
1144 source.
index() == registerIndex) {
1145 if (n.
cycle() < killCycle) {
1146 firstReads.insert(&n);
1167 int killCycle = lastKill == NULL ? -1 : lastKill->
cycle();
1172 for (
int i = 0; i < nodeCounter; ++i) {
1186 if (&rf == currentRF &&
1188 if (n.
cycle() > killCycle) {
1189 lastGuards.insert(&n);
1210 int killCycle = lastKill == NULL ? -1 : lastKill->
cycle();
1215 for (
int i = 0; i < nodeCounter; ++i) {
1225 if (&rf == currentRF &&
1226 dest.
index() == registerIndex) {
1227 if (n.
cycle() >= killCycle) {
1228 lastReads.insert(&n);
1251 int killCycle = firstKill == NULL ? INT_MAX : firstKill->
cycle();
1256 for (
int i = 0; i < nodeCounter; ++i) {
1266 if (&rf == currentRF &&
1267 dest.
index() == registerIndex) {
1268 if (n.
cycle() <= killCycle) {
1269 firstWrites.insert(&n);
1291 for (
int i = 0; i < nodeCounter; ++i) {
1301 if (&rf == currentRF &&
1302 dest.
index() == registerIndex &&
1303 n.
cycle() > lastCycle &&
1305 lastCycle = n.
cycle();
1323 int firstCycle = INT_MAX;
1326 for (
int i = 0; i < nodeCounter; ++i) {
1336 if (&rf == currentRF &&
1337 dest.
index() == registerIndex &&
1338 n.
cycle() < firstCycle &&
1340 firstCycle = n.
cycle();
1359 for (
int i = 0; i < nodeCounter; ++i) {
1379 for (
int i = 0; i < nodeCounter; ++i) {
1417 "DEP_UNKNOWN in edge between %s and %s."))
1422 if (tailDestination.
equals(headSource))
1452 if (tailDestination.
isGPR() &&
1461 "DEP_RAW in edge between %s and %s."))
1465 if (headDestination.
equals(tailSource))
1486 tailSource.
isGPR() &&
1504 "DEP_WAR in edge between %s and %s."))
1508 if (headDestination.
equals(tailDestination))
1530 if (tailDestination.
isGPR() &&
1539 "DEP_WAW in edge between %s and %s."))
1546 "Unknown edge type: %d in edge between %s and %s."))
1565 std::ostringstream s;
1566 s <<
"digraph " <<
name() <<
" {" << std::endl;
1570 s <<
"\t{" << std::endl
1571 <<
"\t\tnode [shape=plaintext];" << std::endl
1575 for (
int c = smallest; c <= largest; ++c) {
1576 s <<
"\"cycle " << c <<
"\" -> ";
1578 s <<
"\"cycle " << largest + 1 <<
"\"; "
1579 << std::endl <<
"\t}" << std::endl;
1582 for (
int c = smallest; c <= largest; ++c) {
1584 if (moves.size() > 0) {
1585 s <<
"\t{ rank = same; \"cycle " << c <<
"\"; ";
1586 for (NodeSet::iterator i = moves.begin();
1587 i != moves.end(); ++i) {
1589 s <<
"n" << n.
nodeID() <<
"; ";
1591 s <<
"}" << std::endl;
1612 nodeStr.
replaceString(
"shape=ellipse",
"shape=invtriangle");
1614 s <<
"\tn" << n.
nodeID() <<
" [" << nodeStr <<
"]; " << std::endl;
1617 typedef std::set<ProgramOperation*> POSet;
1621 typedef std::pair<EdgeIter, EdgeIter> EdgeIterPair;
1622 EdgeIterPair edges = boost::edges(
graph_);
1623 for (
EdgeIter i = edges.first; i != edges.second; i++) {
1641 tailNodeId <<
"n" << tail.
nodeID();
1653 headNodeId <<
"n" << head.
nodeID();
1656 if (tailNodeId == headNodeId)
continue;
1658 float weight = 1.0f;
1659 s <<
"\t" << tailNodeId
1660 <<
" -> " << headNodeId <<
"[";
1664 s <<
"color=\"red\", ";
1668 s <<
"constraint=false,";
1682 <<
"\",weight=" << weight <<
"];" << std::endl;
1694 <<
" -> n" << n.
nodeID() <<
"["
1695 <<
"label=\"T\", weight=10.0" <<
"];" << std::endl;
1702 for (POSet::iterator i = programOps.begin();
1703 i != programOps.end(); ++i) {
1720 label <<
"src line: " << lineNo <<
"\\n";
1722 s <<
"\tpo" << po.
poId() <<
" [label=\""
1723 << label <<
"\",shape=box];" << std::endl;
1727 s <<
"}" << std::endl;
1779 typedef std::pair<EdgeIter, EdgeIter> EdgeIterPair;
1780 EdgeIterPair edges = boost::edges(
graph_);
1781 for (
EdgeIter i = edges.first; i != edges.second; i++) {
1820 int minCycle = INT_MAX;
1824 minCycle = std::min(minCycle, n.
cycle());
1844 maxCycle = std::max(maxCycle, n.
cycle());
1861 int scheduledCount = 0;
1868 return scheduledCount;
1887 for (
int i = 0; i <
outDegree(sourceNode); i++) {
1894 if (&target != &userNode &&
hasPath(target, userNode)) {
1901 if (!
hasEdge(sourceNode, userNode)) {
1904 __FILE__,__LINE__,
__func__,
"No edge between nodes being merged "
1910 __FILE__,__LINE__,
__func__,
"Cannot merge entry/exit node!");
1918 sourceNode, userNode);
1920 for (EdgeSet::iterator i = edges.begin();
1921 i != edges.end(); i++ ) {
1942 for (
auto edge: edges) {
1950 if (regName ==
"") {
1951 std::cerr <<
"Missing RAW edge between: " << sourceNode.
toString()
1952 <<
" and " << userNode.
toString() <<
" on removeRawEdges."
1953 <<
" Wrote missing_raw.dot" << std::endl;
1972 bool userIsRegToItselfCopy =
false;
1977 dstOp->addInputNode(sourceNode);
1982 for (
int j = 0; j < userNode.
move().annotationCount(); j++) {
1999 userIsRegToItselfCopy =
true;
2039 for (
int i = 0; i <
inDegree(sourceNode); i++) {
2048 if (!userIsRegToItselfCopy) {
2092 for (
int i = 0; i <
inDegree(sourceNode); i++) {
2103 bool sourceIsRegToItselfCopy =
false;
2107 srcOp->addOutputNode(userNode);
2111 for (
int j = 0; j < sourceNode.
move().annotationCount(); j++) {
2133 sourceIsRegToItselfCopy =
true;
2182 &userNode != &target) {
2201 if (!sourceIsRegToItselfCopy) {
2214 for (
int i = 0; i <
outDegree(mergedNode); i++) {
2225 reg,
false,
false,
false,
false,
false);
2276 for (
int i = 0; i <
inDegree(mergedNode); i++) {
2291 bool nodeRegToItselfCopy =
false;
2293 nodeRegToItselfCopy =
true;
2301 false,
false,
false,
false, loopBypass);
2307 for(
int i = 0; i <
outDegree(mergedNode); i++) {
2321 for (
int i = 0; i <
outDegree(sourceNode); i++) {
2333 nodeRegToItselfCopy);
2362 bool killingWrite =
true;
2364 killingWrite =
false;
2366 bool hasRAW =
false;
2367 bool hasOtherEdge =
false;
2370 EdgeSet::iterator edgeIter = edges.begin();
2371 while (edgeIter != edges.end()) {
2377 if (regCopy != NULL && &head == regCopy) {
2395 if (killingWrite ==
false) {
2400 killingWrite =
true;
2407 hasOtherEdge =
true;
2411 return (!killingWrite || hasRAW || hasOtherEdge );
2432 for (EdgeSet::iterator i = oEdges.begin(); i != oEdges.end(); i++) {
2443 for (EdgeSet::iterator j = iEdges.begin();
2444 j != iEdges.end(); j++) {
2474 createdEdges.insert(
edge);
2504 createdEdges.insert(
edge);
2511 return createdEdges;
2527 for (EdgeSet::iterator i = oEdges2.begin(); i != oEdges2.end(); i++) {
2547 for (EdgeSet::iterator j = iEdges1.begin();
2548 j != iEdges1.end(); j++) {
2588 for (EdgeSet::iterator j = iEdges2.begin();
2589 j != iEdges2.end(); j++) {
2643 if (&tail == &head) {
2644 std::cerr <<
"copydeps over copying edge same node(1)!" << tail.
toString() <<
" edge: " <<
edge->
toString()
2656 for (EdgeSet::iterator j = iEdges1.begin();
2657 j != iEdges1.end(); j++) {
2680 if (&tail == &head) {
2681 std::cerr <<
"copydeps over copying edge same node(2)!" << tail.
toString() <<
" edge: " <<
edge->
toString()
2696 for (EdgeSet::iterator i = oEdges1.begin(); i != oEdges1.end(); i++) {
2708 if (&head == &node2) {
2713 for (EdgeSet::iterator j = iEdges2.begin();
2714 j != iEdges2.end(); j++) {
2745 if (&head == &node2) {
2749 for (EdgeSet::iterator j = iEdges1.begin();
2750 j != iEdges1.end(); j++) {
2795 for (EdgeSet::iterator i = oEdges1.begin(); i != oEdges1.end(); i++) {
2803 if (&head == &node2) {
2810 for (EdgeSet::iterator i = iEdges2.begin(); i != iEdges2.end(); i++) {
2819 if (&tail == &node1) {
2968 int ew = std::max(1, 3 * glat);
3064 int ew = std::max(1, glat);
3123 typedef std::pair<EdgeIter, EdgeIter> EdgeIterPair;
3124 EdgeIterPair edges = boost::edges(
graph_);
3125 for (
EdgeIter i = edges.first; i != edges.second; i++) {
3146 for (
int i = 0; i < fuNav.
count(); i++) {
3150 int latency = hwop->
latency();
3182 std::pair<InEdgeIter, InEdgeIter> edges =
3183 boost::in_edges(nd,
graph_);
3188 for (
InEdgeIter ei = edges.first; ei != edges.second; ei++) {
3234 std::pair<OutEdgeIter, OutEdgeIter> edges =
3235 boost::out_edges(nd,
graph_);
3237 for (
OutEdgeIter ei = edges.first; ei != edges.second; ei++) {
3245 const bool operandMoveOfSameOperation =
3248 const bool resultMoveOfSameOperation =
3251 const bool operandsOfSameOperation =
3254 if (operandMoveOfSameOperation || resultMoveOfSameOperation ||
3255 operandsOfSameOperation) {
3271 std::pair<OutEdgeIter, OutEdgeIter> edges =
3272 boost::out_edges(nd,
graph_);
3274 for (
OutEdgeIter ei = edges.first; ei != edges.second; ei++) {
3305 std::map<TCEString, int>::const_iterator iter =
3308 return iter->second;
3329 typedef GraphTraits::out_edge_iterator outEdgeIter;
3330 std::pair<outEdgeIter, outEdgeIter> edges = boost::out_edges(
3334 for (outEdgeIter ei = edges.first; ei != edges.second; ei++) {
3335 if (boost::target(*ei,
graph_) == hnd) {
3378 NodeSet& nodes,
bool includeLoops) {
3390 typedef std::set<ProgramOperationPtr, ProgramOperationPtrComparator> POSet;
3395 for (
int i = 0, nc = subGraph->
nodeCount(); i < nc; i++) {
3407 for (
auto i: subgraphPOs) {
3418 bool removeMemAntideps,
bool ignoreMemDeps) {
3422 NULL,
false,
false);
3425 nodes.insert(&
node(i));
3434 for (
int e = 0; e < subGraph->
outDegree(tail);) {
3470 nodes.insert(&
node(i));
3497 for (EdgeSet::iterator ei = outEdg.begin(); ei != outEdg.end(); ei++) {
3500 nodes.insert(&
node(i));
3506 if (found)
continue;
3508 for (EdgeSet::iterator ei = inEdg.begin(); ei != inEdg.end(); ei++) {
3511 nodes.insert(&
node(i));
3536 for (
int i = 0; i < nc; i++) {
3543 if (&parentIns.
parent() == &cs) {
3544 moveNodes.insert(&mn);
3564 std::list<TTAProgram::CodeSnippet*>& codeSnippets,
bool includeLoops) {
3568 for (
int i = 0; i < nc; i++) {
3574 for (std::list<TTAProgram::CodeSnippet*>::iterator iter =
3575 codeSnippets.begin();
3576 iter != codeSnippets.end(); iter++) {
3579 moveNodes.insert(&mn);
3604 return *(i->second);
3624 for (
int n = 0; n < nc; n++) {
3630 std::pair<OutEdgeIter, OutEdgeIter> edges =
3631 boost::out_edges(nd,
graph_);
3633 for (
OutEdgeIter ei = edges.first; ei != edges.second;) {
3637 boost::remove_edge(*ei,
graph_);
3640 edges = boost::out_edges(nd,
graph_);
3644 DataDependenceGraph::EdgeDescMap::iterator
3650 for (
unsigned int i = 0; i <
childGraphs_.size(); i++) {
3691 std::map<TCEString, TTAProgram::Move*> firstWrites2;
3692 std::map<TCEString, TTAProgram::Move*> lastReads1;
3693 std::map<TCEString, TTAProgram::Move*> lastWrites1;
3694 std::map<TCEString, TTAProgram::Move*> lastGuards1;
3702 for (
int j2 = 0; j2 < ins.
moveCount(); j2++) {
3708 std::map<TCEString, TTAProgram::Move*>::iterator iter2 =
3709 firstWrites2.find(reg2);
3710 if (iter2 == firstWrites2.end()) {
3711 firstWrites2[reg2] = &move;
3720 for (
int j1 = 0; j1 < ins.
moveCount(); j1++) {
3728 std::map<TCEString, TTAProgram::Move*>::iterator iter1 =
3729 lastWrites1.find(reg1);
3730 if (iter1 == lastWrites1.end()) {
3731 lastWrites1[reg1] = &move;
3738 std::map<TCEString, TTAProgram::Move*>::iterator iter1 =
3739 lastReads1.find(reg1);
3740 if (iter1 == lastReads1.end()) {
3741 lastReads1[reg1] = &move;
3753 std::map<TCEString, TTAProgram::Move*>::iterator iter2 =
3754 lastGuards1.find(reg1);
3755 if (iter2 == lastGuards1.end()) {
3756 lastGuards1[reg1] = &move;
3764 for (std::map<TCEString, TTAProgram::Move*>::iterator iter2 =
3765 firstWrites2.begin();
3766 iter2 != firstWrites2.end(); iter2++) {
3772 if (move1 != NULL) {
3782 move1 = lastWrites1[reg2];
3783 if (move1 != NULL) {
3793 move1 = lastGuards1[reg2];
3794 if (move1 != NULL) {
3818 bool moveOverLoopEdge) {
3825 std::pair<InEdgeIter, InEdgeIter> iEdges =
3826 boost::in_edges(nd,
graph_);
3828 for (
InEdgeIter ii = iEdges.first; ii != iEdges.second; ii++) {
3837 *
edge, (moveOverLoopEdge && tail != &src && tail != &dst));
3841 std::pair<OutEdgeIter, OutEdgeIter> oEdges =
3842 boost::out_edges(nd,
graph_);
3844 for (
OutEdgeIter oi = oEdges.first; oi != oEdges.second; oi++) {
3853 *
edge, (moveOverLoopEdge && head != &src && head != &dst));
3874 std::pair<InEdgeIter, InEdgeIter> iEdges =
3875 boost::in_edges(nd,
graph_);
3877 for (
InEdgeIter ii = iEdges.first; ii != iEdges.second; ii++) {
3906 std::pair<OutEdgeIter, OutEdgeIter> oEdges =
3907 boost::out_edges(nd,
graph_);
3909 for (
OutEdgeIter oi = oEdges.first; oi != oEdges.second; oi++) {
3933 for (EdgeSet::iterator iter =
3934 oEdges.begin(); iter != oEdges.end(); iter++) {
3953 const MoveNode& mn,
bool onlyScheduled) {
3956 for (EdgeSet::iterator iter =
3957 oEdges.begin(); iter != oEdges.end(); iter++) {
3961 if (!onlyScheduled || mn.
isPlaced()) {
3980 for (EdgeSet::iterator iter =
3981 oEdges.begin(); iter != oEdges.end(); iter++) {
4004 for (EdgeSet::iterator iter =
4005 iEdges.begin(); iter != iEdges.end(); iter++) {
4029 for (DataDependenceGraph::EdgeSet::iterator i = iEdges.begin();
4030 i != iEdges.end(); i++) {
4034 if (guard == NULL) {
4037 if (!(*guard == *iEdge) ||
4051 for (DataDependenceGraph::EdgeSet::iterator i = iEdges.begin();
4052 i != iEdges.end(); i++) {
4084 const MoveNode& mn,
int guardEdges,
int backEdges)
4092 std::pair<InEdgeIter, InEdgeIter> edges =
4093 boost::in_edges(nd,
graph_);
4095 for (
InEdgeIter ei = edges.first; ei != edges.second; ei++) {
4105 if (source == NULL) {
4123 std::map<DataDependenceEdge*, MoveNode*, DataDependenceEdge::Comparator>
4125 const MoveNode& mn,
bool allowBackEdges)
const {
4126 std::map<DataDependenceEdge*, MoveNode*, DataDependenceEdge::Comparator>
4133 std::pair<OutEdgeIter, OutEdgeIter> edges =
4134 boost::out_edges(nd,
graph_);
4136 for (
OutEdgeIter ei = edges.first; ei != edges.second; ei++) {
4143 destination.insert(std::make_pair(
edge,
graph_[boost::target(ed,
graph_)]));
4145 destination.clear();
4164 const MoveNode& mn,
bool allowGuardEdges,
bool allowBackEdges)
const {
4171 std::pair<OutEdgeIter, OutEdgeIter> edges =
4172 boost::out_edges(nd,
graph_);
4174 for (
OutEdgeIter ei = edges.first; ei != edges.second; ei++) {
4184 destination.clear();
4204 const MoveNode& mn,
const std::string& sp)
const {
4245 typedef EdgeSet::iterator EdgeIterator;
4247 for (EdgeIterator i = out.begin(); i != out.end(); ++i) {
4278 typedef EdgeSet::iterator EdgeIterator;
4280 for (EdgeIterator i = out.begin(); i != out.end(); ++i) {
4316 typedef EdgeSet::iterator EdgeIterator;
4318 for (EdgeIterator i = in.begin(); i != in.end(); ++i) {
4322 }
else if (backedges == 2 && e.
isBackEdge()) {
4353 typedef EdgeSet::iterator EdgeIterator;
4355 for (EdgeIterator i = out.begin(); i != out.end(); ++i) {
4384 typedef std::map<int, NodeSet >
4386 MovesByCycles movesInCycles;
4387 typedef std::map<TCEString, NodeSet> NodeSetMap;
4392 for (NodeSet::iterator nsIter = nodes.begin();
4393 nsIter != nodes.end(); nsIter++) {
4396 movesInCycles[mn->
cycle()].insert(mn);
4400 for (MovesByCycles::iterator i = movesInCycles.begin();
4401 i != movesInCycles.end(); i++) {
4403 NodeSet& nodesInCycle = i->second;
4405 for (NodeSet::iterator j = nodesInCycle.begin();
4406 j != nodesInCycle.end(); j++) {
4412 reads[reg].insert(mn);
4417 for (NodeSet::iterator j = nodesInCycle.begin();
4418 j != nodesInCycle.end(); j++) {
4426 NodeSet& readsFromReg = reads[reg];
4427 NodeSet& writesToReg = writes[reg];
4431 for (NodeSet::iterator k = readsFromReg.begin();
4432 k != readsFromReg.end(); k++) {
4444 for (NodeSet::iterator k = writesToReg.begin();
4445 k != writesToReg.end(); k++) {
4458 writes[reg].clear();
4461 writes[reg].insert(mn);
4501 return !incomingGuards1.empty() &&
4502 incomingGuards1 == incomingGuards2;
4532 return !incomingGuards1.empty() &&
4533 incomingGuards1 == incomingGuards2;
4562 if (loopBypass && !defGuardDefMoves.empty()) {
4568 if (defGuardDefMoves != useGuardDefMoves) {
4583 if (guardDefs.size() != 1) {
4586 return *guardDefs.begin();
4595 for (
auto n: succs) {
4596 if (n->move().isJump()) {
4617 std::pair<MoveNode*, MoveNode*>
4621 if (guardDef == NULL) {
4622 return std::pair<MoveNode*, MoveNode*>(NULL, NULL);
4626 if (guardDef == NULL) {
4627 return std::pair<MoveNode*, MoveNode*>(NULL, NULL);
4638 if (input1Set.
count() != 1 || input2Set.
count() != 1) {
4639 return std::pair<MoveNode*, MoveNode*>(NULL, NULL);
4664 if (regMove != NULL) {
4667 inverted = !inverted;
4670 return std::pair<MoveNode*, MoveNode*>(NULL, NULL);
4673 return std::pair<MoveNode*, MoveNode*>(NULL, NULL);
4683 if (input1Set.
count() != 1 || input2Set.
count() != 1) {
4684 return std::pair<MoveNode*, MoveNode*>(NULL, NULL);
4691 return std::pair<MoveNode*, MoveNode*>(&input2, &input1);
4696 return std::pair<MoveNode*, MoveNode*>(&input1, &input2);
4700 return std::pair<MoveNode*, MoveNode*>(NULL, NULL);
4703 std::pair<MoveNode*, int>
4707 if (indexMove == NULL) {
4708 return std::pair<MoveNode*, int>(NULL,0);
4717 if (input1Set.
count() != 1 || input2Set.
count() != 1) {
4718 return std::pair<MoveNode*, int>(NULL,0);
4734 return std::pair<MoveNode*, int>(NULL,0);
4738 if (oldIndex == NULL) {
4739 return std::pair<MoveNode*, int>(NULL,0);
4747 return std::pair<MoveNode*, int>(oldIndex, value);
4752 return std::pair<MoveNode*, int>(NULL,0);
4759 for (EdgeSet::iterator i=iEdges.begin(); i != iEdges.end(); i++) {
4764 if (initEdge != NULL) {
4771 if (initEdge == NULL) {
4794 if (&
node != &trigger) {
4796 for (EdgeSet::iterator i=iEdges.begin(); i != iEdges.end(); i++) {
4808 if (&
node != &trigger) {
4810 for (EdgeSet::iterator i=oEdges.begin(); i != oEdges.end(); i++) {
4828 MoveNode& moveNode,
bool dest,
bool guard)
const {
4834 typedef EdgeSet::iterator EdgeIterator;
4839 queuedWrites.insert(&moveNode);
4843 queuedGuards.insert(&moveNode);
4845 queuedReads.insert(&moveNode);
4854 while (!queuedWrites.empty() || !queuedReads.empty() ||
4855 !queuedGuards.empty()) {
4857 while (!queuedWrites.empty()) {
4858 MoveNode& write = **queuedWrites.begin();
4863 for (EdgeIterator i = out.begin(); i != out.end(); ++i) {
4881 if (liveRange->
guards.find(&succ) ==
4882 liveRange->
guards.end()) {
4883 queuedGuards.insert(&succ);
4887 if (liveRange->
reads.find(&succ) ==
4888 liveRange->
reads.end()) {
4889 queuedReads.insert(&succ);
4896 liveRange->
writes.insert(&write);
4897 queuedWrites.erase(&write);
4901 queuedReads, liveRange->
reads, queuedWrites,
4902 liveRange->
writes,
false)) {
4908 queuedGuards, liveRange->
guards, queuedWrites,
4909 liveRange->
writes,
true)) {
4919 NodeSet& queue, NodeSet& finalDest, NodeSet& predQueue,
4920 NodeSet& predFinalDest,
bool guard)
const {
4922 typedef EdgeSet::iterator EdgeIterator;
4925 while (!queue.empty()) {
4931 for (EdgeIterator j = in.begin(); j != in.end(); j++) {
4944 if (predFinalDest.find(&pred) ==
4945 predFinalDest.end()) {
4946 predQueue.insert(&pred);
4952 finalDest.insert(&read);
4977 for (
int i = 0; i <
outDegree(mn); i++) {
4989 (writeTerm.
isGPR() && (
4992 undoData.
removedEdges.insert(RemovedEdgeDatum(mn, head, oEdge));
5018 for (
int i = 0; i <
outDegree(mn); i++) {
5030 (writeTerm.
isGPR() && (
5033 undoData.
removedEdges.insert(RemovedEdgeDatum(mn, head, oEdge));
5063 for (
int i = 0 ; i <
inDegree(mn); i++) {
5076 (writeTerm.
isGPR() && (
5079 undoData.
removedEdges.insert(RemovedEdgeDatum(tail, mn, iEdge));
5093 bool removeE =
false;
5101 if (readTerm.
isGPR() && (
5130 undoData.
removedEdges.insert(RemovedEdgeDatum(tail, mn, iEdge));
5141 for (
int i = 0; i <
outDegree(mn); i++) {
5163 (writeTerm.
isGPR() && (
5167 RemovedEdgeDatum(mn, head,
edge));
5188 if (oldReg == newReg) {
5202 for (EdgeSet::iterator i = resultInEdges.begin();
5203 i != resultInEdges.end(); i++) {
5212 if (e.
loopDepth() == 0 && &tail == &src) {
5223 newReg,
false,
false,
false,
false, 0);
5228 newReg,
false,
false,
false,
false, 0);
5237 for (EdgeSet::iterator i = firstInEdges.begin();
5238 i != firstInEdges.end(); i++) {
5247 for (EdgeSet::iterator i = firstOutEdges.begin();
5248 i != firstOutEdges.end(); i++) {
5257 for (EdgeSet::iterator i = lastOutEdges.begin();
5258 i != lastOutEdges.end(); i++) {
5276 for (EdgeSet::iterator ie = iEdges.begin(); ie != iEdges.end(); ie++) {
5283 if (tail.
isPlaced() && (limitingAntidep == NULL ||
5285 limitingAntidep = &tail;
5289 return limitingAntidep;
5297 for (EdgeSet::iterator oe = oEdges.begin(); oe != oEdges.end(); oe++) {
5306 if (head.
isPlaced() && (limitingAntidep == NULL ||
5308 limitingAntidep = &head;
5312 return limitingAntidep;
5328 for (EdgeSet::iterator i = edges.begin(); i != edges.end(); i++) {
5351 for (EdgeSet::iterator i = edges.begin(); i != edges.end(); i++) {
5371 std::set<MoveNodeUse>& defReaches =
5373 for (std::set<MoveNodeUse>::iterator i = defReaches.begin();
5374 i != defReaches.end(); i++) {
5407 std::set<MoveNodeUse>& defReaches =
5409 for (std::set<MoveNodeUse>::iterator i = defReaches.begin();
5410 i != defReaches.end(); i++) {
5426 addedEdges.insert(dde);
5432 std::set<MoveNodeUse>& useReaches =
5434 for (std::set<MoveNodeUse>::iterator i = useReaches.begin();
5435 i != useReaches.end(); i++) {
5451 addedEdges.insert(dde);
5468 std::pair<InEdgeIter, InEdgeIter> edges =
5469 boost::in_edges(nd,
graph_);
5472 for (
InEdgeIter ei = edges.first; ei != edges.second; ) {
5477 boost::remove_edge(*ei,
graph_);
5480 edges = boost::in_edges(nd,
graph_);
5498 std::pair<OutEdgeIter, OutEdgeIter> edges =
5499 boost::out_edges(nd,
graph_);
5502 for (
OutEdgeIter ei = edges.first; ei != edges.second; ) {
5507 boost::remove_edge(*ei,
graph_);
5510 edges = boost::out_edges(nd,
graph_);
5519 const MoveNodeUse& mnu, std::set<MoveNodeUse> targets)
const {
5522 std::pair<OutEdgeIter, OutEdgeIter> edges =
5523 boost::out_edges(nd,
graph_);
5526 for (
OutEdgeIter ei = edges.first; ei != edges.second; ei++ ) {
5597 for (DataDependenceGraph::NodeSet::iterator i = pred.begin();
5598 i != pred.end(); ++i) {
5599 if (!(**i).isPlaced()) {
5610 for (DataDependenceGraph::NodeSet::iterator i = succ.begin();
5611 i != succ.end(); ++i) {
5612 if (!(**i).isPlaced()) {
5627 int edgeCounter = 0;
5631 e->headPseudo() || e->tailPseudo() || e->guardUse()) {
5637 regDepSources.insert(&tail);
5639 for (
auto f: outs) {
5642 f->headPseudo() || f->tailPseudo() || f->guardUse()) {
5645 if (e != f && *e == *f) {
5648 potentialSiblings.insert(&head);
5654 for (
auto n : potentialSiblings) {
5657 int edgeCounter2 = 0;
5658 for (
auto e: ins2) {
5661 e->headPseudo() || e->tailPseudo() || e->guardUse()) {
5665 bool foundSame =
false;
5667 for (
auto f : ins) {
5668 if (*e == *f && &
tailNode(*f) == &tail) {
5681 if (ok && edgeCounter2 == edgeCounter) {
5690 for (EdgeSet::iterator i = iEdges.begin(); i != iEdges.end(); i++) {
5703 for (
auto e: iEdges) {
5723 typedef std::pair<EdgeIter, EdgeIter> EdgeIterPair;
5724 EdgeIterPair edges = boost::edges(
graph_);
5725 for (
EdgeIter i = edges.first; i != edges.second; i++) {
5737 DataDependenceGraph::EdgeSet::iterator edgeIter = edges.begin();
5741 while (edgeIter != edges.end()) {
5752 if (bypassEdge == NULL) {
5762 if (bypassEdge == NULL || bypassEdge->
isBackEdge()) {
5778 std::pair<InEdgeIter, InEdgeIter> iEdges =
5779 boost::in_edges(nd,
graph_);
5781 for (
InEdgeIter ii = iEdges.first; ii != iEdges.second; ii++) {
5798 srcPO->addGuardOutputNode(dst);
5815 std::cerr <<
"Warning: non-operation edge: " <<
edge.
toString()
5816 <<
" on guard bypass" << std::endl;
5856 for (
int i = 0; i <
inDegree(dst); i++) {
5875 true,
false,
false,
false);
5882 for (
int i = 0; i <
outDegree(guardSrc); i++) {
5900 i.first->setData(i.second);
5914 std::pair<InEdgeIter, InEdgeIter> edges = boost::in_edges(
5919 for (
InEdgeIter ei = edges.first; ei != edges.second; ++ei) {
5923 result.insert(
edge);
5931 std::pair<InEdgeIter, InEdgeIter> edges = boost::in_edges(
5936 for (
InEdgeIter ei = edges.first; ei != edges.second; ++ei) {
5940 result.insert(
edge);