Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 1 | //===- subzero/src/IceCfgNode.h - Control flow graph node -------*- C++ -*-===// |
| 2 | // |
| 3 | // The Subzero Code Generator |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file declares the CfgNode class, which represents a single |
| 11 | // basic block as its instruction list, in-edge list, and out-edge |
| 12 | // list. |
| 13 | // |
| 14 | //===----------------------------------------------------------------------===// |
| 15 | |
| 16 | #ifndef SUBZERO_SRC_ICECFGNODE_H |
| 17 | #define SUBZERO_SRC_ICECFGNODE_H |
| 18 | |
| 19 | #include "IceDefs.h" |
| 20 | |
| 21 | namespace Ice { |
| 22 | |
| 23 | class CfgNode { |
| 24 | public: |
| 25 | static CfgNode *create(Cfg *Func, SizeT LabelIndex, IceString Name = "") { |
| 26 | return new (Func->allocate<CfgNode>()) CfgNode(Func, LabelIndex, Name); |
| 27 | } |
| 28 | |
| 29 | // Access the label number and name for this node. |
| 30 | SizeT getIndex() const { return Number; } |
| 31 | IceString getName() const; |
Karl Schimpf | c132b76 | 2014-09-11 09:43:47 -0700 | [diff] [blame] | 32 | void setName(IceString &NewName) { |
| 33 | // Make sure that the name can only be set once. |
| 34 | assert(Name.empty()); |
| 35 | Name = NewName; |
| 36 | } |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 37 | IceString getAsmName() const { |
| 38 | return ".L" + Func->getFunctionName() + "$" + getName(); |
| 39 | } |
| 40 | |
| 41 | // The HasReturn flag indicates that this node contains a return |
| 42 | // instruction and therefore needs an epilog. |
| 43 | void setHasReturn() { HasReturn = true; } |
| 44 | bool getHasReturn() const { return HasReturn; } |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 45 | |
| 46 | // Access predecessor and successor edge lists. |
| 47 | const NodeList &getInEdges() const { return InEdges; } |
| 48 | const NodeList &getOutEdges() const { return OutEdges; } |
| 49 | |
| 50 | // Manage the instruction list. |
| 51 | InstList &getInsts() { return Insts; } |
| 52 | void appendInst(Inst *Inst); |
Jim Stichnoth | d97c7df | 2014-06-04 11:57:08 -0700 | [diff] [blame] | 53 | void renumberInstructions(); |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 54 | |
| 55 | // Add a predecessor edge to the InEdges list for each of this |
| 56 | // node's successors. |
| 57 | void computePredecessors(); |
| 58 | |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 59 | void placePhiLoads(); |
| 60 | void placePhiStores(); |
| 61 | void deletePhis(); |
Jim Stichnoth | d97c7df | 2014-06-04 11:57:08 -0700 | [diff] [blame] | 62 | void doAddressOpt(); |
Matt Wala | c330274 | 2014-08-15 16:21:56 -0700 | [diff] [blame] | 63 | void doNopInsertion(); |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 64 | void genCode(); |
Jim Stichnoth | d97c7df | 2014-06-04 11:57:08 -0700 | [diff] [blame] | 65 | void livenessLightweight(); |
| 66 | bool liveness(Liveness *Liveness); |
| 67 | void livenessPostprocess(LivenessMode Mode, Liveness *Liveness); |
Jim Stichnoth | ff9c706 | 2014-09-18 04:50:49 -0700 | [diff] [blame] | 68 | void doBranchOpt(const CfgNode *NextNode); |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 69 | void emit(Cfg *Func) const; |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 70 | void dump(Cfg *Func) const; |
| 71 | |
| 72 | private: |
| 73 | CfgNode(Cfg *Func, SizeT LabelIndex, IceString Name); |
| 74 | CfgNode(const CfgNode &) LLVM_DELETED_FUNCTION; |
| 75 | CfgNode &operator=(const CfgNode &) LLVM_DELETED_FUNCTION; |
| 76 | Cfg *const Func; |
| 77 | const SizeT Number; // label index |
| 78 | IceString Name; // for dumping only |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 79 | bool HasReturn; // does this block need an epilog? |
Jim Stichnoth | f7c9a14 | 2014-04-29 10:52:43 -0700 | [diff] [blame] | 80 | NodeList InEdges; // in no particular order |
| 81 | NodeList OutEdges; // in no particular order |
| 82 | PhiList Phis; // unordered set of phi instructions |
| 83 | InstList Insts; // ordered list of non-phi instructions |
| 84 | }; |
| 85 | |
| 86 | } // end of namespace Ice |
| 87 | |
| 88 | #endif // SUBZERO_SRC_ICECFGNODE_H |