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 */
013package org.jikesrvm.compilers.opt.regalloc.ia32;
014
015import static org.jikesrvm.compilers.opt.ir.ia32.ArchOperators.IA32_MOV_opcode;
016
017import java.util.Enumeration;
018
019import org.jikesrvm.compilers.opt.ir.IR;
020import org.jikesrvm.compilers.opt.ir.Instruction;
021import org.jikesrvm.compilers.opt.ir.Register;
022import org.jikesrvm.compilers.opt.ir.ia32.MIR_Move;
023import org.jikesrvm.compilers.opt.ir.operand.Operand;
024import org.jikesrvm.compilers.opt.regalloc.GenericRegisterPreferences;
025
026public class RegisterPreferences extends GenericRegisterPreferences {
027
028  @Override
029  public void initialize(IR ir) {
030
031    for (Enumeration<Instruction> e = ir.forwardInstrEnumerator(); e.hasMoreElements();) {
032      Instruction s = e.nextElement();
033      switch (s.getOpcode()) {
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}