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 "ARMBaseInstrInfo.h"
20 #include "llvm/CodeGen/MachineFunctionPass.h"
21 #include "llvm/CodeGen/MachineInstrBuilder.h"
22 #include "llvm/Target/TargetRegisterInfo.h"
26 class ARMExpandPseudo : public MachineFunctionPass {
29 ARMExpandPseudo() : MachineFunctionPass(ID) {}
31 const TargetInstrInfo *TII;
32 const TargetRegisterInfo *TRI;
34 virtual bool runOnMachineFunction(MachineFunction &Fn);
36 virtual const char *getPassName() const {
37 return "ARM pseudo instruction expansion pass";
41 void TransferImpOps(MachineInstr &OldMI,
42 MachineInstrBuilder &UseMI, MachineInstrBuilder &DefMI);
43 bool ExpandMBB(MachineBasicBlock &MBB);
44 void ExpandVLD(MachineBasicBlock::iterator &MBBI);
45 void ExpandVST(MachineBasicBlock::iterator &MBBI);
46 void ExpandLaneOp(MachineBasicBlock::iterator &MBBI);
48 char ARMExpandPseudo::ID = 0;
51 /// TransferImpOps - Transfer implicit operands on the pseudo instruction to
52 /// the instructions created from the expansion.
53 void ARMExpandPseudo::TransferImpOps(MachineInstr &OldMI,
54 MachineInstrBuilder &UseMI,
55 MachineInstrBuilder &DefMI) {
56 const TargetInstrDesc &Desc = OldMI.getDesc();
57 for (unsigned i = Desc.getNumOperands(), e = OldMI.getNumOperands();
59 const MachineOperand &MO = OldMI.getOperand(i);
60 assert(MO.isReg() && MO.getReg());
69 // Constants for register spacing in NEON load/store instructions.
70 // For quad-register load-lane and store-lane pseudo instructors, the
71 // spacing is initially assumed to be EvenDblSpc, and that is changed to
72 // OddDblSpc depending on the lane number operand.
79 // Entries for NEON load/store information table. The table is sorted by
80 // PseudoOpc for fast binary-search lookups.
81 struct NEONLdStTableEntry {
86 NEONRegSpacing RegSpacing;
87 unsigned char NumRegs; // D registers loaded or stored
88 unsigned char RegElts; // elements per D register; used for lane ops
90 // Comparison methods for binary search of the table.
91 bool operator<(const NEONLdStTableEntry &TE) const {
92 return PseudoOpc < TE.PseudoOpc;
94 friend bool operator<(const NEONLdStTableEntry &TE, unsigned PseudoOpc) {
95 return TE.PseudoOpc < PseudoOpc;
97 friend bool ATTRIBUTE_UNUSED operator<(unsigned PseudoOpc,
98 const NEONLdStTableEntry &TE) {
99 return PseudoOpc < TE.PseudoOpc;
104 static const NEONLdStTableEntry NEONLdStTable[] = {
105 { ARM::VLD1d64QPseudo, ARM::VLD1d64Q, true, false, SingleSpc, 4, 1 },
106 { ARM::VLD1d64QPseudo_UPD, ARM::VLD1d64Q_UPD, true, true, SingleSpc, 4, 1 },
107 { ARM::VLD1d64TPseudo, ARM::VLD1d64T, true, false, SingleSpc, 3, 1 },
108 { ARM::VLD1d64TPseudo_UPD, ARM::VLD1d64T_UPD, true, true, SingleSpc, 3, 1 },
110 { ARM::VLD1q16Pseudo, ARM::VLD1q16, true, false, SingleSpc, 2, 4 },
111 { ARM::VLD1q16Pseudo_UPD, ARM::VLD1q16_UPD, true, true, SingleSpc, 2, 4 },
112 { ARM::VLD1q32Pseudo, ARM::VLD1q32, true, false, SingleSpc, 2, 2 },
113 { ARM::VLD1q32Pseudo_UPD, ARM::VLD1q32_UPD, true, true, SingleSpc, 2, 2 },
114 { ARM::VLD1q64Pseudo, ARM::VLD1q64, true, false, SingleSpc, 2, 1 },
115 { ARM::VLD1q64Pseudo_UPD, ARM::VLD1q64_UPD, true, true, SingleSpc, 2, 1 },
116 { ARM::VLD1q8Pseudo, ARM::VLD1q8, true, false, SingleSpc, 2, 8 },
117 { ARM::VLD1q8Pseudo_UPD, ARM::VLD1q8_UPD, true, true, SingleSpc, 2, 8 },
119 { ARM::VLD2LNd16Pseudo, ARM::VLD2LNd16, true, false, SingleSpc, 2, 4 },
120 { ARM::VLD2LNd16Pseudo_UPD, ARM::VLD2LNd16_UPD, true, true, SingleSpc, 2, 4 },
121 { ARM::VLD2LNd32Pseudo, ARM::VLD2LNd32, true, false, SingleSpc, 2, 2 },
122 { ARM::VLD2LNd32Pseudo_UPD, ARM::VLD2LNd32_UPD, true, true, SingleSpc, 2, 2 },
123 { ARM::VLD2LNd8Pseudo, ARM::VLD2LNd8, true, false, SingleSpc, 2, 8 },
124 { ARM::VLD2LNd8Pseudo_UPD, ARM::VLD2LNd8_UPD, true, true, SingleSpc, 2, 8 },
125 { ARM::VLD2LNq16Pseudo, ARM::VLD2LNq16, true, false, EvenDblSpc, 2, 4 },
126 { ARM::VLD2LNq16Pseudo_UPD, ARM::VLD2LNq16_UPD, true, true, EvenDblSpc, 2, 4 },
127 { ARM::VLD2LNq32Pseudo, ARM::VLD2LNq32, true, false, EvenDblSpc, 2, 2 },
128 { ARM::VLD2LNq32Pseudo_UPD, ARM::VLD2LNq32_UPD, true, true, EvenDblSpc, 2, 2 },
130 { ARM::VLD2d16Pseudo, ARM::VLD2d16, true, false, SingleSpc, 2, 4 },
131 { ARM::VLD2d16Pseudo_UPD, ARM::VLD2d16_UPD, true, true, SingleSpc, 2, 4 },
132 { ARM::VLD2d32Pseudo, ARM::VLD2d32, true, false, SingleSpc, 2, 2 },
133 { ARM::VLD2d32Pseudo_UPD, ARM::VLD2d32_UPD, true, true, SingleSpc, 2, 2 },
134 { ARM::VLD2d8Pseudo, ARM::VLD2d8, true, false, SingleSpc, 2, 8 },
135 { ARM::VLD2d8Pseudo_UPD, ARM::VLD2d8_UPD, true, true, SingleSpc, 2, 8 },
137 { ARM::VLD2q16Pseudo, ARM::VLD2q16, true, false, SingleSpc, 4, 4 },
138 { ARM::VLD2q16Pseudo_UPD, ARM::VLD2q16_UPD, true, true, SingleSpc, 4, 4 },
139 { ARM::VLD2q32Pseudo, ARM::VLD2q32, true, false, SingleSpc, 4, 2 },
140 { ARM::VLD2q32Pseudo_UPD, ARM::VLD2q32_UPD, true, true, SingleSpc, 4, 2 },
141 { ARM::VLD2q8Pseudo, ARM::VLD2q8, true, false, SingleSpc, 4, 8 },
142 { ARM::VLD2q8Pseudo_UPD, ARM::VLD2q8_UPD, true, true, SingleSpc, 4, 8 },
144 { ARM::VLD3LNd16Pseudo, ARM::VLD3LNd16, true, false, SingleSpc, 3, 4 },
145 { ARM::VLD3LNd16Pseudo_UPD, ARM::VLD3LNd16_UPD, true, true, SingleSpc, 3, 4 },
146 { ARM::VLD3LNd32Pseudo, ARM::VLD3LNd32, true, false, SingleSpc, 3, 2 },
147 { ARM::VLD3LNd32Pseudo_UPD, ARM::VLD3LNd32_UPD, true, true, SingleSpc, 3, 2 },
148 { ARM::VLD3LNd8Pseudo, ARM::VLD3LNd8, true, false, SingleSpc, 3, 8 },
149 { ARM::VLD3LNd8Pseudo_UPD, ARM::VLD3LNd8_UPD, true, true, SingleSpc, 3, 8 },
150 { ARM::VLD3LNq16Pseudo, ARM::VLD3LNq16, true, false, EvenDblSpc, 3, 4 },
151 { ARM::VLD3LNq16Pseudo_UPD, ARM::VLD3LNq16_UPD, true, true, EvenDblSpc, 3, 4 },
152 { ARM::VLD3LNq32Pseudo, ARM::VLD3LNq32, true, false, EvenDblSpc, 3, 2 },
153 { ARM::VLD3LNq32Pseudo_UPD, ARM::VLD3LNq32_UPD, true, true, EvenDblSpc, 3, 2 },
155 { ARM::VLD3d16Pseudo, ARM::VLD3d16, true, false, SingleSpc, 3, 4 },
156 { ARM::VLD3d16Pseudo_UPD, ARM::VLD3d16_UPD, true, true, SingleSpc, 3, 4 },
157 { ARM::VLD3d32Pseudo, ARM::VLD3d32, true, false, SingleSpc, 3, 2 },
158 { ARM::VLD3d32Pseudo_UPD, ARM::VLD3d32_UPD, true, true, SingleSpc, 3, 2 },
159 { ARM::VLD3d8Pseudo, ARM::VLD3d8, true, false, SingleSpc, 3, 8 },
160 { ARM::VLD3d8Pseudo_UPD, ARM::VLD3d8_UPD, true, true, SingleSpc, 3, 8 },
162 { ARM::VLD3q16Pseudo_UPD, ARM::VLD3q16_UPD, true, true, EvenDblSpc, 3, 4 },
163 { ARM::VLD3q16oddPseudo_UPD, ARM::VLD3q16_UPD, true, true, OddDblSpc, 3, 4 },
164 { ARM::VLD3q32Pseudo_UPD, ARM::VLD3q32_UPD, true, true, EvenDblSpc, 3, 2 },
165 { ARM::VLD3q32oddPseudo_UPD, ARM::VLD3q32_UPD, true, true, OddDblSpc, 3, 2 },
166 { ARM::VLD3q8Pseudo_UPD, ARM::VLD3q8_UPD, true, true, EvenDblSpc, 3, 8 },
167 { ARM::VLD3q8oddPseudo_UPD, ARM::VLD3q8_UPD, true, true, OddDblSpc, 3, 8 },
169 { ARM::VLD4LNd16Pseudo, ARM::VLD4LNd16, true, false, SingleSpc, 4, 4 },
170 { ARM::VLD4LNd16Pseudo_UPD, ARM::VLD4LNd16_UPD, true, true, SingleSpc, 4, 4 },
171 { ARM::VLD4LNd32Pseudo, ARM::VLD4LNd32, true, false, SingleSpc, 4, 2 },
172 { ARM::VLD4LNd32Pseudo_UPD, ARM::VLD4LNd32_UPD, true, true, SingleSpc, 4, 2 },
173 { ARM::VLD4LNd8Pseudo, ARM::VLD4LNd8, true, false, SingleSpc, 4, 8 },
174 { ARM::VLD4LNd8Pseudo_UPD, ARM::VLD4LNd8_UPD, true, true, SingleSpc, 4, 8 },
175 { ARM::VLD4LNq16Pseudo, ARM::VLD4LNq16, true, false, EvenDblSpc, 4, 4 },
176 { ARM::VLD4LNq16Pseudo_UPD, ARM::VLD4LNq16_UPD, true, true, EvenDblSpc, 4, 4 },
177 { ARM::VLD4LNq32Pseudo, ARM::VLD4LNq32, true, false, EvenDblSpc, 4, 2 },
178 { ARM::VLD4LNq32Pseudo_UPD, ARM::VLD4LNq32_UPD, true, true, EvenDblSpc, 4, 2 },
180 { ARM::VLD4d16Pseudo, ARM::VLD4d16, true, false, SingleSpc, 4, 4 },
181 { ARM::VLD4d16Pseudo_UPD, ARM::VLD4d16_UPD, true, true, SingleSpc, 4, 4 },
182 { ARM::VLD4d32Pseudo, ARM::VLD4d32, true, false, SingleSpc, 4, 2 },
183 { ARM::VLD4d32Pseudo_UPD, ARM::VLD4d32_UPD, true, true, SingleSpc, 4, 2 },
184 { ARM::VLD4d8Pseudo, ARM::VLD4d8, true, false, SingleSpc, 4, 8 },
185 { ARM::VLD4d8Pseudo_UPD, ARM::VLD4d8_UPD, true, true, SingleSpc, 4, 8 },
187 { ARM::VLD4q16Pseudo_UPD, ARM::VLD4q16_UPD, true, true, EvenDblSpc, 4, 4 },
188 { ARM::VLD4q16oddPseudo_UPD, ARM::VLD4q16_UPD, true, true, OddDblSpc, 4, 4 },
189 { ARM::VLD4q32Pseudo_UPD, ARM::VLD4q32_UPD, true, true, EvenDblSpc, 4, 2 },
190 { ARM::VLD4q32oddPseudo_UPD, ARM::VLD4q32_UPD, true, true, OddDblSpc, 4, 2 },
191 { ARM::VLD4q8Pseudo_UPD, ARM::VLD4q8_UPD, true, true, EvenDblSpc, 4, 8 },
192 { ARM::VLD4q8oddPseudo_UPD, ARM::VLD4q8_UPD, true, true, OddDblSpc, 4, 8 },
194 { ARM::VST1d64QPseudo, ARM::VST1d64Q, false, false, SingleSpc, 4, 1 },
195 { ARM::VST1d64QPseudo_UPD, ARM::VST1d64Q_UPD, false, true, SingleSpc, 4, 1 },
196 { ARM::VST1d64TPseudo, ARM::VST1d64T, false, false, SingleSpc, 3, 1 },
197 { ARM::VST1d64TPseudo_UPD, ARM::VST1d64T_UPD, false, true, SingleSpc, 3, 1 },
199 { ARM::VST1q16Pseudo, ARM::VST1q16, false, false, SingleSpc, 2, 4 },
200 { ARM::VST1q16Pseudo_UPD, ARM::VST1q16_UPD, false, true, SingleSpc, 2, 4 },
201 { ARM::VST1q32Pseudo, ARM::VST1q32, false, false, SingleSpc, 2, 2 },
202 { ARM::VST1q32Pseudo_UPD, ARM::VST1q32_UPD, false, true, SingleSpc, 2, 2 },
203 { ARM::VST1q64Pseudo, ARM::VST1q64, false, false, SingleSpc, 2, 1 },
204 { ARM::VST1q64Pseudo_UPD, ARM::VST1q64_UPD, false, true, SingleSpc, 2, 1 },
205 { ARM::VST1q8Pseudo, ARM::VST1q8, false, false, SingleSpc, 2, 8 },
206 { ARM::VST1q8Pseudo_UPD, ARM::VST1q8_UPD, false, true, SingleSpc, 2, 8 },
208 { ARM::VST2LNd16Pseudo, ARM::VST2LNd16, false, false, SingleSpc, 2, 4 },
209 { ARM::VST2LNd16Pseudo_UPD, ARM::VST2LNd16_UPD, false, true, SingleSpc, 2, 4 },
210 { ARM::VST2LNd32Pseudo, ARM::VST2LNd32, false, false, SingleSpc, 2, 2 },
211 { ARM::VST2LNd32Pseudo_UPD, ARM::VST2LNd32_UPD, false, true, SingleSpc, 2, 2 },
212 { ARM::VST2LNd8Pseudo, ARM::VST2LNd8, false, false, SingleSpc, 2, 8 },
213 { ARM::VST2LNd8Pseudo_UPD, ARM::VST2LNd8_UPD, false, true, SingleSpc, 2, 8 },
214 { ARM::VST2LNq16Pseudo, ARM::VST2LNq16, false, false, EvenDblSpc, 2, 4},
215 { ARM::VST2LNq16Pseudo_UPD, ARM::VST2LNq16_UPD, false, true, EvenDblSpc, 2, 4},
216 { ARM::VST2LNq32Pseudo, ARM::VST2LNq32, false, false, EvenDblSpc, 2, 2},
217 { ARM::VST2LNq32Pseudo_UPD, ARM::VST2LNq32_UPD, false, true, EvenDblSpc, 2, 2},
219 { ARM::VST2d16Pseudo, ARM::VST2d16, false, false, SingleSpc, 2, 4 },
220 { ARM::VST2d16Pseudo_UPD, ARM::VST2d16_UPD, false, true, SingleSpc, 2, 4 },
221 { ARM::VST2d32Pseudo, ARM::VST2d32, false, false, SingleSpc, 2, 2 },
222 { ARM::VST2d32Pseudo_UPD, ARM::VST2d32_UPD, false, true, SingleSpc, 2, 2 },
223 { ARM::VST2d8Pseudo, ARM::VST2d8, false, false, SingleSpc, 2, 8 },
224 { ARM::VST2d8Pseudo_UPD, ARM::VST2d8_UPD, false, true, SingleSpc, 2, 8 },
226 { ARM::VST2q16Pseudo, ARM::VST2q16, false, false, SingleSpc, 4, 4 },
227 { ARM::VST2q16Pseudo_UPD, ARM::VST2q16_UPD, false, true, SingleSpc, 4, 4 },
228 { ARM::VST2q32Pseudo, ARM::VST2q32, false, false, SingleSpc, 4, 2 },
229 { ARM::VST2q32Pseudo_UPD, ARM::VST2q32_UPD, false, true, SingleSpc, 4, 2 },
230 { ARM::VST2q8Pseudo, ARM::VST2q8, false, false, SingleSpc, 4, 8 },
231 { ARM::VST2q8Pseudo_UPD, ARM::VST2q8_UPD, false, true, SingleSpc, 4, 8 },
233 { ARM::VST3LNd16Pseudo, ARM::VST3LNd16, false, false, SingleSpc, 3, 4 },
234 { ARM::VST3LNd16Pseudo_UPD, ARM::VST3LNd16_UPD, false, true, SingleSpc, 3, 4 },
235 { ARM::VST3LNd32Pseudo, ARM::VST3LNd32, false, false, SingleSpc, 3, 2 },
236 { ARM::VST3LNd32Pseudo_UPD, ARM::VST3LNd32_UPD, false, true, SingleSpc, 3, 2 },
237 { ARM::VST3LNd8Pseudo, ARM::VST3LNd8, false, false, SingleSpc, 3, 8 },
238 { ARM::VST3LNd8Pseudo_UPD, ARM::VST3LNd8_UPD, false, true, SingleSpc, 3, 8 },
239 { ARM::VST3LNq16Pseudo, ARM::VST3LNq16, false, false, EvenDblSpc, 3, 4},
240 { ARM::VST3LNq16Pseudo_UPD, ARM::VST3LNq16_UPD, false, true, EvenDblSpc, 3, 4},
241 { ARM::VST3LNq32Pseudo, ARM::VST3LNq32, false, false, EvenDblSpc, 3, 2},
242 { ARM::VST3LNq32Pseudo_UPD, ARM::VST3LNq32_UPD, false, true, EvenDblSpc, 3, 2},
244 { ARM::VST3d16Pseudo, ARM::VST3d16, false, false, SingleSpc, 3, 4 },
245 { ARM::VST3d16Pseudo_UPD, ARM::VST3d16_UPD, false, true, SingleSpc, 3, 4 },
246 { ARM::VST3d32Pseudo, ARM::VST3d32, false, false, SingleSpc, 3, 2 },
247 { ARM::VST3d32Pseudo_UPD, ARM::VST3d32_UPD, false, true, SingleSpc, 3, 2 },
248 { ARM::VST3d8Pseudo, ARM::VST3d8, false, false, SingleSpc, 3, 8 },
249 { ARM::VST3d8Pseudo_UPD, ARM::VST3d8_UPD, false, true, SingleSpc, 3, 8 },
251 { ARM::VST3q16Pseudo_UPD, ARM::VST3q16_UPD, false, true, EvenDblSpc, 3, 4 },
252 { ARM::VST3q16oddPseudo_UPD, ARM::VST3q16_UPD, false, true, OddDblSpc, 3, 4 },
253 { ARM::VST3q32Pseudo_UPD, ARM::VST3q32_UPD, false, true, EvenDblSpc, 3, 2 },
254 { ARM::VST3q32oddPseudo_UPD, ARM::VST3q32_UPD, false, true, OddDblSpc, 3, 2 },
255 { ARM::VST3q8Pseudo_UPD, ARM::VST3q8_UPD, false, true, EvenDblSpc, 3, 8 },
256 { ARM::VST3q8oddPseudo_UPD, ARM::VST3q8_UPD, false, true, OddDblSpc, 3, 8 },
258 { ARM::VST4LNd16Pseudo, ARM::VST4LNd16, false, false, SingleSpc, 4, 4 },
259 { ARM::VST4LNd16Pseudo_UPD, ARM::VST4LNd16_UPD, false, true, SingleSpc, 4, 4 },
260 { ARM::VST4LNd32Pseudo, ARM::VST4LNd32, false, false, SingleSpc, 4, 2 },
261 { ARM::VST4LNd32Pseudo_UPD, ARM::VST4LNd32_UPD, false, true, SingleSpc, 4, 2 },
262 { ARM::VST4LNd8Pseudo, ARM::VST4LNd8, false, false, SingleSpc, 4, 8 },
263 { ARM::VST4LNd8Pseudo_UPD, ARM::VST4LNd8_UPD, false, true, SingleSpc, 4, 8 },
264 { ARM::VST4LNq16Pseudo, ARM::VST4LNq16, false, false, EvenDblSpc, 4, 4},
265 { ARM::VST4LNq16Pseudo_UPD, ARM::VST4LNq16_UPD, false, true, EvenDblSpc, 4, 4},
266 { ARM::VST4LNq32Pseudo, ARM::VST4LNq32, false, false, EvenDblSpc, 4, 2},
267 { ARM::VST4LNq32Pseudo_UPD, ARM::VST4LNq32_UPD, false, true, EvenDblSpc, 4, 2},
269 { ARM::VST4d16Pseudo, ARM::VST4d16, false, false, SingleSpc, 4, 4 },
270 { ARM::VST4d16Pseudo_UPD, ARM::VST4d16_UPD, false, true, SingleSpc, 4, 4 },
271 { ARM::VST4d32Pseudo, ARM::VST4d32, false, false, SingleSpc, 4, 2 },
272 { ARM::VST4d32Pseudo_UPD, ARM::VST4d32_UPD, false, true, SingleSpc, 4, 2 },
273 { ARM::VST4d8Pseudo, ARM::VST4d8, false, false, SingleSpc, 4, 8 },
274 { ARM::VST4d8Pseudo_UPD, ARM::VST4d8_UPD, false, true, SingleSpc, 4, 8 },
276 { ARM::VST4q16Pseudo_UPD, ARM::VST4q16_UPD, false, true, EvenDblSpc, 4, 4 },
277 { ARM::VST4q16oddPseudo_UPD, ARM::VST4q16_UPD, false, true, OddDblSpc, 4, 4 },
278 { ARM::VST4q32Pseudo_UPD, ARM::VST4q32_UPD, false, true, EvenDblSpc, 4, 2 },
279 { ARM::VST4q32oddPseudo_UPD, ARM::VST4q32_UPD, false, true, OddDblSpc, 4, 2 },
280 { ARM::VST4q8Pseudo_UPD, ARM::VST4q8_UPD, false, true, EvenDblSpc, 4, 8 },
281 { ARM::VST4q8oddPseudo_UPD , ARM::VST4q8_UPD, false, true, OddDblSpc, 4, 8 }
284 /// LookupNEONLdSt - Search the NEONLdStTable for information about a NEON
285 /// load or store pseudo instruction.
286 static const NEONLdStTableEntry *LookupNEONLdSt(unsigned Opcode) {
287 unsigned NumEntries = array_lengthof(NEONLdStTable);
290 // Make sure the table is sorted.
291 static bool TableChecked = false;
293 for (unsigned i = 0; i != NumEntries-1; ++i)
294 assert(NEONLdStTable[i] < NEONLdStTable[i+1] &&
295 "NEONLdStTable is not sorted!");
300 const NEONLdStTableEntry *I =
301 std::lower_bound(NEONLdStTable, NEONLdStTable + NumEntries, Opcode);
302 if (I != NEONLdStTable + NumEntries && I->PseudoOpc == Opcode)
307 /// GetDSubRegs - Get 4 D subregisters of a Q, QQ, or QQQQ register,
308 /// corresponding to the specified register spacing. Not all of the results
309 /// are necessarily valid, e.g., a Q register only has 2 D subregisters.
310 static void GetDSubRegs(unsigned Reg, NEONRegSpacing RegSpc,
311 const TargetRegisterInfo *TRI, unsigned &D0,
312 unsigned &D1, unsigned &D2, unsigned &D3) {
313 if (RegSpc == SingleSpc) {
314 D0 = TRI->getSubReg(Reg, ARM::dsub_0);
315 D1 = TRI->getSubReg(Reg, ARM::dsub_1);
316 D2 = TRI->getSubReg(Reg, ARM::dsub_2);
317 D3 = TRI->getSubReg(Reg, ARM::dsub_3);
318 } else if (RegSpc == EvenDblSpc) {
319 D0 = TRI->getSubReg(Reg, ARM::dsub_0);
320 D1 = TRI->getSubReg(Reg, ARM::dsub_2);
321 D2 = TRI->getSubReg(Reg, ARM::dsub_4);
322 D3 = TRI->getSubReg(Reg, ARM::dsub_6);
324 assert(RegSpc == OddDblSpc && "unknown register spacing");
325 D0 = TRI->getSubReg(Reg, ARM::dsub_1);
326 D1 = TRI->getSubReg(Reg, ARM::dsub_3);
327 D2 = TRI->getSubReg(Reg, ARM::dsub_5);
328 D3 = TRI->getSubReg(Reg, ARM::dsub_7);
332 /// ExpandVLD - Translate VLD pseudo instructions with Q, QQ or QQQQ register
333 /// operands to real VLD instructions with D register operands.
334 void ARMExpandPseudo::ExpandVLD(MachineBasicBlock::iterator &MBBI) {
335 MachineInstr &MI = *MBBI;
336 MachineBasicBlock &MBB = *MI.getParent();
338 const NEONLdStTableEntry *TableEntry = LookupNEONLdSt(MI.getOpcode());
339 assert(TableEntry && TableEntry->IsLoad && "NEONLdStTable lookup failed");
340 NEONRegSpacing RegSpc = TableEntry->RegSpacing;
341 unsigned NumRegs = TableEntry->NumRegs;
343 MachineInstrBuilder MIB = BuildMI(MBB, MBBI, MI.getDebugLoc(),
344 TII->get(TableEntry->RealOpc));
347 bool DstIsDead = MI.getOperand(OpIdx).isDead();
348 unsigned DstReg = MI.getOperand(OpIdx++).getReg();
349 unsigned D0, D1, D2, D3;
350 GetDSubRegs(DstReg, RegSpc, TRI, D0, D1, D2, D3);
351 MIB.addReg(D0, RegState::Define | getDeadRegState(DstIsDead))
352 .addReg(D1, RegState::Define | getDeadRegState(DstIsDead));
354 MIB.addReg(D2, RegState::Define | getDeadRegState(DstIsDead));
356 MIB.addReg(D3, RegState::Define | getDeadRegState(DstIsDead));
358 if (TableEntry->HasWriteBack)
359 MIB.addOperand(MI.getOperand(OpIdx++));
361 // Copy the addrmode6 operands.
362 MIB.addOperand(MI.getOperand(OpIdx++));
363 MIB.addOperand(MI.getOperand(OpIdx++));
364 // Copy the am6offset operand.
365 if (TableEntry->HasWriteBack)
366 MIB.addOperand(MI.getOperand(OpIdx++));
368 MIB = AddDefaultPred(MIB);
369 // For an instruction writing double-spaced subregs, the pseudo instruction
370 // has an extra operand that is a use of the super-register. Copy that over
371 // to the new instruction as an implicit operand.
372 if (RegSpc == EvenDblSpc || RegSpc == OddDblSpc) {
373 MachineOperand MO = MI.getOperand(OpIdx);
374 MO.setImplicit(true);
377 // Add an implicit def for the super-register.
378 MIB.addReg(DstReg, RegState::ImplicitDefine | getDeadRegState(DstIsDead));
379 TransferImpOps(MI, MIB, MIB);
380 MI.eraseFromParent();
383 /// ExpandVST - Translate VST pseudo instructions with Q, QQ or QQQQ register
384 /// operands to real VST instructions with D register operands.
385 void ARMExpandPseudo::ExpandVST(MachineBasicBlock::iterator &MBBI) {
386 MachineInstr &MI = *MBBI;
387 MachineBasicBlock &MBB = *MI.getParent();
389 const NEONLdStTableEntry *TableEntry = LookupNEONLdSt(MI.getOpcode());
390 assert(TableEntry && !TableEntry->IsLoad && "NEONLdStTable lookup failed");
391 NEONRegSpacing RegSpc = TableEntry->RegSpacing;
392 unsigned NumRegs = TableEntry->NumRegs;
394 MachineInstrBuilder MIB = BuildMI(MBB, MBBI, MI.getDebugLoc(),
395 TII->get(TableEntry->RealOpc));
397 if (TableEntry->HasWriteBack)
398 MIB.addOperand(MI.getOperand(OpIdx++));
400 // Copy the addrmode6 operands.
401 MIB.addOperand(MI.getOperand(OpIdx++));
402 MIB.addOperand(MI.getOperand(OpIdx++));
403 // Copy the am6offset operand.
404 if (TableEntry->HasWriteBack)
405 MIB.addOperand(MI.getOperand(OpIdx++));
407 bool SrcIsKill = MI.getOperand(OpIdx).isKill();
408 unsigned SrcReg = MI.getOperand(OpIdx).getReg();
409 unsigned D0, D1, D2, D3;
410 GetDSubRegs(SrcReg, RegSpc, TRI, D0, D1, D2, D3);
411 MIB.addReg(D0).addReg(D1);
416 MIB = AddDefaultPred(MIB);
417 TransferImpOps(MI, MIB, MIB);
419 // Add an implicit kill for the super-reg.
420 (*MIB).addRegisterKilled(SrcReg, TRI, true);
421 MI.eraseFromParent();
424 /// ExpandLaneOp - Translate VLD*LN and VST*LN instructions with Q, QQ or QQQQ
425 /// register operands to real instructions with D register operands.
426 void ARMExpandPseudo::ExpandLaneOp(MachineBasicBlock::iterator &MBBI) {
427 MachineInstr &MI = *MBBI;
428 MachineBasicBlock &MBB = *MI.getParent();
430 const NEONLdStTableEntry *TableEntry = LookupNEONLdSt(MI.getOpcode());
431 assert(TableEntry && "NEONLdStTable lookup failed");
432 NEONRegSpacing RegSpc = TableEntry->RegSpacing;
433 unsigned NumRegs = TableEntry->NumRegs;
434 unsigned RegElts = TableEntry->RegElts;
436 MachineInstrBuilder MIB = BuildMI(MBB, MBBI, MI.getDebugLoc(),
437 TII->get(TableEntry->RealOpc));
439 // The lane operand is always the 3rd from last operand, before the 2
440 // predicate operands.
441 unsigned Lane = MI.getOperand(MI.getDesc().getNumOperands() - 3).getImm();
443 // Adjust the lane and spacing as needed for Q registers.
444 assert(RegSpc != OddDblSpc && "unexpected register spacing for VLD/VST-lane");
445 if (RegSpc == EvenDblSpc && Lane >= RegElts) {
449 assert(Lane < RegElts && "out of range lane for VLD/VST-lane");
451 unsigned DstReg, D0, D1, D2, D3;
453 if (TableEntry->IsLoad) {
454 DstIsDead = MI.getOperand(OpIdx).isDead();
455 DstReg = MI.getOperand(OpIdx++).getReg();
456 GetDSubRegs(DstReg, RegSpc, TRI, D0, D1, D2, D3);
457 MIB.addReg(D0, RegState::Define | getDeadRegState(DstIsDead))
458 .addReg(D1, RegState::Define | getDeadRegState(DstIsDead));
460 MIB.addReg(D2, RegState::Define | getDeadRegState(DstIsDead));
462 MIB.addReg(D3, RegState::Define | getDeadRegState(DstIsDead));
465 if (TableEntry->HasWriteBack)
466 MIB.addOperand(MI.getOperand(OpIdx++));
468 // Copy the addrmode6 operands.
469 MIB.addOperand(MI.getOperand(OpIdx++));
470 MIB.addOperand(MI.getOperand(OpIdx++));
471 // Copy the am6offset operand.
472 if (TableEntry->HasWriteBack)
473 MIB.addOperand(MI.getOperand(OpIdx++));
475 // Grab the super-register source.
476 MachineOperand MO = MI.getOperand(OpIdx++);
477 if (!TableEntry->IsLoad)
478 GetDSubRegs(MO.getReg(), RegSpc, TRI, D0, D1, D2, D3);
480 // Add the subregs as sources of the new instruction.
481 unsigned SrcFlags = (getUndefRegState(MO.isUndef()) |
482 getKillRegState(MO.isKill()));
483 MIB.addReg(D0, SrcFlags).addReg(D1, SrcFlags);
485 MIB.addReg(D2, SrcFlags);
487 MIB.addReg(D3, SrcFlags);
489 // Add the lane number operand.
492 MIB = AddDefaultPred(MIB);
493 // Copy the super-register source to be an implicit source.
494 MO.setImplicit(true);
496 if (TableEntry->IsLoad)
497 // Add an implicit def for the super-register.
498 MIB.addReg(DstReg, RegState::ImplicitDefine | getDeadRegState(DstIsDead));
499 TransferImpOps(MI, MIB, MIB);
500 MI.eraseFromParent();
503 bool ARMExpandPseudo::ExpandMBB(MachineBasicBlock &MBB) {
504 bool Modified = false;
506 MachineBasicBlock::iterator MBBI = MBB.begin(), E = MBB.end();
508 MachineInstr &MI = *MBBI;
509 MachineBasicBlock::iterator NMBBI = llvm::next(MBBI);
511 bool ModifiedOp = true;
512 unsigned Opcode = MI.getOpcode();
518 case ARM::tLDRpci_pic:
519 case ARM::t2LDRpci_pic: {
520 unsigned NewLdOpc = (Opcode == ARM::tLDRpci_pic)
521 ? ARM::tLDRpci : ARM::t2LDRpci;
522 unsigned DstReg = MI.getOperand(0).getReg();
523 bool DstIsDead = MI.getOperand(0).isDead();
524 MachineInstrBuilder MIB1 =
525 AddDefaultPred(BuildMI(MBB, MBBI, MI.getDebugLoc(),
526 TII->get(NewLdOpc), DstReg)
527 .addOperand(MI.getOperand(1)));
528 (*MIB1).setMemRefs(MI.memoperands_begin(), MI.memoperands_end());
529 MachineInstrBuilder MIB2 = BuildMI(MBB, MBBI, MI.getDebugLoc(),
530 TII->get(ARM::tPICADD))
531 .addReg(DstReg, getDefRegState(true) | getDeadRegState(DstIsDead))
533 .addOperand(MI.getOperand(2));
534 TransferImpOps(MI, MIB1, MIB2);
535 MI.eraseFromParent();
540 case ARM::t2MOVi32imm: {
541 unsigned PredReg = 0;
542 ARMCC::CondCodes Pred = llvm::getInstrPredicate(&MI, PredReg);
543 unsigned DstReg = MI.getOperand(0).getReg();
544 bool DstIsDead = MI.getOperand(0).isDead();
545 const MachineOperand &MO = MI.getOperand(1);
546 MachineInstrBuilder LO16, HI16;
548 LO16 = BuildMI(MBB, MBBI, MI.getDebugLoc(),
549 TII->get(Opcode == ARM::MOVi32imm ?
550 ARM::MOVi16 : ARM::t2MOVi16),
552 HI16 = BuildMI(MBB, MBBI, MI.getDebugLoc(),
553 TII->get(Opcode == ARM::MOVi32imm ?
554 ARM::MOVTi16 : ARM::t2MOVTi16))
555 .addReg(DstReg, getDefRegState(true) | getDeadRegState(DstIsDead))
559 unsigned Imm = MO.getImm();
560 unsigned Lo16 = Imm & 0xffff;
561 unsigned Hi16 = (Imm >> 16) & 0xffff;
562 LO16 = LO16.addImm(Lo16);
563 HI16 = HI16.addImm(Hi16);
565 const GlobalValue *GV = MO.getGlobal();
566 unsigned TF = MO.getTargetFlags();
567 LO16 = LO16.addGlobalAddress(GV, MO.getOffset(), TF | ARMII::MO_LO16);
568 HI16 = HI16.addGlobalAddress(GV, MO.getOffset(), TF | ARMII::MO_HI16);
570 (*LO16).setMemRefs(MI.memoperands_begin(), MI.memoperands_end());
571 (*HI16).setMemRefs(MI.memoperands_begin(), MI.memoperands_end());
572 LO16.addImm(Pred).addReg(PredReg);
573 HI16.addImm(Pred).addReg(PredReg);
574 TransferImpOps(MI, LO16, HI16);
575 MI.eraseFromParent();
580 unsigned DstReg = MI.getOperand(0).getReg();
581 bool DstIsDead = MI.getOperand(0).isDead();
582 unsigned EvenDst = TRI->getSubReg(DstReg, ARM::qsub_0);
583 unsigned OddDst = TRI->getSubReg(DstReg, ARM::qsub_1);
584 unsigned SrcReg = MI.getOperand(1).getReg();
585 bool SrcIsKill = MI.getOperand(1).isKill();
586 unsigned EvenSrc = TRI->getSubReg(SrcReg, ARM::qsub_0);
587 unsigned OddSrc = TRI->getSubReg(SrcReg, ARM::qsub_1);
588 MachineInstrBuilder Even =
589 AddDefaultPred(BuildMI(MBB, MBBI, MI.getDebugLoc(),
590 TII->get(ARM::VMOVQ))
592 getDefRegState(true) | getDeadRegState(DstIsDead))
593 .addReg(EvenSrc, getKillRegState(SrcIsKill)));
594 MachineInstrBuilder Odd =
595 AddDefaultPred(BuildMI(MBB, MBBI, MI.getDebugLoc(),
596 TII->get(ARM::VMOVQ))
598 getDefRegState(true) | getDeadRegState(DstIsDead))
599 .addReg(OddSrc, getKillRegState(SrcIsKill)));
600 TransferImpOps(MI, Even, Odd);
601 MI.eraseFromParent();
604 case ARM::VLD1q8Pseudo:
605 case ARM::VLD1q16Pseudo:
606 case ARM::VLD1q32Pseudo:
607 case ARM::VLD1q64Pseudo:
608 case ARM::VLD1q8Pseudo_UPD:
609 case ARM::VLD1q16Pseudo_UPD:
610 case ARM::VLD1q32Pseudo_UPD:
611 case ARM::VLD1q64Pseudo_UPD:
612 case ARM::VLD2d8Pseudo:
613 case ARM::VLD2d16Pseudo:
614 case ARM::VLD2d32Pseudo:
615 case ARM::VLD2q8Pseudo:
616 case ARM::VLD2q16Pseudo:
617 case ARM::VLD2q32Pseudo:
618 case ARM::VLD2d8Pseudo_UPD:
619 case ARM::VLD2d16Pseudo_UPD:
620 case ARM::VLD2d32Pseudo_UPD:
621 case ARM::VLD2q8Pseudo_UPD:
622 case ARM::VLD2q16Pseudo_UPD:
623 case ARM::VLD2q32Pseudo_UPD:
624 case ARM::VLD3d8Pseudo:
625 case ARM::VLD3d16Pseudo:
626 case ARM::VLD3d32Pseudo:
627 case ARM::VLD1d64TPseudo:
628 case ARM::VLD3d8Pseudo_UPD:
629 case ARM::VLD3d16Pseudo_UPD:
630 case ARM::VLD3d32Pseudo_UPD:
631 case ARM::VLD1d64TPseudo_UPD:
632 case ARM::VLD3q8Pseudo_UPD:
633 case ARM::VLD3q16Pseudo_UPD:
634 case ARM::VLD3q32Pseudo_UPD:
635 case ARM::VLD3q8oddPseudo_UPD:
636 case ARM::VLD3q16oddPseudo_UPD:
637 case ARM::VLD3q32oddPseudo_UPD:
638 case ARM::VLD4d8Pseudo:
639 case ARM::VLD4d16Pseudo:
640 case ARM::VLD4d32Pseudo:
641 case ARM::VLD1d64QPseudo:
642 case ARM::VLD4d8Pseudo_UPD:
643 case ARM::VLD4d16Pseudo_UPD:
644 case ARM::VLD4d32Pseudo_UPD:
645 case ARM::VLD1d64QPseudo_UPD:
646 case ARM::VLD4q8Pseudo_UPD:
647 case ARM::VLD4q16Pseudo_UPD:
648 case ARM::VLD4q32Pseudo_UPD:
649 case ARM::VLD4q8oddPseudo_UPD:
650 case ARM::VLD4q16oddPseudo_UPD:
651 case ARM::VLD4q32oddPseudo_UPD:
655 case ARM::VST1q8Pseudo:
656 case ARM::VST1q16Pseudo:
657 case ARM::VST1q32Pseudo:
658 case ARM::VST1q64Pseudo:
659 case ARM::VST1q8Pseudo_UPD:
660 case ARM::VST1q16Pseudo_UPD:
661 case ARM::VST1q32Pseudo_UPD:
662 case ARM::VST1q64Pseudo_UPD:
663 case ARM::VST2d8Pseudo:
664 case ARM::VST2d16Pseudo:
665 case ARM::VST2d32Pseudo:
666 case ARM::VST2q8Pseudo:
667 case ARM::VST2q16Pseudo:
668 case ARM::VST2q32Pseudo:
669 case ARM::VST2d8Pseudo_UPD:
670 case ARM::VST2d16Pseudo_UPD:
671 case ARM::VST2d32Pseudo_UPD:
672 case ARM::VST2q8Pseudo_UPD:
673 case ARM::VST2q16Pseudo_UPD:
674 case ARM::VST2q32Pseudo_UPD:
675 case ARM::VST3d8Pseudo:
676 case ARM::VST3d16Pseudo:
677 case ARM::VST3d32Pseudo:
678 case ARM::VST1d64TPseudo:
679 case ARM::VST3d8Pseudo_UPD:
680 case ARM::VST3d16Pseudo_UPD:
681 case ARM::VST3d32Pseudo_UPD:
682 case ARM::VST1d64TPseudo_UPD:
683 case ARM::VST3q8Pseudo_UPD:
684 case ARM::VST3q16Pseudo_UPD:
685 case ARM::VST3q32Pseudo_UPD:
686 case ARM::VST3q8oddPseudo_UPD:
687 case ARM::VST3q16oddPseudo_UPD:
688 case ARM::VST3q32oddPseudo_UPD:
689 case ARM::VST4d8Pseudo:
690 case ARM::VST4d16Pseudo:
691 case ARM::VST4d32Pseudo:
692 case ARM::VST1d64QPseudo:
693 case ARM::VST4d8Pseudo_UPD:
694 case ARM::VST4d16Pseudo_UPD:
695 case ARM::VST4d32Pseudo_UPD:
696 case ARM::VST1d64QPseudo_UPD:
697 case ARM::VST4q8Pseudo_UPD:
698 case ARM::VST4q16Pseudo_UPD:
699 case ARM::VST4q32Pseudo_UPD:
700 case ARM::VST4q8oddPseudo_UPD:
701 case ARM::VST4q16oddPseudo_UPD:
702 case ARM::VST4q32oddPseudo_UPD:
706 case ARM::VLD2LNd8Pseudo:
707 case ARM::VLD2LNd16Pseudo:
708 case ARM::VLD2LNd32Pseudo:
709 case ARM::VLD2LNq16Pseudo:
710 case ARM::VLD2LNq32Pseudo:
711 case ARM::VLD2LNd8Pseudo_UPD:
712 case ARM::VLD2LNd16Pseudo_UPD:
713 case ARM::VLD2LNd32Pseudo_UPD:
714 case ARM::VLD2LNq16Pseudo_UPD:
715 case ARM::VLD2LNq32Pseudo_UPD:
716 case ARM::VLD3LNd8Pseudo:
717 case ARM::VLD3LNd16Pseudo:
718 case ARM::VLD3LNd32Pseudo:
719 case ARM::VLD3LNq16Pseudo:
720 case ARM::VLD3LNq32Pseudo:
721 case ARM::VLD3LNd8Pseudo_UPD:
722 case ARM::VLD3LNd16Pseudo_UPD:
723 case ARM::VLD3LNd32Pseudo_UPD:
724 case ARM::VLD3LNq16Pseudo_UPD:
725 case ARM::VLD3LNq32Pseudo_UPD:
726 case ARM::VLD4LNd8Pseudo:
727 case ARM::VLD4LNd16Pseudo:
728 case ARM::VLD4LNd32Pseudo:
729 case ARM::VLD4LNq16Pseudo:
730 case ARM::VLD4LNq32Pseudo:
731 case ARM::VLD4LNd8Pseudo_UPD:
732 case ARM::VLD4LNd16Pseudo_UPD:
733 case ARM::VLD4LNd32Pseudo_UPD:
734 case ARM::VLD4LNq16Pseudo_UPD:
735 case ARM::VLD4LNq32Pseudo_UPD:
736 case ARM::VST2LNd8Pseudo:
737 case ARM::VST2LNd16Pseudo:
738 case ARM::VST2LNd32Pseudo:
739 case ARM::VST2LNq16Pseudo:
740 case ARM::VST2LNq32Pseudo:
741 case ARM::VST2LNd8Pseudo_UPD:
742 case ARM::VST2LNd16Pseudo_UPD:
743 case ARM::VST2LNd32Pseudo_UPD:
744 case ARM::VST2LNq16Pseudo_UPD:
745 case ARM::VST2LNq32Pseudo_UPD:
746 case ARM::VST3LNd8Pseudo:
747 case ARM::VST3LNd16Pseudo:
748 case ARM::VST3LNd32Pseudo:
749 case ARM::VST3LNq16Pseudo:
750 case ARM::VST3LNq32Pseudo:
751 case ARM::VST3LNd8Pseudo_UPD:
752 case ARM::VST3LNd16Pseudo_UPD:
753 case ARM::VST3LNd32Pseudo_UPD:
754 case ARM::VST3LNq16Pseudo_UPD:
755 case ARM::VST3LNq32Pseudo_UPD:
756 case ARM::VST4LNd8Pseudo:
757 case ARM::VST4LNd16Pseudo:
758 case ARM::VST4LNd32Pseudo:
759 case ARM::VST4LNq16Pseudo:
760 case ARM::VST4LNq32Pseudo:
761 case ARM::VST4LNd8Pseudo_UPD:
762 case ARM::VST4LNd16Pseudo_UPD:
763 case ARM::VST4LNd32Pseudo_UPD:
764 case ARM::VST4LNq16Pseudo_UPD:
765 case ARM::VST4LNq32Pseudo_UPD:
778 bool ARMExpandPseudo::runOnMachineFunction(MachineFunction &MF) {
779 TII = MF.getTarget().getInstrInfo();
780 TRI = MF.getTarget().getRegisterInfo();
782 bool Modified = false;
783 for (MachineFunction::iterator MFI = MF.begin(), E = MF.end(); MFI != E;
785 Modified |= ExpandMBB(*MFI);
789 /// createARMExpandPseudoPass - returns an instance of the pseudo instruction
791 FunctionPass *llvm::createARMExpandPseudoPass() {
792 return new ARMExpandPseudo();