001 /* 002 * This file is part of the Jikes RVM project (http://jikesrvm.org). 003 * 004 * This file is licensed to You under the Eclipse Public License (EPL); 005 * You may not use this file except in compliance with the License. You 006 * may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/eclipse-1.0.php 009 * 010 * See the COPYRIGHT.txt file distributed with this work for information 011 * regarding copyright ownership. 012 */ 013 package org.jikesrvm.compilers.opt.ssa; 014 015 import org.jikesrvm.compilers.opt.ir.Instruction; 016 import org.jikesrvm.compilers.opt.ir.operand.ConstantOperand; 017 import org.jikesrvm.compilers.opt.util.SpaceEffGraphNode; 018 019 /** 020 * This class implements a vertex in the value graph used in global 021 * value numbering 022 * ala Alpern, Wegman and Zadeck. See Muchnick p.348 for a nice 023 * discussion. 024 */ 025 final class ValueGraphVertex extends SpaceEffGraphNode { 026 /** the name of the variable defined by this node */ 027 private final Object name; 028 /** the name of the operator that does the definition */ 029 private Object label; 030 /** operand vertices, in order */ 031 private ValueGraphVertex[] targets; 032 /** integer value number */ 033 private int valueNumber; 034 /** number of operands needed */ 035 private int arity; 036 037 ValueGraphVertex(Object name) { 038 this.name = name; 039 } 040 041 /** 042 * Set up properties of this vertex identically to another vertex 043 */ 044 void copyVertex(ValueGraphVertex v) { 045 this.label = v.label; 046 this.valueNumber = v.valueNumber; 047 this.arity = v.arity; 048 this.targets = new ValueGraphVertex[v.targets.length]; 049 for (int i = 0; i < targets.length; i++) { 050 this.targets[i] = v.targets[i]; 051 } 052 } 053 054 /** 055 * Does this vertex represent an incoming parameter? 056 */ 057 boolean representsParameter() { 058 return (label instanceof ValueGraphParamLabel); 059 } 060 061 /** 062 * Set the label for this vertex. 063 * 064 * @param label the label (an operator of some type) 065 * @param arity the number of operands needed 066 */ 067 void setLabel(Object label, int arity) { 068 this.label = label; 069 this.arity = arity; 070 targets = new ValueGraphVertex[arity]; 071 } 072 073 Object getLabel() { 074 return label; 075 } 076 077 Object getName() { 078 return name; 079 } 080 081 int getValueNumber() { 082 return valueNumber; 083 } 084 085 void setValueNumber(int number) { 086 valueNumber = number; 087 } 088 089 boolean isConstant() { 090 return (label instanceof ConstantOperand); 091 } 092 093 // is the def for this node an allocation instruction? 094 boolean isBornAtAllocation() { 095 return (label instanceof Instruction); 096 } 097 098 /** 099 * return the target of the ith operand of this node 100 */ 101 public ValueGraphVertex getTarget(int i) { 102 return targets[i]; 103 } 104 105 public void addTarget(ValueGraphVertex target, int pos) { 106 targets[pos] = target; 107 } 108 109 public int getArity() { 110 return arity; 111 } 112 113 @Override 114 public String toString() { 115 StringBuilder s = new StringBuilder("Vertex: " + name + " " + label); 116 s.append(" Targets: "); 117 for (int i = 0; i < arity; i++) { 118 if (targets[i] == null) { 119 s.append("null "); 120 } else { 121 s.append(targets[i].getName()).append(" "); 122 } 123 } 124 return s.toString(); 125 } 126 }