proplong.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578
  1. /**************************************************************************
  2. * File : propLong.c
  3. * Purpose: propagate the value of long variables (local variables and
  4. * registers) along the graph. Structure the graph in this way.
  5. * (C) Cristina Cifuentes
  6. **************************************************************************/
  7. #include <string.h>
  8. #include <memory.h>
  9. #include <cassert>
  10. #include <algorithm>
  11. #include "dcc.h"
  12. /* Returns whether the given icode opcode is within the range of valid
  13. * high-level conditional jump icodes (iJB..iJG) */
  14. static bool isJCond (llIcode opcode)
  15. {
  16. if ((opcode >= iJB) && (opcode <= iJG))
  17. return true;
  18. return false;
  19. }
  20. /* Returns whether the conditions for a 2-3 long variable are satisfied */
  21. static bool isLong23 (BB * pbb, iICODE &off, int *arc)
  22. {
  23. BB * t, * e, * obb2;
  24. if (pbb->nodeType != TWO_BRANCH)
  25. return false;
  26. t = pbb->edges[THEN].BBptr;
  27. e = pbb->edges[ELSE].BBptr;
  28. /* Check along the THEN path */
  29. if ((t->size() == 1) && (t->nodeType == TWO_BRANCH) && (t->inEdges.size() == 1))
  30. {
  31. obb2 = t->edges[THEN].BBptr;
  32. if ((obb2->size() == 2) && (obb2->nodeType == TWO_BRANCH) && (obb2->front().ll()->getOpcode() == iCMP))
  33. {
  34. off = obb2->begin();//std::distance(iter,obb2->begin2());
  35. *arc = THEN;
  36. return true;
  37. }
  38. }
  39. /* Check along the ELSE path */
  40. else if ((e->size() == 1) && (e->nodeType == TWO_BRANCH) && (e->inEdges.size() == 1))
  41. {
  42. obb2 = e->edges[THEN].BBptr;
  43. if ((obb2->size() == 2) && (obb2->nodeType == TWO_BRANCH) && (obb2->front().ll()->getOpcode() == iCMP))
  44. {
  45. off = obb2->begin();//std::distance(iter,obb2->begin2());//obb2->front().loc_ip - i;
  46. *arc = ELSE;
  47. return true;
  48. }
  49. }
  50. return false;
  51. }
  52. /* Returns whether the conditions for a 2-2 long variable are satisfied */
  53. static bool isLong22 (iICODE pIcode, iICODE pEnd, iICODE &off)
  54. {
  55. iICODE initial_icode=pIcode;
  56. if(distance(pIcode,pEnd)<4)
  57. return false;
  58. // preincrement because pIcode is not checked here
  59. iICODE icodes[] = { ++pIcode,++pIcode,++pIcode };
  60. if ( icodes[1]->ll()->match(iCMP) &&
  61. (isJCond ((llIcode)icodes[0]->ll()->getOpcode())) &&
  62. (isJCond ((llIcode)icodes[2]->ll()->getOpcode())))
  63. {
  64. off = initial_icode;
  65. advance(off,2);
  66. return true;
  67. }
  68. return false;
  69. }
  70. /** Creates a long conditional <=, >=, <, or > at (pIcode+1).
  71. * Removes excess nodes from the graph by flagging them, and updates
  72. * the new edges for the remaining nodes.
  73. * @return number of ICODEs to skip
  74. */
  75. static int longJCond23 (Assignment &asgn, iICODE pIcode, int arc, iICODE atOffset)
  76. {
  77. BB * pbb, * obb1, * obb2, * tbb;
  78. int skipped_insn=0;
  79. if (arc == THEN)
  80. {
  81. /* Find intermediate basic blocks and target block */
  82. pbb = pIcode->getParent();
  83. obb1 = pbb->edges[THEN].BBptr;
  84. obb2 = obb1->edges[THEN].BBptr;
  85. tbb = obb2->edges[THEN].BBptr;
  86. /* Modify out edge of header basic block */
  87. pbb->edges[THEN].BBptr = tbb;
  88. /* Modify in edges of target basic block */
  89. auto newlast=std::remove_if(tbb->inEdges.begin(),tbb->inEdges.end(),
  90. [obb1,obb2](BB *b) -> bool {
  91. return (b==obb1) || (b==obb2); });
  92. tbb->inEdges.erase(newlast,tbb->inEdges.end());
  93. tbb->inEdges.push_back(pbb); /* looses 2 arcs, gains 1 arc */
  94. /* Modify in edges of the ELSE basic block */
  95. tbb = pbb->edges[ELSE].BBptr;
  96. auto iter=std::find(tbb->inEdges.begin(),tbb->inEdges.end(),obb2);
  97. assert(iter!=tbb->inEdges.end());
  98. tbb->inEdges.erase(iter); /* looses 1 arc */
  99. /* Update icode index */
  100. skipped_insn = 5;
  101. }
  102. else /* ELSE arc */
  103. {
  104. /* Find intermediate basic blocks and target block */
  105. pbb = pIcode->getParent();
  106. obb1 = pbb->edges[ELSE].BBptr;
  107. obb2 = obb1->edges[THEN].BBptr;
  108. tbb = obb2->edges[THEN].BBptr;
  109. /* Modify in edges of target basic block */
  110. auto iter=std::find(tbb->inEdges.begin(),tbb->inEdges.end(),obb2);
  111. assert(iter!=tbb->inEdges.end());
  112. tbb->inEdges.erase(iter); /* looses 1 arc */
  113. /* Modify in edges of the ELSE basic block */
  114. tbb = obb2->edges[ELSE].BBptr;
  115. auto newlast=std::remove_if(tbb->inEdges.begin(),tbb->inEdges.end(),
  116. [obb1,obb2](BB *b) -> bool { return (b==obb1) || (b==obb2); });
  117. tbb->inEdges.erase(newlast,tbb->inEdges.end());
  118. tbb->inEdges.push_back(pbb); /* looses 2 arcs, gains 1 arc */
  119. /* Modify out edge of header basic block */
  120. pbb->edges[ELSE].BBptr = tbb;
  121. /* Update icode index */
  122. skipped_insn = 2;
  123. }
  124. iICODE atOffset1(atOffset),next1(++iICODE(pIcode));
  125. advance(atOffset1,1);
  126. /* Create new HLI_JCOND and condition */
  127. condOp oper=condOpJCond[atOffset1->ll()->getOpcode()-iJB];
  128. asgn.lhs = new BinaryOperator(oper,asgn.lhs, asgn.rhs);
  129. next1->setJCond(asgn.lhs);
  130. next1->copyDU(*pIcode, eUSE, eUSE);
  131. next1->du.use |= atOffset->du.use;
  132. /* Update statistics */
  133. obb1->flg |= INVALID_BB;
  134. obb2->flg |= INVALID_BB;
  135. stats.numBBaft -= 2;
  136. pIcode->invalidate();
  137. obb1->front().invalidate();
  138. // invalidate 2 first instructions of BB 2
  139. iICODE ibb2 = obb2->begin();
  140. (ibb2++)->invalidate();
  141. (ibb2++)->invalidate();
  142. return skipped_insn;
  143. }
  144. /** Creates a long conditional equality or inequality at (pIcode+1).
  145. * Removes excess nodes from the graph by flagging them, and updates
  146. * the new edges for the remaining nodes.
  147. * @return number of ICODE's to skip
  148. */
  149. static int longJCond22 (Assignment &asgn, iICODE pIcode,iICODE pEnd)
  150. {
  151. BB * pbb, * obb1, * tbb;
  152. if(distance(pIcode,pEnd)<4)
  153. return false;
  154. // preincrement because pIcode is not checked here
  155. iICODE icodes[] = { pIcode++,pIcode++,pIcode++,pIcode++ };
  156. /* Form conditional expression */
  157. condOp oper=condOpJCond[icodes[3]->ll()->getOpcode() - iJB];
  158. asgn.lhs = new BinaryOperator(oper,asgn.lhs, asgn.rhs);
  159. icodes[1]->setJCond(asgn.lhs);
  160. icodes[1]->copyDU (*icodes[0], eUSE, eUSE);
  161. icodes[1]->du.use |= icodes[2]->du.use;
  162. /* Adjust outEdges[0] to the new target basic block */
  163. pbb = icodes[0]->getParent();
  164. if (pbb->back().loc_ip == icodes[1]->loc_ip)
  165. {
  166. /* Find intermediate and target basic blocks */
  167. obb1 = pbb->edges[THEN].BBptr;
  168. tbb = obb1->edges[THEN].BBptr;
  169. /* Modify THEN out edge of header basic block */
  170. pbb->edges[THEN].BBptr = tbb;
  171. /* Modify in edges of target basic block */
  172. auto iter=std::find(tbb->inEdges.begin(),tbb->inEdges.end(),obb1);
  173. assert(iter!=tbb->inEdges.end());
  174. tbb->inEdges.erase(iter);
  175. if (icodes[3]->ll()->getOpcode() != iJE)
  176. tbb->inEdges.push_back(pbb); /* iJNE => replace arc */
  177. /* Modify ELSE out edge of header basic block */
  178. tbb = obb1->edges[ELSE].BBptr;
  179. pbb->edges[ELSE].BBptr = tbb;
  180. iter=std::find(tbb->inEdges.begin(),tbb->inEdges.end(),obb1);
  181. assert(iter!=tbb->inEdges.end());
  182. tbb->inEdges.erase(iter);
  183. if (icodes[3]->ll()->getOpcode() == iJE) /* replace */
  184. tbb->inEdges.push_back(pbb);
  185. /* Update statistics */
  186. obb1->flg |= INVALID_BB;
  187. stats.numBBaft--;
  188. }
  189. icodes[0]->invalidate();
  190. icodes[2]->invalidate();
  191. icodes[3]->invalidate();
  192. return 4;
  193. }
  194. /* Propagates TYPE_LONG_(UN)SIGN icode information to the current pIcode
  195. * Pointer.
  196. * Arguments: i : index into the local identifier table
  197. * pLocId: ptr to the long local identifier
  198. * pProc : ptr to current procedure's record. */
  199. void Function::propLongStk (int i, const ID &pLocId)
  200. {
  201. int arc;
  202. Assignment asgn;
  203. //COND_EXPR *lhs, *rhs; /* Pointers to left and right hand expression */
  204. iICODE next1, pEnd;
  205. iICODE l23;
  206. /* Check all icodes for offHi:offLo */
  207. pEnd = Icode.end();
  208. size_t stat_size=Icode.size();
  209. // for (idx = 0; idx < (Icode.size() - 1); idx++)
  210. for(auto pIcode = Icode.begin(); ;++pIcode)
  211. {
  212. assert(Icode.size()==stat_size);
  213. next1 = ++iICODE(pIcode);
  214. if(next1==pEnd)
  215. break;
  216. if ((pIcode->type == HIGH_LEVEL) || ( not pIcode->valid() ))
  217. continue;
  218. if (pIcode->ll()->getOpcode() == next1->ll()->getOpcode())
  219. {
  220. if (checkLongEq (pLocId.longStkId(), pIcode, i, this, asgn, *next1->ll()) == true)
  221. {
  222. switch (pIcode->ll()->getOpcode())
  223. {
  224. case iMOV:
  225. pIcode->setAsgn(dynamic_cast<AstIdent *>(asgn.lhs), asgn.rhs);
  226. next1->invalidate();
  227. break;
  228. case iAND: case iOR: case iXOR:
  229. {
  230. condOp oper = DUMMY;
  231. switch (pIcode->ll()->getOpcode())
  232. {
  233. case iAND: oper=AND; break;
  234. case iOR: oper=OR; break;
  235. case iXOR: oper=XOR; break;
  236. }
  237. if(DUMMY!=oper)
  238. {
  239. asgn.rhs = new BinaryOperator(oper,asgn.lhs, asgn.rhs);
  240. }
  241. pIcode->setAsgn(dynamic_cast<AstIdent *>(asgn.lhs), asgn.rhs);
  242. next1->invalidate();
  243. break;
  244. }
  245. case iPUSH:
  246. pIcode->setUnary( HLI_PUSH, asgn.lhs);
  247. next1->invalidate();
  248. break;
  249. default:
  250. printf("Wild ass checkLongEq success on opcode %d\n",pIcode->ll()->getOpcode());
  251. } /*eos*/
  252. }
  253. }
  254. //TODO: Simplify this!
  255. /* Check long conditional (i.e. 2 CMPs and 3 branches */
  256. else if ((pIcode->ll()->getOpcode() == iCMP) && (isLong23 (pIcode->getParent(), l23, &arc)))
  257. {
  258. if ( checkLongEq (pLocId.longStkId(), pIcode, i, this, asgn, *l23->ll()) )
  259. {
  260. advance(pIcode,longJCond23 (asgn, pIcode, arc, l23));
  261. }
  262. }
  263. /* Check for long conditional equality or inequality. This requires
  264. * 2 CMPs and 2 branches */
  265. else if ((pIcode->ll()->getOpcode() == iCMP) && isLong22 (pIcode, pEnd, l23))
  266. {
  267. if ( checkLongEq (pLocId.longStkId(), pIcode, i, this,asgn, *l23->ll()) )
  268. {
  269. advance(pIcode,longJCond22 (asgn, pIcode,pEnd));
  270. }
  271. }
  272. }
  273. }
  274. int Function::findBackwarLongDefs(int loc_ident_idx, const ID &pLocId, iICODE beg)
  275. {
  276. Assignment asgn;
  277. LLOperand * pmH,* pmL;
  278. iICODE pIcode;
  279. riICODE rev(beg);
  280. bool forced_finish=false;
  281. for (; not forced_finish and rev!=Icode.rend();rev++) //idx = pLocId_idx - 1; idx > 0 ; idx--
  282. {
  283. pIcode = (++riICODE(rev)).base();//forward iterator from rev
  284. iICODE next1((++iICODE(pIcode))); // next instruction
  285. ICODE &icode(*pIcode);
  286. if ((icode.type == HIGH_LEVEL) || ( not icode.valid() ))
  287. continue;
  288. if (icode.ll()->getOpcode() != next1->ll()->getOpcode())
  289. continue;
  290. switch (icode.ll()->getOpcode())
  291. {
  292. case iMOV:
  293. pmH = &icode.ll()->m_dst;
  294. pmL = &next1->ll()->m_dst;
  295. if ((pLocId.longId().h() == pmH->regi) && (pLocId.longId().l() == pmL->regi))
  296. {
  297. localId.id_arr[loc_ident_idx].idx.push_back(pIcode);//idx-1//insert
  298. icode.setRegDU( pmL->regi, eDEF);
  299. asgn.lhs = AstIdent::LongIdx (loc_ident_idx);
  300. asgn.rhs = AstIdent::Long (&this->localId, SRC, pIcode, HIGH_FIRST, pIcode, eUSE, *next1->ll());
  301. icode.setAsgn(asgn.lhs, asgn.rhs);
  302. next1->invalidate();
  303. forced_finish=true; /* to exit the loop */
  304. }
  305. break;
  306. case iPOP:
  307. pmH = &next1->ll()->m_dst;
  308. pmL = &icode.ll()->m_dst;
  309. if ((pLocId.longId().h() == pmH->regi) && (pLocId.longId().l() == pmL->regi))
  310. {
  311. asgn.lhs = AstIdent::LongIdx (loc_ident_idx);
  312. icode.setRegDU( pmH->regi, eDEF);
  313. icode.setUnary(HLI_POP, asgn.lhs);
  314. next1->invalidate();
  315. asgn.lhs=nullptr;
  316. forced_finish=true; /* to exit the loop */
  317. }
  318. break;
  319. // /**** others missing ***/
  320. case iAND: case iOR: case iXOR:
  321. pmL = &icode.ll()->m_dst;
  322. pmH = &next1->ll()->m_dst;
  323. if ((pLocId.longId().h() == pmH->regi) && (pLocId.longId().l() == pmL->regi))
  324. {
  325. asgn.lhs = AstIdent::LongIdx (loc_ident_idx);
  326. asgn.rhs = AstIdent::Long (&this->localId, SRC, pIcode, LOW_FIRST, pIcode, eUSE, *next1->ll());
  327. icode.setRegDU( pmH->regi, USE_DEF);
  328. condOp toCreate=DUMMY;
  329. switch (icode.ll()->getOpcode())
  330. {
  331. case iAND: toCreate = AND; break;
  332. case iOR: toCreate = OR; break;
  333. case iXOR: toCreate = XOR; break;
  334. } /* eos */
  335. if(toCreate != DUMMY)
  336. asgn.rhs = new BinaryOperator(toCreate,asgn.lhs, asgn.rhs);
  337. icode.setAsgn(asgn.lhs, asgn.rhs);
  338. next1->invalidate();
  339. forced_finish=true; /* to exit the loop */
  340. }
  341. break;
  342. } /* eos */
  343. }
  344. return rev!=Icode.rend();
  345. }
  346. int Function::findForwardLongUses(int loc_ident_idx, const ID &pLocId, iICODE beg)
  347. {
  348. bool forced_finish=false;
  349. auto pEnd=Icode.end();
  350. iICODE long_loc;
  351. Assignment asgn;
  352. for (auto pIcode=beg; not forced_finish; ++pIcode)
  353. {
  354. iICODE next1(++iICODE(pIcode));
  355. if(next1==pEnd)
  356. break;
  357. LLOperand * pmH,* pmL; /* Pointers to dst LOW_LEVEL icodes */
  358. int arc;
  359. if ((pIcode->type == HIGH_LEVEL) || ( not pIcode->valid() ))
  360. continue;
  361. if (pIcode->ll()->getOpcode() == next1->ll()->getOpcode())
  362. switch (pIcode->ll()->getOpcode())
  363. {
  364. case iMOV:
  365. {
  366. const LONGID_TYPE &ref_long(pLocId.longId());
  367. const LLOperand &src_op1(pIcode->ll()->src());
  368. const LLOperand &src_op2(next1->ll()->src());
  369. eReg srcReg1=src_op1.getReg2();
  370. eReg nextReg2=src_op2.getReg2();
  371. if ((ref_long.h() == srcReg1) && (ref_long.l() == nextReg2))
  372. {
  373. pIcode->setRegDU( nextReg2, eUSE);
  374. asgn.rhs = AstIdent::LongIdx (loc_ident_idx);
  375. asgn.lhs = AstIdent::Long (&this->localId, DST, pIcode,HIGH_FIRST, pIcode, eDEF, *next1->ll());
  376. pIcode->setAsgn(dynamic_cast<AstIdent *>(asgn.lhs), asgn.rhs);
  377. next1->invalidate();
  378. forced_finish =true; /* to exit the loop */
  379. }
  380. break;
  381. }
  382. case iPUSH:
  383. {
  384. const LONGID_TYPE &ref_long(pLocId.longId());
  385. const LLOperand &src_op1(pIcode->ll()->src());
  386. const LLOperand &src_op2(next1->ll()->src());
  387. if ((ref_long.h() == src_op1.getReg2()) && (ref_long.l() == src_op2.getReg2()))
  388. {
  389. asgn.rhs = AstIdent::LongIdx (loc_ident_idx);
  390. pIcode->setRegDU( next1->ll()->src().getReg2(), eUSE);
  391. pIcode->setUnary(HLI_PUSH, asgn.rhs);
  392. next1->invalidate();
  393. }
  394. forced_finish =true; /* to exit the loop */
  395. break;
  396. }
  397. /*** others missing ****/
  398. case iAND: case iOR: case iXOR:
  399. pmL = &pIcode->ll()->m_dst;
  400. pmH = &next1->ll()->m_dst;
  401. if ((pLocId.longId().h() == pmH->regi) && (pLocId.longId().l() == pmL->regi))
  402. {
  403. asgn.lhs = AstIdent::LongIdx (loc_ident_idx);
  404. pIcode->setRegDU( pmH->regi, USE_DEF);
  405. asgn.rhs = AstIdent::Long (&this->localId, SRC, pIcode,
  406. LOW_FIRST, pIcode, eUSE, *next1->ll());
  407. condOp toCreate=DUMMY;
  408. switch (pIcode->ll()->getOpcode()) {
  409. case iAND: toCreate=AND; break;
  410. case iOR: toCreate=OR; break;
  411. case iXOR: toCreate= XOR; break;
  412. }
  413. if(DUMMY!=toCreate)
  414. {
  415. asgn.rhs = new BinaryOperator(toCreate,asgn.lhs, asgn.rhs);
  416. }
  417. pIcode->setAsgn(dynamic_cast<AstIdent *>(asgn.lhs), asgn.rhs);
  418. next1->invalidate();
  419. // ftw loop restart ????
  420. //idx = 0;
  421. // maybe this should end the loop instead
  422. forced_finish =true; /* to exit the loop */
  423. }
  424. break;
  425. } /* eos */
  426. /* Check long conditional (i.e. 2 CMPs and 3 branches */
  427. else if ((pIcode->ll()->getOpcode() == iCMP) && (isLong23 (pIcode->getParent(), long_loc, &arc)))
  428. {
  429. if (checkLongRegEq (pLocId.longId(), pIcode, loc_ident_idx, this, asgn, *long_loc->ll()))
  430. {
  431. // reduce the advance by 1 here (loop increases) ?
  432. advance(pIcode,longJCond23 (asgn, pIcode, arc, long_loc));
  433. }
  434. }
  435. /* Check for long conditional equality or inequality. This requires
  436. * 2 CMPs and 2 branches */
  437. else if (pIcode->ll()->match(iCMP) && (isLong22 (pIcode, pEnd, long_loc)))
  438. {
  439. if (checkLongRegEq (pLocId.longId(), pIcode, loc_ident_idx, this, asgn, *long_loc->ll()) )
  440. {
  441. // TODO: verify that removing -1 does not change anything !
  442. advance(pIcode,longJCond22 (asgn, pIcode,pEnd));
  443. }
  444. }
  445. /* Check for OR regH, regL
  446. * JX lab
  447. * => HLI_JCOND (regH:regL X 0) lab
  448. * This is better code than HLI_JCOND (HI(regH:regL) | LO(regH:regL)) */
  449. else if (pIcode->ll()->match(iOR) && (next1 != pEnd) && (isJCond ((llIcode)next1->ll()->getOpcode())))
  450. {
  451. if (pLocId.longId().srcDstRegMatch(pIcode,pIcode))
  452. {
  453. asgn.lhs = AstIdent::LongIdx (loc_ident_idx);
  454. asgn.rhs = new Constant(0, 4); /* long 0 */
  455. asgn.lhs = new BinaryOperator(condOpJCond[next1->ll()->getOpcode() - iJB],asgn.lhs, asgn.rhs);
  456. next1->setJCond(asgn.lhs);
  457. next1->copyDU(*pIcode, eUSE, eUSE);
  458. pIcode->invalidate();
  459. }
  460. }
  461. } /* end for */
  462. return 0;
  463. }
  464. /** Finds the definition of the long register pointed to by pLocId, and
  465. * transforms that instruction into a HIGH_LEVEL icode instruction.
  466. * @arg i index into the local identifier table
  467. * @arg pLocId ptr to the long local identifier
  468. *
  469. */
  470. void Function::propLongReg (int loc_ident_idx, const ID &pLocId)
  471. {
  472. /* Process all definitions/uses of long registers at an icode position */
  473. // WARNING: this loop modifies the iterated-over container.
  474. //size_t initial_size=pLocId.idx.size();
  475. for (size_t j = 0; j < pLocId.idx.size(); j++)
  476. {
  477. auto idx_iter=pLocId.idx.begin();
  478. std::advance(idx_iter,j);
  479. /* Check backwards for a definition of this long register */
  480. if (findBackwarLongDefs(loc_ident_idx,pLocId,*idx_iter))
  481. {
  482. //assert(initial_size==pLocId.idx.size());
  483. continue;
  484. }
  485. /* If no definition backwards, check forward for a use of this long reg */
  486. findForwardLongUses(loc_ident_idx,pLocId,*idx_iter);
  487. //assert(initial_size==pLocId.idx.size());
  488. } /* end for */
  489. }
  490. /* Propagates the long global address across all LOW_LEVEL icodes.
  491. * Transforms some LOW_LEVEL icodes into HIGH_LEVEL */
  492. void Function::propLongGlb (int /*i*/, const ID &/*pLocId*/)
  493. {
  494. printf("WARN: Function::propLongGlb not implemented\n");
  495. }
  496. /* Propagated identifier information, thus converting some LOW_LEVEL icodes
  497. * into HIGH_LEVEL icodes. */
  498. void Function::propLong()
  499. {
  500. /* Pointer to current local identifier */
  501. //TODO: change into range based for
  502. for (size_t i = 0; i < localId.csym(); i++)
  503. {
  504. const ID &pLocId(localId.id_arr[i]);
  505. if ((pLocId.type!=TYPE_LONG_SIGN) and (pLocId.type!=TYPE_LONG_UNSIGN))
  506. continue;
  507. switch (pLocId.loc)
  508. {
  509. case STK_FRAME:
  510. propLongStk (i, pLocId);
  511. break;
  512. case REG_FRAME:
  513. propLongReg (i, pLocId);
  514. break;
  515. case GLB_FRAME:
  516. propLongGlb (i, pLocId);
  517. break;
  518. }
  519. }
  520. }