1 /*
2  * Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved.
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * This code is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License version 2 only, as
7  * published by the Free Software Foundation.
8  *
9  * This code is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12  * version 2 for more details (a copy is included in the LICENSE file that
13  * accompanied this code).
14  *
15  * You should have received a copy of the GNU General Public License version
16  * 2 along with this work; if not, write to the Free Software Foundation,
17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18  *
19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20  * or visit www.oracle.com if you need additional information or have any
21  * questions.
22  */
23 
24 
25 package org.graalvm.compiler.core.common.cfg;
26 
27 public abstract class AbstractBlockBase<T extends AbstractBlockBase<T>> {
28 
29     protected int id;
30     protected int domDepth;
31 
32     protected T[] predecessors;
33     protected T[] successors;
34 
35     private T dominator;
36     private T firstDominated;
37     private T dominatedSibling;
38     private int domNumber;
39     private int maxChildDomNumber;
40 
41     private boolean align;
42     private int linearScanNumber;
43 
AbstractBlockBase()44     protected AbstractBlockBase() {
45         this.id = AbstractControlFlowGraph.BLOCK_ID_INITIAL;
46         this.linearScanNumber = -1;
47         this.domNumber = -1;
48         this.maxChildDomNumber = -1;
49     }
50 
setDominatorNumber(int domNumber)51     public void setDominatorNumber(int domNumber) {
52         this.domNumber = domNumber;
53     }
54 
setMaxChildDomNumber(int maxChildDomNumber)55     public void setMaxChildDomNumber(int maxChildDomNumber) {
56         this.maxChildDomNumber = maxChildDomNumber;
57     }
58 
getDominatorNumber()59     public int getDominatorNumber() {
60         return domNumber;
61     }
62 
getMaxChildDominatorNumber()63     public int getMaxChildDominatorNumber() {
64         return this.maxChildDomNumber;
65     }
66 
getId()67     public int getId() {
68         return id;
69     }
70 
setId(int id)71     public void setId(int id) {
72         this.id = id;
73     }
74 
getPredecessors()75     public T[] getPredecessors() {
76         return predecessors;
77     }
78 
setPredecessors(T[] predecessors)79     public void setPredecessors(T[] predecessors) {
80         this.predecessors = predecessors;
81     }
82 
getSuccessors()83     public T[] getSuccessors() {
84         return successors;
85     }
86 
setSuccessors(T[] successors)87     public void setSuccessors(T[] successors) {
88         this.successors = successors;
89     }
90 
getDominator()91     public T getDominator() {
92         return dominator;
93     }
94 
setDominator(T dominator)95     public void setDominator(T dominator) {
96         this.dominator = dominator;
97         this.domDepth = dominator.domDepth + 1;
98     }
99 
100     /**
101      * Level in the dominator tree starting with 0 for the start block.
102      */
getDominatorDepth()103     public int getDominatorDepth() {
104         return domDepth;
105     }
106 
getFirstDominated()107     public T getFirstDominated() {
108         return this.firstDominated;
109     }
110 
setFirstDominated(T block)111     public void setFirstDominated(T block) {
112         this.firstDominated = block;
113     }
114 
getDominatedSibling()115     public T getDominatedSibling() {
116         return this.dominatedSibling;
117     }
118 
setDominatedSibling(T block)119     public void setDominatedSibling(T block) {
120         this.dominatedSibling = block;
121     }
122 
123     @Override
toString()124     public String toString() {
125         return "B" + id;
126     }
127 
getPredecessorCount()128     public int getPredecessorCount() {
129         return getPredecessors().length;
130     }
131 
getSuccessorCount()132     public int getSuccessorCount() {
133         return getSuccessors().length;
134     }
135 
getLinearScanNumber()136     public int getLinearScanNumber() {
137         return linearScanNumber;
138     }
139 
setLinearScanNumber(int linearScanNumber)140     public void setLinearScanNumber(int linearScanNumber) {
141         this.linearScanNumber = linearScanNumber;
142     }
143 
isAligned()144     public boolean isAligned() {
145         return align;
146     }
147 
setAlign(boolean align)148     public void setAlign(boolean align) {
149         this.align = align;
150     }
151 
isExceptionEntry()152     public abstract boolean isExceptionEntry();
153 
getLoop()154     public abstract Loop<T> getLoop();
155 
getLoopDepth()156     public abstract int getLoopDepth();
157 
delete()158     public abstract void delete();
159 
isLoopEnd()160     public abstract boolean isLoopEnd();
161 
isLoopHeader()162     public abstract boolean isLoopHeader();
163 
getPostdominator()164     public abstract T getPostdominator();
165 
probability()166     public abstract double probability();
167 
getDominator(int distance)168     public abstract T getDominator(int distance);
169 
170     @Override
hashCode()171     public int hashCode() {
172         return id;
173     }
174 }
175