AbstractBlockBase.java revision 12651:6ef01bd40ce2
1191271Srwatson/*
2191271Srwatson * Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved.
3191271Srwatson * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4191271Srwatson *
5191271Srwatson * This code is free software; you can redistribute it and/or modify it
6191271Srwatson * under the terms of the GNU General Public License version 2 only, as
7191271Srwatson * published by the Free Software Foundation.
8191271Srwatson *
9191271Srwatson * This code is distributed in the hope that it will be useful, but WITHOUT
10191271Srwatson * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11191271Srwatson * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12191271Srwatson * version 2 for more details (a copy is included in the LICENSE file that
13191271Srwatson * accompanied this code).
14191271Srwatson *
15191271Srwatson * You should have received a copy of the GNU General Public License version
16191271Srwatson * 2 along with this work; if not, write to the Free Software Foundation,
17191271Srwatson * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18191271Srwatson *
19191271Srwatson * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20191271Srwatson * or visit www.oracle.com if you need additional information or have any
21191271Srwatson * questions.
22191271Srwatson */
23191271Srwatsonpackage org.graalvm.compiler.core.common.cfg;
24191271Srwatson
25191271Srwatsonimport java.util.Collections;
26191271Srwatsonimport java.util.List;
27191271Srwatson
28191271Srwatsonpublic abstract class AbstractBlockBase<T extends AbstractBlockBase<T>> {
29191271Srwatson
30191271Srwatson    protected int id;
31191271Srwatson    protected int domDepth;
32191271Srwatson
33191271Srwatson    protected T[] predecessors;
34191271Srwatson    protected T[] successors;
35191271Srwatson
36191271Srwatson    private T dominator;
37191271Srwatson    private List<T> dominated;
38191271Srwatson    private int domNumber;
39191271Srwatson    private int maxChildDomNumber;
40191271Srwatson
41191271Srwatson    private boolean align;
42191271Srwatson    private int linearScanNumber;
43191271Srwatson
44191271Srwatson    protected AbstractBlockBase() {
45191271Srwatson        this.id = AbstractControlFlowGraph.BLOCK_ID_INITIAL;
46191271Srwatson        this.linearScanNumber = -1;
47191271Srwatson        this.domNumber = -1;
48191271Srwatson        this.maxChildDomNumber = -1;
49191271Srwatson    }
50191271Srwatson
51191271Srwatson    public void setDominatorNumber(int domNumber) {
52191271Srwatson        this.domNumber = domNumber;
53191271Srwatson    }
54191271Srwatson
55191271Srwatson    public void setMaxChildDomNumber(int maxChildDomNumber) {
56191271Srwatson        this.maxChildDomNumber = maxChildDomNumber;
57191271Srwatson    }
58191271Srwatson
59191271Srwatson    public int getDominatorNumber() {
60191271Srwatson        return domNumber;
61191271Srwatson    }
62191271Srwatson
63191271Srwatson    public int getMaxChildDominatorNumber() {
64191271Srwatson        return this.maxChildDomNumber;
65191271Srwatson    }
66191271Srwatson
67191271Srwatson    public int getId() {
68191271Srwatson        return id;
69191271Srwatson    }
70191271Srwatson
71191271Srwatson    public void setId(int id) {
72191271Srwatson        this.id = id;
73191271Srwatson    }
74191271Srwatson
75191271Srwatson    public T[] getPredecessors() {
76191271Srwatson        return predecessors;
77191271Srwatson    }
78191271Srwatson
79191271Srwatson    public void setPredecessors(T[] predecessors) {
80191271Srwatson        this.predecessors = predecessors;
81191271Srwatson    }
82191271Srwatson
83191271Srwatson    public T[] getSuccessors() {
84191271Srwatson        return successors;
85191271Srwatson    }
86191271Srwatson
87191271Srwatson    public void setSuccessors(T[] successors) {
88191271Srwatson        this.successors = successors;
89191271Srwatson    }
90191271Srwatson
91191271Srwatson    public T getDominator() {
92191271Srwatson        return dominator;
93191271Srwatson    }
94191271Srwatson
95191271Srwatson    public void setDominator(T dominator) {
96191271Srwatson        this.dominator = dominator;
97191271Srwatson        this.domDepth = dominator.domDepth + 1;
98191271Srwatson    }
99191271Srwatson
100191271Srwatson    public int getDominatorDepth() {
101191271Srwatson        return domDepth;
102191271Srwatson    }
103191271Srwatson
104191271Srwatson    public List<T> getDominated() {
105191271Srwatson        if (dominated == null) {
106191271Srwatson            return Collections.emptyList();
107191271Srwatson        }
108191271Srwatson        return dominated;
109191271Srwatson    }
110191271Srwatson
111191271Srwatson    public void setDominated(List<T> blocks) {
112191271Srwatson        dominated = blocks;
113191271Srwatson    }
114191271Srwatson
115191271Srwatson    @Override
116191271Srwatson    public String toString() {
117191271Srwatson        return "B" + id;
118191271Srwatson    }
119191271Srwatson
120191271Srwatson    public int getPredecessorCount() {
121191271Srwatson        return getPredecessors().length;
122191271Srwatson    }
123191271Srwatson
124191271Srwatson    public int getSuccessorCount() {
125191271Srwatson        return getSuccessors().length;
126191271Srwatson    }
127191271Srwatson
128191271Srwatson    public int getLinearScanNumber() {
129191271Srwatson        return linearScanNumber;
130191271Srwatson    }
131191271Srwatson
132191271Srwatson    public void setLinearScanNumber(int linearScanNumber) {
133191271Srwatson        this.linearScanNumber = linearScanNumber;
134191271Srwatson    }
135191271Srwatson
136191271Srwatson    public boolean isAligned() {
137191271Srwatson        return align;
138191271Srwatson    }
139191271Srwatson
140191271Srwatson    public void setAlign(boolean align) {
141191271Srwatson        this.align = align;
142191271Srwatson    }
143191271Srwatson
144191271Srwatson    public abstract boolean isExceptionEntry();
145191271Srwatson
146191271Srwatson    public abstract Loop<T> getLoop();
147191271Srwatson
148191271Srwatson    public abstract int getLoopDepth();
149191271Srwatson
150191271Srwatson    public abstract void delete();
151191271Srwatson
152191271Srwatson    public abstract boolean isLoopEnd();
153191271Srwatson
154191271Srwatson    public abstract boolean isLoopHeader();
155191271Srwatson
156191271Srwatson    public abstract T getPostdominator();
157191271Srwatson
158191271Srwatson    public abstract double probability();
159191271Srwatson
160191271Srwatson    public abstract T getDominator(int distance);
161191271Srwatson}
162191271Srwatson