blob: eba98c0bafb4a4068f208c5c1058acfcee6ba40d [file] [log] [blame]
Jim Stichnothf7c9a142014-04-29 10:52:43 -07001//===- 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
21namespace Ice {
22
23class CfgNode {
24public:
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 Schimpfc132b762014-09-11 09:43:47 -070032 void setName(IceString &NewName) {
33 // Make sure that the name can only be set once.
34 assert(Name.empty());
35 Name = NewName;
36 }
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -070037 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 Stichnothf7c9a142014-04-29 10:52:43 -070045
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 Stichnothd97c7df2014-06-04 11:57:08 -070053 void renumberInstructions();
Jim Stichnothf7c9a142014-04-29 10:52:43 -070054
55 // Add a predecessor edge to the InEdges list for each of this
56 // node's successors.
57 void computePredecessors();
58
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -070059 void placePhiLoads();
60 void placePhiStores();
61 void deletePhis();
Jim Stichnothd97c7df2014-06-04 11:57:08 -070062 void doAddressOpt();
Matt Walac3302742014-08-15 16:21:56 -070063 void doNopInsertion();
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -070064 void genCode();
Jim Stichnothd97c7df2014-06-04 11:57:08 -070065 void livenessLightweight();
66 bool liveness(Liveness *Liveness);
67 void livenessPostprocess(LivenessMode Mode, Liveness *Liveness);
Jim Stichnothff9c7062014-09-18 04:50:49 -070068 void doBranchOpt(const CfgNode *NextNode);
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -070069 void emit(Cfg *Func) const;
Jim Stichnothf7c9a142014-04-29 10:52:43 -070070 void dump(Cfg *Func) const;
71
72private:
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 Stichnoth5bc2b1d2014-05-22 13:38:48 -070079 bool HasReturn; // does this block need an epilog?
Jim Stichnothf7c9a142014-04-29 10:52:43 -070080 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