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 | 812caee | 2016-12-16 12:54:46 +0000 | [diff] [blame] | 18 | #include "llvm/CodeGen/MachineRegisterInfo.h" |
Diana Picus | 2227493 | 2016-11-11 08:27:37 +0000 | [diff] [blame] | 19 | #include "llvm/Support/Debug.h" |
| 20 | |
| 21 | #define DEBUG_TYPE "arm-isel" |
| 22 | |
| 23 | using namespace llvm; |
| 24 | |
| 25 | #ifndef LLVM_BUILD_GLOBAL_ISEL |
| 26 | #error "You shouldn't build this" |
| 27 | #endif |
| 28 | |
Diana Picus | 674888d | 2017-04-28 09:10:38 +0000 | [diff] [blame] | 29 | namespace { |
Diana Picus | 8abcbbb | 2017-05-02 09:40:49 +0000 | [diff] [blame] | 30 | |
| 31 | #define GET_GLOBALISEL_PREDICATE_BITSET |
| 32 | #include "ARMGenGlobalISel.inc" |
| 33 | #undef GET_GLOBALISEL_PREDICATE_BITSET |
| 34 | |
Diana Picus | 674888d | 2017-04-28 09:10:38 +0000 | [diff] [blame] | 35 | class ARMInstructionSelector : public InstructionSelector { |
| 36 | public: |
Diana Picus | 8abcbbb | 2017-05-02 09:40:49 +0000 | [diff] [blame] | 37 | ARMInstructionSelector(const ARMBaseTargetMachine &TM, const ARMSubtarget &STI, |
Diana Picus | 674888d | 2017-04-28 09:10:38 +0000 | [diff] [blame] | 38 | const ARMRegisterBankInfo &RBI); |
| 39 | |
| 40 | bool select(MachineInstr &I) const override; |
| 41 | |
| 42 | private: |
Diana Picus | 8abcbbb | 2017-05-02 09:40:49 +0000 | [diff] [blame] | 43 | bool selectImpl(MachineInstr &I) const; |
| 44 | |
Diana Picus | 674888d | 2017-04-28 09:10:38 +0000 | [diff] [blame] | 45 | const ARMBaseInstrInfo &TII; |
| 46 | const ARMBaseRegisterInfo &TRI; |
Diana Picus | 8abcbbb | 2017-05-02 09:40:49 +0000 | [diff] [blame] | 47 | const ARMBaseTargetMachine &TM; |
Diana Picus | 674888d | 2017-04-28 09:10:38 +0000 | [diff] [blame] | 48 | const ARMRegisterBankInfo &RBI; |
Diana Picus | 8abcbbb | 2017-05-02 09:40:49 +0000 | [diff] [blame] | 49 | const ARMSubtarget &STI; |
| 50 | |
| 51 | #define GET_GLOBALISEL_PREDICATES_DECL |
| 52 | #include "ARMGenGlobalISel.inc" |
| 53 | #undef GET_GLOBALISEL_PREDICATES_DECL |
| 54 | |
| 55 | // We declare the temporaries used by selectImpl() in the class to minimize the |
| 56 | // cost of constructing placeholder values. |
| 57 | #define GET_GLOBALISEL_TEMPORARIES_DECL |
| 58 | #include "ARMGenGlobalISel.inc" |
| 59 | #undef GET_GLOBALISEL_TEMPORARIES_DECL |
Diana Picus | 674888d | 2017-04-28 09:10:38 +0000 | [diff] [blame] | 60 | }; |
| 61 | } // end anonymous namespace |
| 62 | |
| 63 | namespace llvm { |
| 64 | InstructionSelector * |
Diana Picus | 8abcbbb | 2017-05-02 09:40:49 +0000 | [diff] [blame] | 65 | createARMInstructionSelector(const ARMBaseTargetMachine &TM, |
| 66 | const ARMSubtarget &STI, |
Diana Picus | 674888d | 2017-04-28 09:10:38 +0000 | [diff] [blame] | 67 | const ARMRegisterBankInfo &RBI) { |
Diana Picus | 8abcbbb | 2017-05-02 09:40:49 +0000 | [diff] [blame] | 68 | return new ARMInstructionSelector(TM, STI, RBI); |
Diana Picus | 674888d | 2017-04-28 09:10:38 +0000 | [diff] [blame] | 69 | } |
| 70 | } |
| 71 | |
Diana Picus | 8abcbbb | 2017-05-02 09:40:49 +0000 | [diff] [blame] | 72 | unsigned zero_reg = 0; |
| 73 | |
| 74 | #define GET_GLOBALISEL_IMPL |
| 75 | #include "ARMGenGlobalISel.inc" |
| 76 | #undef GET_GLOBALISEL_IMPL |
| 77 | |
| 78 | ARMInstructionSelector::ARMInstructionSelector(const ARMBaseTargetMachine &TM, |
| 79 | const ARMSubtarget &STI, |
Diana Picus | 2227493 | 2016-11-11 08:27:37 +0000 | [diff] [blame] | 80 | const ARMRegisterBankInfo &RBI) |
Diana Picus | 895c6aa | 2016-11-15 16:42:10 +0000 | [diff] [blame] | 81 | : InstructionSelector(), TII(*STI.getInstrInfo()), |
Diana Picus | 8abcbbb | 2017-05-02 09:40:49 +0000 | [diff] [blame] | 82 | TRI(*STI.getRegisterInfo()), TM(TM), RBI(RBI), STI(STI), |
| 83 | #define GET_GLOBALISEL_PREDICATES_INIT |
| 84 | #include "ARMGenGlobalISel.inc" |
| 85 | #undef GET_GLOBALISEL_PREDICATES_INIT |
| 86 | #define GET_GLOBALISEL_TEMPORARIES_INIT |
| 87 | #include "ARMGenGlobalISel.inc" |
| 88 | #undef GET_GLOBALISEL_TEMPORARIES_INIT |
| 89 | { |
| 90 | } |
Diana Picus | 2227493 | 2016-11-11 08:27:37 +0000 | [diff] [blame] | 91 | |
Diana Picus | 812caee | 2016-12-16 12:54:46 +0000 | [diff] [blame] | 92 | static bool selectCopy(MachineInstr &I, const TargetInstrInfo &TII, |
| 93 | MachineRegisterInfo &MRI, const TargetRegisterInfo &TRI, |
| 94 | const RegisterBankInfo &RBI) { |
| 95 | unsigned DstReg = I.getOperand(0).getReg(); |
| 96 | if (TargetRegisterInfo::isPhysicalRegister(DstReg)) |
| 97 | return true; |
| 98 | |
| 99 | const RegisterBank *RegBank = RBI.getRegBank(DstReg, MRI, TRI); |
Benjamin Kramer | 24bf868 | 2016-12-16 13:13:03 +0000 | [diff] [blame] | 100 | (void)RegBank; |
Diana Picus | 812caee | 2016-12-16 12:54:46 +0000 | [diff] [blame] | 101 | assert(RegBank && "Can't get reg bank for virtual register"); |
| 102 | |
Diana Picus | 36aa09f | 2016-12-19 14:07:50 +0000 | [diff] [blame] | 103 | const unsigned DstSize = MRI.getType(DstReg).getSizeInBits(); |
Diana Picus | 4fa83c0 | 2017-02-08 13:23:04 +0000 | [diff] [blame] | 104 | assert((RegBank->getID() == ARM::GPRRegBankID || |
| 105 | RegBank->getID() == ARM::FPRRegBankID) && |
| 106 | "Unsupported reg bank"); |
| 107 | |
Diana Picus | 812caee | 2016-12-16 12:54:46 +0000 | [diff] [blame] | 108 | const TargetRegisterClass *RC = &ARM::GPRRegClass; |
| 109 | |
Diana Picus | 4fa83c0 | 2017-02-08 13:23:04 +0000 | [diff] [blame] | 110 | if (RegBank->getID() == ARM::FPRRegBankID) { |
Diana Picus | 6beef3c | 2017-02-16 12:19:52 +0000 | [diff] [blame] | 111 | if (DstSize == 32) |
| 112 | RC = &ARM::SPRRegClass; |
| 113 | else if (DstSize == 64) |
| 114 | RC = &ARM::DPRRegClass; |
| 115 | else |
| 116 | llvm_unreachable("Unsupported destination size"); |
Diana Picus | 4fa83c0 | 2017-02-08 13:23:04 +0000 | [diff] [blame] | 117 | } |
| 118 | |
Diana Picus | 812caee | 2016-12-16 12:54:46 +0000 | [diff] [blame] | 119 | // No need to constrain SrcReg. It will get constrained when |
| 120 | // we hit another of its uses or its defs. |
| 121 | // Copies do not have constraints. |
| 122 | if (!RBI.constrainGenericRegister(DstReg, *RC, MRI)) { |
| 123 | DEBUG(dbgs() << "Failed to constrain " << TII.getName(I.getOpcode()) |
| 124 | << " operand\n"); |
| 125 | return false; |
| 126 | } |
| 127 | return true; |
| 128 | } |
| 129 | |
Diana Picus | 0b4190a | 2017-06-07 12:35:05 +0000 | [diff] [blame] | 130 | static bool selectMergeValues(MachineInstrBuilder &MIB, |
| 131 | const ARMBaseInstrInfo &TII, |
| 132 | MachineRegisterInfo &MRI, |
| 133 | const TargetRegisterInfo &TRI, |
| 134 | const RegisterBankInfo &RBI) { |
| 135 | assert(TII.getSubtarget().hasVFP2() && "Can't select merge without VFP"); |
Diana Picus | b1701e0 | 2017-02-16 12:19:57 +0000 | [diff] [blame] | 136 | |
Diana Picus | 0b4190a | 2017-06-07 12:35:05 +0000 | [diff] [blame] | 137 | // 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] | 138 | // into one DPR. |
| 139 | unsigned VReg0 = MIB->getOperand(0).getReg(); |
| 140 | (void)VReg0; |
| 141 | assert(MRI.getType(VReg0).getSizeInBits() == 64 && |
| 142 | RBI.getRegBank(VReg0, MRI, TRI)->getID() == ARM::FPRRegBankID && |
Diana Picus | 0b4190a | 2017-06-07 12:35:05 +0000 | [diff] [blame] | 143 | "Unsupported operand for G_MERGE_VALUES"); |
Diana Picus | b1701e0 | 2017-02-16 12:19:57 +0000 | [diff] [blame] | 144 | unsigned VReg1 = MIB->getOperand(1).getReg(); |
| 145 | (void)VReg1; |
| 146 | assert(MRI.getType(VReg1).getSizeInBits() == 32 && |
| 147 | RBI.getRegBank(VReg1, MRI, TRI)->getID() == ARM::GPRRegBankID && |
Diana Picus | 0b4190a | 2017-06-07 12:35:05 +0000 | [diff] [blame] | 148 | "Unsupported operand for G_MERGE_VALUES"); |
| 149 | unsigned VReg2 = MIB->getOperand(2).getReg(); |
Diana Picus | b1701e0 | 2017-02-16 12:19:57 +0000 | [diff] [blame] | 150 | (void)VReg2; |
| 151 | assert(MRI.getType(VReg2).getSizeInBits() == 32 && |
| 152 | RBI.getRegBank(VReg2, MRI, TRI)->getID() == ARM::GPRRegBankID && |
Diana Picus | 0b4190a | 2017-06-07 12:35:05 +0000 | [diff] [blame] | 153 | "Unsupported operand for G_MERGE_VALUES"); |
Diana Picus | b1701e0 | 2017-02-16 12:19:57 +0000 | [diff] [blame] | 154 | |
| 155 | MIB->setDesc(TII.get(ARM::VMOVDRR)); |
| 156 | MIB.add(predOps(ARMCC::AL)); |
| 157 | |
| 158 | return true; |
| 159 | } |
| 160 | |
Diana Picus | 0b4190a | 2017-06-07 12:35:05 +0000 | [diff] [blame] | 161 | static bool selectUnmergeValues(MachineInstrBuilder &MIB, |
| 162 | const ARMBaseInstrInfo &TII, |
| 163 | MachineRegisterInfo &MRI, |
| 164 | const TargetRegisterInfo &TRI, |
| 165 | const RegisterBankInfo &RBI) { |
| 166 | assert(TII.getSubtarget().hasVFP2() && "Can't select unmerge without VFP"); |
Diana Picus | b1701e0 | 2017-02-16 12:19:57 +0000 | [diff] [blame] | 167 | |
Diana Picus | 0b4190a | 2017-06-07 12:35:05 +0000 | [diff] [blame] | 168 | // We only support G_UNMERGE_VALUES as a way to break up one DPR into two |
| 169 | // GPRs. |
Diana Picus | b1701e0 | 2017-02-16 12:19:57 +0000 | [diff] [blame] | 170 | unsigned VReg0 = MIB->getOperand(0).getReg(); |
| 171 | (void)VReg0; |
| 172 | assert(MRI.getType(VReg0).getSizeInBits() == 32 && |
| 173 | RBI.getRegBank(VReg0, MRI, TRI)->getID() == ARM::GPRRegBankID && |
Diana Picus | 0b4190a | 2017-06-07 12:35:05 +0000 | [diff] [blame] | 174 | "Unsupported operand for G_UNMERGE_VALUES"); |
Diana Picus | b1701e0 | 2017-02-16 12:19:57 +0000 | [diff] [blame] | 175 | unsigned VReg1 = MIB->getOperand(1).getReg(); |
| 176 | (void)VReg1; |
Diana Picus | 0b4190a | 2017-06-07 12:35:05 +0000 | [diff] [blame] | 177 | assert(MRI.getType(VReg1).getSizeInBits() == 32 && |
| 178 | RBI.getRegBank(VReg1, MRI, TRI)->getID() == ARM::GPRRegBankID && |
| 179 | "Unsupported operand for G_UNMERGE_VALUES"); |
| 180 | unsigned VReg2 = MIB->getOperand(2).getReg(); |
| 181 | (void)VReg2; |
| 182 | assert(MRI.getType(VReg2).getSizeInBits() == 64 && |
| 183 | RBI.getRegBank(VReg2, MRI, TRI)->getID() == ARM::FPRRegBankID && |
| 184 | "Unsupported operand for G_UNMERGE_VALUES"); |
Diana Picus | b1701e0 | 2017-02-16 12:19:57 +0000 | [diff] [blame] | 185 | |
Diana Picus | 0b4190a | 2017-06-07 12:35:05 +0000 | [diff] [blame] | 186 | MIB->setDesc(TII.get(ARM::VMOVRRD)); |
Diana Picus | b1701e0 | 2017-02-16 12:19:57 +0000 | [diff] [blame] | 187 | MIB.add(predOps(ARMCC::AL)); |
| 188 | |
| 189 | return true; |
| 190 | } |
| 191 | |
Diana Picus | 8b6c6be | 2017-01-25 08:10:40 +0000 | [diff] [blame] | 192 | /// Select the opcode for simple extensions (that translate to a single SXT/UXT |
| 193 | /// instruction). Extension operations more complicated than that should not |
Diana Picus | e836878 | 2017-02-17 13:44:19 +0000 | [diff] [blame] | 194 | /// invoke this. Returns the original opcode if it doesn't know how to select a |
| 195 | /// better one. |
Diana Picus | 8b6c6be | 2017-01-25 08:10:40 +0000 | [diff] [blame] | 196 | static unsigned selectSimpleExtOpc(unsigned Opc, unsigned Size) { |
| 197 | using namespace TargetOpcode; |
| 198 | |
Diana Picus | e836878 | 2017-02-17 13:44:19 +0000 | [diff] [blame] | 199 | if (Size != 8 && Size != 16) |
| 200 | return Opc; |
Diana Picus | 8b6c6be | 2017-01-25 08:10:40 +0000 | [diff] [blame] | 201 | |
| 202 | if (Opc == G_SEXT) |
| 203 | return Size == 8 ? ARM::SXTB : ARM::SXTH; |
| 204 | |
| 205 | if (Opc == G_ZEXT) |
| 206 | return Size == 8 ? ARM::UXTB : ARM::UXTH; |
| 207 | |
Diana Picus | e836878 | 2017-02-17 13:44:19 +0000 | [diff] [blame] | 208 | return Opc; |
Diana Picus | 8b6c6be | 2017-01-25 08:10:40 +0000 | [diff] [blame] | 209 | } |
| 210 | |
Diana Picus | 3b99c64 | 2017-02-24 14:01:27 +0000 | [diff] [blame] | 211 | /// Select the opcode for simple loads and stores. For types smaller than 32 |
| 212 | /// bits, the value will be zero extended. Returns the original opcode if it |
| 213 | /// doesn't know how to select a better one. |
| 214 | static unsigned selectLoadStoreOpCode(unsigned Opc, unsigned RegBank, |
| 215 | unsigned Size) { |
| 216 | bool isStore = Opc == TargetOpcode::G_STORE; |
| 217 | |
Diana Picus | 1540b06 | 2017-02-16 14:10:50 +0000 | [diff] [blame] | 218 | if (RegBank == ARM::GPRRegBankID) { |
| 219 | switch (Size) { |
| 220 | case 1: |
| 221 | case 8: |
Diana Picus | 3b99c64 | 2017-02-24 14:01:27 +0000 | [diff] [blame] | 222 | return isStore ? ARM::STRBi12 : ARM::LDRBi12; |
Diana Picus | 1540b06 | 2017-02-16 14:10:50 +0000 | [diff] [blame] | 223 | case 16: |
Diana Picus | 3b99c64 | 2017-02-24 14:01:27 +0000 | [diff] [blame] | 224 | return isStore ? ARM::STRH : ARM::LDRH; |
Diana Picus | 1540b06 | 2017-02-16 14:10:50 +0000 | [diff] [blame] | 225 | case 32: |
Diana Picus | 3b99c64 | 2017-02-24 14:01:27 +0000 | [diff] [blame] | 226 | return isStore ? ARM::STRi12 : ARM::LDRi12; |
Diana Picus | e836878 | 2017-02-17 13:44:19 +0000 | [diff] [blame] | 227 | default: |
Diana Picus | 3b99c64 | 2017-02-24 14:01:27 +0000 | [diff] [blame] | 228 | return Opc; |
Diana Picus | 1540b06 | 2017-02-16 14:10:50 +0000 | [diff] [blame] | 229 | } |
Diana Picus | 1540b06 | 2017-02-16 14:10:50 +0000 | [diff] [blame] | 230 | } |
| 231 | |
Diana Picus | e836878 | 2017-02-17 13:44:19 +0000 | [diff] [blame] | 232 | if (RegBank == ARM::FPRRegBankID) { |
| 233 | switch (Size) { |
| 234 | case 32: |
Diana Picus | 3b99c64 | 2017-02-24 14:01:27 +0000 | [diff] [blame] | 235 | return isStore ? ARM::VSTRS : ARM::VLDRS; |
Diana Picus | e836878 | 2017-02-17 13:44:19 +0000 | [diff] [blame] | 236 | case 64: |
Diana Picus | 3b99c64 | 2017-02-24 14:01:27 +0000 | [diff] [blame] | 237 | return isStore ? ARM::VSTRD : ARM::VLDRD; |
Diana Picus | e836878 | 2017-02-17 13:44:19 +0000 | [diff] [blame] | 238 | default: |
Diana Picus | 3b99c64 | 2017-02-24 14:01:27 +0000 | [diff] [blame] | 239 | return Opc; |
Diana Picus | e836878 | 2017-02-17 13:44:19 +0000 | [diff] [blame] | 240 | } |
Diana Picus | 278c722 | 2017-01-26 09:20:47 +0000 | [diff] [blame] | 241 | } |
| 242 | |
Diana Picus | 3b99c64 | 2017-02-24 14:01:27 +0000 | [diff] [blame] | 243 | return Opc; |
Diana Picus | 278c722 | 2017-01-26 09:20:47 +0000 | [diff] [blame] | 244 | } |
| 245 | |
Diana Picus | 812caee | 2016-12-16 12:54:46 +0000 | [diff] [blame] | 246 | bool ARMInstructionSelector::select(MachineInstr &I) const { |
| 247 | assert(I.getParent() && "Instruction should be in a basic block!"); |
| 248 | assert(I.getParent()->getParent() && "Instruction should be in a function!"); |
| 249 | |
| 250 | auto &MBB = *I.getParent(); |
| 251 | auto &MF = *MBB.getParent(); |
| 252 | auto &MRI = MF.getRegInfo(); |
| 253 | |
| 254 | if (!isPreISelGenericOpcode(I.getOpcode())) { |
| 255 | if (I.isCopy()) |
| 256 | return selectCopy(I, TII, MRI, TRI, RBI); |
| 257 | |
| 258 | return true; |
| 259 | } |
| 260 | |
Diana Picus | 8abcbbb | 2017-05-02 09:40:49 +0000 | [diff] [blame] | 261 | if (selectImpl(I)) |
| 262 | return true; |
| 263 | |
Diana Picus | 519807f | 2016-12-19 11:26:31 +0000 | [diff] [blame] | 264 | MachineInstrBuilder MIB{MF, I}; |
Diana Picus | d83df5d | 2017-01-25 08:47:40 +0000 | [diff] [blame] | 265 | bool isSExt = false; |
Diana Picus | 519807f | 2016-12-19 11:26:31 +0000 | [diff] [blame] | 266 | |
| 267 | using namespace TargetOpcode; |
| 268 | switch (I.getOpcode()) { |
Diana Picus | 8b6c6be | 2017-01-25 08:10:40 +0000 | [diff] [blame] | 269 | case G_SEXT: |
Diana Picus | d83df5d | 2017-01-25 08:47:40 +0000 | [diff] [blame] | 270 | isSExt = true; |
| 271 | LLVM_FALLTHROUGH; |
Diana Picus | 8b6c6be | 2017-01-25 08:10:40 +0000 | [diff] [blame] | 272 | case G_ZEXT: { |
| 273 | LLT DstTy = MRI.getType(I.getOperand(0).getReg()); |
| 274 | // FIXME: Smaller destination sizes coming soon! |
| 275 | if (DstTy.getSizeInBits() != 32) { |
| 276 | DEBUG(dbgs() << "Unsupported destination size for extension"); |
| 277 | return false; |
| 278 | } |
| 279 | |
| 280 | LLT SrcTy = MRI.getType(I.getOperand(1).getReg()); |
| 281 | unsigned SrcSize = SrcTy.getSizeInBits(); |
| 282 | switch (SrcSize) { |
Diana Picus | d83df5d | 2017-01-25 08:47:40 +0000 | [diff] [blame] | 283 | case 1: { |
| 284 | // ZExt boils down to & 0x1; for SExt we also subtract that from 0 |
| 285 | I.setDesc(TII.get(ARM::ANDri)); |
| 286 | MIB.addImm(1).add(predOps(ARMCC::AL)).add(condCodeOp()); |
| 287 | |
| 288 | if (isSExt) { |
| 289 | unsigned SExtResult = I.getOperand(0).getReg(); |
| 290 | |
| 291 | // Use a new virtual register for the result of the AND |
| 292 | unsigned AndResult = MRI.createVirtualRegister(&ARM::GPRRegClass); |
| 293 | I.getOperand(0).setReg(AndResult); |
| 294 | |
| 295 | auto InsertBefore = std::next(I.getIterator()); |
Martin Bohme | 8396e14 | 2017-01-25 14:28:19 +0000 | [diff] [blame] | 296 | auto SubI = |
Diana Picus | d83df5d | 2017-01-25 08:47:40 +0000 | [diff] [blame] | 297 | BuildMI(MBB, InsertBefore, I.getDebugLoc(), TII.get(ARM::RSBri)) |
| 298 | .addDef(SExtResult) |
| 299 | .addUse(AndResult) |
| 300 | .addImm(0) |
| 301 | .add(predOps(ARMCC::AL)) |
| 302 | .add(condCodeOp()); |
| 303 | if (!constrainSelectedInstRegOperands(*SubI, TII, TRI, RBI)) |
| 304 | return false; |
| 305 | } |
| 306 | break; |
| 307 | } |
Diana Picus | 8b6c6be | 2017-01-25 08:10:40 +0000 | [diff] [blame] | 308 | case 8: |
| 309 | case 16: { |
| 310 | unsigned NewOpc = selectSimpleExtOpc(I.getOpcode(), SrcSize); |
Diana Picus | e836878 | 2017-02-17 13:44:19 +0000 | [diff] [blame] | 311 | if (NewOpc == I.getOpcode()) |
| 312 | return false; |
Diana Picus | 8b6c6be | 2017-01-25 08:10:40 +0000 | [diff] [blame] | 313 | I.setDesc(TII.get(NewOpc)); |
| 314 | MIB.addImm(0).add(predOps(ARMCC::AL)); |
| 315 | break; |
| 316 | } |
| 317 | default: |
| 318 | DEBUG(dbgs() << "Unsupported source size for extension"); |
| 319 | return false; |
| 320 | } |
| 321 | break; |
| 322 | } |
Diana Picus | 657bfd3 | 2017-05-11 08:28:31 +0000 | [diff] [blame] | 323 | case G_ANYEXT: |
Diana Picus | 64a3343 | 2017-04-21 13:16:50 +0000 | [diff] [blame] | 324 | case G_TRUNC: { |
| 325 | // The high bits are undefined, so there's nothing special to do, just |
| 326 | // treat it as a copy. |
| 327 | auto SrcReg = I.getOperand(1).getReg(); |
| 328 | auto DstReg = I.getOperand(0).getReg(); |
| 329 | |
| 330 | const auto &SrcRegBank = *RBI.getRegBank(SrcReg, MRI, TRI); |
| 331 | const auto &DstRegBank = *RBI.getRegBank(DstReg, MRI, TRI); |
| 332 | |
| 333 | if (SrcRegBank.getID() != DstRegBank.getID()) { |
Diana Picus | 657bfd3 | 2017-05-11 08:28:31 +0000 | [diff] [blame] | 334 | DEBUG(dbgs() << "G_TRUNC/G_ANYEXT operands on different register banks\n"); |
Diana Picus | 64a3343 | 2017-04-21 13:16:50 +0000 | [diff] [blame] | 335 | return false; |
| 336 | } |
| 337 | |
| 338 | if (SrcRegBank.getID() != ARM::GPRRegBankID) { |
Diana Picus | 657bfd3 | 2017-05-11 08:28:31 +0000 | [diff] [blame] | 339 | 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] | 340 | return false; |
| 341 | } |
| 342 | |
| 343 | I.setDesc(TII.get(COPY)); |
| 344 | return selectCopy(I, TII, MRI, TRI, RBI); |
| 345 | } |
Diana Picus | 9d07094 | 2017-02-28 10:14:38 +0000 | [diff] [blame] | 346 | case G_GEP: |
Diana Picus | 812caee | 2016-12-16 12:54:46 +0000 | [diff] [blame] | 347 | I.setDesc(TII.get(ARM::ADDrr)); |
Diana Picus | 8a73f55 | 2017-01-13 10:18:01 +0000 | [diff] [blame] | 348 | MIB.add(predOps(ARMCC::AL)).add(condCodeOp()); |
Diana Picus | 519807f | 2016-12-19 11:26:31 +0000 | [diff] [blame] | 349 | break; |
| 350 | case G_FRAME_INDEX: |
| 351 | // Add 0 to the given frame index and hope it will eventually be folded into |
| 352 | // the user(s). |
| 353 | I.setDesc(TII.get(ARM::ADDri)); |
Diana Picus | 8a73f55 | 2017-01-13 10:18:01 +0000 | [diff] [blame] | 354 | MIB.addImm(0).add(predOps(ARMCC::AL)).add(condCodeOp()); |
Diana Picus | 519807f | 2016-12-19 11:26:31 +0000 | [diff] [blame] | 355 | break; |
Diana Picus | 5a7203a | 2017-02-28 13:05:42 +0000 | [diff] [blame] | 356 | case G_CONSTANT: { |
| 357 | unsigned Reg = I.getOperand(0).getReg(); |
| 358 | if (MRI.getType(Reg).getSizeInBits() != 32) |
| 359 | return false; |
| 360 | |
| 361 | assert(RBI.getRegBank(Reg, MRI, TRI)->getID() == ARM::GPRRegBankID && |
| 362 | "Expected constant to live in a GPR"); |
| 363 | I.setDesc(TII.get(ARM::MOVi)); |
| 364 | MIB.add(predOps(ARMCC::AL)).add(condCodeOp()); |
Diana Picus | 95a8aa9 | 2017-04-24 06:30:56 +0000 | [diff] [blame] | 365 | |
| 366 | auto &Val = I.getOperand(1); |
| 367 | if (Val.isCImm()) { |
| 368 | if (Val.getCImm()->getBitWidth() > 32) |
| 369 | return false; |
| 370 | Val.ChangeToImmediate(Val.getCImm()->getZExtValue()); |
| 371 | } |
| 372 | |
| 373 | if (!Val.isImm()) { |
| 374 | return false; |
| 375 | } |
| 376 | |
Diana Picus | 5a7203a | 2017-02-28 13:05:42 +0000 | [diff] [blame] | 377 | break; |
| 378 | } |
Diana Picus | 3b99c64 | 2017-02-24 14:01:27 +0000 | [diff] [blame] | 379 | case G_STORE: |
Diana Picus | 278c722 | 2017-01-26 09:20:47 +0000 | [diff] [blame] | 380 | case G_LOAD: { |
Diana Picus | 1c33c9f | 2017-02-20 14:45:58 +0000 | [diff] [blame] | 381 | const auto &MemOp = **I.memoperands_begin(); |
| 382 | if (MemOp.getOrdering() != AtomicOrdering::NotAtomic) { |
| 383 | DEBUG(dbgs() << "Atomic load/store not supported yet\n"); |
| 384 | return false; |
| 385 | } |
| 386 | |
Diana Picus | 1540b06 | 2017-02-16 14:10:50 +0000 | [diff] [blame] | 387 | unsigned Reg = I.getOperand(0).getReg(); |
| 388 | unsigned RegBank = RBI.getRegBank(Reg, MRI, TRI)->getID(); |
| 389 | |
| 390 | LLT ValTy = MRI.getType(Reg); |
Diana Picus | 278c722 | 2017-01-26 09:20:47 +0000 | [diff] [blame] | 391 | const auto ValSize = ValTy.getSizeInBits(); |
| 392 | |
Diana Picus | 1540b06 | 2017-02-16 14:10:50 +0000 | [diff] [blame] | 393 | assert((ValSize != 64 || TII.getSubtarget().hasVFP2()) && |
Diana Picus | 3b99c64 | 2017-02-24 14:01:27 +0000 | [diff] [blame] | 394 | "Don't know how to load/store 64-bit value without VFP"); |
Diana Picus | 1540b06 | 2017-02-16 14:10:50 +0000 | [diff] [blame] | 395 | |
Diana Picus | 3b99c64 | 2017-02-24 14:01:27 +0000 | [diff] [blame] | 396 | const auto NewOpc = selectLoadStoreOpCode(I.getOpcode(), RegBank, ValSize); |
| 397 | if (NewOpc == G_LOAD || NewOpc == G_STORE) |
Diana Picus | e836878 | 2017-02-17 13:44:19 +0000 | [diff] [blame] | 398 | return false; |
| 399 | |
Diana Picus | 278c722 | 2017-01-26 09:20:47 +0000 | [diff] [blame] | 400 | I.setDesc(TII.get(NewOpc)); |
| 401 | |
Diana Picus | 3b99c64 | 2017-02-24 14:01:27 +0000 | [diff] [blame] | 402 | if (NewOpc == ARM::LDRH || NewOpc == ARM::STRH) |
Diana Picus | 278c722 | 2017-01-26 09:20:47 +0000 | [diff] [blame] | 403 | // LDRH has a funny addressing mode (there's already a FIXME for it). |
| 404 | MIB.addReg(0); |
Diana Picus | 4f8c3e1 | 2017-01-13 09:37:56 +0000 | [diff] [blame] | 405 | MIB.addImm(0).add(predOps(ARMCC::AL)); |
Diana Picus | 519807f | 2016-12-19 11:26:31 +0000 | [diff] [blame] | 406 | break; |
Diana Picus | 278c722 | 2017-01-26 09:20:47 +0000 | [diff] [blame] | 407 | } |
Diana Picus | 0b4190a | 2017-06-07 12:35:05 +0000 | [diff] [blame] | 408 | case G_MERGE_VALUES: { |
| 409 | if (!selectMergeValues(MIB, TII, MRI, TRI, RBI)) |
Diana Picus | b1701e0 | 2017-02-16 12:19:57 +0000 | [diff] [blame] | 410 | return false; |
| 411 | break; |
| 412 | } |
Diana Picus | 0b4190a | 2017-06-07 12:35:05 +0000 | [diff] [blame] | 413 | case G_UNMERGE_VALUES: { |
| 414 | if (!selectUnmergeValues(MIB, TII, MRI, TRI, RBI)) |
Diana Picus | b1701e0 | 2017-02-16 12:19:57 +0000 | [diff] [blame] | 415 | return false; |
| 416 | break; |
| 417 | } |
Diana Picus | 519807f | 2016-12-19 11:26:31 +0000 | [diff] [blame] | 418 | default: |
| 419 | return false; |
Diana Picus | 812caee | 2016-12-16 12:54:46 +0000 | [diff] [blame] | 420 | } |
| 421 | |
Diana Picus | 519807f | 2016-12-19 11:26:31 +0000 | [diff] [blame] | 422 | return constrainSelectedInstRegOperands(I, TII, TRI, RBI); |
Diana Picus | 2227493 | 2016-11-11 08:27:37 +0000 | [diff] [blame] | 423 | } |