blob: 86bbe2a4c61f2612069d2b6d9644f9f7e8683f93 [file] [log] [blame]
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00001//===- ARMInstrInfo.cpp - ARM Instruction Information -----------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00006// 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"
Evan Chenga8e29892007-01-19 07:51:42 +000016#include "ARMAddressingModes.h"
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000017#include "ARMGenInstrInfo.inc"
Evan Chenga8e29892007-01-19 07:51:42 +000018#include "ARMMachineFunctionInfo.h"
Owen Anderson718cb662007-09-07 04:06:50 +000019#include "llvm/ADT/STLExtras.h"
Evan Chenga8e29892007-01-19 07:51:42 +000020#include "llvm/CodeGen/LiveVariables.h"
Owen Andersond94b6a12008-01-04 23:57:37 +000021#include "llvm/CodeGen/MachineFrameInfo.h"
Evan Cheng29836c32007-01-29 23:45:17 +000022#include "llvm/CodeGen/MachineInstrBuilder.h"
23#include "llvm/CodeGen/MachineJumpTableInfo.h"
Chris Lattneraf76e592009-08-22 20:48:53 +000024#include "llvm/MC/MCAsmInfo.h"
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000025using namespace llvm;
26
Anton Korobeynikovd49ea772009-06-26 21:28:53 +000027ARMInstrInfo::ARMInstrInfo(const ARMSubtarget &STI)
Anton Korobeynikovf95215f2009-11-02 00:10:38 +000028 : ARMBaseInstrInfo(STI), RI(*this, STI) {
Anton Korobeynikovd49ea772009-06-26 21:28:53 +000029}
Rafael Espindola46adf812006-08-08 20:35:03 +000030
Chris Lattnerd90183d2009-08-02 05:20:37 +000031unsigned ARMInstrInfo::getUnindexedOpcode(unsigned Opc) const {
Evan Chenga8e29892007-01-19 07:51:42 +000032 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 }
David Goodwin334c2642009-07-08 16:09:28 +000059
Evan Chenga8e29892007-01-19 07:51:42 +000060 return 0;
61}
62
Chris Lattnerd90183d2009-08-02 05:20:37 +000063bool ARMInstrInfo::BlockHasNoFallThrough(const MachineBasicBlock &MBB) const {
Evan Chenga8e29892007-01-19 07:51:42 +000064 if (MBB.empty()) return false;
Anton Korobeynikovd49ea772009-06-26 21:28:53 +000065
Evan Chenga8e29892007-01-19 07:51:42 +000066 switch (MBB.back().getOpcode()) {
Evan Cheng5a18ebc2007-05-21 18:56:31 +000067 case ARM::BX_RET: // Return.
68 case ARM::LDM_RET:
Evan Chenga8e29892007-01-19 07:51:42 +000069 case ARM::B:
Bob Wilson8d4de5a2009-10-28 18:26:41 +000070 case ARM::BRIND:
Evan Chenga8e29892007-01-19 07:51:42 +000071 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;
Evan Cheng69d55562007-05-23 07:22:05 +000075 default:
Evan Cheng29836c32007-01-29 23:45:17 +000076 break;
Evan Chenge5ad88e2008-12-10 21:54:21 +000077 }
David Goodwinb50ea5c2009-07-02 22:18:33 +000078
79 return false;
80}
David Goodwin334c2642009-07-08 16:09:28 +000081
82void ARMInstrInfo::
83reMaterialize(MachineBasicBlock &MBB,
84 MachineBasicBlock::iterator I,
Evan Cheng37844532009-07-16 09:20:10 +000085 unsigned DestReg, unsigned SubIdx,
David Goodwin334c2642009-07-08 16:09:28 +000086 const MachineInstr *Orig) const {
87 DebugLoc dl = Orig->getDebugLoc();
88 if (Orig->getOpcode() == ARM::MOVi2pieces) {
David Goodwin77521f52009-07-08 20:28:28 +000089 RI.emitLoadConstPool(MBB, I, dl,
Evan Cheng37844532009-07-16 09:20:10 +000090 DestReg, SubIdx,
David Goodwin334c2642009-07-08 16:09:28 +000091 Orig->getOperand(1).getImm(),
92 (ARMCC::CondCodes)Orig->getOperand(2).getImm(),
93 Orig->getOperand(3).getReg());
94 return;
95 }
96
97 MachineInstr *MI = MBB.getParent()->CloneMachineInstr(Orig);
98 MI->getOperand(0).setReg(DestReg);
99 MBB.insert(I, MI);
100}
Chris Lattnerd90183d2009-08-02 05:20:37 +0000101