001/*
002 * Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved.
003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004 *
005 * This code is free software; you can redistribute it and/or modify it
006 * under the terms of the GNU General Public License version 2 only, as
007 * published by the Free Software Foundation.
008 *
009 * This code is distributed in the hope that it will be useful, but WITHOUT
010 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
011 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
012 * version 2 for more details (a copy is included in the LICENSE file that
013 * accompanied this code).
014 *
015 * You should have received a copy of the GNU General Public License version
016 * 2 along with this work; if not, write to the Free Software Foundation,
017 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
018 *
019 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
020 * or visit www.oracle.com if you need additional information or have any
021 * questions.
022 */
023package com.oracle.graal.compiler.common.cfg;
024
025import java.util.*;
026
027public abstract class AbstractBlockBase<T extends AbstractBlockBase<T>> {
028
029    protected int id;
030    protected int domDepth;
031
032    protected List<T> predecessors;
033    protected List<T> successors;
034
035    private T dominator;
036    private List<T> dominated;
037    private int domNumber;
038    private int maxChildDomNumber;
039
040    private boolean align;
041    private int linearScanNumber;
042
043    protected AbstractBlockBase() {
044        this.id = AbstractControlFlowGraph.BLOCK_ID_INITIAL;
045        this.linearScanNumber = -1;
046    }
047
048    public void setDominatorNumbers(int domNumber, int maxChildDomNumber) {
049        this.domNumber = domNumber;
050        this.maxChildDomNumber = maxChildDomNumber;
051    }
052
053    public int getDominatorNumber() {
054        return domNumber;
055    }
056
057    public int getMaxChildDominatorNumber() {
058        return this.maxChildDomNumber;
059    }
060
061    public int getId() {
062        return id;
063    }
064
065    public void setId(int id) {
066        this.id = id;
067    }
068
069    public List<T> getPredecessors() {
070        return predecessors;
071    }
072
073    public void setPredecessors(List<T> predecessors) {
074        this.predecessors = predecessors;
075    }
076
077    public List<T> getSuccessors() {
078        return successors;
079    }
080
081    public void setSuccessors(List<T> successors) {
082        this.successors = successors;
083    }
084
085    public T getDominator() {
086        return dominator;
087    }
088
089    public void setDominator(T dominator) {
090        this.dominator = dominator;
091        this.domDepth = dominator.domDepth + 1;
092    }
093
094    public int getDominatorDepth() {
095        return domDepth;
096    }
097
098    public List<T> getDominated() {
099        if (dominated == null) {
100            return Collections.emptyList();
101        }
102        return dominated;
103    }
104
105    public void setDominated(List<T> blocks) {
106        dominated = blocks;
107    }
108
109    @Override
110    public String toString() {
111        return "B" + id;
112    }
113
114    public int getPredecessorCount() {
115        return getPredecessors().size();
116    }
117
118    public int getSuccessorCount() {
119        return getSuccessors().size();
120    }
121
122    public int getLinearScanNumber() {
123        return linearScanNumber;
124    }
125
126    public void setLinearScanNumber(int linearScanNumber) {
127        this.linearScanNumber = linearScanNumber;
128    }
129
130    public boolean isAligned() {
131        return align;
132    }
133
134    public void setAlign(boolean align) {
135        this.align = align;
136    }
137
138    public abstract boolean isExceptionEntry();
139
140    public abstract Loop<T> getLoop();
141
142    public abstract int getLoopDepth();
143
144    public abstract boolean isLoopEnd();
145
146    public abstract boolean isLoopHeader();
147
148    public abstract T getPostdominator();
149
150    public abstract double probability();
151
152    public abstract T getDominator(int distance);
153}