blob: e4fe2f9acdff15e93deb0b4ce947fde16b49670b [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"
Jim Stichnoth607e9f02014-11-06 13:32:05 -080020#include "IceInst.h" // InstList traits
Jim Stichnothf7c9a142014-04-29 10:52:43 -070021
22namespace Ice {
23
24class CfgNode {
Jim Stichnothc6ead202015-02-24 09:30:30 -080025 CfgNode() = delete;
Jim Stichnoth7b451a92014-10-15 14:39:23 -070026 CfgNode(const CfgNode &) = delete;
27 CfgNode &operator=(const CfgNode &) = delete;
28
Jim Stichnothf7c9a142014-04-29 10:52:43 -070029public:
Jim Stichnoth668a7a32014-12-10 15:32:25 -080030 static CfgNode *create(Cfg *Func, SizeT LabelIndex) {
31 return new (Func->allocate<CfgNode>()) CfgNode(Func, LabelIndex);
Jim Stichnothf7c9a142014-04-29 10:52:43 -070032 }
33
34 // Access the label number and name for this node.
35 SizeT getIndex() const { return Number; }
Jim Stichnoth69d3f9c2015-03-23 10:33:38 -070036 void resetIndex(SizeT NewNumber) { Number = NewNumber; }
Jim Stichnothf7c9a142014-04-29 10:52:43 -070037 IceString getName() const;
Jim Stichnoth668a7a32014-12-10 15:32:25 -080038 void setName(const IceString &NewName) {
Karl Schimpfc132b762014-09-11 09:43:47 -070039 // Make sure that the name can only be set once.
Jim Stichnoth9a04c072014-12-11 15:51:42 -080040 assert(NameIndex == Cfg::IdentifierIndexInvalid);
Jim Stichnoth668a7a32014-12-10 15:32:25 -080041 if (!NewName.empty())
Jim Stichnoth9a04c072014-12-11 15:51:42 -080042 NameIndex = Func->addIdentifierName(NewName);
Karl Schimpfc132b762014-09-11 09:43:47 -070043 }
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -070044 IceString getAsmName() const {
45 return ".L" + Func->getFunctionName() + "$" + getName();
46 }
47
48 // The HasReturn flag indicates that this node contains a return
49 // instruction and therefore needs an epilog.
50 void setHasReturn() { HasReturn = true; }
51 bool getHasReturn() const { return HasReturn; }
Jim Stichnothf7c9a142014-04-29 10:52:43 -070052
Jim Stichnoth336f6c42014-10-30 15:01:31 -070053 void setNeedsPlacement(bool Value) { NeedsPlacement = Value; }
54 bool needsPlacement() const { return NeedsPlacement; }
55
Jim Stichnothf7c9a142014-04-29 10:52:43 -070056 // Access predecessor and successor edge lists.
57 const NodeList &getInEdges() const { return InEdges; }
58 const NodeList &getOutEdges() const { return OutEdges; }
59
60 // Manage the instruction list.
61 InstList &getInsts() { return Insts; }
Jim Stichnoth98712a32014-10-24 10:59:02 -070062 PhiList &getPhis() { return Phis; }
Jim Stichnothf7c9a142014-04-29 10:52:43 -070063 void appendInst(Inst *Inst);
Jim Stichnothd97c7df2014-06-04 11:57:08 -070064 void renumberInstructions();
Jim Stichnoth47752552014-10-13 17:15:08 -070065 // Rough and generally conservative estimate of the number of
66 // instructions in the block. It is updated when an instruction is
67 // added, but not when deleted. It is recomputed during
68 // renumberInstructions().
69 InstNumberT getInstCountEstimate() const { return InstCountEstimate; }
Jim Stichnothf7c9a142014-04-29 10:52:43 -070070
71 // Add a predecessor edge to the InEdges list for each of this
72 // node's successors.
73 void computePredecessors();
Jim Stichnoth69d3f9c2015-03-23 10:33:38 -070074 void computeSuccessors();
Jim Stichnoth336f6c42014-10-30 15:01:31 -070075 CfgNode *splitIncomingEdge(CfgNode *Pred, SizeT InEdgeIndex);
Jim Stichnothf7c9a142014-04-29 10:52:43 -070076
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -070077 void placePhiLoads();
78 void placePhiStores();
79 void deletePhis();
Jim Stichnoth336f6c42014-10-30 15:01:31 -070080 void advancedPhiLowering();
Jim Stichnothd97c7df2014-06-04 11:57:08 -070081 void doAddressOpt();
Matt Walac3302742014-08-15 16:21:56 -070082 void doNopInsertion();
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -070083 void genCode();
Jim Stichnothd97c7df2014-06-04 11:57:08 -070084 void livenessLightweight();
85 bool liveness(Liveness *Liveness);
Jim Stichnothe5b73e62014-12-15 09:58:51 -080086 void livenessAddIntervals(Liveness *Liveness, InstNumberT FirstInstNum,
87 InstNumberT LastInstNum);
Jim Stichnoth336f6c42014-10-30 15:01:31 -070088 void contractIfEmpty();
Jim Stichnothff9c7062014-09-18 04:50:49 -070089 void doBranchOpt(const CfgNode *NextNode);
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -070090 void emit(Cfg *Func) const;
Jan Voung0faec4c2014-11-05 17:29:56 -080091 void emitIAS(Cfg *Func) const;
Jim Stichnothf7c9a142014-04-29 10:52:43 -070092 void dump(Cfg *Func) const;
93
94private:
Jim Stichnoth668a7a32014-12-10 15:32:25 -080095 CfgNode(Cfg *Func, SizeT LabelIndex);
Jim Stichnothf7c9a142014-04-29 10:52:43 -070096 Cfg *const Func;
Jim Stichnoth69d3f9c2015-03-23 10:33:38 -070097 SizeT Number; // label index
Jim Stichnoth9a04c072014-12-11 15:51:42 -080098 Cfg::IdentifierIndexType NameIndex; // index into Cfg::NodeNames table
Jim Stichnothdd842db2015-01-27 12:53:53 -080099 bool HasReturn; // does this block need an epilog?
Jim Stichnoth336f6c42014-10-30 15:01:31 -0700100 bool NeedsPlacement;
Jim Stichnoth47752552014-10-13 17:15:08 -0700101 InstNumberT InstCountEstimate; // rough instruction count estimate
Jim Stichnothdd842db2015-01-27 12:53:53 -0800102 NodeList InEdges; // in no particular order
103 NodeList OutEdges; // in no particular order
104 PhiList Phis; // unordered set of phi instructions
105 InstList Insts; // ordered list of non-phi instructions
Jim Stichnothf7c9a142014-04-29 10:52:43 -0700106};
107
108} // end of namespace Ice
109
110#endif // SUBZERO_SRC_ICECFGNODE_H