Use t2LDRi12 and t2STRi12 to load / store to / from stack frames. Eliminate more...
[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::BX_RET: return ARM::tBX_RET;
42   case ARMII::LDRri: return ARM::t2LDRi12;
43   case ARMII::MOVr: return ARM::t2MOVr;
44   case ARMII::STRri: return ARM::t2STRi12;
45   case ARMII::SUBri: return ARM::t2SUBri;
46   case ARMII::SUBrs: return ARM::t2SUBrs;
47   case ARMII::SUBrr: return ARM::t2SUBrr;
48   default:
49     break;
50   }
51
52   return 0;
53 }
54
55 bool
56 Thumb2InstrInfo::BlockHasNoFallThrough(const MachineBasicBlock &MBB) const {
57   if (MBB.empty()) return false;
58
59   switch (MBB.back().getOpcode()) {
60   case ARM::t2LDM_RET:
61   case ARM::t2B:        // Uncond branch.
62   case ARM::t2BR_JT:    // Jumptable branch.
63   case ARM::tBR_JTr:    // Jumptable branch (16-bit version).
64   case ARM::tBX_RET:
65   case ARM::tBX_RET_vararg:
66   case ARM::tPOP_RET:
67   case ARM::tB:
68     return true;
69   default:
70     break;
71   }
72
73   return false;
74 }
75
76 bool
77 Thumb2InstrInfo::copyRegToReg(MachineBasicBlock &MBB,
78                               MachineBasicBlock::iterator I,
79                               unsigned DestReg, unsigned SrcReg,
80                               const TargetRegisterClass *DestRC,
81                               const TargetRegisterClass *SrcRC) const {
82   DebugLoc DL = DebugLoc::getUnknownLoc();
83   if (I != MBB.end()) DL = I->getDebugLoc();
84
85   if (DestRC == ARM::GPRRegisterClass &&
86       SrcRC == ARM::GPRRegisterClass) {
87     AddDefaultCC(AddDefaultPred(BuildMI(MBB, I, DL, get(ARM::t2MOVr),
88                                         DestReg).addReg(SrcReg)));
89     return true;
90   } else if (DestRC == ARM::GPRRegisterClass &&
91       SrcRC == ARM::tGPRRegisterClass) {
92     BuildMI(MBB, I, DL, get(ARM::tMOVtgpr2gpr), DestReg).addReg(SrcReg);
93     return true;
94   } else if (DestRC == ARM::tGPRRegisterClass &&
95              SrcRC == ARM::GPRRegisterClass) {
96     BuildMI(MBB, I, DL, get(ARM::tMOVgpr2tgpr), DestReg).addReg(SrcReg);
97     return true;
98   }
99
100   // Handle SPR, DPR, and QPR copies.
101   return ARMBaseInstrInfo::copyRegToReg(MBB, I, DestReg, SrcReg, DestRC, SrcRC);
102 }
103
104 void Thumb2InstrInfo::
105 storeRegToStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator I,
106                     unsigned SrcReg, bool isKill, int FI,
107                     const TargetRegisterClass *RC) const {
108   DebugLoc DL = DebugLoc::getUnknownLoc();
109   if (I != MBB.end()) DL = I->getDebugLoc();
110
111   if (RC == ARM::GPRRegisterClass) {
112     AddDefaultPred(BuildMI(MBB, I, DL, get(ARM::t2STRi12))
113                    .addReg(SrcReg, getKillRegState(isKill))
114                    .addFrameIndex(FI).addImm(0));
115     return;
116   }
117
118   ARMBaseInstrInfo::storeRegToStackSlot(MBB, I, SrcReg, isKill, FI, RC);
119 }
120
121 void Thumb2InstrInfo::
122 loadRegFromStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator I,
123                      unsigned DestReg, int FI,
124                      const TargetRegisterClass *RC) const {
125   DebugLoc DL = DebugLoc::getUnknownLoc();
126   if (I != MBB.end()) DL = I->getDebugLoc();
127
128   if (RC == ARM::GPRRegisterClass) {
129     AddDefaultPred(BuildMI(MBB, I, DL, get(ARM::t2LDRi12), DestReg)
130                    .addFrameIndex(FI).addImm(0));
131     return;
132   }
133
134   ARMBaseInstrInfo::loadRegFromStackSlot(MBB, I, DestReg, FI, RC);
135 }