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.regalloc;
014
015import org.jikesrvm.compilers.opt.ir.BasicBlock;
016import org.jikesrvm.compilers.opt.ir.Instruction;
017import org.jikesrvm.compilers.opt.ir.Register;
018
019/**
020 * This class defines a LiveInterval node created by Live Variable analysis
021 * and used in Linear Scan.
022 *
023 * @see LinearScan
024 */
025public final class LiveIntervalElement {
026
027  /**
028   * register that this live interval is for
029   */
030  private Register register;
031
032  /**
033   * instruction where the live interval begins
034   * (null if alive at basic block entry)
035   */
036  private Instruction begin;
037
038  /**
039   * instruction where the live interval ends
040   * (null if alive at basic block exit)
041   */
042  private final Instruction end;
043
044  /**
045   * The basic block holding this live interval element
046   */
047  private BasicBlock bb;
048
049  /**
050   * LiveIntervalElements are linked in a singly-linked list; this is the
051   * next pointer.
052   */
053  LiveIntervalElement next;
054
055  /**
056   * Use this constructor when the live interval spans a basic block
057   * boundary.
058   *
059   * @param reg The Register whose live interval we are representing
060   */
061  public LiveIntervalElement(Register reg) {
062    register = reg;
063    begin = null;
064    end = null;
065  }
066
067  /**
068   * Use this constructur when the live interval is within a basic block
069   *
070   * @param reg   the Register whose live interval we are representing
071   * @param begin the definition of the register
072   * @param end   the last use of the register
073   */
074  public LiveIntervalElement(Register reg, Instruction begin, Instruction end) {
075    register = reg;
076    this.begin = begin;
077    this.end = end;
078  }
079
080  @Override
081  public String toString() {
082    return "Reg: " + register + "\n     Begin: " + begin + "\n     End:   " + end;
083  }
084
085  @Override
086  public int hashCode() {
087    return register.hashCode();
088  }
089
090  /*
091   * Getters and setters for instance fields
092   */
093  public Instruction getBegin() {
094    return begin;
095  }
096
097  public void setBegin(Instruction begin) {
098    this.begin = begin;
099  }
100
101  public Instruction getEnd() {
102    return end;
103  }
104
105  public Register getRegister() {
106    return register;
107  }
108
109  public void setRegister(Register r) {
110    register = r;
111  }
112
113  public LiveIntervalElement getNext() {
114    return next;
115  }
116
117  public void setNext(LiveIntervalElement Next) {
118    next = Next;
119  }
120
121  public BasicBlock getBasicBlock() {
122    return bb;
123  }
124
125  public void setBasicBlock(BasicBlock bb) {
126    this.bb = bb;
127  }
128}