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 /** 016 * Represents a pair of value numbers. 017 */ 018 class ValueNumberPair implements Comparable<ValueNumberPair> { 019 /** the value number of an array pointer */ 020 final int v1; 021 /** the value number of an array index */ 022 final int v2; 023 024 /** Construct a pair from the given arguments */ 025 ValueNumberPair(int v1, int v2) { 026 this.v1 = v1; 027 this.v2 = v2; 028 } 029 030 /** Copy a pair */ 031 ValueNumberPair(ValueNumberPair p) { 032 this.v1 = p.v1; 033 this.v2 = p.v2; 034 } 035 036 @Override 037 public boolean equals(Object o) { 038 if (!(o instanceof ValueNumberPair)) { 039 return false; 040 } 041 ValueNumberPair p = (ValueNumberPair) o; 042 return (v1 == p.v1) && (v2 == p.v2); 043 } 044 045 @Override 046 public int hashCode() { 047 return v1 << 16 | v2; 048 } 049 050 @Override 051 public String toString() { 052 return "<" + v1 + "," + v2 + ">"; 053 } 054 055 // total order over ValueNumberPairs 056 @Override 057 public int compareTo(ValueNumberPair p) { 058 if (v1 > p.v1) { 059 return 1; 060 } else if (v1 < p.v1) { 061 return -1; 062 } else if (v2 > p.v2) { 063 // v1 == p.v1 064 return 1; 065 } else if (v2 < p.v2) { 066 return -1; 067 } else { 068 // v2 == p.v2 069 return 0; 070 } 071 } 072 }