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