c84c96e6569f6887159ecb5a42f9ddaa25550eca
[oota-llvm.git] / lib / Target / MSP430 / MSP430InstrInfo.cpp
1 //===- MSP430InstrInfo.cpp - MSP430 Instruction Information ---------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file contains the MSP430 implementation of the TargetInstrInfo class.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "MSP430.h"
15 #include "MSP430InstrInfo.h"
16 #include "MSP430TargetMachine.h"
17 #include "MSP430GenInstrInfo.inc"
18 #include "llvm/Function.h"
19 #include "llvm/CodeGen/MachineFunction.h"
20 #include "llvm/CodeGen/MachineInstrBuilder.h"
21 #include "llvm/CodeGen/MachineRegisterInfo.h"
22
23
24 using namespace llvm;
25
26 MSP430InstrInfo::MSP430InstrInfo(MSP430TargetMachine &tm)
27   : TargetInstrInfoImpl(MSP430Insts, array_lengthof(MSP430Insts)),
28     RI(*this), TM(tm) {}
29
30 bool MSP430InstrInfo::copyRegToReg(MachineBasicBlock &MBB,
31                                    MachineBasicBlock::iterator I,
32                                    unsigned DestReg, unsigned SrcReg,
33                                    const TargetRegisterClass *DestRC,
34                                    const TargetRegisterClass *SrcRC) const {
35   if (DestRC != SrcRC) {
36     // Not yet supported!
37     return false;
38   }
39
40   DebugLoc DL = DebugLoc::getUnknownLoc();
41   if (I != MBB.end()) DL = I->getDebugLoc();
42
43   BuildMI(MBB, I, DL, get(MSP430::MOV16rr), DestReg).addReg(SrcReg);
44   return true;
45 }
46
47 bool
48 MSP430InstrInfo::isMoveInstr(const MachineInstr& MI,
49                              unsigned &SrcReg, unsigned &DstReg,
50                              unsigned &SrcSubIdx, unsigned &DstSubIdx) const {
51   SrcSubIdx = DstSubIdx = 0; // No sub-registers yet.
52
53   switch (MI.getOpcode()) {
54   default:
55     return false;
56   case MSP430::MOV16rr:
57     assert(MI.getNumOperands() >= 2 &&
58            MI.getOperand(0).isReg() &&
59            MI.getOperand(1).isReg() &&
60            "invalid register-register move instruction");
61     SrcReg = MI.getOperand(1).getReg();
62     DstReg = MI.getOperand(0).getReg();
63     return true;
64   }
65 }