blob: 4c92891c82bd6fca4a7313aa4287ff5c8d04a570 [file] [log] [blame]
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001//===- ARMInstrInfo.cpp - ARM Instruction Information -----------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner081ce942007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
Dan Gohmanf17a25c2007-07-18 16:29:46 +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"
16#include "ARMAddressingModes.h"
17#include "ARMGenInstrInfo.inc"
18#include "ARMMachineFunctionInfo.h"
Owen Anderson1636de92007-09-07 04:06:50 +000019#include "llvm/ADT/STLExtras.h"
Dan Gohmanf17a25c2007-07-18 16:29:46 +000020#include "llvm/CodeGen/LiveVariables.h"
Owen Anderson6690c7f2008-01-04 23:57:37 +000021#include "llvm/CodeGen/MachineFrameInfo.h"
Dan Gohmanf17a25c2007-07-18 16:29:46 +000022#include "llvm/CodeGen/MachineInstrBuilder.h"
23#include "llvm/CodeGen/MachineJumpTableInfo.h"
Chris Lattner621c44d2009-08-22 20:48:53 +000024#include "llvm/MC/MCAsmInfo.h"
Dan Gohmanf17a25c2007-07-18 16:29:46 +000025#include "llvm/Support/CommandLine.h"
26using namespace llvm;
27
Anton Korobeynikov65d16ea2009-06-26 21:28:53 +000028ARMInstrInfo::ARMInstrInfo(const ARMSubtarget &STI)
Chris Lattner5f1fdb32009-08-02 05:20:37 +000029 : RI(*this, STI), Subtarget(STI) {
Anton Korobeynikov65d16ea2009-06-26 21:28:53 +000030}
Dan Gohmanf17a25c2007-07-18 16:29:46 +000031
Chris Lattner5f1fdb32009-08-02 05:20:37 +000032unsigned ARMInstrInfo::getUnindexedOpcode(unsigned Opc) const {
Dan Gohmanf17a25c2007-07-18 16:29:46 +000033 switch (Opc) {
34 default: break;
35 case ARM::LDR_PRE:
36 case ARM::LDR_POST:
37 return ARM::LDR;
38 case ARM::LDRH_PRE:
39 case ARM::LDRH_POST:
40 return ARM::LDRH;
41 case ARM::LDRB_PRE:
42 case ARM::LDRB_POST:
43 return ARM::LDRB;
44 case ARM::LDRSH_PRE:
45 case ARM::LDRSH_POST:
46 return ARM::LDRSH;
47 case ARM::LDRSB_PRE:
48 case ARM::LDRSB_POST:
49 return ARM::LDRSB;
50 case ARM::STR_PRE:
51 case ARM::STR_POST:
52 return ARM::STR;
53 case ARM::STRH_PRE:
54 case ARM::STRH_POST:
55 return ARM::STRH;
56 case ARM::STRB_PRE:
57 case ARM::STRB_POST:
58 return ARM::STRB;
59 }
David Goodwin41afec22009-07-08 16:09:28 +000060
Dan Gohmanf17a25c2007-07-18 16:29:46 +000061 return 0;
62}
63
Chris Lattner5f1fdb32009-08-02 05:20:37 +000064bool ARMInstrInfo::BlockHasNoFallThrough(const MachineBasicBlock &MBB) const {
Dan Gohmanf17a25c2007-07-18 16:29:46 +000065 if (MBB.empty()) return false;
Anton Korobeynikov65d16ea2009-06-26 21:28:53 +000066
Dan Gohmanf17a25c2007-07-18 16:29:46 +000067 switch (MBB.back().getOpcode()) {
68 case ARM::BX_RET: // Return.
69 case ARM::LDM_RET:
Dan Gohmanf17a25c2007-07-18 16:29:46 +000070 case ARM::B:
Dan Gohmanf17a25c2007-07-18 16:29:46 +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;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000075 default:
Dan Gohmanf17a25c2007-07-18 16:29:46 +000076 break;
Evan Chenge4428082008-12-10 21:54:21 +000077 }
David Goodwinaca520d2009-07-02 22:18:33 +000078
79 return false;
80}
David Goodwin41afec22009-07-08 16:09:28 +000081
82void ARMInstrInfo::
83reMaterialize(MachineBasicBlock &MBB,
84 MachineBasicBlock::iterator I,
Evan Cheng463a3e42009-07-16 09:20:10 +000085 unsigned DestReg, unsigned SubIdx,
David Goodwin41afec22009-07-08 16:09:28 +000086 const MachineInstr *Orig) const {
87 DebugLoc dl = Orig->getDebugLoc();
88 if (Orig->getOpcode() == ARM::MOVi2pieces) {
David Goodwin1f0bb992009-07-08 20:28:28 +000089 RI.emitLoadConstPool(MBB, I, dl,
Evan Cheng463a3e42009-07-16 09:20:10 +000090 DestReg, SubIdx,
David Goodwin41afec22009-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 Lattner5f1fdb32009-08-02 05:20:37 +0000101