778b55c81fdf29673b45d87698f61f3c2dc6881e
[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 "llvm/CodeGen/MachineInstrBuilder.h"
17 #include "PowerPCGenInstrInfo.inc"
18 #include <iostream>
19 using namespace llvm;
20
21 PowerPCInstrInfo::PowerPCInstrInfo()
22   : TargetInstrInfo(PowerPCInsts, sizeof(PowerPCInsts)/sizeof(PowerPCInsts[0])){
23 }
24
25 bool PowerPCInstrInfo::isMoveInstr(const MachineInstr& MI,
26                                unsigned& sourceReg,
27                                unsigned& destReg) const {
28   MachineOpCode oc = MI.getOpcode();
29   if (oc == PPC32::OR) {
30       assert(MI.getNumOperands() == 3 &&
31              MI.getOperand(0).isRegister() &&
32              MI.getOperand(1).isRegister() &&
33              MI.getOperand(2).isRegister() &&
34              "invalid register-register int move instruction");
35       if (MI.getOperand(1).getReg() == MI.getOperand(2).getReg()) {
36         sourceReg = MI.getOperand(1).getReg();
37         destReg = MI.getOperand(0).getReg();
38         return true;
39       }
40   }
41   else if (oc == PPC32::FMR) {
42       assert(MI.getNumOperands() == 2 &&
43              MI.getOperand(0).isRegister() &&
44              MI.getOperand(1).isRegister() &&
45              "invalid register-register fp move instruction");
46       sourceReg = MI.getOperand(1).getReg();
47       destReg = MI.getOperand(0).getReg();
48       return true;
49   }
50   return false;
51 }