1 //===-- ARMExpandPseudoInsts.cpp - Expand pseudo instructions -----*- 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 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 "ARMAddressingModes.h"
20 #include "ARMBaseInstrInfo.h"
21 #include "ARMBaseRegisterInfo.h"
22 #include "ARMMachineFunctionInfo.h"
23 #include "ARMRegisterInfo.h"
24 #include "llvm/CodeGen/MachineFrameInfo.h"
25 #include "llvm/CodeGen/MachineFunctionPass.h"
26 #include "llvm/CodeGen/MachineInstrBuilder.h"
27 #include "llvm/Target/TargetFrameInfo.h"
28 #include "llvm/Target/TargetRegisterInfo.h"
29 #include "llvm/Support/raw_ostream.h" // FIXME: for debug only. remove!
33 class ARMExpandPseudo : public MachineFunctionPass {
36 ARMExpandPseudo() : MachineFunctionPass(ID) {}
38 const ARMBaseInstrInfo *TII;
39 const TargetRegisterInfo *TRI;
40 const ARMSubtarget *STI;
42 virtual bool runOnMachineFunction(MachineFunction &Fn);
44 virtual const char *getPassName() const {
45 return "ARM pseudo instruction expansion pass";
49 void TransferImpOps(MachineInstr &OldMI,
50 MachineInstrBuilder &UseMI, MachineInstrBuilder &DefMI);
51 bool ExpandMBB(MachineBasicBlock &MBB);
52 void ExpandVLD(MachineBasicBlock::iterator &MBBI);
53 void ExpandVST(MachineBasicBlock::iterator &MBBI);
54 void ExpandLaneOp(MachineBasicBlock::iterator &MBBI);
55 void ExpandVTBL(MachineBasicBlock::iterator &MBBI,
56 unsigned Opc, bool IsExt, unsigned NumRegs);
58 char ARMExpandPseudo::ID = 0;
61 /// TransferImpOps - Transfer implicit operands on the pseudo instruction to
62 /// the instructions created from the expansion.
63 void ARMExpandPseudo::TransferImpOps(MachineInstr &OldMI,
64 MachineInstrBuilder &UseMI,
65 MachineInstrBuilder &DefMI) {
66 const TargetInstrDesc &Desc = OldMI.getDesc();
67 for (unsigned i = Desc.getNumOperands(), e = OldMI.getNumOperands();
69 const MachineOperand &MO = OldMI.getOperand(i);
70 assert(MO.isReg() && MO.getReg());
79 // Constants for register spacing in NEON load/store instructions.
80 // For quad-register load-lane and store-lane pseudo instructors, the
81 // spacing is initially assumed to be EvenDblSpc, and that is changed to
82 // OddDblSpc depending on the lane number operand.
89 // Entries for NEON load/store information table. The table is sorted by
90 // PseudoOpc for fast binary-search lookups.
91 struct NEONLdStTableEntry {
96 NEONRegSpacing RegSpacing;
97 unsigned char NumRegs; // D registers loaded or stored
98 unsigned char RegElts; // elements per D register; used for lane ops
100 // Comparison methods for binary search of the table.
101 bool operator<(const NEONLdStTableEntry &TE) const {
102 return PseudoOpc < TE.PseudoOpc;
104 friend bool operator<(const NEONLdStTableEntry &TE, unsigned PseudoOpc) {
105 return TE.PseudoOpc < PseudoOpc;
107 friend bool LLVM_ATTRIBUTE_UNUSED operator<(unsigned PseudoOpc,
108 const NEONLdStTableEntry &TE) {
109 return PseudoOpc < TE.PseudoOpc;
114 static const NEONLdStTableEntry NEONLdStTable[] = {
115 { ARM::VLD1DUPq16Pseudo, ARM::VLD1DUPq16, true, false, SingleSpc, 2, 4},
116 { ARM::VLD1DUPq16Pseudo_UPD, ARM::VLD1DUPq16_UPD, true, true, SingleSpc, 2, 4},
117 { ARM::VLD1DUPq32Pseudo, ARM::VLD1DUPq32, true, false, SingleSpc, 2, 2},
118 { ARM::VLD1DUPq32Pseudo_UPD, ARM::VLD1DUPq32_UPD, true, true, SingleSpc, 2, 2},
119 { ARM::VLD1DUPq8Pseudo, ARM::VLD1DUPq8, true, false, SingleSpc, 2, 8},
120 { ARM::VLD1DUPq8Pseudo_UPD, ARM::VLD1DUPq8_UPD, true, true, SingleSpc, 2, 8},
122 { ARM::VLD1LNq16Pseudo, ARM::VLD1LNd16, true, false, EvenDblSpc, 1, 4 },
123 { ARM::VLD1LNq16Pseudo_UPD, ARM::VLD1LNd16_UPD, true, true, EvenDblSpc, 1, 4 },
124 { ARM::VLD1LNq32Pseudo, ARM::VLD1LNd32, true, false, EvenDblSpc, 1, 2 },
125 { ARM::VLD1LNq32Pseudo_UPD, ARM::VLD1LNd32_UPD, true, true, EvenDblSpc, 1, 2 },
126 { ARM::VLD1LNq8Pseudo, ARM::VLD1LNd8, true, false, EvenDblSpc, 1, 8 },
127 { ARM::VLD1LNq8Pseudo_UPD, ARM::VLD1LNd8_UPD, true, true, EvenDblSpc, 1, 8 },
129 { ARM::VLD1d64QPseudo, ARM::VLD1d64Q, true, false, SingleSpc, 4, 1 },
130 { ARM::VLD1d64QPseudo_UPD, ARM::VLD1d64Q_UPD, true, true, SingleSpc, 4, 1 },
131 { ARM::VLD1d64TPseudo, ARM::VLD1d64T, true, false, SingleSpc, 3, 1 },
132 { ARM::VLD1d64TPseudo_UPD, ARM::VLD1d64T_UPD, true, true, SingleSpc, 3, 1 },
134 { ARM::VLD1q16Pseudo, ARM::VLD1q16, true, false, SingleSpc, 2, 4 },
135 { ARM::VLD1q16Pseudo_UPD, ARM::VLD1q16_UPD, true, true, SingleSpc, 2, 4 },
136 { ARM::VLD1q32Pseudo, ARM::VLD1q32, true, false, SingleSpc, 2, 2 },
137 { ARM::VLD1q32Pseudo_UPD, ARM::VLD1q32_UPD, true, true, SingleSpc, 2, 2 },
138 { ARM::VLD1q64Pseudo, ARM::VLD1q64, true, false, SingleSpc, 2, 1 },
139 { ARM::VLD1q64Pseudo_UPD, ARM::VLD1q64_UPD, true, true, SingleSpc, 2, 1 },
140 { ARM::VLD1q8Pseudo, ARM::VLD1q8, true, false, SingleSpc, 2, 8 },
141 { ARM::VLD1q8Pseudo_UPD, ARM::VLD1q8_UPD, true, true, SingleSpc, 2, 8 },
143 { ARM::VLD2LNd16Pseudo, ARM::VLD2LNd16, true, false, SingleSpc, 2, 4 },
144 { ARM::VLD2LNd16Pseudo_UPD, ARM::VLD2LNd16_UPD, true, true, SingleSpc, 2, 4 },
145 { ARM::VLD2LNd32Pseudo, ARM::VLD2LNd32, true, false, SingleSpc, 2, 2 },
146 { ARM::VLD2LNd32Pseudo_UPD, ARM::VLD2LNd32_UPD, true, true, SingleSpc, 2, 2 },
147 { ARM::VLD2LNd8Pseudo, ARM::VLD2LNd8, true, false, SingleSpc, 2, 8 },
148 { ARM::VLD2LNd8Pseudo_UPD, ARM::VLD2LNd8_UPD, true, true, SingleSpc, 2, 8 },
149 { ARM::VLD2LNq16Pseudo, ARM::VLD2LNq16, true, false, EvenDblSpc, 2, 4 },
150 { ARM::VLD2LNq16Pseudo_UPD, ARM::VLD2LNq16_UPD, true, true, EvenDblSpc, 2, 4 },
151 { ARM::VLD2LNq32Pseudo, ARM::VLD2LNq32, true, false, EvenDblSpc, 2, 2 },
152 { ARM::VLD2LNq32Pseudo_UPD, ARM::VLD2LNq32_UPD, true, true, EvenDblSpc, 2, 2 },
154 { ARM::VLD2d16Pseudo, ARM::VLD2d16, true, false, SingleSpc, 2, 4 },
155 { ARM::VLD2d16Pseudo_UPD, ARM::VLD2d16_UPD, true, true, SingleSpc, 2, 4 },
156 { ARM::VLD2d32Pseudo, ARM::VLD2d32, true, false, SingleSpc, 2, 2 },
157 { ARM::VLD2d32Pseudo_UPD, ARM::VLD2d32_UPD, true, true, SingleSpc, 2, 2 },
158 { ARM::VLD2d8Pseudo, ARM::VLD2d8, true, false, SingleSpc, 2, 8 },
159 { ARM::VLD2d8Pseudo_UPD, ARM::VLD2d8_UPD, true, true, SingleSpc, 2, 8 },
161 { ARM::VLD2q16Pseudo, ARM::VLD2q16, true, false, SingleSpc, 4, 4 },
162 { ARM::VLD2q16Pseudo_UPD, ARM::VLD2q16_UPD, true, true, SingleSpc, 4, 4 },
163 { ARM::VLD2q32Pseudo, ARM::VLD2q32, true, false, SingleSpc, 4, 2 },
164 { ARM::VLD2q32Pseudo_UPD, ARM::VLD2q32_UPD, true, true, SingleSpc, 4, 2 },
165 { ARM::VLD2q8Pseudo, ARM::VLD2q8, true, false, SingleSpc, 4, 8 },
166 { ARM::VLD2q8Pseudo_UPD, ARM::VLD2q8_UPD, true, true, SingleSpc, 4, 8 },
168 { ARM::VLD3LNd16Pseudo, ARM::VLD3LNd16, true, false, SingleSpc, 3, 4 },
169 { ARM::VLD3LNd16Pseudo_UPD, ARM::VLD3LNd16_UPD, true, true, SingleSpc, 3, 4 },
170 { ARM::VLD3LNd32Pseudo, ARM::VLD3LNd32, true, false, SingleSpc, 3, 2 },
171 { ARM::VLD3LNd32Pseudo_UPD, ARM::VLD3LNd32_UPD, true, true, SingleSpc, 3, 2 },
172 { ARM::VLD3LNd8Pseudo, ARM::VLD3LNd8, true, false, SingleSpc, 3, 8 },
173 { ARM::VLD3LNd8Pseudo_UPD, ARM::VLD3LNd8_UPD, true, true, SingleSpc, 3, 8 },
174 { ARM::VLD3LNq16Pseudo, ARM::VLD3LNq16, true, false, EvenDblSpc, 3, 4 },
175 { ARM::VLD3LNq16Pseudo_UPD, ARM::VLD3LNq16_UPD, true, true, EvenDblSpc, 3, 4 },
176 { ARM::VLD3LNq32Pseudo, ARM::VLD3LNq32, true, false, EvenDblSpc, 3, 2 },
177 { ARM::VLD3LNq32Pseudo_UPD, ARM::VLD3LNq32_UPD, true, true, EvenDblSpc, 3, 2 },
179 { ARM::VLD3d16Pseudo, ARM::VLD3d16, true, false, SingleSpc, 3, 4 },
180 { ARM::VLD3d16Pseudo_UPD, ARM::VLD3d16_UPD, true, true, SingleSpc, 3, 4 },
181 { ARM::VLD3d32Pseudo, ARM::VLD3d32, true, false, SingleSpc, 3, 2 },
182 { ARM::VLD3d32Pseudo_UPD, ARM::VLD3d32_UPD, true, true, SingleSpc, 3, 2 },
183 { ARM::VLD3d8Pseudo, ARM::VLD3d8, true, false, SingleSpc, 3, 8 },
184 { ARM::VLD3d8Pseudo_UPD, ARM::VLD3d8_UPD, true, true, SingleSpc, 3, 8 },
186 { ARM::VLD3q16Pseudo_UPD, ARM::VLD3q16_UPD, true, true, EvenDblSpc, 3, 4 },
187 { ARM::VLD3q16oddPseudo_UPD, ARM::VLD3q16_UPD, true, true, OddDblSpc, 3, 4 },
188 { ARM::VLD3q32Pseudo_UPD, ARM::VLD3q32_UPD, true, true, EvenDblSpc, 3, 2 },
189 { ARM::VLD3q32oddPseudo_UPD, ARM::VLD3q32_UPD, true, true, OddDblSpc, 3, 2 },
190 { ARM::VLD3q8Pseudo_UPD, ARM::VLD3q8_UPD, true, true, EvenDblSpc, 3, 8 },
191 { ARM::VLD3q8oddPseudo_UPD, ARM::VLD3q8_UPD, true, true, OddDblSpc, 3, 8 },
193 { ARM::VLD4LNd16Pseudo, ARM::VLD4LNd16, true, false, SingleSpc, 4, 4 },
194 { ARM::VLD4LNd16Pseudo_UPD, ARM::VLD4LNd16_UPD, true, true, SingleSpc, 4, 4 },
195 { ARM::VLD4LNd32Pseudo, ARM::VLD4LNd32, true, false, SingleSpc, 4, 2 },
196 { ARM::VLD4LNd32Pseudo_UPD, ARM::VLD4LNd32_UPD, true, true, SingleSpc, 4, 2 },
197 { ARM::VLD4LNd8Pseudo, ARM::VLD4LNd8, true, false, SingleSpc, 4, 8 },
198 { ARM::VLD4LNd8Pseudo_UPD, ARM::VLD4LNd8_UPD, true, true, SingleSpc, 4, 8 },
199 { ARM::VLD4LNq16Pseudo, ARM::VLD4LNq16, true, false, EvenDblSpc, 4, 4 },
200 { ARM::VLD4LNq16Pseudo_UPD, ARM::VLD4LNq16_UPD, true, true, EvenDblSpc, 4, 4 },
201 { ARM::VLD4LNq32Pseudo, ARM::VLD4LNq32, true, false, EvenDblSpc, 4, 2 },
202 { ARM::VLD4LNq32Pseudo_UPD, ARM::VLD4LNq32_UPD, true, true, EvenDblSpc, 4, 2 },
204 { ARM::VLD4d16Pseudo, ARM::VLD4d16, true, false, SingleSpc, 4, 4 },
205 { ARM::VLD4d16Pseudo_UPD, ARM::VLD4d16_UPD, true, true, SingleSpc, 4, 4 },
206 { ARM::VLD4d32Pseudo, ARM::VLD4d32, true, false, SingleSpc, 4, 2 },
207 { ARM::VLD4d32Pseudo_UPD, ARM::VLD4d32_UPD, true, true, SingleSpc, 4, 2 },
208 { ARM::VLD4d8Pseudo, ARM::VLD4d8, true, false, SingleSpc, 4, 8 },
209 { ARM::VLD4d8Pseudo_UPD, ARM::VLD4d8_UPD, true, true, SingleSpc, 4, 8 },
211 { ARM::VLD4q16Pseudo_UPD, ARM::VLD4q16_UPD, true, true, EvenDblSpc, 4, 4 },
212 { ARM::VLD4q16oddPseudo_UPD, ARM::VLD4q16_UPD, true, true, OddDblSpc, 4, 4 },
213 { ARM::VLD4q32Pseudo_UPD, ARM::VLD4q32_UPD, true, true, EvenDblSpc, 4, 2 },
214 { ARM::VLD4q32oddPseudo_UPD, ARM::VLD4q32_UPD, true, true, OddDblSpc, 4, 2 },
215 { ARM::VLD4q8Pseudo_UPD, ARM::VLD4q8_UPD, true, true, EvenDblSpc, 4, 8 },
216 { ARM::VLD4q8oddPseudo_UPD, ARM::VLD4q8_UPD, true, true, OddDblSpc, 4, 8 },
218 { ARM::VST1LNq16Pseudo, ARM::VST1LNd16, false, false, EvenDblSpc, 1, 4 },
219 { ARM::VST1LNq16Pseudo_UPD, ARM::VST1LNd16_UPD,false, true, EvenDblSpc, 1, 4 },
220 { ARM::VST1LNq32Pseudo, ARM::VST1LNd32, false, false, EvenDblSpc, 1, 2 },
221 { ARM::VST1LNq32Pseudo_UPD, ARM::VST1LNd32_UPD,false, true, EvenDblSpc, 1, 2 },
222 { ARM::VST1LNq8Pseudo, ARM::VST1LNd8, false, false, EvenDblSpc, 1, 8 },
223 { ARM::VST1LNq8Pseudo_UPD, ARM::VST1LNd8_UPD, false, true, EvenDblSpc, 1, 8 },
225 { ARM::VST1d64QPseudo, ARM::VST1d64Q, false, false, SingleSpc, 4, 1 },
226 { ARM::VST1d64QPseudo_UPD, ARM::VST1d64Q_UPD, false, true, SingleSpc, 4, 1 },
227 { ARM::VST1d64TPseudo, ARM::VST1d64T, false, false, SingleSpc, 3, 1 },
228 { ARM::VST1d64TPseudo_UPD, ARM::VST1d64T_UPD, false, true, SingleSpc, 3, 1 },
230 { ARM::VST1q16Pseudo, ARM::VST1q16, false, false, SingleSpc, 2, 4 },
231 { ARM::VST1q16Pseudo_UPD, ARM::VST1q16_UPD, false, true, SingleSpc, 2, 4 },
232 { ARM::VST1q32Pseudo, ARM::VST1q32, false, false, SingleSpc, 2, 2 },
233 { ARM::VST1q32Pseudo_UPD, ARM::VST1q32_UPD, false, true, SingleSpc, 2, 2 },
234 { ARM::VST1q64Pseudo, ARM::VST1q64, false, false, SingleSpc, 2, 1 },
235 { ARM::VST1q64Pseudo_UPD, ARM::VST1q64_UPD, false, true, SingleSpc, 2, 1 },
236 { ARM::VST1q8Pseudo, ARM::VST1q8, false, false, SingleSpc, 2, 8 },
237 { ARM::VST1q8Pseudo_UPD, ARM::VST1q8_UPD, false, true, SingleSpc, 2, 8 },
239 { ARM::VST2LNd16Pseudo, ARM::VST2LNd16, false, false, SingleSpc, 2, 4 },
240 { ARM::VST2LNd16Pseudo_UPD, ARM::VST2LNd16_UPD, false, true, SingleSpc, 2, 4 },
241 { ARM::VST2LNd32Pseudo, ARM::VST2LNd32, false, false, SingleSpc, 2, 2 },
242 { ARM::VST2LNd32Pseudo_UPD, ARM::VST2LNd32_UPD, false, true, SingleSpc, 2, 2 },
243 { ARM::VST2LNd8Pseudo, ARM::VST2LNd8, false, false, SingleSpc, 2, 8 },
244 { ARM::VST2LNd8Pseudo_UPD, ARM::VST2LNd8_UPD, false, true, SingleSpc, 2, 8 },
245 { ARM::VST2LNq16Pseudo, ARM::VST2LNq16, false, false, EvenDblSpc, 2, 4},
246 { ARM::VST2LNq16Pseudo_UPD, ARM::VST2LNq16_UPD, false, true, EvenDblSpc, 2, 4},
247 { ARM::VST2LNq32Pseudo, ARM::VST2LNq32, false, false, EvenDblSpc, 2, 2},
248 { ARM::VST2LNq32Pseudo_UPD, ARM::VST2LNq32_UPD, false, true, EvenDblSpc, 2, 2},
250 { ARM::VST2d16Pseudo, ARM::VST2d16, false, false, SingleSpc, 2, 4 },
251 { ARM::VST2d16Pseudo_UPD, ARM::VST2d16_UPD, false, true, SingleSpc, 2, 4 },
252 { ARM::VST2d32Pseudo, ARM::VST2d32, false, false, SingleSpc, 2, 2 },
253 { ARM::VST2d32Pseudo_UPD, ARM::VST2d32_UPD, false, true, SingleSpc, 2, 2 },
254 { ARM::VST2d8Pseudo, ARM::VST2d8, false, false, SingleSpc, 2, 8 },
255 { ARM::VST2d8Pseudo_UPD, ARM::VST2d8_UPD, false, true, SingleSpc, 2, 8 },
257 { ARM::VST2q16Pseudo, ARM::VST2q16, false, false, SingleSpc, 4, 4 },
258 { ARM::VST2q16Pseudo_UPD, ARM::VST2q16_UPD, false, true, SingleSpc, 4, 4 },
259 { ARM::VST2q32Pseudo, ARM::VST2q32, false, false, SingleSpc, 4, 2 },
260 { ARM::VST2q32Pseudo_UPD, ARM::VST2q32_UPD, false, true, SingleSpc, 4, 2 },
261 { ARM::VST2q8Pseudo, ARM::VST2q8, false, false, SingleSpc, 4, 8 },
262 { ARM::VST2q8Pseudo_UPD, ARM::VST2q8_UPD, false, true, SingleSpc, 4, 8 },
264 { ARM::VST3LNd16Pseudo, ARM::VST3LNd16, false, false, SingleSpc, 3, 4 },
265 { ARM::VST3LNd16Pseudo_UPD, ARM::VST3LNd16_UPD, false, true, SingleSpc, 3, 4 },
266 { ARM::VST3LNd32Pseudo, ARM::VST3LNd32, false, false, SingleSpc, 3, 2 },
267 { ARM::VST3LNd32Pseudo_UPD, ARM::VST3LNd32_UPD, false, true, SingleSpc, 3, 2 },
268 { ARM::VST3LNd8Pseudo, ARM::VST3LNd8, false, false, SingleSpc, 3, 8 },
269 { ARM::VST3LNd8Pseudo_UPD, ARM::VST3LNd8_UPD, false, true, SingleSpc, 3, 8 },
270 { ARM::VST3LNq16Pseudo, ARM::VST3LNq16, false, false, EvenDblSpc, 3, 4},
271 { ARM::VST3LNq16Pseudo_UPD, ARM::VST3LNq16_UPD, false, true, EvenDblSpc, 3, 4},
272 { ARM::VST3LNq32Pseudo, ARM::VST3LNq32, false, false, EvenDblSpc, 3, 2},
273 { ARM::VST3LNq32Pseudo_UPD, ARM::VST3LNq32_UPD, false, true, EvenDblSpc, 3, 2},
275 { ARM::VST3d16Pseudo, ARM::VST3d16, false, false, SingleSpc, 3, 4 },
276 { ARM::VST3d16Pseudo_UPD, ARM::VST3d16_UPD, false, true, SingleSpc, 3, 4 },
277 { ARM::VST3d32Pseudo, ARM::VST3d32, false, false, SingleSpc, 3, 2 },
278 { ARM::VST3d32Pseudo_UPD, ARM::VST3d32_UPD, false, true, SingleSpc, 3, 2 },
279 { ARM::VST3d8Pseudo, ARM::VST3d8, false, false, SingleSpc, 3, 8 },
280 { ARM::VST3d8Pseudo_UPD, ARM::VST3d8_UPD, false, true, SingleSpc, 3, 8 },
282 { ARM::VST3q16Pseudo_UPD, ARM::VST3q16_UPD, false, true, EvenDblSpc, 3, 4 },
283 { ARM::VST3q16oddPseudo_UPD, ARM::VST3q16_UPD, false, true, OddDblSpc, 3, 4 },
284 { ARM::VST3q32Pseudo_UPD, ARM::VST3q32_UPD, false, true, EvenDblSpc, 3, 2 },
285 { ARM::VST3q32oddPseudo_UPD, ARM::VST3q32_UPD, false, true, OddDblSpc, 3, 2 },
286 { ARM::VST3q8Pseudo_UPD, ARM::VST3q8_UPD, false, true, EvenDblSpc, 3, 8 },
287 { ARM::VST3q8oddPseudo_UPD, ARM::VST3q8_UPD, false, true, OddDblSpc, 3, 8 },
289 { ARM::VST4LNd16Pseudo, ARM::VST4LNd16, false, false, SingleSpc, 4, 4 },
290 { ARM::VST4LNd16Pseudo_UPD, ARM::VST4LNd16_UPD, false, true, SingleSpc, 4, 4 },
291 { ARM::VST4LNd32Pseudo, ARM::VST4LNd32, false, false, SingleSpc, 4, 2 },
292 { ARM::VST4LNd32Pseudo_UPD, ARM::VST4LNd32_UPD, false, true, SingleSpc, 4, 2 },
293 { ARM::VST4LNd8Pseudo, ARM::VST4LNd8, false, false, SingleSpc, 4, 8 },
294 { ARM::VST4LNd8Pseudo_UPD, ARM::VST4LNd8_UPD, false, true, SingleSpc, 4, 8 },
295 { ARM::VST4LNq16Pseudo, ARM::VST4LNq16, false, false, EvenDblSpc, 4, 4},
296 { ARM::VST4LNq16Pseudo_UPD, ARM::VST4LNq16_UPD, false, true, EvenDblSpc, 4, 4},
297 { ARM::VST4LNq32Pseudo, ARM::VST4LNq32, false, false, EvenDblSpc, 4, 2},
298 { ARM::VST4LNq32Pseudo_UPD, ARM::VST4LNq32_UPD, false, true, EvenDblSpc, 4, 2},
300 { ARM::VST4d16Pseudo, ARM::VST4d16, false, false, SingleSpc, 4, 4 },
301 { ARM::VST4d16Pseudo_UPD, ARM::VST4d16_UPD, false, true, SingleSpc, 4, 4 },
302 { ARM::VST4d32Pseudo, ARM::VST4d32, false, false, SingleSpc, 4, 2 },
303 { ARM::VST4d32Pseudo_UPD, ARM::VST4d32_UPD, false, true, SingleSpc, 4, 2 },
304 { ARM::VST4d8Pseudo, ARM::VST4d8, false, false, SingleSpc, 4, 8 },
305 { ARM::VST4d8Pseudo_UPD, ARM::VST4d8_UPD, false, true, SingleSpc, 4, 8 },
307 { ARM::VST4q16Pseudo_UPD, ARM::VST4q16_UPD, false, true, EvenDblSpc, 4, 4 },
308 { ARM::VST4q16oddPseudo_UPD, ARM::VST4q16_UPD, false, true, OddDblSpc, 4, 4 },
309 { ARM::VST4q32Pseudo_UPD, ARM::VST4q32_UPD, false, true, EvenDblSpc, 4, 2 },
310 { ARM::VST4q32oddPseudo_UPD, ARM::VST4q32_UPD, false, true, OddDblSpc, 4, 2 },
311 { ARM::VST4q8Pseudo_UPD, ARM::VST4q8_UPD, false, true, EvenDblSpc, 4, 8 },
312 { ARM::VST4q8oddPseudo_UPD , ARM::VST4q8_UPD, false, true, OddDblSpc, 4, 8 }
315 /// LookupNEONLdSt - Search the NEONLdStTable for information about a NEON
316 /// load or store pseudo instruction.
317 static const NEONLdStTableEntry *LookupNEONLdSt(unsigned Opcode) {
318 unsigned NumEntries = array_lengthof(NEONLdStTable);
321 // Make sure the table is sorted.
322 static bool TableChecked = false;
324 for (unsigned i = 0; i != NumEntries-1; ++i)
325 assert(NEONLdStTable[i] < NEONLdStTable[i+1] &&
326 "NEONLdStTable is not sorted!");
331 const NEONLdStTableEntry *I =
332 std::lower_bound(NEONLdStTable, NEONLdStTable + NumEntries, Opcode);
333 if (I != NEONLdStTable + NumEntries && I->PseudoOpc == Opcode)
338 /// GetDSubRegs - Get 4 D subregisters of a Q, QQ, or QQQQ register,
339 /// corresponding to the specified register spacing. Not all of the results
340 /// are necessarily valid, e.g., a Q register only has 2 D subregisters.
341 static void GetDSubRegs(unsigned Reg, NEONRegSpacing RegSpc,
342 const TargetRegisterInfo *TRI, unsigned &D0,
343 unsigned &D1, unsigned &D2, unsigned &D3) {
344 if (RegSpc == SingleSpc) {
345 D0 = TRI->getSubReg(Reg, ARM::dsub_0);
346 D1 = TRI->getSubReg(Reg, ARM::dsub_1);
347 D2 = TRI->getSubReg(Reg, ARM::dsub_2);
348 D3 = TRI->getSubReg(Reg, ARM::dsub_3);
349 } else if (RegSpc == EvenDblSpc) {
350 D0 = TRI->getSubReg(Reg, ARM::dsub_0);
351 D1 = TRI->getSubReg(Reg, ARM::dsub_2);
352 D2 = TRI->getSubReg(Reg, ARM::dsub_4);
353 D3 = TRI->getSubReg(Reg, ARM::dsub_6);
355 assert(RegSpc == OddDblSpc && "unknown register spacing");
356 D0 = TRI->getSubReg(Reg, ARM::dsub_1);
357 D1 = TRI->getSubReg(Reg, ARM::dsub_3);
358 D2 = TRI->getSubReg(Reg, ARM::dsub_5);
359 D3 = TRI->getSubReg(Reg, ARM::dsub_7);
363 /// ExpandVLD - Translate VLD pseudo instructions with Q, QQ or QQQQ register
364 /// operands to real VLD instructions with D register operands.
365 void ARMExpandPseudo::ExpandVLD(MachineBasicBlock::iterator &MBBI) {
366 MachineInstr &MI = *MBBI;
367 MachineBasicBlock &MBB = *MI.getParent();
369 const NEONLdStTableEntry *TableEntry = LookupNEONLdSt(MI.getOpcode());
370 assert(TableEntry && TableEntry->IsLoad && "NEONLdStTable lookup failed");
371 NEONRegSpacing RegSpc = TableEntry->RegSpacing;
372 unsigned NumRegs = TableEntry->NumRegs;
374 MachineInstrBuilder MIB = BuildMI(MBB, MBBI, MI.getDebugLoc(),
375 TII->get(TableEntry->RealOpc));
378 bool DstIsDead = MI.getOperand(OpIdx).isDead();
379 unsigned DstReg = MI.getOperand(OpIdx++).getReg();
380 unsigned D0, D1, D2, D3;
381 GetDSubRegs(DstReg, RegSpc, TRI, D0, D1, D2, D3);
382 MIB.addReg(D0, RegState::Define | getDeadRegState(DstIsDead))
383 .addReg(D1, RegState::Define | getDeadRegState(DstIsDead));
385 MIB.addReg(D2, RegState::Define | getDeadRegState(DstIsDead));
387 MIB.addReg(D3, RegState::Define | getDeadRegState(DstIsDead));
389 if (TableEntry->HasWriteBack)
390 MIB.addOperand(MI.getOperand(OpIdx++));
392 // Copy the addrmode6 operands.
393 MIB.addOperand(MI.getOperand(OpIdx++));
394 MIB.addOperand(MI.getOperand(OpIdx++));
395 // Copy the am6offset operand.
396 if (TableEntry->HasWriteBack)
397 MIB.addOperand(MI.getOperand(OpIdx++));
399 // For an instruction writing double-spaced subregs, the pseudo instruction
400 // has an extra operand that is a use of the super-register. Record the
401 // operand index and skip over it.
402 unsigned SrcOpIdx = 0;
403 if (RegSpc == EvenDblSpc || RegSpc == OddDblSpc)
406 // Copy the predicate operands.
407 MIB.addOperand(MI.getOperand(OpIdx++));
408 MIB.addOperand(MI.getOperand(OpIdx++));
410 // Copy the super-register source operand used for double-spaced subregs over
411 // to the new instruction as an implicit operand.
413 MachineOperand MO = MI.getOperand(SrcOpIdx);
414 MO.setImplicit(true);
417 // Add an implicit def for the super-register.
418 MIB.addReg(DstReg, RegState::ImplicitDefine | getDeadRegState(DstIsDead));
419 TransferImpOps(MI, MIB, MIB);
420 MI.eraseFromParent();
423 /// ExpandVST - Translate VST pseudo instructions with Q, QQ or QQQQ register
424 /// operands to real VST instructions with D register operands.
425 void ARMExpandPseudo::ExpandVST(MachineBasicBlock::iterator &MBBI) {
426 MachineInstr &MI = *MBBI;
427 MachineBasicBlock &MBB = *MI.getParent();
429 const NEONLdStTableEntry *TableEntry = LookupNEONLdSt(MI.getOpcode());
430 assert(TableEntry && !TableEntry->IsLoad && "NEONLdStTable lookup failed");
431 NEONRegSpacing RegSpc = TableEntry->RegSpacing;
432 unsigned NumRegs = TableEntry->NumRegs;
434 MachineInstrBuilder MIB = BuildMI(MBB, MBBI, MI.getDebugLoc(),
435 TII->get(TableEntry->RealOpc));
437 if (TableEntry->HasWriteBack)
438 MIB.addOperand(MI.getOperand(OpIdx++));
440 // Copy the addrmode6 operands.
441 MIB.addOperand(MI.getOperand(OpIdx++));
442 MIB.addOperand(MI.getOperand(OpIdx++));
443 // Copy the am6offset operand.
444 if (TableEntry->HasWriteBack)
445 MIB.addOperand(MI.getOperand(OpIdx++));
447 bool SrcIsKill = MI.getOperand(OpIdx).isKill();
448 unsigned SrcReg = MI.getOperand(OpIdx++).getReg();
449 unsigned D0, D1, D2, D3;
450 GetDSubRegs(SrcReg, RegSpc, TRI, D0, D1, D2, D3);
451 MIB.addReg(D0).addReg(D1);
457 // Copy the predicate operands.
458 MIB.addOperand(MI.getOperand(OpIdx++));
459 MIB.addOperand(MI.getOperand(OpIdx++));
462 // Add an implicit kill for the super-reg.
463 (*MIB).addRegisterKilled(SrcReg, TRI, true);
464 TransferImpOps(MI, MIB, MIB);
465 MI.eraseFromParent();
468 /// ExpandLaneOp - Translate VLD*LN and VST*LN instructions with Q, QQ or QQQQ
469 /// register operands to real instructions with D register operands.
470 void ARMExpandPseudo::ExpandLaneOp(MachineBasicBlock::iterator &MBBI) {
471 MachineInstr &MI = *MBBI;
472 MachineBasicBlock &MBB = *MI.getParent();
474 const NEONLdStTableEntry *TableEntry = LookupNEONLdSt(MI.getOpcode());
475 assert(TableEntry && "NEONLdStTable lookup failed");
476 NEONRegSpacing RegSpc = TableEntry->RegSpacing;
477 unsigned NumRegs = TableEntry->NumRegs;
478 unsigned RegElts = TableEntry->RegElts;
480 MachineInstrBuilder MIB = BuildMI(MBB, MBBI, MI.getDebugLoc(),
481 TII->get(TableEntry->RealOpc));
483 // The lane operand is always the 3rd from last operand, before the 2
484 // predicate operands.
485 unsigned Lane = MI.getOperand(MI.getDesc().getNumOperands() - 3).getImm();
487 // Adjust the lane and spacing as needed for Q registers.
488 assert(RegSpc != OddDblSpc && "unexpected register spacing for VLD/VST-lane");
489 if (RegSpc == EvenDblSpc && Lane >= RegElts) {
493 assert(Lane < RegElts && "out of range lane for VLD/VST-lane");
495 unsigned D0, D1, D2, D3;
497 bool DstIsDead = false;
498 if (TableEntry->IsLoad) {
499 DstIsDead = MI.getOperand(OpIdx).isDead();
500 DstReg = MI.getOperand(OpIdx++).getReg();
501 GetDSubRegs(DstReg, RegSpc, TRI, D0, D1, D2, D3);
502 MIB.addReg(D0, RegState::Define | getDeadRegState(DstIsDead));
504 MIB.addReg(D1, RegState::Define | getDeadRegState(DstIsDead));
506 MIB.addReg(D2, RegState::Define | getDeadRegState(DstIsDead));
508 MIB.addReg(D3, RegState::Define | getDeadRegState(DstIsDead));
511 if (TableEntry->HasWriteBack)
512 MIB.addOperand(MI.getOperand(OpIdx++));
514 // Copy the addrmode6 operands.
515 MIB.addOperand(MI.getOperand(OpIdx++));
516 MIB.addOperand(MI.getOperand(OpIdx++));
517 // Copy the am6offset operand.
518 if (TableEntry->HasWriteBack)
519 MIB.addOperand(MI.getOperand(OpIdx++));
521 // Grab the super-register source.
522 MachineOperand MO = MI.getOperand(OpIdx++);
523 if (!TableEntry->IsLoad)
524 GetDSubRegs(MO.getReg(), RegSpc, TRI, D0, D1, D2, D3);
526 // Add the subregs as sources of the new instruction.
527 unsigned SrcFlags = (getUndefRegState(MO.isUndef()) |
528 getKillRegState(MO.isKill()));
529 MIB.addReg(D0, SrcFlags);
531 MIB.addReg(D1, SrcFlags);
533 MIB.addReg(D2, SrcFlags);
535 MIB.addReg(D3, SrcFlags);
537 // Add the lane number operand.
541 // Copy the predicate operands.
542 MIB.addOperand(MI.getOperand(OpIdx++));
543 MIB.addOperand(MI.getOperand(OpIdx++));
545 // Copy the super-register source to be an implicit source.
546 MO.setImplicit(true);
548 if (TableEntry->IsLoad)
549 // Add an implicit def for the super-register.
550 MIB.addReg(DstReg, RegState::ImplicitDefine | getDeadRegState(DstIsDead));
551 TransferImpOps(MI, MIB, MIB);
552 MI.eraseFromParent();
555 /// ExpandVTBL - Translate VTBL and VTBX pseudo instructions with Q or QQ
556 /// register operands to real instructions with D register operands.
557 void ARMExpandPseudo::ExpandVTBL(MachineBasicBlock::iterator &MBBI,
558 unsigned Opc, bool IsExt, unsigned NumRegs) {
559 MachineInstr &MI = *MBBI;
560 MachineBasicBlock &MBB = *MI.getParent();
562 MachineInstrBuilder MIB = BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(Opc));
565 // Transfer the destination register operand.
566 MIB.addOperand(MI.getOperand(OpIdx++));
568 MIB.addOperand(MI.getOperand(OpIdx++));
570 bool SrcIsKill = MI.getOperand(OpIdx).isKill();
571 unsigned SrcReg = MI.getOperand(OpIdx++).getReg();
572 unsigned D0, D1, D2, D3;
573 GetDSubRegs(SrcReg, SingleSpc, TRI, D0, D1, D2, D3);
574 MIB.addReg(D0).addReg(D1);
580 // Copy the other source register operand.
581 MIB.addOperand(MI.getOperand(OpIdx++));
583 // Copy the predicate operands.
584 MIB.addOperand(MI.getOperand(OpIdx++));
585 MIB.addOperand(MI.getOperand(OpIdx++));
588 // Add an implicit kill for the super-reg.
589 (*MIB).addRegisterKilled(SrcReg, TRI, true);
590 TransferImpOps(MI, MIB, MIB);
591 MI.eraseFromParent();
594 bool ARMExpandPseudo::ExpandMBB(MachineBasicBlock &MBB) {
595 bool Modified = false;
597 MachineBasicBlock::iterator MBBI = MBB.begin(), E = MBB.end();
599 MachineInstr &MI = *MBBI;
600 MachineBasicBlock::iterator NMBBI = llvm::next(MBBI);
602 bool ModifiedOp = true;
603 unsigned Opcode = MI.getOpcode();
609 case ARM::Int_eh_sjlj_dispatchsetup: {
610 MachineFunction &MF = *MI.getParent()->getParent();
611 const ARMBaseInstrInfo *AII =
612 static_cast<const ARMBaseInstrInfo*>(TII);
613 const ARMBaseRegisterInfo &RI = AII->getRegisterInfo();
614 // For functions using a base pointer, we rematerialize it (via the frame
615 // pointer) here since eh.sjlj.setjmp and eh.sjlj.longjmp don't do it
616 // for us. Otherwise, expand to nothing.
617 if (RI.hasBasePointer(MF)) {
618 ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>();
619 int32_t NumBytes = AFI->getFramePtrSpillOffset();
620 unsigned FramePtr = RI.getFrameRegister(MF);
621 assert(MF.getTarget().getFrameInfo()->hasFP(MF) &&
622 "base pointer without frame pointer?");
624 if (AFI->isThumb2Function()) {
625 llvm::emitT2RegPlusImmediate(MBB, MBBI, MI.getDebugLoc(), ARM::R6,
626 FramePtr, -NumBytes, ARMCC::AL, 0, *TII);
627 } else if (AFI->isThumbFunction()) {
628 llvm::emitThumbRegPlusImmediate(MBB, MBBI, ARM::R6,
630 *TII, RI, MI.getDebugLoc());
632 llvm::emitARMRegPlusImmediate(MBB, MBBI, MI.getDebugLoc(), ARM::R6,
633 FramePtr, -NumBytes, ARMCC::AL, 0,
636 // If there's dynamic realignment, adjust for it.
637 if (RI.needsStackRealignment(MF)) {
638 MachineFrameInfo *MFI = MF.getFrameInfo();
639 unsigned MaxAlign = MFI->getMaxAlignment();
640 assert (!AFI->isThumb1OnlyFunction());
641 // Emit bic r6, r6, MaxAlign
642 unsigned bicOpc = AFI->isThumbFunction() ?
643 ARM::t2BICri : ARM::BICri;
644 AddDefaultCC(AddDefaultPred(BuildMI(MBB, MBBI, MI.getDebugLoc(),
645 TII->get(bicOpc), ARM::R6)
646 .addReg(ARM::R6, RegState::Kill)
647 .addImm(MaxAlign-1)));
651 MI.eraseFromParent();
655 case ARM::MOVsrl_flag:
656 case ARM::MOVsra_flag: {
657 // These are just fancy MOVs insructions.
658 AddDefaultPred(BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(ARM::MOVs),
659 MI.getOperand(0).getReg())
660 .addOperand(MI.getOperand(1))
662 .addImm(ARM_AM::getSORegOpc((Opcode == ARM::MOVsrl_flag ? ARM_AM::lsr
664 .addReg(ARM::CPSR, RegState::Define);
665 MI.eraseFromParent();
669 // This encodes as "MOVs Rd, Rm, rrx
670 MachineInstrBuilder MIB =
671 AddDefaultPred(BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(ARM::MOVs),
672 MI.getOperand(0).getReg())
673 .addOperand(MI.getOperand(1))
674 .addOperand(MI.getOperand(1))
675 .addImm(ARM_AM::getSORegOpc(ARM_AM::rrx, 0)))
677 TransferImpOps(MI, MIB, MIB);
678 MI.eraseFromParent();
681 case ARM::tLDRpci_pic:
682 case ARM::t2LDRpci_pic: {
683 unsigned NewLdOpc = (Opcode == ARM::tLDRpci_pic)
684 ? ARM::tLDRpci : ARM::t2LDRpci;
685 unsigned DstReg = MI.getOperand(0).getReg();
686 bool DstIsDead = MI.getOperand(0).isDead();
687 MachineInstrBuilder MIB1 =
688 AddDefaultPred(BuildMI(MBB, MBBI, MI.getDebugLoc(),
689 TII->get(NewLdOpc), DstReg)
690 .addOperand(MI.getOperand(1)));
691 (*MIB1).setMemRefs(MI.memoperands_begin(), MI.memoperands_end());
692 MachineInstrBuilder MIB2 = BuildMI(MBB, MBBI, MI.getDebugLoc(),
693 TII->get(ARM::tPICADD))
694 .addReg(DstReg, RegState::Define | getDeadRegState(DstIsDead))
696 .addOperand(MI.getOperand(2));
697 TransferImpOps(MI, MIB1, MIB2);
698 MI.eraseFromParent();
703 case ARM::MOVCCi32imm:
704 case ARM::t2MOVi32imm:
705 case ARM::t2MOVCCi32imm: {
706 unsigned PredReg = 0;
707 ARMCC::CondCodes Pred = llvm::getInstrPredicate(&MI, PredReg);
708 unsigned DstReg = MI.getOperand(0).getReg();
709 bool DstIsDead = MI.getOperand(0).isDead();
710 bool isCC = Opcode == ARM::MOVCCi32imm || Opcode == ARM::t2MOVCCi32imm;
711 const MachineOperand &MO = MI.getOperand(isCC ? 2 : 1);
712 MachineInstrBuilder LO16, HI16;
714 if (!STI->hasV6T2Ops() &&
715 (Opcode == ARM::MOVi32imm || Opcode == ARM::MOVCCi32imm)) {
716 // Expand into a movi + orr.
717 LO16 = BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(ARM::MOVi), DstReg);
718 HI16 = BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(ARM::ORRri))
719 .addReg(DstReg, RegState::Define | getDeadRegState(DstIsDead))
722 assert (MO.isImm() && "MOVi32imm w/ non-immediate source operand!");
723 unsigned ImmVal = (unsigned)MO.getImm();
724 unsigned SOImmValV1 = ARM_AM::getSOImmTwoPartFirst(ImmVal);
725 unsigned SOImmValV2 = ARM_AM::getSOImmTwoPartSecond(ImmVal);
726 LO16 = LO16.addImm(SOImmValV1);
727 HI16 = HI16.addImm(SOImmValV2);
728 (*LO16).setMemRefs(MI.memoperands_begin(), MI.memoperands_end());
729 (*HI16).setMemRefs(MI.memoperands_begin(), MI.memoperands_end());
730 LO16.addImm(Pred).addReg(PredReg).addReg(0);
731 HI16.addImm(Pred).addReg(PredReg).addReg(0);
732 TransferImpOps(MI, LO16, HI16);
733 MI.eraseFromParent();
737 LO16 = BuildMI(MBB, MBBI, MI.getDebugLoc(),
738 TII->get(Opcode == ARM::MOVi32imm ?
739 ARM::MOVi16 : ARM::t2MOVi16),
741 HI16 = BuildMI(MBB, MBBI, MI.getDebugLoc(),
742 TII->get(Opcode == ARM::MOVi32imm ?
743 ARM::MOVTi16 : ARM::t2MOVTi16))
744 .addReg(DstReg, RegState::Define | getDeadRegState(DstIsDead))
748 unsigned Imm = MO.getImm();
749 unsigned Lo16 = Imm & 0xffff;
750 unsigned Hi16 = (Imm >> 16) & 0xffff;
751 LO16 = LO16.addImm(Lo16);
752 HI16 = HI16.addImm(Hi16);
754 const GlobalValue *GV = MO.getGlobal();
755 unsigned TF = MO.getTargetFlags();
756 LO16 = LO16.addGlobalAddress(GV, MO.getOffset(), TF | ARMII::MO_LO16);
757 HI16 = HI16.addGlobalAddress(GV, MO.getOffset(), TF | ARMII::MO_HI16);
759 (*LO16).setMemRefs(MI.memoperands_begin(), MI.memoperands_end());
760 (*HI16).setMemRefs(MI.memoperands_begin(), MI.memoperands_end());
761 LO16.addImm(Pred).addReg(PredReg);
762 HI16.addImm(Pred).addReg(PredReg);
763 TransferImpOps(MI, LO16, HI16);
764 MI.eraseFromParent();
769 unsigned DstReg = MI.getOperand(0).getReg();
770 bool DstIsDead = MI.getOperand(0).isDead();
771 unsigned EvenDst = TRI->getSubReg(DstReg, ARM::qsub_0);
772 unsigned OddDst = TRI->getSubReg(DstReg, ARM::qsub_1);
773 unsigned SrcReg = MI.getOperand(1).getReg();
774 bool SrcIsKill = MI.getOperand(1).isKill();
775 unsigned EvenSrc = TRI->getSubReg(SrcReg, ARM::qsub_0);
776 unsigned OddSrc = TRI->getSubReg(SrcReg, ARM::qsub_1);
777 MachineInstrBuilder Even =
778 AddDefaultPred(BuildMI(MBB, MBBI, MI.getDebugLoc(),
779 TII->get(ARM::VMOVQ))
781 RegState::Define | getDeadRegState(DstIsDead))
782 .addReg(EvenSrc, getKillRegState(SrcIsKill)));
783 MachineInstrBuilder Odd =
784 AddDefaultPred(BuildMI(MBB, MBBI, MI.getDebugLoc(),
785 TII->get(ARM::VMOVQ))
787 RegState::Define | getDeadRegState(DstIsDead))
788 .addReg(OddSrc, getKillRegState(SrcIsKill)));
789 TransferImpOps(MI, Even, Odd);
790 MI.eraseFromParent();
796 unsigned NewOpc = (Opcode == ARM::VLDMQIA) ? ARM::VLDMDIA : ARM::VLDMDDB;
797 MachineInstrBuilder MIB =
798 BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(NewOpc));
801 // Grab the Q register destination.
802 bool DstIsDead = MI.getOperand(OpIdx).isDead();
803 unsigned DstReg = MI.getOperand(OpIdx++).getReg();
805 // Copy the source register.
806 MIB.addOperand(MI.getOperand(OpIdx++));
808 // Copy the predicate operands.
809 MIB.addOperand(MI.getOperand(OpIdx++));
810 MIB.addOperand(MI.getOperand(OpIdx++));
812 // Add the destination operands (D subregs).
813 unsigned D0 = TRI->getSubReg(DstReg, ARM::dsub_0);
814 unsigned D1 = TRI->getSubReg(DstReg, ARM::dsub_1);
815 MIB.addReg(D0, RegState::Define | getDeadRegState(DstIsDead))
816 .addReg(D1, RegState::Define | getDeadRegState(DstIsDead));
818 // Add an implicit def for the super-register.
819 MIB.addReg(DstReg, RegState::ImplicitDefine | getDeadRegState(DstIsDead));
820 TransferImpOps(MI, MIB, MIB);
821 MI.eraseFromParent();
827 unsigned NewOpc = (Opcode == ARM::VSTMQIA) ? ARM::VSTMDIA : ARM::VSTMDDB;
828 MachineInstrBuilder MIB =
829 BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(NewOpc));
832 // Grab the Q register source.
833 bool SrcIsKill = MI.getOperand(OpIdx).isKill();
834 unsigned SrcReg = MI.getOperand(OpIdx++).getReg();
836 // Copy the destination register.
837 MIB.addOperand(MI.getOperand(OpIdx++));
839 // Copy the predicate operands.
840 MIB.addOperand(MI.getOperand(OpIdx++));
841 MIB.addOperand(MI.getOperand(OpIdx++));
843 // Add the source operands (D subregs).
844 unsigned D0 = TRI->getSubReg(SrcReg, ARM::dsub_0);
845 unsigned D1 = TRI->getSubReg(SrcReg, ARM::dsub_1);
846 MIB.addReg(D0).addReg(D1);
849 // Add an implicit kill for the Q register.
850 (*MIB).addRegisterKilled(SrcReg, TRI, true);
852 TransferImpOps(MI, MIB, MIB);
853 MI.eraseFromParent();
858 unsigned NewOpc = Opcode == ARM::VDUPfqf ? ARM::VDUPLNfq : ARM::VDUPLNfd;
859 MachineInstrBuilder MIB =
860 BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(NewOpc));
862 unsigned SrcReg = MI.getOperand(1).getReg();
863 unsigned Lane = getARMRegisterNumbering(SrcReg) & 1;
864 unsigned DReg = TRI->getMatchingSuperReg(SrcReg,
865 Lane & 1 ? ARM::ssub_1 : ARM::ssub_0, &ARM::DPR_VFP2RegClass);
866 // The lane is [0,1] for the containing DReg superregister.
867 // Copy the dst/src register operands.
868 MIB.addOperand(MI.getOperand(OpIdx++));
871 // Add the lane select operand.
873 // Add the predicate operands.
874 MIB.addOperand(MI.getOperand(OpIdx++));
875 MIB.addOperand(MI.getOperand(OpIdx++));
877 TransferImpOps(MI, MIB, MIB);
878 MI.eraseFromParent();
882 case ARM::VLD1q8Pseudo:
883 case ARM::VLD1q16Pseudo:
884 case ARM::VLD1q32Pseudo:
885 case ARM::VLD1q64Pseudo:
886 case ARM::VLD1q8Pseudo_UPD:
887 case ARM::VLD1q16Pseudo_UPD:
888 case ARM::VLD1q32Pseudo_UPD:
889 case ARM::VLD1q64Pseudo_UPD:
890 case ARM::VLD2d8Pseudo:
891 case ARM::VLD2d16Pseudo:
892 case ARM::VLD2d32Pseudo:
893 case ARM::VLD2q8Pseudo:
894 case ARM::VLD2q16Pseudo:
895 case ARM::VLD2q32Pseudo:
896 case ARM::VLD2d8Pseudo_UPD:
897 case ARM::VLD2d16Pseudo_UPD:
898 case ARM::VLD2d32Pseudo_UPD:
899 case ARM::VLD2q8Pseudo_UPD:
900 case ARM::VLD2q16Pseudo_UPD:
901 case ARM::VLD2q32Pseudo_UPD:
902 case ARM::VLD3d8Pseudo:
903 case ARM::VLD3d16Pseudo:
904 case ARM::VLD3d32Pseudo:
905 case ARM::VLD1d64TPseudo:
906 case ARM::VLD3d8Pseudo_UPD:
907 case ARM::VLD3d16Pseudo_UPD:
908 case ARM::VLD3d32Pseudo_UPD:
909 case ARM::VLD1d64TPseudo_UPD:
910 case ARM::VLD3q8Pseudo_UPD:
911 case ARM::VLD3q16Pseudo_UPD:
912 case ARM::VLD3q32Pseudo_UPD:
913 case ARM::VLD3q8oddPseudo_UPD:
914 case ARM::VLD3q16oddPseudo_UPD:
915 case ARM::VLD3q32oddPseudo_UPD:
916 case ARM::VLD4d8Pseudo:
917 case ARM::VLD4d16Pseudo:
918 case ARM::VLD4d32Pseudo:
919 case ARM::VLD1d64QPseudo:
920 case ARM::VLD4d8Pseudo_UPD:
921 case ARM::VLD4d16Pseudo_UPD:
922 case ARM::VLD4d32Pseudo_UPD:
923 case ARM::VLD1d64QPseudo_UPD:
924 case ARM::VLD4q8Pseudo_UPD:
925 case ARM::VLD4q16Pseudo_UPD:
926 case ARM::VLD4q32Pseudo_UPD:
927 case ARM::VLD4q8oddPseudo_UPD:
928 case ARM::VLD4q16oddPseudo_UPD:
929 case ARM::VLD4q32oddPseudo_UPD:
930 case ARM::VLD1DUPq8Pseudo:
931 case ARM::VLD1DUPq16Pseudo:
932 case ARM::VLD1DUPq32Pseudo:
933 case ARM::VLD1DUPq8Pseudo_UPD:
934 case ARM::VLD1DUPq16Pseudo_UPD:
935 case ARM::VLD1DUPq32Pseudo_UPD:
939 case ARM::VST1q8Pseudo:
940 case ARM::VST1q16Pseudo:
941 case ARM::VST1q32Pseudo:
942 case ARM::VST1q64Pseudo:
943 case ARM::VST1q8Pseudo_UPD:
944 case ARM::VST1q16Pseudo_UPD:
945 case ARM::VST1q32Pseudo_UPD:
946 case ARM::VST1q64Pseudo_UPD:
947 case ARM::VST2d8Pseudo:
948 case ARM::VST2d16Pseudo:
949 case ARM::VST2d32Pseudo:
950 case ARM::VST2q8Pseudo:
951 case ARM::VST2q16Pseudo:
952 case ARM::VST2q32Pseudo:
953 case ARM::VST2d8Pseudo_UPD:
954 case ARM::VST2d16Pseudo_UPD:
955 case ARM::VST2d32Pseudo_UPD:
956 case ARM::VST2q8Pseudo_UPD:
957 case ARM::VST2q16Pseudo_UPD:
958 case ARM::VST2q32Pseudo_UPD:
959 case ARM::VST3d8Pseudo:
960 case ARM::VST3d16Pseudo:
961 case ARM::VST3d32Pseudo:
962 case ARM::VST1d64TPseudo:
963 case ARM::VST3d8Pseudo_UPD:
964 case ARM::VST3d16Pseudo_UPD:
965 case ARM::VST3d32Pseudo_UPD:
966 case ARM::VST1d64TPseudo_UPD:
967 case ARM::VST3q8Pseudo_UPD:
968 case ARM::VST3q16Pseudo_UPD:
969 case ARM::VST3q32Pseudo_UPD:
970 case ARM::VST3q8oddPseudo_UPD:
971 case ARM::VST3q16oddPseudo_UPD:
972 case ARM::VST3q32oddPseudo_UPD:
973 case ARM::VST4d8Pseudo:
974 case ARM::VST4d16Pseudo:
975 case ARM::VST4d32Pseudo:
976 case ARM::VST1d64QPseudo:
977 case ARM::VST4d8Pseudo_UPD:
978 case ARM::VST4d16Pseudo_UPD:
979 case ARM::VST4d32Pseudo_UPD:
980 case ARM::VST1d64QPseudo_UPD:
981 case ARM::VST4q8Pseudo_UPD:
982 case ARM::VST4q16Pseudo_UPD:
983 case ARM::VST4q32Pseudo_UPD:
984 case ARM::VST4q8oddPseudo_UPD:
985 case ARM::VST4q16oddPseudo_UPD:
986 case ARM::VST4q32oddPseudo_UPD:
990 case ARM::VLD1LNq8Pseudo:
991 case ARM::VLD1LNq16Pseudo:
992 case ARM::VLD1LNq32Pseudo:
993 case ARM::VLD1LNq8Pseudo_UPD:
994 case ARM::VLD1LNq16Pseudo_UPD:
995 case ARM::VLD1LNq32Pseudo_UPD:
996 case ARM::VLD2LNd8Pseudo:
997 case ARM::VLD2LNd16Pseudo:
998 case ARM::VLD2LNd32Pseudo:
999 case ARM::VLD2LNq16Pseudo:
1000 case ARM::VLD2LNq32Pseudo:
1001 case ARM::VLD2LNd8Pseudo_UPD:
1002 case ARM::VLD2LNd16Pseudo_UPD:
1003 case ARM::VLD2LNd32Pseudo_UPD:
1004 case ARM::VLD2LNq16Pseudo_UPD:
1005 case ARM::VLD2LNq32Pseudo_UPD:
1006 case ARM::VLD3LNd8Pseudo:
1007 case ARM::VLD3LNd16Pseudo:
1008 case ARM::VLD3LNd32Pseudo:
1009 case ARM::VLD3LNq16Pseudo:
1010 case ARM::VLD3LNq32Pseudo:
1011 case ARM::VLD3LNd8Pseudo_UPD:
1012 case ARM::VLD3LNd16Pseudo_UPD:
1013 case ARM::VLD3LNd32Pseudo_UPD:
1014 case ARM::VLD3LNq16Pseudo_UPD:
1015 case ARM::VLD3LNq32Pseudo_UPD:
1016 case ARM::VLD4LNd8Pseudo:
1017 case ARM::VLD4LNd16Pseudo:
1018 case ARM::VLD4LNd32Pseudo:
1019 case ARM::VLD4LNq16Pseudo:
1020 case ARM::VLD4LNq32Pseudo:
1021 case ARM::VLD4LNd8Pseudo_UPD:
1022 case ARM::VLD4LNd16Pseudo_UPD:
1023 case ARM::VLD4LNd32Pseudo_UPD:
1024 case ARM::VLD4LNq16Pseudo_UPD:
1025 case ARM::VLD4LNq32Pseudo_UPD:
1026 case ARM::VST1LNq8Pseudo:
1027 case ARM::VST1LNq16Pseudo:
1028 case ARM::VST1LNq32Pseudo:
1029 case ARM::VST1LNq8Pseudo_UPD:
1030 case ARM::VST1LNq16Pseudo_UPD:
1031 case ARM::VST1LNq32Pseudo_UPD:
1032 case ARM::VST2LNd8Pseudo:
1033 case ARM::VST2LNd16Pseudo:
1034 case ARM::VST2LNd32Pseudo:
1035 case ARM::VST2LNq16Pseudo:
1036 case ARM::VST2LNq32Pseudo:
1037 case ARM::VST2LNd8Pseudo_UPD:
1038 case ARM::VST2LNd16Pseudo_UPD:
1039 case ARM::VST2LNd32Pseudo_UPD:
1040 case ARM::VST2LNq16Pseudo_UPD:
1041 case ARM::VST2LNq32Pseudo_UPD:
1042 case ARM::VST3LNd8Pseudo:
1043 case ARM::VST3LNd16Pseudo:
1044 case ARM::VST3LNd32Pseudo:
1045 case ARM::VST3LNq16Pseudo:
1046 case ARM::VST3LNq32Pseudo:
1047 case ARM::VST3LNd8Pseudo_UPD:
1048 case ARM::VST3LNd16Pseudo_UPD:
1049 case ARM::VST3LNd32Pseudo_UPD:
1050 case ARM::VST3LNq16Pseudo_UPD:
1051 case ARM::VST3LNq32Pseudo_UPD:
1052 case ARM::VST4LNd8Pseudo:
1053 case ARM::VST4LNd16Pseudo:
1054 case ARM::VST4LNd32Pseudo:
1055 case ARM::VST4LNq16Pseudo:
1056 case ARM::VST4LNq32Pseudo:
1057 case ARM::VST4LNd8Pseudo_UPD:
1058 case ARM::VST4LNd16Pseudo_UPD:
1059 case ARM::VST4LNd32Pseudo_UPD:
1060 case ARM::VST4LNq16Pseudo_UPD:
1061 case ARM::VST4LNq32Pseudo_UPD:
1065 case ARM::VTBL2Pseudo:
1066 ExpandVTBL(MBBI, ARM::VTBL2, false, 2); break;
1067 case ARM::VTBL3Pseudo:
1068 ExpandVTBL(MBBI, ARM::VTBL3, false, 3); break;
1069 case ARM::VTBL4Pseudo:
1070 ExpandVTBL(MBBI, ARM::VTBL4, false, 4); break;
1071 case ARM::VTBX2Pseudo:
1072 ExpandVTBL(MBBI, ARM::VTBX2, true, 2); break;
1073 case ARM::VTBX3Pseudo:
1074 ExpandVTBL(MBBI, ARM::VTBX3, true, 3); break;
1075 case ARM::VTBX4Pseudo:
1076 ExpandVTBL(MBBI, ARM::VTBX4, true, 4); break;
1087 bool ARMExpandPseudo::runOnMachineFunction(MachineFunction &MF) {
1088 TII = static_cast<const ARMBaseInstrInfo*>(MF.getTarget().getInstrInfo());
1089 TRI = MF.getTarget().getRegisterInfo();
1090 STI = &MF.getTarget().getSubtarget<ARMSubtarget>();
1092 bool Modified = false;
1093 for (MachineFunction::iterator MFI = MF.begin(), E = MF.end(); MFI != E;
1095 Modified |= ExpandMBB(*MFI);
1099 /// createARMExpandPseudoPass - returns an instance of the pseudo instruction
1101 FunctionPass *llvm::createARMExpandPseudoPass() {
1102 return new ARMExpandPseudo();