Diana Picus | 2227493 | 2016-11-11 08:27:37 +0000 | [diff] [blame] | 1 | //===- ARMInstructionSelector.cpp ----------------------------*- C++ -*-==// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | /// \file |
| 10 | /// This file implements the targeting of the InstructionSelector class for ARM. |
| 11 | /// \todo This should be generated by TableGen. |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Diana Picus | 2227493 | 2016-11-11 08:27:37 +0000 | [diff] [blame] | 14 | #include "ARMRegisterBankInfo.h" |
| 15 | #include "ARMSubtarget.h" |
| 16 | #include "ARMTargetMachine.h" |
Diana Picus | 674888d | 2017-04-28 09:10:38 +0000 | [diff] [blame] | 17 | #include "llvm/CodeGen/GlobalISel/InstructionSelector.h" |
Diana Picus | 930e6ec | 2017-08-03 09:14:59 +0000 | [diff] [blame] | 18 | #include "llvm/CodeGen/MachineConstantPool.h" |
Diana Picus | 812caee | 2016-12-16 12:54:46 +0000 | [diff] [blame] | 19 | #include "llvm/CodeGen/MachineRegisterInfo.h" |
Diana Picus | 2227493 | 2016-11-11 08:27:37 +0000 | [diff] [blame] | 20 | #include "llvm/Support/Debug.h" |
| 21 | |
| 22 | #define DEBUG_TYPE "arm-isel" |
| 23 | |
Daniel Sanders | 6ab0daa | 2017-07-04 14:35:06 +0000 | [diff] [blame] | 24 | #include "llvm/CodeGen/GlobalISel/InstructionSelectorImpl.h" |
| 25 | |
Diana Picus | 2227493 | 2016-11-11 08:27:37 +0000 | [diff] [blame] | 26 | using namespace llvm; |
| 27 | |
Diana Picus | 674888d | 2017-04-28 09:10:38 +0000 | [diff] [blame] | 28 | namespace { |
Diana Picus | 8abcbbb | 2017-05-02 09:40:49 +0000 | [diff] [blame] | 29 | |
| 30 | #define GET_GLOBALISEL_PREDICATE_BITSET |
| 31 | #include "ARMGenGlobalISel.inc" |
| 32 | #undef GET_GLOBALISEL_PREDICATE_BITSET |
| 33 | |
Diana Picus | 674888d | 2017-04-28 09:10:38 +0000 | [diff] [blame] | 34 | class ARMInstructionSelector : public InstructionSelector { |
| 35 | public: |
Diana Picus | 8abcbbb | 2017-05-02 09:40:49 +0000 | [diff] [blame] | 36 | ARMInstructionSelector(const ARMBaseTargetMachine &TM, const ARMSubtarget &STI, |
Diana Picus | 674888d | 2017-04-28 09:10:38 +0000 | [diff] [blame] | 37 | const ARMRegisterBankInfo &RBI); |
| 38 | |
| 39 | bool select(MachineInstr &I) const override; |
| 40 | |
| 41 | private: |
Diana Picus | 8abcbbb | 2017-05-02 09:40:49 +0000 | [diff] [blame] | 42 | bool selectImpl(MachineInstr &I) const; |
| 43 | |
Diana Picus | 995746d | 2017-07-12 10:31:16 +0000 | [diff] [blame] | 44 | struct CmpConstants; |
| 45 | struct InsertInfo; |
Diana Picus | 5b91653 | 2017-07-07 08:39:04 +0000 | [diff] [blame] | 46 | |
Diana Picus | 995746d | 2017-07-12 10:31:16 +0000 | [diff] [blame] | 47 | bool selectCmp(CmpConstants Helper, MachineInstrBuilder &MIB, |
| 48 | MachineRegisterInfo &MRI) const; |
Diana Picus | 621894a | 2017-06-19 09:40:51 +0000 | [diff] [blame] | 49 | |
Diana Picus | 995746d | 2017-07-12 10:31:16 +0000 | [diff] [blame] | 50 | // Helper for inserting a comparison sequence that sets \p ResReg to either 1 |
| 51 | // if \p LHSReg and \p RHSReg are in the relationship defined by \p Cond, or |
| 52 | // \p PrevRes otherwise. In essence, it computes PrevRes OR (LHS Cond RHS). |
| 53 | bool insertComparison(CmpConstants Helper, InsertInfo I, unsigned ResReg, |
| 54 | ARMCC::CondCodes Cond, unsigned LHSReg, unsigned RHSReg, |
| 55 | unsigned PrevRes) const; |
| 56 | |
| 57 | // Set \p DestReg to \p Constant. |
| 58 | void putConstant(InsertInfo I, unsigned DestReg, unsigned Constant) const; |
| 59 | |
Diana Picus | 930e6ec | 2017-08-03 09:14:59 +0000 | [diff] [blame] | 60 | bool selectGlobal(MachineInstrBuilder &MIB, MachineRegisterInfo &MRI) const; |
Diana Picus | 995746d | 2017-07-12 10:31:16 +0000 | [diff] [blame] | 61 | bool selectSelect(MachineInstrBuilder &MIB, MachineRegisterInfo &MRI) const; |
Diana Picus | e393bc7 | 2017-10-06 15:39:16 +0000 | [diff] [blame^] | 62 | bool selectShift(unsigned ShiftOpc, MachineInstrBuilder &MIB) const; |
Diana Picus | 995746d | 2017-07-12 10:31:16 +0000 | [diff] [blame] | 63 | |
| 64 | // Check if the types match and both operands have the expected size and |
| 65 | // register bank. |
| 66 | bool validOpRegPair(MachineRegisterInfo &MRI, unsigned LHS, unsigned RHS, |
| 67 | unsigned ExpectedSize, unsigned ExpectedRegBankID) const; |
| 68 | |
| 69 | // Check if the register has the expected size and register bank. |
| 70 | bool validReg(MachineRegisterInfo &MRI, unsigned Reg, unsigned ExpectedSize, |
| 71 | unsigned ExpectedRegBankID) const; |
Diana Picus | 7145d22 | 2017-06-27 09:19:51 +0000 | [diff] [blame] | 72 | |
Diana Picus | 674888d | 2017-04-28 09:10:38 +0000 | [diff] [blame] | 73 | const ARMBaseInstrInfo &TII; |
| 74 | const ARMBaseRegisterInfo &TRI; |
Diana Picus | 8abcbbb | 2017-05-02 09:40:49 +0000 | [diff] [blame] | 75 | const ARMBaseTargetMachine &TM; |
Diana Picus | 674888d | 2017-04-28 09:10:38 +0000 | [diff] [blame] | 76 | const ARMRegisterBankInfo &RBI; |
Diana Picus | 8abcbbb | 2017-05-02 09:40:49 +0000 | [diff] [blame] | 77 | const ARMSubtarget &STI; |
| 78 | |
| 79 | #define GET_GLOBALISEL_PREDICATES_DECL |
| 80 | #include "ARMGenGlobalISel.inc" |
| 81 | #undef GET_GLOBALISEL_PREDICATES_DECL |
| 82 | |
| 83 | // We declare the temporaries used by selectImpl() in the class to minimize the |
| 84 | // cost of constructing placeholder values. |
| 85 | #define GET_GLOBALISEL_TEMPORARIES_DECL |
| 86 | #include "ARMGenGlobalISel.inc" |
| 87 | #undef GET_GLOBALISEL_TEMPORARIES_DECL |
Diana Picus | 674888d | 2017-04-28 09:10:38 +0000 | [diff] [blame] | 88 | }; |
| 89 | } // end anonymous namespace |
| 90 | |
| 91 | namespace llvm { |
| 92 | InstructionSelector * |
Diana Picus | 8abcbbb | 2017-05-02 09:40:49 +0000 | [diff] [blame] | 93 | createARMInstructionSelector(const ARMBaseTargetMachine &TM, |
| 94 | const ARMSubtarget &STI, |
Diana Picus | 674888d | 2017-04-28 09:10:38 +0000 | [diff] [blame] | 95 | const ARMRegisterBankInfo &RBI) { |
Diana Picus | 8abcbbb | 2017-05-02 09:40:49 +0000 | [diff] [blame] | 96 | return new ARMInstructionSelector(TM, STI, RBI); |
Diana Picus | 674888d | 2017-04-28 09:10:38 +0000 | [diff] [blame] | 97 | } |
| 98 | } |
| 99 | |
Daniel Sanders | 8e82af2 | 2017-07-27 11:03:45 +0000 | [diff] [blame] | 100 | const unsigned zero_reg = 0; |
Diana Picus | 8abcbbb | 2017-05-02 09:40:49 +0000 | [diff] [blame] | 101 | |
| 102 | #define GET_GLOBALISEL_IMPL |
| 103 | #include "ARMGenGlobalISel.inc" |
| 104 | #undef GET_GLOBALISEL_IMPL |
| 105 | |
| 106 | ARMInstructionSelector::ARMInstructionSelector(const ARMBaseTargetMachine &TM, |
| 107 | const ARMSubtarget &STI, |
Diana Picus | 2227493 | 2016-11-11 08:27:37 +0000 | [diff] [blame] | 108 | const ARMRegisterBankInfo &RBI) |
Diana Picus | 895c6aa | 2016-11-15 16:42:10 +0000 | [diff] [blame] | 109 | : InstructionSelector(), TII(*STI.getInstrInfo()), |
Diana Picus | 8abcbbb | 2017-05-02 09:40:49 +0000 | [diff] [blame] | 110 | TRI(*STI.getRegisterInfo()), TM(TM), RBI(RBI), STI(STI), |
| 111 | #define GET_GLOBALISEL_PREDICATES_INIT |
| 112 | #include "ARMGenGlobalISel.inc" |
| 113 | #undef GET_GLOBALISEL_PREDICATES_INIT |
| 114 | #define GET_GLOBALISEL_TEMPORARIES_INIT |
| 115 | #include "ARMGenGlobalISel.inc" |
| 116 | #undef GET_GLOBALISEL_TEMPORARIES_INIT |
| 117 | { |
| 118 | } |
Diana Picus | 2227493 | 2016-11-11 08:27:37 +0000 | [diff] [blame] | 119 | |
Diana Picus | 812caee | 2016-12-16 12:54:46 +0000 | [diff] [blame] | 120 | static bool selectCopy(MachineInstr &I, const TargetInstrInfo &TII, |
| 121 | MachineRegisterInfo &MRI, const TargetRegisterInfo &TRI, |
| 122 | const RegisterBankInfo &RBI) { |
| 123 | unsigned DstReg = I.getOperand(0).getReg(); |
| 124 | if (TargetRegisterInfo::isPhysicalRegister(DstReg)) |
| 125 | return true; |
| 126 | |
| 127 | const RegisterBank *RegBank = RBI.getRegBank(DstReg, MRI, TRI); |
Benjamin Kramer | 24bf868 | 2016-12-16 13:13:03 +0000 | [diff] [blame] | 128 | (void)RegBank; |
Diana Picus | 812caee | 2016-12-16 12:54:46 +0000 | [diff] [blame] | 129 | assert(RegBank && "Can't get reg bank for virtual register"); |
| 130 | |
Diana Picus | 36aa09f | 2016-12-19 14:07:50 +0000 | [diff] [blame] | 131 | const unsigned DstSize = MRI.getType(DstReg).getSizeInBits(); |
Diana Picus | 4fa83c0 | 2017-02-08 13:23:04 +0000 | [diff] [blame] | 132 | assert((RegBank->getID() == ARM::GPRRegBankID || |
| 133 | RegBank->getID() == ARM::FPRRegBankID) && |
| 134 | "Unsupported reg bank"); |
| 135 | |
Diana Picus | 812caee | 2016-12-16 12:54:46 +0000 | [diff] [blame] | 136 | const TargetRegisterClass *RC = &ARM::GPRRegClass; |
| 137 | |
Diana Picus | 4fa83c0 | 2017-02-08 13:23:04 +0000 | [diff] [blame] | 138 | if (RegBank->getID() == ARM::FPRRegBankID) { |
Diana Picus | 6beef3c | 2017-02-16 12:19:52 +0000 | [diff] [blame] | 139 | if (DstSize == 32) |
| 140 | RC = &ARM::SPRRegClass; |
| 141 | else if (DstSize == 64) |
| 142 | RC = &ARM::DPRRegClass; |
| 143 | else |
| 144 | llvm_unreachable("Unsupported destination size"); |
Diana Picus | 4fa83c0 | 2017-02-08 13:23:04 +0000 | [diff] [blame] | 145 | } |
| 146 | |
Diana Picus | 812caee | 2016-12-16 12:54:46 +0000 | [diff] [blame] | 147 | // No need to constrain SrcReg. It will get constrained when |
| 148 | // we hit another of its uses or its defs. |
| 149 | // Copies do not have constraints. |
| 150 | if (!RBI.constrainGenericRegister(DstReg, *RC, MRI)) { |
| 151 | DEBUG(dbgs() << "Failed to constrain " << TII.getName(I.getOpcode()) |
| 152 | << " operand\n"); |
| 153 | return false; |
| 154 | } |
| 155 | return true; |
| 156 | } |
| 157 | |
Diana Picus | 0b4190a | 2017-06-07 12:35:05 +0000 | [diff] [blame] | 158 | static bool selectMergeValues(MachineInstrBuilder &MIB, |
| 159 | const ARMBaseInstrInfo &TII, |
| 160 | MachineRegisterInfo &MRI, |
| 161 | const TargetRegisterInfo &TRI, |
| 162 | const RegisterBankInfo &RBI) { |
| 163 | assert(TII.getSubtarget().hasVFP2() && "Can't select merge without VFP"); |
Diana Picus | b1701e0 | 2017-02-16 12:19:57 +0000 | [diff] [blame] | 164 | |
Diana Picus | 0b4190a | 2017-06-07 12:35:05 +0000 | [diff] [blame] | 165 | // We only support G_MERGE_VALUES as a way to stick together two scalar GPRs |
Diana Picus | b1701e0 | 2017-02-16 12:19:57 +0000 | [diff] [blame] | 166 | // into one DPR. |
| 167 | unsigned VReg0 = MIB->getOperand(0).getReg(); |
| 168 | (void)VReg0; |
| 169 | assert(MRI.getType(VReg0).getSizeInBits() == 64 && |
| 170 | RBI.getRegBank(VReg0, MRI, TRI)->getID() == ARM::FPRRegBankID && |
Diana Picus | 0b4190a | 2017-06-07 12:35:05 +0000 | [diff] [blame] | 171 | "Unsupported operand for G_MERGE_VALUES"); |
Diana Picus | b1701e0 | 2017-02-16 12:19:57 +0000 | [diff] [blame] | 172 | unsigned VReg1 = MIB->getOperand(1).getReg(); |
| 173 | (void)VReg1; |
| 174 | assert(MRI.getType(VReg1).getSizeInBits() == 32 && |
| 175 | RBI.getRegBank(VReg1, MRI, TRI)->getID() == ARM::GPRRegBankID && |
Diana Picus | 0b4190a | 2017-06-07 12:35:05 +0000 | [diff] [blame] | 176 | "Unsupported operand for G_MERGE_VALUES"); |
| 177 | unsigned VReg2 = MIB->getOperand(2).getReg(); |
Diana Picus | b1701e0 | 2017-02-16 12:19:57 +0000 | [diff] [blame] | 178 | (void)VReg2; |
| 179 | assert(MRI.getType(VReg2).getSizeInBits() == 32 && |
| 180 | RBI.getRegBank(VReg2, MRI, TRI)->getID() == ARM::GPRRegBankID && |
Diana Picus | 0b4190a | 2017-06-07 12:35:05 +0000 | [diff] [blame] | 181 | "Unsupported operand for G_MERGE_VALUES"); |
Diana Picus | b1701e0 | 2017-02-16 12:19:57 +0000 | [diff] [blame] | 182 | |
| 183 | MIB->setDesc(TII.get(ARM::VMOVDRR)); |
| 184 | MIB.add(predOps(ARMCC::AL)); |
| 185 | |
| 186 | return true; |
| 187 | } |
| 188 | |
Diana Picus | 0b4190a | 2017-06-07 12:35:05 +0000 | [diff] [blame] | 189 | static bool selectUnmergeValues(MachineInstrBuilder &MIB, |
| 190 | const ARMBaseInstrInfo &TII, |
| 191 | MachineRegisterInfo &MRI, |
| 192 | const TargetRegisterInfo &TRI, |
| 193 | const RegisterBankInfo &RBI) { |
| 194 | assert(TII.getSubtarget().hasVFP2() && "Can't select unmerge without VFP"); |
Diana Picus | b1701e0 | 2017-02-16 12:19:57 +0000 | [diff] [blame] | 195 | |
Diana Picus | 0b4190a | 2017-06-07 12:35:05 +0000 | [diff] [blame] | 196 | // We only support G_UNMERGE_VALUES as a way to break up one DPR into two |
| 197 | // GPRs. |
Diana Picus | b1701e0 | 2017-02-16 12:19:57 +0000 | [diff] [blame] | 198 | unsigned VReg0 = MIB->getOperand(0).getReg(); |
| 199 | (void)VReg0; |
| 200 | assert(MRI.getType(VReg0).getSizeInBits() == 32 && |
| 201 | RBI.getRegBank(VReg0, MRI, TRI)->getID() == ARM::GPRRegBankID && |
Diana Picus | 0b4190a | 2017-06-07 12:35:05 +0000 | [diff] [blame] | 202 | "Unsupported operand for G_UNMERGE_VALUES"); |
Diana Picus | b1701e0 | 2017-02-16 12:19:57 +0000 | [diff] [blame] | 203 | unsigned VReg1 = MIB->getOperand(1).getReg(); |
| 204 | (void)VReg1; |
Diana Picus | 0b4190a | 2017-06-07 12:35:05 +0000 | [diff] [blame] | 205 | assert(MRI.getType(VReg1).getSizeInBits() == 32 && |
| 206 | RBI.getRegBank(VReg1, MRI, TRI)->getID() == ARM::GPRRegBankID && |
| 207 | "Unsupported operand for G_UNMERGE_VALUES"); |
| 208 | unsigned VReg2 = MIB->getOperand(2).getReg(); |
| 209 | (void)VReg2; |
| 210 | assert(MRI.getType(VReg2).getSizeInBits() == 64 && |
| 211 | RBI.getRegBank(VReg2, MRI, TRI)->getID() == ARM::FPRRegBankID && |
| 212 | "Unsupported operand for G_UNMERGE_VALUES"); |
Diana Picus | b1701e0 | 2017-02-16 12:19:57 +0000 | [diff] [blame] | 213 | |
Diana Picus | 0b4190a | 2017-06-07 12:35:05 +0000 | [diff] [blame] | 214 | MIB->setDesc(TII.get(ARM::VMOVRRD)); |
Diana Picus | b1701e0 | 2017-02-16 12:19:57 +0000 | [diff] [blame] | 215 | MIB.add(predOps(ARMCC::AL)); |
| 216 | |
| 217 | return true; |
| 218 | } |
| 219 | |
Diana Picus | 8b6c6be | 2017-01-25 08:10:40 +0000 | [diff] [blame] | 220 | /// Select the opcode for simple extensions (that translate to a single SXT/UXT |
| 221 | /// instruction). Extension operations more complicated than that should not |
Diana Picus | e836878 | 2017-02-17 13:44:19 +0000 | [diff] [blame] | 222 | /// invoke this. Returns the original opcode if it doesn't know how to select a |
| 223 | /// better one. |
Diana Picus | 8b6c6be | 2017-01-25 08:10:40 +0000 | [diff] [blame] | 224 | static unsigned selectSimpleExtOpc(unsigned Opc, unsigned Size) { |
| 225 | using namespace TargetOpcode; |
| 226 | |
Diana Picus | e836878 | 2017-02-17 13:44:19 +0000 | [diff] [blame] | 227 | if (Size != 8 && Size != 16) |
| 228 | return Opc; |
Diana Picus | 8b6c6be | 2017-01-25 08:10:40 +0000 | [diff] [blame] | 229 | |
| 230 | if (Opc == G_SEXT) |
| 231 | return Size == 8 ? ARM::SXTB : ARM::SXTH; |
| 232 | |
| 233 | if (Opc == G_ZEXT) |
| 234 | return Size == 8 ? ARM::UXTB : ARM::UXTH; |
| 235 | |
Diana Picus | e836878 | 2017-02-17 13:44:19 +0000 | [diff] [blame] | 236 | return Opc; |
Diana Picus | 8b6c6be | 2017-01-25 08:10:40 +0000 | [diff] [blame] | 237 | } |
| 238 | |
Diana Picus | 3b99c64 | 2017-02-24 14:01:27 +0000 | [diff] [blame] | 239 | /// Select the opcode for simple loads and stores. For types smaller than 32 |
| 240 | /// bits, the value will be zero extended. Returns the original opcode if it |
| 241 | /// doesn't know how to select a better one. |
| 242 | static unsigned selectLoadStoreOpCode(unsigned Opc, unsigned RegBank, |
| 243 | unsigned Size) { |
| 244 | bool isStore = Opc == TargetOpcode::G_STORE; |
| 245 | |
Diana Picus | 1540b06 | 2017-02-16 14:10:50 +0000 | [diff] [blame] | 246 | if (RegBank == ARM::GPRRegBankID) { |
| 247 | switch (Size) { |
| 248 | case 1: |
| 249 | case 8: |
Diana Picus | 3b99c64 | 2017-02-24 14:01:27 +0000 | [diff] [blame] | 250 | return isStore ? ARM::STRBi12 : ARM::LDRBi12; |
Diana Picus | 1540b06 | 2017-02-16 14:10:50 +0000 | [diff] [blame] | 251 | case 16: |
Diana Picus | 3b99c64 | 2017-02-24 14:01:27 +0000 | [diff] [blame] | 252 | return isStore ? ARM::STRH : ARM::LDRH; |
Diana Picus | 1540b06 | 2017-02-16 14:10:50 +0000 | [diff] [blame] | 253 | case 32: |
Diana Picus | 3b99c64 | 2017-02-24 14:01:27 +0000 | [diff] [blame] | 254 | return isStore ? ARM::STRi12 : ARM::LDRi12; |
Diana Picus | e836878 | 2017-02-17 13:44:19 +0000 | [diff] [blame] | 255 | default: |
Diana Picus | 3b99c64 | 2017-02-24 14:01:27 +0000 | [diff] [blame] | 256 | return Opc; |
Diana Picus | 1540b06 | 2017-02-16 14:10:50 +0000 | [diff] [blame] | 257 | } |
Diana Picus | 1540b06 | 2017-02-16 14:10:50 +0000 | [diff] [blame] | 258 | } |
| 259 | |
Diana Picus | e836878 | 2017-02-17 13:44:19 +0000 | [diff] [blame] | 260 | if (RegBank == ARM::FPRRegBankID) { |
| 261 | switch (Size) { |
| 262 | case 32: |
Diana Picus | 3b99c64 | 2017-02-24 14:01:27 +0000 | [diff] [blame] | 263 | return isStore ? ARM::VSTRS : ARM::VLDRS; |
Diana Picus | e836878 | 2017-02-17 13:44:19 +0000 | [diff] [blame] | 264 | case 64: |
Diana Picus | 3b99c64 | 2017-02-24 14:01:27 +0000 | [diff] [blame] | 265 | return isStore ? ARM::VSTRD : ARM::VLDRD; |
Diana Picus | e836878 | 2017-02-17 13:44:19 +0000 | [diff] [blame] | 266 | default: |
Diana Picus | 3b99c64 | 2017-02-24 14:01:27 +0000 | [diff] [blame] | 267 | return Opc; |
Diana Picus | e836878 | 2017-02-17 13:44:19 +0000 | [diff] [blame] | 268 | } |
Diana Picus | 278c722 | 2017-01-26 09:20:47 +0000 | [diff] [blame] | 269 | } |
| 270 | |
Diana Picus | 3b99c64 | 2017-02-24 14:01:27 +0000 | [diff] [blame] | 271 | return Opc; |
Diana Picus | 278c722 | 2017-01-26 09:20:47 +0000 | [diff] [blame] | 272 | } |
| 273 | |
Diana Picus | 5b91653 | 2017-07-07 08:39:04 +0000 | [diff] [blame] | 274 | // When lowering comparisons, we sometimes need to perform two compares instead |
| 275 | // of just one. Get the condition codes for both comparisons. If only one is |
| 276 | // needed, the second member of the pair is ARMCC::AL. |
| 277 | static std::pair<ARMCC::CondCodes, ARMCC::CondCodes> |
| 278 | getComparePreds(CmpInst::Predicate Pred) { |
| 279 | std::pair<ARMCC::CondCodes, ARMCC::CondCodes> Preds = {ARMCC::AL, ARMCC::AL}; |
Diana Picus | 621894a | 2017-06-19 09:40:51 +0000 | [diff] [blame] | 280 | switch (Pred) { |
Diana Picus | 621894a | 2017-06-19 09:40:51 +0000 | [diff] [blame] | 281 | case CmpInst::FCMP_ONE: |
Diana Picus | 5b91653 | 2017-07-07 08:39:04 +0000 | [diff] [blame] | 282 | Preds = {ARMCC::GT, ARMCC::MI}; |
| 283 | break; |
Diana Picus | 621894a | 2017-06-19 09:40:51 +0000 | [diff] [blame] | 284 | case CmpInst::FCMP_UEQ: |
Diana Picus | 5b91653 | 2017-07-07 08:39:04 +0000 | [diff] [blame] | 285 | Preds = {ARMCC::EQ, ARMCC::VS}; |
| 286 | break; |
Diana Picus | 621894a | 2017-06-19 09:40:51 +0000 | [diff] [blame] | 287 | case CmpInst::ICMP_EQ: |
| 288 | case CmpInst::FCMP_OEQ: |
Diana Picus | 5b91653 | 2017-07-07 08:39:04 +0000 | [diff] [blame] | 289 | Preds.first = ARMCC::EQ; |
| 290 | break; |
Diana Picus | 621894a | 2017-06-19 09:40:51 +0000 | [diff] [blame] | 291 | case CmpInst::ICMP_SGT: |
| 292 | case CmpInst::FCMP_OGT: |
Diana Picus | 5b91653 | 2017-07-07 08:39:04 +0000 | [diff] [blame] | 293 | Preds.first = ARMCC::GT; |
| 294 | break; |
Diana Picus | 621894a | 2017-06-19 09:40:51 +0000 | [diff] [blame] | 295 | case CmpInst::ICMP_SGE: |
| 296 | case CmpInst::FCMP_OGE: |
Diana Picus | 5b91653 | 2017-07-07 08:39:04 +0000 | [diff] [blame] | 297 | Preds.first = ARMCC::GE; |
| 298 | break; |
Diana Picus | 621894a | 2017-06-19 09:40:51 +0000 | [diff] [blame] | 299 | case CmpInst::ICMP_UGT: |
| 300 | case CmpInst::FCMP_UGT: |
Diana Picus | 5b91653 | 2017-07-07 08:39:04 +0000 | [diff] [blame] | 301 | Preds.first = ARMCC::HI; |
| 302 | break; |
Diana Picus | 621894a | 2017-06-19 09:40:51 +0000 | [diff] [blame] | 303 | case CmpInst::FCMP_OLT: |
Diana Picus | 5b91653 | 2017-07-07 08:39:04 +0000 | [diff] [blame] | 304 | Preds.first = ARMCC::MI; |
| 305 | break; |
Diana Picus | 621894a | 2017-06-19 09:40:51 +0000 | [diff] [blame] | 306 | case CmpInst::ICMP_ULE: |
| 307 | case CmpInst::FCMP_OLE: |
Diana Picus | 5b91653 | 2017-07-07 08:39:04 +0000 | [diff] [blame] | 308 | Preds.first = ARMCC::LS; |
| 309 | break; |
Diana Picus | 621894a | 2017-06-19 09:40:51 +0000 | [diff] [blame] | 310 | case CmpInst::FCMP_ORD: |
Diana Picus | 5b91653 | 2017-07-07 08:39:04 +0000 | [diff] [blame] | 311 | Preds.first = ARMCC::VC; |
| 312 | break; |
Diana Picus | 621894a | 2017-06-19 09:40:51 +0000 | [diff] [blame] | 313 | case CmpInst::FCMP_UNO: |
Diana Picus | 5b91653 | 2017-07-07 08:39:04 +0000 | [diff] [blame] | 314 | Preds.first = ARMCC::VS; |
| 315 | break; |
Diana Picus | 621894a | 2017-06-19 09:40:51 +0000 | [diff] [blame] | 316 | case CmpInst::FCMP_UGE: |
Diana Picus | 5b91653 | 2017-07-07 08:39:04 +0000 | [diff] [blame] | 317 | Preds.first = ARMCC::PL; |
| 318 | break; |
Diana Picus | 621894a | 2017-06-19 09:40:51 +0000 | [diff] [blame] | 319 | case CmpInst::ICMP_SLT: |
| 320 | case CmpInst::FCMP_ULT: |
Diana Picus | 5b91653 | 2017-07-07 08:39:04 +0000 | [diff] [blame] | 321 | Preds.first = ARMCC::LT; |
| 322 | break; |
Diana Picus | 621894a | 2017-06-19 09:40:51 +0000 | [diff] [blame] | 323 | case CmpInst::ICMP_SLE: |
| 324 | case CmpInst::FCMP_ULE: |
Diana Picus | 5b91653 | 2017-07-07 08:39:04 +0000 | [diff] [blame] | 325 | Preds.first = ARMCC::LE; |
| 326 | break; |
Diana Picus | 621894a | 2017-06-19 09:40:51 +0000 | [diff] [blame] | 327 | case CmpInst::FCMP_UNE: |
| 328 | case CmpInst::ICMP_NE: |
Diana Picus | 5b91653 | 2017-07-07 08:39:04 +0000 | [diff] [blame] | 329 | Preds.first = ARMCC::NE; |
| 330 | break; |
Diana Picus | 621894a | 2017-06-19 09:40:51 +0000 | [diff] [blame] | 331 | case CmpInst::ICMP_UGE: |
Diana Picus | 5b91653 | 2017-07-07 08:39:04 +0000 | [diff] [blame] | 332 | Preds.first = ARMCC::HS; |
| 333 | break; |
Diana Picus | 621894a | 2017-06-19 09:40:51 +0000 | [diff] [blame] | 334 | case CmpInst::ICMP_ULT: |
Diana Picus | 5b91653 | 2017-07-07 08:39:04 +0000 | [diff] [blame] | 335 | Preds.first = ARMCC::LO; |
| 336 | break; |
| 337 | default: |
| 338 | break; |
Diana Picus | 621894a | 2017-06-19 09:40:51 +0000 | [diff] [blame] | 339 | } |
Diana Picus | 5b91653 | 2017-07-07 08:39:04 +0000 | [diff] [blame] | 340 | assert(Preds.first != ARMCC::AL && "No comparisons needed?"); |
| 341 | return Preds; |
Diana Picus | 621894a | 2017-06-19 09:40:51 +0000 | [diff] [blame] | 342 | } |
| 343 | |
Diana Picus | 995746d | 2017-07-12 10:31:16 +0000 | [diff] [blame] | 344 | struct ARMInstructionSelector::CmpConstants { |
| 345 | CmpConstants(unsigned CmpOpcode, unsigned FlagsOpcode, unsigned OpRegBank, |
| 346 | unsigned OpSize) |
| 347 | : ComparisonOpcode(CmpOpcode), ReadFlagsOpcode(FlagsOpcode), |
| 348 | OperandRegBankID(OpRegBank), OperandSize(OpSize) {} |
Diana Picus | 621894a | 2017-06-19 09:40:51 +0000 | [diff] [blame] | 349 | |
Diana Picus | 5b91653 | 2017-07-07 08:39:04 +0000 | [diff] [blame] | 350 | // The opcode used for performing the comparison. |
Diana Picus | 995746d | 2017-07-12 10:31:16 +0000 | [diff] [blame] | 351 | const unsigned ComparisonOpcode; |
Diana Picus | 621894a | 2017-06-19 09:40:51 +0000 | [diff] [blame] | 352 | |
Diana Picus | 5b91653 | 2017-07-07 08:39:04 +0000 | [diff] [blame] | 353 | // The opcode used for reading the flags set by the comparison. May be |
| 354 | // ARM::INSTRUCTION_LIST_END if we don't need to read the flags. |
Diana Picus | 995746d | 2017-07-12 10:31:16 +0000 | [diff] [blame] | 355 | const unsigned ReadFlagsOpcode; |
Diana Picus | 5b91653 | 2017-07-07 08:39:04 +0000 | [diff] [blame] | 356 | |
| 357 | // The assumed register bank ID for the operands. |
Diana Picus | 995746d | 2017-07-12 10:31:16 +0000 | [diff] [blame] | 358 | const unsigned OperandRegBankID; |
Diana Picus | 5b91653 | 2017-07-07 08:39:04 +0000 | [diff] [blame] | 359 | |
Diana Picus | 21014df | 2017-07-12 09:01:54 +0000 | [diff] [blame] | 360 | // The assumed size in bits for the operands. |
Diana Picus | 995746d | 2017-07-12 10:31:16 +0000 | [diff] [blame] | 361 | const unsigned OperandSize; |
Diana Picus | 5b91653 | 2017-07-07 08:39:04 +0000 | [diff] [blame] | 362 | }; |
| 363 | |
Diana Picus | 995746d | 2017-07-12 10:31:16 +0000 | [diff] [blame] | 364 | struct ARMInstructionSelector::InsertInfo { |
| 365 | InsertInfo(MachineInstrBuilder &MIB) |
| 366 | : MBB(*MIB->getParent()), InsertBefore(std::next(MIB->getIterator())), |
| 367 | DbgLoc(MIB->getDebugLoc()) {} |
Diana Picus | 5b91653 | 2017-07-07 08:39:04 +0000 | [diff] [blame] | 368 | |
Diana Picus | 995746d | 2017-07-12 10:31:16 +0000 | [diff] [blame] | 369 | MachineBasicBlock &MBB; |
| 370 | const MachineBasicBlock::instr_iterator InsertBefore; |
| 371 | const DebugLoc &DbgLoc; |
| 372 | }; |
Diana Picus | 5b91653 | 2017-07-07 08:39:04 +0000 | [diff] [blame] | 373 | |
Diana Picus | 995746d | 2017-07-12 10:31:16 +0000 | [diff] [blame] | 374 | void ARMInstructionSelector::putConstant(InsertInfo I, unsigned DestReg, |
| 375 | unsigned Constant) const { |
| 376 | (void)BuildMI(I.MBB, I.InsertBefore, I.DbgLoc, TII.get(ARM::MOVi)) |
| 377 | .addDef(DestReg) |
| 378 | .addImm(Constant) |
| 379 | .add(predOps(ARMCC::AL)) |
| 380 | .add(condCodeOp()); |
| 381 | } |
Diana Picus | 21014df | 2017-07-12 09:01:54 +0000 | [diff] [blame] | 382 | |
Diana Picus | 995746d | 2017-07-12 10:31:16 +0000 | [diff] [blame] | 383 | bool ARMInstructionSelector::validOpRegPair(MachineRegisterInfo &MRI, |
| 384 | unsigned LHSReg, unsigned RHSReg, |
| 385 | unsigned ExpectedSize, |
| 386 | unsigned ExpectedRegBankID) const { |
| 387 | return MRI.getType(LHSReg) == MRI.getType(RHSReg) && |
| 388 | validReg(MRI, LHSReg, ExpectedSize, ExpectedRegBankID) && |
| 389 | validReg(MRI, RHSReg, ExpectedSize, ExpectedRegBankID); |
| 390 | } |
Diana Picus | 5b91653 | 2017-07-07 08:39:04 +0000 | [diff] [blame] | 391 | |
Diana Picus | 995746d | 2017-07-12 10:31:16 +0000 | [diff] [blame] | 392 | bool ARMInstructionSelector::validReg(MachineRegisterInfo &MRI, unsigned Reg, |
| 393 | unsigned ExpectedSize, |
| 394 | unsigned ExpectedRegBankID) const { |
| 395 | if (MRI.getType(Reg).getSizeInBits() != ExpectedSize) { |
| 396 | DEBUG(dbgs() << "Unexpected size for register"); |
| 397 | return false; |
| 398 | } |
| 399 | |
| 400 | if (RBI.getRegBank(Reg, MRI, TRI)->getID() != ExpectedRegBankID) { |
| 401 | DEBUG(dbgs() << "Unexpected register bank for register"); |
| 402 | return false; |
| 403 | } |
| 404 | |
| 405 | return true; |
| 406 | } |
| 407 | |
| 408 | bool ARMInstructionSelector::selectCmp(CmpConstants Helper, |
| 409 | MachineInstrBuilder &MIB, |
| 410 | MachineRegisterInfo &MRI) const { |
| 411 | const InsertInfo I(MIB); |
Diana Picus | 5b91653 | 2017-07-07 08:39:04 +0000 | [diff] [blame] | 412 | |
Diana Picus | 621894a | 2017-06-19 09:40:51 +0000 | [diff] [blame] | 413 | auto ResReg = MIB->getOperand(0).getReg(); |
Diana Picus | 995746d | 2017-07-12 10:31:16 +0000 | [diff] [blame] | 414 | if (!validReg(MRI, ResReg, 1, ARM::GPRRegBankID)) |
Diana Picus | 5b91653 | 2017-07-07 08:39:04 +0000 | [diff] [blame] | 415 | return false; |
| 416 | |
Diana Picus | 621894a | 2017-06-19 09:40:51 +0000 | [diff] [blame] | 417 | auto Cond = |
| 418 | static_cast<CmpInst::Predicate>(MIB->getOperand(1).getPredicate()); |
Diana Picus | 5b91653 | 2017-07-07 08:39:04 +0000 | [diff] [blame] | 419 | if (Cond == CmpInst::FCMP_TRUE || Cond == CmpInst::FCMP_FALSE) { |
Diana Picus | 995746d | 2017-07-12 10:31:16 +0000 | [diff] [blame] | 420 | putConstant(I, ResReg, Cond == CmpInst::FCMP_TRUE ? 1 : 0); |
Diana Picus | 5b91653 | 2017-07-07 08:39:04 +0000 | [diff] [blame] | 421 | MIB->eraseFromParent(); |
| 422 | return true; |
| 423 | } |
| 424 | |
| 425 | auto LHSReg = MIB->getOperand(2).getReg(); |
| 426 | auto RHSReg = MIB->getOperand(3).getReg(); |
Diana Picus | 995746d | 2017-07-12 10:31:16 +0000 | [diff] [blame] | 427 | if (!validOpRegPair(MRI, LHSReg, RHSReg, Helper.OperandSize, |
| 428 | Helper.OperandRegBankID)) |
Diana Picus | 621894a | 2017-06-19 09:40:51 +0000 | [diff] [blame] | 429 | return false; |
| 430 | |
Diana Picus | 5b91653 | 2017-07-07 08:39:04 +0000 | [diff] [blame] | 431 | auto ARMConds = getComparePreds(Cond); |
Diana Picus | 995746d | 2017-07-12 10:31:16 +0000 | [diff] [blame] | 432 | auto ZeroReg = MRI.createVirtualRegister(&ARM::GPRRegClass); |
| 433 | putConstant(I, ZeroReg, 0); |
Diana Picus | 5b91653 | 2017-07-07 08:39:04 +0000 | [diff] [blame] | 434 | |
| 435 | if (ARMConds.second == ARMCC::AL) { |
| 436 | // Simple case, we only need one comparison and we're done. |
Diana Picus | 995746d | 2017-07-12 10:31:16 +0000 | [diff] [blame] | 437 | if (!insertComparison(Helper, I, ResReg, ARMConds.first, LHSReg, RHSReg, |
| 438 | ZeroReg)) |
Diana Picus | 5b91653 | 2017-07-07 08:39:04 +0000 | [diff] [blame] | 439 | return false; |
| 440 | } else { |
| 441 | // Not so simple, we need two successive comparisons. |
| 442 | auto IntermediateRes = MRI.createVirtualRegister(&ARM::GPRRegClass); |
Diana Picus | 995746d | 2017-07-12 10:31:16 +0000 | [diff] [blame] | 443 | if (!insertComparison(Helper, I, IntermediateRes, ARMConds.first, LHSReg, |
| 444 | RHSReg, ZeroReg)) |
Diana Picus | 5b91653 | 2017-07-07 08:39:04 +0000 | [diff] [blame] | 445 | return false; |
Diana Picus | 995746d | 2017-07-12 10:31:16 +0000 | [diff] [blame] | 446 | if (!insertComparison(Helper, I, ResReg, ARMConds.second, LHSReg, RHSReg, |
| 447 | IntermediateRes)) |
Diana Picus | 5b91653 | 2017-07-07 08:39:04 +0000 | [diff] [blame] | 448 | return false; |
| 449 | } |
Diana Picus | 621894a | 2017-06-19 09:40:51 +0000 | [diff] [blame] | 450 | |
| 451 | MIB->eraseFromParent(); |
| 452 | return true; |
| 453 | } |
| 454 | |
Diana Picus | 995746d | 2017-07-12 10:31:16 +0000 | [diff] [blame] | 455 | bool ARMInstructionSelector::insertComparison(CmpConstants Helper, InsertInfo I, |
| 456 | unsigned ResReg, |
| 457 | ARMCC::CondCodes Cond, |
| 458 | unsigned LHSReg, unsigned RHSReg, |
| 459 | unsigned PrevRes) const { |
| 460 | // Perform the comparison. |
| 461 | auto CmpI = |
| 462 | BuildMI(I.MBB, I.InsertBefore, I.DbgLoc, TII.get(Helper.ComparisonOpcode)) |
| 463 | .addUse(LHSReg) |
| 464 | .addUse(RHSReg) |
| 465 | .add(predOps(ARMCC::AL)); |
| 466 | if (!constrainSelectedInstRegOperands(*CmpI, TII, TRI, RBI)) |
| 467 | return false; |
| 468 | |
| 469 | // Read the comparison flags (if necessary). |
| 470 | if (Helper.ReadFlagsOpcode != ARM::INSTRUCTION_LIST_END) { |
| 471 | auto ReadI = BuildMI(I.MBB, I.InsertBefore, I.DbgLoc, |
| 472 | TII.get(Helper.ReadFlagsOpcode)) |
| 473 | .add(predOps(ARMCC::AL)); |
| 474 | if (!constrainSelectedInstRegOperands(*ReadI, TII, TRI, RBI)) |
| 475 | return false; |
| 476 | } |
| 477 | |
| 478 | // Select either 1 or the previous result based on the value of the flags. |
| 479 | auto Mov1I = BuildMI(I.MBB, I.InsertBefore, I.DbgLoc, TII.get(ARM::MOVCCi)) |
| 480 | .addDef(ResReg) |
| 481 | .addUse(PrevRes) |
| 482 | .addImm(1) |
| 483 | .add(predOps(Cond, ARM::CPSR)); |
| 484 | if (!constrainSelectedInstRegOperands(*Mov1I, TII, TRI, RBI)) |
| 485 | return false; |
| 486 | |
| 487 | return true; |
| 488 | } |
| 489 | |
Diana Picus | 930e6ec | 2017-08-03 09:14:59 +0000 | [diff] [blame] | 490 | bool ARMInstructionSelector::selectGlobal(MachineInstrBuilder &MIB, |
| 491 | MachineRegisterInfo &MRI) const { |
Diana Picus | abb0886 | 2017-09-05 07:57:41 +0000 | [diff] [blame] | 492 | if ((STI.isROPI() || STI.isRWPI()) && !STI.isTargetELF()) { |
| 493 | DEBUG(dbgs() << "ROPI and RWPI only supported for ELF\n"); |
Diana Picus | 930e6ec | 2017-08-03 09:14:59 +0000 | [diff] [blame] | 494 | return false; |
| 495 | } |
Diana Picus | 930e6ec | 2017-08-03 09:14:59 +0000 | [diff] [blame] | 496 | |
| 497 | auto GV = MIB->getOperand(1).getGlobal(); |
| 498 | if (GV->isThreadLocal()) { |
| 499 | DEBUG(dbgs() << "TLS variables not supported yet\n"); |
| 500 | return false; |
| 501 | } |
| 502 | |
| 503 | auto &MBB = *MIB->getParent(); |
| 504 | auto &MF = *MBB.getParent(); |
| 505 | |
Diana Picus | ac15473 | 2017-09-05 08:22:47 +0000 | [diff] [blame] | 506 | bool UseMovt = STI.useMovt(MF); |
Diana Picus | 930e6ec | 2017-08-03 09:14:59 +0000 | [diff] [blame] | 507 | |
Diana Picus | abb0886 | 2017-09-05 07:57:41 +0000 | [diff] [blame] | 508 | unsigned Size = TM.getPointerSize(); |
Diana Picus | c9f29c6 | 2017-08-29 09:47:55 +0000 | [diff] [blame] | 509 | unsigned Alignment = 4; |
Diana Picus | abb0886 | 2017-09-05 07:57:41 +0000 | [diff] [blame] | 510 | |
| 511 | auto addOpsForConstantPoolLoad = [&MF, Alignment, |
| 512 | Size](MachineInstrBuilder &MIB, |
| 513 | const GlobalValue *GV, bool IsSBREL) { |
| 514 | assert(MIB->getOpcode() == ARM::LDRi12 && "Unsupported instruction"); |
| 515 | auto ConstPool = MF.getConstantPool(); |
| 516 | auto CPIndex = |
| 517 | // For SB relative entries we need a target-specific constant pool. |
| 518 | // Otherwise, just use a regular constant pool entry. |
| 519 | IsSBREL |
| 520 | ? ConstPool->getConstantPoolIndex( |
| 521 | ARMConstantPoolConstant::Create(GV, ARMCP::SBREL), Alignment) |
| 522 | : ConstPool->getConstantPoolIndex(GV, Alignment); |
| 523 | MIB.addConstantPoolIndex(CPIndex, /*Offset*/ 0, /*TargetFlags*/ 0) |
| 524 | .addMemOperand( |
| 525 | MF.getMachineMemOperand(MachinePointerInfo::getConstantPool(MF), |
| 526 | MachineMemOperand::MOLoad, Size, Alignment)) |
| 527 | .addImm(0) |
| 528 | .add(predOps(ARMCC::AL)); |
| 529 | }; |
| 530 | |
Diana Picus | c9f29c6 | 2017-08-29 09:47:55 +0000 | [diff] [blame] | 531 | if (TM.isPositionIndependent()) { |
Diana Picus | ac15473 | 2017-09-05 08:22:47 +0000 | [diff] [blame] | 532 | bool Indirect = STI.isGVIndirectSymbol(GV); |
Diana Picus | c9f29c6 | 2017-08-29 09:47:55 +0000 | [diff] [blame] | 533 | // FIXME: Taking advantage of MOVT for ELF is pretty involved, so we don't |
| 534 | // support it yet. See PR28229. |
| 535 | unsigned Opc = |
Diana Picus | ac15473 | 2017-09-05 08:22:47 +0000 | [diff] [blame] | 536 | UseMovt && !STI.isTargetELF() |
Diana Picus | c9f29c6 | 2017-08-29 09:47:55 +0000 | [diff] [blame] | 537 | ? (Indirect ? ARM::MOV_ga_pcrel_ldr : ARM::MOV_ga_pcrel) |
| 538 | : (Indirect ? ARM::LDRLIT_ga_pcrel_ldr : ARM::LDRLIT_ga_pcrel); |
| 539 | MIB->setDesc(TII.get(Opc)); |
| 540 | |
Diana Picus | ac15473 | 2017-09-05 08:22:47 +0000 | [diff] [blame] | 541 | if (STI.isTargetDarwin()) |
Diana Picus | c9f29c6 | 2017-08-29 09:47:55 +0000 | [diff] [blame] | 542 | MIB->getOperand(1).setTargetFlags(ARMII::MO_NONLAZY); |
| 543 | |
| 544 | if (Indirect) |
| 545 | MIB.addMemOperand(MF.getMachineMemOperand( |
| 546 | MachinePointerInfo::getGOT(MF), MachineMemOperand::MOLoad, |
| 547 | TM.getPointerSize(), Alignment)); |
| 548 | |
Diana Picus | ac15473 | 2017-09-05 08:22:47 +0000 | [diff] [blame] | 549 | return constrainSelectedInstRegOperands(*MIB, TII, TRI, RBI); |
Diana Picus | c9f29c6 | 2017-08-29 09:47:55 +0000 | [diff] [blame] | 550 | } |
| 551 | |
Diana Picus | f9597911 | 2017-09-01 11:13:39 +0000 | [diff] [blame] | 552 | bool isReadOnly = STI.getTargetLowering()->isReadOnly(GV); |
| 553 | if (STI.isROPI() && isReadOnly) { |
| 554 | unsigned Opc = UseMovt ? ARM::MOV_ga_pcrel : ARM::LDRLIT_ga_pcrel; |
| 555 | MIB->setDesc(TII.get(Opc)); |
| 556 | return constrainSelectedInstRegOperands(*MIB, TII, TRI, RBI); |
| 557 | } |
Diana Picus | abb0886 | 2017-09-05 07:57:41 +0000 | [diff] [blame] | 558 | if (STI.isRWPI() && !isReadOnly) { |
| 559 | auto Offset = MRI.createVirtualRegister(&ARM::GPRRegClass); |
| 560 | MachineInstrBuilder OffsetMIB; |
| 561 | if (UseMovt) { |
| 562 | OffsetMIB = BuildMI(MBB, *MIB, MIB->getDebugLoc(), |
| 563 | TII.get(ARM::MOVi32imm), Offset); |
| 564 | OffsetMIB.addGlobalAddress(GV, /*Offset*/ 0, ARMII::MO_SBREL); |
| 565 | } else { |
| 566 | // Load the offset from the constant pool. |
| 567 | OffsetMIB = |
| 568 | BuildMI(MBB, *MIB, MIB->getDebugLoc(), TII.get(ARM::LDRi12), Offset); |
| 569 | addOpsForConstantPoolLoad(OffsetMIB, GV, /*IsSBREL*/ true); |
| 570 | } |
| 571 | if (!constrainSelectedInstRegOperands(*OffsetMIB, TII, TRI, RBI)) |
| 572 | return false; |
| 573 | |
| 574 | // Add the offset to the SB register. |
| 575 | MIB->setDesc(TII.get(ARM::ADDrr)); |
| 576 | MIB->RemoveOperand(1); |
| 577 | MIB.addReg(ARM::R9) // FIXME: don't hardcode R9 |
| 578 | .addReg(Offset) |
| 579 | .add(predOps(ARMCC::AL)) |
| 580 | .add(condCodeOp()); |
| 581 | |
| 582 | return constrainSelectedInstRegOperands(*MIB, TII, TRI, RBI); |
| 583 | } |
Diana Picus | f9597911 | 2017-09-01 11:13:39 +0000 | [diff] [blame] | 584 | |
Diana Picus | ac15473 | 2017-09-05 08:22:47 +0000 | [diff] [blame] | 585 | if (STI.isTargetELF()) { |
Diana Picus | 930e6ec | 2017-08-03 09:14:59 +0000 | [diff] [blame] | 586 | if (UseMovt) { |
| 587 | MIB->setDesc(TII.get(ARM::MOVi32imm)); |
| 588 | } else { |
| 589 | // Load the global's address from the constant pool. |
| 590 | MIB->setDesc(TII.get(ARM::LDRi12)); |
| 591 | MIB->RemoveOperand(1); |
Diana Picus | abb0886 | 2017-09-05 07:57:41 +0000 | [diff] [blame] | 592 | addOpsForConstantPoolLoad(MIB, GV, /*IsSBREL*/ false); |
Diana Picus | 930e6ec | 2017-08-03 09:14:59 +0000 | [diff] [blame] | 593 | } |
Diana Picus | ac15473 | 2017-09-05 08:22:47 +0000 | [diff] [blame] | 594 | } else if (STI.isTargetMachO()) { |
Diana Picus | 930e6ec | 2017-08-03 09:14:59 +0000 | [diff] [blame] | 595 | if (UseMovt) |
| 596 | MIB->setDesc(TII.get(ARM::MOVi32imm)); |
| 597 | else |
| 598 | MIB->setDesc(TII.get(ARM::LDRLIT_ga_abs)); |
| 599 | } else { |
| 600 | DEBUG(dbgs() << "Object format not supported yet\n"); |
| 601 | return false; |
| 602 | } |
| 603 | |
| 604 | return constrainSelectedInstRegOperands(*MIB, TII, TRI, RBI); |
| 605 | } |
| 606 | |
Diana Picus | 7145d22 | 2017-06-27 09:19:51 +0000 | [diff] [blame] | 607 | bool ARMInstructionSelector::selectSelect(MachineInstrBuilder &MIB, |
Diana Picus | 995746d | 2017-07-12 10:31:16 +0000 | [diff] [blame] | 608 | MachineRegisterInfo &MRI) const { |
Diana Picus | 7145d22 | 2017-06-27 09:19:51 +0000 | [diff] [blame] | 609 | auto &MBB = *MIB->getParent(); |
| 610 | auto InsertBefore = std::next(MIB->getIterator()); |
Diana Picus | 7736737 | 2017-07-07 08:53:27 +0000 | [diff] [blame] | 611 | auto &DbgLoc = MIB->getDebugLoc(); |
Diana Picus | 7145d22 | 2017-06-27 09:19:51 +0000 | [diff] [blame] | 612 | |
| 613 | // Compare the condition to 0. |
| 614 | auto CondReg = MIB->getOperand(1).getReg(); |
Diana Picus | 995746d | 2017-07-12 10:31:16 +0000 | [diff] [blame] | 615 | assert(validReg(MRI, CondReg, 1, ARM::GPRRegBankID) && |
Diana Picus | 7145d22 | 2017-06-27 09:19:51 +0000 | [diff] [blame] | 616 | "Unsupported types for select operation"); |
Diana Picus | 7736737 | 2017-07-07 08:53:27 +0000 | [diff] [blame] | 617 | auto CmpI = BuildMI(MBB, InsertBefore, DbgLoc, TII.get(ARM::CMPri)) |
Diana Picus | 7145d22 | 2017-06-27 09:19:51 +0000 | [diff] [blame] | 618 | .addUse(CondReg) |
| 619 | .addImm(0) |
| 620 | .add(predOps(ARMCC::AL)); |
| 621 | if (!constrainSelectedInstRegOperands(*CmpI, TII, TRI, RBI)) |
| 622 | return false; |
| 623 | |
| 624 | // Move a value into the result register based on the result of the |
| 625 | // comparison. |
| 626 | auto ResReg = MIB->getOperand(0).getReg(); |
| 627 | auto TrueReg = MIB->getOperand(2).getReg(); |
| 628 | auto FalseReg = MIB->getOperand(3).getReg(); |
Diana Picus | 995746d | 2017-07-12 10:31:16 +0000 | [diff] [blame] | 629 | assert(validOpRegPair(MRI, ResReg, TrueReg, 32, ARM::GPRRegBankID) && |
| 630 | validOpRegPair(MRI, TrueReg, FalseReg, 32, ARM::GPRRegBankID) && |
Diana Picus | 7145d22 | 2017-06-27 09:19:51 +0000 | [diff] [blame] | 631 | "Unsupported types for select operation"); |
Diana Picus | 7736737 | 2017-07-07 08:53:27 +0000 | [diff] [blame] | 632 | auto Mov1I = BuildMI(MBB, InsertBefore, DbgLoc, TII.get(ARM::MOVCCr)) |
Diana Picus | 7145d22 | 2017-06-27 09:19:51 +0000 | [diff] [blame] | 633 | .addDef(ResReg) |
| 634 | .addUse(TrueReg) |
| 635 | .addUse(FalseReg) |
| 636 | .add(predOps(ARMCC::EQ, ARM::CPSR)); |
| 637 | if (!constrainSelectedInstRegOperands(*Mov1I, TII, TRI, RBI)) |
| 638 | return false; |
| 639 | |
| 640 | MIB->eraseFromParent(); |
| 641 | return true; |
| 642 | } |
| 643 | |
Diana Picus | e393bc7 | 2017-10-06 15:39:16 +0000 | [diff] [blame^] | 644 | bool ARMInstructionSelector::selectShift(unsigned ShiftOpc, |
| 645 | MachineInstrBuilder &MIB) const { |
| 646 | MIB->setDesc(TII.get(ARM::MOVsr)); |
| 647 | MIB.addImm(ShiftOpc); |
| 648 | MIB.add(predOps(ARMCC::AL)).add(condCodeOp()); |
| 649 | return constrainSelectedInstRegOperands(*MIB, TII, TRI, RBI); |
| 650 | } |
| 651 | |
Diana Picus | 812caee | 2016-12-16 12:54:46 +0000 | [diff] [blame] | 652 | bool ARMInstructionSelector::select(MachineInstr &I) const { |
| 653 | assert(I.getParent() && "Instruction should be in a basic block!"); |
| 654 | assert(I.getParent()->getParent() && "Instruction should be in a function!"); |
| 655 | |
| 656 | auto &MBB = *I.getParent(); |
| 657 | auto &MF = *MBB.getParent(); |
| 658 | auto &MRI = MF.getRegInfo(); |
| 659 | |
| 660 | if (!isPreISelGenericOpcode(I.getOpcode())) { |
| 661 | if (I.isCopy()) |
| 662 | return selectCopy(I, TII, MRI, TRI, RBI); |
| 663 | |
| 664 | return true; |
| 665 | } |
| 666 | |
Diana Picus | 8abcbbb | 2017-05-02 09:40:49 +0000 | [diff] [blame] | 667 | if (selectImpl(I)) |
| 668 | return true; |
| 669 | |
Diana Picus | 519807f | 2016-12-19 11:26:31 +0000 | [diff] [blame] | 670 | MachineInstrBuilder MIB{MF, I}; |
Diana Picus | d83df5d | 2017-01-25 08:47:40 +0000 | [diff] [blame] | 671 | bool isSExt = false; |
Diana Picus | 519807f | 2016-12-19 11:26:31 +0000 | [diff] [blame] | 672 | |
| 673 | using namespace TargetOpcode; |
| 674 | switch (I.getOpcode()) { |
Diana Picus | 8b6c6be | 2017-01-25 08:10:40 +0000 | [diff] [blame] | 675 | case G_SEXT: |
Diana Picus | d83df5d | 2017-01-25 08:47:40 +0000 | [diff] [blame] | 676 | isSExt = true; |
| 677 | LLVM_FALLTHROUGH; |
Diana Picus | 8b6c6be | 2017-01-25 08:10:40 +0000 | [diff] [blame] | 678 | case G_ZEXT: { |
| 679 | LLT DstTy = MRI.getType(I.getOperand(0).getReg()); |
| 680 | // FIXME: Smaller destination sizes coming soon! |
| 681 | if (DstTy.getSizeInBits() != 32) { |
| 682 | DEBUG(dbgs() << "Unsupported destination size for extension"); |
| 683 | return false; |
| 684 | } |
| 685 | |
| 686 | LLT SrcTy = MRI.getType(I.getOperand(1).getReg()); |
| 687 | unsigned SrcSize = SrcTy.getSizeInBits(); |
| 688 | switch (SrcSize) { |
Diana Picus | d83df5d | 2017-01-25 08:47:40 +0000 | [diff] [blame] | 689 | case 1: { |
| 690 | // ZExt boils down to & 0x1; for SExt we also subtract that from 0 |
| 691 | I.setDesc(TII.get(ARM::ANDri)); |
| 692 | MIB.addImm(1).add(predOps(ARMCC::AL)).add(condCodeOp()); |
| 693 | |
| 694 | if (isSExt) { |
| 695 | unsigned SExtResult = I.getOperand(0).getReg(); |
| 696 | |
| 697 | // Use a new virtual register for the result of the AND |
| 698 | unsigned AndResult = MRI.createVirtualRegister(&ARM::GPRRegClass); |
| 699 | I.getOperand(0).setReg(AndResult); |
| 700 | |
| 701 | auto InsertBefore = std::next(I.getIterator()); |
Martin Bohme | 8396e14 | 2017-01-25 14:28:19 +0000 | [diff] [blame] | 702 | auto SubI = |
Diana Picus | d83df5d | 2017-01-25 08:47:40 +0000 | [diff] [blame] | 703 | BuildMI(MBB, InsertBefore, I.getDebugLoc(), TII.get(ARM::RSBri)) |
| 704 | .addDef(SExtResult) |
| 705 | .addUse(AndResult) |
| 706 | .addImm(0) |
| 707 | .add(predOps(ARMCC::AL)) |
| 708 | .add(condCodeOp()); |
| 709 | if (!constrainSelectedInstRegOperands(*SubI, TII, TRI, RBI)) |
| 710 | return false; |
| 711 | } |
| 712 | break; |
| 713 | } |
Diana Picus | 8b6c6be | 2017-01-25 08:10:40 +0000 | [diff] [blame] | 714 | case 8: |
| 715 | case 16: { |
| 716 | unsigned NewOpc = selectSimpleExtOpc(I.getOpcode(), SrcSize); |
Diana Picus | e836878 | 2017-02-17 13:44:19 +0000 | [diff] [blame] | 717 | if (NewOpc == I.getOpcode()) |
| 718 | return false; |
Diana Picus | 8b6c6be | 2017-01-25 08:10:40 +0000 | [diff] [blame] | 719 | I.setDesc(TII.get(NewOpc)); |
| 720 | MIB.addImm(0).add(predOps(ARMCC::AL)); |
| 721 | break; |
| 722 | } |
| 723 | default: |
| 724 | DEBUG(dbgs() << "Unsupported source size for extension"); |
| 725 | return false; |
| 726 | } |
| 727 | break; |
| 728 | } |
Diana Picus | 657bfd3 | 2017-05-11 08:28:31 +0000 | [diff] [blame] | 729 | case G_ANYEXT: |
Diana Picus | 64a3343 | 2017-04-21 13:16:50 +0000 | [diff] [blame] | 730 | case G_TRUNC: { |
| 731 | // The high bits are undefined, so there's nothing special to do, just |
| 732 | // treat it as a copy. |
| 733 | auto SrcReg = I.getOperand(1).getReg(); |
| 734 | auto DstReg = I.getOperand(0).getReg(); |
| 735 | |
| 736 | const auto &SrcRegBank = *RBI.getRegBank(SrcReg, MRI, TRI); |
| 737 | const auto &DstRegBank = *RBI.getRegBank(DstReg, MRI, TRI); |
| 738 | |
| 739 | if (SrcRegBank.getID() != DstRegBank.getID()) { |
Diana Picus | 657bfd3 | 2017-05-11 08:28:31 +0000 | [diff] [blame] | 740 | DEBUG(dbgs() << "G_TRUNC/G_ANYEXT operands on different register banks\n"); |
Diana Picus | 64a3343 | 2017-04-21 13:16:50 +0000 | [diff] [blame] | 741 | return false; |
| 742 | } |
| 743 | |
| 744 | if (SrcRegBank.getID() != ARM::GPRRegBankID) { |
Diana Picus | 657bfd3 | 2017-05-11 08:28:31 +0000 | [diff] [blame] | 745 | DEBUG(dbgs() << "G_TRUNC/G_ANYEXT on non-GPR not supported yet\n"); |
Diana Picus | 64a3343 | 2017-04-21 13:16:50 +0000 | [diff] [blame] | 746 | return false; |
| 747 | } |
| 748 | |
| 749 | I.setDesc(TII.get(COPY)); |
| 750 | return selectCopy(I, TII, MRI, TRI, RBI); |
| 751 | } |
Diana Picus | 7145d22 | 2017-06-27 09:19:51 +0000 | [diff] [blame] | 752 | case G_SELECT: |
Diana Picus | 995746d | 2017-07-12 10:31:16 +0000 | [diff] [blame] | 753 | return selectSelect(MIB, MRI); |
| 754 | case G_ICMP: { |
| 755 | CmpConstants Helper(ARM::CMPrr, ARM::INSTRUCTION_LIST_END, |
| 756 | ARM::GPRRegBankID, 32); |
| 757 | return selectCmp(Helper, MIB, MRI); |
| 758 | } |
Diana Picus | 21014df | 2017-07-12 09:01:54 +0000 | [diff] [blame] | 759 | case G_FCMP: { |
Diana Picus | ac15473 | 2017-09-05 08:22:47 +0000 | [diff] [blame] | 760 | assert(STI.hasVFP2() && "Can't select fcmp without VFP"); |
Diana Picus | 21014df | 2017-07-12 09:01:54 +0000 | [diff] [blame] | 761 | |
| 762 | unsigned OpReg = I.getOperand(2).getReg(); |
| 763 | unsigned Size = MRI.getType(OpReg).getSizeInBits(); |
Diana Picus | 995746d | 2017-07-12 10:31:16 +0000 | [diff] [blame] | 764 | |
Diana Picus | ac15473 | 2017-09-05 08:22:47 +0000 | [diff] [blame] | 765 | if (Size == 64 && STI.isFPOnlySP()) { |
Diana Picus | 995746d | 2017-07-12 10:31:16 +0000 | [diff] [blame] | 766 | DEBUG(dbgs() << "Subtarget only supports single precision"); |
| 767 | return false; |
| 768 | } |
| 769 | if (Size != 32 && Size != 64) { |
| 770 | DEBUG(dbgs() << "Unsupported size for G_FCMP operand"); |
| 771 | return false; |
Diana Picus | 21014df | 2017-07-12 09:01:54 +0000 | [diff] [blame] | 772 | } |
| 773 | |
Diana Picus | 995746d | 2017-07-12 10:31:16 +0000 | [diff] [blame] | 774 | CmpConstants Helper(Size == 32 ? ARM::VCMPS : ARM::VCMPD, ARM::FMSTAT, |
| 775 | ARM::FPRRegBankID, Size); |
| 776 | return selectCmp(Helper, MIB, MRI); |
Diana Picus | 21014df | 2017-07-12 09:01:54 +0000 | [diff] [blame] | 777 | } |
Diana Picus | e393bc7 | 2017-10-06 15:39:16 +0000 | [diff] [blame^] | 778 | case G_LSHR: |
| 779 | return selectShift(ARM_AM::ShiftOpc::lsr, MIB); |
| 780 | case G_ASHR: |
| 781 | return selectShift(ARM_AM::ShiftOpc::asr, MIB); |
| 782 | case G_SHL: { |
| 783 | return selectShift(ARM_AM::ShiftOpc::lsl, MIB); |
| 784 | } |
Diana Picus | 9d07094 | 2017-02-28 10:14:38 +0000 | [diff] [blame] | 785 | case G_GEP: |
Diana Picus | 812caee | 2016-12-16 12:54:46 +0000 | [diff] [blame] | 786 | I.setDesc(TII.get(ARM::ADDrr)); |
Diana Picus | 8a73f55 | 2017-01-13 10:18:01 +0000 | [diff] [blame] | 787 | MIB.add(predOps(ARMCC::AL)).add(condCodeOp()); |
Diana Picus | 519807f | 2016-12-19 11:26:31 +0000 | [diff] [blame] | 788 | break; |
| 789 | case G_FRAME_INDEX: |
| 790 | // Add 0 to the given frame index and hope it will eventually be folded into |
| 791 | // the user(s). |
| 792 | I.setDesc(TII.get(ARM::ADDri)); |
Diana Picus | 8a73f55 | 2017-01-13 10:18:01 +0000 | [diff] [blame] | 793 | MIB.addImm(0).add(predOps(ARMCC::AL)).add(condCodeOp()); |
Diana Picus | 519807f | 2016-12-19 11:26:31 +0000 | [diff] [blame] | 794 | break; |
Diana Picus | 5a7203a | 2017-02-28 13:05:42 +0000 | [diff] [blame] | 795 | case G_CONSTANT: { |
| 796 | unsigned Reg = I.getOperand(0).getReg(); |
Diana Picus | 995746d | 2017-07-12 10:31:16 +0000 | [diff] [blame] | 797 | |
| 798 | if (!validReg(MRI, Reg, 32, ARM::GPRRegBankID)) |
Diana Picus | 5a7203a | 2017-02-28 13:05:42 +0000 | [diff] [blame] | 799 | return false; |
| 800 | |
Diana Picus | 5a7203a | 2017-02-28 13:05:42 +0000 | [diff] [blame] | 801 | I.setDesc(TII.get(ARM::MOVi)); |
| 802 | MIB.add(predOps(ARMCC::AL)).add(condCodeOp()); |
Diana Picus | 95a8aa9 | 2017-04-24 06:30:56 +0000 | [diff] [blame] | 803 | |
| 804 | auto &Val = I.getOperand(1); |
| 805 | if (Val.isCImm()) { |
| 806 | if (Val.getCImm()->getBitWidth() > 32) |
| 807 | return false; |
| 808 | Val.ChangeToImmediate(Val.getCImm()->getZExtValue()); |
| 809 | } |
| 810 | |
| 811 | if (!Val.isImm()) { |
| 812 | return false; |
| 813 | } |
| 814 | |
Diana Picus | 5a7203a | 2017-02-28 13:05:42 +0000 | [diff] [blame] | 815 | break; |
| 816 | } |
Diana Picus | 930e6ec | 2017-08-03 09:14:59 +0000 | [diff] [blame] | 817 | case G_GLOBAL_VALUE: |
| 818 | return selectGlobal(MIB, MRI); |
Diana Picus | 3b99c64 | 2017-02-24 14:01:27 +0000 | [diff] [blame] | 819 | case G_STORE: |
Diana Picus | 278c722 | 2017-01-26 09:20:47 +0000 | [diff] [blame] | 820 | case G_LOAD: { |
Diana Picus | 1c33c9f | 2017-02-20 14:45:58 +0000 | [diff] [blame] | 821 | const auto &MemOp = **I.memoperands_begin(); |
| 822 | if (MemOp.getOrdering() != AtomicOrdering::NotAtomic) { |
| 823 | DEBUG(dbgs() << "Atomic load/store not supported yet\n"); |
| 824 | return false; |
| 825 | } |
| 826 | |
Diana Picus | 1540b06 | 2017-02-16 14:10:50 +0000 | [diff] [blame] | 827 | unsigned Reg = I.getOperand(0).getReg(); |
| 828 | unsigned RegBank = RBI.getRegBank(Reg, MRI, TRI)->getID(); |
| 829 | |
| 830 | LLT ValTy = MRI.getType(Reg); |
Diana Picus | 278c722 | 2017-01-26 09:20:47 +0000 | [diff] [blame] | 831 | const auto ValSize = ValTy.getSizeInBits(); |
| 832 | |
Diana Picus | ac15473 | 2017-09-05 08:22:47 +0000 | [diff] [blame] | 833 | assert((ValSize != 64 || STI.hasVFP2()) && |
Diana Picus | 3b99c64 | 2017-02-24 14:01:27 +0000 | [diff] [blame] | 834 | "Don't know how to load/store 64-bit value without VFP"); |
Diana Picus | 1540b06 | 2017-02-16 14:10:50 +0000 | [diff] [blame] | 835 | |
Diana Picus | 3b99c64 | 2017-02-24 14:01:27 +0000 | [diff] [blame] | 836 | const auto NewOpc = selectLoadStoreOpCode(I.getOpcode(), RegBank, ValSize); |
| 837 | if (NewOpc == G_LOAD || NewOpc == G_STORE) |
Diana Picus | e836878 | 2017-02-17 13:44:19 +0000 | [diff] [blame] | 838 | return false; |
| 839 | |
Diana Picus | 278c722 | 2017-01-26 09:20:47 +0000 | [diff] [blame] | 840 | I.setDesc(TII.get(NewOpc)); |
| 841 | |
Diana Picus | 3b99c64 | 2017-02-24 14:01:27 +0000 | [diff] [blame] | 842 | if (NewOpc == ARM::LDRH || NewOpc == ARM::STRH) |
Diana Picus | 278c722 | 2017-01-26 09:20:47 +0000 | [diff] [blame] | 843 | // LDRH has a funny addressing mode (there's already a FIXME for it). |
| 844 | MIB.addReg(0); |
Diana Picus | 4f8c3e1 | 2017-01-13 09:37:56 +0000 | [diff] [blame] | 845 | MIB.addImm(0).add(predOps(ARMCC::AL)); |
Diana Picus | 519807f | 2016-12-19 11:26:31 +0000 | [diff] [blame] | 846 | break; |
Diana Picus | 278c722 | 2017-01-26 09:20:47 +0000 | [diff] [blame] | 847 | } |
Diana Picus | 0b4190a | 2017-06-07 12:35:05 +0000 | [diff] [blame] | 848 | case G_MERGE_VALUES: { |
| 849 | if (!selectMergeValues(MIB, TII, MRI, TRI, RBI)) |
Diana Picus | b1701e0 | 2017-02-16 12:19:57 +0000 | [diff] [blame] | 850 | return false; |
| 851 | break; |
| 852 | } |
Diana Picus | 0b4190a | 2017-06-07 12:35:05 +0000 | [diff] [blame] | 853 | case G_UNMERGE_VALUES: { |
| 854 | if (!selectUnmergeValues(MIB, TII, MRI, TRI, RBI)) |
Diana Picus | b1701e0 | 2017-02-16 12:19:57 +0000 | [diff] [blame] | 855 | return false; |
| 856 | break; |
| 857 | } |
Diana Picus | 87a7067 | 2017-07-14 09:46:06 +0000 | [diff] [blame] | 858 | case G_BRCOND: { |
| 859 | if (!validReg(MRI, I.getOperand(0).getReg(), 1, ARM::GPRRegBankID)) { |
| 860 | DEBUG(dbgs() << "Unsupported condition register for G_BRCOND"); |
| 861 | return false; |
| 862 | } |
| 863 | |
| 864 | // Set the flags. |
| 865 | auto Test = BuildMI(*I.getParent(), I, I.getDebugLoc(), TII.get(ARM::TSTri)) |
| 866 | .addReg(I.getOperand(0).getReg()) |
| 867 | .addImm(1) |
| 868 | .add(predOps(ARMCC::AL)); |
| 869 | if (!constrainSelectedInstRegOperands(*Test, TII, TRI, RBI)) |
| 870 | return false; |
| 871 | |
| 872 | // Branch conditionally. |
| 873 | auto Branch = BuildMI(*I.getParent(), I, I.getDebugLoc(), TII.get(ARM::Bcc)) |
| 874 | .add(I.getOperand(1)) |
| 875 | .add(predOps(ARMCC::EQ, ARM::CPSR)); |
| 876 | if (!constrainSelectedInstRegOperands(*Branch, TII, TRI, RBI)) |
| 877 | return false; |
| 878 | I.eraseFromParent(); |
| 879 | return true; |
| 880 | } |
Diana Picus | 519807f | 2016-12-19 11:26:31 +0000 | [diff] [blame] | 881 | default: |
| 882 | return false; |
Diana Picus | 812caee | 2016-12-16 12:54:46 +0000 | [diff] [blame] | 883 | } |
| 884 | |
Diana Picus | 519807f | 2016-12-19 11:26:31 +0000 | [diff] [blame] | 885 | return constrainSelectedInstRegOperands(I, TII, TRI, RBI); |
Diana Picus | 2227493 | 2016-11-11 08:27:37 +0000 | [diff] [blame] | 886 | } |