e5eb7bc8991d4dc40b3dd985deda1768f556038a
[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 getUnindexedOpcode(unsigned Opc) const {
34   switch (Opc) {
35   default: break;
36   case ARM::LDR_PRE:
37   case ARM::LDR_POST:
38     return ARM::LDR;
39   case ARM::LDRH_PRE:
40   case ARM::LDRH_POST:
41     return ARM::LDRH;
42   case ARM::LDRB_PRE:
43   case ARM::LDRB_POST:
44     return ARM::LDRB;
45   case ARM::LDRSH_PRE:
46   case ARM::LDRSH_POST:
47     return ARM::LDRSH;
48   case ARM::LDRSB_PRE:
49   case ARM::LDRSB_POST:
50     return ARM::LDRSB;
51   case ARM::STR_PRE:
52   case ARM::STR_POST:
53     return ARM::STR;
54   case ARM::STRH_PRE:
55   case ARM::STRH_POST:
56     return ARM::STRH;
57   case ARM::STRB_PRE:
58   case ARM::STRB_POST:
59     return ARM::STRB;
60   }
61
62   return 0;
63 }
64
65 unsigned ARMInstrInfo::
66 getOpcode(ARMII::Op Op) const {
67   switch (Op) {
68   case ARMII::ADDri: return ARM::ADDri;
69   case ARMII::ADDrs: return ARM::ADDrs;
70   case ARMII::ADDrr: return ARM::ADDrr;
71   case ARMII::MOVr: return ARM::MOVr;
72   case ARMII::SUBri: return ARM::SUBri;
73   case ARMII::SUBrs: return ARM::SUBrs;
74   case ARMII::SUBrr: return ARM::SUBrr;
75   default:
76     break;
77   }
78
79   return 0;
80 }
81
82 bool ARMInstrInfo::
83 BlockHasNoFallThrough(const MachineBasicBlock &MBB) const {
84   if (MBB.empty()) return false;
85
86   switch (MBB.back().getOpcode()) {
87   case ARM::BX_RET:   // Return.
88   case ARM::LDM_RET:
89   case ARM::B:
90   case ARM::BR_JTr:   // Jumptable branch.
91   case ARM::BR_JTm:   // Jumptable branch through mem.
92   case ARM::BR_JTadd: // Jumptable branch add to pc.
93     return true;
94   default:
95     break;
96   }
97
98   return false;
99 }
100
101 void ARMInstrInfo::
102 reMaterialize(MachineBasicBlock &MBB,
103               MachineBasicBlock::iterator I,
104               unsigned DestReg, unsigned SubIdx,
105               const MachineInstr *Orig) const {
106   DebugLoc dl = Orig->getDebugLoc();
107   if (Orig->getOpcode() == ARM::MOVi2pieces) {
108     RI.emitLoadConstPool(MBB, I, dl,
109                          DestReg, SubIdx,
110                          Orig->getOperand(1).getImm(),
111                          (ARMCC::CondCodes)Orig->getOperand(2).getImm(),
112                          Orig->getOperand(3).getReg());
113     return;
114   }
115
116   MachineInstr *MI = MBB.getParent()->CloneMachineInstr(Orig);
117   MI->getOperand(0).setReg(DestReg);
118   MBB.insert(I, MI);
119 }