BasicBlock.h 4.7 KB

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