LLVM API Documentation

ARMExpandPseudoInsts.cpp
Go to the documentation of this file.
00001 //===-- ARMExpandPseudoInsts.cpp - Expand pseudo instructions -------------===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file contains a pass that expands pseudo instructions into target
00011 // instructions to allow proper scheduling, if-conversion, and other late
00012 // optimizations. This pass should be run after register allocation but before
00013 // the post-regalloc scheduling pass.
00014 //
00015 //===----------------------------------------------------------------------===//
00016 
00017 #include "ARM.h"
00018 #include "ARMBaseInstrInfo.h"
00019 #include "ARMBaseRegisterInfo.h"
00020 #include "ARMConstantPoolValue.h"
00021 #include "ARMMachineFunctionInfo.h"
00022 #include "MCTargetDesc/ARMAddressingModes.h"
00023 #include "llvm/CodeGen/MachineFrameInfo.h"
00024 #include "llvm/CodeGen/MachineFunctionPass.h"
00025 #include "llvm/CodeGen/MachineInstrBundle.h"
00026 #include "llvm/CodeGen/MachineInstrBuilder.h"
00027 #include "llvm/IR/GlobalValue.h"
00028 #include "llvm/Support/CommandLine.h"
00029 #include "llvm/Support/raw_ostream.h" // FIXME: for debug only. remove!
00030 #include "llvm/Target/TargetFrameLowering.h"
00031 #include "llvm/Target/TargetRegisterInfo.h"
00032 using namespace llvm;
00033 
00034 #define DEBUG_TYPE "arm-pseudo"
00035 
00036 static cl::opt<bool>
00037 VerifyARMPseudo("verify-arm-pseudo-expand", cl::Hidden,
00038                 cl::desc("Verify machine code after expanding ARM pseudos"));
00039 
00040 namespace {
00041   class ARMExpandPseudo : public MachineFunctionPass {
00042   public:
00043     static char ID;
00044     ARMExpandPseudo() : MachineFunctionPass(ID) {}
00045 
00046     const ARMBaseInstrInfo *TII;
00047     const TargetRegisterInfo *TRI;
00048     const ARMSubtarget *STI;
00049     ARMFunctionInfo *AFI;
00050 
00051     bool runOnMachineFunction(MachineFunction &Fn) override;
00052 
00053     const char *getPassName() const override {
00054       return "ARM pseudo instruction expansion pass";
00055     }
00056 
00057   private:
00058     void TransferImpOps(MachineInstr &OldMI,
00059                         MachineInstrBuilder &UseMI, MachineInstrBuilder &DefMI);
00060     bool ExpandMI(MachineBasicBlock &MBB,
00061                   MachineBasicBlock::iterator MBBI);
00062     bool ExpandMBB(MachineBasicBlock &MBB);
00063     void ExpandVLD(MachineBasicBlock::iterator &MBBI);
00064     void ExpandVST(MachineBasicBlock::iterator &MBBI);
00065     void ExpandLaneOp(MachineBasicBlock::iterator &MBBI);
00066     void ExpandVTBL(MachineBasicBlock::iterator &MBBI,
00067                     unsigned Opc, bool IsExt);
00068     void ExpandMOV32BitImm(MachineBasicBlock &MBB,
00069                            MachineBasicBlock::iterator &MBBI);
00070   };
00071   char ARMExpandPseudo::ID = 0;
00072 }
00073 
00074 /// TransferImpOps - Transfer implicit operands on the pseudo instruction to
00075 /// the instructions created from the expansion.
00076 void ARMExpandPseudo::TransferImpOps(MachineInstr &OldMI,
00077                                      MachineInstrBuilder &UseMI,
00078                                      MachineInstrBuilder &DefMI) {
00079   const MCInstrDesc &Desc = OldMI.getDesc();
00080   for (unsigned i = Desc.getNumOperands(), e = OldMI.getNumOperands();
00081        i != e; ++i) {
00082     const MachineOperand &MO = OldMI.getOperand(i);
00083     assert(MO.isReg() && MO.getReg());
00084     if (MO.isUse())
00085       UseMI.addOperand(MO);
00086     else
00087       DefMI.addOperand(MO);
00088   }
00089 }
00090 
00091 namespace {
00092   // Constants for register spacing in NEON load/store instructions.
00093   // For quad-register load-lane and store-lane pseudo instructors, the
00094   // spacing is initially assumed to be EvenDblSpc, and that is changed to
00095   // OddDblSpc depending on the lane number operand.
00096   enum NEONRegSpacing {
00097     SingleSpc,
00098     EvenDblSpc,
00099     OddDblSpc
00100   };
00101 
00102   // Entries for NEON load/store information table.  The table is sorted by
00103   // PseudoOpc for fast binary-search lookups.
00104   struct NEONLdStTableEntry {
00105     uint16_t PseudoOpc;
00106     uint16_t RealOpc;
00107     bool IsLoad;
00108     bool isUpdating;
00109     bool hasWritebackOperand;
00110     uint8_t RegSpacing; // One of type NEONRegSpacing
00111     uint8_t NumRegs; // D registers loaded or stored
00112     uint8_t RegElts; // elements per D register; used for lane ops
00113     // FIXME: Temporary flag to denote whether the real instruction takes
00114     // a single register (like the encoding) or all of the registers in
00115     // the list (like the asm syntax and the isel DAG). When all definitions
00116     // are converted to take only the single encoded register, this will
00117     // go away.
00118     bool copyAllListRegs;
00119 
00120     // Comparison methods for binary search of the table.
00121     bool operator<(const NEONLdStTableEntry &TE) const {
00122       return PseudoOpc < TE.PseudoOpc;
00123     }
00124     friend bool operator<(const NEONLdStTableEntry &TE, unsigned PseudoOpc) {
00125       return TE.PseudoOpc < PseudoOpc;
00126     }
00127     friend bool LLVM_ATTRIBUTE_UNUSED operator<(unsigned PseudoOpc,
00128                                                 const NEONLdStTableEntry &TE) {
00129       return PseudoOpc < TE.PseudoOpc;
00130     }
00131   };
00132 }
00133 
00134 static const NEONLdStTableEntry NEONLdStTable[] = {
00135 { ARM::VLD1LNq16Pseudo,     ARM::VLD1LNd16,     true, false, false, EvenDblSpc, 1, 4 ,true},
00136 { ARM::VLD1LNq16Pseudo_UPD, ARM::VLD1LNd16_UPD, true, true, true,  EvenDblSpc, 1, 4 ,true},
00137 { ARM::VLD1LNq32Pseudo,     ARM::VLD1LNd32,     true, false, false, EvenDblSpc, 1, 2 ,true},
00138 { ARM::VLD1LNq32Pseudo_UPD, ARM::VLD1LNd32_UPD, true, true, true,  EvenDblSpc, 1, 2 ,true},
00139 { ARM::VLD1LNq8Pseudo,      ARM::VLD1LNd8,      true, false, false, EvenDblSpc, 1, 8 ,true},
00140 { ARM::VLD1LNq8Pseudo_UPD,  ARM::VLD1LNd8_UPD, true, true, true,  EvenDblSpc, 1, 8 ,true},
00141 
00142 { ARM::VLD1d64QPseudo,      ARM::VLD1d64Q,     true,  false, false, SingleSpc,  4, 1 ,false},
00143 { ARM::VLD1d64QPseudoWB_fixed,  ARM::VLD1d64Qwb_fixed,   true,  true, false, SingleSpc,  4, 1 ,false},
00144 { ARM::VLD1d64TPseudo,      ARM::VLD1d64T,     true,  false, false, SingleSpc,  3, 1 ,false},
00145 { ARM::VLD1d64TPseudoWB_fixed,  ARM::VLD1d64Twb_fixed,   true,  true, false, SingleSpc,  3, 1 ,false},
00146 
00147 { ARM::VLD2LNd16Pseudo,     ARM::VLD2LNd16,     true, false, false, SingleSpc,  2, 4 ,true},
00148 { ARM::VLD2LNd16Pseudo_UPD, ARM::VLD2LNd16_UPD, true, true, true,  SingleSpc,  2, 4 ,true},
00149 { ARM::VLD2LNd32Pseudo,     ARM::VLD2LNd32,     true, false, false, SingleSpc,  2, 2 ,true},
00150 { ARM::VLD2LNd32Pseudo_UPD, ARM::VLD2LNd32_UPD, true, true, true,  SingleSpc,  2, 2 ,true},
00151 { ARM::VLD2LNd8Pseudo,      ARM::VLD2LNd8,      true, false, false, SingleSpc,  2, 8 ,true},
00152 { ARM::VLD2LNd8Pseudo_UPD,  ARM::VLD2LNd8_UPD, true, true, true,  SingleSpc,  2, 8 ,true},
00153 { ARM::VLD2LNq16Pseudo,     ARM::VLD2LNq16,     true, false, false, EvenDblSpc, 2, 4 ,true},
00154 { ARM::VLD2LNq16Pseudo_UPD, ARM::VLD2LNq16_UPD, true, true, true,  EvenDblSpc, 2, 4 ,true},
00155 { ARM::VLD2LNq32Pseudo,     ARM::VLD2LNq32,     true, false, false, EvenDblSpc, 2, 2 ,true},
00156 { ARM::VLD2LNq32Pseudo_UPD, ARM::VLD2LNq32_UPD, true, true, true,  EvenDblSpc, 2, 2 ,true},
00157 
00158 { ARM::VLD2q16Pseudo,       ARM::VLD2q16,      true,  false, false, SingleSpc,  4, 4 ,false},
00159 { ARM::VLD2q16PseudoWB_fixed,   ARM::VLD2q16wb_fixed, true, true, false,  SingleSpc,  4, 4 ,false},
00160 { ARM::VLD2q16PseudoWB_register,   ARM::VLD2q16wb_register, true, true, true,  SingleSpc,  4, 4 ,false},
00161 { ARM::VLD2q32Pseudo,       ARM::VLD2q32,      true,  false, false, SingleSpc,  4, 2 ,false},
00162 { ARM::VLD2q32PseudoWB_fixed,   ARM::VLD2q32wb_fixed, true, true, false,  SingleSpc,  4, 2 ,false},
00163 { ARM::VLD2q32PseudoWB_register,   ARM::VLD2q32wb_register, true, true, true,  SingleSpc,  4, 2 ,false},
00164 { ARM::VLD2q8Pseudo,        ARM::VLD2q8,       true,  false, false, SingleSpc,  4, 8 ,false},
00165 { ARM::VLD2q8PseudoWB_fixed,    ARM::VLD2q8wb_fixed, true, true, false,  SingleSpc,  4, 8 ,false},
00166 { ARM::VLD2q8PseudoWB_register,    ARM::VLD2q8wb_register, true, true, true,  SingleSpc,  4, 8 ,false},
00167 
00168 { ARM::VLD3DUPd16Pseudo,     ARM::VLD3DUPd16,     true, false, false, SingleSpc, 3, 4,true},
00169 { ARM::VLD3DUPd16Pseudo_UPD, ARM::VLD3DUPd16_UPD, true, true, true,  SingleSpc, 3, 4,true},
00170 { ARM::VLD3DUPd32Pseudo,     ARM::VLD3DUPd32,     true, false, false, SingleSpc, 3, 2,true},
00171 { ARM::VLD3DUPd32Pseudo_UPD, ARM::VLD3DUPd32_UPD, true, true, true,  SingleSpc, 3, 2,true},
00172 { ARM::VLD3DUPd8Pseudo,      ARM::VLD3DUPd8,      true, false, false, SingleSpc, 3, 8,true},
00173 { ARM::VLD3DUPd8Pseudo_UPD,  ARM::VLD3DUPd8_UPD, true, true, true,  SingleSpc, 3, 8,true},
00174 
00175 { ARM::VLD3LNd16Pseudo,     ARM::VLD3LNd16,     true, false, false, SingleSpc,  3, 4 ,true},
00176 { ARM::VLD3LNd16Pseudo_UPD, ARM::VLD3LNd16_UPD, true, true, true,  SingleSpc,  3, 4 ,true},
00177 { ARM::VLD3LNd32Pseudo,     ARM::VLD3LNd32,     true, false, false, SingleSpc,  3, 2 ,true},
00178 { ARM::VLD3LNd32Pseudo_UPD, ARM::VLD3LNd32_UPD, true, true, true,  SingleSpc,  3, 2 ,true},
00179 { ARM::VLD3LNd8Pseudo,      ARM::VLD3LNd8,      true, false, false, SingleSpc,  3, 8 ,true},
00180 { ARM::VLD3LNd8Pseudo_UPD,  ARM::VLD3LNd8_UPD, true, true, true,  SingleSpc,  3, 8 ,true},
00181 { ARM::VLD3LNq16Pseudo,     ARM::VLD3LNq16,     true, false, false, EvenDblSpc, 3, 4 ,true},
00182 { ARM::VLD3LNq16Pseudo_UPD, ARM::VLD3LNq16_UPD, true, true, true,  EvenDblSpc, 3, 4 ,true},
00183 { ARM::VLD3LNq32Pseudo,     ARM::VLD3LNq32,     true, false, false, EvenDblSpc, 3, 2 ,true},
00184 { ARM::VLD3LNq32Pseudo_UPD, ARM::VLD3LNq32_UPD, true, true, true,  EvenDblSpc, 3, 2 ,true},
00185 
00186 { ARM::VLD3d16Pseudo,       ARM::VLD3d16,      true,  false, false, SingleSpc,  3, 4 ,true},
00187 { ARM::VLD3d16Pseudo_UPD,   ARM::VLD3d16_UPD, true, true, true,  SingleSpc,  3, 4 ,true},
00188 { ARM::VLD3d32Pseudo,       ARM::VLD3d32,      true,  false, false, SingleSpc,  3, 2 ,true},
00189 { ARM::VLD3d32Pseudo_UPD,   ARM::VLD3d32_UPD, true, true, true,  SingleSpc,  3, 2 ,true},
00190 { ARM::VLD3d8Pseudo,        ARM::VLD3d8,       true,  false, false, SingleSpc,  3, 8 ,true},
00191 { ARM::VLD3d8Pseudo_UPD,    ARM::VLD3d8_UPD, true, true, true,  SingleSpc,  3, 8 ,true},
00192 
00193 { ARM::VLD3q16Pseudo_UPD,    ARM::VLD3q16_UPD, true, true, true,  EvenDblSpc, 3, 4 ,true},
00194 { ARM::VLD3q16oddPseudo,     ARM::VLD3q16,     true,  false, false, OddDblSpc,  3, 4 ,true},
00195 { ARM::VLD3q16oddPseudo_UPD, ARM::VLD3q16_UPD, true, true, true,  OddDblSpc,  3, 4 ,true},
00196 { ARM::VLD3q32Pseudo_UPD,    ARM::VLD3q32_UPD, true, true, true,  EvenDblSpc, 3, 2 ,true},
00197 { ARM::VLD3q32oddPseudo,     ARM::VLD3q32,     true,  false, false, OddDblSpc,  3, 2 ,true},
00198 { ARM::VLD3q32oddPseudo_UPD, ARM::VLD3q32_UPD, true, true, true,  OddDblSpc,  3, 2 ,true},
00199 { ARM::VLD3q8Pseudo_UPD,     ARM::VLD3q8_UPD, true, true, true,  EvenDblSpc, 3, 8 ,true},
00200 { ARM::VLD3q8oddPseudo,      ARM::VLD3q8,      true,  false, false, OddDblSpc,  3, 8 ,true},
00201 { ARM::VLD3q8oddPseudo_UPD,  ARM::VLD3q8_UPD, true, true, true,  OddDblSpc,  3, 8 ,true},
00202 
00203 { ARM::VLD4DUPd16Pseudo,     ARM::VLD4DUPd16,     true, false, false, SingleSpc, 4, 4,true},
00204 { ARM::VLD4DUPd16Pseudo_UPD, ARM::VLD4DUPd16_UPD, true, true, true,  SingleSpc, 4, 4,true},
00205 { ARM::VLD4DUPd32Pseudo,     ARM::VLD4DUPd32,     true, false, false, SingleSpc, 4, 2,true},
00206 { ARM::VLD4DUPd32Pseudo_UPD, ARM::VLD4DUPd32_UPD, true, true, true,  SingleSpc, 4, 2,true},
00207 { ARM::VLD4DUPd8Pseudo,      ARM::VLD4DUPd8,      true, false, false, SingleSpc, 4, 8,true},
00208 { ARM::VLD4DUPd8Pseudo_UPD,  ARM::VLD4DUPd8_UPD, true, true, true,  SingleSpc, 4, 8,true},
00209 
00210 { ARM::VLD4LNd16Pseudo,     ARM::VLD4LNd16,     true, false, false, SingleSpc,  4, 4 ,true},
00211 { ARM::VLD4LNd16Pseudo_UPD, ARM::VLD4LNd16_UPD, true, true, true,  SingleSpc,  4, 4 ,true},
00212 { ARM::VLD4LNd32Pseudo,     ARM::VLD4LNd32,     true, false, false, SingleSpc,  4, 2 ,true},
00213 { ARM::VLD4LNd32Pseudo_UPD, ARM::VLD4LNd32_UPD, true, true, true,  SingleSpc,  4, 2 ,true},
00214 { ARM::VLD4LNd8Pseudo,      ARM::VLD4LNd8,      true, false, false, SingleSpc,  4, 8 ,true},
00215 { ARM::VLD4LNd8Pseudo_UPD,  ARM::VLD4LNd8_UPD, true, true, true,  SingleSpc,  4, 8 ,true},
00216 { ARM::VLD4LNq16Pseudo,     ARM::VLD4LNq16,     true, false, false, EvenDblSpc, 4, 4 ,true},
00217 { ARM::VLD4LNq16Pseudo_UPD, ARM::VLD4LNq16_UPD, true, true, true,  EvenDblSpc, 4, 4 ,true},
00218 { ARM::VLD4LNq32Pseudo,     ARM::VLD4LNq32,     true, false, false, EvenDblSpc, 4, 2 ,true},
00219 { ARM::VLD4LNq32Pseudo_UPD, ARM::VLD4LNq32_UPD, true, true, true,  EvenDblSpc, 4, 2 ,true},
00220 
00221 { ARM::VLD4d16Pseudo,       ARM::VLD4d16,      true,  false, false, SingleSpc,  4, 4 ,true},
00222 { ARM::VLD4d16Pseudo_UPD,   ARM::VLD4d16_UPD, true, true, true,  SingleSpc,  4, 4 ,true},
00223 { ARM::VLD4d32Pseudo,       ARM::VLD4d32,      true,  false, false, SingleSpc,  4, 2 ,true},
00224 { ARM::VLD4d32Pseudo_UPD,   ARM::VLD4d32_UPD, true, true, true,  SingleSpc,  4, 2 ,true},
00225 { ARM::VLD4d8Pseudo,        ARM::VLD4d8,       true,  false, false, SingleSpc,  4, 8 ,true},
00226 { ARM::VLD4d8Pseudo_UPD,    ARM::VLD4d8_UPD, true, true, true,  SingleSpc,  4, 8 ,true},
00227 
00228 { ARM::VLD4q16Pseudo_UPD,    ARM::VLD4q16_UPD, true, true, true,  EvenDblSpc, 4, 4 ,true},
00229 { ARM::VLD4q16oddPseudo,     ARM::VLD4q16,     true,  false, false, OddDblSpc,  4, 4 ,true},
00230 { ARM::VLD4q16oddPseudo_UPD, ARM::VLD4q16_UPD, true, true, true,  OddDblSpc,  4, 4 ,true},
00231 { ARM::VLD4q32Pseudo_UPD,    ARM::VLD4q32_UPD, true, true, true,  EvenDblSpc, 4, 2 ,true},
00232 { ARM::VLD4q32oddPseudo,     ARM::VLD4q32,     true,  false, false, OddDblSpc,  4, 2 ,true},
00233 { ARM::VLD4q32oddPseudo_UPD, ARM::VLD4q32_UPD, true, true, true,  OddDblSpc,  4, 2 ,true},
00234 { ARM::VLD4q8Pseudo_UPD,     ARM::VLD4q8_UPD, true, true, true,  EvenDblSpc, 4, 8 ,true},
00235 { ARM::VLD4q8oddPseudo,      ARM::VLD4q8,      true,  false, false, OddDblSpc,  4, 8 ,true},
00236 { ARM::VLD4q8oddPseudo_UPD,  ARM::VLD4q8_UPD, true, true, true,  OddDblSpc,  4, 8 ,true},
00237 
00238 { ARM::VST1LNq16Pseudo,     ARM::VST1LNd16,    false, false, false, EvenDblSpc, 1, 4 ,true},
00239 { ARM::VST1LNq16Pseudo_UPD, ARM::VST1LNd16_UPD, false, true, true,  EvenDblSpc, 1, 4 ,true},
00240 { ARM::VST1LNq32Pseudo,     ARM::VST1LNd32,    false, false, false, EvenDblSpc, 1, 2 ,true},
00241 { ARM::VST1LNq32Pseudo_UPD, ARM::VST1LNd32_UPD, false, true, true,  EvenDblSpc, 1, 2 ,true},
00242 { ARM::VST1LNq8Pseudo,      ARM::VST1LNd8,     false, false, false, EvenDblSpc, 1, 8 ,true},
00243 { ARM::VST1LNq8Pseudo_UPD,  ARM::VST1LNd8_UPD, false, true, true,  EvenDblSpc, 1, 8 ,true},
00244 
00245 { ARM::VST1d64QPseudo,      ARM::VST1d64Q,     false, false, false, SingleSpc,  4, 1 ,false},
00246 { ARM::VST1d64QPseudoWB_fixed,  ARM::VST1d64Qwb_fixed, false, true, false,  SingleSpc,  4, 1 ,false},
00247 { ARM::VST1d64QPseudoWB_register, ARM::VST1d64Qwb_register, false, true, true,  SingleSpc,  4, 1 ,false},
00248 { ARM::VST1d64TPseudo,      ARM::VST1d64T,     false, false, false, SingleSpc,  3, 1 ,false},
00249 { ARM::VST1d64TPseudoWB_fixed,  ARM::VST1d64Twb_fixed, false, true, false,  SingleSpc,  3, 1 ,false},
00250 { ARM::VST1d64TPseudoWB_register,  ARM::VST1d64Twb_register, false, true, true,  SingleSpc,  3, 1 ,false},
00251 
00252 { ARM::VST2LNd16Pseudo,     ARM::VST2LNd16,     false, false, false, SingleSpc, 2, 4 ,true},
00253 { ARM::VST2LNd16Pseudo_UPD, ARM::VST2LNd16_UPD, false, true, true,  SingleSpc, 2, 4 ,true},
00254 { ARM::VST2LNd32Pseudo,     ARM::VST2LNd32,     false, false, false, SingleSpc, 2, 2 ,true},
00255 { ARM::VST2LNd32Pseudo_UPD, ARM::VST2LNd32_UPD, false, true, true,  SingleSpc, 2, 2 ,true},
00256 { ARM::VST2LNd8Pseudo,      ARM::VST2LNd8,      false, false, false, SingleSpc, 2, 8 ,true},
00257 { ARM::VST2LNd8Pseudo_UPD,  ARM::VST2LNd8_UPD, false, true, true,  SingleSpc, 2, 8 ,true},
00258 { ARM::VST2LNq16Pseudo,     ARM::VST2LNq16,     false, false, false, EvenDblSpc, 2, 4,true},
00259 { ARM::VST2LNq16Pseudo_UPD, ARM::VST2LNq16_UPD, false, true, true,  EvenDblSpc, 2, 4,true},
00260 { ARM::VST2LNq32Pseudo,     ARM::VST2LNq32,     false, false, false, EvenDblSpc, 2, 2,true},
00261 { ARM::VST2LNq32Pseudo_UPD, ARM::VST2LNq32_UPD, false, true, true,  EvenDblSpc, 2, 2,true},
00262 
00263 { ARM::VST2q16Pseudo,       ARM::VST2q16,      false, false, false, SingleSpc,  4, 4 ,false},
00264 { ARM::VST2q16PseudoWB_fixed,   ARM::VST2q16wb_fixed, false, true, false,  SingleSpc,  4, 4 ,false},
00265 { ARM::VST2q16PseudoWB_register,   ARM::VST2q16wb_register, false, true, true,  SingleSpc,  4, 4 ,false},
00266 { ARM::VST2q32Pseudo,       ARM::VST2q32,      false, false, false, SingleSpc,  4, 2 ,false},
00267 { ARM::VST2q32PseudoWB_fixed,   ARM::VST2q32wb_fixed, false, true, false,  SingleSpc,  4, 2 ,false},
00268 { ARM::VST2q32PseudoWB_register,   ARM::VST2q32wb_register, false, true, true,  SingleSpc,  4, 2 ,false},
00269 { ARM::VST2q8Pseudo,        ARM::VST2q8,       false, false, false, SingleSpc,  4, 8 ,false},
00270 { ARM::VST2q8PseudoWB_fixed,    ARM::VST2q8wb_fixed, false, true, false,  SingleSpc,  4, 8 ,false},
00271 { ARM::VST2q8PseudoWB_register,    ARM::VST2q8wb_register, false, true, true,  SingleSpc,  4, 8 ,false},
00272 
00273 { ARM::VST3LNd16Pseudo,     ARM::VST3LNd16,     false, false, false, SingleSpc, 3, 4 ,true},
00274 { ARM::VST3LNd16Pseudo_UPD, ARM::VST3LNd16_UPD, false, true, true,  SingleSpc, 3, 4 ,true},
00275 { ARM::VST3LNd32Pseudo,     ARM::VST3LNd32,     false, false, false, SingleSpc, 3, 2 ,true},
00276 { ARM::VST3LNd32Pseudo_UPD, ARM::VST3LNd32_UPD, false, true, true,  SingleSpc, 3, 2 ,true},
00277 { ARM::VST3LNd8Pseudo,      ARM::VST3LNd8,      false, false, false, SingleSpc, 3, 8 ,true},
00278 { ARM::VST3LNd8Pseudo_UPD,  ARM::VST3LNd8_UPD, false, true, true,  SingleSpc, 3, 8 ,true},
00279 { ARM::VST3LNq16Pseudo,     ARM::VST3LNq16,     false, false, false, EvenDblSpc, 3, 4,true},
00280 { ARM::VST3LNq16Pseudo_UPD, ARM::VST3LNq16_UPD, false, true, true,  EvenDblSpc, 3, 4,true},
00281 { ARM::VST3LNq32Pseudo,     ARM::VST3LNq32,     false, false, false, EvenDblSpc, 3, 2,true},
00282 { ARM::VST3LNq32Pseudo_UPD, ARM::VST3LNq32_UPD, false, true, true,  EvenDblSpc, 3, 2,true},
00283 
00284 { ARM::VST3d16Pseudo,       ARM::VST3d16,      false, false, false, SingleSpc,  3, 4 ,true},
00285 { ARM::VST3d16Pseudo_UPD,   ARM::VST3d16_UPD, false, true, true,  SingleSpc,  3, 4 ,true},
00286 { ARM::VST3d32Pseudo,       ARM::VST3d32,      false, false, false, SingleSpc,  3, 2 ,true},
00287 { ARM::VST3d32Pseudo_UPD,   ARM::VST3d32_UPD, false, true, true,  SingleSpc,  3, 2 ,true},
00288 { ARM::VST3d8Pseudo,        ARM::VST3d8,       false, false, false, SingleSpc,  3, 8 ,true},
00289 { ARM::VST3d8Pseudo_UPD,    ARM::VST3d8_UPD, false, true, true,  SingleSpc,  3, 8 ,true},
00290 
00291 { ARM::VST3q16Pseudo_UPD,    ARM::VST3q16_UPD, false, true, true,  EvenDblSpc, 3, 4 ,true},
00292 { ARM::VST3q16oddPseudo,     ARM::VST3q16,     false, false, false, OddDblSpc,  3, 4 ,true},
00293 { ARM::VST3q16oddPseudo_UPD, ARM::VST3q16_UPD, false, true, true,  OddDblSpc,  3, 4 ,true},
00294 { ARM::VST3q32Pseudo_UPD,    ARM::VST3q32_UPD, false, true, true,  EvenDblSpc, 3, 2 ,true},
00295 { ARM::VST3q32oddPseudo,     ARM::VST3q32,     false, false, false, OddDblSpc,  3, 2 ,true},
00296 { ARM::VST3q32oddPseudo_UPD, ARM::VST3q32_UPD, false, true, true,  OddDblSpc,  3, 2 ,true},
00297 { ARM::VST3q8Pseudo_UPD,     ARM::VST3q8_UPD, false, true, true,  EvenDblSpc, 3, 8 ,true},
00298 { ARM::VST3q8oddPseudo,      ARM::VST3q8,      false, false, false, OddDblSpc,  3, 8 ,true},
00299 { ARM::VST3q8oddPseudo_UPD,  ARM::VST3q8_UPD, false, true, true,  OddDblSpc,  3, 8 ,true},
00300 
00301 { ARM::VST4LNd16Pseudo,     ARM::VST4LNd16,     false, false, false, SingleSpc, 4, 4 ,true},
00302 { ARM::VST4LNd16Pseudo_UPD, ARM::VST4LNd16_UPD, false, true, true,  SingleSpc, 4, 4 ,true},
00303 { ARM::VST4LNd32Pseudo,     ARM::VST4LNd32,     false, false, false, SingleSpc, 4, 2 ,true},
00304 { ARM::VST4LNd32Pseudo_UPD, ARM::VST4LNd32_UPD, false, true, true,  SingleSpc, 4, 2 ,true},
00305 { ARM::VST4LNd8Pseudo,      ARM::VST4LNd8,      false, false, false, SingleSpc, 4, 8 ,true},
00306 { ARM::VST4LNd8Pseudo_UPD,  ARM::VST4LNd8_UPD, false, true, true,  SingleSpc, 4, 8 ,true},
00307 { ARM::VST4LNq16Pseudo,     ARM::VST4LNq16,     false, false, false, EvenDblSpc, 4, 4,true},
00308 { ARM::VST4LNq16Pseudo_UPD, ARM::VST4LNq16_UPD, false, true, true,  EvenDblSpc, 4, 4,true},
00309 { ARM::VST4LNq32Pseudo,     ARM::VST4LNq32,     false, false, false, EvenDblSpc, 4, 2,true},
00310 { ARM::VST4LNq32Pseudo_UPD, ARM::VST4LNq32_UPD, false, true, true,  EvenDblSpc, 4, 2,true},
00311 
00312 { ARM::VST4d16Pseudo,       ARM::VST4d16,      false, false, false, SingleSpc,  4, 4 ,true},
00313 { ARM::VST4d16Pseudo_UPD,   ARM::VST4d16_UPD, false, true, true,  SingleSpc,  4, 4 ,true},
00314 { ARM::VST4d32Pseudo,       ARM::VST4d32,      false, false, false, SingleSpc,  4, 2 ,true},
00315 { ARM::VST4d32Pseudo_UPD,   ARM::VST4d32_UPD, false, true, true,  SingleSpc,  4, 2 ,true},
00316 { ARM::VST4d8Pseudo,        ARM::VST4d8,       false, false, false, SingleSpc,  4, 8 ,true},
00317 { ARM::VST4d8Pseudo_UPD,    ARM::VST4d8_UPD, false, true, true,  SingleSpc,  4, 8 ,true},
00318 
00319 { ARM::VST4q16Pseudo_UPD,    ARM::VST4q16_UPD, false, true, true,  EvenDblSpc, 4, 4 ,true},
00320 { ARM::VST4q16oddPseudo,     ARM::VST4q16,     false, false, false, OddDblSpc,  4, 4 ,true},
00321 { ARM::VST4q16oddPseudo_UPD, ARM::VST4q16_UPD, false, true, true,  OddDblSpc,  4, 4 ,true},
00322 { ARM::VST4q32Pseudo_UPD,    ARM::VST4q32_UPD, false, true, true,  EvenDblSpc, 4, 2 ,true},
00323 { ARM::VST4q32oddPseudo,     ARM::VST4q32,     false, false, false, OddDblSpc,  4, 2 ,true},
00324 { ARM::VST4q32oddPseudo_UPD, ARM::VST4q32_UPD, false, true, true,  OddDblSpc,  4, 2 ,true},
00325 { ARM::VST4q8Pseudo_UPD,     ARM::VST4q8_UPD, false, true, true,  EvenDblSpc, 4, 8 ,true},
00326 { ARM::VST4q8oddPseudo,      ARM::VST4q8,      false, false, false, OddDblSpc,  4, 8 ,true},
00327 { ARM::VST4q8oddPseudo_UPD,  ARM::VST4q8_UPD, false, true, true,  OddDblSpc,  4, 8 ,true}
00328 };
00329 
00330 /// LookupNEONLdSt - Search the NEONLdStTable for information about a NEON
00331 /// load or store pseudo instruction.
00332 static const NEONLdStTableEntry *LookupNEONLdSt(unsigned Opcode) {
00333   const unsigned NumEntries = array_lengthof(NEONLdStTable);
00334 
00335 #ifndef NDEBUG
00336   // Make sure the table is sorted.
00337   static bool TableChecked = false;
00338   if (!TableChecked) {
00339     for (unsigned i = 0; i != NumEntries-1; ++i)
00340       assert(NEONLdStTable[i] < NEONLdStTable[i+1] &&
00341              "NEONLdStTable is not sorted!");
00342     TableChecked = true;
00343   }
00344 #endif
00345 
00346   const NEONLdStTableEntry *I =
00347     std::lower_bound(NEONLdStTable, NEONLdStTable + NumEntries, Opcode);
00348   if (I != NEONLdStTable + NumEntries && I->PseudoOpc == Opcode)
00349     return I;
00350   return nullptr;
00351 }
00352 
00353 /// GetDSubRegs - Get 4 D subregisters of a Q, QQ, or QQQQ register,
00354 /// corresponding to the specified register spacing.  Not all of the results
00355 /// are necessarily valid, e.g., a Q register only has 2 D subregisters.
00356 static void GetDSubRegs(unsigned Reg, NEONRegSpacing RegSpc,
00357                         const TargetRegisterInfo *TRI, unsigned &D0,
00358                         unsigned &D1, unsigned &D2, unsigned &D3) {
00359   if (RegSpc == SingleSpc) {
00360     D0 = TRI->getSubReg(Reg, ARM::dsub_0);
00361     D1 = TRI->getSubReg(Reg, ARM::dsub_1);
00362     D2 = TRI->getSubReg(Reg, ARM::dsub_2);
00363     D3 = TRI->getSubReg(Reg, ARM::dsub_3);
00364   } else if (RegSpc == EvenDblSpc) {
00365     D0 = TRI->getSubReg(Reg, ARM::dsub_0);
00366     D1 = TRI->getSubReg(Reg, ARM::dsub_2);
00367     D2 = TRI->getSubReg(Reg, ARM::dsub_4);
00368     D3 = TRI->getSubReg(Reg, ARM::dsub_6);
00369   } else {
00370     assert(RegSpc == OddDblSpc && "unknown register spacing");
00371     D0 = TRI->getSubReg(Reg, ARM::dsub_1);
00372     D1 = TRI->getSubReg(Reg, ARM::dsub_3);
00373     D2 = TRI->getSubReg(Reg, ARM::dsub_5);
00374     D3 = TRI->getSubReg(Reg, ARM::dsub_7);
00375   }
00376 }
00377 
00378 /// ExpandVLD - Translate VLD pseudo instructions with Q, QQ or QQQQ register
00379 /// operands to real VLD instructions with D register operands.
00380 void ARMExpandPseudo::ExpandVLD(MachineBasicBlock::iterator &MBBI) {
00381   MachineInstr &MI = *MBBI;
00382   MachineBasicBlock &MBB = *MI.getParent();
00383 
00384   const NEONLdStTableEntry *TableEntry = LookupNEONLdSt(MI.getOpcode());
00385   assert(TableEntry && TableEntry->IsLoad && "NEONLdStTable lookup failed");
00386   NEONRegSpacing RegSpc = (NEONRegSpacing)TableEntry->RegSpacing;
00387   unsigned NumRegs = TableEntry->NumRegs;
00388 
00389   MachineInstrBuilder MIB = BuildMI(MBB, MBBI, MI.getDebugLoc(),
00390                                     TII->get(TableEntry->RealOpc));
00391   unsigned OpIdx = 0;
00392 
00393   bool DstIsDead = MI.getOperand(OpIdx).isDead();
00394   unsigned DstReg = MI.getOperand(OpIdx++).getReg();
00395   unsigned D0, D1, D2, D3;
00396   GetDSubRegs(DstReg, RegSpc, TRI, D0, D1, D2, D3);
00397   MIB.addReg(D0, RegState::Define | getDeadRegState(DstIsDead));
00398   if (NumRegs > 1 && TableEntry->copyAllListRegs)
00399     MIB.addReg(D1, RegState::Define | getDeadRegState(DstIsDead));
00400   if (NumRegs > 2 && TableEntry->copyAllListRegs)
00401     MIB.addReg(D2, RegState::Define | getDeadRegState(DstIsDead));
00402   if (NumRegs > 3 && TableEntry->copyAllListRegs)
00403     MIB.addReg(D3, RegState::Define | getDeadRegState(DstIsDead));
00404 
00405   if (TableEntry->isUpdating)
00406     MIB.addOperand(MI.getOperand(OpIdx++));
00407 
00408   // Copy the addrmode6 operands.
00409   MIB.addOperand(MI.getOperand(OpIdx++));
00410   MIB.addOperand(MI.getOperand(OpIdx++));
00411   // Copy the am6offset operand.
00412   if (TableEntry->hasWritebackOperand)
00413     MIB.addOperand(MI.getOperand(OpIdx++));
00414 
00415   // For an instruction writing double-spaced subregs, the pseudo instruction
00416   // has an extra operand that is a use of the super-register.  Record the
00417   // operand index and skip over it.
00418   unsigned SrcOpIdx = 0;
00419   if (RegSpc == EvenDblSpc || RegSpc == OddDblSpc)
00420     SrcOpIdx = OpIdx++;
00421 
00422   // Copy the predicate operands.
00423   MIB.addOperand(MI.getOperand(OpIdx++));
00424   MIB.addOperand(MI.getOperand(OpIdx++));
00425 
00426   // Copy the super-register source operand used for double-spaced subregs over
00427   // to the new instruction as an implicit operand.
00428   if (SrcOpIdx != 0) {
00429     MachineOperand MO = MI.getOperand(SrcOpIdx);
00430     MO.setImplicit(true);
00431     MIB.addOperand(MO);
00432   }
00433   // Add an implicit def for the super-register.
00434   MIB.addReg(DstReg, RegState::ImplicitDefine | getDeadRegState(DstIsDead));
00435   TransferImpOps(MI, MIB, MIB);
00436 
00437   // Transfer memoperands.
00438   MIB->setMemRefs(MI.memoperands_begin(), MI.memoperands_end());
00439 
00440   MI.eraseFromParent();
00441 }
00442 
00443 /// ExpandVST - Translate VST pseudo instructions with Q, QQ or QQQQ register
00444 /// operands to real VST instructions with D register operands.
00445 void ARMExpandPseudo::ExpandVST(MachineBasicBlock::iterator &MBBI) {
00446   MachineInstr &MI = *MBBI;
00447   MachineBasicBlock &MBB = *MI.getParent();
00448 
00449   const NEONLdStTableEntry *TableEntry = LookupNEONLdSt(MI.getOpcode());
00450   assert(TableEntry && !TableEntry->IsLoad && "NEONLdStTable lookup failed");
00451   NEONRegSpacing RegSpc = (NEONRegSpacing)TableEntry->RegSpacing;
00452   unsigned NumRegs = TableEntry->NumRegs;
00453 
00454   MachineInstrBuilder MIB = BuildMI(MBB, MBBI, MI.getDebugLoc(),
00455                                     TII->get(TableEntry->RealOpc));
00456   unsigned OpIdx = 0;
00457   if (TableEntry->isUpdating)
00458     MIB.addOperand(MI.getOperand(OpIdx++));
00459 
00460   // Copy the addrmode6 operands.
00461   MIB.addOperand(MI.getOperand(OpIdx++));
00462   MIB.addOperand(MI.getOperand(OpIdx++));
00463   // Copy the am6offset operand.
00464   if (TableEntry->hasWritebackOperand)
00465     MIB.addOperand(MI.getOperand(OpIdx++));
00466 
00467   bool SrcIsKill = MI.getOperand(OpIdx).isKill();
00468   bool SrcIsUndef = MI.getOperand(OpIdx).isUndef();
00469   unsigned SrcReg = MI.getOperand(OpIdx++).getReg();
00470   unsigned D0, D1, D2, D3;
00471   GetDSubRegs(SrcReg, RegSpc, TRI, D0, D1, D2, D3);
00472   MIB.addReg(D0, getUndefRegState(SrcIsUndef));
00473   if (NumRegs > 1 && TableEntry->copyAllListRegs)
00474     MIB.addReg(D1, getUndefRegState(SrcIsUndef));
00475   if (NumRegs > 2 && TableEntry->copyAllListRegs)
00476     MIB.addReg(D2, getUndefRegState(SrcIsUndef));
00477   if (NumRegs > 3 && TableEntry->copyAllListRegs)
00478     MIB.addReg(D3, getUndefRegState(SrcIsUndef));
00479 
00480   // Copy the predicate operands.
00481   MIB.addOperand(MI.getOperand(OpIdx++));
00482   MIB.addOperand(MI.getOperand(OpIdx++));
00483 
00484   if (SrcIsKill && !SrcIsUndef) // Add an implicit kill for the super-reg.
00485     MIB->addRegisterKilled(SrcReg, TRI, true);
00486   else if (!SrcIsUndef)
00487     MIB.addReg(SrcReg, RegState::Implicit); // Add implicit uses for src reg.
00488   TransferImpOps(MI, MIB, MIB);
00489 
00490   // Transfer memoperands.
00491   MIB->setMemRefs(MI.memoperands_begin(), MI.memoperands_end());
00492 
00493   MI.eraseFromParent();
00494 }
00495 
00496 /// ExpandLaneOp - Translate VLD*LN and VST*LN instructions with Q, QQ or QQQQ
00497 /// register operands to real instructions with D register operands.
00498 void ARMExpandPseudo::ExpandLaneOp(MachineBasicBlock::iterator &MBBI) {
00499   MachineInstr &MI = *MBBI;
00500   MachineBasicBlock &MBB = *MI.getParent();
00501 
00502   const NEONLdStTableEntry *TableEntry = LookupNEONLdSt(MI.getOpcode());
00503   assert(TableEntry && "NEONLdStTable lookup failed");
00504   NEONRegSpacing RegSpc = (NEONRegSpacing)TableEntry->RegSpacing;
00505   unsigned NumRegs = TableEntry->NumRegs;
00506   unsigned RegElts = TableEntry->RegElts;
00507 
00508   MachineInstrBuilder MIB = BuildMI(MBB, MBBI, MI.getDebugLoc(),
00509                                     TII->get(TableEntry->RealOpc));
00510   unsigned OpIdx = 0;
00511   // The lane operand is always the 3rd from last operand, before the 2
00512   // predicate operands.
00513   unsigned Lane = MI.getOperand(MI.getDesc().getNumOperands() - 3).getImm();
00514 
00515   // Adjust the lane and spacing as needed for Q registers.
00516   assert(RegSpc != OddDblSpc && "unexpected register spacing for VLD/VST-lane");
00517   if (RegSpc == EvenDblSpc && Lane >= RegElts) {
00518     RegSpc = OddDblSpc;
00519     Lane -= RegElts;
00520   }
00521   assert(Lane < RegElts && "out of range lane for VLD/VST-lane");
00522 
00523   unsigned D0 = 0, D1 = 0, D2 = 0, D3 = 0;
00524   unsigned DstReg = 0;
00525   bool DstIsDead = false;
00526   if (TableEntry->IsLoad) {
00527     DstIsDead = MI.getOperand(OpIdx).isDead();
00528     DstReg = MI.getOperand(OpIdx++).getReg();
00529     GetDSubRegs(DstReg, RegSpc, TRI, D0, D1, D2, D3);
00530     MIB.addReg(D0, RegState::Define | getDeadRegState(DstIsDead));
00531     if (NumRegs > 1)
00532       MIB.addReg(D1, RegState::Define | getDeadRegState(DstIsDead));
00533     if (NumRegs > 2)
00534       MIB.addReg(D2, RegState::Define | getDeadRegState(DstIsDead));
00535     if (NumRegs > 3)
00536       MIB.addReg(D3, RegState::Define | getDeadRegState(DstIsDead));
00537   }
00538 
00539   if (TableEntry->isUpdating)
00540     MIB.addOperand(MI.getOperand(OpIdx++));
00541 
00542   // Copy the addrmode6 operands.
00543   MIB.addOperand(MI.getOperand(OpIdx++));
00544   MIB.addOperand(MI.getOperand(OpIdx++));
00545   // Copy the am6offset operand.
00546   if (TableEntry->hasWritebackOperand)
00547     MIB.addOperand(MI.getOperand(OpIdx++));
00548 
00549   // Grab the super-register source.
00550   MachineOperand MO = MI.getOperand(OpIdx++);
00551   if (!TableEntry->IsLoad)
00552     GetDSubRegs(MO.getReg(), RegSpc, TRI, D0, D1, D2, D3);
00553 
00554   // Add the subregs as sources of the new instruction.
00555   unsigned SrcFlags = (getUndefRegState(MO.isUndef()) |
00556                        getKillRegState(MO.isKill()));
00557   MIB.addReg(D0, SrcFlags);
00558   if (NumRegs > 1)
00559     MIB.addReg(D1, SrcFlags);
00560   if (NumRegs > 2)
00561     MIB.addReg(D2, SrcFlags);
00562   if (NumRegs > 3)
00563     MIB.addReg(D3, SrcFlags);
00564 
00565   // Add the lane number operand.
00566   MIB.addImm(Lane);
00567   OpIdx += 1;
00568 
00569   // Copy the predicate operands.
00570   MIB.addOperand(MI.getOperand(OpIdx++));
00571   MIB.addOperand(MI.getOperand(OpIdx++));
00572 
00573   // Copy the super-register source to be an implicit source.
00574   MO.setImplicit(true);
00575   MIB.addOperand(MO);
00576   if (TableEntry->IsLoad)
00577     // Add an implicit def for the super-register.
00578     MIB.addReg(DstReg, RegState::ImplicitDefine | getDeadRegState(DstIsDead));
00579   TransferImpOps(MI, MIB, MIB);
00580   // Transfer memoperands.
00581   MIB->setMemRefs(MI.memoperands_begin(), MI.memoperands_end());
00582   MI.eraseFromParent();
00583 }
00584 
00585 /// ExpandVTBL - Translate VTBL and VTBX pseudo instructions with Q or QQ
00586 /// register operands to real instructions with D register operands.
00587 void ARMExpandPseudo::ExpandVTBL(MachineBasicBlock::iterator &MBBI,
00588                                  unsigned Opc, bool IsExt) {
00589   MachineInstr &MI = *MBBI;
00590   MachineBasicBlock &MBB = *MI.getParent();
00591 
00592   MachineInstrBuilder MIB = BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(Opc));
00593   unsigned OpIdx = 0;
00594 
00595   // Transfer the destination register operand.
00596   MIB.addOperand(MI.getOperand(OpIdx++));
00597   if (IsExt)
00598     MIB.addOperand(MI.getOperand(OpIdx++));
00599 
00600   bool SrcIsKill = MI.getOperand(OpIdx).isKill();
00601   unsigned SrcReg = MI.getOperand(OpIdx++).getReg();
00602   unsigned D0, D1, D2, D3;
00603   GetDSubRegs(SrcReg, SingleSpc, TRI, D0, D1, D2, D3);
00604   MIB.addReg(D0);
00605 
00606   // Copy the other source register operand.
00607   MIB.addOperand(MI.getOperand(OpIdx++));
00608 
00609   // Copy the predicate operands.
00610   MIB.addOperand(MI.getOperand(OpIdx++));
00611   MIB.addOperand(MI.getOperand(OpIdx++));
00612 
00613   // Add an implicit kill and use for the super-reg.
00614   MIB.addReg(SrcReg, RegState::Implicit | getKillRegState(SrcIsKill));
00615   TransferImpOps(MI, MIB, MIB);
00616   MI.eraseFromParent();
00617 }
00618 
00619 static bool IsAnAddressOperand(const MachineOperand &MO) {
00620   // This check is overly conservative.  Unless we are certain that the machine
00621   // operand is not a symbol reference, we return that it is a symbol reference.
00622   // This is important as the load pair may not be split up Windows.
00623   switch (MO.getType()) {
00624   case MachineOperand::MO_Register:
00625   case MachineOperand::MO_Immediate:
00626   case MachineOperand::MO_CImmediate:
00627   case MachineOperand::MO_FPImmediate:
00628     return false;
00629   case MachineOperand::MO_MachineBasicBlock:
00630     return true;
00631   case MachineOperand::MO_FrameIndex:
00632     return false;
00633   case MachineOperand::MO_ConstantPoolIndex:
00634   case MachineOperand::MO_TargetIndex:
00635   case MachineOperand::MO_JumpTableIndex:
00636   case MachineOperand::MO_ExternalSymbol:
00637   case MachineOperand::MO_GlobalAddress:
00638   case MachineOperand::MO_BlockAddress:
00639     return true;
00640   case MachineOperand::MO_RegisterMask:
00641   case MachineOperand::MO_RegisterLiveOut:
00642     return false;
00643   case MachineOperand::MO_Metadata:
00644   case MachineOperand::MO_MCSymbol:
00645     return true;
00646   case MachineOperand::MO_CFIIndex:
00647     return false;
00648   }
00649   llvm_unreachable("unhandled machine operand type");
00650 }
00651 
00652 void ARMExpandPseudo::ExpandMOV32BitImm(MachineBasicBlock &MBB,
00653                                         MachineBasicBlock::iterator &MBBI) {
00654   MachineInstr &MI = *MBBI;
00655   unsigned Opcode = MI.getOpcode();
00656   unsigned PredReg = 0;
00657   ARMCC::CondCodes Pred = getInstrPredicate(&MI, PredReg);
00658   unsigned DstReg = MI.getOperand(0).getReg();
00659   bool DstIsDead = MI.getOperand(0).isDead();
00660   bool isCC = Opcode == ARM::MOVCCi32imm || Opcode == ARM::t2MOVCCi32imm;
00661   const MachineOperand &MO = MI.getOperand(isCC ? 2 : 1);
00662   bool RequiresBundling = STI->isTargetWindows() && IsAnAddressOperand(MO);
00663   MachineInstrBuilder LO16, HI16;
00664 
00665   if (!STI->hasV6T2Ops() &&
00666       (Opcode == ARM::MOVi32imm || Opcode == ARM::MOVCCi32imm)) {
00667     // FIXME Windows CE supports older ARM CPUs
00668     assert(!STI->isTargetWindows() && "Windows on ARM requires ARMv7+");
00669 
00670     // Expand into a movi + orr.
00671     LO16 = BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(ARM::MOVi), DstReg);
00672     HI16 = BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(ARM::ORRri))
00673       .addReg(DstReg, RegState::Define | getDeadRegState(DstIsDead))
00674       .addReg(DstReg);
00675 
00676     assert (MO.isImm() && "MOVi32imm w/ non-immediate source operand!");
00677     unsigned ImmVal = (unsigned)MO.getImm();
00678     unsigned SOImmValV1 = ARM_AM::getSOImmTwoPartFirst(ImmVal);
00679     unsigned SOImmValV2 = ARM_AM::getSOImmTwoPartSecond(ImmVal);
00680     LO16 = LO16.addImm(SOImmValV1);
00681     HI16 = HI16.addImm(SOImmValV2);
00682     LO16->setMemRefs(MI.memoperands_begin(), MI.memoperands_end());
00683     HI16->setMemRefs(MI.memoperands_begin(), MI.memoperands_end());
00684     LO16.addImm(Pred).addReg(PredReg).addReg(0);
00685     HI16.addImm(Pred).addReg(PredReg).addReg(0);
00686     TransferImpOps(MI, LO16, HI16);
00687     MI.eraseFromParent();
00688     return;
00689   }
00690 
00691   unsigned LO16Opc = 0;
00692   unsigned HI16Opc = 0;
00693   if (Opcode == ARM::t2MOVi32imm || Opcode == ARM::t2MOVCCi32imm) {
00694     LO16Opc = ARM::t2MOVi16;
00695     HI16Opc = ARM::t2MOVTi16;
00696   } else {
00697     LO16Opc = ARM::MOVi16;
00698     HI16Opc = ARM::MOVTi16;
00699   }
00700 
00701   LO16 = BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(LO16Opc), DstReg);
00702   HI16 = BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(HI16Opc))
00703     .addReg(DstReg, RegState::Define | getDeadRegState(DstIsDead))
00704     .addReg(DstReg);
00705 
00706   switch (MO.getType()) {
00707   case MachineOperand::MO_Immediate: {
00708     unsigned Imm = MO.getImm();
00709     unsigned Lo16 = Imm & 0xffff;
00710     unsigned Hi16 = (Imm >> 16) & 0xffff;
00711     LO16 = LO16.addImm(Lo16);
00712     HI16 = HI16.addImm(Hi16);
00713     break;
00714   }
00715   case MachineOperand::MO_ExternalSymbol: {
00716     const char *ES = MO.getSymbolName();
00717     unsigned TF = MO.getTargetFlags();
00718     LO16 = LO16.addExternalSymbol(ES, TF | ARMII::MO_LO16);
00719     HI16 = HI16.addExternalSymbol(ES, TF | ARMII::MO_HI16);
00720     break;
00721   }
00722   default: {
00723     const GlobalValue *GV = MO.getGlobal();
00724     unsigned TF = MO.getTargetFlags();
00725     LO16 = LO16.addGlobalAddress(GV, MO.getOffset(), TF | ARMII::MO_LO16);
00726     HI16 = HI16.addGlobalAddress(GV, MO.getOffset(), TF | ARMII::MO_HI16);
00727     break;
00728   }
00729   }
00730 
00731   LO16->setMemRefs(MI.memoperands_begin(), MI.memoperands_end());
00732   HI16->setMemRefs(MI.memoperands_begin(), MI.memoperands_end());
00733   LO16.addImm(Pred).addReg(PredReg);
00734   HI16.addImm(Pred).addReg(PredReg);
00735 
00736   if (RequiresBundling)
00737     finalizeBundle(MBB, &*LO16, &*MBBI);
00738 
00739   TransferImpOps(MI, LO16, HI16);
00740   MI.eraseFromParent();
00741 }
00742 
00743 bool ARMExpandPseudo::ExpandMI(MachineBasicBlock &MBB,
00744                                MachineBasicBlock::iterator MBBI) {
00745   MachineInstr &MI = *MBBI;
00746   unsigned Opcode = MI.getOpcode();
00747   switch (Opcode) {
00748     default:
00749       return false;
00750     case ARM::VMOVScc:
00751     case ARM::VMOVDcc: {
00752       unsigned newOpc = Opcode == ARM::VMOVScc ? ARM::VMOVS : ARM::VMOVD;
00753       BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(newOpc),
00754               MI.getOperand(1).getReg())
00755         .addOperand(MI.getOperand(2))
00756         .addImm(MI.getOperand(3).getImm()) // 'pred'
00757         .addOperand(MI.getOperand(4));
00758 
00759       MI.eraseFromParent();
00760       return true;
00761     }
00762     case ARM::t2MOVCCr:
00763     case ARM::MOVCCr: {
00764       unsigned Opc = AFI->isThumbFunction() ? ARM::t2MOVr : ARM::MOVr;
00765       BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(Opc),
00766               MI.getOperand(1).getReg())
00767         .addOperand(MI.getOperand(2))
00768         .addImm(MI.getOperand(3).getImm()) // 'pred'
00769         .addOperand(MI.getOperand(4))
00770         .addReg(0); // 's' bit
00771 
00772       MI.eraseFromParent();
00773       return true;
00774     }
00775     case ARM::MOVCCsi: {
00776       BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(ARM::MOVsi),
00777               (MI.getOperand(1).getReg()))
00778         .addOperand(MI.getOperand(2))
00779         .addImm(MI.getOperand(3).getImm())
00780         .addImm(MI.getOperand(4).getImm()) // 'pred'
00781         .addOperand(MI.getOperand(5))
00782         .addReg(0); // 's' bit
00783 
00784       MI.eraseFromParent();
00785       return true;
00786     }
00787     case ARM::MOVCCsr: {
00788       BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(ARM::MOVsr),
00789               (MI.getOperand(1).getReg()))
00790         .addOperand(MI.getOperand(2))
00791         .addOperand(MI.getOperand(3))
00792         .addImm(MI.getOperand(4).getImm())
00793         .addImm(MI.getOperand(5).getImm()) // 'pred'
00794         .addOperand(MI.getOperand(6))
00795         .addReg(0); // 's' bit
00796 
00797       MI.eraseFromParent();
00798       return true;
00799     }
00800     case ARM::t2MOVCCi16:
00801     case ARM::MOVCCi16: {
00802       unsigned NewOpc = AFI->isThumbFunction() ? ARM::t2MOVi16 : ARM::MOVi16;
00803       BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(NewOpc),
00804               MI.getOperand(1).getReg())
00805         .addImm(MI.getOperand(2).getImm())
00806         .addImm(MI.getOperand(3).getImm()) // 'pred'
00807         .addOperand(MI.getOperand(4));
00808       MI.eraseFromParent();
00809       return true;
00810     }
00811     case ARM::t2MOVCCi:
00812     case ARM::MOVCCi: {
00813       unsigned Opc = AFI->isThumbFunction() ? ARM::t2MOVi : ARM::MOVi;
00814       BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(Opc),
00815               MI.getOperand(1).getReg())
00816         .addImm(MI.getOperand(2).getImm())
00817         .addImm(MI.getOperand(3).getImm()) // 'pred'
00818         .addOperand(MI.getOperand(4))
00819         .addReg(0); // 's' bit
00820 
00821       MI.eraseFromParent();
00822       return true;
00823     }
00824     case ARM::t2MVNCCi:
00825     case ARM::MVNCCi: {
00826       unsigned Opc = AFI->isThumbFunction() ? ARM::t2MVNi : ARM::MVNi;
00827       BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(Opc),
00828               MI.getOperand(1).getReg())
00829         .addImm(MI.getOperand(2).getImm())
00830         .addImm(MI.getOperand(3).getImm()) // 'pred'
00831         .addOperand(MI.getOperand(4))
00832         .addReg(0); // 's' bit
00833 
00834       MI.eraseFromParent();
00835       return true;
00836     }
00837     case ARM::t2MOVCClsl:
00838     case ARM::t2MOVCClsr:
00839     case ARM::t2MOVCCasr:
00840     case ARM::t2MOVCCror: {
00841       unsigned NewOpc;
00842       switch (Opcode) {
00843       case ARM::t2MOVCClsl: NewOpc = ARM::t2LSLri; break;
00844       case ARM::t2MOVCClsr: NewOpc = ARM::t2LSRri; break;
00845       case ARM::t2MOVCCasr: NewOpc = ARM::t2ASRri; break;
00846       case ARM::t2MOVCCror: NewOpc = ARM::t2RORri; break;
00847       default: llvm_unreachable("unexpeced conditional move");
00848       }
00849       BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(NewOpc),
00850               MI.getOperand(1).getReg())
00851         .addOperand(MI.getOperand(2))
00852         .addImm(MI.getOperand(3).getImm())
00853         .addImm(MI.getOperand(4).getImm()) // 'pred'
00854         .addOperand(MI.getOperand(5))
00855         .addReg(0); // 's' bit
00856       MI.eraseFromParent();
00857       return true;
00858     }
00859     case ARM::Int_eh_sjlj_dispatchsetup: {
00860       MachineFunction &MF = *MI.getParent()->getParent();
00861       const ARMBaseInstrInfo *AII =
00862         static_cast<const ARMBaseInstrInfo*>(TII);
00863       const ARMBaseRegisterInfo &RI = AII->getRegisterInfo();
00864       // For functions using a base pointer, we rematerialize it (via the frame
00865       // pointer) here since eh.sjlj.setjmp and eh.sjlj.longjmp don't do it
00866       // for us. Otherwise, expand to nothing.
00867       if (RI.hasBasePointer(MF)) {
00868         int32_t NumBytes = AFI->getFramePtrSpillOffset();
00869         unsigned FramePtr = RI.getFrameRegister(MF);
00870         assert(MF.getSubtarget().getFrameLowering()->hasFP(MF) &&
00871                "base pointer without frame pointer?");
00872 
00873         if (AFI->isThumb2Function()) {
00874           emitT2RegPlusImmediate(MBB, MBBI, MI.getDebugLoc(), ARM::R6,
00875                                  FramePtr, -NumBytes, ARMCC::AL, 0, *TII);
00876         } else if (AFI->isThumbFunction()) {
00877           emitThumbRegPlusImmediate(MBB, MBBI, MI.getDebugLoc(), ARM::R6,
00878                                     FramePtr, -NumBytes, *TII, RI);
00879         } else {
00880           emitARMRegPlusImmediate(MBB, MBBI, MI.getDebugLoc(), ARM::R6,
00881                                   FramePtr, -NumBytes, ARMCC::AL, 0,
00882                                   *TII);
00883         }
00884         // If there's dynamic realignment, adjust for it.
00885         if (RI.needsStackRealignment(MF)) {
00886           MachineFrameInfo  *MFI = MF.getFrameInfo();
00887           unsigned MaxAlign = MFI->getMaxAlignment();
00888           assert (!AFI->isThumb1OnlyFunction());
00889           // Emit bic r6, r6, MaxAlign
00890           unsigned bicOpc = AFI->isThumbFunction() ?
00891             ARM::t2BICri : ARM::BICri;
00892           AddDefaultCC(AddDefaultPred(BuildMI(MBB, MBBI, MI.getDebugLoc(),
00893                                               TII->get(bicOpc), ARM::R6)
00894                                       .addReg(ARM::R6, RegState::Kill)
00895                                       .addImm(MaxAlign-1)));
00896         }
00897 
00898       }
00899       MI.eraseFromParent();
00900       return true;
00901     }
00902 
00903     case ARM::MOVsrl_flag:
00904     case ARM::MOVsra_flag: {
00905       // These are just fancy MOVs instructions.
00906       AddDefaultPred(BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(ARM::MOVsi),
00907                              MI.getOperand(0).getReg())
00908                      .addOperand(MI.getOperand(1))
00909                      .addImm(ARM_AM::getSORegOpc((Opcode == ARM::MOVsrl_flag ?
00910                                                   ARM_AM::lsr : ARM_AM::asr),
00911                                                  1)))
00912         .addReg(ARM::CPSR, RegState::Define);
00913       MI.eraseFromParent();
00914       return true;
00915     }
00916     case ARM::RRX: {
00917       // This encodes as "MOVs Rd, Rm, rrx
00918       MachineInstrBuilder MIB =
00919         AddDefaultPred(BuildMI(MBB, MBBI, MI.getDebugLoc(),TII->get(ARM::MOVsi),
00920                                MI.getOperand(0).getReg())
00921                        .addOperand(MI.getOperand(1))
00922                        .addImm(ARM_AM::getSORegOpc(ARM_AM::rrx, 0)))
00923         .addReg(0);
00924       TransferImpOps(MI, MIB, MIB);
00925       MI.eraseFromParent();
00926       return true;
00927     }
00928     case ARM::tTPsoft:
00929     case ARM::TPsoft: {
00930       MachineInstrBuilder MIB;
00931       if (Opcode == ARM::tTPsoft)
00932         MIB = BuildMI(MBB, MBBI, MI.getDebugLoc(),
00933                       TII->get( ARM::tBL))
00934               .addImm((unsigned)ARMCC::AL).addReg(0)
00935               .addExternalSymbol("__aeabi_read_tp", 0);
00936       else
00937         MIB = BuildMI(MBB, MBBI, MI.getDebugLoc(),
00938                       TII->get( ARM::BL))
00939               .addExternalSymbol("__aeabi_read_tp", 0);
00940 
00941       MIB->setMemRefs(MI.memoperands_begin(), MI.memoperands_end());
00942       TransferImpOps(MI, MIB, MIB);
00943       MI.eraseFromParent();
00944       return true;
00945     }
00946     case ARM::tLDRpci_pic:
00947     case ARM::t2LDRpci_pic: {
00948       unsigned NewLdOpc = (Opcode == ARM::tLDRpci_pic)
00949         ? ARM::tLDRpci : ARM::t2LDRpci;
00950       unsigned DstReg = MI.getOperand(0).getReg();
00951       bool DstIsDead = MI.getOperand(0).isDead();
00952       MachineInstrBuilder MIB1 =
00953         AddDefaultPred(BuildMI(MBB, MBBI, MI.getDebugLoc(),
00954                                TII->get(NewLdOpc), DstReg)
00955                        .addOperand(MI.getOperand(1)));
00956       MIB1->setMemRefs(MI.memoperands_begin(), MI.memoperands_end());
00957       MachineInstrBuilder MIB2 = BuildMI(MBB, MBBI, MI.getDebugLoc(),
00958                                          TII->get(ARM::tPICADD))
00959         .addReg(DstReg, RegState::Define | getDeadRegState(DstIsDead))
00960         .addReg(DstReg)
00961         .addOperand(MI.getOperand(2));
00962       TransferImpOps(MI, MIB1, MIB2);
00963       MI.eraseFromParent();
00964       return true;
00965     }
00966 
00967     case ARM::LDRLIT_ga_abs:
00968     case ARM::LDRLIT_ga_pcrel:
00969     case ARM::LDRLIT_ga_pcrel_ldr:
00970     case ARM::tLDRLIT_ga_abs:
00971     case ARM::tLDRLIT_ga_pcrel: {
00972       unsigned DstReg = MI.getOperand(0).getReg();
00973       bool DstIsDead = MI.getOperand(0).isDead();
00974       const MachineOperand &MO1 = MI.getOperand(1);
00975       const GlobalValue *GV = MO1.getGlobal();
00976       bool IsARM =
00977           Opcode != ARM::tLDRLIT_ga_pcrel && Opcode != ARM::tLDRLIT_ga_abs;
00978       bool IsPIC =
00979           Opcode != ARM::LDRLIT_ga_abs && Opcode != ARM::tLDRLIT_ga_abs;
00980       unsigned LDRLITOpc = IsARM ? ARM::LDRi12 : ARM::tLDRpci;
00981       unsigned PICAddOpc =
00982           IsARM
00983               ? (Opcode == ARM::LDRLIT_ga_pcrel_ldr ? ARM::PICADD : ARM::PICLDR)
00984               : ARM::tPICADD;
00985 
00986       // We need a new const-pool entry to load from.
00987       MachineConstantPool *MCP = MBB.getParent()->getConstantPool();
00988       unsigned ARMPCLabelIndex = 0;
00989       MachineConstantPoolValue *CPV;
00990 
00991       if (IsPIC) {
00992         unsigned PCAdj = IsARM ? 8 : 4;
00993         ARMPCLabelIndex = AFI->createPICLabelUId();
00994         CPV = ARMConstantPoolConstant::Create(GV, ARMPCLabelIndex,
00995                                               ARMCP::CPValue, PCAdj);
00996       } else
00997         CPV = ARMConstantPoolConstant::Create(GV, ARMCP::no_modifier);
00998 
00999       MachineInstrBuilder MIB =
01000           BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(LDRLITOpc), DstReg)
01001             .addConstantPoolIndex(MCP->getConstantPoolIndex(CPV, 4));
01002       if (IsARM)
01003         MIB.addImm(0);
01004       AddDefaultPred(MIB);
01005 
01006       if (IsPIC) {
01007         MachineInstrBuilder MIB =
01008           BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(PICAddOpc))
01009             .addReg(DstReg, RegState::Define | getDeadRegState(DstIsDead))
01010             .addReg(DstReg)
01011             .addImm(ARMPCLabelIndex);
01012 
01013         if (IsARM)
01014           AddDefaultPred(MIB);
01015       }
01016 
01017       MI.eraseFromParent();
01018       return true;
01019     }
01020     case ARM::MOV_ga_pcrel:
01021     case ARM::MOV_ga_pcrel_ldr:
01022     case ARM::t2MOV_ga_pcrel: {
01023       // Expand into movw + movw. Also "add pc" / ldr [pc] in PIC mode.
01024       unsigned LabelId = AFI->createPICLabelUId();
01025       unsigned DstReg = MI.getOperand(0).getReg();
01026       bool DstIsDead = MI.getOperand(0).isDead();
01027       const MachineOperand &MO1 = MI.getOperand(1);
01028       const GlobalValue *GV = MO1.getGlobal();
01029       unsigned TF = MO1.getTargetFlags();
01030       bool isARM = Opcode != ARM::t2MOV_ga_pcrel;
01031       unsigned LO16Opc = isARM ? ARM::MOVi16_ga_pcrel : ARM::t2MOVi16_ga_pcrel;
01032       unsigned HI16Opc = isARM ? ARM::MOVTi16_ga_pcrel :ARM::t2MOVTi16_ga_pcrel;
01033       unsigned LO16TF = TF | ARMII::MO_LO16;
01034       unsigned HI16TF = TF | ARMII::MO_HI16;
01035       unsigned PICAddOpc = isARM
01036         ? (Opcode == ARM::MOV_ga_pcrel_ldr ? ARM::PICLDR : ARM::PICADD)
01037         : ARM::tPICADD;
01038       MachineInstrBuilder MIB1 = BuildMI(MBB, MBBI, MI.getDebugLoc(),
01039                                          TII->get(LO16Opc), DstReg)
01040         .addGlobalAddress(GV, MO1.getOffset(), TF | LO16TF)
01041         .addImm(LabelId);
01042 
01043       BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(HI16Opc), DstReg)
01044         .addReg(DstReg)
01045         .addGlobalAddress(GV, MO1.getOffset(), TF | HI16TF)
01046         .addImm(LabelId);
01047 
01048       MachineInstrBuilder MIB3 = BuildMI(MBB, MBBI, MI.getDebugLoc(),
01049                                          TII->get(PICAddOpc))
01050         .addReg(DstReg, RegState::Define | getDeadRegState(DstIsDead))
01051         .addReg(DstReg).addImm(LabelId);
01052       if (isARM) {
01053         AddDefaultPred(MIB3);
01054         if (Opcode == ARM::MOV_ga_pcrel_ldr)
01055           MIB3->setMemRefs(MI.memoperands_begin(), MI.memoperands_end());
01056       }
01057       TransferImpOps(MI, MIB1, MIB3);
01058       MI.eraseFromParent();
01059       return true;
01060     }
01061 
01062     case ARM::MOVi32imm:
01063     case ARM::MOVCCi32imm:
01064     case ARM::t2MOVi32imm:
01065     case ARM::t2MOVCCi32imm:
01066       ExpandMOV32BitImm(MBB, MBBI);
01067       return true;
01068 
01069     case ARM::SUBS_PC_LR: {
01070       MachineInstrBuilder MIB =
01071           BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(ARM::SUBri), ARM::PC)
01072               .addReg(ARM::LR)
01073               .addOperand(MI.getOperand(0))
01074               .addOperand(MI.getOperand(1))
01075               .addOperand(MI.getOperand(2))
01076               .addReg(ARM::CPSR, RegState::Undef);
01077       TransferImpOps(MI, MIB, MIB);
01078       MI.eraseFromParent();
01079       return true;
01080     }
01081     case ARM::VLDMQIA: {
01082       unsigned NewOpc = ARM::VLDMDIA;
01083       MachineInstrBuilder MIB =
01084         BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(NewOpc));
01085       unsigned OpIdx = 0;
01086 
01087       // Grab the Q register destination.
01088       bool DstIsDead = MI.getOperand(OpIdx).isDead();
01089       unsigned DstReg = MI.getOperand(OpIdx++).getReg();
01090 
01091       // Copy the source register.
01092       MIB.addOperand(MI.getOperand(OpIdx++));
01093 
01094       // Copy the predicate operands.
01095       MIB.addOperand(MI.getOperand(OpIdx++));
01096       MIB.addOperand(MI.getOperand(OpIdx++));
01097 
01098       // Add the destination operands (D subregs).
01099       unsigned D0 = TRI->getSubReg(DstReg, ARM::dsub_0);
01100       unsigned D1 = TRI->getSubReg(DstReg, ARM::dsub_1);
01101       MIB.addReg(D0, RegState::Define | getDeadRegState(DstIsDead))
01102         .addReg(D1, RegState::Define | getDeadRegState(DstIsDead));
01103 
01104       // Add an implicit def for the super-register.
01105       MIB.addReg(DstReg, RegState::ImplicitDefine | getDeadRegState(DstIsDead));
01106       TransferImpOps(MI, MIB, MIB);
01107       MIB.setMemRefs(MI.memoperands_begin(), MI.memoperands_end());
01108       MI.eraseFromParent();
01109       return true;
01110     }
01111 
01112     case ARM::VSTMQIA: {
01113       unsigned NewOpc = ARM::VSTMDIA;
01114       MachineInstrBuilder MIB =
01115         BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(NewOpc));
01116       unsigned OpIdx = 0;
01117 
01118       // Grab the Q register source.
01119       bool SrcIsKill = MI.getOperand(OpIdx).isKill();
01120       unsigned SrcReg = MI.getOperand(OpIdx++).getReg();
01121 
01122       // Copy the destination register.
01123       MIB.addOperand(MI.getOperand(OpIdx++));
01124 
01125       // Copy the predicate operands.
01126       MIB.addOperand(MI.getOperand(OpIdx++));
01127       MIB.addOperand(MI.getOperand(OpIdx++));
01128 
01129       // Add the source operands (D subregs).
01130       unsigned D0 = TRI->getSubReg(SrcReg, ARM::dsub_0);
01131       unsigned D1 = TRI->getSubReg(SrcReg, ARM::dsub_1);
01132       MIB.addReg(D0).addReg(D1);
01133 
01134       if (SrcIsKill)      // Add an implicit kill for the Q register.
01135         MIB->addRegisterKilled(SrcReg, TRI, true);
01136 
01137       TransferImpOps(MI, MIB, MIB);
01138       MIB.setMemRefs(MI.memoperands_begin(), MI.memoperands_end());
01139       MI.eraseFromParent();
01140       return true;
01141     }
01142 
01143     case ARM::VLD2q8Pseudo:
01144     case ARM::VLD2q16Pseudo:
01145     case ARM::VLD2q32Pseudo:
01146     case ARM::VLD2q8PseudoWB_fixed:
01147     case ARM::VLD2q16PseudoWB_fixed:
01148     case ARM::VLD2q32PseudoWB_fixed:
01149     case ARM::VLD2q8PseudoWB_register:
01150     case ARM::VLD2q16PseudoWB_register:
01151     case ARM::VLD2q32PseudoWB_register:
01152     case ARM::VLD3d8Pseudo:
01153     case ARM::VLD3d16Pseudo:
01154     case ARM::VLD3d32Pseudo:
01155     case ARM::VLD1d64TPseudo:
01156     case ARM::VLD1d64TPseudoWB_fixed:
01157     case ARM::VLD3d8Pseudo_UPD:
01158     case ARM::VLD3d16Pseudo_UPD:
01159     case ARM::VLD3d32Pseudo_UPD:
01160     case ARM::VLD3q8Pseudo_UPD:
01161     case ARM::VLD3q16Pseudo_UPD:
01162     case ARM::VLD3q32Pseudo_UPD:
01163     case ARM::VLD3q8oddPseudo:
01164     case ARM::VLD3q16oddPseudo:
01165     case ARM::VLD3q32oddPseudo:
01166     case ARM::VLD3q8oddPseudo_UPD:
01167     case ARM::VLD3q16oddPseudo_UPD:
01168     case ARM::VLD3q32oddPseudo_UPD:
01169     case ARM::VLD4d8Pseudo:
01170     case ARM::VLD4d16Pseudo:
01171     case ARM::VLD4d32Pseudo:
01172     case ARM::VLD1d64QPseudo:
01173     case ARM::VLD1d64QPseudoWB_fixed:
01174     case ARM::VLD4d8Pseudo_UPD:
01175     case ARM::VLD4d16Pseudo_UPD:
01176     case ARM::VLD4d32Pseudo_UPD:
01177     case ARM::VLD4q8Pseudo_UPD:
01178     case ARM::VLD4q16Pseudo_UPD:
01179     case ARM::VLD4q32Pseudo_UPD:
01180     case ARM::VLD4q8oddPseudo:
01181     case ARM::VLD4q16oddPseudo:
01182     case ARM::VLD4q32oddPseudo:
01183     case ARM::VLD4q8oddPseudo_UPD:
01184     case ARM::VLD4q16oddPseudo_UPD:
01185     case ARM::VLD4q32oddPseudo_UPD:
01186     case ARM::VLD3DUPd8Pseudo:
01187     case ARM::VLD3DUPd16Pseudo:
01188     case ARM::VLD3DUPd32Pseudo:
01189     case ARM::VLD3DUPd8Pseudo_UPD:
01190     case ARM::VLD3DUPd16Pseudo_UPD:
01191     case ARM::VLD3DUPd32Pseudo_UPD:
01192     case ARM::VLD4DUPd8Pseudo:
01193     case ARM::VLD4DUPd16Pseudo:
01194     case ARM::VLD4DUPd32Pseudo:
01195     case ARM::VLD4DUPd8Pseudo_UPD:
01196     case ARM::VLD4DUPd16Pseudo_UPD:
01197     case ARM::VLD4DUPd32Pseudo_UPD:
01198       ExpandVLD(MBBI);
01199       return true;
01200 
01201     case ARM::VST2q8Pseudo:
01202     case ARM::VST2q16Pseudo:
01203     case ARM::VST2q32Pseudo:
01204     case ARM::VST2q8PseudoWB_fixed:
01205     case ARM::VST2q16PseudoWB_fixed:
01206     case ARM::VST2q32PseudoWB_fixed:
01207     case ARM::VST2q8PseudoWB_register:
01208     case ARM::VST2q16PseudoWB_register:
01209     case ARM::VST2q32PseudoWB_register:
01210     case ARM::VST3d8Pseudo:
01211     case ARM::VST3d16Pseudo:
01212     case ARM::VST3d32Pseudo:
01213     case ARM::VST1d64TPseudo:
01214     case ARM::VST3d8Pseudo_UPD:
01215     case ARM::VST3d16Pseudo_UPD:
01216     case ARM::VST3d32Pseudo_UPD:
01217     case ARM::VST1d64TPseudoWB_fixed:
01218     case ARM::VST1d64TPseudoWB_register:
01219     case ARM::VST3q8Pseudo_UPD:
01220     case ARM::VST3q16Pseudo_UPD:
01221     case ARM::VST3q32Pseudo_UPD:
01222     case ARM::VST3q8oddPseudo:
01223     case ARM::VST3q16oddPseudo:
01224     case ARM::VST3q32oddPseudo:
01225     case ARM::VST3q8oddPseudo_UPD:
01226     case ARM::VST3q16oddPseudo_UPD:
01227     case ARM::VST3q32oddPseudo_UPD:
01228     case ARM::VST4d8Pseudo:
01229     case ARM::VST4d16Pseudo:
01230     case ARM::VST4d32Pseudo:
01231     case ARM::VST1d64QPseudo:
01232     case ARM::VST4d8Pseudo_UPD:
01233     case ARM::VST4d16Pseudo_UPD:
01234     case ARM::VST4d32Pseudo_UPD:
01235     case ARM::VST1d64QPseudoWB_fixed:
01236     case ARM::VST1d64QPseudoWB_register:
01237     case ARM::VST4q8Pseudo_UPD:
01238     case ARM::VST4q16Pseudo_UPD:
01239     case ARM::VST4q32Pseudo_UPD:
01240     case ARM::VST4q8oddPseudo:
01241     case ARM::VST4q16oddPseudo:
01242     case ARM::VST4q32oddPseudo:
01243     case ARM::VST4q8oddPseudo_UPD:
01244     case ARM::VST4q16oddPseudo_UPD:
01245     case ARM::VST4q32oddPseudo_UPD:
01246       ExpandVST(MBBI);
01247       return true;
01248 
01249     case ARM::VLD1LNq8Pseudo:
01250     case ARM::VLD1LNq16Pseudo:
01251     case ARM::VLD1LNq32Pseudo:
01252     case ARM::VLD1LNq8Pseudo_UPD:
01253     case ARM::VLD1LNq16Pseudo_UPD:
01254     case ARM::VLD1LNq32Pseudo_UPD:
01255     case ARM::VLD2LNd8Pseudo:
01256     case ARM::VLD2LNd16Pseudo:
01257     case ARM::VLD2LNd32Pseudo:
01258     case ARM::VLD2LNq16Pseudo:
01259     case ARM::VLD2LNq32Pseudo:
01260     case ARM::VLD2LNd8Pseudo_UPD:
01261     case ARM::VLD2LNd16Pseudo_UPD:
01262     case ARM::VLD2LNd32Pseudo_UPD:
01263     case ARM::VLD2LNq16Pseudo_UPD:
01264     case ARM::VLD2LNq32Pseudo_UPD:
01265     case ARM::VLD3LNd8Pseudo:
01266     case ARM::VLD3LNd16Pseudo:
01267     case ARM::VLD3LNd32Pseudo:
01268     case ARM::VLD3LNq16Pseudo:
01269     case ARM::VLD3LNq32Pseudo:
01270     case ARM::VLD3LNd8Pseudo_UPD:
01271     case ARM::VLD3LNd16Pseudo_UPD:
01272     case ARM::VLD3LNd32Pseudo_UPD:
01273     case ARM::VLD3LNq16Pseudo_UPD:
01274     case ARM::VLD3LNq32Pseudo_UPD:
01275     case ARM::VLD4LNd8Pseudo:
01276     case ARM::VLD4LNd16Pseudo:
01277     case ARM::VLD4LNd32Pseudo:
01278     case ARM::VLD4LNq16Pseudo:
01279     case ARM::VLD4LNq32Pseudo:
01280     case ARM::VLD4LNd8Pseudo_UPD:
01281     case ARM::VLD4LNd16Pseudo_UPD:
01282     case ARM::VLD4LNd32Pseudo_UPD:
01283     case ARM::VLD4LNq16Pseudo_UPD:
01284     case ARM::VLD4LNq32Pseudo_UPD:
01285     case ARM::VST1LNq8Pseudo:
01286     case ARM::VST1LNq16Pseudo:
01287     case ARM::VST1LNq32Pseudo:
01288     case ARM::VST1LNq8Pseudo_UPD:
01289     case ARM::VST1LNq16Pseudo_UPD:
01290     case ARM::VST1LNq32Pseudo_UPD:
01291     case ARM::VST2LNd8Pseudo:
01292     case ARM::VST2LNd16Pseudo:
01293     case ARM::VST2LNd32Pseudo:
01294     case ARM::VST2LNq16Pseudo:
01295     case ARM::VST2LNq32Pseudo:
01296     case ARM::VST2LNd8Pseudo_UPD:
01297     case ARM::VST2LNd16Pseudo_UPD:
01298     case ARM::VST2LNd32Pseudo_UPD:
01299     case ARM::VST2LNq16Pseudo_UPD:
01300     case ARM::VST2LNq32Pseudo_UPD:
01301     case ARM::VST3LNd8Pseudo:
01302     case ARM::VST3LNd16Pseudo:
01303     case ARM::VST3LNd32Pseudo:
01304     case ARM::VST3LNq16Pseudo:
01305     case ARM::VST3LNq32Pseudo:
01306     case ARM::VST3LNd8Pseudo_UPD:
01307     case ARM::VST3LNd16Pseudo_UPD:
01308     case ARM::VST3LNd32Pseudo_UPD:
01309     case ARM::VST3LNq16Pseudo_UPD:
01310     case ARM::VST3LNq32Pseudo_UPD:
01311     case ARM::VST4LNd8Pseudo:
01312     case ARM::VST4LNd16Pseudo:
01313     case ARM::VST4LNd32Pseudo:
01314     case ARM::VST4LNq16Pseudo:
01315     case ARM::VST4LNq32Pseudo:
01316     case ARM::VST4LNd8Pseudo_UPD:
01317     case ARM::VST4LNd16Pseudo_UPD:
01318     case ARM::VST4LNd32Pseudo_UPD:
01319     case ARM::VST4LNq16Pseudo_UPD:
01320     case ARM::VST4LNq32Pseudo_UPD:
01321       ExpandLaneOp(MBBI);
01322       return true;
01323 
01324     case ARM::VTBL3Pseudo: ExpandVTBL(MBBI, ARM::VTBL3, false); return true;
01325     case ARM::VTBL4Pseudo: ExpandVTBL(MBBI, ARM::VTBL4, false); return true;
01326     case ARM::VTBX3Pseudo: ExpandVTBL(MBBI, ARM::VTBX3, true); return true;
01327     case ARM::VTBX4Pseudo: ExpandVTBL(MBBI, ARM::VTBX4, true); return true;
01328   }
01329 }
01330 
01331 bool ARMExpandPseudo::ExpandMBB(MachineBasicBlock &MBB) {
01332   bool Modified = false;
01333 
01334   MachineBasicBlock::iterator MBBI = MBB.begin(), E = MBB.end();
01335   while (MBBI != E) {
01336     MachineBasicBlock::iterator NMBBI = std::next(MBBI);
01337     Modified |= ExpandMI(MBB, MBBI);
01338     MBBI = NMBBI;
01339   }
01340 
01341   return Modified;
01342 }
01343 
01344 bool ARMExpandPseudo::runOnMachineFunction(MachineFunction &MF) {
01345   const TargetMachine &TM = MF.getTarget();
01346   TII = static_cast<const ARMBaseInstrInfo *>(
01347       TM.getSubtargetImpl()->getInstrInfo());
01348   TRI = TM.getSubtargetImpl()->getRegisterInfo();
01349   STI = &TM.getSubtarget<ARMSubtarget>();
01350   AFI = MF.getInfo<ARMFunctionInfo>();
01351 
01352   bool Modified = false;
01353   for (MachineFunction::iterator MFI = MF.begin(), E = MF.end(); MFI != E;
01354        ++MFI)
01355     Modified |= ExpandMBB(*MFI);
01356   if (VerifyARMPseudo)
01357     MF.verify(this, "After expanding ARM pseudo instructions.");
01358   return Modified;
01359 }
01360 
01361 /// createARMExpandPseudoPass - returns an instance of the pseudo instruction
01362 /// expansion pass.
01363 FunctionPass *llvm::createARMExpandPseudoPass() {
01364   return new ARMExpandPseudo();
01365 }