BasicBlock.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. #pragma once
  2. #include <list>
  3. #include <vector>
  4. #include <string>
  5. #include <llvm/ADT/ilist.h>
  6. #include <llvm/ADT/ilist_node.h>
  7. #include "types.h"
  8. #include "graph.h"
  9. #include "icode.h"
  10. /* Basic block (BB) node definition */
  11. struct Function;
  12. class CIcodeRec;
  13. struct BB;
  14. struct interval;
  15. struct ICODE;
  16. typedef union
  17. {
  18. dword ip; /* Out edge icode address */
  19. BB * BBptr; /* Out edge pointer to next BB */
  20. interval *intPtr; /* Out edge ptr to next interval*/
  21. } TYPEADR_TYPE;
  22. struct BB : public llvm::ilist_node<BB>
  23. {
  24. private:
  25. BB(const BB&);
  26. BB() : start(0),length(0),nodeType(0),traversed(0),
  27. numHlIcodes(0),flg(0),
  28. inEdges(0),
  29. edges(0),beenOnH(0),inEdgeCount(0),reachingInt(0),
  30. inInterval(0),correspInt(0),liveUse(0),def(0),liveIn(0),liveOut(0),
  31. dfsFirstNum(0),dfsLastNum(0),immedDom(0),ifFollow(0),loopType(0),latchNode(0),
  32. numBackEdges(0),loopHead(0),loopFollow(0),caseHead(0),caseTail(0),index(0)
  33. {
  34. }
  35. //friend class SymbolTableListTraits<BB, Function>;
  36. //Int numInEdges; /* Number of in edges */
  37. Int start; /* First instruction offset */
  38. Int length; /* No. of instructions this BB */
  39. public:
  40. Int begin();
  41. iICODE begin2();
  42. iICODE end2();
  43. Int end();
  44. Int rbegin();
  45. Int rend();
  46. riICODE rbegin2();
  47. riICODE rend2();
  48. ICODE &front();
  49. ICODE &back();
  50. size_t size();
  51. byte nodeType; /* Type of node */
  52. int traversed; /* Boolean: traversed yet? */
  53. Int numHlIcodes; /* No. of high-level icodes */
  54. flags32 flg; /* BB flags */
  55. /* In edges and out edges */
  56. std::vector<BB *> inEdges; // does not own held pointers
  57. //Int numOutEdges; /* Number of out edges */
  58. std::vector<TYPEADR_TYPE> edges;/* Array of ptrs. to out edges */
  59. /* For interval construction */
  60. Int beenOnH; /* #times been on header list H */
  61. Int inEdgeCount; /* #inEdges (to find intervals) */
  62. BB * reachingInt; /* Reaching interval header */
  63. interval *inInterval; /* Node's interval */
  64. /* For derived sequence construction */
  65. interval *correspInt; /* Corresponding interval in
  66. * derived graph Gi-1 */
  67. /* For live register analysis
  68. * LiveIn(b) = LiveUse(b) U (LiveOut(b) - Def(b)) */
  69. std::bitset<32> liveUse; /* LiveUse(b) */
  70. std::bitset<32> def; /* Def(b) */
  71. std::bitset<32> liveIn; /* LiveIn(b) */
  72. std::bitset<32> liveOut; /* LiveOut(b) */
  73. /* For structuring analysis */
  74. Int dfsFirstNum; /* DFS #: first visit of node */
  75. Int dfsLastNum; /* DFS #: last visit of node */
  76. Int immedDom; /* Immediate dominator (dfsLast
  77. * index) */
  78. Int ifFollow; /* node that ends the if */
  79. Int loopType; /* Type of loop (if any) */
  80. Int latchNode; /* latching node of the loop */
  81. Int numBackEdges; /* # of back edges */
  82. Int loopHead; /* most nested loop head to which
  83. * thcis node belongs (dfsLast) */
  84. Int loopFollow; /* node that follows the loop */
  85. Int caseHead; /* most nested case to which this
  86. node belongs (dfsLast) */
  87. Int caseTail; /* tail node for the case */
  88. Int index; /* Index, used in several ways */
  89. static BB * Create(void *ctx=0,const std::string &s="",Function *parent=0,BB *insertBefore=0);
  90. static BB * Create(Int start, Int ip, byte nodeType, Int numOutEdges, Function * parent);
  91. void writeCode(Int indLevel, Function *pProc, Int *numLoc, Int latchNode, Int ifFollow);
  92. void mergeFallThrough(CIcodeRec &Icode);
  93. void dfsNumbering(std::vector<BB *> &dfsLast, Int *first, Int *last);
  94. void displayDfs();
  95. void display();
  96. /// getParent - Return the enclosing method, or null if none
  97. ///
  98. const Function *getParent() const { return Parent; }
  99. Function *getParent() { return Parent; }
  100. void writeBB(ICODE *hli, Int lev, Function *pProc, Int *numLoc);
  101. BB *rmJMP(Int marker, BB *pBB);
  102. private:
  103. Function *Parent;
  104. };