1 //===-- ARMExpandPseudoInsts.cpp - Expand pseudo instructions -------------===//
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 a pass that expands pseudo instructions into target
11 // instructions to allow proper scheduling, if-conversion, and other late
12 // optimizations. This pass should be run after register allocation but before
13 // the post-regalloc scheduling pass.
15 //===----------------------------------------------------------------------===//
17 #define DEBUG_TYPE "arm-pseudo"
19 #include "ARMBaseInstrInfo.h"
20 #include "ARMBaseRegisterInfo.h"
21 #include "ARMMachineFunctionInfo.h"
22 #include "MCTargetDesc/ARMAddressingModes.h"
23 #include "llvm/CodeGen/MachineFrameInfo.h"
24 #include "llvm/CodeGen/MachineFunctionPass.h"
25 #include "llvm/CodeGen/MachineInstrBuilder.h"
26 #include "llvm/Target/TargetFrameLowering.h"
27 #include "llvm/Target/TargetRegisterInfo.h"
28 #include "llvm/Support/CommandLine.h"
29 #include "llvm/Support/raw_ostream.h" // FIXME: for debug only. remove!
33 VerifyARMPseudo("verify-arm-pseudo-expand", cl::Hidden,
34 cl::desc("Verify machine code after expanding ARM pseudos"));
37 class ARMExpandPseudo : public MachineFunctionPass {
40 ARMExpandPseudo() : MachineFunctionPass(ID) {}
42 const ARMBaseInstrInfo *TII;
43 const TargetRegisterInfo *TRI;
44 const ARMSubtarget *STI;
47 virtual bool runOnMachineFunction(MachineFunction &Fn);
49 virtual const char *getPassName() const {
50 return "ARM pseudo instruction expansion pass";
54 void TransferImpOps(MachineInstr &OldMI,
55 MachineInstrBuilder &UseMI, MachineInstrBuilder &DefMI);
56 bool ExpandMI(MachineBasicBlock &MBB,
57 MachineBasicBlock::iterator MBBI);
58 bool ExpandMBB(MachineBasicBlock &MBB);
59 void ExpandVLD(MachineBasicBlock::iterator &MBBI);
60 void ExpandVST(MachineBasicBlock::iterator &MBBI);
61 void ExpandLaneOp(MachineBasicBlock::iterator &MBBI);
62 void ExpandVTBL(MachineBasicBlock::iterator &MBBI,
63 unsigned Opc, bool IsExt);
64 void ExpandMOV32BitImm(MachineBasicBlock &MBB,
65 MachineBasicBlock::iterator &MBBI);
67 char ARMExpandPseudo::ID = 0;
70 /// TransferImpOps - Transfer implicit operands on the pseudo instruction to
71 /// the instructions created from the expansion.
72 void ARMExpandPseudo::TransferImpOps(MachineInstr &OldMI,
73 MachineInstrBuilder &UseMI,
74 MachineInstrBuilder &DefMI) {
75 const MCInstrDesc &Desc = OldMI.getDesc();
76 for (unsigned i = Desc.getNumOperands(), e = OldMI.getNumOperands();
78 const MachineOperand &MO = OldMI.getOperand(i);
79 assert(MO.isReg() && MO.getReg());
88 // Constants for register spacing in NEON load/store instructions.
89 // For quad-register load-lane and store-lane pseudo instructors, the
90 // spacing is initially assumed to be EvenDblSpc, and that is changed to
91 // OddDblSpc depending on the lane number operand.
98 // Entries for NEON load/store information table. The table is sorted by
99 // PseudoOpc for fast binary-search lookups.
100 struct NEONLdStTableEntry {
105 bool hasWritebackOperand;
106 NEONRegSpacing RegSpacing;
107 unsigned char NumRegs; // D registers loaded or stored
108 unsigned char RegElts; // elements per D register; used for lane ops
109 // FIXME: Temporary flag to denote whether the real instruction takes
110 // a single register (like the encoding) or all of the registers in
111 // the list (like the asm syntax and the isel DAG). When all definitions
112 // are converted to take only the single encoded register, this will
114 bool copyAllListRegs;
116 // Comparison methods for binary search of the table.
117 bool operator<(const NEONLdStTableEntry &TE) const {
118 return PseudoOpc < TE.PseudoOpc;
120 friend bool operator<(const NEONLdStTableEntry &TE, unsigned PseudoOpc) {
121 return TE.PseudoOpc < PseudoOpc;
123 friend bool LLVM_ATTRIBUTE_UNUSED operator<(unsigned PseudoOpc,
124 const NEONLdStTableEntry &TE) {
125 return PseudoOpc < TE.PseudoOpc;
130 static const NEONLdStTableEntry NEONLdStTable[] = {
131 { ARM::VLD1LNq16Pseudo, ARM::VLD1LNd16, true, false, false, EvenDblSpc, 1, 4 ,true},
132 { ARM::VLD1LNq16Pseudo_UPD, ARM::VLD1LNd16_UPD, true, true, true, EvenDblSpc, 1, 4 ,true},
133 { ARM::VLD1LNq32Pseudo, ARM::VLD1LNd32, true, false, false, EvenDblSpc, 1, 2 ,true},
134 { ARM::VLD1LNq32Pseudo_UPD, ARM::VLD1LNd32_UPD, true, true, true, EvenDblSpc, 1, 2 ,true},
135 { ARM::VLD1LNq8Pseudo, ARM::VLD1LNd8, true, false, false, EvenDblSpc, 1, 8 ,true},
136 { ARM::VLD1LNq8Pseudo_UPD, ARM::VLD1LNd8_UPD, true, true, true, EvenDblSpc, 1, 8 ,true},
138 { ARM::VLD1d64QPseudo, ARM::VLD1d64Q, true, false, false, SingleSpc, 4, 1 ,false},
139 { ARM::VLD1d64TPseudo, ARM::VLD1d64T, true, false, false, SingleSpc, 3, 1 ,false},
141 { ARM::VLD2LNd16Pseudo, ARM::VLD2LNd16, true, false, false, SingleSpc, 2, 4 ,true},
142 { ARM::VLD2LNd16Pseudo_UPD, ARM::VLD2LNd16_UPD, true, true, true, SingleSpc, 2, 4 ,true},
143 { ARM::VLD2LNd32Pseudo, ARM::VLD2LNd32, true, false, false, SingleSpc, 2, 2 ,true},
144 { ARM::VLD2LNd32Pseudo_UPD, ARM::VLD2LNd32_UPD, true, true, true, SingleSpc, 2, 2 ,true},
145 { ARM::VLD2LNd8Pseudo, ARM::VLD2LNd8, true, false, false, SingleSpc, 2, 8 ,true},
146 { ARM::VLD2LNd8Pseudo_UPD, ARM::VLD2LNd8_UPD, true, true, true, SingleSpc, 2, 8 ,true},
147 { ARM::VLD2LNq16Pseudo, ARM::VLD2LNq16, true, false, false, EvenDblSpc, 2, 4 ,true},
148 { ARM::VLD2LNq16Pseudo_UPD, ARM::VLD2LNq16_UPD, true, true, true, EvenDblSpc, 2, 4 ,true},
149 { ARM::VLD2LNq32Pseudo, ARM::VLD2LNq32, true, false, false, EvenDblSpc, 2, 2 ,true},
150 { ARM::VLD2LNq32Pseudo_UPD, ARM::VLD2LNq32_UPD, true, true, true, EvenDblSpc, 2, 2 ,true},
152 { ARM::VLD2q16Pseudo, ARM::VLD2q16, true, false, false, SingleSpc, 4, 4 ,false},
153 { ARM::VLD2q16PseudoWB_fixed, ARM::VLD2q16wb_fixed, true, true, false, SingleSpc, 4, 4 ,false},
154 { ARM::VLD2q16PseudoWB_register, ARM::VLD2q16wb_register, true, true, true, SingleSpc, 4, 4 ,false},
155 { ARM::VLD2q32Pseudo, ARM::VLD2q32, true, false, false, SingleSpc, 4, 2 ,false},
156 { ARM::VLD2q32PseudoWB_fixed, ARM::VLD2q32wb_fixed, true, true, false, SingleSpc, 4, 2 ,false},
157 { ARM::VLD2q32PseudoWB_register, ARM::VLD2q32wb_register, true, true, true, SingleSpc, 4, 2 ,false},
158 { ARM::VLD2q8Pseudo, ARM::VLD2q8, true, false, false, SingleSpc, 4, 8 ,false},
159 { ARM::VLD2q8PseudoWB_fixed, ARM::VLD2q8wb_fixed, true, true, false, SingleSpc, 4, 8 ,false},
160 { ARM::VLD2q8PseudoWB_register, ARM::VLD2q8wb_register, true, true, true, SingleSpc, 4, 8 ,false},
162 { ARM::VLD3DUPd16Pseudo, ARM::VLD3DUPd16, true, false, false, SingleSpc, 3, 4,true},
163 { ARM::VLD3DUPd16Pseudo_UPD, ARM::VLD3DUPd16_UPD, true, true, true, SingleSpc, 3, 4,true},
164 { ARM::VLD3DUPd32Pseudo, ARM::VLD3DUPd32, true, false, false, SingleSpc, 3, 2,true},
165 { ARM::VLD3DUPd32Pseudo_UPD, ARM::VLD3DUPd32_UPD, true, true, true, SingleSpc, 3, 2,true},
166 { ARM::VLD3DUPd8Pseudo, ARM::VLD3DUPd8, true, false, false, SingleSpc, 3, 8,true},
167 { ARM::VLD3DUPd8Pseudo_UPD, ARM::VLD3DUPd8_UPD, true, true, true, SingleSpc, 3, 8,true},
169 { ARM::VLD3LNd16Pseudo, ARM::VLD3LNd16, true, false, false, SingleSpc, 3, 4 ,true},
170 { ARM::VLD3LNd16Pseudo_UPD, ARM::VLD3LNd16_UPD, true, true, true, SingleSpc, 3, 4 ,true},
171 { ARM::VLD3LNd32Pseudo, ARM::VLD3LNd32, true, false, false, SingleSpc, 3, 2 ,true},
172 { ARM::VLD3LNd32Pseudo_UPD, ARM::VLD3LNd32_UPD, true, true, true, SingleSpc, 3, 2 ,true},
173 { ARM::VLD3LNd8Pseudo, ARM::VLD3LNd8, true, false, false, SingleSpc, 3, 8 ,true},
174 { ARM::VLD3LNd8Pseudo_UPD, ARM::VLD3LNd8_UPD, true, true, true, SingleSpc, 3, 8 ,true},
175 { ARM::VLD3LNq16Pseudo, ARM::VLD3LNq16, true, false, false, EvenDblSpc, 3, 4 ,true},
176 { ARM::VLD3LNq16Pseudo_UPD, ARM::VLD3LNq16_UPD, true, true, true, EvenDblSpc, 3, 4 ,true},
177 { ARM::VLD3LNq32Pseudo, ARM::VLD3LNq32, true, false, false, EvenDblSpc, 3, 2 ,true},
178 { ARM::VLD3LNq32Pseudo_UPD, ARM::VLD3LNq32_UPD, true, true, true, EvenDblSpc, 3, 2 ,true},
180 { ARM::VLD3d16Pseudo, ARM::VLD3d16, true, false, false, SingleSpc, 3, 4 ,true},
181 { ARM::VLD3d16Pseudo_UPD, ARM::VLD3d16_UPD, true, true, true, SingleSpc, 3, 4 ,true},
182 { ARM::VLD3d32Pseudo, ARM::VLD3d32, true, false, false, SingleSpc, 3, 2 ,true},
183 { ARM::VLD3d32Pseudo_UPD, ARM::VLD3d32_UPD, true, true, true, SingleSpc, 3, 2 ,true},
184 { ARM::VLD3d8Pseudo, ARM::VLD3d8, true, false, false, SingleSpc, 3, 8 ,true},
185 { ARM::VLD3d8Pseudo_UPD, ARM::VLD3d8_UPD, true, true, true, SingleSpc, 3, 8 ,true},
187 { ARM::VLD3q16Pseudo_UPD, ARM::VLD3q16_UPD, true, true, true, EvenDblSpc, 3, 4 ,true},
188 { ARM::VLD3q16oddPseudo, ARM::VLD3q16, true, false, false, OddDblSpc, 3, 4 ,true},
189 { ARM::VLD3q16oddPseudo_UPD, ARM::VLD3q16_UPD, true, true, true, OddDblSpc, 3, 4 ,true},
190 { ARM::VLD3q32Pseudo_UPD, ARM::VLD3q32_UPD, true, true, true, EvenDblSpc, 3, 2 ,true},
191 { ARM::VLD3q32oddPseudo, ARM::VLD3q32, true, false, false, OddDblSpc, 3, 2 ,true},
192 { ARM::VLD3q32oddPseudo_UPD, ARM::VLD3q32_UPD, true, true, true, OddDblSpc, 3, 2 ,true},
193 { ARM::VLD3q8Pseudo_UPD, ARM::VLD3q8_UPD, true, true, true, EvenDblSpc, 3, 8 ,true},
194 { ARM::VLD3q8oddPseudo, ARM::VLD3q8, true, false, false, OddDblSpc, 3, 8 ,true},
195 { ARM::VLD3q8oddPseudo_UPD, ARM::VLD3q8_UPD, true, true, true, OddDblSpc, 3, 8 ,true},
197 { ARM::VLD4DUPd16Pseudo, ARM::VLD4DUPd16, true, false, false, SingleSpc, 4, 4,true},
198 { ARM::VLD4DUPd16Pseudo_UPD, ARM::VLD4DUPd16_UPD, true, true, true, SingleSpc, 4, 4,true},
199 { ARM::VLD4DUPd32Pseudo, ARM::VLD4DUPd32, true, false, false, SingleSpc, 4, 2,true},
200 { ARM::VLD4DUPd32Pseudo_UPD, ARM::VLD4DUPd32_UPD, true, true, true, SingleSpc, 4, 2,true},
201 { ARM::VLD4DUPd8Pseudo, ARM::VLD4DUPd8, true, false, false, SingleSpc, 4, 8,true},
202 { ARM::VLD4DUPd8Pseudo_UPD, ARM::VLD4DUPd8_UPD, true, true, true, SingleSpc, 4, 8,true},
204 { ARM::VLD4LNd16Pseudo, ARM::VLD4LNd16, true, false, false, SingleSpc, 4, 4 ,true},
205 { ARM::VLD4LNd16Pseudo_UPD, ARM::VLD4LNd16_UPD, true, true, true, SingleSpc, 4, 4 ,true},
206 { ARM::VLD4LNd32Pseudo, ARM::VLD4LNd32, true, false, false, SingleSpc, 4, 2 ,true},
207 { ARM::VLD4LNd32Pseudo_UPD, ARM::VLD4LNd32_UPD, true, true, true, SingleSpc, 4, 2 ,true},
208 { ARM::VLD4LNd8Pseudo, ARM::VLD4LNd8, true, false, false, SingleSpc, 4, 8 ,true},
209 { ARM::VLD4LNd8Pseudo_UPD, ARM::VLD4LNd8_UPD, true, true, true, SingleSpc, 4, 8 ,true},
210 { ARM::VLD4LNq16Pseudo, ARM::VLD4LNq16, true, false, false, EvenDblSpc, 4, 4 ,true},
211 { ARM::VLD4LNq16Pseudo_UPD, ARM::VLD4LNq16_UPD, true, true, true, EvenDblSpc, 4, 4 ,true},
212 { ARM::VLD4LNq32Pseudo, ARM::VLD4LNq32, true, false, false, EvenDblSpc, 4, 2 ,true},
213 { ARM::VLD4LNq32Pseudo_UPD, ARM::VLD4LNq32_UPD, true, true, true, EvenDblSpc, 4, 2 ,true},
215 { ARM::VLD4d16Pseudo, ARM::VLD4d16, true, false, false, SingleSpc, 4, 4 ,true},
216 { ARM::VLD4d16Pseudo_UPD, ARM::VLD4d16_UPD, true, true, true, SingleSpc, 4, 4 ,true},
217 { ARM::VLD4d32Pseudo, ARM::VLD4d32, true, false, false, SingleSpc, 4, 2 ,true},
218 { ARM::VLD4d32Pseudo_UPD, ARM::VLD4d32_UPD, true, true, true, SingleSpc, 4, 2 ,true},
219 { ARM::VLD4d8Pseudo, ARM::VLD4d8, true, false, false, SingleSpc, 4, 8 ,true},
220 { ARM::VLD4d8Pseudo_UPD, ARM::VLD4d8_UPD, true, true, true, SingleSpc, 4, 8 ,true},
222 { ARM::VLD4q16Pseudo_UPD, ARM::VLD4q16_UPD, true, true, true, EvenDblSpc, 4, 4 ,true},
223 { ARM::VLD4q16oddPseudo, ARM::VLD4q16, true, false, false, OddDblSpc, 4, 4 ,true},
224 { ARM::VLD4q16oddPseudo_UPD, ARM::VLD4q16_UPD, true, true, true, OddDblSpc, 4, 4 ,true},
225 { ARM::VLD4q32Pseudo_UPD, ARM::VLD4q32_UPD, true, true, true, EvenDblSpc, 4, 2 ,true},
226 { ARM::VLD4q32oddPseudo, ARM::VLD4q32, true, false, false, OddDblSpc, 4, 2 ,true},
227 { ARM::VLD4q32oddPseudo_UPD, ARM::VLD4q32_UPD, true, true, true, OddDblSpc, 4, 2 ,true},
228 { ARM::VLD4q8Pseudo_UPD, ARM::VLD4q8_UPD, true, true, true, EvenDblSpc, 4, 8 ,true},
229 { ARM::VLD4q8oddPseudo, ARM::VLD4q8, true, false, false, OddDblSpc, 4, 8 ,true},
230 { ARM::VLD4q8oddPseudo_UPD, ARM::VLD4q8_UPD, true, true, true, OddDblSpc, 4, 8 ,true},
232 { ARM::VST1LNq16Pseudo, ARM::VST1LNd16, false, false, false, EvenDblSpc, 1, 4 ,true},
233 { ARM::VST1LNq16Pseudo_UPD, ARM::VST1LNd16_UPD, false, true, true, EvenDblSpc, 1, 4 ,true},
234 { ARM::VST1LNq32Pseudo, ARM::VST1LNd32, false, false, false, EvenDblSpc, 1, 2 ,true},
235 { ARM::VST1LNq32Pseudo_UPD, ARM::VST1LNd32_UPD, false, true, true, EvenDblSpc, 1, 2 ,true},
236 { ARM::VST1LNq8Pseudo, ARM::VST1LNd8, false, false, false, EvenDblSpc, 1, 8 ,true},
237 { ARM::VST1LNq8Pseudo_UPD, ARM::VST1LNd8_UPD, false, true, true, EvenDblSpc, 1, 8 ,true},
239 { ARM::VST1d64QPseudo, ARM::VST1d64Q, false, false, false, SingleSpc, 4, 1 ,false},
240 { ARM::VST1d64QPseudoWB_fixed, ARM::VST1d64Qwb_fixed, false, true, false, SingleSpc, 4, 1 ,false},
241 { ARM::VST1d64QPseudoWB_register, ARM::VST1d64Qwb_register, false, true, true, SingleSpc, 4, 1 ,false},
242 { ARM::VST1d64TPseudo, ARM::VST1d64T, false, false, false, SingleSpc, 3, 1 ,false},
243 { ARM::VST1d64TPseudoWB_fixed, ARM::VST1d64Twb_fixed, false, true, false, SingleSpc, 3, 1 ,false},
244 { ARM::VST1d64TPseudoWB_register, ARM::VST1d64Twb_register, false, true, true, SingleSpc, 3, 1 ,false},
246 { ARM::VST2LNd16Pseudo, ARM::VST2LNd16, false, false, false, SingleSpc, 2, 4 ,true},
247 { ARM::VST2LNd16Pseudo_UPD, ARM::VST2LNd16_UPD, false, true, true, SingleSpc, 2, 4 ,true},
248 { ARM::VST2LNd32Pseudo, ARM::VST2LNd32, false, false, false, SingleSpc, 2, 2 ,true},
249 { ARM::VST2LNd32Pseudo_UPD, ARM::VST2LNd32_UPD, false, true, true, SingleSpc, 2, 2 ,true},
250 { ARM::VST2LNd8Pseudo, ARM::VST2LNd8, false, false, false, SingleSpc, 2, 8 ,true},
251 { ARM::VST2LNd8Pseudo_UPD, ARM::VST2LNd8_UPD, false, true, true, SingleSpc, 2, 8 ,true},
252 { ARM::VST2LNq16Pseudo, ARM::VST2LNq16, false, false, false, EvenDblSpc, 2, 4,true},
253 { ARM::VST2LNq16Pseudo_UPD, ARM::VST2LNq16_UPD, false, true, true, EvenDblSpc, 2, 4,true},
254 { ARM::VST2LNq32Pseudo, ARM::VST2LNq32, false, false, false, EvenDblSpc, 2, 2,true},
255 { ARM::VST2LNq32Pseudo_UPD, ARM::VST2LNq32_UPD, false, true, true, EvenDblSpc, 2, 2,true},
257 { ARM::VST2q16Pseudo, ARM::VST2q16, false, false, false, SingleSpc, 4, 4 ,false},
258 { ARM::VST2q16PseudoWB_fixed, ARM::VST2q16wb_fixed, false, true, false, SingleSpc, 4, 4 ,false},
259 { ARM::VST2q16PseudoWB_register, ARM::VST2q16wb_register, false, true, true, SingleSpc, 4, 4 ,false},
260 { ARM::VST2q32Pseudo, ARM::VST2q32, false, false, false, SingleSpc, 4, 2 ,false},
261 { ARM::VST2q32PseudoWB_fixed, ARM::VST2q32wb_fixed, false, true, false, SingleSpc, 4, 2 ,false},
262 { ARM::VST2q32PseudoWB_register, ARM::VST2q32wb_register, false, true, true, SingleSpc, 4, 2 ,false},
263 { ARM::VST2q8Pseudo, ARM::VST2q8, false, false, false, SingleSpc, 4, 8 ,false},
264 { ARM::VST2q8PseudoWB_fixed, ARM::VST2q8wb_fixed, false, true, false, SingleSpc, 4, 8 ,false},
265 { ARM::VST2q8PseudoWB_register, ARM::VST2q8wb_register, false, true, true, SingleSpc, 4, 8 ,false},
267 { ARM::VST3LNd16Pseudo, ARM::VST3LNd16, false, false, false, SingleSpc, 3, 4 ,true},
268 { ARM::VST3LNd16Pseudo_UPD, ARM::VST3LNd16_UPD, false, true, true, SingleSpc, 3, 4 ,true},
269 { ARM::VST3LNd32Pseudo, ARM::VST3LNd32, false, false, false, SingleSpc, 3, 2 ,true},
270 { ARM::VST3LNd32Pseudo_UPD, ARM::VST3LNd32_UPD, false, true, true, SingleSpc, 3, 2 ,true},
271 { ARM::VST3LNd8Pseudo, ARM::VST3LNd8, false, false, false, SingleSpc, 3, 8 ,true},
272 { ARM::VST3LNd8Pseudo_UPD, ARM::VST3LNd8_UPD, false, true, true, SingleSpc, 3, 8 ,true},
273 { ARM::VST3LNq16Pseudo, ARM::VST3LNq16, false, false, false, EvenDblSpc, 3, 4,true},
274 { ARM::VST3LNq16Pseudo_UPD, ARM::VST3LNq16_UPD, false, true, true, EvenDblSpc, 3, 4,true},
275 { ARM::VST3LNq32Pseudo, ARM::VST3LNq32, false, false, false, EvenDblSpc, 3, 2,true},
276 { ARM::VST3LNq32Pseudo_UPD, ARM::VST3LNq32_UPD, false, true, true, EvenDblSpc, 3, 2,true},
278 { ARM::VST3d16Pseudo, ARM::VST3d16, false, false, false, SingleSpc, 3, 4 ,true},
279 { ARM::VST3d16Pseudo_UPD, ARM::VST3d16_UPD, false, true, true, SingleSpc, 3, 4 ,true},
280 { ARM::VST3d32Pseudo, ARM::VST3d32, false, false, false, SingleSpc, 3, 2 ,true},
281 { ARM::VST3d32Pseudo_UPD, ARM::VST3d32_UPD, false, true, true, SingleSpc, 3, 2 ,true},
282 { ARM::VST3d8Pseudo, ARM::VST3d8, false, false, false, SingleSpc, 3, 8 ,true},
283 { ARM::VST3d8Pseudo_UPD, ARM::VST3d8_UPD, false, true, true, SingleSpc, 3, 8 ,true},
285 { ARM::VST3q16Pseudo_UPD, ARM::VST3q16_UPD, false, true, true, EvenDblSpc, 3, 4 ,true},
286 { ARM::VST3q16oddPseudo, ARM::VST3q16, false, false, false, OddDblSpc, 3, 4 ,true},
287 { ARM::VST3q16oddPseudo_UPD, ARM::VST3q16_UPD, false, true, true, OddDblSpc, 3, 4 ,true},
288 { ARM::VST3q32Pseudo_UPD, ARM::VST3q32_UPD, false, true, true, EvenDblSpc, 3, 2 ,true},
289 { ARM::VST3q32oddPseudo, ARM::VST3q32, false, false, false, OddDblSpc, 3, 2 ,true},
290 { ARM::VST3q32oddPseudo_UPD, ARM::VST3q32_UPD, false, true, true, OddDblSpc, 3, 2 ,true},
291 { ARM::VST3q8Pseudo_UPD, ARM::VST3q8_UPD, false, true, true, EvenDblSpc, 3, 8 ,true},
292 { ARM::VST3q8oddPseudo, ARM::VST3q8, false, false, false, OddDblSpc, 3, 8 ,true},
293 { ARM::VST3q8oddPseudo_UPD, ARM::VST3q8_UPD, false, true, true, OddDblSpc, 3, 8 ,true},
295 { ARM::VST4LNd16Pseudo, ARM::VST4LNd16, false, false, false, SingleSpc, 4, 4 ,true},
296 { ARM::VST4LNd16Pseudo_UPD, ARM::VST4LNd16_UPD, false, true, true, SingleSpc, 4, 4 ,true},
297 { ARM::VST4LNd32Pseudo, ARM::VST4LNd32, false, false, false, SingleSpc, 4, 2 ,true},
298 { ARM::VST4LNd32Pseudo_UPD, ARM::VST4LNd32_UPD, false, true, true, SingleSpc, 4, 2 ,true},
299 { ARM::VST4LNd8Pseudo, ARM::VST4LNd8, false, false, false, SingleSpc, 4, 8 ,true},
300 { ARM::VST4LNd8Pseudo_UPD, ARM::VST4LNd8_UPD, false, true, true, SingleSpc, 4, 8 ,true},
301 { ARM::VST4LNq16Pseudo, ARM::VST4LNq16, false, false, false, EvenDblSpc, 4, 4,true},
302 { ARM::VST4LNq16Pseudo_UPD, ARM::VST4LNq16_UPD, false, true, true, EvenDblSpc, 4, 4,true},
303 { ARM::VST4LNq32Pseudo, ARM::VST4LNq32, false, false, false, EvenDblSpc, 4, 2,true},
304 { ARM::VST4LNq32Pseudo_UPD, ARM::VST4LNq32_UPD, false, true, true, EvenDblSpc, 4, 2,true},
306 { ARM::VST4d16Pseudo, ARM::VST4d16, false, false, false, SingleSpc, 4, 4 ,true},
307 { ARM::VST4d16Pseudo_UPD, ARM::VST4d16_UPD, false, true, true, SingleSpc, 4, 4 ,true},
308 { ARM::VST4d32Pseudo, ARM::VST4d32, false, false, false, SingleSpc, 4, 2 ,true},
309 { ARM::VST4d32Pseudo_UPD, ARM::VST4d32_UPD, false, true, true, SingleSpc, 4, 2 ,true},
310 { ARM::VST4d8Pseudo, ARM::VST4d8, false, false, false, SingleSpc, 4, 8 ,true},
311 { ARM::VST4d8Pseudo_UPD, ARM::VST4d8_UPD, false, true, true, SingleSpc, 4, 8 ,true},
313 { ARM::VST4q16Pseudo_UPD, ARM::VST4q16_UPD, false, true, true, EvenDblSpc, 4, 4 ,true},
314 { ARM::VST4q16oddPseudo, ARM::VST4q16, false, false, false, OddDblSpc, 4, 4 ,true},
315 { ARM::VST4q16oddPseudo_UPD, ARM::VST4q16_UPD, false, true, true, OddDblSpc, 4, 4 ,true},
316 { ARM::VST4q32Pseudo_UPD, ARM::VST4q32_UPD, false, true, true, EvenDblSpc, 4, 2 ,true},
317 { ARM::VST4q32oddPseudo, ARM::VST4q32, false, false, false, OddDblSpc, 4, 2 ,true},
318 { ARM::VST4q32oddPseudo_UPD, ARM::VST4q32_UPD, false, true, true, OddDblSpc, 4, 2 ,true},
319 { ARM::VST4q8Pseudo_UPD, ARM::VST4q8_UPD, false, true, true, EvenDblSpc, 4, 8 ,true},
320 { ARM::VST4q8oddPseudo, ARM::VST4q8, false, false, false, OddDblSpc, 4, 8 ,true},
321 { ARM::VST4q8oddPseudo_UPD, ARM::VST4q8_UPD, false, true, true, OddDblSpc, 4, 8 ,true}
324 /// LookupNEONLdSt - Search the NEONLdStTable for information about a NEON
325 /// load or store pseudo instruction.
326 static const NEONLdStTableEntry *LookupNEONLdSt(unsigned Opcode) {
327 const unsigned NumEntries = array_lengthof(NEONLdStTable);
330 // Make sure the table is sorted.
331 static bool TableChecked = false;
333 for (unsigned i = 0; i != NumEntries-1; ++i)
334 assert(NEONLdStTable[i] < NEONLdStTable[i+1] &&
335 "NEONLdStTable is not sorted!");
340 const NEONLdStTableEntry *I =
341 std::lower_bound(NEONLdStTable, NEONLdStTable + NumEntries, Opcode);
342 if (I != NEONLdStTable + NumEntries && I->PseudoOpc == Opcode)
347 /// GetDSubRegs - Get 4 D subregisters of a Q, QQ, or QQQQ register,
348 /// corresponding to the specified register spacing. Not all of the results
349 /// are necessarily valid, e.g., a Q register only has 2 D subregisters.
350 static void GetDSubRegs(unsigned Reg, NEONRegSpacing RegSpc,
351 const TargetRegisterInfo *TRI, unsigned &D0,
352 unsigned &D1, unsigned &D2, unsigned &D3) {
353 if (RegSpc == SingleSpc) {
354 D0 = TRI->getSubReg(Reg, ARM::dsub_0);
355 D1 = TRI->getSubReg(Reg, ARM::dsub_1);
356 D2 = TRI->getSubReg(Reg, ARM::dsub_2);
357 D3 = TRI->getSubReg(Reg, ARM::dsub_3);
358 } else if (RegSpc == EvenDblSpc) {
359 D0 = TRI->getSubReg(Reg, ARM::dsub_0);
360 D1 = TRI->getSubReg(Reg, ARM::dsub_2);
361 D2 = TRI->getSubReg(Reg, ARM::dsub_4);
362 D3 = TRI->getSubReg(Reg, ARM::dsub_6);
364 assert(RegSpc == OddDblSpc && "unknown register spacing");
365 D0 = TRI->getSubReg(Reg, ARM::dsub_1);
366 D1 = TRI->getSubReg(Reg, ARM::dsub_3);
367 D2 = TRI->getSubReg(Reg, ARM::dsub_5);
368 D3 = TRI->getSubReg(Reg, ARM::dsub_7);
372 /// ExpandVLD - Translate VLD pseudo instructions with Q, QQ or QQQQ register
373 /// operands to real VLD instructions with D register operands.
374 void ARMExpandPseudo::ExpandVLD(MachineBasicBlock::iterator &MBBI) {
375 MachineInstr &MI = *MBBI;
376 MachineBasicBlock &MBB = *MI.getParent();
378 const NEONLdStTableEntry *TableEntry = LookupNEONLdSt(MI.getOpcode());
379 assert(TableEntry && TableEntry->IsLoad && "NEONLdStTable lookup failed");
380 NEONRegSpacing RegSpc = TableEntry->RegSpacing;
381 unsigned NumRegs = TableEntry->NumRegs;
383 MachineInstrBuilder MIB = BuildMI(MBB, MBBI, MI.getDebugLoc(),
384 TII->get(TableEntry->RealOpc));
387 bool DstIsDead = MI.getOperand(OpIdx).isDead();
388 unsigned DstReg = MI.getOperand(OpIdx++).getReg();
389 unsigned D0, D1, D2, D3;
390 GetDSubRegs(DstReg, RegSpc, TRI, D0, D1, D2, D3);
391 MIB.addReg(D0, RegState::Define | getDeadRegState(DstIsDead));
392 if (NumRegs > 1 && TableEntry->copyAllListRegs)
393 MIB.addReg(D1, RegState::Define | getDeadRegState(DstIsDead));
394 if (NumRegs > 2 && TableEntry->copyAllListRegs)
395 MIB.addReg(D2, RegState::Define | getDeadRegState(DstIsDead));
396 if (NumRegs > 3 && TableEntry->copyAllListRegs)
397 MIB.addReg(D3, RegState::Define | getDeadRegState(DstIsDead));
399 if (TableEntry->isUpdating)
400 MIB.addOperand(MI.getOperand(OpIdx++));
402 // Copy the addrmode6 operands.
403 MIB.addOperand(MI.getOperand(OpIdx++));
404 MIB.addOperand(MI.getOperand(OpIdx++));
405 // Copy the am6offset operand.
406 if (TableEntry->hasWritebackOperand)
407 MIB.addOperand(MI.getOperand(OpIdx++));
409 // For an instruction writing double-spaced subregs, the pseudo instruction
410 // has an extra operand that is a use of the super-register. Record the
411 // operand index and skip over it.
412 unsigned SrcOpIdx = 0;
413 if (RegSpc == EvenDblSpc || RegSpc == OddDblSpc)
416 // Copy the predicate operands.
417 MIB.addOperand(MI.getOperand(OpIdx++));
418 MIB.addOperand(MI.getOperand(OpIdx++));
420 // Copy the super-register source operand used for double-spaced subregs over
421 // to the new instruction as an implicit operand.
423 MachineOperand MO = MI.getOperand(SrcOpIdx);
424 MO.setImplicit(true);
427 // Add an implicit def for the super-register.
428 MIB.addReg(DstReg, RegState::ImplicitDefine | getDeadRegState(DstIsDead));
429 TransferImpOps(MI, MIB, MIB);
431 // Transfer memoperands.
432 MIB->setMemRefs(MI.memoperands_begin(), MI.memoperands_end());
434 MI.eraseFromParent();
437 /// ExpandVST - Translate VST pseudo instructions with Q, QQ or QQQQ register
438 /// operands to real VST instructions with D register operands.
439 void ARMExpandPseudo::ExpandVST(MachineBasicBlock::iterator &MBBI) {
440 MachineInstr &MI = *MBBI;
441 MachineBasicBlock &MBB = *MI.getParent();
443 const NEONLdStTableEntry *TableEntry = LookupNEONLdSt(MI.getOpcode());
444 assert(TableEntry && !TableEntry->IsLoad && "NEONLdStTable lookup failed");
445 NEONRegSpacing RegSpc = TableEntry->RegSpacing;
446 unsigned NumRegs = TableEntry->NumRegs;
448 MachineInstrBuilder MIB = BuildMI(MBB, MBBI, MI.getDebugLoc(),
449 TII->get(TableEntry->RealOpc));
451 if (TableEntry->isUpdating)
452 MIB.addOperand(MI.getOperand(OpIdx++));
454 // Copy the addrmode6 operands.
455 MIB.addOperand(MI.getOperand(OpIdx++));
456 MIB.addOperand(MI.getOperand(OpIdx++));
457 // Copy the am6offset operand.
458 if (TableEntry->hasWritebackOperand)
459 MIB.addOperand(MI.getOperand(OpIdx++));
461 bool SrcIsKill = MI.getOperand(OpIdx).isKill();
462 unsigned SrcReg = MI.getOperand(OpIdx++).getReg();
463 unsigned D0, D1, D2, D3;
464 GetDSubRegs(SrcReg, RegSpc, TRI, D0, D1, D2, D3);
466 if (NumRegs > 1 && TableEntry->copyAllListRegs)
468 if (NumRegs > 2 && TableEntry->copyAllListRegs)
470 if (NumRegs > 3 && TableEntry->copyAllListRegs)
473 // Copy the predicate operands.
474 MIB.addOperand(MI.getOperand(OpIdx++));
475 MIB.addOperand(MI.getOperand(OpIdx++));
477 if (SrcIsKill) // Add an implicit kill for the super-reg.
478 MIB->addRegisterKilled(SrcReg, TRI, true);
479 TransferImpOps(MI, MIB, MIB);
481 // Transfer memoperands.
482 MIB->setMemRefs(MI.memoperands_begin(), MI.memoperands_end());
484 MI.eraseFromParent();
487 /// ExpandLaneOp - Translate VLD*LN and VST*LN instructions with Q, QQ or QQQQ
488 /// register operands to real instructions with D register operands.
489 void ARMExpandPseudo::ExpandLaneOp(MachineBasicBlock::iterator &MBBI) {
490 MachineInstr &MI = *MBBI;
491 MachineBasicBlock &MBB = *MI.getParent();
493 const NEONLdStTableEntry *TableEntry = LookupNEONLdSt(MI.getOpcode());
494 assert(TableEntry && "NEONLdStTable lookup failed");
495 NEONRegSpacing RegSpc = TableEntry->RegSpacing;
496 unsigned NumRegs = TableEntry->NumRegs;
497 unsigned RegElts = TableEntry->RegElts;
499 MachineInstrBuilder MIB = BuildMI(MBB, MBBI, MI.getDebugLoc(),
500 TII->get(TableEntry->RealOpc));
502 // The lane operand is always the 3rd from last operand, before the 2
503 // predicate operands.
504 unsigned Lane = MI.getOperand(MI.getDesc().getNumOperands() - 3).getImm();
506 // Adjust the lane and spacing as needed for Q registers.
507 assert(RegSpc != OddDblSpc && "unexpected register spacing for VLD/VST-lane");
508 if (RegSpc == EvenDblSpc && Lane >= RegElts) {
512 assert(Lane < RegElts && "out of range lane for VLD/VST-lane");
514 unsigned D0 = 0, D1 = 0, D2 = 0, D3 = 0;
516 bool DstIsDead = false;
517 if (TableEntry->IsLoad) {
518 DstIsDead = MI.getOperand(OpIdx).isDead();
519 DstReg = MI.getOperand(OpIdx++).getReg();
520 GetDSubRegs(DstReg, RegSpc, TRI, D0, D1, D2, D3);
521 MIB.addReg(D0, RegState::Define | getDeadRegState(DstIsDead));
523 MIB.addReg(D1, RegState::Define | getDeadRegState(DstIsDead));
525 MIB.addReg(D2, RegState::Define | getDeadRegState(DstIsDead));
527 MIB.addReg(D3, RegState::Define | getDeadRegState(DstIsDead));
530 if (TableEntry->isUpdating)
531 MIB.addOperand(MI.getOperand(OpIdx++));
533 // Copy the addrmode6 operands.
534 MIB.addOperand(MI.getOperand(OpIdx++));
535 MIB.addOperand(MI.getOperand(OpIdx++));
536 // Copy the am6offset operand.
537 if (TableEntry->hasWritebackOperand)
538 MIB.addOperand(MI.getOperand(OpIdx++));
540 // Grab the super-register source.
541 MachineOperand MO = MI.getOperand(OpIdx++);
542 if (!TableEntry->IsLoad)
543 GetDSubRegs(MO.getReg(), RegSpc, TRI, D0, D1, D2, D3);
545 // Add the subregs as sources of the new instruction.
546 unsigned SrcFlags = (getUndefRegState(MO.isUndef()) |
547 getKillRegState(MO.isKill()));
548 MIB.addReg(D0, SrcFlags);
550 MIB.addReg(D1, SrcFlags);
552 MIB.addReg(D2, SrcFlags);
554 MIB.addReg(D3, SrcFlags);
556 // Add the lane number operand.
560 // Copy the predicate operands.
561 MIB.addOperand(MI.getOperand(OpIdx++));
562 MIB.addOperand(MI.getOperand(OpIdx++));
564 // Copy the super-register source to be an implicit source.
565 MO.setImplicit(true);
567 if (TableEntry->IsLoad)
568 // Add an implicit def for the super-register.
569 MIB.addReg(DstReg, RegState::ImplicitDefine | getDeadRegState(DstIsDead));
570 TransferImpOps(MI, MIB, MIB);
571 // Transfer memoperands.
572 MIB->setMemRefs(MI.memoperands_begin(), MI.memoperands_end());
573 MI.eraseFromParent();
576 /// ExpandVTBL - Translate VTBL and VTBX pseudo instructions with Q or QQ
577 /// register operands to real instructions with D register operands.
578 void ARMExpandPseudo::ExpandVTBL(MachineBasicBlock::iterator &MBBI,
579 unsigned Opc, bool IsExt) {
580 MachineInstr &MI = *MBBI;
581 MachineBasicBlock &MBB = *MI.getParent();
583 MachineInstrBuilder MIB = BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(Opc));
586 // Transfer the destination register operand.
587 MIB.addOperand(MI.getOperand(OpIdx++));
589 MIB.addOperand(MI.getOperand(OpIdx++));
591 bool SrcIsKill = MI.getOperand(OpIdx).isKill();
592 unsigned SrcReg = MI.getOperand(OpIdx++).getReg();
593 unsigned D0, D1, D2, D3;
594 GetDSubRegs(SrcReg, SingleSpc, TRI, D0, D1, D2, D3);
597 // Copy the other source register operand.
598 MIB.addOperand(MI.getOperand(OpIdx++));
600 // Copy the predicate operands.
601 MIB.addOperand(MI.getOperand(OpIdx++));
602 MIB.addOperand(MI.getOperand(OpIdx++));
604 if (SrcIsKill) // Add an implicit kill for the super-reg.
605 MIB->addRegisterKilled(SrcReg, TRI, true);
606 TransferImpOps(MI, MIB, MIB);
607 MI.eraseFromParent();
610 void ARMExpandPseudo::ExpandMOV32BitImm(MachineBasicBlock &MBB,
611 MachineBasicBlock::iterator &MBBI) {
612 MachineInstr &MI = *MBBI;
613 unsigned Opcode = MI.getOpcode();
614 unsigned PredReg = 0;
615 ARMCC::CondCodes Pred = getInstrPredicate(&MI, PredReg);
616 unsigned DstReg = MI.getOperand(0).getReg();
617 bool DstIsDead = MI.getOperand(0).isDead();
618 bool isCC = Opcode == ARM::MOVCCi32imm || Opcode == ARM::t2MOVCCi32imm;
619 const MachineOperand &MO = MI.getOperand(isCC ? 2 : 1);
620 MachineInstrBuilder LO16, HI16;
622 if (!STI->hasV6T2Ops() &&
623 (Opcode == ARM::MOVi32imm || Opcode == ARM::MOVCCi32imm)) {
624 // Expand into a movi + orr.
625 LO16 = BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(ARM::MOVi), DstReg);
626 HI16 = BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(ARM::ORRri))
627 .addReg(DstReg, RegState::Define | getDeadRegState(DstIsDead))
630 assert (MO.isImm() && "MOVi32imm w/ non-immediate source operand!");
631 unsigned ImmVal = (unsigned)MO.getImm();
632 unsigned SOImmValV1 = ARM_AM::getSOImmTwoPartFirst(ImmVal);
633 unsigned SOImmValV2 = ARM_AM::getSOImmTwoPartSecond(ImmVal);
634 LO16 = LO16.addImm(SOImmValV1);
635 HI16 = HI16.addImm(SOImmValV2);
636 LO16->setMemRefs(MI.memoperands_begin(), MI.memoperands_end());
637 HI16->setMemRefs(MI.memoperands_begin(), MI.memoperands_end());
638 LO16.addImm(Pred).addReg(PredReg).addReg(0);
639 HI16.addImm(Pred).addReg(PredReg).addReg(0);
640 TransferImpOps(MI, LO16, HI16);
641 MI.eraseFromParent();
645 unsigned LO16Opc = 0;
646 unsigned HI16Opc = 0;
647 if (Opcode == ARM::t2MOVi32imm || Opcode == ARM::t2MOVCCi32imm) {
648 LO16Opc = ARM::t2MOVi16;
649 HI16Opc = ARM::t2MOVTi16;
651 LO16Opc = ARM::MOVi16;
652 HI16Opc = ARM::MOVTi16;
655 LO16 = BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(LO16Opc), DstReg);
656 HI16 = BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(HI16Opc))
657 .addReg(DstReg, RegState::Define | getDeadRegState(DstIsDead))
661 unsigned Imm = MO.getImm();
662 unsigned Lo16 = Imm & 0xffff;
663 unsigned Hi16 = (Imm >> 16) & 0xffff;
664 LO16 = LO16.addImm(Lo16);
665 HI16 = HI16.addImm(Hi16);
667 const GlobalValue *GV = MO.getGlobal();
668 unsigned TF = MO.getTargetFlags();
669 LO16 = LO16.addGlobalAddress(GV, MO.getOffset(), TF | ARMII::MO_LO16);
670 HI16 = HI16.addGlobalAddress(GV, MO.getOffset(), TF | ARMII::MO_HI16);
673 LO16->setMemRefs(MI.memoperands_begin(), MI.memoperands_end());
674 HI16->setMemRefs(MI.memoperands_begin(), MI.memoperands_end());
675 LO16.addImm(Pred).addReg(PredReg);
676 HI16.addImm(Pred).addReg(PredReg);
678 TransferImpOps(MI, LO16, HI16);
679 MI.eraseFromParent();
682 bool ARMExpandPseudo::ExpandMI(MachineBasicBlock &MBB,
683 MachineBasicBlock::iterator MBBI) {
684 MachineInstr &MI = *MBBI;
685 unsigned Opcode = MI.getOpcode();
691 unsigned newOpc = Opcode == ARM::VMOVScc ? ARM::VMOVS : ARM::VMOVD;
692 BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(newOpc),
693 MI.getOperand(1).getReg())
694 .addReg(MI.getOperand(2).getReg(),
695 getKillRegState(MI.getOperand(2).isKill()))
696 .addImm(MI.getOperand(3).getImm()) // 'pred'
697 .addReg(MI.getOperand(4).getReg());
699 MI.eraseFromParent();
704 unsigned Opc = AFI->isThumbFunction() ? ARM::t2MOVr : ARM::MOVr;
705 BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(Opc),
706 MI.getOperand(1).getReg())
707 .addReg(MI.getOperand(2).getReg(),
708 getKillRegState(MI.getOperand(2).isKill()))
709 .addImm(MI.getOperand(3).getImm()) // 'pred'
710 .addReg(MI.getOperand(4).getReg())
711 .addReg(0); // 's' bit
713 MI.eraseFromParent();
717 BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(ARM::MOVsi),
718 (MI.getOperand(1).getReg()))
719 .addReg(MI.getOperand(2).getReg(),
720 getKillRegState(MI.getOperand(2).isKill()))
721 .addImm(MI.getOperand(3).getImm())
722 .addImm(MI.getOperand(4).getImm()) // 'pred'
723 .addReg(MI.getOperand(5).getReg())
724 .addReg(0); // 's' bit
726 MI.eraseFromParent();
731 BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(ARM::MOVsr),
732 (MI.getOperand(1).getReg()))
733 .addReg(MI.getOperand(2).getReg(),
734 getKillRegState(MI.getOperand(2).isKill()))
735 .addReg(MI.getOperand(3).getReg(),
736 getKillRegState(MI.getOperand(3).isKill()))
737 .addImm(MI.getOperand(4).getImm())
738 .addImm(MI.getOperand(5).getImm()) // 'pred'
739 .addReg(MI.getOperand(6).getReg())
740 .addReg(0); // 's' bit
742 MI.eraseFromParent();
745 case ARM::MOVCCi16: {
746 BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(ARM::MOVi16),
747 MI.getOperand(1).getReg())
748 .addImm(MI.getOperand(2).getImm())
749 .addImm(MI.getOperand(3).getImm()) // 'pred'
750 .addReg(MI.getOperand(4).getReg());
752 MI.eraseFromParent();
757 unsigned Opc = AFI->isThumbFunction() ? ARM::t2MOVi : ARM::MOVi;
758 BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(Opc),
759 MI.getOperand(1).getReg())
760 .addImm(MI.getOperand(2).getImm())
761 .addImm(MI.getOperand(3).getImm()) // 'pred'
762 .addReg(MI.getOperand(4).getReg())
763 .addReg(0); // 's' bit
765 MI.eraseFromParent();
769 BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(ARM::MVNi),
770 MI.getOperand(1).getReg())
771 .addImm(MI.getOperand(2).getImm())
772 .addImm(MI.getOperand(3).getImm()) // 'pred'
773 .addReg(MI.getOperand(4).getReg())
774 .addReg(0); // 's' bit
776 MI.eraseFromParent();
779 case ARM::Int_eh_sjlj_dispatchsetup:
780 case ARM::Int_eh_sjlj_dispatchsetup_nofp:
781 case ARM::tInt_eh_sjlj_dispatchsetup: {
782 MachineFunction &MF = *MI.getParent()->getParent();
783 const ARMBaseInstrInfo *AII =
784 static_cast<const ARMBaseInstrInfo*>(TII);
785 const ARMBaseRegisterInfo &RI = AII->getRegisterInfo();
786 // For functions using a base pointer, we rematerialize it (via the frame
787 // pointer) here since eh.sjlj.setjmp and eh.sjlj.longjmp don't do it
788 // for us. Otherwise, expand to nothing.
789 if (RI.hasBasePointer(MF)) {
790 int32_t NumBytes = AFI->getFramePtrSpillOffset();
791 unsigned FramePtr = RI.getFrameRegister(MF);
792 assert(MF.getTarget().getFrameLowering()->hasFP(MF) &&
793 "base pointer without frame pointer?");
795 if (AFI->isThumb2Function()) {
796 emitT2RegPlusImmediate(MBB, MBBI, MI.getDebugLoc(), ARM::R6,
797 FramePtr, -NumBytes, ARMCC::AL, 0, *TII);
798 } else if (AFI->isThumbFunction()) {
799 emitThumbRegPlusImmediate(MBB, MBBI, MI.getDebugLoc(), ARM::R6,
800 FramePtr, -NumBytes, *TII, RI);
802 emitARMRegPlusImmediate(MBB, MBBI, MI.getDebugLoc(), ARM::R6,
803 FramePtr, -NumBytes, ARMCC::AL, 0,
806 // If there's dynamic realignment, adjust for it.
807 if (RI.needsStackRealignment(MF)) {
808 MachineFrameInfo *MFI = MF.getFrameInfo();
809 unsigned MaxAlign = MFI->getMaxAlignment();
810 assert (!AFI->isThumb1OnlyFunction());
811 // Emit bic r6, r6, MaxAlign
812 unsigned bicOpc = AFI->isThumbFunction() ?
813 ARM::t2BICri : ARM::BICri;
814 AddDefaultCC(AddDefaultPred(BuildMI(MBB, MBBI, MI.getDebugLoc(),
815 TII->get(bicOpc), ARM::R6)
816 .addReg(ARM::R6, RegState::Kill)
817 .addImm(MaxAlign-1)));
821 MI.eraseFromParent();
825 case ARM::MOVsrl_flag:
826 case ARM::MOVsra_flag: {
827 // These are just fancy MOVs insructions.
828 AddDefaultPred(BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(ARM::MOVsi),
829 MI.getOperand(0).getReg())
830 .addOperand(MI.getOperand(1))
831 .addImm(ARM_AM::getSORegOpc((Opcode == ARM::MOVsrl_flag ?
832 ARM_AM::lsr : ARM_AM::asr),
834 .addReg(ARM::CPSR, RegState::Define);
835 MI.eraseFromParent();
839 // This encodes as "MOVs Rd, Rm, rrx
840 MachineInstrBuilder MIB =
841 AddDefaultPred(BuildMI(MBB, MBBI, MI.getDebugLoc(),TII->get(ARM::MOVsi),
842 MI.getOperand(0).getReg())
843 .addOperand(MI.getOperand(1))
844 .addImm(ARM_AM::getSORegOpc(ARM_AM::rrx, 0)))
846 TransferImpOps(MI, MIB, MIB);
847 MI.eraseFromParent();
852 MachineInstrBuilder MIB =
853 BuildMI(MBB, MBBI, MI.getDebugLoc(),
854 TII->get(Opcode == ARM::tTPsoft ? ARM::tBL : ARM::BL))
855 .addExternalSymbol("__aeabi_read_tp", 0);
857 MIB->setMemRefs(MI.memoperands_begin(), MI.memoperands_end());
858 TransferImpOps(MI, MIB, MIB);
859 MI.eraseFromParent();
862 case ARM::tLDRpci_pic:
863 case ARM::t2LDRpci_pic: {
864 unsigned NewLdOpc = (Opcode == ARM::tLDRpci_pic)
865 ? ARM::tLDRpci : ARM::t2LDRpci;
866 unsigned DstReg = MI.getOperand(0).getReg();
867 bool DstIsDead = MI.getOperand(0).isDead();
868 MachineInstrBuilder MIB1 =
869 AddDefaultPred(BuildMI(MBB, MBBI, MI.getDebugLoc(),
870 TII->get(NewLdOpc), DstReg)
871 .addOperand(MI.getOperand(1)));
872 MIB1->setMemRefs(MI.memoperands_begin(), MI.memoperands_end());
873 MachineInstrBuilder MIB2 = BuildMI(MBB, MBBI, MI.getDebugLoc(),
874 TII->get(ARM::tPICADD))
875 .addReg(DstReg, RegState::Define | getDeadRegState(DstIsDead))
877 .addOperand(MI.getOperand(2));
878 TransferImpOps(MI, MIB1, MIB2);
879 MI.eraseFromParent();
883 case ARM::MOV_ga_dyn:
884 case ARM::MOV_ga_pcrel:
885 case ARM::MOV_ga_pcrel_ldr:
886 case ARM::t2MOV_ga_dyn:
887 case ARM::t2MOV_ga_pcrel: {
888 // Expand into movw + movw. Also "add pc" / ldr [pc] in PIC mode.
889 unsigned LabelId = AFI->createPICLabelUId();
890 unsigned DstReg = MI.getOperand(0).getReg();
891 bool DstIsDead = MI.getOperand(0).isDead();
892 const MachineOperand &MO1 = MI.getOperand(1);
893 const GlobalValue *GV = MO1.getGlobal();
894 unsigned TF = MO1.getTargetFlags();
895 bool isARM = (Opcode != ARM::t2MOV_ga_pcrel && Opcode!=ARM::t2MOV_ga_dyn);
896 bool isPIC = (Opcode != ARM::MOV_ga_dyn && Opcode != ARM::t2MOV_ga_dyn);
897 unsigned LO16Opc = isARM ? ARM::MOVi16_ga_pcrel : ARM::t2MOVi16_ga_pcrel;
898 unsigned HI16Opc = isARM ? ARM::MOVTi16_ga_pcrel :ARM::t2MOVTi16_ga_pcrel;
899 unsigned LO16TF = isPIC
900 ? ARMII::MO_LO16_NONLAZY_PIC : ARMII::MO_LO16_NONLAZY;
901 unsigned HI16TF = isPIC
902 ? ARMII::MO_HI16_NONLAZY_PIC : ARMII::MO_HI16_NONLAZY;
903 unsigned PICAddOpc = isARM
904 ? (Opcode == ARM::MOV_ga_pcrel_ldr ? ARM::PICLDR : ARM::PICADD)
906 MachineInstrBuilder MIB1 = BuildMI(MBB, MBBI, MI.getDebugLoc(),
907 TII->get(LO16Opc), DstReg)
908 .addGlobalAddress(GV, MO1.getOffset(), TF | LO16TF)
910 MachineInstrBuilder MIB2 = BuildMI(MBB, MBBI, MI.getDebugLoc(),
911 TII->get(HI16Opc), DstReg)
913 .addGlobalAddress(GV, MO1.getOffset(), TF | HI16TF)
916 TransferImpOps(MI, MIB1, MIB2);
917 MI.eraseFromParent();
921 MachineInstrBuilder MIB3 = BuildMI(MBB, MBBI, MI.getDebugLoc(),
923 .addReg(DstReg, RegState::Define | getDeadRegState(DstIsDead))
924 .addReg(DstReg).addImm(LabelId);
926 AddDefaultPred(MIB3);
927 if (Opcode == ARM::MOV_ga_pcrel_ldr)
928 MIB3->setMemRefs(MI.memoperands_begin(), MI.memoperands_end());
930 TransferImpOps(MI, MIB1, MIB3);
931 MI.eraseFromParent();
936 case ARM::MOVCCi32imm:
937 case ARM::t2MOVi32imm:
938 case ARM::t2MOVCCi32imm:
939 ExpandMOV32BitImm(MBB, MBBI);
943 unsigned NewOpc = ARM::VLDMDIA;
944 MachineInstrBuilder MIB =
945 BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(NewOpc));
948 // Grab the Q register destination.
949 bool DstIsDead = MI.getOperand(OpIdx).isDead();
950 unsigned DstReg = MI.getOperand(OpIdx++).getReg();
952 // Copy the source register.
953 MIB.addOperand(MI.getOperand(OpIdx++));
955 // Copy the predicate operands.
956 MIB.addOperand(MI.getOperand(OpIdx++));
957 MIB.addOperand(MI.getOperand(OpIdx++));
959 // Add the destination operands (D subregs).
960 unsigned D0 = TRI->getSubReg(DstReg, ARM::dsub_0);
961 unsigned D1 = TRI->getSubReg(DstReg, ARM::dsub_1);
962 MIB.addReg(D0, RegState::Define | getDeadRegState(DstIsDead))
963 .addReg(D1, RegState::Define | getDeadRegState(DstIsDead));
965 // Add an implicit def for the super-register.
966 MIB.addReg(DstReg, RegState::ImplicitDefine | getDeadRegState(DstIsDead));
967 TransferImpOps(MI, MIB, MIB);
968 MIB.setMemRefs(MI.memoperands_begin(), MI.memoperands_end());
969 MI.eraseFromParent();
974 unsigned NewOpc = ARM::VSTMDIA;
975 MachineInstrBuilder MIB =
976 BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(NewOpc));
979 // Grab the Q register source.
980 bool SrcIsKill = MI.getOperand(OpIdx).isKill();
981 unsigned SrcReg = MI.getOperand(OpIdx++).getReg();
983 // Copy the destination register.
984 MIB.addOperand(MI.getOperand(OpIdx++));
986 // Copy the predicate operands.
987 MIB.addOperand(MI.getOperand(OpIdx++));
988 MIB.addOperand(MI.getOperand(OpIdx++));
990 // Add the source operands (D subregs).
991 unsigned D0 = TRI->getSubReg(SrcReg, ARM::dsub_0);
992 unsigned D1 = TRI->getSubReg(SrcReg, ARM::dsub_1);
993 MIB.addReg(D0).addReg(D1);
995 if (SrcIsKill) // Add an implicit kill for the Q register.
996 MIB->addRegisterKilled(SrcReg, TRI, true);
998 TransferImpOps(MI, MIB, MIB);
999 MIB.setMemRefs(MI.memoperands_begin(), MI.memoperands_end());
1000 MI.eraseFromParent();
1005 unsigned NewOpc = Opcode == ARM::VDUPfqf ? ARM::VDUPLN32q :
1007 MachineInstrBuilder MIB =
1008 BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(NewOpc));
1010 unsigned SrcReg = MI.getOperand(1).getReg();
1011 unsigned Lane = getARMRegisterNumbering(SrcReg) & 1;
1012 unsigned DReg = TRI->getMatchingSuperReg(SrcReg,
1013 Lane & 1 ? ARM::ssub_1 : ARM::ssub_0,
1014 &ARM::DPR_VFP2RegClass);
1015 // The lane is [0,1] for the containing DReg superregister.
1016 // Copy the dst/src register operands.
1017 MIB.addOperand(MI.getOperand(OpIdx++));
1020 // Add the lane select operand.
1022 // Add the predicate operands.
1023 MIB.addOperand(MI.getOperand(OpIdx++));
1024 MIB.addOperand(MI.getOperand(OpIdx++));
1026 TransferImpOps(MI, MIB, MIB);
1027 MI.eraseFromParent();
1031 case ARM::VLD2q8Pseudo:
1032 case ARM::VLD2q16Pseudo:
1033 case ARM::VLD2q32Pseudo:
1034 case ARM::VLD2q8PseudoWB_fixed:
1035 case ARM::VLD2q16PseudoWB_fixed:
1036 case ARM::VLD2q32PseudoWB_fixed:
1037 case ARM::VLD2q8PseudoWB_register:
1038 case ARM::VLD2q16PseudoWB_register:
1039 case ARM::VLD2q32PseudoWB_register:
1040 case ARM::VLD3d8Pseudo:
1041 case ARM::VLD3d16Pseudo:
1042 case ARM::VLD3d32Pseudo:
1043 case ARM::VLD1d64TPseudo:
1044 case ARM::VLD3d8Pseudo_UPD:
1045 case ARM::VLD3d16Pseudo_UPD:
1046 case ARM::VLD3d32Pseudo_UPD:
1047 case ARM::VLD3q8Pseudo_UPD:
1048 case ARM::VLD3q16Pseudo_UPD:
1049 case ARM::VLD3q32Pseudo_UPD:
1050 case ARM::VLD3q8oddPseudo:
1051 case ARM::VLD3q16oddPseudo:
1052 case ARM::VLD3q32oddPseudo:
1053 case ARM::VLD3q8oddPseudo_UPD:
1054 case ARM::VLD3q16oddPseudo_UPD:
1055 case ARM::VLD3q32oddPseudo_UPD:
1056 case ARM::VLD4d8Pseudo:
1057 case ARM::VLD4d16Pseudo:
1058 case ARM::VLD4d32Pseudo:
1059 case ARM::VLD1d64QPseudo:
1060 case ARM::VLD4d8Pseudo_UPD:
1061 case ARM::VLD4d16Pseudo_UPD:
1062 case ARM::VLD4d32Pseudo_UPD:
1063 case ARM::VLD4q8Pseudo_UPD:
1064 case ARM::VLD4q16Pseudo_UPD:
1065 case ARM::VLD4q32Pseudo_UPD:
1066 case ARM::VLD4q8oddPseudo:
1067 case ARM::VLD4q16oddPseudo:
1068 case ARM::VLD4q32oddPseudo:
1069 case ARM::VLD4q8oddPseudo_UPD:
1070 case ARM::VLD4q16oddPseudo_UPD:
1071 case ARM::VLD4q32oddPseudo_UPD:
1072 case ARM::VLD3DUPd8Pseudo:
1073 case ARM::VLD3DUPd16Pseudo:
1074 case ARM::VLD3DUPd32Pseudo:
1075 case ARM::VLD3DUPd8Pseudo_UPD:
1076 case ARM::VLD3DUPd16Pseudo_UPD:
1077 case ARM::VLD3DUPd32Pseudo_UPD:
1078 case ARM::VLD4DUPd8Pseudo:
1079 case ARM::VLD4DUPd16Pseudo:
1080 case ARM::VLD4DUPd32Pseudo:
1081 case ARM::VLD4DUPd8Pseudo_UPD:
1082 case ARM::VLD4DUPd16Pseudo_UPD:
1083 case ARM::VLD4DUPd32Pseudo_UPD:
1087 case ARM::VST2q8Pseudo:
1088 case ARM::VST2q16Pseudo:
1089 case ARM::VST2q32Pseudo:
1090 case ARM::VST2q8PseudoWB_fixed:
1091 case ARM::VST2q16PseudoWB_fixed:
1092 case ARM::VST2q32PseudoWB_fixed:
1093 case ARM::VST2q8PseudoWB_register:
1094 case ARM::VST2q16PseudoWB_register:
1095 case ARM::VST2q32PseudoWB_register:
1096 case ARM::VST3d8Pseudo:
1097 case ARM::VST3d16Pseudo:
1098 case ARM::VST3d32Pseudo:
1099 case ARM::VST1d64TPseudo:
1100 case ARM::VST3d8Pseudo_UPD:
1101 case ARM::VST3d16Pseudo_UPD:
1102 case ARM::VST3d32Pseudo_UPD:
1103 case ARM::VST1d64TPseudoWB_fixed:
1104 case ARM::VST1d64TPseudoWB_register:
1105 case ARM::VST3q8Pseudo_UPD:
1106 case ARM::VST3q16Pseudo_UPD:
1107 case ARM::VST3q32Pseudo_UPD:
1108 case ARM::VST3q8oddPseudo:
1109 case ARM::VST3q16oddPseudo:
1110 case ARM::VST3q32oddPseudo:
1111 case ARM::VST3q8oddPseudo_UPD:
1112 case ARM::VST3q16oddPseudo_UPD:
1113 case ARM::VST3q32oddPseudo_UPD:
1114 case ARM::VST4d8Pseudo:
1115 case ARM::VST4d16Pseudo:
1116 case ARM::VST4d32Pseudo:
1117 case ARM::VST1d64QPseudo:
1118 case ARM::VST4d8Pseudo_UPD:
1119 case ARM::VST4d16Pseudo_UPD:
1120 case ARM::VST4d32Pseudo_UPD:
1121 case ARM::VST1d64QPseudoWB_fixed:
1122 case ARM::VST1d64QPseudoWB_register:
1123 case ARM::VST4q8Pseudo_UPD:
1124 case ARM::VST4q16Pseudo_UPD:
1125 case ARM::VST4q32Pseudo_UPD:
1126 case ARM::VST4q8oddPseudo:
1127 case ARM::VST4q16oddPseudo:
1128 case ARM::VST4q32oddPseudo:
1129 case ARM::VST4q8oddPseudo_UPD:
1130 case ARM::VST4q16oddPseudo_UPD:
1131 case ARM::VST4q32oddPseudo_UPD:
1135 case ARM::VLD1LNq8Pseudo:
1136 case ARM::VLD1LNq16Pseudo:
1137 case ARM::VLD1LNq32Pseudo:
1138 case ARM::VLD1LNq8Pseudo_UPD:
1139 case ARM::VLD1LNq16Pseudo_UPD:
1140 case ARM::VLD1LNq32Pseudo_UPD:
1141 case ARM::VLD2LNd8Pseudo:
1142 case ARM::VLD2LNd16Pseudo:
1143 case ARM::VLD2LNd32Pseudo:
1144 case ARM::VLD2LNq16Pseudo:
1145 case ARM::VLD2LNq32Pseudo:
1146 case ARM::VLD2LNd8Pseudo_UPD:
1147 case ARM::VLD2LNd16Pseudo_UPD:
1148 case ARM::VLD2LNd32Pseudo_UPD:
1149 case ARM::VLD2LNq16Pseudo_UPD:
1150 case ARM::VLD2LNq32Pseudo_UPD:
1151 case ARM::VLD3LNd8Pseudo:
1152 case ARM::VLD3LNd16Pseudo:
1153 case ARM::VLD3LNd32Pseudo:
1154 case ARM::VLD3LNq16Pseudo:
1155 case ARM::VLD3LNq32Pseudo:
1156 case ARM::VLD3LNd8Pseudo_UPD:
1157 case ARM::VLD3LNd16Pseudo_UPD:
1158 case ARM::VLD3LNd32Pseudo_UPD:
1159 case ARM::VLD3LNq16Pseudo_UPD:
1160 case ARM::VLD3LNq32Pseudo_UPD:
1161 case ARM::VLD4LNd8Pseudo:
1162 case ARM::VLD4LNd16Pseudo:
1163 case ARM::VLD4LNd32Pseudo:
1164 case ARM::VLD4LNq16Pseudo:
1165 case ARM::VLD4LNq32Pseudo:
1166 case ARM::VLD4LNd8Pseudo_UPD:
1167 case ARM::VLD4LNd16Pseudo_UPD:
1168 case ARM::VLD4LNd32Pseudo_UPD:
1169 case ARM::VLD4LNq16Pseudo_UPD:
1170 case ARM::VLD4LNq32Pseudo_UPD:
1171 case ARM::VST1LNq8Pseudo:
1172 case ARM::VST1LNq16Pseudo:
1173 case ARM::VST1LNq32Pseudo:
1174 case ARM::VST1LNq8Pseudo_UPD:
1175 case ARM::VST1LNq16Pseudo_UPD:
1176 case ARM::VST1LNq32Pseudo_UPD:
1177 case ARM::VST2LNd8Pseudo:
1178 case ARM::VST2LNd16Pseudo:
1179 case ARM::VST2LNd32Pseudo:
1180 case ARM::VST2LNq16Pseudo:
1181 case ARM::VST2LNq32Pseudo:
1182 case ARM::VST2LNd8Pseudo_UPD:
1183 case ARM::VST2LNd16Pseudo_UPD:
1184 case ARM::VST2LNd32Pseudo_UPD:
1185 case ARM::VST2LNq16Pseudo_UPD:
1186 case ARM::VST2LNq32Pseudo_UPD:
1187 case ARM::VST3LNd8Pseudo:
1188 case ARM::VST3LNd16Pseudo:
1189 case ARM::VST3LNd32Pseudo:
1190 case ARM::VST3LNq16Pseudo:
1191 case ARM::VST3LNq32Pseudo:
1192 case ARM::VST3LNd8Pseudo_UPD:
1193 case ARM::VST3LNd16Pseudo_UPD:
1194 case ARM::VST3LNd32Pseudo_UPD:
1195 case ARM::VST3LNq16Pseudo_UPD:
1196 case ARM::VST3LNq32Pseudo_UPD:
1197 case ARM::VST4LNd8Pseudo:
1198 case ARM::VST4LNd16Pseudo:
1199 case ARM::VST4LNd32Pseudo:
1200 case ARM::VST4LNq16Pseudo:
1201 case ARM::VST4LNq32Pseudo:
1202 case ARM::VST4LNd8Pseudo_UPD:
1203 case ARM::VST4LNd16Pseudo_UPD:
1204 case ARM::VST4LNd32Pseudo_UPD:
1205 case ARM::VST4LNq16Pseudo_UPD:
1206 case ARM::VST4LNq32Pseudo_UPD:
1210 case ARM::VTBL3Pseudo: ExpandVTBL(MBBI, ARM::VTBL3, false); return true;
1211 case ARM::VTBL4Pseudo: ExpandVTBL(MBBI, ARM::VTBL4, false); return true;
1212 case ARM::VTBX3Pseudo: ExpandVTBL(MBBI, ARM::VTBX3, true); return true;
1213 case ARM::VTBX4Pseudo: ExpandVTBL(MBBI, ARM::VTBX4, true); return true;
1217 bool ARMExpandPseudo::ExpandMBB(MachineBasicBlock &MBB) {
1218 bool Modified = false;
1220 MachineBasicBlock::iterator MBBI = MBB.begin(), E = MBB.end();
1222 MachineBasicBlock::iterator NMBBI = llvm::next(MBBI);
1223 Modified |= ExpandMI(MBB, MBBI);
1230 bool ARMExpandPseudo::runOnMachineFunction(MachineFunction &MF) {
1231 const TargetMachine &TM = MF.getTarget();
1232 TII = static_cast<const ARMBaseInstrInfo*>(TM.getInstrInfo());
1233 TRI = TM.getRegisterInfo();
1234 STI = &TM.getSubtarget<ARMSubtarget>();
1235 AFI = MF.getInfo<ARMFunctionInfo>();
1237 bool Modified = false;
1238 for (MachineFunction::iterator MFI = MF.begin(), E = MF.end(); MFI != E;
1240 Modified |= ExpandMBB(*MFI);
1241 if (VerifyARMPseudo)
1242 MF.verify(this, "After expanding ARM pseudo instructions.");
1246 /// createARMExpandPseudoPass - returns an instance of the pseudo instruction
1248 FunctionPass *llvm::createARMExpandPseudoPass() {
1249 return new ARMExpandPseudo();