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.regalloc.ia32;
014
015 import org.jikesrvm.compilers.opt.ir.MIR_Move;
016 import org.jikesrvm.compilers.opt.ir.IR;
017 import org.jikesrvm.compilers.opt.ir.Instruction;
018 import org.jikesrvm.compilers.opt.ir.InstructionEnumeration;
019 import org.jikesrvm.compilers.opt.ir.Operators;
020 import org.jikesrvm.compilers.opt.ir.Register;
021 import org.jikesrvm.compilers.opt.ir.operand.Operand;
022 import org.jikesrvm.compilers.opt.regalloc.GenericRegisterPreferences;
023
024 public class RegisterPreferences extends GenericRegisterPreferences implements Operators {
025
026 /**
027 * Set up register preferences based on instructions in an IR.
028 */
029 public void initialize(IR ir) {
030
031 for (InstructionEnumeration e = ir.forwardInstrEnumerator(); e.hasMoreElements();) {
032 Instruction s = e.nextElement();
033 switch (s.operator.opcode) {
034 case IA32_MOV_opcode:
035 // add affinities produced by MOVE instructions
036 Operand result = MIR_Move.getResult(s);
037 Operand value = MIR_Move.getValue(s);
038 if (result.isRegister() && value.isRegister()) {
039 Register r1 = result.asRegister().getRegister();
040 Register r2 = value.asRegister().getRegister();
041 addAffinity(1, r1, r2);
042 }
043 break;
044 default:
045 break;
046 }
047 }
048 }
049 }