Emit cross regclass register moves for thumb2.
[oota-llvm.git] / lib / Target / ARM / Thumb2InstrInfo.cpp
1 //===- Thumb2InstrInfo.cpp - Thumb-2 Instruction Information --------*- C++ -*-===//
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 Thumb-2 implementation of the TargetInstrInfo class.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "ARMInstrInfo.h"
15 #include "ARM.h"
16 #include "ARMGenInstrInfo.inc"
17 #include "ARMMachineFunctionInfo.h"
18 #include "llvm/CodeGen/MachineFrameInfo.h"
19 #include "llvm/CodeGen/MachineInstrBuilder.h"
20 #include "llvm/ADT/SmallVector.h"
21 #include "Thumb2InstrInfo.h"
22
23 using namespace llvm;
24
25 Thumb2InstrInfo::Thumb2InstrInfo(const ARMSubtarget &STI)
26   : ARMBaseInstrInfo(STI), RI(*this, STI) {
27 }
28
29 unsigned Thumb2InstrInfo::getUnindexedOpcode(unsigned Opc) const {
30   // FIXME
31   return 0;
32 }
33
34 unsigned Thumb2InstrInfo::getOpcode(ARMII::Op Op) const {
35   switch (Op) {
36   case ARMII::ADDri: return ARM::t2ADDri;
37   case ARMII::ADDrs: return ARM::t2ADDrs;
38   case ARMII::ADDrr: return ARM::t2ADDrr;
39   case ARMII::B: return ARM::t2B;
40   case ARMII::Bcc: return ARM::t2Bcc;
41   case ARMII::BR_JTr: return ARM::t2BR_JTr;
42   case ARMII::BR_JTm: return ARM::t2BR_JTm;
43   case ARMII::BR_JTadd: return ARM::t2BR_JTadd;
44   case ARMII::BX_RET: return ARM::tBX_RET;
45   case ARMII::FCPYS: return ARM::FCPYS;
46   case ARMII::FCPYD: return ARM::FCPYD;
47   case ARMII::FLDD: return ARM::FLDD;
48   case ARMII::FLDS: return ARM::FLDS;
49   case ARMII::FSTD: return ARM::FSTD;
50   case ARMII::FSTS: return ARM::FSTS;
51   case ARMII::LDR: return ARM::LDR;   // FIXME
52   case ARMII::MOVr: return ARM::t2MOVr;
53   case ARMII::STR: return ARM::STR;   // FIXME
54   case ARMII::SUBri: return ARM::t2SUBri;
55   case ARMII::SUBrs: return ARM::t2SUBrs;
56   case ARMII::SUBrr: return ARM::t2SUBrr;
57   case ARMII::VMOVD: return ARM::VMOVD;
58   case ARMII::VMOVQ: return ARM::VMOVQ;
59   default:
60     break;
61   }
62
63   return 0;
64 }
65
66 bool
67 Thumb2InstrInfo::BlockHasNoFallThrough(const MachineBasicBlock &MBB) const {
68   if (MBB.empty()) return false;
69
70   // FIXME
71   switch (MBB.back().getOpcode()) {
72   case ARM::t2LDM_RET:
73   case ARM::t2B:        // Uncond branch.
74   case ARM::t2BR_JTr:   // Jumptable branch.
75   case ARM::t2BR_JTm:   // Jumptable branch through mem.
76   case ARM::t2BR_JTadd: // Jumptable branch add to pc.
77     return true;
78   case ARM::tBX_RET:
79   case ARM::tBX_RET_vararg:
80   case ARM::tPOP_RET:
81   case ARM::tB:
82   case ARM::tBR_JTr:
83     return true;
84   default:
85     break;
86   }
87
88   return false;
89 }
90
91 bool
92 Thumb2InstrInfo::copyRegToReg(MachineBasicBlock &MBB,
93                               MachineBasicBlock::iterator I,
94                               unsigned DestReg, unsigned SrcReg,
95                               const TargetRegisterClass *DestRC,
96                               const TargetRegisterClass *SrcRC) const {
97   DebugLoc DL = DebugLoc::getUnknownLoc();
98   if (I != MBB.end()) DL = I->getDebugLoc();
99
100   if ((DestRC == ARM::GPRRegisterClass &&
101        SrcRC == ARM::tGPRRegisterClass) ||
102       (DestRC == ARM::tGPRRegisterClass &&
103        SrcRC == ARM::GPRRegisterClass)) {
104     AddDefaultCC(AddDefaultPred(BuildMI(MBB, I, DL, get(getOpcode(ARMII::MOVr)),
105                                         DestReg).addReg(SrcReg)));
106     return true;
107   }
108
109   return ARMBaseInstrInfo::copyRegToReg(MBB, I, DestReg, SrcReg, DestRC, SrcRC);
110 }