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