Fix frame index elimination to correctly handle thumb-2 addressing modes that don...
[oota-llvm.git] / lib / Target / ARM / ARMInstrInfo.cpp
1 //===- ARMInstrInfo.cpp - ARM 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 ARM implementation of the TargetInstrInfo class.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "ARMInstrInfo.h"
15 #include "ARM.h"
16 #include "ARMAddressingModes.h"
17 #include "ARMGenInstrInfo.inc"
18 #include "ARMMachineFunctionInfo.h"
19 #include "llvm/ADT/STLExtras.h"
20 #include "llvm/CodeGen/LiveVariables.h"
21 #include "llvm/CodeGen/MachineFrameInfo.h"
22 #include "llvm/CodeGen/MachineInstrBuilder.h"
23 #include "llvm/CodeGen/MachineJumpTableInfo.h"
24 #include "llvm/Target/TargetAsmInfo.h"
25 #include "llvm/Support/CommandLine.h"
26 using namespace llvm;
27
28 ARMInstrInfo::ARMInstrInfo(const ARMSubtarget &STI)
29   : ARMBaseInstrInfo(STI), RI(*this, STI) {
30 }
31
32 unsigned ARMInstrInfo::
33 unsignedOffsetOpcodeToSigned(unsigned opcode, unsigned *NumBits) const {
34   return 0;
35 }
36
37 unsigned ARMInstrInfo::
38 getUnindexedOpcode(unsigned Opc) const {
39   switch (Opc) {
40   default: break;
41   case ARM::LDR_PRE:
42   case ARM::LDR_POST:
43     return ARM::LDR;
44   case ARM::LDRH_PRE:
45   case ARM::LDRH_POST:
46     return ARM::LDRH;
47   case ARM::LDRB_PRE:
48   case ARM::LDRB_POST:
49     return ARM::LDRB;
50   case ARM::LDRSH_PRE:
51   case ARM::LDRSH_POST:
52     return ARM::LDRSH;
53   case ARM::LDRSB_PRE:
54   case ARM::LDRSB_POST:
55     return ARM::LDRSB;
56   case ARM::STR_PRE:
57   case ARM::STR_POST:
58     return ARM::STR;
59   case ARM::STRH_PRE:
60   case ARM::STRH_POST:
61     return ARM::STRH;
62   case ARM::STRB_PRE:
63   case ARM::STRB_POST:
64     return ARM::STRB;
65   }
66
67   return 0;
68 }
69
70 unsigned ARMInstrInfo::
71 getOpcode(ARMII::Op Op) const {
72   switch (Op) {
73   case ARMII::ADDri: return ARM::ADDri;
74   case ARMII::ADDrs: return ARM::ADDrs;
75   case ARMII::ADDrr: return ARM::ADDrr;
76   case ARMII::B: return ARM::B;
77   case ARMII::Bcc: return ARM::Bcc;
78   case ARMII::BR_JTr: return ARM::BR_JTr;
79   case ARMII::BR_JTm: return ARM::BR_JTm;
80   case ARMII::BR_JTadd: return ARM::BR_JTadd;
81   case ARMII::BX_RET: return ARM::BX_RET;
82   case ARMII::FCPYS: return ARM::FCPYS;
83   case ARMII::FCPYD: return ARM::FCPYD;
84   case ARMII::FLDD: return ARM::FLDD;
85   case ARMII::FLDS: return ARM::FLDS;
86   case ARMII::FSTD: return ARM::FSTD;
87   case ARMII::FSTS: return ARM::FSTS;
88   case ARMII::LDR: return ARM::LDR;
89   case ARMII::MOVr: return ARM::MOVr;
90   case ARMII::STR: return ARM::STR;
91   case ARMII::SUBri: return ARM::SUBri;
92   case ARMII::SUBrs: return ARM::SUBrs;
93   case ARMII::SUBrr: return ARM::SUBrr;
94   case ARMII::VMOVD: return ARM::VMOVD;
95   case ARMII::VMOVQ: return ARM::VMOVQ;
96   default:
97     break;
98   }
99
100   return 0;
101 }
102
103 bool ARMInstrInfo::
104 BlockHasNoFallThrough(const MachineBasicBlock &MBB) const {
105   if (MBB.empty()) return false;
106
107   switch (MBB.back().getOpcode()) {
108   case ARM::BX_RET:   // Return.
109   case ARM::LDM_RET:
110   case ARM::B:
111   case ARM::BR_JTr:   // Jumptable branch.
112   case ARM::BR_JTm:   // Jumptable branch through mem.
113   case ARM::BR_JTadd: // Jumptable branch add to pc.
114     return true;
115   default:
116     break;
117   }
118
119   return false;
120 }
121
122 void ARMInstrInfo::
123 reMaterialize(MachineBasicBlock &MBB,
124               MachineBasicBlock::iterator I,
125               unsigned DestReg, unsigned SubIdx,
126               const MachineInstr *Orig) const {
127   DebugLoc dl = Orig->getDebugLoc();
128   if (Orig->getOpcode() == ARM::MOVi2pieces) {
129     RI.emitLoadConstPool(MBB, I, dl,
130                          DestReg, SubIdx,
131                          Orig->getOperand(1).getImm(),
132                          (ARMCC::CondCodes)Orig->getOperand(2).getImm(),
133                          Orig->getOperand(3).getReg());
134     return;
135   }
136
137   MachineInstr *MI = MBB.getParent()->CloneMachineInstr(Orig);
138   MI->getOperand(0).setReg(DestReg);
139   MBB.insert(I, MI);
140 }