BasicBlock.h 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #pragma once
  2. #include <list>
  3. #include <vector>
  4. #include <string>
  5. #include "types.h"
  6. /* Basic block (BB) node definition */
  7. struct Function;
  8. class CIcodeRec;
  9. struct BB;
  10. struct interval;
  11. typedef union
  12. {
  13. dword ip; /* Out edge icode address */
  14. BB * BBptr; /* Out edge pointer to next BB */
  15. interval *intPtr; /* Out edge ptr to next interval*/
  16. } TYPEADR_TYPE;
  17. struct BB
  18. {
  19. protected:
  20. BB(const BB&);
  21. BB() : nodeType(0),traversed(0),start(0),length(0),
  22. numHlIcodes(0),flg(0),
  23. numInEdges(0),inEdges(0),
  24. numOutEdges(0),edges(0),beenOnH(0),inEdgeCount(0),reachingInt(0),
  25. inInterval(0),correspInt(0),liveUse(0),def(0),liveIn(0),liveOut(0),
  26. dfsFirstNum(0),dfsLastNum(0),immedDom(0),ifFollow(0),loopType(0),latchNode(0),
  27. numBackEdges(0),loopHead(0),loopFollow(0),caseHead(0),caseTail(0),index(0)
  28. {
  29. }
  30. public:
  31. byte nodeType; /* Type of node */
  32. Int traversed; /* Boolean: traversed yet? */
  33. Int start; /* First instruction offset */
  34. Int length; /* No. of instructions this BB */
  35. Int numHlIcodes; /* No. of high-level icodes */
  36. flags32 flg; /* BB flags */
  37. /* In edges and out edges */
  38. Int numInEdges; /* Number of in edges */
  39. std::vector<BB *> inEdges; // does not own held pointers
  40. Int numOutEdges; /* Number of out edges */
  41. std::vector<TYPEADR_TYPE> edges;/* Array of ptrs. to out edges */
  42. /* For interval construction */
  43. Int beenOnH; /* #times been on header list H */
  44. Int inEdgeCount; /* #inEdges (to find intervals) */
  45. BB * reachingInt; /* Reaching interval header */
  46. interval *inInterval; /* Node's interval */
  47. /* For derived sequence construction */
  48. interval *correspInt; /* Corresponding interval in
  49. * derived graph Gi-1 */
  50. /* For live register analysis
  51. * LiveIn(b) = LiveUse(b) U (LiveOut(b) - Def(b)) */
  52. dword liveUse; /* LiveUse(b) */
  53. dword def; /* Def(b) */
  54. dword liveIn; /* LiveIn(b) */
  55. dword liveOut; /* LiveOut(b) */
  56. /* For structuring analysis */
  57. Int dfsFirstNum; /* DFS #: first visit of node */
  58. Int dfsLastNum; /* DFS #: last visit of node */
  59. Int immedDom; /* Immediate dominator (dfsLast
  60. * index) */
  61. Int ifFollow; /* node that ends the if */
  62. Int loopType; /* Type of loop (if any) */
  63. Int latchNode; /* latching node of the loop */
  64. Int numBackEdges; /* # of back edges */
  65. Int loopHead; /* most nested loop head to which
  66. * thcis node belongs (dfsLast) */
  67. Int loopFollow; /* node that follows the loop */
  68. Int caseHead; /* most nested case to which this
  69. node belongs (dfsLast) */
  70. Int caseTail; /* tail node for the case */
  71. Int index; /* Index, used in several ways */
  72. static BB *Create(void *ctx=0,const std::string &s="",Function *parent=0,BB *insertBefore=0);
  73. static BB *Create(Int start, Int ip, byte nodeType, Int numOutEdges, Function * parent);
  74. void writeCode(Int indLevel, Function *pProc, Int *numLoc, Int latchNode, Int ifFollow);
  75. void mergeFallThrough(CIcodeRec &Icode);
  76. void dfsNumbering(std::vector<BB *> &dfsLast, Int *first, Int *last);
  77. void displayDfs();
  78. };