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.ir.ia32;
014    
015    import org.jikesrvm.VM;
016    import org.jikesrvm.compilers.opt.OptimizingCompilerException;
017    import org.jikesrvm.compilers.opt.ir.GenericPhysicalRegisterTools;
018    import org.jikesrvm.compilers.opt.ir.MIR_Move;
019    import org.jikesrvm.compilers.opt.ir.IR;
020    import org.jikesrvm.compilers.opt.ir.Instruction;
021    import static org.jikesrvm.compilers.opt.ir.Operators.IA32_FMOV;
022    import static org.jikesrvm.compilers.opt.ir.Operators.IA32_MOV;
023    import static org.jikesrvm.compilers.opt.ir.Operators.IA32_MOVSD;
024    import static org.jikesrvm.compilers.opt.ir.Operators.IA32_MOVSS;
025    
026    import org.jikesrvm.compilers.opt.ir.operand.RegisterOperand;
027    import org.jikesrvm.ia32.ArchConstants;
028    
029    /**
030     * This abstract class provides a set of useful methods for
031     * manipulating physical registers for an IR.
032     */
033    public abstract class PhysicalRegisterTools extends GenericPhysicalRegisterTools {
034    
035      /**
036       * Return the governing IR.
037       */
038      public abstract IR getIR();
039    
040      /**
041       * Create an MIR instruction to move rhs into lhs
042       */
043      public static Instruction makeMoveInstruction(RegisterOperand lhs, RegisterOperand rhs) {
044        if (rhs.getRegister().isInteger() || rhs.getRegister().isLong() || rhs.getRegister().isAddress()) {
045          if (VM.VerifyAssertions) {
046            VM._assert(lhs.getRegister().isInteger() || lhs.getRegister().isLong() || lhs.getRegister().isAddress());
047          }
048          return MIR_Move.create(IA32_MOV, lhs, rhs);
049        } else if (rhs.getRegister().isFloatingPoint()) {
050          if (VM.VerifyAssertions) {
051            VM._assert(lhs.getRegister().isFloatingPoint());
052          }
053          if (ArchConstants.SSE2_FULL) {
054            if (rhs.getRegister().isFloat()) {
055              return MIR_Move.create(IA32_MOVSS, lhs, rhs);
056            } else {
057              return MIR_Move.create(IA32_MOVSD, lhs, rhs);
058            }
059          } else {
060            return MIR_Move.create(IA32_FMOV, lhs, rhs);
061          }
062        } else {
063          OptimizingCompilerException.TODO("PhysicalRegisterTools.makeMoveInstruction");
064          return null;
065        }
066      }
067    }