BasicBlock.h 4.4 KB

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