1 //===- ARMInstrInfo.h - ARM Instruction Information -------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file contains the ARM implementation of the TargetInstrInfo class.
12 //===----------------------------------------------------------------------===//
14 #ifndef ARMINSTRUCTIONINFO_H
15 #define ARMINSTRUCTIONINFO_H
17 #include "llvm/Target/TargetInstrInfo.h"
18 #include "ARMRegisterInfo.h"
23 /// ARMII - This namespace holds all of the target specific flags that
24 /// instruction info tracks.
28 //===------------------------------------------------------------------===//
31 //===------------------------------------------------------------------===//
32 // This three-bit field describes the addressing mode used. Zero is unused
33 // so that we can tell if we forgot to set a value.
45 AddrModeTs
= 9, // i8 * 4 for pc and sp relative data
47 // Size* - Flags to keep track of the size of an instruction.
49 SizeMask
= 7 << SizeShift
,
50 SizeSpecial
= 1, // 0 byte pseudo or special case.
55 // IndexMode - Unindex, pre-indexed, or post-indexed. Only valid for load
58 IndexModeMask
= 3 << IndexModeShift
,
64 OpcodeMask
= 0xf << OpcodeShift
,
68 FormMask
= 31 << FormShift
,
70 // Pseudo instructions
71 Pseudo
= 1 << FormShift
,
73 // Multiply instructions
74 MulFrm
= 2 << FormShift
,
75 MulSMLAW
= 3 << FormShift
,
76 MulSMULW
= 4 << FormShift
,
77 MulSMLA
= 5 << FormShift
,
78 MulSMUL
= 6 << FormShift
,
80 // Branch instructions
81 Branch
= 7 << FormShift
,
82 BranchMisc
= 8 << FormShift
,
84 // Data Processing instructions
85 DPRdIm
= 9 << FormShift
,
86 DPRdReg
= 10 << FormShift
,
87 DPRdSoReg
= 11 << FormShift
,
88 DPRdMisc
= 12 << FormShift
,
90 DPRnIm
= 13 << FormShift
,
91 DPRnReg
= 14 << FormShift
,
92 DPRnSoReg
= 15 << FormShift
,
94 DPRIm
= 16 << FormShift
,
95 DPRReg
= 17 << FormShift
,
96 DPRSoReg
= 18 << FormShift
,
98 DPRImS
= 19 << FormShift
,
99 DPRRegS
= 20 << FormShift
,
100 DPRSoRegS
= 21 << FormShift
,
103 LdFrm
= 22 << FormShift
,
104 StFrm
= 23 << FormShift
,
106 // Miscellaneous arithmetic instructions
107 ArithMisc
= 24 << FormShift
,
110 ThumbFrm
= 25 << FormShift
,
113 VPFFrm
= 26 << FormShift
,
115 // Field shifts - such shifts are used to set field while generating
116 // machine instructions.
128 class ARMInstrInfo
: public TargetInstrInfoImpl
{
129 const ARMRegisterInfo RI
;
131 ARMInstrInfo(const ARMSubtarget
&STI
);
133 /// getRegisterInfo - TargetInstrInfo is a superset of MRegister info. As
134 /// such, whenever a client has an instance of instruction info, it should
135 /// always be able to get register info as well (through this method).
137 virtual const MRegisterInfo
&getRegisterInfo() const { return RI
; }
139 /// getPointerRegClass - Return the register class to use to hold pointers.
140 /// This is used for addressing modes.
141 virtual const TargetRegisterClass
*getPointerRegClass() const;
143 /// Return true if the instruction is a register to register move and
144 /// leave the source and dest operands in the passed parameters.
146 virtual bool isMoveInstr(const MachineInstr
&MI
,
147 unsigned &SrcReg
, unsigned &DstReg
) const;
148 virtual unsigned isLoadFromStackSlot(MachineInstr
*MI
, int &FrameIndex
) const;
149 virtual unsigned isStoreToStackSlot(MachineInstr
*MI
, int &FrameIndex
) const;
151 virtual MachineInstr
*convertToThreeAddress(MachineFunction::iterator
&MFI
,
152 MachineBasicBlock::iterator
&MBBI
,
153 LiveVariables
&LV
) const;
156 virtual bool AnalyzeBranch(MachineBasicBlock
&MBB
, MachineBasicBlock
*&TBB
,
157 MachineBasicBlock
*&FBB
,
158 std::vector
<MachineOperand
> &Cond
) const;
159 virtual unsigned RemoveBranch(MachineBasicBlock
&MBB
) const;
160 virtual unsigned InsertBranch(MachineBasicBlock
&MBB
, MachineBasicBlock
*TBB
,
161 MachineBasicBlock
*FBB
,
162 const std::vector
<MachineOperand
> &Cond
) const;
163 virtual void copyRegToReg(MachineBasicBlock
&MBB
,
164 MachineBasicBlock::iterator I
,
165 unsigned DestReg
, unsigned SrcReg
,
166 const TargetRegisterClass
*DestRC
,
167 const TargetRegisterClass
*SrcRC
) const;
168 virtual void storeRegToStackSlot(MachineBasicBlock
&MBB
,
169 MachineBasicBlock::iterator MBBI
,
170 unsigned SrcReg
, bool isKill
, int FrameIndex
,
171 const TargetRegisterClass
*RC
) const;
173 virtual void storeRegToAddr(MachineFunction
&MF
, unsigned SrcReg
, bool isKill
,
174 SmallVectorImpl
<MachineOperand
> &Addr
,
175 const TargetRegisterClass
*RC
,
176 SmallVectorImpl
<MachineInstr
*> &NewMIs
) const;
178 virtual void loadRegFromStackSlot(MachineBasicBlock
&MBB
,
179 MachineBasicBlock::iterator MBBI
,
180 unsigned DestReg
, int FrameIndex
,
181 const TargetRegisterClass
*RC
) const;
183 virtual void loadRegFromAddr(MachineFunction
&MF
, unsigned DestReg
,
184 SmallVectorImpl
<MachineOperand
> &Addr
,
185 const TargetRegisterClass
*RC
,
186 SmallVectorImpl
<MachineInstr
*> &NewMIs
) const;
187 virtual bool spillCalleeSavedRegisters(MachineBasicBlock
&MBB
,
188 MachineBasicBlock::iterator MI
,
189 const std::vector
<CalleeSavedInfo
> &CSI
) const;
190 virtual bool restoreCalleeSavedRegisters(MachineBasicBlock
&MBB
,
191 MachineBasicBlock::iterator MI
,
192 const std::vector
<CalleeSavedInfo
> &CSI
) const;
194 virtual MachineInstr
* foldMemoryOperand(MachineInstr
* MI
,
195 SmallVectorImpl
<unsigned> &Ops
,
196 int FrameIndex
) const;
198 virtual MachineInstr
* foldMemoryOperand(MachineInstr
* MI
,
199 SmallVectorImpl
<unsigned> &Ops
,
200 MachineInstr
* LoadMI
) const {
204 virtual bool canFoldMemoryOperand(MachineInstr
*MI
,
205 SmallVectorImpl
<unsigned> &Ops
) const;
207 virtual bool BlockHasNoFallThrough(MachineBasicBlock
&MBB
) const;
208 virtual bool ReverseBranchCondition(std::vector
<MachineOperand
> &Cond
) const;
210 // Predication support.
211 virtual bool isPredicated(const MachineInstr
*MI
) const;
214 bool PredicateInstruction(MachineInstr
*MI
,
215 const std::vector
<MachineOperand
> &Pred
) const;
218 bool SubsumesPredicate(const std::vector
<MachineOperand
> &Pred1
,
219 const std::vector
<MachineOperand
> &Pred2
) const;
221 virtual bool DefinesPredicate(MachineInstr
*MI
,
222 std::vector
<MachineOperand
> &Pred
) const;
227 /// GetInstSize - Returns the size of the specified MachineInstr.
229 unsigned GetInstSize(MachineInstr
*MI
);
231 /// GetFunctionSize - Returns the size of the specified MachineFunction.
233 unsigned GetFunctionSize(MachineFunction
&MF
);