17 #ifdef DEBUG_LOOP_ANALYZER
19 dotName << ddg.
name();
27 for (
int j = 0; j < ins.
moveCount(); j++) {
34 if (jumpMove == NULL) {
39 if (guardDef == NULL) {
44 if (guardDef == NULL) {
59 if (input1Set.
count() != 1 || input2Set.
count() != 1) {
85 if (regMove == NULL) {
113 #ifndef DEBUG_LOOP_ANALYZER
116 std::cerr <<
"\tLoop comparison op is: " <<gdpo->
toString()<< std::endl;
117 #ifndef DEBUG_LOOP_ANALYZER
132 #ifndef DEBUG_LOOP_ANALYZER
136 "Unsupported comparison op for loop analyzer." <<
138 #ifndef DEBUG_LOOP_ANALYZER
153 if (input1Set.
count() != 1 || input2Set.
count() != 1) {
159 onlyRegCmp = regCmp1 = &input1;
167 if (onlyRegCmp == NULL) {
168 onlyRegCmp = regCmp2;
174 if (constCmp != NULL) {
183 if (constCmp == &input1) {
201 if (initAndUpdate == NULL) {
204 int update = initAndUpdate->
update;
205 if (initAndUpdate->
initNode != NULL) {
207 if (update <0 && endVal == 0) {
208 if (ltu)
return NULL;
212 if (update < 0 && abs(endVal) < -update) {
213 if (ltu)
return NULL;
218 if (ltu)
return NULL;
221 initAndUpdate->
loopEdge + (endVal/update),
228 int diff = endVal - initAndUpdate->
initVal;
229 if (diff % update != 0) {
232 if (update < 0 && gtu)
return NULL;
233 if (update > 0 && ltu)
return NULL;
235 (diff / update) + initAndUpdate->
loopEdge, NULL);
240 if (initAndUpdate == NULL) {
242 if (initAndUpdate == NULL) {
256 if (endCond == NULL) {
261 if (endCond == NULL) {
265 if (endCond == NULL) {
266 #ifndef DEBUG_LOOP_ANALYZER
269 std::cerr <<
"Could not analyze end condition" << std::endl;
270 #ifndef DEBUG_LOOP_ANALYZER
278 if (initAndUpdate->
initNode != NULL) {
279 int update = initAndUpdate->
update;
281 if (endCond->first == 0 && endCond->second == NULL) {
283 if (ltu || update >= 0 )
return NULL;
284 if (update == -1 || gtu) {
292 if (endCond->second && initAndUpdate->
initNode) {
295 ddg, *initAndUpdate->
initNode, *endCond->second);
296 if (commonAncestor != NULL) {
297 if (commonAncestor->second == NULL) {
298 if (update < 0 && ltu)
return NULL;
299 if (update > 0 && gtu)
return NULL;
301 commonAncestor->first/update +
309 if (endCond->second == NULL) {
310 #ifndef DEBUG_LOOP_ANALYZER
313 std::cerr <<
"End condition is constant:" << endCond->first << std::endl;
314 #ifndef DEBUG_LOOP_ANALYZER
317 int diff = endCond->first - initAndUpdate->
initVal;
318 int update = initAndUpdate->
update;
319 if (diff % update != 0) {
322 if (update < 0 && ltu)
return NULL;
323 if (update > 0 && gtu)
return NULL;
327 #ifndef DEBUG_LOOP_ANALYZER
330 std::cerr <<
"\tLoop end register might be: " << endCond->second->toString() << std::endl;
331 std::cerr <<
"\tEnd cond first is: " << endCond->first << std::endl;
332 std::cerr <<
"\t init is: " << initAndUpdate->
initVal
333 <<
" and update is: " << initAndUpdate->
update << std::endl;
334 #ifndef DEBUG_LOOP_ANALYZER
337 if (initAndUpdate->
initVal != 0) {
338 #ifndef DEBUG_LOOP_ANALYZER
341 std::cerr <<
"Variable loop counts with init !=0 not yet supported" << std::endl;
342 #ifndef DEBUG_LOOP_ANALYZER
358 #ifdef DEBUG_LOOP_ANALYZER
359 std::cerr <<
"\tSearching end cond, allow var: " << allowVariable
360 <<
" from: " << cmpVal.
toString() << std::endl;
367 if (cmpSrc == NULL) {
368 #ifdef DEBUG_LOOP_ANALYZER
369 std::cerr <<
"\t\tNo only RRAW source found, returning this or NULL"
386 #ifdef DEBUG_LOOP_ANALYZER
387 std::cerr <<
"cmp val" << cmpVal.
toString() <<
" and cmpsrc "
388 << cmpSrc->
toString() <<
" has different BB, ret cmpval"
409 if (!isSub && !isAdd) {
410 #ifdef DEBUG_LOOP_ANALYZER
411 std::cerr <<
"\t\tFind End Cond unknown op, returning NULL" << std::endl;
418 if (input1Set.
count() != 1 || input2Set.
count() != 1) {
429 if (tmpRes2 == NULL) {
432 if (tmpRes2->second == NULL) {
433 int value = tmpRes2->first;
439 if (tmpRes1 == NULL) {
442 tmpRes1->first += value;
454 if (tmpRes1 == NULL) {
457 if (tmpRes1->second == NULL) {
458 tmpRes2->first += tmpRes1->first;
473 #ifndef DEBUG_LOOP_ANALYZER
476 std::cerr <<
"\tSearching init and update from cmpval: "
478 #ifndef DEBUG_LOOP_ANALYZER
485 if (cmpSrc == NULL) {
487 if (backCmpSrc && fwdCmpSrc) {
500 if (cmpSrcSrc == NULL) {
514 if (!isSub && !isAdd) {
521 if (input1Set.
count() != 1 || input2Set.
count() != 1) {
552 if (updateSource == NULL ||
553 (updateSource != cmpSrc && updateSource != originalCmpSrc)) {
560 if (initNodes.size() == 1) {
561 counterInit = *initNodes.begin();
562 }
else if (initNodes.size() > 1) {
563 #ifdef DEBUG_LOOP_ANALYZER
564 std::cerr <<
"multiple init nodes, must be dynamic " << std::endl;
566 for (
auto i = initNodes.begin(); i != initNodes.end(); i++) {
567 std::cerr <<
"\t\t" << (**i).
toString() << std::endl;
569 return new InitAndUpdate(*regMove, updateVal, backCmpSrc != 0);
572 if (counterInit == NULL) {
575 int counterOffset = 0;
579 if (counterInit == NULL) {
580 return new InitAndUpdate(*regMove, updateVal, backCmpSrc !=0);
583 #ifdef DEBUG_LOOP_ANALYZER
584 std::cerr <<
"Coutner init src not var: " << counterInit->
toString() << std::endl;
587 #ifdef DEBUG_LOOP_ANALYZER
588 std::cerr <<
"Coutner init src op: " << counterInit->
toString() << std::endl;
593 if (!isSub && !isAdd) {
600 if (input1Set.
count() != 1 || input2Set.
count() != 1) {
605 #ifdef DEBUG_LOOP_ANALYZER
606 std::cerr <<
"inputs: " << input1.
toString() <<
" and "
610 #ifdef DEBUG_LOOP_ANALYZER
611 std::cerr <<
"input2 imm" << input2.
toString() << std::endl;
620 + counterOffset, updateVal, backCmpSrc != 0);
622 counterInit = &input1;
636 updateVal, backCmpSrc != 0);
638 #ifndef DEBUG_LOOP_ANALYZER
641 std::cerr <<
"\t\tCounter init variable: " << counterInit->
toString() << std::endl;
642 #ifndef DEBUG_LOOP_ANALYZER
645 return new InitAndUpdate(*counterInit, counterOffset, updateVal, backCmpSrc != 0);
654 while (initSrc != NULL) {
661 while (eSrc != NULL) {
666 if (e == NULL || i == NULL) {
677 if (input1Set.
count() != 1 || input2Set.
count() != 1) {