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.instrsched; 014 015 import java.util.Enumeration; 016 017 import org.jikesrvm.compilers.opt.ir.BasicBlock; 018 import org.jikesrvm.compilers.opt.ir.Instruction; 019 020 /** 021 * Default (IR-order) instruction list. 022 * Used by the scheduler to enumerate over instructions. 023 * 024 * @see Priority 025 * @see Scheduler 026 */ 027 class DefaultPriority extends Priority { 028 // Underlying enumeration. 029 private final BasicBlock bb; 030 private Instruction i; 031 private Enumeration<Instruction> instr; 032 033 /** 034 * Creates new priority object for a given basic block 035 * 036 * @param bb basic block 037 */ 038 public DefaultPriority(BasicBlock bb) { 039 this.bb = bb; 040 } 041 042 @Override 043 public final void reset() { 044 i = bb.firstInstruction(); 045 instr = bb.forwardRealInstrEnumerator(); 046 } 047 048 @Override 049 public final boolean hasMoreElements() { 050 return i != null || instr.hasMoreElements(); 051 } 052 053 @Override 054 public final Instruction nextElement() { 055 if (i != null) { 056 Instruction r = i; 057 i = null; 058 return r; 059 } 060 return instr.nextElement(); 061 } 062 }