Move this code to lib/Target/SparcV9/MachineFunctionInfo.cpp
[oota-llvm.git] / lib / Target / PowerPC / PowerPCInstrInfo.cpp
1 //===- PowerPCInstrInfo.cpp - PowerPC Instruction Information ---*- C++ -*-===//
2 // 
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
7 // 
8 //===----------------------------------------------------------------------===//
9 //
10 // This file contains the PowerPC implementation of the TargetInstrInfo class.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "PowerPCInstrInfo.h"
15 #include "PowerPC.h"
16 #include "PowerPCGenInstrInfo.inc"
17 #include "llvm/CodeGen/MachineInstrBuilder.h"
18 #include <iostream>
19 using namespace llvm;
20
21 PowerPCInstrInfo::PowerPCInstrInfo(bool is64b)
22   : TargetInstrInfo(PowerPCInsts, sizeof(PowerPCInsts)/sizeof(PowerPCInsts[0])),
23     RI(is64b),
24     is64bit(is64b)
25 { }
26
27 bool PowerPCInstrInfo::isMoveInstr(const MachineInstr& MI,
28                                    unsigned& sourceReg,
29                                    unsigned& destReg) const {
30   MachineOpCode oc = MI.getOpcode();
31   if (oc == PPC::OR) {                      // or r1, r2, r2
32     assert(MI.getNumOperands() == 3 &&
33            MI.getOperand(0).isRegister() &&
34            MI.getOperand(1).isRegister() &&
35            MI.getOperand(2).isRegister() &&
36            "invalid PPC OR instruction!");
37     if (MI.getOperand(1).getReg() == MI.getOperand(2).getReg()) {
38       sourceReg = MI.getOperand(1).getReg();
39       destReg = MI.getOperand(0).getReg();
40       return true;
41     }
42   } else if (oc == PPC::ADDI) {             // addi r1, r2, 0
43     assert(MI.getNumOperands() == 3 &&
44            MI.getOperand(0).isRegister() &&
45            MI.getOperand(2).isImmediate() &&
46            "invalid PPC ADDI instruction!");
47     if (MI.getOperand(1).isRegister() && MI.getOperand(2).getImmedValue()==0) {
48       sourceReg = MI.getOperand(1).getReg();
49       destReg = MI.getOperand(0).getReg();
50       return true;
51     }
52   } else if (oc == PPC::FMR) {              // fmr r1, r2
53     assert(MI.getNumOperands() == 2 &&
54            MI.getOperand(0).isRegister() &&
55            MI.getOperand(1).isRegister() &&
56            "invalid PPC FMR instruction");
57     sourceReg = MI.getOperand(1).getReg();
58     destReg = MI.getOperand(0).getReg();
59     return true;
60   }
61   return false;
62 }