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 
  44     protected AbstractBlockBase() {
  45         this.id = AbstractControlFlowGraph.BLOCK_ID_INITIAL;
  46         this.linearScanNumber = -1;
  47         this.domNumber = -1;
  48         this.maxChildDomNumber = -1;
  49     }
  50 
  51     public void setDominatorNumber(int domNumber) {
  52         this.domNumber = domNumber;
  53     }
  54 
  55     public void setMaxChildDomNumber(int maxChildDomNumber) {
  56         this.maxChildDomNumber = maxChildDomNumber;
  57     }
  58 
  59     public int getDominatorNumber() {
  60         return domNumber;
  61     }
  62 
  63     public int getMaxChildDominatorNumber() {
  64         return this.maxChildDomNumber;
  65     }
  66 
  67     public int getId() {
  68         return id;
  69     }
  70 
  71     public void setId(int id) {
  72         this.id = id;
  73     }
  74 
  75     public T[] getPredecessors() {
  76         return predecessors;
  77     }
  78 
  79     public void setPredecessors(T[] predecessors) {
  80         this.predecessors = predecessors;
  81     }
  82 
  83     public T[] getSuccessors() {
  84         return successors;
  85     }
  86 
  87     public void setSuccessors(T[] successors) {
  88         this.successors = successors;
  89     }
  90 
  91     public T getDominator() {
  92         return dominator;
  93     }
  94 
  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      */
 103     public int getDominatorDepth() {
 104         return domDepth;
 105     }
 106 
 107     public T getFirstDominated() {
 108         return this.firstDominated;
 109     }
 110 
 111     public void setFirstDominated(T block) {
 112         this.firstDominated = block;
 113     }
 114 
 115     public T getDominatedSibling() {
 116         return this.dominatedSibling;
 117     }
 118 
 119     public void setDominatedSibling(T block) {
 120         this.dominatedSibling = block;
 121     }
 122 
 123     @Override
 124     public String toString() {
 125         return "B" + id;
 126     }
 127 
 128     public int getPredecessorCount() {
 129         return getPredecessors().length;
 130     }
 131 
 132     public int getSuccessorCount() {
 133         return getSuccessors().length;
 134     }
 135 
 136     public int getLinearScanNumber() {
 137         return linearScanNumber;
 138     }
 139 
 140     public void setLinearScanNumber(int linearScanNumber) {
 141         this.linearScanNumber = linearScanNumber;
 142     }
 143 
 144     public boolean isAligned() {
 145         return align;
 146     }
 147 
 148     public void setAlign(boolean align) {
 149         this.align = align;
 150     }
 151 
 152     public abstract boolean isExceptionEntry();
 153 
 154     public abstract Loop<T> getLoop();
 155 
 156     public abstract int getLoopDepth();
 157 
 158     public abstract void delete();
 159 
 160     public abstract boolean isLoopEnd();
 161 
 162     public abstract boolean isLoopHeader();
 163 
 164     public abstract T getPostdominator();
 165 
 166     public abstract double probability();
 167 
 168     public abstract T getDominator(int distance);
 169 
 170     @Override
 171     public int hashCode() {
 172         return id;
 173     }
 174 }