BasicBlock.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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() : nodeType(0),traversed(0),start(0),length(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. public:
  38. Int begin();
  39. iICODE begin2();
  40. iICODE end2();
  41. Int end();
  42. Int rbegin();
  43. Int rend();
  44. ICODE &front();
  45. ICODE &back();
  46. size_t size();
  47. byte nodeType; /* Type of node */
  48. int traversed; /* Boolean: traversed yet? */
  49. Int start; /* First instruction offset */
  50. Int length; /* No. of instructions this BB */
  51. Int numHlIcodes; /* No. of high-level icodes */
  52. flags32 flg; /* BB flags */
  53. /* In edges and out edges */
  54. std::vector<BB *> inEdges; // does not own held pointers
  55. //Int numOutEdges; /* Number of out edges */
  56. std::vector<TYPEADR_TYPE> edges;/* Array of ptrs. to out edges */
  57. /* For interval construction */
  58. Int beenOnH; /* #times been on header list H */
  59. Int inEdgeCount; /* #inEdges (to find intervals) */
  60. BB * reachingInt; /* Reaching interval header */
  61. interval *inInterval; /* Node's interval */
  62. /* For derived sequence construction */
  63. interval *correspInt; /* Corresponding interval in
  64. * derived graph Gi-1 */
  65. /* For live register analysis
  66. * LiveIn(b) = LiveUse(b) U (LiveOut(b) - Def(b)) */
  67. dword liveUse; /* LiveUse(b) */
  68. dword def; /* Def(b) */
  69. dword liveIn; /* LiveIn(b) */
  70. dword liveOut; /* LiveOut(b) */
  71. /* For structuring analysis */
  72. Int dfsFirstNum; /* DFS #: first visit of node */
  73. Int dfsLastNum; /* DFS #: last visit of node */
  74. Int immedDom; /* Immediate dominator (dfsLast
  75. * index) */
  76. Int ifFollow; /* node that ends the if */
  77. Int loopType; /* Type of loop (if any) */
  78. Int latchNode; /* latching node of the loop */
  79. Int numBackEdges; /* # of back edges */
  80. Int loopHead; /* most nested loop head to which
  81. * thcis node belongs (dfsLast) */
  82. Int loopFollow; /* node that follows the loop */
  83. Int caseHead; /* most nested case to which this
  84. node belongs (dfsLast) */
  85. Int caseTail; /* tail node for the case */
  86. Int index; /* Index, used in several ways */
  87. static BB *Create(void *ctx=0,const std::string &s="",Function *parent=0,BB *insertBefore=0);
  88. static BB *Create(Int start, Int ip, byte nodeType, Int numOutEdges, Function * parent);
  89. void writeCode(Int indLevel, Function *pProc, Int *numLoc, Int latchNode, Int ifFollow);
  90. void mergeFallThrough(CIcodeRec &Icode);
  91. void dfsNumbering(std::vector<BB *> &dfsLast, Int *first, Int *last);
  92. void displayDfs();
  93. void display();
  94. /// getParent - Return the enclosing method, or null if none
  95. ///
  96. const Function *getParent() const { return Parent; }
  97. Function *getParent() { return Parent; }
  98. void writeBB(ICODE *hli, Int lev, Function *pProc, Int *numLoc);
  99. BB *rmJMP(Int marker, BB *pBB);
  100. private:
  101. Function *Parent;
  102. };