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