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 org.jikesrvm.compilers.opt.ir.Instruction;
016
017 /**
018 * Object containing scheduling information
019 * Used by the scheduler
020 */
021 final class SchedulingInfo {
022 int alt;
023 int time;
024 int etime;
025 int cp;
026
027 // Creates new scheduling info object.
028 // For internal use only.
029 // Other classes should invoke createInfo().
030 private SchedulingInfo() {
031 alt = -1;
032 time = -1;
033 etime = -1;
034 cp = -1;
035 }
036
037 /**
038 * Initializes scheduling information for instruction.
039 *
040 * @param i instruction
041 */
042 public static void createInfo(Instruction i) {
043 i.scratchObject = new SchedulingInfo();
044 }
045
046 /**
047 * Removes scheduling information from instruction.
048 *
049 * @param i instruction
050 */
051 public static void removeInfo(Instruction i) {
052 i.scratchObject = null;
053 }
054
055 /**
056 * Returns scheduling information for instruction.
057 *
058 * @param i instruction
059 * @return scheduling info for instruction
060 */
061 public static SchedulingInfo getInfo(Instruction i) {
062 return (SchedulingInfo) i.scratchObject;
063 }
064
065 /**
066 * Adds scheduling information to instruction.
067 *
068 * @param i instruction
069 * @param alt scheduling alternative
070 * @param time scheduling time
071 */
072 public static void setInfo(Instruction i, int alt, int time) {
073 SchedulingInfo si = getInfo(i);
074 si.alt = alt;
075 si.time = time;
076 }
077
078 /**
079 * Clears scheduling information of instruction.
080 *
081 * @param i instruction
082 */
083 public static void resetInfo(Instruction i) {
084 setInfo(i, -1, -1);
085 }
086
087 /**
088 * Checks whether instruction is scheduled.
089 *
090 * @param i instruction
091 * @return true if instruction is scheduled, false otherwise
092 */
093 public static boolean isScheduled(Instruction i) {
094 return getInfo(i).alt != -1;
095 }
096
097 /**
098 * Returns scheduling alternative for instruction.
099 *
100 * @param i instruction
101 * @return scheduling alternative for instruction
102 */
103 public static int getAlt(Instruction i) {
104 return getInfo(i).alt;
105 }
106
107 /**
108 * Returns scheduling time for instruction.
109 *
110 * @param i instruction
111 * @return scheduling time for instruction
112 */
113 public static int getTime(Instruction i) {
114 return getInfo(i).time;
115 }
116
117 /**
118 * Returns earliest scheduling time for instruction.
119 *
120 * @param i instruction
121 * @return earliest scheduling time for instruction
122 */
123 public static int getEarliestTime(Instruction i) {
124 return getInfo(i).etime;
125 }
126
127 /**
128 * Sets earliest scheduling time for instruction.
129 *
130 * @param i instruction
131 * @param etime earliest scheduling time for instruction
132 */
133 public static void setEarliestTime(Instruction i, int etime) {
134 getInfo(i).etime = etime;
135 }
136
137 /**
138 * Returns critical path length for instruction.
139 *
140 * @param i instruction
141 * @return critical path length for instruction
142 */
143 public static int getCriticalPath(Instruction i) {
144 return getInfo(i).cp;
145 }
146
147 /**
148 * Sets critical path length for instruction.
149 *
150 * @param i instruction
151 * @param cp critical path length for instruction
152 */
153 public static void setCriticalPath(Instruction i, int cp) {
154 getInfo(i).cp = cp;
155 }
156
157 /**
158 * Returns a string representation of scheduling info.
159 *
160 * @return string representation of scheduling info
161 */
162 public String toString() {
163 return "time=" + time + "; alt=" + alt + "; eTime=" + etime + "; cp=" + cp;
164 }
165 }