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.regalloc;
014    
015    import org.jikesrvm.compilers.opt.ir.BasicBlock;
016    import org.jikesrvm.compilers.opt.ir.Instruction;
017    import 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     */
025    public 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 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() { return begin; }
094    
095      public void setBegin(Instruction begin) { this.begin = begin; }
096    
097      public Instruction getEnd() { return end; }
098    
099      public Register getRegister() { return register; }
100    
101      public void setRegister(Register r) { register = r; }
102    
103      public LiveIntervalElement getNext() { return next; }
104    
105      public void setNext(LiveIntervalElement Next) { next = Next; }
106    
107      public BasicBlock getBasicBlock() { return bb; }
108    
109      public void setBasicBlock(BasicBlock bb) { this.bb = bb; }
110    }