FLDD, FLDS, FCPYD, FCPYS, FSTD, FSTS, VMOVD, VMOVQ maps to the same instructions...
[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::B: return ARM::B;
72   case ARMII::Bcc: return ARM::Bcc;
73   case ARMII::BR_JTr: return ARM::BR_JTr;
74   case ARMII::BR_JTm: return ARM::BR_JTm;
75   case ARMII::BR_JTadd: return ARM::BR_JTadd;
76   case ARMII::BX_RET: return ARM::BX_RET;
77   case ARMII::LDRrr: return ARM::LDR;
78   case ARMII::LDRri: return 0;
79   case ARMII::MOVr: return ARM::MOVr;
80   case ARMII::STRrr: return ARM::STR;
81   case ARMII::STRri: return 0;
82   case ARMII::SUBri: return ARM::SUBri;
83   case ARMII::SUBrs: return ARM::SUBrs;
84   case ARMII::SUBrr: return ARM::SUBrr;
85   default:
86     break;
87   }
88
89   return 0;
90 }
91
92 bool ARMInstrInfo::
93 BlockHasNoFallThrough(const MachineBasicBlock &MBB) const {
94   if (MBB.empty()) return false;
95
96   switch (MBB.back().getOpcode()) {
97   case ARM::BX_RET:   // Return.
98   case ARM::LDM_RET:
99   case ARM::B:
100   case ARM::BR_JTr:   // Jumptable branch.
101   case ARM::BR_JTm:   // Jumptable branch through mem.
102   case ARM::BR_JTadd: // Jumptable branch add to pc.
103     return true;
104   default:
105     break;
106   }
107
108   return false;
109 }
110
111 void ARMInstrInfo::
112 reMaterialize(MachineBasicBlock &MBB,
113               MachineBasicBlock::iterator I,
114               unsigned DestReg, unsigned SubIdx,
115               const MachineInstr *Orig) const {
116   DebugLoc dl = Orig->getDebugLoc();
117   if (Orig->getOpcode() == ARM::MOVi2pieces) {
118     RI.emitLoadConstPool(MBB, I, dl,
119                          DestReg, SubIdx,
120                          Orig->getOperand(1).getImm(),
121                          (ARMCC::CondCodes)Orig->getOperand(2).getImm(),
122                          Orig->getOperand(3).getReg());
123     return;
124   }
125
126   MachineInstr *MI = MBB.getParent()->CloneMachineInstr(Orig);
127   MI->getOperand(0).setReg(DestReg);
128   MBB.insert(I, MI);
129 }