]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/lib/Target/ARM/ARMExpandPseudoInsts.cpp
Merge llvm trunk r300422 and resolve conflicts.
[FreeBSD/FreeBSD.git] / contrib / llvm / lib / Target / ARM / ARMExpandPseudoInsts.cpp
1 //===-- ARMExpandPseudoInsts.cpp - Expand pseudo instructions -------------===//
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 #include "ARM.h"
18 #include "ARMBaseInstrInfo.h"
19 #include "ARMBaseRegisterInfo.h"
20 #include "ARMConstantPoolValue.h"
21 #include "ARMMachineFunctionInfo.h"
22 #include "ARMSubtarget.h"
23 #include "MCTargetDesc/ARMAddressingModes.h"
24 #include "llvm/CodeGen/LivePhysRegs.h"
25 #include "llvm/CodeGen/MachineFrameInfo.h"
26 #include "llvm/CodeGen/MachineFunctionPass.h"
27 #include "llvm/CodeGen/MachineInstrBuilder.h"
28 #include "llvm/CodeGen/MachineInstrBundle.h"
29 #include "llvm/IR/GlobalValue.h"
30 #include "llvm/Support/CommandLine.h"
31 #include "llvm/Support/raw_ostream.h" // FIXME: for debug only. remove!
32 #include "llvm/Target/TargetFrameLowering.h"
33 #include "llvm/Target/TargetRegisterInfo.h"
34
35 using namespace llvm;
36
37 #define DEBUG_TYPE "arm-pseudo"
38
39 static cl::opt<bool>
40 VerifyARMPseudo("verify-arm-pseudo-expand", cl::Hidden,
41                 cl::desc("Verify machine code after expanding ARM pseudos"));
42
43 namespace {
44   class ARMExpandPseudo : public MachineFunctionPass {
45   public:
46     static char ID;
47     ARMExpandPseudo() : MachineFunctionPass(ID) {}
48
49     const ARMBaseInstrInfo *TII;
50     const TargetRegisterInfo *TRI;
51     const ARMSubtarget *STI;
52     ARMFunctionInfo *AFI;
53
54     bool runOnMachineFunction(MachineFunction &Fn) override;
55
56     MachineFunctionProperties getRequiredProperties() const override {
57       return MachineFunctionProperties().set(
58           MachineFunctionProperties::Property::NoVRegs);
59     }
60
61     StringRef getPassName() const override {
62       return "ARM pseudo instruction expansion pass";
63     }
64
65   private:
66     void TransferImpOps(MachineInstr &OldMI,
67                         MachineInstrBuilder &UseMI, MachineInstrBuilder &DefMI);
68     bool ExpandMI(MachineBasicBlock &MBB,
69                   MachineBasicBlock::iterator MBBI,
70                   MachineBasicBlock::iterator &NextMBBI);
71     bool ExpandMBB(MachineBasicBlock &MBB);
72     void ExpandVLD(MachineBasicBlock::iterator &MBBI);
73     void ExpandVST(MachineBasicBlock::iterator &MBBI);
74     void ExpandLaneOp(MachineBasicBlock::iterator &MBBI);
75     void ExpandVTBL(MachineBasicBlock::iterator &MBBI,
76                     unsigned Opc, bool IsExt);
77     void ExpandMOV32BitImm(MachineBasicBlock &MBB,
78                            MachineBasicBlock::iterator &MBBI);
79     bool ExpandCMP_SWAP(MachineBasicBlock &MBB,
80                         MachineBasicBlock::iterator MBBI, unsigned LdrexOp,
81                         unsigned StrexOp, unsigned UxtOp,
82                         MachineBasicBlock::iterator &NextMBBI);
83
84     bool ExpandCMP_SWAP_64(MachineBasicBlock &MBB,
85                            MachineBasicBlock::iterator MBBI,
86                            MachineBasicBlock::iterator &NextMBBI);
87   };
88   char ARMExpandPseudo::ID = 0;
89 }
90
91 /// TransferImpOps - Transfer implicit operands on the pseudo instruction to
92 /// the instructions created from the expansion.
93 void ARMExpandPseudo::TransferImpOps(MachineInstr &OldMI,
94                                      MachineInstrBuilder &UseMI,
95                                      MachineInstrBuilder &DefMI) {
96   const MCInstrDesc &Desc = OldMI.getDesc();
97   for (unsigned i = Desc.getNumOperands(), e = OldMI.getNumOperands();
98        i != e; ++i) {
99     const MachineOperand &MO = OldMI.getOperand(i);
100     assert(MO.isReg() && MO.getReg());
101     if (MO.isUse())
102       UseMI.add(MO);
103     else
104       DefMI.add(MO);
105   }
106 }
107
108 namespace {
109   // Constants for register spacing in NEON load/store instructions.
110   // For quad-register load-lane and store-lane pseudo instructors, the
111   // spacing is initially assumed to be EvenDblSpc, and that is changed to
112   // OddDblSpc depending on the lane number operand.
113   enum NEONRegSpacing {
114     SingleSpc,
115     EvenDblSpc,
116     OddDblSpc
117   };
118
119   // Entries for NEON load/store information table.  The table is sorted by
120   // PseudoOpc for fast binary-search lookups.
121   struct NEONLdStTableEntry {
122     uint16_t PseudoOpc;
123     uint16_t RealOpc;
124     bool IsLoad;
125     bool isUpdating;
126     bool hasWritebackOperand;
127     uint8_t RegSpacing; // One of type NEONRegSpacing
128     uint8_t NumRegs; // D registers loaded or stored
129     uint8_t RegElts; // elements per D register; used for lane ops
130     // FIXME: Temporary flag to denote whether the real instruction takes
131     // a single register (like the encoding) or all of the registers in
132     // the list (like the asm syntax and the isel DAG). When all definitions
133     // are converted to take only the single encoded register, this will
134     // go away.
135     bool copyAllListRegs;
136
137     // Comparison methods for binary search of the table.
138     bool operator<(const NEONLdStTableEntry &TE) const {
139       return PseudoOpc < TE.PseudoOpc;
140     }
141     friend bool operator<(const NEONLdStTableEntry &TE, unsigned PseudoOpc) {
142       return TE.PseudoOpc < PseudoOpc;
143     }
144     friend bool LLVM_ATTRIBUTE_UNUSED operator<(unsigned PseudoOpc,
145                                                 const NEONLdStTableEntry &TE) {
146       return PseudoOpc < TE.PseudoOpc;
147     }
148   };
149 }
150
151 static const NEONLdStTableEntry NEONLdStTable[] = {
152 { ARM::VLD1LNq16Pseudo,     ARM::VLD1LNd16,     true, false, false, EvenDblSpc, 1, 4 ,true},
153 { ARM::VLD1LNq16Pseudo_UPD, ARM::VLD1LNd16_UPD, true, true, true,  EvenDblSpc, 1, 4 ,true},
154 { ARM::VLD1LNq32Pseudo,     ARM::VLD1LNd32,     true, false, false, EvenDblSpc, 1, 2 ,true},
155 { ARM::VLD1LNq32Pseudo_UPD, ARM::VLD1LNd32_UPD, true, true, true,  EvenDblSpc, 1, 2 ,true},
156 { ARM::VLD1LNq8Pseudo,      ARM::VLD1LNd8,      true, false, false, EvenDblSpc, 1, 8 ,true},
157 { ARM::VLD1LNq8Pseudo_UPD,  ARM::VLD1LNd8_UPD, true, true, true,  EvenDblSpc, 1, 8 ,true},
158
159 { ARM::VLD1d64QPseudo,      ARM::VLD1d64Q,     true,  false, false, SingleSpc,  4, 1 ,false},
160 { ARM::VLD1d64QPseudoWB_fixed,  ARM::VLD1d64Qwb_fixed,   true,  true, false, SingleSpc,  4, 1 ,false},
161 { ARM::VLD1d64TPseudo,      ARM::VLD1d64T,     true,  false, false, SingleSpc,  3, 1 ,false},
162 { ARM::VLD1d64TPseudoWB_fixed,  ARM::VLD1d64Twb_fixed,   true,  true, false, SingleSpc,  3, 1 ,false},
163
164 { ARM::VLD2LNd16Pseudo,     ARM::VLD2LNd16,     true, false, false, SingleSpc,  2, 4 ,true},
165 { ARM::VLD2LNd16Pseudo_UPD, ARM::VLD2LNd16_UPD, true, true, true,  SingleSpc,  2, 4 ,true},
166 { ARM::VLD2LNd32Pseudo,     ARM::VLD2LNd32,     true, false, false, SingleSpc,  2, 2 ,true},
167 { ARM::VLD2LNd32Pseudo_UPD, ARM::VLD2LNd32_UPD, true, true, true,  SingleSpc,  2, 2 ,true},
168 { ARM::VLD2LNd8Pseudo,      ARM::VLD2LNd8,      true, false, false, SingleSpc,  2, 8 ,true},
169 { ARM::VLD2LNd8Pseudo_UPD,  ARM::VLD2LNd8_UPD, true, true, true,  SingleSpc,  2, 8 ,true},
170 { ARM::VLD2LNq16Pseudo,     ARM::VLD2LNq16,     true, false, false, EvenDblSpc, 2, 4 ,true},
171 { ARM::VLD2LNq16Pseudo_UPD, ARM::VLD2LNq16_UPD, true, true, true,  EvenDblSpc, 2, 4 ,true},
172 { ARM::VLD2LNq32Pseudo,     ARM::VLD2LNq32,     true, false, false, EvenDblSpc, 2, 2 ,true},
173 { ARM::VLD2LNq32Pseudo_UPD, ARM::VLD2LNq32_UPD, true, true, true,  EvenDblSpc, 2, 2 ,true},
174
175 { ARM::VLD2q16Pseudo,       ARM::VLD2q16,      true,  false, false, SingleSpc,  4, 4 ,false},
176 { ARM::VLD2q16PseudoWB_fixed,   ARM::VLD2q16wb_fixed, true, true, false,  SingleSpc,  4, 4 ,false},
177 { ARM::VLD2q16PseudoWB_register,   ARM::VLD2q16wb_register, true, true, true,  SingleSpc,  4, 4 ,false},
178 { ARM::VLD2q32Pseudo,       ARM::VLD2q32,      true,  false, false, SingleSpc,  4, 2 ,false},
179 { ARM::VLD2q32PseudoWB_fixed,   ARM::VLD2q32wb_fixed, true, true, false,  SingleSpc,  4, 2 ,false},
180 { ARM::VLD2q32PseudoWB_register,   ARM::VLD2q32wb_register, true, true, true,  SingleSpc,  4, 2 ,false},
181 { ARM::VLD2q8Pseudo,        ARM::VLD2q8,       true,  false, false, SingleSpc,  4, 8 ,false},
182 { ARM::VLD2q8PseudoWB_fixed,    ARM::VLD2q8wb_fixed, true, true, false,  SingleSpc,  4, 8 ,false},
183 { ARM::VLD2q8PseudoWB_register,    ARM::VLD2q8wb_register, true, true, true,  SingleSpc,  4, 8 ,false},
184
185 { ARM::VLD3DUPd16Pseudo,     ARM::VLD3DUPd16,     true, false, false, SingleSpc, 3, 4,true},
186 { ARM::VLD3DUPd16Pseudo_UPD, ARM::VLD3DUPd16_UPD, true, true, true,  SingleSpc, 3, 4,true},
187 { ARM::VLD3DUPd32Pseudo,     ARM::VLD3DUPd32,     true, false, false, SingleSpc, 3, 2,true},
188 { ARM::VLD3DUPd32Pseudo_UPD, ARM::VLD3DUPd32_UPD, true, true, true,  SingleSpc, 3, 2,true},
189 { ARM::VLD3DUPd8Pseudo,      ARM::VLD3DUPd8,      true, false, false, SingleSpc, 3, 8,true},
190 { ARM::VLD3DUPd8Pseudo_UPD,  ARM::VLD3DUPd8_UPD, true, true, true,  SingleSpc, 3, 8,true},
191
192 { ARM::VLD3LNd16Pseudo,     ARM::VLD3LNd16,     true, false, false, SingleSpc,  3, 4 ,true},
193 { ARM::VLD3LNd16Pseudo_UPD, ARM::VLD3LNd16_UPD, true, true, true,  SingleSpc,  3, 4 ,true},
194 { ARM::VLD3LNd32Pseudo,     ARM::VLD3LNd32,     true, false, false, SingleSpc,  3, 2 ,true},
195 { ARM::VLD3LNd32Pseudo_UPD, ARM::VLD3LNd32_UPD, true, true, true,  SingleSpc,  3, 2 ,true},
196 { ARM::VLD3LNd8Pseudo,      ARM::VLD3LNd8,      true, false, false, SingleSpc,  3, 8 ,true},
197 { ARM::VLD3LNd8Pseudo_UPD,  ARM::VLD3LNd8_UPD, true, true, true,  SingleSpc,  3, 8 ,true},
198 { ARM::VLD3LNq16Pseudo,     ARM::VLD3LNq16,     true, false, false, EvenDblSpc, 3, 4 ,true},
199 { ARM::VLD3LNq16Pseudo_UPD, ARM::VLD3LNq16_UPD, true, true, true,  EvenDblSpc, 3, 4 ,true},
200 { ARM::VLD3LNq32Pseudo,     ARM::VLD3LNq32,     true, false, false, EvenDblSpc, 3, 2 ,true},
201 { ARM::VLD3LNq32Pseudo_UPD, ARM::VLD3LNq32_UPD, true, true, true,  EvenDblSpc, 3, 2 ,true},
202
203 { ARM::VLD3d16Pseudo,       ARM::VLD3d16,      true,  false, false, SingleSpc,  3, 4 ,true},
204 { ARM::VLD3d16Pseudo_UPD,   ARM::VLD3d16_UPD, true, true, true,  SingleSpc,  3, 4 ,true},
205 { ARM::VLD3d32Pseudo,       ARM::VLD3d32,      true,  false, false, SingleSpc,  3, 2 ,true},
206 { ARM::VLD3d32Pseudo_UPD,   ARM::VLD3d32_UPD, true, true, true,  SingleSpc,  3, 2 ,true},
207 { ARM::VLD3d8Pseudo,        ARM::VLD3d8,       true,  false, false, SingleSpc,  3, 8 ,true},
208 { ARM::VLD3d8Pseudo_UPD,    ARM::VLD3d8_UPD, true, true, true,  SingleSpc,  3, 8 ,true},
209
210 { ARM::VLD3q16Pseudo_UPD,    ARM::VLD3q16_UPD, true, true, true,  EvenDblSpc, 3, 4 ,true},
211 { ARM::VLD3q16oddPseudo,     ARM::VLD3q16,     true,  false, false, OddDblSpc,  3, 4 ,true},
212 { ARM::VLD3q16oddPseudo_UPD, ARM::VLD3q16_UPD, true, true, true,  OddDblSpc,  3, 4 ,true},
213 { ARM::VLD3q32Pseudo_UPD,    ARM::VLD3q32_UPD, true, true, true,  EvenDblSpc, 3, 2 ,true},
214 { ARM::VLD3q32oddPseudo,     ARM::VLD3q32,     true,  false, false, OddDblSpc,  3, 2 ,true},
215 { ARM::VLD3q32oddPseudo_UPD, ARM::VLD3q32_UPD, true, true, true,  OddDblSpc,  3, 2 ,true},
216 { ARM::VLD3q8Pseudo_UPD,     ARM::VLD3q8_UPD, true, true, true,  EvenDblSpc, 3, 8 ,true},
217 { ARM::VLD3q8oddPseudo,      ARM::VLD3q8,      true,  false, false, OddDblSpc,  3, 8 ,true},
218 { ARM::VLD3q8oddPseudo_UPD,  ARM::VLD3q8_UPD, true, true, true,  OddDblSpc,  3, 8 ,true},
219
220 { ARM::VLD4DUPd16Pseudo,     ARM::VLD4DUPd16,     true, false, false, SingleSpc, 4, 4,true},
221 { ARM::VLD4DUPd16Pseudo_UPD, ARM::VLD4DUPd16_UPD, true, true, true,  SingleSpc, 4, 4,true},
222 { ARM::VLD4DUPd32Pseudo,     ARM::VLD4DUPd32,     true, false, false, SingleSpc, 4, 2,true},
223 { ARM::VLD4DUPd32Pseudo_UPD, ARM::VLD4DUPd32_UPD, true, true, true,  SingleSpc, 4, 2,true},
224 { ARM::VLD4DUPd8Pseudo,      ARM::VLD4DUPd8,      true, false, false, SingleSpc, 4, 8,true},
225 { ARM::VLD4DUPd8Pseudo_UPD,  ARM::VLD4DUPd8_UPD, true, true, true,  SingleSpc, 4, 8,true},
226
227 { ARM::VLD4LNd16Pseudo,     ARM::VLD4LNd16,     true, false, false, SingleSpc,  4, 4 ,true},
228 { ARM::VLD4LNd16Pseudo_UPD, ARM::VLD4LNd16_UPD, true, true, true,  SingleSpc,  4, 4 ,true},
229 { ARM::VLD4LNd32Pseudo,     ARM::VLD4LNd32,     true, false, false, SingleSpc,  4, 2 ,true},
230 { ARM::VLD4LNd32Pseudo_UPD, ARM::VLD4LNd32_UPD, true, true, true,  SingleSpc,  4, 2 ,true},
231 { ARM::VLD4LNd8Pseudo,      ARM::VLD4LNd8,      true, false, false, SingleSpc,  4, 8 ,true},
232 { ARM::VLD4LNd8Pseudo_UPD,  ARM::VLD4LNd8_UPD, true, true, true,  SingleSpc,  4, 8 ,true},
233 { ARM::VLD4LNq16Pseudo,     ARM::VLD4LNq16,     true, false, false, EvenDblSpc, 4, 4 ,true},
234 { ARM::VLD4LNq16Pseudo_UPD, ARM::VLD4LNq16_UPD, true, true, true,  EvenDblSpc, 4, 4 ,true},
235 { ARM::VLD4LNq32Pseudo,     ARM::VLD4LNq32,     true, false, false, EvenDblSpc, 4, 2 ,true},
236 { ARM::VLD4LNq32Pseudo_UPD, ARM::VLD4LNq32_UPD, true, true, true,  EvenDblSpc, 4, 2 ,true},
237
238 { ARM::VLD4d16Pseudo,       ARM::VLD4d16,      true,  false, false, SingleSpc,  4, 4 ,true},
239 { ARM::VLD4d16Pseudo_UPD,   ARM::VLD4d16_UPD, true, true, true,  SingleSpc,  4, 4 ,true},
240 { ARM::VLD4d32Pseudo,       ARM::VLD4d32,      true,  false, false, SingleSpc,  4, 2 ,true},
241 { ARM::VLD4d32Pseudo_UPD,   ARM::VLD4d32_UPD, true, true, true,  SingleSpc,  4, 2 ,true},
242 { ARM::VLD4d8Pseudo,        ARM::VLD4d8,       true,  false, false, SingleSpc,  4, 8 ,true},
243 { ARM::VLD4d8Pseudo_UPD,    ARM::VLD4d8_UPD, true, true, true,  SingleSpc,  4, 8 ,true},
244
245 { ARM::VLD4q16Pseudo_UPD,    ARM::VLD4q16_UPD, true, true, true,  EvenDblSpc, 4, 4 ,true},
246 { ARM::VLD4q16oddPseudo,     ARM::VLD4q16,     true,  false, false, OddDblSpc,  4, 4 ,true},
247 { ARM::VLD4q16oddPseudo_UPD, ARM::VLD4q16_UPD, true, true, true,  OddDblSpc,  4, 4 ,true},
248 { ARM::VLD4q32Pseudo_UPD,    ARM::VLD4q32_UPD, true, true, true,  EvenDblSpc, 4, 2 ,true},
249 { ARM::VLD4q32oddPseudo,     ARM::VLD4q32,     true,  false, false, OddDblSpc,  4, 2 ,true},
250 { ARM::VLD4q32oddPseudo_UPD, ARM::VLD4q32_UPD, true, true, true,  OddDblSpc,  4, 2 ,true},
251 { ARM::VLD4q8Pseudo_UPD,     ARM::VLD4q8_UPD, true, true, true,  EvenDblSpc, 4, 8 ,true},
252 { ARM::VLD4q8oddPseudo,      ARM::VLD4q8,      true,  false, false, OddDblSpc,  4, 8 ,true},
253 { ARM::VLD4q8oddPseudo_UPD,  ARM::VLD4q8_UPD, true, true, true,  OddDblSpc,  4, 8 ,true},
254
255 { ARM::VST1LNq16Pseudo,     ARM::VST1LNd16,    false, false, false, EvenDblSpc, 1, 4 ,true},
256 { ARM::VST1LNq16Pseudo_UPD, ARM::VST1LNd16_UPD, false, true, true,  EvenDblSpc, 1, 4 ,true},
257 { ARM::VST1LNq32Pseudo,     ARM::VST1LNd32,    false, false, false, EvenDblSpc, 1, 2 ,true},
258 { ARM::VST1LNq32Pseudo_UPD, ARM::VST1LNd32_UPD, false, true, true,  EvenDblSpc, 1, 2 ,true},
259 { ARM::VST1LNq8Pseudo,      ARM::VST1LNd8,     false, false, false, EvenDblSpc, 1, 8 ,true},
260 { ARM::VST1LNq8Pseudo_UPD,  ARM::VST1LNd8_UPD, false, true, true,  EvenDblSpc, 1, 8 ,true},
261
262 { ARM::VST1d64QPseudo,      ARM::VST1d64Q,     false, false, false, SingleSpc,  4, 1 ,false},
263 { ARM::VST1d64QPseudoWB_fixed,  ARM::VST1d64Qwb_fixed, false, true, false,  SingleSpc,  4, 1 ,false},
264 { ARM::VST1d64QPseudoWB_register, ARM::VST1d64Qwb_register, false, true, true,  SingleSpc,  4, 1 ,false},
265 { ARM::VST1d64TPseudo,      ARM::VST1d64T,     false, false, false, SingleSpc,  3, 1 ,false},
266 { ARM::VST1d64TPseudoWB_fixed,  ARM::VST1d64Twb_fixed, false, true, false,  SingleSpc,  3, 1 ,false},
267 { ARM::VST1d64TPseudoWB_register,  ARM::VST1d64Twb_register, false, true, true,  SingleSpc,  3, 1 ,false},
268
269 { ARM::VST2LNd16Pseudo,     ARM::VST2LNd16,     false, false, false, SingleSpc, 2, 4 ,true},
270 { ARM::VST2LNd16Pseudo_UPD, ARM::VST2LNd16_UPD, false, true, true,  SingleSpc, 2, 4 ,true},
271 { ARM::VST2LNd32Pseudo,     ARM::VST2LNd32,     false, false, false, SingleSpc, 2, 2 ,true},
272 { ARM::VST2LNd32Pseudo_UPD, ARM::VST2LNd32_UPD, false, true, true,  SingleSpc, 2, 2 ,true},
273 { ARM::VST2LNd8Pseudo,      ARM::VST2LNd8,      false, false, false, SingleSpc, 2, 8 ,true},
274 { ARM::VST2LNd8Pseudo_UPD,  ARM::VST2LNd8_UPD, false, true, true,  SingleSpc, 2, 8 ,true},
275 { ARM::VST2LNq16Pseudo,     ARM::VST2LNq16,     false, false, false, EvenDblSpc, 2, 4,true},
276 { ARM::VST2LNq16Pseudo_UPD, ARM::VST2LNq16_UPD, false, true, true,  EvenDblSpc, 2, 4,true},
277 { ARM::VST2LNq32Pseudo,     ARM::VST2LNq32,     false, false, false, EvenDblSpc, 2, 2,true},
278 { ARM::VST2LNq32Pseudo_UPD, ARM::VST2LNq32_UPD, false, true, true,  EvenDblSpc, 2, 2,true},
279
280 { ARM::VST2q16Pseudo,       ARM::VST2q16,      false, false, false, SingleSpc,  4, 4 ,false},
281 { ARM::VST2q16PseudoWB_fixed,   ARM::VST2q16wb_fixed, false, true, false,  SingleSpc,  4, 4 ,false},
282 { ARM::VST2q16PseudoWB_register,   ARM::VST2q16wb_register, false, true, true,  SingleSpc,  4, 4 ,false},
283 { ARM::VST2q32Pseudo,       ARM::VST2q32,      false, false, false, SingleSpc,  4, 2 ,false},
284 { ARM::VST2q32PseudoWB_fixed,   ARM::VST2q32wb_fixed, false, true, false,  SingleSpc,  4, 2 ,false},
285 { ARM::VST2q32PseudoWB_register,   ARM::VST2q32wb_register, false, true, true,  SingleSpc,  4, 2 ,false},
286 { ARM::VST2q8Pseudo,        ARM::VST2q8,       false, false, false, SingleSpc,  4, 8 ,false},
287 { ARM::VST2q8PseudoWB_fixed,    ARM::VST2q8wb_fixed, false, true, false,  SingleSpc,  4, 8 ,false},
288 { ARM::VST2q8PseudoWB_register,    ARM::VST2q8wb_register, false, true, true,  SingleSpc,  4, 8 ,false},
289
290 { ARM::VST3LNd16Pseudo,     ARM::VST3LNd16,     false, false, false, SingleSpc, 3, 4 ,true},
291 { ARM::VST3LNd16Pseudo_UPD, ARM::VST3LNd16_UPD, false, true, true,  SingleSpc, 3, 4 ,true},
292 { ARM::VST3LNd32Pseudo,     ARM::VST3LNd32,     false, false, false, SingleSpc, 3, 2 ,true},
293 { ARM::VST3LNd32Pseudo_UPD, ARM::VST3LNd32_UPD, false, true, true,  SingleSpc, 3, 2 ,true},
294 { ARM::VST3LNd8Pseudo,      ARM::VST3LNd8,      false, false, false, SingleSpc, 3, 8 ,true},
295 { ARM::VST3LNd8Pseudo_UPD,  ARM::VST3LNd8_UPD, false, true, true,  SingleSpc, 3, 8 ,true},
296 { ARM::VST3LNq16Pseudo,     ARM::VST3LNq16,     false, false, false, EvenDblSpc, 3, 4,true},
297 { ARM::VST3LNq16Pseudo_UPD, ARM::VST3LNq16_UPD, false, true, true,  EvenDblSpc, 3, 4,true},
298 { ARM::VST3LNq32Pseudo,     ARM::VST3LNq32,     false, false, false, EvenDblSpc, 3, 2,true},
299 { ARM::VST3LNq32Pseudo_UPD, ARM::VST3LNq32_UPD, false, true, true,  EvenDblSpc, 3, 2,true},
300
301 { ARM::VST3d16Pseudo,       ARM::VST3d16,      false, false, false, SingleSpc,  3, 4 ,true},
302 { ARM::VST3d16Pseudo_UPD,   ARM::VST3d16_UPD, false, true, true,  SingleSpc,  3, 4 ,true},
303 { ARM::VST3d32Pseudo,       ARM::VST3d32,      false, false, false, SingleSpc,  3, 2 ,true},
304 { ARM::VST3d32Pseudo_UPD,   ARM::VST3d32_UPD, false, true, true,  SingleSpc,  3, 2 ,true},
305 { ARM::VST3d8Pseudo,        ARM::VST3d8,       false, false, false, SingleSpc,  3, 8 ,true},
306 { ARM::VST3d8Pseudo_UPD,    ARM::VST3d8_UPD, false, true, true,  SingleSpc,  3, 8 ,true},
307
308 { ARM::VST3q16Pseudo_UPD,    ARM::VST3q16_UPD, false, true, true,  EvenDblSpc, 3, 4 ,true},
309 { ARM::VST3q16oddPseudo,     ARM::VST3q16,     false, false, false, OddDblSpc,  3, 4 ,true},
310 { ARM::VST3q16oddPseudo_UPD, ARM::VST3q16_UPD, false, true, true,  OddDblSpc,  3, 4 ,true},
311 { ARM::VST3q32Pseudo_UPD,    ARM::VST3q32_UPD, false, true, true,  EvenDblSpc, 3, 2 ,true},
312 { ARM::VST3q32oddPseudo,     ARM::VST3q32,     false, false, false, OddDblSpc,  3, 2 ,true},
313 { ARM::VST3q32oddPseudo_UPD, ARM::VST3q32_UPD, false, true, true,  OddDblSpc,  3, 2 ,true},
314 { ARM::VST3q8Pseudo_UPD,     ARM::VST3q8_UPD, false, true, true,  EvenDblSpc, 3, 8 ,true},
315 { ARM::VST3q8oddPseudo,      ARM::VST3q8,      false, false, false, OddDblSpc,  3, 8 ,true},
316 { ARM::VST3q8oddPseudo_UPD,  ARM::VST3q8_UPD, false, true, true,  OddDblSpc,  3, 8 ,true},
317
318 { ARM::VST4LNd16Pseudo,     ARM::VST4LNd16,     false, false, false, SingleSpc, 4, 4 ,true},
319 { ARM::VST4LNd16Pseudo_UPD, ARM::VST4LNd16_UPD, false, true, true,  SingleSpc, 4, 4 ,true},
320 { ARM::VST4LNd32Pseudo,     ARM::VST4LNd32,     false, false, false, SingleSpc, 4, 2 ,true},
321 { ARM::VST4LNd32Pseudo_UPD, ARM::VST4LNd32_UPD, false, true, true,  SingleSpc, 4, 2 ,true},
322 { ARM::VST4LNd8Pseudo,      ARM::VST4LNd8,      false, false, false, SingleSpc, 4, 8 ,true},
323 { ARM::VST4LNd8Pseudo_UPD,  ARM::VST4LNd8_UPD, false, true, true,  SingleSpc, 4, 8 ,true},
324 { ARM::VST4LNq16Pseudo,     ARM::VST4LNq16,     false, false, false, EvenDblSpc, 4, 4,true},
325 { ARM::VST4LNq16Pseudo_UPD, ARM::VST4LNq16_UPD, false, true, true,  EvenDblSpc, 4, 4,true},
326 { ARM::VST4LNq32Pseudo,     ARM::VST4LNq32,     false, false, false, EvenDblSpc, 4, 2,true},
327 { ARM::VST4LNq32Pseudo_UPD, ARM::VST4LNq32_UPD, false, true, true,  EvenDblSpc, 4, 2,true},
328
329 { ARM::VST4d16Pseudo,       ARM::VST4d16,      false, false, false, SingleSpc,  4, 4 ,true},
330 { ARM::VST4d16Pseudo_UPD,   ARM::VST4d16_UPD, false, true, true,  SingleSpc,  4, 4 ,true},
331 { ARM::VST4d32Pseudo,       ARM::VST4d32,      false, false, false, SingleSpc,  4, 2 ,true},
332 { ARM::VST4d32Pseudo_UPD,   ARM::VST4d32_UPD, false, true, true,  SingleSpc,  4, 2 ,true},
333 { ARM::VST4d8Pseudo,        ARM::VST4d8,       false, false, false, SingleSpc,  4, 8 ,true},
334 { ARM::VST4d8Pseudo_UPD,    ARM::VST4d8_UPD, false, true, true,  SingleSpc,  4, 8 ,true},
335
336 { ARM::VST4q16Pseudo_UPD,    ARM::VST4q16_UPD, false, true, true,  EvenDblSpc, 4, 4 ,true},
337 { ARM::VST4q16oddPseudo,     ARM::VST4q16,     false, false, false, OddDblSpc,  4, 4 ,true},
338 { ARM::VST4q16oddPseudo_UPD, ARM::VST4q16_UPD, false, true, true,  OddDblSpc,  4, 4 ,true},
339 { ARM::VST4q32Pseudo_UPD,    ARM::VST4q32_UPD, false, true, true,  EvenDblSpc, 4, 2 ,true},
340 { ARM::VST4q32oddPseudo,     ARM::VST4q32,     false, false, false, OddDblSpc,  4, 2 ,true},
341 { ARM::VST4q32oddPseudo_UPD, ARM::VST4q32_UPD, false, true, true,  OddDblSpc,  4, 2 ,true},
342 { ARM::VST4q8Pseudo_UPD,     ARM::VST4q8_UPD, false, true, true,  EvenDblSpc, 4, 8 ,true},
343 { ARM::VST4q8oddPseudo,      ARM::VST4q8,      false, false, false, OddDblSpc,  4, 8 ,true},
344 { ARM::VST4q8oddPseudo_UPD,  ARM::VST4q8_UPD, false, true, true,  OddDblSpc,  4, 8 ,true}
345 };
346
347 /// LookupNEONLdSt - Search the NEONLdStTable for information about a NEON
348 /// load or store pseudo instruction.
349 static const NEONLdStTableEntry *LookupNEONLdSt(unsigned Opcode) {
350 #ifndef NDEBUG
351   // Make sure the table is sorted.
352   static bool TableChecked = false;
353   if (!TableChecked) {
354     assert(std::is_sorted(std::begin(NEONLdStTable), std::end(NEONLdStTable)) &&
355            "NEONLdStTable is not sorted!");
356     TableChecked = true;
357   }
358 #endif
359
360   auto I = std::lower_bound(std::begin(NEONLdStTable),
361                             std::end(NEONLdStTable), Opcode);
362   if (I != std::end(NEONLdStTable) && I->PseudoOpc == Opcode)
363     return I;
364   return nullptr;
365 }
366
367 /// GetDSubRegs - Get 4 D subregisters of a Q, QQ, or QQQQ register,
368 /// corresponding to the specified register spacing.  Not all of the results
369 /// are necessarily valid, e.g., a Q register only has 2 D subregisters.
370 static void GetDSubRegs(unsigned Reg, NEONRegSpacing RegSpc,
371                         const TargetRegisterInfo *TRI, unsigned &D0,
372                         unsigned &D1, unsigned &D2, unsigned &D3) {
373   if (RegSpc == SingleSpc) {
374     D0 = TRI->getSubReg(Reg, ARM::dsub_0);
375     D1 = TRI->getSubReg(Reg, ARM::dsub_1);
376     D2 = TRI->getSubReg(Reg, ARM::dsub_2);
377     D3 = TRI->getSubReg(Reg, ARM::dsub_3);
378   } else if (RegSpc == EvenDblSpc) {
379     D0 = TRI->getSubReg(Reg, ARM::dsub_0);
380     D1 = TRI->getSubReg(Reg, ARM::dsub_2);
381     D2 = TRI->getSubReg(Reg, ARM::dsub_4);
382     D3 = TRI->getSubReg(Reg, ARM::dsub_6);
383   } else {
384     assert(RegSpc == OddDblSpc && "unknown register spacing");
385     D0 = TRI->getSubReg(Reg, ARM::dsub_1);
386     D1 = TRI->getSubReg(Reg, ARM::dsub_3);
387     D2 = TRI->getSubReg(Reg, ARM::dsub_5);
388     D3 = TRI->getSubReg(Reg, ARM::dsub_7);
389   }
390 }
391
392 /// ExpandVLD - Translate VLD pseudo instructions with Q, QQ or QQQQ register
393 /// operands to real VLD instructions with D register operands.
394 void ARMExpandPseudo::ExpandVLD(MachineBasicBlock::iterator &MBBI) {
395   MachineInstr &MI = *MBBI;
396   MachineBasicBlock &MBB = *MI.getParent();
397
398   const NEONLdStTableEntry *TableEntry = LookupNEONLdSt(MI.getOpcode());
399   assert(TableEntry && TableEntry->IsLoad && "NEONLdStTable lookup failed");
400   NEONRegSpacing RegSpc = (NEONRegSpacing)TableEntry->RegSpacing;
401   unsigned NumRegs = TableEntry->NumRegs;
402
403   MachineInstrBuilder MIB = BuildMI(MBB, MBBI, MI.getDebugLoc(),
404                                     TII->get(TableEntry->RealOpc));
405   unsigned OpIdx = 0;
406
407   bool DstIsDead = MI.getOperand(OpIdx).isDead();
408   unsigned DstReg = MI.getOperand(OpIdx++).getReg();
409   unsigned D0, D1, D2, D3;
410   GetDSubRegs(DstReg, RegSpc, TRI, D0, D1, D2, D3);
411   MIB.addReg(D0, RegState::Define | getDeadRegState(DstIsDead));
412   if (NumRegs > 1 && TableEntry->copyAllListRegs)
413     MIB.addReg(D1, RegState::Define | getDeadRegState(DstIsDead));
414   if (NumRegs > 2 && TableEntry->copyAllListRegs)
415     MIB.addReg(D2, RegState::Define | getDeadRegState(DstIsDead));
416   if (NumRegs > 3 && TableEntry->copyAllListRegs)
417     MIB.addReg(D3, RegState::Define | getDeadRegState(DstIsDead));
418
419   if (TableEntry->isUpdating)
420     MIB.add(MI.getOperand(OpIdx++));
421
422   // Copy the addrmode6 operands.
423   MIB.add(MI.getOperand(OpIdx++));
424   MIB.add(MI.getOperand(OpIdx++));
425   // Copy the am6offset operand.
426   if (TableEntry->hasWritebackOperand)
427     MIB.add(MI.getOperand(OpIdx++));
428
429   // For an instruction writing double-spaced subregs, the pseudo instruction
430   // has an extra operand that is a use of the super-register.  Record the
431   // operand index and skip over it.
432   unsigned SrcOpIdx = 0;
433   if (RegSpc == EvenDblSpc || RegSpc == OddDblSpc)
434     SrcOpIdx = OpIdx++;
435
436   // Copy the predicate operands.
437   MIB.add(MI.getOperand(OpIdx++));
438   MIB.add(MI.getOperand(OpIdx++));
439
440   // Copy the super-register source operand used for double-spaced subregs over
441   // to the new instruction as an implicit operand.
442   if (SrcOpIdx != 0) {
443     MachineOperand MO = MI.getOperand(SrcOpIdx);
444     MO.setImplicit(true);
445     MIB.add(MO);
446   }
447   // Add an implicit def for the super-register.
448   MIB.addReg(DstReg, RegState::ImplicitDefine | getDeadRegState(DstIsDead));
449   TransferImpOps(MI, MIB, MIB);
450
451   // Transfer memoperands.
452   MIB->setMemRefs(MI.memoperands_begin(), MI.memoperands_end());
453
454   MI.eraseFromParent();
455 }
456
457 /// ExpandVST - Translate VST pseudo instructions with Q, QQ or QQQQ register
458 /// operands to real VST instructions with D register operands.
459 void ARMExpandPseudo::ExpandVST(MachineBasicBlock::iterator &MBBI) {
460   MachineInstr &MI = *MBBI;
461   MachineBasicBlock &MBB = *MI.getParent();
462
463   const NEONLdStTableEntry *TableEntry = LookupNEONLdSt(MI.getOpcode());
464   assert(TableEntry && !TableEntry->IsLoad && "NEONLdStTable lookup failed");
465   NEONRegSpacing RegSpc = (NEONRegSpacing)TableEntry->RegSpacing;
466   unsigned NumRegs = TableEntry->NumRegs;
467
468   MachineInstrBuilder MIB = BuildMI(MBB, MBBI, MI.getDebugLoc(),
469                                     TII->get(TableEntry->RealOpc));
470   unsigned OpIdx = 0;
471   if (TableEntry->isUpdating)
472     MIB.add(MI.getOperand(OpIdx++));
473
474   // Copy the addrmode6 operands.
475   MIB.add(MI.getOperand(OpIdx++));
476   MIB.add(MI.getOperand(OpIdx++));
477   // Copy the am6offset operand.
478   if (TableEntry->hasWritebackOperand)
479     MIB.add(MI.getOperand(OpIdx++));
480
481   bool SrcIsKill = MI.getOperand(OpIdx).isKill();
482   bool SrcIsUndef = MI.getOperand(OpIdx).isUndef();
483   unsigned SrcReg = MI.getOperand(OpIdx++).getReg();
484   unsigned D0, D1, D2, D3;
485   GetDSubRegs(SrcReg, RegSpc, TRI, D0, D1, D2, D3);
486   MIB.addReg(D0, getUndefRegState(SrcIsUndef));
487   if (NumRegs > 1 && TableEntry->copyAllListRegs)
488     MIB.addReg(D1, getUndefRegState(SrcIsUndef));
489   if (NumRegs > 2 && TableEntry->copyAllListRegs)
490     MIB.addReg(D2, getUndefRegState(SrcIsUndef));
491   if (NumRegs > 3 && TableEntry->copyAllListRegs)
492     MIB.addReg(D3, getUndefRegState(SrcIsUndef));
493
494   // Copy the predicate operands.
495   MIB.add(MI.getOperand(OpIdx++));
496   MIB.add(MI.getOperand(OpIdx++));
497
498   if (SrcIsKill && !SrcIsUndef) // Add an implicit kill for the super-reg.
499     MIB->addRegisterKilled(SrcReg, TRI, true);
500   else if (!SrcIsUndef)
501     MIB.addReg(SrcReg, RegState::Implicit); // Add implicit uses for src reg.
502   TransferImpOps(MI, MIB, MIB);
503
504   // Transfer memoperands.
505   MIB->setMemRefs(MI.memoperands_begin(), MI.memoperands_end());
506
507   MI.eraseFromParent();
508 }
509
510 /// ExpandLaneOp - Translate VLD*LN and VST*LN instructions with Q, QQ or QQQQ
511 /// register operands to real instructions with D register operands.
512 void ARMExpandPseudo::ExpandLaneOp(MachineBasicBlock::iterator &MBBI) {
513   MachineInstr &MI = *MBBI;
514   MachineBasicBlock &MBB = *MI.getParent();
515
516   const NEONLdStTableEntry *TableEntry = LookupNEONLdSt(MI.getOpcode());
517   assert(TableEntry && "NEONLdStTable lookup failed");
518   NEONRegSpacing RegSpc = (NEONRegSpacing)TableEntry->RegSpacing;
519   unsigned NumRegs = TableEntry->NumRegs;
520   unsigned RegElts = TableEntry->RegElts;
521
522   MachineInstrBuilder MIB = BuildMI(MBB, MBBI, MI.getDebugLoc(),
523                                     TII->get(TableEntry->RealOpc));
524   unsigned OpIdx = 0;
525   // The lane operand is always the 3rd from last operand, before the 2
526   // predicate operands.
527   unsigned Lane = MI.getOperand(MI.getDesc().getNumOperands() - 3).getImm();
528
529   // Adjust the lane and spacing as needed for Q registers.
530   assert(RegSpc != OddDblSpc && "unexpected register spacing for VLD/VST-lane");
531   if (RegSpc == EvenDblSpc && Lane >= RegElts) {
532     RegSpc = OddDblSpc;
533     Lane -= RegElts;
534   }
535   assert(Lane < RegElts && "out of range lane for VLD/VST-lane");
536
537   unsigned D0 = 0, D1 = 0, D2 = 0, D3 = 0;
538   unsigned DstReg = 0;
539   bool DstIsDead = false;
540   if (TableEntry->IsLoad) {
541     DstIsDead = MI.getOperand(OpIdx).isDead();
542     DstReg = MI.getOperand(OpIdx++).getReg();
543     GetDSubRegs(DstReg, RegSpc, TRI, D0, D1, D2, D3);
544     MIB.addReg(D0, RegState::Define | getDeadRegState(DstIsDead));
545     if (NumRegs > 1)
546       MIB.addReg(D1, RegState::Define | getDeadRegState(DstIsDead));
547     if (NumRegs > 2)
548       MIB.addReg(D2, RegState::Define | getDeadRegState(DstIsDead));
549     if (NumRegs > 3)
550       MIB.addReg(D3, RegState::Define | getDeadRegState(DstIsDead));
551   }
552
553   if (TableEntry->isUpdating)
554     MIB.add(MI.getOperand(OpIdx++));
555
556   // Copy the addrmode6 operands.
557   MIB.add(MI.getOperand(OpIdx++));
558   MIB.add(MI.getOperand(OpIdx++));
559   // Copy the am6offset operand.
560   if (TableEntry->hasWritebackOperand)
561     MIB.add(MI.getOperand(OpIdx++));
562
563   // Grab the super-register source.
564   MachineOperand MO = MI.getOperand(OpIdx++);
565   if (!TableEntry->IsLoad)
566     GetDSubRegs(MO.getReg(), RegSpc, TRI, D0, D1, D2, D3);
567
568   // Add the subregs as sources of the new instruction.
569   unsigned SrcFlags = (getUndefRegState(MO.isUndef()) |
570                        getKillRegState(MO.isKill()));
571   MIB.addReg(D0, SrcFlags);
572   if (NumRegs > 1)
573     MIB.addReg(D1, SrcFlags);
574   if (NumRegs > 2)
575     MIB.addReg(D2, SrcFlags);
576   if (NumRegs > 3)
577     MIB.addReg(D3, SrcFlags);
578
579   // Add the lane number operand.
580   MIB.addImm(Lane);
581   OpIdx += 1;
582
583   // Copy the predicate operands.
584   MIB.add(MI.getOperand(OpIdx++));
585   MIB.add(MI.getOperand(OpIdx++));
586
587   // Copy the super-register source to be an implicit source.
588   MO.setImplicit(true);
589   MIB.add(MO);
590   if (TableEntry->IsLoad)
591     // Add an implicit def for the super-register.
592     MIB.addReg(DstReg, RegState::ImplicitDefine | getDeadRegState(DstIsDead));
593   TransferImpOps(MI, MIB, MIB);
594   // Transfer memoperands.
595   MIB->setMemRefs(MI.memoperands_begin(), MI.memoperands_end());
596   MI.eraseFromParent();
597 }
598
599 /// ExpandVTBL - Translate VTBL and VTBX pseudo instructions with Q or QQ
600 /// register operands to real instructions with D register operands.
601 void ARMExpandPseudo::ExpandVTBL(MachineBasicBlock::iterator &MBBI,
602                                  unsigned Opc, bool IsExt) {
603   MachineInstr &MI = *MBBI;
604   MachineBasicBlock &MBB = *MI.getParent();
605
606   MachineInstrBuilder MIB = BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(Opc));
607   unsigned OpIdx = 0;
608
609   // Transfer the destination register operand.
610   MIB.add(MI.getOperand(OpIdx++));
611   if (IsExt)
612     MIB.add(MI.getOperand(OpIdx++));
613
614   bool SrcIsKill = MI.getOperand(OpIdx).isKill();
615   unsigned SrcReg = MI.getOperand(OpIdx++).getReg();
616   unsigned D0, D1, D2, D3;
617   GetDSubRegs(SrcReg, SingleSpc, TRI, D0, D1, D2, D3);
618   MIB.addReg(D0);
619
620   // Copy the other source register operand.
621   MIB.add(MI.getOperand(OpIdx++));
622
623   // Copy the predicate operands.
624   MIB.add(MI.getOperand(OpIdx++));
625   MIB.add(MI.getOperand(OpIdx++));
626
627   // Add an implicit kill and use for the super-reg.
628   MIB.addReg(SrcReg, RegState::Implicit | getKillRegState(SrcIsKill));
629   TransferImpOps(MI, MIB, MIB);
630   MI.eraseFromParent();
631 }
632
633 static bool IsAnAddressOperand(const MachineOperand &MO) {
634   // This check is overly conservative.  Unless we are certain that the machine
635   // operand is not a symbol reference, we return that it is a symbol reference.
636   // This is important as the load pair may not be split up Windows.
637   switch (MO.getType()) {
638   case MachineOperand::MO_Register:
639   case MachineOperand::MO_Immediate:
640   case MachineOperand::MO_CImmediate:
641   case MachineOperand::MO_FPImmediate:
642     return false;
643   case MachineOperand::MO_MachineBasicBlock:
644     return true;
645   case MachineOperand::MO_FrameIndex:
646     return false;
647   case MachineOperand::MO_ConstantPoolIndex:
648   case MachineOperand::MO_TargetIndex:
649   case MachineOperand::MO_JumpTableIndex:
650   case MachineOperand::MO_ExternalSymbol:
651   case MachineOperand::MO_GlobalAddress:
652   case MachineOperand::MO_BlockAddress:
653     return true;
654   case MachineOperand::MO_RegisterMask:
655   case MachineOperand::MO_RegisterLiveOut:
656     return false;
657   case MachineOperand::MO_Metadata:
658   case MachineOperand::MO_MCSymbol:
659     return true;
660   case MachineOperand::MO_CFIIndex:
661     return false;
662   case MachineOperand::MO_IntrinsicID:
663   case MachineOperand::MO_Predicate:
664   case MachineOperand::MO_Placeholder:
665     llvm_unreachable("should not exist post-isel");
666   }
667   llvm_unreachable("unhandled machine operand type");
668 }
669
670 void ARMExpandPseudo::ExpandMOV32BitImm(MachineBasicBlock &MBB,
671                                         MachineBasicBlock::iterator &MBBI) {
672   MachineInstr &MI = *MBBI;
673   unsigned Opcode = MI.getOpcode();
674   unsigned PredReg = 0;
675   ARMCC::CondCodes Pred = getInstrPredicate(MI, PredReg);
676   unsigned DstReg = MI.getOperand(0).getReg();
677   bool DstIsDead = MI.getOperand(0).isDead();
678   bool isCC = Opcode == ARM::MOVCCi32imm || Opcode == ARM::t2MOVCCi32imm;
679   const MachineOperand &MO = MI.getOperand(isCC ? 2 : 1);
680   bool RequiresBundling = STI->isTargetWindows() && IsAnAddressOperand(MO);
681   MachineInstrBuilder LO16, HI16;
682
683   if (!STI->hasV6T2Ops() &&
684       (Opcode == ARM::MOVi32imm || Opcode == ARM::MOVCCi32imm)) {
685     // FIXME Windows CE supports older ARM CPUs
686     assert(!STI->isTargetWindows() && "Windows on ARM requires ARMv7+");
687
688     // Expand into a movi + orr.
689     LO16 = BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(ARM::MOVi), DstReg);
690     HI16 = BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(ARM::ORRri))
691       .addReg(DstReg, RegState::Define | getDeadRegState(DstIsDead))
692       .addReg(DstReg);
693
694     assert (MO.isImm() && "MOVi32imm w/ non-immediate source operand!");
695     unsigned ImmVal = (unsigned)MO.getImm();
696     unsigned SOImmValV1 = ARM_AM::getSOImmTwoPartFirst(ImmVal);
697     unsigned SOImmValV2 = ARM_AM::getSOImmTwoPartSecond(ImmVal);
698     LO16 = LO16.addImm(SOImmValV1);
699     HI16 = HI16.addImm(SOImmValV2);
700     LO16->setMemRefs(MI.memoperands_begin(), MI.memoperands_end());
701     HI16->setMemRefs(MI.memoperands_begin(), MI.memoperands_end());
702     LO16.addImm(Pred).addReg(PredReg).add(condCodeOp());
703     HI16.addImm(Pred).addReg(PredReg).add(condCodeOp());
704     TransferImpOps(MI, LO16, HI16);
705     MI.eraseFromParent();
706     return;
707   }
708
709   unsigned LO16Opc = 0;
710   unsigned HI16Opc = 0;
711   if (Opcode == ARM::t2MOVi32imm || Opcode == ARM::t2MOVCCi32imm) {
712     LO16Opc = ARM::t2MOVi16;
713     HI16Opc = ARM::t2MOVTi16;
714   } else {
715     LO16Opc = ARM::MOVi16;
716     HI16Opc = ARM::MOVTi16;
717   }
718
719   LO16 = BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(LO16Opc), DstReg);
720   HI16 = BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(HI16Opc))
721     .addReg(DstReg, RegState::Define | getDeadRegState(DstIsDead))
722     .addReg(DstReg);
723
724   switch (MO.getType()) {
725   case MachineOperand::MO_Immediate: {
726     unsigned Imm = MO.getImm();
727     unsigned Lo16 = Imm & 0xffff;
728     unsigned Hi16 = (Imm >> 16) & 0xffff;
729     LO16 = LO16.addImm(Lo16);
730     HI16 = HI16.addImm(Hi16);
731     break;
732   }
733   case MachineOperand::MO_ExternalSymbol: {
734     const char *ES = MO.getSymbolName();
735     unsigned TF = MO.getTargetFlags();
736     LO16 = LO16.addExternalSymbol(ES, TF | ARMII::MO_LO16);
737     HI16 = HI16.addExternalSymbol(ES, TF | ARMII::MO_HI16);
738     break;
739   }
740   default: {
741     const GlobalValue *GV = MO.getGlobal();
742     unsigned TF = MO.getTargetFlags();
743     LO16 = LO16.addGlobalAddress(GV, MO.getOffset(), TF | ARMII::MO_LO16);
744     HI16 = HI16.addGlobalAddress(GV, MO.getOffset(), TF | ARMII::MO_HI16);
745     break;
746   }
747   }
748
749   LO16->setMemRefs(MI.memoperands_begin(), MI.memoperands_end());
750   HI16->setMemRefs(MI.memoperands_begin(), MI.memoperands_end());
751   LO16.addImm(Pred).addReg(PredReg);
752   HI16.addImm(Pred).addReg(PredReg);
753
754   if (RequiresBundling)
755     finalizeBundle(MBB, LO16->getIterator(), MBBI->getIterator());
756
757   TransferImpOps(MI, LO16, HI16);
758   MI.eraseFromParent();
759 }
760
761 static void addPostLoopLiveIns(MachineBasicBlock *MBB, LivePhysRegs &LiveRegs) {
762   for (auto I = LiveRegs.begin(); I != LiveRegs.end(); ++I)
763     MBB->addLiveIn(*I);
764 }
765
766 /// Expand a CMP_SWAP pseudo-inst to an ldrex/strex loop as simply as
767 /// possible. This only gets used at -O0 so we don't care about efficiency of the
768 /// generated code.
769 bool ARMExpandPseudo::ExpandCMP_SWAP(MachineBasicBlock &MBB,
770                                      MachineBasicBlock::iterator MBBI,
771                                      unsigned LdrexOp, unsigned StrexOp,
772                                      unsigned UxtOp,
773                                      MachineBasicBlock::iterator &NextMBBI) {
774   bool IsThumb = STI->isThumb();
775   MachineInstr &MI = *MBBI;
776   DebugLoc DL = MI.getDebugLoc();
777   MachineOperand &Dest = MI.getOperand(0);
778   unsigned StatusReg = MI.getOperand(1).getReg();
779   MachineOperand &Addr = MI.getOperand(2);
780   MachineOperand &Desired = MI.getOperand(3);
781   MachineOperand &New = MI.getOperand(4);
782
783   LivePhysRegs LiveRegs(&TII->getRegisterInfo());
784   LiveRegs.addLiveOuts(MBB);
785   for (auto I = std::prev(MBB.end()); I != MBBI; --I)
786     LiveRegs.stepBackward(*I);
787
788   MachineFunction *MF = MBB.getParent();
789   auto LoadCmpBB = MF->CreateMachineBasicBlock(MBB.getBasicBlock());
790   auto StoreBB = MF->CreateMachineBasicBlock(MBB.getBasicBlock());
791   auto DoneBB = MF->CreateMachineBasicBlock(MBB.getBasicBlock());
792
793   MF->insert(++MBB.getIterator(), LoadCmpBB);
794   MF->insert(++LoadCmpBB->getIterator(), StoreBB);
795   MF->insert(++StoreBB->getIterator(), DoneBB);
796
797   if (UxtOp) {
798     MachineInstrBuilder MIB =
799         BuildMI(MBB, MBBI, DL, TII->get(UxtOp), Desired.getReg())
800             .addReg(Desired.getReg(), RegState::Kill);
801     if (!IsThumb)
802       MIB.addImm(0);
803     MIB.add(predOps(ARMCC::AL));
804   }
805
806   // .Lloadcmp:
807   //     ldrex rDest, [rAddr]
808   //     cmp rDest, rDesired
809   //     bne .Ldone
810   LoadCmpBB->addLiveIn(Addr.getReg());
811   LoadCmpBB->addLiveIn(Dest.getReg());
812   LoadCmpBB->addLiveIn(Desired.getReg());
813   addPostLoopLiveIns(LoadCmpBB, LiveRegs);
814
815   MachineInstrBuilder MIB;
816   MIB = BuildMI(LoadCmpBB, DL, TII->get(LdrexOp), Dest.getReg());
817   MIB.addReg(Addr.getReg());
818   if (LdrexOp == ARM::t2LDREX)
819     MIB.addImm(0); // a 32-bit Thumb ldrex (only) allows an offset.
820   MIB.add(predOps(ARMCC::AL));
821
822   unsigned CMPrr = IsThumb ? ARM::tCMPhir : ARM::CMPrr;
823   BuildMI(LoadCmpBB, DL, TII->get(CMPrr))
824       .addReg(Dest.getReg(), getKillRegState(Dest.isDead()))
825       .add(Desired)
826       .add(predOps(ARMCC::AL));
827   unsigned Bcc = IsThumb ? ARM::tBcc : ARM::Bcc;
828   BuildMI(LoadCmpBB, DL, TII->get(Bcc))
829       .addMBB(DoneBB)
830       .addImm(ARMCC::NE)
831       .addReg(ARM::CPSR, RegState::Kill);
832   LoadCmpBB->addSuccessor(DoneBB);
833   LoadCmpBB->addSuccessor(StoreBB);
834
835   // .Lstore:
836   //     strex rStatus, rNew, [rAddr]
837   //     cmp rStatus, #0
838   //     bne .Lloadcmp
839   StoreBB->addLiveIn(Addr.getReg());
840   StoreBB->addLiveIn(New.getReg());
841   addPostLoopLiveIns(StoreBB, LiveRegs);
842
843
844   MIB = BuildMI(StoreBB, DL, TII->get(StrexOp), StatusReg);
845   MIB.add(New);
846   MIB.add(Addr);
847   if (StrexOp == ARM::t2STREX)
848     MIB.addImm(0); // a 32-bit Thumb strex (only) allows an offset.
849   MIB.add(predOps(ARMCC::AL));
850
851   unsigned CMPri = IsThumb ? ARM::t2CMPri : ARM::CMPri;
852   BuildMI(StoreBB, DL, TII->get(CMPri))
853       .addReg(StatusReg, RegState::Kill)
854       .addImm(0)
855       .add(predOps(ARMCC::AL));
856   BuildMI(StoreBB, DL, TII->get(Bcc))
857       .addMBB(LoadCmpBB)
858       .addImm(ARMCC::NE)
859       .addReg(ARM::CPSR, RegState::Kill);
860   StoreBB->addSuccessor(LoadCmpBB);
861   StoreBB->addSuccessor(DoneBB);
862
863   DoneBB->splice(DoneBB->end(), &MBB, MI, MBB.end());
864   DoneBB->transferSuccessors(&MBB);
865   addPostLoopLiveIns(DoneBB, LiveRegs);
866
867   MBB.addSuccessor(LoadCmpBB);
868
869   NextMBBI = MBB.end();
870   MI.eraseFromParent();
871   return true;
872 }
873
874 /// ARM's ldrexd/strexd take a consecutive register pair (represented as a
875 /// single GPRPair register), Thumb's take two separate registers so we need to
876 /// extract the subregs from the pair.
877 static void addExclusiveRegPair(MachineInstrBuilder &MIB, MachineOperand &Reg,
878                                 unsigned Flags, bool IsThumb,
879                                 const TargetRegisterInfo *TRI) {
880   if (IsThumb) {
881     unsigned RegLo = TRI->getSubReg(Reg.getReg(), ARM::gsub_0);
882     unsigned RegHi = TRI->getSubReg(Reg.getReg(), ARM::gsub_1);
883     MIB.addReg(RegLo, Flags | getKillRegState(Reg.isDead()));
884     MIB.addReg(RegHi, Flags | getKillRegState(Reg.isDead()));
885   } else
886     MIB.addReg(Reg.getReg(), Flags | getKillRegState(Reg.isDead()));
887 }
888
889 /// Expand a 64-bit CMP_SWAP to an ldrexd/strexd loop.
890 bool ARMExpandPseudo::ExpandCMP_SWAP_64(MachineBasicBlock &MBB,
891                                         MachineBasicBlock::iterator MBBI,
892                                         MachineBasicBlock::iterator &NextMBBI) {
893   bool IsThumb = STI->isThumb();
894   MachineInstr &MI = *MBBI;
895   DebugLoc DL = MI.getDebugLoc();
896   MachineOperand &Dest = MI.getOperand(0);
897   unsigned StatusReg = MI.getOperand(1).getReg();
898   MachineOperand &Addr = MI.getOperand(2);
899   MachineOperand &Desired = MI.getOperand(3);
900   MachineOperand &New = MI.getOperand(4);
901
902   unsigned DestLo = TRI->getSubReg(Dest.getReg(), ARM::gsub_0);
903   unsigned DestHi = TRI->getSubReg(Dest.getReg(), ARM::gsub_1);
904   unsigned DesiredLo = TRI->getSubReg(Desired.getReg(), ARM::gsub_0);
905   unsigned DesiredHi = TRI->getSubReg(Desired.getReg(), ARM::gsub_1);
906
907   LivePhysRegs LiveRegs(&TII->getRegisterInfo());
908   LiveRegs.addLiveOuts(MBB);
909   for (auto I = std::prev(MBB.end()); I != MBBI; --I)
910     LiveRegs.stepBackward(*I);
911
912   MachineFunction *MF = MBB.getParent();
913   auto LoadCmpBB = MF->CreateMachineBasicBlock(MBB.getBasicBlock());
914   auto StoreBB = MF->CreateMachineBasicBlock(MBB.getBasicBlock());
915   auto DoneBB = MF->CreateMachineBasicBlock(MBB.getBasicBlock());
916
917   MF->insert(++MBB.getIterator(), LoadCmpBB);
918   MF->insert(++LoadCmpBB->getIterator(), StoreBB);
919   MF->insert(++StoreBB->getIterator(), DoneBB);
920
921   // .Lloadcmp:
922   //     ldrexd rDestLo, rDestHi, [rAddr]
923   //     cmp rDestLo, rDesiredLo
924   //     sbcs rStatus<dead>, rDestHi, rDesiredHi
925   //     bne .Ldone
926   LoadCmpBB->addLiveIn(Addr.getReg());
927   LoadCmpBB->addLiveIn(Dest.getReg());
928   LoadCmpBB->addLiveIn(Desired.getReg());
929   addPostLoopLiveIns(LoadCmpBB, LiveRegs);
930
931   unsigned LDREXD = IsThumb ? ARM::t2LDREXD : ARM::LDREXD;
932   MachineInstrBuilder MIB;
933   MIB = BuildMI(LoadCmpBB, DL, TII->get(LDREXD));
934   addExclusiveRegPair(MIB, Dest, RegState::Define, IsThumb, TRI);
935   MIB.addReg(Addr.getReg()).add(predOps(ARMCC::AL));
936
937   unsigned CMPrr = IsThumb ? ARM::tCMPhir : ARM::CMPrr;
938   BuildMI(LoadCmpBB, DL, TII->get(CMPrr))
939       .addReg(DestLo, getKillRegState(Dest.isDead()))
940       .addReg(DesiredLo, getKillRegState(Desired.isDead()))
941       .add(predOps(ARMCC::AL));
942
943   BuildMI(LoadCmpBB, DL, TII->get(CMPrr))
944       .addReg(DestHi, getKillRegState(Dest.isDead()))
945       .addReg(DesiredHi, getKillRegState(Desired.isDead()))
946       .addImm(ARMCC::EQ).addReg(ARM::CPSR, RegState::Kill);
947
948   unsigned Bcc = IsThumb ? ARM::tBcc : ARM::Bcc;
949   BuildMI(LoadCmpBB, DL, TII->get(Bcc))
950       .addMBB(DoneBB)
951       .addImm(ARMCC::NE)
952       .addReg(ARM::CPSR, RegState::Kill);
953   LoadCmpBB->addSuccessor(DoneBB);
954   LoadCmpBB->addSuccessor(StoreBB);
955
956   // .Lstore:
957   //     strexd rStatus, rNewLo, rNewHi, [rAddr]
958   //     cmp rStatus, #0
959   //     bne .Lloadcmp
960   StoreBB->addLiveIn(Addr.getReg());
961   StoreBB->addLiveIn(New.getReg());
962   addPostLoopLiveIns(StoreBB, LiveRegs);
963
964   unsigned STREXD = IsThumb ? ARM::t2STREXD : ARM::STREXD;
965   MIB = BuildMI(StoreBB, DL, TII->get(STREXD), StatusReg);
966   addExclusiveRegPair(MIB, New, 0, IsThumb, TRI);
967   MIB.add(Addr).add(predOps(ARMCC::AL));
968
969   unsigned CMPri = IsThumb ? ARM::t2CMPri : ARM::CMPri;
970   BuildMI(StoreBB, DL, TII->get(CMPri))
971       .addReg(StatusReg, RegState::Kill)
972       .addImm(0)
973       .add(predOps(ARMCC::AL));
974   BuildMI(StoreBB, DL, TII->get(Bcc))
975       .addMBB(LoadCmpBB)
976       .addImm(ARMCC::NE)
977       .addReg(ARM::CPSR, RegState::Kill);
978   StoreBB->addSuccessor(LoadCmpBB);
979   StoreBB->addSuccessor(DoneBB);
980
981   DoneBB->splice(DoneBB->end(), &MBB, MI, MBB.end());
982   DoneBB->transferSuccessors(&MBB);
983   addPostLoopLiveIns(DoneBB, LiveRegs);
984
985   MBB.addSuccessor(LoadCmpBB);
986
987   NextMBBI = MBB.end();
988   MI.eraseFromParent();
989   return true;
990 }
991
992
993 bool ARMExpandPseudo::ExpandMI(MachineBasicBlock &MBB,
994                                MachineBasicBlock::iterator MBBI,
995                                MachineBasicBlock::iterator &NextMBBI) {
996   MachineInstr &MI = *MBBI;
997   unsigned Opcode = MI.getOpcode();
998   switch (Opcode) {
999     default:
1000       return false;
1001
1002     case ARM::TCRETURNdi:
1003     case ARM::TCRETURNri: {
1004       MachineBasicBlock::iterator MBBI = MBB.getLastNonDebugInstr();
1005       assert(MBBI->isReturn() &&
1006              "Can only insert epilog into returning blocks");
1007       unsigned RetOpcode = MBBI->getOpcode();
1008       DebugLoc dl = MBBI->getDebugLoc();
1009       const ARMBaseInstrInfo &TII = *static_cast<const ARMBaseInstrInfo *>(
1010           MBB.getParent()->getSubtarget().getInstrInfo());
1011
1012       // Tail call return: adjust the stack pointer and jump to callee.
1013       MBBI = MBB.getLastNonDebugInstr();
1014       MachineOperand &JumpTarget = MBBI->getOperand(0);
1015
1016       // Jump to label or value in register.
1017       if (RetOpcode == ARM::TCRETURNdi) {
1018         unsigned TCOpcode =
1019             STI->isThumb()
1020                 ? (STI->isTargetMachO() ? ARM::tTAILJMPd : ARM::tTAILJMPdND)
1021                 : ARM::TAILJMPd;
1022         MachineInstrBuilder MIB = BuildMI(MBB, MBBI, dl, TII.get(TCOpcode));
1023         if (JumpTarget.isGlobal())
1024           MIB.addGlobalAddress(JumpTarget.getGlobal(), JumpTarget.getOffset(),
1025                                JumpTarget.getTargetFlags());
1026         else {
1027           assert(JumpTarget.isSymbol());
1028           MIB.addExternalSymbol(JumpTarget.getSymbolName(),
1029                                 JumpTarget.getTargetFlags());
1030         }
1031
1032         // Add the default predicate in Thumb mode.
1033         if (STI->isThumb())
1034           MIB.add(predOps(ARMCC::AL));
1035       } else if (RetOpcode == ARM::TCRETURNri) {
1036         BuildMI(MBB, MBBI, dl,
1037                 TII.get(STI->isThumb() ? ARM::tTAILJMPr : ARM::TAILJMPr))
1038             .addReg(JumpTarget.getReg(), RegState::Kill);
1039       }
1040
1041       auto NewMI = std::prev(MBBI);
1042       for (unsigned i = 1, e = MBBI->getNumOperands(); i != e; ++i)
1043         NewMI->addOperand(MBBI->getOperand(i));
1044
1045       // Delete the pseudo instruction TCRETURN.
1046       MBB.erase(MBBI);
1047       MBBI = NewMI;
1048       return true;
1049     }
1050     case ARM::VMOVScc:
1051     case ARM::VMOVDcc: {
1052       unsigned newOpc = Opcode == ARM::VMOVScc ? ARM::VMOVS : ARM::VMOVD;
1053       BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(newOpc),
1054               MI.getOperand(1).getReg())
1055           .add(MI.getOperand(2))
1056           .addImm(MI.getOperand(3).getImm()) // 'pred'
1057           .add(MI.getOperand(4));
1058
1059       MI.eraseFromParent();
1060       return true;
1061     }
1062     case ARM::t2MOVCCr:
1063     case ARM::MOVCCr: {
1064       unsigned Opc = AFI->isThumbFunction() ? ARM::t2MOVr : ARM::MOVr;
1065       BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(Opc),
1066               MI.getOperand(1).getReg())
1067           .add(MI.getOperand(2))
1068           .addImm(MI.getOperand(3).getImm()) // 'pred'
1069           .add(MI.getOperand(4))
1070           .add(condCodeOp()); // 's' bit
1071
1072       MI.eraseFromParent();
1073       return true;
1074     }
1075     case ARM::MOVCCsi: {
1076       BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(ARM::MOVsi),
1077               (MI.getOperand(1).getReg()))
1078           .add(MI.getOperand(2))
1079           .addImm(MI.getOperand(3).getImm())
1080           .addImm(MI.getOperand(4).getImm()) // 'pred'
1081           .add(MI.getOperand(5))
1082           .add(condCodeOp()); // 's' bit
1083
1084       MI.eraseFromParent();
1085       return true;
1086     }
1087     case ARM::MOVCCsr: {
1088       BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(ARM::MOVsr),
1089               (MI.getOperand(1).getReg()))
1090           .add(MI.getOperand(2))
1091           .add(MI.getOperand(3))
1092           .addImm(MI.getOperand(4).getImm())
1093           .addImm(MI.getOperand(5).getImm()) // 'pred'
1094           .add(MI.getOperand(6))
1095           .add(condCodeOp()); // 's' bit
1096
1097       MI.eraseFromParent();
1098       return true;
1099     }
1100     case ARM::t2MOVCCi16:
1101     case ARM::MOVCCi16: {
1102       unsigned NewOpc = AFI->isThumbFunction() ? ARM::t2MOVi16 : ARM::MOVi16;
1103       BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(NewOpc),
1104               MI.getOperand(1).getReg())
1105           .addImm(MI.getOperand(2).getImm())
1106           .addImm(MI.getOperand(3).getImm()) // 'pred'
1107           .add(MI.getOperand(4));
1108       MI.eraseFromParent();
1109       return true;
1110     }
1111     case ARM::t2MOVCCi:
1112     case ARM::MOVCCi: {
1113       unsigned Opc = AFI->isThumbFunction() ? ARM::t2MOVi : ARM::MOVi;
1114       BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(Opc),
1115               MI.getOperand(1).getReg())
1116           .addImm(MI.getOperand(2).getImm())
1117           .addImm(MI.getOperand(3).getImm()) // 'pred'
1118           .add(MI.getOperand(4))
1119           .add(condCodeOp()); // 's' bit
1120
1121       MI.eraseFromParent();
1122       return true;
1123     }
1124     case ARM::t2MVNCCi:
1125     case ARM::MVNCCi: {
1126       unsigned Opc = AFI->isThumbFunction() ? ARM::t2MVNi : ARM::MVNi;
1127       BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(Opc),
1128               MI.getOperand(1).getReg())
1129           .addImm(MI.getOperand(2).getImm())
1130           .addImm(MI.getOperand(3).getImm()) // 'pred'
1131           .add(MI.getOperand(4))
1132           .add(condCodeOp()); // 's' bit
1133
1134       MI.eraseFromParent();
1135       return true;
1136     }
1137     case ARM::t2MOVCClsl:
1138     case ARM::t2MOVCClsr:
1139     case ARM::t2MOVCCasr:
1140     case ARM::t2MOVCCror: {
1141       unsigned NewOpc;
1142       switch (Opcode) {
1143       case ARM::t2MOVCClsl: NewOpc = ARM::t2LSLri; break;
1144       case ARM::t2MOVCClsr: NewOpc = ARM::t2LSRri; break;
1145       case ARM::t2MOVCCasr: NewOpc = ARM::t2ASRri; break;
1146       case ARM::t2MOVCCror: NewOpc = ARM::t2RORri; break;
1147       default: llvm_unreachable("unexpeced conditional move");
1148       }
1149       BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(NewOpc),
1150               MI.getOperand(1).getReg())
1151           .add(MI.getOperand(2))
1152           .addImm(MI.getOperand(3).getImm())
1153           .addImm(MI.getOperand(4).getImm()) // 'pred'
1154           .add(MI.getOperand(5))
1155           .add(condCodeOp()); // 's' bit
1156       MI.eraseFromParent();
1157       return true;
1158     }
1159     case ARM::Int_eh_sjlj_dispatchsetup: {
1160       MachineFunction &MF = *MI.getParent()->getParent();
1161       const ARMBaseInstrInfo *AII =
1162         static_cast<const ARMBaseInstrInfo*>(TII);
1163       const ARMBaseRegisterInfo &RI = AII->getRegisterInfo();
1164       // For functions using a base pointer, we rematerialize it (via the frame
1165       // pointer) here since eh.sjlj.setjmp and eh.sjlj.longjmp don't do it
1166       // for us. Otherwise, expand to nothing.
1167       if (RI.hasBasePointer(MF)) {
1168         int32_t NumBytes = AFI->getFramePtrSpillOffset();
1169         unsigned FramePtr = RI.getFrameRegister(MF);
1170         assert(MF.getSubtarget().getFrameLowering()->hasFP(MF) &&
1171                "base pointer without frame pointer?");
1172
1173         if (AFI->isThumb2Function()) {
1174           emitT2RegPlusImmediate(MBB, MBBI, MI.getDebugLoc(), ARM::R6,
1175                                  FramePtr, -NumBytes, ARMCC::AL, 0, *TII);
1176         } else if (AFI->isThumbFunction()) {
1177           emitThumbRegPlusImmediate(MBB, MBBI, MI.getDebugLoc(), ARM::R6,
1178                                     FramePtr, -NumBytes, *TII, RI);
1179         } else {
1180           emitARMRegPlusImmediate(MBB, MBBI, MI.getDebugLoc(), ARM::R6,
1181                                   FramePtr, -NumBytes, ARMCC::AL, 0,
1182                                   *TII);
1183         }
1184         // If there's dynamic realignment, adjust for it.
1185         if (RI.needsStackRealignment(MF)) {
1186           MachineFrameInfo &MFI = MF.getFrameInfo();
1187           unsigned MaxAlign = MFI.getMaxAlignment();
1188           assert (!AFI->isThumb1OnlyFunction());
1189           // Emit bic r6, r6, MaxAlign
1190           assert(MaxAlign <= 256 && "The BIC instruction cannot encode "
1191                                     "immediates larger than 256 with all lower "
1192                                     "bits set.");
1193           unsigned bicOpc = AFI->isThumbFunction() ?
1194             ARM::t2BICri : ARM::BICri;
1195           BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(bicOpc), ARM::R6)
1196               .addReg(ARM::R6, RegState::Kill)
1197               .addImm(MaxAlign - 1)
1198               .add(predOps(ARMCC::AL))
1199               .add(condCodeOp());
1200         }
1201
1202       }
1203       MI.eraseFromParent();
1204       return true;
1205     }
1206
1207     case ARM::MOVsrl_flag:
1208     case ARM::MOVsra_flag: {
1209       // These are just fancy MOVs instructions.
1210       BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(ARM::MOVsi),
1211               MI.getOperand(0).getReg())
1212           .add(MI.getOperand(1))
1213           .addImm(ARM_AM::getSORegOpc(
1214               (Opcode == ARM::MOVsrl_flag ? ARM_AM::lsr : ARM_AM::asr), 1))
1215           .add(predOps(ARMCC::AL))
1216           .addReg(ARM::CPSR, RegState::Define);
1217       MI.eraseFromParent();
1218       return true;
1219     }
1220     case ARM::RRX: {
1221       // This encodes as "MOVs Rd, Rm, rrx
1222       MachineInstrBuilder MIB =
1223           BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(ARM::MOVsi),
1224                   MI.getOperand(0).getReg())
1225               .add(MI.getOperand(1))
1226               .addImm(ARM_AM::getSORegOpc(ARM_AM::rrx, 0))
1227               .add(predOps(ARMCC::AL))
1228               .add(condCodeOp());
1229       TransferImpOps(MI, MIB, MIB);
1230       MI.eraseFromParent();
1231       return true;
1232     }
1233     case ARM::tTPsoft:
1234     case ARM::TPsoft: {
1235       const bool Thumb = Opcode == ARM::tTPsoft;
1236
1237       MachineInstrBuilder MIB;
1238       if (STI->genLongCalls()) {
1239         MachineFunction *MF = MBB.getParent();
1240         MachineConstantPool *MCP = MF->getConstantPool();
1241         unsigned PCLabelID = AFI->createPICLabelUId();
1242         MachineConstantPoolValue *CPV =
1243             ARMConstantPoolSymbol::Create(MF->getFunction()->getContext(),
1244                                           "__aeabi_read_tp", PCLabelID, 0);
1245         unsigned Reg = MI.getOperand(0).getReg();
1246         MIB = BuildMI(MBB, MBBI, MI.getDebugLoc(),
1247                       TII->get(Thumb ? ARM::tLDRpci : ARM::LDRi12), Reg)
1248                   .addConstantPoolIndex(MCP->getConstantPoolIndex(CPV, 4));
1249         if (!Thumb)
1250           MIB.addImm(0);
1251         MIB.add(predOps(ARMCC::AL));
1252
1253         MIB = BuildMI(MBB, MBBI, MI.getDebugLoc(),
1254                       TII->get(Thumb ? ARM::tBLXr : ARM::BLX));
1255         if (Thumb)
1256           MIB.add(predOps(ARMCC::AL));
1257         MIB.addReg(Reg, RegState::Kill);
1258       } else {
1259         MIB = BuildMI(MBB, MBBI, MI.getDebugLoc(),
1260                       TII->get(Thumb ? ARM::tBL : ARM::BL));
1261         if (Thumb)
1262           MIB.add(predOps(ARMCC::AL));
1263         MIB.addExternalSymbol("__aeabi_read_tp", 0);
1264       }
1265
1266       MIB->setMemRefs(MI.memoperands_begin(), MI.memoperands_end());
1267       TransferImpOps(MI, MIB, MIB);
1268       MI.eraseFromParent();
1269       return true;
1270     }
1271     case ARM::tLDRpci_pic:
1272     case ARM::t2LDRpci_pic: {
1273       unsigned NewLdOpc = (Opcode == ARM::tLDRpci_pic)
1274         ? ARM::tLDRpci : ARM::t2LDRpci;
1275       unsigned DstReg = MI.getOperand(0).getReg();
1276       bool DstIsDead = MI.getOperand(0).isDead();
1277       MachineInstrBuilder MIB1 =
1278           BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(NewLdOpc), DstReg)
1279               .add(MI.getOperand(1))
1280               .add(predOps(ARMCC::AL));
1281       MIB1->setMemRefs(MI.memoperands_begin(), MI.memoperands_end());
1282       MachineInstrBuilder MIB2 =
1283           BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(ARM::tPICADD))
1284               .addReg(DstReg, RegState::Define | getDeadRegState(DstIsDead))
1285               .addReg(DstReg)
1286               .add(MI.getOperand(2));
1287       TransferImpOps(MI, MIB1, MIB2);
1288       MI.eraseFromParent();
1289       return true;
1290     }
1291
1292     case ARM::LDRLIT_ga_abs:
1293     case ARM::LDRLIT_ga_pcrel:
1294     case ARM::LDRLIT_ga_pcrel_ldr:
1295     case ARM::tLDRLIT_ga_abs:
1296     case ARM::tLDRLIT_ga_pcrel: {
1297       unsigned DstReg = MI.getOperand(0).getReg();
1298       bool DstIsDead = MI.getOperand(0).isDead();
1299       const MachineOperand &MO1 = MI.getOperand(1);
1300       const GlobalValue *GV = MO1.getGlobal();
1301       bool IsARM =
1302           Opcode != ARM::tLDRLIT_ga_pcrel && Opcode != ARM::tLDRLIT_ga_abs;
1303       bool IsPIC =
1304           Opcode != ARM::LDRLIT_ga_abs && Opcode != ARM::tLDRLIT_ga_abs;
1305       unsigned LDRLITOpc = IsARM ? ARM::LDRi12 : ARM::tLDRpci;
1306       unsigned PICAddOpc =
1307           IsARM
1308               ? (Opcode == ARM::LDRLIT_ga_pcrel_ldr ? ARM::PICLDR : ARM::PICADD)
1309               : ARM::tPICADD;
1310
1311       // We need a new const-pool entry to load from.
1312       MachineConstantPool *MCP = MBB.getParent()->getConstantPool();
1313       unsigned ARMPCLabelIndex = 0;
1314       MachineConstantPoolValue *CPV;
1315
1316       if (IsPIC) {
1317         unsigned PCAdj = IsARM ? 8 : 4;
1318         ARMPCLabelIndex = AFI->createPICLabelUId();
1319         CPV = ARMConstantPoolConstant::Create(GV, ARMPCLabelIndex,
1320                                               ARMCP::CPValue, PCAdj);
1321       } else
1322         CPV = ARMConstantPoolConstant::Create(GV, ARMCP::no_modifier);
1323
1324       MachineInstrBuilder MIB =
1325           BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(LDRLITOpc), DstReg)
1326             .addConstantPoolIndex(MCP->getConstantPoolIndex(CPV, 4));
1327       if (IsARM)
1328         MIB.addImm(0);
1329       MIB.add(predOps(ARMCC::AL));
1330
1331       if (IsPIC) {
1332         MachineInstrBuilder MIB =
1333           BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(PICAddOpc))
1334             .addReg(DstReg, RegState::Define | getDeadRegState(DstIsDead))
1335             .addReg(DstReg)
1336             .addImm(ARMPCLabelIndex);
1337
1338         if (IsARM)
1339           MIB.add(predOps(ARMCC::AL));
1340       }
1341
1342       MI.eraseFromParent();
1343       return true;
1344     }
1345     case ARM::MOV_ga_pcrel:
1346     case ARM::MOV_ga_pcrel_ldr:
1347     case ARM::t2MOV_ga_pcrel: {
1348       // Expand into movw + movw. Also "add pc" / ldr [pc] in PIC mode.
1349       unsigned LabelId = AFI->createPICLabelUId();
1350       unsigned DstReg = MI.getOperand(0).getReg();
1351       bool DstIsDead = MI.getOperand(0).isDead();
1352       const MachineOperand &MO1 = MI.getOperand(1);
1353       const GlobalValue *GV = MO1.getGlobal();
1354       unsigned TF = MO1.getTargetFlags();
1355       bool isARM = Opcode != ARM::t2MOV_ga_pcrel;
1356       unsigned LO16Opc = isARM ? ARM::MOVi16_ga_pcrel : ARM::t2MOVi16_ga_pcrel;
1357       unsigned HI16Opc = isARM ? ARM::MOVTi16_ga_pcrel :ARM::t2MOVTi16_ga_pcrel;
1358       unsigned LO16TF = TF | ARMII::MO_LO16;
1359       unsigned HI16TF = TF | ARMII::MO_HI16;
1360       unsigned PICAddOpc = isARM
1361         ? (Opcode == ARM::MOV_ga_pcrel_ldr ? ARM::PICLDR : ARM::PICADD)
1362         : ARM::tPICADD;
1363       MachineInstrBuilder MIB1 = BuildMI(MBB, MBBI, MI.getDebugLoc(),
1364                                          TII->get(LO16Opc), DstReg)
1365         .addGlobalAddress(GV, MO1.getOffset(), TF | LO16TF)
1366         .addImm(LabelId);
1367
1368       BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(HI16Opc), DstReg)
1369         .addReg(DstReg)
1370         .addGlobalAddress(GV, MO1.getOffset(), TF | HI16TF)
1371         .addImm(LabelId);
1372
1373       MachineInstrBuilder MIB3 = BuildMI(MBB, MBBI, MI.getDebugLoc(),
1374                                          TII->get(PICAddOpc))
1375         .addReg(DstReg, RegState::Define | getDeadRegState(DstIsDead))
1376         .addReg(DstReg).addImm(LabelId);
1377       if (isARM) {
1378         MIB3.add(predOps(ARMCC::AL));
1379         if (Opcode == ARM::MOV_ga_pcrel_ldr)
1380           MIB3->setMemRefs(MI.memoperands_begin(), MI.memoperands_end());
1381       }
1382       TransferImpOps(MI, MIB1, MIB3);
1383       MI.eraseFromParent();
1384       return true;
1385     }
1386
1387     case ARM::MOVi32imm:
1388     case ARM::MOVCCi32imm:
1389     case ARM::t2MOVi32imm:
1390     case ARM::t2MOVCCi32imm:
1391       ExpandMOV32BitImm(MBB, MBBI);
1392       return true;
1393
1394     case ARM::SUBS_PC_LR: {
1395       MachineInstrBuilder MIB =
1396           BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(ARM::SUBri), ARM::PC)
1397               .addReg(ARM::LR)
1398               .add(MI.getOperand(0))
1399               .add(MI.getOperand(1))
1400               .add(MI.getOperand(2))
1401               .addReg(ARM::CPSR, RegState::Undef);
1402       TransferImpOps(MI, MIB, MIB);
1403       MI.eraseFromParent();
1404       return true;
1405     }
1406     case ARM::VLDMQIA: {
1407       unsigned NewOpc = ARM::VLDMDIA;
1408       MachineInstrBuilder MIB =
1409         BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(NewOpc));
1410       unsigned OpIdx = 0;
1411
1412       // Grab the Q register destination.
1413       bool DstIsDead = MI.getOperand(OpIdx).isDead();
1414       unsigned DstReg = MI.getOperand(OpIdx++).getReg();
1415
1416       // Copy the source register.
1417       MIB.add(MI.getOperand(OpIdx++));
1418
1419       // Copy the predicate operands.
1420       MIB.add(MI.getOperand(OpIdx++));
1421       MIB.add(MI.getOperand(OpIdx++));
1422
1423       // Add the destination operands (D subregs).
1424       unsigned D0 = TRI->getSubReg(DstReg, ARM::dsub_0);
1425       unsigned D1 = TRI->getSubReg(DstReg, ARM::dsub_1);
1426       MIB.addReg(D0, RegState::Define | getDeadRegState(DstIsDead))
1427         .addReg(D1, RegState::Define | getDeadRegState(DstIsDead));
1428
1429       // Add an implicit def for the super-register.
1430       MIB.addReg(DstReg, RegState::ImplicitDefine | getDeadRegState(DstIsDead));
1431       TransferImpOps(MI, MIB, MIB);
1432       MIB.setMemRefs(MI.memoperands_begin(), MI.memoperands_end());
1433       MI.eraseFromParent();
1434       return true;
1435     }
1436
1437     case ARM::VSTMQIA: {
1438       unsigned NewOpc = ARM::VSTMDIA;
1439       MachineInstrBuilder MIB =
1440         BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(NewOpc));
1441       unsigned OpIdx = 0;
1442
1443       // Grab the Q register source.
1444       bool SrcIsKill = MI.getOperand(OpIdx).isKill();
1445       unsigned SrcReg = MI.getOperand(OpIdx++).getReg();
1446
1447       // Copy the destination register.
1448       MIB.add(MI.getOperand(OpIdx++));
1449
1450       // Copy the predicate operands.
1451       MIB.add(MI.getOperand(OpIdx++));
1452       MIB.add(MI.getOperand(OpIdx++));
1453
1454       // Add the source operands (D subregs).
1455       unsigned D0 = TRI->getSubReg(SrcReg, ARM::dsub_0);
1456       unsigned D1 = TRI->getSubReg(SrcReg, ARM::dsub_1);
1457       MIB.addReg(D0, SrcIsKill ? RegState::Kill : 0)
1458          .addReg(D1, SrcIsKill ? RegState::Kill : 0);
1459
1460       if (SrcIsKill)      // Add an implicit kill for the Q register.
1461         MIB->addRegisterKilled(SrcReg, TRI, true);
1462
1463       TransferImpOps(MI, MIB, MIB);
1464       MIB.setMemRefs(MI.memoperands_begin(), MI.memoperands_end());
1465       MI.eraseFromParent();
1466       return true;
1467     }
1468
1469     case ARM::VLD2q8Pseudo:
1470     case ARM::VLD2q16Pseudo:
1471     case ARM::VLD2q32Pseudo:
1472     case ARM::VLD2q8PseudoWB_fixed:
1473     case ARM::VLD2q16PseudoWB_fixed:
1474     case ARM::VLD2q32PseudoWB_fixed:
1475     case ARM::VLD2q8PseudoWB_register:
1476     case ARM::VLD2q16PseudoWB_register:
1477     case ARM::VLD2q32PseudoWB_register:
1478     case ARM::VLD3d8Pseudo:
1479     case ARM::VLD3d16Pseudo:
1480     case ARM::VLD3d32Pseudo:
1481     case ARM::VLD1d64TPseudo:
1482     case ARM::VLD1d64TPseudoWB_fixed:
1483     case ARM::VLD3d8Pseudo_UPD:
1484     case ARM::VLD3d16Pseudo_UPD:
1485     case ARM::VLD3d32Pseudo_UPD:
1486     case ARM::VLD3q8Pseudo_UPD:
1487     case ARM::VLD3q16Pseudo_UPD:
1488     case ARM::VLD3q32Pseudo_UPD:
1489     case ARM::VLD3q8oddPseudo:
1490     case ARM::VLD3q16oddPseudo:
1491     case ARM::VLD3q32oddPseudo:
1492     case ARM::VLD3q8oddPseudo_UPD:
1493     case ARM::VLD3q16oddPseudo_UPD:
1494     case ARM::VLD3q32oddPseudo_UPD:
1495     case ARM::VLD4d8Pseudo:
1496     case ARM::VLD4d16Pseudo:
1497     case ARM::VLD4d32Pseudo:
1498     case ARM::VLD1d64QPseudo:
1499     case ARM::VLD1d64QPseudoWB_fixed:
1500     case ARM::VLD4d8Pseudo_UPD:
1501     case ARM::VLD4d16Pseudo_UPD:
1502     case ARM::VLD4d32Pseudo_UPD:
1503     case ARM::VLD4q8Pseudo_UPD:
1504     case ARM::VLD4q16Pseudo_UPD:
1505     case ARM::VLD4q32Pseudo_UPD:
1506     case ARM::VLD4q8oddPseudo:
1507     case ARM::VLD4q16oddPseudo:
1508     case ARM::VLD4q32oddPseudo:
1509     case ARM::VLD4q8oddPseudo_UPD:
1510     case ARM::VLD4q16oddPseudo_UPD:
1511     case ARM::VLD4q32oddPseudo_UPD:
1512     case ARM::VLD3DUPd8Pseudo:
1513     case ARM::VLD3DUPd16Pseudo:
1514     case ARM::VLD3DUPd32Pseudo:
1515     case ARM::VLD3DUPd8Pseudo_UPD:
1516     case ARM::VLD3DUPd16Pseudo_UPD:
1517     case ARM::VLD3DUPd32Pseudo_UPD:
1518     case ARM::VLD4DUPd8Pseudo:
1519     case ARM::VLD4DUPd16Pseudo:
1520     case ARM::VLD4DUPd32Pseudo:
1521     case ARM::VLD4DUPd8Pseudo_UPD:
1522     case ARM::VLD4DUPd16Pseudo_UPD:
1523     case ARM::VLD4DUPd32Pseudo_UPD:
1524       ExpandVLD(MBBI);
1525       return true;
1526
1527     case ARM::VST2q8Pseudo:
1528     case ARM::VST2q16Pseudo:
1529     case ARM::VST2q32Pseudo:
1530     case ARM::VST2q8PseudoWB_fixed:
1531     case ARM::VST2q16PseudoWB_fixed:
1532     case ARM::VST2q32PseudoWB_fixed:
1533     case ARM::VST2q8PseudoWB_register:
1534     case ARM::VST2q16PseudoWB_register:
1535     case ARM::VST2q32PseudoWB_register:
1536     case ARM::VST3d8Pseudo:
1537     case ARM::VST3d16Pseudo:
1538     case ARM::VST3d32Pseudo:
1539     case ARM::VST1d64TPseudo:
1540     case ARM::VST3d8Pseudo_UPD:
1541     case ARM::VST3d16Pseudo_UPD:
1542     case ARM::VST3d32Pseudo_UPD:
1543     case ARM::VST1d64TPseudoWB_fixed:
1544     case ARM::VST1d64TPseudoWB_register:
1545     case ARM::VST3q8Pseudo_UPD:
1546     case ARM::VST3q16Pseudo_UPD:
1547     case ARM::VST3q32Pseudo_UPD:
1548     case ARM::VST3q8oddPseudo:
1549     case ARM::VST3q16oddPseudo:
1550     case ARM::VST3q32oddPseudo:
1551     case ARM::VST3q8oddPseudo_UPD:
1552     case ARM::VST3q16oddPseudo_UPD:
1553     case ARM::VST3q32oddPseudo_UPD:
1554     case ARM::VST4d8Pseudo:
1555     case ARM::VST4d16Pseudo:
1556     case ARM::VST4d32Pseudo:
1557     case ARM::VST1d64QPseudo:
1558     case ARM::VST4d8Pseudo_UPD:
1559     case ARM::VST4d16Pseudo_UPD:
1560     case ARM::VST4d32Pseudo_UPD:
1561     case ARM::VST1d64QPseudoWB_fixed:
1562     case ARM::VST1d64QPseudoWB_register:
1563     case ARM::VST4q8Pseudo_UPD:
1564     case ARM::VST4q16Pseudo_UPD:
1565     case ARM::VST4q32Pseudo_UPD:
1566     case ARM::VST4q8oddPseudo:
1567     case ARM::VST4q16oddPseudo:
1568     case ARM::VST4q32oddPseudo:
1569     case ARM::VST4q8oddPseudo_UPD:
1570     case ARM::VST4q16oddPseudo_UPD:
1571     case ARM::VST4q32oddPseudo_UPD:
1572       ExpandVST(MBBI);
1573       return true;
1574
1575     case ARM::VLD1LNq8Pseudo:
1576     case ARM::VLD1LNq16Pseudo:
1577     case ARM::VLD1LNq32Pseudo:
1578     case ARM::VLD1LNq8Pseudo_UPD:
1579     case ARM::VLD1LNq16Pseudo_UPD:
1580     case ARM::VLD1LNq32Pseudo_UPD:
1581     case ARM::VLD2LNd8Pseudo:
1582     case ARM::VLD2LNd16Pseudo:
1583     case ARM::VLD2LNd32Pseudo:
1584     case ARM::VLD2LNq16Pseudo:
1585     case ARM::VLD2LNq32Pseudo:
1586     case ARM::VLD2LNd8Pseudo_UPD:
1587     case ARM::VLD2LNd16Pseudo_UPD:
1588     case ARM::VLD2LNd32Pseudo_UPD:
1589     case ARM::VLD2LNq16Pseudo_UPD:
1590     case ARM::VLD2LNq32Pseudo_UPD:
1591     case ARM::VLD3LNd8Pseudo:
1592     case ARM::VLD3LNd16Pseudo:
1593     case ARM::VLD3LNd32Pseudo:
1594     case ARM::VLD3LNq16Pseudo:
1595     case ARM::VLD3LNq32Pseudo:
1596     case ARM::VLD3LNd8Pseudo_UPD:
1597     case ARM::VLD3LNd16Pseudo_UPD:
1598     case ARM::VLD3LNd32Pseudo_UPD:
1599     case ARM::VLD3LNq16Pseudo_UPD:
1600     case ARM::VLD3LNq32Pseudo_UPD:
1601     case ARM::VLD4LNd8Pseudo:
1602     case ARM::VLD4LNd16Pseudo:
1603     case ARM::VLD4LNd32Pseudo:
1604     case ARM::VLD4LNq16Pseudo:
1605     case ARM::VLD4LNq32Pseudo:
1606     case ARM::VLD4LNd8Pseudo_UPD:
1607     case ARM::VLD4LNd16Pseudo_UPD:
1608     case ARM::VLD4LNd32Pseudo_UPD:
1609     case ARM::VLD4LNq16Pseudo_UPD:
1610     case ARM::VLD4LNq32Pseudo_UPD:
1611     case ARM::VST1LNq8Pseudo:
1612     case ARM::VST1LNq16Pseudo:
1613     case ARM::VST1LNq32Pseudo:
1614     case ARM::VST1LNq8Pseudo_UPD:
1615     case ARM::VST1LNq16Pseudo_UPD:
1616     case ARM::VST1LNq32Pseudo_UPD:
1617     case ARM::VST2LNd8Pseudo:
1618     case ARM::VST2LNd16Pseudo:
1619     case ARM::VST2LNd32Pseudo:
1620     case ARM::VST2LNq16Pseudo:
1621     case ARM::VST2LNq32Pseudo:
1622     case ARM::VST2LNd8Pseudo_UPD:
1623     case ARM::VST2LNd16Pseudo_UPD:
1624     case ARM::VST2LNd32Pseudo_UPD:
1625     case ARM::VST2LNq16Pseudo_UPD:
1626     case ARM::VST2LNq32Pseudo_UPD:
1627     case ARM::VST3LNd8Pseudo:
1628     case ARM::VST3LNd16Pseudo:
1629     case ARM::VST3LNd32Pseudo:
1630     case ARM::VST3LNq16Pseudo:
1631     case ARM::VST3LNq32Pseudo:
1632     case ARM::VST3LNd8Pseudo_UPD:
1633     case ARM::VST3LNd16Pseudo_UPD:
1634     case ARM::VST3LNd32Pseudo_UPD:
1635     case ARM::VST3LNq16Pseudo_UPD:
1636     case ARM::VST3LNq32Pseudo_UPD:
1637     case ARM::VST4LNd8Pseudo:
1638     case ARM::VST4LNd16Pseudo:
1639     case ARM::VST4LNd32Pseudo:
1640     case ARM::VST4LNq16Pseudo:
1641     case ARM::VST4LNq32Pseudo:
1642     case ARM::VST4LNd8Pseudo_UPD:
1643     case ARM::VST4LNd16Pseudo_UPD:
1644     case ARM::VST4LNd32Pseudo_UPD:
1645     case ARM::VST4LNq16Pseudo_UPD:
1646     case ARM::VST4LNq32Pseudo_UPD:
1647       ExpandLaneOp(MBBI);
1648       return true;
1649
1650     case ARM::VTBL3Pseudo: ExpandVTBL(MBBI, ARM::VTBL3, false); return true;
1651     case ARM::VTBL4Pseudo: ExpandVTBL(MBBI, ARM::VTBL4, false); return true;
1652     case ARM::VTBX3Pseudo: ExpandVTBL(MBBI, ARM::VTBX3, true); return true;
1653     case ARM::VTBX4Pseudo: ExpandVTBL(MBBI, ARM::VTBX4, true); return true;
1654
1655     case ARM::CMP_SWAP_8:
1656       if (STI->isThumb())
1657         return ExpandCMP_SWAP(MBB, MBBI, ARM::t2LDREXB, ARM::t2STREXB,
1658                               ARM::tUXTB, NextMBBI);
1659       else
1660         return ExpandCMP_SWAP(MBB, MBBI, ARM::LDREXB, ARM::STREXB,
1661                               ARM::UXTB, NextMBBI);
1662     case ARM::CMP_SWAP_16:
1663       if (STI->isThumb())
1664         return ExpandCMP_SWAP(MBB, MBBI, ARM::t2LDREXH, ARM::t2STREXH,
1665                               ARM::tUXTH, NextMBBI);
1666       else
1667         return ExpandCMP_SWAP(MBB, MBBI, ARM::LDREXH, ARM::STREXH,
1668                               ARM::UXTH, NextMBBI);
1669     case ARM::CMP_SWAP_32:
1670       if (STI->isThumb())
1671         return ExpandCMP_SWAP(MBB, MBBI, ARM::t2LDREX, ARM::t2STREX, 0,
1672                               NextMBBI);
1673       else
1674         return ExpandCMP_SWAP(MBB, MBBI, ARM::LDREX, ARM::STREX, 0, NextMBBI);
1675
1676     case ARM::CMP_SWAP_64:
1677       return ExpandCMP_SWAP_64(MBB, MBBI, NextMBBI);
1678   }
1679 }
1680
1681 bool ARMExpandPseudo::ExpandMBB(MachineBasicBlock &MBB) {
1682   bool Modified = false;
1683
1684   MachineBasicBlock::iterator MBBI = MBB.begin(), E = MBB.end();
1685   while (MBBI != E) {
1686     MachineBasicBlock::iterator NMBBI = std::next(MBBI);
1687     Modified |= ExpandMI(MBB, MBBI, NMBBI);
1688     MBBI = NMBBI;
1689   }
1690
1691   return Modified;
1692 }
1693
1694 bool ARMExpandPseudo::runOnMachineFunction(MachineFunction &MF) {
1695   STI = &static_cast<const ARMSubtarget &>(MF.getSubtarget());
1696   TII = STI->getInstrInfo();
1697   TRI = STI->getRegisterInfo();
1698   AFI = MF.getInfo<ARMFunctionInfo>();
1699
1700   bool Modified = false;
1701   for (MachineFunction::iterator MFI = MF.begin(), E = MF.end(); MFI != E;
1702        ++MFI)
1703     Modified |= ExpandMBB(*MFI);
1704   if (VerifyARMPseudo)
1705     MF.verify(this, "After expanding ARM pseudo instructions.");
1706   return Modified;
1707 }
1708
1709 /// createARMExpandPseudoPass - returns an instance of the pseudo instruction
1710 /// expansion pass.
1711 FunctionPass *llvm::createARMExpandPseudoPass() {
1712   return new ARMExpandPseudo();
1713 }