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 package org.graalvm.compiler.core.common.cfg;
  24 
  25 import java.util.Collections;
  26 import java.util.List;
  27 
  28 public abstract class AbstractBlockBase<T extends AbstractBlockBase<T>> {
  29 
  30     protected int id;
  31     protected int domDepth;
  32 
  33     protected T[] predecessors;
  34     protected T[] successors;
  35 
  36     private T dominator;
  37     private List<T> dominated;
  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     public int getDominatorDepth() {
 101         return domDepth;
 102     }
 103 
 104     public List<T> getDominated() {
 105         if (dominated == null) {
 106             return Collections.emptyList();
 107         }
 108         return dominated;
 109     }
 110 
 111     public void setDominated(List<T> blocks) {
 112         dominated = blocks;
 113     }
 114 
 115     @Override
 116     public String toString() {
 117         return "B" + id;
 118     }
 119 
 120     public int getPredecessorCount() {
 121         return getPredecessors().length;
 122     }
 123 
 124     public int getSuccessorCount() {
 125         return getSuccessors().length;
 126     }
 127 
 128     public int getLinearScanNumber() {
 129         return linearScanNumber;
 130     }
 131 
 132     public void setLinearScanNumber(int linearScanNumber) {
 133         this.linearScanNumber = linearScanNumber;
 134     }
 135 
 136     public boolean isAligned() {
 137         return align;
 138     }
 139 
 140     public void setAlign(boolean align) {
 141         this.align = align;
 142     }
 143 
 144     public abstract boolean isExceptionEntry();
 145 
 146     public abstract Loop<T> getLoop();
 147 
 148     public abstract int getLoopDepth();
 149 
 150     public abstract void delete();
 151 
 152     public abstract boolean isLoopEnd();
 153 
 154     public abstract boolean isLoopHeader();
 155 
 156     public abstract T getPostdominator();
 157 
 158     public abstract double probability();
 159 
 160     public abstract T getDominator(int distance);
 161 }