Eric Christopher | 84bdfd8 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 1 | //===-- ARMFastISel.cpp - ARM FastISel implementation ---------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file defines the ARM-specific support for the FastISel class. Some |
| 11 | // of the target-specific code is generated by tablegen in the file |
| 12 | // ARMGenFastISel.inc, which is #included here. |
| 13 | // |
| 14 | //===----------------------------------------------------------------------===// |
| 15 | |
| 16 | #include "ARM.h" |
Craig Topper | a925326 | 2014-03-22 23:51:00 +0000 | [diff] [blame] | 17 | #include "ARMBaseRegisterInfo.h" |
Eric Christopher | 72497e5 | 2010-09-10 23:18:12 +0000 | [diff] [blame] | 18 | #include "ARMCallingConv.h" |
Eric Christopher | 83a5ec8 | 2010-10-01 23:24:42 +0000 | [diff] [blame] | 19 | #include "ARMConstantPoolValue.h" |
Craig Topper | a925326 | 2014-03-22 23:51:00 +0000 | [diff] [blame] | 20 | #include "ARMISelLowering.h" |
| 21 | #include "ARMMachineFunctionInfo.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 22 | #include "ARMSubtarget.h" |
Evan Cheng | a20cde3 | 2011-07-20 23:34:39 +0000 | [diff] [blame] | 23 | #include "MCTargetDesc/ARMAddressingModes.h" |
JF Bastien | 3c6bb8e | 2013-06-11 22:13:46 +0000 | [diff] [blame] | 24 | #include "llvm/ADT/STLExtras.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 25 | #include "llvm/CodeGen/Analysis.h" |
| 26 | #include "llvm/CodeGen/FastISel.h" |
| 27 | #include "llvm/CodeGen/FunctionLoweringInfo.h" |
| 28 | #include "llvm/CodeGen/MachineConstantPool.h" |
| 29 | #include "llvm/CodeGen/MachineFrameInfo.h" |
| 30 | #include "llvm/CodeGen/MachineInstrBuilder.h" |
| 31 | #include "llvm/CodeGen/MachineMemOperand.h" |
| 32 | #include "llvm/CodeGen/MachineModuleInfo.h" |
| 33 | #include "llvm/CodeGen/MachineRegisterInfo.h" |
Chandler Carruth | 219b89b | 2014-03-04 11:01:28 +0000 | [diff] [blame] | 34 | #include "llvm/IR/CallSite.h" |
Chandler Carruth | 9fb823b | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 35 | #include "llvm/IR/CallingConv.h" |
| 36 | #include "llvm/IR/DataLayout.h" |
| 37 | #include "llvm/IR/DerivedTypes.h" |
Chandler Carruth | 03eb0de | 2014-03-04 10:40:04 +0000 | [diff] [blame] | 38 | #include "llvm/IR/GetElementPtrTypeIterator.h" |
Chandler Carruth | 9fb823b | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 39 | #include "llvm/IR/GlobalVariable.h" |
| 40 | #include "llvm/IR/Instructions.h" |
| 41 | #include "llvm/IR/IntrinsicInst.h" |
| 42 | #include "llvm/IR/Module.h" |
| 43 | #include "llvm/IR/Operator.h" |
Eric Christopher | 663f499 | 2010-08-17 00:46:57 +0000 | [diff] [blame] | 44 | #include "llvm/Support/CommandLine.h" |
Eric Christopher | 84bdfd8 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 45 | #include "llvm/Support/ErrorHandling.h" |
Eric Christopher | 09f757d | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 46 | #include "llvm/Target/TargetInstrInfo.h" |
| 47 | #include "llvm/Target/TargetLowering.h" |
| 48 | #include "llvm/Target/TargetMachine.h" |
Eric Christopher | 84bdfd8 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 49 | #include "llvm/Target/TargetOptions.h" |
| 50 | using namespace llvm; |
| 51 | |
| 52 | namespace { |
Eric Christopher | 0a3c28b | 2010-11-20 22:38:27 +0000 | [diff] [blame] | 53 | |
Eric Christopher | fef5f31 | 2010-11-19 22:30:02 +0000 | [diff] [blame] | 54 | // All possible address modes, plus some. |
| 55 | typedef struct Address { |
| 56 | enum { |
| 57 | RegBase, |
| 58 | FrameIndexBase |
| 59 | } BaseType; |
Eric Christopher | 0a3c28b | 2010-11-20 22:38:27 +0000 | [diff] [blame] | 60 | |
Eric Christopher | fef5f31 | 2010-11-19 22:30:02 +0000 | [diff] [blame] | 61 | union { |
| 62 | unsigned Reg; |
| 63 | int FI; |
| 64 | } Base; |
Eric Christopher | 0a3c28b | 2010-11-20 22:38:27 +0000 | [diff] [blame] | 65 | |
Eric Christopher | fef5f31 | 2010-11-19 22:30:02 +0000 | [diff] [blame] | 66 | int Offset; |
Eric Christopher | 0a3c28b | 2010-11-20 22:38:27 +0000 | [diff] [blame] | 67 | |
Eric Christopher | fef5f31 | 2010-11-19 22:30:02 +0000 | [diff] [blame] | 68 | // Innocuous defaults for our address. |
| 69 | Address() |
Jim Grosbach | 4e98316 | 2011-05-16 22:24:07 +0000 | [diff] [blame] | 70 | : BaseType(RegBase), Offset(0) { |
Eric Christopher | fef5f31 | 2010-11-19 22:30:02 +0000 | [diff] [blame] | 71 | Base.Reg = 0; |
| 72 | } |
| 73 | } Address; |
Eric Christopher | 84bdfd8 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 74 | |
Craig Topper | 2669631 | 2014-03-18 07:27:13 +0000 | [diff] [blame] | 75 | class ARMFastISel final : public FastISel { |
Eric Christopher | 84bdfd8 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 76 | |
| 77 | /// Subtarget - Keep a pointer to the ARMSubtarget around so that we can |
| 78 | /// make the right decision when generating code for different targets. |
| 79 | const ARMSubtarget *Subtarget; |
Bill Wendling | 6c1d959 | 2013-12-30 05:17:29 +0000 | [diff] [blame] | 80 | Module &M; |
Eric Christopher | 09f757d | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 81 | const TargetMachine &TM; |
| 82 | const TargetInstrInfo &TII; |
| 83 | const TargetLowering &TLI; |
Eric Christopher | 83a5ec8 | 2010-10-01 23:24:42 +0000 | [diff] [blame] | 84 | ARMFunctionInfo *AFI; |
Eric Christopher | 84bdfd8 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 85 | |
Eric Christopher | b024be3 | 2010-09-29 22:24:45 +0000 | [diff] [blame] | 86 | // Convenience variables to avoid some queries. |
Chad Rosier | 0439cfc | 2011-11-08 21:12:00 +0000 | [diff] [blame] | 87 | bool isThumb2; |
Eric Christopher | b024be3 | 2010-09-29 22:24:45 +0000 | [diff] [blame] | 88 | LLVMContext *Context; |
Eric Christopher | 6a0333c | 2010-09-02 01:39:14 +0000 | [diff] [blame] | 89 | |
Eric Christopher | 84bdfd8 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 90 | public: |
Bob Wilson | 3e6fa46 | 2012-08-03 04:06:28 +0000 | [diff] [blame] | 91 | explicit ARMFastISel(FunctionLoweringInfo &funcInfo, |
| 92 | const TargetLibraryInfo *libInfo) |
Eric Christopher | d913448 | 2014-08-04 21:25:23 +0000 | [diff] [blame] | 93 | : FastISel(funcInfo, libInfo), |
Eric Christopher | c125e12 | 2015-01-29 00:19:37 +0000 | [diff] [blame] | 94 | Subtarget( |
| 95 | &static_cast<const ARMSubtarget &>(funcInfo.MF->getSubtarget())), |
Eric Christopher | d913448 | 2014-08-04 21:25:23 +0000 | [diff] [blame] | 96 | M(const_cast<Module &>(*funcInfo.Fn->getParent())), |
Eric Christopher | c125e12 | 2015-01-29 00:19:37 +0000 | [diff] [blame] | 97 | TM(funcInfo.MF->getTarget()), TII(*Subtarget->getInstrInfo()), |
| 98 | TLI(*Subtarget->getTargetLowering()) { |
Eric Christopher | 8d03b8a | 2010-08-23 22:32:45 +0000 | [diff] [blame] | 99 | AFI = funcInfo.MF->getInfo<ARMFunctionInfo>(); |
Chad Rosier | 0439cfc | 2011-11-08 21:12:00 +0000 | [diff] [blame] | 100 | isThumb2 = AFI->isThumbFunction(); |
Eric Christopher | b024be3 | 2010-09-29 22:24:45 +0000 | [diff] [blame] | 101 | Context = &funcInfo.Fn->getContext(); |
Eric Christopher | 84bdfd8 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 102 | } |
| 103 | |
Eric Christopher | d8e8a29 | 2010-08-20 00:20:31 +0000 | [diff] [blame] | 104 | // Code from FastISel.cpp. |
Craig Topper | fd1c925 | 2012-08-18 21:38:45 +0000 | [diff] [blame] | 105 | private: |
Juergen Ributzka | 88e3251 | 2014-09-03 20:56:59 +0000 | [diff] [blame] | 106 | unsigned fastEmitInst_r(unsigned MachineInstOpcode, |
Craig Topper | fd1c925 | 2012-08-18 21:38:45 +0000 | [diff] [blame] | 107 | const TargetRegisterClass *RC, |
| 108 | unsigned Op0, bool Op0IsKill); |
Juergen Ributzka | 88e3251 | 2014-09-03 20:56:59 +0000 | [diff] [blame] | 109 | unsigned fastEmitInst_rr(unsigned MachineInstOpcode, |
Craig Topper | fd1c925 | 2012-08-18 21:38:45 +0000 | [diff] [blame] | 110 | const TargetRegisterClass *RC, |
| 111 | unsigned Op0, bool Op0IsKill, |
| 112 | unsigned Op1, bool Op1IsKill); |
Juergen Ributzka | 88e3251 | 2014-09-03 20:56:59 +0000 | [diff] [blame] | 113 | unsigned fastEmitInst_rrr(unsigned MachineInstOpcode, |
Craig Topper | fd1c925 | 2012-08-18 21:38:45 +0000 | [diff] [blame] | 114 | const TargetRegisterClass *RC, |
| 115 | unsigned Op0, bool Op0IsKill, |
| 116 | unsigned Op1, bool Op1IsKill, |
| 117 | unsigned Op2, bool Op2IsKill); |
Juergen Ributzka | 88e3251 | 2014-09-03 20:56:59 +0000 | [diff] [blame] | 118 | unsigned fastEmitInst_ri(unsigned MachineInstOpcode, |
Craig Topper | fd1c925 | 2012-08-18 21:38:45 +0000 | [diff] [blame] | 119 | const TargetRegisterClass *RC, |
| 120 | unsigned Op0, bool Op0IsKill, |
| 121 | uint64_t Imm); |
Juergen Ributzka | 88e3251 | 2014-09-03 20:56:59 +0000 | [diff] [blame] | 122 | unsigned fastEmitInst_rri(unsigned MachineInstOpcode, |
Craig Topper | fd1c925 | 2012-08-18 21:38:45 +0000 | [diff] [blame] | 123 | const TargetRegisterClass *RC, |
| 124 | unsigned Op0, bool Op0IsKill, |
| 125 | unsigned Op1, bool Op1IsKill, |
| 126 | uint64_t Imm); |
Juergen Ributzka | 88e3251 | 2014-09-03 20:56:59 +0000 | [diff] [blame] | 127 | unsigned fastEmitInst_i(unsigned MachineInstOpcode, |
Craig Topper | fd1c925 | 2012-08-18 21:38:45 +0000 | [diff] [blame] | 128 | const TargetRegisterClass *RC, |
| 129 | uint64_t Imm); |
Eric Christopher | 2ff757d | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 130 | |
Eric Christopher | d8e8a29 | 2010-08-20 00:20:31 +0000 | [diff] [blame] | 131 | // Backend specific FastISel code. |
Craig Topper | fd1c925 | 2012-08-18 21:38:45 +0000 | [diff] [blame] | 132 | private: |
Juergen Ributzka | 5b8bb4d | 2014-09-03 20:56:52 +0000 | [diff] [blame] | 133 | bool fastSelectInstruction(const Instruction *I) override; |
| 134 | unsigned fastMaterializeConstant(const Constant *C) override; |
| 135 | unsigned fastMaterializeAlloca(const AllocaInst *AI) override; |
Craig Topper | 6bc27bf | 2014-03-10 02:09:33 +0000 | [diff] [blame] | 136 | bool tryToFoldLoadIntoMI(MachineInstr *MI, unsigned OpNo, |
| 137 | const LoadInst *LI) override; |
Juergen Ributzka | 5b8bb4d | 2014-09-03 20:56:52 +0000 | [diff] [blame] | 138 | bool fastLowerArguments() override; |
Craig Topper | fd1c925 | 2012-08-18 21:38:45 +0000 | [diff] [blame] | 139 | private: |
Eric Christopher | 84bdfd8 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 140 | #include "ARMGenFastISel.inc" |
Eric Christopher | 2ff757d | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 141 | |
Eric Christopher | 00202ee | 2010-08-23 21:44:12 +0000 | [diff] [blame] | 142 | // Instruction selection routines. |
Eric Christopher | cc766a2 | 2010-09-10 23:10:30 +0000 | [diff] [blame] | 143 | private: |
Eric Christopher | 2f8637d | 2010-10-21 21:47:51 +0000 | [diff] [blame] | 144 | bool SelectLoad(const Instruction *I); |
| 145 | bool SelectStore(const Instruction *I); |
| 146 | bool SelectBranch(const Instruction *I); |
Chad Rosier | ded4c99 | 2012-02-07 23:56:08 +0000 | [diff] [blame] | 147 | bool SelectIndirectBr(const Instruction *I); |
Eric Christopher | 2f8637d | 2010-10-21 21:47:51 +0000 | [diff] [blame] | 148 | bool SelectCmp(const Instruction *I); |
| 149 | bool SelectFPExt(const Instruction *I); |
| 150 | bool SelectFPTrunc(const Instruction *I); |
Chad Rosier | 685b20c | 2012-02-06 23:50:07 +0000 | [diff] [blame] | 151 | bool SelectBinaryIntOp(const Instruction *I, unsigned ISDOpcode); |
| 152 | bool SelectBinaryFPOp(const Instruction *I, unsigned ISDOpcode); |
Chad Rosier | e023d5d | 2012-02-03 21:14:11 +0000 | [diff] [blame] | 153 | bool SelectIToFP(const Instruction *I, bool isSigned); |
| 154 | bool SelectFPToI(const Instruction *I, bool isSigned); |
Chad Rosier | aaa55a8 | 2012-02-03 21:07:27 +0000 | [diff] [blame] | 155 | bool SelectDiv(const Instruction *I, bool isSigned); |
Chad Rosier | b84a4b4 | 2012-02-03 21:23:45 +0000 | [diff] [blame] | 156 | bool SelectRem(const Instruction *I, bool isSigned); |
Chad Rosier | a7ebc56 | 2011-11-11 23:31:03 +0000 | [diff] [blame] | 157 | bool SelectCall(const Instruction *I, const char *IntrMemName); |
| 158 | bool SelectIntrinsicCall(const IntrinsicInst &I); |
Eric Christopher | 2f8637d | 2010-10-21 21:47:51 +0000 | [diff] [blame] | 159 | bool SelectSelect(const Instruction *I); |
Eric Christopher | 93bbe65 | 2010-10-22 01:28:00 +0000 | [diff] [blame] | 160 | bool SelectRet(const Instruction *I); |
Chad Rosier | ee7e452 | 2011-11-02 00:18:48 +0000 | [diff] [blame] | 161 | bool SelectTrunc(const Instruction *I); |
| 162 | bool SelectIntExt(const Instruction *I); |
Jush Lu | 4705da9 | 2012-08-03 02:37:48 +0000 | [diff] [blame] | 163 | bool SelectShift(const Instruction *I, ARM_AM::ShiftOpc ShiftTy); |
Eric Christopher | 84bdfd8 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 164 | |
Eric Christopher | 00202ee | 2010-08-23 21:44:12 +0000 | [diff] [blame] | 165 | // Utility routines. |
Eric Christopher | 0d274a0 | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 166 | private: |
Chris Lattner | 229907c | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 167 | bool isTypeLegal(Type *Ty, MVT &VT); |
| 168 | bool isLoadTypeLegal(Type *Ty, MVT &VT); |
Chad Rosier | 9cf803c | 2011-11-02 18:08:25 +0000 | [diff] [blame] | 169 | bool ARMEmitCmp(const Value *Src1Value, const Value *Src2Value, |
David Blaikie | 3ef249c9 | 2015-01-30 23:04:39 +0000 | [diff] [blame] | 170 | bool isZExt); |
Patrik Hagglund | 5e6c361 | 2012-12-13 06:34:11 +0000 | [diff] [blame] | 171 | bool ARMEmitLoad(MVT VT, unsigned &ResultReg, Address &Addr, |
Chad Rosier | a26979b | 2011-12-14 17:26:05 +0000 | [diff] [blame] | 172 | unsigned Alignment = 0, bool isZExt = true, |
| 173 | bool allocReg = true); |
Patrik Hagglund | 5e6c361 | 2012-12-13 06:34:11 +0000 | [diff] [blame] | 174 | bool ARMEmitStore(MVT VT, unsigned SrcReg, Address &Addr, |
Bob Wilson | 80381f6 | 2011-12-04 00:52:23 +0000 | [diff] [blame] | 175 | unsigned Alignment = 0); |
Eric Christopher | fef5f31 | 2010-11-19 22:30:02 +0000 | [diff] [blame] | 176 | bool ARMComputeAddress(const Value *Obj, Address &Addr); |
Chad Rosier | 150d35b | 2012-12-17 22:35:29 +0000 | [diff] [blame] | 177 | void ARMSimplifyAddress(Address &Addr, MVT VT, bool useAM3); |
Chad Rosier | 057b6d3 | 2011-11-14 23:04:09 +0000 | [diff] [blame] | 178 | bool ARMIsMemCpySmall(uint64_t Len); |
Chad Rosier | 9f5c68a | 2012-12-06 01:34:31 +0000 | [diff] [blame] | 179 | bool ARMTryEmitSmallMemCpy(Address Dest, Address Src, uint64_t Len, |
| 180 | unsigned Alignment); |
Chad Rosier | 62a144f | 2012-12-17 19:59:43 +0000 | [diff] [blame] | 181 | unsigned ARMEmitIntExt(MVT SrcVT, unsigned SrcReg, MVT DestVT, bool isZExt); |
Patrik Hagglund | 5e6c361 | 2012-12-13 06:34:11 +0000 | [diff] [blame] | 182 | unsigned ARMMaterializeFP(const ConstantFP *CFP, MVT VT); |
| 183 | unsigned ARMMaterializeInt(const Constant *C, MVT VT); |
| 184 | unsigned ARMMaterializeGV(const GlobalValue *GV, MVT VT); |
| 185 | unsigned ARMMoveToFPReg(MVT VT, unsigned SrcReg); |
| 186 | unsigned ARMMoveToIntReg(MVT VT, unsigned SrcReg); |
Chad Rosier | c6916f8 | 2012-06-12 19:25:13 +0000 | [diff] [blame] | 187 | unsigned ARMSelectCallOp(bool UseReg); |
Patrik Hagglund | 5e6c361 | 2012-12-13 06:34:11 +0000 | [diff] [blame] | 188 | unsigned ARMLowerPICELF(const GlobalValue *GV, unsigned Align, MVT VT); |
Eric Christopher | 2ff757d | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 189 | |
Eric Christopher | 1b21f00 | 2015-01-29 00:19:33 +0000 | [diff] [blame] | 190 | const TargetLowering *getTargetLowering() { return &TLI; } |
Christian Pirker | 238c7c1 | 2014-05-12 11:19:20 +0000 | [diff] [blame] | 191 | |
Eric Christopher | 72497e5 | 2010-09-10 23:18:12 +0000 | [diff] [blame] | 192 | // Call handling routines. |
| 193 | private: |
Jush Lu | e67e07b | 2012-07-19 09:49:00 +0000 | [diff] [blame] | 194 | CCAssignFn *CCAssignFnForCall(CallingConv::ID CC, |
| 195 | bool Return, |
| 196 | bool isVarArg); |
Eric Christopher | 7ac602b | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 197 | bool ProcessCallArgs(SmallVectorImpl<Value*> &Args, |
Eric Christopher | 7939806 | 2010-09-29 23:11:09 +0000 | [diff] [blame] | 198 | SmallVectorImpl<unsigned> &ArgRegs, |
Duncan Sands | f5dda01 | 2010-11-03 11:35:31 +0000 | [diff] [blame] | 199 | SmallVectorImpl<MVT> &ArgVTs, |
Eric Christopher | 7939806 | 2010-09-29 23:11:09 +0000 | [diff] [blame] | 200 | SmallVectorImpl<ISD::ArgFlagsTy> &ArgFlags, |
| 201 | SmallVectorImpl<unsigned> &RegArgs, |
| 202 | CallingConv::ID CC, |
Jush Lu | e67e07b | 2012-07-19 09:49:00 +0000 | [diff] [blame] | 203 | unsigned &NumBytes, |
| 204 | bool isVarArg); |
Chad Rosier | c6916f8 | 2012-06-12 19:25:13 +0000 | [diff] [blame] | 205 | unsigned getLibcallReg(const Twine &Name); |
Duncan Sands | f5dda01 | 2010-11-03 11:35:31 +0000 | [diff] [blame] | 206 | bool FinishCall(MVT RetVT, SmallVectorImpl<unsigned> &UsedRegs, |
Eric Christopher | 7939806 | 2010-09-29 23:11:09 +0000 | [diff] [blame] | 207 | const Instruction *I, CallingConv::ID CC, |
Jush Lu | e67e07b | 2012-07-19 09:49:00 +0000 | [diff] [blame] | 208 | unsigned &NumBytes, bool isVarArg); |
Eric Christopher | 7990df1 | 2010-09-28 01:21:42 +0000 | [diff] [blame] | 209 | bool ARMEmitLibcall(const Instruction *I, RTLIB::Libcall Call); |
Eric Christopher | 72497e5 | 2010-09-10 23:18:12 +0000 | [diff] [blame] | 210 | |
| 211 | // OptionalDef handling routines. |
| 212 | private: |
Eric Christopher | 174d872 | 2011-03-12 01:09:29 +0000 | [diff] [blame] | 213 | bool isARMNEONPred(const MachineInstr *MI); |
Eric Christopher | 0d274a0 | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 214 | bool DefinesOptionalPredicate(MachineInstr *MI, bool *CPSR); |
| 215 | const MachineInstrBuilder &AddOptionalDefs(const MachineInstrBuilder &MIB); |
Chad Rosier | 150d35b | 2012-12-17 22:35:29 +0000 | [diff] [blame] | 216 | void AddLoadStoreOperands(MVT VT, Address &Addr, |
Cameron Zwarich | 6528a54 | 2011-05-28 20:34:49 +0000 | [diff] [blame] | 217 | const MachineInstrBuilder &MIB, |
Chad Rosier | c8cfd3a | 2011-11-13 02:23:59 +0000 | [diff] [blame] | 218 | unsigned Flags, bool useAM3); |
Eric Christopher | 0d274a0 | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 219 | }; |
Eric Christopher | 84bdfd8 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 220 | |
| 221 | } // end anonymous namespace |
| 222 | |
Eric Christopher | 72497e5 | 2010-09-10 23:18:12 +0000 | [diff] [blame] | 223 | #include "ARMGenCallingConv.inc" |
Eric Christopher | 84bdfd8 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 224 | |
Eric Christopher | 0d274a0 | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 225 | // DefinesOptionalPredicate - This is different from DefinesPredicate in that |
| 226 | // we don't care about implicit defs here, just places we'll need to add a |
| 227 | // default CCReg argument. Sets CPSR if we're setting CPSR instead of CCR. |
| 228 | bool ARMFastISel::DefinesOptionalPredicate(MachineInstr *MI, bool *CPSR) { |
Evan Cheng | 7f8e563 | 2011-12-07 07:15:52 +0000 | [diff] [blame] | 229 | if (!MI->hasOptionalDef()) |
Eric Christopher | 0d274a0 | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 230 | return false; |
| 231 | |
| 232 | // Look to see if our OptionalDef is defining CPSR or CCR. |
| 233 | for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) { |
| 234 | const MachineOperand &MO = MI->getOperand(i); |
Eric Christopher | 985d9e4 | 2010-08-20 00:36:24 +0000 | [diff] [blame] | 235 | if (!MO.isReg() || !MO.isDef()) continue; |
| 236 | if (MO.getReg() == ARM::CPSR) |
Eric Christopher | 0d274a0 | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 237 | *CPSR = true; |
| 238 | } |
| 239 | return true; |
| 240 | } |
| 241 | |
Eric Christopher | 174d872 | 2011-03-12 01:09:29 +0000 | [diff] [blame] | 242 | bool ARMFastISel::isARMNEONPred(const MachineInstr *MI) { |
Evan Cheng | 6cc775f | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 243 | const MCInstrDesc &MCID = MI->getDesc(); |
Eric Christopher | 501d2e2 | 2011-04-29 00:03:10 +0000 | [diff] [blame] | 244 | |
Joey Gouly | a5153cb | 2013-09-09 14:21:49 +0000 | [diff] [blame] | 245 | // If we're a thumb2 or not NEON function we'll be handled via isPredicable. |
Evan Cheng | 6cc775f | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 246 | if ((MCID.TSFlags & ARMII::DomainMask) != ARMII::DomainNEON || |
Eric Christopher | 174d872 | 2011-03-12 01:09:29 +0000 | [diff] [blame] | 247 | AFI->isThumb2Function()) |
Joey Gouly | a5153cb | 2013-09-09 14:21:49 +0000 | [diff] [blame] | 248 | return MI->isPredicable(); |
Eric Christopher | 501d2e2 | 2011-04-29 00:03:10 +0000 | [diff] [blame] | 249 | |
Evan Cheng | 6cc775f | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 250 | for (unsigned i = 0, e = MCID.getNumOperands(); i != e; ++i) |
| 251 | if (MCID.OpInfo[i].isPredicate()) |
Eric Christopher | 174d872 | 2011-03-12 01:09:29 +0000 | [diff] [blame] | 252 | return true; |
Eric Christopher | 501d2e2 | 2011-04-29 00:03:10 +0000 | [diff] [blame] | 253 | |
Eric Christopher | 174d872 | 2011-03-12 01:09:29 +0000 | [diff] [blame] | 254 | return false; |
| 255 | } |
| 256 | |
Eric Christopher | 0d274a0 | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 257 | // If the machine is predicable go ahead and add the predicate operands, if |
| 258 | // it needs default CC operands add those. |
Eric Christopher | e8fccc8 | 2010-11-02 01:21:28 +0000 | [diff] [blame] | 259 | // TODO: If we want to support thumb1 then we'll need to deal with optional |
| 260 | // CPSR defs that need to be added before the remaining operands. See s_cc_out |
| 261 | // for descriptions why. |
Eric Christopher | 0d274a0 | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 262 | const MachineInstrBuilder & |
| 263 | ARMFastISel::AddOptionalDefs(const MachineInstrBuilder &MIB) { |
| 264 | MachineInstr *MI = &*MIB; |
| 265 | |
Eric Christopher | 174d872 | 2011-03-12 01:09:29 +0000 | [diff] [blame] | 266 | // Do we use a predicate? or... |
| 267 | // Are we NEON in ARM mode and have a predicate operand? If so, I know |
| 268 | // we're not predicable but add it anyways. |
Joey Gouly | a5153cb | 2013-09-09 14:21:49 +0000 | [diff] [blame] | 269 | if (isARMNEONPred(MI)) |
Eric Christopher | 0d274a0 | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 270 | AddDefaultPred(MIB); |
Eric Christopher | 501d2e2 | 2011-04-29 00:03:10 +0000 | [diff] [blame] | 271 | |
Sylvestre Ledru | 91ce36c | 2012-09-27 10:14:43 +0000 | [diff] [blame] | 272 | // Do we optionally set a predicate? Preds is size > 0 iff the predicate |
Eric Christopher | 0d274a0 | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 273 | // defines CPSR. All other OptionalDefines in ARM are the CCR register. |
Eric Christopher | a5d60c6 | 2010-08-19 15:35:27 +0000 | [diff] [blame] | 274 | bool CPSR = false; |
Eric Christopher | 0d274a0 | 2010-08-19 00:37:05 +0000 | [diff] [blame] | 275 | if (DefinesOptionalPredicate(MI, &CPSR)) { |
| 276 | if (CPSR) |
| 277 | AddDefaultT1CC(MIB); |
| 278 | else |
| 279 | AddDefaultCC(MIB); |
| 280 | } |
| 281 | return MIB; |
| 282 | } |
| 283 | |
Juergen Ributzka | 88e3251 | 2014-09-03 20:56:59 +0000 | [diff] [blame] | 284 | unsigned ARMFastISel::fastEmitInst_r(unsigned MachineInstOpcode, |
Eric Christopher | 09f757d | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 285 | const TargetRegisterClass *RC, |
| 286 | unsigned Op0, bool Op0IsKill) { |
| 287 | unsigned ResultReg = createResultReg(RC); |
Evan Cheng | 6cc775f | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 288 | const MCInstrDesc &II = TII.get(MachineInstOpcode); |
Eric Christopher | 09f757d | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 289 | |
Jim Grosbach | 06c2a68 | 2013-08-16 23:37:31 +0000 | [diff] [blame] | 290 | // Make sure the input operand is sufficiently constrained to be legal |
| 291 | // for this instruction. |
| 292 | Op0 = constrainOperandRegClass(II, Op0, 1); |
Chad Rosier | 0bc5132 | 2012-02-15 17:36:21 +0000 | [diff] [blame] | 293 | if (II.getNumDefs() >= 1) { |
Rafael Espindola | ea09c59 | 2014-02-18 22:05:46 +0000 | [diff] [blame] | 294 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, II, |
| 295 | ResultReg).addReg(Op0, Op0IsKill * RegState::Kill)); |
Chad Rosier | 0bc5132 | 2012-02-15 17:36:21 +0000 | [diff] [blame] | 296 | } else { |
Rafael Espindola | ea09c59 | 2014-02-18 22:05:46 +0000 | [diff] [blame] | 297 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, II) |
Eric Christopher | 09f757d | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 298 | .addReg(Op0, Op0IsKill * RegState::Kill)); |
Rafael Espindola | ea09c59 | 2014-02-18 22:05:46 +0000 | [diff] [blame] | 299 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, |
Eric Christopher | 09f757d | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 300 | TII.get(TargetOpcode::COPY), ResultReg) |
| 301 | .addReg(II.ImplicitDefs[0])); |
| 302 | } |
| 303 | return ResultReg; |
| 304 | } |
| 305 | |
Juergen Ributzka | 88e3251 | 2014-09-03 20:56:59 +0000 | [diff] [blame] | 306 | unsigned ARMFastISel::fastEmitInst_rr(unsigned MachineInstOpcode, |
Eric Christopher | 09f757d | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 307 | const TargetRegisterClass *RC, |
| 308 | unsigned Op0, bool Op0IsKill, |
| 309 | unsigned Op1, bool Op1IsKill) { |
| 310 | unsigned ResultReg = createResultReg(RC); |
Evan Cheng | 6cc775f | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 311 | const MCInstrDesc &II = TII.get(MachineInstOpcode); |
Eric Christopher | 09f757d | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 312 | |
Jim Grosbach | 06c2a68 | 2013-08-16 23:37:31 +0000 | [diff] [blame] | 313 | // Make sure the input operands are sufficiently constrained to be legal |
| 314 | // for this instruction. |
| 315 | Op0 = constrainOperandRegClass(II, Op0, 1); |
| 316 | Op1 = constrainOperandRegClass(II, Op1, 2); |
| 317 | |
Chad Rosier | 0bc5132 | 2012-02-15 17:36:21 +0000 | [diff] [blame] | 318 | if (II.getNumDefs() >= 1) { |
Rafael Espindola | ea09c59 | 2014-02-18 22:05:46 +0000 | [diff] [blame] | 319 | AddOptionalDefs( |
| 320 | BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, II, ResultReg) |
| 321 | .addReg(Op0, Op0IsKill * RegState::Kill) |
| 322 | .addReg(Op1, Op1IsKill * RegState::Kill)); |
Chad Rosier | 0bc5132 | 2012-02-15 17:36:21 +0000 | [diff] [blame] | 323 | } else { |
Rafael Espindola | ea09c59 | 2014-02-18 22:05:46 +0000 | [diff] [blame] | 324 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, II) |
Eric Christopher | 09f757d | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 325 | .addReg(Op0, Op0IsKill * RegState::Kill) |
| 326 | .addReg(Op1, Op1IsKill * RegState::Kill)); |
Rafael Espindola | ea09c59 | 2014-02-18 22:05:46 +0000 | [diff] [blame] | 327 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, |
Eric Christopher | 09f757d | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 328 | TII.get(TargetOpcode::COPY), ResultReg) |
| 329 | .addReg(II.ImplicitDefs[0])); |
| 330 | } |
| 331 | return ResultReg; |
| 332 | } |
| 333 | |
Juergen Ributzka | 88e3251 | 2014-09-03 20:56:59 +0000 | [diff] [blame] | 334 | unsigned ARMFastISel::fastEmitInst_rrr(unsigned MachineInstOpcode, |
Cameron Zwarich | 53dd03d | 2011-03-30 23:01:21 +0000 | [diff] [blame] | 335 | const TargetRegisterClass *RC, |
| 336 | unsigned Op0, bool Op0IsKill, |
| 337 | unsigned Op1, bool Op1IsKill, |
| 338 | unsigned Op2, bool Op2IsKill) { |
| 339 | unsigned ResultReg = createResultReg(RC); |
Evan Cheng | 6cc775f | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 340 | const MCInstrDesc &II = TII.get(MachineInstOpcode); |
Cameron Zwarich | 53dd03d | 2011-03-30 23:01:21 +0000 | [diff] [blame] | 341 | |
Jim Grosbach | 06c2a68 | 2013-08-16 23:37:31 +0000 | [diff] [blame] | 342 | // Make sure the input operands are sufficiently constrained to be legal |
| 343 | // for this instruction. |
| 344 | Op0 = constrainOperandRegClass(II, Op0, 1); |
| 345 | Op1 = constrainOperandRegClass(II, Op1, 2); |
| 346 | Op2 = constrainOperandRegClass(II, Op1, 3); |
| 347 | |
Chad Rosier | 0bc5132 | 2012-02-15 17:36:21 +0000 | [diff] [blame] | 348 | if (II.getNumDefs() >= 1) { |
Rafael Espindola | ea09c59 | 2014-02-18 22:05:46 +0000 | [diff] [blame] | 349 | AddOptionalDefs( |
| 350 | BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, II, ResultReg) |
| 351 | .addReg(Op0, Op0IsKill * RegState::Kill) |
| 352 | .addReg(Op1, Op1IsKill * RegState::Kill) |
| 353 | .addReg(Op2, Op2IsKill * RegState::Kill)); |
Chad Rosier | 0bc5132 | 2012-02-15 17:36:21 +0000 | [diff] [blame] | 354 | } else { |
Rafael Espindola | ea09c59 | 2014-02-18 22:05:46 +0000 | [diff] [blame] | 355 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, II) |
Cameron Zwarich | 53dd03d | 2011-03-30 23:01:21 +0000 | [diff] [blame] | 356 | .addReg(Op0, Op0IsKill * RegState::Kill) |
| 357 | .addReg(Op1, Op1IsKill * RegState::Kill) |
| 358 | .addReg(Op2, Op2IsKill * RegState::Kill)); |
Rafael Espindola | ea09c59 | 2014-02-18 22:05:46 +0000 | [diff] [blame] | 359 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, |
Cameron Zwarich | 53dd03d | 2011-03-30 23:01:21 +0000 | [diff] [blame] | 360 | TII.get(TargetOpcode::COPY), ResultReg) |
| 361 | .addReg(II.ImplicitDefs[0])); |
| 362 | } |
| 363 | return ResultReg; |
| 364 | } |
| 365 | |
Juergen Ributzka | 88e3251 | 2014-09-03 20:56:59 +0000 | [diff] [blame] | 366 | unsigned ARMFastISel::fastEmitInst_ri(unsigned MachineInstOpcode, |
Eric Christopher | 09f757d | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 367 | const TargetRegisterClass *RC, |
| 368 | unsigned Op0, bool Op0IsKill, |
| 369 | uint64_t Imm) { |
| 370 | unsigned ResultReg = createResultReg(RC); |
Evan Cheng | 6cc775f | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 371 | const MCInstrDesc &II = TII.get(MachineInstOpcode); |
Eric Christopher | 09f757d | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 372 | |
Jim Grosbach | 06c2a68 | 2013-08-16 23:37:31 +0000 | [diff] [blame] | 373 | // Make sure the input operand is sufficiently constrained to be legal |
| 374 | // for this instruction. |
| 375 | Op0 = constrainOperandRegClass(II, Op0, 1); |
Chad Rosier | 0bc5132 | 2012-02-15 17:36:21 +0000 | [diff] [blame] | 376 | if (II.getNumDefs() >= 1) { |
Rafael Espindola | ea09c59 | 2014-02-18 22:05:46 +0000 | [diff] [blame] | 377 | AddOptionalDefs( |
| 378 | BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, II, ResultReg) |
| 379 | .addReg(Op0, Op0IsKill * RegState::Kill) |
| 380 | .addImm(Imm)); |
Chad Rosier | 0bc5132 | 2012-02-15 17:36:21 +0000 | [diff] [blame] | 381 | } else { |
Rafael Espindola | ea09c59 | 2014-02-18 22:05:46 +0000 | [diff] [blame] | 382 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, II) |
Eric Christopher | 09f757d | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 383 | .addReg(Op0, Op0IsKill * RegState::Kill) |
| 384 | .addImm(Imm)); |
Rafael Espindola | ea09c59 | 2014-02-18 22:05:46 +0000 | [diff] [blame] | 385 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, |
Eric Christopher | 09f757d | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 386 | TII.get(TargetOpcode::COPY), ResultReg) |
| 387 | .addReg(II.ImplicitDefs[0])); |
| 388 | } |
| 389 | return ResultReg; |
| 390 | } |
| 391 | |
Juergen Ributzka | 88e3251 | 2014-09-03 20:56:59 +0000 | [diff] [blame] | 392 | unsigned ARMFastISel::fastEmitInst_rri(unsigned MachineInstOpcode, |
Eric Christopher | 09f757d | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 393 | const TargetRegisterClass *RC, |
| 394 | unsigned Op0, bool Op0IsKill, |
| 395 | unsigned Op1, bool Op1IsKill, |
| 396 | uint64_t Imm) { |
| 397 | unsigned ResultReg = createResultReg(RC); |
Evan Cheng | 6cc775f | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 398 | const MCInstrDesc &II = TII.get(MachineInstOpcode); |
Eric Christopher | 09f757d | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 399 | |
Jim Grosbach | 06c2a68 | 2013-08-16 23:37:31 +0000 | [diff] [blame] | 400 | // Make sure the input operands are sufficiently constrained to be legal |
| 401 | // for this instruction. |
| 402 | Op0 = constrainOperandRegClass(II, Op0, 1); |
| 403 | Op1 = constrainOperandRegClass(II, Op1, 2); |
Chad Rosier | 0bc5132 | 2012-02-15 17:36:21 +0000 | [diff] [blame] | 404 | if (II.getNumDefs() >= 1) { |
Rafael Espindola | ea09c59 | 2014-02-18 22:05:46 +0000 | [diff] [blame] | 405 | AddOptionalDefs( |
| 406 | BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, II, ResultReg) |
| 407 | .addReg(Op0, Op0IsKill * RegState::Kill) |
| 408 | .addReg(Op1, Op1IsKill * RegState::Kill) |
| 409 | .addImm(Imm)); |
Chad Rosier | 0bc5132 | 2012-02-15 17:36:21 +0000 | [diff] [blame] | 410 | } else { |
Rafael Espindola | ea09c59 | 2014-02-18 22:05:46 +0000 | [diff] [blame] | 411 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, II) |
Eric Christopher | 09f757d | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 412 | .addReg(Op0, Op0IsKill * RegState::Kill) |
| 413 | .addReg(Op1, Op1IsKill * RegState::Kill) |
| 414 | .addImm(Imm)); |
Rafael Espindola | ea09c59 | 2014-02-18 22:05:46 +0000 | [diff] [blame] | 415 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, |
Eric Christopher | 09f757d | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 416 | TII.get(TargetOpcode::COPY), ResultReg) |
| 417 | .addReg(II.ImplicitDefs[0])); |
| 418 | } |
| 419 | return ResultReg; |
| 420 | } |
| 421 | |
Juergen Ributzka | 88e3251 | 2014-09-03 20:56:59 +0000 | [diff] [blame] | 422 | unsigned ARMFastISel::fastEmitInst_i(unsigned MachineInstOpcode, |
Eric Christopher | 09f757d | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 423 | const TargetRegisterClass *RC, |
| 424 | uint64_t Imm) { |
| 425 | unsigned ResultReg = createResultReg(RC); |
Evan Cheng | 6cc775f | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 426 | const MCInstrDesc &II = TII.get(MachineInstOpcode); |
Eric Christopher | 2ff757d | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 427 | |
Chad Rosier | 0bc5132 | 2012-02-15 17:36:21 +0000 | [diff] [blame] | 428 | if (II.getNumDefs() >= 1) { |
Rafael Espindola | ea09c59 | 2014-02-18 22:05:46 +0000 | [diff] [blame] | 429 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, II, |
| 430 | ResultReg).addImm(Imm)); |
Chad Rosier | 0bc5132 | 2012-02-15 17:36:21 +0000 | [diff] [blame] | 431 | } else { |
Rafael Espindola | ea09c59 | 2014-02-18 22:05:46 +0000 | [diff] [blame] | 432 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, II) |
Eric Christopher | 09f757d | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 433 | .addImm(Imm)); |
Rafael Espindola | ea09c59 | 2014-02-18 22:05:46 +0000 | [diff] [blame] | 434 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, |
Eric Christopher | 09f757d | 2010-08-17 01:25:29 +0000 | [diff] [blame] | 435 | TII.get(TargetOpcode::COPY), ResultReg) |
| 436 | .addReg(II.ImplicitDefs[0])); |
| 437 | } |
| 438 | return ResultReg; |
| 439 | } |
| 440 | |
Eric Christopher | 860fc93 | 2010-09-10 00:34:35 +0000 | [diff] [blame] | 441 | // TODO: Don't worry about 64-bit now, but when this is fixed remove the |
| 442 | // checks from the various callers. |
Patrik Hagglund | 5e6c361 | 2012-12-13 06:34:11 +0000 | [diff] [blame] | 443 | unsigned ARMFastISel::ARMMoveToFPReg(MVT VT, unsigned SrcReg) { |
Duncan Sands | 1462777 | 2010-11-03 12:17:33 +0000 | [diff] [blame] | 444 | if (VT == MVT::f64) return 0; |
Eric Christopher | 7ac602b | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 445 | |
Eric Christopher | 4bd7047 | 2010-09-09 21:44:45 +0000 | [diff] [blame] | 446 | unsigned MoveReg = createResultReg(TLI.getRegClassFor(VT)); |
Rafael Espindola | ea09c59 | 2014-02-18 22:05:46 +0000 | [diff] [blame] | 447 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, |
Jim Grosbach | 6990e5f | 2012-03-01 22:47:09 +0000 | [diff] [blame] | 448 | TII.get(ARM::VMOVSR), MoveReg) |
Eric Christopher | 4bd7047 | 2010-09-09 21:44:45 +0000 | [diff] [blame] | 449 | .addReg(SrcReg)); |
| 450 | return MoveReg; |
| 451 | } |
| 452 | |
Patrik Hagglund | 5e6c361 | 2012-12-13 06:34:11 +0000 | [diff] [blame] | 453 | unsigned ARMFastISel::ARMMoveToIntReg(MVT VT, unsigned SrcReg) { |
Duncan Sands | 1462777 | 2010-11-03 12:17:33 +0000 | [diff] [blame] | 454 | if (VT == MVT::i64) return 0; |
Eric Christopher | 7ac602b | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 455 | |
Eric Christopher | 2cbe0fd | 2010-09-09 20:49:25 +0000 | [diff] [blame] | 456 | unsigned MoveReg = createResultReg(TLI.getRegClassFor(VT)); |
Rafael Espindola | ea09c59 | 2014-02-18 22:05:46 +0000 | [diff] [blame] | 457 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, |
Jim Grosbach | 6990e5f | 2012-03-01 22:47:09 +0000 | [diff] [blame] | 458 | TII.get(ARM::VMOVRS), MoveReg) |
Eric Christopher | 2cbe0fd | 2010-09-09 20:49:25 +0000 | [diff] [blame] | 459 | .addReg(SrcReg)); |
| 460 | return MoveReg; |
| 461 | } |
| 462 | |
Eric Christopher | 3cf63f1 | 2010-09-09 00:19:41 +0000 | [diff] [blame] | 463 | // For double width floating point we need to materialize two constants |
| 464 | // (the high and the low) into integer registers then use a move to get |
| 465 | // the combined constant into an FP reg. |
Patrik Hagglund | 5e6c361 | 2012-12-13 06:34:11 +0000 | [diff] [blame] | 466 | unsigned ARMFastISel::ARMMaterializeFP(const ConstantFP *CFP, MVT VT) { |
Eric Christopher | 3cf63f1 | 2010-09-09 00:19:41 +0000 | [diff] [blame] | 467 | const APFloat Val = CFP->getValueAPF(); |
Duncan Sands | 1462777 | 2010-11-03 12:17:33 +0000 | [diff] [blame] | 468 | bool is64bit = VT == MVT::f64; |
Eric Christopher | 2ff757d | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 469 | |
Eric Christopher | 3cf63f1 | 2010-09-09 00:19:41 +0000 | [diff] [blame] | 470 | // This checks to see if we can use VFP3 instructions to materialize |
| 471 | // a constant, otherwise we have to go through the constant pool. |
| 472 | if (TLI.isFPImmLegal(Val, VT)) { |
Jim Grosbach | efc761a | 2011-09-30 00:50:06 +0000 | [diff] [blame] | 473 | int Imm; |
| 474 | unsigned Opc; |
| 475 | if (is64bit) { |
| 476 | Imm = ARM_AM::getFP64Imm(Val); |
| 477 | Opc = ARM::FCONSTD; |
| 478 | } else { |
| 479 | Imm = ARM_AM::getFP32Imm(Val); |
| 480 | Opc = ARM::FCONSTS; |
| 481 | } |
Eric Christopher | 3cf63f1 | 2010-09-09 00:19:41 +0000 | [diff] [blame] | 482 | unsigned DestReg = createResultReg(TLI.getRegClassFor(VT)); |
Rafael Espindola | ea09c59 | 2014-02-18 22:05:46 +0000 | [diff] [blame] | 483 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, |
| 484 | TII.get(Opc), DestReg).addImm(Imm)); |
Eric Christopher | 3cf63f1 | 2010-09-09 00:19:41 +0000 | [diff] [blame] | 485 | return DestReg; |
| 486 | } |
Eric Christopher | 7ac602b | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 487 | |
Eric Christopher | 860fc93 | 2010-09-10 00:34:35 +0000 | [diff] [blame] | 488 | // Require VFP2 for loading fp constants. |
Eric Christopher | 22fd29a | 2010-09-09 23:50:00 +0000 | [diff] [blame] | 489 | if (!Subtarget->hasVFP2()) return false; |
Eric Christopher | 7ac602b | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 490 | |
Eric Christopher | 22fd29a | 2010-09-09 23:50:00 +0000 | [diff] [blame] | 491 | // MachineConstantPool wants an explicit alignment. |
Rafael Espindola | ea09c59 | 2014-02-18 22:05:46 +0000 | [diff] [blame] | 492 | unsigned Align = DL.getPrefTypeAlignment(CFP->getType()); |
Eric Christopher | 22fd29a | 2010-09-09 23:50:00 +0000 | [diff] [blame] | 493 | if (Align == 0) { |
| 494 | // TODO: Figure out if this is correct. |
Rafael Espindola | ea09c59 | 2014-02-18 22:05:46 +0000 | [diff] [blame] | 495 | Align = DL.getTypeAllocSize(CFP->getType()); |
Eric Christopher | 22fd29a | 2010-09-09 23:50:00 +0000 | [diff] [blame] | 496 | } |
| 497 | unsigned Idx = MCP.getConstantPoolIndex(cast<Constant>(CFP), Align); |
| 498 | unsigned DestReg = createResultReg(TLI.getRegClassFor(VT)); |
| 499 | unsigned Opc = is64bit ? ARM::VLDRD : ARM::VLDRS; |
Eric Christopher | 7ac602b | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 500 | |
Eric Christopher | 860fc93 | 2010-09-10 00:34:35 +0000 | [diff] [blame] | 501 | // The extra reg is for addrmode5. |
Rafael Espindola | ea09c59 | 2014-02-18 22:05:46 +0000 | [diff] [blame] | 502 | AddOptionalDefs( |
| 503 | BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, TII.get(Opc), DestReg) |
| 504 | .addConstantPoolIndex(Idx) |
| 505 | .addReg(0)); |
Eric Christopher | 22fd29a | 2010-09-09 23:50:00 +0000 | [diff] [blame] | 506 | return DestReg; |
Eric Christopher | 3cf63f1 | 2010-09-09 00:19:41 +0000 | [diff] [blame] | 507 | } |
| 508 | |
Patrik Hagglund | 5e6c361 | 2012-12-13 06:34:11 +0000 | [diff] [blame] | 509 | unsigned ARMFastISel::ARMMaterializeInt(const Constant *C, MVT VT) { |
Eric Christopher | 7ac602b | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 510 | |
Chad Rosier | 67f9688 | 2011-11-04 22:29:00 +0000 | [diff] [blame] | 511 | if (VT != MVT::i32 && VT != MVT::i16 && VT != MVT::i8 && VT != MVT::i1) |
Juergen Ributzka | 5df8603df | 2014-08-15 16:59:46 +0000 | [diff] [blame] | 512 | return 0; |
Eric Christopher | e4dd737 | 2010-11-03 20:21:17 +0000 | [diff] [blame] | 513 | |
| 514 | // If we can do this in a single instruction without a constant pool entry |
| 515 | // do so now. |
| 516 | const ConstantInt *CI = cast<ConstantInt>(C); |
Chad Rosier | e8b8b77 | 2011-11-04 23:09:49 +0000 | [diff] [blame] | 517 | if (Subtarget->hasV6T2Ops() && isUInt<16>(CI->getZExtValue())) { |
Chad Rosier | 0439cfc | 2011-11-08 21:12:00 +0000 | [diff] [blame] | 518 | unsigned Opc = isThumb2 ? ARM::t2MOVi16 : ARM::MOVi16; |
Chad Rosier | 2e82ad1 | 2012-11-27 01:06:49 +0000 | [diff] [blame] | 519 | const TargetRegisterClass *RC = isThumb2 ? &ARM::rGPRRegClass : |
| 520 | &ARM::GPRRegClass; |
| 521 | unsigned ImmReg = createResultReg(RC); |
Rafael Espindola | ea09c59 | 2014-02-18 22:05:46 +0000 | [diff] [blame] | 522 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, |
Chad Rosier | 67f9688 | 2011-11-04 22:29:00 +0000 | [diff] [blame] | 523 | TII.get(Opc), ImmReg) |
Chad Rosier | d0191a5 | 2011-11-05 20:16:15 +0000 | [diff] [blame] | 524 | .addImm(CI->getZExtValue())); |
Chad Rosier | 67f9688 | 2011-11-04 22:29:00 +0000 | [diff] [blame] | 525 | return ImmReg; |
Eric Christopher | e4dd737 | 2010-11-03 20:21:17 +0000 | [diff] [blame] | 526 | } |
| 527 | |
Chad Rosier | 2a3503e | 2011-11-11 00:36:21 +0000 | [diff] [blame] | 528 | // Use MVN to emit negative constants. |
| 529 | if (VT == MVT::i32 && Subtarget->hasV6T2Ops() && CI->isNegative()) { |
| 530 | unsigned Imm = (unsigned)~(CI->getSExtValue()); |
Chad Rosier | e19b0a9 | 2011-11-11 06:27:41 +0000 | [diff] [blame] | 531 | bool UseImm = isThumb2 ? (ARM_AM::getT2SOImmVal(Imm) != -1) : |
Chad Rosier | 2a3503e | 2011-11-11 00:36:21 +0000 | [diff] [blame] | 532 | (ARM_AM::getSOImmVal(Imm) != -1); |
Chad Rosier | e19b0a9 | 2011-11-11 06:27:41 +0000 | [diff] [blame] | 533 | if (UseImm) { |
Chad Rosier | 2a3503e | 2011-11-11 00:36:21 +0000 | [diff] [blame] | 534 | unsigned Opc = isThumb2 ? ARM::t2MVNi : ARM::MVNi; |
Juergen Ributzka | 2cbcf7a | 2014-08-13 21:39:18 +0000 | [diff] [blame] | 535 | const TargetRegisterClass *RC = isThumb2 ? &ARM::rGPRRegClass : |
| 536 | &ARM::GPRRegClass; |
| 537 | unsigned ImmReg = createResultReg(RC); |
Rafael Espindola | ea09c59 | 2014-02-18 22:05:46 +0000 | [diff] [blame] | 538 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, |
Chad Rosier | 2a3503e | 2011-11-11 00:36:21 +0000 | [diff] [blame] | 539 | TII.get(Opc), ImmReg) |
| 540 | .addImm(Imm)); |
| 541 | return ImmReg; |
| 542 | } |
| 543 | } |
| 544 | |
Juergen Ributzka | 5df8603df | 2014-08-15 16:59:46 +0000 | [diff] [blame] | 545 | unsigned ResultReg = 0; |
Juergen Ributzka | a5b0838 | 2014-08-13 21:42:19 +0000 | [diff] [blame] | 546 | if (Subtarget->useMovt(*FuncInfo.MF)) |
Juergen Ributzka | 88e3251 | 2014-09-03 20:56:59 +0000 | [diff] [blame] | 547 | ResultReg = fastEmit_i(VT, VT, ISD::Constant, CI->getZExtValue()); |
Juergen Ributzka | 5df8603df | 2014-08-15 16:59:46 +0000 | [diff] [blame] | 548 | |
| 549 | if (ResultReg) |
| 550 | return ResultReg; |
Juergen Ributzka | a5b0838 | 2014-08-13 21:42:19 +0000 | [diff] [blame] | 551 | |
Chad Rosier | 2a3503e | 2011-11-11 00:36:21 +0000 | [diff] [blame] | 552 | // Load from constant pool. For now 32-bit only. |
Chad Rosier | 67f9688 | 2011-11-04 22:29:00 +0000 | [diff] [blame] | 553 | if (VT != MVT::i32) |
Juergen Ributzka | 5df8603df | 2014-08-15 16:59:46 +0000 | [diff] [blame] | 554 | return 0; |
Chad Rosier | 67f9688 | 2011-11-04 22:29:00 +0000 | [diff] [blame] | 555 | |
Eric Christopher | c3e118e | 2010-09-02 23:43:26 +0000 | [diff] [blame] | 556 | // MachineConstantPool wants an explicit alignment. |
Rafael Espindola | ea09c59 | 2014-02-18 22:05:46 +0000 | [diff] [blame] | 557 | unsigned Align = DL.getPrefTypeAlignment(C->getType()); |
Eric Christopher | c3e118e | 2010-09-02 23:43:26 +0000 | [diff] [blame] | 558 | if (Align == 0) { |
| 559 | // TODO: Figure out if this is correct. |
Rafael Espindola | ea09c59 | 2014-02-18 22:05:46 +0000 | [diff] [blame] | 560 | Align = DL.getTypeAllocSize(C->getType()); |
Eric Christopher | c3e118e | 2010-09-02 23:43:26 +0000 | [diff] [blame] | 561 | } |
| 562 | unsigned Idx = MCP.getConstantPoolIndex(C, Align); |
Juergen Ributzka | 5df8603df | 2014-08-15 16:59:46 +0000 | [diff] [blame] | 563 | ResultReg = createResultReg(TLI.getRegClassFor(VT)); |
Chad Rosier | 0439cfc | 2011-11-08 21:12:00 +0000 | [diff] [blame] | 564 | if (isThumb2) |
Rafael Espindola | ea09c59 | 2014-02-18 22:05:46 +0000 | [diff] [blame] | 565 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, |
Juergen Ributzka | 5df8603df | 2014-08-15 16:59:46 +0000 | [diff] [blame] | 566 | TII.get(ARM::t2LDRpci), ResultReg) |
| 567 | .addConstantPoolIndex(Idx)); |
Tim Northover | e42fb07 | 2014-02-04 10:38:46 +0000 | [diff] [blame] | 568 | else { |
Eric Christopher | 22d0492 | 2010-11-12 09:48:30 +0000 | [diff] [blame] | 569 | // The extra immediate is for addrmode2. |
Juergen Ributzka | 5df8603df | 2014-08-15 16:59:46 +0000 | [diff] [blame] | 570 | ResultReg = constrainOperandRegClass(TII.get(ARM::LDRcp), ResultReg, 0); |
Rafael Espindola | ea09c59 | 2014-02-18 22:05:46 +0000 | [diff] [blame] | 571 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, |
Juergen Ributzka | 5df8603df | 2014-08-15 16:59:46 +0000 | [diff] [blame] | 572 | TII.get(ARM::LDRcp), ResultReg) |
| 573 | .addConstantPoolIndex(Idx) |
| 574 | .addImm(0)); |
Tim Northover | e42fb07 | 2014-02-04 10:38:46 +0000 | [diff] [blame] | 575 | } |
Juergen Ributzka | 5df8603df | 2014-08-15 16:59:46 +0000 | [diff] [blame] | 576 | return ResultReg; |
Eric Christopher | 92db201 | 2010-09-02 01:48:11 +0000 | [diff] [blame] | 577 | } |
| 578 | |
Patrik Hagglund | 5e6c361 | 2012-12-13 06:34:11 +0000 | [diff] [blame] | 579 | unsigned ARMFastISel::ARMMaterializeGV(const GlobalValue *GV, MVT VT) { |
Eric Christopher | 7787f79 | 2010-10-02 00:32:44 +0000 | [diff] [blame] | 580 | // For now 32-bit only. |
Duncan Sands | 1462777 | 2010-11-03 12:17:33 +0000 | [diff] [blame] | 581 | if (VT != MVT::i32) return 0; |
Eric Christopher | 7ac602b | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 582 | |
Eric Christopher | 7787f79 | 2010-10-02 00:32:44 +0000 | [diff] [blame] | 583 | Reloc::Model RelocM = TM.getRelocationModel(); |
Jush Lu | e87e559 | 2012-08-29 02:41:21 +0000 | [diff] [blame] | 584 | bool IsIndirect = Subtarget->GVIsIndirectSymbol(GV, RelocM); |
Craig Topper | 61e88f4 | 2014-11-21 05:58:21 +0000 | [diff] [blame] | 585 | const TargetRegisterClass *RC = isThumb2 ? &ARM::rGPRRegClass |
| 586 | : &ARM::GPRRegClass; |
Chad Rosier | 65710a7 | 2012-11-07 00:13:01 +0000 | [diff] [blame] | 587 | unsigned DestReg = createResultReg(RC); |
Jakob Stoklund Olesen | 68f034e | 2012-01-07 01:47:05 +0000 | [diff] [blame] | 588 | |
Tim Northover | d6a729b | 2014-01-06 14:28:05 +0000 | [diff] [blame] | 589 | // FastISel TLS support on non-MachO is broken, punt to SelectionDAG. |
JF Bastien | 18db1f2 | 2013-06-14 02:49:43 +0000 | [diff] [blame] | 590 | const GlobalVariable *GVar = dyn_cast<GlobalVariable>(GV); |
| 591 | bool IsThreadLocal = GVar && GVar->isThreadLocal(); |
Tim Northover | d6a729b | 2014-01-06 14:28:05 +0000 | [diff] [blame] | 592 | if (!Subtarget->isTargetMachO() && IsThreadLocal) return 0; |
JF Bastien | 18db1f2 | 2013-06-14 02:49:43 +0000 | [diff] [blame] | 593 | |
Jakob Stoklund Olesen | 68f034e | 2012-01-07 01:47:05 +0000 | [diff] [blame] | 594 | // Use movw+movt when possible, it avoids constant pool entries. |
Tim Northover | fa36dfe | 2013-11-26 12:45:05 +0000 | [diff] [blame] | 595 | // Non-darwin targets only support static movt relocations in FastISel. |
Eric Christopher | c1058df | 2014-07-04 01:55:26 +0000 | [diff] [blame] | 596 | if (Subtarget->useMovt(*FuncInfo.MF) && |
Tim Northover | d6a729b | 2014-01-06 14:28:05 +0000 | [diff] [blame] | 597 | (Subtarget->isTargetMachO() || RelocM == Reloc::Static)) { |
Jakob Stoklund Olesen | 68f034e | 2012-01-07 01:47:05 +0000 | [diff] [blame] | 598 | unsigned Opc; |
Tim Northover | db962e2c | 2013-11-25 16:24:52 +0000 | [diff] [blame] | 599 | unsigned char TF = 0; |
Tim Northover | d6a729b | 2014-01-06 14:28:05 +0000 | [diff] [blame] | 600 | if (Subtarget->isTargetMachO()) |
Tim Northover | db962e2c | 2013-11-25 16:24:52 +0000 | [diff] [blame] | 601 | TF = ARMII::MO_NONLAZY; |
| 602 | |
Jakob Stoklund Olesen | 68f034e | 2012-01-07 01:47:05 +0000 | [diff] [blame] | 603 | switch (RelocM) { |
| 604 | case Reloc::PIC_: |
| 605 | Opc = isThumb2 ? ARM::t2MOV_ga_pcrel : ARM::MOV_ga_pcrel; |
| 606 | break; |
Jakob Stoklund Olesen | 68f034e | 2012-01-07 01:47:05 +0000 | [diff] [blame] | 607 | default: |
| 608 | Opc = isThumb2 ? ARM::t2MOVi32imm : ARM::MOVi32imm; |
| 609 | break; |
| 610 | } |
Rafael Espindola | ea09c59 | 2014-02-18 22:05:46 +0000 | [diff] [blame] | 611 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, |
| 612 | TII.get(Opc), DestReg).addGlobalAddress(GV, 0, TF)); |
Eric Christopher | 7787f79 | 2010-10-02 00:32:44 +0000 | [diff] [blame] | 613 | } else { |
Jakob Stoklund Olesen | 68f034e | 2012-01-07 01:47:05 +0000 | [diff] [blame] | 614 | // MachineConstantPool wants an explicit alignment. |
Rafael Espindola | ea09c59 | 2014-02-18 22:05:46 +0000 | [diff] [blame] | 615 | unsigned Align = DL.getPrefTypeAlignment(GV->getType()); |
Jakob Stoklund Olesen | 68f034e | 2012-01-07 01:47:05 +0000 | [diff] [blame] | 616 | if (Align == 0) { |
| 617 | // TODO: Figure out if this is correct. |
Rafael Espindola | ea09c59 | 2014-02-18 22:05:46 +0000 | [diff] [blame] | 618 | Align = DL.getTypeAllocSize(GV->getType()); |
Jakob Stoklund Olesen | 68f034e | 2012-01-07 01:47:05 +0000 | [diff] [blame] | 619 | } |
| 620 | |
Jush Lu | 47172a0 | 2012-09-27 05:21:41 +0000 | [diff] [blame] | 621 | if (Subtarget->isTargetELF() && RelocM == Reloc::PIC_) |
| 622 | return ARMLowerPICELF(GV, Align, VT); |
| 623 | |
Jakob Stoklund Olesen | 68f034e | 2012-01-07 01:47:05 +0000 | [diff] [blame] | 624 | // Grab index. |
| 625 | unsigned PCAdj = (RelocM != Reloc::PIC_) ? 0 : |
| 626 | (Subtarget->isThumb() ? 4 : 8); |
| 627 | unsigned Id = AFI->createPICLabelUId(); |
| 628 | ARMConstantPoolValue *CPV = ARMConstantPoolConstant::Create(GV, Id, |
| 629 | ARMCP::CPValue, |
| 630 | PCAdj); |
| 631 | unsigned Idx = MCP.getConstantPoolIndex(CPV, Align); |
| 632 | |
| 633 | // Load value. |
| 634 | MachineInstrBuilder MIB; |
| 635 | if (isThumb2) { |
| 636 | unsigned Opc = (RelocM!=Reloc::PIC_) ? ARM::t2LDRpci : ARM::t2LDRpci_pic; |
Rafael Espindola | ea09c59 | 2014-02-18 22:05:46 +0000 | [diff] [blame] | 637 | MIB = BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, TII.get(Opc), |
| 638 | DestReg).addConstantPoolIndex(Idx); |
Jakob Stoklund Olesen | 68f034e | 2012-01-07 01:47:05 +0000 | [diff] [blame] | 639 | if (RelocM == Reloc::PIC_) |
| 640 | MIB.addImm(Id); |
Jush Lu | e87e559 | 2012-08-29 02:41:21 +0000 | [diff] [blame] | 641 | AddOptionalDefs(MIB); |
Jakob Stoklund Olesen | 68f034e | 2012-01-07 01:47:05 +0000 | [diff] [blame] | 642 | } else { |
| 643 | // The extra immediate is for addrmode2. |
Jim Grosbach | 5f71aab | 2013-08-26 20:07:29 +0000 | [diff] [blame] | 644 | DestReg = constrainOperandRegClass(TII.get(ARM::LDRcp), DestReg, 0); |
Rafael Espindola | ea09c59 | 2014-02-18 22:05:46 +0000 | [diff] [blame] | 645 | MIB = BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, |
| 646 | TII.get(ARM::LDRcp), DestReg) |
| 647 | .addConstantPoolIndex(Idx) |
| 648 | .addImm(0); |
Jush Lu | e87e559 | 2012-08-29 02:41:21 +0000 | [diff] [blame] | 649 | AddOptionalDefs(MIB); |
| 650 | |
| 651 | if (RelocM == Reloc::PIC_) { |
| 652 | unsigned Opc = IsIndirect ? ARM::PICLDR : ARM::PICADD; |
| 653 | unsigned NewDestReg = createResultReg(TLI.getRegClassFor(VT)); |
| 654 | |
| 655 | MachineInstrBuilder MIB = BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, |
Rafael Espindola | ea09c59 | 2014-02-18 22:05:46 +0000 | [diff] [blame] | 656 | DbgLoc, TII.get(Opc), NewDestReg) |
Jush Lu | e87e559 | 2012-08-29 02:41:21 +0000 | [diff] [blame] | 657 | .addReg(DestReg) |
| 658 | .addImm(Id); |
| 659 | AddOptionalDefs(MIB); |
| 660 | return NewDestReg; |
| 661 | } |
Jakob Stoklund Olesen | 68f034e | 2012-01-07 01:47:05 +0000 | [diff] [blame] | 662 | } |
Eric Christopher | 7787f79 | 2010-10-02 00:32:44 +0000 | [diff] [blame] | 663 | } |
Eli Friedman | 8658579 | 2011-06-03 01:13:19 +0000 | [diff] [blame] | 664 | |
Jush Lu | e87e559 | 2012-08-29 02:41:21 +0000 | [diff] [blame] | 665 | if (IsIndirect) { |
Jakob Stoklund Olesen | 68f034e | 2012-01-07 01:47:05 +0000 | [diff] [blame] | 666 | MachineInstrBuilder MIB; |
Eli Friedman | 8658579 | 2011-06-03 01:13:19 +0000 | [diff] [blame] | 667 | unsigned NewDestReg = createResultReg(TLI.getRegClassFor(VT)); |
Chad Rosier | 0439cfc | 2011-11-08 21:12:00 +0000 | [diff] [blame] | 668 | if (isThumb2) |
Rafael Espindola | ea09c59 | 2014-02-18 22:05:46 +0000 | [diff] [blame] | 669 | MIB = BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, |
Jim Grosbach | e7e2aca | 2011-09-13 20:30:37 +0000 | [diff] [blame] | 670 | TII.get(ARM::t2LDRi12), NewDestReg) |
Eli Friedman | 8658579 | 2011-06-03 01:13:19 +0000 | [diff] [blame] | 671 | .addReg(DestReg) |
| 672 | .addImm(0); |
| 673 | else |
Rafael Espindola | ea09c59 | 2014-02-18 22:05:46 +0000 | [diff] [blame] | 674 | MIB = BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, |
| 675 | TII.get(ARM::LDRi12), NewDestReg) |
| 676 | .addReg(DestReg) |
| 677 | .addImm(0); |
Eli Friedman | 8658579 | 2011-06-03 01:13:19 +0000 | [diff] [blame] | 678 | DestReg = NewDestReg; |
| 679 | AddOptionalDefs(MIB); |
| 680 | } |
| 681 | |
Eric Christopher | 7787f79 | 2010-10-02 00:32:44 +0000 | [diff] [blame] | 682 | return DestReg; |
Eric Christopher | 83a5ec8 | 2010-10-01 23:24:42 +0000 | [diff] [blame] | 683 | } |
| 684 | |
Juergen Ributzka | 5b8bb4d | 2014-09-03 20:56:52 +0000 | [diff] [blame] | 685 | unsigned ARMFastISel::fastMaterializeConstant(const Constant *C) { |
Patrik Hagglund | c494d24 | 2012-12-17 14:30:06 +0000 | [diff] [blame] | 686 | EVT CEVT = TLI.getValueType(C->getType(), true); |
| 687 | |
| 688 | // Only handle simple types. |
| 689 | if (!CEVT.isSimple()) return 0; |
| 690 | MVT VT = CEVT.getSimpleVT(); |
Eric Christopher | 3cf63f1 | 2010-09-09 00:19:41 +0000 | [diff] [blame] | 691 | |
| 692 | if (const ConstantFP *CFP = dyn_cast<ConstantFP>(C)) |
| 693 | return ARMMaterializeFP(CFP, VT); |
Eric Christopher | 83a5ec8 | 2010-10-01 23:24:42 +0000 | [diff] [blame] | 694 | else if (const GlobalValue *GV = dyn_cast<GlobalValue>(C)) |
| 695 | return ARMMaterializeGV(GV, VT); |
| 696 | else if (isa<ConstantInt>(C)) |
| 697 | return ARMMaterializeInt(C, VT); |
Eric Christopher | 7ac602b | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 698 | |
Eric Christopher | 83a5ec8 | 2010-10-01 23:24:42 +0000 | [diff] [blame] | 699 | return 0; |
Eric Christopher | 3cf63f1 | 2010-09-09 00:19:41 +0000 | [diff] [blame] | 700 | } |
| 701 | |
Chad Rosier | 0eff3e5 | 2011-11-17 21:46:13 +0000 | [diff] [blame] | 702 | // TODO: unsigned ARMFastISel::TargetMaterializeFloatZero(const ConstantFP *CF); |
| 703 | |
Juergen Ributzka | 5b8bb4d | 2014-09-03 20:56:52 +0000 | [diff] [blame] | 704 | unsigned ARMFastISel::fastMaterializeAlloca(const AllocaInst *AI) { |
Eric Christopher | 78f8d4e | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 705 | // Don't handle dynamic allocas. |
| 706 | if (!FuncInfo.StaticAllocaMap.count(AI)) return 0; |
Eric Christopher | 7ac602b | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 707 | |
Duncan Sands | f5dda01 | 2010-11-03 11:35:31 +0000 | [diff] [blame] | 708 | MVT VT; |
Chad Rosier | 466d3d8 | 2012-05-11 16:41:38 +0000 | [diff] [blame] | 709 | if (!isLoadTypeLegal(AI->getType(), VT)) return 0; |
Eric Christopher | 7ac602b | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 710 | |
Eric Christopher | 78f8d4e | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 711 | DenseMap<const AllocaInst*, int>::iterator SI = |
| 712 | FuncInfo.StaticAllocaMap.find(AI); |
| 713 | |
| 714 | // This will get lowered later into the correct offsets and registers |
| 715 | // via rewriteXFrameIndex. |
| 716 | if (SI != FuncInfo.StaticAllocaMap.end()) { |
Tim Northover | 76fc8a4 | 2013-12-11 16:04:57 +0000 | [diff] [blame] | 717 | unsigned Opc = isThumb2 ? ARM::t2ADDri : ARM::ADDri; |
Craig Topper | 760b134 | 2012-02-22 05:59:10 +0000 | [diff] [blame] | 718 | const TargetRegisterClass* RC = TLI.getRegClassFor(VT); |
Eric Christopher | 78f8d4e | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 719 | unsigned ResultReg = createResultReg(RC); |
Tim Northover | 76fc8a4 | 2013-12-11 16:04:57 +0000 | [diff] [blame] | 720 | ResultReg = constrainOperandRegClass(TII.get(Opc), ResultReg, 0); |
| 721 | |
Rafael Espindola | ea09c59 | 2014-02-18 22:05:46 +0000 | [diff] [blame] | 722 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, |
Eric Christopher | 78f8d4e | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 723 | TII.get(Opc), ResultReg) |
| 724 | .addFrameIndex(SI->second) |
| 725 | .addImm(0)); |
| 726 | return ResultReg; |
| 727 | } |
Eric Christopher | 7ac602b | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 728 | |
Eric Christopher | 78f8d4e | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 729 | return 0; |
| 730 | } |
| 731 | |
Chris Lattner | 229907c | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 732 | bool ARMFastISel::isTypeLegal(Type *Ty, MVT &VT) { |
Duncan Sands | f5dda01 | 2010-11-03 11:35:31 +0000 | [diff] [blame] | 733 | EVT evt = TLI.getValueType(Ty, true); |
Eric Christopher | 2ff757d | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 734 | |
Eric Christopher | 761e7fb | 2010-08-25 07:23:49 +0000 | [diff] [blame] | 735 | // Only handle simple types. |
Duncan Sands | f5dda01 | 2010-11-03 11:35:31 +0000 | [diff] [blame] | 736 | if (evt == MVT::Other || !evt.isSimple()) return false; |
| 737 | VT = evt.getSimpleVT(); |
Eric Christopher | 2ff757d | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 738 | |
Eric Christopher | 901176a | 2010-08-31 01:28:42 +0000 | [diff] [blame] | 739 | // Handle all legal types, i.e. a register that will directly hold this |
| 740 | // value. |
| 741 | return TLI.isTypeLegal(VT); |
Eric Christopher | 761e7fb | 2010-08-25 07:23:49 +0000 | [diff] [blame] | 742 | } |
| 743 | |
Chris Lattner | 229907c | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 744 | bool ARMFastISel::isLoadTypeLegal(Type *Ty, MVT &VT) { |
Eric Christopher | 3ce9c4a | 2010-09-01 18:01:32 +0000 | [diff] [blame] | 745 | if (isTypeLegal(Ty, VT)) return true; |
Eric Christopher | 2ff757d | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 746 | |
Eric Christopher | 3ce9c4a | 2010-09-01 18:01:32 +0000 | [diff] [blame] | 747 | // If this is a type than can be sign or zero-extended to a basic operation |
| 748 | // go ahead and accept it now. |
Chad Rosier | c8cfd3a | 2011-11-13 02:23:59 +0000 | [diff] [blame] | 749 | if (VT == MVT::i1 || VT == MVT::i8 || VT == MVT::i16) |
Eric Christopher | 3ce9c4a | 2010-09-01 18:01:32 +0000 | [diff] [blame] | 750 | return true; |
Eric Christopher | 2ff757d | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 751 | |
Eric Christopher | 3ce9c4a | 2010-09-01 18:01:32 +0000 | [diff] [blame] | 752 | return false; |
| 753 | } |
| 754 | |
Eric Christopher | 558b61e | 2010-11-19 22:36:41 +0000 | [diff] [blame] | 755 | // Computes the address to get to an object. |
Eric Christopher | fef5f31 | 2010-11-19 22:30:02 +0000 | [diff] [blame] | 756 | bool ARMFastISel::ARMComputeAddress(const Value *Obj, Address &Addr) { |
Eric Christopher | 00202ee | 2010-08-23 21:44:12 +0000 | [diff] [blame] | 757 | // Some boilerplate from the X86 FastISel. |
Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 758 | const User *U = nullptr; |
Eric Christopher | 00202ee | 2010-08-23 21:44:12 +0000 | [diff] [blame] | 759 | unsigned Opcode = Instruction::UserOp1; |
Eric Christopher | 9d4e471 | 2010-08-24 00:07:24 +0000 | [diff] [blame] | 760 | if (const Instruction *I = dyn_cast<Instruction>(Obj)) { |
Eric Christopher | cee83d6 | 2010-11-19 22:37:58 +0000 | [diff] [blame] | 761 | // Don't walk into other basic blocks unless the object is an alloca from |
| 762 | // another block, otherwise it may not have a virtual register assigned. |
Eric Christopher | 9649437 | 2010-11-15 21:11:06 +0000 | [diff] [blame] | 763 | if (FuncInfo.StaticAllocaMap.count(static_cast<const AllocaInst *>(Obj)) || |
| 764 | FuncInfo.MBBMap[I->getParent()] == FuncInfo.MBB) { |
| 765 | Opcode = I->getOpcode(); |
| 766 | U = I; |
| 767 | } |
Eric Christopher | 9d4e471 | 2010-08-24 00:07:24 +0000 | [diff] [blame] | 768 | } else if (const ConstantExpr *C = dyn_cast<ConstantExpr>(Obj)) { |
Eric Christopher | 00202ee | 2010-08-23 21:44:12 +0000 | [diff] [blame] | 769 | Opcode = C->getOpcode(); |
| 770 | U = C; |
| 771 | } |
| 772 | |
Chris Lattner | 229907c | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 773 | if (PointerType *Ty = dyn_cast<PointerType>(Obj->getType())) |
Eric Christopher | 00202ee | 2010-08-23 21:44:12 +0000 | [diff] [blame] | 774 | if (Ty->getAddressSpace() > 255) |
| 775 | // Fast instruction selection doesn't support the special |
| 776 | // address spaces. |
| 777 | return false; |
Eric Christopher | 2ff757d | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 778 | |
Eric Christopher | 00202ee | 2010-08-23 21:44:12 +0000 | [diff] [blame] | 779 | switch (Opcode) { |
Eric Christopher | 2ff757d | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 780 | default: |
Eric Christopher | 00202ee | 2010-08-23 21:44:12 +0000 | [diff] [blame] | 781 | break; |
Eric Christopher | 3931cf9 | 2013-07-12 22:08:24 +0000 | [diff] [blame] | 782 | case Instruction::BitCast: |
Eric Christopher | db3bcc9 | 2010-10-12 00:43:21 +0000 | [diff] [blame] | 783 | // Look through bitcasts. |
Eric Christopher | fef5f31 | 2010-11-19 22:30:02 +0000 | [diff] [blame] | 784 | return ARMComputeAddress(U->getOperand(0), Addr); |
Eric Christopher | 3931cf9 | 2013-07-12 22:08:24 +0000 | [diff] [blame] | 785 | case Instruction::IntToPtr: |
Eric Christopher | db3bcc9 | 2010-10-12 00:43:21 +0000 | [diff] [blame] | 786 | // Look past no-op inttoptrs. |
| 787 | if (TLI.getValueType(U->getOperand(0)->getType()) == TLI.getPointerTy()) |
Eric Christopher | fef5f31 | 2010-11-19 22:30:02 +0000 | [diff] [blame] | 788 | return ARMComputeAddress(U->getOperand(0), Addr); |
Eric Christopher | db3bcc9 | 2010-10-12 00:43:21 +0000 | [diff] [blame] | 789 | break; |
Eric Christopher | 3931cf9 | 2013-07-12 22:08:24 +0000 | [diff] [blame] | 790 | case Instruction::PtrToInt: |
Eric Christopher | db3bcc9 | 2010-10-12 00:43:21 +0000 | [diff] [blame] | 791 | // Look past no-op ptrtoints. |
| 792 | if (TLI.getValueType(U->getType()) == TLI.getPointerTy()) |
Eric Christopher | fef5f31 | 2010-11-19 22:30:02 +0000 | [diff] [blame] | 793 | return ARMComputeAddress(U->getOperand(0), Addr); |
Eric Christopher | db3bcc9 | 2010-10-12 00:43:21 +0000 | [diff] [blame] | 794 | break; |
Eric Christopher | 21d0c17 | 2010-10-14 09:29:41 +0000 | [diff] [blame] | 795 | case Instruction::GetElementPtr: { |
Eric Christopher | 35e2d7f | 2010-11-19 22:39:56 +0000 | [diff] [blame] | 796 | Address SavedAddr = Addr; |
Eric Christopher | fef5f31 | 2010-11-19 22:30:02 +0000 | [diff] [blame] | 797 | int TmpOffset = Addr.Offset; |
Eric Christopher | e4b3d6b | 2010-10-15 18:02:07 +0000 | [diff] [blame] | 798 | |
Eric Christopher | 21d0c17 | 2010-10-14 09:29:41 +0000 | [diff] [blame] | 799 | // Iterate through the GEP folding the constants into offsets where |
| 800 | // we can. |
| 801 | gep_type_iterator GTI = gep_type_begin(U); |
| 802 | for (User::const_op_iterator i = U->op_begin() + 1, e = U->op_end(); |
| 803 | i != e; ++i, ++GTI) { |
| 804 | const Value *Op = *i; |
Chris Lattner | 229907c | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 805 | if (StructType *STy = dyn_cast<StructType>(*GTI)) { |
Rafael Espindola | ea09c59 | 2014-02-18 22:05:46 +0000 | [diff] [blame] | 806 | const StructLayout *SL = DL.getStructLayout(STy); |
Eric Christopher | 21d0c17 | 2010-10-14 09:29:41 +0000 | [diff] [blame] | 807 | unsigned Idx = cast<ConstantInt>(Op)->getZExtValue(); |
| 808 | TmpOffset += SL->getElementOffset(Idx); |
| 809 | } else { |
Rafael Espindola | ea09c59 | 2014-02-18 22:05:46 +0000 | [diff] [blame] | 810 | uint64_t S = DL.getTypeAllocSize(GTI.getIndexedType()); |
Eric Christopher | a5a779e | 2011-03-22 19:39:17 +0000 | [diff] [blame] | 811 | for (;;) { |
Eric Christopher | e4b3d6b | 2010-10-15 18:02:07 +0000 | [diff] [blame] | 812 | if (const ConstantInt *CI = dyn_cast<ConstantInt>(Op)) { |
| 813 | // Constant-offset addressing. |
| 814 | TmpOffset += CI->getSExtValue() * S; |
Eric Christopher | a5a779e | 2011-03-22 19:39:17 +0000 | [diff] [blame] | 815 | break; |
| 816 | } |
Bob Wilson | 9f3e6b2 | 2013-11-15 19:09:27 +0000 | [diff] [blame] | 817 | if (canFoldAddIntoGEP(U, Op)) { |
| 818 | // A compatible add with a constant operand. Fold the constant. |
Eric Christopher | e4b3d6b | 2010-10-15 18:02:07 +0000 | [diff] [blame] | 819 | ConstantInt *CI = |
Eric Christopher | a5a779e | 2011-03-22 19:39:17 +0000 | [diff] [blame] | 820 | cast<ConstantInt>(cast<AddOperator>(Op)->getOperand(1)); |
Eric Christopher | e4b3d6b | 2010-10-15 18:02:07 +0000 | [diff] [blame] | 821 | TmpOffset += CI->getSExtValue() * S; |
Eric Christopher | a5a779e | 2011-03-22 19:39:17 +0000 | [diff] [blame] | 822 | // Iterate on the other operand. |
| 823 | Op = cast<AddOperator>(Op)->getOperand(0); |
| 824 | continue; |
Eric Christopher | 501d2e2 | 2011-04-29 00:03:10 +0000 | [diff] [blame] | 825 | } |
Eric Christopher | a5a779e | 2011-03-22 19:39:17 +0000 | [diff] [blame] | 826 | // Unsupported |
| 827 | goto unsupported_gep; |
| 828 | } |
Eric Christopher | 21d0c17 | 2010-10-14 09:29:41 +0000 | [diff] [blame] | 829 | } |
| 830 | } |
Eric Christopher | e4b3d6b | 2010-10-15 18:02:07 +0000 | [diff] [blame] | 831 | |
| 832 | // Try to grab the base operand now. |
Eric Christopher | fef5f31 | 2010-11-19 22:30:02 +0000 | [diff] [blame] | 833 | Addr.Offset = TmpOffset; |
| 834 | if (ARMComputeAddress(U->getOperand(0), Addr)) return true; |
Eric Christopher | e4b3d6b | 2010-10-15 18:02:07 +0000 | [diff] [blame] | 835 | |
| 836 | // We failed, restore everything and try the other options. |
Eric Christopher | 35e2d7f | 2010-11-19 22:39:56 +0000 | [diff] [blame] | 837 | Addr = SavedAddr; |
Eric Christopher | e4b3d6b | 2010-10-15 18:02:07 +0000 | [diff] [blame] | 838 | |
Eric Christopher | 21d0c17 | 2010-10-14 09:29:41 +0000 | [diff] [blame] | 839 | unsupported_gep: |
Eric Christopher | 21d0c17 | 2010-10-14 09:29:41 +0000 | [diff] [blame] | 840 | break; |
| 841 | } |
Eric Christopher | 00202ee | 2010-08-23 21:44:12 +0000 | [diff] [blame] | 842 | case Instruction::Alloca: { |
Eric Christopher | 7cd5cda | 2010-10-12 05:39:06 +0000 | [diff] [blame] | 843 | const AllocaInst *AI = cast<AllocaInst>(Obj); |
Eric Christopher | 0a3c28b | 2010-11-20 22:38:27 +0000 | [diff] [blame] | 844 | DenseMap<const AllocaInst*, int>::iterator SI = |
| 845 | FuncInfo.StaticAllocaMap.find(AI); |
| 846 | if (SI != FuncInfo.StaticAllocaMap.end()) { |
| 847 | Addr.BaseType = Address::FrameIndexBase; |
| 848 | Addr.Base.FI = SI->second; |
| 849 | return true; |
| 850 | } |
| 851 | break; |
Eric Christopher | 00202ee | 2010-08-23 21:44:12 +0000 | [diff] [blame] | 852 | } |
| 853 | } |
Eric Christopher | 2ff757d | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 854 | |
Eric Christopher | 9d4e471 | 2010-08-24 00:07:24 +0000 | [diff] [blame] | 855 | // Try to get this in a register if nothing else has worked. |
Eric Christopher | fef5f31 | 2010-11-19 22:30:02 +0000 | [diff] [blame] | 856 | if (Addr.Base.Reg == 0) Addr.Base.Reg = getRegForValue(Obj); |
| 857 | return Addr.Base.Reg != 0; |
Eric Christopher | 21d0c17 | 2010-10-14 09:29:41 +0000 | [diff] [blame] | 858 | } |
| 859 | |
Chad Rosier | 150d35b | 2012-12-17 22:35:29 +0000 | [diff] [blame] | 860 | void ARMFastISel::ARMSimplifyAddress(Address &Addr, MVT VT, bool useAM3) { |
Eric Christopher | 73bc5b0 | 2010-10-21 19:40:30 +0000 | [diff] [blame] | 861 | bool needsLowering = false; |
Chad Rosier | 150d35b | 2012-12-17 22:35:29 +0000 | [diff] [blame] | 862 | switch (VT.SimpleTy) { |
Craig Topper | e55c556 | 2012-02-07 02:50:20 +0000 | [diff] [blame] | 863 | default: llvm_unreachable("Unhandled load/store type!"); |
Eric Christopher | 73bc5b0 | 2010-10-21 19:40:30 +0000 | [diff] [blame] | 864 | case MVT::i1: |
| 865 | case MVT::i8: |
Chad Rosier | c8cfd3a | 2011-11-13 02:23:59 +0000 | [diff] [blame] | 866 | case MVT::i16: |
Eric Christopher | 73bc5b0 | 2010-10-21 19:40:30 +0000 | [diff] [blame] | 867 | case MVT::i32: |
Chad Rosier | adfd200 | 2011-11-14 20:22:27 +0000 | [diff] [blame] | 868 | if (!useAM3) { |
Chad Rosier | c8cfd3a | 2011-11-13 02:23:59 +0000 | [diff] [blame] | 869 | // Integer loads/stores handle 12-bit offsets. |
| 870 | needsLowering = ((Addr.Offset & 0xfff) != Addr.Offset); |
Chad Rosier | adfd200 | 2011-11-14 20:22:27 +0000 | [diff] [blame] | 871 | // Handle negative offsets. |
Chad Rosier | 45110fd | 2011-11-14 22:34:48 +0000 | [diff] [blame] | 872 | if (needsLowering && isThumb2) |
| 873 | needsLowering = !(Subtarget->hasV6T2Ops() && Addr.Offset < 0 && |
| 874 | Addr.Offset > -256); |
Chad Rosier | adfd200 | 2011-11-14 20:22:27 +0000 | [diff] [blame] | 875 | } else { |
Chad Rosier | 5196efd | 2011-11-13 04:25:02 +0000 | [diff] [blame] | 876 | // ARM halfword load/stores and signed byte loads use +/-imm8 offsets. |
Chad Rosier | 2a1df88 | 2011-11-14 04:09:28 +0000 | [diff] [blame] | 877 | needsLowering = (Addr.Offset > 255 || Addr.Offset < -255); |
Chad Rosier | adfd200 | 2011-11-14 20:22:27 +0000 | [diff] [blame] | 878 | } |
Eric Christopher | 73bc5b0 | 2010-10-21 19:40:30 +0000 | [diff] [blame] | 879 | break; |
| 880 | case MVT::f32: |
| 881 | case MVT::f64: |
| 882 | // Floating point operands handle 8-bit offsets. |
Eric Christopher | fef5f31 | 2010-11-19 22:30:02 +0000 | [diff] [blame] | 883 | needsLowering = ((Addr.Offset & 0xff) != Addr.Offset); |
Eric Christopher | 73bc5b0 | 2010-10-21 19:40:30 +0000 | [diff] [blame] | 884 | break; |
| 885 | } |
Jim Grosbach | 055de2c | 2010-10-27 21:39:08 +0000 | [diff] [blame] | 886 | |
Eric Christopher | 0a3c28b | 2010-11-20 22:38:27 +0000 | [diff] [blame] | 887 | // If this is a stack pointer and the offset needs to be simplified then |
| 888 | // put the alloca address into a register, set the base type back to |
| 889 | // register and continue. This should almost never happen. |
| 890 | if (needsLowering && Addr.BaseType == Address::FrameIndexBase) { |
Craig Topper | 61e88f4 | 2014-11-21 05:58:21 +0000 | [diff] [blame] | 891 | const TargetRegisterClass *RC = isThumb2 ? &ARM::tGPRRegClass |
| 892 | : &ARM::GPRRegClass; |
Eric Christopher | 0a3c28b | 2010-11-20 22:38:27 +0000 | [diff] [blame] | 893 | unsigned ResultReg = createResultReg(RC); |
Chad Rosier | 0439cfc | 2011-11-08 21:12:00 +0000 | [diff] [blame] | 894 | unsigned Opc = isThumb2 ? ARM::t2ADDri : ARM::ADDri; |
Rafael Espindola | ea09c59 | 2014-02-18 22:05:46 +0000 | [diff] [blame] | 895 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, |
Eric Christopher | 0a3c28b | 2010-11-20 22:38:27 +0000 | [diff] [blame] | 896 | TII.get(Opc), ResultReg) |
| 897 | .addFrameIndex(Addr.Base.FI) |
| 898 | .addImm(0)); |
| 899 | Addr.Base.Reg = ResultReg; |
| 900 | Addr.BaseType = Address::RegBase; |
| 901 | } |
| 902 | |
Eric Christopher | 73bc5b0 | 2010-10-21 19:40:30 +0000 | [diff] [blame] | 903 | // Since the offset is too large for the load/store instruction |
Eric Christopher | 74487fc | 2010-09-02 00:53:56 +0000 | [diff] [blame] | 904 | // get the reg+offset into a register. |
Eric Christopher | 73bc5b0 | 2010-10-21 19:40:30 +0000 | [diff] [blame] | 905 | if (needsLowering) { |
Juergen Ributzka | 88e3251 | 2014-09-03 20:56:59 +0000 | [diff] [blame] | 906 | Addr.Base.Reg = fastEmit_ri_(MVT::i32, ISD::ADD, Addr.Base.Reg, |
Eli Friedman | 86caced | 2011-04-29 21:22:56 +0000 | [diff] [blame] | 907 | /*Op0IsKill*/false, Addr.Offset, MVT::i32); |
Eric Christopher | fef5f31 | 2010-11-19 22:30:02 +0000 | [diff] [blame] | 908 | Addr.Offset = 0; |
Eric Christopher | 74487fc | 2010-09-02 00:53:56 +0000 | [diff] [blame] | 909 | } |
Eric Christopher | 00202ee | 2010-08-23 21:44:12 +0000 | [diff] [blame] | 910 | } |
| 911 | |
Chad Rosier | 150d35b | 2012-12-17 22:35:29 +0000 | [diff] [blame] | 912 | void ARMFastISel::AddLoadStoreOperands(MVT VT, Address &Addr, |
Cameron Zwarich | 6528a54 | 2011-05-28 20:34:49 +0000 | [diff] [blame] | 913 | const MachineInstrBuilder &MIB, |
Chad Rosier | c8cfd3a | 2011-11-13 02:23:59 +0000 | [diff] [blame] | 914 | unsigned Flags, bool useAM3) { |
Eric Christopher | 119ff7f | 2010-12-01 01:40:24 +0000 | [diff] [blame] | 915 | // addrmode5 output depends on the selection dag addressing dividing the |
| 916 | // offset by 4 that it then later multiplies. Do this here as well. |
Chad Rosier | 150d35b | 2012-12-17 22:35:29 +0000 | [diff] [blame] | 917 | if (VT.SimpleTy == MVT::f32 || VT.SimpleTy == MVT::f64) |
Eric Christopher | 119ff7f | 2010-12-01 01:40:24 +0000 | [diff] [blame] | 918 | Addr.Offset /= 4; |
Eric Christopher | 501d2e2 | 2011-04-29 00:03:10 +0000 | [diff] [blame] | 919 | |
Eric Christopher | 119ff7f | 2010-12-01 01:40:24 +0000 | [diff] [blame] | 920 | // Frame base works a bit differently. Handle it separately. |
| 921 | if (Addr.BaseType == Address::FrameIndexBase) { |
| 922 | int FI = Addr.Base.FI; |
| 923 | int Offset = Addr.Offset; |
| 924 | MachineMemOperand *MMO = |
| 925 | FuncInfo.MF->getMachineMemOperand( |
| 926 | MachinePointerInfo::getFixedStack(FI, Offset), |
Cameron Zwarich | 6528a54 | 2011-05-28 20:34:49 +0000 | [diff] [blame] | 927 | Flags, |
Eric Christopher | 119ff7f | 2010-12-01 01:40:24 +0000 | [diff] [blame] | 928 | MFI.getObjectSize(FI), |
| 929 | MFI.getObjectAlignment(FI)); |
| 930 | // Now add the rest of the operands. |
| 931 | MIB.addFrameIndex(FI); |
| 932 | |
Bob Wilson | 80381f6 | 2011-12-04 00:52:23 +0000 | [diff] [blame] | 933 | // ARM halfword load/stores and signed byte loads need an additional |
| 934 | // operand. |
Chad Rosier | 2a1df88 | 2011-11-14 04:09:28 +0000 | [diff] [blame] | 935 | if (useAM3) { |
| 936 | signed Imm = (Addr.Offset < 0) ? (0x100 | -Addr.Offset) : Addr.Offset; |
| 937 | MIB.addReg(0); |
| 938 | MIB.addImm(Imm); |
| 939 | } else { |
| 940 | MIB.addImm(Addr.Offset); |
| 941 | } |
Eric Christopher | 119ff7f | 2010-12-01 01:40:24 +0000 | [diff] [blame] | 942 | MIB.addMemOperand(MMO); |
| 943 | } else { |
| 944 | // Now add the rest of the operands. |
| 945 | MIB.addReg(Addr.Base.Reg); |
Eric Christopher | 501d2e2 | 2011-04-29 00:03:10 +0000 | [diff] [blame] | 946 | |
Bob Wilson | 80381f6 | 2011-12-04 00:52:23 +0000 | [diff] [blame] | 947 | // ARM halfword load/stores and signed byte loads need an additional |
| 948 | // operand. |
Chad Rosier | 2a1df88 | 2011-11-14 04:09:28 +0000 | [diff] [blame] | 949 | if (useAM3) { |
| 950 | signed Imm = (Addr.Offset < 0) ? (0x100 | -Addr.Offset) : Addr.Offset; |
| 951 | MIB.addReg(0); |
| 952 | MIB.addImm(Imm); |
| 953 | } else { |
| 954 | MIB.addImm(Addr.Offset); |
| 955 | } |
Eric Christopher | 119ff7f | 2010-12-01 01:40:24 +0000 | [diff] [blame] | 956 | } |
| 957 | AddOptionalDefs(MIB); |
| 958 | } |
| 959 | |
Patrik Hagglund | 5e6c361 | 2012-12-13 06:34:11 +0000 | [diff] [blame] | 960 | bool ARMFastISel::ARMEmitLoad(MVT VT, unsigned &ResultReg, Address &Addr, |
Chad Rosier | 563de60 | 2011-12-13 19:22:14 +0000 | [diff] [blame] | 961 | unsigned Alignment, bool isZExt, bool allocReg) { |
Eric Christopher | 901176a | 2010-08-31 01:28:42 +0000 | [diff] [blame] | 962 | unsigned Opc; |
Chad Rosier | c8cfd3a | 2011-11-13 02:23:59 +0000 | [diff] [blame] | 963 | bool useAM3 = false; |
Chad Rosier | 563de60 | 2011-12-13 19:22:14 +0000 | [diff] [blame] | 964 | bool needVMOV = false; |
Craig Topper | 760b134 | 2012-02-22 05:59:10 +0000 | [diff] [blame] | 965 | const TargetRegisterClass *RC; |
Patrik Hagglund | 5e6c361 | 2012-12-13 06:34:11 +0000 | [diff] [blame] | 966 | switch (VT.SimpleTy) { |
Eric Christopher | 119ff7f | 2010-12-01 01:40:24 +0000 | [diff] [blame] | 967 | // This is mostly going to be Neon/vector support. |
| 968 | default: return false; |
Chad Rosier | 023ede5 | 2011-11-11 02:38:59 +0000 | [diff] [blame] | 969 | case MVT::i1: |
Eric Christopher | 3ce9c4a | 2010-09-01 18:01:32 +0000 | [diff] [blame] | 970 | case MVT::i8: |
Chad Rosier | adfd200 | 2011-11-14 20:22:27 +0000 | [diff] [blame] | 971 | if (isThumb2) { |
| 972 | if (Addr.Offset < 0 && Addr.Offset > -256 && Subtarget->hasV6T2Ops()) |
| 973 | Opc = isZExt ? ARM::t2LDRBi8 : ARM::t2LDRSBi8; |
| 974 | else |
| 975 | Opc = isZExt ? ARM::t2LDRBi12 : ARM::t2LDRSBi12; |
Chad Rosier | c8cfd3a | 2011-11-13 02:23:59 +0000 | [diff] [blame] | 976 | } else { |
Chad Rosier | adfd200 | 2011-11-14 20:22:27 +0000 | [diff] [blame] | 977 | if (isZExt) { |
| 978 | Opc = ARM::LDRBi12; |
| 979 | } else { |
| 980 | Opc = ARM::LDRSB; |
| 981 | useAM3 = true; |
| 982 | } |
Chad Rosier | c8cfd3a | 2011-11-13 02:23:59 +0000 | [diff] [blame] | 983 | } |
JF Bastien | 652fa6a | 2013-06-09 00:20:24 +0000 | [diff] [blame] | 984 | RC = isThumb2 ? &ARM::rGPRRegClass : &ARM::GPRnopcRegClass; |
Eric Christopher | 3ce9c4a | 2010-09-01 18:01:32 +0000 | [diff] [blame] | 985 | break; |
Chad Rosier | 2f27fab | 2011-11-09 21:30:12 +0000 | [diff] [blame] | 986 | case MVT::i16: |
Chad Rosier | 66bb178 | 2012-11-09 18:25:27 +0000 | [diff] [blame] | 987 | if (Alignment && Alignment < 2 && !Subtarget->allowsUnalignedMem()) |
Chad Rosier | 2364f58 | 2012-09-21 00:41:42 +0000 | [diff] [blame] | 988 | return false; |
| 989 | |
Chad Rosier | adfd200 | 2011-11-14 20:22:27 +0000 | [diff] [blame] | 990 | if (isThumb2) { |
| 991 | if (Addr.Offset < 0 && Addr.Offset > -256 && Subtarget->hasV6T2Ops()) |
| 992 | Opc = isZExt ? ARM::t2LDRHi8 : ARM::t2LDRSHi8; |
| 993 | else |
| 994 | Opc = isZExt ? ARM::t2LDRHi12 : ARM::t2LDRSHi12; |
| 995 | } else { |
| 996 | Opc = isZExt ? ARM::LDRH : ARM::LDRSH; |
| 997 | useAM3 = true; |
| 998 | } |
JF Bastien | 652fa6a | 2013-06-09 00:20:24 +0000 | [diff] [blame] | 999 | RC = isThumb2 ? &ARM::rGPRRegClass : &ARM::GPRnopcRegClass; |
Chad Rosier | 2f27fab | 2011-11-09 21:30:12 +0000 | [diff] [blame] | 1000 | break; |
Eric Christopher | 901176a | 2010-08-31 01:28:42 +0000 | [diff] [blame] | 1001 | case MVT::i32: |
Chad Rosier | 66bb178 | 2012-11-09 18:25:27 +0000 | [diff] [blame] | 1002 | if (Alignment && Alignment < 4 && !Subtarget->allowsUnalignedMem()) |
Chad Rosier | 8bf01fc | 2012-09-21 16:58:35 +0000 | [diff] [blame] | 1003 | return false; |
| 1004 | |
Chad Rosier | adfd200 | 2011-11-14 20:22:27 +0000 | [diff] [blame] | 1005 | if (isThumb2) { |
| 1006 | if (Addr.Offset < 0 && Addr.Offset > -256 && Subtarget->hasV6T2Ops()) |
| 1007 | Opc = ARM::t2LDRi8; |
| 1008 | else |
| 1009 | Opc = ARM::t2LDRi12; |
| 1010 | } else { |
| 1011 | Opc = ARM::LDRi12; |
| 1012 | } |
JF Bastien | 652fa6a | 2013-06-09 00:20:24 +0000 | [diff] [blame] | 1013 | RC = isThumb2 ? &ARM::rGPRRegClass : &ARM::GPRnopcRegClass; |
Eric Christopher | 901176a | 2010-08-31 01:28:42 +0000 | [diff] [blame] | 1014 | break; |
Eric Christopher | aef6499b | 2010-09-18 01:59:37 +0000 | [diff] [blame] | 1015 | case MVT::f32: |
Chad Rosier | ded6160 | 2011-12-14 17:55:03 +0000 | [diff] [blame] | 1016 | if (!Subtarget->hasVFP2()) return false; |
Chad Rosier | 563de60 | 2011-12-13 19:22:14 +0000 | [diff] [blame] | 1017 | // Unaligned loads need special handling. Floats require word-alignment. |
| 1018 | if (Alignment && Alignment < 4) { |
| 1019 | needVMOV = true; |
| 1020 | VT = MVT::i32; |
| 1021 | Opc = isThumb2 ? ARM::t2LDRi12 : ARM::LDRi12; |
JF Bastien | 652fa6a | 2013-06-09 00:20:24 +0000 | [diff] [blame] | 1022 | RC = isThumb2 ? &ARM::rGPRRegClass : &ARM::GPRnopcRegClass; |
Chad Rosier | 563de60 | 2011-12-13 19:22:14 +0000 | [diff] [blame] | 1023 | } else { |
| 1024 | Opc = ARM::VLDRS; |
| 1025 | RC = TLI.getRegClassFor(VT); |
| 1026 | } |
Eric Christopher | aef6499b | 2010-09-18 01:59:37 +0000 | [diff] [blame] | 1027 | break; |
| 1028 | case MVT::f64: |
Chad Rosier | ded6160 | 2011-12-14 17:55:03 +0000 | [diff] [blame] | 1029 | if (!Subtarget->hasVFP2()) return false; |
Chad Rosier | a26979b | 2011-12-14 17:26:05 +0000 | [diff] [blame] | 1030 | // FIXME: Unaligned loads need special handling. Doublewords require |
| 1031 | // word-alignment. |
| 1032 | if (Alignment && Alignment < 4) |
Chad Rosier | 563de60 | 2011-12-13 19:22:14 +0000 | [diff] [blame] | 1033 | return false; |
Chad Rosier | a26979b | 2011-12-14 17:26:05 +0000 | [diff] [blame] | 1034 | |
Eric Christopher | aef6499b | 2010-09-18 01:59:37 +0000 | [diff] [blame] | 1035 | Opc = ARM::VLDRD; |
Eric Christopher | a2583ea | 2010-10-07 05:50:44 +0000 | [diff] [blame] | 1036 | RC = TLI.getRegClassFor(VT); |
Eric Christopher | aef6499b | 2010-09-18 01:59:37 +0000 | [diff] [blame] | 1037 | break; |
Eric Christopher | 761e7fb | 2010-08-25 07:23:49 +0000 | [diff] [blame] | 1038 | } |
Eric Christopher | 119ff7f | 2010-12-01 01:40:24 +0000 | [diff] [blame] | 1039 | // Simplify this down to something we can handle. |
Chad Rosier | c8cfd3a | 2011-11-13 02:23:59 +0000 | [diff] [blame] | 1040 | ARMSimplifyAddress(Addr, VT, useAM3); |
Jim Grosbach | 055de2c | 2010-10-27 21:39:08 +0000 | [diff] [blame] | 1041 | |
Eric Christopher | 119ff7f | 2010-12-01 01:40:24 +0000 | [diff] [blame] | 1042 | // Create the base instruction, then add the operands. |
Chad Rosier | c8cfd3a | 2011-11-13 02:23:59 +0000 | [diff] [blame] | 1043 | if (allocReg) |
| 1044 | ResultReg = createResultReg(RC); |
| 1045 | assert (ResultReg > 255 && "Expected an allocated virtual register."); |
Rafael Espindola | ea09c59 | 2014-02-18 22:05:46 +0000 | [diff] [blame] | 1046 | MachineInstrBuilder MIB = BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, |
Eric Christopher | 119ff7f | 2010-12-01 01:40:24 +0000 | [diff] [blame] | 1047 | TII.get(Opc), ResultReg); |
Chad Rosier | c8cfd3a | 2011-11-13 02:23:59 +0000 | [diff] [blame] | 1048 | AddLoadStoreOperands(VT, Addr, MIB, MachineMemOperand::MOLoad, useAM3); |
Chad Rosier | 563de60 | 2011-12-13 19:22:14 +0000 | [diff] [blame] | 1049 | |
| 1050 | // If we had an unaligned load of a float we've converted it to an regular |
| 1051 | // load. Now we must move from the GRP to the FP register. |
| 1052 | if (needVMOV) { |
| 1053 | unsigned MoveReg = createResultReg(TLI.getRegClassFor(MVT::f32)); |
Rafael Espindola | ea09c59 | 2014-02-18 22:05:46 +0000 | [diff] [blame] | 1054 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, |
Chad Rosier | 563de60 | 2011-12-13 19:22:14 +0000 | [diff] [blame] | 1055 | TII.get(ARM::VMOVSR), MoveReg) |
| 1056 | .addReg(ResultReg)); |
| 1057 | ResultReg = MoveReg; |
| 1058 | } |
Eric Christopher | 901176a | 2010-08-31 01:28:42 +0000 | [diff] [blame] | 1059 | return true; |
Eric Christopher | 761e7fb | 2010-08-25 07:23:49 +0000 | [diff] [blame] | 1060 | } |
| 1061 | |
Eric Christopher | 29ab6d1 | 2010-09-27 06:02:23 +0000 | [diff] [blame] | 1062 | bool ARMFastISel::SelectLoad(const Instruction *I) { |
Eli Friedman | f3dd6da | 2011-09-02 22:33:24 +0000 | [diff] [blame] | 1063 | // Atomic loads need special handling. |
| 1064 | if (cast<LoadInst>(I)->isAtomic()) |
| 1065 | return false; |
| 1066 | |
Eric Christopher | 860fc93 | 2010-09-10 00:34:35 +0000 | [diff] [blame] | 1067 | // Verify we have a legal type before going any further. |
Duncan Sands | f5dda01 | 2010-11-03 11:35:31 +0000 | [diff] [blame] | 1068 | MVT VT; |
Eric Christopher | 860fc93 | 2010-09-10 00:34:35 +0000 | [diff] [blame] | 1069 | if (!isLoadTypeLegal(I->getType(), VT)) |
| 1070 | return false; |
| 1071 | |
Eric Christopher | 119ff7f | 2010-12-01 01:40:24 +0000 | [diff] [blame] | 1072 | // See if we can handle this address. |
Eric Christopher | fef5f31 | 2010-11-19 22:30:02 +0000 | [diff] [blame] | 1073 | Address Addr; |
Eric Christopher | 119ff7f | 2010-12-01 01:40:24 +0000 | [diff] [blame] | 1074 | if (!ARMComputeAddress(I->getOperand(0), Addr)) return false; |
Eric Christopher | 860fc93 | 2010-09-10 00:34:35 +0000 | [diff] [blame] | 1075 | |
| 1076 | unsigned ResultReg; |
Chad Rosier | 563de60 | 2011-12-13 19:22:14 +0000 | [diff] [blame] | 1077 | if (!ARMEmitLoad(VT, ResultReg, Addr, cast<LoadInst>(I)->getAlignment())) |
| 1078 | return false; |
Juergen Ributzka | 5b8bb4d | 2014-09-03 20:56:52 +0000 | [diff] [blame] | 1079 | updateValueMap(I, ResultReg); |
Eric Christopher | 860fc93 | 2010-09-10 00:34:35 +0000 | [diff] [blame] | 1080 | return true; |
| 1081 | } |
| 1082 | |
Patrik Hagglund | 5e6c361 | 2012-12-13 06:34:11 +0000 | [diff] [blame] | 1083 | bool ARMFastISel::ARMEmitStore(MVT VT, unsigned SrcReg, Address &Addr, |
Bob Wilson | 80381f6 | 2011-12-04 00:52:23 +0000 | [diff] [blame] | 1084 | unsigned Alignment) { |
Eric Christopher | 74487fc | 2010-09-02 00:53:56 +0000 | [diff] [blame] | 1085 | unsigned StrOpc; |
Chad Rosier | c8cfd3a | 2011-11-13 02:23:59 +0000 | [diff] [blame] | 1086 | bool useAM3 = false; |
Patrik Hagglund | 5e6c361 | 2012-12-13 06:34:11 +0000 | [diff] [blame] | 1087 | switch (VT.SimpleTy) { |
Eric Christopher | 119ff7f | 2010-12-01 01:40:24 +0000 | [diff] [blame] | 1088 | // This is mostly going to be Neon/vector support. |
Eric Christopher | 74487fc | 2010-09-02 00:53:56 +0000 | [diff] [blame] | 1089 | default: return false; |
Eric Christopher | 1e43892e | 2010-11-02 23:59:09 +0000 | [diff] [blame] | 1090 | case MVT::i1: { |
Craig Topper | 61e88f4 | 2014-11-21 05:58:21 +0000 | [diff] [blame] | 1091 | unsigned Res = createResultReg(isThumb2 ? &ARM::tGPRRegClass |
| 1092 | : &ARM::GPRRegClass); |
Chad Rosier | 0439cfc | 2011-11-08 21:12:00 +0000 | [diff] [blame] | 1093 | unsigned Opc = isThumb2 ? ARM::t2ANDri : ARM::ANDri; |
Joey Gouly | c7cda1c | 2013-08-23 15:20:56 +0000 | [diff] [blame] | 1094 | SrcReg = constrainOperandRegClass(TII.get(Opc), SrcReg, 1); |
Rafael Espindola | ea09c59 | 2014-02-18 22:05:46 +0000 | [diff] [blame] | 1095 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, |
Eric Christopher | 1e43892e | 2010-11-02 23:59:09 +0000 | [diff] [blame] | 1096 | TII.get(Opc), Res) |
| 1097 | .addReg(SrcReg).addImm(1)); |
| 1098 | SrcReg = Res; |
| 1099 | } // Fallthrough here. |
Eric Christopher | e4b3d6b | 2010-10-15 18:02:07 +0000 | [diff] [blame] | 1100 | case MVT::i8: |
Chad Rosier | adfd200 | 2011-11-14 20:22:27 +0000 | [diff] [blame] | 1101 | if (isThumb2) { |
| 1102 | if (Addr.Offset < 0 && Addr.Offset > -256 && Subtarget->hasV6T2Ops()) |
| 1103 | StrOpc = ARM::t2STRBi8; |
| 1104 | else |
| 1105 | StrOpc = ARM::t2STRBi12; |
| 1106 | } else { |
| 1107 | StrOpc = ARM::STRBi12; |
| 1108 | } |
Eric Christopher | 7cd5cda | 2010-10-12 05:39:06 +0000 | [diff] [blame] | 1109 | break; |
| 1110 | case MVT::i16: |
Chad Rosier | 66bb178 | 2012-11-09 18:25:27 +0000 | [diff] [blame] | 1111 | if (Alignment && Alignment < 2 && !Subtarget->allowsUnalignedMem()) |
Chad Rosier | 2364f58 | 2012-09-21 00:41:42 +0000 | [diff] [blame] | 1112 | return false; |
| 1113 | |
Chad Rosier | adfd200 | 2011-11-14 20:22:27 +0000 | [diff] [blame] | 1114 | if (isThumb2) { |
| 1115 | if (Addr.Offset < 0 && Addr.Offset > -256 && Subtarget->hasV6T2Ops()) |
| 1116 | StrOpc = ARM::t2STRHi8; |
| 1117 | else |
| 1118 | StrOpc = ARM::t2STRHi12; |
| 1119 | } else { |
| 1120 | StrOpc = ARM::STRH; |
| 1121 | useAM3 = true; |
| 1122 | } |
Eric Christopher | 7cd5cda | 2010-10-12 05:39:06 +0000 | [diff] [blame] | 1123 | break; |
Eric Christopher | c918d55 | 2010-10-16 01:10:35 +0000 | [diff] [blame] | 1124 | case MVT::i32: |
Chad Rosier | 66bb178 | 2012-11-09 18:25:27 +0000 | [diff] [blame] | 1125 | if (Alignment && Alignment < 4 && !Subtarget->allowsUnalignedMem()) |
Chad Rosier | 8bf01fc | 2012-09-21 16:58:35 +0000 | [diff] [blame] | 1126 | return false; |
| 1127 | |
Chad Rosier | adfd200 | 2011-11-14 20:22:27 +0000 | [diff] [blame] | 1128 | if (isThumb2) { |
| 1129 | if (Addr.Offset < 0 && Addr.Offset > -256 && Subtarget->hasV6T2Ops()) |
| 1130 | StrOpc = ARM::t2STRi8; |
| 1131 | else |
| 1132 | StrOpc = ARM::t2STRi12; |
| 1133 | } else { |
| 1134 | StrOpc = ARM::STRi12; |
| 1135 | } |
Eric Christopher | c918d55 | 2010-10-16 01:10:35 +0000 | [diff] [blame] | 1136 | break; |
Eric Christopher | c3e118e | 2010-09-02 23:43:26 +0000 | [diff] [blame] | 1137 | case MVT::f32: |
| 1138 | if (!Subtarget->hasVFP2()) return false; |
Chad Rosier | c77830d | 2011-12-06 01:44:17 +0000 | [diff] [blame] | 1139 | // Unaligned stores need special handling. Floats require word-alignment. |
Chad Rosier | ec3b77e | 2011-12-03 02:21:57 +0000 | [diff] [blame] | 1140 | if (Alignment && Alignment < 4) { |
| 1141 | unsigned MoveReg = createResultReg(TLI.getRegClassFor(MVT::i32)); |
Rafael Espindola | ea09c59 | 2014-02-18 22:05:46 +0000 | [diff] [blame] | 1142 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, |
Chad Rosier | ec3b77e | 2011-12-03 02:21:57 +0000 | [diff] [blame] | 1143 | TII.get(ARM::VMOVRS), MoveReg) |
| 1144 | .addReg(SrcReg)); |
| 1145 | SrcReg = MoveReg; |
| 1146 | VT = MVT::i32; |
| 1147 | StrOpc = isThumb2 ? ARM::t2STRi12 : ARM::STRi12; |
Chad Rosier | fce2891 | 2011-12-14 17:32:02 +0000 | [diff] [blame] | 1148 | } else { |
| 1149 | StrOpc = ARM::VSTRS; |
Chad Rosier | ec3b77e | 2011-12-03 02:21:57 +0000 | [diff] [blame] | 1150 | } |
Eric Christopher | c3e118e | 2010-09-02 23:43:26 +0000 | [diff] [blame] | 1151 | break; |
| 1152 | case MVT::f64: |
| 1153 | if (!Subtarget->hasVFP2()) return false; |
Chad Rosier | c77830d | 2011-12-06 01:44:17 +0000 | [diff] [blame] | 1154 | // FIXME: Unaligned stores need special handling. Doublewords require |
| 1155 | // word-alignment. |
Chad Rosier | a26979b | 2011-12-14 17:26:05 +0000 | [diff] [blame] | 1156 | if (Alignment && Alignment < 4) |
Chad Rosier | ec3b77e | 2011-12-03 02:21:57 +0000 | [diff] [blame] | 1157 | return false; |
Chad Rosier | a26979b | 2011-12-14 17:26:05 +0000 | [diff] [blame] | 1158 | |
Eric Christopher | c3e118e | 2010-09-02 23:43:26 +0000 | [diff] [blame] | 1159 | StrOpc = ARM::VSTRD; |
| 1160 | break; |
Eric Christopher | 74487fc | 2010-09-02 00:53:56 +0000 | [diff] [blame] | 1161 | } |
Eric Christopher | 119ff7f | 2010-12-01 01:40:24 +0000 | [diff] [blame] | 1162 | // Simplify this down to something we can handle. |
Chad Rosier | c8cfd3a | 2011-11-13 02:23:59 +0000 | [diff] [blame] | 1163 | ARMSimplifyAddress(Addr, VT, useAM3); |
Jim Grosbach | 055de2c | 2010-10-27 21:39:08 +0000 | [diff] [blame] | 1164 | |
Eric Christopher | 119ff7f | 2010-12-01 01:40:24 +0000 | [diff] [blame] | 1165 | // Create the base instruction, then add the operands. |
Joey Gouly | c7cda1c | 2013-08-23 15:20:56 +0000 | [diff] [blame] | 1166 | SrcReg = constrainOperandRegClass(TII.get(StrOpc), SrcReg, 0); |
Rafael Espindola | ea09c59 | 2014-02-18 22:05:46 +0000 | [diff] [blame] | 1167 | MachineInstrBuilder MIB = BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, |
Eric Christopher | 119ff7f | 2010-12-01 01:40:24 +0000 | [diff] [blame] | 1168 | TII.get(StrOpc)) |
Chad Rosier | ce619dd | 2011-11-17 01:16:53 +0000 | [diff] [blame] | 1169 | .addReg(SrcReg); |
Chad Rosier | c8cfd3a | 2011-11-13 02:23:59 +0000 | [diff] [blame] | 1170 | AddLoadStoreOperands(VT, Addr, MIB, MachineMemOperand::MOStore, useAM3); |
Eric Christopher | 74487fc | 2010-09-02 00:53:56 +0000 | [diff] [blame] | 1171 | return true; |
| 1172 | } |
| 1173 | |
Eric Christopher | 29ab6d1 | 2010-09-27 06:02:23 +0000 | [diff] [blame] | 1174 | bool ARMFastISel::SelectStore(const Instruction *I) { |
Eric Christopher | 74487fc | 2010-09-02 00:53:56 +0000 | [diff] [blame] | 1175 | Value *Op0 = I->getOperand(0); |
| 1176 | unsigned SrcReg = 0; |
| 1177 | |
Eli Friedman | f3dd6da | 2011-09-02 22:33:24 +0000 | [diff] [blame] | 1178 | // Atomic stores need special handling. |
| 1179 | if (cast<StoreInst>(I)->isAtomic()) |
| 1180 | return false; |
| 1181 | |
Eric Christopher | 119ff7f | 2010-12-01 01:40:24 +0000 | [diff] [blame] | 1182 | // Verify we have a legal type before going any further. |
Duncan Sands | f5dda01 | 2010-11-03 11:35:31 +0000 | [diff] [blame] | 1183 | MVT VT; |
Eric Christopher | 74487fc | 2010-09-02 00:53:56 +0000 | [diff] [blame] | 1184 | if (!isLoadTypeLegal(I->getOperand(0)->getType(), VT)) |
Eric Christopher | fde5a3d | 2010-09-01 22:16:27 +0000 | [diff] [blame] | 1185 | return false; |
Eric Christopher | 74487fc | 2010-09-02 00:53:56 +0000 | [diff] [blame] | 1186 | |
Eric Christopher | 92db201 | 2010-09-02 01:48:11 +0000 | [diff] [blame] | 1187 | // Get the value to be stored into a register. |
| 1188 | SrcReg = getRegForValue(Op0); |
Eric Christopher | 119ff7f | 2010-12-01 01:40:24 +0000 | [diff] [blame] | 1189 | if (SrcReg == 0) return false; |
Eric Christopher | 2ff757d | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 1190 | |
Eric Christopher | 119ff7f | 2010-12-01 01:40:24 +0000 | [diff] [blame] | 1191 | // See if we can handle this address. |
Eric Christopher | fef5f31 | 2010-11-19 22:30:02 +0000 | [diff] [blame] | 1192 | Address Addr; |
Eric Christopher | fef5f31 | 2010-11-19 22:30:02 +0000 | [diff] [blame] | 1193 | if (!ARMComputeAddress(I->getOperand(1), Addr)) |
Eric Christopher | 74487fc | 2010-09-02 00:53:56 +0000 | [diff] [blame] | 1194 | return false; |
Eric Christopher | 2ff757d | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 1195 | |
Chad Rosier | ec3b77e | 2011-12-03 02:21:57 +0000 | [diff] [blame] | 1196 | if (!ARMEmitStore(VT, SrcReg, Addr, cast<StoreInst>(I)->getAlignment())) |
| 1197 | return false; |
Eric Christopher | 2ccc1aa | 2010-09-17 22:28:18 +0000 | [diff] [blame] | 1198 | return true; |
| 1199 | } |
| 1200 | |
| 1201 | static ARMCC::CondCodes getComparePred(CmpInst::Predicate Pred) { |
| 1202 | switch (Pred) { |
| 1203 | // Needs two compares... |
| 1204 | case CmpInst::FCMP_ONE: |
Eric Christopher | 7ac602b | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1205 | case CmpInst::FCMP_UEQ: |
Eric Christopher | 2ccc1aa | 2010-09-17 22:28:18 +0000 | [diff] [blame] | 1206 | default: |
Eric Christopher | b2abb50 | 2010-11-02 01:24:49 +0000 | [diff] [blame] | 1207 | // AL is our "false" for now. The other two need more compares. |
Eric Christopher | 2ccc1aa | 2010-09-17 22:28:18 +0000 | [diff] [blame] | 1208 | return ARMCC::AL; |
| 1209 | case CmpInst::ICMP_EQ: |
| 1210 | case CmpInst::FCMP_OEQ: |
| 1211 | return ARMCC::EQ; |
| 1212 | case CmpInst::ICMP_SGT: |
| 1213 | case CmpInst::FCMP_OGT: |
| 1214 | return ARMCC::GT; |
| 1215 | case CmpInst::ICMP_SGE: |
| 1216 | case CmpInst::FCMP_OGE: |
| 1217 | return ARMCC::GE; |
| 1218 | case CmpInst::ICMP_UGT: |
| 1219 | case CmpInst::FCMP_UGT: |
| 1220 | return ARMCC::HI; |
| 1221 | case CmpInst::FCMP_OLT: |
| 1222 | return ARMCC::MI; |
| 1223 | case CmpInst::ICMP_ULE: |
| 1224 | case CmpInst::FCMP_OLE: |
| 1225 | return ARMCC::LS; |
| 1226 | case CmpInst::FCMP_ORD: |
| 1227 | return ARMCC::VC; |
| 1228 | case CmpInst::FCMP_UNO: |
| 1229 | return ARMCC::VS; |
| 1230 | case CmpInst::FCMP_UGE: |
| 1231 | return ARMCC::PL; |
| 1232 | case CmpInst::ICMP_SLT: |
| 1233 | case CmpInst::FCMP_ULT: |
Eric Christopher | 7ac602b | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1234 | return ARMCC::LT; |
Eric Christopher | 2ccc1aa | 2010-09-17 22:28:18 +0000 | [diff] [blame] | 1235 | case CmpInst::ICMP_SLE: |
| 1236 | case CmpInst::FCMP_ULE: |
| 1237 | return ARMCC::LE; |
| 1238 | case CmpInst::FCMP_UNE: |
| 1239 | case CmpInst::ICMP_NE: |
| 1240 | return ARMCC::NE; |
| 1241 | case CmpInst::ICMP_UGE: |
| 1242 | return ARMCC::HS; |
| 1243 | case CmpInst::ICMP_ULT: |
| 1244 | return ARMCC::LO; |
| 1245 | } |
Eric Christopher | fde5a3d | 2010-09-01 22:16:27 +0000 | [diff] [blame] | 1246 | } |
| 1247 | |
Eric Christopher | 29ab6d1 | 2010-09-27 06:02:23 +0000 | [diff] [blame] | 1248 | bool ARMFastISel::SelectBranch(const Instruction *I) { |
Eric Christopher | 6aaed72 | 2010-09-03 00:35:47 +0000 | [diff] [blame] | 1249 | const BranchInst *BI = cast<BranchInst>(I); |
| 1250 | MachineBasicBlock *TBB = FuncInfo.MBBMap[BI->getSuccessor(0)]; |
| 1251 | MachineBasicBlock *FBB = FuncInfo.MBBMap[BI->getSuccessor(1)]; |
Eric Christopher | 2ff757d | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 1252 | |
Eric Christopher | 6aaed72 | 2010-09-03 00:35:47 +0000 | [diff] [blame] | 1253 | // Simple branch support. |
Jim Grosbach | 68147ee | 2010-11-09 19:22:26 +0000 | [diff] [blame] | 1254 | |
Eric Christopher | 5c308f8 | 2010-10-29 21:08:19 +0000 | [diff] [blame] | 1255 | // If we can, avoid recomputing the compare - redoing it could lead to wonky |
| 1256 | // behavior. |
Eric Christopher | 5c308f8 | 2010-10-29 21:08:19 +0000 | [diff] [blame] | 1257 | if (const CmpInst *CI = dyn_cast<CmpInst>(BI->getCondition())) { |
Chad Rosier | eafbf3f | 2011-10-26 23:17:28 +0000 | [diff] [blame] | 1258 | if (CI->hasOneUse() && (CI->getParent() == I->getParent())) { |
Eric Christopher | 5c308f8 | 2010-10-29 21:08:19 +0000 | [diff] [blame] | 1259 | |
| 1260 | // Get the compare predicate. |
Eric Christopher | 26b8ac4 | 2011-04-29 21:56:31 +0000 | [diff] [blame] | 1261 | // Try to take advantage of fallthrough opportunities. |
| 1262 | CmpInst::Predicate Predicate = CI->getPredicate(); |
| 1263 | if (FuncInfo.MBB->isLayoutSuccessor(TBB)) { |
| 1264 | std::swap(TBB, FBB); |
| 1265 | Predicate = CmpInst::getInversePredicate(Predicate); |
| 1266 | } |
| 1267 | |
| 1268 | ARMCC::CondCodes ARMPred = getComparePred(Predicate); |
Eric Christopher | 5c308f8 | 2010-10-29 21:08:19 +0000 | [diff] [blame] | 1269 | |
| 1270 | // We may not handle every CC for now. |
| 1271 | if (ARMPred == ARMCC::AL) return false; |
| 1272 | |
Chad Rosier | eafbf3f | 2011-10-26 23:17:28 +0000 | [diff] [blame] | 1273 | // Emit the compare. |
David Blaikie | 3ef249c9 | 2015-01-30 23:04:39 +0000 | [diff] [blame] | 1274 | if (!ARMEmitCmp(CI->getOperand(0), CI->getOperand(1), CI->isUnsigned())) |
Chad Rosier | eafbf3f | 2011-10-26 23:17:28 +0000 | [diff] [blame] | 1275 | return false; |
Jim Grosbach | 68147ee | 2010-11-09 19:22:26 +0000 | [diff] [blame] | 1276 | |
Chad Rosier | 0439cfc | 2011-11-08 21:12:00 +0000 | [diff] [blame] | 1277 | unsigned BrOpc = isThumb2 ? ARM::t2Bcc : ARM::Bcc; |
Rafael Espindola | ea09c59 | 2014-02-18 22:05:46 +0000 | [diff] [blame] | 1278 | BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, TII.get(BrOpc)) |
Eric Christopher | 5c308f8 | 2010-10-29 21:08:19 +0000 | [diff] [blame] | 1279 | .addMBB(TBB).addImm(ARMPred).addReg(ARM::CPSR); |
Juergen Ributzka | 5b8bb4d | 2014-09-03 20:56:52 +0000 | [diff] [blame] | 1280 | fastEmitBranch(FBB, DbgLoc); |
Eric Christopher | 5c308f8 | 2010-10-29 21:08:19 +0000 | [diff] [blame] | 1281 | FuncInfo.MBB->addSuccessor(TBB); |
| 1282 | return true; |
| 1283 | } |
Eric Christopher | 8d46b47 | 2011-04-29 20:02:39 +0000 | [diff] [blame] | 1284 | } else if (TruncInst *TI = dyn_cast<TruncInst>(BI->getCondition())) { |
| 1285 | MVT SourceVT; |
| 1286 | if (TI->hasOneUse() && TI->getParent() == I->getParent() && |
Eli Friedman | c703551 | 2011-05-25 23:49:02 +0000 | [diff] [blame] | 1287 | (isLoadTypeLegal(TI->getOperand(0)->getType(), SourceVT))) { |
Chad Rosier | 0439cfc | 2011-11-08 21:12:00 +0000 | [diff] [blame] | 1288 | unsigned TstOpc = isThumb2 ? ARM::t2TSTri : ARM::TSTri; |
Eric Christopher | 8d46b47 | 2011-04-29 20:02:39 +0000 | [diff] [blame] | 1289 | unsigned OpReg = getRegForValue(TI->getOperand(0)); |
Jim Grosbach | 667b147 | 2013-08-26 20:22:05 +0000 | [diff] [blame] | 1290 | OpReg = constrainOperandRegClass(TII.get(TstOpc), OpReg, 0); |
Rafael Espindola | ea09c59 | 2014-02-18 22:05:46 +0000 | [diff] [blame] | 1291 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, |
Eric Christopher | 8d46b47 | 2011-04-29 20:02:39 +0000 | [diff] [blame] | 1292 | TII.get(TstOpc)) |
| 1293 | .addReg(OpReg).addImm(1)); |
| 1294 | |
| 1295 | unsigned CCMode = ARMCC::NE; |
| 1296 | if (FuncInfo.MBB->isLayoutSuccessor(TBB)) { |
| 1297 | std::swap(TBB, FBB); |
| 1298 | CCMode = ARMCC::EQ; |
| 1299 | } |
| 1300 | |
Chad Rosier | 0439cfc | 2011-11-08 21:12:00 +0000 | [diff] [blame] | 1301 | unsigned BrOpc = isThumb2 ? ARM::t2Bcc : ARM::Bcc; |
Rafael Espindola | ea09c59 | 2014-02-18 22:05:46 +0000 | [diff] [blame] | 1302 | BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, TII.get(BrOpc)) |
Eric Christopher | 8d46b47 | 2011-04-29 20:02:39 +0000 | [diff] [blame] | 1303 | .addMBB(TBB).addImm(CCMode).addReg(ARM::CPSR); |
| 1304 | |
Juergen Ributzka | 5b8bb4d | 2014-09-03 20:56:52 +0000 | [diff] [blame] | 1305 | fastEmitBranch(FBB, DbgLoc); |
Eric Christopher | 8d46b47 | 2011-04-29 20:02:39 +0000 | [diff] [blame] | 1306 | FuncInfo.MBB->addSuccessor(TBB); |
| 1307 | return true; |
| 1308 | } |
Chad Rosier | d24e7e1d | 2011-10-27 00:21:16 +0000 | [diff] [blame] | 1309 | } else if (const ConstantInt *CI = |
| 1310 | dyn_cast<ConstantInt>(BI->getCondition())) { |
| 1311 | uint64_t Imm = CI->getZExtValue(); |
| 1312 | MachineBasicBlock *Target = (Imm == 0) ? FBB : TBB; |
Juergen Ributzka | 5b8bb4d | 2014-09-03 20:56:52 +0000 | [diff] [blame] | 1313 | fastEmitBranch(Target, DbgLoc); |
Chad Rosier | d24e7e1d | 2011-10-27 00:21:16 +0000 | [diff] [blame] | 1314 | return true; |
Eric Christopher | 5c308f8 | 2010-10-29 21:08:19 +0000 | [diff] [blame] | 1315 | } |
Jim Grosbach | 68147ee | 2010-11-09 19:22:26 +0000 | [diff] [blame] | 1316 | |
Eric Christopher | 5c308f8 | 2010-10-29 21:08:19 +0000 | [diff] [blame] | 1317 | unsigned CmpReg = getRegForValue(BI->getCondition()); |
| 1318 | if (CmpReg == 0) return false; |
Eric Christopher | 2ff757d | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 1319 | |
Stuart Hastings | ebddfe6 | 2011-04-16 03:31:26 +0000 | [diff] [blame] | 1320 | // We've been divorced from our compare! Our block was split, and |
| 1321 | // now our compare lives in a predecessor block. We musn't |
| 1322 | // re-compare here, as the children of the compare aren't guaranteed |
| 1323 | // live across the block boundary (we *could* check for this). |
| 1324 | // Regardless, the compare has been done in the predecessor block, |
| 1325 | // and it left a value for us in a virtual register. Ergo, we test |
| 1326 | // the one-bit value left in the virtual register. |
Chad Rosier | 0439cfc | 2011-11-08 21:12:00 +0000 | [diff] [blame] | 1327 | unsigned TstOpc = isThumb2 ? ARM::t2TSTri : ARM::TSTri; |
Jim Grosbach | 667b147 | 2013-08-26 20:22:05 +0000 | [diff] [blame] | 1328 | CmpReg = constrainOperandRegClass(TII.get(TstOpc), CmpReg, 0); |
Rafael Espindola | ea09c59 | 2014-02-18 22:05:46 +0000 | [diff] [blame] | 1329 | AddOptionalDefs( |
| 1330 | BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, TII.get(TstOpc)) |
| 1331 | .addReg(CmpReg) |
| 1332 | .addImm(1)); |
Eric Christopher | 7ac602b | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1333 | |
Eric Christopher | 4f012fd | 2011-04-28 16:52:09 +0000 | [diff] [blame] | 1334 | unsigned CCMode = ARMCC::NE; |
| 1335 | if (FuncInfo.MBB->isLayoutSuccessor(TBB)) { |
| 1336 | std::swap(TBB, FBB); |
| 1337 | CCMode = ARMCC::EQ; |
| 1338 | } |
| 1339 | |
Chad Rosier | 0439cfc | 2011-11-08 21:12:00 +0000 | [diff] [blame] | 1340 | unsigned BrOpc = isThumb2 ? ARM::t2Bcc : ARM::Bcc; |
Rafael Espindola | ea09c59 | 2014-02-18 22:05:46 +0000 | [diff] [blame] | 1341 | BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, TII.get(BrOpc)) |
Eric Christopher | 4f012fd | 2011-04-28 16:52:09 +0000 | [diff] [blame] | 1342 | .addMBB(TBB).addImm(CCMode).addReg(ARM::CPSR); |
Juergen Ributzka | 5b8bb4d | 2014-09-03 20:56:52 +0000 | [diff] [blame] | 1343 | fastEmitBranch(FBB, DbgLoc); |
Eric Christopher | 6aaed72 | 2010-09-03 00:35:47 +0000 | [diff] [blame] | 1344 | FuncInfo.MBB->addSuccessor(TBB); |
Eric Christopher | 7ac602b | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1345 | return true; |
Eric Christopher | 6aaed72 | 2010-09-03 00:35:47 +0000 | [diff] [blame] | 1346 | } |
| 1347 | |
Chad Rosier | ded4c99 | 2012-02-07 23:56:08 +0000 | [diff] [blame] | 1348 | bool ARMFastISel::SelectIndirectBr(const Instruction *I) { |
| 1349 | unsigned AddrReg = getRegForValue(I->getOperand(0)); |
| 1350 | if (AddrReg == 0) return false; |
| 1351 | |
| 1352 | unsigned Opc = isThumb2 ? ARM::tBRIND : ARM::BX; |
Rafael Espindola | ea09c59 | 2014-02-18 22:05:46 +0000 | [diff] [blame] | 1353 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, |
| 1354 | TII.get(Opc)).addReg(AddrReg)); |
Bill Wendling | 12cda50 | 2012-10-22 23:30:04 +0000 | [diff] [blame] | 1355 | |
| 1356 | const IndirectBrInst *IB = cast<IndirectBrInst>(I); |
| 1357 | for (unsigned i = 0, e = IB->getNumSuccessors(); i != e; ++i) |
| 1358 | FuncInfo.MBB->addSuccessor(FuncInfo.MBBMap[IB->getSuccessor(i)]); |
| 1359 | |
Jush Lu | ac96b76 | 2012-06-14 06:08:19 +0000 | [diff] [blame] | 1360 | return true; |
Chad Rosier | ded4c99 | 2012-02-07 23:56:08 +0000 | [diff] [blame] | 1361 | } |
| 1362 | |
Chad Rosier | 9cf803c | 2011-11-02 18:08:25 +0000 | [diff] [blame] | 1363 | bool ARMFastISel::ARMEmitCmp(const Value *Src1Value, const Value *Src2Value, |
David Blaikie | 3ef249c9 | 2015-01-30 23:04:39 +0000 | [diff] [blame] | 1364 | bool isZExt) { |
Chad Rosier | 78127d3 | 2011-10-26 23:25:44 +0000 | [diff] [blame] | 1365 | Type *Ty = Src1Value->getType(); |
Patrik Hagglund | c494d24 | 2012-12-17 14:30:06 +0000 | [diff] [blame] | 1366 | EVT SrcEVT = TLI.getValueType(Ty, true); |
| 1367 | if (!SrcEVT.isSimple()) return false; |
| 1368 | MVT SrcVT = SrcEVT.getSimpleVT(); |
Eric Christopher | 2ff757d | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 1369 | |
Chad Rosier | 78127d3 | 2011-10-26 23:25:44 +0000 | [diff] [blame] | 1370 | bool isFloat = (Ty->isFloatTy() || Ty->isDoubleTy()); |
| 1371 | if (isFloat && !Subtarget->hasVFP2()) |
Eric Christopher | c3e9c40 | 2010-09-08 23:13:45 +0000 | [diff] [blame] | 1372 | return false; |
Eric Christopher | 2ff757d | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 1373 | |
Chad Rosier | 595d419 | 2011-11-09 03:22:02 +0000 | [diff] [blame] | 1374 | // Check to see if the 2nd operand is a constant that we can encode directly |
| 1375 | // in the compare. |
Chad Rosier | e19b0a9 | 2011-11-11 06:27:41 +0000 | [diff] [blame] | 1376 | int Imm = 0; |
| 1377 | bool UseImm = false; |
Chad Rosier | 595d419 | 2011-11-09 03:22:02 +0000 | [diff] [blame] | 1378 | bool isNegativeImm = false; |
Chad Rosier | af13d76 | 2011-11-16 00:32:20 +0000 | [diff] [blame] | 1379 | // FIXME: At -O0 we don't have anything that canonicalizes operand order. |
| 1380 | // Thus, Src1Value may be a ConstantInt, but we're missing it. |
Chad Rosier | 595d419 | 2011-11-09 03:22:02 +0000 | [diff] [blame] | 1381 | if (const ConstantInt *ConstInt = dyn_cast<ConstantInt>(Src2Value)) { |
| 1382 | if (SrcVT == MVT::i32 || SrcVT == MVT::i16 || SrcVT == MVT::i8 || |
| 1383 | SrcVT == MVT::i1) { |
| 1384 | const APInt &CIVal = ConstInt->getValue(); |
Chad Rosier | e19b0a9 | 2011-11-11 06:27:41 +0000 | [diff] [blame] | 1385 | Imm = (isZExt) ? (int)CIVal.getZExtValue() : (int)CIVal.getSExtValue(); |
Chad Rosier | 26d0588 | 2012-03-15 22:54:20 +0000 | [diff] [blame] | 1386 | // For INT_MIN/LONG_MIN (i.e., 0x80000000) we need to use a cmp, rather |
Jim Grosbach | 1a59711 | 2014-04-03 23:43:18 +0000 | [diff] [blame] | 1387 | // then a cmn, because there is no way to represent 2147483648 as a |
Chad Rosier | 26d0588 | 2012-03-15 22:54:20 +0000 | [diff] [blame] | 1388 | // signed 32-bit int. |
| 1389 | if (Imm < 0 && Imm != (int)0x80000000) { |
| 1390 | isNegativeImm = true; |
| 1391 | Imm = -Imm; |
Chad Rosier | 3fbd094 | 2011-11-10 01:30:39 +0000 | [diff] [blame] | 1392 | } |
Chad Rosier | 26d0588 | 2012-03-15 22:54:20 +0000 | [diff] [blame] | 1393 | UseImm = isThumb2 ? (ARM_AM::getT2SOImmVal(Imm) != -1) : |
| 1394 | (ARM_AM::getSOImmVal(Imm) != -1); |
Chad Rosier | 595d419 | 2011-11-09 03:22:02 +0000 | [diff] [blame] | 1395 | } |
| 1396 | } else if (const ConstantFP *ConstFP = dyn_cast<ConstantFP>(Src2Value)) { |
| 1397 | if (SrcVT == MVT::f32 || SrcVT == MVT::f64) |
| 1398 | if (ConstFP->isZero() && !ConstFP->isNegative()) |
Chad Rosier | e19b0a9 | 2011-11-11 06:27:41 +0000 | [diff] [blame] | 1399 | UseImm = true; |
Chad Rosier | 595d419 | 2011-11-09 03:22:02 +0000 | [diff] [blame] | 1400 | } |
| 1401 | |
Eric Christopher | c3e9c40 | 2010-09-08 23:13:45 +0000 | [diff] [blame] | 1402 | unsigned CmpOpc; |
Chad Rosier | 595d419 | 2011-11-09 03:22:02 +0000 | [diff] [blame] | 1403 | bool isICmp = true; |
Chad Rosier | 9cf803c | 2011-11-02 18:08:25 +0000 | [diff] [blame] | 1404 | bool needsExt = false; |
Patrik Hagglund | 5e6c361 | 2012-12-13 06:34:11 +0000 | [diff] [blame] | 1405 | switch (SrcVT.SimpleTy) { |
Eric Christopher | c3e9c40 | 2010-09-08 23:13:45 +0000 | [diff] [blame] | 1406 | default: return false; |
| 1407 | // TODO: Verify compares. |
| 1408 | case MVT::f32: |
Chad Rosier | 595d419 | 2011-11-09 03:22:02 +0000 | [diff] [blame] | 1409 | isICmp = false; |
Chad Rosier | e19b0a9 | 2011-11-11 06:27:41 +0000 | [diff] [blame] | 1410 | CmpOpc = UseImm ? ARM::VCMPEZS : ARM::VCMPES; |
Eric Christopher | c3e9c40 | 2010-09-08 23:13:45 +0000 | [diff] [blame] | 1411 | break; |
| 1412 | case MVT::f64: |
Chad Rosier | 595d419 | 2011-11-09 03:22:02 +0000 | [diff] [blame] | 1413 | isICmp = false; |
Chad Rosier | e19b0a9 | 2011-11-11 06:27:41 +0000 | [diff] [blame] | 1414 | CmpOpc = UseImm ? ARM::VCMPEZD : ARM::VCMPED; |
Eric Christopher | c3e9c40 | 2010-09-08 23:13:45 +0000 | [diff] [blame] | 1415 | break; |
Chad Rosier | 9cf803c | 2011-11-02 18:08:25 +0000 | [diff] [blame] | 1416 | case MVT::i1: |
| 1417 | case MVT::i8: |
| 1418 | case MVT::i16: |
| 1419 | needsExt = true; |
| 1420 | // Intentional fall-through. |
Eric Christopher | c3e9c40 | 2010-09-08 23:13:45 +0000 | [diff] [blame] | 1421 | case MVT::i32: |
Chad Rosier | 595d419 | 2011-11-09 03:22:02 +0000 | [diff] [blame] | 1422 | if (isThumb2) { |
Chad Rosier | e19b0a9 | 2011-11-11 06:27:41 +0000 | [diff] [blame] | 1423 | if (!UseImm) |
Chad Rosier | 595d419 | 2011-11-09 03:22:02 +0000 | [diff] [blame] | 1424 | CmpOpc = ARM::t2CMPrr; |
| 1425 | else |
Bill Wendling | 4b79647 | 2012-06-11 08:07:26 +0000 | [diff] [blame] | 1426 | CmpOpc = isNegativeImm ? ARM::t2CMNri : ARM::t2CMPri; |
Chad Rosier | 595d419 | 2011-11-09 03:22:02 +0000 | [diff] [blame] | 1427 | } else { |
Chad Rosier | e19b0a9 | 2011-11-11 06:27:41 +0000 | [diff] [blame] | 1428 | if (!UseImm) |
Chad Rosier | 595d419 | 2011-11-09 03:22:02 +0000 | [diff] [blame] | 1429 | CmpOpc = ARM::CMPrr; |
| 1430 | else |
Bill Wendling | 4b79647 | 2012-06-11 08:07:26 +0000 | [diff] [blame] | 1431 | CmpOpc = isNegativeImm ? ARM::CMNri : ARM::CMPri; |
Chad Rosier | 595d419 | 2011-11-09 03:22:02 +0000 | [diff] [blame] | 1432 | } |
Eric Christopher | c3e9c40 | 2010-09-08 23:13:45 +0000 | [diff] [blame] | 1433 | break; |
| 1434 | } |
| 1435 | |
Chad Rosier | 9cf803c | 2011-11-02 18:08:25 +0000 | [diff] [blame] | 1436 | unsigned SrcReg1 = getRegForValue(Src1Value); |
| 1437 | if (SrcReg1 == 0) return false; |
Chad Rosier | 59a2019 | 2011-10-26 22:47:55 +0000 | [diff] [blame] | 1438 | |
Duncan Sands | 1233065 | 2011-11-28 10:31:27 +0000 | [diff] [blame] | 1439 | unsigned SrcReg2 = 0; |
Chad Rosier | e19b0a9 | 2011-11-11 06:27:41 +0000 | [diff] [blame] | 1440 | if (!UseImm) { |
Chad Rosier | 595d419 | 2011-11-09 03:22:02 +0000 | [diff] [blame] | 1441 | SrcReg2 = getRegForValue(Src2Value); |
| 1442 | if (SrcReg2 == 0) return false; |
| 1443 | } |
Chad Rosier | 9cf803c | 2011-11-02 18:08:25 +0000 | [diff] [blame] | 1444 | |
| 1445 | // We have i1, i8, or i16, we need to either zero extend or sign extend. |
| 1446 | if (needsExt) { |
Chad Rosier | a0d3c75 | 2012-02-16 22:45:33 +0000 | [diff] [blame] | 1447 | SrcReg1 = ARMEmitIntExt(SrcVT, SrcReg1, MVT::i32, isZExt); |
| 1448 | if (SrcReg1 == 0) return false; |
Chad Rosier | e19b0a9 | 2011-11-11 06:27:41 +0000 | [diff] [blame] | 1449 | if (!UseImm) { |
Chad Rosier | a0d3c75 | 2012-02-16 22:45:33 +0000 | [diff] [blame] | 1450 | SrcReg2 = ARMEmitIntExt(SrcVT, SrcReg2, MVT::i32, isZExt); |
| 1451 | if (SrcReg2 == 0) return false; |
Chad Rosier | 595d419 | 2011-11-09 03:22:02 +0000 | [diff] [blame] | 1452 | } |
Chad Rosier | 9cf803c | 2011-11-02 18:08:25 +0000 | [diff] [blame] | 1453 | } |
Chad Rosier | 59a2019 | 2011-10-26 22:47:55 +0000 | [diff] [blame] | 1454 | |
Jim Grosbach | d786679 | 2013-08-16 23:37:40 +0000 | [diff] [blame] | 1455 | const MCInstrDesc &II = TII.get(CmpOpc); |
| 1456 | SrcReg1 = constrainOperandRegClass(II, SrcReg1, 0); |
Chad Rosier | e19b0a9 | 2011-11-11 06:27:41 +0000 | [diff] [blame] | 1457 | if (!UseImm) { |
Jim Grosbach | d786679 | 2013-08-16 23:37:40 +0000 | [diff] [blame] | 1458 | SrcReg2 = constrainOperandRegClass(II, SrcReg2, 1); |
David Blaikie | 3ef249c9 | 2015-01-30 23:04:39 +0000 | [diff] [blame] | 1459 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, II) |
Chad Rosier | 595d419 | 2011-11-09 03:22:02 +0000 | [diff] [blame] | 1460 | .addReg(SrcReg1).addReg(SrcReg2)); |
| 1461 | } else { |
| 1462 | MachineInstrBuilder MIB; |
David Blaikie | 3ef249c9 | 2015-01-30 23:04:39 +0000 | [diff] [blame] | 1463 | MIB = BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, II) |
Chad Rosier | 595d419 | 2011-11-09 03:22:02 +0000 | [diff] [blame] | 1464 | .addReg(SrcReg1); |
| 1465 | |
| 1466 | // Only add immediate for icmp as the immediate for fcmp is an implicit 0.0. |
| 1467 | if (isICmp) |
Chad Rosier | e19b0a9 | 2011-11-11 06:27:41 +0000 | [diff] [blame] | 1468 | MIB.addImm(Imm); |
Chad Rosier | 595d419 | 2011-11-09 03:22:02 +0000 | [diff] [blame] | 1469 | AddOptionalDefs(MIB); |
| 1470 | } |
Chad Rosier | 78127d3 | 2011-10-26 23:25:44 +0000 | [diff] [blame] | 1471 | |
| 1472 | // For floating point we need to move the result to a comparison register |
| 1473 | // that we can then use for branches. |
| 1474 | if (Ty->isFloatTy() || Ty->isDoubleTy()) |
David Blaikie | 3ef249c9 | 2015-01-30 23:04:39 +0000 | [diff] [blame] | 1475 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, |
Chad Rosier | 78127d3 | 2011-10-26 23:25:44 +0000 | [diff] [blame] | 1476 | TII.get(ARM::FMSTAT))); |
Chad Rosier | 59a2019 | 2011-10-26 22:47:55 +0000 | [diff] [blame] | 1477 | return true; |
| 1478 | } |
| 1479 | |
| 1480 | bool ARMFastISel::SelectCmp(const Instruction *I) { |
| 1481 | const CmpInst *CI = cast<CmpInst>(I); |
| 1482 | |
Eric Christopher | 3a7e8cd | 2010-09-29 01:14:47 +0000 | [diff] [blame] | 1483 | // Get the compare predicate. |
| 1484 | ARMCC::CondCodes ARMPred = getComparePred(CI->getPredicate()); |
Eric Christopher | 7ac602b | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1485 | |
Eric Christopher | 3a7e8cd | 2010-09-29 01:14:47 +0000 | [diff] [blame] | 1486 | // We may not handle every CC for now. |
| 1487 | if (ARMPred == ARMCC::AL) return false; |
| 1488 | |
Chad Rosier | 59a2019 | 2011-10-26 22:47:55 +0000 | [diff] [blame] | 1489 | // Emit the compare. |
David Blaikie | 3ef249c9 | 2015-01-30 23:04:39 +0000 | [diff] [blame] | 1490 | if (!ARMEmitCmp(CI->getOperand(0), CI->getOperand(1), CI->isUnsigned())) |
Chad Rosier | 59a2019 | 2011-10-26 22:47:55 +0000 | [diff] [blame] | 1491 | return false; |
Eric Christopher | 2ff757d | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 1492 | |
Eric Christopher | 3a7e8cd | 2010-09-29 01:14:47 +0000 | [diff] [blame] | 1493 | // Now set a register based on the comparison. Explicitly set the predicates |
| 1494 | // here. |
Chad Rosier | 0439cfc | 2011-11-08 21:12:00 +0000 | [diff] [blame] | 1495 | unsigned MovCCOpc = isThumb2 ? ARM::t2MOVCCi : ARM::MOVCCi; |
Craig Topper | 61e88f4 | 2014-11-21 05:58:21 +0000 | [diff] [blame] | 1496 | const TargetRegisterClass *RC = isThumb2 ? &ARM::rGPRRegClass |
| 1497 | : &ARM::GPRRegClass; |
Eric Christopher | 76a9752 | 2010-10-07 05:39:19 +0000 | [diff] [blame] | 1498 | unsigned DestReg = createResultReg(RC); |
Chad Rosier | 78127d3 | 2011-10-26 23:25:44 +0000 | [diff] [blame] | 1499 | Constant *Zero = ConstantInt::get(Type::getInt32Ty(*Context), 0); |
Juergen Ributzka | 5b8bb4d | 2014-09-03 20:56:52 +0000 | [diff] [blame] | 1500 | unsigned ZeroReg = fastMaterializeConstant(Zero); |
Chad Rosier | 377f1f2 | 2012-03-07 20:59:26 +0000 | [diff] [blame] | 1501 | // ARMEmitCmp emits a FMSTAT when necessary, so it's always safe to use CPSR. |
Rafael Espindola | ea09c59 | 2014-02-18 22:05:46 +0000 | [diff] [blame] | 1502 | BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, TII.get(MovCCOpc), DestReg) |
Eric Christopher | 3a7e8cd | 2010-09-29 01:14:47 +0000 | [diff] [blame] | 1503 | .addReg(ZeroReg).addImm(1) |
Chad Rosier | 377f1f2 | 2012-03-07 20:59:26 +0000 | [diff] [blame] | 1504 | .addImm(ARMPred).addReg(ARM::CPSR); |
Eric Christopher | 3a7e8cd | 2010-09-29 01:14:47 +0000 | [diff] [blame] | 1505 | |
Juergen Ributzka | 5b8bb4d | 2014-09-03 20:56:52 +0000 | [diff] [blame] | 1506 | updateValueMap(I, DestReg); |
Eric Christopher | c3e9c40 | 2010-09-08 23:13:45 +0000 | [diff] [blame] | 1507 | return true; |
| 1508 | } |
| 1509 | |
Eric Christopher | 29ab6d1 | 2010-09-27 06:02:23 +0000 | [diff] [blame] | 1510 | bool ARMFastISel::SelectFPExt(const Instruction *I) { |
Eric Christopher | f14b9bf | 2010-09-09 00:26:48 +0000 | [diff] [blame] | 1511 | // Make sure we have VFP and that we're extending float to double. |
| 1512 | if (!Subtarget->hasVFP2()) return false; |
Eric Christopher | 2ff757d | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 1513 | |
Eric Christopher | f14b9bf | 2010-09-09 00:26:48 +0000 | [diff] [blame] | 1514 | Value *V = I->getOperand(0); |
| 1515 | if (!I->getType()->isDoubleTy() || |
| 1516 | !V->getType()->isFloatTy()) return false; |
Eric Christopher | 2ff757d | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 1517 | |
Eric Christopher | f14b9bf | 2010-09-09 00:26:48 +0000 | [diff] [blame] | 1518 | unsigned Op = getRegForValue(V); |
| 1519 | if (Op == 0) return false; |
Eric Christopher | 2ff757d | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 1520 | |
Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 1521 | unsigned Result = createResultReg(&ARM::DPRRegClass); |
Rafael Espindola | ea09c59 | 2014-02-18 22:05:46 +0000 | [diff] [blame] | 1522 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, |
Eric Christopher | 82b05d7 | 2010-09-09 20:36:19 +0000 | [diff] [blame] | 1523 | TII.get(ARM::VCVTDS), Result) |
Eric Christopher | 5903c0b | 2010-09-09 20:26:31 +0000 | [diff] [blame] | 1524 | .addReg(Op)); |
Juergen Ributzka | 5b8bb4d | 2014-09-03 20:56:52 +0000 | [diff] [blame] | 1525 | updateValueMap(I, Result); |
Eric Christopher | 5903c0b | 2010-09-09 20:26:31 +0000 | [diff] [blame] | 1526 | return true; |
| 1527 | } |
| 1528 | |
Eric Christopher | 29ab6d1 | 2010-09-27 06:02:23 +0000 | [diff] [blame] | 1529 | bool ARMFastISel::SelectFPTrunc(const Instruction *I) { |
Eric Christopher | 5903c0b | 2010-09-09 20:26:31 +0000 | [diff] [blame] | 1530 | // Make sure we have VFP and that we're truncating double to float. |
| 1531 | if (!Subtarget->hasVFP2()) return false; |
| 1532 | |
| 1533 | Value *V = I->getOperand(0); |
Eric Christopher | 8cfc459 | 2010-10-05 23:13:24 +0000 | [diff] [blame] | 1534 | if (!(I->getType()->isFloatTy() && |
| 1535 | V->getType()->isDoubleTy())) return false; |
Eric Christopher | 5903c0b | 2010-09-09 20:26:31 +0000 | [diff] [blame] | 1536 | |
| 1537 | unsigned Op = getRegForValue(V); |
| 1538 | if (Op == 0) return false; |
| 1539 | |
Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 1540 | unsigned Result = createResultReg(&ARM::SPRRegClass); |
Rafael Espindola | ea09c59 | 2014-02-18 22:05:46 +0000 | [diff] [blame] | 1541 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, |
Eric Christopher | 82b05d7 | 2010-09-09 20:36:19 +0000 | [diff] [blame] | 1542 | TII.get(ARM::VCVTSD), Result) |
Eric Christopher | f14b9bf | 2010-09-09 00:26:48 +0000 | [diff] [blame] | 1543 | .addReg(Op)); |
Juergen Ributzka | 5b8bb4d | 2014-09-03 20:56:52 +0000 | [diff] [blame] | 1544 | updateValueMap(I, Result); |
Eric Christopher | f14b9bf | 2010-09-09 00:26:48 +0000 | [diff] [blame] | 1545 | return true; |
| 1546 | } |
| 1547 | |
Chad Rosier | e023d5d | 2012-02-03 21:14:11 +0000 | [diff] [blame] | 1548 | bool ARMFastISel::SelectIToFP(const Instruction *I, bool isSigned) { |
Eric Christopher | 6e3eeba | 2010-09-09 18:54:59 +0000 | [diff] [blame] | 1549 | // Make sure we have VFP. |
| 1550 | if (!Subtarget->hasVFP2()) return false; |
Eric Christopher | 7ac602b | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1551 | |
Duncan Sands | f5dda01 | 2010-11-03 11:35:31 +0000 | [diff] [blame] | 1552 | MVT DstVT; |
Chris Lattner | 229907c | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 1553 | Type *Ty = I->getType(); |
Eric Christopher | 4bd7047 | 2010-09-09 21:44:45 +0000 | [diff] [blame] | 1554 | if (!isTypeLegal(Ty, DstVT)) |
Eric Christopher | 6e3eeba | 2010-09-09 18:54:59 +0000 | [diff] [blame] | 1555 | return false; |
Eric Christopher | 7ac602b | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1556 | |
Chad Rosier | bf5f4be | 2011-11-03 02:04:59 +0000 | [diff] [blame] | 1557 | Value *Src = I->getOperand(0); |
Patrik Hagglund | c494d24 | 2012-12-17 14:30:06 +0000 | [diff] [blame] | 1558 | EVT SrcEVT = TLI.getValueType(Src->getType(), true); |
| 1559 | if (!SrcEVT.isSimple()) |
| 1560 | return false; |
| 1561 | MVT SrcVT = SrcEVT.getSimpleVT(); |
Chad Rosier | bf5f4be | 2011-11-03 02:04:59 +0000 | [diff] [blame] | 1562 | if (SrcVT != MVT::i32 && SrcVT != MVT::i16 && SrcVT != MVT::i8) |
Eli Friedman | 5bbb756 | 2011-05-25 19:09:45 +0000 | [diff] [blame] | 1563 | return false; |
| 1564 | |
Chad Rosier | bf5f4be | 2011-11-03 02:04:59 +0000 | [diff] [blame] | 1565 | unsigned SrcReg = getRegForValue(Src); |
| 1566 | if (SrcReg == 0) return false; |
| 1567 | |
| 1568 | // Handle sign-extension. |
| 1569 | if (SrcVT == MVT::i16 || SrcVT == MVT::i8) { |
Chad Rosier | 62a144f | 2012-12-17 19:59:43 +0000 | [diff] [blame] | 1570 | SrcReg = ARMEmitIntExt(SrcVT, SrcReg, MVT::i32, |
Chad Rosier | e023d5d | 2012-02-03 21:14:11 +0000 | [diff] [blame] | 1571 | /*isZExt*/!isSigned); |
Chad Rosier | a0d3c75 | 2012-02-16 22:45:33 +0000 | [diff] [blame] | 1572 | if (SrcReg == 0) return false; |
Chad Rosier | bf5f4be | 2011-11-03 02:04:59 +0000 | [diff] [blame] | 1573 | } |
Eric Christopher | 7ac602b | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1574 | |
Eric Christopher | 860fc93 | 2010-09-10 00:34:35 +0000 | [diff] [blame] | 1575 | // The conversion routine works on fp-reg to fp-reg and the operand above |
| 1576 | // was an integer, move it to the fp registers if possible. |
Chad Rosier | bf5f4be | 2011-11-03 02:04:59 +0000 | [diff] [blame] | 1577 | unsigned FP = ARMMoveToFPReg(MVT::f32, SrcReg); |
Eric Christopher | 4bd7047 | 2010-09-09 21:44:45 +0000 | [diff] [blame] | 1578 | if (FP == 0) return false; |
Eric Christopher | 7ac602b | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1579 | |
Eric Christopher | 6e3eeba | 2010-09-09 18:54:59 +0000 | [diff] [blame] | 1580 | unsigned Opc; |
Chad Rosier | e023d5d | 2012-02-03 21:14:11 +0000 | [diff] [blame] | 1581 | if (Ty->isFloatTy()) Opc = isSigned ? ARM::VSITOS : ARM::VUITOS; |
| 1582 | else if (Ty->isDoubleTy()) Opc = isSigned ? ARM::VSITOD : ARM::VUITOD; |
Chad Rosier | 17847ae | 2011-08-31 23:49:05 +0000 | [diff] [blame] | 1583 | else return false; |
Eric Christopher | 7ac602b | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1584 | |
Eric Christopher | 4bd7047 | 2010-09-09 21:44:45 +0000 | [diff] [blame] | 1585 | unsigned ResultReg = createResultReg(TLI.getRegClassFor(DstVT)); |
Rafael Espindola | ea09c59 | 2014-02-18 22:05:46 +0000 | [diff] [blame] | 1586 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, |
| 1587 | TII.get(Opc), ResultReg).addReg(FP)); |
Juergen Ributzka | 5b8bb4d | 2014-09-03 20:56:52 +0000 | [diff] [blame] | 1588 | updateValueMap(I, ResultReg); |
Eric Christopher | 6e3eeba | 2010-09-09 18:54:59 +0000 | [diff] [blame] | 1589 | return true; |
| 1590 | } |
| 1591 | |
Chad Rosier | e023d5d | 2012-02-03 21:14:11 +0000 | [diff] [blame] | 1592 | bool ARMFastISel::SelectFPToI(const Instruction *I, bool isSigned) { |
Eric Christopher | 6e3eeba | 2010-09-09 18:54:59 +0000 | [diff] [blame] | 1593 | // Make sure we have VFP. |
| 1594 | if (!Subtarget->hasVFP2()) return false; |
Eric Christopher | 7ac602b | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1595 | |
Duncan Sands | f5dda01 | 2010-11-03 11:35:31 +0000 | [diff] [blame] | 1596 | MVT DstVT; |
Chris Lattner | 229907c | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 1597 | Type *RetTy = I->getType(); |
Eric Christopher | 712bd0a | 2010-09-10 00:35:09 +0000 | [diff] [blame] | 1598 | if (!isTypeLegal(RetTy, DstVT)) |
Eric Christopher | 6e3eeba | 2010-09-09 18:54:59 +0000 | [diff] [blame] | 1599 | return false; |
Eric Christopher | 7ac602b | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1600 | |
Eric Christopher | 6e3eeba | 2010-09-09 18:54:59 +0000 | [diff] [blame] | 1601 | unsigned Op = getRegForValue(I->getOperand(0)); |
| 1602 | if (Op == 0) return false; |
Eric Christopher | 7ac602b | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1603 | |
Eric Christopher | 6e3eeba | 2010-09-09 18:54:59 +0000 | [diff] [blame] | 1604 | unsigned Opc; |
Chris Lattner | 229907c | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 1605 | Type *OpTy = I->getOperand(0)->getType(); |
Chad Rosier | e023d5d | 2012-02-03 21:14:11 +0000 | [diff] [blame] | 1606 | if (OpTy->isFloatTy()) Opc = isSigned ? ARM::VTOSIZS : ARM::VTOUIZS; |
| 1607 | else if (OpTy->isDoubleTy()) Opc = isSigned ? ARM::VTOSIZD : ARM::VTOUIZD; |
Chad Rosier | 17847ae | 2011-08-31 23:49:05 +0000 | [diff] [blame] | 1608 | else return false; |
Eric Christopher | 7ac602b | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1609 | |
Chad Rosier | 41f0e78 | 2012-02-03 20:27:51 +0000 | [diff] [blame] | 1610 | // f64->s32/u32 or f32->s32/u32 both need an intermediate f32 reg. |
Eric Christopher | 8cfc459 | 2010-10-05 23:13:24 +0000 | [diff] [blame] | 1611 | unsigned ResultReg = createResultReg(TLI.getRegClassFor(MVT::f32)); |
Rafael Espindola | ea09c59 | 2014-02-18 22:05:46 +0000 | [diff] [blame] | 1612 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, |
| 1613 | TII.get(Opc), ResultReg).addReg(Op)); |
Eric Christopher | 7ac602b | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1614 | |
Eric Christopher | 4bd7047 | 2010-09-09 21:44:45 +0000 | [diff] [blame] | 1615 | // This result needs to be in an integer register, but the conversion only |
| 1616 | // takes place in fp-regs. |
Eric Christopher | 860fc93 | 2010-09-10 00:34:35 +0000 | [diff] [blame] | 1617 | unsigned IntReg = ARMMoveToIntReg(DstVT, ResultReg); |
Eric Christopher | 4bd7047 | 2010-09-09 21:44:45 +0000 | [diff] [blame] | 1618 | if (IntReg == 0) return false; |
Eric Christopher | 7ac602b | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1619 | |
Juergen Ributzka | 5b8bb4d | 2014-09-03 20:56:52 +0000 | [diff] [blame] | 1620 | updateValueMap(I, IntReg); |
Eric Christopher | 6e3eeba | 2010-09-09 18:54:59 +0000 | [diff] [blame] | 1621 | return true; |
| 1622 | } |
| 1623 | |
Eric Christopher | 511aa31 | 2010-10-11 08:27:59 +0000 | [diff] [blame] | 1624 | bool ARMFastISel::SelectSelect(const Instruction *I) { |
Duncan Sands | f5dda01 | 2010-11-03 11:35:31 +0000 | [diff] [blame] | 1625 | MVT VT; |
| 1626 | if (!isTypeLegal(I->getType(), VT)) |
Eric Christopher | 511aa31 | 2010-10-11 08:27:59 +0000 | [diff] [blame] | 1627 | return false; |
| 1628 | |
| 1629 | // Things need to be register sized for register moves. |
Duncan Sands | f5dda01 | 2010-11-03 11:35:31 +0000 | [diff] [blame] | 1630 | if (VT != MVT::i32) return false; |
Eric Christopher | 511aa31 | 2010-10-11 08:27:59 +0000 | [diff] [blame] | 1631 | |
| 1632 | unsigned CondReg = getRegForValue(I->getOperand(0)); |
| 1633 | if (CondReg == 0) return false; |
| 1634 | unsigned Op1Reg = getRegForValue(I->getOperand(1)); |
| 1635 | if (Op1Reg == 0) return false; |
Eric Christopher | 511aa31 | 2010-10-11 08:27:59 +0000 | [diff] [blame] | 1636 | |
Chad Rosier | 7ddd63c | 2011-11-11 06:20:39 +0000 | [diff] [blame] | 1637 | // Check to see if we can use an immediate in the conditional move. |
| 1638 | int Imm = 0; |
| 1639 | bool UseImm = false; |
| 1640 | bool isNegativeImm = false; |
| 1641 | if (const ConstantInt *ConstInt = dyn_cast<ConstantInt>(I->getOperand(2))) { |
| 1642 | assert (VT == MVT::i32 && "Expecting an i32."); |
| 1643 | Imm = (int)ConstInt->getValue().getZExtValue(); |
| 1644 | if (Imm < 0) { |
| 1645 | isNegativeImm = true; |
| 1646 | Imm = ~Imm; |
| 1647 | } |
| 1648 | UseImm = isThumb2 ? (ARM_AM::getT2SOImmVal(Imm) != -1) : |
| 1649 | (ARM_AM::getSOImmVal(Imm) != -1); |
| 1650 | } |
| 1651 | |
Duncan Sands | 1233065 | 2011-11-28 10:31:27 +0000 | [diff] [blame] | 1652 | unsigned Op2Reg = 0; |
Chad Rosier | 7ddd63c | 2011-11-11 06:20:39 +0000 | [diff] [blame] | 1653 | if (!UseImm) { |
| 1654 | Op2Reg = getRegForValue(I->getOperand(2)); |
| 1655 | if (Op2Reg == 0) return false; |
| 1656 | } |
| 1657 | |
Ahmed Bougacha | e8d0c4c | 2015-05-06 04:14:02 +0000 | [diff] [blame] | 1658 | unsigned TstOpc = isThumb2 ? ARM::t2TSTri : ARM::TSTri; |
| 1659 | CondReg = constrainOperandRegClass(TII.get(TstOpc), CondReg, 0); |
Rafael Espindola | ea09c59 | 2014-02-18 22:05:46 +0000 | [diff] [blame] | 1660 | AddOptionalDefs( |
Ahmed Bougacha | e8d0c4c | 2015-05-06 04:14:02 +0000 | [diff] [blame] | 1661 | BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, TII.get(TstOpc)) |
Rafael Espindola | ea09c59 | 2014-02-18 22:05:46 +0000 | [diff] [blame] | 1662 | .addReg(CondReg) |
Ahmed Bougacha | e8d0c4c | 2015-05-06 04:14:02 +0000 | [diff] [blame] | 1663 | .addImm(1)); |
Chad Rosier | 7ddd63c | 2011-11-11 06:20:39 +0000 | [diff] [blame] | 1664 | |
| 1665 | unsigned MovCCOpc; |
Chad Rosier | 2ec7db0 | 2012-11-27 21:46:46 +0000 | [diff] [blame] | 1666 | const TargetRegisterClass *RC; |
Chad Rosier | 7ddd63c | 2011-11-11 06:20:39 +0000 | [diff] [blame] | 1667 | if (!UseImm) { |
Chad Rosier | 2ec7db0 | 2012-11-27 21:46:46 +0000 | [diff] [blame] | 1668 | RC = isThumb2 ? &ARM::tGPRRegClass : &ARM::GPRRegClass; |
Chad Rosier | 7ddd63c | 2011-11-11 06:20:39 +0000 | [diff] [blame] | 1669 | MovCCOpc = isThumb2 ? ARM::t2MOVCCr : ARM::MOVCCr; |
| 1670 | } else { |
Chad Rosier | 2ec7db0 | 2012-11-27 21:46:46 +0000 | [diff] [blame] | 1671 | RC = isThumb2 ? &ARM::rGPRRegClass : &ARM::GPRRegClass; |
| 1672 | if (!isNegativeImm) |
Chad Rosier | 7ddd63c | 2011-11-11 06:20:39 +0000 | [diff] [blame] | 1673 | MovCCOpc = isThumb2 ? ARM::t2MOVCCi : ARM::MOVCCi; |
Chad Rosier | 2ec7db0 | 2012-11-27 21:46:46 +0000 | [diff] [blame] | 1674 | else |
Chad Rosier | 7ddd63c | 2011-11-11 06:20:39 +0000 | [diff] [blame] | 1675 | MovCCOpc = isThumb2 ? ARM::t2MVNCCi : ARM::MVNCCi; |
Chad Rosier | 7ddd63c | 2011-11-11 06:20:39 +0000 | [diff] [blame] | 1676 | } |
Eric Christopher | 511aa31 | 2010-10-11 08:27:59 +0000 | [diff] [blame] | 1677 | unsigned ResultReg = createResultReg(RC); |
Jim Grosbach | d786679 | 2013-08-16 23:37:40 +0000 | [diff] [blame] | 1678 | if (!UseImm) { |
Jim Grosbach | 71a78f9 | 2013-08-20 19:12:42 +0000 | [diff] [blame] | 1679 | Op2Reg = constrainOperandRegClass(TII.get(MovCCOpc), Op2Reg, 1); |
Jim Grosbach | d786679 | 2013-08-16 23:37:40 +0000 | [diff] [blame] | 1680 | Op1Reg = constrainOperandRegClass(TII.get(MovCCOpc), Op1Reg, 2); |
Rafael Espindola | ea09c59 | 2014-02-18 22:05:46 +0000 | [diff] [blame] | 1681 | BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, TII.get(MovCCOpc), |
| 1682 | ResultReg) |
| 1683 | .addReg(Op2Reg) |
| 1684 | .addReg(Op1Reg) |
| 1685 | .addImm(ARMCC::NE) |
| 1686 | .addReg(ARM::CPSR); |
Jim Grosbach | d786679 | 2013-08-16 23:37:40 +0000 | [diff] [blame] | 1687 | } else { |
| 1688 | Op1Reg = constrainOperandRegClass(TII.get(MovCCOpc), Op1Reg, 1); |
Rafael Espindola | ea09c59 | 2014-02-18 22:05:46 +0000 | [diff] [blame] | 1689 | BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, TII.get(MovCCOpc), |
| 1690 | ResultReg) |
| 1691 | .addReg(Op1Reg) |
| 1692 | .addImm(Imm) |
| 1693 | .addImm(ARMCC::EQ) |
| 1694 | .addReg(ARM::CPSR); |
Jim Grosbach | d786679 | 2013-08-16 23:37:40 +0000 | [diff] [blame] | 1695 | } |
Juergen Ributzka | 5b8bb4d | 2014-09-03 20:56:52 +0000 | [diff] [blame] | 1696 | updateValueMap(I, ResultReg); |
Eric Christopher | 511aa31 | 2010-10-11 08:27:59 +0000 | [diff] [blame] | 1697 | return true; |
| 1698 | } |
| 1699 | |
Chad Rosier | aaa55a8 | 2012-02-03 21:07:27 +0000 | [diff] [blame] | 1700 | bool ARMFastISel::SelectDiv(const Instruction *I, bool isSigned) { |
Duncan Sands | f5dda01 | 2010-11-03 11:35:31 +0000 | [diff] [blame] | 1701 | MVT VT; |
Chris Lattner | 229907c | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 1702 | Type *Ty = I->getType(); |
Eric Christopher | 56094ff | 2010-09-30 22:34:19 +0000 | [diff] [blame] | 1703 | if (!isTypeLegal(Ty, VT)) |
| 1704 | return false; |
| 1705 | |
| 1706 | // If we have integer div support we should have selected this automagically. |
| 1707 | // In case we have a real miss go ahead and return false and we'll pick |
| 1708 | // it up later. |
Eric Christopher | 7ac602b | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1709 | if (Subtarget->hasDivide()) return false; |
| 1710 | |
Eric Christopher | 56094ff | 2010-09-30 22:34:19 +0000 | [diff] [blame] | 1711 | // Otherwise emit a libcall. |
| 1712 | RTLIB::Libcall LC = RTLIB::UNKNOWN_LIBCALL; |
Eric Christopher | e11017c | 2010-10-11 08:31:54 +0000 | [diff] [blame] | 1713 | if (VT == MVT::i8) |
Chad Rosier | aaa55a8 | 2012-02-03 21:07:27 +0000 | [diff] [blame] | 1714 | LC = isSigned ? RTLIB::SDIV_I8 : RTLIB::UDIV_I8; |
Eric Christopher | e11017c | 2010-10-11 08:31:54 +0000 | [diff] [blame] | 1715 | else if (VT == MVT::i16) |
Chad Rosier | aaa55a8 | 2012-02-03 21:07:27 +0000 | [diff] [blame] | 1716 | LC = isSigned ? RTLIB::SDIV_I16 : RTLIB::UDIV_I16; |
Eric Christopher | 56094ff | 2010-09-30 22:34:19 +0000 | [diff] [blame] | 1717 | else if (VT == MVT::i32) |
Chad Rosier | aaa55a8 | 2012-02-03 21:07:27 +0000 | [diff] [blame] | 1718 | LC = isSigned ? RTLIB::SDIV_I32 : RTLIB::UDIV_I32; |
Eric Christopher | 56094ff | 2010-09-30 22:34:19 +0000 | [diff] [blame] | 1719 | else if (VT == MVT::i64) |
Chad Rosier | aaa55a8 | 2012-02-03 21:07:27 +0000 | [diff] [blame] | 1720 | LC = isSigned ? RTLIB::SDIV_I64 : RTLIB::UDIV_I64; |
Eric Christopher | 56094ff | 2010-09-30 22:34:19 +0000 | [diff] [blame] | 1721 | else if (VT == MVT::i128) |
Chad Rosier | aaa55a8 | 2012-02-03 21:07:27 +0000 | [diff] [blame] | 1722 | LC = isSigned ? RTLIB::SDIV_I128 : RTLIB::UDIV_I128; |
Eric Christopher | 56094ff | 2010-09-30 22:34:19 +0000 | [diff] [blame] | 1723 | assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unsupported SDIV!"); |
Eric Christopher | 7ac602b | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 1724 | |
Eric Christopher | 56094ff | 2010-09-30 22:34:19 +0000 | [diff] [blame] | 1725 | return ARMEmitLibcall(I, LC); |
| 1726 | } |
| 1727 | |
Chad Rosier | b84a4b4 | 2012-02-03 21:23:45 +0000 | [diff] [blame] | 1728 | bool ARMFastISel::SelectRem(const Instruction *I, bool isSigned) { |
Duncan Sands | f5dda01 | 2010-11-03 11:35:31 +0000 | [diff] [blame] | 1729 | MVT VT; |
Chris Lattner | 229907c | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 1730 | Type *Ty = I->getType(); |
Eric Christopher | eae1b38 | 2010-10-11 08:37:26 +0000 | [diff] [blame] | 1731 | if (!isTypeLegal(Ty, VT)) |
| 1732 | return false; |
| 1733 | |
| 1734 | RTLIB::Libcall LC = RTLIB::UNKNOWN_LIBCALL; |
| 1735 | if (VT == MVT::i8) |
Chad Rosier | b84a4b4 | 2012-02-03 21:23:45 +0000 | [diff] [blame] | 1736 | LC = isSigned ? RTLIB::SREM_I8 : RTLIB::UREM_I8; |
Eric Christopher | eae1b38 | 2010-10-11 08:37:26 +0000 | [diff] [blame] | 1737 | else if (VT == MVT::i16) |
Chad Rosier | b84a4b4 | 2012-02-03 21:23:45 +0000 | [diff] [blame] | 1738 | LC = isSigned ? RTLIB::SREM_I16 : RTLIB::UREM_I16; |
Eric Christopher | eae1b38 | 2010-10-11 08:37:26 +0000 | [diff] [blame] | 1739 | else if (VT == MVT::i32) |
Chad Rosier | b84a4b4 | 2012-02-03 21:23:45 +0000 | [diff] [blame] | 1740 | LC = isSigned ? RTLIB::SREM_I32 : RTLIB::UREM_I32; |
Eric Christopher | eae1b38 | 2010-10-11 08:37:26 +0000 | [diff] [blame] | 1741 | else if (VT == MVT::i64) |
Chad Rosier | b84a4b4 | 2012-02-03 21:23:45 +0000 | [diff] [blame] | 1742 | LC = isSigned ? RTLIB::SREM_I64 : RTLIB::UREM_I64; |
Eric Christopher | eae1b38 | 2010-10-11 08:37:26 +0000 | [diff] [blame] | 1743 | else if (VT == MVT::i128) |
Chad Rosier | b84a4b4 | 2012-02-03 21:23:45 +0000 | [diff] [blame] | 1744 | LC = isSigned ? RTLIB::SREM_I128 : RTLIB::UREM_I128; |
Eric Christopher | e1bcb43 | 2010-10-11 08:40:05 +0000 | [diff] [blame] | 1745 | assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unsupported SREM!"); |
Eric Christopher | e4b3d6b | 2010-10-15 18:02:07 +0000 | [diff] [blame] | 1746 | |
Eric Christopher | eae1b38 | 2010-10-11 08:37:26 +0000 | [diff] [blame] | 1747 | return ARMEmitLibcall(I, LC); |
| 1748 | } |
| 1749 | |
Chad Rosier | 685b20c | 2012-02-06 23:50:07 +0000 | [diff] [blame] | 1750 | bool ARMFastISel::SelectBinaryIntOp(const Instruction *I, unsigned ISDOpcode) { |
Chad Rosier | 685b20c | 2012-02-06 23:50:07 +0000 | [diff] [blame] | 1751 | EVT DestVT = TLI.getValueType(I->getType(), true); |
| 1752 | |
| 1753 | // We can get here in the case when we have a binary operation on a non-legal |
| 1754 | // type and the target independent selector doesn't know how to handle it. |
| 1755 | if (DestVT != MVT::i16 && DestVT != MVT::i8 && DestVT != MVT::i1) |
| 1756 | return false; |
Jush Lu | ac96b76 | 2012-06-14 06:08:19 +0000 | [diff] [blame] | 1757 | |
Chad Rosier | bd47125 | 2012-02-08 02:29:21 +0000 | [diff] [blame] | 1758 | unsigned Opc; |
| 1759 | switch (ISDOpcode) { |
| 1760 | default: return false; |
| 1761 | case ISD::ADD: |
| 1762 | Opc = isThumb2 ? ARM::t2ADDrr : ARM::ADDrr; |
| 1763 | break; |
| 1764 | case ISD::OR: |
| 1765 | Opc = isThumb2 ? ARM::t2ORRrr : ARM::ORRrr; |
| 1766 | break; |
Chad Rosier | 0ee8c51 | 2012-02-08 02:45:44 +0000 | [diff] [blame] | 1767 | case ISD::SUB: |
| 1768 | Opc = isThumb2 ? ARM::t2SUBrr : ARM::SUBrr; |
| 1769 | break; |
Chad Rosier | bd47125 | 2012-02-08 02:29:21 +0000 | [diff] [blame] | 1770 | } |
| 1771 | |
Chad Rosier | 685b20c | 2012-02-06 23:50:07 +0000 | [diff] [blame] | 1772 | unsigned SrcReg1 = getRegForValue(I->getOperand(0)); |
| 1773 | if (SrcReg1 == 0) return false; |
| 1774 | |
| 1775 | // TODO: Often the 2nd operand is an immediate, which can be encoded directly |
| 1776 | // in the instruction, rather then materializing the value in a register. |
| 1777 | unsigned SrcReg2 = getRegForValue(I->getOperand(1)); |
| 1778 | if (SrcReg2 == 0) return false; |
| 1779 | |
JF Bastien | 13969d0 | 2013-05-29 15:45:47 +0000 | [diff] [blame] | 1780 | unsigned ResultReg = createResultReg(&ARM::GPRnopcRegClass); |
Joey Gouly | c7cda1c | 2013-08-23 15:20:56 +0000 | [diff] [blame] | 1781 | SrcReg1 = constrainOperandRegClass(TII.get(Opc), SrcReg1, 1); |
| 1782 | SrcReg2 = constrainOperandRegClass(TII.get(Opc), SrcReg2, 2); |
Rafael Espindola | ea09c59 | 2014-02-18 22:05:46 +0000 | [diff] [blame] | 1783 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, |
Chad Rosier | 685b20c | 2012-02-06 23:50:07 +0000 | [diff] [blame] | 1784 | TII.get(Opc), ResultReg) |
| 1785 | .addReg(SrcReg1).addReg(SrcReg2)); |
Juergen Ributzka | 5b8bb4d | 2014-09-03 20:56:52 +0000 | [diff] [blame] | 1786 | updateValueMap(I, ResultReg); |
Chad Rosier | 685b20c | 2012-02-06 23:50:07 +0000 | [diff] [blame] | 1787 | return true; |
| 1788 | } |
| 1789 | |
| 1790 | bool ARMFastISel::SelectBinaryFPOp(const Instruction *I, unsigned ISDOpcode) { |
Chad Rosier | 62a144f | 2012-12-17 19:59:43 +0000 | [diff] [blame] | 1791 | EVT FPVT = TLI.getValueType(I->getType(), true); |
| 1792 | if (!FPVT.isSimple()) return false; |
| 1793 | MVT VT = FPVT.getSimpleVT(); |
Eric Christopher | 2ff757d | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 1794 | |
Pete Cooper | d927c6e | 2015-05-06 16:39:17 +0000 | [diff] [blame] | 1795 | // FIXME: Support vector types where possible. |
| 1796 | if (VT.isVector()) |
| 1797 | return false; |
| 1798 | |
Eric Christopher | 24dc27f | 2010-09-09 00:53:57 +0000 | [diff] [blame] | 1799 | // We can get here in the case when we want to use NEON for our fp |
| 1800 | // operations, but can't figure out how to. Just use the vfp instructions |
| 1801 | // if we have them. |
| 1802 | // FIXME: It'd be nice to use NEON instructions. |
Chris Lattner | 229907c | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 1803 | Type *Ty = I->getType(); |
Eric Christopher | bd3d121 | 2010-09-09 01:02:03 +0000 | [diff] [blame] | 1804 | bool isFloat = (Ty->isDoubleTy() || Ty->isFloatTy()); |
| 1805 | if (isFloat && !Subtarget->hasVFP2()) |
| 1806 | return false; |
Eric Christopher | 2ff757d | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 1807 | |
Eric Christopher | 24dc27f | 2010-09-09 00:53:57 +0000 | [diff] [blame] | 1808 | unsigned Opc; |
Duncan Sands | 1462777 | 2010-11-03 12:17:33 +0000 | [diff] [blame] | 1809 | bool is64bit = VT == MVT::f64 || VT == MVT::i64; |
Eric Christopher | 24dc27f | 2010-09-09 00:53:57 +0000 | [diff] [blame] | 1810 | switch (ISDOpcode) { |
| 1811 | default: return false; |
| 1812 | case ISD::FADD: |
Eric Christopher | bd3d121 | 2010-09-09 01:02:03 +0000 | [diff] [blame] | 1813 | Opc = is64bit ? ARM::VADDD : ARM::VADDS; |
Eric Christopher | 24dc27f | 2010-09-09 00:53:57 +0000 | [diff] [blame] | 1814 | break; |
| 1815 | case ISD::FSUB: |
Eric Christopher | bd3d121 | 2010-09-09 01:02:03 +0000 | [diff] [blame] | 1816 | Opc = is64bit ? ARM::VSUBD : ARM::VSUBS; |
Eric Christopher | 24dc27f | 2010-09-09 00:53:57 +0000 | [diff] [blame] | 1817 | break; |
| 1818 | case ISD::FMUL: |
Eric Christopher | bd3d121 | 2010-09-09 01:02:03 +0000 | [diff] [blame] | 1819 | Opc = is64bit ? ARM::VMULD : ARM::VMULS; |
Eric Christopher | 24dc27f | 2010-09-09 00:53:57 +0000 | [diff] [blame] | 1820 | break; |
| 1821 | } |
Chad Rosier | 80979b6 | 2011-11-16 18:39:44 +0000 | [diff] [blame] | 1822 | unsigned Op1 = getRegForValue(I->getOperand(0)); |
| 1823 | if (Op1 == 0) return false; |
| 1824 | |
| 1825 | unsigned Op2 = getRegForValue(I->getOperand(1)); |
| 1826 | if (Op2 == 0) return false; |
| 1827 | |
Chad Rosier | 62a144f | 2012-12-17 19:59:43 +0000 | [diff] [blame] | 1828 | unsigned ResultReg = createResultReg(TLI.getRegClassFor(VT.SimpleTy)); |
Rafael Espindola | ea09c59 | 2014-02-18 22:05:46 +0000 | [diff] [blame] | 1829 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, |
Eric Christopher | 24dc27f | 2010-09-09 00:53:57 +0000 | [diff] [blame] | 1830 | TII.get(Opc), ResultReg) |
| 1831 | .addReg(Op1).addReg(Op2)); |
Juergen Ributzka | 5b8bb4d | 2014-09-03 20:56:52 +0000 | [diff] [blame] | 1832 | updateValueMap(I, ResultReg); |
Eric Christopher | 24dc27f | 2010-09-09 00:53:57 +0000 | [diff] [blame] | 1833 | return true; |
| 1834 | } |
| 1835 | |
Eric Christopher | 72497e5 | 2010-09-10 23:18:12 +0000 | [diff] [blame] | 1836 | // Call Handling Code |
| 1837 | |
Jush Lu | e67e07b | 2012-07-19 09:49:00 +0000 | [diff] [blame] | 1838 | // This is largely taken directly from CCAssignFnForNode |
Eric Christopher | 72497e5 | 2010-09-10 23:18:12 +0000 | [diff] [blame] | 1839 | // TODO: We may not support all of this. |
Jush Lu | e67e07b | 2012-07-19 09:49:00 +0000 | [diff] [blame] | 1840 | CCAssignFn *ARMFastISel::CCAssignFnForCall(CallingConv::ID CC, |
| 1841 | bool Return, |
| 1842 | bool isVarArg) { |
Eric Christopher | 72497e5 | 2010-09-10 23:18:12 +0000 | [diff] [blame] | 1843 | switch (CC) { |
| 1844 | default: |
| 1845 | llvm_unreachable("Unsupported calling convention"); |
Eric Christopher | 72497e5 | 2010-09-10 23:18:12 +0000 | [diff] [blame] | 1846 | case CallingConv::Fast: |
Jush Lu | 26088cb | 2012-08-16 05:15:53 +0000 | [diff] [blame] | 1847 | if (Subtarget->hasVFP2() && !isVarArg) { |
| 1848 | if (!Subtarget->isAAPCS_ABI()) |
| 1849 | return (Return ? RetFastCC_ARM_APCS : FastCC_ARM_APCS); |
| 1850 | // For AAPCS ABI targets, just use VFP variant of the calling convention. |
| 1851 | return (Return ? RetCC_ARM_AAPCS_VFP : CC_ARM_AAPCS_VFP); |
| 1852 | } |
Evan Cheng | 21abfc9 | 2010-10-22 18:57:05 +0000 | [diff] [blame] | 1853 | // Fallthrough |
| 1854 | case CallingConv::C: |
Eric Christopher | 72497e5 | 2010-09-10 23:18:12 +0000 | [diff] [blame] | 1855 | // Use target triple & subtarget features to do actual dispatch. |
| 1856 | if (Subtarget->isAAPCS_ABI()) { |
| 1857 | if (Subtarget->hasVFP2() && |
Jush Lu | e67e07b | 2012-07-19 09:49:00 +0000 | [diff] [blame] | 1858 | TM.Options.FloatABIType == FloatABI::Hard && !isVarArg) |
Eric Christopher | 72497e5 | 2010-09-10 23:18:12 +0000 | [diff] [blame] | 1859 | return (Return ? RetCC_ARM_AAPCS_VFP: CC_ARM_AAPCS_VFP); |
| 1860 | else |
| 1861 | return (Return ? RetCC_ARM_AAPCS: CC_ARM_AAPCS); |
| 1862 | } else |
| 1863 | return (Return ? RetCC_ARM_APCS: CC_ARM_APCS); |
| 1864 | case CallingConv::ARM_AAPCS_VFP: |
Jush Lu | e67e07b | 2012-07-19 09:49:00 +0000 | [diff] [blame] | 1865 | if (!isVarArg) |
| 1866 | return (Return ? RetCC_ARM_AAPCS_VFP: CC_ARM_AAPCS_VFP); |
| 1867 | // Fall through to soft float variant, variadic functions don't |
| 1868 | // use hard floating point ABI. |
Eric Christopher | 72497e5 | 2010-09-10 23:18:12 +0000 | [diff] [blame] | 1869 | case CallingConv::ARM_AAPCS: |
| 1870 | return (Return ? RetCC_ARM_AAPCS: CC_ARM_AAPCS); |
| 1871 | case CallingConv::ARM_APCS: |
| 1872 | return (Return ? RetCC_ARM_APCS: CC_ARM_APCS); |
Eric Christopher | b332236 | 2012-08-03 00:05:53 +0000 | [diff] [blame] | 1873 | case CallingConv::GHC: |
| 1874 | if (Return) |
| 1875 | llvm_unreachable("Can't return in GHC call convention"); |
| 1876 | else |
| 1877 | return CC_ARM_APCS_GHC; |
Eric Christopher | 72497e5 | 2010-09-10 23:18:12 +0000 | [diff] [blame] | 1878 | } |
| 1879 | } |
| 1880 | |
Eric Christopher | 7939806 | 2010-09-29 23:11:09 +0000 | [diff] [blame] | 1881 | bool ARMFastISel::ProcessCallArgs(SmallVectorImpl<Value*> &Args, |
| 1882 | SmallVectorImpl<unsigned> &ArgRegs, |
Duncan Sands | f5dda01 | 2010-11-03 11:35:31 +0000 | [diff] [blame] | 1883 | SmallVectorImpl<MVT> &ArgVTs, |
Eric Christopher | 7939806 | 2010-09-29 23:11:09 +0000 | [diff] [blame] | 1884 | SmallVectorImpl<ISD::ArgFlagsTy> &ArgFlags, |
| 1885 | SmallVectorImpl<unsigned> &RegArgs, |
| 1886 | CallingConv::ID CC, |
Jush Lu | e67e07b | 2012-07-19 09:49:00 +0000 | [diff] [blame] | 1887 | unsigned &NumBytes, |
| 1888 | bool isVarArg) { |
Eric Christopher | 7939806 | 2010-09-29 23:11:09 +0000 | [diff] [blame] | 1889 | SmallVector<CCValAssign, 16> ArgLocs; |
Eric Christopher | b521750 | 2014-08-06 18:45:26 +0000 | [diff] [blame] | 1890 | CCState CCInfo(CC, isVarArg, *FuncInfo.MF, ArgLocs, *Context); |
Jush Lu | e67e07b | 2012-07-19 09:49:00 +0000 | [diff] [blame] | 1891 | CCInfo.AnalyzeCallOperands(ArgVTs, ArgFlags, |
| 1892 | CCAssignFnForCall(CC, false, isVarArg)); |
Eric Christopher | 7939806 | 2010-09-29 23:11:09 +0000 | [diff] [blame] | 1893 | |
Bill Wendling | 23f8c4a | 2012-03-16 23:11:07 +0000 | [diff] [blame] | 1894 | // Check that we can handle all of the arguments. If we can't, then bail out |
| 1895 | // now before we add code to the MBB. |
| 1896 | for (unsigned i = 0, e = ArgLocs.size(); i != e; ++i) { |
| 1897 | CCValAssign &VA = ArgLocs[i]; |
| 1898 | MVT ArgVT = ArgVTs[VA.getValNo()]; |
| 1899 | |
| 1900 | // We don't handle NEON/vector parameters yet. |
| 1901 | if (ArgVT.isVector() || ArgVT.getSizeInBits() > 64) |
| 1902 | return false; |
| 1903 | |
| 1904 | // Now copy/store arg to correct locations. |
| 1905 | if (VA.isRegLoc() && !VA.needsCustom()) { |
| 1906 | continue; |
| 1907 | } else if (VA.needsCustom()) { |
| 1908 | // TODO: We need custom lowering for vector (v2f64) args. |
| 1909 | if (VA.getLocVT() != MVT::f64 || |
| 1910 | // TODO: Only handle register args for now. |
| 1911 | !VA.isRegLoc() || !ArgLocs[++i].isRegLoc()) |
| 1912 | return false; |
| 1913 | } else { |
Craig Topper | 5671010 | 2013-08-15 02:33:50 +0000 | [diff] [blame] | 1914 | switch (ArgVT.SimpleTy) { |
Bill Wendling | 23f8c4a | 2012-03-16 23:11:07 +0000 | [diff] [blame] | 1915 | default: |
| 1916 | return false; |
| 1917 | case MVT::i1: |
| 1918 | case MVT::i8: |
| 1919 | case MVT::i16: |
| 1920 | case MVT::i32: |
| 1921 | break; |
| 1922 | case MVT::f32: |
| 1923 | if (!Subtarget->hasVFP2()) |
| 1924 | return false; |
| 1925 | break; |
| 1926 | case MVT::f64: |
| 1927 | if (!Subtarget->hasVFP2()) |
| 1928 | return false; |
| 1929 | break; |
| 1930 | } |
| 1931 | } |
| 1932 | } |
| 1933 | |
| 1934 | // At the point, we are able to handle the call's arguments in fast isel. |
| 1935 | |
Eric Christopher | 7939806 | 2010-09-29 23:11:09 +0000 | [diff] [blame] | 1936 | // Get a count of how many bytes are to be pushed on the stack. |
| 1937 | NumBytes = CCInfo.getNextStackOffset(); |
| 1938 | |
| 1939 | // Issue CALLSEQ_START |
Evan Cheng | 194c3dc | 2011-06-28 21:14:33 +0000 | [diff] [blame] | 1940 | unsigned AdjStackDown = TII.getCallFrameSetupOpcode(); |
Rafael Espindola | ea09c59 | 2014-02-18 22:05:46 +0000 | [diff] [blame] | 1941 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, |
Eric Christopher | 71ef1af | 2010-10-11 21:20:02 +0000 | [diff] [blame] | 1942 | TII.get(AdjStackDown)) |
| 1943 | .addImm(NumBytes)); |
Eric Christopher | 7939806 | 2010-09-29 23:11:09 +0000 | [diff] [blame] | 1944 | |
| 1945 | // Process the args. |
| 1946 | for (unsigned i = 0, e = ArgLocs.size(); i != e; ++i) { |
| 1947 | CCValAssign &VA = ArgLocs[i]; |
Juergen Ributzka | 4c018a1 | 2014-08-01 18:04:14 +0000 | [diff] [blame] | 1948 | const Value *ArgVal = Args[VA.getValNo()]; |
Eric Christopher | 7939806 | 2010-09-29 23:11:09 +0000 | [diff] [blame] | 1949 | unsigned Arg = ArgRegs[VA.getValNo()]; |
Duncan Sands | f5dda01 | 2010-11-03 11:35:31 +0000 | [diff] [blame] | 1950 | MVT ArgVT = ArgVTs[VA.getValNo()]; |
Eric Christopher | 7939806 | 2010-09-29 23:11:09 +0000 | [diff] [blame] | 1951 | |
Bill Wendling | 23f8c4a | 2012-03-16 23:11:07 +0000 | [diff] [blame] | 1952 | assert((!ArgVT.isVector() && ArgVT.getSizeInBits() <= 64) && |
| 1953 | "We don't handle NEON/vector parameters yet."); |
Eric Christopher | c9616f2 | 2010-10-23 09:37:17 +0000 | [diff] [blame] | 1954 | |
Eric Christopher | 78f8d4e | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 1955 | // Handle arg promotion, etc. |
Eric Christopher | 7939806 | 2010-09-29 23:11:09 +0000 | [diff] [blame] | 1956 | switch (VA.getLocInfo()) { |
| 1957 | case CCValAssign::Full: break; |
Eric Christopher | c103c66 | 2010-10-18 02:17:53 +0000 | [diff] [blame] | 1958 | case CCValAssign::SExt: { |
Chad Rosier | 9fd0e55 | 2011-12-02 20:25:18 +0000 | [diff] [blame] | 1959 | MVT DestVT = VA.getLocVT(); |
Chad Rosier | 5b9c397 | 2012-02-14 22:29:48 +0000 | [diff] [blame] | 1960 | Arg = ARMEmitIntExt(ArgVT, Arg, DestVT, /*isZExt*/false); |
| 1961 | assert (Arg != 0 && "Failed to emit a sext"); |
Chad Rosier | 9fd0e55 | 2011-12-02 20:25:18 +0000 | [diff] [blame] | 1962 | ArgVT = DestVT; |
Eric Christopher | c103c66 | 2010-10-18 02:17:53 +0000 | [diff] [blame] | 1963 | break; |
| 1964 | } |
Chad Rosier | d0191a5 | 2011-11-05 20:16:15 +0000 | [diff] [blame] | 1965 | case CCValAssign::AExt: |
| 1966 | // Intentional fall-through. Handle AExt and ZExt. |
Eric Christopher | c103c66 | 2010-10-18 02:17:53 +0000 | [diff] [blame] | 1967 | case CCValAssign::ZExt: { |
Chad Rosier | 9fd0e55 | 2011-12-02 20:25:18 +0000 | [diff] [blame] | 1968 | MVT DestVT = VA.getLocVT(); |
Chad Rosier | 5b9c397 | 2012-02-14 22:29:48 +0000 | [diff] [blame] | 1969 | Arg = ARMEmitIntExt(ArgVT, Arg, DestVT, /*isZExt*/true); |
JF Bastien | 06ce03d | 2013-06-07 20:10:37 +0000 | [diff] [blame] | 1970 | assert (Arg != 0 && "Failed to emit a zext"); |
Chad Rosier | 9fd0e55 | 2011-12-02 20:25:18 +0000 | [diff] [blame] | 1971 | ArgVT = DestVT; |
Eric Christopher | c103c66 | 2010-10-18 02:17:53 +0000 | [diff] [blame] | 1972 | break; |
| 1973 | } |
| 1974 | case CCValAssign::BCvt: { |
Juergen Ributzka | 88e3251 | 2014-09-03 20:56:59 +0000 | [diff] [blame] | 1975 | unsigned BC = fastEmit_r(ArgVT, VA.getLocVT(), ISD::BITCAST, Arg, |
Duncan Sands | f5dda01 | 2010-11-03 11:35:31 +0000 | [diff] [blame] | 1976 | /*TODO: Kill=*/false); |
Eric Christopher | c103c66 | 2010-10-18 02:17:53 +0000 | [diff] [blame] | 1977 | assert(BC != 0 && "Failed to emit a bitcast!"); |
| 1978 | Arg = BC; |
| 1979 | ArgVT = VA.getLocVT(); |
| 1980 | break; |
| 1981 | } |
| 1982 | default: llvm_unreachable("Unknown arg promotion!"); |
Eric Christopher | 7939806 | 2010-09-29 23:11:09 +0000 | [diff] [blame] | 1983 | } |
| 1984 | |
| 1985 | // Now copy/store arg to correct locations. |
Eric Christopher | 71ef1af | 2010-10-11 21:20:02 +0000 | [diff] [blame] | 1986 | if (VA.isRegLoc() && !VA.needsCustom()) { |
Rafael Espindola | ea09c59 | 2014-02-18 22:05:46 +0000 | [diff] [blame] | 1987 | BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, |
| 1988 | TII.get(TargetOpcode::COPY), VA.getLocReg()).addReg(Arg); |
Eric Christopher | 7939806 | 2010-09-29 23:11:09 +0000 | [diff] [blame] | 1989 | RegArgs.push_back(VA.getLocReg()); |
Eric Christopher | 4ac3ed0 | 2010-10-21 00:01:47 +0000 | [diff] [blame] | 1990 | } else if (VA.needsCustom()) { |
| 1991 | // TODO: We need custom lowering for vector (v2f64) args. |
Bill Wendling | 23f8c4a | 2012-03-16 23:11:07 +0000 | [diff] [blame] | 1992 | assert(VA.getLocVT() == MVT::f64 && |
| 1993 | "Custom lowering for v2f64 args not available"); |
Jim Grosbach | 055de2c | 2010-10-27 21:39:08 +0000 | [diff] [blame] | 1994 | |
Eric Christopher | 4ac3ed0 | 2010-10-21 00:01:47 +0000 | [diff] [blame] | 1995 | CCValAssign &NextVA = ArgLocs[++i]; |
| 1996 | |
Bill Wendling | 23f8c4a | 2012-03-16 23:11:07 +0000 | [diff] [blame] | 1997 | assert(VA.isRegLoc() && NextVA.isRegLoc() && |
| 1998 | "We only handle register args!"); |
Eric Christopher | 4ac3ed0 | 2010-10-21 00:01:47 +0000 | [diff] [blame] | 1999 | |
Rafael Espindola | ea09c59 | 2014-02-18 22:05:46 +0000 | [diff] [blame] | 2000 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, |
Eric Christopher | 4ac3ed0 | 2010-10-21 00:01:47 +0000 | [diff] [blame] | 2001 | TII.get(ARM::VMOVRRD), VA.getLocReg()) |
| 2002 | .addReg(NextVA.getLocReg(), RegState::Define) |
| 2003 | .addReg(Arg)); |
| 2004 | RegArgs.push_back(VA.getLocReg()); |
| 2005 | RegArgs.push_back(NextVA.getLocReg()); |
Eric Christopher | 7939806 | 2010-09-29 23:11:09 +0000 | [diff] [blame] | 2006 | } else { |
Eric Christopher | b353e4f | 2010-10-21 20:09:54 +0000 | [diff] [blame] | 2007 | assert(VA.isMemLoc()); |
| 2008 | // Need to store on the stack. |
Juergen Ributzka | 4c018a1 | 2014-08-01 18:04:14 +0000 | [diff] [blame] | 2009 | |
| 2010 | // Don't emit stores for undef values. |
| 2011 | if (isa<UndefValue>(ArgVal)) |
| 2012 | continue; |
| 2013 | |
Eric Christopher | fef5f31 | 2010-11-19 22:30:02 +0000 | [diff] [blame] | 2014 | Address Addr; |
| 2015 | Addr.BaseType = Address::RegBase; |
| 2016 | Addr.Base.Reg = ARM::SP; |
| 2017 | Addr.Offset = VA.getLocMemOffset(); |
Eric Christopher | b353e4f | 2010-10-21 20:09:54 +0000 | [diff] [blame] | 2018 | |
Bill Wendling | 23f8c4a | 2012-03-16 23:11:07 +0000 | [diff] [blame] | 2019 | bool EmitRet = ARMEmitStore(ArgVT, Arg, Addr); (void)EmitRet; |
| 2020 | assert(EmitRet && "Could not emit a store for argument!"); |
Eric Christopher | 7939806 | 2010-09-29 23:11:09 +0000 | [diff] [blame] | 2021 | } |
| 2022 | } |
Bill Wendling | 23f8c4a | 2012-03-16 23:11:07 +0000 | [diff] [blame] | 2023 | |
Eric Christopher | 7939806 | 2010-09-29 23:11:09 +0000 | [diff] [blame] | 2024 | return true; |
| 2025 | } |
| 2026 | |
Duncan Sands | f5dda01 | 2010-11-03 11:35:31 +0000 | [diff] [blame] | 2027 | bool ARMFastISel::FinishCall(MVT RetVT, SmallVectorImpl<unsigned> &UsedRegs, |
Eric Christopher | 7939806 | 2010-09-29 23:11:09 +0000 | [diff] [blame] | 2028 | const Instruction *I, CallingConv::ID CC, |
Jush Lu | e67e07b | 2012-07-19 09:49:00 +0000 | [diff] [blame] | 2029 | unsigned &NumBytes, bool isVarArg) { |
Eric Christopher | 7939806 | 2010-09-29 23:11:09 +0000 | [diff] [blame] | 2030 | // Issue CALLSEQ_END |
Evan Cheng | 194c3dc | 2011-06-28 21:14:33 +0000 | [diff] [blame] | 2031 | unsigned AdjStackUp = TII.getCallFrameDestroyOpcode(); |
Rafael Espindola | ea09c59 | 2014-02-18 22:05:46 +0000 | [diff] [blame] | 2032 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, |
Eric Christopher | 71ef1af | 2010-10-11 21:20:02 +0000 | [diff] [blame] | 2033 | TII.get(AdjStackUp)) |
| 2034 | .addImm(NumBytes).addImm(0)); |
Eric Christopher | 7939806 | 2010-09-29 23:11:09 +0000 | [diff] [blame] | 2035 | |
| 2036 | // Now the return value. |
Duncan Sands | f5dda01 | 2010-11-03 11:35:31 +0000 | [diff] [blame] | 2037 | if (RetVT != MVT::isVoid) { |
Eric Christopher | 7939806 | 2010-09-29 23:11:09 +0000 | [diff] [blame] | 2038 | SmallVector<CCValAssign, 16> RVLocs; |
Eric Christopher | b521750 | 2014-08-06 18:45:26 +0000 | [diff] [blame] | 2039 | CCState CCInfo(CC, isVarArg, *FuncInfo.MF, RVLocs, *Context); |
Jush Lu | e67e07b | 2012-07-19 09:49:00 +0000 | [diff] [blame] | 2040 | CCInfo.AnalyzeCallResult(RetVT, CCAssignFnForCall(CC, true, isVarArg)); |
Eric Christopher | 7939806 | 2010-09-29 23:11:09 +0000 | [diff] [blame] | 2041 | |
| 2042 | // Copy all of the result registers out of their specified physreg. |
Duncan Sands | f5dda01 | 2010-11-03 11:35:31 +0000 | [diff] [blame] | 2043 | if (RVLocs.size() == 2 && RetVT == MVT::f64) { |
Eric Christopher | c1e209d | 2010-10-01 00:00:11 +0000 | [diff] [blame] | 2044 | // For this move we copy into two registers and then move into the |
| 2045 | // double fp reg we want. |
Patrik Hagglund | 5e6c361 | 2012-12-13 06:34:11 +0000 | [diff] [blame] | 2046 | MVT DestVT = RVLocs[0].getValVT(); |
Craig Topper | 760b134 | 2012-02-22 05:59:10 +0000 | [diff] [blame] | 2047 | const TargetRegisterClass* DstRC = TLI.getRegClassFor(DestVT); |
Eric Christopher | c1e209d | 2010-10-01 00:00:11 +0000 | [diff] [blame] | 2048 | unsigned ResultReg = createResultReg(DstRC); |
Rafael Espindola | ea09c59 | 2014-02-18 22:05:46 +0000 | [diff] [blame] | 2049 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, |
Eric Christopher | c1e209d | 2010-10-01 00:00:11 +0000 | [diff] [blame] | 2050 | TII.get(ARM::VMOVDRR), ResultReg) |
Eric Christopher | af719ef | 2010-10-20 08:02:24 +0000 | [diff] [blame] | 2051 | .addReg(RVLocs[0].getLocReg()) |
| 2052 | .addReg(RVLocs[1].getLocReg())); |
Eric Christopher | 7ac602b | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 2053 | |
Eric Christopher | af719ef | 2010-10-20 08:02:24 +0000 | [diff] [blame] | 2054 | UsedRegs.push_back(RVLocs[0].getLocReg()); |
| 2055 | UsedRegs.push_back(RVLocs[1].getLocReg()); |
Jim Grosbach | 055de2c | 2010-10-27 21:39:08 +0000 | [diff] [blame] | 2056 | |
Eric Christopher | 7ac602b | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 2057 | // Finally update the result. |
Juergen Ributzka | 5b8bb4d | 2014-09-03 20:56:52 +0000 | [diff] [blame] | 2058 | updateValueMap(I, ResultReg); |
Chad Rosier | 90f9afe | 2012-05-11 18:51:55 +0000 | [diff] [blame] | 2059 | } else { |
| 2060 | assert(RVLocs.size() == 1 &&"Can't handle non-double multi-reg retvals!"); |
Patrik Hagglund | 5e6c361 | 2012-12-13 06:34:11 +0000 | [diff] [blame] | 2061 | MVT CopyVT = RVLocs[0].getValVT(); |
Chad Rosier | 5de1bea | 2011-11-08 00:03:32 +0000 | [diff] [blame] | 2062 | |
| 2063 | // Special handling for extended integers. |
| 2064 | if (RetVT == MVT::i1 || RetVT == MVT::i8 || RetVT == MVT::i16) |
| 2065 | CopyVT = MVT::i32; |
| 2066 | |
Craig Topper | 760b134 | 2012-02-22 05:59:10 +0000 | [diff] [blame] | 2067 | const TargetRegisterClass* DstRC = TLI.getRegClassFor(CopyVT); |
Eric Christopher | 7939806 | 2010-09-29 23:11:09 +0000 | [diff] [blame] | 2068 | |
Eric Christopher | c1e209d | 2010-10-01 00:00:11 +0000 | [diff] [blame] | 2069 | unsigned ResultReg = createResultReg(DstRC); |
Rafael Espindola | ea09c59 | 2014-02-18 22:05:46 +0000 | [diff] [blame] | 2070 | BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, |
| 2071 | TII.get(TargetOpcode::COPY), |
Eric Christopher | c1e209d | 2010-10-01 00:00:11 +0000 | [diff] [blame] | 2072 | ResultReg).addReg(RVLocs[0].getLocReg()); |
| 2073 | UsedRegs.push_back(RVLocs[0].getLocReg()); |
Eric Christopher | 7939806 | 2010-09-29 23:11:09 +0000 | [diff] [blame] | 2074 | |
Eric Christopher | 7ac602b | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 2075 | // Finally update the result. |
Juergen Ributzka | 5b8bb4d | 2014-09-03 20:56:52 +0000 | [diff] [blame] | 2076 | updateValueMap(I, ResultReg); |
Eric Christopher | c1e209d | 2010-10-01 00:00:11 +0000 | [diff] [blame] | 2077 | } |
Eric Christopher | 7939806 | 2010-09-29 23:11:09 +0000 | [diff] [blame] | 2078 | } |
| 2079 | |
Eric Christopher | 7ac602b | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 2080 | return true; |
Eric Christopher | 7939806 | 2010-09-29 23:11:09 +0000 | [diff] [blame] | 2081 | } |
| 2082 | |
Eric Christopher | 93bbe65 | 2010-10-22 01:28:00 +0000 | [diff] [blame] | 2083 | bool ARMFastISel::SelectRet(const Instruction *I) { |
| 2084 | const ReturnInst *Ret = cast<ReturnInst>(I); |
| 2085 | const Function &F = *I->getParent()->getParent(); |
Jim Grosbach | 055de2c | 2010-10-27 21:39:08 +0000 | [diff] [blame] | 2086 | |
Eric Christopher | 93bbe65 | 2010-10-22 01:28:00 +0000 | [diff] [blame] | 2087 | if (!FuncInfo.CanLowerReturn) |
| 2088 | return false; |
Jim Grosbach | 055de2c | 2010-10-27 21:39:08 +0000 | [diff] [blame] | 2089 | |
Jakob Stoklund Olesen | f90fb6e | 2013-02-05 18:08:40 +0000 | [diff] [blame] | 2090 | // Build a list of return value registers. |
| 2091 | SmallVector<unsigned, 4> RetRegs; |
| 2092 | |
Eric Christopher | 93bbe65 | 2010-10-22 01:28:00 +0000 | [diff] [blame] | 2093 | CallingConv::ID CC = F.getCallingConv(); |
| 2094 | if (Ret->getNumOperands() > 0) { |
| 2095 | SmallVector<ISD::OutputArg, 4> Outs; |
Bill Wendling | 74dba87 | 2012-12-30 13:01:51 +0000 | [diff] [blame] | 2096 | GetReturnInfo(F.getReturnType(), F.getAttributes(), Outs, TLI); |
Eric Christopher | 93bbe65 | 2010-10-22 01:28:00 +0000 | [diff] [blame] | 2097 | |
| 2098 | // Analyze operands of the call, assigning locations to each operand. |
| 2099 | SmallVector<CCValAssign, 16> ValLocs; |
Eric Christopher | b521750 | 2014-08-06 18:45:26 +0000 | [diff] [blame] | 2100 | CCState CCInfo(CC, F.isVarArg(), *FuncInfo.MF, ValLocs, I->getContext()); |
Jush Lu | e67e07b | 2012-07-19 09:49:00 +0000 | [diff] [blame] | 2101 | CCInfo.AnalyzeReturn(Outs, CCAssignFnForCall(CC, true /* is Ret */, |
| 2102 | F.isVarArg())); |
Eric Christopher | 93bbe65 | 2010-10-22 01:28:00 +0000 | [diff] [blame] | 2103 | |
| 2104 | const Value *RV = Ret->getOperand(0); |
| 2105 | unsigned Reg = getRegForValue(RV); |
| 2106 | if (Reg == 0) |
| 2107 | return false; |
| 2108 | |
| 2109 | // Only handle a single return value for now. |
| 2110 | if (ValLocs.size() != 1) |
| 2111 | return false; |
| 2112 | |
| 2113 | CCValAssign &VA = ValLocs[0]; |
Jim Grosbach | 055de2c | 2010-10-27 21:39:08 +0000 | [diff] [blame] | 2114 | |
Eric Christopher | 93bbe65 | 2010-10-22 01:28:00 +0000 | [diff] [blame] | 2115 | // Don't bother handling odd stuff for now. |
| 2116 | if (VA.getLocInfo() != CCValAssign::Full) |
| 2117 | return false; |
| 2118 | // Only handle register returns for now. |
| 2119 | if (!VA.isRegLoc()) |
| 2120 | return false; |
Chad Rosier | f3e73ad | 2011-11-04 00:50:21 +0000 | [diff] [blame] | 2121 | |
| 2122 | unsigned SrcReg = Reg + VA.getValNo(); |
Chad Rosier | 62a144f | 2012-12-17 19:59:43 +0000 | [diff] [blame] | 2123 | EVT RVEVT = TLI.getValueType(RV->getType()); |
| 2124 | if (!RVEVT.isSimple()) return false; |
| 2125 | MVT RVVT = RVEVT.getSimpleVT(); |
Patrik Hagglund | 5e6c361 | 2012-12-13 06:34:11 +0000 | [diff] [blame] | 2126 | MVT DestVT = VA.getValVT(); |
Chad Rosier | f3e73ad | 2011-11-04 00:50:21 +0000 | [diff] [blame] | 2127 | // Special handling for extended integers. |
| 2128 | if (RVVT != DestVT) { |
| 2129 | if (RVVT != MVT::i1 && RVVT != MVT::i8 && RVVT != MVT::i16) |
| 2130 | return false; |
| 2131 | |
Chad Rosier | f3e73ad | 2011-11-04 00:50:21 +0000 | [diff] [blame] | 2132 | assert(DestVT == MVT::i32 && "ARM should always ext to i32"); |
| 2133 | |
Chad Rosier | fcd29ae | 2012-02-17 01:21:28 +0000 | [diff] [blame] | 2134 | // Perform extension if flagged as either zext or sext. Otherwise, do |
| 2135 | // nothing. |
| 2136 | if (Outs[0].Flags.isZExt() || Outs[0].Flags.isSExt()) { |
| 2137 | SrcReg = ARMEmitIntExt(RVVT, SrcReg, DestVT, Outs[0].Flags.isZExt()); |
| 2138 | if (SrcReg == 0) return false; |
| 2139 | } |
Chad Rosier | f3e73ad | 2011-11-04 00:50:21 +0000 | [diff] [blame] | 2140 | } |
Jim Grosbach | 055de2c | 2010-10-27 21:39:08 +0000 | [diff] [blame] | 2141 | |
Eric Christopher | 93bbe65 | 2010-10-22 01:28:00 +0000 | [diff] [blame] | 2142 | // Make the copy. |
Eric Christopher | 93bbe65 | 2010-10-22 01:28:00 +0000 | [diff] [blame] | 2143 | unsigned DstReg = VA.getLocReg(); |
| 2144 | const TargetRegisterClass* SrcRC = MRI.getRegClass(SrcReg); |
| 2145 | // Avoid a cross-class copy. This is very unlikely. |
| 2146 | if (!SrcRC->contains(DstReg)) |
| 2147 | return false; |
Rafael Espindola | ea09c59 | 2014-02-18 22:05:46 +0000 | [diff] [blame] | 2148 | BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, |
| 2149 | TII.get(TargetOpcode::COPY), DstReg).addReg(SrcReg); |
Eric Christopher | 93bbe65 | 2010-10-22 01:28:00 +0000 | [diff] [blame] | 2150 | |
Jakob Stoklund Olesen | f90fb6e | 2013-02-05 18:08:40 +0000 | [diff] [blame] | 2151 | // Add register to return instruction. |
| 2152 | RetRegs.push_back(VA.getLocReg()); |
Eric Christopher | 93bbe65 | 2010-10-22 01:28:00 +0000 | [diff] [blame] | 2153 | } |
Jim Grosbach | 055de2c | 2010-10-27 21:39:08 +0000 | [diff] [blame] | 2154 | |
Chad Rosier | 0439cfc | 2011-11-08 21:12:00 +0000 | [diff] [blame] | 2155 | unsigned RetOpc = isThumb2 ? ARM::tBX_RET : ARM::BX_RET; |
Rafael Espindola | ea09c59 | 2014-02-18 22:05:46 +0000 | [diff] [blame] | 2156 | MachineInstrBuilder MIB = BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, |
Jakob Stoklund Olesen | f90fb6e | 2013-02-05 18:08:40 +0000 | [diff] [blame] | 2157 | TII.get(RetOpc)); |
| 2158 | AddOptionalDefs(MIB); |
| 2159 | for (unsigned i = 0, e = RetRegs.size(); i != e; ++i) |
| 2160 | MIB.addReg(RetRegs[i], RegState::Implicit); |
Eric Christopher | 93bbe65 | 2010-10-22 01:28:00 +0000 | [diff] [blame] | 2161 | return true; |
| 2162 | } |
| 2163 | |
Chad Rosier | c6916f8 | 2012-06-12 19:25:13 +0000 | [diff] [blame] | 2164 | unsigned ARMFastISel::ARMSelectCallOp(bool UseReg) { |
| 2165 | if (UseReg) |
| 2166 | return isThumb2 ? ARM::tBLXr : ARM::BLX; |
| 2167 | else |
| 2168 | return isThumb2 ? ARM::tBL : ARM::BL; |
| 2169 | } |
| 2170 | |
| 2171 | unsigned ARMFastISel::getLibcallReg(const Twine &Name) { |
Chandler Carruth | 1c82d33 | 2013-07-27 11:23:08 +0000 | [diff] [blame] | 2172 | // Manually compute the global's type to avoid building it when unnecessary. |
| 2173 | Type *GVTy = Type::getInt32PtrTy(*Context, /*AS=*/0); |
| 2174 | EVT LCREVT = TLI.getValueType(GVTy); |
| 2175 | if (!LCREVT.isSimple()) return 0; |
| 2176 | |
Bill Wendling | 76cce19 | 2013-12-29 08:00:04 +0000 | [diff] [blame] | 2177 | GlobalValue *GV = new GlobalVariable(M, Type::getInt32Ty(*Context), false, |
Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 2178 | GlobalValue::ExternalLinkage, nullptr, |
| 2179 | Name); |
Chandler Carruth | 1c82d33 | 2013-07-27 11:23:08 +0000 | [diff] [blame] | 2180 | assert(GV->getType() == GVTy && "We miscomputed the type for the global!"); |
Chad Rosier | 62a144f | 2012-12-17 19:59:43 +0000 | [diff] [blame] | 2181 | return ARMMaterializeGV(GV, LCREVT.getSimpleVT()); |
Eric Christopher | 919772f | 2011-02-22 01:37:10 +0000 | [diff] [blame] | 2182 | } |
| 2183 | |
Eric Christopher | 8b91266 | 2010-09-14 23:03:37 +0000 | [diff] [blame] | 2184 | // A quick function that will emit a call for a named libcall in F with the |
| 2185 | // vector of passed arguments for the Instruction in I. We can assume that we |
Eric Christopher | 7ac602b | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 2186 | // can emit a call for any libcall we can produce. This is an abridged version |
| 2187 | // of the full call infrastructure since we won't need to worry about things |
Eric Christopher | 8b91266 | 2010-09-14 23:03:37 +0000 | [diff] [blame] | 2188 | // like computed function pointers or strange arguments at call sites. |
| 2189 | // TODO: Try to unify this and the normal call bits for ARM, then try to unify |
| 2190 | // with X86. |
Eric Christopher | 7990df1 | 2010-09-28 01:21:42 +0000 | [diff] [blame] | 2191 | bool ARMFastISel::ARMEmitLibcall(const Instruction *I, RTLIB::Libcall Call) { |
| 2192 | CallingConv::ID CC = TLI.getLibcallCallingConv(Call); |
Eric Christopher | 7ac602b | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 2193 | |
Eric Christopher | 8b91266 | 2010-09-14 23:03:37 +0000 | [diff] [blame] | 2194 | // Handle *simple* calls for now. |
Chris Lattner | 229907c | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 2195 | Type *RetTy = I->getType(); |
Duncan Sands | f5dda01 | 2010-11-03 11:35:31 +0000 | [diff] [blame] | 2196 | MVT RetVT; |
Eric Christopher | 8b91266 | 2010-09-14 23:03:37 +0000 | [diff] [blame] | 2197 | if (RetTy->isVoidTy()) |
| 2198 | RetVT = MVT::isVoid; |
| 2199 | else if (!isTypeLegal(RetTy, RetVT)) |
| 2200 | return false; |
Eric Christopher | 7ac602b | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 2201 | |
Chad Rosier | 90f9afe | 2012-05-11 18:51:55 +0000 | [diff] [blame] | 2202 | // Can't handle non-double multi-reg retvals. |
Jush Lu | ac96b76 | 2012-06-14 06:08:19 +0000 | [diff] [blame] | 2203 | if (RetVT != MVT::isVoid && RetVT != MVT::i32) { |
Chad Rosier | 90f9afe | 2012-05-11 18:51:55 +0000 | [diff] [blame] | 2204 | SmallVector<CCValAssign, 16> RVLocs; |
Eric Christopher | b521750 | 2014-08-06 18:45:26 +0000 | [diff] [blame] | 2205 | CCState CCInfo(CC, false, *FuncInfo.MF, RVLocs, *Context); |
Jush Lu | e67e07b | 2012-07-19 09:49:00 +0000 | [diff] [blame] | 2206 | CCInfo.AnalyzeCallResult(RetVT, CCAssignFnForCall(CC, true, false)); |
Chad Rosier | 90f9afe | 2012-05-11 18:51:55 +0000 | [diff] [blame] | 2207 | if (RVLocs.size() >= 2 && RetVT != MVT::f64) |
| 2208 | return false; |
| 2209 | } |
| 2210 | |
Eric Christopher | 7939806 | 2010-09-29 23:11:09 +0000 | [diff] [blame] | 2211 | // Set up the argument vectors. |
Eric Christopher | 8b91266 | 2010-09-14 23:03:37 +0000 | [diff] [blame] | 2212 | SmallVector<Value*, 8> Args; |
| 2213 | SmallVector<unsigned, 8> ArgRegs; |
Duncan Sands | f5dda01 | 2010-11-03 11:35:31 +0000 | [diff] [blame] | 2214 | SmallVector<MVT, 8> ArgVTs; |
Eric Christopher | 8b91266 | 2010-09-14 23:03:37 +0000 | [diff] [blame] | 2215 | SmallVector<ISD::ArgFlagsTy, 8> ArgFlags; |
| 2216 | Args.reserve(I->getNumOperands()); |
| 2217 | ArgRegs.reserve(I->getNumOperands()); |
| 2218 | ArgVTs.reserve(I->getNumOperands()); |
| 2219 | ArgFlags.reserve(I->getNumOperands()); |
Eric Christopher | 7990df1 | 2010-09-28 01:21:42 +0000 | [diff] [blame] | 2220 | for (unsigned i = 0; i < I->getNumOperands(); ++i) { |
Eric Christopher | 8b91266 | 2010-09-14 23:03:37 +0000 | [diff] [blame] | 2221 | Value *Op = I->getOperand(i); |
| 2222 | unsigned Arg = getRegForValue(Op); |
| 2223 | if (Arg == 0) return false; |
Eric Christopher | 7ac602b | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 2224 | |
Chris Lattner | 229907c | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 2225 | Type *ArgTy = Op->getType(); |
Duncan Sands | f5dda01 | 2010-11-03 11:35:31 +0000 | [diff] [blame] | 2226 | MVT ArgVT; |
Eric Christopher | 8b91266 | 2010-09-14 23:03:37 +0000 | [diff] [blame] | 2227 | if (!isTypeLegal(ArgTy, ArgVT)) return false; |
Eric Christopher | 7ac602b | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 2228 | |
Eric Christopher | 8b91266 | 2010-09-14 23:03:37 +0000 | [diff] [blame] | 2229 | ISD::ArgFlagsTy Flags; |
Rafael Espindola | ea09c59 | 2014-02-18 22:05:46 +0000 | [diff] [blame] | 2230 | unsigned OriginalAlignment = DL.getABITypeAlignment(ArgTy); |
Eric Christopher | 8b91266 | 2010-09-14 23:03:37 +0000 | [diff] [blame] | 2231 | Flags.setOrigAlign(OriginalAlignment); |
Eric Christopher | 7ac602b | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 2232 | |
Eric Christopher | 8b91266 | 2010-09-14 23:03:37 +0000 | [diff] [blame] | 2233 | Args.push_back(Op); |
| 2234 | ArgRegs.push_back(Arg); |
| 2235 | ArgVTs.push_back(ArgVT); |
| 2236 | ArgFlags.push_back(Flags); |
| 2237 | } |
Eric Christopher | 7ac602b | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 2238 | |
Eric Christopher | 7939806 | 2010-09-29 23:11:09 +0000 | [diff] [blame] | 2239 | // Handle the arguments now that we've gotten them. |
Eric Christopher | 8b91266 | 2010-09-14 23:03:37 +0000 | [diff] [blame] | 2240 | SmallVector<unsigned, 4> RegArgs; |
Eric Christopher | 7939806 | 2010-09-29 23:11:09 +0000 | [diff] [blame] | 2241 | unsigned NumBytes; |
Jush Lu | e67e07b | 2012-07-19 09:49:00 +0000 | [diff] [blame] | 2242 | if (!ProcessCallArgs(Args, ArgRegs, ArgVTs, ArgFlags, |
| 2243 | RegArgs, CC, NumBytes, false)) |
Eric Christopher | 7939806 | 2010-09-29 23:11:09 +0000 | [diff] [blame] | 2244 | return false; |
Eric Christopher | 7ac602b | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 2245 | |
Chad Rosier | c6916f8 | 2012-06-12 19:25:13 +0000 | [diff] [blame] | 2246 | unsigned CalleeReg = 0; |
Akira Hatanaka | 1bc8af7 | 2015-07-07 06:54:42 +0000 | [diff] [blame^] | 2247 | if (Subtarget->genLongCalls()) { |
Chad Rosier | c6916f8 | 2012-06-12 19:25:13 +0000 | [diff] [blame] | 2248 | CalleeReg = getLibcallReg(TLI.getLibcallName(Call)); |
| 2249 | if (CalleeReg == 0) return false; |
| 2250 | } |
Eric Christopher | 7ac602b | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 2251 | |
Chad Rosier | c6916f8 | 2012-06-12 19:25:13 +0000 | [diff] [blame] | 2252 | // Issue the call. |
Akira Hatanaka | 1bc8af7 | 2015-07-07 06:54:42 +0000 | [diff] [blame^] | 2253 | unsigned CallOpc = ARMSelectCallOp(Subtarget->genLongCalls()); |
Chad Rosier | c6916f8 | 2012-06-12 19:25:13 +0000 | [diff] [blame] | 2254 | MachineInstrBuilder MIB = BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, |
Rafael Espindola | ea09c59 | 2014-02-18 22:05:46 +0000 | [diff] [blame] | 2255 | DbgLoc, TII.get(CallOpc)); |
Jakob Stoklund Olesen | e6afde5 | 2012-08-24 20:52:46 +0000 | [diff] [blame] | 2256 | // BL / BLX don't take a predicate, but tBL / tBLX do. |
| 2257 | if (isThumb2) |
Chad Rosier | c6916f8 | 2012-06-12 19:25:13 +0000 | [diff] [blame] | 2258 | AddDefaultPred(MIB); |
Akira Hatanaka | 1bc8af7 | 2015-07-07 06:54:42 +0000 | [diff] [blame^] | 2259 | if (Subtarget->genLongCalls()) |
Jakob Stoklund Olesen | e6afde5 | 2012-08-24 20:52:46 +0000 | [diff] [blame] | 2260 | MIB.addReg(CalleeReg); |
| 2261 | else |
| 2262 | MIB.addExternalSymbol(TLI.getLibcallName(Call)); |
Chad Rosier | c6916f8 | 2012-06-12 19:25:13 +0000 | [diff] [blame] | 2263 | |
Eric Christopher | 8b91266 | 2010-09-14 23:03:37 +0000 | [diff] [blame] | 2264 | // Add implicit physical register uses to the call. |
| 2265 | for (unsigned i = 0, e = RegArgs.size(); i != e; ++i) |
Jakob Stoklund Olesen | e6afde5 | 2012-08-24 20:52:46 +0000 | [diff] [blame] | 2266 | MIB.addReg(RegArgs[i], RegState::Implicit); |
Eric Christopher | 7ac602b | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 2267 | |
Jakob Stoklund Olesen | fa7a537 | 2012-02-24 01:19:29 +0000 | [diff] [blame] | 2268 | // Add a register mask with the call-preserved registers. |
| 2269 | // Proper defs for return values will be added by setPhysRegsDeadExcept(). |
Eric Christopher | 9deb75d | 2015-03-11 22:42:13 +0000 | [diff] [blame] | 2270 | MIB.addRegMask(TRI.getCallPreservedMask(*FuncInfo.MF, CC)); |
Jakob Stoklund Olesen | fa7a537 | 2012-02-24 01:19:29 +0000 | [diff] [blame] | 2271 | |
Eric Christopher | 7939806 | 2010-09-29 23:11:09 +0000 | [diff] [blame] | 2272 | // Finish off the call including any return values. |
Eric Christopher | 7ac602b | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 2273 | SmallVector<unsigned, 4> UsedRegs; |
Jush Lu | e67e07b | 2012-07-19 09:49:00 +0000 | [diff] [blame] | 2274 | if (!FinishCall(RetVT, UsedRegs, I, CC, NumBytes, false)) return false; |
Eric Christopher | 7ac602b | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 2275 | |
Eric Christopher | 8b91266 | 2010-09-14 23:03:37 +0000 | [diff] [blame] | 2276 | // Set all unused physreg defs as dead. |
| 2277 | static_cast<MachineInstr *>(MIB)->setPhysRegsDeadExcept(UsedRegs, TRI); |
Eric Christopher | 7ac602b | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 2278 | |
Eric Christopher | 8b91266 | 2010-09-14 23:03:37 +0000 | [diff] [blame] | 2279 | return true; |
| 2280 | } |
| 2281 | |
Chad Rosier | a7ebc56 | 2011-11-11 23:31:03 +0000 | [diff] [blame] | 2282 | bool ARMFastISel::SelectCall(const Instruction *I, |
Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 2283 | const char *IntrMemName = nullptr) { |
Eric Christopher | 78f8d4e | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 2284 | const CallInst *CI = cast<CallInst>(I); |
| 2285 | const Value *Callee = CI->getCalledValue(); |
| 2286 | |
Chad Rosier | a7ebc56 | 2011-11-11 23:31:03 +0000 | [diff] [blame] | 2287 | // Can't handle inline asm. |
| 2288 | if (isa<InlineAsm>(Callee)) return false; |
Eric Christopher | 78f8d4e | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 2289 | |
Chad Rosier | df42cf3 | 2012-12-11 00:18:02 +0000 | [diff] [blame] | 2290 | // Allow SelectionDAG isel to handle tail calls. |
| 2291 | if (CI->isTailCall()) return false; |
| 2292 | |
Eric Christopher | 78f8d4e | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 2293 | // Check the calling convention. |
| 2294 | ImmutableCallSite CS(CI); |
| 2295 | CallingConv::ID CC = CS.getCallingConv(); |
Eric Christopher | 167a7002 | 2010-10-18 06:49:12 +0000 | [diff] [blame] | 2296 | |
Eric Christopher | 78f8d4e | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 2297 | // TODO: Avoid some calling conventions? |
Eric Christopher | 7ac602b | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 2298 | |
Chris Lattner | 229907c | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 2299 | PointerType *PT = cast<PointerType>(CS.getCalledValue()->getType()); |
| 2300 | FunctionType *FTy = cast<FunctionType>(PT->getElementType()); |
Jush Lu | e67e07b | 2012-07-19 09:49:00 +0000 | [diff] [blame] | 2301 | bool isVarArg = FTy->isVarArg(); |
Eric Christopher | 7ac602b | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 2302 | |
Eric Christopher | 78f8d4e | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 2303 | // Handle *simple* calls for now. |
Chris Lattner | 229907c | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 2304 | Type *RetTy = I->getType(); |
Duncan Sands | f5dda01 | 2010-11-03 11:35:31 +0000 | [diff] [blame] | 2305 | MVT RetVT; |
Eric Christopher | 78f8d4e | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 2306 | if (RetTy->isVoidTy()) |
| 2307 | RetVT = MVT::isVoid; |
Chad Rosier | 5de1bea | 2011-11-08 00:03:32 +0000 | [diff] [blame] | 2308 | else if (!isTypeLegal(RetTy, RetVT) && RetVT != MVT::i16 && |
| 2309 | RetVT != MVT::i8 && RetVT != MVT::i1) |
Eric Christopher | 78f8d4e | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 2310 | return false; |
Eric Christopher | 7ac602b | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 2311 | |
Chad Rosier | 90f9afe | 2012-05-11 18:51:55 +0000 | [diff] [blame] | 2312 | // Can't handle non-double multi-reg retvals. |
| 2313 | if (RetVT != MVT::isVoid && RetVT != MVT::i1 && RetVT != MVT::i8 && |
| 2314 | RetVT != MVT::i16 && RetVT != MVT::i32) { |
| 2315 | SmallVector<CCValAssign, 16> RVLocs; |
Eric Christopher | b521750 | 2014-08-06 18:45:26 +0000 | [diff] [blame] | 2316 | CCState CCInfo(CC, isVarArg, *FuncInfo.MF, RVLocs, *Context); |
Jush Lu | e67e07b | 2012-07-19 09:49:00 +0000 | [diff] [blame] | 2317 | CCInfo.AnalyzeCallResult(RetVT, CCAssignFnForCall(CC, true, isVarArg)); |
Chad Rosier | 90f9afe | 2012-05-11 18:51:55 +0000 | [diff] [blame] | 2318 | if (RVLocs.size() >= 2 && RetVT != MVT::f64) |
| 2319 | return false; |
| 2320 | } |
| 2321 | |
Eric Christopher | 78f8d4e | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 2322 | // Set up the argument vectors. |
| 2323 | SmallVector<Value*, 8> Args; |
| 2324 | SmallVector<unsigned, 8> ArgRegs; |
Duncan Sands | f5dda01 | 2010-11-03 11:35:31 +0000 | [diff] [blame] | 2325 | SmallVector<MVT, 8> ArgVTs; |
Eric Christopher | 78f8d4e | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 2326 | SmallVector<ISD::ArgFlagsTy, 8> ArgFlags; |
Chad Rosier | dccc479 | 2012-02-15 00:23:55 +0000 | [diff] [blame] | 2327 | unsigned arg_size = CS.arg_size(); |
| 2328 | Args.reserve(arg_size); |
| 2329 | ArgRegs.reserve(arg_size); |
| 2330 | ArgVTs.reserve(arg_size); |
| 2331 | ArgFlags.reserve(arg_size); |
Eric Christopher | 78f8d4e | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 2332 | for (ImmutableCallSite::arg_iterator i = CS.arg_begin(), e = CS.arg_end(); |
| 2333 | i != e; ++i) { |
Chad Rosier | a7ebc56 | 2011-11-11 23:31:03 +0000 | [diff] [blame] | 2334 | // If we're lowering a memory intrinsic instead of a regular call, skip the |
| 2335 | // last two arguments, which shouldn't be passed to the underlying function. |
| 2336 | if (IntrMemName && e-i <= 2) |
| 2337 | break; |
Eric Christopher | 7ac602b | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 2338 | |
Eric Christopher | 78f8d4e | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 2339 | ISD::ArgFlagsTy Flags; |
| 2340 | unsigned AttrInd = i - CS.arg_begin() + 1; |
Bill Wendling | 3d7b0b8 | 2012-12-19 07:18:57 +0000 | [diff] [blame] | 2341 | if (CS.paramHasAttr(AttrInd, Attribute::SExt)) |
Eric Christopher | 78f8d4e | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 2342 | Flags.setSExt(); |
Bill Wendling | 3d7b0b8 | 2012-12-19 07:18:57 +0000 | [diff] [blame] | 2343 | if (CS.paramHasAttr(AttrInd, Attribute::ZExt)) |
Eric Christopher | 78f8d4e | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 2344 | Flags.setZExt(); |
| 2345 | |
Chad Rosier | 8a98ec4 | 2011-11-04 00:58:10 +0000 | [diff] [blame] | 2346 | // FIXME: Only handle *easy* calls for now. |
Bill Wendling | 3d7b0b8 | 2012-12-19 07:18:57 +0000 | [diff] [blame] | 2347 | if (CS.paramHasAttr(AttrInd, Attribute::InReg) || |
| 2348 | CS.paramHasAttr(AttrInd, Attribute::StructRet) || |
| 2349 | CS.paramHasAttr(AttrInd, Attribute::Nest) || |
| 2350 | CS.paramHasAttr(AttrInd, Attribute::ByVal)) |
Eric Christopher | 78f8d4e | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 2351 | return false; |
| 2352 | |
Chris Lattner | 229907c | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 2353 | Type *ArgTy = (*i)->getType(); |
Duncan Sands | f5dda01 | 2010-11-03 11:35:31 +0000 | [diff] [blame] | 2354 | MVT ArgVT; |
Chad Rosier | d0191a5 | 2011-11-05 20:16:15 +0000 | [diff] [blame] | 2355 | if (!isTypeLegal(ArgTy, ArgVT) && ArgVT != MVT::i16 && ArgVT != MVT::i8 && |
| 2356 | ArgVT != MVT::i1) |
Eric Christopher | 78f8d4e | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 2357 | return false; |
Chad Rosier | ee93ff7 | 2011-11-18 01:17:34 +0000 | [diff] [blame] | 2358 | |
| 2359 | unsigned Arg = getRegForValue(*i); |
| 2360 | if (Arg == 0) |
| 2361 | return false; |
| 2362 | |
Rafael Espindola | ea09c59 | 2014-02-18 22:05:46 +0000 | [diff] [blame] | 2363 | unsigned OriginalAlignment = DL.getABITypeAlignment(ArgTy); |
Eric Christopher | 78f8d4e | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 2364 | Flags.setOrigAlign(OriginalAlignment); |
Eric Christopher | 7ac602b | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 2365 | |
Eric Christopher | 78f8d4e | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 2366 | Args.push_back(*i); |
| 2367 | ArgRegs.push_back(Arg); |
| 2368 | ArgVTs.push_back(ArgVT); |
| 2369 | ArgFlags.push_back(Flags); |
| 2370 | } |
Eric Christopher | 7ac602b | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 2371 | |
Eric Christopher | 78f8d4e | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 2372 | // Handle the arguments now that we've gotten them. |
| 2373 | SmallVector<unsigned, 4> RegArgs; |
| 2374 | unsigned NumBytes; |
Jush Lu | e67e07b | 2012-07-19 09:49:00 +0000 | [diff] [blame] | 2375 | if (!ProcessCallArgs(Args, ArgRegs, ArgVTs, ArgFlags, |
| 2376 | RegArgs, CC, NumBytes, isVarArg)) |
Eric Christopher | 78f8d4e | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 2377 | return false; |
Eric Christopher | 7ac602b | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 2378 | |
Chad Rosier | c6916f8 | 2012-06-12 19:25:13 +0000 | [diff] [blame] | 2379 | bool UseReg = false; |
Chad Rosier | 223faf7 | 2012-05-23 18:38:57 +0000 | [diff] [blame] | 2380 | const GlobalValue *GV = dyn_cast<GlobalValue>(Callee); |
Akira Hatanaka | 1bc8af7 | 2015-07-07 06:54:42 +0000 | [diff] [blame^] | 2381 | if (!GV || Subtarget->genLongCalls()) UseReg = true; |
Chad Rosier | 223faf7 | 2012-05-23 18:38:57 +0000 | [diff] [blame] | 2382 | |
Chad Rosier | c6916f8 | 2012-06-12 19:25:13 +0000 | [diff] [blame] | 2383 | unsigned CalleeReg = 0; |
| 2384 | if (UseReg) { |
| 2385 | if (IntrMemName) |
| 2386 | CalleeReg = getLibcallReg(IntrMemName); |
| 2387 | else |
| 2388 | CalleeReg = getRegForValue(Callee); |
| 2389 | |
Chad Rosier | 223faf7 | 2012-05-23 18:38:57 +0000 | [diff] [blame] | 2390 | if (CalleeReg == 0) return false; |
| 2391 | } |
| 2392 | |
Chad Rosier | c6916f8 | 2012-06-12 19:25:13 +0000 | [diff] [blame] | 2393 | // Issue the call. |
| 2394 | unsigned CallOpc = ARMSelectCallOp(UseReg); |
| 2395 | MachineInstrBuilder MIB = BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, |
Rafael Espindola | ea09c59 | 2014-02-18 22:05:46 +0000 | [diff] [blame] | 2396 | DbgLoc, TII.get(CallOpc)); |
Chad Rosier | c6916f8 | 2012-06-12 19:25:13 +0000 | [diff] [blame] | 2397 | |
Logan Chien | 2361f51 | 2013-08-22 12:08:04 +0000 | [diff] [blame] | 2398 | unsigned char OpFlags = 0; |
| 2399 | |
| 2400 | // Add MO_PLT for global address or external symbol in the PIC relocation |
| 2401 | // model. |
| 2402 | if (Subtarget->isTargetELF() && TM.getRelocationModel() == Reloc::PIC_) |
| 2403 | OpFlags = ARMII::MO_PLT; |
| 2404 | |
Jakob Stoklund Olesen | e6afde5 | 2012-08-24 20:52:46 +0000 | [diff] [blame] | 2405 | // ARM calls don't take a predicate, but tBL / tBLX do. |
| 2406 | if(isThumb2) |
Chad Rosier | c6916f8 | 2012-06-12 19:25:13 +0000 | [diff] [blame] | 2407 | AddDefaultPred(MIB); |
Jakob Stoklund Olesen | e6afde5 | 2012-08-24 20:52:46 +0000 | [diff] [blame] | 2408 | if (UseReg) |
| 2409 | MIB.addReg(CalleeReg); |
| 2410 | else if (!IntrMemName) |
Logan Chien | 2361f51 | 2013-08-22 12:08:04 +0000 | [diff] [blame] | 2411 | MIB.addGlobalAddress(GV, 0, OpFlags); |
Jakob Stoklund Olesen | e6afde5 | 2012-08-24 20:52:46 +0000 | [diff] [blame] | 2412 | else |
Logan Chien | 2361f51 | 2013-08-22 12:08:04 +0000 | [diff] [blame] | 2413 | MIB.addExternalSymbol(IntrMemName, OpFlags); |
Jush Lu | ac96b76 | 2012-06-14 06:08:19 +0000 | [diff] [blame] | 2414 | |
Eric Christopher | 78f8d4e | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 2415 | // Add implicit physical register uses to the call. |
| 2416 | for (unsigned i = 0, e = RegArgs.size(); i != e; ++i) |
Jakob Stoklund Olesen | e6afde5 | 2012-08-24 20:52:46 +0000 | [diff] [blame] | 2417 | MIB.addReg(RegArgs[i], RegState::Implicit); |
Eric Christopher | 7ac602b | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 2418 | |
Jakob Stoklund Olesen | fa7a537 | 2012-02-24 01:19:29 +0000 | [diff] [blame] | 2419 | // Add a register mask with the call-preserved registers. |
| 2420 | // Proper defs for return values will be added by setPhysRegsDeadExcept(). |
Eric Christopher | 9deb75d | 2015-03-11 22:42:13 +0000 | [diff] [blame] | 2421 | MIB.addRegMask(TRI.getCallPreservedMask(*FuncInfo.MF, CC)); |
Jakob Stoklund Olesen | fa7a537 | 2012-02-24 01:19:29 +0000 | [diff] [blame] | 2422 | |
Eric Christopher | 78f8d4e | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 2423 | // Finish off the call including any return values. |
Eric Christopher | 7ac602b | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 2424 | SmallVector<unsigned, 4> UsedRegs; |
Jush Lu | e67e07b | 2012-07-19 09:49:00 +0000 | [diff] [blame] | 2425 | if (!FinishCall(RetVT, UsedRegs, I, CC, NumBytes, isVarArg)) |
| 2426 | return false; |
Eric Christopher | 7ac602b | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 2427 | |
Eric Christopher | 78f8d4e | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 2428 | // Set all unused physreg defs as dead. |
| 2429 | static_cast<MachineInstr *>(MIB)->setPhysRegsDeadExcept(UsedRegs, TRI); |
Eric Christopher | 7ac602b | 2010-10-11 08:38:55 +0000 | [diff] [blame] | 2430 | |
Eric Christopher | 78f8d4e | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 2431 | return true; |
Eric Christopher | 78f8d4e | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 2432 | } |
| 2433 | |
Chad Rosier | 057b6d3 | 2011-11-14 23:04:09 +0000 | [diff] [blame] | 2434 | bool ARMFastISel::ARMIsMemCpySmall(uint64_t Len) { |
Chad Rosier | ab7223e | 2011-11-14 22:46:17 +0000 | [diff] [blame] | 2435 | return Len <= 16; |
| 2436 | } |
| 2437 | |
Jim Grosbach | 0c509fa | 2012-04-06 23:43:50 +0000 | [diff] [blame] | 2438 | bool ARMFastISel::ARMTryEmitSmallMemCpy(Address Dest, Address Src, |
Chad Rosier | 9f5c68a | 2012-12-06 01:34:31 +0000 | [diff] [blame] | 2439 | uint64_t Len, unsigned Alignment) { |
Chad Rosier | ab7223e | 2011-11-14 22:46:17 +0000 | [diff] [blame] | 2440 | // Make sure we don't bloat code by inlining very large memcpy's. |
Chad Rosier | 057b6d3 | 2011-11-14 23:04:09 +0000 | [diff] [blame] | 2441 | if (!ARMIsMemCpySmall(Len)) |
Chad Rosier | ab7223e | 2011-11-14 22:46:17 +0000 | [diff] [blame] | 2442 | return false; |
| 2443 | |
Chad Rosier | ab7223e | 2011-11-14 22:46:17 +0000 | [diff] [blame] | 2444 | while (Len) { |
| 2445 | MVT VT; |
Chad Rosier | 9f5c68a | 2012-12-06 01:34:31 +0000 | [diff] [blame] | 2446 | if (!Alignment || Alignment >= 4) { |
| 2447 | if (Len >= 4) |
| 2448 | VT = MVT::i32; |
| 2449 | else if (Len >= 2) |
| 2450 | VT = MVT::i16; |
| 2451 | else { |
| 2452 | assert (Len == 1 && "Expected a length of 1!"); |
| 2453 | VT = MVT::i8; |
| 2454 | } |
| 2455 | } else { |
| 2456 | // Bound based on alignment. |
| 2457 | if (Len >= 2 && Alignment == 2) |
| 2458 | VT = MVT::i16; |
| 2459 | else { |
Chad Rosier | 9f5c68a | 2012-12-06 01:34:31 +0000 | [diff] [blame] | 2460 | VT = MVT::i8; |
| 2461 | } |
Chad Rosier | ab7223e | 2011-11-14 22:46:17 +0000 | [diff] [blame] | 2462 | } |
| 2463 | |
| 2464 | bool RV; |
| 2465 | unsigned ResultReg; |
| 2466 | RV = ARMEmitLoad(VT, ResultReg, Src); |
Eric Christopher | d284c1d | 2012-01-11 20:55:27 +0000 | [diff] [blame] | 2467 | assert (RV == true && "Should be able to handle this load."); |
Chad Rosier | ab7223e | 2011-11-14 22:46:17 +0000 | [diff] [blame] | 2468 | RV = ARMEmitStore(VT, ResultReg, Dest); |
Eric Christopher | d284c1d | 2012-01-11 20:55:27 +0000 | [diff] [blame] | 2469 | assert (RV == true && "Should be able to handle this store."); |
Duncan Sands | ae22c60 | 2012-02-05 14:20:11 +0000 | [diff] [blame] | 2470 | (void)RV; |
Chad Rosier | ab7223e | 2011-11-14 22:46:17 +0000 | [diff] [blame] | 2471 | |
| 2472 | unsigned Size = VT.getSizeInBits()/8; |
| 2473 | Len -= Size; |
| 2474 | Dest.Offset += Size; |
| 2475 | Src.Offset += Size; |
| 2476 | } |
| 2477 | |
| 2478 | return true; |
| 2479 | } |
| 2480 | |
Chad Rosier | a7ebc56 | 2011-11-11 23:31:03 +0000 | [diff] [blame] | 2481 | bool ARMFastISel::SelectIntrinsicCall(const IntrinsicInst &I) { |
| 2482 | // FIXME: Handle more intrinsics. |
| 2483 | switch (I.getIntrinsicID()) { |
| 2484 | default: return false; |
Chad Rosier | 820d248c | 2012-05-30 17:23:22 +0000 | [diff] [blame] | 2485 | case Intrinsic::frameaddress: { |
| 2486 | MachineFrameInfo *MFI = FuncInfo.MF->getFrameInfo(); |
| 2487 | MFI->setFrameAddressIsTaken(true); |
| 2488 | |
Craig Topper | 61e88f4 | 2014-11-21 05:58:21 +0000 | [diff] [blame] | 2489 | unsigned LdrOpc = isThumb2 ? ARM::t2LDRi12 : ARM::LDRi12; |
| 2490 | const TargetRegisterClass *RC = isThumb2 ? &ARM::tGPRRegClass |
| 2491 | : &ARM::GPRRegClass; |
Chad Rosier | 820d248c | 2012-05-30 17:23:22 +0000 | [diff] [blame] | 2492 | |
| 2493 | const ARMBaseRegisterInfo *RegInfo = |
Eric Christopher | 1b21f00 | 2015-01-29 00:19:33 +0000 | [diff] [blame] | 2494 | static_cast<const ARMBaseRegisterInfo *>(Subtarget->getRegisterInfo()); |
Chad Rosier | 820d248c | 2012-05-30 17:23:22 +0000 | [diff] [blame] | 2495 | unsigned FramePtr = RegInfo->getFrameRegister(*(FuncInfo.MF)); |
| 2496 | unsigned SrcReg = FramePtr; |
| 2497 | |
| 2498 | // Recursively load frame address |
| 2499 | // ldr r0 [fp] |
| 2500 | // ldr r0 [r0] |
| 2501 | // ldr r0 [r0] |
| 2502 | // ... |
| 2503 | unsigned DestReg; |
| 2504 | unsigned Depth = cast<ConstantInt>(I.getOperand(0))->getZExtValue(); |
| 2505 | while (Depth--) { |
| 2506 | DestReg = createResultReg(RC); |
Rafael Espindola | ea09c59 | 2014-02-18 22:05:46 +0000 | [diff] [blame] | 2507 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, |
Chad Rosier | 820d248c | 2012-05-30 17:23:22 +0000 | [diff] [blame] | 2508 | TII.get(LdrOpc), DestReg) |
| 2509 | .addReg(SrcReg).addImm(0)); |
| 2510 | SrcReg = DestReg; |
| 2511 | } |
Juergen Ributzka | 5b8bb4d | 2014-09-03 20:56:52 +0000 | [diff] [blame] | 2512 | updateValueMap(&I, SrcReg); |
Chad Rosier | 820d248c | 2012-05-30 17:23:22 +0000 | [diff] [blame] | 2513 | return true; |
| 2514 | } |
Chad Rosier | a7ebc56 | 2011-11-11 23:31:03 +0000 | [diff] [blame] | 2515 | case Intrinsic::memcpy: |
| 2516 | case Intrinsic::memmove: { |
Chad Rosier | a7ebc56 | 2011-11-11 23:31:03 +0000 | [diff] [blame] | 2517 | const MemTransferInst &MTI = cast<MemTransferInst>(I); |
| 2518 | // Don't handle volatile. |
| 2519 | if (MTI.isVolatile()) |
| 2520 | return false; |
Chad Rosier | ab7223e | 2011-11-14 22:46:17 +0000 | [diff] [blame] | 2521 | |
| 2522 | // Disable inlining for memmove before calls to ComputeAddress. Otherwise, |
| 2523 | // we would emit dead code because we don't currently handle memmoves. |
| 2524 | bool isMemCpy = (I.getIntrinsicID() == Intrinsic::memcpy); |
| 2525 | if (isa<ConstantInt>(MTI.getLength()) && isMemCpy) { |
Chad Rosier | 057b6d3 | 2011-11-14 23:04:09 +0000 | [diff] [blame] | 2526 | // Small memcpy's are common enough that we want to do them without a call |
| 2527 | // if possible. |
Chad Rosier | ab7223e | 2011-11-14 22:46:17 +0000 | [diff] [blame] | 2528 | uint64_t Len = cast<ConstantInt>(MTI.getLength())->getZExtValue(); |
Chad Rosier | 057b6d3 | 2011-11-14 23:04:09 +0000 | [diff] [blame] | 2529 | if (ARMIsMemCpySmall(Len)) { |
Chad Rosier | ab7223e | 2011-11-14 22:46:17 +0000 | [diff] [blame] | 2530 | Address Dest, Src; |
| 2531 | if (!ARMComputeAddress(MTI.getRawDest(), Dest) || |
| 2532 | !ARMComputeAddress(MTI.getRawSource(), Src)) |
| 2533 | return false; |
Chad Rosier | 9f5c68a | 2012-12-06 01:34:31 +0000 | [diff] [blame] | 2534 | unsigned Alignment = MTI.getAlignment(); |
| 2535 | if (ARMTryEmitSmallMemCpy(Dest, Src, Len, Alignment)) |
Chad Rosier | ab7223e | 2011-11-14 22:46:17 +0000 | [diff] [blame] | 2536 | return true; |
| 2537 | } |
| 2538 | } |
Jush Lu | ac96b76 | 2012-06-14 06:08:19 +0000 | [diff] [blame] | 2539 | |
Chad Rosier | a7ebc56 | 2011-11-11 23:31:03 +0000 | [diff] [blame] | 2540 | if (!MTI.getLength()->getType()->isIntegerTy(32)) |
| 2541 | return false; |
Jush Lu | ac96b76 | 2012-06-14 06:08:19 +0000 | [diff] [blame] | 2542 | |
Chad Rosier | a7ebc56 | 2011-11-11 23:31:03 +0000 | [diff] [blame] | 2543 | if (MTI.getSourceAddressSpace() > 255 || MTI.getDestAddressSpace() > 255) |
| 2544 | return false; |
| 2545 | |
| 2546 | const char *IntrMemName = isa<MemCpyInst>(I) ? "memcpy" : "memmove"; |
| 2547 | return SelectCall(&I, IntrMemName); |
| 2548 | } |
| 2549 | case Intrinsic::memset: { |
| 2550 | const MemSetInst &MSI = cast<MemSetInst>(I); |
| 2551 | // Don't handle volatile. |
| 2552 | if (MSI.isVolatile()) |
| 2553 | return false; |
Jush Lu | ac96b76 | 2012-06-14 06:08:19 +0000 | [diff] [blame] | 2554 | |
Chad Rosier | a7ebc56 | 2011-11-11 23:31:03 +0000 | [diff] [blame] | 2555 | if (!MSI.getLength()->getType()->isIntegerTy(32)) |
| 2556 | return false; |
Jush Lu | ac96b76 | 2012-06-14 06:08:19 +0000 | [diff] [blame] | 2557 | |
Chad Rosier | a7ebc56 | 2011-11-11 23:31:03 +0000 | [diff] [blame] | 2558 | if (MSI.getDestAddressSpace() > 255) |
| 2559 | return false; |
Jush Lu | ac96b76 | 2012-06-14 06:08:19 +0000 | [diff] [blame] | 2560 | |
Chad Rosier | a7ebc56 | 2011-11-11 23:31:03 +0000 | [diff] [blame] | 2561 | return SelectCall(&I, "memset"); |
| 2562 | } |
Chad Rosier | aa9cb9d | 2012-05-11 21:33:49 +0000 | [diff] [blame] | 2563 | case Intrinsic::trap: { |
Rafael Espindola | ea09c59 | 2014-02-18 22:05:46 +0000 | [diff] [blame] | 2564 | BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, TII.get( |
Eli Bendersky | 2e2ce49 | 2013-01-30 16:30:19 +0000 | [diff] [blame] | 2565 | Subtarget->useNaClTrap() ? ARM::TRAPNaCl : ARM::TRAP)); |
Chad Rosier | aa9cb9d | 2012-05-11 21:33:49 +0000 | [diff] [blame] | 2566 | return true; |
| 2567 | } |
Chad Rosier | a7ebc56 | 2011-11-11 23:31:03 +0000 | [diff] [blame] | 2568 | } |
Chad Rosier | a7ebc56 | 2011-11-11 23:31:03 +0000 | [diff] [blame] | 2569 | } |
| 2570 | |
Chad Rosier | ee7e452 | 2011-11-02 00:18:48 +0000 | [diff] [blame] | 2571 | bool ARMFastISel::SelectTrunc(const Instruction *I) { |
Jush Lu | ac96b76 | 2012-06-14 06:08:19 +0000 | [diff] [blame] | 2572 | // The high bits for a type smaller than the register size are assumed to be |
Chad Rosier | ee7e452 | 2011-11-02 00:18:48 +0000 | [diff] [blame] | 2573 | // undefined. |
| 2574 | Value *Op = I->getOperand(0); |
| 2575 | |
| 2576 | EVT SrcVT, DestVT; |
| 2577 | SrcVT = TLI.getValueType(Op->getType(), true); |
| 2578 | DestVT = TLI.getValueType(I->getType(), true); |
| 2579 | |
| 2580 | if (SrcVT != MVT::i32 && SrcVT != MVT::i16 && SrcVT != MVT::i8) |
| 2581 | return false; |
| 2582 | if (DestVT != MVT::i16 && DestVT != MVT::i8 && DestVT != MVT::i1) |
| 2583 | return false; |
| 2584 | |
| 2585 | unsigned SrcReg = getRegForValue(Op); |
| 2586 | if (!SrcReg) return false; |
| 2587 | |
| 2588 | // Because the high bits are undefined, a truncate doesn't generate |
| 2589 | // any code. |
Juergen Ributzka | 5b8bb4d | 2014-09-03 20:56:52 +0000 | [diff] [blame] | 2590 | updateValueMap(I, SrcReg); |
Chad Rosier | ee7e452 | 2011-11-02 00:18:48 +0000 | [diff] [blame] | 2591 | return true; |
| 2592 | } |
| 2593 | |
Chad Rosier | 62a144f | 2012-12-17 19:59:43 +0000 | [diff] [blame] | 2594 | unsigned ARMFastISel::ARMEmitIntExt(MVT SrcVT, unsigned SrcReg, MVT DestVT, |
Chad Rosier | 4489f94 | 2011-11-02 17:20:24 +0000 | [diff] [blame] | 2595 | bool isZExt) { |
Eli Friedman | c703551 | 2011-05-25 23:49:02 +0000 | [diff] [blame] | 2596 | if (DestVT != MVT::i32 && DestVT != MVT::i16 && DestVT != MVT::i8) |
Chad Rosier | 4489f94 | 2011-11-02 17:20:24 +0000 | [diff] [blame] | 2597 | return 0; |
JF Bastien | 06ce03d | 2013-06-07 20:10:37 +0000 | [diff] [blame] | 2598 | if (SrcVT != MVT::i16 && SrcVT != MVT::i8 && SrcVT != MVT::i1) |
Chad Rosier | 4489f94 | 2011-11-02 17:20:24 +0000 | [diff] [blame] | 2599 | return 0; |
JF Bastien | 06ce03d | 2013-06-07 20:10:37 +0000 | [diff] [blame] | 2600 | |
| 2601 | // Table of which combinations can be emitted as a single instruction, |
| 2602 | // and which will require two. |
| 2603 | static const uint8_t isSingleInstrTbl[3][2][2][2] = { |
| 2604 | // ARM Thumb |
| 2605 | // !hasV6Ops hasV6Ops !hasV6Ops hasV6Ops |
| 2606 | // ext: s z s z s z s z |
| 2607 | /* 1 */ { { { 0, 1 }, { 0, 1 } }, { { 0, 0 }, { 0, 1 } } }, |
| 2608 | /* 8 */ { { { 0, 1 }, { 1, 1 } }, { { 0, 0 }, { 1, 1 } } }, |
| 2609 | /* 16 */ { { { 0, 0 }, { 1, 1 } }, { { 0, 0 }, { 1, 1 } } } |
| 2610 | }; |
| 2611 | |
| 2612 | // Target registers for: |
| 2613 | // - For ARM can never be PC. |
| 2614 | // - For 16-bit Thumb are restricted to lower 8 registers. |
| 2615 | // - For 32-bit Thumb are restricted to non-SP and non-PC. |
| 2616 | static const TargetRegisterClass *RCTbl[2][2] = { |
| 2617 | // Instructions: Two Single |
| 2618 | /* ARM */ { &ARM::GPRnopcRegClass, &ARM::GPRnopcRegClass }, |
| 2619 | /* Thumb */ { &ARM::tGPRRegClass, &ARM::rGPRRegClass } |
| 2620 | }; |
| 2621 | |
| 2622 | // Table governing the instruction(s) to be emitted. |
JF Bastien | cd4c64d | 2013-07-17 05:46:46 +0000 | [diff] [blame] | 2623 | static const struct InstructionTable { |
| 2624 | uint32_t Opc : 16; |
| 2625 | uint32_t hasS : 1; // Some instructions have an S bit, always set it to 0. |
| 2626 | uint32_t Shift : 7; // For shift operand addressing mode, used by MOVsi. |
| 2627 | uint32_t Imm : 8; // All instructions have either a shift or a mask. |
| 2628 | } IT[2][2][3][2] = { |
JF Bastien | 06ce03d | 2013-06-07 20:10:37 +0000 | [diff] [blame] | 2629 | { // Two instructions (first is left shift, second is in this table). |
JF Bastien | cd4c64d | 2013-07-17 05:46:46 +0000 | [diff] [blame] | 2630 | { // ARM Opc S Shift Imm |
| 2631 | /* 1 bit sext */ { { ARM::MOVsi , 1, ARM_AM::asr , 31 }, |
| 2632 | /* 1 bit zext */ { ARM::MOVsi , 1, ARM_AM::lsr , 31 } }, |
| 2633 | /* 8 bit sext */ { { ARM::MOVsi , 1, ARM_AM::asr , 24 }, |
| 2634 | /* 8 bit zext */ { ARM::MOVsi , 1, ARM_AM::lsr , 24 } }, |
| 2635 | /* 16 bit sext */ { { ARM::MOVsi , 1, ARM_AM::asr , 16 }, |
| 2636 | /* 16 bit zext */ { ARM::MOVsi , 1, ARM_AM::lsr , 16 } } |
JF Bastien | 06ce03d | 2013-06-07 20:10:37 +0000 | [diff] [blame] | 2637 | }, |
JF Bastien | cd4c64d | 2013-07-17 05:46:46 +0000 | [diff] [blame] | 2638 | { // Thumb Opc S Shift Imm |
| 2639 | /* 1 bit sext */ { { ARM::tASRri , 0, ARM_AM::no_shift, 31 }, |
| 2640 | /* 1 bit zext */ { ARM::tLSRri , 0, ARM_AM::no_shift, 31 } }, |
| 2641 | /* 8 bit sext */ { { ARM::tASRri , 0, ARM_AM::no_shift, 24 }, |
| 2642 | /* 8 bit zext */ { ARM::tLSRri , 0, ARM_AM::no_shift, 24 } }, |
| 2643 | /* 16 bit sext */ { { ARM::tASRri , 0, ARM_AM::no_shift, 16 }, |
| 2644 | /* 16 bit zext */ { ARM::tLSRri , 0, ARM_AM::no_shift, 16 } } |
JF Bastien | 06ce03d | 2013-06-07 20:10:37 +0000 | [diff] [blame] | 2645 | } |
| 2646 | }, |
| 2647 | { // Single instruction. |
JF Bastien | cd4c64d | 2013-07-17 05:46:46 +0000 | [diff] [blame] | 2648 | { // ARM Opc S Shift Imm |
| 2649 | /* 1 bit sext */ { { ARM::KILL , 0, ARM_AM::no_shift, 0 }, |
| 2650 | /* 1 bit zext */ { ARM::ANDri , 1, ARM_AM::no_shift, 1 } }, |
| 2651 | /* 8 bit sext */ { { ARM::SXTB , 0, ARM_AM::no_shift, 0 }, |
| 2652 | /* 8 bit zext */ { ARM::ANDri , 1, ARM_AM::no_shift, 255 } }, |
| 2653 | /* 16 bit sext */ { { ARM::SXTH , 0, ARM_AM::no_shift, 0 }, |
| 2654 | /* 16 bit zext */ { ARM::UXTH , 0, ARM_AM::no_shift, 0 } } |
JF Bastien | 06ce03d | 2013-06-07 20:10:37 +0000 | [diff] [blame] | 2655 | }, |
JF Bastien | cd4c64d | 2013-07-17 05:46:46 +0000 | [diff] [blame] | 2656 | { // Thumb Opc S Shift Imm |
| 2657 | /* 1 bit sext */ { { ARM::KILL , 0, ARM_AM::no_shift, 0 }, |
| 2658 | /* 1 bit zext */ { ARM::t2ANDri, 1, ARM_AM::no_shift, 1 } }, |
| 2659 | /* 8 bit sext */ { { ARM::t2SXTB , 0, ARM_AM::no_shift, 0 }, |
| 2660 | /* 8 bit zext */ { ARM::t2ANDri, 1, ARM_AM::no_shift, 255 } }, |
| 2661 | /* 16 bit sext */ { { ARM::t2SXTH , 0, ARM_AM::no_shift, 0 }, |
| 2662 | /* 16 bit zext */ { ARM::t2UXTH , 0, ARM_AM::no_shift, 0 } } |
JF Bastien | 06ce03d | 2013-06-07 20:10:37 +0000 | [diff] [blame] | 2663 | } |
| 2664 | } |
| 2665 | }; |
| 2666 | |
| 2667 | unsigned SrcBits = SrcVT.getSizeInBits(); |
| 2668 | unsigned DestBits = DestVT.getSizeInBits(); |
JF Bastien | 60a2442 | 2013-06-08 00:51:51 +0000 | [diff] [blame] | 2669 | (void) DestBits; |
JF Bastien | 06ce03d | 2013-06-07 20:10:37 +0000 | [diff] [blame] | 2670 | assert((SrcBits < DestBits) && "can only extend to larger types"); |
| 2671 | assert((DestBits == 32 || DestBits == 16 || DestBits == 8) && |
| 2672 | "other sizes unimplemented"); |
| 2673 | assert((SrcBits == 16 || SrcBits == 8 || SrcBits == 1) && |
| 2674 | "other sizes unimplemented"); |
| 2675 | |
| 2676 | bool hasV6Ops = Subtarget->hasV6Ops(); |
JF Bastien | cd4c64d | 2013-07-17 05:46:46 +0000 | [diff] [blame] | 2677 | unsigned Bitness = SrcBits / 8; // {1,8,16}=>{0,1,2} |
JF Bastien | 06ce03d | 2013-06-07 20:10:37 +0000 | [diff] [blame] | 2678 | assert((Bitness < 3) && "sanity-check table bounds"); |
| 2679 | |
| 2680 | bool isSingleInstr = isSingleInstrTbl[Bitness][isThumb2][hasV6Ops][isZExt]; |
| 2681 | const TargetRegisterClass *RC = RCTbl[isThumb2][isSingleInstr]; |
JF Bastien | cd4c64d | 2013-07-17 05:46:46 +0000 | [diff] [blame] | 2682 | const InstructionTable *ITP = &IT[isSingleInstr][isThumb2][Bitness][isZExt]; |
| 2683 | unsigned Opc = ITP->Opc; |
JF Bastien | 06ce03d | 2013-06-07 20:10:37 +0000 | [diff] [blame] | 2684 | assert(ARM::KILL != Opc && "Invalid table entry"); |
JF Bastien | cd4c64d | 2013-07-17 05:46:46 +0000 | [diff] [blame] | 2685 | unsigned hasS = ITP->hasS; |
| 2686 | ARM_AM::ShiftOpc Shift = (ARM_AM::ShiftOpc) ITP->Shift; |
| 2687 | assert(((Shift == ARM_AM::no_shift) == (Opc != ARM::MOVsi)) && |
| 2688 | "only MOVsi has shift operand addressing mode"); |
| 2689 | unsigned Imm = ITP->Imm; |
JF Bastien | 06ce03d | 2013-06-07 20:10:37 +0000 | [diff] [blame] | 2690 | |
| 2691 | // 16-bit Thumb instructions always set CPSR (unless they're in an IT block). |
| 2692 | bool setsCPSR = &ARM::tGPRRegClass == RC; |
JF Bastien | cd4c64d | 2013-07-17 05:46:46 +0000 | [diff] [blame] | 2693 | unsigned LSLOpc = isThumb2 ? ARM::tLSLri : ARM::MOVsi; |
JF Bastien | 06ce03d | 2013-06-07 20:10:37 +0000 | [diff] [blame] | 2694 | unsigned ResultReg; |
JF Bastien | cd4c64d | 2013-07-17 05:46:46 +0000 | [diff] [blame] | 2695 | // MOVsi encodes shift and immediate in shift operand addressing mode. |
| 2696 | // The following condition has the same value when emitting two |
| 2697 | // instruction sequences: both are shifts. |
| 2698 | bool ImmIsSO = (Shift != ARM_AM::no_shift); |
JF Bastien | 06ce03d | 2013-06-07 20:10:37 +0000 | [diff] [blame] | 2699 | |
| 2700 | // Either one or two instructions are emitted. |
| 2701 | // They're always of the form: |
| 2702 | // dst = in OP imm |
| 2703 | // CPSR is set only by 16-bit Thumb instructions. |
| 2704 | // Predicate, if any, is AL. |
| 2705 | // S bit, if available, is always 0. |
| 2706 | // When two are emitted the first's result will feed as the second's input, |
| 2707 | // that value is then dead. |
| 2708 | unsigned NumInstrsEmitted = isSingleInstr ? 1 : 2; |
| 2709 | for (unsigned Instr = 0; Instr != NumInstrsEmitted; ++Instr) { |
| 2710 | ResultReg = createResultReg(RC); |
JF Bastien | cd4c64d | 2013-07-17 05:46:46 +0000 | [diff] [blame] | 2711 | bool isLsl = (0 == Instr) && !isSingleInstr; |
| 2712 | unsigned Opcode = isLsl ? LSLOpc : Opc; |
| 2713 | ARM_AM::ShiftOpc ShiftAM = isLsl ? ARM_AM::lsl : Shift; |
| 2714 | unsigned ImmEnc = ImmIsSO ? ARM_AM::getSORegOpc(ShiftAM, Imm) : Imm; |
JF Bastien | 06ce03d | 2013-06-07 20:10:37 +0000 | [diff] [blame] | 2715 | bool isKill = 1 == Instr; |
| 2716 | MachineInstrBuilder MIB = BuildMI( |
Rafael Espindola | ea09c59 | 2014-02-18 22:05:46 +0000 | [diff] [blame] | 2717 | *FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, TII.get(Opcode), ResultReg); |
JF Bastien | 06ce03d | 2013-06-07 20:10:37 +0000 | [diff] [blame] | 2718 | if (setsCPSR) |
| 2719 | MIB.addReg(ARM::CPSR, RegState::Define); |
Jim Grosbach | 3fa7491 | 2013-08-16 23:37:36 +0000 | [diff] [blame] | 2720 | SrcReg = constrainOperandRegClass(TII.get(Opcode), SrcReg, 1 + setsCPSR); |
JF Bastien | cd4c64d | 2013-07-17 05:46:46 +0000 | [diff] [blame] | 2721 | AddDefaultPred(MIB.addReg(SrcReg, isKill * RegState::Kill).addImm(ImmEnc)); |
JF Bastien | 06ce03d | 2013-06-07 20:10:37 +0000 | [diff] [blame] | 2722 | if (hasS) |
| 2723 | AddDefaultCC(MIB); |
| 2724 | // Second instruction consumes the first's result. |
| 2725 | SrcReg = ResultReg; |
Eli Friedman | c703551 | 2011-05-25 23:49:02 +0000 | [diff] [blame] | 2726 | } |
| 2727 | |
Chad Rosier | 4489f94 | 2011-11-02 17:20:24 +0000 | [diff] [blame] | 2728 | return ResultReg; |
| 2729 | } |
| 2730 | |
| 2731 | bool ARMFastISel::SelectIntExt(const Instruction *I) { |
| 2732 | // On ARM, in general, integer casts don't involve legal types; this code |
| 2733 | // handles promotable integers. |
Chad Rosier | 4489f94 | 2011-11-02 17:20:24 +0000 | [diff] [blame] | 2734 | Type *DestTy = I->getType(); |
| 2735 | Value *Src = I->getOperand(0); |
| 2736 | Type *SrcTy = Src->getType(); |
| 2737 | |
Chad Rosier | 4489f94 | 2011-11-02 17:20:24 +0000 | [diff] [blame] | 2738 | bool isZExt = isa<ZExtInst>(I); |
| 2739 | unsigned SrcReg = getRegForValue(Src); |
| 2740 | if (!SrcReg) return false; |
| 2741 | |
Chad Rosier | 62a144f | 2012-12-17 19:59:43 +0000 | [diff] [blame] | 2742 | EVT SrcEVT, DestEVT; |
| 2743 | SrcEVT = TLI.getValueType(SrcTy, true); |
| 2744 | DestEVT = TLI.getValueType(DestTy, true); |
| 2745 | if (!SrcEVT.isSimple()) return false; |
| 2746 | if (!DestEVT.isSimple()) return false; |
Patrik Hagglund | c494d24 | 2012-12-17 14:30:06 +0000 | [diff] [blame] | 2747 | |
Chad Rosier | 62a144f | 2012-12-17 19:59:43 +0000 | [diff] [blame] | 2748 | MVT SrcVT = SrcEVT.getSimpleVT(); |
| 2749 | MVT DestVT = DestEVT.getSimpleVT(); |
Chad Rosier | 4489f94 | 2011-11-02 17:20:24 +0000 | [diff] [blame] | 2750 | unsigned ResultReg = ARMEmitIntExt(SrcVT, SrcReg, DestVT, isZExt); |
| 2751 | if (ResultReg == 0) return false; |
Juergen Ributzka | 5b8bb4d | 2014-09-03 20:56:52 +0000 | [diff] [blame] | 2752 | updateValueMap(I, ResultReg); |
Eli Friedman | c703551 | 2011-05-25 23:49:02 +0000 | [diff] [blame] | 2753 | return true; |
| 2754 | } |
| 2755 | |
Jush Lu | 4705da9 | 2012-08-03 02:37:48 +0000 | [diff] [blame] | 2756 | bool ARMFastISel::SelectShift(const Instruction *I, |
| 2757 | ARM_AM::ShiftOpc ShiftTy) { |
| 2758 | // We handle thumb2 mode by target independent selector |
| 2759 | // or SelectionDAG ISel. |
| 2760 | if (isThumb2) |
| 2761 | return false; |
| 2762 | |
| 2763 | // Only handle i32 now. |
| 2764 | EVT DestVT = TLI.getValueType(I->getType(), true); |
| 2765 | if (DestVT != MVT::i32) |
| 2766 | return false; |
| 2767 | |
| 2768 | unsigned Opc = ARM::MOVsr; |
| 2769 | unsigned ShiftImm; |
| 2770 | Value *Src2Value = I->getOperand(1); |
| 2771 | if (const ConstantInt *CI = dyn_cast<ConstantInt>(Src2Value)) { |
| 2772 | ShiftImm = CI->getZExtValue(); |
| 2773 | |
| 2774 | // Fall back to selection DAG isel if the shift amount |
| 2775 | // is zero or greater than the width of the value type. |
| 2776 | if (ShiftImm == 0 || ShiftImm >=32) |
| 2777 | return false; |
| 2778 | |
| 2779 | Opc = ARM::MOVsi; |
| 2780 | } |
| 2781 | |
| 2782 | Value *Src1Value = I->getOperand(0); |
| 2783 | unsigned Reg1 = getRegForValue(Src1Value); |
| 2784 | if (Reg1 == 0) return false; |
| 2785 | |
Nadav Rotem | a8e15b0 | 2012-09-06 11:13:55 +0000 | [diff] [blame] | 2786 | unsigned Reg2 = 0; |
Jush Lu | 4705da9 | 2012-08-03 02:37:48 +0000 | [diff] [blame] | 2787 | if (Opc == ARM::MOVsr) { |
| 2788 | Reg2 = getRegForValue(Src2Value); |
| 2789 | if (Reg2 == 0) return false; |
| 2790 | } |
| 2791 | |
JF Bastien | 13969d0 | 2013-05-29 15:45:47 +0000 | [diff] [blame] | 2792 | unsigned ResultReg = createResultReg(&ARM::GPRnopcRegClass); |
Jush Lu | 4705da9 | 2012-08-03 02:37:48 +0000 | [diff] [blame] | 2793 | if(ResultReg == 0) return false; |
| 2794 | |
Rafael Espindola | ea09c59 | 2014-02-18 22:05:46 +0000 | [diff] [blame] | 2795 | MachineInstrBuilder MIB = BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, |
Jush Lu | 4705da9 | 2012-08-03 02:37:48 +0000 | [diff] [blame] | 2796 | TII.get(Opc), ResultReg) |
| 2797 | .addReg(Reg1); |
| 2798 | |
| 2799 | if (Opc == ARM::MOVsi) |
| 2800 | MIB.addImm(ARM_AM::getSORegOpc(ShiftTy, ShiftImm)); |
| 2801 | else if (Opc == ARM::MOVsr) { |
| 2802 | MIB.addReg(Reg2); |
| 2803 | MIB.addImm(ARM_AM::getSORegOpc(ShiftTy, 0)); |
| 2804 | } |
| 2805 | |
| 2806 | AddOptionalDefs(MIB); |
Juergen Ributzka | 5b8bb4d | 2014-09-03 20:56:52 +0000 | [diff] [blame] | 2807 | updateValueMap(I, ResultReg); |
Jush Lu | 4705da9 | 2012-08-03 02:37:48 +0000 | [diff] [blame] | 2808 | return true; |
| 2809 | } |
| 2810 | |
Eric Christopher | c3e118e | 2010-09-02 23:43:26 +0000 | [diff] [blame] | 2811 | // TODO: SoftFP support. |
Juergen Ributzka | 5b8bb4d | 2014-09-03 20:56:52 +0000 | [diff] [blame] | 2812 | bool ARMFastISel::fastSelectInstruction(const Instruction *I) { |
Eric Christopher | 2ff757d | 2010-09-09 01:06:51 +0000 | [diff] [blame] | 2813 | |
Eric Christopher | 84bdfd8 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 2814 | switch (I->getOpcode()) { |
Eric Christopher | 00202ee | 2010-08-23 21:44:12 +0000 | [diff] [blame] | 2815 | case Instruction::Load: |
Eric Christopher | 29ab6d1 | 2010-09-27 06:02:23 +0000 | [diff] [blame] | 2816 | return SelectLoad(I); |
Eric Christopher | fde5a3d | 2010-09-01 22:16:27 +0000 | [diff] [blame] | 2817 | case Instruction::Store: |
Eric Christopher | 29ab6d1 | 2010-09-27 06:02:23 +0000 | [diff] [blame] | 2818 | return SelectStore(I); |
Eric Christopher | 6aaed72 | 2010-09-03 00:35:47 +0000 | [diff] [blame] | 2819 | case Instruction::Br: |
Eric Christopher | 29ab6d1 | 2010-09-27 06:02:23 +0000 | [diff] [blame] | 2820 | return SelectBranch(I); |
Chad Rosier | ded4c99 | 2012-02-07 23:56:08 +0000 | [diff] [blame] | 2821 | case Instruction::IndirectBr: |
| 2822 | return SelectIndirectBr(I); |
Eric Christopher | c3e9c40 | 2010-09-08 23:13:45 +0000 | [diff] [blame] | 2823 | case Instruction::ICmp: |
| 2824 | case Instruction::FCmp: |
Eric Christopher | 29ab6d1 | 2010-09-27 06:02:23 +0000 | [diff] [blame] | 2825 | return SelectCmp(I); |
Eric Christopher | f14b9bf | 2010-09-09 00:26:48 +0000 | [diff] [blame] | 2826 | case Instruction::FPExt: |
Eric Christopher | 29ab6d1 | 2010-09-27 06:02:23 +0000 | [diff] [blame] | 2827 | return SelectFPExt(I); |
Eric Christopher | 5903c0b | 2010-09-09 20:26:31 +0000 | [diff] [blame] | 2828 | case Instruction::FPTrunc: |
Eric Christopher | 29ab6d1 | 2010-09-27 06:02:23 +0000 | [diff] [blame] | 2829 | return SelectFPTrunc(I); |
Eric Christopher | 6e3eeba | 2010-09-09 18:54:59 +0000 | [diff] [blame] | 2830 | case Instruction::SIToFP: |
Chad Rosier | e023d5d | 2012-02-03 21:14:11 +0000 | [diff] [blame] | 2831 | return SelectIToFP(I, /*isSigned*/ true); |
Chad Rosier | a8a8ac5 | 2012-02-03 19:42:52 +0000 | [diff] [blame] | 2832 | case Instruction::UIToFP: |
Chad Rosier | e023d5d | 2012-02-03 21:14:11 +0000 | [diff] [blame] | 2833 | return SelectIToFP(I, /*isSigned*/ false); |
Eric Christopher | 6e3eeba | 2010-09-09 18:54:59 +0000 | [diff] [blame] | 2834 | case Instruction::FPToSI: |
Chad Rosier | e023d5d | 2012-02-03 21:14:11 +0000 | [diff] [blame] | 2835 | return SelectFPToI(I, /*isSigned*/ true); |
Chad Rosier | 41f0e78 | 2012-02-03 20:27:51 +0000 | [diff] [blame] | 2836 | case Instruction::FPToUI: |
Chad Rosier | e023d5d | 2012-02-03 21:14:11 +0000 | [diff] [blame] | 2837 | return SelectFPToI(I, /*isSigned*/ false); |
Chad Rosier | 685b20c | 2012-02-06 23:50:07 +0000 | [diff] [blame] | 2838 | case Instruction::Add: |
| 2839 | return SelectBinaryIntOp(I, ISD::ADD); |
Chad Rosier | bd47125 | 2012-02-08 02:29:21 +0000 | [diff] [blame] | 2840 | case Instruction::Or: |
| 2841 | return SelectBinaryIntOp(I, ISD::OR); |
Chad Rosier | 0ee8c51 | 2012-02-08 02:45:44 +0000 | [diff] [blame] | 2842 | case Instruction::Sub: |
| 2843 | return SelectBinaryIntOp(I, ISD::SUB); |
Eric Christopher | 24dc27f | 2010-09-09 00:53:57 +0000 | [diff] [blame] | 2844 | case Instruction::FAdd: |
Chad Rosier | 685b20c | 2012-02-06 23:50:07 +0000 | [diff] [blame] | 2845 | return SelectBinaryFPOp(I, ISD::FADD); |
Eric Christopher | 24dc27f | 2010-09-09 00:53:57 +0000 | [diff] [blame] | 2846 | case Instruction::FSub: |
Chad Rosier | 685b20c | 2012-02-06 23:50:07 +0000 | [diff] [blame] | 2847 | return SelectBinaryFPOp(I, ISD::FSUB); |
Eric Christopher | 24dc27f | 2010-09-09 00:53:57 +0000 | [diff] [blame] | 2848 | case Instruction::FMul: |
Chad Rosier | 685b20c | 2012-02-06 23:50:07 +0000 | [diff] [blame] | 2849 | return SelectBinaryFPOp(I, ISD::FMUL); |
Eric Christopher | 8b91266 | 2010-09-14 23:03:37 +0000 | [diff] [blame] | 2850 | case Instruction::SDiv: |
Chad Rosier | aaa55a8 | 2012-02-03 21:07:27 +0000 | [diff] [blame] | 2851 | return SelectDiv(I, /*isSigned*/ true); |
| 2852 | case Instruction::UDiv: |
| 2853 | return SelectDiv(I, /*isSigned*/ false); |
Eric Christopher | eae1b38 | 2010-10-11 08:37:26 +0000 | [diff] [blame] | 2854 | case Instruction::SRem: |
Chad Rosier | b84a4b4 | 2012-02-03 21:23:45 +0000 | [diff] [blame] | 2855 | return SelectRem(I, /*isSigned*/ true); |
| 2856 | case Instruction::URem: |
| 2857 | return SelectRem(I, /*isSigned*/ false); |
Eric Christopher | 78f8d4e | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 2858 | case Instruction::Call: |
Chad Rosier | a7ebc56 | 2011-11-11 23:31:03 +0000 | [diff] [blame] | 2859 | if (const IntrinsicInst *II = dyn_cast<IntrinsicInst>(I)) |
| 2860 | return SelectIntrinsicCall(*II); |
Eric Christopher | 78f8d4e | 2010-09-30 20:49:44 +0000 | [diff] [blame] | 2861 | return SelectCall(I); |
Eric Christopher | 511aa31 | 2010-10-11 08:27:59 +0000 | [diff] [blame] | 2862 | case Instruction::Select: |
| 2863 | return SelectSelect(I); |
Eric Christopher | 93bbe65 | 2010-10-22 01:28:00 +0000 | [diff] [blame] | 2864 | case Instruction::Ret: |
| 2865 | return SelectRet(I); |
Eli Friedman | c703551 | 2011-05-25 23:49:02 +0000 | [diff] [blame] | 2866 | case Instruction::Trunc: |
Chad Rosier | ee7e452 | 2011-11-02 00:18:48 +0000 | [diff] [blame] | 2867 | return SelectTrunc(I); |
Eli Friedman | c703551 | 2011-05-25 23:49:02 +0000 | [diff] [blame] | 2868 | case Instruction::ZExt: |
| 2869 | case Instruction::SExt: |
Chad Rosier | ee7e452 | 2011-11-02 00:18:48 +0000 | [diff] [blame] | 2870 | return SelectIntExt(I); |
Jush Lu | 4705da9 | 2012-08-03 02:37:48 +0000 | [diff] [blame] | 2871 | case Instruction::Shl: |
| 2872 | return SelectShift(I, ARM_AM::lsl); |
| 2873 | case Instruction::LShr: |
| 2874 | return SelectShift(I, ARM_AM::lsr); |
| 2875 | case Instruction::AShr: |
| 2876 | return SelectShift(I, ARM_AM::asr); |
Eric Christopher | 84bdfd8 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 2877 | default: break; |
| 2878 | } |
| 2879 | return false; |
| 2880 | } |
| 2881 | |
JF Bastien | 3c6bb8e | 2013-06-11 22:13:46 +0000 | [diff] [blame] | 2882 | namespace { |
| 2883 | // This table describes sign- and zero-extend instructions which can be |
| 2884 | // folded into a preceding load. All of these extends have an immediate |
| 2885 | // (sometimes a mask and sometimes a shift) that's applied after |
| 2886 | // extension. |
| 2887 | const struct FoldableLoadExtendsStruct { |
| 2888 | uint16_t Opc[2]; // ARM, Thumb. |
| 2889 | uint8_t ExpectedImm; |
| 2890 | uint8_t isZExt : 1; |
| 2891 | uint8_t ExpectedVT : 7; |
| 2892 | } FoldableLoadExtends[] = { |
| 2893 | { { ARM::SXTH, ARM::t2SXTH }, 0, 0, MVT::i16 }, |
| 2894 | { { ARM::UXTH, ARM::t2UXTH }, 0, 1, MVT::i16 }, |
| 2895 | { { ARM::ANDri, ARM::t2ANDri }, 255, 1, MVT::i8 }, |
| 2896 | { { ARM::SXTB, ARM::t2SXTB }, 0, 0, MVT::i8 }, |
| 2897 | { { ARM::UXTB, ARM::t2UXTB }, 0, 1, MVT::i8 } |
| 2898 | }; |
Alexander Kornienko | f00654e | 2015-06-23 09:49:53 +0000 | [diff] [blame] | 2899 | } |
JF Bastien | 3c6bb8e | 2013-06-11 22:13:46 +0000 | [diff] [blame] | 2900 | |
Eli Bendersky | 90dd3e7 | 2013-04-19 22:29:18 +0000 | [diff] [blame] | 2901 | /// \brief The specified machine instr operand is a vreg, and that |
Chad Rosier | c8cfd3a | 2011-11-13 02:23:59 +0000 | [diff] [blame] | 2902 | /// vreg is being provided by the specified load instruction. If possible, |
| 2903 | /// try to fold the load as an operand to the instruction, returning true if |
| 2904 | /// successful. |
Eli Bendersky | 90dd3e7 | 2013-04-19 22:29:18 +0000 | [diff] [blame] | 2905 | bool ARMFastISel::tryToFoldLoadIntoMI(MachineInstr *MI, unsigned OpNo, |
| 2906 | const LoadInst *LI) { |
Chad Rosier | c8cfd3a | 2011-11-13 02:23:59 +0000 | [diff] [blame] | 2907 | // Verify we have a legal type before going any further. |
| 2908 | MVT VT; |
| 2909 | if (!isLoadTypeLegal(LI->getType(), VT)) |
| 2910 | return false; |
| 2911 | |
| 2912 | // Combine load followed by zero- or sign-extend. |
| 2913 | // ldrb r1, [r0] ldrb r1, [r0] |
| 2914 | // uxtb r2, r1 => |
| 2915 | // mov r3, r2 mov r3, r1 |
JF Bastien | 3c6bb8e | 2013-06-11 22:13:46 +0000 | [diff] [blame] | 2916 | if (MI->getNumOperands() < 3 || !MI->getOperand(2).isImm()) |
| 2917 | return false; |
| 2918 | const uint64_t Imm = MI->getOperand(2).getImm(); |
| 2919 | |
| 2920 | bool Found = false; |
| 2921 | bool isZExt; |
| 2922 | for (unsigned i = 0, e = array_lengthof(FoldableLoadExtends); |
| 2923 | i != e; ++i) { |
| 2924 | if (FoldableLoadExtends[i].Opc[isThumb2] == MI->getOpcode() && |
| 2925 | (uint64_t)FoldableLoadExtends[i].ExpectedImm == Imm && |
| 2926 | MVT((MVT::SimpleValueType)FoldableLoadExtends[i].ExpectedVT) == VT) { |
| 2927 | Found = true; |
| 2928 | isZExt = FoldableLoadExtends[i].isZExt; |
| 2929 | } |
Chad Rosier | c8cfd3a | 2011-11-13 02:23:59 +0000 | [diff] [blame] | 2930 | } |
JF Bastien | 3c6bb8e | 2013-06-11 22:13:46 +0000 | [diff] [blame] | 2931 | if (!Found) return false; |
| 2932 | |
Chad Rosier | c8cfd3a | 2011-11-13 02:23:59 +0000 | [diff] [blame] | 2933 | // See if we can handle this address. |
| 2934 | Address Addr; |
| 2935 | if (!ARMComputeAddress(LI->getOperand(0), Addr)) return false; |
Jush Lu | ac96b76 | 2012-06-14 06:08:19 +0000 | [diff] [blame] | 2936 | |
Chad Rosier | c8cfd3a | 2011-11-13 02:23:59 +0000 | [diff] [blame] | 2937 | unsigned ResultReg = MI->getOperand(0).getReg(); |
Chad Rosier | 563de60 | 2011-12-13 19:22:14 +0000 | [diff] [blame] | 2938 | if (!ARMEmitLoad(VT, ResultReg, Addr, LI->getAlignment(), isZExt, false)) |
Chad Rosier | c8cfd3a | 2011-11-13 02:23:59 +0000 | [diff] [blame] | 2939 | return false; |
| 2940 | MI->eraseFromParent(); |
| 2941 | return true; |
| 2942 | } |
| 2943 | |
Jush Lu | 47172a0 | 2012-09-27 05:21:41 +0000 | [diff] [blame] | 2944 | unsigned ARMFastISel::ARMLowerPICELF(const GlobalValue *GV, |
Patrik Hagglund | 5e6c361 | 2012-12-13 06:34:11 +0000 | [diff] [blame] | 2945 | unsigned Align, MVT VT) { |
Jush Lu | 47172a0 | 2012-09-27 05:21:41 +0000 | [diff] [blame] | 2946 | bool UseGOTOFF = GV->hasLocalLinkage() || GV->hasHiddenVisibility(); |
| 2947 | ARMConstantPoolConstant *CPV = |
| 2948 | ARMConstantPoolConstant::Create(GV, UseGOTOFF ? ARMCP::GOTOFF : ARMCP::GOT); |
| 2949 | unsigned Idx = MCP.getConstantPoolIndex(CPV, Align); |
| 2950 | |
| 2951 | unsigned Opc; |
| 2952 | unsigned DestReg1 = createResultReg(TLI.getRegClassFor(VT)); |
| 2953 | // Load value. |
| 2954 | if (isThumb2) { |
Jim Grosbach | 5f71aab | 2013-08-26 20:07:29 +0000 | [diff] [blame] | 2955 | DestReg1 = constrainOperandRegClass(TII.get(ARM::t2LDRpci), DestReg1, 0); |
Rafael Espindola | ea09c59 | 2014-02-18 22:05:46 +0000 | [diff] [blame] | 2956 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, |
Jush Lu | 47172a0 | 2012-09-27 05:21:41 +0000 | [diff] [blame] | 2957 | TII.get(ARM::t2LDRpci), DestReg1) |
| 2958 | .addConstantPoolIndex(Idx)); |
| 2959 | Opc = UseGOTOFF ? ARM::t2ADDrr : ARM::t2LDRs; |
| 2960 | } else { |
| 2961 | // The extra immediate is for addrmode2. |
Jim Grosbach | 5f71aab | 2013-08-26 20:07:29 +0000 | [diff] [blame] | 2962 | DestReg1 = constrainOperandRegClass(TII.get(ARM::LDRcp), DestReg1, 0); |
Jush Lu | 47172a0 | 2012-09-27 05:21:41 +0000 | [diff] [blame] | 2963 | AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, |
Rafael Espindola | ea09c59 | 2014-02-18 22:05:46 +0000 | [diff] [blame] | 2964 | DbgLoc, TII.get(ARM::LDRcp), DestReg1) |
Jush Lu | 47172a0 | 2012-09-27 05:21:41 +0000 | [diff] [blame] | 2965 | .addConstantPoolIndex(Idx).addImm(0)); |
| 2966 | Opc = UseGOTOFF ? ARM::ADDrr : ARM::LDRrs; |
| 2967 | } |
| 2968 | |
| 2969 | unsigned GlobalBaseReg = AFI->getGlobalBaseReg(); |
| 2970 | if (GlobalBaseReg == 0) { |
| 2971 | GlobalBaseReg = MRI.createVirtualRegister(TLI.getRegClassFor(VT)); |
| 2972 | AFI->setGlobalBaseReg(GlobalBaseReg); |
| 2973 | } |
| 2974 | |
| 2975 | unsigned DestReg2 = createResultReg(TLI.getRegClassFor(VT)); |
Jim Grosbach | 5f71aab | 2013-08-26 20:07:29 +0000 | [diff] [blame] | 2976 | DestReg2 = constrainOperandRegClass(TII.get(Opc), DestReg2, 0); |
| 2977 | DestReg1 = constrainOperandRegClass(TII.get(Opc), DestReg1, 1); |
| 2978 | GlobalBaseReg = constrainOperandRegClass(TII.get(Opc), GlobalBaseReg, 2); |
Jush Lu | 47172a0 | 2012-09-27 05:21:41 +0000 | [diff] [blame] | 2979 | MachineInstrBuilder MIB = BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, |
Rafael Espindola | ea09c59 | 2014-02-18 22:05:46 +0000 | [diff] [blame] | 2980 | DbgLoc, TII.get(Opc), DestReg2) |
Jush Lu | 47172a0 | 2012-09-27 05:21:41 +0000 | [diff] [blame] | 2981 | .addReg(DestReg1) |
| 2982 | .addReg(GlobalBaseReg); |
| 2983 | if (!UseGOTOFF) |
| 2984 | MIB.addImm(0); |
| 2985 | AddOptionalDefs(MIB); |
| 2986 | |
| 2987 | return DestReg2; |
| 2988 | } |
| 2989 | |
Juergen Ributzka | 5b8bb4d | 2014-09-03 20:56:52 +0000 | [diff] [blame] | 2990 | bool ARMFastISel::fastLowerArguments() { |
Evan Cheng | 615620c | 2013-02-11 01:27:15 +0000 | [diff] [blame] | 2991 | if (!FuncInfo.CanLowerReturn) |
| 2992 | return false; |
| 2993 | |
| 2994 | const Function *F = FuncInfo.Fn; |
| 2995 | if (F->isVarArg()) |
| 2996 | return false; |
| 2997 | |
| 2998 | CallingConv::ID CC = F->getCallingConv(); |
| 2999 | switch (CC) { |
| 3000 | default: |
| 3001 | return false; |
| 3002 | case CallingConv::Fast: |
| 3003 | case CallingConv::C: |
| 3004 | case CallingConv::ARM_AAPCS_VFP: |
| 3005 | case CallingConv::ARM_AAPCS: |
| 3006 | case CallingConv::ARM_APCS: |
| 3007 | break; |
| 3008 | } |
| 3009 | |
| 3010 | // Only handle simple cases. i.e. Up to 4 i8/i16/i32 scalar arguments |
| 3011 | // which are passed in r0 - r3. |
| 3012 | unsigned Idx = 1; |
| 3013 | for (Function::const_arg_iterator I = F->arg_begin(), E = F->arg_end(); |
| 3014 | I != E; ++I, ++Idx) { |
| 3015 | if (Idx > 4) |
| 3016 | return false; |
| 3017 | |
| 3018 | if (F->getAttributes().hasAttribute(Idx, Attribute::InReg) || |
| 3019 | F->getAttributes().hasAttribute(Idx, Attribute::StructRet) || |
| 3020 | F->getAttributes().hasAttribute(Idx, Attribute::ByVal)) |
| 3021 | return false; |
| 3022 | |
| 3023 | Type *ArgTy = I->getType(); |
| 3024 | if (ArgTy->isStructTy() || ArgTy->isArrayTy() || ArgTy->isVectorTy()) |
| 3025 | return false; |
| 3026 | |
| 3027 | EVT ArgVT = TLI.getValueType(ArgTy); |
Chad Rosier | 1b33e8d | 2013-02-26 01:05:31 +0000 | [diff] [blame] | 3028 | if (!ArgVT.isSimple()) return false; |
Evan Cheng | 615620c | 2013-02-11 01:27:15 +0000 | [diff] [blame] | 3029 | switch (ArgVT.getSimpleVT().SimpleTy) { |
| 3030 | case MVT::i8: |
| 3031 | case MVT::i16: |
| 3032 | case MVT::i32: |
| 3033 | break; |
| 3034 | default: |
| 3035 | return false; |
| 3036 | } |
| 3037 | } |
| 3038 | |
| 3039 | |
| 3040 | static const uint16_t GPRArgRegs[] = { |
| 3041 | ARM::R0, ARM::R1, ARM::R2, ARM::R3 |
| 3042 | }; |
| 3043 | |
Jim Grosbach | d69f3ed | 2013-08-16 23:37:23 +0000 | [diff] [blame] | 3044 | const TargetRegisterClass *RC = &ARM::rGPRRegClass; |
Evan Cheng | 615620c | 2013-02-11 01:27:15 +0000 | [diff] [blame] | 3045 | Idx = 0; |
| 3046 | for (Function::const_arg_iterator I = F->arg_begin(), E = F->arg_end(); |
| 3047 | I != E; ++I, ++Idx) { |
Evan Cheng | 615620c | 2013-02-11 01:27:15 +0000 | [diff] [blame] | 3048 | unsigned SrcReg = GPRArgRegs[Idx]; |
| 3049 | unsigned DstReg = FuncInfo.MF->addLiveIn(SrcReg, RC); |
| 3050 | // FIXME: Unfortunately it's necessary to emit a copy from the livein copy. |
| 3051 | // Without this, EmitLiveInCopies may eliminate the livein if its only |
| 3052 | // use is a bitcast (which isn't turned into an instruction). |
| 3053 | unsigned ResultReg = createResultReg(RC); |
Rafael Espindola | ea09c59 | 2014-02-18 22:05:46 +0000 | [diff] [blame] | 3054 | BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, |
| 3055 | TII.get(TargetOpcode::COPY), |
Evan Cheng | 615620c | 2013-02-11 01:27:15 +0000 | [diff] [blame] | 3056 | ResultReg).addReg(DstReg, getKillRegState(true)); |
Juergen Ributzka | 5b8bb4d | 2014-09-03 20:56:52 +0000 | [diff] [blame] | 3057 | updateValueMap(I, ResultReg); |
Evan Cheng | 615620c | 2013-02-11 01:27:15 +0000 | [diff] [blame] | 3058 | } |
| 3059 | |
| 3060 | return true; |
| 3061 | } |
| 3062 | |
Eric Christopher | 84bdfd8 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 3063 | namespace llvm { |
Bob Wilson | 3e6fa46 | 2012-08-03 04:06:28 +0000 | [diff] [blame] | 3064 | FastISel *ARM::createFastISel(FunctionLoweringInfo &funcInfo, |
| 3065 | const TargetLibraryInfo *libInfo) { |
Akira Hatanaka | ddf76aa | 2015-05-23 01:14:08 +0000 | [diff] [blame] | 3066 | if (funcInfo.MF->getSubtarget<ARMSubtarget>().useFastISel()) |
Bob Wilson | 3e6fa46 | 2012-08-03 04:06:28 +0000 | [diff] [blame] | 3067 | return new ARMFastISel(funcInfo, libInfo); |
Akira Hatanaka | ddf76aa | 2015-05-23 01:14:08 +0000 | [diff] [blame] | 3068 | |
Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 3069 | return nullptr; |
Eric Christopher | 84bdfd8 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 3070 | } |
| 3071 | } |