BasicBlock.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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() : 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. iICODE range_start;
  40. iICODE range_end;
  41. public:
  42. iICODE begin();
  43. iICODE end() const;
  44. riICODE rbegin();
  45. riICODE rend();
  46. ICODE &front();
  47. ICODE &back();
  48. size_t size();
  49. uint8_t nodeType; /* Type of node */
  50. int traversed; /* Boolean: traversed yet? */
  51. int numHlIcodes; /* No. of high-level icodes */
  52. uint32_t 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. std::bitset<32> liveUse; /* LiveUse(b) */
  68. std::bitset<32> def; /* Def(b) */
  69. std::bitset<32> liveIn; /* LiveIn(b) */
  70. std::bitset<32> 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, uint8_t 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(std::ostream &ostr, int lev, Function *pProc, int *numLoc);
  99. BB *rmJMP(int marker, BB *pBB);
  100. void genDU1();
  101. private:
  102. Function *Parent;
  103. };