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