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.lir2mir; 014 015 import org.jikesrvm.ArchitectureSpecificOpt.BURS_TreeNode; 016 import org.jikesrvm.ArchitectureSpecificOpt.PhysicalRegisterTools; 017 import org.jikesrvm.ArchitectureSpecificOpt.RegisterPool; 018 import org.jikesrvm.compilers.opt.ir.IR; 019 import org.jikesrvm.compilers.opt.ir.Instruction; 020 import org.jikesrvm.compilers.opt.ir.operand.AddressConstantOperand; 021 import org.jikesrvm.compilers.opt.ir.operand.ConditionOperand; 022 import org.jikesrvm.compilers.opt.ir.operand.IntConstantOperand; 023 import org.jikesrvm.compilers.opt.ir.operand.LongConstantOperand; 024 import org.jikesrvm.compilers.opt.ir.operand.Operand; 025 import org.jikesrvm.compilers.opt.ir.operand.RegisterOperand; 026 import org.jikesrvm.compilers.opt.util.Bits; 027 import org.vmmagic.unboxed.Address; 028 029 /** 030 * Contains BURS helper functions common to all platforms. 031 */ 032 public abstract class BURS_Common_Helpers extends PhysicalRegisterTools { 033 034 /** Infinite cost for a rule */ 035 protected static final int INFINITE = 0x7fff; 036 037 /** 038 * The BURS object 039 */ 040 protected final BURS burs; 041 042 /** 043 * The register pool of the IR being processed 044 */ 045 protected final RegisterPool regpool; 046 047 protected BURS_Common_Helpers(BURS b) { 048 burs = b; 049 regpool = b.ir.regpool; 050 } 051 052 @Override 053 public final IR getIR() { return burs.ir; } 054 055 protected final void EMIT(Instruction s) { 056 burs.append(s); 057 } 058 059 // returns the given operand as a register 060 protected static RegisterOperand R(Operand op) { 061 return op.asRegister(); 062 } 063 064 // returns the given operand as an address constant 065 protected static AddressConstantOperand AC(Operand op) { 066 return op.asAddressConstant(); 067 } 068 069 // returns the given operand as an integer constant 070 protected static IntConstantOperand IC(Operand op) { 071 return op.asIntConstant(); 072 } 073 074 // returns the given operand as a long constant 075 protected static LongConstantOperand LC(Operand op) { 076 return op.asLongConstant(); 077 } 078 079 // returns the integer value of the given operand 080 protected static int IV(Operand op) { 081 return IC(op).value; 082 } 083 084 // returns the Address value of the given operand 085 protected static Address AV(Operand op) { 086 return AC(op).value; 087 } 088 089 // is a == 0? 090 protected static boolean ZERO(Operand a) { 091 return (IV(a) == 0); 092 } 093 094 // is a == 1? 095 protected static boolean ONE(Operand a) { 096 return (IV(a) == 1); 097 } 098 099 // is a == -1? 100 protected static boolean MINUSONE(Operand a) { 101 return (IV(a) == -1); 102 } 103 104 protected static int FITS(Operand op, int numBits, int trueCost) { 105 return FITS(op, numBits, trueCost, INFINITE); 106 } 107 108 protected static int FITS(Operand op, int numBits, int trueCost, int falseCost) { 109 if (op.isIntConstant() && Bits.fits(IV(op), numBits)) { 110 return trueCost; 111 } else if (op.isAddressConstant() && Bits.fits(AV(op), numBits)) { 112 return trueCost; 113 } else { 114 return falseCost; 115 } 116 } 117 118 protected static int isZERO(int x, int trueCost) { 119 return isZERO(x, trueCost, INFINITE); 120 } 121 122 protected static int isZERO(int x, int trueCost, int falseCost) { 123 return x == 0 ? trueCost : falseCost; 124 } 125 126 protected static int isONE(int x, int trueCost) { 127 return isONE(x, trueCost, INFINITE); 128 } 129 130 protected static int isONE(int x, int trueCost, int falseCost) { 131 return x == 1 ? trueCost : falseCost; 132 } 133 134 // helper functions for condition operands 135 protected static boolean EQ_NE(ConditionOperand c) { 136 int cond = c.value; 137 return ((cond == ConditionOperand.EQUAL) || (cond == ConditionOperand.NOT_EQUAL)); 138 } 139 140 protected static boolean EQ_LT_LE(ConditionOperand c) { 141 int cond = c.value; 142 return ((cond == ConditionOperand.EQUAL) || 143 (cond == ConditionOperand.LESS) || 144 (cond == ConditionOperand.LESS_EQUAL)); 145 } 146 147 protected static boolean EQ_GT_GE(ConditionOperand c) { 148 int cond = c.value; 149 return ((cond == ConditionOperand.EQUAL) || 150 (cond == ConditionOperand.GREATER) || 151 (cond == ConditionOperand.GREATER_EQUAL)); 152 } 153 154 /* node accessors */ 155 protected static Instruction P(BURS_TreeNode p) { 156 return p.getInstruction(); 157 } 158 159 protected static Instruction PL(BURS_TreeNode p) { 160 return p.child1.getInstruction(); 161 } 162 163 protected static Instruction PLL(BURS_TreeNode p) { 164 return p.child1.child1.getInstruction(); 165 } 166 167 protected static Instruction PLLL(BURS_TreeNode p) { 168 return p.child1.child1.child1.getInstruction(); 169 } 170 171 protected static Instruction PLLLL(BURS_TreeNode p) { 172 return p.child1.child1.child1.child1.getInstruction(); 173 } 174 175 protected static Instruction PLLLLLL(BURS_TreeNode p) { 176 return p.child1.child1.child1.child1.child1.child1.getInstruction(); 177 } 178 179 protected static Instruction PLLLLLLL(BURS_TreeNode p) { 180 return p.child1.child1.child1.child1.child1.child1.child1.getInstruction(); 181 } 182 183 protected static Instruction PLLLRL(BURS_TreeNode p) { 184 return p.child1.child1.child1.child2.child1.getInstruction(); 185 } 186 187 protected static Instruction PLLLRLL(BURS_TreeNode p) { 188 return p.child1.child1.child1.child2.child1.child1.getInstruction(); 189 } 190 191 protected static Instruction PLLLRLLL(BURS_TreeNode p) { 192 return p.child1.child1.child1.child2.child1.child1.child1.getInstruction(); 193 } 194 195 protected static Instruction PLLRLLL(BURS_TreeNode p) { 196 return p.child1.child1.child2.child1.child1.child1.getInstruction(); 197 } 198 199 protected static Instruction PLLR(BURS_TreeNode p) { 200 return p.child1.child1.child2.getInstruction(); 201 } 202 203 protected static Instruction PLLRL(BURS_TreeNode p) { 204 return p.child1.child1.child2.child1.getInstruction(); 205 } 206 207 protected static Instruction PLLRLL(BURS_TreeNode p) { 208 return p.child1.child1.child2.child1.child1.getInstruction(); 209 } 210 211 protected static Instruction PLLRLLR(BURS_TreeNode p) { 212 return p.child1.child1.child2.child1.child1.child2.getInstruction(); 213 } 214 215 protected static Instruction PLR(BURS_TreeNode p) { 216 return p.child1.child2.getInstruction(); 217 } 218 219 protected static Instruction PLRL(BURS_TreeNode p) { 220 return p.child1.child2.child1.getInstruction(); 221 } 222 223 protected static Instruction PLRLL(BURS_TreeNode p) { 224 return p.child1.child2.child1.child1.getInstruction(); 225 } 226 227 protected static Instruction PLRLLRL(BURS_TreeNode p) { 228 return p.child1.child2.child1.child1.child2.child1.getInstruction(); 229 } 230 231 protected static Instruction PLRR(BURS_TreeNode p) { 232 return p.child1.child2.child2.getInstruction(); 233 } 234 235 protected static Instruction PR(BURS_TreeNode p) { 236 return p.child2.getInstruction(); 237 } 238 239 protected static Instruction PRL(BURS_TreeNode p) { 240 return p.child2.child1.getInstruction(); 241 } 242 243 protected static Instruction PRLL(BURS_TreeNode p) { 244 return p.child2.child1.child1.getInstruction(); 245 } 246 247 protected static Instruction PRLLL(BURS_TreeNode p) { 248 return p.child2.child1.child1.child1.getInstruction(); 249 } 250 251 protected static Instruction PRLLLL(BURS_TreeNode p) { 252 return p.child2.child1.child1.child1.child1.getInstruction(); 253 } 254 255 protected static Instruction PRLLR(BURS_TreeNode p) { 256 return p.child2.child1.child1.child2.getInstruction(); 257 } 258 259 protected static Instruction PRLLRLLL(BURS_TreeNode p) { 260 return p.child2.child1.child1.child2.child1.child1.child1.getInstruction(); 261 } 262 263 protected static Instruction PRLR(BURS_TreeNode p) { 264 return p.child2.child1.child2.getInstruction(); 265 } 266 267 protected static Instruction PRLRL(BURS_TreeNode p) { 268 return p.child2.child1.child2.child1.getInstruction(); 269 } 270 271 protected static Instruction PRR(BURS_TreeNode p) { 272 return p.child2.child2.getInstruction(); 273 } 274 275 protected static Instruction PRRL(BURS_TreeNode p) { 276 return p.child2.child2.child1.getInstruction(); 277 } 278 279 protected static Instruction PRRR(BURS_TreeNode p) { 280 return p.child2.child2.child2.getInstruction(); 281 } 282 283 protected static int V(BURS_TreeNode p) { 284 return ((BURS_IntConstantTreeNode) p).value; 285 } 286 287 protected static int VL(BURS_TreeNode p) { 288 return ((BURS_IntConstantTreeNode) p.child1).value; 289 } 290 291 protected static int VLL(BURS_TreeNode p) { 292 return ((BURS_IntConstantTreeNode) p.child1.child1).value; 293 } 294 295 protected static int VLLL(BURS_TreeNode p) { 296 return ((BURS_IntConstantTreeNode) p.child1.child1.child1).value; 297 } 298 299 protected static int VLLLL(BURS_TreeNode p) { 300 return ((BURS_IntConstantTreeNode) p.child1.child1.child1.child1).value; 301 } 302 303 protected static int VLLLLLR(BURS_TreeNode p) { 304 return ((BURS_IntConstantTreeNode) p.child1.child1.child1.child1.child1.child2).value; 305 } 306 307 protected static int VLLLLLLR(BURS_TreeNode p) { 308 return ((BURS_IntConstantTreeNode) p.child1.child1.child1.child1.child1.child1.child2).value; 309 } 310 311 protected static int VLLLLLLLR(BURS_TreeNode p) { 312 return ((BURS_IntConstantTreeNode) p.child1.child1.child1.child1.child1.child1.child1.child2).value; 313 } 314 315 protected static int VLLLR(BURS_TreeNode p) { 316 return ((BURS_IntConstantTreeNode) p.child1.child1.child1.child2).value; 317 } 318 319 protected static int VLLLLR(BURS_TreeNode p) { 320 return ((BURS_IntConstantTreeNode) p.child1.child1.child1.child1.child2).value; 321 } 322 323 protected static int VLLLRLLLR(BURS_TreeNode p) { 324 return ((BURS_IntConstantTreeNode) p.child1.child1.child1.child2.child1.child1.child1.child2).value; 325 } 326 327 protected static int VLLLRLLR(BURS_TreeNode p) { 328 return ((BURS_IntConstantTreeNode) p.child1.child1.child1.child2.child1.child1.child2).value; 329 } 330 331 protected static int VLLLRLR(BURS_TreeNode p) { 332 return ((BURS_IntConstantTreeNode) p.child1.child1.child1.child2.child1.child2).value; 333 } 334 335 protected static int VLLLRR(BURS_TreeNode p) { 336 return ((BURS_IntConstantTreeNode) p.child1.child1.child1.child2.child2).value; 337 } 338 339 protected static int VLLR(BURS_TreeNode p) { 340 return ((BURS_IntConstantTreeNode) p.child1.child1.child2).value; 341 } 342 343 protected static int VLLRLLRR(BURS_TreeNode p) { 344 return ((BURS_IntConstantTreeNode) p.child1.child1.child2.child1.child1.child2.child2).value; 345 } 346 347 protected static int VLLRLR(BURS_TreeNode p) { 348 return ((BURS_IntConstantTreeNode) p.child1.child1.child2.child1.child2).value; 349 } 350 351 protected static int VLLRLLLR(BURS_TreeNode p) { 352 return ((BURS_IntConstantTreeNode) p.child1.child1.child2.child1.child1.child1.child2).value; 353 } 354 355 protected static int VLLRLLR(BURS_TreeNode p) { 356 return ((BURS_IntConstantTreeNode) p.child1.child1.child2.child1.child1.child2).value; 357 } 358 359 protected static int VLLRR(BURS_TreeNode p) { 360 return ((BURS_IntConstantTreeNode) p.child1.child1.child2.child2).value; 361 } 362 363 protected static int VLR(BURS_TreeNode p) { 364 return ((BURS_IntConstantTreeNode) p.child1.child2).value; 365 } 366 367 protected static int VLRLR(BURS_TreeNode p) { 368 return ((BURS_IntConstantTreeNode) p.child1.child2.child1.child2).value; 369 } 370 371 protected static int VLRL(BURS_TreeNode p) { 372 return ((BURS_IntConstantTreeNode) p.child1.child2.child1).value; 373 } 374 375 protected static int VLRR(BURS_TreeNode p) { 376 return ((BURS_IntConstantTreeNode) p.child1.child2.child2).value; 377 } 378 379 protected static int VLRLL(BURS_TreeNode p) { 380 return ((BURS_IntConstantTreeNode) p.child1.child2.child1.child1).value; 381 } 382 383 protected static int VLRLLRR(BURS_TreeNode p) { 384 return ((BURS_IntConstantTreeNode) p.child1.child2.child1.child1.child2.child2).value; 385 } 386 387 protected static int VLRRR(BURS_TreeNode p) { 388 return ((BURS_IntConstantTreeNode) p.child1.child2.child2.child2).value; 389 } 390 391 protected static int VR(BURS_TreeNode p) { 392 return ((BURS_IntConstantTreeNode) p.child2).value; 393 } 394 395 protected static int VRL(BURS_TreeNode p) { 396 return ((BURS_IntConstantTreeNode) p.child2.child1).value; 397 } 398 399 protected static int VRLLR(BURS_TreeNode p) { 400 return ((BURS_IntConstantTreeNode) p.child2.child1.child1.child2).value; 401 } 402 403 protected static int VRLLLR(BURS_TreeNode p) { 404 return ((BURS_IntConstantTreeNode) p.child2.child1.child1.child1.child2).value; 405 } 406 407 protected static int VRLLLLR(BURS_TreeNode p) { 408 return ((BURS_IntConstantTreeNode) p.child2.child1.child1.child1.child1.child2).value; 409 } 410 411 protected static int VRLLRLLLR(BURS_TreeNode p) { 412 return ((BURS_IntConstantTreeNode) p.child2.child1.child1.child2.child1.child1.child1.child2).value; 413 } 414 415 protected static int VRLLRLLR(BURS_TreeNode p) { 416 return ((BURS_IntConstantTreeNode) p.child2.child1.child1.child2.child1.child1.child2).value; 417 } 418 419 protected static int VRLLRR(BURS_TreeNode p) { 420 return ((BURS_IntConstantTreeNode) p.child2.child1.child1.child2.child2).value; 421 } 422 423 protected static int VRLRLR(BURS_TreeNode p) { 424 return ((BURS_IntConstantTreeNode) p.child2.child1.child2.child1.child2).value; 425 } 426 427 protected static int VRLRR(BURS_TreeNode p) { 428 return ((BURS_IntConstantTreeNode) p.child2.child1.child2.child2).value; 429 } 430 431 protected static int VRLL(BURS_TreeNode p) { 432 return ((BURS_IntConstantTreeNode) p.child2.child1.child1).value; 433 } 434 435 protected static int VRLR(BURS_TreeNode p) { 436 return ((BURS_IntConstantTreeNode) p.child2.child1.child2).value; 437 } 438 439 protected static int VRR(BURS_TreeNode p) { 440 return ((BURS_IntConstantTreeNode) p.child2.child2).value; 441 } 442 443 protected static int VRRL(BURS_TreeNode p) { 444 return ((BURS_IntConstantTreeNode) p.child2.child2.child1).value; 445 } 446 447 protected static int VRRLR(BURS_TreeNode p) { 448 return ((BURS_IntConstantTreeNode) p.child2.child2.child1.child2).value; 449 } 450 451 protected static int VRRR(BURS_TreeNode p) { 452 return ((BURS_IntConstantTreeNode) p.child2.child2.child2).value; 453 } 454 }