- Add pseudo instructions tLDRpci_pic and t2LDRpci_pic which does a pc-relative
[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/MC/MCAsmInfo.h"
25 using namespace llvm;
26
27 ARMInstrInfo::ARMInstrInfo(const ARMSubtarget &STI)
28   : ARMBaseInstrInfo(STI), RI(*this, STI) {
29 }
30
31 unsigned ARMInstrInfo::getUnindexedOpcode(unsigned Opc) const {
32   switch (Opc) {
33   default: break;
34   case ARM::LDR_PRE:
35   case ARM::LDR_POST:
36     return ARM::LDR;
37   case ARM::LDRH_PRE:
38   case ARM::LDRH_POST:
39     return ARM::LDRH;
40   case ARM::LDRB_PRE:
41   case ARM::LDRB_POST:
42     return ARM::LDRB;
43   case ARM::LDRSH_PRE:
44   case ARM::LDRSH_POST:
45     return ARM::LDRSH;
46   case ARM::LDRSB_PRE:
47   case ARM::LDRSB_POST:
48     return ARM::LDRSB;
49   case ARM::STR_PRE:
50   case ARM::STR_POST:
51     return ARM::STR;
52   case ARM::STRH_PRE:
53   case ARM::STRH_POST:
54     return ARM::STRH;
55   case ARM::STRB_PRE:
56   case ARM::STRB_POST:
57     return ARM::STRB;
58   }
59
60   return 0;
61 }
62
63 bool ARMInstrInfo::BlockHasNoFallThrough(const MachineBasicBlock &MBB) const {
64   if (MBB.empty()) return false;
65
66   switch (MBB.back().getOpcode()) {
67   case ARM::BX_RET:   // Return.
68   case ARM::LDM_RET:
69   case ARM::B:
70   case ARM::BRIND:
71   case ARM::BR_JTr:   // Jumptable branch.
72   case ARM::BR_JTm:   // Jumptable branch through mem.
73   case ARM::BR_JTadd: // Jumptable branch add to pc.
74     return true;
75   default:
76     break;
77   }
78
79   return false;
80 }
81
82 void ARMInstrInfo::
83 reMaterialize(MachineBasicBlock &MBB,
84               MachineBasicBlock::iterator I,
85               unsigned DestReg, unsigned SubIdx,
86               const MachineInstr *Orig) const {
87   DebugLoc dl = Orig->getDebugLoc();
88   unsigned Opcode = Orig->getOpcode();
89   switch (Opcode) {
90   default: {
91     MachineInstr *MI = MBB.getParent()->CloneMachineInstr(Orig);
92     MI->getOperand(0).setReg(DestReg);
93     MBB.insert(I, MI);
94     break;
95   }
96   case ARM::MOVi2pieces:
97     RI.emitLoadConstPool(MBB, I, dl,
98                          DestReg, SubIdx,
99                          Orig->getOperand(1).getImm(),
100                          (ARMCC::CondCodes)Orig->getOperand(2).getImm(),
101                          Orig->getOperand(3).getReg());
102     break;
103   }
104
105   MachineInstr *NewMI = prior(I);
106   NewMI->getOperand(0).setSubReg(SubIdx);
107 }
108