73 delete criticalPath; criticalPath = NULL;
78 delete memDeps; memDeps = NULL;
100 const int cycleCount = ddg_.largestCycle() + 1;
101 const int nodes = ddg_.nodeCount();
135 int maxMovesToFind = 4;
137 resourceConstrained_ = 0;
139 cycle < cycleCount && resourceConstrained_ < maxMovesToFind; ++cycle) {
141 for (DataDependenceGraph::NodeSet::iterator m = moves.begin();
142 m != moves.end() && resourceConstrained_ < maxMovesToFind; ++m) {
146 <<
"found a schedule constraining move: "
148 << node->
cycle() <<
" earliest DDG cycle "
149 << ddg_.earliestCycle(*node) << std::endl;
150 ++resourceConstrained_;
155 if (
true || resourceConstrained_ > 0) {
161 for (
int c = 0; c < cycleCount; ++c) {
164 for (DataDependenceGraph::NodeSet::iterator m = moves.begin();
165 m != moves.end(); ++m) {
185 << resourceConstrained_ <<
" of " << nodes
186 <<
" were resource constrained:" << std::endl;
196 for (RFCountMap::const_iterator rfi =
200 << (*rfi).first <<
": " << (*rfi).second <<
" ";
209 for (RFCountMap::const_iterator rfi =
213 << (*rfi).first <<
": " << (*rfi).second <<
" ";
222 <<
" operation (FU) constrained ";
223 for (OperationCountMap::const_iterator rfi =
227 << (*rfi).first <<
": " << (*rfi).second <<
" ";
235 return regAntidepsFound;
243 const std::map<
int, std::list<MoveNode*> >& schedule) {
245 std::ofstream s(dotFileName.c_str());
247 s <<
"digraph ddg {" << std::endl;
250 s <<
"/*" << std::endl <<
"### dependence constraints: " << std::endl << std::endl;
254 int smallestCycle = (*schedule.begin()).first;
255 int largestCycle = (*schedule.rbegin()).first;
259 typedef std::map<std::pair<TCEString, TCEString>,
int> BypassMap;
261 typedef std::map<TCEString, int> OpCountMap;
262 OpCountMap maxParallelOps;
265 OpCountMap operationMix;
272 std::set<ProgramOperation*> recordedOps;
274 for (
int c = smallestCycle; c <= largestCycle; ++c) {
275 if (schedule.find(c) == schedule.end())
continue;
276 std::list<MoveNode*> moves = (*schedule.find(c)).second;
277 if (moves.size() == 0)
continue;
279 std::map<TCEString, int> parallelOpsAtCycle;
280 for (std::list<MoveNode*>::iterator i = moves.begin();
281 i != moves.end(); ++i) {
286 std::pair<TCEString, TCEString> key =
297 operationMix[opName]++;
298 parallelOpsAtCycle[opName]++;
299 recordedOps.insert(&op);
304 for (OpCountMap::const_iterator i = parallelOpsAtCycle.begin();
305 i != parallelOpsAtCycle.end(); ++i) {
307 int count = (*i).second;
308 maxParallelOps[opName] =
309 std::max(maxParallelOps[opName], count);
314 s <<
"### resource statistics: " << std::endl << std::endl;
316 const int COL_WIDTH = 14;
318 s << std::setw(COL_WIDTH) << std::right <<
"operation stats: ";
319 s << std::endl << std::endl;
321 for (OpCountMap::const_iterator i = maxParallelOps.begin();
322 i != maxParallelOps.end(); ++i) {
324 int parCount = (*i).second;
325 int total = operationMix[opName];
326 s << std::setw(COL_WIDTH) << std::right
328 s << std::setw(COL_WIDTH) << std::right
330 s <<
" total, " << std::setw(COL_WIDTH) << std::right
331 << parCount <<
" at most in parallel" << std::endl;
336 s << std::setw(COL_WIDTH) << std::right <<
"bypass stats: ";
337 s << std::endl << std::endl;
339 for (BypassMap::const_iterator i = bypasses.begin();
340 i != bypasses.end(); ++i) {
341 std::pair<TCEString, TCEString> opPair = (*i).first;
342 int count = (*i).second;
343 s << std::setw(COL_WIDTH) << std::right
344 << opPair.first +
" -> " + opPair.second +
": ";
345 s << std::setw(COL_WIDTH) << std::right
346 << count << std::endl;
351 s << std::endl <<
"### moves not at the earliest cycles:" << std::endl << std::endl;
352 for (
int i = 0; i < ddg.
nodeCount(); ++i) {
357 if (n.
cycle() > ddgEarliest)
358 s << n.
toString() <<
" (" << n.
cycle() <<
" > " << ddgEarliest <<
")" << std::endl;
362 s << std::endl <<
"*/" << std::endl << std::endl;
367 s <<
"\t{" << std::endl
368 <<
"\t\tnode [shape=plaintext];" << std::endl
370 for (
int c = smallestCycle; c <= largestCycle; ++c) {
371 s <<
"\"cycle " << c <<
"\" -> ";
373 s <<
"\"cycle " << largestCycle + 1 <<
"\"; "
374 << std::endl <<
"\t}" << std::endl;
377 for (
int c = smallestCycle; c <= largestCycle; ++c) {
378 if (schedule.find(c) == schedule.end())
continue;
379 std::list<MoveNode*> moves = (*schedule.find(c)).second;
380 if (moves.size() == 0)
continue;
381 s <<
"\t{ rank = same; \"cycle " << c <<
"\"; ";
382 for (std::list<MoveNode*>::iterator i = moves.begin();
383 i != moves.end(); ++i) {
385 s <<
"n" << n.
nodeID() <<
"; ";
387 s <<
"}" << std::endl;
391 for (
int i = 0; i < ddg.
nodeCount(); ++i) {
399 for (
int count = ddg.
edgeCount(), i = 0; i < count ; ++i) {
404 s <<
"\tn" << tail.
nodeID() <<
" -> n"
409 s <<
"}" << std::endl;
429 TCEString dotFileName = graphName +
".optimal_schedule.dot";
431 std::map<int, std::list<MoveNode*> > schedule;
434 for (
int nc = 0; nc < ddg.
nodeCount(); ++nc) {
447 if (&inputMove == &n)
continue;
451 schedule[cycle].push_back(&n);
469 TCEString dotFileName = graphName +
".memory_bound_optimal_schedule.dot";
471 int maxMemOpsPerCycle = 2;
472 std::map<int, std::list<MoveNode*> > schedule;
473 std::map<int, std::list<ProgramOperationPtr> > operationSchedule;
476 std::map<TCEString, unsigned> maxParallelOps;
483 <<
"### analyzing " << graphName << std::endl;
497 for (
auto mn : po->inputNode(1)) {
499 *mn, UINT_MAX,
false,
false,
false,
false,
false,
true);
500 int memOpsInCycle = 0;
507 for (
auto otherOp : operationSchedule[cycle]) {
508 if (otherOp->operation().usesMemory())
511 if (memOpsInCycle > maxMemOpsPerCycle) {
513 <<
"would get " << memOpsInCycle
514 <<
" mem operations in cycle " << cycle
518 }
while (memOpsInCycle > maxMemOpsPerCycle);
520 schedule[cycle].push_back(mn);
521 operationSchedule[cycle].push_back(po);
523 <<
"placed operation trigger " << mn->toString() << std::endl;
527 for (
int n = 0; n < cands.
nodeCount(); ++n) {
531 mn, UINT_MAX,
false,
false,
false,
false,
false,
true);
533 schedule[cycle].push_back(&mn);
535 <<
"placed mn " << mn.
toString() << std::endl;
566 s <<
"DDG height: " << ddg.
height() << std::endl;
571 s <<
"DDG height without register antideps: "
572 << trueDepGraph->
height() << std::endl;
578 s <<
"DDG height without any antideps: "
579 << trueDepGraph2->
height() << std::endl;
582 (boost::format(
"%s.tddg_noantidep_.dot") %
graphName_).str());
583 delete trueDepGraph2;
587 s <<
"DDG height without any antideps and memory deps: "
588 << trueDepGraph3->
height() << std::endl;
591 (boost::format(
"%s.tddg_noantidep_nonmemdep.dot") %
graphName_).str());
593 delete trueDepGraph3;
595 std::map<int, int> foundCounts;
597 bool restrictingEdgeFound =
false;
599 for (
int i = 0; i < ddg.
nodeCount(); i++) {
601 for (
int e = 0; e < ddg.
outDegree(tail); ++e) {
612 if (trueDepGraph->
hasPath(tail, head))
630 <<
"WARNING: not a GPR: "
638 <<
"WARNING: not a GPR: "
643 s <<
"Limiting antidep: from "
657 <<
"Edge " << edge.
toString() <<
" between moves: "
666 for (std::map<int, int>::iterator i = foundCounts.begin();
667 i != foundCounts.end(); ++i) {
668 int foundCount = (*i).second;
669 int bitWidth = (*i).first;
670 s <<
"found " << foundCount <<
" " << bitWidth <<
" bit "
671 <<
" register antideps that restrict parallelism" << std::endl;
675 return restrictingEdgeFound;
691 if (child == NULL || !child->
isMove())
701 for (DataDependenceGraph::NodeSet::const_iterator p = parents.begin();
702 p != parents.end(); ++p) {
720 if (node.
cycle() == 0)
724 if (ddgEarliestCycle == node.
cycle())
729 <<
"earliest cycle for JUMP: " << ddgEarliestCycle << std::endl;
747 if (node.
cycle() == trigger.
cycle() + latency) {
760 if (prevInstr->
moveCount() == busCount) {
770 for (
int m = 0; m < prevInstr->
moveCount(); ++m) {
790 for (
int m = 0; m < prevInstr->
moveCount(); ++m) {
812 bool operandConstrained =
false;
816 !operandConstrained; ++input) {
820 if (&operandMove == &node)
824 operandConstrained =
true;
830 if (!operandConstrained) {
835 << opName <<
" constrained: "
840 }
else if (operandConstrained){
848 <<
"resource set constrained move of unknown reason: "
853 <<
"ProgramOperation: " << op.
toString() << std::endl;
860 for (
int c = 3; c >= 0; --c) {
861 int printCycle = node.
cycle() - c;
862 if (printCycle > 0) {
864 << printCycle <<
": "