| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1 | //===-- HexagonISelLowering.cpp - Hexagon DAG Lowering 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 implements the interfaces that Hexagon uses to lower LLVM code |
| 11 | // into a selection DAG. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #include "HexagonISelLowering.h" |
| Chandler Carruth | 6bda14b | 2017-06-06 11:49:48 +0000 | [diff] [blame] | 16 | #include "Hexagon.h" |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 17 | #include "HexagonMachineFunctionInfo.h" |
| Eugene Zelenko | 58655bb | 2016-12-17 01:09:05 +0000 | [diff] [blame] | 18 | #include "HexagonRegisterInfo.h" |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 19 | #include "HexagonSubtarget.h" |
| Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 20 | #include "HexagonTargetMachine.h" |
| 21 | #include "HexagonTargetObjectFile.h" |
| Eugene Zelenko | 58655bb | 2016-12-17 01:09:05 +0000 | [diff] [blame] | 22 | #include "llvm/ADT/APInt.h" |
| 23 | #include "llvm/ADT/ArrayRef.h" |
| 24 | #include "llvm/ADT/SmallVector.h" |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 25 | #include "llvm/CodeGen/CallingConvLower.h" |
| 26 | #include "llvm/CodeGen/MachineFrameInfo.h" |
| 27 | #include "llvm/CodeGen/MachineFunction.h" |
| Eugene Zelenko | 58655bb | 2016-12-17 01:09:05 +0000 | [diff] [blame] | 28 | #include "llvm/CodeGen/MachineMemOperand.h" |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 29 | #include "llvm/CodeGen/MachineRegisterInfo.h" |
| Chandler Carruth | 6bda14b | 2017-06-06 11:49:48 +0000 | [diff] [blame] | 30 | #include "llvm/CodeGen/RuntimeLibcalls.h" |
| Eugene Zelenko | 58655bb | 2016-12-17 01:09:05 +0000 | [diff] [blame] | 31 | #include "llvm/CodeGen/SelectionDAG.h" |
| David Blaikie | b3bde2e | 2017-11-17 01:07:10 +0000 | [diff] [blame] | 32 | #include "llvm/CodeGen/TargetCallingConv.h" |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 33 | #include "llvm/CodeGen/ValueTypes.h" |
| Eugene Zelenko | 58655bb | 2016-12-17 01:09:05 +0000 | [diff] [blame] | 34 | #include "llvm/IR/BasicBlock.h" |
| Chandler Carruth | 9fb823b | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 35 | #include "llvm/IR/CallingConv.h" |
| Eugene Zelenko | 58655bb | 2016-12-17 01:09:05 +0000 | [diff] [blame] | 36 | #include "llvm/IR/DataLayout.h" |
| Chandler Carruth | 9fb823b | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 37 | #include "llvm/IR/DerivedTypes.h" |
| 38 | #include "llvm/IR/Function.h" |
| Eugene Zelenko | 58655bb | 2016-12-17 01:09:05 +0000 | [diff] [blame] | 39 | #include "llvm/IR/GlobalValue.h" |
| Chandler Carruth | 9fb823b | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 40 | #include "llvm/IR/InlineAsm.h" |
| Eugene Zelenko | 58655bb | 2016-12-17 01:09:05 +0000 | [diff] [blame] | 41 | #include "llvm/IR/Instructions.h" |
| Chandler Carruth | 9fb823b | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 42 | #include "llvm/IR/Intrinsics.h" |
| Eugene Zelenko | 58655bb | 2016-12-17 01:09:05 +0000 | [diff] [blame] | 43 | #include "llvm/IR/Module.h" |
| 44 | #include "llvm/IR/Type.h" |
| 45 | #include "llvm/IR/Value.h" |
| 46 | #include "llvm/MC/MCRegisterInfo.h" |
| 47 | #include "llvm/Support/Casting.h" |
| 48 | #include "llvm/Support/CodeGen.h" |
| NAKAMURA Takumi | 54eed76 | 2012-04-21 15:31:36 +0000 | [diff] [blame] | 49 | #include "llvm/Support/CommandLine.h" |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 50 | #include "llvm/Support/Debug.h" |
| 51 | #include "llvm/Support/ErrorHandling.h" |
| Eugene Zelenko | 58655bb | 2016-12-17 01:09:05 +0000 | [diff] [blame] | 52 | #include "llvm/Support/MathExtras.h" |
| NAKAMURA Takumi | e30303f | 2012-04-21 15:31:45 +0000 | [diff] [blame] | 53 | #include "llvm/Support/raw_ostream.h" |
| Eugene Zelenko | 58655bb | 2016-12-17 01:09:05 +0000 | [diff] [blame] | 54 | #include "llvm/Target/TargetMachine.h" |
| 55 | #include <algorithm> |
| 56 | #include <cassert> |
| 57 | #include <cstddef> |
| 58 | #include <cstdint> |
| 59 | #include <limits> |
| 60 | #include <utility> |
| NAKAMURA Takumi | 54eed76 | 2012-04-21 15:31:36 +0000 | [diff] [blame] | 61 | |
| Craig Topper | b25fda9 | 2012-03-17 18:46:09 +0000 | [diff] [blame] | 62 | using namespace llvm; |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 63 | |
| Chandler Carruth | e96dd89 | 2014-04-21 22:55:11 +0000 | [diff] [blame] | 64 | #define DEBUG_TYPE "hexagon-lowering" |
| 65 | |
| Krzysztof Parzyszek | 21dc8bd | 2015-12-18 20:19:30 +0000 | [diff] [blame] | 66 | static cl::opt<bool> EmitJumpTables("hexagon-emit-jump-tables", |
| 67 | cl::init(true), cl::Hidden, |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 68 | cl::desc("Control jump table emission on Hexagon target")); |
| 69 | |
| 70 | static cl::opt<bool> EnableHexSDNodeSched("enable-hexagon-sdnode-sched", |
| 71 | cl::Hidden, cl::ZeroOrMore, cl::init(false), |
| 72 | cl::desc("Enable Hexagon SDNode scheduling")); |
| 73 | |
| 74 | static cl::opt<bool> EnableFastMath("ffast-math", |
| 75 | cl::Hidden, cl::ZeroOrMore, cl::init(false), |
| 76 | cl::desc("Enable Fast Math processing")); |
| 77 | |
| 78 | static cl::opt<int> MinimumJumpTables("minimum-jump-tables", |
| 79 | cl::Hidden, cl::ZeroOrMore, cl::init(5), |
| 80 | cl::desc("Set minimum jump tables")); |
| 81 | |
| 82 | static cl::opt<int> MaxStoresPerMemcpyCL("max-store-memcpy", |
| 83 | cl::Hidden, cl::ZeroOrMore, cl::init(6), |
| 84 | cl::desc("Max #stores to inline memcpy")); |
| 85 | |
| 86 | static cl::opt<int> MaxStoresPerMemcpyOptSizeCL("max-store-memcpy-Os", |
| 87 | cl::Hidden, cl::ZeroOrMore, cl::init(4), |
| 88 | cl::desc("Max #stores to inline memcpy")); |
| 89 | |
| 90 | static cl::opt<int> MaxStoresPerMemmoveCL("max-store-memmove", |
| 91 | cl::Hidden, cl::ZeroOrMore, cl::init(6), |
| 92 | cl::desc("Max #stores to inline memmove")); |
| 93 | |
| 94 | static cl::opt<int> MaxStoresPerMemmoveOptSizeCL("max-store-memmove-Os", |
| 95 | cl::Hidden, cl::ZeroOrMore, cl::init(4), |
| 96 | cl::desc("Max #stores to inline memmove")); |
| 97 | |
| 98 | static cl::opt<int> MaxStoresPerMemsetCL("max-store-memset", |
| 99 | cl::Hidden, cl::ZeroOrMore, cl::init(8), |
| 100 | cl::desc("Max #stores to inline memset")); |
| 101 | |
| 102 | static cl::opt<int> MaxStoresPerMemsetOptSizeCL("max-store-memset-Os", |
| 103 | cl::Hidden, cl::ZeroOrMore, cl::init(4), |
| 104 | cl::desc("Max #stores to inline memset")); |
| 105 | |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 106 | |
| Benjamin Kramer | 602bb4a | 2013-10-27 11:16:09 +0000 | [diff] [blame] | 107 | namespace { |
| Eugene Zelenko | 58655bb | 2016-12-17 01:09:05 +0000 | [diff] [blame] | 108 | |
| Krzysztof Parzyszek | 0bd55a7 | 2016-07-29 16:44:27 +0000 | [diff] [blame] | 109 | class HexagonCCState : public CCState { |
| 110 | unsigned NumNamedVarArgParams; |
| Benjamin Kramer | 602bb4a | 2013-10-27 11:16:09 +0000 | [diff] [blame] | 111 | |
| Krzysztof Parzyszek | 0bd55a7 | 2016-07-29 16:44:27 +0000 | [diff] [blame] | 112 | public: |
| Krzysztof Parzyszek | 7cfe7cb | 2018-02-09 15:30:02 +0000 | [diff] [blame] | 113 | HexagonCCState(CallingConv::ID CC, bool IsVarArg, MachineFunction &MF, |
| Krzysztof Parzyszek | 0bd55a7 | 2016-07-29 16:44:27 +0000 | [diff] [blame] | 114 | SmallVectorImpl<CCValAssign> &locs, LLVMContext &C, |
| 115 | int NumNamedVarArgParams) |
| Krzysztof Parzyszek | 7cfe7cb | 2018-02-09 15:30:02 +0000 | [diff] [blame] | 116 | : CCState(CC, IsVarArg, MF, locs, C), |
| Krzysztof Parzyszek | 0bd55a7 | 2016-07-29 16:44:27 +0000 | [diff] [blame] | 117 | NumNamedVarArgParams(NumNamedVarArgParams) {} |
| Benjamin Kramer | 602bb4a | 2013-10-27 11:16:09 +0000 | [diff] [blame] | 118 | |
| Krzysztof Parzyszek | 0bd55a7 | 2016-07-29 16:44:27 +0000 | [diff] [blame] | 119 | unsigned getNumNamedVarArgParams() const { return NumNamedVarArgParams; } |
| 120 | }; |
| 121 | |
| Eugene Zelenko | 58655bb | 2016-12-17 01:09:05 +0000 | [diff] [blame] | 122 | } // end anonymous namespace |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 123 | |
| Krzysztof Parzyszek | 7cfe7cb | 2018-02-09 15:30:02 +0000 | [diff] [blame] | 124 | |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 125 | // Implement calling convention for Hexagon. |
| Krzysztof Parzyszek | 08ff888 | 2015-11-26 18:38:27 +0000 | [diff] [blame] | 126 | |
| Krzysztof Parzyszek | 7cfe7cb | 2018-02-09 15:30:02 +0000 | [diff] [blame] | 127 | static bool CC_SkipOdd(unsigned &ValNo, MVT &ValVT, MVT &LocVT, |
| 128 | CCValAssign::LocInfo &LocInfo, |
| 129 | ISD::ArgFlagsTy &ArgFlags, CCState &State) { |
| 130 | static const MCPhysReg ArgRegs[] = { |
| 131 | Hexagon::R0, Hexagon::R1, Hexagon::R2, |
| 132 | Hexagon::R3, Hexagon::R4, Hexagon::R5 |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 133 | }; |
| Krzysztof Parzyszek | 7cfe7cb | 2018-02-09 15:30:02 +0000 | [diff] [blame] | 134 | const unsigned NumArgRegs = array_lengthof(ArgRegs); |
| 135 | unsigned RegNum = State.getFirstUnallocated(ArgRegs); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 136 | |
| Krzysztof Parzyszek | 7cfe7cb | 2018-02-09 15:30:02 +0000 | [diff] [blame] | 137 | // RegNum is an index into ArgRegs: skip a register if RegNum is odd. |
| 138 | if (RegNum != NumArgRegs && RegNum % 2 == 1) |
| 139 | State.AllocateReg(ArgRegs[RegNum]); |
| 140 | |
| 141 | // Always return false here, as this function only makes sure that the first |
| 142 | // unallocated register has an even register number and does not actually |
| 143 | // allocate a register for the current argument. |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 144 | return false; |
| 145 | } |
| 146 | |
| Krzysztof Parzyszek | 7cfe7cb | 2018-02-09 15:30:02 +0000 | [diff] [blame] | 147 | #include "HexagonGenCallingConv.inc" |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 148 | |
| Krzysztof Parzyszek | 08ff888 | 2015-11-26 18:38:27 +0000 | [diff] [blame] | 149 | |
| Craig Topper | 18e69f4 | 2016-04-15 06:20:21 +0000 | [diff] [blame] | 150 | void HexagonTargetLowering::promoteLdStType(MVT VT, MVT PromotedLdStVT) { |
| Krzysztof Parzyszek | 21dc8bd | 2015-12-18 20:19:30 +0000 | [diff] [blame] | 151 | if (VT != PromotedLdStVT) { |
| Craig Topper | 18e69f4 | 2016-04-15 06:20:21 +0000 | [diff] [blame] | 152 | setOperationAction(ISD::LOAD, VT, Promote); |
| 153 | AddPromotedToType(ISD::LOAD, VT, PromotedLdStVT); |
| Krzysztof Parzyszek | 21dc8bd | 2015-12-18 20:19:30 +0000 | [diff] [blame] | 154 | |
| Craig Topper | 18e69f4 | 2016-04-15 06:20:21 +0000 | [diff] [blame] | 155 | setOperationAction(ISD::STORE, VT, Promote); |
| 156 | AddPromotedToType(ISD::STORE, VT, PromotedLdStVT); |
| Krzysztof Parzyszek | 21dc8bd | 2015-12-18 20:19:30 +0000 | [diff] [blame] | 157 | } |
| 158 | } |
| 159 | |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 160 | SDValue |
| 161 | HexagonTargetLowering::LowerINTRINSIC_WO_CHAIN(SDValue Op, SelectionDAG &DAG) |
| Krzysztof Parzyszek | 317d42c | 2016-08-01 20:31:50 +0000 | [diff] [blame] | 162 | const { |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 163 | return SDValue(); |
| 164 | } |
| 165 | |
| 166 | /// CreateCopyOfByValArgument - Make a copy of an aggregate at address specified |
| 167 | /// by "Src" to address "Dst" of size "Size". Alignment information is |
| 168 | /// specified by the specific parameter attribute. The copy will be passed as |
| 169 | /// a byval function parameter. Sometimes what we are copying is the end of a |
| 170 | /// larger object, the part that does not fit in registers. |
| Benjamin Kramer | bdc4956 | 2016-06-12 15:39:02 +0000 | [diff] [blame] | 171 | static SDValue CreateCopyOfByValArgument(SDValue Src, SDValue Dst, |
| 172 | SDValue Chain, ISD::ArgFlagsTy Flags, |
| 173 | SelectionDAG &DAG, const SDLoc &dl) { |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 174 | SDValue SizeNode = DAG.getConstant(Flags.getByValSize(), dl, MVT::i32); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 175 | return DAG.getMemcpy(Chain, dl, Dst, Src, SizeNode, Flags.getByValAlign(), |
| 176 | /*isVolatile=*/false, /*AlwaysInline=*/false, |
| Krzysztof Parzyszek | a46c36b | 2015-04-13 17:16:45 +0000 | [diff] [blame] | 177 | /*isTailCall=*/false, |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 178 | MachinePointerInfo(), MachinePointerInfo()); |
| 179 | } |
| 180 | |
| Krzysztof Parzyszek | 5619952 | 2017-04-13 15:05:51 +0000 | [diff] [blame] | 181 | bool |
| 182 | HexagonTargetLowering::CanLowerReturn( |
| Krzysztof Parzyszek | 7cfe7cb | 2018-02-09 15:30:02 +0000 | [diff] [blame] | 183 | CallingConv::ID CallConv, MachineFunction &MF, bool IsVarArg, |
| Krzysztof Parzyszek | 5619952 | 2017-04-13 15:05:51 +0000 | [diff] [blame] | 184 | const SmallVectorImpl<ISD::OutputArg> &Outs, |
| 185 | LLVMContext &Context) const { |
| 186 | SmallVector<CCValAssign, 16> RVLocs; |
| Krzysztof Parzyszek | 7cfe7cb | 2018-02-09 15:30:02 +0000 | [diff] [blame] | 187 | CCState CCInfo(CallConv, IsVarArg, MF, RVLocs, Context); |
| 188 | |
| 189 | if (MF.getSubtarget<HexagonSubtarget>().useHVXOps()) |
| 190 | return CCInfo.CheckReturn(Outs, RetCC_Hexagon_HVX); |
| Krzysztof Parzyszek | 5619952 | 2017-04-13 15:05:51 +0000 | [diff] [blame] | 191 | return CCInfo.CheckReturn(Outs, RetCC_Hexagon); |
| 192 | } |
| 193 | |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 194 | // LowerReturn - Lower ISD::RET. If a struct is larger than 8 bytes and is |
| 195 | // passed by value, the function prototype is modified to return void and |
| 196 | // the value is stored in memory pointed by a pointer passed by caller. |
| 197 | SDValue |
| Benjamin Kramer | bdc4956 | 2016-06-12 15:39:02 +0000 | [diff] [blame] | 198 | HexagonTargetLowering::LowerReturn(SDValue Chain, CallingConv::ID CallConv, |
| Krzysztof Parzyszek | 7cfe7cb | 2018-02-09 15:30:02 +0000 | [diff] [blame] | 199 | bool IsVarArg, |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 200 | const SmallVectorImpl<ISD::OutputArg> &Outs, |
| 201 | const SmallVectorImpl<SDValue> &OutVals, |
| Benjamin Kramer | bdc4956 | 2016-06-12 15:39:02 +0000 | [diff] [blame] | 202 | const SDLoc &dl, SelectionDAG &DAG) const { |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 203 | // CCValAssign - represent the assignment of the return value to locations. |
| 204 | SmallVector<CCValAssign, 16> RVLocs; |
| 205 | |
| 206 | // CCState - Info about the registers and stack slot. |
| Krzysztof Parzyszek | 7cfe7cb | 2018-02-09 15:30:02 +0000 | [diff] [blame] | 207 | CCState CCInfo(CallConv, IsVarArg, DAG.getMachineFunction(), RVLocs, |
| Eric Christopher | b521750 | 2014-08-06 18:45:26 +0000 | [diff] [blame] | 208 | *DAG.getContext()); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 209 | |
| 210 | // Analyze return values of ISD::RET |
| Krzysztof Parzyszek | 7cfe7cb | 2018-02-09 15:30:02 +0000 | [diff] [blame] | 211 | if (Subtarget.useHVXOps()) |
| 212 | CCInfo.AnalyzeReturn(Outs, RetCC_Hexagon_HVX); |
| 213 | else |
| 214 | CCInfo.AnalyzeReturn(Outs, RetCC_Hexagon); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 215 | |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 216 | SDValue Flag; |
| Jakob Stoklund Olesen | 0af477c | 2013-02-05 18:08:43 +0000 | [diff] [blame] | 217 | SmallVector<SDValue, 4> RetOps(1, Chain); |
| 218 | |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 219 | // Copy the result values into the output registers. |
| 220 | for (unsigned i = 0; i != RVLocs.size(); ++i) { |
| 221 | CCValAssign &VA = RVLocs[i]; |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 222 | |
| 223 | Chain = DAG.getCopyToReg(Chain, dl, VA.getLocReg(), OutVals[i], Flag); |
| 224 | |
| 225 | // Guarantee that all emitted copies are stuck together with flags. |
| 226 | Flag = Chain.getValue(1); |
| Jakob Stoklund Olesen | 0af477c | 2013-02-05 18:08:43 +0000 | [diff] [blame] | 227 | RetOps.push_back(DAG.getRegister(VA.getLocReg(), VA.getLocVT())); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 228 | } |
| 229 | |
| Jakob Stoklund Olesen | 0af477c | 2013-02-05 18:08:43 +0000 | [diff] [blame] | 230 | RetOps[0] = Chain; // Update chain. |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 231 | |
| Jakob Stoklund Olesen | 0af477c | 2013-02-05 18:08:43 +0000 | [diff] [blame] | 232 | // Add the flag if we have it. |
| 233 | if (Flag.getNode()) |
| 234 | RetOps.push_back(Flag); |
| 235 | |
| Craig Topper | 48d114b | 2014-04-26 18:35:24 +0000 | [diff] [blame] | 236 | return DAG.getNode(HexagonISD::RET_FLAG, dl, MVT::Other, RetOps); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 237 | } |
| 238 | |
| Matt Arsenault | 3138075 | 2017-04-18 21:16:46 +0000 | [diff] [blame] | 239 | bool HexagonTargetLowering::mayBeEmittedAsTailCall(const CallInst *CI) const { |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 240 | // If either no tail call or told not to tail call at all, don't. |
| Akira Hatanaka | d9699bc | 2015-06-09 19:07:19 +0000 | [diff] [blame] | 241 | auto Attr = |
| 242 | CI->getParent()->getParent()->getFnAttribute("disable-tail-calls"); |
| 243 | if (!CI->isTailCall() || Attr.getValueAsString() == "true") |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 244 | return false; |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 245 | |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 246 | return true; |
| 247 | } |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 248 | |
| 249 | /// LowerCallResult - Lower the result values of an ISD::CALL into the |
| 250 | /// appropriate copies out of appropriate physical registers. This assumes that |
| Krzysztof Parzyszek | 1aaf41a | 2017-02-17 22:14:51 +0000 | [diff] [blame] | 251 | /// Chain/Glue are the input chain/glue to use, and that TheCall is the call |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 252 | /// being lowered. Returns a SDNode with the same number of values as the |
| 253 | /// ISD::CALL. |
| Benjamin Kramer | bdc4956 | 2016-06-12 15:39:02 +0000 | [diff] [blame] | 254 | SDValue HexagonTargetLowering::LowerCallResult( |
| Krzysztof Parzyszek | 7cfe7cb | 2018-02-09 15:30:02 +0000 | [diff] [blame] | 255 | SDValue Chain, SDValue Glue, CallingConv::ID CallConv, bool IsVarArg, |
| Benjamin Kramer | bdc4956 | 2016-06-12 15:39:02 +0000 | [diff] [blame] | 256 | const SmallVectorImpl<ISD::InputArg> &Ins, const SDLoc &dl, |
| 257 | SelectionDAG &DAG, SmallVectorImpl<SDValue> &InVals, |
| 258 | const SmallVectorImpl<SDValue> &OutVals, SDValue Callee) const { |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 259 | // Assign locations to each value returned by this call. |
| 260 | SmallVector<CCValAssign, 16> RVLocs; |
| 261 | |
| Krzysztof Parzyszek | 7cfe7cb | 2018-02-09 15:30:02 +0000 | [diff] [blame] | 262 | CCState CCInfo(CallConv, IsVarArg, DAG.getMachineFunction(), RVLocs, |
| Eric Christopher | b521750 | 2014-08-06 18:45:26 +0000 | [diff] [blame] | 263 | *DAG.getContext()); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 264 | |
| Krzysztof Parzyszek | 7cfe7cb | 2018-02-09 15:30:02 +0000 | [diff] [blame] | 265 | if (Subtarget.useHVXOps()) |
| 266 | CCInfo.AnalyzeCallResult(Ins, RetCC_Hexagon_HVX); |
| 267 | else |
| 268 | CCInfo.AnalyzeCallResult(Ins, RetCC_Hexagon); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 269 | |
| 270 | // Copy all of the result registers out of their specified physreg. |
| 271 | for (unsigned i = 0; i != RVLocs.size(); ++i) { |
| Krzysztof Parzyszek | 51155fc | 2016-03-04 17:38:05 +0000 | [diff] [blame] | 272 | SDValue RetVal; |
| 273 | if (RVLocs[i].getValVT() == MVT::i1) { |
| 274 | // Return values of type MVT::i1 require special handling. The reason |
| 275 | // is that MVT::i1 is associated with the PredRegs register class, but |
| 276 | // values of that type are still returned in R0. Generate an explicit |
| 277 | // copy into a predicate register from R0, and treat the value of the |
| 278 | // predicate register as the call result. |
| 279 | auto &MRI = DAG.getMachineFunction().getRegInfo(); |
| 280 | SDValue FR0 = DAG.getCopyFromReg(Chain, dl, RVLocs[i].getLocReg(), |
| Krzysztof Parzyszek | 1aaf41a | 2017-02-17 22:14:51 +0000 | [diff] [blame] | 281 | MVT::i32, Glue); |
| Krzysztof Parzyszek | 51155fc | 2016-03-04 17:38:05 +0000 | [diff] [blame] | 282 | // FR0 = (Value, Chain, Glue) |
| 283 | unsigned PredR = MRI.createVirtualRegister(&Hexagon::PredRegsRegClass); |
| 284 | SDValue TPR = DAG.getCopyToReg(FR0.getValue(1), dl, PredR, |
| 285 | FR0.getValue(0), FR0.getValue(2)); |
| 286 | // TPR = (Chain, Glue) |
| Krzysztof Parzyszek | 1aaf41a | 2017-02-17 22:14:51 +0000 | [diff] [blame] | 287 | // Don't glue this CopyFromReg, because it copies from a virtual |
| 288 | // register. If it is glued to the call, InstrEmitter will add it |
| 289 | // as an implicit def to the call (EmitMachineNode). |
| 290 | RetVal = DAG.getCopyFromReg(TPR.getValue(0), dl, PredR, MVT::i1); |
| 291 | Glue = TPR.getValue(1); |
| Krzysztof Parzyszek | 6f06b6e | 2017-10-23 19:35:25 +0000 | [diff] [blame] | 292 | Chain = TPR.getValue(0); |
| Krzysztof Parzyszek | 51155fc | 2016-03-04 17:38:05 +0000 | [diff] [blame] | 293 | } else { |
| 294 | RetVal = DAG.getCopyFromReg(Chain, dl, RVLocs[i].getLocReg(), |
| Krzysztof Parzyszek | 1aaf41a | 2017-02-17 22:14:51 +0000 | [diff] [blame] | 295 | RVLocs[i].getValVT(), Glue); |
| 296 | Glue = RetVal.getValue(2); |
| Krzysztof Parzyszek | 6f06b6e | 2017-10-23 19:35:25 +0000 | [diff] [blame] | 297 | Chain = RetVal.getValue(1); |
| Krzysztof Parzyszek | 51155fc | 2016-03-04 17:38:05 +0000 | [diff] [blame] | 298 | } |
| 299 | InVals.push_back(RetVal.getValue(0)); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 300 | } |
| 301 | |
| 302 | return Chain; |
| 303 | } |
| 304 | |
| 305 | /// LowerCall - Functions arguments are copied from virtual regs to |
| 306 | /// (physical regs)/(stack frame), CALLSEQ_START and CALLSEQ_END are emitted. |
| 307 | SDValue |
| Justin Holewinski | aa58397 | 2012-05-25 16:35:28 +0000 | [diff] [blame] | 308 | HexagonTargetLowering::LowerCall(TargetLowering::CallLoweringInfo &CLI, |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 309 | SmallVectorImpl<SDValue> &InVals) const { |
| Justin Holewinski | aa58397 | 2012-05-25 16:35:28 +0000 | [diff] [blame] | 310 | SelectionDAG &DAG = CLI.DAG; |
| Craig Topper | b94011f | 2013-07-14 04:42:23 +0000 | [diff] [blame] | 311 | SDLoc &dl = CLI.DL; |
| 312 | SmallVectorImpl<ISD::OutputArg> &Outs = CLI.Outs; |
| 313 | SmallVectorImpl<SDValue> &OutVals = CLI.OutVals; |
| 314 | SmallVectorImpl<ISD::InputArg> &Ins = CLI.Ins; |
| Justin Holewinski | aa58397 | 2012-05-25 16:35:28 +0000 | [diff] [blame] | 315 | SDValue Chain = CLI.Chain; |
| 316 | SDValue Callee = CLI.Callee; |
| Justin Holewinski | aa58397 | 2012-05-25 16:35:28 +0000 | [diff] [blame] | 317 | CallingConv::ID CallConv = CLI.CallConv; |
| Krzysztof Parzyszek | 317d42c | 2016-08-01 20:31:50 +0000 | [diff] [blame] | 318 | bool IsVarArg = CLI.IsVarArg; |
| 319 | bool DoesNotReturn = CLI.DoesNotReturn; |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 320 | |
| 321 | bool IsStructRet = (Outs.empty()) ? false : Outs[0].Flags.isSRet(); |
| Krzysztof Parzyszek | 4fa2a9f | 2015-04-22 16:43:53 +0000 | [diff] [blame] | 322 | MachineFunction &MF = DAG.getMachineFunction(); |
| Krzysztof Parzyszek | f67cd82 | 2017-07-11 17:11:54 +0000 | [diff] [blame] | 323 | MachineFrameInfo &MFI = MF.getFrameInfo(); |
| Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 324 | auto PtrVT = getPointerTy(MF.getDataLayout()); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 325 | |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 326 | // Check for varargs. |
| Krzysztof Parzyszek | 7cfe7cb | 2018-02-09 15:30:02 +0000 | [diff] [blame] | 327 | unsigned NumNamedVarArgParams = 0; |
| 328 | |
| Krzysztof Parzyszek | 21dc8bd | 2015-12-18 20:19:30 +0000 | [diff] [blame] | 329 | if (GlobalAddressSDNode *GAN = dyn_cast<GlobalAddressSDNode>(Callee)) { |
| 330 | const GlobalValue *GV = GAN->getGlobal(); |
| 331 | Callee = DAG.getTargetGlobalAddress(GV, dl, MVT::i32); |
| 332 | if (const Function* F = dyn_cast<Function>(GV)) { |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 333 | // If a function has zero args and is a vararg function, that's |
| 334 | // disallowed so it must be an undeclared function. Do not assume |
| 335 | // varargs if the callee is undefined. |
| Krzysztof Parzyszek | 21dc8bd | 2015-12-18 20:19:30 +0000 | [diff] [blame] | 336 | if (F->isVarArg() && F->getFunctionType()->getNumParams() != 0) |
| 337 | NumNamedVarArgParams = F->getFunctionType()->getNumParams(); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 338 | } |
| 339 | } |
| 340 | |
| Benjamin Kramer | 602bb4a | 2013-10-27 11:16:09 +0000 | [diff] [blame] | 341 | // Analyze operands of the call, assigning locations to each operand. |
| 342 | SmallVector<CCValAssign, 16> ArgLocs; |
| Krzysztof Parzyszek | 7cfe7cb | 2018-02-09 15:30:02 +0000 | [diff] [blame] | 343 | HexagonCCState CCInfo(CallConv, IsVarArg, DAG.getMachineFunction(), |
| 344 | ArgLocs, *DAG.getContext(), NumNamedVarArgParams); |
| Benjamin Kramer | 602bb4a | 2013-10-27 11:16:09 +0000 | [diff] [blame] | 345 | |
| Krzysztof Parzyszek | 7cfe7cb | 2018-02-09 15:30:02 +0000 | [diff] [blame] | 346 | if (Subtarget.useHVXOps()) |
| 347 | CCInfo.AnalyzeCallOperands(Outs, CC_Hexagon_HVX); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 348 | else |
| 349 | CCInfo.AnalyzeCallOperands(Outs, CC_Hexagon); |
| 350 | |
| Matthias Braun | f1caa28 | 2017-12-15 22:22:58 +0000 | [diff] [blame] | 351 | auto Attr = MF.getFunction().getFnAttribute("disable-tail-calls"); |
| Akira Hatanaka | d9699bc | 2015-06-09 19:07:19 +0000 | [diff] [blame] | 352 | if (Attr.getValueAsString() == "true") |
| Krzysztof Parzyszek | 7cfe7cb | 2018-02-09 15:30:02 +0000 | [diff] [blame] | 353 | CLI.IsTailCall = false; |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 354 | |
| Krzysztof Parzyszek | 7cfe7cb | 2018-02-09 15:30:02 +0000 | [diff] [blame] | 355 | if (CLI.IsTailCall) { |
| Matthias Braun | f1caa28 | 2017-12-15 22:22:58 +0000 | [diff] [blame] | 356 | bool StructAttrFlag = MF.getFunction().hasStructRetAttr(); |
| Krzysztof Parzyszek | 7cfe7cb | 2018-02-09 15:30:02 +0000 | [diff] [blame] | 357 | CLI.IsTailCall = IsEligibleForTailCallOptimization(Callee, CallConv, |
| 358 | IsVarArg, IsStructRet, StructAttrFlag, Outs, |
| 359 | OutVals, Ins, DAG); |
| Krzysztof Parzyszek | 4fa2a9f | 2015-04-22 16:43:53 +0000 | [diff] [blame] | 360 | for (unsigned i = 0, e = ArgLocs.size(); i != e; ++i) { |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 361 | CCValAssign &VA = ArgLocs[i]; |
| 362 | if (VA.isMemLoc()) { |
| Krzysztof Parzyszek | 7cfe7cb | 2018-02-09 15:30:02 +0000 | [diff] [blame] | 363 | CLI.IsTailCall = false; |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 364 | break; |
| 365 | } |
| 366 | } |
| Krzysztof Parzyszek | 7cfe7cb | 2018-02-09 15:30:02 +0000 | [diff] [blame] | 367 | DEBUG(dbgs() << (CLI.IsTailCall ? "Eligible for Tail Call\n" |
| 368 | : "Argument must be passed on stack. " |
| 369 | "Not eligible for Tail Call\n")); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 370 | } |
| 371 | // Get a count of how many bytes are to be pushed on the stack. |
| 372 | unsigned NumBytes = CCInfo.getNextStackOffset(); |
| 373 | SmallVector<std::pair<unsigned, SDValue>, 16> RegsToPass; |
| 374 | SmallVector<SDValue, 8> MemOpChains; |
| 375 | |
| Krzysztof Parzyszek | 7cfe7cb | 2018-02-09 15:30:02 +0000 | [diff] [blame] | 376 | const HexagonRegisterInfo &HRI = *Subtarget.getRegisterInfo(); |
| Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 377 | SDValue StackPtr = |
| 378 | DAG.getCopyFromReg(Chain, dl, HRI.getStackRegister(), PtrVT); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 379 | |
| Krzysztof Parzyszek | 08ff888 | 2015-11-26 18:38:27 +0000 | [diff] [blame] | 380 | bool NeedsArgAlign = false; |
| 381 | unsigned LargestAlignSeen = 0; |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 382 | // Walk the register/memloc assignments, inserting copies/loads. |
| 383 | for (unsigned i = 0, e = ArgLocs.size(); i != e; ++i) { |
| 384 | CCValAssign &VA = ArgLocs[i]; |
| 385 | SDValue Arg = OutVals[i]; |
| 386 | ISD::ArgFlagsTy Flags = Outs[i].Flags; |
| Krzysztof Parzyszek | 08ff888 | 2015-11-26 18:38:27 +0000 | [diff] [blame] | 387 | // Record if we need > 8 byte alignment on an argument. |
| Krzysztof Parzyszek | ac1966e | 2017-11-27 18:12:16 +0000 | [diff] [blame] | 388 | bool ArgAlign = Subtarget.isHVXVectorType(VA.getValVT()); |
| Krzysztof Parzyszek | 08ff888 | 2015-11-26 18:38:27 +0000 | [diff] [blame] | 389 | NeedsArgAlign |= ArgAlign; |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 390 | |
| 391 | // Promote the value if needed. |
| 392 | switch (VA.getLocInfo()) { |
| 393 | default: |
| Krzysztof Parzyszek | 8f6b0c8 | 2017-12-20 14:44:05 +0000 | [diff] [blame] | 394 | // Loc info must be one of Full, BCvt, SExt, ZExt, or AExt. |
| Craig Topper | e55c556 | 2012-02-07 02:50:20 +0000 | [diff] [blame] | 395 | llvm_unreachable("Unknown loc info!"); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 396 | case CCValAssign::Full: |
| 397 | break; |
| Krzysztof Parzyszek | 8f6b0c8 | 2017-12-20 14:44:05 +0000 | [diff] [blame] | 398 | case CCValAssign::BCvt: |
| 399 | Arg = DAG.getBitcast(VA.getLocVT(), Arg); |
| 400 | break; |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 401 | case CCValAssign::SExt: |
| 402 | Arg = DAG.getNode(ISD::SIGN_EXTEND, dl, VA.getLocVT(), Arg); |
| 403 | break; |
| 404 | case CCValAssign::ZExt: |
| 405 | Arg = DAG.getNode(ISD::ZERO_EXTEND, dl, VA.getLocVT(), Arg); |
| 406 | break; |
| 407 | case CCValAssign::AExt: |
| 408 | Arg = DAG.getNode(ISD::ANY_EXTEND, dl, VA.getLocVT(), Arg); |
| 409 | break; |
| 410 | } |
| 411 | |
| 412 | if (VA.isMemLoc()) { |
| 413 | unsigned LocMemOffset = VA.getLocMemOffset(); |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 414 | SDValue MemAddr = DAG.getConstant(LocMemOffset, dl, |
| 415 | StackPtr.getValueType()); |
| Krzysztof Parzyszek | 4fa2a9f | 2015-04-22 16:43:53 +0000 | [diff] [blame] | 416 | MemAddr = DAG.getNode(ISD::ADD, dl, MVT::i32, StackPtr, MemAddr); |
| Krzysztof Parzyszek | 08ff888 | 2015-11-26 18:38:27 +0000 | [diff] [blame] | 417 | if (ArgAlign) |
| 418 | LargestAlignSeen = std::max(LargestAlignSeen, |
| 419 | VA.getLocVT().getStoreSizeInBits() >> 3); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 420 | if (Flags.isByVal()) { |
| 421 | // The argument is a struct passed by value. According to LLVM, "Arg" |
| 422 | // is is pointer. |
| Krzysztof Parzyszek | 4fa2a9f | 2015-04-22 16:43:53 +0000 | [diff] [blame] | 423 | MemOpChains.push_back(CreateCopyOfByValArgument(Arg, MemAddr, Chain, |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 424 | Flags, DAG, dl)); |
| 425 | } else { |
| Alex Lorenz | e40c8a2 | 2015-08-11 23:09:45 +0000 | [diff] [blame] | 426 | MachinePointerInfo LocPI = MachinePointerInfo::getStack( |
| 427 | DAG.getMachineFunction(), LocMemOffset); |
| Justin Lebar | 9c37581 | 2016-07-15 18:27:10 +0000 | [diff] [blame] | 428 | SDValue S = DAG.getStore(Chain, dl, Arg, MemAddr, LocPI); |
| Krzysztof Parzyszek | 4fa2a9f | 2015-04-22 16:43:53 +0000 | [diff] [blame] | 429 | MemOpChains.push_back(S); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 430 | } |
| 431 | continue; |
| 432 | } |
| 433 | |
| 434 | // Arguments that can be passed on register must be kept at RegsToPass |
| 435 | // vector. |
| Krzysztof Parzyszek | 4fa2a9f | 2015-04-22 16:43:53 +0000 | [diff] [blame] | 436 | if (VA.isRegLoc()) |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 437 | RegsToPass.push_back(std::make_pair(VA.getLocReg(), Arg)); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 438 | } |
| 439 | |
| Krzysztof Parzyszek | 08ff888 | 2015-11-26 18:38:27 +0000 | [diff] [blame] | 440 | if (NeedsArgAlign && Subtarget.hasV60TOps()) { |
| 441 | DEBUG(dbgs() << "Function needs byte stack align due to call args\n"); |
| Krzysztof Parzyszek | 7cfe7cb | 2018-02-09 15:30:02 +0000 | [diff] [blame] | 442 | unsigned VecAlign = HRI.getSpillAlignment(Hexagon::HvxVRRegClass); |
| 443 | LargestAlignSeen = std::max(LargestAlignSeen, VecAlign); |
| Matthias Braun | 941a705 | 2016-07-28 18:40:00 +0000 | [diff] [blame] | 444 | MFI.ensureMaxAlignment(LargestAlignSeen); |
| Krzysztof Parzyszek | 08ff888 | 2015-11-26 18:38:27 +0000 | [diff] [blame] | 445 | } |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 446 | // Transform all store nodes into one single node because all store |
| 447 | // nodes are independent of each other. |
| Krzysztof Parzyszek | 4fa2a9f | 2015-04-22 16:43:53 +0000 | [diff] [blame] | 448 | if (!MemOpChains.empty()) |
| Craig Topper | 48d114b | 2014-04-26 18:35:24 +0000 | [diff] [blame] | 449 | Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, MemOpChains); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 450 | |
| Krzysztof Parzyszek | 1aaf41a | 2017-02-17 22:14:51 +0000 | [diff] [blame] | 451 | SDValue Glue; |
| Krzysztof Parzyszek | 7cfe7cb | 2018-02-09 15:30:02 +0000 | [diff] [blame] | 452 | if (!CLI.IsTailCall) { |
| Serge Pavlov | d526b13 | 2017-05-09 13:35:13 +0000 | [diff] [blame] | 453 | Chain = DAG.getCALLSEQ_START(Chain, NumBytes, 0, dl); |
| Krzysztof Parzyszek | 1aaf41a | 2017-02-17 22:14:51 +0000 | [diff] [blame] | 454 | Glue = Chain.getValue(1); |
| Krzysztof Parzyszek | 4fa2a9f | 2015-04-22 16:43:53 +0000 | [diff] [blame] | 455 | } |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 456 | |
| 457 | // Build a sequence of copy-to-reg nodes chained together with token |
| 458 | // chain and flag operands which copy the outgoing args into registers. |
| Krzysztof Parzyszek | 317d42c | 2016-08-01 20:31:50 +0000 | [diff] [blame] | 459 | // The Glue is necessary since all emitted instructions must be |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 460 | // stuck together. |
| Krzysztof Parzyszek | 7cfe7cb | 2018-02-09 15:30:02 +0000 | [diff] [blame] | 461 | if (!CLI.IsTailCall) { |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 462 | for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i) { |
| 463 | Chain = DAG.getCopyToReg(Chain, dl, RegsToPass[i].first, |
| Krzysztof Parzyszek | 317d42c | 2016-08-01 20:31:50 +0000 | [diff] [blame] | 464 | RegsToPass[i].second, Glue); |
| 465 | Glue = Chain.getValue(1); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 466 | } |
| Krzysztof Parzyszek | 4fa2a9f | 2015-04-22 16:43:53 +0000 | [diff] [blame] | 467 | } else { |
| 468 | // For tail calls lower the arguments to the 'real' stack slot. |
| 469 | // |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 470 | // Force all the incoming stack arguments to be loaded from the stack |
| 471 | // before any new outgoing arguments are stored to the stack, because the |
| 472 | // outgoing stack slots may alias the incoming argument stack slots, and |
| 473 | // the alias isn't otherwise explicit. This is slightly more conservative |
| 474 | // than necessary, because it means that each store effectively depends |
| 475 | // on every argument instead of just those arguments it would clobber. |
| 476 | // |
| Benjamin Kramer | bde9176 | 2012-06-02 10:20:22 +0000 | [diff] [blame] | 477 | // Do not flag preceding copytoreg stuff together with the following stuff. |
| Krzysztof Parzyszek | 317d42c | 2016-08-01 20:31:50 +0000 | [diff] [blame] | 478 | Glue = SDValue(); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 479 | for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i) { |
| 480 | Chain = DAG.getCopyToReg(Chain, dl, RegsToPass[i].first, |
| Krzysztof Parzyszek | 317d42c | 2016-08-01 20:31:50 +0000 | [diff] [blame] | 481 | RegsToPass[i].second, Glue); |
| 482 | Glue = Chain.getValue(1); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 483 | } |
| Krzysztof Parzyszek | 317d42c | 2016-08-01 20:31:50 +0000 | [diff] [blame] | 484 | Glue = SDValue(); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 485 | } |
| 486 | |
| Krzysztof Parzyszek | 080bebd | 2016-07-25 14:42:11 +0000 | [diff] [blame] | 487 | bool LongCalls = MF.getSubtarget<HexagonSubtarget>().useLongCalls(); |
| 488 | unsigned Flags = LongCalls ? HexagonII::HMOTF_ConstExtended : 0; |
| 489 | |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 490 | // If the callee is a GlobalAddress/ExternalSymbol node (quite common, every |
| 491 | // direct call is) turn it into a TargetGlobalAddress/TargetExternalSymbol |
| 492 | // node so that legalize doesn't hack it. |
| Tobias Edler von Koch | b51460c | 2015-12-16 17:29:37 +0000 | [diff] [blame] | 493 | if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee)) { |
| Krzysztof Parzyszek | 080bebd | 2016-07-25 14:42:11 +0000 | [diff] [blame] | 494 | Callee = DAG.getTargetGlobalAddress(G->getGlobal(), dl, PtrVT, 0, Flags); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 495 | } else if (ExternalSymbolSDNode *S = |
| 496 | dyn_cast<ExternalSymbolSDNode>(Callee)) { |
| Krzysztof Parzyszek | 080bebd | 2016-07-25 14:42:11 +0000 | [diff] [blame] | 497 | Callee = DAG.getTargetExternalSymbol(S->getSymbol(), PtrVT, Flags); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 498 | } |
| 499 | |
| 500 | // Returns a chain & a flag for retval copy to use. |
| 501 | SDVTList NodeTys = DAG.getVTList(MVT::Other, MVT::Glue); |
| 502 | SmallVector<SDValue, 8> Ops; |
| 503 | Ops.push_back(Chain); |
| 504 | Ops.push_back(Callee); |
| 505 | |
| 506 | // Add argument registers to the end of the list so that they are |
| 507 | // known live into the call. |
| 508 | for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i) { |
| 509 | Ops.push_back(DAG.getRegister(RegsToPass[i].first, |
| 510 | RegsToPass[i].second.getValueType())); |
| 511 | } |
| 512 | |
| Krzysztof Parzyszek | 1aaf41a | 2017-02-17 22:14:51 +0000 | [diff] [blame] | 513 | const uint32_t *Mask = HRI.getCallPreservedMask(MF, CallConv); |
| 514 | assert(Mask && "Missing call preserved mask for calling convention"); |
| 515 | Ops.push_back(DAG.getRegisterMask(Mask)); |
| 516 | |
| Krzysztof Parzyszek | 317d42c | 2016-08-01 20:31:50 +0000 | [diff] [blame] | 517 | if (Glue.getNode()) |
| 518 | Ops.push_back(Glue); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 519 | |
| Krzysztof Parzyszek | 7cfe7cb | 2018-02-09 15:30:02 +0000 | [diff] [blame] | 520 | if (CLI.IsTailCall) { |
| Krzysztof Parzyszek | f67cd82 | 2017-07-11 17:11:54 +0000 | [diff] [blame] | 521 | MFI.setHasTailCall(); |
| Craig Topper | 48d114b | 2014-04-26 18:35:24 +0000 | [diff] [blame] | 522 | return DAG.getNode(HexagonISD::TC_RETURN, dl, NodeTys, Ops); |
| Arnold Schwaighofer | f54b73d | 2015-05-08 23:52:00 +0000 | [diff] [blame] | 523 | } |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 524 | |
| Krzysztof Parzyszek | f67cd82 | 2017-07-11 17:11:54 +0000 | [diff] [blame] | 525 | // Set this here because we need to know this for "hasFP" in frame lowering. |
| 526 | // The target-independent code calls getFrameRegister before setting it, and |
| 527 | // getFrameRegister uses hasFP to determine whether the function has FP. |
| 528 | MFI.setHasCalls(true); |
| 529 | |
| Krzysztof Parzyszek | be976d4 | 2016-08-12 11:12:02 +0000 | [diff] [blame] | 530 | unsigned OpCode = DoesNotReturn ? HexagonISD::CALLnr : HexagonISD::CALL; |
| Colin LeMahieu | 2e3a26d | 2015-01-16 17:05:27 +0000 | [diff] [blame] | 531 | Chain = DAG.getNode(OpCode, dl, NodeTys, Ops); |
| Krzysztof Parzyszek | 317d42c | 2016-08-01 20:31:50 +0000 | [diff] [blame] | 532 | Glue = Chain.getValue(1); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 533 | |
| 534 | // Create the CALLSEQ_END node. |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 535 | Chain = DAG.getCALLSEQ_END(Chain, DAG.getIntPtrConstant(NumBytes, dl, true), |
| Krzysztof Parzyszek | 317d42c | 2016-08-01 20:31:50 +0000 | [diff] [blame] | 536 | DAG.getIntPtrConstant(0, dl, true), Glue, dl); |
| 537 | Glue = Chain.getValue(1); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 538 | |
| 539 | // Handle result values, copying them out of physregs into vregs that we |
| 540 | // return. |
| Krzysztof Parzyszek | 317d42c | 2016-08-01 20:31:50 +0000 | [diff] [blame] | 541 | return LowerCallResult(Chain, Glue, CallConv, IsVarArg, Ins, dl, DAG, |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 542 | InVals, OutVals, Callee); |
| 543 | } |
| 544 | |
| Krzysztof Parzyszek | cfbe6ba | 2018-02-13 15:35:07 +0000 | [diff] [blame] | 545 | /// Returns true by value, base pointer and offset pointer and addressing |
| 546 | /// mode by reference if this node can be combined with a load / store to |
| 547 | /// form a post-indexed load / store. |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 548 | bool HexagonTargetLowering::getPostIndexedAddressParts(SDNode *N, SDNode *Op, |
| Krzysztof Parzyszek | cfbe6ba | 2018-02-13 15:35:07 +0000 | [diff] [blame] | 549 | SDValue &Base, SDValue &Offset, ISD::MemIndexedMode &AM, |
| 550 | SelectionDAG &DAG) const { |
| 551 | LSBaseSDNode *LSN = dyn_cast<LSBaseSDNode>(N); |
| 552 | if (!LSN) |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 553 | return false; |
| Krzysztof Parzyszek | cfbe6ba | 2018-02-13 15:35:07 +0000 | [diff] [blame] | 554 | EVT VT = LSN->getMemoryVT(); |
| 555 | if (!VT.isSimple()) |
| 556 | return false; |
| 557 | bool IsLegalType = VT == MVT::i8 || VT == MVT::i16 || |
| 558 | VT == MVT::i32 || VT == MVT::i64 || |
| 559 | Subtarget.isHVXVectorType(VT.getSimpleVT()); |
| 560 | if (!IsLegalType) |
| 561 | return false; |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 562 | |
| Krzysztof Parzyszek | cfbe6ba | 2018-02-13 15:35:07 +0000 | [diff] [blame] | 563 | if (Op->getOpcode() != ISD::ADD) |
| 564 | return false; |
| 565 | Base = Op->getOperand(0); |
| 566 | Offset = Op->getOperand(1); |
| 567 | if (!isa<ConstantSDNode>(Offset.getNode())) |
| 568 | return false; |
| 569 | AM = ISD::POST_INC; |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 570 | |
| Krzysztof Parzyszek | cfbe6ba | 2018-02-13 15:35:07 +0000 | [diff] [blame] | 571 | int32_t V = cast<ConstantSDNode>(Offset.getNode())->getSExtValue(); |
| 572 | return Subtarget.getInstrInfo()->isValidAutoIncImm(VT, V); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 573 | } |
| 574 | |
| Krzysztof Parzyszek | 21dc8bd | 2015-12-18 20:19:30 +0000 | [diff] [blame] | 575 | SDValue |
| 576 | HexagonTargetLowering::LowerINLINEASM(SDValue Op, SelectionDAG &DAG) const { |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 577 | MachineFunction &MF = DAG.getMachineFunction(); |
| Krzysztof Parzyszek | 9eb75c4 | 2017-06-30 21:21:40 +0000 | [diff] [blame] | 578 | auto &HMFI = *MF.getInfo<HexagonMachineFunctionInfo>(); |
| 579 | const HexagonRegisterInfo &HRI = *Subtarget.getRegisterInfo(); |
| 580 | unsigned LR = HRI.getRARegister(); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 581 | |
| Krzysztof Parzyszek | 9eb75c4 | 2017-06-30 21:21:40 +0000 | [diff] [blame] | 582 | if (Op.getOpcode() != ISD::INLINEASM || HMFI.hasClobberLR()) |
| 583 | return Op; |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 584 | |
| Krzysztof Parzyszek | 9eb75c4 | 2017-06-30 21:21:40 +0000 | [diff] [blame] | 585 | unsigned NumOps = Op.getNumOperands(); |
| 586 | if (Op.getOperand(NumOps-1).getValueType() == MVT::Glue) |
| 587 | --NumOps; // Ignore the flag operand. |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 588 | |
| Krzysztof Parzyszek | 9eb75c4 | 2017-06-30 21:21:40 +0000 | [diff] [blame] | 589 | for (unsigned i = InlineAsm::Op_FirstOperand; i != NumOps;) { |
| 590 | unsigned Flags = cast<ConstantSDNode>(Op.getOperand(i))->getZExtValue(); |
| 591 | unsigned NumVals = InlineAsm::getNumOperandRegisters(Flags); |
| 592 | ++i; // Skip the ID value. |
| 593 | |
| 594 | switch (InlineAsm::getKind(Flags)) { |
| 595 | default: |
| 596 | llvm_unreachable("Bad flags!"); |
| 597 | case InlineAsm::Kind_RegUse: |
| 598 | case InlineAsm::Kind_Imm: |
| 599 | case InlineAsm::Kind_Mem: |
| 600 | i += NumVals; |
| 601 | break; |
| 602 | case InlineAsm::Kind_Clobber: |
| 603 | case InlineAsm::Kind_RegDef: |
| 604 | case InlineAsm::Kind_RegDefEarlyClobber: { |
| 605 | for (; NumVals; --NumVals, ++i) { |
| 606 | unsigned Reg = cast<RegisterSDNode>(Op.getOperand(i))->getReg(); |
| 607 | if (Reg != LR) |
| 608 | continue; |
| 609 | HMFI.setHasClobberLR(true); |
| 610 | return Op; |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 611 | } |
| Krzysztof Parzyszek | 9eb75c4 | 2017-06-30 21:21:40 +0000 | [diff] [blame] | 612 | break; |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 613 | } |
| 614 | } |
| Krzysztof Parzyszek | 9eb75c4 | 2017-06-30 21:21:40 +0000 | [diff] [blame] | 615 | } |
| 616 | |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 617 | return Op; |
| 618 | } |
| 619 | |
| Krzysztof Parzyszek | 6895b2c | 2016-02-18 13:58:38 +0000 | [diff] [blame] | 620 | // Need to transform ISD::PREFETCH into something that doesn't inherit |
| 621 | // all of the properties of ISD::PREFETCH, specifically SDNPMayLoad and |
| 622 | // SDNPMayStore. |
| 623 | SDValue HexagonTargetLowering::LowerPREFETCH(SDValue Op, |
| 624 | SelectionDAG &DAG) const { |
| 625 | SDValue Chain = Op.getOperand(0); |
| 626 | SDValue Addr = Op.getOperand(1); |
| 627 | // Lower it to DCFETCH($reg, #0). A "pat" will try to merge the offset in, |
| 628 | // if the "reg" is fed by an "add". |
| 629 | SDLoc DL(Op); |
| 630 | SDValue Zero = DAG.getConstant(0, DL, MVT::i32); |
| 631 | return DAG.getNode(HexagonISD::DCFETCH, DL, MVT::Other, Chain, Addr, Zero); |
| 632 | } |
| 633 | |
| Krzysztof Parzyszek | ab57c2b | 2017-02-22 22:28:47 +0000 | [diff] [blame] | 634 | // Custom-handle ISD::READCYCLECOUNTER because the target-independent SDNode |
| 635 | // is marked as having side-effects, while the register read on Hexagon does |
| 636 | // not have any. TableGen refuses to accept the direct pattern from that node |
| 637 | // to the A4_tfrcpp. |
| 638 | SDValue HexagonTargetLowering::LowerREADCYCLECOUNTER(SDValue Op, |
| 639 | SelectionDAG &DAG) const { |
| 640 | SDValue Chain = Op.getOperand(0); |
| 641 | SDLoc dl(Op); |
| 642 | SDVTList VTs = DAG.getVTList(MVT::i32, MVT::Other); |
| 643 | return DAG.getNode(HexagonISD::READCYCLE, dl, VTs, Chain); |
| 644 | } |
| 645 | |
| Krzysztof Parzyszek | 6895b2c | 2016-02-18 13:58:38 +0000 | [diff] [blame] | 646 | SDValue HexagonTargetLowering::LowerINTRINSIC_VOID(SDValue Op, |
| 647 | SelectionDAG &DAG) const { |
| 648 | SDValue Chain = Op.getOperand(0); |
| 649 | unsigned IntNo = cast<ConstantSDNode>(Op.getOperand(1))->getZExtValue(); |
| 650 | // Lower the hexagon_prefetch builtin to DCFETCH, as above. |
| 651 | if (IntNo == Intrinsic::hexagon_prefetch) { |
| 652 | SDValue Addr = Op.getOperand(2); |
| 653 | SDLoc DL(Op); |
| 654 | SDValue Zero = DAG.getConstant(0, DL, MVT::i32); |
| 655 | return DAG.getNode(HexagonISD::DCFETCH, DL, MVT::Other, Chain, Addr, Zero); |
| 656 | } |
| 657 | return SDValue(); |
| 658 | } |
| 659 | |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 660 | SDValue |
| 661 | HexagonTargetLowering::LowerDYNAMIC_STACKALLOC(SDValue Op, |
| 662 | SelectionDAG &DAG) const { |
| 663 | SDValue Chain = Op.getOperand(0); |
| 664 | SDValue Size = Op.getOperand(1); |
| Krzysztof Parzyszek | 4fa2a9f | 2015-04-22 16:43:53 +0000 | [diff] [blame] | 665 | SDValue Align = Op.getOperand(2); |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 666 | SDLoc dl(Op); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 667 | |
| Krzysztof Parzyszek | 4fa2a9f | 2015-04-22 16:43:53 +0000 | [diff] [blame] | 668 | ConstantSDNode *AlignConst = dyn_cast<ConstantSDNode>(Align); |
| 669 | assert(AlignConst && "Non-constant Align in LowerDYNAMIC_STACKALLOC"); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 670 | |
| Krzysztof Parzyszek | 4fa2a9f | 2015-04-22 16:43:53 +0000 | [diff] [blame] | 671 | unsigned A = AlignConst->getSExtValue(); |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 672 | auto &HFI = *Subtarget.getFrameLowering(); |
| Krzysztof Parzyszek | 4fa2a9f | 2015-04-22 16:43:53 +0000 | [diff] [blame] | 673 | // "Zero" means natural stack alignment. |
| 674 | if (A == 0) |
| 675 | A = HFI.getStackAlignment(); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 676 | |
| Krzysztof Parzyszek | 4fa2a9f | 2015-04-22 16:43:53 +0000 | [diff] [blame] | 677 | DEBUG({ |
| Reid Kleckner | 40d7230 | 2016-10-20 00:22:23 +0000 | [diff] [blame] | 678 | dbgs () << __func__ << " Align: " << A << " Size: "; |
| Krzysztof Parzyszek | 4fa2a9f | 2015-04-22 16:43:53 +0000 | [diff] [blame] | 679 | Size.getNode()->dump(&DAG); |
| 680 | dbgs() << "\n"; |
| 681 | }); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 682 | |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 683 | SDValue AC = DAG.getConstant(A, dl, MVT::i32); |
| Krzysztof Parzyszek | 4fa2a9f | 2015-04-22 16:43:53 +0000 | [diff] [blame] | 684 | SDVTList VTs = DAG.getVTList(MVT::i32, MVT::Other); |
| Krzysztof Parzyszek | 23920ec | 2015-10-19 18:30:27 +0000 | [diff] [blame] | 685 | SDValue AA = DAG.getNode(HexagonISD::ALLOCA, dl, VTs, Chain, Size, AC); |
| Nirav Dave | bfdb483 | 2016-06-23 17:52:57 +0000 | [diff] [blame] | 686 | |
| 687 | DAG.ReplaceAllUsesOfValueWith(Op, AA); |
| Krzysztof Parzyszek | 23920ec | 2015-10-19 18:30:27 +0000 | [diff] [blame] | 688 | return AA; |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 689 | } |
| 690 | |
| Benjamin Kramer | bdc4956 | 2016-06-12 15:39:02 +0000 | [diff] [blame] | 691 | SDValue HexagonTargetLowering::LowerFormalArguments( |
| Krzysztof Parzyszek | 7cfe7cb | 2018-02-09 15:30:02 +0000 | [diff] [blame] | 692 | SDValue Chain, CallingConv::ID CallConv, bool IsVarArg, |
| Benjamin Kramer | bdc4956 | 2016-06-12 15:39:02 +0000 | [diff] [blame] | 693 | const SmallVectorImpl<ISD::InputArg> &Ins, const SDLoc &dl, |
| 694 | SelectionDAG &DAG, SmallVectorImpl<SDValue> &InVals) const { |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 695 | MachineFunction &MF = DAG.getMachineFunction(); |
| Matthias Braun | 941a705 | 2016-07-28 18:40:00 +0000 | [diff] [blame] | 696 | MachineFrameInfo &MFI = MF.getFrameInfo(); |
| Krzysztof Parzyszek | 7cfe7cb | 2018-02-09 15:30:02 +0000 | [diff] [blame] | 697 | MachineRegisterInfo &MRI = MF.getRegInfo(); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 698 | |
| 699 | // Assign locations to all of the incoming arguments. |
| 700 | SmallVector<CCValAssign, 16> ArgLocs; |
| Krzysztof Parzyszek | 7cfe7cb | 2018-02-09 15:30:02 +0000 | [diff] [blame] | 701 | CCState CCInfo(CallConv, IsVarArg, DAG.getMachineFunction(), ArgLocs, |
| Eric Christopher | b521750 | 2014-08-06 18:45:26 +0000 | [diff] [blame] | 702 | *DAG.getContext()); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 703 | |
| Krzysztof Parzyszek | 7cfe7cb | 2018-02-09 15:30:02 +0000 | [diff] [blame] | 704 | if (Subtarget.useHVXOps()) |
| 705 | CCInfo.AnalyzeFormalArguments(Ins, CC_Hexagon_HVX); |
| 706 | else |
| 707 | CCInfo.AnalyzeFormalArguments(Ins, CC_Hexagon); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 708 | |
| 709 | // For LLVM, in the case when returning a struct by value (>8byte), |
| 710 | // the first argument is a pointer that points to the location on caller's |
| 711 | // stack where the return value will be stored. For Hexagon, the location on |
| 712 | // caller's stack is passed only when the struct size is smaller than (and |
| 713 | // equal to) 8 bytes. If not, no address will be passed into callee and |
| 714 | // callee return the result direclty through R0/R1. |
| 715 | |
| Krzysztof Parzyszek | 7cfe7cb | 2018-02-09 15:30:02 +0000 | [diff] [blame] | 716 | auto &HMFI = *MF.getInfo<HexagonMachineFunctionInfo>(); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 717 | |
| 718 | for (unsigned i = 0, e = ArgLocs.size(); i != e; ++i) { |
| 719 | CCValAssign &VA = ArgLocs[i]; |
| 720 | ISD::ArgFlagsTy Flags = Ins[i].Flags; |
| Krzysztof Parzyszek | 7cfe7cb | 2018-02-09 15:30:02 +0000 | [diff] [blame] | 721 | bool ByVal = Flags.isByVal(); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 722 | |
| Krzysztof Parzyszek | 7cfe7cb | 2018-02-09 15:30:02 +0000 | [diff] [blame] | 723 | // Arguments passed in registers: |
| 724 | // 1. 32- and 64-bit values and HVX vectors are passed directly, |
| 725 | // 2. Large structs are passed via an address, and the address is |
| 726 | // passed in a register. |
| 727 | if (VA.isRegLoc() && ByVal && Flags.getByValSize() <= 8) |
| 728 | llvm_unreachable("ByValSize must be bigger than 8 bytes"); |
| Krzysztof Parzyszek | 08ff888 | 2015-11-26 18:38:27 +0000 | [diff] [blame] | 729 | |
| Krzysztof Parzyszek | 7cfe7cb | 2018-02-09 15:30:02 +0000 | [diff] [blame] | 730 | bool InReg = VA.isRegLoc() && |
| 731 | (!ByVal || (ByVal && Flags.getByValSize() > 8)); |
| Krzysztof Parzyszek | 08ff888 | 2015-11-26 18:38:27 +0000 | [diff] [blame] | 732 | |
| Krzysztof Parzyszek | 7cfe7cb | 2018-02-09 15:30:02 +0000 | [diff] [blame] | 733 | if (InReg) { |
| 734 | MVT RegVT = VA.getLocVT(); |
| 735 | if (VA.getLocInfo() == CCValAssign::BCvt) |
| 736 | RegVT = VA.getValVT(); |
| 737 | |
| 738 | const TargetRegisterClass *RC = getRegClassFor(RegVT); |
| 739 | unsigned VReg = MRI.createVirtualRegister(RC); |
| 740 | SDValue Copy = DAG.getCopyFromReg(Chain, dl, VReg, RegVT); |
| 741 | |
| 742 | // Treat values of type MVT::i1 specially: they are passed in |
| 743 | // registers of type i32, but they need to remain as values of |
| 744 | // type i1 for consistency of the argument lowering. |
| 745 | if (VA.getValVT() == MVT::i1) { |
| 746 | assert(RegVT.getSizeInBits() <= 32); |
| 747 | SDValue T = DAG.getNode(ISD::AND, dl, RegVT, |
| 748 | Copy, DAG.getConstant(1, dl, RegVT)); |
| 749 | Copy = DAG.getSetCC(dl, MVT::i1, T, DAG.getConstant(0, dl, RegVT), |
| 750 | ISD::SETNE); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 751 | } else { |
| Krzysztof Parzyszek | 7cfe7cb | 2018-02-09 15:30:02 +0000 | [diff] [blame] | 752 | #ifndef NDEBUG |
| 753 | unsigned RegSize = RegVT.getSizeInBits(); |
| 754 | assert(RegSize == 32 || RegSize == 64 || |
| 755 | Subtarget.isHVXVectorType(RegVT)); |
| 756 | #endif |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 757 | } |
| Krzysztof Parzyszek | 7cfe7cb | 2018-02-09 15:30:02 +0000 | [diff] [blame] | 758 | InVals.push_back(Copy); |
| 759 | MRI.addLiveIn(VA.getLocReg(), VReg); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 760 | } else { |
| Krzysztof Parzyszek | 7cfe7cb | 2018-02-09 15:30:02 +0000 | [diff] [blame] | 761 | assert(VA.isMemLoc() && "Argument should be passed in memory"); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 762 | |
| Krzysztof Parzyszek | 7cfe7cb | 2018-02-09 15:30:02 +0000 | [diff] [blame] | 763 | // If it's a byval parameter, then we need to compute the |
| 764 | // "real" size, not the size of the pointer. |
| 765 | unsigned ObjSize = Flags.isByVal() |
| 766 | ? Flags.getByValSize() |
| 767 | : VA.getLocVT().getStoreSizeInBits() / 8; |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 768 | |
| Krzysztof Parzyszek | 7cfe7cb | 2018-02-09 15:30:02 +0000 | [diff] [blame] | 769 | // Create the frame index object for this incoming parameter. |
| 770 | int Offset = HEXAGON_LRFP_SIZE + VA.getLocMemOffset(); |
| 771 | int FI = MFI.CreateFixedObject(ObjSize, Offset, true); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 772 | SDValue FIN = DAG.getFrameIndex(FI, MVT::i32); |
| 773 | |
| 774 | if (Flags.isByVal()) { |
| 775 | // If it's a pass-by-value aggregate, then do not dereference the stack |
| 776 | // location. Instead, we should generate a reference to the stack |
| 777 | // location. |
| 778 | InVals.push_back(FIN); |
| 779 | } else { |
| Krzysztof Parzyszek | 7cfe7cb | 2018-02-09 15:30:02 +0000 | [diff] [blame] | 780 | SDValue L = DAG.getLoad(VA.getValVT(), dl, Chain, FIN, |
| 781 | MachinePointerInfo::getFixedStack(MF, FI, 0)); |
| 782 | InVals.push_back(L); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 783 | } |
| 784 | } |
| 785 | } |
| 786 | |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 787 | |
| Krzysztof Parzyszek | 7cfe7cb | 2018-02-09 15:30:02 +0000 | [diff] [blame] | 788 | if (IsVarArg) { |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 789 | // This will point to the next argument passed via stack. |
| Krzysztof Parzyszek | 7cfe7cb | 2018-02-09 15:30:02 +0000 | [diff] [blame] | 790 | int Offset = HEXAGON_LRFP_SIZE + CCInfo.getNextStackOffset(); |
| 791 | int FI = MFI.CreateFixedObject(Hexagon_PointerSize, Offset, true); |
| 792 | HMFI.setVarArgsFrameIndex(FI); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 793 | } |
| 794 | |
| 795 | return Chain; |
| 796 | } |
| 797 | |
| 798 | SDValue |
| 799 | HexagonTargetLowering::LowerVASTART(SDValue Op, SelectionDAG &DAG) const { |
| 800 | // VASTART stores the address of the VarArgsFrameIndex slot into the |
| 801 | // memory location argument. |
| 802 | MachineFunction &MF = DAG.getMachineFunction(); |
| 803 | HexagonMachineFunctionInfo *QFI = MF.getInfo<HexagonMachineFunctionInfo>(); |
| 804 | SDValue Addr = DAG.getFrameIndex(QFI->getVarArgsFrameIndex(), MVT::i32); |
| 805 | const Value *SV = cast<SrcValueSDNode>(Op.getOperand(2))->getValue(); |
| Justin Lebar | 9c37581 | 2016-07-15 18:27:10 +0000 | [diff] [blame] | 806 | return DAG.getStore(Op.getOperand(0), SDLoc(Op), Addr, Op.getOperand(1), |
| 807 | MachinePointerInfo(SV)); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 808 | } |
| 809 | |
| Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 810 | static bool isSExtFree(SDValue N) { |
| 811 | // A sign-extend of a truncate of a sign-extend is free. |
| 812 | if (N.getOpcode() == ISD::TRUNCATE && |
| 813 | N.getOperand(0).getOpcode() == ISD::AssertSext) |
| 814 | return true; |
| 815 | // We have sign-extended loads. |
| 816 | if (N.getOpcode() == ISD::LOAD) |
| 817 | return true; |
| 818 | return false; |
| 819 | } |
| 820 | |
| Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 821 | SDValue HexagonTargetLowering::LowerSETCC(SDValue Op, SelectionDAG &DAG) const { |
| 822 | SDLoc dl(Op); |
| Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 823 | SDValue LHS = Op.getOperand(0); |
| 824 | SDValue RHS = Op.getOperand(1); |
| 825 | SDValue Cmp = Op.getOperand(2); |
| 826 | ISD::CondCode CC = cast<CondCodeSDNode>(Cmp)->get(); |
| 827 | |
| 828 | EVT VT = Op.getValueType(); |
| 829 | EVT LHSVT = LHS.getValueType(); |
| 830 | EVT RHSVT = RHS.getValueType(); |
| 831 | |
| 832 | if (LHSVT == MVT::v2i16) { |
| Krzysztof Parzyszek | b2c458e | 2018-01-25 18:07:27 +0000 | [diff] [blame] | 833 | assert(CC == ISD::SETEQ || CC == ISD::SETNE || |
| 834 | ISD::isSignedIntSetCC(CC) || ISD::isUnsignedIntSetCC(CC)); |
| Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 835 | unsigned ExtOpc = ISD::isSignedIntSetCC(CC) ? ISD::SIGN_EXTEND |
| 836 | : ISD::ZERO_EXTEND; |
| 837 | SDValue LX = DAG.getNode(ExtOpc, dl, MVT::v2i32, LHS); |
| 838 | SDValue RX = DAG.getNode(ExtOpc, dl, MVT::v2i32, RHS); |
| 839 | SDValue SC = DAG.getNode(ISD::SETCC, dl, MVT::v2i1, LX, RX, Cmp); |
| 840 | return SC; |
| 841 | } |
| 842 | |
| 843 | // Treat all other vector types as legal. |
| 844 | if (VT.isVector()) |
| 845 | return Op; |
| 846 | |
| 847 | // Equals and not equals should use sign-extend, not zero-extend, since |
| 848 | // we can represent small negative values in the compare instructions. |
| 849 | // The LLVM default is to use zero-extend arbitrarily in these cases. |
| 850 | if ((CC == ISD::SETEQ || CC == ISD::SETNE) && |
| 851 | (RHSVT == MVT::i8 || RHSVT == MVT::i16) && |
| 852 | (LHSVT == MVT::i8 || LHSVT == MVT::i16)) { |
| 853 | ConstantSDNode *C = dyn_cast<ConstantSDNode>(RHS); |
| 854 | if (C && C->getAPIntValue().isNegative()) { |
| 855 | LHS = DAG.getNode(ISD::SIGN_EXTEND, dl, MVT::i32, LHS); |
| 856 | RHS = DAG.getNode(ISD::SIGN_EXTEND, dl, MVT::i32, RHS); |
| 857 | return DAG.getNode(ISD::SETCC, dl, Op.getValueType(), |
| 858 | LHS, RHS, Op.getOperand(2)); |
| 859 | } |
| 860 | if (isSExtFree(LHS) || isSExtFree(RHS)) { |
| 861 | LHS = DAG.getNode(ISD::SIGN_EXTEND, dl, MVT::i32, LHS); |
| 862 | RHS = DAG.getNode(ISD::SIGN_EXTEND, dl, MVT::i32, RHS); |
| 863 | return DAG.getNode(ISD::SETCC, dl, Op.getValueType(), |
| 864 | LHS, RHS, Op.getOperand(2)); |
| 865 | } |
| 866 | } |
| 867 | return SDValue(); |
| 868 | } |
| 869 | |
| Krzysztof Parzyszek | 21dc8bd | 2015-12-18 20:19:30 +0000 | [diff] [blame] | 870 | SDValue |
| 871 | HexagonTargetLowering::LowerVSELECT(SDValue Op, SelectionDAG &DAG) const { |
| Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 872 | SDValue PredOp = Op.getOperand(0); |
| 873 | SDValue Op1 = Op.getOperand(1), Op2 = Op.getOperand(2); |
| 874 | EVT OpVT = Op1.getValueType(); |
| 875 | SDLoc DL(Op); |
| 876 | |
| 877 | if (OpVT == MVT::v2i16) { |
| 878 | SDValue X1 = DAG.getNode(ISD::ZERO_EXTEND, DL, MVT::v2i32, Op1); |
| 879 | SDValue X2 = DAG.getNode(ISD::ZERO_EXTEND, DL, MVT::v2i32, Op2); |
| 880 | SDValue SL = DAG.getNode(ISD::VSELECT, DL, MVT::v2i32, PredOp, X1, X2); |
| 881 | SDValue TR = DAG.getNode(ISD::TRUNCATE, DL, MVT::v2i16, SL); |
| 882 | return TR; |
| 883 | } |
| 884 | |
| 885 | return SDValue(); |
| 886 | } |
| 887 | |
| Krzysztof Parzyszek | 91ff5c6 | 2017-08-01 13:12:53 +0000 | [diff] [blame] | 888 | static Constant *convert_i1_to_i8(const Constant *ConstVal) { |
| 889 | SmallVector<Constant *, 128> NewConst; |
| 890 | const ConstantVector *CV = dyn_cast<ConstantVector>(ConstVal); |
| 891 | if (!CV) |
| 892 | return nullptr; |
| 893 | |
| 894 | LLVMContext &Ctx = ConstVal->getContext(); |
| 895 | IRBuilder<> IRB(Ctx); |
| 896 | unsigned NumVectorElements = CV->getNumOperands(); |
| 897 | assert(isPowerOf2_32(NumVectorElements) && |
| 898 | "conversion only supported for pow2 VectorSize!"); |
| 899 | |
| 900 | for (unsigned i = 0; i < NumVectorElements / 8; ++i) { |
| 901 | uint8_t x = 0; |
| 902 | for (unsigned j = 0; j < 8; ++j) { |
| 903 | uint8_t y = CV->getOperand(i * 8 + j)->getUniqueInteger().getZExtValue(); |
| 904 | x |= y << (7 - j); |
| 905 | } |
| 906 | assert((x == 0 || x == 255) && "Either all 0's or all 1's expected!"); |
| 907 | NewConst.push_back(IRB.getInt8(x)); |
| 908 | } |
| 909 | return ConstantVector::get(NewConst); |
| 910 | } |
| 911 | |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 912 | SDValue |
| Sirish Pande | 69295b8 | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 913 | HexagonTargetLowering::LowerConstantPool(SDValue Op, SelectionDAG &DAG) const { |
| 914 | EVT ValTy = Op.getValueType(); |
| Krzysztof Parzyszek | 21dc8bd | 2015-12-18 20:19:30 +0000 | [diff] [blame] | 915 | ConstantPoolSDNode *CPN = cast<ConstantPoolSDNode>(Op); |
| Krzysztof Parzyszek | 91ff5c6 | 2017-08-01 13:12:53 +0000 | [diff] [blame] | 916 | Constant *CVal = nullptr; |
| 917 | bool isVTi1Type = false; |
| 918 | if (const Constant *ConstVal = dyn_cast<Constant>(CPN->getConstVal())) { |
| 919 | Type *CValTy = ConstVal->getType(); |
| 920 | if (CValTy->isVectorTy() && |
| 921 | CValTy->getVectorElementType()->isIntegerTy(1)) { |
| 922 | CVal = convert_i1_to_i8(ConstVal); |
| 923 | isVTi1Type = (CVal != nullptr); |
| 924 | } |
| 925 | } |
| Krzysztof Parzyszek | 21dc8bd | 2015-12-18 20:19:30 +0000 | [diff] [blame] | 926 | unsigned Align = CPN->getAlignment(); |
| Rafael Espindola | 405e25a | 2016-06-26 22:24:01 +0000 | [diff] [blame] | 927 | bool IsPositionIndependent = isPositionIndependent(); |
| 928 | unsigned char TF = IsPositionIndependent ? HexagonII::MO_PCREL : 0; |
| Krzysztof Parzyszek | 21dc8bd | 2015-12-18 20:19:30 +0000 | [diff] [blame] | 929 | |
| Ron Lieberman | 822ee88 | 2016-08-13 23:41:11 +0000 | [diff] [blame] | 930 | unsigned Offset = 0; |
| Krzysztof Parzyszek | 21dc8bd | 2015-12-18 20:19:30 +0000 | [diff] [blame] | 931 | SDValue T; |
| 932 | if (CPN->isMachineConstantPoolEntry()) |
| Ron Lieberman | 822ee88 | 2016-08-13 23:41:11 +0000 | [diff] [blame] | 933 | T = DAG.getTargetConstantPool(CPN->getMachineCPVal(), ValTy, Align, Offset, |
| 934 | TF); |
| Krzysztof Parzyszek | 91ff5c6 | 2017-08-01 13:12:53 +0000 | [diff] [blame] | 935 | else if (isVTi1Type) |
| 936 | T = DAG.getTargetConstantPool(CVal, ValTy, Align, Offset, TF); |
| Sirish Pande | 69295b8 | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 937 | else |
| Krzysztof Parzyszek | cfbe6ba | 2018-02-13 15:35:07 +0000 | [diff] [blame] | 938 | T = DAG.getTargetConstantPool(CPN->getConstVal(), ValTy, Align, Offset, TF); |
| Ron Lieberman | 822ee88 | 2016-08-13 23:41:11 +0000 | [diff] [blame] | 939 | |
| 940 | assert(cast<ConstantPoolSDNode>(T)->getTargetFlags() == TF && |
| 941 | "Inconsistent target flag encountered"); |
| 942 | |
| Rafael Espindola | 405e25a | 2016-06-26 22:24:01 +0000 | [diff] [blame] | 943 | if (IsPositionIndependent) |
| Krzysztof Parzyszek | 21dc8bd | 2015-12-18 20:19:30 +0000 | [diff] [blame] | 944 | return DAG.getNode(HexagonISD::AT_PCREL, SDLoc(Op), ValTy, T); |
| 945 | return DAG.getNode(HexagonISD::CP, SDLoc(Op), ValTy, T); |
| 946 | } |
| 947 | |
| 948 | SDValue |
| 949 | HexagonTargetLowering::LowerJumpTable(SDValue Op, SelectionDAG &DAG) const { |
| 950 | EVT VT = Op.getValueType(); |
| 951 | int Idx = cast<JumpTableSDNode>(Op)->getIndex(); |
| Rafael Espindola | 405e25a | 2016-06-26 22:24:01 +0000 | [diff] [blame] | 952 | if (isPositionIndependent()) { |
| Krzysztof Parzyszek | 21dc8bd | 2015-12-18 20:19:30 +0000 | [diff] [blame] | 953 | SDValue T = DAG.getTargetJumpTable(Idx, VT, HexagonII::MO_PCREL); |
| 954 | return DAG.getNode(HexagonISD::AT_PCREL, SDLoc(Op), VT, T); |
| 955 | } |
| 956 | |
| 957 | SDValue T = DAG.getTargetJumpTable(Idx, VT); |
| 958 | return DAG.getNode(HexagonISD::JT, SDLoc(Op), VT, T); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 959 | } |
| 960 | |
| 961 | SDValue |
| 962 | HexagonTargetLowering::LowerRETURNADDR(SDValue Op, SelectionDAG &DAG) const { |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 963 | const HexagonRegisterInfo &HRI = *Subtarget.getRegisterInfo(); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 964 | MachineFunction &MF = DAG.getMachineFunction(); |
| Matthias Braun | 941a705 | 2016-07-28 18:40:00 +0000 | [diff] [blame] | 965 | MachineFrameInfo &MFI = MF.getFrameInfo(); |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 966 | MFI.setReturnAddressIsTaken(true); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 967 | |
| Bill Wendling | 908bf81 | 2014-01-06 00:43:20 +0000 | [diff] [blame] | 968 | if (verifyReturnAddressArgumentIsConstant(Op, DAG)) |
| Bill Wendling | df7dd28 | 2014-01-05 01:47:20 +0000 | [diff] [blame] | 969 | return SDValue(); |
| Bill Wendling | df7dd28 | 2014-01-05 01:47:20 +0000 | [diff] [blame] | 970 | |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 971 | EVT VT = Op.getValueType(); |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 972 | SDLoc dl(Op); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 973 | unsigned Depth = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue(); |
| 974 | if (Depth) { |
| 975 | SDValue FrameAddr = LowerFRAMEADDR(Op, DAG); |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 976 | SDValue Offset = DAG.getConstant(4, dl, MVT::i32); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 977 | return DAG.getLoad(VT, dl, DAG.getEntryNode(), |
| 978 | DAG.getNode(ISD::ADD, dl, VT, FrameAddr, Offset), |
| Justin Lebar | 9c37581 | 2016-07-15 18:27:10 +0000 | [diff] [blame] | 979 | MachinePointerInfo()); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 980 | } |
| 981 | |
| 982 | // Return LR, which contains the return address. Mark it an implicit live-in. |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 983 | unsigned Reg = MF.addLiveIn(HRI.getRARegister(), getRegClassFor(MVT::i32)); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 984 | return DAG.getCopyFromReg(DAG.getEntryNode(), dl, Reg, VT); |
| 985 | } |
| 986 | |
| 987 | SDValue |
| 988 | HexagonTargetLowering::LowerFRAMEADDR(SDValue Op, SelectionDAG &DAG) const { |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 989 | const HexagonRegisterInfo &HRI = *Subtarget.getRegisterInfo(); |
| Matthias Braun | 941a705 | 2016-07-28 18:40:00 +0000 | [diff] [blame] | 990 | MachineFrameInfo &MFI = DAG.getMachineFunction().getFrameInfo(); |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 991 | MFI.setFrameAddressIsTaken(true); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 992 | |
| 993 | EVT VT = Op.getValueType(); |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 994 | SDLoc dl(Op); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 995 | unsigned Depth = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue(); |
| 996 | SDValue FrameAddr = DAG.getCopyFromReg(DAG.getEntryNode(), dl, |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 997 | HRI.getFrameRegister(), VT); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 998 | while (Depth--) |
| 999 | FrameAddr = DAG.getLoad(VT, dl, DAG.getEntryNode(), FrameAddr, |
| Justin Lebar | 9c37581 | 2016-07-15 18:27:10 +0000 | [diff] [blame] | 1000 | MachinePointerInfo()); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1001 | return FrameAddr; |
| 1002 | } |
| 1003 | |
| Krzysztof Parzyszek | 21dc8bd | 2015-12-18 20:19:30 +0000 | [diff] [blame] | 1004 | SDValue |
| 1005 | HexagonTargetLowering::LowerATOMIC_FENCE(SDValue Op, SelectionDAG& DAG) const { |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 1006 | SDLoc dl(Op); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1007 | return DAG.getNode(HexagonISD::BARRIER, dl, MVT::Other, Op.getOperand(0)); |
| 1008 | } |
| 1009 | |
| Krzysztof Parzyszek | 21dc8bd | 2015-12-18 20:19:30 +0000 | [diff] [blame] | 1010 | SDValue |
| 1011 | HexagonTargetLowering::LowerGLOBALADDRESS(SDValue Op, SelectionDAG &DAG) const { |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 1012 | SDLoc dl(Op); |
| Krzysztof Parzyszek | 21dc8bd | 2015-12-18 20:19:30 +0000 | [diff] [blame] | 1013 | auto *GAN = cast<GlobalAddressSDNode>(Op); |
| Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 1014 | auto PtrVT = getPointerTy(DAG.getDataLayout()); |
| Krzysztof Parzyszek | 96a2841 | 2018-01-30 18:10:27 +0000 | [diff] [blame] | 1015 | auto *GV = GAN->getGlobal(); |
| 1016 | int64_t Offset = GAN->getOffset(); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1017 | |
| Krzysztof Parzyszek | 21dc8bd | 2015-12-18 20:19:30 +0000 | [diff] [blame] | 1018 | auto &HLOF = *HTM.getObjFileLowering(); |
| 1019 | Reloc::Model RM = HTM.getRelocationModel(); |
| 1020 | |
| 1021 | if (RM == Reloc::Static) { |
| 1022 | SDValue GA = DAG.getTargetGlobalAddress(GV, dl, PtrVT, Offset); |
| Peter Collingbourne | 6733564 | 2016-10-24 19:23:39 +0000 | [diff] [blame] | 1023 | const GlobalObject *GO = GV->getBaseObject(); |
| 1024 | if (GO && HLOF.isGlobalInSmallSection(GO, HTM)) |
| Krzysztof Parzyszek | 96a2841 | 2018-01-30 18:10:27 +0000 | [diff] [blame] | 1025 | return DAG.getNode(HexagonISD::CONST32_GP, dl, PtrVT, GA); |
| 1026 | return DAG.getNode(HexagonISD::CONST32, dl, PtrVT, GA); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1027 | } |
| 1028 | |
| Krzysztof Parzyszek | 96a2841 | 2018-01-30 18:10:27 +0000 | [diff] [blame] | 1029 | bool UsePCRel = getTargetMachine().shouldAssumeDSOLocal(*GV->getParent(), GV); |
| 1030 | if (UsePCRel) { |
| 1031 | SDValue GA = DAG.getTargetGlobalAddress(GV, dl, PtrVT, Offset, |
| 1032 | HexagonII::MO_PCREL); |
| 1033 | return DAG.getNode(HexagonISD::AT_PCREL, dl, PtrVT, GA); |
| Krzysztof Parzyszek | 21dc8bd | 2015-12-18 20:19:30 +0000 | [diff] [blame] | 1034 | } |
| 1035 | |
| Krzysztof Parzyszek | 96a2841 | 2018-01-30 18:10:27 +0000 | [diff] [blame] | 1036 | // Use GOT index. |
| 1037 | SDValue GOT = DAG.getGLOBAL_OFFSET_TABLE(PtrVT); |
| 1038 | SDValue GA = DAG.getTargetGlobalAddress(GV, dl, PtrVT, 0, HexagonII::MO_GOT); |
| 1039 | SDValue Off = DAG.getConstant(Offset, dl, MVT::i32); |
| 1040 | return DAG.getNode(HexagonISD::AT_GOT, dl, PtrVT, GOT, GA, Off); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1041 | } |
| 1042 | |
| Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 1043 | // Specifies that for loads and stores VT can be promoted to PromotedLdStVT. |
| Jyotsna Verma | 2ba0c0b | 2013-03-07 19:10:28 +0000 | [diff] [blame] | 1044 | SDValue |
| 1045 | HexagonTargetLowering::LowerBlockAddress(SDValue Op, SelectionDAG &DAG) const { |
| 1046 | const BlockAddress *BA = cast<BlockAddressSDNode>(Op)->getBlockAddress(); |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 1047 | SDLoc dl(Op); |
| Krzysztof Parzyszek | 21dc8bd | 2015-12-18 20:19:30 +0000 | [diff] [blame] | 1048 | EVT PtrVT = getPointerTy(DAG.getDataLayout()); |
| 1049 | |
| 1050 | Reloc::Model RM = HTM.getRelocationModel(); |
| 1051 | if (RM == Reloc::Static) { |
| Krzysztof Parzyszek | 7a737d1 | 2016-02-18 15:42:57 +0000 | [diff] [blame] | 1052 | SDValue A = DAG.getTargetBlockAddress(BA, PtrVT); |
| Krzysztof Parzyszek | 21dc8bd | 2015-12-18 20:19:30 +0000 | [diff] [blame] | 1053 | return DAG.getNode(HexagonISD::CONST32_GP, dl, PtrVT, A); |
| 1054 | } |
| 1055 | |
| 1056 | SDValue A = DAG.getTargetBlockAddress(BA, PtrVT, 0, HexagonII::MO_PCREL); |
| 1057 | return DAG.getNode(HexagonISD::AT_PCREL, dl, PtrVT, A); |
| 1058 | } |
| 1059 | |
| 1060 | SDValue |
| 1061 | HexagonTargetLowering::LowerGLOBAL_OFFSET_TABLE(SDValue Op, SelectionDAG &DAG) |
| 1062 | const { |
| 1063 | EVT PtrVT = getPointerTy(DAG.getDataLayout()); |
| 1064 | SDValue GOTSym = DAG.getTargetExternalSymbol(HEXAGON_GOT_SYM_NAME, PtrVT, |
| 1065 | HexagonII::MO_PCREL); |
| 1066 | return DAG.getNode(HexagonISD::AT_PCREL, SDLoc(Op), PtrVT, GOTSym); |
| Jyotsna Verma | 2ba0c0b | 2013-03-07 19:10:28 +0000 | [diff] [blame] | 1067 | } |
| 1068 | |
| Krzysztof Parzyszek | 7a737d1 | 2016-02-18 15:42:57 +0000 | [diff] [blame] | 1069 | SDValue |
| 1070 | HexagonTargetLowering::GetDynamicTLSAddr(SelectionDAG &DAG, SDValue Chain, |
| Krzysztof Parzyszek | 1aaf41a | 2017-02-17 22:14:51 +0000 | [diff] [blame] | 1071 | GlobalAddressSDNode *GA, SDValue Glue, EVT PtrVT, unsigned ReturnReg, |
| Krzysztof Parzyszek | 7a737d1 | 2016-02-18 15:42:57 +0000 | [diff] [blame] | 1072 | unsigned char OperandFlags) const { |
| Krzysztof Parzyszek | 1aaf41a | 2017-02-17 22:14:51 +0000 | [diff] [blame] | 1073 | MachineFunction &MF = DAG.getMachineFunction(); |
| 1074 | MachineFrameInfo &MFI = MF.getFrameInfo(); |
| Krzysztof Parzyszek | 7a737d1 | 2016-02-18 15:42:57 +0000 | [diff] [blame] | 1075 | SDVTList NodeTys = DAG.getVTList(MVT::Other, MVT::Glue); |
| 1076 | SDLoc dl(GA); |
| 1077 | SDValue TGA = DAG.getTargetGlobalAddress(GA->getGlobal(), dl, |
| 1078 | GA->getValueType(0), |
| 1079 | GA->getOffset(), |
| 1080 | OperandFlags); |
| 1081 | // Create Operands for the call.The Operands should have the following: |
| 1082 | // 1. Chain SDValue |
| 1083 | // 2. Callee which in this case is the Global address value. |
| 1084 | // 3. Registers live into the call.In this case its R0, as we |
| 1085 | // have just one argument to be passed. |
| Krzysztof Parzyszek | 1aaf41a | 2017-02-17 22:14:51 +0000 | [diff] [blame] | 1086 | // 4. Glue. |
| Krzysztof Parzyszek | 7a737d1 | 2016-02-18 15:42:57 +0000 | [diff] [blame] | 1087 | // Note: The order is important. |
| 1088 | |
| Krzysztof Parzyszek | 1aaf41a | 2017-02-17 22:14:51 +0000 | [diff] [blame] | 1089 | const auto &HRI = *Subtarget.getRegisterInfo(); |
| 1090 | const uint32_t *Mask = HRI.getCallPreservedMask(MF, CallingConv::C); |
| 1091 | assert(Mask && "Missing call preserved mask for calling convention"); |
| 1092 | SDValue Ops[] = { Chain, TGA, DAG.getRegister(Hexagon::R0, PtrVT), |
| 1093 | DAG.getRegisterMask(Mask), Glue }; |
| 1094 | Chain = DAG.getNode(HexagonISD::CALL, dl, NodeTys, Ops); |
| Krzysztof Parzyszek | 7a737d1 | 2016-02-18 15:42:57 +0000 | [diff] [blame] | 1095 | |
| 1096 | // Inform MFI that function has calls. |
| Matthias Braun | 941a705 | 2016-07-28 18:40:00 +0000 | [diff] [blame] | 1097 | MFI.setAdjustsStack(true); |
| Krzysztof Parzyszek | 7a737d1 | 2016-02-18 15:42:57 +0000 | [diff] [blame] | 1098 | |
| Krzysztof Parzyszek | 1aaf41a | 2017-02-17 22:14:51 +0000 | [diff] [blame] | 1099 | Glue = Chain.getValue(1); |
| 1100 | return DAG.getCopyFromReg(Chain, dl, ReturnReg, PtrVT, Glue); |
| Krzysztof Parzyszek | 7a737d1 | 2016-02-18 15:42:57 +0000 | [diff] [blame] | 1101 | } |
| 1102 | |
| 1103 | // |
| 1104 | // Lower using the intial executable model for TLS addresses |
| 1105 | // |
| 1106 | SDValue |
| 1107 | HexagonTargetLowering::LowerToTLSInitialExecModel(GlobalAddressSDNode *GA, |
| 1108 | SelectionDAG &DAG) const { |
| 1109 | SDLoc dl(GA); |
| 1110 | int64_t Offset = GA->getOffset(); |
| 1111 | auto PtrVT = getPointerTy(DAG.getDataLayout()); |
| 1112 | |
| 1113 | // Get the thread pointer. |
| 1114 | SDValue TP = DAG.getCopyFromReg(DAG.getEntryNode(), dl, Hexagon::UGP, PtrVT); |
| 1115 | |
| Rafael Espindola | 405e25a | 2016-06-26 22:24:01 +0000 | [diff] [blame] | 1116 | bool IsPositionIndependent = isPositionIndependent(); |
| 1117 | unsigned char TF = |
| 1118 | IsPositionIndependent ? HexagonII::MO_IEGOT : HexagonII::MO_IE; |
| Krzysztof Parzyszek | 7a737d1 | 2016-02-18 15:42:57 +0000 | [diff] [blame] | 1119 | |
| 1120 | // First generate the TLS symbol address |
| 1121 | SDValue TGA = DAG.getTargetGlobalAddress(GA->getGlobal(), dl, PtrVT, |
| 1122 | Offset, TF); |
| 1123 | |
| 1124 | SDValue Sym = DAG.getNode(HexagonISD::CONST32, dl, PtrVT, TGA); |
| 1125 | |
| Rafael Espindola | 405e25a | 2016-06-26 22:24:01 +0000 | [diff] [blame] | 1126 | if (IsPositionIndependent) { |
| Krzysztof Parzyszek | 7a737d1 | 2016-02-18 15:42:57 +0000 | [diff] [blame] | 1127 | // Generate the GOT pointer in case of position independent code |
| 1128 | SDValue GOT = LowerGLOBAL_OFFSET_TABLE(Sym, DAG); |
| 1129 | |
| 1130 | // Add the TLS Symbol address to GOT pointer.This gives |
| 1131 | // GOT relative relocation for the symbol. |
| 1132 | Sym = DAG.getNode(ISD::ADD, dl, PtrVT, GOT, Sym); |
| 1133 | } |
| 1134 | |
| 1135 | // Load the offset value for TLS symbol.This offset is relative to |
| 1136 | // thread pointer. |
| Justin Lebar | 9c37581 | 2016-07-15 18:27:10 +0000 | [diff] [blame] | 1137 | SDValue LoadOffset = |
| 1138 | DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), Sym, MachinePointerInfo()); |
| Krzysztof Parzyszek | 7a737d1 | 2016-02-18 15:42:57 +0000 | [diff] [blame] | 1139 | |
| 1140 | // Address of the thread local variable is the add of thread |
| 1141 | // pointer and the offset of the variable. |
| 1142 | return DAG.getNode(ISD::ADD, dl, PtrVT, TP, LoadOffset); |
| 1143 | } |
| 1144 | |
| 1145 | // |
| 1146 | // Lower using the local executable model for TLS addresses |
| 1147 | // |
| 1148 | SDValue |
| 1149 | HexagonTargetLowering::LowerToTLSLocalExecModel(GlobalAddressSDNode *GA, |
| 1150 | SelectionDAG &DAG) const { |
| 1151 | SDLoc dl(GA); |
| 1152 | int64_t Offset = GA->getOffset(); |
| 1153 | auto PtrVT = getPointerTy(DAG.getDataLayout()); |
| 1154 | |
| 1155 | // Get the thread pointer. |
| 1156 | SDValue TP = DAG.getCopyFromReg(DAG.getEntryNode(), dl, Hexagon::UGP, PtrVT); |
| 1157 | // Generate the TLS symbol address |
| 1158 | SDValue TGA = DAG.getTargetGlobalAddress(GA->getGlobal(), dl, PtrVT, Offset, |
| 1159 | HexagonII::MO_TPREL); |
| 1160 | SDValue Sym = DAG.getNode(HexagonISD::CONST32, dl, PtrVT, TGA); |
| 1161 | |
| 1162 | // Address of the thread local variable is the add of thread |
| 1163 | // pointer and the offset of the variable. |
| 1164 | return DAG.getNode(ISD::ADD, dl, PtrVT, TP, Sym); |
| 1165 | } |
| 1166 | |
| 1167 | // |
| 1168 | // Lower using the general dynamic model for TLS addresses |
| 1169 | // |
| 1170 | SDValue |
| 1171 | HexagonTargetLowering::LowerToTLSGeneralDynamicModel(GlobalAddressSDNode *GA, |
| 1172 | SelectionDAG &DAG) const { |
| 1173 | SDLoc dl(GA); |
| 1174 | int64_t Offset = GA->getOffset(); |
| 1175 | auto PtrVT = getPointerTy(DAG.getDataLayout()); |
| 1176 | |
| 1177 | // First generate the TLS symbol address |
| 1178 | SDValue TGA = DAG.getTargetGlobalAddress(GA->getGlobal(), dl, PtrVT, Offset, |
| 1179 | HexagonII::MO_GDGOT); |
| 1180 | |
| 1181 | // Then, generate the GOT pointer |
| 1182 | SDValue GOT = LowerGLOBAL_OFFSET_TABLE(TGA, DAG); |
| 1183 | |
| 1184 | // Add the TLS symbol and the GOT pointer |
| 1185 | SDValue Sym = DAG.getNode(HexagonISD::CONST32, dl, PtrVT, TGA); |
| 1186 | SDValue Chain = DAG.getNode(ISD::ADD, dl, PtrVT, GOT, Sym); |
| 1187 | |
| 1188 | // Copy over the argument to R0 |
| 1189 | SDValue InFlag; |
| 1190 | Chain = DAG.getCopyToReg(DAG.getEntryNode(), dl, Hexagon::R0, Chain, InFlag); |
| 1191 | InFlag = Chain.getValue(1); |
| 1192 | |
| Krzysztof Parzyszek | a750383 | 2017-05-02 18:15:33 +0000 | [diff] [blame] | 1193 | unsigned Flags = |
| 1194 | static_cast<const HexagonSubtarget &>(DAG.getSubtarget()).useLongCalls() |
| 1195 | ? HexagonII::MO_GDPLT | HexagonII::HMOTF_ConstExtended |
| 1196 | : HexagonII::MO_GDPLT; |
| 1197 | |
| Krzysztof Parzyszek | 1aaf41a | 2017-02-17 22:14:51 +0000 | [diff] [blame] | 1198 | return GetDynamicTLSAddr(DAG, Chain, GA, InFlag, PtrVT, |
| Krzysztof Parzyszek | a750383 | 2017-05-02 18:15:33 +0000 | [diff] [blame] | 1199 | Hexagon::R0, Flags); |
| Krzysztof Parzyszek | 7a737d1 | 2016-02-18 15:42:57 +0000 | [diff] [blame] | 1200 | } |
| 1201 | |
| 1202 | // |
| 1203 | // Lower TLS addresses. |
| 1204 | // |
| 1205 | // For now for dynamic models, we only support the general dynamic model. |
| 1206 | // |
| 1207 | SDValue |
| 1208 | HexagonTargetLowering::LowerGlobalTLSAddress(SDValue Op, |
| 1209 | SelectionDAG &DAG) const { |
| 1210 | GlobalAddressSDNode *GA = cast<GlobalAddressSDNode>(Op); |
| 1211 | |
| 1212 | switch (HTM.getTLSModel(GA->getGlobal())) { |
| 1213 | case TLSModel::GeneralDynamic: |
| 1214 | case TLSModel::LocalDynamic: |
| 1215 | return LowerToTLSGeneralDynamicModel(GA, DAG); |
| 1216 | case TLSModel::InitialExec: |
| 1217 | return LowerToTLSInitialExecModel(GA, DAG); |
| 1218 | case TLSModel::LocalExec: |
| 1219 | return LowerToTLSLocalExecModel(GA, DAG); |
| 1220 | } |
| 1221 | llvm_unreachable("Bogus TLS model"); |
| 1222 | } |
| 1223 | |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1224 | //===----------------------------------------------------------------------===// |
| 1225 | // TargetLowering Implementation |
| 1226 | //===----------------------------------------------------------------------===// |
| 1227 | |
| Eric Christopher | d737b76 | 2015-02-02 22:11:36 +0000 | [diff] [blame] | 1228 | HexagonTargetLowering::HexagonTargetLowering(const TargetMachine &TM, |
| Krzysztof Parzyszek | 08ff888 | 2015-11-26 18:38:27 +0000 | [diff] [blame] | 1229 | const HexagonSubtarget &ST) |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1230 | : TargetLowering(TM), HTM(static_cast<const HexagonTargetMachine&>(TM)), |
| Krzysztof Parzyszek | 08ff888 | 2015-11-26 18:38:27 +0000 | [diff] [blame] | 1231 | Subtarget(ST) { |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1232 | bool IsV4 = !Subtarget.hasV5TOps(); |
| 1233 | auto &HRI = *Subtarget.getRegisterInfo(); |
| Sirish Pande | 69295b8 | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 1234 | |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1235 | setPrefLoopAlignment(4); |
| 1236 | setPrefFunctionAlignment(4); |
| 1237 | setMinFunctionAlignment(2); |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1238 | setStackPointerRegisterToSaveRestore(HRI.getStackRegister()); |
| Krzysztof Parzyszek | b3e50ac | 2018-01-05 20:41:50 +0000 | [diff] [blame] | 1239 | setBooleanContents(TargetLoweringBase::UndefinedBooleanContent); |
| 1240 | setBooleanVectorContents(TargetLoweringBase::UndefinedBooleanContent); |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1241 | |
| Krzysztof Parzyszek | f228c95 | 2016-06-22 16:07:10 +0000 | [diff] [blame] | 1242 | setMaxAtomicSizeInBitsSupported(64); |
| 1243 | setMinCmpXchgSizeInBits(32); |
| 1244 | |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1245 | if (EnableHexSDNodeSched) |
| 1246 | setSchedulingPreference(Sched::VLIW); |
| 1247 | else |
| 1248 | setSchedulingPreference(Sched::Source); |
| 1249 | |
| 1250 | // Limits for inline expansion of memcpy/memmove |
| 1251 | MaxStoresPerMemcpy = MaxStoresPerMemcpyCL; |
| 1252 | MaxStoresPerMemcpyOptSize = MaxStoresPerMemcpyOptSizeCL; |
| 1253 | MaxStoresPerMemmove = MaxStoresPerMemmoveCL; |
| 1254 | MaxStoresPerMemmoveOptSize = MaxStoresPerMemmoveOptSizeCL; |
| 1255 | MaxStoresPerMemset = MaxStoresPerMemsetCL; |
| 1256 | MaxStoresPerMemsetOptSize = MaxStoresPerMemsetOptSizeCL; |
| 1257 | |
| 1258 | // |
| 1259 | // Set up register classes. |
| 1260 | // |
| 1261 | |
| 1262 | addRegisterClass(MVT::i1, &Hexagon::PredRegsRegClass); |
| 1263 | addRegisterClass(MVT::v2i1, &Hexagon::PredRegsRegClass); // bbbbaaaa |
| 1264 | addRegisterClass(MVT::v4i1, &Hexagon::PredRegsRegClass); // ddccbbaa |
| 1265 | addRegisterClass(MVT::v8i1, &Hexagon::PredRegsRegClass); // hgfedcba |
| 1266 | addRegisterClass(MVT::i32, &Hexagon::IntRegsRegClass); |
| Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 1267 | addRegisterClass(MVT::v2i16, &Hexagon::IntRegsRegClass); |
| Krzysztof Parzyszek | e4ce92c | 2017-12-20 20:49:43 +0000 | [diff] [blame] | 1268 | addRegisterClass(MVT::v4i8, &Hexagon::IntRegsRegClass); |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1269 | addRegisterClass(MVT::i64, &Hexagon::DoubleRegsRegClass); |
| 1270 | addRegisterClass(MVT::v8i8, &Hexagon::DoubleRegsRegClass); |
| 1271 | addRegisterClass(MVT::v4i16, &Hexagon::DoubleRegsRegClass); |
| 1272 | addRegisterClass(MVT::v2i32, &Hexagon::DoubleRegsRegClass); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1273 | |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1274 | if (Subtarget.hasV5TOps()) { |
| Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1275 | addRegisterClass(MVT::f32, &Hexagon::IntRegsRegClass); |
| 1276 | addRegisterClass(MVT::f64, &Hexagon::DoubleRegsRegClass); |
| 1277 | } |
| Sirish Pande | 69295b8 | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 1278 | |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1279 | // |
| 1280 | // Handling of scalar operations. |
| 1281 | // |
| 1282 | // All operations default to "legal", except: |
| 1283 | // - indexed loads and stores (pre-/post-incremented), |
| 1284 | // - ANY_EXTEND_VECTOR_INREG, ATOMIC_CMP_SWAP_WITH_SUCCESS, CONCAT_VECTORS, |
| 1285 | // ConstantFP, DEBUGTRAP, FCEIL, FCOPYSIGN, FEXP, FEXP2, FFLOOR, FGETSIGN, |
| 1286 | // FLOG, FLOG2, FLOG10, FMAXNUM, FMINNUM, FNEARBYINT, FRINT, FROUND, TRAP, |
| 1287 | // FTRUNC, PREFETCH, SIGN_EXTEND_VECTOR_INREG, ZERO_EXTEND_VECTOR_INREG, |
| 1288 | // which default to "expand" for at least one type. |
| Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 1289 | |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1290 | // Misc operations. |
| 1291 | setOperationAction(ISD::ConstantFP, MVT::f32, Legal); // Default: expand |
| 1292 | setOperationAction(ISD::ConstantFP, MVT::f64, Legal); // Default: expand |
| Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 1293 | |
| 1294 | setOperationAction(ISD::ConstantPool, MVT::i32, Custom); |
| Krzysztof Parzyszek | 21dc8bd | 2015-12-18 20:19:30 +0000 | [diff] [blame] | 1295 | setOperationAction(ISD::JumpTable, MVT::i32, Custom); |
| Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1296 | setOperationAction(ISD::BUILD_PAIR, MVT::i64, Expand); |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1297 | setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i1, Expand); |
| 1298 | setOperationAction(ISD::INLINEASM, MVT::Other, Custom); |
| Krzysztof Parzyszek | 6895b2c | 2016-02-18 13:58:38 +0000 | [diff] [blame] | 1299 | setOperationAction(ISD::PREFETCH, MVT::Other, Custom); |
| Krzysztof Parzyszek | ab57c2b | 2017-02-22 22:28:47 +0000 | [diff] [blame] | 1300 | setOperationAction(ISD::READCYCLECOUNTER, MVT::i64, Custom); |
| Krzysztof Parzyszek | 6895b2c | 2016-02-18 13:58:38 +0000 | [diff] [blame] | 1301 | setOperationAction(ISD::INTRINSIC_VOID, MVT::Other, Custom); |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1302 | setOperationAction(ISD::EH_RETURN, MVT::Other, Custom); |
| Krzysztof Parzyszek | 21dc8bd | 2015-12-18 20:19:30 +0000 | [diff] [blame] | 1303 | setOperationAction(ISD::GLOBAL_OFFSET_TABLE, MVT::i32, Custom); |
| Krzysztof Parzyszek | 7a737d1 | 2016-02-18 15:42:57 +0000 | [diff] [blame] | 1304 | setOperationAction(ISD::GlobalTLSAddress, MVT::i32, Custom); |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1305 | setOperationAction(ISD::ATOMIC_FENCE, MVT::Other, Custom); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1306 | |
| Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1307 | // Custom legalize GlobalAddress nodes into CONST32. |
| 1308 | setOperationAction(ISD::GlobalAddress, MVT::i32, Custom); |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1309 | setOperationAction(ISD::GlobalAddress, MVT::i8, Custom); |
| 1310 | setOperationAction(ISD::BlockAddress, MVT::i32, Custom); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1311 | |
| Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 1312 | // Hexagon needs to optimize cases with negative constants. |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1313 | setOperationAction(ISD::SETCC, MVT::i8, Custom); |
| Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 1314 | setOperationAction(ISD::SETCC, MVT::i16, Custom); |
| Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 1315 | |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1316 | // VASTART needs to be custom lowered to use the VarArgsFrameIndex. |
| 1317 | setOperationAction(ISD::VASTART, MVT::Other, Custom); |
| 1318 | setOperationAction(ISD::VAEND, MVT::Other, Expand); |
| 1319 | setOperationAction(ISD::VAARG, MVT::Other, Expand); |
| 1320 | |
| 1321 | setOperationAction(ISD::STACKSAVE, MVT::Other, Expand); |
| 1322 | setOperationAction(ISD::STACKRESTORE, MVT::Other, Expand); |
| 1323 | setOperationAction(ISD::DYNAMIC_STACKALLOC, MVT::i32, Custom); |
| 1324 | |
| 1325 | if (EmitJumpTables) |
| Krzysztof Parzyszek | 21dc8bd | 2015-12-18 20:19:30 +0000 | [diff] [blame] | 1326 | setMinimumJumpTableEntries(MinimumJumpTables); |
| Krzysztof Parzyszek | a61f7da | 2016-01-13 21:43:13 +0000 | [diff] [blame] | 1327 | else |
| Eugene Zelenko | 58655bb | 2016-12-17 01:09:05 +0000 | [diff] [blame] | 1328 | setMinimumJumpTableEntries(std::numeric_limits<int>::max()); |
| Krzysztof Parzyszek | 21dc8bd | 2015-12-18 20:19:30 +0000 | [diff] [blame] | 1329 | setOperationAction(ISD::BR_JT, MVT::Other, Expand); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1330 | |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1331 | // Hexagon has instructions for add/sub with carry. The problem with |
| 1332 | // modeling these instructions is that they produce 2 results: Rdd and Px. |
| 1333 | // To model the update of Px, we will have to use Defs[p0..p3] which will |
| 1334 | // cause any predicate live range to spill. So, we pretend we dont't have |
| 1335 | // these instructions. |
| 1336 | setOperationAction(ISD::ADDE, MVT::i8, Expand); |
| Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1337 | setOperationAction(ISD::ADDE, MVT::i16, Expand); |
| 1338 | setOperationAction(ISD::ADDE, MVT::i32, Expand); |
| 1339 | setOperationAction(ISD::ADDE, MVT::i64, Expand); |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1340 | setOperationAction(ISD::SUBE, MVT::i8, Expand); |
| Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1341 | setOperationAction(ISD::SUBE, MVT::i16, Expand); |
| 1342 | setOperationAction(ISD::SUBE, MVT::i32, Expand); |
| 1343 | setOperationAction(ISD::SUBE, MVT::i64, Expand); |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1344 | setOperationAction(ISD::ADDC, MVT::i8, Expand); |
| Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1345 | setOperationAction(ISD::ADDC, MVT::i16, Expand); |
| 1346 | setOperationAction(ISD::ADDC, MVT::i32, Expand); |
| 1347 | setOperationAction(ISD::ADDC, MVT::i64, Expand); |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1348 | setOperationAction(ISD::SUBC, MVT::i8, Expand); |
| Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1349 | setOperationAction(ISD::SUBC, MVT::i16, Expand); |
| 1350 | setOperationAction(ISD::SUBC, MVT::i32, Expand); |
| 1351 | setOperationAction(ISD::SUBC, MVT::i64, Expand); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1352 | |
| Krzysztof Parzyszek | 2c4487d | 2015-04-13 20:37:01 +0000 | [diff] [blame] | 1353 | // Only add and sub that detect overflow are the saturating ones. |
| 1354 | for (MVT VT : MVT::integer_valuetypes()) { |
| 1355 | setOperationAction(ISD::UADDO, VT, Expand); |
| 1356 | setOperationAction(ISD::SADDO, VT, Expand); |
| 1357 | setOperationAction(ISD::USUBO, VT, Expand); |
| 1358 | setOperationAction(ISD::SSUBO, VT, Expand); |
| 1359 | } |
| 1360 | |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1361 | setOperationAction(ISD::CTLZ, MVT::i8, Promote); |
| 1362 | setOperationAction(ISD::CTLZ, MVT::i16, Promote); |
| 1363 | setOperationAction(ISD::CTTZ, MVT::i8, Promote); |
| 1364 | setOperationAction(ISD::CTTZ, MVT::i16, Promote); |
| Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 1365 | |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1366 | // In V5, popcount can count # of 1s in i64 but returns i32. |
| 1367 | // On V4 it will be expanded (set later). |
| 1368 | setOperationAction(ISD::CTPOP, MVT::i8, Promote); |
| 1369 | setOperationAction(ISD::CTPOP, MVT::i16, Promote); |
| 1370 | setOperationAction(ISD::CTPOP, MVT::i32, Promote); |
| Krzysztof Parzyszek | af5ff65 | 2017-02-23 15:02:09 +0000 | [diff] [blame] | 1371 | setOperationAction(ISD::CTPOP, MVT::i64, Legal); |
| 1372 | |
| 1373 | setOperationAction(ISD::BITREVERSE, MVT::i32, Legal); |
| 1374 | setOperationAction(ISD::BITREVERSE, MVT::i64, Legal); |
| 1375 | setOperationAction(ISD::BSWAP, MVT::i32, Legal); |
| 1376 | setOperationAction(ISD::BSWAP, MVT::i64, Legal); |
| Krzysztof Parzyszek | ef58017 | 2017-05-30 17:47:51 +0000 | [diff] [blame] | 1377 | setOperationAction(ISD::MUL, MVT::i64, Legal); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1378 | |
| Benjamin Kramer | 6246069 | 2015-04-25 14:46:53 +0000 | [diff] [blame] | 1379 | for (unsigned IntExpOp : |
| Krzysztof Parzyszek | 08ff888 | 2015-11-26 18:38:27 +0000 | [diff] [blame] | 1380 | { ISD::SDIV, ISD::UDIV, ISD::SREM, ISD::UREM, |
| 1381 | ISD::SDIVREM, ISD::UDIVREM, ISD::ROTL, ISD::ROTR, |
| Krzysztof Parzyszek | af5ff65 | 2017-02-23 15:02:09 +0000 | [diff] [blame] | 1382 | ISD::SHL_PARTS, ISD::SRA_PARTS, ISD::SRL_PARTS, |
| Krzysztof Parzyszek | 08ff888 | 2015-11-26 18:38:27 +0000 | [diff] [blame] | 1383 | ISD::SMUL_LOHI, ISD::UMUL_LOHI }) { |
| Benjamin Kramer | 6246069 | 2015-04-25 14:46:53 +0000 | [diff] [blame] | 1384 | setOperationAction(IntExpOp, MVT::i32, Expand); |
| 1385 | setOperationAction(IntExpOp, MVT::i64, Expand); |
| 1386 | } |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1387 | |
| Benjamin Kramer | 6246069 | 2015-04-25 14:46:53 +0000 | [diff] [blame] | 1388 | for (unsigned FPExpOp : |
| 1389 | {ISD::FDIV, ISD::FREM, ISD::FSQRT, ISD::FSIN, ISD::FCOS, ISD::FSINCOS, |
| 1390 | ISD::FPOW, ISD::FCOPYSIGN}) { |
| 1391 | setOperationAction(FPExpOp, MVT::f32, Expand); |
| 1392 | setOperationAction(FPExpOp, MVT::f64, Expand); |
| 1393 | } |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1394 | |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1395 | // No extending loads from i32. |
| 1396 | for (MVT VT : MVT::integer_valuetypes()) { |
| 1397 | setLoadExtAction(ISD::ZEXTLOAD, VT, MVT::i32, Expand); |
| 1398 | setLoadExtAction(ISD::SEXTLOAD, VT, MVT::i32, Expand); |
| 1399 | setLoadExtAction(ISD::EXTLOAD, VT, MVT::i32, Expand); |
| 1400 | } |
| 1401 | // Turn FP truncstore into trunc + store. |
| 1402 | setTruncStoreAction(MVT::f64, MVT::f32, Expand); |
| Michael Kuperstein | 2bc3d4d | 2016-08-18 20:08:15 +0000 | [diff] [blame] | 1403 | // Turn FP extload into load/fpextend. |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1404 | for (MVT VT : MVT::fp_valuetypes()) |
| 1405 | setLoadExtAction(ISD::EXTLOAD, VT, MVT::f32, Expand); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1406 | |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1407 | // Expand BR_CC and SELECT_CC for all integer and fp types. |
| 1408 | for (MVT VT : MVT::integer_valuetypes()) { |
| 1409 | setOperationAction(ISD::BR_CC, VT, Expand); |
| 1410 | setOperationAction(ISD::SELECT_CC, VT, Expand); |
| 1411 | } |
| 1412 | for (MVT VT : MVT::fp_valuetypes()) { |
| 1413 | setOperationAction(ISD::BR_CC, VT, Expand); |
| 1414 | setOperationAction(ISD::SELECT_CC, VT, Expand); |
| 1415 | } |
| 1416 | setOperationAction(ISD::BR_CC, MVT::Other, Expand); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1417 | |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1418 | // |
| 1419 | // Handling of vector operations. |
| 1420 | // |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1421 | |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1422 | promoteLdStType(MVT::v4i8, MVT::i32); |
| 1423 | promoteLdStType(MVT::v2i16, MVT::i32); |
| 1424 | promoteLdStType(MVT::v8i8, MVT::i64); |
| Krzysztof Parzyszek | 5eef92e | 2017-07-17 15:45:45 +0000 | [diff] [blame] | 1425 | promoteLdStType(MVT::v4i16, MVT::i64); |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1426 | promoteLdStType(MVT::v2i32, MVT::i64); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1427 | |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1428 | // Set the action for vector operations to "expand", then override it with |
| 1429 | // either "custom" or "legal" for specific cases. |
| Craig Topper | 2626094 | 2015-10-18 05:15:34 +0000 | [diff] [blame] | 1430 | static const unsigned VectExpOps[] = { |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1431 | // Integer arithmetic: |
| 1432 | ISD::ADD, ISD::SUB, ISD::MUL, ISD::SDIV, ISD::UDIV, |
| 1433 | ISD::SREM, ISD::UREM, ISD::SDIVREM, ISD::UDIVREM, ISD::ADDC, |
| 1434 | ISD::SUBC, ISD::SADDO, ISD::UADDO, ISD::SSUBO, ISD::USUBO, |
| 1435 | ISD::SMUL_LOHI, ISD::UMUL_LOHI, |
| 1436 | // Logical/bit: |
| 1437 | ISD::AND, ISD::OR, ISD::XOR, ISD::ROTL, ISD::ROTR, |
| Craig Topper | 33772c5 | 2016-04-28 03:34:31 +0000 | [diff] [blame] | 1438 | ISD::CTPOP, ISD::CTLZ, ISD::CTTZ, |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1439 | // Floating point arithmetic/math functions: |
| 1440 | ISD::FADD, ISD::FSUB, ISD::FMUL, ISD::FMA, ISD::FDIV, |
| 1441 | ISD::FREM, ISD::FNEG, ISD::FABS, ISD::FSQRT, ISD::FSIN, |
| Craig Topper | f6d4dc5 | 2017-05-30 15:27:55 +0000 | [diff] [blame] | 1442 | ISD::FCOS, ISD::FPOW, ISD::FLOG, ISD::FLOG2, |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1443 | ISD::FLOG10, ISD::FEXP, ISD::FEXP2, ISD::FCEIL, ISD::FTRUNC, |
| 1444 | ISD::FRINT, ISD::FNEARBYINT, ISD::FROUND, ISD::FFLOOR, |
| 1445 | ISD::FMINNUM, ISD::FMAXNUM, ISD::FSINCOS, |
| 1446 | // Misc: |
| Krzysztof Parzyszek | 046da74 | 2016-10-27 14:30:16 +0000 | [diff] [blame] | 1447 | ISD::BR_CC, ISD::SELECT_CC, ISD::ConstantPool, |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1448 | // Vector: |
| 1449 | ISD::BUILD_VECTOR, ISD::SCALAR_TO_VECTOR, |
| 1450 | ISD::EXTRACT_VECTOR_ELT, ISD::INSERT_VECTOR_ELT, |
| 1451 | ISD::EXTRACT_SUBVECTOR, ISD::INSERT_SUBVECTOR, |
| 1452 | ISD::CONCAT_VECTORS, ISD::VECTOR_SHUFFLE |
| 1453 | }; |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1454 | |
| 1455 | for (MVT VT : MVT::vector_valuetypes()) { |
| Benjamin Kramer | 6246069 | 2015-04-25 14:46:53 +0000 | [diff] [blame] | 1456 | for (unsigned VectExpOp : VectExpOps) |
| 1457 | setOperationAction(VectExpOp, VT, Expand); |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1458 | |
| Krzysztof Parzyszek | a696b1b | 2016-09-08 17:42:14 +0000 | [diff] [blame] | 1459 | // Expand all extending loads and truncating stores: |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1460 | for (MVT TargetVT : MVT::vector_valuetypes()) { |
| Krzysztof Parzyszek | a696b1b | 2016-09-08 17:42:14 +0000 | [diff] [blame] | 1461 | if (TargetVT == VT) |
| 1462 | continue; |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1463 | setLoadExtAction(ISD::EXTLOAD, TargetVT, VT, Expand); |
| Krzysztof Parzyszek | a696b1b | 2016-09-08 17:42:14 +0000 | [diff] [blame] | 1464 | setLoadExtAction(ISD::ZEXTLOAD, TargetVT, VT, Expand); |
| 1465 | setLoadExtAction(ISD::SEXTLOAD, TargetVT, VT, Expand); |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1466 | setTruncStoreAction(VT, TargetVT, Expand); |
| 1467 | } |
| 1468 | |
| Krzysztof Parzyszek | 046da74 | 2016-10-27 14:30:16 +0000 | [diff] [blame] | 1469 | // Normalize all inputs to SELECT to be vectors of i32. |
| 1470 | if (VT.getVectorElementType() != MVT::i32) { |
| 1471 | MVT VT32 = MVT::getVectorVT(MVT::i32, VT.getSizeInBits()/32); |
| 1472 | setOperationAction(ISD::SELECT, VT, Promote); |
| 1473 | AddPromotedToType(ISD::SELECT, VT, VT32); |
| 1474 | } |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1475 | setOperationAction(ISD::SRA, VT, Custom); |
| 1476 | setOperationAction(ISD::SHL, VT, Custom); |
| 1477 | setOperationAction(ISD::SRL, VT, Custom); |
| 1478 | } |
| 1479 | |
| Krzysztof Parzyszek | 64e5d7d | 2017-10-20 19:33:12 +0000 | [diff] [blame] | 1480 | // Extending loads from (native) vectors of i8 into (native) vectors of i16 |
| 1481 | // are legal. |
| Krzysztof Parzyszek | 3780a0e | 2018-01-23 17:53:59 +0000 | [diff] [blame] | 1482 | setLoadExtAction(ISD::EXTLOAD, MVT::v2i16, MVT::v2i8, Legal); |
| Krzysztof Parzyszek | 64e5d7d | 2017-10-20 19:33:12 +0000 | [diff] [blame] | 1483 | setLoadExtAction(ISD::ZEXTLOAD, MVT::v2i16, MVT::v2i8, Legal); |
| 1484 | setLoadExtAction(ISD::SEXTLOAD, MVT::v2i16, MVT::v2i8, Legal); |
| Krzysztof Parzyszek | 3780a0e | 2018-01-23 17:53:59 +0000 | [diff] [blame] | 1485 | setLoadExtAction(ISD::EXTLOAD, MVT::v4i16, MVT::v4i8, Legal); |
| Krzysztof Parzyszek | 64e5d7d | 2017-10-20 19:33:12 +0000 | [diff] [blame] | 1486 | setLoadExtAction(ISD::ZEXTLOAD, MVT::v4i16, MVT::v4i8, Legal); |
| 1487 | setLoadExtAction(ISD::SEXTLOAD, MVT::v4i16, MVT::v4i8, Legal); |
| 1488 | |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1489 | // Types natively supported: |
| Krzysztof Parzyszek | 3780a0e | 2018-01-23 17:53:59 +0000 | [diff] [blame] | 1490 | for (MVT NativeVT : {MVT::v8i1, MVT::v4i1, MVT::v2i1, MVT::v4i8, |
| 1491 | MVT::v8i8, MVT::v2i16, MVT::v4i16, MVT::v2i32}) { |
| Benjamin Kramer | 6246069 | 2015-04-25 14:46:53 +0000 | [diff] [blame] | 1492 | setOperationAction(ISD::BUILD_VECTOR, NativeVT, Custom); |
| 1493 | setOperationAction(ISD::EXTRACT_VECTOR_ELT, NativeVT, Custom); |
| 1494 | setOperationAction(ISD::INSERT_VECTOR_ELT, NativeVT, Custom); |
| 1495 | setOperationAction(ISD::EXTRACT_SUBVECTOR, NativeVT, Custom); |
| 1496 | setOperationAction(ISD::INSERT_SUBVECTOR, NativeVT, Custom); |
| 1497 | setOperationAction(ISD::CONCAT_VECTORS, NativeVT, Custom); |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1498 | |
| Benjamin Kramer | 6246069 | 2015-04-25 14:46:53 +0000 | [diff] [blame] | 1499 | setOperationAction(ISD::ADD, NativeVT, Legal); |
| 1500 | setOperationAction(ISD::SUB, NativeVT, Legal); |
| 1501 | setOperationAction(ISD::MUL, NativeVT, Legal); |
| 1502 | setOperationAction(ISD::AND, NativeVT, Legal); |
| 1503 | setOperationAction(ISD::OR, NativeVT, Legal); |
| 1504 | setOperationAction(ISD::XOR, NativeVT, Legal); |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1505 | } |
| 1506 | |
| Krzysztof Parzyszek | 3780a0e | 2018-01-23 17:53:59 +0000 | [diff] [blame] | 1507 | // Custom-lower bitcasts from i8 to v8i1. |
| 1508 | setOperationAction(ISD::BITCAST, MVT::i8, Custom); |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1509 | setOperationAction(ISD::SETCC, MVT::v2i16, Custom); |
| 1510 | setOperationAction(ISD::VSELECT, MVT::v2i16, Custom); |
| Krzysztof Parzyszek | b8f2a1e | 2018-01-15 18:33:33 +0000 | [diff] [blame] | 1511 | setOperationAction(ISD::VECTOR_SHUFFLE, MVT::v4i8, Custom); |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1512 | setOperationAction(ISD::VECTOR_SHUFFLE, MVT::v4i16, Custom); |
| 1513 | setOperationAction(ISD::VECTOR_SHUFFLE, MVT::v8i8, Custom); |
| Krzysztof Parzyszek | d19d050 | 2016-09-13 21:16:07 +0000 | [diff] [blame] | 1514 | |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1515 | // Subtarget-specific operation actions. |
| 1516 | // |
| 1517 | if (Subtarget.hasV5TOps()) { |
| 1518 | setOperationAction(ISD::FMA, MVT::f64, Expand); |
| 1519 | setOperationAction(ISD::FADD, MVT::f64, Expand); |
| 1520 | setOperationAction(ISD::FSUB, MVT::f64, Expand); |
| 1521 | setOperationAction(ISD::FMUL, MVT::f64, Expand); |
| 1522 | |
| Krzysztof Parzyszek | bd8ef4b | 2016-08-19 13:34:31 +0000 | [diff] [blame] | 1523 | setOperationAction(ISD::FMINNUM, MVT::f32, Legal); |
| 1524 | setOperationAction(ISD::FMAXNUM, MVT::f32, Legal); |
| 1525 | |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1526 | setOperationAction(ISD::FP_TO_UINT, MVT::i1, Promote); |
| 1527 | setOperationAction(ISD::FP_TO_UINT, MVT::i8, Promote); |
| 1528 | setOperationAction(ISD::FP_TO_UINT, MVT::i16, Promote); |
| 1529 | setOperationAction(ISD::FP_TO_SINT, MVT::i1, Promote); |
| 1530 | setOperationAction(ISD::FP_TO_SINT, MVT::i8, Promote); |
| 1531 | setOperationAction(ISD::FP_TO_SINT, MVT::i16, Promote); |
| 1532 | setOperationAction(ISD::UINT_TO_FP, MVT::i1, Promote); |
| 1533 | setOperationAction(ISD::UINT_TO_FP, MVT::i8, Promote); |
| 1534 | setOperationAction(ISD::UINT_TO_FP, MVT::i16, Promote); |
| 1535 | setOperationAction(ISD::SINT_TO_FP, MVT::i1, Promote); |
| 1536 | setOperationAction(ISD::SINT_TO_FP, MVT::i8, Promote); |
| 1537 | setOperationAction(ISD::SINT_TO_FP, MVT::i16, Promote); |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1538 | } else { // V4 |
| 1539 | setOperationAction(ISD::SINT_TO_FP, MVT::i32, Expand); |
| 1540 | setOperationAction(ISD::SINT_TO_FP, MVT::i64, Expand); |
| 1541 | setOperationAction(ISD::UINT_TO_FP, MVT::i32, Expand); |
| 1542 | setOperationAction(ISD::UINT_TO_FP, MVT::i64, Expand); |
| 1543 | setOperationAction(ISD::FP_TO_SINT, MVT::f64, Expand); |
| 1544 | setOperationAction(ISD::FP_TO_SINT, MVT::f32, Expand); |
| 1545 | setOperationAction(ISD::FP_EXTEND, MVT::f32, Expand); |
| 1546 | setOperationAction(ISD::FP_ROUND, MVT::f64, Expand); |
| 1547 | setCondCodeAction(ISD::SETUNE, MVT::f64, Expand); |
| 1548 | |
| 1549 | setOperationAction(ISD::CTPOP, MVT::i8, Expand); |
| 1550 | setOperationAction(ISD::CTPOP, MVT::i16, Expand); |
| 1551 | setOperationAction(ISD::CTPOP, MVT::i32, Expand); |
| 1552 | setOperationAction(ISD::CTPOP, MVT::i64, Expand); |
| 1553 | |
| 1554 | // Expand these operations for both f32 and f64: |
| Benjamin Kramer | 6246069 | 2015-04-25 14:46:53 +0000 | [diff] [blame] | 1555 | for (unsigned FPExpOpV4 : |
| 1556 | {ISD::FADD, ISD::FSUB, ISD::FMUL, ISD::FABS, ISD::FNEG, ISD::FMA}) { |
| 1557 | setOperationAction(FPExpOpV4, MVT::f32, Expand); |
| 1558 | setOperationAction(FPExpOpV4, MVT::f64, Expand); |
| 1559 | } |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1560 | |
| Benjamin Kramer | 6246069 | 2015-04-25 14:46:53 +0000 | [diff] [blame] | 1561 | for (ISD::CondCode FPExpCCV4 : |
| 1562 | {ISD::SETOEQ, ISD::SETOGT, ISD::SETOLT, ISD::SETOGE, ISD::SETOLE, |
| Krzysztof Parzyszek | 08ff888 | 2015-11-26 18:38:27 +0000 | [diff] [blame] | 1563 | ISD::SETUO, ISD::SETO}) { |
| Benjamin Kramer | 6246069 | 2015-04-25 14:46:53 +0000 | [diff] [blame] | 1564 | setCondCodeAction(FPExpCCV4, MVT::f32, Expand); |
| 1565 | setCondCodeAction(FPExpCCV4, MVT::f64, Expand); |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1566 | } |
| 1567 | } |
| 1568 | |
| 1569 | // Handling of indexed loads/stores: default is "expand". |
| 1570 | // |
| Krzysztof Parzyszek | 2a48059 | 2016-07-26 20:30:30 +0000 | [diff] [blame] | 1571 | for (MVT VT : {MVT::i8, MVT::i16, MVT::i32, MVT::i64}) { |
| 1572 | setIndexedLoadAction(ISD::POST_INC, VT, Legal); |
| 1573 | setIndexedStoreAction(ISD::POST_INC, VT, Legal); |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1574 | } |
| 1575 | |
| Krzysztof Parzyszek | 8abaf89 | 2018-02-06 20:22:20 +0000 | [diff] [blame] | 1576 | if (Subtarget.useHVXOps()) |
| 1577 | initializeHVXLowering(); |
| Krzysztof Parzyszek | e4ce92c | 2017-12-20 20:49:43 +0000 | [diff] [blame] | 1578 | |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1579 | computeRegisterProperties(&HRI); |
| 1580 | |
| 1581 | // |
| 1582 | // Library calls for unsupported operations |
| 1583 | // |
| 1584 | bool FastMath = EnableFastMath; |
| 1585 | |
| Benjamin Kramer | a37c809 | 2015-04-25 14:46:46 +0000 | [diff] [blame] | 1586 | setLibcallName(RTLIB::SDIV_I32, "__hexagon_divsi3"); |
| 1587 | setLibcallName(RTLIB::SDIV_I64, "__hexagon_divdi3"); |
| 1588 | setLibcallName(RTLIB::UDIV_I32, "__hexagon_udivsi3"); |
| 1589 | setLibcallName(RTLIB::UDIV_I64, "__hexagon_udivdi3"); |
| 1590 | setLibcallName(RTLIB::SREM_I32, "__hexagon_modsi3"); |
| 1591 | setLibcallName(RTLIB::SREM_I64, "__hexagon_moddi3"); |
| 1592 | setLibcallName(RTLIB::UREM_I32, "__hexagon_umodsi3"); |
| 1593 | setLibcallName(RTLIB::UREM_I64, "__hexagon_umoddi3"); |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1594 | |
| Benjamin Kramer | a37c809 | 2015-04-25 14:46:46 +0000 | [diff] [blame] | 1595 | setLibcallName(RTLIB::SINTTOFP_I128_F64, "__hexagon_floattidf"); |
| 1596 | setLibcallName(RTLIB::SINTTOFP_I128_F32, "__hexagon_floattisf"); |
| 1597 | setLibcallName(RTLIB::FPTOUINT_F32_I128, "__hexagon_fixunssfti"); |
| 1598 | setLibcallName(RTLIB::FPTOUINT_F64_I128, "__hexagon_fixunsdfti"); |
| 1599 | setLibcallName(RTLIB::FPTOSINT_F32_I128, "__hexagon_fixsfti"); |
| 1600 | setLibcallName(RTLIB::FPTOSINT_F64_I128, "__hexagon_fixdfti"); |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1601 | |
| 1602 | if (IsV4) { |
| 1603 | // Handle single-precision floating point operations on V4. |
| Benjamin Kramer | a37c809 | 2015-04-25 14:46:46 +0000 | [diff] [blame] | 1604 | if (FastMath) { |
| 1605 | setLibcallName(RTLIB::ADD_F32, "__hexagon_fast_addsf3"); |
| 1606 | setLibcallName(RTLIB::SUB_F32, "__hexagon_fast_subsf3"); |
| 1607 | setLibcallName(RTLIB::MUL_F32, "__hexagon_fast_mulsf3"); |
| 1608 | setLibcallName(RTLIB::OGT_F32, "__hexagon_fast_gtsf2"); |
| 1609 | setLibcallName(RTLIB::OLT_F32, "__hexagon_fast_ltsf2"); |
| 1610 | // Double-precision compares. |
| 1611 | setLibcallName(RTLIB::OGT_F64, "__hexagon_fast_gtdf2"); |
| 1612 | setLibcallName(RTLIB::OLT_F64, "__hexagon_fast_ltdf2"); |
| 1613 | } else { |
| 1614 | setLibcallName(RTLIB::ADD_F32, "__hexagon_addsf3"); |
| 1615 | setLibcallName(RTLIB::SUB_F32, "__hexagon_subsf3"); |
| 1616 | setLibcallName(RTLIB::MUL_F32, "__hexagon_mulsf3"); |
| 1617 | setLibcallName(RTLIB::OGT_F32, "__hexagon_gtsf2"); |
| 1618 | setLibcallName(RTLIB::OLT_F32, "__hexagon_ltsf2"); |
| 1619 | // Double-precision compares. |
| 1620 | setLibcallName(RTLIB::OGT_F64, "__hexagon_gtdf2"); |
| 1621 | setLibcallName(RTLIB::OLT_F64, "__hexagon_ltdf2"); |
| 1622 | } |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1623 | } |
| 1624 | |
| 1625 | // This is the only fast library function for sqrtd. |
| 1626 | if (FastMath) |
| Benjamin Kramer | a37c809 | 2015-04-25 14:46:46 +0000 | [diff] [blame] | 1627 | setLibcallName(RTLIB::SQRT_F64, "__hexagon_fast2_sqrtdf2"); |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1628 | |
| Benjamin Kramer | a37c809 | 2015-04-25 14:46:46 +0000 | [diff] [blame] | 1629 | // Prefix is: nothing for "slow-math", |
| 1630 | // "fast2_" for V4 fast-math and V5+ fast-math double-precision |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1631 | // (actually, keep fast-math and fast-math2 separate for now) |
| Benjamin Kramer | a37c809 | 2015-04-25 14:46:46 +0000 | [diff] [blame] | 1632 | if (FastMath) { |
| 1633 | setLibcallName(RTLIB::ADD_F64, "__hexagon_fast_adddf3"); |
| 1634 | setLibcallName(RTLIB::SUB_F64, "__hexagon_fast_subdf3"); |
| 1635 | setLibcallName(RTLIB::MUL_F64, "__hexagon_fast_muldf3"); |
| 1636 | setLibcallName(RTLIB::DIV_F64, "__hexagon_fast_divdf3"); |
| 1637 | // Calling __hexagon_fast2_divsf3 with fast-math on V5 (ok). |
| 1638 | setLibcallName(RTLIB::DIV_F32, "__hexagon_fast_divsf3"); |
| 1639 | } else { |
| 1640 | setLibcallName(RTLIB::ADD_F64, "__hexagon_adddf3"); |
| 1641 | setLibcallName(RTLIB::SUB_F64, "__hexagon_subdf3"); |
| 1642 | setLibcallName(RTLIB::MUL_F64, "__hexagon_muldf3"); |
| 1643 | setLibcallName(RTLIB::DIV_F64, "__hexagon_divdf3"); |
| 1644 | setLibcallName(RTLIB::DIV_F32, "__hexagon_divsf3"); |
| 1645 | } |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1646 | |
| 1647 | if (Subtarget.hasV5TOps()) { |
| 1648 | if (FastMath) |
| Benjamin Kramer | a37c809 | 2015-04-25 14:46:46 +0000 | [diff] [blame] | 1649 | setLibcallName(RTLIB::SQRT_F32, "__hexagon_fast2_sqrtf"); |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1650 | else |
| Benjamin Kramer | a37c809 | 2015-04-25 14:46:46 +0000 | [diff] [blame] | 1651 | setLibcallName(RTLIB::SQRT_F32, "__hexagon_sqrtf"); |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1652 | } else { |
| 1653 | // V4 |
| Benjamin Kramer | a37c809 | 2015-04-25 14:46:46 +0000 | [diff] [blame] | 1654 | setLibcallName(RTLIB::SINTTOFP_I32_F32, "__hexagon_floatsisf"); |
| 1655 | setLibcallName(RTLIB::SINTTOFP_I32_F64, "__hexagon_floatsidf"); |
| 1656 | setLibcallName(RTLIB::SINTTOFP_I64_F32, "__hexagon_floatdisf"); |
| 1657 | setLibcallName(RTLIB::SINTTOFP_I64_F64, "__hexagon_floatdidf"); |
| 1658 | setLibcallName(RTLIB::UINTTOFP_I32_F32, "__hexagon_floatunsisf"); |
| 1659 | setLibcallName(RTLIB::UINTTOFP_I32_F64, "__hexagon_floatunsidf"); |
| 1660 | setLibcallName(RTLIB::UINTTOFP_I64_F32, "__hexagon_floatundisf"); |
| 1661 | setLibcallName(RTLIB::UINTTOFP_I64_F64, "__hexagon_floatundidf"); |
| 1662 | setLibcallName(RTLIB::FPTOUINT_F32_I32, "__hexagon_fixunssfsi"); |
| 1663 | setLibcallName(RTLIB::FPTOUINT_F32_I64, "__hexagon_fixunssfdi"); |
| 1664 | setLibcallName(RTLIB::FPTOUINT_F64_I32, "__hexagon_fixunsdfsi"); |
| 1665 | setLibcallName(RTLIB::FPTOUINT_F64_I64, "__hexagon_fixunsdfdi"); |
| 1666 | setLibcallName(RTLIB::FPTOSINT_F32_I32, "__hexagon_fixsfsi"); |
| 1667 | setLibcallName(RTLIB::FPTOSINT_F32_I64, "__hexagon_fixsfdi"); |
| 1668 | setLibcallName(RTLIB::FPTOSINT_F64_I32, "__hexagon_fixdfsi"); |
| 1669 | setLibcallName(RTLIB::FPTOSINT_F64_I64, "__hexagon_fixdfdi"); |
| 1670 | setLibcallName(RTLIB::FPEXT_F32_F64, "__hexagon_extendsfdf2"); |
| 1671 | setLibcallName(RTLIB::FPROUND_F64_F32, "__hexagon_truncdfsf2"); |
| 1672 | setLibcallName(RTLIB::OEQ_F32, "__hexagon_eqsf2"); |
| 1673 | setLibcallName(RTLIB::OEQ_F64, "__hexagon_eqdf2"); |
| 1674 | setLibcallName(RTLIB::OGE_F32, "__hexagon_gesf2"); |
| 1675 | setLibcallName(RTLIB::OGE_F64, "__hexagon_gedf2"); |
| 1676 | setLibcallName(RTLIB::OLE_F32, "__hexagon_lesf2"); |
| 1677 | setLibcallName(RTLIB::OLE_F64, "__hexagon_ledf2"); |
| 1678 | setLibcallName(RTLIB::UNE_F32, "__hexagon_nesf2"); |
| 1679 | setLibcallName(RTLIB::UNE_F64, "__hexagon_nedf2"); |
| 1680 | setLibcallName(RTLIB::UO_F32, "__hexagon_unordsf2"); |
| 1681 | setLibcallName(RTLIB::UO_F64, "__hexagon_unorddf2"); |
| 1682 | setLibcallName(RTLIB::O_F32, "__hexagon_unordsf2"); |
| 1683 | setLibcallName(RTLIB::O_F64, "__hexagon_unorddf2"); |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1684 | } |
| 1685 | |
| 1686 | // These cause problems when the shift amount is non-constant. |
| 1687 | setLibcallName(RTLIB::SHL_I128, nullptr); |
| 1688 | setLibcallName(RTLIB::SRL_I128, nullptr); |
| 1689 | setLibcallName(RTLIB::SRA_I128, nullptr); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1690 | } |
| 1691 | |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1692 | const char* HexagonTargetLowering::getTargetNodeName(unsigned Opcode) const { |
| Matthias Braun | d04893f | 2015-05-07 21:33:59 +0000 | [diff] [blame] | 1693 | switch ((HexagonISD::NodeType)Opcode) { |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1694 | case HexagonISD::ALLOCA: return "HexagonISD::ALLOCA"; |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1695 | case HexagonISD::AT_GOT: return "HexagonISD::AT_GOT"; |
| 1696 | case HexagonISD::AT_PCREL: return "HexagonISD::AT_PCREL"; |
| 1697 | case HexagonISD::BARRIER: return "HexagonISD::BARRIER"; |
| Krzysztof Parzyszek | be976d4 | 2016-08-12 11:12:02 +0000 | [diff] [blame] | 1698 | case HexagonISD::CALL: return "HexagonISD::CALL"; |
| 1699 | case HexagonISD::CALLnr: return "HexagonISD::CALLnr"; |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1700 | case HexagonISD::CALLR: return "HexagonISD::CALLR"; |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1701 | case HexagonISD::COMBINE: return "HexagonISD::COMBINE"; |
| 1702 | case HexagonISD::CONST32_GP: return "HexagonISD::CONST32_GP"; |
| 1703 | case HexagonISD::CONST32: return "HexagonISD::CONST32"; |
| 1704 | case HexagonISD::CP: return "HexagonISD::CP"; |
| 1705 | case HexagonISD::DCFETCH: return "HexagonISD::DCFETCH"; |
| 1706 | case HexagonISD::EH_RETURN: return "HexagonISD::EH_RETURN"; |
| Krzysztof Parzyszek | 3780a0e | 2018-01-23 17:53:59 +0000 | [diff] [blame] | 1707 | case HexagonISD::TSTBIT: return "HexagonISD::TSTBIT"; |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1708 | case HexagonISD::EXTRACTU: return "HexagonISD::EXTRACTU"; |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1709 | case HexagonISD::INSERT: return "HexagonISD::INSERT"; |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1710 | case HexagonISD::JT: return "HexagonISD::JT"; |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1711 | case HexagonISD::RET_FLAG: return "HexagonISD::RET_FLAG"; |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1712 | case HexagonISD::TC_RETURN: return "HexagonISD::TC_RETURN"; |
| Krzysztof Parzyszek | f85dd9f | 2017-07-10 20:16:44 +0000 | [diff] [blame] | 1713 | case HexagonISD::VASL: return "HexagonISD::VASL"; |
| 1714 | case HexagonISD::VASR: return "HexagonISD::VASR"; |
| 1715 | case HexagonISD::VLSR: return "HexagonISD::VLSR"; |
| 1716 | case HexagonISD::VSPLAT: return "HexagonISD::VSPLAT"; |
| Krzysztof Parzyszek | 7d37dd8 | 2017-12-06 16:40:37 +0000 | [diff] [blame] | 1717 | case HexagonISD::VEXTRACTW: return "HexagonISD::VEXTRACTW"; |
| 1718 | case HexagonISD::VINSERTW0: return "HexagonISD::VINSERTW0"; |
| 1719 | case HexagonISD::VROR: return "HexagonISD::VROR"; |
| Krzysztof Parzyszek | ab57c2b | 2017-02-22 22:28:47 +0000 | [diff] [blame] | 1720 | case HexagonISD::READCYCLE: return "HexagonISD::READCYCLE"; |
| Krzysztof Parzyszek | e4ce92c | 2017-12-20 20:49:43 +0000 | [diff] [blame] | 1721 | case HexagonISD::VZERO: return "HexagonISD::VZERO"; |
| Krzysztof Parzyszek | 3780a0e | 2018-01-23 17:53:59 +0000 | [diff] [blame] | 1722 | case HexagonISD::D2P: return "HexagonISD::D2P"; |
| 1723 | case HexagonISD::P2D: return "HexagonISD::P2D"; |
| 1724 | case HexagonISD::V2Q: return "HexagonISD::V2Q"; |
| 1725 | case HexagonISD::Q2V: return "HexagonISD::Q2V"; |
| Krzysztof Parzyszek | 88f1100 | 2018-02-06 14:24:57 +0000 | [diff] [blame] | 1726 | case HexagonISD::QCAT: return "HexagonISD::QCAT"; |
| Krzysztof Parzyszek | 69f1d7e | 2018-02-06 14:16:52 +0000 | [diff] [blame] | 1727 | case HexagonISD::QTRUE: return "HexagonISD::QTRUE"; |
| 1728 | case HexagonISD::QFALSE: return "HexagonISD::QFALSE"; |
| Krzysztof Parzyszek | 3780a0e | 2018-01-23 17:53:59 +0000 | [diff] [blame] | 1729 | case HexagonISD::TYPECAST: return "HexagonISD::TYPECAST"; |
| Krzysztof Parzyszek | ad83ce4 | 2018-02-14 20:46:06 +0000 | [diff] [blame] | 1730 | case HexagonISD::VALIGNADDR: return "HexagonISD::VALIGNADDR"; |
| Matthias Braun | d04893f | 2015-05-07 21:33:59 +0000 | [diff] [blame] | 1731 | case HexagonISD::OP_END: break; |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1732 | } |
| Matthias Braun | d04893f | 2015-05-07 21:33:59 +0000 | [diff] [blame] | 1733 | return nullptr; |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1734 | } |
| 1735 | |
| Krzysztof Parzyszek | a8ab1b7 | 2017-12-11 18:57:54 +0000 | [diff] [blame] | 1736 | /// Given an intrinsic, checks if on the target the intrinsic will need to map |
| 1737 | /// to a MemIntrinsicNode (touches memory). If this is the case, it returns |
| 1738 | /// true and store the intrinsic information into the IntrinsicInfo that was |
| 1739 | /// passed to the function. |
| 1740 | bool HexagonTargetLowering::getTgtMemIntrinsic(IntrinsicInfo &Info, |
| 1741 | const CallInst &I, |
| Matt Arsenault | 7d7adf4 | 2017-12-14 22:34:10 +0000 | [diff] [blame] | 1742 | MachineFunction &MF, |
| Krzysztof Parzyszek | a8ab1b7 | 2017-12-11 18:57:54 +0000 | [diff] [blame] | 1743 | unsigned Intrinsic) const { |
| 1744 | switch (Intrinsic) { |
| 1745 | case Intrinsic::hexagon_V6_vgathermw: |
| 1746 | case Intrinsic::hexagon_V6_vgathermw_128B: |
| 1747 | case Intrinsic::hexagon_V6_vgathermh: |
| 1748 | case Intrinsic::hexagon_V6_vgathermh_128B: |
| 1749 | case Intrinsic::hexagon_V6_vgathermhw: |
| 1750 | case Intrinsic::hexagon_V6_vgathermhw_128B: |
| 1751 | case Intrinsic::hexagon_V6_vgathermwq: |
| 1752 | case Intrinsic::hexagon_V6_vgathermwq_128B: |
| 1753 | case Intrinsic::hexagon_V6_vgathermhq: |
| 1754 | case Intrinsic::hexagon_V6_vgathermhq_128B: |
| 1755 | case Intrinsic::hexagon_V6_vgathermhwq: |
| 1756 | case Intrinsic::hexagon_V6_vgathermhwq_128B: { |
| 1757 | const Module &M = *I.getParent()->getParent()->getParent(); |
| 1758 | Info.opc = ISD::INTRINSIC_W_CHAIN; |
| 1759 | Type *VecTy = I.getArgOperand(1)->getType(); |
| 1760 | Info.memVT = MVT::getVT(VecTy); |
| 1761 | Info.ptrVal = I.getArgOperand(0); |
| 1762 | Info.offset = 0; |
| 1763 | Info.align = M.getDataLayout().getTypeAllocSizeInBits(VecTy) / 8; |
| Matt Arsenault | 1117133 | 2017-12-14 21:39:51 +0000 | [diff] [blame] | 1764 | Info.flags = MachineMemOperand::MOLoad | |
| 1765 | MachineMemOperand::MOStore | |
| 1766 | MachineMemOperand::MOVolatile; |
| Krzysztof Parzyszek | a8ab1b7 | 2017-12-11 18:57:54 +0000 | [diff] [blame] | 1767 | return true; |
| 1768 | } |
| 1769 | default: |
| 1770 | break; |
| 1771 | } |
| 1772 | return false; |
| 1773 | } |
| 1774 | |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1775 | bool HexagonTargetLowering::isTruncateFree(Type *Ty1, Type *Ty2) const { |
| Krzysztof Parzyszek | cfbe6ba | 2018-02-13 15:35:07 +0000 | [diff] [blame] | 1776 | return isTruncateFree(EVT::getEVT(Ty1), EVT::getEVT(Ty2)); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1777 | } |
| 1778 | |
| 1779 | bool HexagonTargetLowering::isTruncateFree(EVT VT1, EVT VT2) const { |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1780 | if (!VT1.isSimple() || !VT2.isSimple()) |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1781 | return false; |
| Krzysztof Parzyszek | cfbe6ba | 2018-02-13 15:35:07 +0000 | [diff] [blame] | 1782 | return VT1.getSimpleVT() == MVT::i64 && VT2.getSimpleVT() == MVT::i32; |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1783 | } |
| 1784 | |
| Krzysztof Parzyszek | bd8ef4b | 2016-08-19 13:34:31 +0000 | [diff] [blame] | 1785 | bool HexagonTargetLowering::isFMAFasterThanFMulAndFAdd(EVT VT) const { |
| 1786 | return isOperationLegalOrCustom(ISD::FMA, VT); |
| 1787 | } |
| 1788 | |
| Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 1789 | // Should we expand the build vector with shuffles? |
| Krzysztof Parzyszek | d19d050 | 2016-09-13 21:16:07 +0000 | [diff] [blame] | 1790 | bool HexagonTargetLowering::shouldExpandBuildVectorWithShuffles(EVT VT, |
| 1791 | unsigned DefinedValues) const { |
| Krzysztof Parzyszek | 7d37dd8 | 2017-12-06 16:40:37 +0000 | [diff] [blame] | 1792 | return false; |
| Krzysztof Parzyszek | 0bd55a7 | 2016-07-29 16:44:27 +0000 | [diff] [blame] | 1793 | } |
| 1794 | |
| Zvi Rackover | 1b73682 | 2017-07-26 08:06:58 +0000 | [diff] [blame] | 1795 | bool HexagonTargetLowering::isShuffleMaskLegal(ArrayRef<int> Mask, |
| 1796 | EVT VT) const { |
| Krzysztof Parzyszek | d19d050 | 2016-09-13 21:16:07 +0000 | [diff] [blame] | 1797 | return true; |
| 1798 | } |
| 1799 | |
| Krzysztof Parzyszek | 5439a70 | 2017-12-18 18:21:01 +0000 | [diff] [blame] | 1800 | TargetLoweringBase::LegalizeTypeAction |
| 1801 | HexagonTargetLowering::getPreferredVectorAction(EVT VT) const { |
| Krzysztof Parzyszek | e4ce92c | 2017-12-20 20:49:43 +0000 | [diff] [blame] | 1802 | if (VT.getVectorNumElements() == 1) |
| 1803 | return TargetLoweringBase::TypeScalarizeVector; |
| 1804 | |
| 1805 | // Always widen vectors of i1. |
| 1806 | MVT ElemTy = VT.getSimpleVT().getVectorElementType(); |
| 1807 | if (ElemTy == MVT::i1) |
| 1808 | return TargetLoweringBase::TypeWidenVector; |
| 1809 | |
| Krzysztof Parzyszek | 5439a70 | 2017-12-18 18:21:01 +0000 | [diff] [blame] | 1810 | if (Subtarget.useHVXOps()) { |
| 1811 | // If the size of VT is at least half of the vector length, |
| 1812 | // widen the vector. Note: the threshold was not selected in |
| 1813 | // any scientific way. |
| Krzysztof Parzyszek | e4ce92c | 2017-12-20 20:49:43 +0000 | [diff] [blame] | 1814 | ArrayRef<MVT> Tys = Subtarget.getHVXElementTypes(); |
| 1815 | if (llvm::find(Tys, ElemTy) != Tys.end()) { |
| 1816 | unsigned HwWidth = 8*Subtarget.getVectorLength(); |
| 1817 | unsigned VecWidth = VT.getSizeInBits(); |
| 1818 | if (VecWidth >= HwWidth/2 && VecWidth < HwWidth) |
| 1819 | return TargetLoweringBase::TypeWidenVector; |
| 1820 | } |
| Krzysztof Parzyszek | 5439a70 | 2017-12-18 18:21:01 +0000 | [diff] [blame] | 1821 | } |
| Krzysztof Parzyszek | e4ce92c | 2017-12-20 20:49:43 +0000 | [diff] [blame] | 1822 | return TargetLoweringBase::TypeSplitVector; |
| Krzysztof Parzyszek | 5439a70 | 2017-12-18 18:21:01 +0000 | [diff] [blame] | 1823 | } |
| 1824 | |
| Krzysztof Parzyszek | ad83ce4 | 2018-02-14 20:46:06 +0000 | [diff] [blame] | 1825 | std::pair<SDValue, int> |
| 1826 | HexagonTargetLowering::getBaseAndOffset(SDValue Addr) const { |
| 1827 | if (Addr.getOpcode() == ISD::ADD) { |
| 1828 | SDValue Op1 = Addr.getOperand(1); |
| 1829 | if (auto *CN = dyn_cast<const ConstantSDNode>(Op1.getNode())) |
| 1830 | return { Addr.getOperand(0), CN->getSExtValue() }; |
| 1831 | } |
| 1832 | return { Addr, 0 }; |
| 1833 | } |
| 1834 | |
| Krzysztof Parzyszek | 0bd55a7 | 2016-07-29 16:44:27 +0000 | [diff] [blame] | 1835 | // Lower a vector shuffle (V1, V2, V3). V1 and V2 are the two vectors |
| 1836 | // to select data from, V3 is the permutation. |
| 1837 | SDValue |
| 1838 | HexagonTargetLowering::LowerVECTOR_SHUFFLE(SDValue Op, SelectionDAG &DAG) |
| 1839 | const { |
| Krzysztof Parzyszek | b8f2a1e | 2018-01-15 18:33:33 +0000 | [diff] [blame] | 1840 | const auto *SVN = cast<ShuffleVectorSDNode>(Op); |
| 1841 | ArrayRef<int> AM = SVN->getMask(); |
| 1842 | assert(AM.size() <= 8 && "Unexpected shuffle mask"); |
| 1843 | unsigned VecLen = AM.size(); |
| Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 1844 | |
| Krzysztof Parzyszek | b8f2a1e | 2018-01-15 18:33:33 +0000 | [diff] [blame] | 1845 | MVT VecTy = ty(Op); |
| Krzysztof Parzyszek | 8abaf89 | 2018-02-06 20:22:20 +0000 | [diff] [blame] | 1846 | assert(!Subtarget.isHVXVectorType(VecTy, true) && |
| 1847 | "HVX shuffles should be legal"); |
| Krzysztof Parzyszek | b8f2a1e | 2018-01-15 18:33:33 +0000 | [diff] [blame] | 1848 | assert(VecTy.getSizeInBits() <= 64 && "Unexpected vector length"); |
| Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 1849 | |
| Krzysztof Parzyszek | b8f2a1e | 2018-01-15 18:33:33 +0000 | [diff] [blame] | 1850 | SDValue Op0 = Op.getOperand(0); |
| 1851 | SDValue Op1 = Op.getOperand(1); |
| Krzysztof Parzyszek | 7cfe7cb | 2018-02-09 15:30:02 +0000 | [diff] [blame] | 1852 | const SDLoc &dl(Op); |
| 1853 | |
| Krzysztof Parzyszek | b8f2a1e | 2018-01-15 18:33:33 +0000 | [diff] [blame] | 1854 | // If the inputs are not the same as the output, bail. This is not an |
| 1855 | // error situation, but complicates the handling and the default expansion |
| 1856 | // (into BUILD_VECTOR) should be adequate. |
| 1857 | if (ty(Op0) != VecTy || ty(Op1) != VecTy) |
| 1858 | return SDValue(); |
| Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 1859 | |
| Krzysztof Parzyszek | b8f2a1e | 2018-01-15 18:33:33 +0000 | [diff] [blame] | 1860 | // Normalize the mask so that the first non-negative index comes from |
| 1861 | // the first operand. |
| 1862 | SmallVector<int,8> Mask(AM.begin(), AM.end()); |
| 1863 | unsigned F = llvm::find_if(AM, [](int M) { return M >= 0; }) - AM.data(); |
| 1864 | if (F == AM.size()) |
| 1865 | return DAG.getUNDEF(VecTy); |
| 1866 | if (AM[F] >= int(VecLen)) { |
| 1867 | ShuffleVectorSDNode::commuteMask(Mask); |
| 1868 | std::swap(Op0, Op1); |
| Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 1869 | } |
| 1870 | |
| Krzysztof Parzyszek | b8f2a1e | 2018-01-15 18:33:33 +0000 | [diff] [blame] | 1871 | // Express the shuffle mask in terms of bytes. |
| 1872 | SmallVector<int,8> ByteMask; |
| 1873 | unsigned ElemBytes = VecTy.getVectorElementType().getSizeInBits() / 8; |
| 1874 | for (unsigned i = 0, e = Mask.size(); i != e; ++i) { |
| 1875 | int M = Mask[i]; |
| 1876 | if (M < 0) { |
| 1877 | for (unsigned j = 0; j != ElemBytes; ++j) |
| 1878 | ByteMask.push_back(-1); |
| 1879 | } else { |
| 1880 | for (unsigned j = 0; j != ElemBytes; ++j) |
| 1881 | ByteMask.push_back(M*ElemBytes + j); |
| 1882 | } |
| 1883 | } |
| 1884 | assert(ByteMask.size() <= 8); |
| Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 1885 | |
| Krzysztof Parzyszek | b8f2a1e | 2018-01-15 18:33:33 +0000 | [diff] [blame] | 1886 | // All non-undef (non-negative) indexes are well within [0..127], so they |
| 1887 | // fit in a single byte. Build two 64-bit words: |
| 1888 | // - MaskIdx where each byte is the corresponding index (for non-negative |
| 1889 | // indexes), and 0xFF for negative indexes, and |
| 1890 | // - MaskUnd that has 0xFF for each negative index. |
| 1891 | uint64_t MaskIdx = 0; |
| 1892 | uint64_t MaskUnd = 0; |
| 1893 | for (unsigned i = 0, e = ByteMask.size(); i != e; ++i) { |
| 1894 | unsigned S = 8*i; |
| 1895 | uint64_t M = ByteMask[i] & 0xFF; |
| 1896 | if (M == 0xFF) |
| 1897 | MaskUnd |= M << S; |
| 1898 | MaskIdx |= M << S; |
| 1899 | } |
| 1900 | |
| Krzysztof Parzyszek | b8f2a1e | 2018-01-15 18:33:33 +0000 | [diff] [blame] | 1901 | if (ByteMask.size() == 4) { |
| 1902 | // Identity. |
| 1903 | if (MaskIdx == (0x03020100 | MaskUnd)) |
| 1904 | return Op0; |
| 1905 | // Byte swap. |
| 1906 | if (MaskIdx == (0x00010203 | MaskUnd)) { |
| 1907 | SDValue T0 = DAG.getBitcast(MVT::i32, Op0); |
| 1908 | SDValue T1 = DAG.getNode(ISD::BSWAP, dl, MVT::i32, T0); |
| 1909 | return DAG.getBitcast(VecTy, T1); |
| 1910 | } |
| 1911 | |
| 1912 | // Byte packs. |
| 1913 | SDValue Concat10 = DAG.getNode(HexagonISD::COMBINE, dl, |
| 1914 | typeJoin({ty(Op1), ty(Op0)}), {Op1, Op0}); |
| 1915 | if (MaskIdx == (0x06040200 | MaskUnd)) |
| Krzysztof Parzyszek | 15efa98 | 2018-01-31 21:17:03 +0000 | [diff] [blame] | 1916 | return getInstr(Hexagon::S2_vtrunehb, dl, VecTy, {Concat10}, DAG); |
| Krzysztof Parzyszek | b8f2a1e | 2018-01-15 18:33:33 +0000 | [diff] [blame] | 1917 | if (MaskIdx == (0x07050301 | MaskUnd)) |
| Krzysztof Parzyszek | 15efa98 | 2018-01-31 21:17:03 +0000 | [diff] [blame] | 1918 | return getInstr(Hexagon::S2_vtrunohb, dl, VecTy, {Concat10}, DAG); |
| Krzysztof Parzyszek | b8f2a1e | 2018-01-15 18:33:33 +0000 | [diff] [blame] | 1919 | |
| 1920 | SDValue Concat01 = DAG.getNode(HexagonISD::COMBINE, dl, |
| 1921 | typeJoin({ty(Op0), ty(Op1)}), {Op0, Op1}); |
| 1922 | if (MaskIdx == (0x02000604 | MaskUnd)) |
| Krzysztof Parzyszek | 15efa98 | 2018-01-31 21:17:03 +0000 | [diff] [blame] | 1923 | return getInstr(Hexagon::S2_vtrunehb, dl, VecTy, {Concat01}, DAG); |
| Krzysztof Parzyszek | b8f2a1e | 2018-01-15 18:33:33 +0000 | [diff] [blame] | 1924 | if (MaskIdx == (0x03010705 | MaskUnd)) |
| Krzysztof Parzyszek | 15efa98 | 2018-01-31 21:17:03 +0000 | [diff] [blame] | 1925 | return getInstr(Hexagon::S2_vtrunohb, dl, VecTy, {Concat01}, DAG); |
| Krzysztof Parzyszek | b8f2a1e | 2018-01-15 18:33:33 +0000 | [diff] [blame] | 1926 | } |
| 1927 | |
| 1928 | if (ByteMask.size() == 8) { |
| 1929 | // Identity. |
| 1930 | if (MaskIdx == (0x0706050403020100ull | MaskUnd)) |
| 1931 | return Op0; |
| 1932 | // Byte swap. |
| 1933 | if (MaskIdx == (0x0001020304050607ull | MaskUnd)) { |
| 1934 | SDValue T0 = DAG.getBitcast(MVT::i64, Op0); |
| 1935 | SDValue T1 = DAG.getNode(ISD::BSWAP, dl, MVT::i64, T0); |
| 1936 | return DAG.getBitcast(VecTy, T1); |
| 1937 | } |
| 1938 | |
| 1939 | // Halfword picks. |
| 1940 | if (MaskIdx == (0x0d0c050409080100ull | MaskUnd)) |
| Krzysztof Parzyszek | 15efa98 | 2018-01-31 21:17:03 +0000 | [diff] [blame] | 1941 | return getInstr(Hexagon::S2_shuffeh, dl, VecTy, {Op1, Op0}, DAG); |
| Krzysztof Parzyszek | b8f2a1e | 2018-01-15 18:33:33 +0000 | [diff] [blame] | 1942 | if (MaskIdx == (0x0f0e07060b0a0302ull | MaskUnd)) |
| Krzysztof Parzyszek | 15efa98 | 2018-01-31 21:17:03 +0000 | [diff] [blame] | 1943 | return getInstr(Hexagon::S2_shuffoh, dl, VecTy, {Op1, Op0}, DAG); |
| Krzysztof Parzyszek | b8f2a1e | 2018-01-15 18:33:33 +0000 | [diff] [blame] | 1944 | if (MaskIdx == (0x0d0c090805040100ull | MaskUnd)) |
| Krzysztof Parzyszek | 15efa98 | 2018-01-31 21:17:03 +0000 | [diff] [blame] | 1945 | return getInstr(Hexagon::S2_vtrunewh, dl, VecTy, {Op1, Op0}, DAG); |
| Krzysztof Parzyszek | b8f2a1e | 2018-01-15 18:33:33 +0000 | [diff] [blame] | 1946 | if (MaskIdx == (0x0f0e0b0a07060302ull | MaskUnd)) |
| Krzysztof Parzyszek | 15efa98 | 2018-01-31 21:17:03 +0000 | [diff] [blame] | 1947 | return getInstr(Hexagon::S2_vtrunowh, dl, VecTy, {Op1, Op0}, DAG); |
| Krzysztof Parzyszek | b8f2a1e | 2018-01-15 18:33:33 +0000 | [diff] [blame] | 1948 | if (MaskIdx == (0x0706030205040100ull | MaskUnd)) { |
| 1949 | VectorPair P = opSplit(Op0, dl, DAG); |
| Krzysztof Parzyszek | 15efa98 | 2018-01-31 21:17:03 +0000 | [diff] [blame] | 1950 | return getInstr(Hexagon::S2_packhl, dl, VecTy, {P.second, P.first}, DAG); |
| Krzysztof Parzyszek | b8f2a1e | 2018-01-15 18:33:33 +0000 | [diff] [blame] | 1951 | } |
| 1952 | |
| 1953 | // Byte packs. |
| 1954 | if (MaskIdx == (0x0e060c040a020800ull | MaskUnd)) |
| Krzysztof Parzyszek | 15efa98 | 2018-01-31 21:17:03 +0000 | [diff] [blame] | 1955 | return getInstr(Hexagon::S2_shuffeb, dl, VecTy, {Op1, Op0}, DAG); |
| Krzysztof Parzyszek | b8f2a1e | 2018-01-15 18:33:33 +0000 | [diff] [blame] | 1956 | if (MaskIdx == (0x0f070d050b030901ull | MaskUnd)) |
| Krzysztof Parzyszek | 15efa98 | 2018-01-31 21:17:03 +0000 | [diff] [blame] | 1957 | return getInstr(Hexagon::S2_shuffob, dl, VecTy, {Op1, Op0}, DAG); |
| Krzysztof Parzyszek | b8f2a1e | 2018-01-15 18:33:33 +0000 | [diff] [blame] | 1958 | } |
| 1959 | |
| 1960 | return SDValue(); |
| Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 1961 | } |
| 1962 | |
| Krzysztof Parzyszek | 8abaf89 | 2018-02-06 20:22:20 +0000 | [diff] [blame] | 1963 | // Create a Hexagon-specific node for shifting a vector by an integer. |
| Krzysztof Parzyszek | 0bd55a7 | 2016-07-29 16:44:27 +0000 | [diff] [blame] | 1964 | SDValue |
| Krzysztof Parzyszek | 8abaf89 | 2018-02-06 20:22:20 +0000 | [diff] [blame] | 1965 | HexagonTargetLowering::getVectorShiftByInt(SDValue Op, SelectionDAG &DAG) |
| 1966 | const { |
| Krzysztof Parzyszek | 1108ee2 | 2018-01-31 20:49:24 +0000 | [diff] [blame] | 1967 | if (auto *BVN = dyn_cast<BuildVectorSDNode>(Op.getOperand(1).getNode())) { |
| 1968 | if (SDValue S = BVN->getSplatValue()) { |
| 1969 | unsigned NewOpc; |
| 1970 | switch (Op.getOpcode()) { |
| 1971 | case ISD::SHL: |
| 1972 | NewOpc = HexagonISD::VASL; |
| 1973 | break; |
| 1974 | case ISD::SRA: |
| 1975 | NewOpc = HexagonISD::VASR; |
| 1976 | break; |
| 1977 | case ISD::SRL: |
| 1978 | NewOpc = HexagonISD::VLSR; |
| 1979 | break; |
| 1980 | default: |
| 1981 | llvm_unreachable("Unexpected shift opcode"); |
| 1982 | } |
| Krzysztof Parzyszek | 8abaf89 | 2018-02-06 20:22:20 +0000 | [diff] [blame] | 1983 | return DAG.getNode(NewOpc, SDLoc(Op), ty(Op), Op.getOperand(0), S); |
| Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 1984 | } |
| Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 1985 | } |
| 1986 | |
| Krzysztof Parzyszek | 1108ee2 | 2018-01-31 20:49:24 +0000 | [diff] [blame] | 1987 | return SDValue(); |
| Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 1988 | } |
| 1989 | |
| Krzysztof Parzyszek | 3780a0e | 2018-01-23 17:53:59 +0000 | [diff] [blame] | 1990 | SDValue |
| Krzysztof Parzyszek | 8abaf89 | 2018-02-06 20:22:20 +0000 | [diff] [blame] | 1991 | HexagonTargetLowering::LowerVECTOR_SHIFT(SDValue Op, SelectionDAG &DAG) const { |
| 1992 | return getVectorShiftByInt(Op, DAG); |
| 1993 | } |
| 1994 | |
| 1995 | SDValue |
| Krzysztof Parzyszek | 3780a0e | 2018-01-23 17:53:59 +0000 | [diff] [blame] | 1996 | HexagonTargetLowering::LowerBITCAST(SDValue Op, SelectionDAG &DAG) const { |
| 1997 | MVT ResTy = ty(Op); |
| 1998 | SDValue InpV = Op.getOperand(0); |
| 1999 | MVT InpTy = ty(InpV); |
| 2000 | assert(ResTy.getSizeInBits() == InpTy.getSizeInBits()); |
| 2001 | const SDLoc &dl(Op); |
| 2002 | |
| 2003 | // Handle conversion from i8 to v8i1. |
| 2004 | if (ResTy == MVT::v8i1) { |
| 2005 | SDValue Sc = DAG.getBitcast(tyScalar(InpTy), InpV); |
| 2006 | SDValue Ext = DAG.getZExtOrTrunc(Sc, dl, MVT::i32); |
| Krzysztof Parzyszek | 15efa98 | 2018-01-31 21:17:03 +0000 | [diff] [blame] | 2007 | return getInstr(Hexagon::C2_tfrrp, dl, ResTy, Ext, DAG); |
| Krzysztof Parzyszek | 3780a0e | 2018-01-23 17:53:59 +0000 | [diff] [blame] | 2008 | } |
| 2009 | |
| 2010 | return SDValue(); |
| 2011 | } |
| 2012 | |
| Krzysztof Parzyszek | e4ce92c | 2017-12-20 20:49:43 +0000 | [diff] [blame] | 2013 | bool |
| 2014 | HexagonTargetLowering::getBuildVectorConstInts(ArrayRef<SDValue> Values, |
| 2015 | MVT VecTy, SelectionDAG &DAG, |
| 2016 | MutableArrayRef<ConstantInt*> Consts) const { |
| 2017 | MVT ElemTy = VecTy.getVectorElementType(); |
| 2018 | unsigned ElemWidth = ElemTy.getSizeInBits(); |
| 2019 | IntegerType *IntTy = IntegerType::get(*DAG.getContext(), ElemWidth); |
| 2020 | bool AllConst = true; |
| 2021 | |
| 2022 | for (unsigned i = 0, e = Values.size(); i != e; ++i) { |
| 2023 | SDValue V = Values[i]; |
| 2024 | if (V.isUndef()) { |
| 2025 | Consts[i] = ConstantInt::get(IntTy, 0); |
| 2026 | continue; |
| 2027 | } |
| Krzysztof Parzyszek | 4ef6cff | 2018-01-11 18:03:23 +0000 | [diff] [blame] | 2028 | // Make sure to always cast to IntTy. |
| Krzysztof Parzyszek | e4ce92c | 2017-12-20 20:49:43 +0000 | [diff] [blame] | 2029 | if (auto *CN = dyn_cast<ConstantSDNode>(V.getNode())) { |
| 2030 | const ConstantInt *CI = CN->getConstantIntValue(); |
| Krzysztof Parzyszek | 4ef6cff | 2018-01-11 18:03:23 +0000 | [diff] [blame] | 2031 | Consts[i] = ConstantInt::get(IntTy, CI->getValue().getSExtValue()); |
| Krzysztof Parzyszek | e4ce92c | 2017-12-20 20:49:43 +0000 | [diff] [blame] | 2032 | } else if (auto *CN = dyn_cast<ConstantFPSDNode>(V.getNode())) { |
| 2033 | const ConstantFP *CF = CN->getConstantFPValue(); |
| 2034 | APInt A = CF->getValueAPF().bitcastToAPInt(); |
| 2035 | Consts[i] = ConstantInt::get(IntTy, A.getZExtValue()); |
| 2036 | } else { |
| 2037 | AllConst = false; |
| 2038 | } |
| 2039 | } |
| 2040 | return AllConst; |
| 2041 | } |
| 2042 | |
| Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2043 | SDValue |
| Krzysztof Parzyszek | 942fa16 | 2017-11-22 20:56:23 +0000 | [diff] [blame] | 2044 | HexagonTargetLowering::buildVector32(ArrayRef<SDValue> Elem, const SDLoc &dl, |
| 2045 | MVT VecTy, SelectionDAG &DAG) const { |
| 2046 | MVT ElemTy = VecTy.getVectorElementType(); |
| 2047 | assert(VecTy.getVectorNumElements() == Elem.size()); |
| Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2048 | |
| Krzysztof Parzyszek | e4ce92c | 2017-12-20 20:49:43 +0000 | [diff] [blame] | 2049 | SmallVector<ConstantInt*,4> Consts(Elem.size()); |
| 2050 | bool AllConst = getBuildVectorConstInts(Elem, VecTy, DAG, Consts); |
| Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2051 | |
| Krzysztof Parzyszek | 942fa16 | 2017-11-22 20:56:23 +0000 | [diff] [blame] | 2052 | unsigned First, Num = Elem.size(); |
| 2053 | for (First = 0; First != Num; ++First) |
| Krzysztof Parzyszek | 7d37dd8 | 2017-12-06 16:40:37 +0000 | [diff] [blame] | 2054 | if (!isUndef(Elem[First])) |
| Krzysztof Parzyszek | 942fa16 | 2017-11-22 20:56:23 +0000 | [diff] [blame] | 2055 | break; |
| 2056 | if (First == Num) |
| 2057 | return DAG.getUNDEF(VecTy); |
| Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2058 | |
| Krzysztof Parzyszek | e4ce92c | 2017-12-20 20:49:43 +0000 | [diff] [blame] | 2059 | if (AllConst && |
| 2060 | llvm::all_of(Consts, [](ConstantInt *CI) { return CI->isZero(); })) |
| 2061 | return getZero(dl, VecTy, DAG); |
| 2062 | |
| Krzysztof Parzyszek | 942fa16 | 2017-11-22 20:56:23 +0000 | [diff] [blame] | 2063 | if (ElemTy == MVT::i16) { |
| 2064 | assert(Elem.size() == 2); |
| 2065 | if (AllConst) { |
| 2066 | uint32_t V = (Consts[0]->getZExtValue() & 0xFFFF) | |
| 2067 | Consts[1]->getZExtValue() << 16; |
| 2068 | return DAG.getBitcast(MVT::v2i16, DAG.getConstant(V, dl, MVT::i32)); |
| Krzysztof Parzyszek | 89b2d7c | 2017-07-13 18:17:58 +0000 | [diff] [blame] | 2069 | } |
| Krzysztof Parzyszek | 15efa98 | 2018-01-31 21:17:03 +0000 | [diff] [blame] | 2070 | SDValue N = getInstr(Hexagon::A2_combine_ll, dl, MVT::i32, |
| 2071 | {Elem[1], Elem[0]}, DAG); |
| Krzysztof Parzyszek | 7d37dd8 | 2017-12-06 16:40:37 +0000 | [diff] [blame] | 2072 | return DAG.getBitcast(MVT::v2i16, N); |
| Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2073 | } |
| 2074 | |
| Krzysztof Parzyszek | e4ce92c | 2017-12-20 20:49:43 +0000 | [diff] [blame] | 2075 | if (ElemTy == MVT::i8) { |
| 2076 | // First try generating a constant. |
| 2077 | if (AllConst) { |
| 2078 | int32_t V = (Consts[0]->getZExtValue() & 0xFF) | |
| 2079 | (Consts[1]->getZExtValue() & 0xFF) << 8 | |
| 2080 | (Consts[1]->getZExtValue() & 0xFF) << 16 | |
| 2081 | Consts[2]->getZExtValue() << 24; |
| 2082 | return DAG.getBitcast(MVT::v4i8, DAG.getConstant(V, dl, MVT::i32)); |
| 2083 | } |
| 2084 | |
| 2085 | // Then try splat. |
| 2086 | bool IsSplat = true; |
| 2087 | for (unsigned i = 0; i != Num; ++i) { |
| 2088 | if (i == First) |
| 2089 | continue; |
| 2090 | if (Elem[i] == Elem[First] || isUndef(Elem[i])) |
| 2091 | continue; |
| 2092 | IsSplat = false; |
| 2093 | break; |
| 2094 | } |
| 2095 | if (IsSplat) { |
| 2096 | // Legalize the operand to VSPLAT. |
| 2097 | SDValue Ext = DAG.getZExtOrTrunc(Elem[First], dl, MVT::i32); |
| 2098 | return DAG.getNode(HexagonISD::VSPLAT, dl, VecTy, Ext); |
| 2099 | } |
| 2100 | |
| 2101 | // Generate |
| 2102 | // (zxtb(Elem[0]) | (zxtb(Elem[1]) << 8)) | |
| 2103 | // (zxtb(Elem[2]) | (zxtb(Elem[3]) << 8)) << 16 |
| 2104 | assert(Elem.size() == 4); |
| 2105 | SDValue Vs[4]; |
| 2106 | for (unsigned i = 0; i != 4; ++i) { |
| 2107 | Vs[i] = DAG.getZExtOrTrunc(Elem[i], dl, MVT::i32); |
| 2108 | Vs[i] = DAG.getZeroExtendInReg(Vs[i], dl, MVT::i8); |
| 2109 | } |
| 2110 | SDValue S8 = DAG.getConstant(8, dl, MVT::i32); |
| 2111 | SDValue T0 = DAG.getNode(ISD::SHL, dl, MVT::i32, {Vs[1], S8}); |
| 2112 | SDValue T1 = DAG.getNode(ISD::SHL, dl, MVT::i32, {Vs[3], S8}); |
| 2113 | SDValue B0 = DAG.getNode(ISD::OR, dl, MVT::i32, {Vs[0], T0}); |
| 2114 | SDValue B1 = DAG.getNode(ISD::OR, dl, MVT::i32, {Vs[2], T1}); |
| 2115 | |
| Krzysztof Parzyszek | 15efa98 | 2018-01-31 21:17:03 +0000 | [diff] [blame] | 2116 | SDValue R = getInstr(Hexagon::A2_combine_ll, dl, MVT::i32, {B1, B0}, DAG); |
| Krzysztof Parzyszek | e4ce92c | 2017-12-20 20:49:43 +0000 | [diff] [blame] | 2117 | return DAG.getBitcast(MVT::v4i8, R); |
| Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2118 | } |
| 2119 | |
| Krzysztof Parzyszek | e4ce92c | 2017-12-20 20:49:43 +0000 | [diff] [blame] | 2120 | #ifndef NDEBUG |
| 2121 | dbgs() << "VecTy: " << EVT(VecTy).getEVTString() << '\n'; |
| 2122 | #endif |
| 2123 | llvm_unreachable("Unexpected vector element type"); |
| Krzysztof Parzyszek | 942fa16 | 2017-11-22 20:56:23 +0000 | [diff] [blame] | 2124 | } |
| Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2125 | |
| Krzysztof Parzyszek | 942fa16 | 2017-11-22 20:56:23 +0000 | [diff] [blame] | 2126 | SDValue |
| 2127 | HexagonTargetLowering::buildVector64(ArrayRef<SDValue> Elem, const SDLoc &dl, |
| 2128 | MVT VecTy, SelectionDAG &DAG) const { |
| 2129 | MVT ElemTy = VecTy.getVectorElementType(); |
| 2130 | assert(VecTy.getVectorNumElements() == Elem.size()); |
| 2131 | |
| Krzysztof Parzyszek | e4ce92c | 2017-12-20 20:49:43 +0000 | [diff] [blame] | 2132 | SmallVector<ConstantInt*,8> Consts(Elem.size()); |
| 2133 | bool AllConst = getBuildVectorConstInts(Elem, VecTy, DAG, Consts); |
| Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2134 | |
| Krzysztof Parzyszek | 942fa16 | 2017-11-22 20:56:23 +0000 | [diff] [blame] | 2135 | unsigned First, Num = Elem.size(); |
| 2136 | for (First = 0; First != Num; ++First) |
| Krzysztof Parzyszek | 7d37dd8 | 2017-12-06 16:40:37 +0000 | [diff] [blame] | 2137 | if (!isUndef(Elem[First])) |
| Krzysztof Parzyszek | 942fa16 | 2017-11-22 20:56:23 +0000 | [diff] [blame] | 2138 | break; |
| 2139 | if (First == Num) |
| 2140 | return DAG.getUNDEF(VecTy); |
| Krzysztof Parzyszek | 0bd55a7 | 2016-07-29 16:44:27 +0000 | [diff] [blame] | 2141 | |
| Krzysztof Parzyszek | e4ce92c | 2017-12-20 20:49:43 +0000 | [diff] [blame] | 2142 | if (AllConst && |
| 2143 | llvm::all_of(Consts, [](ConstantInt *CI) { return CI->isZero(); })) |
| 2144 | return getZero(dl, VecTy, DAG); |
| 2145 | |
| Krzysztof Parzyszek | 942fa16 | 2017-11-22 20:56:23 +0000 | [diff] [blame] | 2146 | // First try splat if possible. |
| 2147 | if (ElemTy == MVT::i16) { |
| 2148 | bool IsSplat = true; |
| 2149 | for (unsigned i = 0; i != Num; ++i) { |
| 2150 | if (i == First) |
| Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2151 | continue; |
| Krzysztof Parzyszek | 7d37dd8 | 2017-12-06 16:40:37 +0000 | [diff] [blame] | 2152 | if (Elem[i] == Elem[First] || isUndef(Elem[i])) |
| Krzysztof Parzyszek | 942fa16 | 2017-11-22 20:56:23 +0000 | [diff] [blame] | 2153 | continue; |
| 2154 | IsSplat = false; |
| 2155 | break; |
| Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2156 | } |
| Krzysztof Parzyszek | fb0fcac | 2017-12-20 20:33:49 +0000 | [diff] [blame] | 2157 | if (IsSplat) { |
| 2158 | // Legalize the operand to VSPLAT. |
| 2159 | SDValue Ext = DAG.getZExtOrTrunc(Elem[First], dl, MVT::i32); |
| 2160 | return DAG.getNode(HexagonISD::VSPLAT, dl, VecTy, Ext); |
| 2161 | } |
| Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2162 | } |
| 2163 | |
| Krzysztof Parzyszek | 942fa16 | 2017-11-22 20:56:23 +0000 | [diff] [blame] | 2164 | // Then try constant. |
| 2165 | if (AllConst) { |
| 2166 | uint64_t Val = 0; |
| 2167 | unsigned W = ElemTy.getSizeInBits(); |
| 2168 | uint64_t Mask = (ElemTy == MVT::i8) ? 0xFFull |
| 2169 | : (ElemTy == MVT::i16) ? 0xFFFFull : 0xFFFFFFFFull; |
| 2170 | for (unsigned i = 0; i != Num; ++i) |
| Krzysztof Parzyszek | 240df6f | 2018-01-11 18:30:41 +0000 | [diff] [blame] | 2171 | Val = (Val << W) | (Consts[Num-1-i]->getZExtValue() & Mask); |
| Krzysztof Parzyszek | 942fa16 | 2017-11-22 20:56:23 +0000 | [diff] [blame] | 2172 | SDValue V0 = DAG.getConstant(Val, dl, MVT::i64); |
| 2173 | return DAG.getBitcast(VecTy, V0); |
| 2174 | } |
| 2175 | |
| 2176 | // Build two 32-bit vectors and concatenate. |
| 2177 | MVT HalfTy = MVT::getVectorVT(ElemTy, Num/2); |
| 2178 | SDValue L = (ElemTy == MVT::i32) |
| 2179 | ? Elem[0] |
| Krzysztof Parzyszek | e4ce92c | 2017-12-20 20:49:43 +0000 | [diff] [blame] | 2180 | : buildVector32(Elem.take_front(Num/2), dl, HalfTy, DAG); |
| Krzysztof Parzyszek | 942fa16 | 2017-11-22 20:56:23 +0000 | [diff] [blame] | 2181 | SDValue H = (ElemTy == MVT::i32) |
| 2182 | ? Elem[1] |
| Krzysztof Parzyszek | e4ce92c | 2017-12-20 20:49:43 +0000 | [diff] [blame] | 2183 | : buildVector32(Elem.drop_front(Num/2), dl, HalfTy, DAG); |
| Krzysztof Parzyszek | 7d37dd8 | 2017-12-06 16:40:37 +0000 | [diff] [blame] | 2184 | return DAG.getNode(HexagonISD::COMBINE, dl, VecTy, {H, L}); |
| Krzysztof Parzyszek | 942fa16 | 2017-11-22 20:56:23 +0000 | [diff] [blame] | 2185 | } |
| 2186 | |
| 2187 | SDValue |
| Krzysztof Parzyszek | 6a8e5f4 | 2017-11-29 19:58:10 +0000 | [diff] [blame] | 2188 | HexagonTargetLowering::extractVector(SDValue VecV, SDValue IdxV, |
| 2189 | const SDLoc &dl, MVT ValTy, MVT ResTy, |
| 2190 | SelectionDAG &DAG) const { |
| 2191 | MVT VecTy = ty(VecV); |
| 2192 | assert(!ValTy.isVector() || |
| 2193 | VecTy.getVectorElementType() == ValTy.getVectorElementType()); |
| 2194 | unsigned VecWidth = VecTy.getSizeInBits(); |
| 2195 | unsigned ValWidth = ValTy.getSizeInBits(); |
| 2196 | unsigned ElemWidth = VecTy.getVectorElementType().getSizeInBits(); |
| Krzysztof Parzyszek | 6a8e5f4 | 2017-11-29 19:58:10 +0000 | [diff] [blame] | 2197 | assert((VecWidth % ElemWidth) == 0); |
| Krzysztof Parzyszek | 3780a0e | 2018-01-23 17:53:59 +0000 | [diff] [blame] | 2198 | auto *IdxN = dyn_cast<ConstantSDNode>(IdxV); |
| 2199 | |
| 2200 | // Special case for v{8,4,2}i1 (the only boolean vectors legal in Hexagon |
| 2201 | // without any coprocessors). |
| 2202 | if (ElemWidth == 1) { |
| 2203 | assert(VecWidth == VecTy.getVectorNumElements() && "Sanity failure"); |
| 2204 | assert(VecWidth == 8 || VecWidth == 4 || VecWidth == 2); |
| 2205 | // Check if this is an extract of the lowest bit. |
| 2206 | if (IdxN) { |
| 2207 | // Extracting the lowest bit is a no-op, but it changes the type, |
| 2208 | // so it must be kept as an operation to avoid errors related to |
| 2209 | // type mismatches. |
| 2210 | if (IdxN->isNullValue() && ValTy.getSizeInBits() == 1) |
| 2211 | return DAG.getNode(HexagonISD::TYPECAST, dl, MVT::i1, VecV); |
| 2212 | } |
| 2213 | |
| 2214 | // If the value extracted is a single bit, use tstbit. |
| 2215 | if (ValWidth == 1) { |
| Krzysztof Parzyszek | 15efa98 | 2018-01-31 21:17:03 +0000 | [diff] [blame] | 2216 | SDValue A0 = getInstr(Hexagon::C2_tfrpr, dl, MVT::i32, {VecV}, DAG); |
| Krzysztof Parzyszek | 3780a0e | 2018-01-23 17:53:59 +0000 | [diff] [blame] | 2217 | return DAG.getNode(HexagonISD::TSTBIT, dl, MVT::i1, A0, IdxV); |
| 2218 | } |
| 2219 | |
| 2220 | // Each bool vector (v2i1, v4i1, v8i1) always occupies 8 bits in |
| 2221 | // a predicate register. The elements of the vector are repeated |
| 2222 | // in the register (if necessary) so that the total number is 8. |
| 2223 | // The extracted subvector will need to be expanded in such a way. |
| 2224 | unsigned Scale = VecWidth / ValWidth; |
| 2225 | |
| 2226 | // Generate (p2d VecV) >> 8*Idx to move the interesting bytes to |
| 2227 | // position 0. |
| 2228 | assert(ty(IdxV) == MVT::i32); |
| 2229 | SDValue S0 = DAG.getNode(ISD::MUL, dl, MVT::i32, IdxV, |
| 2230 | DAG.getConstant(8, dl, MVT::i32)); |
| 2231 | SDValue T0 = DAG.getNode(HexagonISD::P2D, dl, MVT::i64, VecV); |
| 2232 | SDValue T1 = DAG.getNode(ISD::SRL, dl, MVT::i64, T0, S0); |
| 2233 | while (Scale > 1) { |
| 2234 | // The longest possible subvector is at most 32 bits, so it is always |
| 2235 | // contained in the low subregister. |
| 2236 | T1 = DAG.getTargetExtractSubreg(Hexagon::isub_lo, dl, MVT::i32, T1); |
| 2237 | T1 = expandPredicate(T1, dl, DAG); |
| 2238 | Scale /= 2; |
| 2239 | } |
| 2240 | |
| 2241 | return DAG.getNode(HexagonISD::D2P, dl, ResTy, T1); |
| 2242 | } |
| 2243 | |
| 2244 | assert(VecWidth == 32 || VecWidth == 64); |
| Krzysztof Parzyszek | 6a8e5f4 | 2017-11-29 19:58:10 +0000 | [diff] [blame] | 2245 | |
| 2246 | // Cast everything to scalar integer types. |
| 2247 | MVT ScalarTy = tyScalar(VecTy); |
| 2248 | VecV = DAG.getBitcast(ScalarTy, VecV); |
| 2249 | |
| 2250 | SDValue WidthV = DAG.getConstant(ValWidth, dl, MVT::i32); |
| 2251 | SDValue ExtV; |
| 2252 | |
| Krzysztof Parzyszek | 3780a0e | 2018-01-23 17:53:59 +0000 | [diff] [blame] | 2253 | if (IdxN) { |
| 2254 | unsigned Off = IdxN->getZExtValue() * ElemWidth; |
| Krzysztof Parzyszek | 6a8e5f4 | 2017-11-29 19:58:10 +0000 | [diff] [blame] | 2255 | if (VecWidth == 64 && ValWidth == 32) { |
| 2256 | assert(Off == 0 || Off == 32); |
| 2257 | unsigned SubIdx = Off == 0 ? Hexagon::isub_lo : Hexagon::isub_hi; |
| 2258 | ExtV = DAG.getTargetExtractSubreg(SubIdx, dl, MVT::i32, VecV); |
| 2259 | } else if (Off == 0 && (ValWidth % 8) == 0) { |
| 2260 | ExtV = DAG.getZeroExtendInReg(VecV, dl, tyScalar(ValTy)); |
| 2261 | } else { |
| 2262 | SDValue OffV = DAG.getConstant(Off, dl, MVT::i32); |
| 2263 | // The return type of EXTRACTU must be the same as the type of the |
| 2264 | // input vector. |
| 2265 | ExtV = DAG.getNode(HexagonISD::EXTRACTU, dl, ScalarTy, |
| 2266 | {VecV, WidthV, OffV}); |
| 2267 | } |
| 2268 | } else { |
| 2269 | if (ty(IdxV) != MVT::i32) |
| 2270 | IdxV = DAG.getZExtOrTrunc(IdxV, dl, MVT::i32); |
| 2271 | SDValue OffV = DAG.getNode(ISD::MUL, dl, MVT::i32, IdxV, |
| 2272 | DAG.getConstant(ElemWidth, dl, MVT::i32)); |
| Krzysztof Parzyszek | b1b2960 | 2018-01-04 13:56:04 +0000 | [diff] [blame] | 2273 | ExtV = DAG.getNode(HexagonISD::EXTRACTU, dl, ScalarTy, |
| 2274 | {VecV, WidthV, OffV}); |
| Krzysztof Parzyszek | 6a8e5f4 | 2017-11-29 19:58:10 +0000 | [diff] [blame] | 2275 | } |
| 2276 | |
| 2277 | // Cast ExtV to the requested result type. |
| 2278 | ExtV = DAG.getZExtOrTrunc(ExtV, dl, tyScalar(ResTy)); |
| 2279 | ExtV = DAG.getBitcast(ResTy, ExtV); |
| 2280 | return ExtV; |
| 2281 | } |
| 2282 | |
| 2283 | SDValue |
| 2284 | HexagonTargetLowering::insertVector(SDValue VecV, SDValue ValV, SDValue IdxV, |
| 2285 | const SDLoc &dl, MVT ValTy, |
| 2286 | SelectionDAG &DAG) const { |
| 2287 | MVT VecTy = ty(VecV); |
| Krzysztof Parzyszek | 3780a0e | 2018-01-23 17:53:59 +0000 | [diff] [blame] | 2288 | if (VecTy.getVectorElementType() == MVT::i1) { |
| 2289 | MVT ValTy = ty(ValV); |
| 2290 | assert(ValTy.getVectorElementType() == MVT::i1); |
| 2291 | SDValue ValR = DAG.getNode(HexagonISD::P2D, dl, MVT::i64, ValV); |
| 2292 | unsigned VecLen = VecTy.getVectorNumElements(); |
| 2293 | unsigned Scale = VecLen / ValTy.getVectorNumElements(); |
| 2294 | assert(Scale > 1); |
| 2295 | |
| 2296 | for (unsigned R = Scale; R > 1; R /= 2) { |
| 2297 | ValR = contractPredicate(ValR, dl, DAG); |
| 2298 | ValR = DAG.getNode(HexagonISD::COMBINE, dl, MVT::i64, |
| 2299 | DAG.getUNDEF(MVT::i32), ValR); |
| 2300 | } |
| 2301 | // The longest possible subvector is at most 32 bits, so it is always |
| 2302 | // contained in the low subregister. |
| 2303 | ValR = DAG.getTargetExtractSubreg(Hexagon::isub_lo, dl, MVT::i32, ValR); |
| 2304 | |
| 2305 | unsigned ValBytes = 64 / Scale; |
| 2306 | SDValue Width = DAG.getConstant(ValBytes*8, dl, MVT::i32); |
| 2307 | SDValue Idx = DAG.getNode(ISD::MUL, dl, MVT::i32, IdxV, |
| 2308 | DAG.getConstant(8, dl, MVT::i32)); |
| 2309 | SDValue VecR = DAG.getNode(HexagonISD::P2D, dl, MVT::i64, VecV); |
| 2310 | SDValue Ins = DAG.getNode(HexagonISD::INSERT, dl, MVT::i32, |
| 2311 | {VecR, ValR, Width, Idx}); |
| 2312 | return DAG.getNode(HexagonISD::D2P, dl, VecTy, Ins); |
| 2313 | } |
| 2314 | |
| Krzysztof Parzyszek | 6a8e5f4 | 2017-11-29 19:58:10 +0000 | [diff] [blame] | 2315 | unsigned VecWidth = VecTy.getSizeInBits(); |
| 2316 | unsigned ValWidth = ValTy.getSizeInBits(); |
| 2317 | assert(VecWidth == 32 || VecWidth == 64); |
| 2318 | assert((VecWidth % ValWidth) == 0); |
| 2319 | |
| 2320 | // Cast everything to scalar integer types. |
| 2321 | MVT ScalarTy = MVT::getIntegerVT(VecWidth); |
| 2322 | // The actual type of ValV may be different than ValTy (which is related |
| 2323 | // to the vector type). |
| 2324 | unsigned VW = ty(ValV).getSizeInBits(); |
| 2325 | ValV = DAG.getBitcast(MVT::getIntegerVT(VW), ValV); |
| 2326 | VecV = DAG.getBitcast(ScalarTy, VecV); |
| 2327 | if (VW != VecWidth) |
| 2328 | ValV = DAG.getAnyExtOrTrunc(ValV, dl, ScalarTy); |
| 2329 | |
| 2330 | SDValue WidthV = DAG.getConstant(ValWidth, dl, MVT::i32); |
| 2331 | SDValue InsV; |
| 2332 | |
| 2333 | if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(IdxV)) { |
| 2334 | unsigned W = C->getZExtValue() * ValWidth; |
| 2335 | SDValue OffV = DAG.getConstant(W, dl, MVT::i32); |
| 2336 | InsV = DAG.getNode(HexagonISD::INSERT, dl, ScalarTy, |
| 2337 | {VecV, ValV, WidthV, OffV}); |
| 2338 | } else { |
| 2339 | if (ty(IdxV) != MVT::i32) |
| 2340 | IdxV = DAG.getZExtOrTrunc(IdxV, dl, MVT::i32); |
| 2341 | SDValue OffV = DAG.getNode(ISD::MUL, dl, MVT::i32, IdxV, WidthV); |
| Krzysztof Parzyszek | b1b2960 | 2018-01-04 13:56:04 +0000 | [diff] [blame] | 2342 | InsV = DAG.getNode(HexagonISD::INSERT, dl, ScalarTy, |
| 2343 | {VecV, ValV, WidthV, OffV}); |
| Krzysztof Parzyszek | 6a8e5f4 | 2017-11-29 19:58:10 +0000 | [diff] [blame] | 2344 | } |
| 2345 | |
| 2346 | return DAG.getNode(ISD::BITCAST, dl, VecTy, InsV); |
| 2347 | } |
| 2348 | |
| 2349 | SDValue |
| Krzysztof Parzyszek | 3780a0e | 2018-01-23 17:53:59 +0000 | [diff] [blame] | 2350 | HexagonTargetLowering::expandPredicate(SDValue Vec32, const SDLoc &dl, |
| 2351 | SelectionDAG &DAG) const { |
| 2352 | assert(ty(Vec32).getSizeInBits() == 32); |
| 2353 | if (isUndef(Vec32)) |
| 2354 | return DAG.getUNDEF(MVT::i64); |
| Krzysztof Parzyszek | 15efa98 | 2018-01-31 21:17:03 +0000 | [diff] [blame] | 2355 | return getInstr(Hexagon::S2_vsxtbh, dl, MVT::i64, {Vec32}, DAG); |
| Krzysztof Parzyszek | 3780a0e | 2018-01-23 17:53:59 +0000 | [diff] [blame] | 2356 | } |
| 2357 | |
| 2358 | SDValue |
| 2359 | HexagonTargetLowering::contractPredicate(SDValue Vec64, const SDLoc &dl, |
| 2360 | SelectionDAG &DAG) const { |
| 2361 | assert(ty(Vec64).getSizeInBits() == 64); |
| 2362 | if (isUndef(Vec64)) |
| 2363 | return DAG.getUNDEF(MVT::i32); |
| Krzysztof Parzyszek | 15efa98 | 2018-01-31 21:17:03 +0000 | [diff] [blame] | 2364 | return getInstr(Hexagon::S2_vtrunehb, dl, MVT::i32, {Vec64}, DAG); |
| Krzysztof Parzyszek | 3780a0e | 2018-01-23 17:53:59 +0000 | [diff] [blame] | 2365 | } |
| 2366 | |
| 2367 | SDValue |
| Krzysztof Parzyszek | e4ce92c | 2017-12-20 20:49:43 +0000 | [diff] [blame] | 2368 | HexagonTargetLowering::getZero(const SDLoc &dl, MVT Ty, SelectionDAG &DAG) |
| 2369 | const { |
| 2370 | if (Ty.isVector()) { |
| 2371 | assert(Ty.isInteger() && "Only integer vectors are supported here"); |
| 2372 | unsigned W = Ty.getSizeInBits(); |
| 2373 | if (W <= 64) |
| 2374 | return DAG.getBitcast(Ty, DAG.getConstant(0, dl, MVT::getIntegerVT(W))); |
| 2375 | return DAG.getNode(HexagonISD::VZERO, dl, Ty); |
| 2376 | } |
| 2377 | |
| 2378 | if (Ty.isInteger()) |
| 2379 | return DAG.getConstant(0, dl, Ty); |
| 2380 | if (Ty.isFloatingPoint()) |
| 2381 | return DAG.getConstantFP(0.0, dl, Ty); |
| 2382 | llvm_unreachable("Invalid type for zero"); |
| 2383 | } |
| 2384 | |
| 2385 | SDValue |
| Krzysztof Parzyszek | 942fa16 | 2017-11-22 20:56:23 +0000 | [diff] [blame] | 2386 | HexagonTargetLowering::LowerBUILD_VECTOR(SDValue Op, SelectionDAG &DAG) const { |
| Krzysztof Parzyszek | 7d37dd8 | 2017-12-06 16:40:37 +0000 | [diff] [blame] | 2387 | MVT VecTy = ty(Op); |
| Krzysztof Parzyszek | 3780a0e | 2018-01-23 17:53:59 +0000 | [diff] [blame] | 2388 | unsigned BW = VecTy.getSizeInBits(); |
| 2389 | const SDLoc &dl(Op); |
| 2390 | SmallVector<SDValue,8> Ops; |
| 2391 | for (unsigned i = 0, e = Op.getNumOperands(); i != e; ++i) |
| 2392 | Ops.push_back(Op.getOperand(i)); |
| 2393 | |
| 2394 | if (BW == 32) |
| 2395 | return buildVector32(Ops, dl, VecTy, DAG); |
| 2396 | if (BW == 64) |
| Krzysztof Parzyszek | e4ce92c | 2017-12-20 20:49:43 +0000 | [diff] [blame] | 2397 | return buildVector64(Ops, dl, VecTy, DAG); |
| Krzysztof Parzyszek | 3780a0e | 2018-01-23 17:53:59 +0000 | [diff] [blame] | 2398 | |
| 2399 | if (VecTy == MVT::v8i1 || VecTy == MVT::v4i1 || VecTy == MVT::v2i1) { |
| 2400 | // For each i1 element in the resulting predicate register, put 1 |
| 2401 | // shifted by the index of the element into a general-purpose register, |
| 2402 | // then or them together and transfer it back into a predicate register. |
| 2403 | SDValue Rs[8]; |
| 2404 | SDValue Z = getZero(dl, MVT::i32, DAG); |
| 2405 | // Always produce 8 bits, repeat inputs if necessary. |
| 2406 | unsigned Rep = 8 / VecTy.getVectorNumElements(); |
| 2407 | for (unsigned i = 0; i != 8; ++i) { |
| Simon Pilgrim | c1e2290 | 2018-01-23 21:22:16 +0000 | [diff] [blame] | 2408 | SDValue S = DAG.getConstant(1ull << i, dl, MVT::i32); |
| Krzysztof Parzyszek | 3780a0e | 2018-01-23 17:53:59 +0000 | [diff] [blame] | 2409 | Rs[i] = DAG.getSelect(dl, MVT::i32, Ops[i/Rep], S, Z); |
| 2410 | } |
| 2411 | for (ArrayRef<SDValue> A(Rs); A.size() != 1; A = A.drop_back(A.size()/2)) { |
| 2412 | for (unsigned i = 0, e = A.size()/2; i != e; ++i) |
| 2413 | Rs[i] = DAG.getNode(ISD::OR, dl, MVT::i32, Rs[2*i], Rs[2*i+1]); |
| 2414 | } |
| 2415 | // Move the value directly to a predicate register. |
| Krzysztof Parzyszek | 15efa98 | 2018-01-31 21:17:03 +0000 | [diff] [blame] | 2416 | return getInstr(Hexagon::C2_tfrrp, dl, VecTy, {Rs[0]}, DAG); |
| Krzysztof Parzyszek | 942fa16 | 2017-11-22 20:56:23 +0000 | [diff] [blame] | 2417 | } |
| 2418 | |
| 2419 | return SDValue(); |
| Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2420 | } |
| 2421 | |
| 2422 | SDValue |
| 2423 | HexagonTargetLowering::LowerCONCAT_VECTORS(SDValue Op, |
| 2424 | SelectionDAG &DAG) const { |
| Krzysztof Parzyszek | 7d37dd8 | 2017-12-06 16:40:37 +0000 | [diff] [blame] | 2425 | MVT VecTy = ty(Op); |
| Krzysztof Parzyszek | 3780a0e | 2018-01-23 17:53:59 +0000 | [diff] [blame] | 2426 | const SDLoc &dl(Op); |
| Krzysztof Parzyszek | 7d37dd8 | 2017-12-06 16:40:37 +0000 | [diff] [blame] | 2427 | if (VecTy.getSizeInBits() == 64) { |
| 2428 | assert(Op.getNumOperands() == 2); |
| Krzysztof Parzyszek | 3780a0e | 2018-01-23 17:53:59 +0000 | [diff] [blame] | 2429 | return DAG.getNode(HexagonISD::COMBINE, dl, VecTy, Op.getOperand(1), |
| Krzysztof Parzyszek | 7d37dd8 | 2017-12-06 16:40:37 +0000 | [diff] [blame] | 2430 | Op.getOperand(0)); |
| Krzysztof Parzyszek | 0bd55a7 | 2016-07-29 16:44:27 +0000 | [diff] [blame] | 2431 | } |
| 2432 | |
| Krzysztof Parzyszek | 3780a0e | 2018-01-23 17:53:59 +0000 | [diff] [blame] | 2433 | MVT ElemTy = VecTy.getVectorElementType(); |
| 2434 | if (ElemTy == MVT::i1) { |
| Krzysztof Parzyszek | 3780a0e | 2018-01-23 17:53:59 +0000 | [diff] [blame] | 2435 | assert(VecTy == MVT::v2i1 || VecTy == MVT::v4i1 || VecTy == MVT::v8i1); |
| 2436 | MVT OpTy = ty(Op.getOperand(0)); |
| 2437 | // Scale is how many times the operands need to be contracted to match |
| 2438 | // the representation in the target register. |
| 2439 | unsigned Scale = VecTy.getVectorNumElements() / OpTy.getVectorNumElements(); |
| 2440 | assert(Scale == Op.getNumOperands() && Scale > 1); |
| 2441 | |
| 2442 | // First, convert all bool vectors to integers, then generate pairwise |
| 2443 | // inserts to form values of doubled length. Up until there are only |
| 2444 | // two values left to concatenate, all of these values will fit in a |
| 2445 | // 32-bit integer, so keep them as i32 to use 32-bit inserts. |
| 2446 | SmallVector<SDValue,4> Words[2]; |
| 2447 | unsigned IdxW = 0; |
| 2448 | |
| 2449 | for (SDValue P : Op.getNode()->op_values()) { |
| 2450 | SDValue W = DAG.getNode(HexagonISD::P2D, dl, MVT::i64, P); |
| 2451 | for (unsigned R = Scale; R > 1; R /= 2) { |
| 2452 | W = contractPredicate(W, dl, DAG); |
| 2453 | W = DAG.getNode(HexagonISD::COMBINE, dl, MVT::i64, |
| 2454 | DAG.getUNDEF(MVT::i32), W); |
| 2455 | } |
| 2456 | W = DAG.getTargetExtractSubreg(Hexagon::isub_lo, dl, MVT::i32, W); |
| 2457 | Words[IdxW].push_back(W); |
| 2458 | } |
| 2459 | |
| 2460 | while (Scale > 2) { |
| 2461 | SDValue WidthV = DAG.getConstant(64 / Scale, dl, MVT::i32); |
| 2462 | Words[IdxW ^ 1].clear(); |
| 2463 | |
| 2464 | for (unsigned i = 0, e = Words[IdxW].size(); i != e; i += 2) { |
| 2465 | SDValue W0 = Words[IdxW][i], W1 = Words[IdxW][i+1]; |
| 2466 | // Insert W1 into W0 right next to the significant bits of W0. |
| 2467 | SDValue T = DAG.getNode(HexagonISD::INSERT, dl, MVT::i32, |
| 2468 | {W0, W1, WidthV, WidthV}); |
| 2469 | Words[IdxW ^ 1].push_back(T); |
| 2470 | } |
| 2471 | IdxW ^= 1; |
| 2472 | Scale /= 2; |
| 2473 | } |
| 2474 | |
| 2475 | // Another sanity check. At this point there should only be two words |
| 2476 | // left, and Scale should be 2. |
| 2477 | assert(Scale == 2 && Words[IdxW].size() == 2); |
| 2478 | |
| 2479 | SDValue WW = DAG.getNode(HexagonISD::COMBINE, dl, MVT::i64, |
| 2480 | Words[IdxW][1], Words[IdxW][0]); |
| 2481 | return DAG.getNode(HexagonISD::D2P, dl, VecTy, WW); |
| 2482 | } |
| 2483 | |
| Krzysztof Parzyszek | 0bd55a7 | 2016-07-29 16:44:27 +0000 | [diff] [blame] | 2484 | return SDValue(); |
| 2485 | } |
| 2486 | |
| 2487 | SDValue |
| Krzysztof Parzyszek | 6a8e5f4 | 2017-11-29 19:58:10 +0000 | [diff] [blame] | 2488 | HexagonTargetLowering::LowerEXTRACT_VECTOR_ELT(SDValue Op, |
| 2489 | SelectionDAG &DAG) const { |
| Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2490 | SDValue Vec = Op.getOperand(0); |
| Krzysztof Parzyszek | 6a8e5f4 | 2017-11-29 19:58:10 +0000 | [diff] [blame] | 2491 | MVT ElemTy = ty(Vec).getVectorElementType(); |
| 2492 | return extractVector(Vec, Op.getOperand(1), SDLoc(Op), ElemTy, ty(Op), DAG); |
| Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2493 | } |
| 2494 | |
| 2495 | SDValue |
| Krzysztof Parzyszek | 6a8e5f4 | 2017-11-29 19:58:10 +0000 | [diff] [blame] | 2496 | HexagonTargetLowering::LowerEXTRACT_SUBVECTOR(SDValue Op, |
| 2497 | SelectionDAG &DAG) const { |
| Krzysztof Parzyszek | 8abaf89 | 2018-02-06 20:22:20 +0000 | [diff] [blame] | 2498 | return extractVector(Op.getOperand(0), Op.getOperand(1), SDLoc(Op), |
| 2499 | ty(Op), ty(Op), DAG); |
| Krzysztof Parzyszek | 6a8e5f4 | 2017-11-29 19:58:10 +0000 | [diff] [blame] | 2500 | } |
| Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2501 | |
| Krzysztof Parzyszek | 6a8e5f4 | 2017-11-29 19:58:10 +0000 | [diff] [blame] | 2502 | SDValue |
| 2503 | HexagonTargetLowering::LowerINSERT_VECTOR_ELT(SDValue Op, |
| 2504 | SelectionDAG &DAG) const { |
| Krzysztof Parzyszek | 6a8e5f4 | 2017-11-29 19:58:10 +0000 | [diff] [blame] | 2505 | return insertVector(Op.getOperand(0), Op.getOperand(1), Op.getOperand(2), |
| Krzysztof Parzyszek | 8abaf89 | 2018-02-06 20:22:20 +0000 | [diff] [blame] | 2506 | SDLoc(Op), ty(Op).getVectorElementType(), DAG); |
| Krzysztof Parzyszek | 6a8e5f4 | 2017-11-29 19:58:10 +0000 | [diff] [blame] | 2507 | } |
| Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2508 | |
| Krzysztof Parzyszek | 6a8e5f4 | 2017-11-29 19:58:10 +0000 | [diff] [blame] | 2509 | SDValue |
| 2510 | HexagonTargetLowering::LowerINSERT_SUBVECTOR(SDValue Op, |
| 2511 | SelectionDAG &DAG) const { |
| 2512 | SDValue ValV = Op.getOperand(1); |
| 2513 | return insertVector(Op.getOperand(0), ValV, Op.getOperand(2), |
| 2514 | SDLoc(Op), ty(ValV), DAG); |
| Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2515 | } |
| 2516 | |
| Tim Northover | a441585 | 2013-08-06 09:12:35 +0000 | [diff] [blame] | 2517 | bool |
| 2518 | HexagonTargetLowering::allowTruncateForTailCall(Type *Ty1, Type *Ty2) const { |
| 2519 | // Assuming the caller does not have either a signext or zeroext modifier, and |
| 2520 | // only one value is accepted, any reasonable truncation is allowed. |
| 2521 | if (!Ty1->isIntegerTy() || !Ty2->isIntegerTy()) |
| 2522 | return false; |
| 2523 | |
| 2524 | // FIXME: in principle up to 64-bit could be made safe, but it would be very |
| 2525 | // fragile at the moment: any support for multiple value returns would be |
| 2526 | // liable to disallow tail calls involving i64 -> iN truncation in many cases. |
| 2527 | return Ty1->getPrimitiveSizeInBits() <= 32; |
| 2528 | } |
| 2529 | |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 2530 | SDValue |
| Jyotsna Verma | 5ed5181 | 2013-05-01 21:37:34 +0000 | [diff] [blame] | 2531 | HexagonTargetLowering::LowerEH_RETURN(SDValue Op, SelectionDAG &DAG) const { |
| 2532 | SDValue Chain = Op.getOperand(0); |
| 2533 | SDValue Offset = Op.getOperand(1); |
| 2534 | SDValue Handler = Op.getOperand(2); |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 2535 | SDLoc dl(Op); |
| Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 2536 | auto PtrVT = getPointerTy(DAG.getDataLayout()); |
| Jyotsna Verma | 5ed5181 | 2013-05-01 21:37:34 +0000 | [diff] [blame] | 2537 | |
| 2538 | // Mark function as containing a call to EH_RETURN. |
| 2539 | HexagonMachineFunctionInfo *FuncInfo = |
| 2540 | DAG.getMachineFunction().getInfo<HexagonMachineFunctionInfo>(); |
| 2541 | FuncInfo->setHasEHReturn(); |
| 2542 | |
| 2543 | unsigned OffsetReg = Hexagon::R28; |
| 2544 | |
| Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 2545 | SDValue StoreAddr = |
| 2546 | DAG.getNode(ISD::ADD, dl, PtrVT, DAG.getRegister(Hexagon::R30, PtrVT), |
| 2547 | DAG.getIntPtrConstant(4, dl)); |
| Justin Lebar | 9c37581 | 2016-07-15 18:27:10 +0000 | [diff] [blame] | 2548 | Chain = DAG.getStore(Chain, dl, Handler, StoreAddr, MachinePointerInfo()); |
| Jyotsna Verma | 5ed5181 | 2013-05-01 21:37:34 +0000 | [diff] [blame] | 2549 | Chain = DAG.getCopyToReg(Chain, dl, OffsetReg, Offset); |
| 2550 | |
| 2551 | // Not needed we already use it as explict input to EH_RETURN. |
| 2552 | // MF.getRegInfo().addLiveOut(OffsetReg); |
| 2553 | |
| 2554 | return DAG.getNode(HexagonISD::EH_RETURN, dl, MVT::Other, Chain); |
| 2555 | } |
| 2556 | |
| 2557 | SDValue |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 2558 | HexagonTargetLowering::LowerOperation(SDValue Op, SelectionDAG &DAG) const { |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 2559 | unsigned Opc = Op.getOpcode(); |
| Krzysztof Parzyszek | 88f1100 | 2018-02-06 14:24:57 +0000 | [diff] [blame] | 2560 | |
| 2561 | // Handle INLINEASM first. |
| 2562 | if (Opc == ISD::INLINEASM) |
| 2563 | return LowerINLINEASM(Op, DAG); |
| 2564 | |
| 2565 | if (isHvxOperation(Op)) |
| 2566 | return LowerHvxOperation(Op, DAG); |
| 2567 | |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 2568 | switch (Opc) { |
| 2569 | default: |
| 2570 | #ifndef NDEBUG |
| 2571 | Op.getNode()->dumpr(&DAG); |
| 2572 | if (Opc > HexagonISD::OP_BEGIN && Opc < HexagonISD::OP_END) |
| Krzysztof Parzyszek | e4ce92c | 2017-12-20 20:49:43 +0000 | [diff] [blame] | 2573 | errs() << "Error: check for a non-legal type in this operation\n"; |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 2574 | #endif |
| 2575 | llvm_unreachable("Should not custom lower this!"); |
| 2576 | case ISD::CONCAT_VECTORS: return LowerCONCAT_VECTORS(Op, DAG); |
| Krzysztof Parzyszek | 6a8e5f4 | 2017-11-29 19:58:10 +0000 | [diff] [blame] | 2577 | case ISD::INSERT_SUBVECTOR: return LowerINSERT_SUBVECTOR(Op, DAG); |
| 2578 | case ISD::INSERT_VECTOR_ELT: return LowerINSERT_VECTOR_ELT(Op, DAG); |
| 2579 | case ISD::EXTRACT_SUBVECTOR: return LowerEXTRACT_SUBVECTOR(Op, DAG); |
| 2580 | case ISD::EXTRACT_VECTOR_ELT: return LowerEXTRACT_VECTOR_ELT(Op, DAG); |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 2581 | case ISD::BUILD_VECTOR: return LowerBUILD_VECTOR(Op, DAG); |
| 2582 | case ISD::VECTOR_SHUFFLE: return LowerVECTOR_SHUFFLE(Op, DAG); |
| Krzysztof Parzyszek | 3780a0e | 2018-01-23 17:53:59 +0000 | [diff] [blame] | 2583 | case ISD::BITCAST: return LowerBITCAST(Op, DAG); |
| Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2584 | case ISD::SRA: |
| 2585 | case ISD::SHL: |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 2586 | case ISD::SRL: return LowerVECTOR_SHIFT(Op, DAG); |
| 2587 | case ISD::ConstantPool: return LowerConstantPool(Op, DAG); |
| Krzysztof Parzyszek | 21dc8bd | 2015-12-18 20:19:30 +0000 | [diff] [blame] | 2588 | case ISD::JumpTable: return LowerJumpTable(Op, DAG); |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 2589 | case ISD::EH_RETURN: return LowerEH_RETURN(Op, DAG); |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 2590 | case ISD::RETURNADDR: return LowerRETURNADDR(Op, DAG); |
| 2591 | case ISD::FRAMEADDR: return LowerFRAMEADDR(Op, DAG); |
| Krzysztof Parzyszek | 7a737d1 | 2016-02-18 15:42:57 +0000 | [diff] [blame] | 2592 | case ISD::GlobalTLSAddress: return LowerGlobalTLSAddress(Op, DAG); |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 2593 | case ISD::ATOMIC_FENCE: return LowerATOMIC_FENCE(Op, DAG); |
| 2594 | case ISD::GlobalAddress: return LowerGLOBALADDRESS(Op, DAG); |
| 2595 | case ISD::BlockAddress: return LowerBlockAddress(Op, DAG); |
| Krzysztof Parzyszek | 21dc8bd | 2015-12-18 20:19:30 +0000 | [diff] [blame] | 2596 | case ISD::GLOBAL_OFFSET_TABLE: return LowerGLOBAL_OFFSET_TABLE(Op, DAG); |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 2597 | case ISD::VASTART: return LowerVASTART(Op, DAG); |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 2598 | case ISD::DYNAMIC_STACKALLOC: return LowerDYNAMIC_STACKALLOC(Op, DAG); |
| 2599 | case ISD::SETCC: return LowerSETCC(Op, DAG); |
| 2600 | case ISD::VSELECT: return LowerVSELECT(Op, DAG); |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 2601 | case ISD::INTRINSIC_WO_CHAIN: return LowerINTRINSIC_WO_CHAIN(Op, DAG); |
| Krzysztof Parzyszek | 6895b2c | 2016-02-18 13:58:38 +0000 | [diff] [blame] | 2602 | case ISD::INTRINSIC_VOID: return LowerINTRINSIC_VOID(Op, DAG); |
| Krzysztof Parzyszek | 6895b2c | 2016-02-18 13:58:38 +0000 | [diff] [blame] | 2603 | case ISD::PREFETCH: return LowerPREFETCH(Op, DAG); |
| Krzysztof Parzyszek | ab57c2b | 2017-02-22 22:28:47 +0000 | [diff] [blame] | 2604 | case ISD::READCYCLECOUNTER: return LowerREADCYCLECOUNTER(Op, DAG); |
| Krzysztof Parzyszek | 9eb085e | 2018-01-31 20:48:11 +0000 | [diff] [blame] | 2605 | break; |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 2606 | } |
| Krzysztof Parzyszek | 88f1100 | 2018-02-06 14:24:57 +0000 | [diff] [blame] | 2607 | |
| Krzysztof Parzyszek | 7d37dd8 | 2017-12-06 16:40:37 +0000 | [diff] [blame] | 2608 | return SDValue(); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 2609 | } |
| 2610 | |
| Krzysztof Parzyszek | 3780a0e | 2018-01-23 17:53:59 +0000 | [diff] [blame] | 2611 | void |
| 2612 | HexagonTargetLowering::ReplaceNodeResults(SDNode *N, |
| 2613 | SmallVectorImpl<SDValue> &Results, |
| 2614 | SelectionDAG &DAG) const { |
| 2615 | const SDLoc &dl(N); |
| 2616 | switch (N->getOpcode()) { |
| 2617 | case ISD::SRL: |
| 2618 | case ISD::SRA: |
| 2619 | case ISD::SHL: |
| 2620 | return; |
| 2621 | case ISD::BITCAST: |
| 2622 | // Handle a bitcast from v8i1 to i8. |
| 2623 | if (N->getValueType(0) == MVT::i8) { |
| Krzysztof Parzyszek | 15efa98 | 2018-01-31 21:17:03 +0000 | [diff] [blame] | 2624 | SDValue P = getInstr(Hexagon::C2_tfrpr, dl, MVT::i32, |
| 2625 | N->getOperand(0), DAG); |
| Krzysztof Parzyszek | 3780a0e | 2018-01-23 17:53:59 +0000 | [diff] [blame] | 2626 | Results.push_back(P); |
| 2627 | } |
| 2628 | break; |
| 2629 | } |
| 2630 | } |
| 2631 | |
| Krzysztof Parzyszek | 21dc8bd | 2015-12-18 20:19:30 +0000 | [diff] [blame] | 2632 | /// Returns relocation base for the given PIC jumptable. |
| 2633 | SDValue |
| 2634 | HexagonTargetLowering::getPICJumpTableRelocBase(SDValue Table, |
| 2635 | SelectionDAG &DAG) const { |
| 2636 | int Idx = cast<JumpTableSDNode>(Table)->getIndex(); |
| 2637 | EVT VT = Table.getValueType(); |
| 2638 | SDValue T = DAG.getTargetJumpTable(Idx, VT, HexagonII::MO_PCREL); |
| 2639 | return DAG.getNode(HexagonISD::AT_PCREL, SDLoc(Table), VT, T); |
| 2640 | } |
| 2641 | |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 2642 | //===----------------------------------------------------------------------===// |
| 2643 | // Inline Assembly Support |
| 2644 | //===----------------------------------------------------------------------===// |
| 2645 | |
| Krzysztof Parzyszek | ca3b532 | 2016-05-18 14:34:51 +0000 | [diff] [blame] | 2646 | TargetLowering::ConstraintType |
| 2647 | HexagonTargetLowering::getConstraintType(StringRef Constraint) const { |
| 2648 | if (Constraint.size() == 1) { |
| 2649 | switch (Constraint[0]) { |
| 2650 | case 'q': |
| 2651 | case 'v': |
| 2652 | if (Subtarget.useHVXOps()) |
| Krzysztof Parzyszek | 3ad0d01 | 2017-07-21 17:51:27 +0000 | [diff] [blame] | 2653 | return C_RegisterClass; |
| 2654 | break; |
| 2655 | case 'a': |
| 2656 | return C_RegisterClass; |
| 2657 | default: |
| Krzysztof Parzyszek | ca3b532 | 2016-05-18 14:34:51 +0000 | [diff] [blame] | 2658 | break; |
| 2659 | } |
| 2660 | } |
| 2661 | return TargetLowering::getConstraintType(Constraint); |
| 2662 | } |
| 2663 | |
| Krzysztof Parzyszek | fb4c417 | 2016-08-19 19:29:15 +0000 | [diff] [blame] | 2664 | std::pair<unsigned, const TargetRegisterClass*> |
| Eric Christopher | 11e4df7 | 2015-02-26 22:38:43 +0000 | [diff] [blame] | 2665 | HexagonTargetLowering::getRegForInlineAsmConstraint( |
| Benjamin Kramer | 9bfb627 | 2015-07-05 19:29:18 +0000 | [diff] [blame] | 2666 | const TargetRegisterInfo *TRI, StringRef Constraint, MVT VT) const { |
| Krzysztof Parzyszek | 08ff888 | 2015-11-26 18:38:27 +0000 | [diff] [blame] | 2667 | |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 2668 | if (Constraint.size() == 1) { |
| 2669 | switch (Constraint[0]) { |
| 2670 | case 'r': // R0-R31 |
| Krzysztof Parzyszek | fb4c417 | 2016-08-19 19:29:15 +0000 | [diff] [blame] | 2671 | switch (VT.SimpleTy) { |
| 2672 | default: |
| Krzysztof Parzyszek | 022922b | 2017-10-20 20:24:44 +0000 | [diff] [blame] | 2673 | return {0u, nullptr}; |
| Krzysztof Parzyszek | fb4c417 | 2016-08-19 19:29:15 +0000 | [diff] [blame] | 2674 | case MVT::i1: |
| 2675 | case MVT::i8: |
| 2676 | case MVT::i16: |
| 2677 | case MVT::i32: |
| 2678 | case MVT::f32: |
| Krzysztof Parzyszek | 022922b | 2017-10-20 20:24:44 +0000 | [diff] [blame] | 2679 | return {0u, &Hexagon::IntRegsRegClass}; |
| Krzysztof Parzyszek | fb4c417 | 2016-08-19 19:29:15 +0000 | [diff] [blame] | 2680 | case MVT::i64: |
| 2681 | case MVT::f64: |
| Krzysztof Parzyszek | 022922b | 2017-10-20 20:24:44 +0000 | [diff] [blame] | 2682 | return {0u, &Hexagon::DoubleRegsRegClass}; |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 2683 | } |
| Krzysztof Parzyszek | 3ad0d01 | 2017-07-21 17:51:27 +0000 | [diff] [blame] | 2684 | break; |
| 2685 | case 'a': // M0-M1 |
| Krzysztof Parzyszek | 022922b | 2017-10-20 20:24:44 +0000 | [diff] [blame] | 2686 | if (VT != MVT::i32) |
| 2687 | return {0u, nullptr}; |
| 2688 | return {0u, &Hexagon::ModRegsRegClass}; |
| Krzysztof Parzyszek | 08ff888 | 2015-11-26 18:38:27 +0000 | [diff] [blame] | 2689 | case 'q': // q0-q3 |
| Krzysztof Parzyszek | fcbb7d1 | 2017-03-02 17:50:24 +0000 | [diff] [blame] | 2690 | switch (VT.getSizeInBits()) { |
| Krzysztof Parzyszek | fb4c417 | 2016-08-19 19:29:15 +0000 | [diff] [blame] | 2691 | default: |
| Krzysztof Parzyszek | 022922b | 2017-10-20 20:24:44 +0000 | [diff] [blame] | 2692 | return {0u, nullptr}; |
| Krzysztof Parzyszek | fcbb7d1 | 2017-03-02 17:50:24 +0000 | [diff] [blame] | 2693 | case 512: |
| Krzysztof Parzyszek | fcbb7d1 | 2017-03-02 17:50:24 +0000 | [diff] [blame] | 2694 | case 1024: |
| Krzysztof Parzyszek | 022922b | 2017-10-20 20:24:44 +0000 | [diff] [blame] | 2695 | return {0u, &Hexagon::HvxQRRegClass}; |
| Krzysztof Parzyszek | fb4c417 | 2016-08-19 19:29:15 +0000 | [diff] [blame] | 2696 | } |
| Krzysztof Parzyszek | 3ad0d01 | 2017-07-21 17:51:27 +0000 | [diff] [blame] | 2697 | break; |
| Krzysztof Parzyszek | 08ff888 | 2015-11-26 18:38:27 +0000 | [diff] [blame] | 2698 | case 'v': // V0-V31 |
| Krzysztof Parzyszek | fcbb7d1 | 2017-03-02 17:50:24 +0000 | [diff] [blame] | 2699 | switch (VT.getSizeInBits()) { |
| Krzysztof Parzyszek | fb4c417 | 2016-08-19 19:29:15 +0000 | [diff] [blame] | 2700 | default: |
| Krzysztof Parzyszek | 022922b | 2017-10-20 20:24:44 +0000 | [diff] [blame] | 2701 | return {0u, nullptr}; |
| Krzysztof Parzyszek | fcbb7d1 | 2017-03-02 17:50:24 +0000 | [diff] [blame] | 2702 | case 512: |
| Krzysztof Parzyszek | 022922b | 2017-10-20 20:24:44 +0000 | [diff] [blame] | 2703 | return {0u, &Hexagon::HvxVRRegClass}; |
| Krzysztof Parzyszek | fcbb7d1 | 2017-03-02 17:50:24 +0000 | [diff] [blame] | 2704 | case 1024: |
| Sumanth Gundapaneni | e1983bc | 2017-10-18 18:07:07 +0000 | [diff] [blame] | 2705 | if (Subtarget.hasV60TOps() && Subtarget.useHVX128BOps()) |
| Krzysztof Parzyszek | 022922b | 2017-10-20 20:24:44 +0000 | [diff] [blame] | 2706 | return {0u, &Hexagon::HvxVRRegClass}; |
| 2707 | return {0u, &Hexagon::HvxWRRegClass}; |
| Krzysztof Parzyszek | fcbb7d1 | 2017-03-02 17:50:24 +0000 | [diff] [blame] | 2708 | case 2048: |
| Krzysztof Parzyszek | 022922b | 2017-10-20 20:24:44 +0000 | [diff] [blame] | 2709 | return {0u, &Hexagon::HvxWRRegClass}; |
| Krzysztof Parzyszek | fb4c417 | 2016-08-19 19:29:15 +0000 | [diff] [blame] | 2710 | } |
| Krzysztof Parzyszek | 3ad0d01 | 2017-07-21 17:51:27 +0000 | [diff] [blame] | 2711 | break; |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 2712 | default: |
| Krzysztof Parzyszek | 022922b | 2017-10-20 20:24:44 +0000 | [diff] [blame] | 2713 | return {0u, nullptr}; |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 2714 | } |
| 2715 | } |
| 2716 | |
| Eric Christopher | 11e4df7 | 2015-02-26 22:38:43 +0000 | [diff] [blame] | 2717 | return TargetLowering::getRegForInlineAsmConstraint(TRI, Constraint, VT); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 2718 | } |
| 2719 | |
| Sirish Pande | 69295b8 | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 2720 | /// isFPImmLegal - Returns true if the target can instruction select the |
| 2721 | /// specified FP immediate natively. If false, the legalizer will |
| 2722 | /// materialize the FP immediate as a load from a constant pool. |
| 2723 | bool HexagonTargetLowering::isFPImmLegal(const APFloat &Imm, EVT VT) const { |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 2724 | return Subtarget.hasV5TOps(); |
| Sirish Pande | 69295b8 | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 2725 | } |
| 2726 | |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 2727 | /// isLegalAddressingMode - Return true if the addressing mode represented by |
| 2728 | /// AM is legal for this target, for a load/store of the specified type. |
| Mehdi Amini | 0cdec1e | 2015-07-09 02:09:40 +0000 | [diff] [blame] | 2729 | bool HexagonTargetLowering::isLegalAddressingMode(const DataLayout &DL, |
| 2730 | const AddrMode &AM, Type *Ty, |
| Jonas Paulsson | 024e319 | 2017-07-21 11:59:37 +0000 | [diff] [blame] | 2731 | unsigned AS, Instruction *I) const { |
| Krzysztof Parzyszek | ed4e782 | 2016-08-03 15:06:18 +0000 | [diff] [blame] | 2732 | if (Ty->isSized()) { |
| 2733 | // When LSR detects uses of the same base address to access different |
| 2734 | // types (e.g. unions), it will assume a conservative type for these |
| 2735 | // uses: |
| 2736 | // LSR Use: Kind=Address of void in addrspace(4294967295), ... |
| 2737 | // The type Ty passed here would then be "void". Skip the alignment |
| 2738 | // checks, but do not return false right away, since that confuses |
| 2739 | // LSR into crashing. |
| 2740 | unsigned A = DL.getABITypeAlignment(Ty); |
| 2741 | // The base offset must be a multiple of the alignment. |
| 2742 | if ((AM.BaseOffs % A) != 0) |
| 2743 | return false; |
| 2744 | // The shifted offset must fit in 11 bits. |
| 2745 | if (!isInt<11>(AM.BaseOffs >> Log2_32(A))) |
| 2746 | return false; |
| 2747 | } |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 2748 | |
| 2749 | // No global is ever allowed as a base. |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 2750 | if (AM.BaseGV) |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 2751 | return false; |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 2752 | |
| 2753 | int Scale = AM.Scale; |
| Krzysztof Parzyszek | 317d42c | 2016-08-01 20:31:50 +0000 | [diff] [blame] | 2754 | if (Scale < 0) |
| 2755 | Scale = -Scale; |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 2756 | switch (Scale) { |
| 2757 | case 0: // No scale reg, "r+i", "r", or just "i". |
| 2758 | break; |
| 2759 | default: // No scaled addressing mode. |
| 2760 | return false; |
| 2761 | } |
| 2762 | return true; |
| 2763 | } |
| 2764 | |
| Krzysztof Parzyszek | 21dc8bd | 2015-12-18 20:19:30 +0000 | [diff] [blame] | 2765 | /// Return true if folding a constant offset with the given GlobalAddress is |
| 2766 | /// legal. It is frequently not legal in PIC relocation models. |
| 2767 | bool HexagonTargetLowering::isOffsetFoldingLegal(const GlobalAddressSDNode *GA) |
| 2768 | const { |
| 2769 | return HTM.getRelocationModel() == Reloc::Static; |
| 2770 | } |
| 2771 | |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 2772 | /// isLegalICmpImmediate - Return true if the specified immediate is legal |
| 2773 | /// icmp immediate, that is the target has icmp instructions which can compare |
| 2774 | /// a register against the immediate without having to materialize the |
| 2775 | /// immediate into a register. |
| 2776 | bool HexagonTargetLowering::isLegalICmpImmediate(int64_t Imm) const { |
| 2777 | return Imm >= -512 && Imm <= 511; |
| 2778 | } |
| 2779 | |
| 2780 | /// IsEligibleForTailCallOptimization - Check whether the call is eligible |
| 2781 | /// for tail call optimization. Targets which want to do tail call |
| 2782 | /// optimization should implement this function. |
| 2783 | bool HexagonTargetLowering::IsEligibleForTailCallOptimization( |
| 2784 | SDValue Callee, |
| 2785 | CallingConv::ID CalleeCC, |
| Krzysztof Parzyszek | cfbe6ba | 2018-02-13 15:35:07 +0000 | [diff] [blame] | 2786 | bool IsVarArg, |
| 2787 | bool IsCalleeStructRet, |
| 2788 | bool IsCallerStructRet, |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 2789 | const SmallVectorImpl<ISD::OutputArg> &Outs, |
| 2790 | const SmallVectorImpl<SDValue> &OutVals, |
| 2791 | const SmallVectorImpl<ISD::InputArg> &Ins, |
| 2792 | SelectionDAG& DAG) const { |
| Matthias Braun | f1caa28 | 2017-12-15 22:22:58 +0000 | [diff] [blame] | 2793 | const Function &CallerF = DAG.getMachineFunction().getFunction(); |
| 2794 | CallingConv::ID CallerCC = CallerF.getCallingConv(); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 2795 | bool CCMatch = CallerCC == CalleeCC; |
| 2796 | |
| 2797 | // *************************************************************************** |
| 2798 | // Look for obvious safe cases to perform tail call optimization that do not |
| 2799 | // require ABI changes. |
| 2800 | // *************************************************************************** |
| 2801 | |
| 2802 | // If this is a tail call via a function pointer, then don't do it! |
| Krzysztof Parzyszek | 317d42c | 2016-08-01 20:31:50 +0000 | [diff] [blame] | 2803 | if (!isa<GlobalAddressSDNode>(Callee) && |
| 2804 | !isa<ExternalSymbolSDNode>(Callee)) { |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 2805 | return false; |
| 2806 | } |
| 2807 | |
| Krzysztof Parzyszek | 0ba9754 | 2016-08-19 15:02:18 +0000 | [diff] [blame] | 2808 | // Do not optimize if the calling conventions do not match and the conventions |
| 2809 | // used are not C or Fast. |
| 2810 | if (!CCMatch) { |
| 2811 | bool R = (CallerCC == CallingConv::C || CallerCC == CallingConv::Fast); |
| 2812 | bool E = (CalleeCC == CallingConv::C || CalleeCC == CallingConv::Fast); |
| 2813 | // If R & E, then ok. |
| 2814 | if (!R || !E) |
| 2815 | return false; |
| 2816 | } |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 2817 | |
| 2818 | // Do not tail call optimize vararg calls. |
| Krzysztof Parzyszek | cfbe6ba | 2018-02-13 15:35:07 +0000 | [diff] [blame] | 2819 | if (IsVarArg) |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 2820 | return false; |
| 2821 | |
| 2822 | // Also avoid tail call optimization if either caller or callee uses struct |
| 2823 | // return semantics. |
| Krzysztof Parzyszek | cfbe6ba | 2018-02-13 15:35:07 +0000 | [diff] [blame] | 2824 | if (IsCalleeStructRet || IsCallerStructRet) |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 2825 | return false; |
| 2826 | |
| 2827 | // In addition to the cases above, we also disable Tail Call Optimization if |
| 2828 | // the calling convention code that at least one outgoing argument needs to |
| 2829 | // go on the stack. We cannot check that here because at this point that |
| 2830 | // information is not available. |
| 2831 | return true; |
| 2832 | } |
| Colin LeMahieu | 025f860 | 2014-12-08 21:19:18 +0000 | [diff] [blame] | 2833 | |
| Krzysztof Parzyszek | 3e409e1 | 2016-08-02 18:34:31 +0000 | [diff] [blame] | 2834 | /// Returns the target specific optimal type for load and store operations as |
| 2835 | /// a result of memset, memcpy, and memmove lowering. |
| 2836 | /// |
| 2837 | /// If DstAlign is zero that means it's safe to destination alignment can |
| 2838 | /// satisfy any constraint. Similarly if SrcAlign is zero it means there isn't |
| 2839 | /// a need to check it against alignment requirement, probably because the |
| 2840 | /// source does not need to be loaded. If 'IsMemset' is true, that means it's |
| 2841 | /// expanding a memset. If 'ZeroMemset' is true, that means it's a memset of |
| 2842 | /// zero. 'MemcpyStrSrc' indicates whether the memcpy source is constant so it |
| 2843 | /// does not need to be loaded. It returns EVT::Other if the type should be |
| 2844 | /// determined using generic target-independent logic. |
| 2845 | EVT HexagonTargetLowering::getOptimalMemOpType(uint64_t Size, |
| 2846 | unsigned DstAlign, unsigned SrcAlign, bool IsMemset, bool ZeroMemset, |
| 2847 | bool MemcpyStrSrc, MachineFunction &MF) const { |
| 2848 | |
| 2849 | auto Aligned = [](unsigned GivenA, unsigned MinA) -> bool { |
| 2850 | return (GivenA % MinA) == 0; |
| 2851 | }; |
| 2852 | |
| 2853 | if (Size >= 8 && Aligned(DstAlign, 8) && (IsMemset || Aligned(SrcAlign, 8))) |
| 2854 | return MVT::i64; |
| 2855 | if (Size >= 4 && Aligned(DstAlign, 4) && (IsMemset || Aligned(SrcAlign, 4))) |
| 2856 | return MVT::i32; |
| 2857 | if (Size >= 2 && Aligned(DstAlign, 2) && (IsMemset || Aligned(SrcAlign, 2))) |
| 2858 | return MVT::i16; |
| 2859 | |
| 2860 | return MVT::Other; |
| 2861 | } |
| 2862 | |
| Krzysztof Parzyszek | 2d65ea7 | 2016-03-28 15:43:03 +0000 | [diff] [blame] | 2863 | bool HexagonTargetLowering::allowsMisalignedMemoryAccesses(EVT VT, |
| 2864 | unsigned AS, unsigned Align, bool *Fast) const { |
| 2865 | if (Fast) |
| 2866 | *Fast = false; |
| Krzysztof Parzyszek | cfbe6ba | 2018-02-13 15:35:07 +0000 | [diff] [blame] | 2867 | return Subtarget.isHVXVectorType(VT.getSimpleVT()); |
| Krzysztof Parzyszek | 2d65ea7 | 2016-03-28 15:43:03 +0000 | [diff] [blame] | 2868 | } |
| 2869 | |
| Krzysztof Parzyszek | 08ff888 | 2015-11-26 18:38:27 +0000 | [diff] [blame] | 2870 | std::pair<const TargetRegisterClass*, uint8_t> |
| 2871 | HexagonTargetLowering::findRepresentativeClass(const TargetRegisterInfo *TRI, |
| 2872 | MVT VT) const { |
| Krzysztof Parzyszek | cfbe6ba | 2018-02-13 15:35:07 +0000 | [diff] [blame] | 2873 | if (Subtarget.isHVXVectorType(VT, true)) { |
| 2874 | unsigned BitWidth = VT.getSizeInBits(); |
| 2875 | unsigned VecWidth = Subtarget.getVectorLength() * 8; |
| Krzysztof Parzyszek | 08ff888 | 2015-11-26 18:38:27 +0000 | [diff] [blame] | 2876 | |
| Krzysztof Parzyszek | cfbe6ba | 2018-02-13 15:35:07 +0000 | [diff] [blame] | 2877 | if (VT.getVectorElementType() == MVT::i1) |
| 2878 | return std::make_pair(&Hexagon::HvxQRRegClass, 1); |
| 2879 | if (BitWidth == VecWidth) |
| 2880 | return std::make_pair(&Hexagon::HvxVRRegClass, 1); |
| 2881 | assert(BitWidth == 2 * VecWidth); |
| 2882 | return std::make_pair(&Hexagon::HvxWRRegClass, 1); |
| Krzysztof Parzyszek | 08ff888 | 2015-11-26 18:38:27 +0000 | [diff] [blame] | 2883 | } |
| Krzysztof Parzyszek | cfbe6ba | 2018-02-13 15:35:07 +0000 | [diff] [blame] | 2884 | |
| 2885 | return TargetLowering::findRepresentativeClass(TRI, VT); |
| Krzysztof Parzyszek | 08ff888 | 2015-11-26 18:38:27 +0000 | [diff] [blame] | 2886 | } |
| 2887 | |
| Krzysztof Parzyszek | feaf7b8 | 2015-07-09 14:51:21 +0000 | [diff] [blame] | 2888 | Value *HexagonTargetLowering::emitLoadLinked(IRBuilder<> &Builder, Value *Addr, |
| 2889 | AtomicOrdering Ord) const { |
| 2890 | BasicBlock *BB = Builder.GetInsertBlock(); |
| 2891 | Module *M = BB->getParent()->getParent(); |
| 2892 | Type *Ty = cast<PointerType>(Addr->getType())->getElementType(); |
| 2893 | unsigned SZ = Ty->getPrimitiveSizeInBits(); |
| 2894 | assert((SZ == 32 || SZ == 64) && "Only 32/64-bit atomic loads supported"); |
| 2895 | Intrinsic::ID IntID = (SZ == 32) ? Intrinsic::hexagon_L2_loadw_locked |
| 2896 | : Intrinsic::hexagon_L4_loadd_locked; |
| 2897 | Value *Fn = Intrinsic::getDeclaration(M, IntID); |
| 2898 | return Builder.CreateCall(Fn, Addr, "larx"); |
| 2899 | } |
| 2900 | |
| 2901 | /// Perform a store-conditional operation to Addr. Return the status of the |
| 2902 | /// store. This should be 0 if the store succeeded, non-zero otherwise. |
| 2903 | Value *HexagonTargetLowering::emitStoreConditional(IRBuilder<> &Builder, |
| 2904 | Value *Val, Value *Addr, AtomicOrdering Ord) const { |
| 2905 | BasicBlock *BB = Builder.GetInsertBlock(); |
| 2906 | Module *M = BB->getParent()->getParent(); |
| 2907 | Type *Ty = Val->getType(); |
| 2908 | unsigned SZ = Ty->getPrimitiveSizeInBits(); |
| 2909 | assert((SZ == 32 || SZ == 64) && "Only 32/64-bit atomic stores supported"); |
| 2910 | Intrinsic::ID IntID = (SZ == 32) ? Intrinsic::hexagon_S2_storew_locked |
| 2911 | : Intrinsic::hexagon_S4_stored_locked; |
| 2912 | Value *Fn = Intrinsic::getDeclaration(M, IntID); |
| 2913 | Value *Call = Builder.CreateCall(Fn, {Addr, Val}, "stcx"); |
| 2914 | Value *Cmp = Builder.CreateICmpEQ(Call, Builder.getInt32(0), ""); |
| 2915 | Value *Ext = Builder.CreateZExt(Cmp, Type::getInt32Ty(M->getContext())); |
| 2916 | return Ext; |
| 2917 | } |
| 2918 | |
| Ahmed Bougacha | 5246867 | 2015-09-11 17:08:28 +0000 | [diff] [blame] | 2919 | TargetLowering::AtomicExpansionKind |
| 2920 | HexagonTargetLowering::shouldExpandAtomicLoadInIR(LoadInst *LI) const { |
| Krzysztof Parzyszek | feaf7b8 | 2015-07-09 14:51:21 +0000 | [diff] [blame] | 2921 | // Do not expand loads and stores that don't exceed 64 bits. |
| Ahmed Bougacha | 5246867 | 2015-09-11 17:08:28 +0000 | [diff] [blame] | 2922 | return LI->getType()->getPrimitiveSizeInBits() > 64 |
| Tim Northover | f520eff | 2015-12-02 18:12:57 +0000 | [diff] [blame] | 2923 | ? AtomicExpansionKind::LLOnly |
| Ahmed Bougacha | 5246867 | 2015-09-11 17:08:28 +0000 | [diff] [blame] | 2924 | : AtomicExpansionKind::None; |
| Krzysztof Parzyszek | feaf7b8 | 2015-07-09 14:51:21 +0000 | [diff] [blame] | 2925 | } |
| 2926 | |
| 2927 | bool HexagonTargetLowering::shouldExpandAtomicStoreInIR(StoreInst *SI) const { |
| 2928 | // Do not expand loads and stores that don't exceed 64 bits. |
| 2929 | return SI->getValueOperand()->getType()->getPrimitiveSizeInBits() > 64; |
| 2930 | } |
| Krzysztof Parzyszek | f228c95 | 2016-06-22 16:07:10 +0000 | [diff] [blame] | 2931 | |
| 2932 | bool HexagonTargetLowering::shouldExpandAtomicCmpXchgInIR( |
| 2933 | AtomicCmpXchgInst *AI) const { |
| 2934 | const DataLayout &DL = AI->getModule()->getDataLayout(); |
| 2935 | unsigned Size = DL.getTypeStoreSize(AI->getCompareOperand()->getType()); |
| 2936 | return Size >= 4 && Size <= 8; |
| 2937 | } |