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 @Override 036 public abstract IR getIR(); 037 038 /** 039 * Create an MIR instruction to move rhs into lhs 040 */ 041 public static Instruction makeMoveInstruction(RegisterOperand lhs, RegisterOperand rhs) { 042 if (rhs.getRegister().isInteger() || rhs.getRegister().isLong() || rhs.getRegister().isAddress()) { 043 if (VM.VerifyAssertions) { 044 VM._assert(lhs.getRegister().isInteger() || lhs.getRegister().isLong() || lhs.getRegister().isAddress()); 045 } 046 return MIR_Move.create(IA32_MOV, lhs, rhs); 047 } else if (rhs.getRegister().isFloatingPoint()) { 048 if (VM.VerifyAssertions) { 049 VM._assert(lhs.getRegister().isFloatingPoint()); 050 } 051 if (ArchConstants.SSE2_FULL) { 052 if (rhs.getRegister().isFloat()) { 053 return MIR_Move.create(IA32_MOVSS, lhs, rhs); 054 } else { 055 return MIR_Move.create(IA32_MOVSD, lhs, rhs); 056 } 057 } else { 058 return MIR_Move.create(IA32_FMOV, lhs, rhs); 059 } 060 } else { 061 OptimizingCompilerException.TODO("PhysicalRegisterTools.makeMoveInstruction"); 062 return null; 063 } 064 } 065 }