Sorry, several patches in one.
[oota-llvm.git] / lib / Target / ARM / ARMExpandPseudoInsts.cpp
1 //===-- ARMExpandPseudoInsts.cpp - Expand pseudo instructions -----*- C++ -*-=//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
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.
14 //
15 //===----------------------------------------------------------------------===//
16
17 #define DEBUG_TYPE "arm-pseudo"
18 #include "ARM.h"
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/TargetFrameLowering.h"
28 #include "llvm/Target/TargetRegisterInfo.h"
29 #include "llvm/Support/raw_ostream.h" // FIXME: for debug only. remove!
30 using namespace llvm;
31
32 namespace {
33   class ARMExpandPseudo : public MachineFunctionPass {
34   public:
35     static char ID;
36     ARMExpandPseudo() : MachineFunctionPass(ID) {}
37
38     const ARMBaseInstrInfo *TII;
39     const TargetRegisterInfo *TRI;
40     const ARMSubtarget *STI;
41     ARMFunctionInfo *AFI;
42
43     virtual bool runOnMachineFunction(MachineFunction &Fn);
44
45     virtual const char *getPassName() const {
46       return "ARM pseudo instruction expansion pass";
47     }
48
49   private:
50     void TransferImpOps(MachineInstr &OldMI,
51                         MachineInstrBuilder &UseMI, MachineInstrBuilder &DefMI);
52     bool ExpandMI(MachineBasicBlock &MBB,
53                   MachineBasicBlock::iterator MBBI);
54     bool ExpandMBB(MachineBasicBlock &MBB);
55     void ExpandVLD(MachineBasicBlock::iterator &MBBI);
56     void ExpandVST(MachineBasicBlock::iterator &MBBI);
57     void ExpandLaneOp(MachineBasicBlock::iterator &MBBI);
58     void ExpandVTBL(MachineBasicBlock::iterator &MBBI,
59                     unsigned Opc, bool IsExt, unsigned NumRegs);
60     void ExpandMOV32BitImm(MachineBasicBlock &MBB,
61                            MachineBasicBlock::iterator &MBBI);
62   };
63   char ARMExpandPseudo::ID = 0;
64 }
65
66 /// TransferImpOps - Transfer implicit operands on the pseudo instruction to
67 /// the instructions created from the expansion.
68 void ARMExpandPseudo::TransferImpOps(MachineInstr &OldMI,
69                                      MachineInstrBuilder &UseMI,
70                                      MachineInstrBuilder &DefMI) {
71   const TargetInstrDesc &Desc = OldMI.getDesc();
72   for (unsigned i = Desc.getNumOperands(), e = OldMI.getNumOperands();
73        i != e; ++i) {
74     const MachineOperand &MO = OldMI.getOperand(i);
75     assert(MO.isReg() && MO.getReg());
76     if (MO.isUse())
77       UseMI.addOperand(MO);
78     else
79       DefMI.addOperand(MO);
80   }
81 }
82
83 namespace {
84   // Constants for register spacing in NEON load/store instructions.
85   // For quad-register load-lane and store-lane pseudo instructors, the
86   // spacing is initially assumed to be EvenDblSpc, and that is changed to
87   // OddDblSpc depending on the lane number operand.
88   enum NEONRegSpacing {
89     SingleSpc,
90     EvenDblSpc,
91     OddDblSpc
92   };
93
94   // Entries for NEON load/store information table.  The table is sorted by
95   // PseudoOpc for fast binary-search lookups.
96   struct NEONLdStTableEntry {
97     unsigned PseudoOpc;
98     unsigned RealOpc;
99     bool IsLoad;
100     bool HasWriteBack;
101     NEONRegSpacing RegSpacing;
102     unsigned char NumRegs; // D registers loaded or stored
103     unsigned char RegElts; // elements per D register; used for lane ops
104
105     // Comparison methods for binary search of the table.
106     bool operator<(const NEONLdStTableEntry &TE) const {
107       return PseudoOpc < TE.PseudoOpc;
108     }
109     friend bool operator<(const NEONLdStTableEntry &TE, unsigned PseudoOpc) {
110       return TE.PseudoOpc < PseudoOpc;
111     }
112     friend bool LLVM_ATTRIBUTE_UNUSED operator<(unsigned PseudoOpc,
113                                                 const NEONLdStTableEntry &TE) {
114       return PseudoOpc < TE.PseudoOpc;
115     }
116   };
117 }
118
119 static const NEONLdStTableEntry NEONLdStTable[] = {
120 { ARM::VLD1DUPq16Pseudo,     ARM::VLD1DUPq16,     true, false, SingleSpc, 2, 4},
121 { ARM::VLD1DUPq16Pseudo_UPD, ARM::VLD1DUPq16_UPD, true, true,  SingleSpc, 2, 4},
122 { ARM::VLD1DUPq32Pseudo,     ARM::VLD1DUPq32,     true, false, SingleSpc, 2, 2},
123 { ARM::VLD1DUPq32Pseudo_UPD, ARM::VLD1DUPq32_UPD, true, true,  SingleSpc, 2, 2},
124 { ARM::VLD1DUPq8Pseudo,      ARM::VLD1DUPq8,      true, false, SingleSpc, 2, 8},
125 { ARM::VLD1DUPq8Pseudo_UPD,  ARM::VLD1DUPq8_UPD,  true, true,  SingleSpc, 2, 8},
126
127 { ARM::VLD1LNq16Pseudo,     ARM::VLD1LNd16,     true, false, EvenDblSpc, 1, 4 },
128 { ARM::VLD1LNq16Pseudo_UPD, ARM::VLD1LNd16_UPD, true, true,  EvenDblSpc, 1, 4 },
129 { ARM::VLD1LNq32Pseudo,     ARM::VLD1LNd32,     true, false, EvenDblSpc, 1, 2 },
130 { ARM::VLD1LNq32Pseudo_UPD, ARM::VLD1LNd32_UPD, true, true,  EvenDblSpc, 1, 2 },
131 { ARM::VLD1LNq8Pseudo,      ARM::VLD1LNd8,      true, false, EvenDblSpc, 1, 8 },
132 { ARM::VLD1LNq8Pseudo_UPD,  ARM::VLD1LNd8_UPD,  true, true,  EvenDblSpc, 1, 8 },
133
134 { ARM::VLD1d64QPseudo,      ARM::VLD1d64Q,     true,  false, SingleSpc,  4, 1 },
135 { ARM::VLD1d64QPseudo_UPD,  ARM::VLD1d64Q_UPD, true,  true,  SingleSpc,  4, 1 },
136 { ARM::VLD1d64TPseudo,      ARM::VLD1d64T,     true,  false, SingleSpc,  3, 1 },
137 { ARM::VLD1d64TPseudo_UPD,  ARM::VLD1d64T_UPD, true,  true,  SingleSpc,  3, 1 },
138
139 { ARM::VLD1q16Pseudo,       ARM::VLD1q16,      true,  false, SingleSpc,  2, 4 },
140 { ARM::VLD1q16Pseudo_UPD,   ARM::VLD1q16_UPD,  true,  true,  SingleSpc,  2, 4 },
141 { ARM::VLD1q32Pseudo,       ARM::VLD1q32,      true,  false, SingleSpc,  2, 2 },
142 { ARM::VLD1q32Pseudo_UPD,   ARM::VLD1q32_UPD,  true,  true,  SingleSpc,  2, 2 },
143 { ARM::VLD1q64Pseudo,       ARM::VLD1q64,      true,  false, SingleSpc,  2, 1 },
144 { ARM::VLD1q64Pseudo_UPD,   ARM::VLD1q64_UPD,  true,  true,  SingleSpc,  2, 1 },
145 { ARM::VLD1q8Pseudo,        ARM::VLD1q8,       true,  false, SingleSpc,  2, 8 },
146 { ARM::VLD1q8Pseudo_UPD,    ARM::VLD1q8_UPD,   true,  true,  SingleSpc,  2, 8 },
147
148 { ARM::VLD2DUPd16Pseudo,     ARM::VLD2DUPd16,     true, false, SingleSpc, 2, 4},
149 { ARM::VLD2DUPd16Pseudo_UPD, ARM::VLD2DUPd16_UPD, true, true,  SingleSpc, 2, 4},
150 { ARM::VLD2DUPd32Pseudo,     ARM::VLD2DUPd32,     true, false, SingleSpc, 2, 2},
151 { ARM::VLD2DUPd32Pseudo_UPD, ARM::VLD2DUPd32_UPD, true, true,  SingleSpc, 2, 2},
152 { ARM::VLD2DUPd8Pseudo,      ARM::VLD2DUPd8,      true, false, SingleSpc, 2, 8},
153 { ARM::VLD2DUPd8Pseudo_UPD,  ARM::VLD2DUPd8_UPD,  true, true,  SingleSpc, 2, 8},
154
155 { ARM::VLD2LNd16Pseudo,     ARM::VLD2LNd16,     true, false, SingleSpc,  2, 4 },
156 { ARM::VLD2LNd16Pseudo_UPD, ARM::VLD2LNd16_UPD, true, true,  SingleSpc,  2, 4 },
157 { ARM::VLD2LNd32Pseudo,     ARM::VLD2LNd32,     true, false, SingleSpc,  2, 2 },
158 { ARM::VLD2LNd32Pseudo_UPD, ARM::VLD2LNd32_UPD, true, true,  SingleSpc,  2, 2 },
159 { ARM::VLD2LNd8Pseudo,      ARM::VLD2LNd8,      true, false, SingleSpc,  2, 8 },
160 { ARM::VLD2LNd8Pseudo_UPD,  ARM::VLD2LNd8_UPD,  true, true,  SingleSpc,  2, 8 },
161 { ARM::VLD2LNq16Pseudo,     ARM::VLD2LNq16,     true, false, EvenDblSpc, 2, 4 },
162 { ARM::VLD2LNq16Pseudo_UPD, ARM::VLD2LNq16_UPD, true, true,  EvenDblSpc, 2, 4 },
163 { ARM::VLD2LNq32Pseudo,     ARM::VLD2LNq32,     true, false, EvenDblSpc, 2, 2 },
164 { ARM::VLD2LNq32Pseudo_UPD, ARM::VLD2LNq32_UPD, true, true,  EvenDblSpc, 2, 2 },
165
166 { ARM::VLD2d16Pseudo,       ARM::VLD2d16,      true,  false, SingleSpc,  2, 4 },
167 { ARM::VLD2d16Pseudo_UPD,   ARM::VLD2d16_UPD,  true,  true,  SingleSpc,  2, 4 },
168 { ARM::VLD2d32Pseudo,       ARM::VLD2d32,      true,  false, SingleSpc,  2, 2 },
169 { ARM::VLD2d32Pseudo_UPD,   ARM::VLD2d32_UPD,  true,  true,  SingleSpc,  2, 2 },
170 { ARM::VLD2d8Pseudo,        ARM::VLD2d8,       true,  false, SingleSpc,  2, 8 },
171 { ARM::VLD2d8Pseudo_UPD,    ARM::VLD2d8_UPD,   true,  true,  SingleSpc,  2, 8 },
172
173 { ARM::VLD2q16Pseudo,       ARM::VLD2q16,      true,  false, SingleSpc,  4, 4 },
174 { ARM::VLD2q16Pseudo_UPD,   ARM::VLD2q16_UPD,  true,  true,  SingleSpc,  4, 4 },
175 { ARM::VLD2q32Pseudo,       ARM::VLD2q32,      true,  false, SingleSpc,  4, 2 },
176 { ARM::VLD2q32Pseudo_UPD,   ARM::VLD2q32_UPD,  true,  true,  SingleSpc,  4, 2 },
177 { ARM::VLD2q8Pseudo,        ARM::VLD2q8,       true,  false, SingleSpc,  4, 8 },
178 { ARM::VLD2q8Pseudo_UPD,    ARM::VLD2q8_UPD,   true,  true,  SingleSpc,  4, 8 },
179
180 { ARM::VLD3DUPd16Pseudo,     ARM::VLD3DUPd16,     true, false, SingleSpc, 3, 4},
181 { ARM::VLD3DUPd16Pseudo_UPD, ARM::VLD3DUPd16_UPD, true, true,  SingleSpc, 3, 4},
182 { ARM::VLD3DUPd32Pseudo,     ARM::VLD3DUPd32,     true, false, SingleSpc, 3, 2},
183 { ARM::VLD3DUPd32Pseudo_UPD, ARM::VLD3DUPd32_UPD, true, true,  SingleSpc, 3, 2},
184 { ARM::VLD3DUPd8Pseudo,      ARM::VLD3DUPd8,      true, false, SingleSpc, 3, 8},
185 { ARM::VLD3DUPd8Pseudo_UPD,  ARM::VLD3DUPd8_UPD,  true, true,  SingleSpc, 3, 8},
186
187 { ARM::VLD3LNd16Pseudo,     ARM::VLD3LNd16,     true, false, SingleSpc,  3, 4 },
188 { ARM::VLD3LNd16Pseudo_UPD, ARM::VLD3LNd16_UPD, true, true,  SingleSpc,  3, 4 },
189 { ARM::VLD3LNd32Pseudo,     ARM::VLD3LNd32,     true, false, SingleSpc,  3, 2 },
190 { ARM::VLD3LNd32Pseudo_UPD, ARM::VLD3LNd32_UPD, true, true,  SingleSpc,  3, 2 },
191 { ARM::VLD3LNd8Pseudo,      ARM::VLD3LNd8,      true, false, SingleSpc,  3, 8 },
192 { ARM::VLD3LNd8Pseudo_UPD,  ARM::VLD3LNd8_UPD,  true, true,  SingleSpc,  3, 8 },
193 { ARM::VLD3LNq16Pseudo,     ARM::VLD3LNq16,     true, false, EvenDblSpc, 3, 4 },
194 { ARM::VLD3LNq16Pseudo_UPD, ARM::VLD3LNq16_UPD, true, true,  EvenDblSpc, 3, 4 },
195 { ARM::VLD3LNq32Pseudo,     ARM::VLD3LNq32,     true, false, EvenDblSpc, 3, 2 },
196 { ARM::VLD3LNq32Pseudo_UPD, ARM::VLD3LNq32_UPD, true, true,  EvenDblSpc, 3, 2 },
197
198 { ARM::VLD3d16Pseudo,       ARM::VLD3d16,      true,  false, SingleSpc,  3, 4 },
199 { ARM::VLD3d16Pseudo_UPD,   ARM::VLD3d16_UPD,  true,  true,  SingleSpc,  3, 4 },
200 { ARM::VLD3d32Pseudo,       ARM::VLD3d32,      true,  false, SingleSpc,  3, 2 },
201 { ARM::VLD3d32Pseudo_UPD,   ARM::VLD3d32_UPD,  true,  true,  SingleSpc,  3, 2 },
202 { ARM::VLD3d8Pseudo,        ARM::VLD3d8,       true,  false, SingleSpc,  3, 8 },
203 { ARM::VLD3d8Pseudo_UPD,    ARM::VLD3d8_UPD,   true,  true,  SingleSpc,  3, 8 },
204
205 { ARM::VLD3q16Pseudo_UPD,    ARM::VLD3q16_UPD, true,  true,  EvenDblSpc, 3, 4 },
206 { ARM::VLD3q16oddPseudo_UPD, ARM::VLD3q16_UPD, true,  true,  OddDblSpc,  3, 4 },
207 { ARM::VLD3q32Pseudo_UPD,    ARM::VLD3q32_UPD, true,  true,  EvenDblSpc, 3, 2 },
208 { ARM::VLD3q32oddPseudo_UPD, ARM::VLD3q32_UPD, true,  true,  OddDblSpc,  3, 2 },
209 { ARM::VLD3q8Pseudo_UPD,     ARM::VLD3q8_UPD,  true,  true,  EvenDblSpc, 3, 8 },
210 { ARM::VLD3q8oddPseudo_UPD,  ARM::VLD3q8_UPD,  true,  true,  OddDblSpc,  3, 8 },
211
212 { ARM::VLD4DUPd16Pseudo,     ARM::VLD4DUPd16,     true, false, SingleSpc, 4, 4},
213 { ARM::VLD4DUPd16Pseudo_UPD, ARM::VLD4DUPd16_UPD, true, true,  SingleSpc, 4, 4},
214 { ARM::VLD4DUPd32Pseudo,     ARM::VLD4DUPd32,     true, false, SingleSpc, 4, 2},
215 { ARM::VLD4DUPd32Pseudo_UPD, ARM::VLD4DUPd32_UPD, true, true,  SingleSpc, 4, 2},
216 { ARM::VLD4DUPd8Pseudo,      ARM::VLD4DUPd8,      true, false, SingleSpc, 4, 8},
217 { ARM::VLD4DUPd8Pseudo_UPD,  ARM::VLD4DUPd8_UPD,  true, true,  SingleSpc, 4, 8},
218
219 { ARM::VLD4LNd16Pseudo,     ARM::VLD4LNd16,     true, false, SingleSpc,  4, 4 },
220 { ARM::VLD4LNd16Pseudo_UPD, ARM::VLD4LNd16_UPD, true, true,  SingleSpc,  4, 4 },
221 { ARM::VLD4LNd32Pseudo,     ARM::VLD4LNd32,     true, false, SingleSpc,  4, 2 },
222 { ARM::VLD4LNd32Pseudo_UPD, ARM::VLD4LNd32_UPD, true, true,  SingleSpc,  4, 2 },
223 { ARM::VLD4LNd8Pseudo,      ARM::VLD4LNd8,      true, false, SingleSpc,  4, 8 },
224 { ARM::VLD4LNd8Pseudo_UPD,  ARM::VLD4LNd8_UPD,  true, true,  SingleSpc,  4, 8 },
225 { ARM::VLD4LNq16Pseudo,     ARM::VLD4LNq16,     true, false, EvenDblSpc, 4, 4 },
226 { ARM::VLD4LNq16Pseudo_UPD, ARM::VLD4LNq16_UPD, true, true,  EvenDblSpc, 4, 4 },
227 { ARM::VLD4LNq32Pseudo,     ARM::VLD4LNq32,     true, false, EvenDblSpc, 4, 2 },
228 { ARM::VLD4LNq32Pseudo_UPD, ARM::VLD4LNq32_UPD, true, true,  EvenDblSpc, 4, 2 },
229
230 { ARM::VLD4d16Pseudo,       ARM::VLD4d16,      true,  false, SingleSpc,  4, 4 },
231 { ARM::VLD4d16Pseudo_UPD,   ARM::VLD4d16_UPD,  true,  true,  SingleSpc,  4, 4 },
232 { ARM::VLD4d32Pseudo,       ARM::VLD4d32,      true,  false, SingleSpc,  4, 2 },
233 { ARM::VLD4d32Pseudo_UPD,   ARM::VLD4d32_UPD,  true,  true,  SingleSpc,  4, 2 },
234 { ARM::VLD4d8Pseudo,        ARM::VLD4d8,       true,  false, SingleSpc,  4, 8 },
235 { ARM::VLD4d8Pseudo_UPD,    ARM::VLD4d8_UPD,   true,  true,  SingleSpc,  4, 8 },
236
237 { ARM::VLD4q16Pseudo_UPD,    ARM::VLD4q16_UPD, true,  true,  EvenDblSpc, 4, 4 },
238 { ARM::VLD4q16oddPseudo_UPD, ARM::VLD4q16_UPD, true,  true,  OddDblSpc,  4, 4 },
239 { ARM::VLD4q32Pseudo_UPD,    ARM::VLD4q32_UPD, true,  true,  EvenDblSpc, 4, 2 },
240 { ARM::VLD4q32oddPseudo_UPD, ARM::VLD4q32_UPD, true,  true,  OddDblSpc,  4, 2 },
241 { ARM::VLD4q8Pseudo_UPD,     ARM::VLD4q8_UPD,  true,  true,  EvenDblSpc, 4, 8 },
242 { ARM::VLD4q8oddPseudo_UPD,  ARM::VLD4q8_UPD,  true,  true,  OddDblSpc,  4, 8 },
243
244 { ARM::VST1LNq16Pseudo,     ARM::VST1LNd16,    false, false, EvenDblSpc, 1, 4 },
245 { ARM::VST1LNq16Pseudo_UPD, ARM::VST1LNd16_UPD,false, true,  EvenDblSpc, 1, 4 },
246 { ARM::VST1LNq32Pseudo,     ARM::VST1LNd32,    false, false, EvenDblSpc, 1, 2 },
247 { ARM::VST1LNq32Pseudo_UPD, ARM::VST1LNd32_UPD,false, true,  EvenDblSpc, 1, 2 },
248 { ARM::VST1LNq8Pseudo,      ARM::VST1LNd8,     false, false, EvenDblSpc, 1, 8 },
249 { ARM::VST1LNq8Pseudo_UPD,  ARM::VST1LNd8_UPD, false, true,  EvenDblSpc, 1, 8 },
250
251 { ARM::VST1d64QPseudo,      ARM::VST1d64Q,     false, false, SingleSpc,  4, 1 },
252 { ARM::VST1d64QPseudo_UPD,  ARM::VST1d64Q_UPD, false, true,  SingleSpc,  4, 1 },
253 { ARM::VST1d64TPseudo,      ARM::VST1d64T,     false, false, SingleSpc,  3, 1 },
254 { ARM::VST1d64TPseudo_UPD,  ARM::VST1d64T_UPD, false, true,  SingleSpc,  3, 1 },
255
256 { ARM::VST1q16Pseudo,       ARM::VST1q16,      false, false, SingleSpc,  2, 4 },
257 { ARM::VST1q16Pseudo_UPD,   ARM::VST1q16_UPD,  false, true,  SingleSpc,  2, 4 },
258 { ARM::VST1q32Pseudo,       ARM::VST1q32,      false, false, SingleSpc,  2, 2 },
259 { ARM::VST1q32Pseudo_UPD,   ARM::VST1q32_UPD,  false, true,  SingleSpc,  2, 2 },
260 { ARM::VST1q64Pseudo,       ARM::VST1q64,      false, false, SingleSpc,  2, 1 },
261 { ARM::VST1q64Pseudo_UPD,   ARM::VST1q64_UPD,  false, true,  SingleSpc,  2, 1 },
262 { ARM::VST1q8Pseudo,        ARM::VST1q8,       false, false, SingleSpc,  2, 8 },
263 { ARM::VST1q8Pseudo_UPD,    ARM::VST1q8_UPD,   false, true,  SingleSpc,  2, 8 },
264
265 { ARM::VST2LNd16Pseudo,     ARM::VST2LNd16,     false, false, SingleSpc, 2, 4 },
266 { ARM::VST2LNd16Pseudo_UPD, ARM::VST2LNd16_UPD, false, true,  SingleSpc, 2, 4 },
267 { ARM::VST2LNd32Pseudo,     ARM::VST2LNd32,     false, false, SingleSpc, 2, 2 },
268 { ARM::VST2LNd32Pseudo_UPD, ARM::VST2LNd32_UPD, false, true,  SingleSpc, 2, 2 },
269 { ARM::VST2LNd8Pseudo,      ARM::VST2LNd8,      false, false, SingleSpc, 2, 8 },
270 { ARM::VST2LNd8Pseudo_UPD,  ARM::VST2LNd8_UPD,  false, true,  SingleSpc, 2, 8 },
271 { ARM::VST2LNq16Pseudo,     ARM::VST2LNq16,     false, false, EvenDblSpc, 2, 4},
272 { ARM::VST2LNq16Pseudo_UPD, ARM::VST2LNq16_UPD, false, true,  EvenDblSpc, 2, 4},
273 { ARM::VST2LNq32Pseudo,     ARM::VST2LNq32,     false, false, EvenDblSpc, 2, 2},
274 { ARM::VST2LNq32Pseudo_UPD, ARM::VST2LNq32_UPD, false, true,  EvenDblSpc, 2, 2},
275
276 { ARM::VST2d16Pseudo,       ARM::VST2d16,      false, false, SingleSpc,  2, 4 },
277 { ARM::VST2d16Pseudo_UPD,   ARM::VST2d16_UPD,  false, true,  SingleSpc,  2, 4 },
278 { ARM::VST2d32Pseudo,       ARM::VST2d32,      false, false, SingleSpc,  2, 2 },
279 { ARM::VST2d32Pseudo_UPD,   ARM::VST2d32_UPD,  false, true,  SingleSpc,  2, 2 },
280 { ARM::VST2d8Pseudo,        ARM::VST2d8,       false, false, SingleSpc,  2, 8 },
281 { ARM::VST2d8Pseudo_UPD,    ARM::VST2d8_UPD,   false, true,  SingleSpc,  2, 8 },
282
283 { ARM::VST2q16Pseudo,       ARM::VST2q16,      false, false, SingleSpc,  4, 4 },
284 { ARM::VST2q16Pseudo_UPD,   ARM::VST2q16_UPD,  false, true,  SingleSpc,  4, 4 },
285 { ARM::VST2q32Pseudo,       ARM::VST2q32,      false, false, SingleSpc,  4, 2 },
286 { ARM::VST2q32Pseudo_UPD,   ARM::VST2q32_UPD,  false, true,  SingleSpc,  4, 2 },
287 { ARM::VST2q8Pseudo,        ARM::VST2q8,       false, false, SingleSpc,  4, 8 },
288 { ARM::VST2q8Pseudo_UPD,    ARM::VST2q8_UPD,   false, true,  SingleSpc,  4, 8 },
289
290 { ARM::VST3LNd16Pseudo,     ARM::VST3LNd16,     false, false, SingleSpc, 3, 4 },
291 { ARM::VST3LNd16Pseudo_UPD, ARM::VST3LNd16_UPD, false, true,  SingleSpc, 3, 4 },
292 { ARM::VST3LNd32Pseudo,     ARM::VST3LNd32,     false, false, SingleSpc, 3, 2 },
293 { ARM::VST3LNd32Pseudo_UPD, ARM::VST3LNd32_UPD, false, true,  SingleSpc, 3, 2 },
294 { ARM::VST3LNd8Pseudo,      ARM::VST3LNd8,      false, false, SingleSpc, 3, 8 },
295 { ARM::VST3LNd8Pseudo_UPD,  ARM::VST3LNd8_UPD,  false, true,  SingleSpc, 3, 8 },
296 { ARM::VST3LNq16Pseudo,     ARM::VST3LNq16,     false, false, EvenDblSpc, 3, 4},
297 { ARM::VST3LNq16Pseudo_UPD, ARM::VST3LNq16_UPD, false, true,  EvenDblSpc, 3, 4},
298 { ARM::VST3LNq32Pseudo,     ARM::VST3LNq32,     false, false, EvenDblSpc, 3, 2},
299 { ARM::VST3LNq32Pseudo_UPD, ARM::VST3LNq32_UPD, false, true,  EvenDblSpc, 3, 2},
300
301 { ARM::VST3d16Pseudo,       ARM::VST3d16,      false, false, SingleSpc,  3, 4 },
302 { ARM::VST3d16Pseudo_UPD,   ARM::VST3d16_UPD,  false, true,  SingleSpc,  3, 4 },
303 { ARM::VST3d32Pseudo,       ARM::VST3d32,      false, false, SingleSpc,  3, 2 },
304 { ARM::VST3d32Pseudo_UPD,   ARM::VST3d32_UPD,  false, true,  SingleSpc,  3, 2 },
305 { ARM::VST3d8Pseudo,        ARM::VST3d8,       false, false, SingleSpc,  3, 8 },
306 { ARM::VST3d8Pseudo_UPD,    ARM::VST3d8_UPD,   false, true,  SingleSpc,  3, 8 },
307
308 { ARM::VST3q16Pseudo_UPD,    ARM::VST3q16_UPD, false, true,  EvenDblSpc, 3, 4 },
309 { ARM::VST3q16oddPseudo_UPD, ARM::VST3q16_UPD, false, true,  OddDblSpc,  3, 4 },
310 { ARM::VST3q32Pseudo_UPD,    ARM::VST3q32_UPD, false, true,  EvenDblSpc, 3, 2 },
311 { ARM::VST3q32oddPseudo_UPD, ARM::VST3q32_UPD, false, true,  OddDblSpc,  3, 2 },
312 { ARM::VST3q8Pseudo_UPD,     ARM::VST3q8_UPD,  false, true,  EvenDblSpc, 3, 8 },
313 { ARM::VST3q8oddPseudo_UPD,  ARM::VST3q8_UPD,  false, true,  OddDblSpc,  3, 8 },
314
315 { ARM::VST4LNd16Pseudo,     ARM::VST4LNd16,     false, false, SingleSpc, 4, 4 },
316 { ARM::VST4LNd16Pseudo_UPD, ARM::VST4LNd16_UPD, false, true,  SingleSpc, 4, 4 },
317 { ARM::VST4LNd32Pseudo,     ARM::VST4LNd32,     false, false, SingleSpc, 4, 2 },
318 { ARM::VST4LNd32Pseudo_UPD, ARM::VST4LNd32_UPD, false, true,  SingleSpc, 4, 2 },
319 { ARM::VST4LNd8Pseudo,      ARM::VST4LNd8,      false, false, SingleSpc, 4, 8 },
320 { ARM::VST4LNd8Pseudo_UPD,  ARM::VST4LNd8_UPD,  false, true,  SingleSpc, 4, 8 },
321 { ARM::VST4LNq16Pseudo,     ARM::VST4LNq16,     false, false, EvenDblSpc, 4, 4},
322 { ARM::VST4LNq16Pseudo_UPD, ARM::VST4LNq16_UPD, false, true,  EvenDblSpc, 4, 4},
323 { ARM::VST4LNq32Pseudo,     ARM::VST4LNq32,     false, false, EvenDblSpc, 4, 2},
324 { ARM::VST4LNq32Pseudo_UPD, ARM::VST4LNq32_UPD, false, true,  EvenDblSpc, 4, 2},
325
326 { ARM::VST4d16Pseudo,       ARM::VST4d16,      false, false, SingleSpc,  4, 4 },
327 { ARM::VST4d16Pseudo_UPD,   ARM::VST4d16_UPD,  false, true,  SingleSpc,  4, 4 },
328 { ARM::VST4d32Pseudo,       ARM::VST4d32,      false, false, SingleSpc,  4, 2 },
329 { ARM::VST4d32Pseudo_UPD,   ARM::VST4d32_UPD,  false, true,  SingleSpc,  4, 2 },
330 { ARM::VST4d8Pseudo,        ARM::VST4d8,       false, false, SingleSpc,  4, 8 },
331 { ARM::VST4d8Pseudo_UPD,    ARM::VST4d8_UPD,   false, true,  SingleSpc,  4, 8 },
332
333 { ARM::VST4q16Pseudo_UPD,    ARM::VST4q16_UPD, false, true,  EvenDblSpc, 4, 4 },
334 { ARM::VST4q16oddPseudo_UPD, ARM::VST4q16_UPD, false, true,  OddDblSpc,  4, 4 },
335 { ARM::VST4q32Pseudo_UPD,    ARM::VST4q32_UPD, false, true,  EvenDblSpc, 4, 2 },
336 { ARM::VST4q32oddPseudo_UPD, ARM::VST4q32_UPD, false, true,  OddDblSpc,  4, 2 },
337 { ARM::VST4q8Pseudo_UPD,     ARM::VST4q8_UPD,  false, true,  EvenDblSpc, 4, 8 },
338 { ARM::VST4q8oddPseudo_UPD , ARM::VST4q8_UPD,  false, true,  OddDblSpc,  4, 8 }
339 };
340
341 /// LookupNEONLdSt - Search the NEONLdStTable for information about a NEON
342 /// load or store pseudo instruction.
343 static const NEONLdStTableEntry *LookupNEONLdSt(unsigned Opcode) {
344   unsigned NumEntries = array_lengthof(NEONLdStTable);
345
346 #ifndef NDEBUG
347   // Make sure the table is sorted.
348   static bool TableChecked = false;
349   if (!TableChecked) {
350     for (unsigned i = 0; i != NumEntries-1; ++i)
351       assert(NEONLdStTable[i] < NEONLdStTable[i+1] &&
352              "NEONLdStTable is not sorted!");
353     TableChecked = true;
354   }
355 #endif
356
357   const NEONLdStTableEntry *I =
358     std::lower_bound(NEONLdStTable, NEONLdStTable + NumEntries, Opcode);
359   if (I != NEONLdStTable + NumEntries && I->PseudoOpc == Opcode)
360     return I;
361   return NULL;
362 }
363
364 /// GetDSubRegs - Get 4 D subregisters of a Q, QQ, or QQQQ register,
365 /// corresponding to the specified register spacing.  Not all of the results
366 /// are necessarily valid, e.g., a Q register only has 2 D subregisters.
367 static void GetDSubRegs(unsigned Reg, NEONRegSpacing RegSpc,
368                         const TargetRegisterInfo *TRI, unsigned &D0,
369                         unsigned &D1, unsigned &D2, unsigned &D3) {
370   if (RegSpc == SingleSpc) {
371     D0 = TRI->getSubReg(Reg, ARM::dsub_0);
372     D1 = TRI->getSubReg(Reg, ARM::dsub_1);
373     D2 = TRI->getSubReg(Reg, ARM::dsub_2);
374     D3 = TRI->getSubReg(Reg, ARM::dsub_3);
375   } else if (RegSpc == EvenDblSpc) {
376     D0 = TRI->getSubReg(Reg, ARM::dsub_0);
377     D1 = TRI->getSubReg(Reg, ARM::dsub_2);
378     D2 = TRI->getSubReg(Reg, ARM::dsub_4);
379     D3 = TRI->getSubReg(Reg, ARM::dsub_6);
380   } else {
381     assert(RegSpc == OddDblSpc && "unknown register spacing");
382     D0 = TRI->getSubReg(Reg, ARM::dsub_1);
383     D1 = TRI->getSubReg(Reg, ARM::dsub_3);
384     D2 = TRI->getSubReg(Reg, ARM::dsub_5);
385     D3 = TRI->getSubReg(Reg, ARM::dsub_7);
386   }
387 }
388
389 /// ExpandVLD - Translate VLD pseudo instructions with Q, QQ or QQQQ register
390 /// operands to real VLD instructions with D register operands.
391 void ARMExpandPseudo::ExpandVLD(MachineBasicBlock::iterator &MBBI) {
392   MachineInstr &MI = *MBBI;
393   MachineBasicBlock &MBB = *MI.getParent();
394
395   const NEONLdStTableEntry *TableEntry = LookupNEONLdSt(MI.getOpcode());
396   assert(TableEntry && TableEntry->IsLoad && "NEONLdStTable lookup failed");
397   NEONRegSpacing RegSpc = TableEntry->RegSpacing;
398   unsigned NumRegs = TableEntry->NumRegs;
399
400   MachineInstrBuilder MIB = BuildMI(MBB, MBBI, MI.getDebugLoc(),
401                                     TII->get(TableEntry->RealOpc));
402   unsigned OpIdx = 0;
403
404   bool DstIsDead = MI.getOperand(OpIdx).isDead();
405   unsigned DstReg = MI.getOperand(OpIdx++).getReg();
406   unsigned D0, D1, D2, D3;
407   GetDSubRegs(DstReg, RegSpc, TRI, D0, D1, D2, D3);
408   MIB.addReg(D0, RegState::Define | getDeadRegState(DstIsDead))
409     .addReg(D1, RegState::Define | getDeadRegState(DstIsDead));
410   if (NumRegs > 2)
411     MIB.addReg(D2, RegState::Define | getDeadRegState(DstIsDead));
412   if (NumRegs > 3)
413     MIB.addReg(D3, RegState::Define | getDeadRegState(DstIsDead));
414
415   if (TableEntry->HasWriteBack)
416     MIB.addOperand(MI.getOperand(OpIdx++));
417
418   // Copy the addrmode6 operands.
419   MIB.addOperand(MI.getOperand(OpIdx++));
420   MIB.addOperand(MI.getOperand(OpIdx++));
421   // Copy the am6offset operand.
422   if (TableEntry->HasWriteBack)
423     MIB.addOperand(MI.getOperand(OpIdx++));
424
425   // For an instruction writing double-spaced subregs, the pseudo instruction
426   // has an extra operand that is a use of the super-register.  Record the
427   // operand index and skip over it.
428   unsigned SrcOpIdx = 0;
429   if (RegSpc == EvenDblSpc || RegSpc == OddDblSpc)
430     SrcOpIdx = OpIdx++;
431
432   // Copy the predicate operands.
433   MIB.addOperand(MI.getOperand(OpIdx++));
434   MIB.addOperand(MI.getOperand(OpIdx++));
435
436   // Copy the super-register source operand used for double-spaced subregs over
437   // to the new instruction as an implicit operand.
438   if (SrcOpIdx != 0) {
439     MachineOperand MO = MI.getOperand(SrcOpIdx);
440     MO.setImplicit(true);
441     MIB.addOperand(MO);
442   }
443   // Add an implicit def for the super-register.
444   MIB.addReg(DstReg, RegState::ImplicitDefine | getDeadRegState(DstIsDead));
445   TransferImpOps(MI, MIB, MIB);
446   MI.eraseFromParent();
447 }
448
449 /// ExpandVST - Translate VST pseudo instructions with Q, QQ or QQQQ register
450 /// operands to real VST instructions with D register operands.
451 void ARMExpandPseudo::ExpandVST(MachineBasicBlock::iterator &MBBI) {
452   MachineInstr &MI = *MBBI;
453   MachineBasicBlock &MBB = *MI.getParent();
454
455   const NEONLdStTableEntry *TableEntry = LookupNEONLdSt(MI.getOpcode());
456   assert(TableEntry && !TableEntry->IsLoad && "NEONLdStTable lookup failed");
457   NEONRegSpacing RegSpc = TableEntry->RegSpacing;
458   unsigned NumRegs = TableEntry->NumRegs;
459
460   MachineInstrBuilder MIB = BuildMI(MBB, MBBI, MI.getDebugLoc(),
461                                     TII->get(TableEntry->RealOpc));
462   unsigned OpIdx = 0;
463   if (TableEntry->HasWriteBack)
464     MIB.addOperand(MI.getOperand(OpIdx++));
465
466   // Copy the addrmode6 operands.
467   MIB.addOperand(MI.getOperand(OpIdx++));
468   MIB.addOperand(MI.getOperand(OpIdx++));
469   // Copy the am6offset operand.
470   if (TableEntry->HasWriteBack)
471     MIB.addOperand(MI.getOperand(OpIdx++));
472
473   bool SrcIsKill = MI.getOperand(OpIdx).isKill();
474   unsigned SrcReg = MI.getOperand(OpIdx++).getReg();
475   unsigned D0, D1, D2, D3;
476   GetDSubRegs(SrcReg, RegSpc, TRI, D0, D1, D2, D3);
477   MIB.addReg(D0).addReg(D1);
478   if (NumRegs > 2)
479     MIB.addReg(D2);
480   if (NumRegs > 3)
481     MIB.addReg(D3);
482
483   // Copy the predicate operands.
484   MIB.addOperand(MI.getOperand(OpIdx++));
485   MIB.addOperand(MI.getOperand(OpIdx++));
486
487   if (SrcIsKill)
488     // Add an implicit kill for the super-reg.
489     (*MIB).addRegisterKilled(SrcReg, TRI, true);
490   TransferImpOps(MI, MIB, MIB);
491   MI.eraseFromParent();
492 }
493
494 /// ExpandLaneOp - Translate VLD*LN and VST*LN instructions with Q, QQ or QQQQ
495 /// register operands to real instructions with D register operands.
496 void ARMExpandPseudo::ExpandLaneOp(MachineBasicBlock::iterator &MBBI) {
497   MachineInstr &MI = *MBBI;
498   MachineBasicBlock &MBB = *MI.getParent();
499
500   const NEONLdStTableEntry *TableEntry = LookupNEONLdSt(MI.getOpcode());
501   assert(TableEntry && "NEONLdStTable lookup failed");
502   NEONRegSpacing RegSpc = TableEntry->RegSpacing;
503   unsigned NumRegs = TableEntry->NumRegs;
504   unsigned RegElts = TableEntry->RegElts;
505
506   MachineInstrBuilder MIB = BuildMI(MBB, MBBI, MI.getDebugLoc(),
507                                     TII->get(TableEntry->RealOpc));
508   unsigned OpIdx = 0;
509   // The lane operand is always the 3rd from last operand, before the 2
510   // predicate operands.
511   unsigned Lane = MI.getOperand(MI.getDesc().getNumOperands() - 3).getImm();
512
513   // Adjust the lane and spacing as needed for Q registers.
514   assert(RegSpc != OddDblSpc && "unexpected register spacing for VLD/VST-lane");
515   if (RegSpc == EvenDblSpc && Lane >= RegElts) {
516     RegSpc = OddDblSpc;
517     Lane -= RegElts;
518   }
519   assert(Lane < RegElts && "out of range lane for VLD/VST-lane");
520
521   unsigned D0, D1, D2, D3;
522   unsigned DstReg = 0;
523   bool DstIsDead = false;
524   if (TableEntry->IsLoad) {
525     DstIsDead = MI.getOperand(OpIdx).isDead();
526     DstReg = MI.getOperand(OpIdx++).getReg();
527     GetDSubRegs(DstReg, RegSpc, TRI, D0, D1, D2, D3);
528     MIB.addReg(D0, RegState::Define | getDeadRegState(DstIsDead));
529     if (NumRegs > 1)
530       MIB.addReg(D1, RegState::Define | getDeadRegState(DstIsDead));
531     if (NumRegs > 2)
532       MIB.addReg(D2, RegState::Define | getDeadRegState(DstIsDead));
533     if (NumRegs > 3)
534       MIB.addReg(D3, RegState::Define | getDeadRegState(DstIsDead));
535   }
536
537   if (TableEntry->HasWriteBack)
538     MIB.addOperand(MI.getOperand(OpIdx++));
539
540   // Copy the addrmode6 operands.
541   MIB.addOperand(MI.getOperand(OpIdx++));
542   MIB.addOperand(MI.getOperand(OpIdx++));
543   // Copy the am6offset operand.
544   if (TableEntry->HasWriteBack)
545     MIB.addOperand(MI.getOperand(OpIdx++));
546
547   // Grab the super-register source.
548   MachineOperand MO = MI.getOperand(OpIdx++);
549   if (!TableEntry->IsLoad)
550     GetDSubRegs(MO.getReg(), RegSpc, TRI, D0, D1, D2, D3);
551
552   // Add the subregs as sources of the new instruction.
553   unsigned SrcFlags = (getUndefRegState(MO.isUndef()) |
554                        getKillRegState(MO.isKill()));
555   MIB.addReg(D0, SrcFlags);
556   if (NumRegs > 1)
557     MIB.addReg(D1, SrcFlags);
558   if (NumRegs > 2)
559     MIB.addReg(D2, SrcFlags);
560   if (NumRegs > 3)
561     MIB.addReg(D3, SrcFlags);
562
563   // Add the lane number operand.
564   MIB.addImm(Lane);
565   OpIdx += 1;
566
567   // Copy the predicate operands.
568   MIB.addOperand(MI.getOperand(OpIdx++));
569   MIB.addOperand(MI.getOperand(OpIdx++));
570
571   // Copy the super-register source to be an implicit source.
572   MO.setImplicit(true);
573   MIB.addOperand(MO);
574   if (TableEntry->IsLoad)
575     // Add an implicit def for the super-register.
576     MIB.addReg(DstReg, RegState::ImplicitDefine | getDeadRegState(DstIsDead));
577   TransferImpOps(MI, MIB, MIB);
578   MI.eraseFromParent();
579 }
580
581 /// ExpandVTBL - Translate VTBL and VTBX pseudo instructions with Q or QQ
582 /// register operands to real instructions with D register operands.
583 void ARMExpandPseudo::ExpandVTBL(MachineBasicBlock::iterator &MBBI,
584                                  unsigned Opc, bool IsExt, unsigned NumRegs) {
585   MachineInstr &MI = *MBBI;
586   MachineBasicBlock &MBB = *MI.getParent();
587
588   MachineInstrBuilder MIB = BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(Opc));
589   unsigned OpIdx = 0;
590
591   // Transfer the destination register operand.
592   MIB.addOperand(MI.getOperand(OpIdx++));
593   if (IsExt)
594     MIB.addOperand(MI.getOperand(OpIdx++));
595
596   bool SrcIsKill = MI.getOperand(OpIdx).isKill();
597   unsigned SrcReg = MI.getOperand(OpIdx++).getReg();
598   unsigned D0, D1, D2, D3;
599   GetDSubRegs(SrcReg, SingleSpc, TRI, D0, D1, D2, D3);
600   MIB.addReg(D0).addReg(D1);
601   if (NumRegs > 2)
602     MIB.addReg(D2);
603   if (NumRegs > 3)
604     MIB.addReg(D3);
605
606   // Copy the other source register operand.
607   MIB.addOperand(MI.getOperand(OpIdx++));
608
609   // Copy the predicate operands.
610   MIB.addOperand(MI.getOperand(OpIdx++));
611   MIB.addOperand(MI.getOperand(OpIdx++));
612
613   if (SrcIsKill)
614     // Add an implicit kill for the super-reg.
615     (*MIB).addRegisterKilled(SrcReg, TRI, true);
616   TransferImpOps(MI, MIB, MIB);
617   MI.eraseFromParent();
618 }
619
620 void ARMExpandPseudo::ExpandMOV32BitImm(MachineBasicBlock &MBB,
621                                         MachineBasicBlock::iterator &MBBI) {
622   MachineInstr &MI = *MBBI;
623   unsigned Opcode = MI.getOpcode();
624   unsigned PredReg = 0;
625   ARMCC::CondCodes Pred = llvm::getInstrPredicate(&MI, PredReg);
626   unsigned DstReg = MI.getOperand(0).getReg();
627   bool DstIsDead = MI.getOperand(0).isDead();
628   bool isCC = Opcode == ARM::MOVCCi32imm || Opcode == ARM::t2MOVCCi32imm;
629   const MachineOperand &MO = MI.getOperand(isCC ? 2 : 1);
630   MachineInstrBuilder LO16, HI16;
631
632   if (!STI->hasV6T2Ops() &&
633       (Opcode == ARM::MOVi32imm || Opcode == ARM::MOVCCi32imm)) {
634     // Expand into a movi + orr.
635     LO16 = BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(ARM::MOVi), DstReg);
636     HI16 = BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(ARM::ORRri))
637       .addReg(DstReg, RegState::Define | getDeadRegState(DstIsDead))
638       .addReg(DstReg);
639
640     assert (MO.isImm() && "MOVi32imm w/ non-immediate source operand!");
641     unsigned ImmVal = (unsigned)MO.getImm();
642     unsigned SOImmValV1 = ARM_AM::getSOImmTwoPartFirst(ImmVal);
643     unsigned SOImmValV2 = ARM_AM::getSOImmTwoPartSecond(ImmVal);
644     LO16 = LO16.addImm(SOImmValV1);
645     HI16 = HI16.addImm(SOImmValV2);
646     (*LO16).setMemRefs(MI.memoperands_begin(), MI.memoperands_end());
647     (*HI16).setMemRefs(MI.memoperands_begin(), MI.memoperands_end());
648     LO16.addImm(Pred).addReg(PredReg).addReg(0);
649     HI16.addImm(Pred).addReg(PredReg).addReg(0);
650     TransferImpOps(MI, LO16, HI16);
651     MI.eraseFromParent();
652     return;
653   }
654
655   unsigned LO16Opc = 0;
656   unsigned HI16Opc = 0;
657   if (Opcode == ARM::t2MOVi32imm || Opcode == ARM::t2MOVCCi32imm) {
658     LO16Opc = ARM::t2MOVi16;
659     HI16Opc = ARM::t2MOVTi16;
660   } else {
661     LO16Opc = ARM::MOVi16;
662     HI16Opc = ARM::MOVTi16;
663   }
664
665   LO16 = BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(LO16Opc), DstReg);
666   HI16 = BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(HI16Opc))
667     .addReg(DstReg, RegState::Define | getDeadRegState(DstIsDead))
668     .addReg(DstReg);
669
670   if (MO.isImm()) {
671     unsigned Imm = MO.getImm();
672     unsigned Lo16 = Imm & 0xffff;
673     unsigned Hi16 = (Imm >> 16) & 0xffff;
674     LO16 = LO16.addImm(Lo16);
675     HI16 = HI16.addImm(Hi16);
676   } else {
677     const GlobalValue *GV = MO.getGlobal();
678     unsigned TF = MO.getTargetFlags();
679     LO16 = LO16.addGlobalAddress(GV, MO.getOffset(), TF | ARMII::MO_LO16);
680     HI16 = HI16.addGlobalAddress(GV, MO.getOffset(), TF | ARMII::MO_HI16);
681   }
682
683   (*LO16).setMemRefs(MI.memoperands_begin(), MI.memoperands_end());
684   (*HI16).setMemRefs(MI.memoperands_begin(), MI.memoperands_end());
685   LO16.addImm(Pred).addReg(PredReg);
686   HI16.addImm(Pred).addReg(PredReg);
687
688   TransferImpOps(MI, LO16, HI16);
689   MI.eraseFromParent();
690 }
691
692 bool ARMExpandPseudo::ExpandMI(MachineBasicBlock &MBB,
693                                MachineBasicBlock::iterator MBBI) {
694   MachineInstr &MI = *MBBI;
695   unsigned Opcode = MI.getOpcode();
696   switch (Opcode) {
697     default:
698       return false;
699     case ARM::Int_eh_sjlj_dispatchsetup: {
700       MachineFunction &MF = *MI.getParent()->getParent();
701       const ARMBaseInstrInfo *AII =
702         static_cast<const ARMBaseInstrInfo*>(TII);
703       const ARMBaseRegisterInfo &RI = AII->getRegisterInfo();
704       // For functions using a base pointer, we rematerialize it (via the frame
705       // pointer) here since eh.sjlj.setjmp and eh.sjlj.longjmp don't do it
706       // for us. Otherwise, expand to nothing.
707       if (RI.hasBasePointer(MF)) {
708         int32_t NumBytes = AFI->getFramePtrSpillOffset();
709         unsigned FramePtr = RI.getFrameRegister(MF);
710         assert(MF.getTarget().getFrameLowering()->hasFP(MF) &&
711                "base pointer without frame pointer?");
712
713         if (AFI->isThumb2Function()) {
714           llvm::emitT2RegPlusImmediate(MBB, MBBI, MI.getDebugLoc(), ARM::R6,
715                                        FramePtr, -NumBytes, ARMCC::AL, 0, *TII);
716         } else if (AFI->isThumbFunction()) {
717           llvm::emitThumbRegPlusImmediate(MBB, MBBI, ARM::R6,
718                                           FramePtr, -NumBytes,
719                                           *TII, RI, MI.getDebugLoc());
720         } else {
721           llvm::emitARMRegPlusImmediate(MBB, MBBI, MI.getDebugLoc(), ARM::R6,
722                                         FramePtr, -NumBytes, ARMCC::AL, 0,
723                                         *TII);
724         }
725         // If there's dynamic realignment, adjust for it.
726         if (RI.needsStackRealignment(MF)) {
727           MachineFrameInfo  *MFI = MF.getFrameInfo();
728           unsigned MaxAlign = MFI->getMaxAlignment();
729           assert (!AFI->isThumb1OnlyFunction());
730           // Emit bic r6, r6, MaxAlign
731           unsigned bicOpc = AFI->isThumbFunction() ?
732             ARM::t2BICri : ARM::BICri;
733           AddDefaultCC(AddDefaultPred(BuildMI(MBB, MBBI, MI.getDebugLoc(),
734                                               TII->get(bicOpc), ARM::R6)
735                                       .addReg(ARM::R6, RegState::Kill)
736                                       .addImm(MaxAlign-1)));
737         }
738
739       }
740       MI.eraseFromParent();
741       return true;
742     }
743
744     case ARM::MOVsrl_flag:
745     case ARM::MOVsra_flag: {
746       // These are just fancy MOVs insructions.
747       AddDefaultPred(BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(ARM::MOVs),
748                              MI.getOperand(0).getReg())
749                      .addOperand(MI.getOperand(1))
750                      .addReg(0)
751                      .addImm(ARM_AM::getSORegOpc((Opcode == ARM::MOVsrl_flag ? ARM_AM::lsr
752                                                   : ARM_AM::asr), 1)))
753         .addReg(ARM::CPSR, RegState::Define);
754       MI.eraseFromParent();
755       return true;
756     }
757     case ARM::RRX: {
758       // This encodes as "MOVs Rd, Rm, rrx
759       MachineInstrBuilder MIB =
760         AddDefaultPred(BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(ARM::MOVs),
761                                MI.getOperand(0).getReg())
762                        .addOperand(MI.getOperand(1))
763                        .addOperand(MI.getOperand(1))
764                        .addImm(ARM_AM::getSORegOpc(ARM_AM::rrx, 0)))
765         .addReg(0);
766       TransferImpOps(MI, MIB, MIB);
767       MI.eraseFromParent();
768       return true;
769     }
770     case ARM::TPsoft: {
771       MachineInstrBuilder MIB = 
772         BuildMI(MBB, MBBI, MI.getDebugLoc(),
773                 TII->get(ARM::BL))
774         .addExternalSymbol("__aeabi_read_tp", 0);
775
776       (*MIB).setMemRefs(MI.memoperands_begin(), MI.memoperands_end());
777       TransferImpOps(MI, MIB, MIB);
778       MI.eraseFromParent();
779       return true;
780     }
781     case ARM::t2LDRHpci:
782     case ARM::t2LDRBpci:
783     case ARM::t2LDRSHpci:
784     case ARM::t2LDRSBpci:
785     case ARM::t2LDRpci: {
786       unsigned NewLdOpc;
787       if (Opcode == ARM::t2LDRpci)
788         NewLdOpc = ARM::t2LDRi12;
789       else if (Opcode == ARM::t2LDRHpci)
790         NewLdOpc = ARM::t2LDRHi12;
791       else if (Opcode == ARM::t2LDRBpci)
792         NewLdOpc = ARM::t2LDRBi12;
793       else if (Opcode == ARM::t2LDRSHpci)
794         NewLdOpc = ARM::t2LDRSHi12;
795       else if (Opcode == ARM::t2LDRSBpci)
796         NewLdOpc = ARM::t2LDRSBi12;
797       else
798         llvm_unreachable("Not a known opcode?");
799
800       unsigned DstReg = MI.getOperand(0).getReg();
801       MachineInstrBuilder MIB =
802         AddDefaultPred(BuildMI(MBB, MBBI, MI.getDebugLoc(),
803                                TII->get(NewLdOpc), DstReg)
804                        .addReg(ARM::PC)
805                        .addOperand(MI.getOperand(1)));
806       (*MIB).setMemRefs(MI.memoperands_begin(), MI.memoperands_end());
807       TransferImpOps(MI, MIB, MIB);
808       MI.eraseFromParent();
809       return true;
810     }
811
812     case ARM::tLDRpci_pic:
813     case ARM::t2LDRpci_pic: {
814       unsigned NewLdOpc = (Opcode == ARM::tLDRpci_pic)
815         ? ARM::tLDRpci : ARM::t2LDRi12;
816       unsigned DstReg = MI.getOperand(0).getReg();
817       bool DstIsDead = MI.getOperand(0).isDead();
818       MachineInstrBuilder MIB1 =
819         BuildMI(MBB, MBBI, MI.getDebugLoc(),
820                 TII->get(NewLdOpc), DstReg);
821       if (Opcode == ARM::t2LDRpci_pic) MIB1.addReg(ARM::PC);
822       MIB1.addOperand(MI.getOperand(1));
823       AddDefaultPred(MIB1);
824       (*MIB1).setMemRefs(MI.memoperands_begin(), MI.memoperands_end());
825       MachineInstrBuilder MIB2 = BuildMI(MBB, MBBI, MI.getDebugLoc(),
826                                          TII->get(ARM::tPICADD))
827         .addReg(DstReg, RegState::Define | getDeadRegState(DstIsDead))
828         .addReg(DstReg)
829         .addOperand(MI.getOperand(2));
830       TransferImpOps(MI, MIB1, MIB2);
831       MI.eraseFromParent();
832       return true;
833     }
834
835     case ARM::MOV_pic_ga_add_pc:
836     case ARM::MOV_pic_ga_ldr:
837     case ARM::t2MOV_pic_ga_add_pc: {
838       // Expand into movw + movw + add pc / ldr [pc]
839       unsigned LabelId = AFI->createPICLabelUId();
840       unsigned DstReg = MI.getOperand(0).getReg();
841       bool DstIsDead = MI.getOperand(0).isDead();
842       const MachineOperand &MO1 = MI.getOperand(1);
843       const GlobalValue *GV = MO1.getGlobal();
844       unsigned TF = MO1.getTargetFlags();
845       bool isARM = Opcode != ARM::t2MOV_pic_ga_add_pc;
846       unsigned LO16Opc = isARM ? ARM::MOVi16_pic_ga : ARM::t2MOVi16_pic_ga;
847       unsigned HI16Opc = isARM ? ARM::MOVTi16_pic_ga : ARM::t2MOVTi16_pic_ga;
848       unsigned PICAddOpc = isARM
849         ? (Opcode == ARM::MOV_pic_ga_ldr ? ARM::PICLDR : ARM::PICADD)
850         : ARM::tPICADD;
851       MachineInstrBuilder MIB1 = BuildMI(MBB, MBBI, MI.getDebugLoc(),
852                                          TII->get(LO16Opc), DstReg)
853         .addGlobalAddress(GV, MO1.getOffset(),
854                           TF | ARMII::MO_LO16_NONLAZY_PIC)
855         .addImm(LabelId);
856       BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(HI16Opc), DstReg)
857         .addReg(DstReg)
858         .addGlobalAddress(GV, MO1.getOffset(),
859                           TF | ARMII::MO_HI16_NONLAZY_PIC)
860         .addImm(LabelId);
861       MachineInstrBuilder MIB2 = BuildMI(MBB, MBBI, MI.getDebugLoc(),
862                                          TII->get(PICAddOpc))
863         .addReg(DstReg, RegState::Define | getDeadRegState(DstIsDead))
864         .addReg(DstReg).addImm(LabelId);
865       if (isARM) {
866         AddDefaultPred(MIB2);
867         if (Opcode == ARM::MOV_pic_ga_ldr)
868           (*MIB2).setMemRefs(MI.memoperands_begin(), MI.memoperands_end());
869       }
870       TransferImpOps(MI, MIB1, MIB2);
871       MI.eraseFromParent();
872       return true;
873     }
874
875     case ARM::MOVi32imm:
876     case ARM::MOVCCi32imm:
877     case ARM::t2MOVi32imm:
878     case ARM::t2MOVCCi32imm:
879       ExpandMOV32BitImm(MBB, MBBI);
880       return true;
881
882     case ARM::VMOVQQ: {
883       unsigned DstReg = MI.getOperand(0).getReg();
884       bool DstIsDead = MI.getOperand(0).isDead();
885       unsigned EvenDst = TRI->getSubReg(DstReg, ARM::qsub_0);
886       unsigned OddDst  = TRI->getSubReg(DstReg, ARM::qsub_1);
887       unsigned SrcReg = MI.getOperand(1).getReg();
888       bool SrcIsKill = MI.getOperand(1).isKill();
889       unsigned EvenSrc = TRI->getSubReg(SrcReg, ARM::qsub_0);
890       unsigned OddSrc  = TRI->getSubReg(SrcReg, ARM::qsub_1);
891       MachineInstrBuilder Even =
892         AddDefaultPred(BuildMI(MBB, MBBI, MI.getDebugLoc(),
893                                TII->get(ARM::VMOVQ))
894                        .addReg(EvenDst,
895                                RegState::Define | getDeadRegState(DstIsDead))
896                        .addReg(EvenSrc, getKillRegState(SrcIsKill)));
897       MachineInstrBuilder Odd =
898         AddDefaultPred(BuildMI(MBB, MBBI, MI.getDebugLoc(),
899                                TII->get(ARM::VMOVQ))
900                        .addReg(OddDst,
901                                RegState::Define | getDeadRegState(DstIsDead))
902                        .addReg(OddSrc, getKillRegState(SrcIsKill)));
903       TransferImpOps(MI, Even, Odd);
904       MI.eraseFromParent();
905       return true;
906     }
907
908     case ARM::VLDMQIA:
909     case ARM::VLDMQDB: {
910       unsigned NewOpc = (Opcode == ARM::VLDMQIA) ? ARM::VLDMDIA : ARM::VLDMDDB;
911       MachineInstrBuilder MIB =
912         BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(NewOpc));
913       unsigned OpIdx = 0;
914
915       // Grab the Q register destination.
916       bool DstIsDead = MI.getOperand(OpIdx).isDead();
917       unsigned DstReg = MI.getOperand(OpIdx++).getReg();
918
919       // Copy the source register.
920       MIB.addOperand(MI.getOperand(OpIdx++));
921
922       // Copy the predicate operands.
923       MIB.addOperand(MI.getOperand(OpIdx++));
924       MIB.addOperand(MI.getOperand(OpIdx++));
925
926       // Add the destination operands (D subregs).
927       unsigned D0 = TRI->getSubReg(DstReg, ARM::dsub_0);
928       unsigned D1 = TRI->getSubReg(DstReg, ARM::dsub_1);
929       MIB.addReg(D0, RegState::Define | getDeadRegState(DstIsDead))
930         .addReg(D1, RegState::Define | getDeadRegState(DstIsDead));
931
932       // Add an implicit def for the super-register.
933       MIB.addReg(DstReg, RegState::ImplicitDefine | getDeadRegState(DstIsDead));
934       TransferImpOps(MI, MIB, MIB);
935       MI.eraseFromParent();
936       return true;
937     }
938
939     case ARM::VSTMQIA:
940     case ARM::VSTMQDB: {
941       unsigned NewOpc = (Opcode == ARM::VSTMQIA) ? ARM::VSTMDIA : ARM::VSTMDDB;
942       MachineInstrBuilder MIB =
943         BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(NewOpc));
944       unsigned OpIdx = 0;
945
946       // Grab the Q register source.
947       bool SrcIsKill = MI.getOperand(OpIdx).isKill();
948       unsigned SrcReg = MI.getOperand(OpIdx++).getReg();
949
950       // Copy the destination register.
951       MIB.addOperand(MI.getOperand(OpIdx++));
952
953       // Copy the predicate operands.
954       MIB.addOperand(MI.getOperand(OpIdx++));
955       MIB.addOperand(MI.getOperand(OpIdx++));
956
957       // Add the source operands (D subregs).
958       unsigned D0 = TRI->getSubReg(SrcReg, ARM::dsub_0);
959       unsigned D1 = TRI->getSubReg(SrcReg, ARM::dsub_1);
960       MIB.addReg(D0).addReg(D1);
961
962       if (SrcIsKill)
963         // Add an implicit kill for the Q register.
964         (*MIB).addRegisterKilled(SrcReg, TRI, true);
965
966       TransferImpOps(MI, MIB, MIB);
967       MI.eraseFromParent();
968       return true;
969     }
970     case ARM::VDUPfqf:
971     case ARM::VDUPfdf:{
972       unsigned NewOpc = Opcode == ARM::VDUPfqf ? ARM::VDUPLNfq : ARM::VDUPLNfd;
973       MachineInstrBuilder MIB =
974         BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(NewOpc));
975       unsigned OpIdx = 0;
976       unsigned SrcReg = MI.getOperand(1).getReg();
977       unsigned Lane = getARMRegisterNumbering(SrcReg) & 1;
978       unsigned DReg = TRI->getMatchingSuperReg(SrcReg,
979                                                Lane & 1 ? ARM::ssub_1 : ARM::ssub_0, &ARM::DPR_VFP2RegClass);
980       // The lane is [0,1] for the containing DReg superregister.
981       // Copy the dst/src register operands.
982       MIB.addOperand(MI.getOperand(OpIdx++));
983       MIB.addReg(DReg);
984       ++OpIdx;
985       // Add the lane select operand.
986       MIB.addImm(Lane);
987       // Add the predicate operands.
988       MIB.addOperand(MI.getOperand(OpIdx++));
989       MIB.addOperand(MI.getOperand(OpIdx++));
990
991       TransferImpOps(MI, MIB, MIB);
992       MI.eraseFromParent();
993       return true;
994     }
995
996     case ARM::VLD1q8Pseudo:
997     case ARM::VLD1q16Pseudo:
998     case ARM::VLD1q32Pseudo:
999     case ARM::VLD1q64Pseudo:
1000     case ARM::VLD1q8Pseudo_UPD:
1001     case ARM::VLD1q16Pseudo_UPD:
1002     case ARM::VLD1q32Pseudo_UPD:
1003     case ARM::VLD1q64Pseudo_UPD:
1004     case ARM::VLD2d8Pseudo:
1005     case ARM::VLD2d16Pseudo:
1006     case ARM::VLD2d32Pseudo:
1007     case ARM::VLD2q8Pseudo:
1008     case ARM::VLD2q16Pseudo:
1009     case ARM::VLD2q32Pseudo:
1010     case ARM::VLD2d8Pseudo_UPD:
1011     case ARM::VLD2d16Pseudo_UPD:
1012     case ARM::VLD2d32Pseudo_UPD:
1013     case ARM::VLD2q8Pseudo_UPD:
1014     case ARM::VLD2q16Pseudo_UPD:
1015     case ARM::VLD2q32Pseudo_UPD:
1016     case ARM::VLD3d8Pseudo:
1017     case ARM::VLD3d16Pseudo:
1018     case ARM::VLD3d32Pseudo:
1019     case ARM::VLD1d64TPseudo:
1020     case ARM::VLD3d8Pseudo_UPD:
1021     case ARM::VLD3d16Pseudo_UPD:
1022     case ARM::VLD3d32Pseudo_UPD:
1023     case ARM::VLD1d64TPseudo_UPD:
1024     case ARM::VLD3q8Pseudo_UPD:
1025     case ARM::VLD3q16Pseudo_UPD:
1026     case ARM::VLD3q32Pseudo_UPD:
1027     case ARM::VLD3q8oddPseudo_UPD:
1028     case ARM::VLD3q16oddPseudo_UPD:
1029     case ARM::VLD3q32oddPseudo_UPD:
1030     case ARM::VLD4d8Pseudo:
1031     case ARM::VLD4d16Pseudo:
1032     case ARM::VLD4d32Pseudo:
1033     case ARM::VLD1d64QPseudo:
1034     case ARM::VLD4d8Pseudo_UPD:
1035     case ARM::VLD4d16Pseudo_UPD:
1036     case ARM::VLD4d32Pseudo_UPD:
1037     case ARM::VLD1d64QPseudo_UPD:
1038     case ARM::VLD4q8Pseudo_UPD:
1039     case ARM::VLD4q16Pseudo_UPD:
1040     case ARM::VLD4q32Pseudo_UPD:
1041     case ARM::VLD4q8oddPseudo_UPD:
1042     case ARM::VLD4q16oddPseudo_UPD:
1043     case ARM::VLD4q32oddPseudo_UPD:
1044     case ARM::VLD1DUPq8Pseudo:
1045     case ARM::VLD1DUPq16Pseudo:
1046     case ARM::VLD1DUPq32Pseudo:
1047     case ARM::VLD1DUPq8Pseudo_UPD:
1048     case ARM::VLD1DUPq16Pseudo_UPD:
1049     case ARM::VLD1DUPq32Pseudo_UPD:
1050     case ARM::VLD2DUPd8Pseudo:
1051     case ARM::VLD2DUPd16Pseudo:
1052     case ARM::VLD2DUPd32Pseudo:
1053     case ARM::VLD2DUPd8Pseudo_UPD:
1054     case ARM::VLD2DUPd16Pseudo_UPD:
1055     case ARM::VLD2DUPd32Pseudo_UPD:
1056     case ARM::VLD3DUPd8Pseudo:
1057     case ARM::VLD3DUPd16Pseudo:
1058     case ARM::VLD3DUPd32Pseudo:
1059     case ARM::VLD3DUPd8Pseudo_UPD:
1060     case ARM::VLD3DUPd16Pseudo_UPD:
1061     case ARM::VLD3DUPd32Pseudo_UPD:
1062     case ARM::VLD4DUPd8Pseudo:
1063     case ARM::VLD4DUPd16Pseudo:
1064     case ARM::VLD4DUPd32Pseudo:
1065     case ARM::VLD4DUPd8Pseudo_UPD:
1066     case ARM::VLD4DUPd16Pseudo_UPD:
1067     case ARM::VLD4DUPd32Pseudo_UPD:
1068       ExpandVLD(MBBI);
1069       return true;
1070
1071     case ARM::VST1q8Pseudo:
1072     case ARM::VST1q16Pseudo:
1073     case ARM::VST1q32Pseudo:
1074     case ARM::VST1q64Pseudo:
1075     case ARM::VST1q8Pseudo_UPD:
1076     case ARM::VST1q16Pseudo_UPD:
1077     case ARM::VST1q32Pseudo_UPD:
1078     case ARM::VST1q64Pseudo_UPD:
1079     case ARM::VST2d8Pseudo:
1080     case ARM::VST2d16Pseudo:
1081     case ARM::VST2d32Pseudo:
1082     case ARM::VST2q8Pseudo:
1083     case ARM::VST2q16Pseudo:
1084     case ARM::VST2q32Pseudo:
1085     case ARM::VST2d8Pseudo_UPD:
1086     case ARM::VST2d16Pseudo_UPD:
1087     case ARM::VST2d32Pseudo_UPD:
1088     case ARM::VST2q8Pseudo_UPD:
1089     case ARM::VST2q16Pseudo_UPD:
1090     case ARM::VST2q32Pseudo_UPD:
1091     case ARM::VST3d8Pseudo:
1092     case ARM::VST3d16Pseudo:
1093     case ARM::VST3d32Pseudo:
1094     case ARM::VST1d64TPseudo:
1095     case ARM::VST3d8Pseudo_UPD:
1096     case ARM::VST3d16Pseudo_UPD:
1097     case ARM::VST3d32Pseudo_UPD:
1098     case ARM::VST1d64TPseudo_UPD:
1099     case ARM::VST3q8Pseudo_UPD:
1100     case ARM::VST3q16Pseudo_UPD:
1101     case ARM::VST3q32Pseudo_UPD:
1102     case ARM::VST3q8oddPseudo_UPD:
1103     case ARM::VST3q16oddPseudo_UPD:
1104     case ARM::VST3q32oddPseudo_UPD:
1105     case ARM::VST4d8Pseudo:
1106     case ARM::VST4d16Pseudo:
1107     case ARM::VST4d32Pseudo:
1108     case ARM::VST1d64QPseudo:
1109     case ARM::VST4d8Pseudo_UPD:
1110     case ARM::VST4d16Pseudo_UPD:
1111     case ARM::VST4d32Pseudo_UPD:
1112     case ARM::VST1d64QPseudo_UPD:
1113     case ARM::VST4q8Pseudo_UPD:
1114     case ARM::VST4q16Pseudo_UPD:
1115     case ARM::VST4q32Pseudo_UPD:
1116     case ARM::VST4q8oddPseudo_UPD:
1117     case ARM::VST4q16oddPseudo_UPD:
1118     case ARM::VST4q32oddPseudo_UPD:
1119       ExpandVST(MBBI);
1120       return true;
1121
1122     case ARM::VLD1LNq8Pseudo:
1123     case ARM::VLD1LNq16Pseudo:
1124     case ARM::VLD1LNq32Pseudo:
1125     case ARM::VLD1LNq8Pseudo_UPD:
1126     case ARM::VLD1LNq16Pseudo_UPD:
1127     case ARM::VLD1LNq32Pseudo_UPD:
1128     case ARM::VLD2LNd8Pseudo:
1129     case ARM::VLD2LNd16Pseudo:
1130     case ARM::VLD2LNd32Pseudo:
1131     case ARM::VLD2LNq16Pseudo:
1132     case ARM::VLD2LNq32Pseudo:
1133     case ARM::VLD2LNd8Pseudo_UPD:
1134     case ARM::VLD2LNd16Pseudo_UPD:
1135     case ARM::VLD2LNd32Pseudo_UPD:
1136     case ARM::VLD2LNq16Pseudo_UPD:
1137     case ARM::VLD2LNq32Pseudo_UPD:
1138     case ARM::VLD3LNd8Pseudo:
1139     case ARM::VLD3LNd16Pseudo:
1140     case ARM::VLD3LNd32Pseudo:
1141     case ARM::VLD3LNq16Pseudo:
1142     case ARM::VLD3LNq32Pseudo:
1143     case ARM::VLD3LNd8Pseudo_UPD:
1144     case ARM::VLD3LNd16Pseudo_UPD:
1145     case ARM::VLD3LNd32Pseudo_UPD:
1146     case ARM::VLD3LNq16Pseudo_UPD:
1147     case ARM::VLD3LNq32Pseudo_UPD:
1148     case ARM::VLD4LNd8Pseudo:
1149     case ARM::VLD4LNd16Pseudo:
1150     case ARM::VLD4LNd32Pseudo:
1151     case ARM::VLD4LNq16Pseudo:
1152     case ARM::VLD4LNq32Pseudo:
1153     case ARM::VLD4LNd8Pseudo_UPD:
1154     case ARM::VLD4LNd16Pseudo_UPD:
1155     case ARM::VLD4LNd32Pseudo_UPD:
1156     case ARM::VLD4LNq16Pseudo_UPD:
1157     case ARM::VLD4LNq32Pseudo_UPD:
1158     case ARM::VST1LNq8Pseudo:
1159     case ARM::VST1LNq16Pseudo:
1160     case ARM::VST1LNq32Pseudo:
1161     case ARM::VST1LNq8Pseudo_UPD:
1162     case ARM::VST1LNq16Pseudo_UPD:
1163     case ARM::VST1LNq32Pseudo_UPD:
1164     case ARM::VST2LNd8Pseudo:
1165     case ARM::VST2LNd16Pseudo:
1166     case ARM::VST2LNd32Pseudo:
1167     case ARM::VST2LNq16Pseudo:
1168     case ARM::VST2LNq32Pseudo:
1169     case ARM::VST2LNd8Pseudo_UPD:
1170     case ARM::VST2LNd16Pseudo_UPD:
1171     case ARM::VST2LNd32Pseudo_UPD:
1172     case ARM::VST2LNq16Pseudo_UPD:
1173     case ARM::VST2LNq32Pseudo_UPD:
1174     case ARM::VST3LNd8Pseudo:
1175     case ARM::VST3LNd16Pseudo:
1176     case ARM::VST3LNd32Pseudo:
1177     case ARM::VST3LNq16Pseudo:
1178     case ARM::VST3LNq32Pseudo:
1179     case ARM::VST3LNd8Pseudo_UPD:
1180     case ARM::VST3LNd16Pseudo_UPD:
1181     case ARM::VST3LNd32Pseudo_UPD:
1182     case ARM::VST3LNq16Pseudo_UPD:
1183     case ARM::VST3LNq32Pseudo_UPD:
1184     case ARM::VST4LNd8Pseudo:
1185     case ARM::VST4LNd16Pseudo:
1186     case ARM::VST4LNd32Pseudo:
1187     case ARM::VST4LNq16Pseudo:
1188     case ARM::VST4LNq32Pseudo:
1189     case ARM::VST4LNd8Pseudo_UPD:
1190     case ARM::VST4LNd16Pseudo_UPD:
1191     case ARM::VST4LNd32Pseudo_UPD:
1192     case ARM::VST4LNq16Pseudo_UPD:
1193     case ARM::VST4LNq32Pseudo_UPD:
1194       ExpandLaneOp(MBBI);
1195       return true;
1196
1197     case ARM::VTBL2Pseudo: ExpandVTBL(MBBI, ARM::VTBL2, false, 2); return true;
1198     case ARM::VTBL3Pseudo: ExpandVTBL(MBBI, ARM::VTBL3, false, 3); return true;
1199     case ARM::VTBL4Pseudo: ExpandVTBL(MBBI, ARM::VTBL4, false, 4); return true;
1200     case ARM::VTBX2Pseudo: ExpandVTBL(MBBI, ARM::VTBX2, true, 2); return true;
1201     case ARM::VTBX3Pseudo: ExpandVTBL(MBBI, ARM::VTBX3, true, 3); return true;
1202     case ARM::VTBX4Pseudo: ExpandVTBL(MBBI, ARM::VTBX4, true, 4); return true;
1203   }
1204
1205   return false;
1206 }
1207
1208 bool ARMExpandPseudo::ExpandMBB(MachineBasicBlock &MBB) {
1209   bool Modified = false;
1210
1211   MachineBasicBlock::iterator MBBI = MBB.begin(), E = MBB.end();
1212   while (MBBI != E) {
1213     MachineBasicBlock::iterator NMBBI = llvm::next(MBBI);
1214     Modified |= ExpandMI(MBB, MBBI);
1215     MBBI = NMBBI;
1216   }
1217
1218   return Modified;
1219 }
1220
1221 bool ARMExpandPseudo::runOnMachineFunction(MachineFunction &MF) {
1222   TII = static_cast<const ARMBaseInstrInfo*>(MF.getTarget().getInstrInfo());
1223   TRI = MF.getTarget().getRegisterInfo();
1224   STI = &MF.getTarget().getSubtarget<ARMSubtarget>();
1225   AFI = MF.getInfo<ARMFunctionInfo>();
1226
1227   bool Modified = false;
1228   for (MachineFunction::iterator MFI = MF.begin(), E = MF.end(); MFI != E;
1229        ++MFI)
1230     Modified |= ExpandMBB(*MFI);
1231   return Modified;
1232 }
1233
1234 /// createARMExpandPseudoPass - returns an instance of the pseudo instruction
1235 /// expansion pass.
1236 FunctionPass *llvm::createARMExpandPseudoPass() {
1237   return new ARMExpandPseudo();
1238 }