001 002/* 003 * THIS FILE IS MACHINE_GENERATED. DO NOT EDIT. 004 * See InstructionFormats.template, InstructionFormatList.dat, 005 * OperatorList.dat, etc. 006 */ 007 008package org.jikesrvm.compilers.opt.ir; 009 010import org.jikesrvm.Configuration; 011import org.jikesrvm.compilers.opt.ir.operand.*; 012 013/** 014 * The Phi InstructionFormat class. 015 * 016 * The header comment for {@link Instruction} contains 017 * an explanation of the role of InstructionFormats in the 018 * opt compiler's IR. 019 */ 020@SuppressWarnings("unused") // Machine generated code is never 100% clean 021public final class Phi extends InstructionFormat { 022 /** 023 * InstructionFormat identification method for Phi. 024 * @param i an instruction 025 * @return <code>true</code> if the InstructionFormat of the argument 026 * instruction is Phi or <code>false</code> 027 * if it is not. 028 */ 029 public static boolean conforms(Instruction i) { 030 return conforms(i.operator()); 031 } 032 /** 033 * InstructionFormat identification method for Phi. 034 * @param o an instruction 035 * @return <code>true</code> if the InstructionFormat of the argument 036 * operator is Phi or <code>false</code> 037 * if it is not. 038 */ 039 public static boolean conforms(Operator o) { 040 return o.format == Phi_format; 041 } 042 043 /** 044 * Get the operand called Result from the 045 * argument instruction. Note that the returned operand 046 * will still point to its containing instruction. 047 * @param i the instruction to fetch the operand from 048 * @return the operand called Result 049 */ 050 public static Operand getResult(Instruction i) { 051 if (Configuration.ExtremeAssertions && !conforms(i)) fail(i, "Phi"); 052 return (Operand) i.getOperand(0); 053 } 054 /** 055 * Get the operand called Result from the argument 056 * instruction clearing its instruction pointer. The returned 057 * operand will not point to any containing instruction. 058 * @param i the instruction to fetch the operand from 059 * @return the operand called Result 060 */ 061 public static Operand getClearResult(Instruction i) { 062 if (Configuration.ExtremeAssertions && !conforms(i)) fail(i, "Phi"); 063 return (Operand) i.getClearOperand(0); 064 } 065 /** 066 * Set the operand called Result in the argument 067 * instruction to the argument operand. The operand will 068 * now point to the argument instruction as its containing 069 * instruction. 070 * @param i the instruction in which to store the operand 071 * @param Result the operand to store 072 */ 073 public static void setResult(Instruction i, Operand Result) { 074 if (Configuration.ExtremeAssertions && !conforms(i)) fail(i, "Phi"); 075 i.putOperand(0, Result); 076 } 077 /** 078 * Return the index of the operand called Result 079 * in the argument instruction. 080 * @param i the instruction to access. 081 * @return the index of the operand called Result 082 * in the argument instruction 083 */ 084 public static int indexOfResult(Instruction i) { 085 if (Configuration.ExtremeAssertions && !conforms(i)) fail(i, "Phi"); 086 return 0; 087 } 088 /** 089 * Does the argument instruction have a non-null 090 * operand named Result? 091 * @param i the instruction to access. 092 * @return <code>true</code> if the instruction has an non-null 093 * operand named Result or <code>false</code> 094 * if it does not. 095 */ 096 public static boolean hasResult(Instruction i) { 097 if (Configuration.ExtremeAssertions && !conforms(i)) fail(i, "Phi"); 098 return i.getOperand(0) != null; 099 } 100 101 /** 102 * Get the k'th operand called Value from the 103 * argument instruction. Note that the returned operand 104 * will still point to its containing instruction. 105 * @param i the instruction to fetch the operand from 106 * @param k the index of the operand 107 * @return the k'th operand called Value 108 */ 109 public static Operand getValue(Instruction i, int k) { 110 if (Configuration.ExtremeAssertions && !conforms(i)) fail(i, "Phi"); 111 return (Operand) i.getOperand(1+k*2+0); 112 } 113 /** 114 * Get the k'th operand called Value from the argument 115 * instruction clearing its instruction pointer. The returned 116 * operand will not point to any containing instruction. 117 * @param i the instruction to fetch the operand from 118 * @param k the index of the operand 119 * @return the k'th operand called Value 120 */ 121 public static Operand getClearValue(Instruction i, int k) { 122 if (Configuration.ExtremeAssertions && !conforms(i)) fail(i, "Phi"); 123 return (Operand) i.getClearOperand(1+k*2+0); 124 } 125 /** 126 * Set the k'th operand called Value in the argument 127 * instruction to the argument operand. The operand will 128 * now point to the argument instruction as its containing 129 * instruction. 130 * @param i the instruction in which to store the operand 131 * @param k the index of the operand 132 * @param o the operand to store 133 */ 134 public static void setValue(Instruction i, int k, Operand o) { 135 if (Configuration.ExtremeAssertions && !conforms(i)) fail(i, "Phi"); 136 i.putOperand(1+k*2+0, o); 137 } 138 /** 139 * Return the index of the k'th operand called Value 140 * in the argument instruction. 141 * @param i the instruction to access. 142 * @param k the index of the operand. 143 * @return the index of the k'th operand called Value 144 * in the argument instruction 145 */ 146 public static int indexOfValue(Instruction i, int k) { 147 if (Configuration.ExtremeAssertions && !conforms(i)) fail(i, "Phi"); 148 return 1+k*2+0; 149 } 150 /** 151 * Does the argument instruction have a non-null 152 * k'th operand named Value? 153 * @param i the instruction to access. 154 * @param k the index of the operand. 155 * @return <code>true</code> if the instruction has an non-null 156 * k'th operand named Value or <code>false</code> 157 * if it does not. 158 */ 159 public static boolean hasValue(Instruction i, int k) { 160 if (Configuration.ExtremeAssertions && !conforms(i)) fail(i, "Phi"); 161 return i.getOperand(1+k*2+0) != null; 162 } 163 164 /** 165 * Return the index of the first operand called Value 166 * in the argument instruction. 167 * @param i the instruction to access. 168 * @return the index of the first operand called Value 169 * in the argument instruction 170 */ 171 public static int indexOfValues(Instruction i) 172 { 173 if (Configuration.ExtremeAssertions && !conforms(i)) fail(i, "Phi"); 174 return 1; 175 } 176 /** 177 * Does the argument instruction have any operands 178 * named Value? 179 * @param i the instruction to access. 180 * @return <code>true</code> if the instruction has operands 181 * named Value or <code>false</code> if it does not. 182 */ 183 public static boolean hasValues(Instruction i) 184 { 185 if (Configuration.ExtremeAssertions && !conforms(i)) fail(i, "Phi"); 186 return i.getNumberOfOperands()-1 > 0 && i.getOperand(1) != null; 187 } 188 189 /** 190 * How many variable-length operands called Values 191 * does the argument instruction have? 192 * @param i the instruction to access 193 * @return the number of operands called Values the instruction has 194 */ 195 public static int getNumberOfValues(Instruction i) 196 { 197 if (Configuration.ExtremeAssertions && !conforms(i)) fail(i, "Phi"); 198 return (i.getNumberOfOperands()-1)/2; 199 } 200 201 /** 202 * Change the number of Values that may be stored in 203 * the argument instruction to numVarOps. 204 * @param i the instruction to access 205 * @param numVarOps the new number of variable operands called Values 206 * that may be stored in the instruction 207 */ 208 public static void resizeNumberOfValues(Instruction i, int numVarOps) 209 { 210 if (Configuration.ExtremeAssertions && !conforms(i)) fail(i, "Phi"); 211 if (1+numVarOps*2>MIN_OPERAND_ARRAY_LENGTH) 212 i.resizeNumberOfOperands(1+numVarOps*2); 213 else 214 for (int j = 1+numVarOps*2; j < MIN_OPERAND_ARRAY_LENGTH; j++) 215 i.putOperand(j, null); 216 } 217 /** 218 * Get the k'th operand called Pred from the 219 * argument instruction. Note that the returned operand 220 * will still point to its containing instruction. 221 * @param i the instruction to fetch the operand from 222 * @param k the index of the operand 223 * @return the k'th operand called Pred 224 */ 225 public static BasicBlockOperand getPred(Instruction i, int k) { 226 if (Configuration.ExtremeAssertions && !conforms(i)) fail(i, "Phi"); 227 return (BasicBlockOperand) i.getOperand(1+k*2+1); 228 } 229 /** 230 * Get the k'th operand called Pred from the argument 231 * instruction clearing its instruction pointer. The returned 232 * operand will not point to any containing instruction. 233 * @param i the instruction to fetch the operand from 234 * @param k the index of the operand 235 * @return the k'th operand called Pred 236 */ 237 public static BasicBlockOperand getClearPred(Instruction i, int k) { 238 if (Configuration.ExtremeAssertions && !conforms(i)) fail(i, "Phi"); 239 return (BasicBlockOperand) i.getClearOperand(1+k*2+1); 240 } 241 /** 242 * Set the k'th operand called Pred in the argument 243 * instruction to the argument operand. The operand will 244 * now point to the argument instruction as its containing 245 * instruction. 246 * @param i the instruction in which to store the operand 247 * @param k the index of the operand 248 * @param o the operand to store 249 */ 250 public static void setPred(Instruction i, int k, BasicBlockOperand o) { 251 if (Configuration.ExtremeAssertions && !conforms(i)) fail(i, "Phi"); 252 i.putOperand(1+k*2+1, o); 253 } 254 /** 255 * Return the index of the k'th operand called Pred 256 * in the argument instruction. 257 * @param i the instruction to access. 258 * @param k the index of the operand. 259 * @return the index of the k'th operand called Pred 260 * in the argument instruction 261 */ 262 public static int indexOfPred(Instruction i, int k) { 263 if (Configuration.ExtremeAssertions && !conforms(i)) fail(i, "Phi"); 264 return 1+k*2+1; 265 } 266 /** 267 * Does the argument instruction have a non-null 268 * k'th operand named Pred? 269 * @param i the instruction to access. 270 * @param k the index of the operand. 271 * @return <code>true</code> if the instruction has an non-null 272 * k'th operand named Pred or <code>false</code> 273 * if it does not. 274 */ 275 public static boolean hasPred(Instruction i, int k) { 276 if (Configuration.ExtremeAssertions && !conforms(i)) fail(i, "Phi"); 277 return i.getOperand(1+k*2+1) != null; 278 } 279 280 /** 281 * Return the index of the first operand called Pred 282 * in the argument instruction. 283 * @param i the instruction to access. 284 * @return the index of the first operand called Pred 285 * in the argument instruction 286 */ 287 public static int indexOfPreds(Instruction i) 288 { 289 if (Configuration.ExtremeAssertions && !conforms(i)) fail(i, "Phi"); 290 return 2; 291 } 292 /** 293 * Does the argument instruction have any operands 294 * named Pred? 295 * @param i the instruction to access. 296 * @return <code>true</code> if the instruction has operands 297 * named Pred or <code>false</code> if it does not. 298 */ 299 public static boolean hasPreds(Instruction i) 300 { 301 if (Configuration.ExtremeAssertions && !conforms(i)) fail(i, "Phi"); 302 return i.getNumberOfOperands()-2 > 0 && i.getOperand(2) != null; 303 } 304 305 /** 306 * How many variable-length operands called Preds 307 * does the argument instruction have? 308 * @param i the instruction to access 309 * @return the number of operands called Preds the instruction has 310 */ 311 public static int getNumberOfPreds(Instruction i) 312 { 313 if (Configuration.ExtremeAssertions && !conforms(i)) fail(i, "Phi"); 314 return (i.getNumberOfOperands()-1)/2; 315 } 316 317 /** 318 * Change the number of Preds that may be stored in 319 * the argument instruction to numVarOps. 320 * @param i the instruction to access 321 * @param numVarOps the new number of variable operands called Preds 322 * that may be stored in the instruction 323 */ 324 public static void resizeNumberOfPreds(Instruction i, int numVarOps) 325 { 326 if (Configuration.ExtremeAssertions && !conforms(i)) fail(i, "Phi"); 327 if (1+numVarOps*2>MIN_OPERAND_ARRAY_LENGTH) 328 i.resizeNumberOfOperands(1+numVarOps*2); 329 else 330 for (int j = 1+numVarOps*2; j < MIN_OPERAND_ARRAY_LENGTH; j++) 331 i.putOperand(j, null); 332 } 333 334 /** 335 * Create an instruction of the Phi instruction format. 336 * @param o the instruction's operator 337 * @param Result the instruction's Result operand 338 * @param numVarOps the number of variable length operands that 339 * will be stored in the insruction. 340 * @return the newly created Phi instruction 341 */ 342 public static Instruction create(Operator o 343 , Operand Result 344 , int numVarOps 345 ) 346 { 347 if (Configuration.ExtremeAssertions && !conforms(o)) fail(o, "Phi"); 348 Instruction i = Instruction.create(o, Math.max(1+numVarOps*2, MIN_OPERAND_ARRAY_LENGTH)); 349 i.putOperand(0, Result); 350 return i; 351 } 352 353 /** 354 * Mutate the argument instruction into an instruction of the 355 * Phi instruction format having the specified 356 * operator and operands. 357 * @param i the instruction to mutate 358 * @param o the instruction's operator 359 * @param Result the instruction's Result operand 360 * @param numVarOps the number of variable length operands that 361 * will be stored in the instruction. 362 * @return the mutated instruction 363 */ 364 public static Instruction mutate(Instruction i, Operator o 365 , Operand Result 366 , int numVarOps 367 ) 368 { 369 if (Configuration.ExtremeAssertions && !conforms(o)) fail(o, "Phi"); 370 if (1+numVarOps*2>MIN_OPERAND_ARRAY_LENGTH) 371 i.resizeNumberOfOperands(1+numVarOps*2); 372 373 i.changeOperatorTo(o); 374 i.putOperand(0, Result); 375 return i; 376 } 377} 378