Procedure.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. #pragma once
  2. #include <llvm/ADT/ilist.h>
  3. #include <llvm/ADT/ilist_node.h>
  4. #include "BasicBlock.h"
  5. #include "types.h"
  6. #include "ast.h"
  7. #include "icode.h"
  8. #include "locident.h"
  9. #include "error.h"
  10. #include "graph.h"
  11. #include "bundle.h"
  12. #include "StackFrame.h"
  13. /* PROCEDURE NODE */
  14. struct CALL_GRAPH;
  15. namespace llvm
  16. {
  17. // Traits for intrusive list of basic blocks...
  18. template<>
  19. struct ilist_traits<BB> : public ilist_default_traits<BB>
  20. {
  21. // createSentinel is used to get hold of the node that marks the end of the
  22. // list... (same trick used here as in ilist_traits<Instruction>)
  23. BB *createSentinel() const {
  24. return static_cast<BB*>(&Sentinel);
  25. }
  26. static void destroySentinel(BB*) {}
  27. BB *provideInitialHead() const { return createSentinel(); }
  28. BB *ensureHead(BB*) const { return createSentinel(); }
  29. static void noteHead(BB*, BB*) {}
  30. //static ValueSymbolTable *getSymTab(Function *ItemParent);
  31. private:
  32. mutable ilist_half_node<BB> Sentinel;
  33. };
  34. }
  35. struct FunctionType
  36. {
  37. bool m_vararg;
  38. bool isVarArg() const {return m_vararg;}
  39. };
  40. struct Function : public llvm::ilist_node<Function>
  41. {
  42. typedef llvm::iplist<BB> BasicBlockListType;
  43. // BasicBlock iterators...
  44. typedef BasicBlockListType::iterator iterator;
  45. typedef BasicBlockListType::const_iterator const_iterator;
  46. private:
  47. BasicBlockListType BasicBlocks; ///< The basic blocks
  48. public:
  49. dword procEntry; /* label number */
  50. char name[SYMLEN]; /* Meaningful name for this proc */
  51. STATE state; /* Entry state */
  52. Int depth; /* Depth at which we found it - for printing */
  53. flags32 flg; /* Combination of Icode & Proc flags */
  54. int16 cbParam; /* Probable no. of bytes of parameters */
  55. STKFRAME args; /* Array of arguments */
  56. LOCAL_ID localId; /* Local identifiers */
  57. ID retVal; /* Return value - identifier */
  58. /* Icodes and control flow graph */
  59. CIcodeRec Icode; /* Object with ICODE records */
  60. std::vector<BB*> cfg; /* Ptr. to BB list/CFG */
  61. std::vector<BB*> dfsLast;
  62. std::vector<BB*> heldBBs;
  63. //BB * *dfsLast; /* Array of pointers to BBs in dfsLast
  64. // * (reverse postorder) order */
  65. Int numBBs; /* Number of BBs in the graph cfg */
  66. boolT hasCase; /* Procedure has a case node */
  67. /* For interprocedural live analysis */
  68. dword liveIn; /* Registers used before defined */
  69. dword liveOut; /* Registers that may be used in successors */
  70. boolT liveAnal; /* Procedure has been analysed already */
  71. Function(void *ty=0) : procEntry(0),depth(0),flg(0),cbParam(0),cfg(0),dfsLast(0),numBBs(0),
  72. hasCase(false),liveIn(0),liveOut(0),liveAnal(0)//,next(0),prev(0)
  73. {
  74. memset(name,0,SYMLEN);
  75. }
  76. public:
  77. static Function *Create(void *ty=0,int Linkage=0,const std::string &nm="",void *module=0)
  78. {
  79. return new Function(ty);
  80. }
  81. void compoundCond();
  82. void writeProcComments();
  83. void lowLevelAnalysis();
  84. void bindIcodeOff();
  85. void dataFlow(dword liveOut);
  86. void compressCFG();
  87. void highLevelGen();
  88. void structure(derSeq *derivedG);
  89. derSeq *checkReducibility();
  90. void createCFG();
  91. void markImpure();
  92. void findImmedDom();
  93. void FollowCtrl(CALL_GRAPH *pcallGraph, STATE *pstate);
  94. void process_operands(ICODE *pIcode, STATE *pstate);
  95. boolT process_JMP(ICODE *pIcode, STATE *pstate, CALL_GRAPH *pcallGraph);
  96. boolT process_CALL(ICODE *pIcode, CALL_GRAPH *pcallGraph, STATE *pstate);
  97. void displayCFG();
  98. void freeCFG();
  99. void codeGen(std::ostream &fs);
  100. void displayStats();
  101. void mergeFallThrough(BB *pBB);
  102. void structIfs();
  103. void structLoops(derSeq *derivedG);
  104. void buildCFG();
  105. void controlFlowAnalysis();
  106. void newRegArg(ICODE *picode, ICODE *ticode);
  107. protected:
  108. void structCases();
  109. void findExps();
  110. void genDU1();
  111. void elimCondCodes();
  112. void liveRegAnalysis(dword in_liveOut);
  113. void findIdioms();
  114. void propLong();
  115. void genLiveKtes();
  116. byte findDerivedSeq (derSeq *derivedGi);
  117. bool nextOrderGraph(derSeq *derivedGi);
  118. };