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