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 */ 013package org.jikesrvm.compilers.opt.ssa; 014 015/** 016 * Represents a pair of value numbers. 017 */ 018class 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 ValueNumberPair(int v1, int v2) { 025 this.v1 = v1; 026 this.v2 = v2; 027 } 028 029 ValueNumberPair(ValueNumberPair p) { 030 this.v1 = p.v1; 031 this.v2 = p.v2; 032 } 033 034 @Override 035 public boolean equals(Object o) { 036 if (!(o instanceof ValueNumberPair)) { 037 return false; 038 } 039 ValueNumberPair p = (ValueNumberPair) o; 040 return (v1 == p.v1) && (v2 == p.v2); 041 } 042 043 @Override 044 public int hashCode() { 045 return v1 << 16 | v2; 046 } 047 048 @Override 049 public String toString() { 050 return "<" + v1 + "," + v2 + ">"; 051 } 052 053 // total order over ValueNumberPairs 054 @Override 055 public int compareTo(ValueNumberPair p) { 056 if (v1 > p.v1) { 057 return 1; 058 } else if (v1 < p.v1) { 059 return -1; 060 } else if (v2 > p.v2) { 061 // v1 == p.v1 062 return 1; 063 } else if (v2 < p.v2) { 064 return -1; 065 } else { 066 // v2 == p.v2 067 return 0; 068 } 069 } 070}