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.liveness;
014
015import org.jikesrvm.VM;
016import org.jikesrvm.classloader.TypeReference;
017import org.jikesrvm.compilers.opt.ir.Register;
018import org.jikesrvm.compilers.opt.ir.operand.RegisterOperand;
019
020/**
021 * A simple class that holds an element in a LiveSet.
022 */
023final class LiveSetElement {
024
025  /**
026   * The register operand, i.e., the data
027   */
028  private RegisterOperand regOp;
029
030  /**
031   * The next field
032   */
033  private LiveSetElement next;
034
035  /**
036   * Construct an {@link LiveSetElement}.
037   *
038   * @param register    An {@link RegisterOperand}
039   */
040  LiveSetElement(RegisterOperand register) {
041    regOp = register;
042  }
043
044  /**
045   * Returns the register operand associated with this element
046   * @return the register operand associated with this element
047   */
048  public RegisterOperand getRegisterOperand() {
049    return regOp;
050  }
051
052  /**
053   * Changes the register operand.  New operand must represent the same register
054   * This is done to promote something of WordType to ReferenceType for the purposes of GC mapping.
055   *
056   * @param newRegOp the register operand that replaces the old one
057   */
058  public void setRegisterOperand(RegisterOperand newRegOp) {
059    if (VM.VerifyAssertions) VM._assert(regOp.getRegister().number == newRegOp.getRegister().number);
060    regOp = newRegOp;
061  }
062
063  /**
064   * Returns the register associated with this element
065   * @return the register associated with this element
066   */
067  public Register getRegister() {
068    return regOp.getRegister();
069  }
070
071  /**
072   * Returns the register type associated with this element
073   * @return the register type associated with this element
074   */
075  public TypeReference getRegisterType() {
076    return regOp.getType();
077  }
078
079  /**
080   * Returns the next element on this list
081   * @return the next element on this list
082   */
083  public LiveSetElement getNext() {
084    return next;
085  }
086
087  /**
088   * Sets the next element field
089   * @param newNext the next element field
090   */
091  public void setNext(LiveSetElement newNext) {
092    next = newNext;
093  }
094
095  /**
096   * @return a string version of this element
097   */
098  @Override
099  public String toString() {
100    return regOp.toString();
101  }
102}