blob: 4202b0151bfa5c2affd287ccb755ee6a3b4b644d [file] [log] [blame]
David Goodwinaca520d2009-07-02 22:18:33 +00001//===- Thumb2InstrInfo.cpp - Thumb-2 Instruction Information --------*- C++ -*-===//
Anton Korobeynikov65d16ea2009-06-26 21:28:53 +00002//
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//
David Goodwinaca520d2009-07-02 22:18:33 +000010// This file contains the Thumb-2 implementation of the TargetInstrInfo class.
Anton Korobeynikov65d16ea2009-06-26 21:28:53 +000011//
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"
David Goodwinaca520d2009-07-02 22:18:33 +000021#include "Thumb2InstrInfo.h"
Anton Korobeynikov65d16ea2009-06-26 21:28:53 +000022
23using namespace llvm;
24
David Goodwinaca520d2009-07-02 22:18:33 +000025Thumb2InstrInfo::Thumb2InstrInfo(const ARMSubtarget &STI)
Anton Korobeynikovcbce7922009-06-27 12:16:40 +000026 : ARMBaseInstrInfo(STI), RI(*this, STI) {
Anton Korobeynikov65d16ea2009-06-26 21:28:53 +000027}
28
Evan Cheng7bd2ad12009-07-11 06:43:01 +000029unsigned Thumb2InstrInfo::getUnindexedOpcode(unsigned Opc) const {
David Goodwin41afec22009-07-08 16:09:28 +000030 // FIXME
31 return 0;
32}
33
Evan Cheng7bd2ad12009-07-11 06:43:01 +000034unsigned Thumb2InstrInfo::getOpcode(ARMII::Op Op) const {
David Goodwin41afec22009-07-08 16:09:28 +000035 switch (Op) {
36 case ARMII::ADDri: return ARM::t2ADDri;
37 case ARMII::ADDrs: return ARM::t2ADDrs;
38 case ARMII::ADDrr: return ARM::t2ADDrr;
39 case ARMII::B: return ARM::t2B;
40 case ARMII::Bcc: return ARM::t2Bcc;
41 case ARMII::BR_JTr: return ARM::t2BR_JTr;
42 case ARMII::BR_JTm: return ARM::t2BR_JTm;
43 case ARMII::BR_JTadd: return ARM::t2BR_JTadd;
Evan Cheng7bd2ad12009-07-11 06:43:01 +000044 case ARMII::BX_RET: return ARM::tBX_RET;
David Goodwin7938afc2009-07-24 00:16:18 +000045 case ARMII::LDRrr: return ARM::t2LDRs;
46 case ARMII::LDRri: return ARM::t2LDRi12;
David Goodwin41afec22009-07-08 16:09:28 +000047 case ARMII::MOVr: return ARM::t2MOVr;
David Goodwin7938afc2009-07-24 00:16:18 +000048 case ARMII::STRrr: return ARM::t2STRs;
49 case ARMII::STRri: return ARM::t2STRi12;
David Goodwin41afec22009-07-08 16:09:28 +000050 case ARMII::SUBri: return ARM::t2SUBri;
51 case ARMII::SUBrs: return ARM::t2SUBrs;
52 case ARMII::SUBrr: return ARM::t2SUBrr;
David Goodwin41afec22009-07-08 16:09:28 +000053 default:
54 break;
55 }
56
57 return 0;
58}
59
60bool
61Thumb2InstrInfo::BlockHasNoFallThrough(const MachineBasicBlock &MBB) const {
62 if (MBB.empty()) return false;
63
64 // FIXME
65 switch (MBB.back().getOpcode()) {
David Goodwin48743562009-07-10 15:33:46 +000066 case ARM::t2LDM_RET:
David Goodwin41afec22009-07-08 16:09:28 +000067 case ARM::t2B: // Uncond branch.
68 case ARM::t2BR_JTr: // Jumptable branch.
69 case ARM::t2BR_JTm: // Jumptable branch through mem.
70 case ARM::t2BR_JTadd: // Jumptable branch add to pc.
71 return true;
72 case ARM::tBX_RET:
73 case ARM::tBX_RET_vararg:
74 case ARM::tPOP_RET:
75 case ARM::tB:
76 case ARM::tBR_JTr:
77 return true;
78 default:
79 break;
80 }
81
82 return false;
83}
Anton Korobeynikov24270fa2009-07-16 23:26:06 +000084
85bool
86Thumb2InstrInfo::copyRegToReg(MachineBasicBlock &MBB,
87 MachineBasicBlock::iterator I,
88 unsigned DestReg, unsigned SrcReg,
89 const TargetRegisterClass *DestRC,
90 const TargetRegisterClass *SrcRC) const {
91 DebugLoc DL = DebugLoc::getUnknownLoc();
92 if (I != MBB.end()) DL = I->getDebugLoc();
93
94 if ((DestRC == ARM::GPRRegisterClass &&
95 SrcRC == ARM::tGPRRegisterClass) ||
96 (DestRC == ARM::tGPRRegisterClass &&
97 SrcRC == ARM::GPRRegisterClass)) {
98 AddDefaultCC(AddDefaultPred(BuildMI(MBB, I, DL, get(getOpcode(ARMII::MOVr)),
99 DestReg).addReg(SrcReg)));
100 return true;
101 }
102
103 return ARMBaseInstrInfo::copyRegToReg(MBB, I, DestReg, SrcReg, DestRC, SrcRC);
104}