| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1 | //===-- HexagonISelLowering.cpp - Hexagon DAG Lowering Implementation -----===// |
| 2 | // |
| Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | // |
| 9 | // This file implements the interfaces that Hexagon uses to lower LLVM code |
| 10 | // into a selection DAG. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "HexagonISelLowering.h" |
| Chandler Carruth | 6bda14b | 2017-06-06 11:49:48 +0000 | [diff] [blame] | 15 | #include "Hexagon.h" |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 16 | #include "HexagonMachineFunctionInfo.h" |
| Eugene Zelenko | 58655bb | 2016-12-17 01:09:05 +0000 | [diff] [blame] | 17 | #include "HexagonRegisterInfo.h" |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 18 | #include "HexagonSubtarget.h" |
| Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 19 | #include "HexagonTargetMachine.h" |
| 20 | #include "HexagonTargetObjectFile.h" |
| Eugene Zelenko | 58655bb | 2016-12-17 01:09:05 +0000 | [diff] [blame] | 21 | #include "llvm/ADT/APInt.h" |
| 22 | #include "llvm/ADT/ArrayRef.h" |
| 23 | #include "llvm/ADT/SmallVector.h" |
| Sid Manning | 9ad0f02 | 2018-09-07 13:36:21 +0000 | [diff] [blame] | 24 | #include "llvm/ADT/StringSwitch.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" |
| Craig Topper | 2fa1436 | 2018-03-29 17:21:10 +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" |
| Krzysztof Parzyszek | dc7a557 | 2018-03-29 13:52:46 +0000 | [diff] [blame] | 43 | #include "llvm/IR/IntrinsicInst.h" |
| Eugene Zelenko | 58655bb | 2016-12-17 01:09:05 +0000 | [diff] [blame] | 44 | #include "llvm/IR/Module.h" |
| 45 | #include "llvm/IR/Type.h" |
| 46 | #include "llvm/IR/Value.h" |
| 47 | #include "llvm/MC/MCRegisterInfo.h" |
| 48 | #include "llvm/Support/Casting.h" |
| 49 | #include "llvm/Support/CodeGen.h" |
| NAKAMURA Takumi | 54eed76 | 2012-04-21 15:31:36 +0000 | [diff] [blame] | 50 | #include "llvm/Support/CommandLine.h" |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 51 | #include "llvm/Support/Debug.h" |
| 52 | #include "llvm/Support/ErrorHandling.h" |
| Eugene Zelenko | 58655bb | 2016-12-17 01:09:05 +0000 | [diff] [blame] | 53 | #include "llvm/Support/MathExtras.h" |
| NAKAMURA Takumi | e30303f | 2012-04-21 15:31:45 +0000 | [diff] [blame] | 54 | #include "llvm/Support/raw_ostream.h" |
| Eugene Zelenko | 58655bb | 2016-12-17 01:09:05 +0000 | [diff] [blame] | 55 | #include "llvm/Target/TargetMachine.h" |
| 56 | #include <algorithm> |
| 57 | #include <cassert> |
| 58 | #include <cstddef> |
| 59 | #include <cstdint> |
| 60 | #include <limits> |
| 61 | #include <utility> |
| NAKAMURA Takumi | 54eed76 | 2012-04-21 15:31:36 +0000 | [diff] [blame] | 62 | |
| Craig Topper | b25fda9 | 2012-03-17 18:46:09 +0000 | [diff] [blame] | 63 | using namespace llvm; |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 64 | |
| Chandler Carruth | e96dd89 | 2014-04-21 22:55:11 +0000 | [diff] [blame] | 65 | #define DEBUG_TYPE "hexagon-lowering" |
| 66 | |
| Krzysztof Parzyszek | 21dc8bd | 2015-12-18 20:19:30 +0000 | [diff] [blame] | 67 | static cl::opt<bool> EmitJumpTables("hexagon-emit-jump-tables", |
| 68 | cl::init(true), cl::Hidden, |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 69 | cl::desc("Control jump table emission on Hexagon target")); |
| 70 | |
| 71 | static cl::opt<bool> EnableHexSDNodeSched("enable-hexagon-sdnode-sched", |
| 72 | cl::Hidden, cl::ZeroOrMore, cl::init(false), |
| 73 | cl::desc("Enable Hexagon SDNode scheduling")); |
| 74 | |
| 75 | static cl::opt<bool> EnableFastMath("ffast-math", |
| 76 | cl::Hidden, cl::ZeroOrMore, cl::init(false), |
| 77 | cl::desc("Enable Fast Math processing")); |
| 78 | |
| 79 | static cl::opt<int> MinimumJumpTables("minimum-jump-tables", |
| 80 | cl::Hidden, cl::ZeroOrMore, cl::init(5), |
| 81 | cl::desc("Set minimum jump tables")); |
| 82 | |
| 83 | static cl::opt<int> MaxStoresPerMemcpyCL("max-store-memcpy", |
| 84 | cl::Hidden, cl::ZeroOrMore, cl::init(6), |
| 85 | cl::desc("Max #stores to inline memcpy")); |
| 86 | |
| 87 | static cl::opt<int> MaxStoresPerMemcpyOptSizeCL("max-store-memcpy-Os", |
| 88 | cl::Hidden, cl::ZeroOrMore, cl::init(4), |
| 89 | cl::desc("Max #stores to inline memcpy")); |
| 90 | |
| 91 | static cl::opt<int> MaxStoresPerMemmoveCL("max-store-memmove", |
| 92 | cl::Hidden, cl::ZeroOrMore, cl::init(6), |
| 93 | cl::desc("Max #stores to inline memmove")); |
| 94 | |
| 95 | static cl::opt<int> MaxStoresPerMemmoveOptSizeCL("max-store-memmove-Os", |
| 96 | cl::Hidden, cl::ZeroOrMore, cl::init(4), |
| 97 | cl::desc("Max #stores to inline memmove")); |
| 98 | |
| 99 | static cl::opt<int> MaxStoresPerMemsetCL("max-store-memset", |
| 100 | cl::Hidden, cl::ZeroOrMore, cl::init(8), |
| 101 | cl::desc("Max #stores to inline memset")); |
| 102 | |
| 103 | static cl::opt<int> MaxStoresPerMemsetOptSizeCL("max-store-memset-Os", |
| 104 | cl::Hidden, cl::ZeroOrMore, cl::init(4), |
| 105 | cl::desc("Max #stores to inline memset")); |
| 106 | |
| Krzysztof Parzyszek | 2c3edf0 | 2018-03-07 17:27:18 +0000 | [diff] [blame] | 107 | static cl::opt<bool> AlignLoads("hexagon-align-loads", |
| 108 | cl::Hidden, cl::init(false), |
| 109 | cl::desc("Rewrite unaligned loads as a pair of aligned loads")); |
| 110 | |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 111 | |
| Benjamin Kramer | 602bb4a | 2013-10-27 11:16:09 +0000 | [diff] [blame] | 112 | namespace { |
| Eugene Zelenko | 58655bb | 2016-12-17 01:09:05 +0000 | [diff] [blame] | 113 | |
| Krzysztof Parzyszek | 0bd55a7 | 2016-07-29 16:44:27 +0000 | [diff] [blame] | 114 | class HexagonCCState : public CCState { |
| Krzysztof Parzyszek | 18e0d2a | 2018-02-15 15:47:53 +0000 | [diff] [blame] | 115 | unsigned NumNamedVarArgParams = 0; |
| Benjamin Kramer | 602bb4a | 2013-10-27 11:16:09 +0000 | [diff] [blame] | 116 | |
| Krzysztof Parzyszek | 0bd55a7 | 2016-07-29 16:44:27 +0000 | [diff] [blame] | 117 | public: |
| Krzysztof Parzyszek | 7cfe7cb | 2018-02-09 15:30:02 +0000 | [diff] [blame] | 118 | HexagonCCState(CallingConv::ID CC, bool IsVarArg, MachineFunction &MF, |
| Krzysztof Parzyszek | 0bd55a7 | 2016-07-29 16:44:27 +0000 | [diff] [blame] | 119 | SmallVectorImpl<CCValAssign> &locs, LLVMContext &C, |
| Krzysztof Parzyszek | e0d7de7 | 2018-02-15 17:20:07 +0000 | [diff] [blame] | 120 | unsigned NumNamedArgs) |
| 121 | : CCState(CC, IsVarArg, MF, locs, C), |
| 122 | NumNamedVarArgParams(NumNamedArgs) {} |
| Krzysztof Parzyszek | 0bd55a7 | 2016-07-29 16:44:27 +0000 | [diff] [blame] | 123 | unsigned getNumNamedVarArgParams() const { return NumNamedVarArgParams; } |
| 124 | }; |
| 125 | |
| Eugene Zelenko | 58655bb | 2016-12-17 01:09:05 +0000 | [diff] [blame] | 126 | } // end anonymous namespace |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 127 | |
| Krzysztof Parzyszek | 7cfe7cb | 2018-02-09 15:30:02 +0000 | [diff] [blame] | 128 | |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 129 | // Implement calling convention for Hexagon. |
| Krzysztof Parzyszek | 08ff888 | 2015-11-26 18:38:27 +0000 | [diff] [blame] | 130 | |
| Krzysztof Parzyszek | 7cfe7cb | 2018-02-09 15:30:02 +0000 | [diff] [blame] | 131 | static bool CC_SkipOdd(unsigned &ValNo, MVT &ValVT, MVT &LocVT, |
| 132 | CCValAssign::LocInfo &LocInfo, |
| 133 | ISD::ArgFlagsTy &ArgFlags, CCState &State) { |
| 134 | static const MCPhysReg ArgRegs[] = { |
| 135 | Hexagon::R0, Hexagon::R1, Hexagon::R2, |
| 136 | Hexagon::R3, Hexagon::R4, Hexagon::R5 |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 137 | }; |
| Krzysztof Parzyszek | 7cfe7cb | 2018-02-09 15:30:02 +0000 | [diff] [blame] | 138 | const unsigned NumArgRegs = array_lengthof(ArgRegs); |
| 139 | unsigned RegNum = State.getFirstUnallocated(ArgRegs); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 140 | |
| Krzysztof Parzyszek | 7cfe7cb | 2018-02-09 15:30:02 +0000 | [diff] [blame] | 141 | // RegNum is an index into ArgRegs: skip a register if RegNum is odd. |
| 142 | if (RegNum != NumArgRegs && RegNum % 2 == 1) |
| 143 | State.AllocateReg(ArgRegs[RegNum]); |
| 144 | |
| 145 | // Always return false here, as this function only makes sure that the first |
| 146 | // unallocated register has an even register number and does not actually |
| 147 | // allocate a register for the current argument. |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 148 | return false; |
| 149 | } |
| 150 | |
| Krzysztof Parzyszek | 7cfe7cb | 2018-02-09 15:30:02 +0000 | [diff] [blame] | 151 | #include "HexagonGenCallingConv.inc" |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 152 | |
| Krzysztof Parzyszek | 08ff888 | 2015-11-26 18:38:27 +0000 | [diff] [blame] | 153 | |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 154 | SDValue |
| 155 | HexagonTargetLowering::LowerINTRINSIC_WO_CHAIN(SDValue Op, SelectionDAG &DAG) |
| Krzysztof Parzyszek | 317d42c | 2016-08-01 20:31:50 +0000 | [diff] [blame] | 156 | const { |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 157 | return SDValue(); |
| 158 | } |
| 159 | |
| 160 | /// CreateCopyOfByValArgument - Make a copy of an aggregate at address specified |
| 161 | /// by "Src" to address "Dst" of size "Size". Alignment information is |
| 162 | /// specified by the specific parameter attribute. The copy will be passed as |
| 163 | /// a byval function parameter. Sometimes what we are copying is the end of a |
| 164 | /// larger object, the part that does not fit in registers. |
| Benjamin Kramer | bdc4956 | 2016-06-12 15:39:02 +0000 | [diff] [blame] | 165 | static SDValue CreateCopyOfByValArgument(SDValue Src, SDValue Dst, |
| 166 | SDValue Chain, ISD::ArgFlagsTy Flags, |
| 167 | SelectionDAG &DAG, const SDLoc &dl) { |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 168 | SDValue SizeNode = DAG.getConstant(Flags.getByValSize(), dl, MVT::i32); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 169 | return DAG.getMemcpy(Chain, dl, Dst, Src, SizeNode, Flags.getByValAlign(), |
| 170 | /*isVolatile=*/false, /*AlwaysInline=*/false, |
| Krzysztof Parzyszek | a46c36b | 2015-04-13 17:16:45 +0000 | [diff] [blame] | 171 | /*isTailCall=*/false, |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 172 | MachinePointerInfo(), MachinePointerInfo()); |
| 173 | } |
| 174 | |
| Krzysztof Parzyszek | 5619952 | 2017-04-13 15:05:51 +0000 | [diff] [blame] | 175 | bool |
| 176 | HexagonTargetLowering::CanLowerReturn( |
| Krzysztof Parzyszek | 7cfe7cb | 2018-02-09 15:30:02 +0000 | [diff] [blame] | 177 | CallingConv::ID CallConv, MachineFunction &MF, bool IsVarArg, |
| Krzysztof Parzyszek | 5619952 | 2017-04-13 15:05:51 +0000 | [diff] [blame] | 178 | const SmallVectorImpl<ISD::OutputArg> &Outs, |
| 179 | LLVMContext &Context) const { |
| 180 | SmallVector<CCValAssign, 16> RVLocs; |
| Krzysztof Parzyszek | 7cfe7cb | 2018-02-09 15:30:02 +0000 | [diff] [blame] | 181 | CCState CCInfo(CallConv, IsVarArg, MF, RVLocs, Context); |
| 182 | |
| 183 | if (MF.getSubtarget<HexagonSubtarget>().useHVXOps()) |
| 184 | return CCInfo.CheckReturn(Outs, RetCC_Hexagon_HVX); |
| Krzysztof Parzyszek | 5619952 | 2017-04-13 15:05:51 +0000 | [diff] [blame] | 185 | return CCInfo.CheckReturn(Outs, RetCC_Hexagon); |
| 186 | } |
| 187 | |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 188 | // LowerReturn - Lower ISD::RET. If a struct is larger than 8 bytes and is |
| 189 | // passed by value, the function prototype is modified to return void and |
| 190 | // the value is stored in memory pointed by a pointer passed by caller. |
| 191 | SDValue |
| Benjamin Kramer | bdc4956 | 2016-06-12 15:39:02 +0000 | [diff] [blame] | 192 | HexagonTargetLowering::LowerReturn(SDValue Chain, CallingConv::ID CallConv, |
| Krzysztof Parzyszek | 7cfe7cb | 2018-02-09 15:30:02 +0000 | [diff] [blame] | 193 | bool IsVarArg, |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 194 | const SmallVectorImpl<ISD::OutputArg> &Outs, |
| 195 | const SmallVectorImpl<SDValue> &OutVals, |
| Benjamin Kramer | bdc4956 | 2016-06-12 15:39:02 +0000 | [diff] [blame] | 196 | const SDLoc &dl, SelectionDAG &DAG) const { |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 197 | // CCValAssign - represent the assignment of the return value to locations. |
| 198 | SmallVector<CCValAssign, 16> RVLocs; |
| 199 | |
| 200 | // CCState - Info about the registers and stack slot. |
| Krzysztof Parzyszek | 7cfe7cb | 2018-02-09 15:30:02 +0000 | [diff] [blame] | 201 | CCState CCInfo(CallConv, IsVarArg, DAG.getMachineFunction(), RVLocs, |
| Eric Christopher | b521750 | 2014-08-06 18:45:26 +0000 | [diff] [blame] | 202 | *DAG.getContext()); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 203 | |
| 204 | // Analyze return values of ISD::RET |
| Krzysztof Parzyszek | 7cfe7cb | 2018-02-09 15:30:02 +0000 | [diff] [blame] | 205 | if (Subtarget.useHVXOps()) |
| 206 | CCInfo.AnalyzeReturn(Outs, RetCC_Hexagon_HVX); |
| 207 | else |
| 208 | CCInfo.AnalyzeReturn(Outs, RetCC_Hexagon); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 209 | |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 210 | SDValue Flag; |
| Jakob Stoklund Olesen | 0af477c | 2013-02-05 18:08:43 +0000 | [diff] [blame] | 211 | SmallVector<SDValue, 4> RetOps(1, Chain); |
| 212 | |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 213 | // Copy the result values into the output registers. |
| 214 | for (unsigned i = 0; i != RVLocs.size(); ++i) { |
| 215 | CCValAssign &VA = RVLocs[i]; |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 216 | |
| 217 | Chain = DAG.getCopyToReg(Chain, dl, VA.getLocReg(), OutVals[i], Flag); |
| 218 | |
| 219 | // Guarantee that all emitted copies are stuck together with flags. |
| 220 | Flag = Chain.getValue(1); |
| Jakob Stoklund Olesen | 0af477c | 2013-02-05 18:08:43 +0000 | [diff] [blame] | 221 | RetOps.push_back(DAG.getRegister(VA.getLocReg(), VA.getLocVT())); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 222 | } |
| 223 | |
| Jakob Stoklund Olesen | 0af477c | 2013-02-05 18:08:43 +0000 | [diff] [blame] | 224 | RetOps[0] = Chain; // Update chain. |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 225 | |
| Jakob Stoklund Olesen | 0af477c | 2013-02-05 18:08:43 +0000 | [diff] [blame] | 226 | // Add the flag if we have it. |
| 227 | if (Flag.getNode()) |
| 228 | RetOps.push_back(Flag); |
| 229 | |
| Craig Topper | 48d114b | 2014-04-26 18:35:24 +0000 | [diff] [blame] | 230 | return DAG.getNode(HexagonISD::RET_FLAG, dl, MVT::Other, RetOps); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 231 | } |
| 232 | |
| Matt Arsenault | 3138075 | 2017-04-18 21:16:46 +0000 | [diff] [blame] | 233 | bool HexagonTargetLowering::mayBeEmittedAsTailCall(const CallInst *CI) const { |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 234 | // 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] | 235 | auto Attr = |
| 236 | CI->getParent()->getParent()->getFnAttribute("disable-tail-calls"); |
| 237 | if (!CI->isTailCall() || Attr.getValueAsString() == "true") |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 238 | return false; |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 239 | |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 240 | return true; |
| 241 | } |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 242 | |
| Sid Manning | 9ad0f02 | 2018-09-07 13:36:21 +0000 | [diff] [blame] | 243 | unsigned HexagonTargetLowering::getRegisterByName(const char* RegName, EVT VT, |
| 244 | SelectionDAG &DAG) const { |
| 245 | // Just support r19, the linux kernel uses it. |
| 246 | unsigned Reg = StringSwitch<unsigned>(RegName) |
| 247 | .Case("r19", Hexagon::R19) |
| 248 | .Default(0); |
| 249 | if (Reg) |
| 250 | return Reg; |
| 251 | |
| 252 | report_fatal_error("Invalid register name global variable"); |
| 253 | } |
| 254 | |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 255 | /// LowerCallResult - Lower the result values of an ISD::CALL into the |
| 256 | /// appropriate copies out of appropriate physical registers. This assumes that |
| Krzysztof Parzyszek | 1aaf41a | 2017-02-17 22:14:51 +0000 | [diff] [blame] | 257 | /// 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] | 258 | /// being lowered. Returns a SDNode with the same number of values as the |
| 259 | /// ISD::CALL. |
| Benjamin Kramer | bdc4956 | 2016-06-12 15:39:02 +0000 | [diff] [blame] | 260 | SDValue HexagonTargetLowering::LowerCallResult( |
| Krzysztof Parzyszek | 7cfe7cb | 2018-02-09 15:30:02 +0000 | [diff] [blame] | 261 | SDValue Chain, SDValue Glue, CallingConv::ID CallConv, bool IsVarArg, |
| Benjamin Kramer | bdc4956 | 2016-06-12 15:39:02 +0000 | [diff] [blame] | 262 | const SmallVectorImpl<ISD::InputArg> &Ins, const SDLoc &dl, |
| 263 | SelectionDAG &DAG, SmallVectorImpl<SDValue> &InVals, |
| 264 | const SmallVectorImpl<SDValue> &OutVals, SDValue Callee) const { |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 265 | // Assign locations to each value returned by this call. |
| 266 | SmallVector<CCValAssign, 16> RVLocs; |
| 267 | |
| Krzysztof Parzyszek | 7cfe7cb | 2018-02-09 15:30:02 +0000 | [diff] [blame] | 268 | CCState CCInfo(CallConv, IsVarArg, DAG.getMachineFunction(), RVLocs, |
| Eric Christopher | b521750 | 2014-08-06 18:45:26 +0000 | [diff] [blame] | 269 | *DAG.getContext()); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 270 | |
| Krzysztof Parzyszek | 7cfe7cb | 2018-02-09 15:30:02 +0000 | [diff] [blame] | 271 | if (Subtarget.useHVXOps()) |
| 272 | CCInfo.AnalyzeCallResult(Ins, RetCC_Hexagon_HVX); |
| 273 | else |
| 274 | CCInfo.AnalyzeCallResult(Ins, RetCC_Hexagon); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 275 | |
| 276 | // Copy all of the result registers out of their specified physreg. |
| 277 | for (unsigned i = 0; i != RVLocs.size(); ++i) { |
| Krzysztof Parzyszek | 51155fc | 2016-03-04 17:38:05 +0000 | [diff] [blame] | 278 | SDValue RetVal; |
| 279 | if (RVLocs[i].getValVT() == MVT::i1) { |
| 280 | // Return values of type MVT::i1 require special handling. The reason |
| 281 | // is that MVT::i1 is associated with the PredRegs register class, but |
| 282 | // values of that type are still returned in R0. Generate an explicit |
| 283 | // copy into a predicate register from R0, and treat the value of the |
| 284 | // predicate register as the call result. |
| 285 | auto &MRI = DAG.getMachineFunction().getRegInfo(); |
| 286 | SDValue FR0 = DAG.getCopyFromReg(Chain, dl, RVLocs[i].getLocReg(), |
| Krzysztof Parzyszek | 1aaf41a | 2017-02-17 22:14:51 +0000 | [diff] [blame] | 287 | MVT::i32, Glue); |
| Krzysztof Parzyszek | 51155fc | 2016-03-04 17:38:05 +0000 | [diff] [blame] | 288 | // FR0 = (Value, Chain, Glue) |
| Daniel Sanders | 0c47611 | 2019-08-15 19:22:08 +0000 | [diff] [blame] | 289 | Register PredR = MRI.createVirtualRegister(&Hexagon::PredRegsRegClass); |
| Krzysztof Parzyszek | 51155fc | 2016-03-04 17:38:05 +0000 | [diff] [blame] | 290 | SDValue TPR = DAG.getCopyToReg(FR0.getValue(1), dl, PredR, |
| 291 | FR0.getValue(0), FR0.getValue(2)); |
| 292 | // TPR = (Chain, Glue) |
| Krzysztof Parzyszek | 1aaf41a | 2017-02-17 22:14:51 +0000 | [diff] [blame] | 293 | // Don't glue this CopyFromReg, because it copies from a virtual |
| 294 | // register. If it is glued to the call, InstrEmitter will add it |
| 295 | // as an implicit def to the call (EmitMachineNode). |
| 296 | RetVal = DAG.getCopyFromReg(TPR.getValue(0), dl, PredR, MVT::i1); |
| 297 | Glue = TPR.getValue(1); |
| Krzysztof Parzyszek | 6f06b6e | 2017-10-23 19:35:25 +0000 | [diff] [blame] | 298 | Chain = TPR.getValue(0); |
| Krzysztof Parzyszek | 51155fc | 2016-03-04 17:38:05 +0000 | [diff] [blame] | 299 | } else { |
| 300 | RetVal = DAG.getCopyFromReg(Chain, dl, RVLocs[i].getLocReg(), |
| Krzysztof Parzyszek | 1aaf41a | 2017-02-17 22:14:51 +0000 | [diff] [blame] | 301 | RVLocs[i].getValVT(), Glue); |
| 302 | Glue = RetVal.getValue(2); |
| Krzysztof Parzyszek | 6f06b6e | 2017-10-23 19:35:25 +0000 | [diff] [blame] | 303 | Chain = RetVal.getValue(1); |
| Krzysztof Parzyszek | 51155fc | 2016-03-04 17:38:05 +0000 | [diff] [blame] | 304 | } |
| 305 | InVals.push_back(RetVal.getValue(0)); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 306 | } |
| 307 | |
| 308 | return Chain; |
| 309 | } |
| 310 | |
| 311 | /// LowerCall - Functions arguments are copied from virtual regs to |
| 312 | /// (physical regs)/(stack frame), CALLSEQ_START and CALLSEQ_END are emitted. |
| 313 | SDValue |
| Justin Holewinski | aa58397 | 2012-05-25 16:35:28 +0000 | [diff] [blame] | 314 | HexagonTargetLowering::LowerCall(TargetLowering::CallLoweringInfo &CLI, |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 315 | SmallVectorImpl<SDValue> &InVals) const { |
| Justin Holewinski | aa58397 | 2012-05-25 16:35:28 +0000 | [diff] [blame] | 316 | SelectionDAG &DAG = CLI.DAG; |
| Craig Topper | b94011f | 2013-07-14 04:42:23 +0000 | [diff] [blame] | 317 | SDLoc &dl = CLI.DL; |
| 318 | SmallVectorImpl<ISD::OutputArg> &Outs = CLI.Outs; |
| 319 | SmallVectorImpl<SDValue> &OutVals = CLI.OutVals; |
| 320 | SmallVectorImpl<ISD::InputArg> &Ins = CLI.Ins; |
| Justin Holewinski | aa58397 | 2012-05-25 16:35:28 +0000 | [diff] [blame] | 321 | SDValue Chain = CLI.Chain; |
| 322 | SDValue Callee = CLI.Callee; |
| Justin Holewinski | aa58397 | 2012-05-25 16:35:28 +0000 | [diff] [blame] | 323 | CallingConv::ID CallConv = CLI.CallConv; |
| Krzysztof Parzyszek | 317d42c | 2016-08-01 20:31:50 +0000 | [diff] [blame] | 324 | bool IsVarArg = CLI.IsVarArg; |
| 325 | bool DoesNotReturn = CLI.DoesNotReturn; |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 326 | |
| Krzysztof Parzyszek | e0d7de7 | 2018-02-15 17:20:07 +0000 | [diff] [blame] | 327 | bool IsStructRet = Outs.empty() ? false : Outs[0].Flags.isSRet(); |
| Krzysztof Parzyszek | 4fa2a9f | 2015-04-22 16:43:53 +0000 | [diff] [blame] | 328 | MachineFunction &MF = DAG.getMachineFunction(); |
| Krzysztof Parzyszek | f67cd82 | 2017-07-11 17:11:54 +0000 | [diff] [blame] | 329 | MachineFrameInfo &MFI = MF.getFrameInfo(); |
| Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 330 | auto PtrVT = getPointerTy(MF.getDataLayout()); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 331 | |
| Krzysztof Parzyszek | e0d7de7 | 2018-02-15 17:20:07 +0000 | [diff] [blame] | 332 | unsigned NumParams = CLI.CS.getInstruction() |
| 333 | ? CLI.CS.getFunctionType()->getNumParams() |
| 334 | : 0; |
| 335 | if (GlobalAddressSDNode *GAN = dyn_cast<GlobalAddressSDNode>(Callee)) |
| 336 | Callee = DAG.getTargetGlobalAddress(GAN->getGlobal(), dl, MVT::i32); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 337 | |
| Benjamin Kramer | 602bb4a | 2013-10-27 11:16:09 +0000 | [diff] [blame] | 338 | // Analyze operands of the call, assigning locations to each operand. |
| 339 | SmallVector<CCValAssign, 16> ArgLocs; |
| Krzysztof Parzyszek | 18e0d2a | 2018-02-15 15:47:53 +0000 | [diff] [blame] | 340 | HexagonCCState CCInfo(CallConv, IsVarArg, MF, ArgLocs, *DAG.getContext(), |
| Krzysztof Parzyszek | e0d7de7 | 2018-02-15 17:20:07 +0000 | [diff] [blame] | 341 | NumParams); |
| Benjamin Kramer | 602bb4a | 2013-10-27 11:16:09 +0000 | [diff] [blame] | 342 | |
| Krzysztof Parzyszek | 7cfe7cb | 2018-02-09 15:30:02 +0000 | [diff] [blame] | 343 | if (Subtarget.useHVXOps()) |
| 344 | CCInfo.AnalyzeCallOperands(Outs, CC_Hexagon_HVX); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 345 | else |
| 346 | CCInfo.AnalyzeCallOperands(Outs, CC_Hexagon); |
| 347 | |
| Matthias Braun | f1caa28 | 2017-12-15 22:22:58 +0000 | [diff] [blame] | 348 | auto Attr = MF.getFunction().getFnAttribute("disable-tail-calls"); |
| Akira Hatanaka | d9699bc | 2015-06-09 19:07:19 +0000 | [diff] [blame] | 349 | if (Attr.getValueAsString() == "true") |
| Krzysztof Parzyszek | 7cfe7cb | 2018-02-09 15:30:02 +0000 | [diff] [blame] | 350 | CLI.IsTailCall = false; |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 351 | |
| Krzysztof Parzyszek | 7cfe7cb | 2018-02-09 15:30:02 +0000 | [diff] [blame] | 352 | if (CLI.IsTailCall) { |
| Matthias Braun | f1caa28 | 2017-12-15 22:22:58 +0000 | [diff] [blame] | 353 | bool StructAttrFlag = MF.getFunction().hasStructRetAttr(); |
| Krzysztof Parzyszek | 7cfe7cb | 2018-02-09 15:30:02 +0000 | [diff] [blame] | 354 | CLI.IsTailCall = IsEligibleForTailCallOptimization(Callee, CallConv, |
| 355 | IsVarArg, IsStructRet, StructAttrFlag, Outs, |
| 356 | OutVals, Ins, DAG); |
| Krzysztof Parzyszek | 4fa2a9f | 2015-04-22 16:43:53 +0000 | [diff] [blame] | 357 | for (unsigned i = 0, e = ArgLocs.size(); i != e; ++i) { |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 358 | CCValAssign &VA = ArgLocs[i]; |
| 359 | if (VA.isMemLoc()) { |
| Krzysztof Parzyszek | 7cfe7cb | 2018-02-09 15:30:02 +0000 | [diff] [blame] | 360 | CLI.IsTailCall = false; |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 361 | break; |
| 362 | } |
| 363 | } |
| Nicola Zaghen | d34e60c | 2018-05-14 12:53:11 +0000 | [diff] [blame] | 364 | LLVM_DEBUG(dbgs() << (CLI.IsTailCall ? "Eligible for Tail Call\n" |
| 365 | : "Argument must be passed on stack. " |
| 366 | "Not eligible for Tail Call\n")); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 367 | } |
| 368 | // Get a count of how many bytes are to be pushed on the stack. |
| 369 | unsigned NumBytes = CCInfo.getNextStackOffset(); |
| 370 | SmallVector<std::pair<unsigned, SDValue>, 16> RegsToPass; |
| 371 | SmallVector<SDValue, 8> MemOpChains; |
| 372 | |
| Krzysztof Parzyszek | 7cfe7cb | 2018-02-09 15:30:02 +0000 | [diff] [blame] | 373 | const HexagonRegisterInfo &HRI = *Subtarget.getRegisterInfo(); |
| Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 374 | SDValue StackPtr = |
| 375 | DAG.getCopyFromReg(Chain, dl, HRI.getStackRegister(), PtrVT); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 376 | |
| Krzysztof Parzyszek | 08ff888 | 2015-11-26 18:38:27 +0000 | [diff] [blame] | 377 | bool NeedsArgAlign = false; |
| 378 | unsigned LargestAlignSeen = 0; |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 379 | // Walk the register/memloc assignments, inserting copies/loads. |
| 380 | for (unsigned i = 0, e = ArgLocs.size(); i != e; ++i) { |
| 381 | CCValAssign &VA = ArgLocs[i]; |
| 382 | SDValue Arg = OutVals[i]; |
| 383 | ISD::ArgFlagsTy Flags = Outs[i].Flags; |
| Krzysztof Parzyszek | 08ff888 | 2015-11-26 18:38:27 +0000 | [diff] [blame] | 384 | // Record if we need > 8 byte alignment on an argument. |
| Krzysztof Parzyszek | ac1966e | 2017-11-27 18:12:16 +0000 | [diff] [blame] | 385 | bool ArgAlign = Subtarget.isHVXVectorType(VA.getValVT()); |
| Krzysztof Parzyszek | 08ff888 | 2015-11-26 18:38:27 +0000 | [diff] [blame] | 386 | NeedsArgAlign |= ArgAlign; |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 387 | |
| 388 | // Promote the value if needed. |
| 389 | switch (VA.getLocInfo()) { |
| 390 | default: |
| Krzysztof Parzyszek | 8f6b0c8 | 2017-12-20 14:44:05 +0000 | [diff] [blame] | 391 | // Loc info must be one of Full, BCvt, SExt, ZExt, or AExt. |
| Craig Topper | e55c556 | 2012-02-07 02:50:20 +0000 | [diff] [blame] | 392 | llvm_unreachable("Unknown loc info!"); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 393 | case CCValAssign::Full: |
| 394 | break; |
| Krzysztof Parzyszek | 8f6b0c8 | 2017-12-20 14:44:05 +0000 | [diff] [blame] | 395 | case CCValAssign::BCvt: |
| 396 | Arg = DAG.getBitcast(VA.getLocVT(), Arg); |
| 397 | break; |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 398 | case CCValAssign::SExt: |
| 399 | Arg = DAG.getNode(ISD::SIGN_EXTEND, dl, VA.getLocVT(), Arg); |
| 400 | break; |
| 401 | case CCValAssign::ZExt: |
| 402 | Arg = DAG.getNode(ISD::ZERO_EXTEND, dl, VA.getLocVT(), Arg); |
| 403 | break; |
| 404 | case CCValAssign::AExt: |
| 405 | Arg = DAG.getNode(ISD::ANY_EXTEND, dl, VA.getLocVT(), Arg); |
| 406 | break; |
| 407 | } |
| 408 | |
| 409 | if (VA.isMemLoc()) { |
| 410 | unsigned LocMemOffset = VA.getLocMemOffset(); |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 411 | SDValue MemAddr = DAG.getConstant(LocMemOffset, dl, |
| 412 | StackPtr.getValueType()); |
| Krzysztof Parzyszek | 4fa2a9f | 2015-04-22 16:43:53 +0000 | [diff] [blame] | 413 | MemAddr = DAG.getNode(ISD::ADD, dl, MVT::i32, StackPtr, MemAddr); |
| Krzysztof Parzyszek | 08ff888 | 2015-11-26 18:38:27 +0000 | [diff] [blame] | 414 | if (ArgAlign) |
| 415 | LargestAlignSeen = std::max(LargestAlignSeen, |
| 416 | VA.getLocVT().getStoreSizeInBits() >> 3); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 417 | if (Flags.isByVal()) { |
| 418 | // The argument is a struct passed by value. According to LLVM, "Arg" |
| Fangrui Song | 956ee79 | 2018-03-30 22:22:31 +0000 | [diff] [blame] | 419 | // is a pointer. |
| Krzysztof Parzyszek | 4fa2a9f | 2015-04-22 16:43:53 +0000 | [diff] [blame] | 420 | MemOpChains.push_back(CreateCopyOfByValArgument(Arg, MemAddr, Chain, |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 421 | Flags, DAG, dl)); |
| 422 | } else { |
| Alex Lorenz | e40c8a2 | 2015-08-11 23:09:45 +0000 | [diff] [blame] | 423 | MachinePointerInfo LocPI = MachinePointerInfo::getStack( |
| 424 | DAG.getMachineFunction(), LocMemOffset); |
| Justin Lebar | 9c37581 | 2016-07-15 18:27:10 +0000 | [diff] [blame] | 425 | SDValue S = DAG.getStore(Chain, dl, Arg, MemAddr, LocPI); |
| Krzysztof Parzyszek | 4fa2a9f | 2015-04-22 16:43:53 +0000 | [diff] [blame] | 426 | MemOpChains.push_back(S); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 427 | } |
| 428 | continue; |
| 429 | } |
| 430 | |
| 431 | // Arguments that can be passed on register must be kept at RegsToPass |
| 432 | // vector. |
| Krzysztof Parzyszek | 4fa2a9f | 2015-04-22 16:43:53 +0000 | [diff] [blame] | 433 | if (VA.isRegLoc()) |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 434 | RegsToPass.push_back(std::make_pair(VA.getLocReg(), Arg)); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 435 | } |
| 436 | |
| Krzysztof Parzyszek | d8b780d | 2018-06-20 13:56:09 +0000 | [diff] [blame] | 437 | if (NeedsArgAlign && Subtarget.hasV60Ops()) { |
| Nicola Zaghen | d34e60c | 2018-05-14 12:53:11 +0000 | [diff] [blame] | 438 | LLVM_DEBUG(dbgs() << "Function needs byte stack align due to call args\n"); |
| Krzysztof Parzyszek | 7cfe7cb | 2018-02-09 15:30:02 +0000 | [diff] [blame] | 439 | unsigned VecAlign = HRI.getSpillAlignment(Hexagon::HvxVRRegClass); |
| 440 | LargestAlignSeen = std::max(LargestAlignSeen, VecAlign); |
| Matthias Braun | 941a705 | 2016-07-28 18:40:00 +0000 | [diff] [blame] | 441 | MFI.ensureMaxAlignment(LargestAlignSeen); |
| Krzysztof Parzyszek | 08ff888 | 2015-11-26 18:38:27 +0000 | [diff] [blame] | 442 | } |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 443 | // Transform all store nodes into one single node because all store |
| 444 | // nodes are independent of each other. |
| Krzysztof Parzyszek | 4fa2a9f | 2015-04-22 16:43:53 +0000 | [diff] [blame] | 445 | if (!MemOpChains.empty()) |
| Craig Topper | 48d114b | 2014-04-26 18:35:24 +0000 | [diff] [blame] | 446 | Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, MemOpChains); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 447 | |
| Krzysztof Parzyszek | 1aaf41a | 2017-02-17 22:14:51 +0000 | [diff] [blame] | 448 | SDValue Glue; |
| Krzysztof Parzyszek | 7cfe7cb | 2018-02-09 15:30:02 +0000 | [diff] [blame] | 449 | if (!CLI.IsTailCall) { |
| Serge Pavlov | d526b13 | 2017-05-09 13:35:13 +0000 | [diff] [blame] | 450 | Chain = DAG.getCALLSEQ_START(Chain, NumBytes, 0, dl); |
| Krzysztof Parzyszek | 1aaf41a | 2017-02-17 22:14:51 +0000 | [diff] [blame] | 451 | Glue = Chain.getValue(1); |
| Krzysztof Parzyszek | 4fa2a9f | 2015-04-22 16:43:53 +0000 | [diff] [blame] | 452 | } |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 453 | |
| 454 | // Build a sequence of copy-to-reg nodes chained together with token |
| 455 | // chain and flag operands which copy the outgoing args into registers. |
| Krzysztof Parzyszek | 317d42c | 2016-08-01 20:31:50 +0000 | [diff] [blame] | 456 | // The Glue is necessary since all emitted instructions must be |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 457 | // stuck together. |
| Krzysztof Parzyszek | 7cfe7cb | 2018-02-09 15:30:02 +0000 | [diff] [blame] | 458 | if (!CLI.IsTailCall) { |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 459 | for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i) { |
| 460 | Chain = DAG.getCopyToReg(Chain, dl, RegsToPass[i].first, |
| Krzysztof Parzyszek | 317d42c | 2016-08-01 20:31:50 +0000 | [diff] [blame] | 461 | RegsToPass[i].second, Glue); |
| 462 | Glue = Chain.getValue(1); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 463 | } |
| Krzysztof Parzyszek | 4fa2a9f | 2015-04-22 16:43:53 +0000 | [diff] [blame] | 464 | } else { |
| 465 | // For tail calls lower the arguments to the 'real' stack slot. |
| 466 | // |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 467 | // Force all the incoming stack arguments to be loaded from the stack |
| 468 | // before any new outgoing arguments are stored to the stack, because the |
| 469 | // outgoing stack slots may alias the incoming argument stack slots, and |
| 470 | // the alias isn't otherwise explicit. This is slightly more conservative |
| 471 | // than necessary, because it means that each store effectively depends |
| 472 | // on every argument instead of just those arguments it would clobber. |
| 473 | // |
| Benjamin Kramer | bde9176 | 2012-06-02 10:20:22 +0000 | [diff] [blame] | 474 | // Do not flag preceding copytoreg stuff together with the following stuff. |
| Krzysztof Parzyszek | 317d42c | 2016-08-01 20:31:50 +0000 | [diff] [blame] | 475 | Glue = SDValue(); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 476 | for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i) { |
| 477 | Chain = DAG.getCopyToReg(Chain, dl, RegsToPass[i].first, |
| Krzysztof Parzyszek | 317d42c | 2016-08-01 20:31:50 +0000 | [diff] [blame] | 478 | RegsToPass[i].second, Glue); |
| 479 | Glue = Chain.getValue(1); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 480 | } |
| Krzysztof Parzyszek | 317d42c | 2016-08-01 20:31:50 +0000 | [diff] [blame] | 481 | Glue = SDValue(); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 482 | } |
| 483 | |
| Krzysztof Parzyszek | 080bebd | 2016-07-25 14:42:11 +0000 | [diff] [blame] | 484 | bool LongCalls = MF.getSubtarget<HexagonSubtarget>().useLongCalls(); |
| 485 | unsigned Flags = LongCalls ? HexagonII::HMOTF_ConstExtended : 0; |
| 486 | |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 487 | // If the callee is a GlobalAddress/ExternalSymbol node (quite common, every |
| 488 | // direct call is) turn it into a TargetGlobalAddress/TargetExternalSymbol |
| 489 | // node so that legalize doesn't hack it. |
| Tobias Edler von Koch | b51460c | 2015-12-16 17:29:37 +0000 | [diff] [blame] | 490 | if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee)) { |
| Krzysztof Parzyszek | 080bebd | 2016-07-25 14:42:11 +0000 | [diff] [blame] | 491 | Callee = DAG.getTargetGlobalAddress(G->getGlobal(), dl, PtrVT, 0, Flags); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 492 | } else if (ExternalSymbolSDNode *S = |
| 493 | dyn_cast<ExternalSymbolSDNode>(Callee)) { |
| Krzysztof Parzyszek | 080bebd | 2016-07-25 14:42:11 +0000 | [diff] [blame] | 494 | Callee = DAG.getTargetExternalSymbol(S->getSymbol(), PtrVT, Flags); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 495 | } |
| 496 | |
| 497 | // Returns a chain & a flag for retval copy to use. |
| 498 | SDVTList NodeTys = DAG.getVTList(MVT::Other, MVT::Glue); |
| 499 | SmallVector<SDValue, 8> Ops; |
| 500 | Ops.push_back(Chain); |
| 501 | Ops.push_back(Callee); |
| 502 | |
| 503 | // Add argument registers to the end of the list so that they are |
| 504 | // known live into the call. |
| 505 | for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i) { |
| 506 | Ops.push_back(DAG.getRegister(RegsToPass[i].first, |
| 507 | RegsToPass[i].second.getValueType())); |
| 508 | } |
| 509 | |
| Krzysztof Parzyszek | 1aaf41a | 2017-02-17 22:14:51 +0000 | [diff] [blame] | 510 | const uint32_t *Mask = HRI.getCallPreservedMask(MF, CallConv); |
| 511 | assert(Mask && "Missing call preserved mask for calling convention"); |
| 512 | Ops.push_back(DAG.getRegisterMask(Mask)); |
| 513 | |
| Krzysztof Parzyszek | 317d42c | 2016-08-01 20:31:50 +0000 | [diff] [blame] | 514 | if (Glue.getNode()) |
| 515 | Ops.push_back(Glue); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 516 | |
| Krzysztof Parzyszek | 7cfe7cb | 2018-02-09 15:30:02 +0000 | [diff] [blame] | 517 | if (CLI.IsTailCall) { |
| Krzysztof Parzyszek | f67cd82 | 2017-07-11 17:11:54 +0000 | [diff] [blame] | 518 | MFI.setHasTailCall(); |
| Craig Topper | 48d114b | 2014-04-26 18:35:24 +0000 | [diff] [blame] | 519 | return DAG.getNode(HexagonISD::TC_RETURN, dl, NodeTys, Ops); |
| Arnold Schwaighofer | f54b73d | 2015-05-08 23:52:00 +0000 | [diff] [blame] | 520 | } |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 521 | |
| Krzysztof Parzyszek | f67cd82 | 2017-07-11 17:11:54 +0000 | [diff] [blame] | 522 | // Set this here because we need to know this for "hasFP" in frame lowering. |
| 523 | // The target-independent code calls getFrameRegister before setting it, and |
| 524 | // getFrameRegister uses hasFP to determine whether the function has FP. |
| 525 | MFI.setHasCalls(true); |
| 526 | |
| Krzysztof Parzyszek | be976d4 | 2016-08-12 11:12:02 +0000 | [diff] [blame] | 527 | unsigned OpCode = DoesNotReturn ? HexagonISD::CALLnr : HexagonISD::CALL; |
| Colin LeMahieu | 2e3a26d | 2015-01-16 17:05:27 +0000 | [diff] [blame] | 528 | Chain = DAG.getNode(OpCode, dl, NodeTys, Ops); |
| Krzysztof Parzyszek | 317d42c | 2016-08-01 20:31:50 +0000 | [diff] [blame] | 529 | Glue = Chain.getValue(1); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 530 | |
| 531 | // Create the CALLSEQ_END node. |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 532 | Chain = DAG.getCALLSEQ_END(Chain, DAG.getIntPtrConstant(NumBytes, dl, true), |
| Krzysztof Parzyszek | 317d42c | 2016-08-01 20:31:50 +0000 | [diff] [blame] | 533 | DAG.getIntPtrConstant(0, dl, true), Glue, dl); |
| 534 | Glue = Chain.getValue(1); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 535 | |
| 536 | // Handle result values, copying them out of physregs into vregs that we |
| 537 | // return. |
| Krzysztof Parzyszek | 317d42c | 2016-08-01 20:31:50 +0000 | [diff] [blame] | 538 | return LowerCallResult(Chain, Glue, CallConv, IsVarArg, Ins, dl, DAG, |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 539 | InVals, OutVals, Callee); |
| 540 | } |
| 541 | |
| Krzysztof Parzyszek | cfbe6ba | 2018-02-13 15:35:07 +0000 | [diff] [blame] | 542 | /// Returns true by value, base pointer and offset pointer and addressing |
| 543 | /// mode by reference if this node can be combined with a load / store to |
| 544 | /// form a post-indexed load / store. |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 545 | bool HexagonTargetLowering::getPostIndexedAddressParts(SDNode *N, SDNode *Op, |
| Krzysztof Parzyszek | cfbe6ba | 2018-02-13 15:35:07 +0000 | [diff] [blame] | 546 | SDValue &Base, SDValue &Offset, ISD::MemIndexedMode &AM, |
| 547 | SelectionDAG &DAG) const { |
| 548 | LSBaseSDNode *LSN = dyn_cast<LSBaseSDNode>(N); |
| 549 | if (!LSN) |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 550 | return false; |
| Krzysztof Parzyszek | cfbe6ba | 2018-02-13 15:35:07 +0000 | [diff] [blame] | 551 | EVT VT = LSN->getMemoryVT(); |
| 552 | if (!VT.isSimple()) |
| 553 | return false; |
| Krzysztof Parzyszek | 2c3edf0 | 2018-03-07 17:27:18 +0000 | [diff] [blame] | 554 | bool IsLegalType = VT == MVT::i8 || VT == MVT::i16 || VT == MVT::i32 || |
| Brendon Cahoon | e5ed563 | 2018-05-18 18:14:44 +0000 | [diff] [blame] | 555 | VT == MVT::i64 || VT == MVT::f32 || VT == MVT::f64 || |
| 556 | VT == MVT::v2i16 || VT == MVT::v2i32 || VT == MVT::v4i8 || |
| 557 | VT == MVT::v4i16 || VT == MVT::v8i8 || |
| Krzysztof Parzyszek | cfbe6ba | 2018-02-13 15:35:07 +0000 | [diff] [blame] | 558 | Subtarget.isHVXVectorType(VT.getSimpleVT()); |
| 559 | if (!IsLegalType) |
| 560 | return false; |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 561 | |
| Krzysztof Parzyszek | cfbe6ba | 2018-02-13 15:35:07 +0000 | [diff] [blame] | 562 | if (Op->getOpcode() != ISD::ADD) |
| 563 | return false; |
| 564 | Base = Op->getOperand(0); |
| 565 | Offset = Op->getOperand(1); |
| 566 | if (!isa<ConstantSDNode>(Offset.getNode())) |
| 567 | return false; |
| 568 | AM = ISD::POST_INC; |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 569 | |
| Krzysztof Parzyszek | cfbe6ba | 2018-02-13 15:35:07 +0000 | [diff] [blame] | 570 | int32_t V = cast<ConstantSDNode>(Offset.getNode())->getSExtValue(); |
| 571 | return Subtarget.getInstrInfo()->isValidAutoIncImm(VT, V); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 572 | } |
| 573 | |
| Krzysztof Parzyszek | 21dc8bd | 2015-12-18 20:19:30 +0000 | [diff] [blame] | 574 | SDValue |
| 575 | HexagonTargetLowering::LowerINLINEASM(SDValue Op, SelectionDAG &DAG) const { |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 576 | MachineFunction &MF = DAG.getMachineFunction(); |
| Krzysztof Parzyszek | 9eb75c4 | 2017-06-30 21:21:40 +0000 | [diff] [blame] | 577 | auto &HMFI = *MF.getInfo<HexagonMachineFunctionInfo>(); |
| 578 | const HexagonRegisterInfo &HRI = *Subtarget.getRegisterInfo(); |
| 579 | unsigned LR = HRI.getRARegister(); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 580 | |
| Craig Topper | 784929d | 2019-02-08 20:48:56 +0000 | [diff] [blame] | 581 | if ((Op.getOpcode() != ISD::INLINEASM && |
| 582 | Op.getOpcode() != ISD::INLINEASM_BR) || HMFI.hasClobberLR()) |
| Krzysztof Parzyszek | 9eb75c4 | 2017-06-30 21:21:40 +0000 | [diff] [blame] | 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 | |
| Nicola Zaghen | d34e60c | 2018-05-14 12:53:11 +0000 | [diff] [blame] | 677 | LLVM_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 | 18e0d2a | 2018-02-15 15:47:53 +0000 | [diff] [blame] | 701 | HexagonCCState CCInfo(CallConv, IsVarArg, MF, ArgLocs, *DAG.getContext(), |
| Krzysztof Parzyszek | e0d7de7 | 2018-02-15 17:20:07 +0000 | [diff] [blame] | 702 | MF.getFunction().getFunctionType()->getNumParams()); |
| 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); |
| Daniel Sanders | 0c47611 | 2019-08-15 19:22:08 +0000 | [diff] [blame] | 739 | Register VReg = MRI.createVirtualRegister(RC); |
| Krzysztof Parzyszek | 7cfe7cb | 2018-02-09 15:30:02 +0000 | [diff] [blame] | 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 | SDValue HexagonTargetLowering::LowerSETCC(SDValue Op, SelectionDAG &DAG) const { |
| Krzysztof Parzyszek | 23bcf06 | 2018-04-19 14:24:31 +0000 | [diff] [blame] | 811 | const SDLoc &dl(Op); |
| Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 812 | SDValue LHS = Op.getOperand(0); |
| 813 | SDValue RHS = Op.getOperand(1); |
| Krzysztof Parzyszek | 23bcf06 | 2018-04-19 14:24:31 +0000 | [diff] [blame] | 814 | ISD::CondCode CC = cast<CondCodeSDNode>(Op.getOperand(2))->get(); |
| 815 | MVT ResTy = ty(Op); |
| 816 | MVT OpTy = ty(LHS); |
| Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 817 | |
| Krzysztof Parzyszek | 23bcf06 | 2018-04-19 14:24:31 +0000 | [diff] [blame] | 818 | if (OpTy == MVT::v2i16 || OpTy == MVT::v4i8) { |
| 819 | MVT ElemTy = OpTy.getVectorElementType(); |
| 820 | assert(ElemTy.isScalarInteger()); |
| 821 | MVT WideTy = MVT::getVectorVT(MVT::getIntegerVT(2*ElemTy.getSizeInBits()), |
| 822 | OpTy.getVectorNumElements()); |
| 823 | return DAG.getSetCC(dl, ResTy, |
| 824 | DAG.getSExtOrTrunc(LHS, SDLoc(LHS), WideTy), |
| 825 | DAG.getSExtOrTrunc(RHS, SDLoc(RHS), WideTy), CC); |
| Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 826 | } |
| 827 | |
| 828 | // Treat all other vector types as legal. |
| Krzysztof Parzyszek | 23bcf06 | 2018-04-19 14:24:31 +0000 | [diff] [blame] | 829 | if (ResTy.isVector()) |
| Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 830 | return Op; |
| 831 | |
| Krzysztof Parzyszek | 23bcf06 | 2018-04-19 14:24:31 +0000 | [diff] [blame] | 832 | // Comparisons of short integers should use sign-extend, not zero-extend, |
| 833 | // since we can represent small negative values in the compare instructions. |
| Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 834 | // The LLVM default is to use zero-extend arbitrarily in these cases. |
| Krzysztof Parzyszek | 23bcf06 | 2018-04-19 14:24:31 +0000 | [diff] [blame] | 835 | auto isSExtFree = [this](SDValue N) { |
| 836 | switch (N.getOpcode()) { |
| 837 | case ISD::TRUNCATE: { |
| 838 | // A sign-extend of a truncate of a sign-extend is free. |
| 839 | SDValue Op = N.getOperand(0); |
| 840 | if (Op.getOpcode() != ISD::AssertSext) |
| 841 | return false; |
| Eli Friedman | 0319c28 | 2018-07-11 23:26:35 +0000 | [diff] [blame] | 842 | EVT OrigTy = cast<VTSDNode>(Op.getOperand(1))->getVT(); |
| Krzysztof Parzyszek | 23bcf06 | 2018-04-19 14:24:31 +0000 | [diff] [blame] | 843 | unsigned ThisBW = ty(N).getSizeInBits(); |
| 844 | unsigned OrigBW = OrigTy.getSizeInBits(); |
| 845 | // The type that was sign-extended to get the AssertSext must be |
| 846 | // narrower than the type of N (so that N has still the same value |
| 847 | // as the original). |
| 848 | return ThisBW >= OrigBW; |
| 849 | } |
| 850 | case ISD::LOAD: |
| 851 | // We have sign-extended loads. |
| 852 | return true; |
| 853 | } |
| 854 | return false; |
| 855 | }; |
| 856 | |
| 857 | if (OpTy == MVT::i8 || OpTy == MVT::i16) { |
| Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 858 | ConstantSDNode *C = dyn_cast<ConstantSDNode>(RHS); |
| Krzysztof Parzyszek | 23bcf06 | 2018-04-19 14:24:31 +0000 | [diff] [blame] | 859 | bool IsNegative = C && C->getAPIntValue().isNegative(); |
| 860 | if (IsNegative || isSExtFree(LHS) || isSExtFree(RHS)) |
| 861 | return DAG.getSetCC(dl, ResTy, |
| 862 | DAG.getSExtOrTrunc(LHS, SDLoc(LHS), MVT::i32), |
| 863 | DAG.getSExtOrTrunc(RHS, SDLoc(RHS), MVT::i32), CC); |
| Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 864 | } |
| Krzysztof Parzyszek | 23bcf06 | 2018-04-19 14:24:31 +0000 | [diff] [blame] | 865 | |
| Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 866 | return SDValue(); |
| 867 | } |
| 868 | |
| Krzysztof Parzyszek | 21dc8bd | 2015-12-18 20:19:30 +0000 | [diff] [blame] | 869 | SDValue |
| 870 | HexagonTargetLowering::LowerVSELECT(SDValue Op, SelectionDAG &DAG) const { |
| Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 871 | SDValue PredOp = Op.getOperand(0); |
| 872 | SDValue Op1 = Op.getOperand(1), Op2 = Op.getOperand(2); |
| Krzysztof Parzyszek | 8e98770 | 2019-08-15 19:20:09 +0000 | [diff] [blame] | 873 | MVT OpTy = ty(Op1); |
| 874 | const SDLoc &dl(Op); |
| Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 875 | |
| Krzysztof Parzyszek | 8e98770 | 2019-08-15 19:20:09 +0000 | [diff] [blame] | 876 | if (OpTy == MVT::v2i16 || OpTy == MVT::v4i8) { |
| 877 | MVT ElemTy = OpTy.getVectorElementType(); |
| 878 | assert(ElemTy.isScalarInteger()); |
| 879 | MVT WideTy = MVT::getVectorVT(MVT::getIntegerVT(2*ElemTy.getSizeInBits()), |
| 880 | OpTy.getVectorNumElements()); |
| 881 | // Generate (trunc (select (_, sext, sext))). |
| 882 | return DAG.getSExtOrTrunc( |
| 883 | DAG.getSelect(dl, WideTy, PredOp, |
| 884 | DAG.getSExtOrTrunc(Op1, dl, WideTy), |
| 885 | DAG.getSExtOrTrunc(Op2, dl, WideTy)), |
| 886 | dl, OpTy); |
| Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 887 | } |
| 888 | |
| 889 | return SDValue(); |
| 890 | } |
| 891 | |
| Krzysztof Parzyszek | 91ff5c6 | 2017-08-01 13:12:53 +0000 | [diff] [blame] | 892 | static Constant *convert_i1_to_i8(const Constant *ConstVal) { |
| 893 | SmallVector<Constant *, 128> NewConst; |
| 894 | const ConstantVector *CV = dyn_cast<ConstantVector>(ConstVal); |
| 895 | if (!CV) |
| 896 | return nullptr; |
| 897 | |
| 898 | LLVMContext &Ctx = ConstVal->getContext(); |
| 899 | IRBuilder<> IRB(Ctx); |
| 900 | unsigned NumVectorElements = CV->getNumOperands(); |
| 901 | assert(isPowerOf2_32(NumVectorElements) && |
| 902 | "conversion only supported for pow2 VectorSize!"); |
| 903 | |
| 904 | for (unsigned i = 0; i < NumVectorElements / 8; ++i) { |
| 905 | uint8_t x = 0; |
| 906 | for (unsigned j = 0; j < 8; ++j) { |
| 907 | uint8_t y = CV->getOperand(i * 8 + j)->getUniqueInteger().getZExtValue(); |
| 908 | x |= y << (7 - j); |
| 909 | } |
| 910 | assert((x == 0 || x == 255) && "Either all 0's or all 1's expected!"); |
| 911 | NewConst.push_back(IRB.getInt8(x)); |
| 912 | } |
| 913 | return ConstantVector::get(NewConst); |
| 914 | } |
| 915 | |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 916 | SDValue |
| Sirish Pande | 69295b8 | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 917 | HexagonTargetLowering::LowerConstantPool(SDValue Op, SelectionDAG &DAG) const { |
| 918 | EVT ValTy = Op.getValueType(); |
| Krzysztof Parzyszek | 21dc8bd | 2015-12-18 20:19:30 +0000 | [diff] [blame] | 919 | ConstantPoolSDNode *CPN = cast<ConstantPoolSDNode>(Op); |
| Krzysztof Parzyszek | 91ff5c6 | 2017-08-01 13:12:53 +0000 | [diff] [blame] | 920 | Constant *CVal = nullptr; |
| 921 | bool isVTi1Type = false; |
| 922 | if (const Constant *ConstVal = dyn_cast<Constant>(CPN->getConstVal())) { |
| 923 | Type *CValTy = ConstVal->getType(); |
| 924 | if (CValTy->isVectorTy() && |
| 925 | CValTy->getVectorElementType()->isIntegerTy(1)) { |
| 926 | CVal = convert_i1_to_i8(ConstVal); |
| 927 | isVTi1Type = (CVal != nullptr); |
| 928 | } |
| 929 | } |
| Krzysztof Parzyszek | 21dc8bd | 2015-12-18 20:19:30 +0000 | [diff] [blame] | 930 | unsigned Align = CPN->getAlignment(); |
| Rafael Espindola | 405e25a | 2016-06-26 22:24:01 +0000 | [diff] [blame] | 931 | bool IsPositionIndependent = isPositionIndependent(); |
| 932 | unsigned char TF = IsPositionIndependent ? HexagonII::MO_PCREL : 0; |
| Krzysztof Parzyszek | 21dc8bd | 2015-12-18 20:19:30 +0000 | [diff] [blame] | 933 | |
| Ron Lieberman | 822ee88 | 2016-08-13 23:41:11 +0000 | [diff] [blame] | 934 | unsigned Offset = 0; |
| Krzysztof Parzyszek | 21dc8bd | 2015-12-18 20:19:30 +0000 | [diff] [blame] | 935 | SDValue T; |
| 936 | if (CPN->isMachineConstantPoolEntry()) |
| Ron Lieberman | 822ee88 | 2016-08-13 23:41:11 +0000 | [diff] [blame] | 937 | T = DAG.getTargetConstantPool(CPN->getMachineCPVal(), ValTy, Align, Offset, |
| 938 | TF); |
| Krzysztof Parzyszek | 91ff5c6 | 2017-08-01 13:12:53 +0000 | [diff] [blame] | 939 | else if (isVTi1Type) |
| 940 | T = DAG.getTargetConstantPool(CVal, ValTy, Align, Offset, TF); |
| Sirish Pande | 69295b8 | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 941 | else |
| Krzysztof Parzyszek | cfbe6ba | 2018-02-13 15:35:07 +0000 | [diff] [blame] | 942 | T = DAG.getTargetConstantPool(CPN->getConstVal(), ValTy, Align, Offset, TF); |
| Ron Lieberman | 822ee88 | 2016-08-13 23:41:11 +0000 | [diff] [blame] | 943 | |
| 944 | assert(cast<ConstantPoolSDNode>(T)->getTargetFlags() == TF && |
| 945 | "Inconsistent target flag encountered"); |
| 946 | |
| Rafael Espindola | 405e25a | 2016-06-26 22:24:01 +0000 | [diff] [blame] | 947 | if (IsPositionIndependent) |
| Krzysztof Parzyszek | 21dc8bd | 2015-12-18 20:19:30 +0000 | [diff] [blame] | 948 | return DAG.getNode(HexagonISD::AT_PCREL, SDLoc(Op), ValTy, T); |
| 949 | return DAG.getNode(HexagonISD::CP, SDLoc(Op), ValTy, T); |
| 950 | } |
| 951 | |
| 952 | SDValue |
| 953 | HexagonTargetLowering::LowerJumpTable(SDValue Op, SelectionDAG &DAG) const { |
| 954 | EVT VT = Op.getValueType(); |
| 955 | int Idx = cast<JumpTableSDNode>(Op)->getIndex(); |
| Rafael Espindola | 405e25a | 2016-06-26 22:24:01 +0000 | [diff] [blame] | 956 | if (isPositionIndependent()) { |
| Krzysztof Parzyszek | 21dc8bd | 2015-12-18 20:19:30 +0000 | [diff] [blame] | 957 | SDValue T = DAG.getTargetJumpTable(Idx, VT, HexagonII::MO_PCREL); |
| 958 | return DAG.getNode(HexagonISD::AT_PCREL, SDLoc(Op), VT, T); |
| 959 | } |
| 960 | |
| 961 | SDValue T = DAG.getTargetJumpTable(Idx, VT); |
| 962 | return DAG.getNode(HexagonISD::JT, SDLoc(Op), VT, T); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 963 | } |
| 964 | |
| 965 | SDValue |
| 966 | HexagonTargetLowering::LowerRETURNADDR(SDValue Op, SelectionDAG &DAG) const { |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 967 | const HexagonRegisterInfo &HRI = *Subtarget.getRegisterInfo(); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 968 | MachineFunction &MF = DAG.getMachineFunction(); |
| Matthias Braun | 941a705 | 2016-07-28 18:40:00 +0000 | [diff] [blame] | 969 | MachineFrameInfo &MFI = MF.getFrameInfo(); |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 970 | MFI.setReturnAddressIsTaken(true); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 971 | |
| Bill Wendling | 908bf81 | 2014-01-06 00:43:20 +0000 | [diff] [blame] | 972 | if (verifyReturnAddressArgumentIsConstant(Op, DAG)) |
| Bill Wendling | df7dd28 | 2014-01-05 01:47:20 +0000 | [diff] [blame] | 973 | return SDValue(); |
| Bill Wendling | df7dd28 | 2014-01-05 01:47:20 +0000 | [diff] [blame] | 974 | |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 975 | EVT VT = Op.getValueType(); |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 976 | SDLoc dl(Op); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 977 | unsigned Depth = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue(); |
| 978 | if (Depth) { |
| 979 | SDValue FrameAddr = LowerFRAMEADDR(Op, DAG); |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 980 | SDValue Offset = DAG.getConstant(4, dl, MVT::i32); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 981 | return DAG.getLoad(VT, dl, DAG.getEntryNode(), |
| 982 | DAG.getNode(ISD::ADD, dl, VT, FrameAddr, Offset), |
| Justin Lebar | 9c37581 | 2016-07-15 18:27:10 +0000 | [diff] [blame] | 983 | MachinePointerInfo()); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 984 | } |
| 985 | |
| 986 | // 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] | 987 | unsigned Reg = MF.addLiveIn(HRI.getRARegister(), getRegClassFor(MVT::i32)); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 988 | return DAG.getCopyFromReg(DAG.getEntryNode(), dl, Reg, VT); |
| 989 | } |
| 990 | |
| 991 | SDValue |
| 992 | HexagonTargetLowering::LowerFRAMEADDR(SDValue Op, SelectionDAG &DAG) const { |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 993 | const HexagonRegisterInfo &HRI = *Subtarget.getRegisterInfo(); |
| Matthias Braun | 941a705 | 2016-07-28 18:40:00 +0000 | [diff] [blame] | 994 | MachineFrameInfo &MFI = DAG.getMachineFunction().getFrameInfo(); |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 995 | MFI.setFrameAddressIsTaken(true); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 996 | |
| 997 | EVT VT = Op.getValueType(); |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 998 | SDLoc dl(Op); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 999 | unsigned Depth = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue(); |
| 1000 | SDValue FrameAddr = DAG.getCopyFromReg(DAG.getEntryNode(), dl, |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1001 | HRI.getFrameRegister(), VT); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1002 | while (Depth--) |
| 1003 | FrameAddr = DAG.getLoad(VT, dl, DAG.getEntryNode(), FrameAddr, |
| Justin Lebar | 9c37581 | 2016-07-15 18:27:10 +0000 | [diff] [blame] | 1004 | MachinePointerInfo()); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1005 | return FrameAddr; |
| 1006 | } |
| 1007 | |
| Krzysztof Parzyszek | 21dc8bd | 2015-12-18 20:19:30 +0000 | [diff] [blame] | 1008 | SDValue |
| 1009 | HexagonTargetLowering::LowerATOMIC_FENCE(SDValue Op, SelectionDAG& DAG) const { |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 1010 | SDLoc dl(Op); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1011 | return DAG.getNode(HexagonISD::BARRIER, dl, MVT::Other, Op.getOperand(0)); |
| 1012 | } |
| 1013 | |
| Krzysztof Parzyszek | 21dc8bd | 2015-12-18 20:19:30 +0000 | [diff] [blame] | 1014 | SDValue |
| 1015 | HexagonTargetLowering::LowerGLOBALADDRESS(SDValue Op, SelectionDAG &DAG) const { |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 1016 | SDLoc dl(Op); |
| Krzysztof Parzyszek | 21dc8bd | 2015-12-18 20:19:30 +0000 | [diff] [blame] | 1017 | auto *GAN = cast<GlobalAddressSDNode>(Op); |
| Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 1018 | auto PtrVT = getPointerTy(DAG.getDataLayout()); |
| Krzysztof Parzyszek | 96a2841 | 2018-01-30 18:10:27 +0000 | [diff] [blame] | 1019 | auto *GV = GAN->getGlobal(); |
| 1020 | int64_t Offset = GAN->getOffset(); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1021 | |
| Krzysztof Parzyszek | 21dc8bd | 2015-12-18 20:19:30 +0000 | [diff] [blame] | 1022 | auto &HLOF = *HTM.getObjFileLowering(); |
| 1023 | Reloc::Model RM = HTM.getRelocationModel(); |
| 1024 | |
| 1025 | if (RM == Reloc::Static) { |
| 1026 | SDValue GA = DAG.getTargetGlobalAddress(GV, dl, PtrVT, Offset); |
| Peter Collingbourne | 6733564 | 2016-10-24 19:23:39 +0000 | [diff] [blame] | 1027 | const GlobalObject *GO = GV->getBaseObject(); |
| Krzysztof Parzyszek | 44e180b | 2018-05-14 21:01:56 +0000 | [diff] [blame] | 1028 | if (GO && Subtarget.useSmallData() && HLOF.isGlobalInSmallSection(GO, HTM)) |
| Krzysztof Parzyszek | 96a2841 | 2018-01-30 18:10:27 +0000 | [diff] [blame] | 1029 | return DAG.getNode(HexagonISD::CONST32_GP, dl, PtrVT, GA); |
| 1030 | return DAG.getNode(HexagonISD::CONST32, dl, PtrVT, GA); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1031 | } |
| 1032 | |
| Krzysztof Parzyszek | 96a2841 | 2018-01-30 18:10:27 +0000 | [diff] [blame] | 1033 | bool UsePCRel = getTargetMachine().shouldAssumeDSOLocal(*GV->getParent(), GV); |
| 1034 | if (UsePCRel) { |
| 1035 | SDValue GA = DAG.getTargetGlobalAddress(GV, dl, PtrVT, Offset, |
| 1036 | HexagonII::MO_PCREL); |
| 1037 | return DAG.getNode(HexagonISD::AT_PCREL, dl, PtrVT, GA); |
| Krzysztof Parzyszek | 21dc8bd | 2015-12-18 20:19:30 +0000 | [diff] [blame] | 1038 | } |
| 1039 | |
| Krzysztof Parzyszek | 96a2841 | 2018-01-30 18:10:27 +0000 | [diff] [blame] | 1040 | // Use GOT index. |
| 1041 | SDValue GOT = DAG.getGLOBAL_OFFSET_TABLE(PtrVT); |
| 1042 | SDValue GA = DAG.getTargetGlobalAddress(GV, dl, PtrVT, 0, HexagonII::MO_GOT); |
| 1043 | SDValue Off = DAG.getConstant(Offset, dl, MVT::i32); |
| 1044 | return DAG.getNode(HexagonISD::AT_GOT, dl, PtrVT, GOT, GA, Off); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1045 | } |
| 1046 | |
| Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 1047 | // Specifies that for loads and stores VT can be promoted to PromotedLdStVT. |
| Jyotsna Verma | 2ba0c0b | 2013-03-07 19:10:28 +0000 | [diff] [blame] | 1048 | SDValue |
| 1049 | HexagonTargetLowering::LowerBlockAddress(SDValue Op, SelectionDAG &DAG) const { |
| 1050 | const BlockAddress *BA = cast<BlockAddressSDNode>(Op)->getBlockAddress(); |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 1051 | SDLoc dl(Op); |
| Krzysztof Parzyszek | 21dc8bd | 2015-12-18 20:19:30 +0000 | [diff] [blame] | 1052 | EVT PtrVT = getPointerTy(DAG.getDataLayout()); |
| 1053 | |
| 1054 | Reloc::Model RM = HTM.getRelocationModel(); |
| 1055 | if (RM == Reloc::Static) { |
| Krzysztof Parzyszek | 7a737d1 | 2016-02-18 15:42:57 +0000 | [diff] [blame] | 1056 | SDValue A = DAG.getTargetBlockAddress(BA, PtrVT); |
| Krzysztof Parzyszek | 21dc8bd | 2015-12-18 20:19:30 +0000 | [diff] [blame] | 1057 | return DAG.getNode(HexagonISD::CONST32_GP, dl, PtrVT, A); |
| 1058 | } |
| 1059 | |
| 1060 | SDValue A = DAG.getTargetBlockAddress(BA, PtrVT, 0, HexagonII::MO_PCREL); |
| 1061 | return DAG.getNode(HexagonISD::AT_PCREL, dl, PtrVT, A); |
| 1062 | } |
| 1063 | |
| 1064 | SDValue |
| 1065 | HexagonTargetLowering::LowerGLOBAL_OFFSET_TABLE(SDValue Op, SelectionDAG &DAG) |
| 1066 | const { |
| 1067 | EVT PtrVT = getPointerTy(DAG.getDataLayout()); |
| 1068 | SDValue GOTSym = DAG.getTargetExternalSymbol(HEXAGON_GOT_SYM_NAME, PtrVT, |
| 1069 | HexagonII::MO_PCREL); |
| 1070 | return DAG.getNode(HexagonISD::AT_PCREL, SDLoc(Op), PtrVT, GOTSym); |
| Jyotsna Verma | 2ba0c0b | 2013-03-07 19:10:28 +0000 | [diff] [blame] | 1071 | } |
| 1072 | |
| Krzysztof Parzyszek | 7a737d1 | 2016-02-18 15:42:57 +0000 | [diff] [blame] | 1073 | SDValue |
| 1074 | HexagonTargetLowering::GetDynamicTLSAddr(SelectionDAG &DAG, SDValue Chain, |
| Krzysztof Parzyszek | 1aaf41a | 2017-02-17 22:14:51 +0000 | [diff] [blame] | 1075 | GlobalAddressSDNode *GA, SDValue Glue, EVT PtrVT, unsigned ReturnReg, |
| Krzysztof Parzyszek | 7a737d1 | 2016-02-18 15:42:57 +0000 | [diff] [blame] | 1076 | unsigned char OperandFlags) const { |
| Krzysztof Parzyszek | 1aaf41a | 2017-02-17 22:14:51 +0000 | [diff] [blame] | 1077 | MachineFunction &MF = DAG.getMachineFunction(); |
| 1078 | MachineFrameInfo &MFI = MF.getFrameInfo(); |
| Krzysztof Parzyszek | 7a737d1 | 2016-02-18 15:42:57 +0000 | [diff] [blame] | 1079 | SDVTList NodeTys = DAG.getVTList(MVT::Other, MVT::Glue); |
| 1080 | SDLoc dl(GA); |
| 1081 | SDValue TGA = DAG.getTargetGlobalAddress(GA->getGlobal(), dl, |
| 1082 | GA->getValueType(0), |
| 1083 | GA->getOffset(), |
| 1084 | OperandFlags); |
| 1085 | // Create Operands for the call.The Operands should have the following: |
| 1086 | // 1. Chain SDValue |
| 1087 | // 2. Callee which in this case is the Global address value. |
| 1088 | // 3. Registers live into the call.In this case its R0, as we |
| 1089 | // have just one argument to be passed. |
| Krzysztof Parzyszek | 1aaf41a | 2017-02-17 22:14:51 +0000 | [diff] [blame] | 1090 | // 4. Glue. |
| Krzysztof Parzyszek | 7a737d1 | 2016-02-18 15:42:57 +0000 | [diff] [blame] | 1091 | // Note: The order is important. |
| 1092 | |
| Krzysztof Parzyszek | 1aaf41a | 2017-02-17 22:14:51 +0000 | [diff] [blame] | 1093 | const auto &HRI = *Subtarget.getRegisterInfo(); |
| 1094 | const uint32_t *Mask = HRI.getCallPreservedMask(MF, CallingConv::C); |
| 1095 | assert(Mask && "Missing call preserved mask for calling convention"); |
| 1096 | SDValue Ops[] = { Chain, TGA, DAG.getRegister(Hexagon::R0, PtrVT), |
| 1097 | DAG.getRegisterMask(Mask), Glue }; |
| 1098 | Chain = DAG.getNode(HexagonISD::CALL, dl, NodeTys, Ops); |
| Krzysztof Parzyszek | 7a737d1 | 2016-02-18 15:42:57 +0000 | [diff] [blame] | 1099 | |
| 1100 | // Inform MFI that function has calls. |
| Matthias Braun | 941a705 | 2016-07-28 18:40:00 +0000 | [diff] [blame] | 1101 | MFI.setAdjustsStack(true); |
| Krzysztof Parzyszek | 7a737d1 | 2016-02-18 15:42:57 +0000 | [diff] [blame] | 1102 | |
| Krzysztof Parzyszek | 1aaf41a | 2017-02-17 22:14:51 +0000 | [diff] [blame] | 1103 | Glue = Chain.getValue(1); |
| 1104 | return DAG.getCopyFromReg(Chain, dl, ReturnReg, PtrVT, Glue); |
| Krzysztof Parzyszek | 7a737d1 | 2016-02-18 15:42:57 +0000 | [diff] [blame] | 1105 | } |
| 1106 | |
| 1107 | // |
| 1108 | // Lower using the intial executable model for TLS addresses |
| 1109 | // |
| 1110 | SDValue |
| 1111 | HexagonTargetLowering::LowerToTLSInitialExecModel(GlobalAddressSDNode *GA, |
| 1112 | SelectionDAG &DAG) const { |
| 1113 | SDLoc dl(GA); |
| 1114 | int64_t Offset = GA->getOffset(); |
| 1115 | auto PtrVT = getPointerTy(DAG.getDataLayout()); |
| 1116 | |
| 1117 | // Get the thread pointer. |
| 1118 | SDValue TP = DAG.getCopyFromReg(DAG.getEntryNode(), dl, Hexagon::UGP, PtrVT); |
| 1119 | |
| Rafael Espindola | 405e25a | 2016-06-26 22:24:01 +0000 | [diff] [blame] | 1120 | bool IsPositionIndependent = isPositionIndependent(); |
| 1121 | unsigned char TF = |
| 1122 | IsPositionIndependent ? HexagonII::MO_IEGOT : HexagonII::MO_IE; |
| Krzysztof Parzyszek | 7a737d1 | 2016-02-18 15:42:57 +0000 | [diff] [blame] | 1123 | |
| 1124 | // First generate the TLS symbol address |
| 1125 | SDValue TGA = DAG.getTargetGlobalAddress(GA->getGlobal(), dl, PtrVT, |
| 1126 | Offset, TF); |
| 1127 | |
| 1128 | SDValue Sym = DAG.getNode(HexagonISD::CONST32, dl, PtrVT, TGA); |
| 1129 | |
| Rafael Espindola | 405e25a | 2016-06-26 22:24:01 +0000 | [diff] [blame] | 1130 | if (IsPositionIndependent) { |
| Krzysztof Parzyszek | 7a737d1 | 2016-02-18 15:42:57 +0000 | [diff] [blame] | 1131 | // Generate the GOT pointer in case of position independent code |
| 1132 | SDValue GOT = LowerGLOBAL_OFFSET_TABLE(Sym, DAG); |
| 1133 | |
| 1134 | // Add the TLS Symbol address to GOT pointer.This gives |
| 1135 | // GOT relative relocation for the symbol. |
| 1136 | Sym = DAG.getNode(ISD::ADD, dl, PtrVT, GOT, Sym); |
| 1137 | } |
| 1138 | |
| 1139 | // Load the offset value for TLS symbol.This offset is relative to |
| 1140 | // thread pointer. |
| Justin Lebar | 9c37581 | 2016-07-15 18:27:10 +0000 | [diff] [blame] | 1141 | SDValue LoadOffset = |
| 1142 | DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), Sym, MachinePointerInfo()); |
| Krzysztof Parzyszek | 7a737d1 | 2016-02-18 15:42:57 +0000 | [diff] [blame] | 1143 | |
| 1144 | // Address of the thread local variable is the add of thread |
| 1145 | // pointer and the offset of the variable. |
| 1146 | return DAG.getNode(ISD::ADD, dl, PtrVT, TP, LoadOffset); |
| 1147 | } |
| 1148 | |
| 1149 | // |
| 1150 | // Lower using the local executable model for TLS addresses |
| 1151 | // |
| 1152 | SDValue |
| 1153 | HexagonTargetLowering::LowerToTLSLocalExecModel(GlobalAddressSDNode *GA, |
| 1154 | SelectionDAG &DAG) const { |
| 1155 | SDLoc dl(GA); |
| 1156 | int64_t Offset = GA->getOffset(); |
| 1157 | auto PtrVT = getPointerTy(DAG.getDataLayout()); |
| 1158 | |
| 1159 | // Get the thread pointer. |
| 1160 | SDValue TP = DAG.getCopyFromReg(DAG.getEntryNode(), dl, Hexagon::UGP, PtrVT); |
| 1161 | // Generate the TLS symbol address |
| 1162 | SDValue TGA = DAG.getTargetGlobalAddress(GA->getGlobal(), dl, PtrVT, Offset, |
| 1163 | HexagonII::MO_TPREL); |
| 1164 | SDValue Sym = DAG.getNode(HexagonISD::CONST32, dl, PtrVT, TGA); |
| 1165 | |
| 1166 | // Address of the thread local variable is the add of thread |
| 1167 | // pointer and the offset of the variable. |
| 1168 | return DAG.getNode(ISD::ADD, dl, PtrVT, TP, Sym); |
| 1169 | } |
| 1170 | |
| 1171 | // |
| 1172 | // Lower using the general dynamic model for TLS addresses |
| 1173 | // |
| 1174 | SDValue |
| 1175 | HexagonTargetLowering::LowerToTLSGeneralDynamicModel(GlobalAddressSDNode *GA, |
| 1176 | SelectionDAG &DAG) const { |
| 1177 | SDLoc dl(GA); |
| 1178 | int64_t Offset = GA->getOffset(); |
| 1179 | auto PtrVT = getPointerTy(DAG.getDataLayout()); |
| 1180 | |
| 1181 | // First generate the TLS symbol address |
| 1182 | SDValue TGA = DAG.getTargetGlobalAddress(GA->getGlobal(), dl, PtrVT, Offset, |
| 1183 | HexagonII::MO_GDGOT); |
| 1184 | |
| 1185 | // Then, generate the GOT pointer |
| 1186 | SDValue GOT = LowerGLOBAL_OFFSET_TABLE(TGA, DAG); |
| 1187 | |
| 1188 | // Add the TLS symbol and the GOT pointer |
| 1189 | SDValue Sym = DAG.getNode(HexagonISD::CONST32, dl, PtrVT, TGA); |
| 1190 | SDValue Chain = DAG.getNode(ISD::ADD, dl, PtrVT, GOT, Sym); |
| 1191 | |
| 1192 | // Copy over the argument to R0 |
| 1193 | SDValue InFlag; |
| 1194 | Chain = DAG.getCopyToReg(DAG.getEntryNode(), dl, Hexagon::R0, Chain, InFlag); |
| 1195 | InFlag = Chain.getValue(1); |
| 1196 | |
| Krzysztof Parzyszek | a750383 | 2017-05-02 18:15:33 +0000 | [diff] [blame] | 1197 | unsigned Flags = |
| 1198 | static_cast<const HexagonSubtarget &>(DAG.getSubtarget()).useLongCalls() |
| 1199 | ? HexagonII::MO_GDPLT | HexagonII::HMOTF_ConstExtended |
| 1200 | : HexagonII::MO_GDPLT; |
| 1201 | |
| Krzysztof Parzyszek | 1aaf41a | 2017-02-17 22:14:51 +0000 | [diff] [blame] | 1202 | return GetDynamicTLSAddr(DAG, Chain, GA, InFlag, PtrVT, |
| Krzysztof Parzyszek | a750383 | 2017-05-02 18:15:33 +0000 | [diff] [blame] | 1203 | Hexagon::R0, Flags); |
| Krzysztof Parzyszek | 7a737d1 | 2016-02-18 15:42:57 +0000 | [diff] [blame] | 1204 | } |
| 1205 | |
| 1206 | // |
| 1207 | // Lower TLS addresses. |
| 1208 | // |
| 1209 | // For now for dynamic models, we only support the general dynamic model. |
| 1210 | // |
| 1211 | SDValue |
| 1212 | HexagonTargetLowering::LowerGlobalTLSAddress(SDValue Op, |
| 1213 | SelectionDAG &DAG) const { |
| 1214 | GlobalAddressSDNode *GA = cast<GlobalAddressSDNode>(Op); |
| 1215 | |
| 1216 | switch (HTM.getTLSModel(GA->getGlobal())) { |
| 1217 | case TLSModel::GeneralDynamic: |
| 1218 | case TLSModel::LocalDynamic: |
| 1219 | return LowerToTLSGeneralDynamicModel(GA, DAG); |
| 1220 | case TLSModel::InitialExec: |
| 1221 | return LowerToTLSInitialExecModel(GA, DAG); |
| 1222 | case TLSModel::LocalExec: |
| 1223 | return LowerToTLSLocalExecModel(GA, DAG); |
| 1224 | } |
| 1225 | llvm_unreachable("Bogus TLS model"); |
| 1226 | } |
| 1227 | |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1228 | //===----------------------------------------------------------------------===// |
| 1229 | // TargetLowering Implementation |
| 1230 | //===----------------------------------------------------------------------===// |
| 1231 | |
| Eric Christopher | d737b76 | 2015-02-02 22:11:36 +0000 | [diff] [blame] | 1232 | HexagonTargetLowering::HexagonTargetLowering(const TargetMachine &TM, |
| Krzysztof Parzyszek | 08ff888 | 2015-11-26 18:38:27 +0000 | [diff] [blame] | 1233 | const HexagonSubtarget &ST) |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1234 | : TargetLowering(TM), HTM(static_cast<const HexagonTargetMachine&>(TM)), |
| Krzysztof Parzyszek | 08ff888 | 2015-11-26 18:38:27 +0000 | [diff] [blame] | 1235 | Subtarget(ST) { |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1236 | auto &HRI = *Subtarget.getRegisterInfo(); |
| Sirish Pande | 69295b8 | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 1237 | |
| Guillaume Chatelet | aff45e4 | 2019-09-05 10:00:22 +0000 | [diff] [blame] | 1238 | setPrefLoopLogAlignment(4); |
| 1239 | setPrefFunctionLogAlignment(4); |
| 1240 | setMinFunctionLogAlignment(2); |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1241 | setStackPointerRegisterToSaveRestore(HRI.getStackRegister()); |
| Krzysztof Parzyszek | b3e50ac | 2018-01-05 20:41:50 +0000 | [diff] [blame] | 1242 | setBooleanContents(TargetLoweringBase::UndefinedBooleanContent); |
| 1243 | setBooleanVectorContents(TargetLoweringBase::UndefinedBooleanContent); |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1244 | |
| Krzysztof Parzyszek | f228c95 | 2016-06-22 16:07:10 +0000 | [diff] [blame] | 1245 | setMaxAtomicSizeInBitsSupported(64); |
| 1246 | setMinCmpXchgSizeInBits(32); |
| 1247 | |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1248 | if (EnableHexSDNodeSched) |
| 1249 | setSchedulingPreference(Sched::VLIW); |
| 1250 | else |
| 1251 | setSchedulingPreference(Sched::Source); |
| 1252 | |
| 1253 | // Limits for inline expansion of memcpy/memmove |
| 1254 | MaxStoresPerMemcpy = MaxStoresPerMemcpyCL; |
| 1255 | MaxStoresPerMemcpyOptSize = MaxStoresPerMemcpyOptSizeCL; |
| 1256 | MaxStoresPerMemmove = MaxStoresPerMemmoveCL; |
| 1257 | MaxStoresPerMemmoveOptSize = MaxStoresPerMemmoveOptSizeCL; |
| 1258 | MaxStoresPerMemset = MaxStoresPerMemsetCL; |
| 1259 | MaxStoresPerMemsetOptSize = MaxStoresPerMemsetOptSizeCL; |
| 1260 | |
| 1261 | // |
| 1262 | // Set up register classes. |
| 1263 | // |
| 1264 | |
| 1265 | addRegisterClass(MVT::i1, &Hexagon::PredRegsRegClass); |
| 1266 | addRegisterClass(MVT::v2i1, &Hexagon::PredRegsRegClass); // bbbbaaaa |
| 1267 | addRegisterClass(MVT::v4i1, &Hexagon::PredRegsRegClass); // ddccbbaa |
| 1268 | addRegisterClass(MVT::v8i1, &Hexagon::PredRegsRegClass); // hgfedcba |
| 1269 | addRegisterClass(MVT::i32, &Hexagon::IntRegsRegClass); |
| Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 1270 | addRegisterClass(MVT::v2i16, &Hexagon::IntRegsRegClass); |
| Krzysztof Parzyszek | e4ce92c | 2017-12-20 20:49:43 +0000 | [diff] [blame] | 1271 | addRegisterClass(MVT::v4i8, &Hexagon::IntRegsRegClass); |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1272 | addRegisterClass(MVT::i64, &Hexagon::DoubleRegsRegClass); |
| 1273 | addRegisterClass(MVT::v8i8, &Hexagon::DoubleRegsRegClass); |
| 1274 | addRegisterClass(MVT::v4i16, &Hexagon::DoubleRegsRegClass); |
| 1275 | addRegisterClass(MVT::v2i32, &Hexagon::DoubleRegsRegClass); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1276 | |
| Krzysztof Parzyszek | 6bfc657 | 2018-10-19 17:31:11 +0000 | [diff] [blame] | 1277 | addRegisterClass(MVT::f32, &Hexagon::IntRegsRegClass); |
| 1278 | addRegisterClass(MVT::f64, &Hexagon::DoubleRegsRegClass); |
| Sirish Pande | 69295b8 | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 1279 | |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1280 | // |
| 1281 | // Handling of scalar operations. |
| 1282 | // |
| 1283 | // All operations default to "legal", except: |
| 1284 | // - indexed loads and stores (pre-/post-incremented), |
| 1285 | // - ANY_EXTEND_VECTOR_INREG, ATOMIC_CMP_SWAP_WITH_SUCCESS, CONCAT_VECTORS, |
| 1286 | // ConstantFP, DEBUGTRAP, FCEIL, FCOPYSIGN, FEXP, FEXP2, FFLOOR, FGETSIGN, |
| 1287 | // FLOG, FLOG2, FLOG10, FMAXNUM, FMINNUM, FNEARBYINT, FRINT, FROUND, TRAP, |
| 1288 | // FTRUNC, PREFETCH, SIGN_EXTEND_VECTOR_INREG, ZERO_EXTEND_VECTOR_INREG, |
| 1289 | // which default to "expand" for at least one type. |
| Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 1290 | |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1291 | // Misc operations. |
| Krzysztof Parzyszek | 75c2ca3 | 2018-08-09 18:03:45 +0000 | [diff] [blame] | 1292 | setOperationAction(ISD::ConstantFP, MVT::f32, Legal); |
| 1293 | setOperationAction(ISD::ConstantFP, MVT::f64, Legal); |
| 1294 | setOperationAction(ISD::TRAP, MVT::Other, Legal); |
| 1295 | setOperationAction(ISD::ConstantPool, MVT::i32, Custom); |
| 1296 | setOperationAction(ISD::JumpTable, MVT::i32, Custom); |
| 1297 | setOperationAction(ISD::BUILD_PAIR, MVT::i64, Expand); |
| 1298 | setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i1, Expand); |
| 1299 | setOperationAction(ISD::INLINEASM, MVT::Other, Custom); |
| Craig Topper | 784929d | 2019-02-08 20:48:56 +0000 | [diff] [blame] | 1300 | setOperationAction(ISD::INLINEASM_BR, MVT::Other, Custom); |
| Krzysztof Parzyszek | 75c2ca3 | 2018-08-09 18:03:45 +0000 | [diff] [blame] | 1301 | setOperationAction(ISD::PREFETCH, MVT::Other, Custom); |
| 1302 | setOperationAction(ISD::READCYCLECOUNTER, MVT::i64, Custom); |
| 1303 | setOperationAction(ISD::INTRINSIC_VOID, MVT::Other, Custom); |
| 1304 | setOperationAction(ISD::EH_RETURN, MVT::Other, Custom); |
| 1305 | setOperationAction(ISD::GLOBAL_OFFSET_TABLE, MVT::i32, Custom); |
| 1306 | setOperationAction(ISD::GlobalTLSAddress, MVT::i32, Custom); |
| 1307 | setOperationAction(ISD::ATOMIC_FENCE, MVT::Other, Custom); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1308 | |
| Eric Christopher | 6e9bcd1 | 2014-06-27 00:13:49 +0000 | [diff] [blame] | 1309 | // Custom legalize GlobalAddress nodes into CONST32. |
| 1310 | setOperationAction(ISD::GlobalAddress, MVT::i32, Custom); |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1311 | setOperationAction(ISD::GlobalAddress, MVT::i8, Custom); |
| 1312 | setOperationAction(ISD::BlockAddress, MVT::i32, Custom); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1313 | |
| Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 1314 | // Hexagon needs to optimize cases with negative constants. |
| Krzysztof Parzyszek | 23bcf06 | 2018-04-19 14:24:31 +0000 | [diff] [blame] | 1315 | setOperationAction(ISD::SETCC, MVT::i8, Custom); |
| 1316 | setOperationAction(ISD::SETCC, MVT::i16, Custom); |
| 1317 | setOperationAction(ISD::SETCC, MVT::v4i8, Custom); |
| 1318 | setOperationAction(ISD::SETCC, MVT::v2i16, Custom); |
| Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 1319 | |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1320 | // VASTART needs to be custom lowered to use the VarArgsFrameIndex. |
| 1321 | setOperationAction(ISD::VASTART, MVT::Other, Custom); |
| 1322 | setOperationAction(ISD::VAEND, MVT::Other, Expand); |
| 1323 | setOperationAction(ISD::VAARG, MVT::Other, Expand); |
| Krzysztof Parzyszek | f608812 | 2018-03-02 18:35:57 +0000 | [diff] [blame] | 1324 | setOperationAction(ISD::VACOPY, MVT::Other, Expand); |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1325 | |
| 1326 | setOperationAction(ISD::STACKSAVE, MVT::Other, Expand); |
| 1327 | setOperationAction(ISD::STACKRESTORE, MVT::Other, Expand); |
| 1328 | setOperationAction(ISD::DYNAMIC_STACKALLOC, MVT::i32, Custom); |
| 1329 | |
| 1330 | if (EmitJumpTables) |
| Krzysztof Parzyszek | 21dc8bd | 2015-12-18 20:19:30 +0000 | [diff] [blame] | 1331 | setMinimumJumpTableEntries(MinimumJumpTables); |
| Krzysztof Parzyszek | a61f7da | 2016-01-13 21:43:13 +0000 | [diff] [blame] | 1332 | else |
| Evandro Menezes | 56c45e9 | 2019-06-19 16:12:01 +0000 | [diff] [blame] | 1333 | setMinimumJumpTableEntries(std::numeric_limits<unsigned>::max()); |
| Krzysztof Parzyszek | 21dc8bd | 2015-12-18 20:19:30 +0000 | [diff] [blame] | 1334 | setOperationAction(ISD::BR_JT, MVT::Other, Expand); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1335 | |
| Krzysztof Parzyszek | 82d284c | 2018-06-12 21:51:49 +0000 | [diff] [blame] | 1336 | setOperationAction(ISD::ABS, MVT::i32, Legal); |
| 1337 | setOperationAction(ISD::ABS, MVT::i64, Legal); |
| 1338 | |
| Krzysztof Parzyszek | 0b6187c | 2018-06-01 14:00:32 +0000 | [diff] [blame] | 1339 | // Hexagon has A4_addp_c and A4_subp_c that take and generate a carry bit, |
| 1340 | // but they only operate on i64. |
| Krzysztof Parzyszek | 2c4487d | 2015-04-13 20:37:01 +0000 | [diff] [blame] | 1341 | for (MVT VT : MVT::integer_valuetypes()) { |
| Krzysztof Parzyszek | 5abf80c | 2019-07-01 15:50:09 +0000 | [diff] [blame] | 1342 | setOperationAction(ISD::UADDO, VT, Custom); |
| 1343 | setOperationAction(ISD::USUBO, VT, Custom); |
| Krzysztof Parzyszek | 0b6187c | 2018-06-01 14:00:32 +0000 | [diff] [blame] | 1344 | setOperationAction(ISD::SADDO, VT, Expand); |
| 1345 | setOperationAction(ISD::SSUBO, VT, Expand); |
| 1346 | setOperationAction(ISD::ADDCARRY, VT, Expand); |
| 1347 | setOperationAction(ISD::SUBCARRY, VT, Expand); |
| Krzysztof Parzyszek | 2c4487d | 2015-04-13 20:37:01 +0000 | [diff] [blame] | 1348 | } |
| Krzysztof Parzyszek | 0b6187c | 2018-06-01 14:00:32 +0000 | [diff] [blame] | 1349 | setOperationAction(ISD::ADDCARRY, MVT::i64, Custom); |
| 1350 | setOperationAction(ISD::SUBCARRY, MVT::i64, Custom); |
| Krzysztof Parzyszek | 2c4487d | 2015-04-13 20:37:01 +0000 | [diff] [blame] | 1351 | |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1352 | setOperationAction(ISD::CTLZ, MVT::i8, Promote); |
| 1353 | setOperationAction(ISD::CTLZ, MVT::i16, Promote); |
| 1354 | setOperationAction(ISD::CTTZ, MVT::i8, Promote); |
| 1355 | setOperationAction(ISD::CTTZ, MVT::i16, Promote); |
| Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 1356 | |
| Krzysztof Parzyszek | 6bfc657 | 2018-10-19 17:31:11 +0000 | [diff] [blame] | 1357 | // Popcount can count # of 1s in i64 but returns i32. |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1358 | setOperationAction(ISD::CTPOP, MVT::i8, Promote); |
| 1359 | setOperationAction(ISD::CTPOP, MVT::i16, Promote); |
| 1360 | setOperationAction(ISD::CTPOP, MVT::i32, Promote); |
| Krzysztof Parzyszek | af5ff65 | 2017-02-23 15:02:09 +0000 | [diff] [blame] | 1361 | setOperationAction(ISD::CTPOP, MVT::i64, Legal); |
| 1362 | |
| 1363 | setOperationAction(ISD::BITREVERSE, MVT::i32, Legal); |
| 1364 | setOperationAction(ISD::BITREVERSE, MVT::i64, Legal); |
| 1365 | setOperationAction(ISD::BSWAP, MVT::i32, Legal); |
| 1366 | setOperationAction(ISD::BSWAP, MVT::i64, Legal); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1367 | |
| Krzysztof Parzyszek | 30c42e2 | 2018-12-20 16:39:20 +0000 | [diff] [blame] | 1368 | setOperationAction(ISD::FSHL, MVT::i32, Legal); |
| 1369 | setOperationAction(ISD::FSHL, MVT::i64, Legal); |
| 1370 | setOperationAction(ISD::FSHR, MVT::i32, Legal); |
| 1371 | setOperationAction(ISD::FSHR, MVT::i64, Legal); |
| 1372 | |
| Benjamin Kramer | 6246069 | 2015-04-25 14:46:53 +0000 | [diff] [blame] | 1373 | for (unsigned IntExpOp : |
| Krzysztof Parzyszek | aafb8c2 | 2018-06-05 12:49:19 +0000 | [diff] [blame] | 1374 | {ISD::SDIV, ISD::UDIV, ISD::SREM, ISD::UREM, |
| 1375 | ISD::SDIVREM, ISD::UDIVREM, ISD::ROTL, ISD::ROTR, |
| 1376 | ISD::SHL_PARTS, ISD::SRA_PARTS, ISD::SRL_PARTS, |
| 1377 | ISD::SMUL_LOHI, ISD::UMUL_LOHI}) { |
| 1378 | for (MVT VT : MVT::integer_valuetypes()) |
| 1379 | setOperationAction(IntExpOp, VT, Expand); |
| Benjamin Kramer | 6246069 | 2015-04-25 14:46:53 +0000 | [diff] [blame] | 1380 | } |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1381 | |
| Benjamin Kramer | 6246069 | 2015-04-25 14:46:53 +0000 | [diff] [blame] | 1382 | for (unsigned FPExpOp : |
| 1383 | {ISD::FDIV, ISD::FREM, ISD::FSQRT, ISD::FSIN, ISD::FCOS, ISD::FSINCOS, |
| 1384 | ISD::FPOW, ISD::FCOPYSIGN}) { |
| Krzysztof Parzyszek | aafb8c2 | 2018-06-05 12:49:19 +0000 | [diff] [blame] | 1385 | for (MVT VT : MVT::fp_valuetypes()) |
| 1386 | setOperationAction(FPExpOp, VT, Expand); |
| Benjamin Kramer | 6246069 | 2015-04-25 14:46:53 +0000 | [diff] [blame] | 1387 | } |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1388 | |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1389 | // No extending loads from i32. |
| 1390 | for (MVT VT : MVT::integer_valuetypes()) { |
| 1391 | setLoadExtAction(ISD::ZEXTLOAD, VT, MVT::i32, Expand); |
| 1392 | setLoadExtAction(ISD::SEXTLOAD, VT, MVT::i32, Expand); |
| 1393 | setLoadExtAction(ISD::EXTLOAD, VT, MVT::i32, Expand); |
| 1394 | } |
| 1395 | // Turn FP truncstore into trunc + store. |
| 1396 | setTruncStoreAction(MVT::f64, MVT::f32, Expand); |
| Michael Kuperstein | 2bc3d4d | 2016-08-18 20:08:15 +0000 | [diff] [blame] | 1397 | // Turn FP extload into load/fpextend. |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1398 | for (MVT VT : MVT::fp_valuetypes()) |
| 1399 | setLoadExtAction(ISD::EXTLOAD, VT, MVT::f32, Expand); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1400 | |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1401 | // Expand BR_CC and SELECT_CC for all integer and fp types. |
| 1402 | for (MVT VT : MVT::integer_valuetypes()) { |
| 1403 | setOperationAction(ISD::BR_CC, VT, Expand); |
| 1404 | setOperationAction(ISD::SELECT_CC, VT, Expand); |
| 1405 | } |
| 1406 | for (MVT VT : MVT::fp_valuetypes()) { |
| 1407 | setOperationAction(ISD::BR_CC, VT, Expand); |
| 1408 | setOperationAction(ISD::SELECT_CC, VT, Expand); |
| 1409 | } |
| 1410 | setOperationAction(ISD::BR_CC, MVT::Other, Expand); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1411 | |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1412 | // |
| 1413 | // Handling of vector operations. |
| 1414 | // |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1415 | |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1416 | // Set the action for vector operations to "expand", then override it with |
| 1417 | // either "custom" or "legal" for specific cases. |
| Craig Topper | 2626094 | 2015-10-18 05:15:34 +0000 | [diff] [blame] | 1418 | static const unsigned VectExpOps[] = { |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1419 | // Integer arithmetic: |
| Amaury Sechet | 8467411 | 2018-06-01 13:21:33 +0000 | [diff] [blame] | 1420 | ISD::ADD, ISD::SUB, ISD::MUL, ISD::SDIV, ISD::UDIV, |
| 1421 | ISD::SREM, ISD::UREM, ISD::SDIVREM, ISD::UDIVREM, ISD::SADDO, |
| 1422 | ISD::UADDO, ISD::SSUBO, ISD::USUBO, ISD::SMUL_LOHI, ISD::UMUL_LOHI, |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1423 | // Logical/bit: |
| 1424 | ISD::AND, ISD::OR, ISD::XOR, ISD::ROTL, ISD::ROTR, |
| Craig Topper | 33772c5 | 2016-04-28 03:34:31 +0000 | [diff] [blame] | 1425 | ISD::CTPOP, ISD::CTLZ, ISD::CTTZ, |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1426 | // Floating point arithmetic/math functions: |
| 1427 | ISD::FADD, ISD::FSUB, ISD::FMUL, ISD::FMA, ISD::FDIV, |
| 1428 | ISD::FREM, ISD::FNEG, ISD::FABS, ISD::FSQRT, ISD::FSIN, |
| Craig Topper | f6d4dc5 | 2017-05-30 15:27:55 +0000 | [diff] [blame] | 1429 | ISD::FCOS, ISD::FPOW, ISD::FLOG, ISD::FLOG2, |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1430 | ISD::FLOG10, ISD::FEXP, ISD::FEXP2, ISD::FCEIL, ISD::FTRUNC, |
| 1431 | ISD::FRINT, ISD::FNEARBYINT, ISD::FROUND, ISD::FFLOOR, |
| 1432 | ISD::FMINNUM, ISD::FMAXNUM, ISD::FSINCOS, |
| 1433 | // Misc: |
| Krzysztof Parzyszek | 046da74 | 2016-10-27 14:30:16 +0000 | [diff] [blame] | 1434 | ISD::BR_CC, ISD::SELECT_CC, ISD::ConstantPool, |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1435 | // Vector: |
| 1436 | ISD::BUILD_VECTOR, ISD::SCALAR_TO_VECTOR, |
| 1437 | ISD::EXTRACT_VECTOR_ELT, ISD::INSERT_VECTOR_ELT, |
| 1438 | ISD::EXTRACT_SUBVECTOR, ISD::INSERT_SUBVECTOR, |
| 1439 | ISD::CONCAT_VECTORS, ISD::VECTOR_SHUFFLE |
| 1440 | }; |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1441 | |
| 1442 | for (MVT VT : MVT::vector_valuetypes()) { |
| Benjamin Kramer | 6246069 | 2015-04-25 14:46:53 +0000 | [diff] [blame] | 1443 | for (unsigned VectExpOp : VectExpOps) |
| 1444 | setOperationAction(VectExpOp, VT, Expand); |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1445 | |
| Krzysztof Parzyszek | a696b1b | 2016-09-08 17:42:14 +0000 | [diff] [blame] | 1446 | // Expand all extending loads and truncating stores: |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1447 | for (MVT TargetVT : MVT::vector_valuetypes()) { |
| Krzysztof Parzyszek | a696b1b | 2016-09-08 17:42:14 +0000 | [diff] [blame] | 1448 | if (TargetVT == VT) |
| 1449 | continue; |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1450 | setLoadExtAction(ISD::EXTLOAD, TargetVT, VT, Expand); |
| Krzysztof Parzyszek | a696b1b | 2016-09-08 17:42:14 +0000 | [diff] [blame] | 1451 | setLoadExtAction(ISD::ZEXTLOAD, TargetVT, VT, Expand); |
| 1452 | setLoadExtAction(ISD::SEXTLOAD, TargetVT, VT, Expand); |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1453 | setTruncStoreAction(VT, TargetVT, Expand); |
| 1454 | } |
| 1455 | |
| Krzysztof Parzyszek | 046da74 | 2016-10-27 14:30:16 +0000 | [diff] [blame] | 1456 | // Normalize all inputs to SELECT to be vectors of i32. |
| 1457 | if (VT.getVectorElementType() != MVT::i32) { |
| 1458 | MVT VT32 = MVT::getVectorVT(MVT::i32, VT.getSizeInBits()/32); |
| 1459 | setOperationAction(ISD::SELECT, VT, Promote); |
| 1460 | AddPromotedToType(ISD::SELECT, VT, VT32); |
| 1461 | } |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1462 | setOperationAction(ISD::SRA, VT, Custom); |
| 1463 | setOperationAction(ISD::SHL, VT, Custom); |
| 1464 | setOperationAction(ISD::SRL, VT, Custom); |
| 1465 | } |
| 1466 | |
| Krzysztof Parzyszek | 64e5d7d | 2017-10-20 19:33:12 +0000 | [diff] [blame] | 1467 | // Extending loads from (native) vectors of i8 into (native) vectors of i16 |
| 1468 | // are legal. |
| Krzysztof Parzyszek | 3780a0e | 2018-01-23 17:53:59 +0000 | [diff] [blame] | 1469 | setLoadExtAction(ISD::EXTLOAD, MVT::v2i16, MVT::v2i8, Legal); |
| Krzysztof Parzyszek | 64e5d7d | 2017-10-20 19:33:12 +0000 | [diff] [blame] | 1470 | setLoadExtAction(ISD::ZEXTLOAD, MVT::v2i16, MVT::v2i8, Legal); |
| 1471 | setLoadExtAction(ISD::SEXTLOAD, MVT::v2i16, MVT::v2i8, Legal); |
| Krzysztof Parzyszek | 3780a0e | 2018-01-23 17:53:59 +0000 | [diff] [blame] | 1472 | setLoadExtAction(ISD::EXTLOAD, MVT::v4i16, MVT::v4i8, Legal); |
| Krzysztof Parzyszek | 64e5d7d | 2017-10-20 19:33:12 +0000 | [diff] [blame] | 1473 | setLoadExtAction(ISD::ZEXTLOAD, MVT::v4i16, MVT::v4i8, Legal); |
| 1474 | setLoadExtAction(ISD::SEXTLOAD, MVT::v4i16, MVT::v4i8, Legal); |
| 1475 | |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1476 | // Types natively supported: |
| Krzysztof Parzyszek | 3780a0e | 2018-01-23 17:53:59 +0000 | [diff] [blame] | 1477 | for (MVT NativeVT : {MVT::v8i1, MVT::v4i1, MVT::v2i1, MVT::v4i8, |
| 1478 | MVT::v8i8, MVT::v2i16, MVT::v4i16, MVT::v2i32}) { |
| Benjamin Kramer | 6246069 | 2015-04-25 14:46:53 +0000 | [diff] [blame] | 1479 | setOperationAction(ISD::BUILD_VECTOR, NativeVT, Custom); |
| 1480 | setOperationAction(ISD::EXTRACT_VECTOR_ELT, NativeVT, Custom); |
| 1481 | setOperationAction(ISD::INSERT_VECTOR_ELT, NativeVT, Custom); |
| 1482 | setOperationAction(ISD::EXTRACT_SUBVECTOR, NativeVT, Custom); |
| 1483 | setOperationAction(ISD::INSERT_SUBVECTOR, NativeVT, Custom); |
| 1484 | setOperationAction(ISD::CONCAT_VECTORS, NativeVT, Custom); |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1485 | |
| Benjamin Kramer | 6246069 | 2015-04-25 14:46:53 +0000 | [diff] [blame] | 1486 | setOperationAction(ISD::ADD, NativeVT, Legal); |
| 1487 | setOperationAction(ISD::SUB, NativeVT, Legal); |
| 1488 | setOperationAction(ISD::MUL, NativeVT, Legal); |
| 1489 | setOperationAction(ISD::AND, NativeVT, Legal); |
| 1490 | setOperationAction(ISD::OR, NativeVT, Legal); |
| 1491 | setOperationAction(ISD::XOR, NativeVT, Legal); |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1492 | } |
| 1493 | |
| Krzysztof Parzyszek | 2c3edf0 | 2018-03-07 17:27:18 +0000 | [diff] [blame] | 1494 | // Custom lower unaligned loads. |
| Krzysztof Parzyszek | 1df7059 | 2018-08-08 17:00:09 +0000 | [diff] [blame] | 1495 | // Also, for both loads and stores, verify the alignment of the address |
| 1496 | // in case it is a compile-time constant. This is a usability feature to |
| 1497 | // provide a meaningful error message to users. |
| 1498 | for (MVT VT : {MVT::i16, MVT::i32, MVT::v4i8, MVT::i64, MVT::v8i8, |
| 1499 | MVT::v2i16, MVT::v4i16, MVT::v2i32}) { |
| 1500 | setOperationAction(ISD::LOAD, VT, Custom); |
| 1501 | setOperationAction(ISD::STORE, VT, Custom); |
| Krzysztof Parzyszek | 2c3edf0 | 2018-03-07 17:27:18 +0000 | [diff] [blame] | 1502 | } |
| 1503 | |
| Krzysztof Parzyszek | ac83aab | 2019-08-16 16:16:27 +0000 | [diff] [blame] | 1504 | for (MVT VT : {MVT::v2i16, MVT::v4i8, MVT::v8i8, MVT::v2i32, MVT::v4i16, |
| 1505 | MVT::v2i32}) { |
| 1506 | setCondCodeAction(ISD::SETNE, VT, Expand); |
| Krzysztof Parzyszek | 9915291 | 2018-03-16 15:03:37 +0000 | [diff] [blame] | 1507 | setCondCodeAction(ISD::SETLE, VT, Expand); |
| Krzysztof Parzyszek | ac83aab | 2019-08-16 16:16:27 +0000 | [diff] [blame] | 1508 | setCondCodeAction(ISD::SETGE, VT, Expand); |
| 1509 | setCondCodeAction(ISD::SETLT, VT, Expand); |
| Krzysztof Parzyszek | 9915291 | 2018-03-16 15:03:37 +0000 | [diff] [blame] | 1510 | setCondCodeAction(ISD::SETULE, VT, Expand); |
| Krzysztof Parzyszek | ac83aab | 2019-08-16 16:16:27 +0000 | [diff] [blame] | 1511 | setCondCodeAction(ISD::SETUGE, VT, Expand); |
| 1512 | setCondCodeAction(ISD::SETULT, VT, Expand); |
| Krzysztof Parzyszek | 9915291 | 2018-03-16 15:03:37 +0000 | [diff] [blame] | 1513 | } |
| 1514 | |
| Krzysztof Parzyszek | 3780a0e | 2018-01-23 17:53:59 +0000 | [diff] [blame] | 1515 | // Custom-lower bitcasts from i8 to v8i1. |
| 1516 | setOperationAction(ISD::BITCAST, MVT::i8, Custom); |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1517 | setOperationAction(ISD::SETCC, MVT::v2i16, Custom); |
| Krzysztof Parzyszek | 8e98770 | 2019-08-15 19:20:09 +0000 | [diff] [blame] | 1518 | setOperationAction(ISD::VSELECT, MVT::v4i8, Custom); |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1519 | setOperationAction(ISD::VSELECT, MVT::v2i16, Custom); |
| Krzysztof Parzyszek | b8f2a1e | 2018-01-15 18:33:33 +0000 | [diff] [blame] | 1520 | setOperationAction(ISD::VECTOR_SHUFFLE, MVT::v4i8, Custom); |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1521 | setOperationAction(ISD::VECTOR_SHUFFLE, MVT::v4i16, Custom); |
| 1522 | setOperationAction(ISD::VECTOR_SHUFFLE, MVT::v8i8, Custom); |
| Krzysztof Parzyszek | d19d050 | 2016-09-13 21:16:07 +0000 | [diff] [blame] | 1523 | |
| Krzysztof Parzyszek | 6bfc657 | 2018-10-19 17:31:11 +0000 | [diff] [blame] | 1524 | // V5+. |
| 1525 | setOperationAction(ISD::FMA, MVT::f64, Expand); |
| 1526 | setOperationAction(ISD::FADD, MVT::f64, Expand); |
| 1527 | setOperationAction(ISD::FSUB, MVT::f64, Expand); |
| 1528 | setOperationAction(ISD::FMUL, MVT::f64, Expand); |
| Krzysztof Parzyszek | bd8ef4b | 2016-08-19 13:34:31 +0000 | [diff] [blame] | 1529 | |
| Krzysztof Parzyszek | 6bfc657 | 2018-10-19 17:31:11 +0000 | [diff] [blame] | 1530 | setOperationAction(ISD::FMINNUM, MVT::f32, Legal); |
| 1531 | setOperationAction(ISD::FMAXNUM, MVT::f32, Legal); |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1532 | |
| Krzysztof Parzyszek | 6bfc657 | 2018-10-19 17:31:11 +0000 | [diff] [blame] | 1533 | setOperationAction(ISD::FP_TO_UINT, MVT::i1, Promote); |
| 1534 | setOperationAction(ISD::FP_TO_UINT, MVT::i8, Promote); |
| 1535 | setOperationAction(ISD::FP_TO_UINT, MVT::i16, Promote); |
| 1536 | setOperationAction(ISD::FP_TO_SINT, MVT::i1, Promote); |
| 1537 | setOperationAction(ISD::FP_TO_SINT, MVT::i8, Promote); |
| 1538 | setOperationAction(ISD::FP_TO_SINT, MVT::i16, Promote); |
| 1539 | setOperationAction(ISD::UINT_TO_FP, MVT::i1, Promote); |
| 1540 | setOperationAction(ISD::UINT_TO_FP, MVT::i8, Promote); |
| 1541 | setOperationAction(ISD::UINT_TO_FP, MVT::i16, Promote); |
| 1542 | setOperationAction(ISD::SINT_TO_FP, MVT::i1, Promote); |
| 1543 | setOperationAction(ISD::SINT_TO_FP, MVT::i8, Promote); |
| 1544 | setOperationAction(ISD::SINT_TO_FP, MVT::i16, Promote); |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1545 | |
| 1546 | // Handling of indexed loads/stores: default is "expand". |
| 1547 | // |
| Brendon Cahoon | e5ed563 | 2018-05-18 18:14:44 +0000 | [diff] [blame] | 1548 | for (MVT VT : {MVT::i8, MVT::i16, MVT::i32, MVT::i64, MVT::f32, MVT::f64, |
| 1549 | MVT::v2i16, MVT::v2i32, MVT::v4i8, MVT::v4i16, MVT::v8i8}) { |
| Krzysztof Parzyszek | 2a48059 | 2016-07-26 20:30:30 +0000 | [diff] [blame] | 1550 | setIndexedLoadAction(ISD::POST_INC, VT, Legal); |
| 1551 | setIndexedStoreAction(ISD::POST_INC, VT, Legal); |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1552 | } |
| 1553 | |
| Krzysztof Parzyszek | 545a68c | 2018-12-05 21:01:07 +0000 | [diff] [blame] | 1554 | // Subtarget-specific operation actions. |
| 1555 | // |
| 1556 | if (Subtarget.hasV60Ops()) { |
| Krzysztof Parzyszek | 30c42e2 | 2018-12-20 16:39:20 +0000 | [diff] [blame] | 1557 | setOperationAction(ISD::ROTL, MVT::i32, Legal); |
| 1558 | setOperationAction(ISD::ROTL, MVT::i64, Legal); |
| 1559 | setOperationAction(ISD::ROTR, MVT::i32, Legal); |
| 1560 | setOperationAction(ISD::ROTR, MVT::i64, Legal); |
| Krzysztof Parzyszek | 545a68c | 2018-12-05 21:01:07 +0000 | [diff] [blame] | 1561 | } |
| 1562 | if (Subtarget.hasV66Ops()) { |
| 1563 | setOperationAction(ISD::FADD, MVT::f64, Legal); |
| 1564 | setOperationAction(ISD::FSUB, MVT::f64, Legal); |
| 1565 | } |
| 1566 | |
| Krzysztof Parzyszek | ac83aab | 2019-08-16 16:16:27 +0000 | [diff] [blame] | 1567 | setTargetDAGCombine(ISD::VSELECT); |
| 1568 | |
| Krzysztof Parzyszek | 8abaf89 | 2018-02-06 20:22:20 +0000 | [diff] [blame] | 1569 | if (Subtarget.useHVXOps()) |
| 1570 | initializeHVXLowering(); |
| Krzysztof Parzyszek | e4ce92c | 2017-12-20 20:49:43 +0000 | [diff] [blame] | 1571 | |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1572 | computeRegisterProperties(&HRI); |
| 1573 | |
| 1574 | // |
| 1575 | // Library calls for unsupported operations |
| 1576 | // |
| 1577 | bool FastMath = EnableFastMath; |
| 1578 | |
| Benjamin Kramer | a37c809 | 2015-04-25 14:46:46 +0000 | [diff] [blame] | 1579 | setLibcallName(RTLIB::SDIV_I32, "__hexagon_divsi3"); |
| 1580 | setLibcallName(RTLIB::SDIV_I64, "__hexagon_divdi3"); |
| 1581 | setLibcallName(RTLIB::UDIV_I32, "__hexagon_udivsi3"); |
| 1582 | setLibcallName(RTLIB::UDIV_I64, "__hexagon_udivdi3"); |
| 1583 | setLibcallName(RTLIB::SREM_I32, "__hexagon_modsi3"); |
| 1584 | setLibcallName(RTLIB::SREM_I64, "__hexagon_moddi3"); |
| 1585 | setLibcallName(RTLIB::UREM_I32, "__hexagon_umodsi3"); |
| 1586 | setLibcallName(RTLIB::UREM_I64, "__hexagon_umoddi3"); |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1587 | |
| Benjamin Kramer | a37c809 | 2015-04-25 14:46:46 +0000 | [diff] [blame] | 1588 | setLibcallName(RTLIB::SINTTOFP_I128_F64, "__hexagon_floattidf"); |
| 1589 | setLibcallName(RTLIB::SINTTOFP_I128_F32, "__hexagon_floattisf"); |
| 1590 | setLibcallName(RTLIB::FPTOUINT_F32_I128, "__hexagon_fixunssfti"); |
| 1591 | setLibcallName(RTLIB::FPTOUINT_F64_I128, "__hexagon_fixunsdfti"); |
| 1592 | setLibcallName(RTLIB::FPTOSINT_F32_I128, "__hexagon_fixsfti"); |
| 1593 | setLibcallName(RTLIB::FPTOSINT_F64_I128, "__hexagon_fixdfti"); |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1594 | |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1595 | // This is the only fast library function for sqrtd. |
| 1596 | if (FastMath) |
| Benjamin Kramer | a37c809 | 2015-04-25 14:46:46 +0000 | [diff] [blame] | 1597 | setLibcallName(RTLIB::SQRT_F64, "__hexagon_fast2_sqrtdf2"); |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1598 | |
| Benjamin Kramer | a37c809 | 2015-04-25 14:46:46 +0000 | [diff] [blame] | 1599 | // Prefix is: nothing for "slow-math", |
| Krzysztof Parzyszek | 6bfc657 | 2018-10-19 17:31:11 +0000 | [diff] [blame] | 1600 | // "fast2_" for V5+ fast-math double-precision |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1601 | // (actually, keep fast-math and fast-math2 separate for now) |
| Benjamin Kramer | a37c809 | 2015-04-25 14:46:46 +0000 | [diff] [blame] | 1602 | if (FastMath) { |
| 1603 | setLibcallName(RTLIB::ADD_F64, "__hexagon_fast_adddf3"); |
| 1604 | setLibcallName(RTLIB::SUB_F64, "__hexagon_fast_subdf3"); |
| 1605 | setLibcallName(RTLIB::MUL_F64, "__hexagon_fast_muldf3"); |
| 1606 | setLibcallName(RTLIB::DIV_F64, "__hexagon_fast_divdf3"); |
| Benjamin Kramer | a37c809 | 2015-04-25 14:46:46 +0000 | [diff] [blame] | 1607 | setLibcallName(RTLIB::DIV_F32, "__hexagon_fast_divsf3"); |
| 1608 | } else { |
| 1609 | setLibcallName(RTLIB::ADD_F64, "__hexagon_adddf3"); |
| 1610 | setLibcallName(RTLIB::SUB_F64, "__hexagon_subdf3"); |
| 1611 | setLibcallName(RTLIB::MUL_F64, "__hexagon_muldf3"); |
| 1612 | setLibcallName(RTLIB::DIV_F64, "__hexagon_divdf3"); |
| 1613 | setLibcallName(RTLIB::DIV_F32, "__hexagon_divsf3"); |
| 1614 | } |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1615 | |
| Krzysztof Parzyszek | 6bfc657 | 2018-10-19 17:31:11 +0000 | [diff] [blame] | 1616 | if (FastMath) |
| 1617 | setLibcallName(RTLIB::SQRT_F32, "__hexagon_fast2_sqrtf"); |
| 1618 | else |
| 1619 | setLibcallName(RTLIB::SQRT_F32, "__hexagon_sqrtf"); |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1620 | |
| 1621 | // These cause problems when the shift amount is non-constant. |
| 1622 | setLibcallName(RTLIB::SHL_I128, nullptr); |
| 1623 | setLibcallName(RTLIB::SRL_I128, nullptr); |
| 1624 | setLibcallName(RTLIB::SRA_I128, nullptr); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1625 | } |
| 1626 | |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1627 | const char* HexagonTargetLowering::getTargetNodeName(unsigned Opcode) const { |
| Matthias Braun | d04893f | 2015-05-07 21:33:59 +0000 | [diff] [blame] | 1628 | switch ((HexagonISD::NodeType)Opcode) { |
| Krzysztof Parzyszek | 0b6187c | 2018-06-01 14:00:32 +0000 | [diff] [blame] | 1629 | case HexagonISD::ADDC: return "HexagonISD::ADDC"; |
| 1630 | case HexagonISD::SUBC: return "HexagonISD::SUBC"; |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1631 | case HexagonISD::ALLOCA: return "HexagonISD::ALLOCA"; |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1632 | case HexagonISD::AT_GOT: return "HexagonISD::AT_GOT"; |
| 1633 | case HexagonISD::AT_PCREL: return "HexagonISD::AT_PCREL"; |
| 1634 | case HexagonISD::BARRIER: return "HexagonISD::BARRIER"; |
| Krzysztof Parzyszek | be976d4 | 2016-08-12 11:12:02 +0000 | [diff] [blame] | 1635 | case HexagonISD::CALL: return "HexagonISD::CALL"; |
| 1636 | case HexagonISD::CALLnr: return "HexagonISD::CALLnr"; |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1637 | case HexagonISD::CALLR: return "HexagonISD::CALLR"; |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1638 | case HexagonISD::COMBINE: return "HexagonISD::COMBINE"; |
| 1639 | case HexagonISD::CONST32_GP: return "HexagonISD::CONST32_GP"; |
| 1640 | case HexagonISD::CONST32: return "HexagonISD::CONST32"; |
| 1641 | case HexagonISD::CP: return "HexagonISD::CP"; |
| 1642 | case HexagonISD::DCFETCH: return "HexagonISD::DCFETCH"; |
| 1643 | case HexagonISD::EH_RETURN: return "HexagonISD::EH_RETURN"; |
| Krzysztof Parzyszek | 3780a0e | 2018-01-23 17:53:59 +0000 | [diff] [blame] | 1644 | case HexagonISD::TSTBIT: return "HexagonISD::TSTBIT"; |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1645 | case HexagonISD::EXTRACTU: return "HexagonISD::EXTRACTU"; |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1646 | case HexagonISD::INSERT: return "HexagonISD::INSERT"; |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1647 | case HexagonISD::JT: return "HexagonISD::JT"; |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1648 | case HexagonISD::RET_FLAG: return "HexagonISD::RET_FLAG"; |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1649 | case HexagonISD::TC_RETURN: return "HexagonISD::TC_RETURN"; |
| Krzysztof Parzyszek | f85dd9f | 2017-07-10 20:16:44 +0000 | [diff] [blame] | 1650 | case HexagonISD::VASL: return "HexagonISD::VASL"; |
| 1651 | case HexagonISD::VASR: return "HexagonISD::VASR"; |
| 1652 | case HexagonISD::VLSR: return "HexagonISD::VLSR"; |
| 1653 | case HexagonISD::VSPLAT: return "HexagonISD::VSPLAT"; |
| Krzysztof Parzyszek | 7d37dd8 | 2017-12-06 16:40:37 +0000 | [diff] [blame] | 1654 | case HexagonISD::VEXTRACTW: return "HexagonISD::VEXTRACTW"; |
| 1655 | case HexagonISD::VINSERTW0: return "HexagonISD::VINSERTW0"; |
| 1656 | case HexagonISD::VROR: return "HexagonISD::VROR"; |
| Krzysztof Parzyszek | ab57c2b | 2017-02-22 22:28:47 +0000 | [diff] [blame] | 1657 | case HexagonISD::READCYCLE: return "HexagonISD::READCYCLE"; |
| Krzysztof Parzyszek | ac83aab | 2019-08-16 16:16:27 +0000 | [diff] [blame] | 1658 | case HexagonISD::PTRUE: return "HexagonISD::PTRUE"; |
| 1659 | case HexagonISD::PFALSE: return "HexagonISD::PFALSE"; |
| Krzysztof Parzyszek | e4ce92c | 2017-12-20 20:49:43 +0000 | [diff] [blame] | 1660 | case HexagonISD::VZERO: return "HexagonISD::VZERO"; |
| Krzysztof Parzyszek | 41a24b7 | 2018-04-20 19:38:37 +0000 | [diff] [blame] | 1661 | case HexagonISD::VSPLATW: return "HexagonISD::VSPLATW"; |
| Krzysztof Parzyszek | 3780a0e | 2018-01-23 17:53:59 +0000 | [diff] [blame] | 1662 | case HexagonISD::D2P: return "HexagonISD::D2P"; |
| 1663 | case HexagonISD::P2D: return "HexagonISD::P2D"; |
| 1664 | case HexagonISD::V2Q: return "HexagonISD::V2Q"; |
| 1665 | case HexagonISD::Q2V: return "HexagonISD::Q2V"; |
| Krzysztof Parzyszek | 88f1100 | 2018-02-06 14:24:57 +0000 | [diff] [blame] | 1666 | case HexagonISD::QCAT: return "HexagonISD::QCAT"; |
| Krzysztof Parzyszek | 69f1d7e | 2018-02-06 14:16:52 +0000 | [diff] [blame] | 1667 | case HexagonISD::QTRUE: return "HexagonISD::QTRUE"; |
| 1668 | case HexagonISD::QFALSE: return "HexagonISD::QFALSE"; |
| Krzysztof Parzyszek | 3780a0e | 2018-01-23 17:53:59 +0000 | [diff] [blame] | 1669 | case HexagonISD::TYPECAST: return "HexagonISD::TYPECAST"; |
| Krzysztof Parzyszek | 2c3edf0 | 2018-03-07 17:27:18 +0000 | [diff] [blame] | 1670 | case HexagonISD::VALIGN: return "HexagonISD::VALIGN"; |
| Krzysztof Parzyszek | ad83ce4 | 2018-02-14 20:46:06 +0000 | [diff] [blame] | 1671 | case HexagonISD::VALIGNADDR: return "HexagonISD::VALIGNADDR"; |
| Matthias Braun | d04893f | 2015-05-07 21:33:59 +0000 | [diff] [blame] | 1672 | case HexagonISD::OP_END: break; |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1673 | } |
| Matthias Braun | d04893f | 2015-05-07 21:33:59 +0000 | [diff] [blame] | 1674 | return nullptr; |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1675 | } |
| 1676 | |
| Krzysztof Parzyszek | 1df7059 | 2018-08-08 17:00:09 +0000 | [diff] [blame] | 1677 | void |
| 1678 | HexagonTargetLowering::validateConstPtrAlignment(SDValue Ptr, const SDLoc &dl, |
| 1679 | unsigned NeedAlign) const { |
| 1680 | auto *CA = dyn_cast<ConstantSDNode>(Ptr); |
| 1681 | if (!CA) |
| 1682 | return; |
| 1683 | unsigned Addr = CA->getZExtValue(); |
| 1684 | unsigned HaveAlign = Addr != 0 ? 1u << countTrailingZeros(Addr) : NeedAlign; |
| 1685 | if (HaveAlign < NeedAlign) { |
| 1686 | std::string ErrMsg; |
| 1687 | raw_string_ostream O(ErrMsg); |
| 1688 | O << "Misaligned constant address: " << format_hex(Addr, 10) |
| 1689 | << " has alignment " << HaveAlign |
| 1690 | << ", but the memory access requires " << NeedAlign; |
| 1691 | if (DebugLoc DL = dl.getDebugLoc()) |
| 1692 | DL.print(O << ", at "); |
| 1693 | report_fatal_error(O.str()); |
| 1694 | } |
| 1695 | } |
| 1696 | |
| Krzysztof Parzyszek | dc7a557 | 2018-03-29 13:52:46 +0000 | [diff] [blame] | 1697 | // Bit-reverse Load Intrinsic: Check if the instruction is a bit reverse load |
| 1698 | // intrinsic. |
| 1699 | static bool isBrevLdIntrinsic(const Value *Inst) { |
| 1700 | unsigned ID = cast<IntrinsicInst>(Inst)->getIntrinsicID(); |
| 1701 | return (ID == Intrinsic::hexagon_L2_loadrd_pbr || |
| 1702 | ID == Intrinsic::hexagon_L2_loadri_pbr || |
| 1703 | ID == Intrinsic::hexagon_L2_loadrh_pbr || |
| 1704 | ID == Intrinsic::hexagon_L2_loadruh_pbr || |
| 1705 | ID == Intrinsic::hexagon_L2_loadrb_pbr || |
| 1706 | ID == Intrinsic::hexagon_L2_loadrub_pbr); |
| 1707 | } |
| 1708 | |
| 1709 | // Bit-reverse Load Intrinsic :Crawl up and figure out the object from previous |
| 1710 | // instruction. So far we only handle bitcast, extract value and bit reverse |
| 1711 | // load intrinsic instructions. Should we handle CGEP ? |
| 1712 | static Value *getBrevLdObject(Value *V) { |
| 1713 | if (Operator::getOpcode(V) == Instruction::ExtractValue || |
| 1714 | Operator::getOpcode(V) == Instruction::BitCast) |
| 1715 | V = cast<Operator>(V)->getOperand(0); |
| 1716 | else if (isa<IntrinsicInst>(V) && isBrevLdIntrinsic(V)) |
| 1717 | V = cast<Instruction>(V)->getOperand(0); |
| 1718 | return V; |
| 1719 | } |
| 1720 | |
| 1721 | // Bit-reverse Load Intrinsic: For a PHI Node return either an incoming edge or |
| 1722 | // a back edge. If the back edge comes from the intrinsic itself, the incoming |
| 1723 | // edge is returned. |
| 1724 | static Value *returnEdge(const PHINode *PN, Value *IntrBaseVal) { |
| 1725 | const BasicBlock *Parent = PN->getParent(); |
| 1726 | int Idx = -1; |
| 1727 | for (unsigned i = 0, e = PN->getNumIncomingValues(); i < e; ++i) { |
| 1728 | BasicBlock *Blk = PN->getIncomingBlock(i); |
| 1729 | // Determine if the back edge is originated from intrinsic. |
| 1730 | if (Blk == Parent) { |
| 1731 | Value *BackEdgeVal = PN->getIncomingValue(i); |
| 1732 | Value *BaseVal; |
| 1733 | // Loop over till we return the same Value or we hit the IntrBaseVal. |
| 1734 | do { |
| 1735 | BaseVal = BackEdgeVal; |
| 1736 | BackEdgeVal = getBrevLdObject(BackEdgeVal); |
| 1737 | } while ((BaseVal != BackEdgeVal) && (IntrBaseVal != BackEdgeVal)); |
| 1738 | // If the getBrevLdObject returns IntrBaseVal, we should return the |
| 1739 | // incoming edge. |
| 1740 | if (IntrBaseVal == BackEdgeVal) |
| 1741 | continue; |
| 1742 | Idx = i; |
| 1743 | break; |
| 1744 | } else // Set the node to incoming edge. |
| 1745 | Idx = i; |
| 1746 | } |
| 1747 | assert(Idx >= 0 && "Unexpected index to incoming argument in PHI"); |
| 1748 | return PN->getIncomingValue(Idx); |
| 1749 | } |
| 1750 | |
| 1751 | // Bit-reverse Load Intrinsic: Figure out the underlying object the base |
| 1752 | // pointer points to, for the bit-reverse load intrinsic. Setting this to |
| 1753 | // memoperand might help alias analysis to figure out the dependencies. |
| 1754 | static Value *getUnderLyingObjectForBrevLdIntr(Value *V) { |
| 1755 | Value *IntrBaseVal = V; |
| 1756 | Value *BaseVal; |
| 1757 | // Loop over till we return the same Value, implies we either figure out |
| 1758 | // the object or we hit a PHI |
| 1759 | do { |
| 1760 | BaseVal = V; |
| 1761 | V = getBrevLdObject(V); |
| 1762 | } while (BaseVal != V); |
| 1763 | |
| 1764 | // Identify the object from PHINode. |
| 1765 | if (const PHINode *PN = dyn_cast<PHINode>(V)) |
| 1766 | return returnEdge(PN, IntrBaseVal); |
| 1767 | // For non PHI nodes, the object is the last value returned by getBrevLdObject |
| 1768 | else |
| 1769 | return V; |
| 1770 | } |
| 1771 | |
| Krzysztof Parzyszek | a8ab1b7 | 2017-12-11 18:57:54 +0000 | [diff] [blame] | 1772 | /// Given an intrinsic, checks if on the target the intrinsic will need to map |
| 1773 | /// to a MemIntrinsicNode (touches memory). If this is the case, it returns |
| 1774 | /// true and store the intrinsic information into the IntrinsicInfo that was |
| 1775 | /// passed to the function. |
| 1776 | bool HexagonTargetLowering::getTgtMemIntrinsic(IntrinsicInfo &Info, |
| 1777 | const CallInst &I, |
| Matt Arsenault | 7d7adf4 | 2017-12-14 22:34:10 +0000 | [diff] [blame] | 1778 | MachineFunction &MF, |
| Krzysztof Parzyszek | a8ab1b7 | 2017-12-11 18:57:54 +0000 | [diff] [blame] | 1779 | unsigned Intrinsic) const { |
| 1780 | switch (Intrinsic) { |
| Krzysztof Parzyszek | dc7a557 | 2018-03-29 13:52:46 +0000 | [diff] [blame] | 1781 | case Intrinsic::hexagon_L2_loadrd_pbr: |
| 1782 | case Intrinsic::hexagon_L2_loadri_pbr: |
| 1783 | case Intrinsic::hexagon_L2_loadrh_pbr: |
| 1784 | case Intrinsic::hexagon_L2_loadruh_pbr: |
| 1785 | case Intrinsic::hexagon_L2_loadrb_pbr: |
| 1786 | case Intrinsic::hexagon_L2_loadrub_pbr: { |
| 1787 | Info.opc = ISD::INTRINSIC_W_CHAIN; |
| 1788 | auto &DL = I.getCalledFunction()->getParent()->getDataLayout(); |
| 1789 | auto &Cont = I.getCalledFunction()->getParent()->getContext(); |
| 1790 | // The intrinsic function call is of the form { ElTy, i8* } |
| 1791 | // @llvm.hexagon.L2.loadXX.pbr(i8*, i32). The pointer and memory access type |
| 1792 | // should be derived from ElTy. |
| James Y Knight | 62df5ee | 2019-01-10 16:07:20 +0000 | [diff] [blame] | 1793 | Type *ElTy = I.getCalledFunction()->getReturnType()->getStructElementType(0); |
| 1794 | Info.memVT = MVT::getVT(ElTy); |
| Krzysztof Parzyszek | dc7a557 | 2018-03-29 13:52:46 +0000 | [diff] [blame] | 1795 | llvm::Value *BasePtrVal = I.getOperand(0); |
| 1796 | Info.ptrVal = getUnderLyingObjectForBrevLdIntr(BasePtrVal); |
| 1797 | // The offset value comes through Modifier register. For now, assume the |
| 1798 | // offset is 0. |
| 1799 | Info.offset = 0; |
| Guillaume Chatelet | c97a3d1 | 2019-08-05 11:02:05 +0000 | [diff] [blame] | 1800 | Info.align = |
| 1801 | MaybeAlign(DL.getABITypeAlignment(Info.memVT.getTypeForEVT(Cont))); |
| Krzysztof Parzyszek | dc7a557 | 2018-03-29 13:52:46 +0000 | [diff] [blame] | 1802 | Info.flags = MachineMemOperand::MOLoad; |
| 1803 | return true; |
| 1804 | } |
| Krzysztof Parzyszek | a8ab1b7 | 2017-12-11 18:57:54 +0000 | [diff] [blame] | 1805 | case Intrinsic::hexagon_V6_vgathermw: |
| 1806 | case Intrinsic::hexagon_V6_vgathermw_128B: |
| 1807 | case Intrinsic::hexagon_V6_vgathermh: |
| 1808 | case Intrinsic::hexagon_V6_vgathermh_128B: |
| 1809 | case Intrinsic::hexagon_V6_vgathermhw: |
| 1810 | case Intrinsic::hexagon_V6_vgathermhw_128B: |
| 1811 | case Intrinsic::hexagon_V6_vgathermwq: |
| 1812 | case Intrinsic::hexagon_V6_vgathermwq_128B: |
| 1813 | case Intrinsic::hexagon_V6_vgathermhq: |
| 1814 | case Intrinsic::hexagon_V6_vgathermhq_128B: |
| 1815 | case Intrinsic::hexagon_V6_vgathermhwq: |
| 1816 | case Intrinsic::hexagon_V6_vgathermhwq_128B: { |
| 1817 | const Module &M = *I.getParent()->getParent()->getParent(); |
| 1818 | Info.opc = ISD::INTRINSIC_W_CHAIN; |
| 1819 | Type *VecTy = I.getArgOperand(1)->getType(); |
| 1820 | Info.memVT = MVT::getVT(VecTy); |
| 1821 | Info.ptrVal = I.getArgOperand(0); |
| 1822 | Info.offset = 0; |
| Guillaume Chatelet | c97a3d1 | 2019-08-05 11:02:05 +0000 | [diff] [blame] | 1823 | Info.align = |
| 1824 | MaybeAlign(M.getDataLayout().getTypeAllocSizeInBits(VecTy) / 8); |
| Matt Arsenault | 1117133 | 2017-12-14 21:39:51 +0000 | [diff] [blame] | 1825 | Info.flags = MachineMemOperand::MOLoad | |
| 1826 | MachineMemOperand::MOStore | |
| 1827 | MachineMemOperand::MOVolatile; |
| Krzysztof Parzyszek | a8ab1b7 | 2017-12-11 18:57:54 +0000 | [diff] [blame] | 1828 | return true; |
| 1829 | } |
| 1830 | default: |
| 1831 | break; |
| 1832 | } |
| 1833 | return false; |
| 1834 | } |
| 1835 | |
| Roman Lebedev | 017e272 | 2019-07-24 22:57:22 +0000 | [diff] [blame] | 1836 | bool HexagonTargetLowering::hasBitTest(SDValue X, SDValue Y) const { |
| 1837 | return X.getValueType().isScalarInteger(); // 'tstbit' |
| 1838 | } |
| 1839 | |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1840 | bool HexagonTargetLowering::isTruncateFree(Type *Ty1, Type *Ty2) const { |
| Krzysztof Parzyszek | cfbe6ba | 2018-02-13 15:35:07 +0000 | [diff] [blame] | 1841 | return isTruncateFree(EVT::getEVT(Ty1), EVT::getEVT(Ty2)); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1842 | } |
| 1843 | |
| 1844 | bool HexagonTargetLowering::isTruncateFree(EVT VT1, EVT VT2) const { |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 1845 | if (!VT1.isSimple() || !VT2.isSimple()) |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1846 | return false; |
| Krzysztof Parzyszek | cfbe6ba | 2018-02-13 15:35:07 +0000 | [diff] [blame] | 1847 | return VT1.getSimpleVT() == MVT::i64 && VT2.getSimpleVT() == MVT::i32; |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 1848 | } |
| 1849 | |
| Krzysztof Parzyszek | bd8ef4b | 2016-08-19 13:34:31 +0000 | [diff] [blame] | 1850 | bool HexagonTargetLowering::isFMAFasterThanFMulAndFAdd(EVT VT) const { |
| 1851 | return isOperationLegalOrCustom(ISD::FMA, VT); |
| 1852 | } |
| 1853 | |
| Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 1854 | // Should we expand the build vector with shuffles? |
| Krzysztof Parzyszek | d19d050 | 2016-09-13 21:16:07 +0000 | [diff] [blame] | 1855 | bool HexagonTargetLowering::shouldExpandBuildVectorWithShuffles(EVT VT, |
| 1856 | unsigned DefinedValues) const { |
| Krzysztof Parzyszek | 7d37dd8 | 2017-12-06 16:40:37 +0000 | [diff] [blame] | 1857 | return false; |
| Krzysztof Parzyszek | 0bd55a7 | 2016-07-29 16:44:27 +0000 | [diff] [blame] | 1858 | } |
| 1859 | |
| Zvi Rackover | 1b73682 | 2017-07-26 08:06:58 +0000 | [diff] [blame] | 1860 | bool HexagonTargetLowering::isShuffleMaskLegal(ArrayRef<int> Mask, |
| 1861 | EVT VT) const { |
| Krzysztof Parzyszek | d19d050 | 2016-09-13 21:16:07 +0000 | [diff] [blame] | 1862 | return true; |
| 1863 | } |
| 1864 | |
| Krzysztof Parzyszek | 5439a70 | 2017-12-18 18:21:01 +0000 | [diff] [blame] | 1865 | TargetLoweringBase::LegalizeTypeAction |
| Craig Topper | 0b5f816 | 2018-11-05 23:26:13 +0000 | [diff] [blame] | 1866 | HexagonTargetLowering::getPreferredVectorAction(MVT VT) const { |
| Krzysztof Parzyszek | e4ce92c | 2017-12-20 20:49:43 +0000 | [diff] [blame] | 1867 | if (VT.getVectorNumElements() == 1) |
| 1868 | return TargetLoweringBase::TypeScalarizeVector; |
| 1869 | |
| 1870 | // Always widen vectors of i1. |
| Craig Topper | 0b5f816 | 2018-11-05 23:26:13 +0000 | [diff] [blame] | 1871 | MVT ElemTy = VT.getVectorElementType(); |
| Krzysztof Parzyszek | e4ce92c | 2017-12-20 20:49:43 +0000 | [diff] [blame] | 1872 | if (ElemTy == MVT::i1) |
| 1873 | return TargetLoweringBase::TypeWidenVector; |
| 1874 | |
| Krzysztof Parzyszek | 5439a70 | 2017-12-18 18:21:01 +0000 | [diff] [blame] | 1875 | if (Subtarget.useHVXOps()) { |
| 1876 | // If the size of VT is at least half of the vector length, |
| 1877 | // widen the vector. Note: the threshold was not selected in |
| 1878 | // any scientific way. |
| Krzysztof Parzyszek | e4ce92c | 2017-12-20 20:49:43 +0000 | [diff] [blame] | 1879 | ArrayRef<MVT> Tys = Subtarget.getHVXElementTypes(); |
| 1880 | if (llvm::find(Tys, ElemTy) != Tys.end()) { |
| 1881 | unsigned HwWidth = 8*Subtarget.getVectorLength(); |
| 1882 | unsigned VecWidth = VT.getSizeInBits(); |
| 1883 | if (VecWidth >= HwWidth/2 && VecWidth < HwWidth) |
| 1884 | return TargetLoweringBase::TypeWidenVector; |
| 1885 | } |
| Krzysztof Parzyszek | 5439a70 | 2017-12-18 18:21:01 +0000 | [diff] [blame] | 1886 | } |
| Krzysztof Parzyszek | e4ce92c | 2017-12-20 20:49:43 +0000 | [diff] [blame] | 1887 | return TargetLoweringBase::TypeSplitVector; |
| Krzysztof Parzyszek | 5439a70 | 2017-12-18 18:21:01 +0000 | [diff] [blame] | 1888 | } |
| 1889 | |
| Krzysztof Parzyszek | ad83ce4 | 2018-02-14 20:46:06 +0000 | [diff] [blame] | 1890 | std::pair<SDValue, int> |
| 1891 | HexagonTargetLowering::getBaseAndOffset(SDValue Addr) const { |
| 1892 | if (Addr.getOpcode() == ISD::ADD) { |
| 1893 | SDValue Op1 = Addr.getOperand(1); |
| 1894 | if (auto *CN = dyn_cast<const ConstantSDNode>(Op1.getNode())) |
| 1895 | return { Addr.getOperand(0), CN->getSExtValue() }; |
| 1896 | } |
| 1897 | return { Addr, 0 }; |
| 1898 | } |
| 1899 | |
| Krzysztof Parzyszek | 0bd55a7 | 2016-07-29 16:44:27 +0000 | [diff] [blame] | 1900 | // Lower a vector shuffle (V1, V2, V3). V1 and V2 are the two vectors |
| 1901 | // to select data from, V3 is the permutation. |
| 1902 | SDValue |
| 1903 | HexagonTargetLowering::LowerVECTOR_SHUFFLE(SDValue Op, SelectionDAG &DAG) |
| 1904 | const { |
| Krzysztof Parzyszek | b8f2a1e | 2018-01-15 18:33:33 +0000 | [diff] [blame] | 1905 | const auto *SVN = cast<ShuffleVectorSDNode>(Op); |
| 1906 | ArrayRef<int> AM = SVN->getMask(); |
| 1907 | assert(AM.size() <= 8 && "Unexpected shuffle mask"); |
| 1908 | unsigned VecLen = AM.size(); |
| Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 1909 | |
| Krzysztof Parzyszek | b8f2a1e | 2018-01-15 18:33:33 +0000 | [diff] [blame] | 1910 | MVT VecTy = ty(Op); |
| Krzysztof Parzyszek | 8abaf89 | 2018-02-06 20:22:20 +0000 | [diff] [blame] | 1911 | assert(!Subtarget.isHVXVectorType(VecTy, true) && |
| 1912 | "HVX shuffles should be legal"); |
| Krzysztof Parzyszek | b8f2a1e | 2018-01-15 18:33:33 +0000 | [diff] [blame] | 1913 | assert(VecTy.getSizeInBits() <= 64 && "Unexpected vector length"); |
| Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 1914 | |
| Krzysztof Parzyszek | b8f2a1e | 2018-01-15 18:33:33 +0000 | [diff] [blame] | 1915 | SDValue Op0 = Op.getOperand(0); |
| 1916 | SDValue Op1 = Op.getOperand(1); |
| Krzysztof Parzyszek | 7cfe7cb | 2018-02-09 15:30:02 +0000 | [diff] [blame] | 1917 | const SDLoc &dl(Op); |
| 1918 | |
| Krzysztof Parzyszek | b8f2a1e | 2018-01-15 18:33:33 +0000 | [diff] [blame] | 1919 | // If the inputs are not the same as the output, bail. This is not an |
| 1920 | // error situation, but complicates the handling and the default expansion |
| 1921 | // (into BUILD_VECTOR) should be adequate. |
| 1922 | if (ty(Op0) != VecTy || ty(Op1) != VecTy) |
| 1923 | return SDValue(); |
| Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 1924 | |
| Krzysztof Parzyszek | b8f2a1e | 2018-01-15 18:33:33 +0000 | [diff] [blame] | 1925 | // Normalize the mask so that the first non-negative index comes from |
| 1926 | // the first operand. |
| 1927 | SmallVector<int,8> Mask(AM.begin(), AM.end()); |
| 1928 | unsigned F = llvm::find_if(AM, [](int M) { return M >= 0; }) - AM.data(); |
| 1929 | if (F == AM.size()) |
| 1930 | return DAG.getUNDEF(VecTy); |
| 1931 | if (AM[F] >= int(VecLen)) { |
| 1932 | ShuffleVectorSDNode::commuteMask(Mask); |
| 1933 | std::swap(Op0, Op1); |
| Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 1934 | } |
| 1935 | |
| Krzysztof Parzyszek | b8f2a1e | 2018-01-15 18:33:33 +0000 | [diff] [blame] | 1936 | // Express the shuffle mask in terms of bytes. |
| 1937 | SmallVector<int,8> ByteMask; |
| 1938 | unsigned ElemBytes = VecTy.getVectorElementType().getSizeInBits() / 8; |
| 1939 | for (unsigned i = 0, e = Mask.size(); i != e; ++i) { |
| 1940 | int M = Mask[i]; |
| 1941 | if (M < 0) { |
| 1942 | for (unsigned j = 0; j != ElemBytes; ++j) |
| 1943 | ByteMask.push_back(-1); |
| 1944 | } else { |
| 1945 | for (unsigned j = 0; j != ElemBytes; ++j) |
| 1946 | ByteMask.push_back(M*ElemBytes + j); |
| 1947 | } |
| 1948 | } |
| 1949 | assert(ByteMask.size() <= 8); |
| Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 1950 | |
| Krzysztof Parzyszek | b8f2a1e | 2018-01-15 18:33:33 +0000 | [diff] [blame] | 1951 | // All non-undef (non-negative) indexes are well within [0..127], so they |
| 1952 | // fit in a single byte. Build two 64-bit words: |
| 1953 | // - MaskIdx where each byte is the corresponding index (for non-negative |
| 1954 | // indexes), and 0xFF for negative indexes, and |
| 1955 | // - MaskUnd that has 0xFF for each negative index. |
| 1956 | uint64_t MaskIdx = 0; |
| 1957 | uint64_t MaskUnd = 0; |
| 1958 | for (unsigned i = 0, e = ByteMask.size(); i != e; ++i) { |
| 1959 | unsigned S = 8*i; |
| 1960 | uint64_t M = ByteMask[i] & 0xFF; |
| 1961 | if (M == 0xFF) |
| 1962 | MaskUnd |= M << S; |
| 1963 | MaskIdx |= M << S; |
| 1964 | } |
| 1965 | |
| Krzysztof Parzyszek | b8f2a1e | 2018-01-15 18:33:33 +0000 | [diff] [blame] | 1966 | if (ByteMask.size() == 4) { |
| 1967 | // Identity. |
| 1968 | if (MaskIdx == (0x03020100 | MaskUnd)) |
| 1969 | return Op0; |
| 1970 | // Byte swap. |
| 1971 | if (MaskIdx == (0x00010203 | MaskUnd)) { |
| 1972 | SDValue T0 = DAG.getBitcast(MVT::i32, Op0); |
| 1973 | SDValue T1 = DAG.getNode(ISD::BSWAP, dl, MVT::i32, T0); |
| 1974 | return DAG.getBitcast(VecTy, T1); |
| 1975 | } |
| 1976 | |
| 1977 | // Byte packs. |
| 1978 | SDValue Concat10 = DAG.getNode(HexagonISD::COMBINE, dl, |
| 1979 | typeJoin({ty(Op1), ty(Op0)}), {Op1, Op0}); |
| 1980 | if (MaskIdx == (0x06040200 | MaskUnd)) |
| Krzysztof Parzyszek | 15efa98 | 2018-01-31 21:17:03 +0000 | [diff] [blame] | 1981 | return getInstr(Hexagon::S2_vtrunehb, dl, VecTy, {Concat10}, DAG); |
| Krzysztof Parzyszek | b8f2a1e | 2018-01-15 18:33:33 +0000 | [diff] [blame] | 1982 | if (MaskIdx == (0x07050301 | MaskUnd)) |
| Krzysztof Parzyszek | 15efa98 | 2018-01-31 21:17:03 +0000 | [diff] [blame] | 1983 | return getInstr(Hexagon::S2_vtrunohb, dl, VecTy, {Concat10}, DAG); |
| Krzysztof Parzyszek | b8f2a1e | 2018-01-15 18:33:33 +0000 | [diff] [blame] | 1984 | |
| 1985 | SDValue Concat01 = DAG.getNode(HexagonISD::COMBINE, dl, |
| 1986 | typeJoin({ty(Op0), ty(Op1)}), {Op0, Op1}); |
| 1987 | if (MaskIdx == (0x02000604 | MaskUnd)) |
| Krzysztof Parzyszek | 15efa98 | 2018-01-31 21:17:03 +0000 | [diff] [blame] | 1988 | return getInstr(Hexagon::S2_vtrunehb, dl, VecTy, {Concat01}, DAG); |
| Krzysztof Parzyszek | b8f2a1e | 2018-01-15 18:33:33 +0000 | [diff] [blame] | 1989 | if (MaskIdx == (0x03010705 | MaskUnd)) |
| Krzysztof Parzyszek | 15efa98 | 2018-01-31 21:17:03 +0000 | [diff] [blame] | 1990 | return getInstr(Hexagon::S2_vtrunohb, dl, VecTy, {Concat01}, DAG); |
| Krzysztof Parzyszek | b8f2a1e | 2018-01-15 18:33:33 +0000 | [diff] [blame] | 1991 | } |
| 1992 | |
| 1993 | if (ByteMask.size() == 8) { |
| 1994 | // Identity. |
| 1995 | if (MaskIdx == (0x0706050403020100ull | MaskUnd)) |
| 1996 | return Op0; |
| 1997 | // Byte swap. |
| 1998 | if (MaskIdx == (0x0001020304050607ull | MaskUnd)) { |
| 1999 | SDValue T0 = DAG.getBitcast(MVT::i64, Op0); |
| 2000 | SDValue T1 = DAG.getNode(ISD::BSWAP, dl, MVT::i64, T0); |
| 2001 | return DAG.getBitcast(VecTy, T1); |
| 2002 | } |
| 2003 | |
| 2004 | // Halfword picks. |
| 2005 | if (MaskIdx == (0x0d0c050409080100ull | MaskUnd)) |
| Krzysztof Parzyszek | 15efa98 | 2018-01-31 21:17:03 +0000 | [diff] [blame] | 2006 | return getInstr(Hexagon::S2_shuffeh, dl, VecTy, {Op1, Op0}, DAG); |
| Krzysztof Parzyszek | b8f2a1e | 2018-01-15 18:33:33 +0000 | [diff] [blame] | 2007 | if (MaskIdx == (0x0f0e07060b0a0302ull | MaskUnd)) |
| Krzysztof Parzyszek | 15efa98 | 2018-01-31 21:17:03 +0000 | [diff] [blame] | 2008 | return getInstr(Hexagon::S2_shuffoh, dl, VecTy, {Op1, Op0}, DAG); |
| Krzysztof Parzyszek | b8f2a1e | 2018-01-15 18:33:33 +0000 | [diff] [blame] | 2009 | if (MaskIdx == (0x0d0c090805040100ull | MaskUnd)) |
| Krzysztof Parzyszek | 15efa98 | 2018-01-31 21:17:03 +0000 | [diff] [blame] | 2010 | return getInstr(Hexagon::S2_vtrunewh, dl, VecTy, {Op1, Op0}, DAG); |
| Krzysztof Parzyszek | b8f2a1e | 2018-01-15 18:33:33 +0000 | [diff] [blame] | 2011 | if (MaskIdx == (0x0f0e0b0a07060302ull | MaskUnd)) |
| Krzysztof Parzyszek | 15efa98 | 2018-01-31 21:17:03 +0000 | [diff] [blame] | 2012 | return getInstr(Hexagon::S2_vtrunowh, dl, VecTy, {Op1, Op0}, DAG); |
| Krzysztof Parzyszek | b8f2a1e | 2018-01-15 18:33:33 +0000 | [diff] [blame] | 2013 | if (MaskIdx == (0x0706030205040100ull | MaskUnd)) { |
| 2014 | VectorPair P = opSplit(Op0, dl, DAG); |
| Krzysztof Parzyszek | 15efa98 | 2018-01-31 21:17:03 +0000 | [diff] [blame] | 2015 | return getInstr(Hexagon::S2_packhl, dl, VecTy, {P.second, P.first}, DAG); |
| Krzysztof Parzyszek | b8f2a1e | 2018-01-15 18:33:33 +0000 | [diff] [blame] | 2016 | } |
| 2017 | |
| 2018 | // Byte packs. |
| 2019 | if (MaskIdx == (0x0e060c040a020800ull | MaskUnd)) |
| Krzysztof Parzyszek | 15efa98 | 2018-01-31 21:17:03 +0000 | [diff] [blame] | 2020 | return getInstr(Hexagon::S2_shuffeb, dl, VecTy, {Op1, Op0}, DAG); |
| Krzysztof Parzyszek | b8f2a1e | 2018-01-15 18:33:33 +0000 | [diff] [blame] | 2021 | if (MaskIdx == (0x0f070d050b030901ull | MaskUnd)) |
| Krzysztof Parzyszek | 15efa98 | 2018-01-31 21:17:03 +0000 | [diff] [blame] | 2022 | return getInstr(Hexagon::S2_shuffob, dl, VecTy, {Op1, Op0}, DAG); |
| Krzysztof Parzyszek | b8f2a1e | 2018-01-15 18:33:33 +0000 | [diff] [blame] | 2023 | } |
| 2024 | |
| 2025 | return SDValue(); |
| Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2026 | } |
| 2027 | |
| Krzysztof Parzyszek | 8abaf89 | 2018-02-06 20:22:20 +0000 | [diff] [blame] | 2028 | // Create a Hexagon-specific node for shifting a vector by an integer. |
| Krzysztof Parzyszek | 0bd55a7 | 2016-07-29 16:44:27 +0000 | [diff] [blame] | 2029 | SDValue |
| Krzysztof Parzyszek | 8abaf89 | 2018-02-06 20:22:20 +0000 | [diff] [blame] | 2030 | HexagonTargetLowering::getVectorShiftByInt(SDValue Op, SelectionDAG &DAG) |
| 2031 | const { |
| Krzysztof Parzyszek | 1108ee2 | 2018-01-31 20:49:24 +0000 | [diff] [blame] | 2032 | if (auto *BVN = dyn_cast<BuildVectorSDNode>(Op.getOperand(1).getNode())) { |
| 2033 | if (SDValue S = BVN->getSplatValue()) { |
| 2034 | unsigned NewOpc; |
| 2035 | switch (Op.getOpcode()) { |
| 2036 | case ISD::SHL: |
| 2037 | NewOpc = HexagonISD::VASL; |
| 2038 | break; |
| 2039 | case ISD::SRA: |
| 2040 | NewOpc = HexagonISD::VASR; |
| 2041 | break; |
| 2042 | case ISD::SRL: |
| 2043 | NewOpc = HexagonISD::VLSR; |
| 2044 | break; |
| 2045 | default: |
| 2046 | llvm_unreachable("Unexpected shift opcode"); |
| 2047 | } |
| Krzysztof Parzyszek | 8abaf89 | 2018-02-06 20:22:20 +0000 | [diff] [blame] | 2048 | return DAG.getNode(NewOpc, SDLoc(Op), ty(Op), Op.getOperand(0), S); |
| Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2049 | } |
| Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2050 | } |
| 2051 | |
| Krzysztof Parzyszek | 1108ee2 | 2018-01-31 20:49:24 +0000 | [diff] [blame] | 2052 | return SDValue(); |
| Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2053 | } |
| 2054 | |
| Krzysztof Parzyszek | 3780a0e | 2018-01-23 17:53:59 +0000 | [diff] [blame] | 2055 | SDValue |
| Krzysztof Parzyszek | 8abaf89 | 2018-02-06 20:22:20 +0000 | [diff] [blame] | 2056 | HexagonTargetLowering::LowerVECTOR_SHIFT(SDValue Op, SelectionDAG &DAG) const { |
| 2057 | return getVectorShiftByInt(Op, DAG); |
| 2058 | } |
| 2059 | |
| 2060 | SDValue |
| Krzysztof Parzyszek | 3d67124 | 2018-06-12 12:49:36 +0000 | [diff] [blame] | 2061 | HexagonTargetLowering::LowerROTL(SDValue Op, SelectionDAG &DAG) const { |
| 2062 | if (isa<ConstantSDNode>(Op.getOperand(1).getNode())) |
| 2063 | return Op; |
| 2064 | return SDValue(); |
| 2065 | } |
| 2066 | |
| 2067 | SDValue |
| Krzysztof Parzyszek | 3780a0e | 2018-01-23 17:53:59 +0000 | [diff] [blame] | 2068 | HexagonTargetLowering::LowerBITCAST(SDValue Op, SelectionDAG &DAG) const { |
| 2069 | MVT ResTy = ty(Op); |
| 2070 | SDValue InpV = Op.getOperand(0); |
| 2071 | MVT InpTy = ty(InpV); |
| 2072 | assert(ResTy.getSizeInBits() == InpTy.getSizeInBits()); |
| 2073 | const SDLoc &dl(Op); |
| 2074 | |
| 2075 | // Handle conversion from i8 to v8i1. |
| 2076 | if (ResTy == MVT::v8i1) { |
| 2077 | SDValue Sc = DAG.getBitcast(tyScalar(InpTy), InpV); |
| 2078 | SDValue Ext = DAG.getZExtOrTrunc(Sc, dl, MVT::i32); |
| Krzysztof Parzyszek | 15efa98 | 2018-01-31 21:17:03 +0000 | [diff] [blame] | 2079 | return getInstr(Hexagon::C2_tfrrp, dl, ResTy, Ext, DAG); |
| Krzysztof Parzyszek | 3780a0e | 2018-01-23 17:53:59 +0000 | [diff] [blame] | 2080 | } |
| 2081 | |
| 2082 | return SDValue(); |
| 2083 | } |
| 2084 | |
| Krzysztof Parzyszek | e4ce92c | 2017-12-20 20:49:43 +0000 | [diff] [blame] | 2085 | bool |
| 2086 | HexagonTargetLowering::getBuildVectorConstInts(ArrayRef<SDValue> Values, |
| 2087 | MVT VecTy, SelectionDAG &DAG, |
| 2088 | MutableArrayRef<ConstantInt*> Consts) const { |
| 2089 | MVT ElemTy = VecTy.getVectorElementType(); |
| 2090 | unsigned ElemWidth = ElemTy.getSizeInBits(); |
| 2091 | IntegerType *IntTy = IntegerType::get(*DAG.getContext(), ElemWidth); |
| 2092 | bool AllConst = true; |
| 2093 | |
| 2094 | for (unsigned i = 0, e = Values.size(); i != e; ++i) { |
| 2095 | SDValue V = Values[i]; |
| 2096 | if (V.isUndef()) { |
| 2097 | Consts[i] = ConstantInt::get(IntTy, 0); |
| 2098 | continue; |
| 2099 | } |
| Krzysztof Parzyszek | 4ef6cff | 2018-01-11 18:03:23 +0000 | [diff] [blame] | 2100 | // Make sure to always cast to IntTy. |
| Krzysztof Parzyszek | e4ce92c | 2017-12-20 20:49:43 +0000 | [diff] [blame] | 2101 | if (auto *CN = dyn_cast<ConstantSDNode>(V.getNode())) { |
| 2102 | const ConstantInt *CI = CN->getConstantIntValue(); |
| Krzysztof Parzyszek | 4ef6cff | 2018-01-11 18:03:23 +0000 | [diff] [blame] | 2103 | Consts[i] = ConstantInt::get(IntTy, CI->getValue().getSExtValue()); |
| Krzysztof Parzyszek | e4ce92c | 2017-12-20 20:49:43 +0000 | [diff] [blame] | 2104 | } else if (auto *CN = dyn_cast<ConstantFPSDNode>(V.getNode())) { |
| 2105 | const ConstantFP *CF = CN->getConstantFPValue(); |
| 2106 | APInt A = CF->getValueAPF().bitcastToAPInt(); |
| 2107 | Consts[i] = ConstantInt::get(IntTy, A.getZExtValue()); |
| 2108 | } else { |
| 2109 | AllConst = false; |
| 2110 | } |
| 2111 | } |
| 2112 | return AllConst; |
| 2113 | } |
| 2114 | |
| Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2115 | SDValue |
| Krzysztof Parzyszek | 942fa16 | 2017-11-22 20:56:23 +0000 | [diff] [blame] | 2116 | HexagonTargetLowering::buildVector32(ArrayRef<SDValue> Elem, const SDLoc &dl, |
| 2117 | MVT VecTy, SelectionDAG &DAG) const { |
| 2118 | MVT ElemTy = VecTy.getVectorElementType(); |
| 2119 | assert(VecTy.getVectorNumElements() == Elem.size()); |
| Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2120 | |
| Krzysztof Parzyszek | e4ce92c | 2017-12-20 20:49:43 +0000 | [diff] [blame] | 2121 | SmallVector<ConstantInt*,4> Consts(Elem.size()); |
| 2122 | bool AllConst = getBuildVectorConstInts(Elem, VecTy, DAG, Consts); |
| Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2123 | |
| Krzysztof Parzyszek | 942fa16 | 2017-11-22 20:56:23 +0000 | [diff] [blame] | 2124 | unsigned First, Num = Elem.size(); |
| 2125 | for (First = 0; First != Num; ++First) |
| Krzysztof Parzyszek | 7d37dd8 | 2017-12-06 16:40:37 +0000 | [diff] [blame] | 2126 | if (!isUndef(Elem[First])) |
| Krzysztof Parzyszek | 942fa16 | 2017-11-22 20:56:23 +0000 | [diff] [blame] | 2127 | break; |
| 2128 | if (First == Num) |
| 2129 | return DAG.getUNDEF(VecTy); |
| Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2130 | |
| Krzysztof Parzyszek | e4ce92c | 2017-12-20 20:49:43 +0000 | [diff] [blame] | 2131 | if (AllConst && |
| 2132 | llvm::all_of(Consts, [](ConstantInt *CI) { return CI->isZero(); })) |
| 2133 | return getZero(dl, VecTy, DAG); |
| 2134 | |
| Krzysztof Parzyszek | 942fa16 | 2017-11-22 20:56:23 +0000 | [diff] [blame] | 2135 | if (ElemTy == MVT::i16) { |
| 2136 | assert(Elem.size() == 2); |
| 2137 | if (AllConst) { |
| 2138 | uint32_t V = (Consts[0]->getZExtValue() & 0xFFFF) | |
| 2139 | Consts[1]->getZExtValue() << 16; |
| 2140 | return DAG.getBitcast(MVT::v2i16, DAG.getConstant(V, dl, MVT::i32)); |
| Krzysztof Parzyszek | 89b2d7c | 2017-07-13 18:17:58 +0000 | [diff] [blame] | 2141 | } |
| Krzysztof Parzyszek | 15efa98 | 2018-01-31 21:17:03 +0000 | [diff] [blame] | 2142 | SDValue N = getInstr(Hexagon::A2_combine_ll, dl, MVT::i32, |
| 2143 | {Elem[1], Elem[0]}, DAG); |
| Krzysztof Parzyszek | 7d37dd8 | 2017-12-06 16:40:37 +0000 | [diff] [blame] | 2144 | return DAG.getBitcast(MVT::v2i16, N); |
| Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2145 | } |
| 2146 | |
| Krzysztof Parzyszek | e4ce92c | 2017-12-20 20:49:43 +0000 | [diff] [blame] | 2147 | if (ElemTy == MVT::i8) { |
| 2148 | // First try generating a constant. |
| 2149 | if (AllConst) { |
| 2150 | int32_t V = (Consts[0]->getZExtValue() & 0xFF) | |
| 2151 | (Consts[1]->getZExtValue() & 0xFF) << 8 | |
| 2152 | (Consts[1]->getZExtValue() & 0xFF) << 16 | |
| 2153 | Consts[2]->getZExtValue() << 24; |
| 2154 | return DAG.getBitcast(MVT::v4i8, DAG.getConstant(V, dl, MVT::i32)); |
| 2155 | } |
| 2156 | |
| 2157 | // Then try splat. |
| 2158 | bool IsSplat = true; |
| 2159 | for (unsigned i = 0; i != Num; ++i) { |
| 2160 | if (i == First) |
| 2161 | continue; |
| 2162 | if (Elem[i] == Elem[First] || isUndef(Elem[i])) |
| 2163 | continue; |
| 2164 | IsSplat = false; |
| 2165 | break; |
| 2166 | } |
| 2167 | if (IsSplat) { |
| 2168 | // Legalize the operand to VSPLAT. |
| 2169 | SDValue Ext = DAG.getZExtOrTrunc(Elem[First], dl, MVT::i32); |
| 2170 | return DAG.getNode(HexagonISD::VSPLAT, dl, VecTy, Ext); |
| 2171 | } |
| 2172 | |
| 2173 | // Generate |
| 2174 | // (zxtb(Elem[0]) | (zxtb(Elem[1]) << 8)) | |
| 2175 | // (zxtb(Elem[2]) | (zxtb(Elem[3]) << 8)) << 16 |
| 2176 | assert(Elem.size() == 4); |
| 2177 | SDValue Vs[4]; |
| 2178 | for (unsigned i = 0; i != 4; ++i) { |
| 2179 | Vs[i] = DAG.getZExtOrTrunc(Elem[i], dl, MVT::i32); |
| 2180 | Vs[i] = DAG.getZeroExtendInReg(Vs[i], dl, MVT::i8); |
| 2181 | } |
| 2182 | SDValue S8 = DAG.getConstant(8, dl, MVT::i32); |
| 2183 | SDValue T0 = DAG.getNode(ISD::SHL, dl, MVT::i32, {Vs[1], S8}); |
| 2184 | SDValue T1 = DAG.getNode(ISD::SHL, dl, MVT::i32, {Vs[3], S8}); |
| 2185 | SDValue B0 = DAG.getNode(ISD::OR, dl, MVT::i32, {Vs[0], T0}); |
| 2186 | SDValue B1 = DAG.getNode(ISD::OR, dl, MVT::i32, {Vs[2], T1}); |
| 2187 | |
| Krzysztof Parzyszek | 15efa98 | 2018-01-31 21:17:03 +0000 | [diff] [blame] | 2188 | 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] | 2189 | return DAG.getBitcast(MVT::v4i8, R); |
| Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2190 | } |
| 2191 | |
| Krzysztof Parzyszek | e4ce92c | 2017-12-20 20:49:43 +0000 | [diff] [blame] | 2192 | #ifndef NDEBUG |
| 2193 | dbgs() << "VecTy: " << EVT(VecTy).getEVTString() << '\n'; |
| 2194 | #endif |
| 2195 | llvm_unreachable("Unexpected vector element type"); |
| Krzysztof Parzyszek | 942fa16 | 2017-11-22 20:56:23 +0000 | [diff] [blame] | 2196 | } |
| Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2197 | |
| Krzysztof Parzyszek | 942fa16 | 2017-11-22 20:56:23 +0000 | [diff] [blame] | 2198 | SDValue |
| 2199 | HexagonTargetLowering::buildVector64(ArrayRef<SDValue> Elem, const SDLoc &dl, |
| 2200 | MVT VecTy, SelectionDAG &DAG) const { |
| 2201 | MVT ElemTy = VecTy.getVectorElementType(); |
| 2202 | assert(VecTy.getVectorNumElements() == Elem.size()); |
| 2203 | |
| Krzysztof Parzyszek | e4ce92c | 2017-12-20 20:49:43 +0000 | [diff] [blame] | 2204 | SmallVector<ConstantInt*,8> Consts(Elem.size()); |
| 2205 | bool AllConst = getBuildVectorConstInts(Elem, VecTy, DAG, Consts); |
| Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2206 | |
| Krzysztof Parzyszek | 942fa16 | 2017-11-22 20:56:23 +0000 | [diff] [blame] | 2207 | unsigned First, Num = Elem.size(); |
| 2208 | for (First = 0; First != Num; ++First) |
| Krzysztof Parzyszek | 7d37dd8 | 2017-12-06 16:40:37 +0000 | [diff] [blame] | 2209 | if (!isUndef(Elem[First])) |
| Krzysztof Parzyszek | 942fa16 | 2017-11-22 20:56:23 +0000 | [diff] [blame] | 2210 | break; |
| 2211 | if (First == Num) |
| 2212 | return DAG.getUNDEF(VecTy); |
| Krzysztof Parzyszek | 0bd55a7 | 2016-07-29 16:44:27 +0000 | [diff] [blame] | 2213 | |
| Krzysztof Parzyszek | e4ce92c | 2017-12-20 20:49:43 +0000 | [diff] [blame] | 2214 | if (AllConst && |
| 2215 | llvm::all_of(Consts, [](ConstantInt *CI) { return CI->isZero(); })) |
| 2216 | return getZero(dl, VecTy, DAG); |
| 2217 | |
| Krzysztof Parzyszek | 942fa16 | 2017-11-22 20:56:23 +0000 | [diff] [blame] | 2218 | // First try splat if possible. |
| 2219 | if (ElemTy == MVT::i16) { |
| 2220 | bool IsSplat = true; |
| 2221 | for (unsigned i = 0; i != Num; ++i) { |
| 2222 | if (i == First) |
| Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2223 | continue; |
| Krzysztof Parzyszek | 7d37dd8 | 2017-12-06 16:40:37 +0000 | [diff] [blame] | 2224 | if (Elem[i] == Elem[First] || isUndef(Elem[i])) |
| Krzysztof Parzyszek | 942fa16 | 2017-11-22 20:56:23 +0000 | [diff] [blame] | 2225 | continue; |
| 2226 | IsSplat = false; |
| 2227 | break; |
| Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2228 | } |
| Krzysztof Parzyszek | fb0fcac | 2017-12-20 20:33:49 +0000 | [diff] [blame] | 2229 | if (IsSplat) { |
| 2230 | // Legalize the operand to VSPLAT. |
| 2231 | SDValue Ext = DAG.getZExtOrTrunc(Elem[First], dl, MVT::i32); |
| 2232 | return DAG.getNode(HexagonISD::VSPLAT, dl, VecTy, Ext); |
| 2233 | } |
| Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2234 | } |
| 2235 | |
| Krzysztof Parzyszek | 942fa16 | 2017-11-22 20:56:23 +0000 | [diff] [blame] | 2236 | // Then try constant. |
| 2237 | if (AllConst) { |
| 2238 | uint64_t Val = 0; |
| 2239 | unsigned W = ElemTy.getSizeInBits(); |
| 2240 | uint64_t Mask = (ElemTy == MVT::i8) ? 0xFFull |
| 2241 | : (ElemTy == MVT::i16) ? 0xFFFFull : 0xFFFFFFFFull; |
| 2242 | for (unsigned i = 0; i != Num; ++i) |
| Krzysztof Parzyszek | 240df6f | 2018-01-11 18:30:41 +0000 | [diff] [blame] | 2243 | Val = (Val << W) | (Consts[Num-1-i]->getZExtValue() & Mask); |
| Krzysztof Parzyszek | 942fa16 | 2017-11-22 20:56:23 +0000 | [diff] [blame] | 2244 | SDValue V0 = DAG.getConstant(Val, dl, MVT::i64); |
| 2245 | return DAG.getBitcast(VecTy, V0); |
| 2246 | } |
| 2247 | |
| 2248 | // Build two 32-bit vectors and concatenate. |
| 2249 | MVT HalfTy = MVT::getVectorVT(ElemTy, Num/2); |
| 2250 | SDValue L = (ElemTy == MVT::i32) |
| 2251 | ? Elem[0] |
| Krzysztof Parzyszek | e4ce92c | 2017-12-20 20:49:43 +0000 | [diff] [blame] | 2252 | : buildVector32(Elem.take_front(Num/2), dl, HalfTy, DAG); |
| Krzysztof Parzyszek | 942fa16 | 2017-11-22 20:56:23 +0000 | [diff] [blame] | 2253 | SDValue H = (ElemTy == MVT::i32) |
| 2254 | ? Elem[1] |
| Krzysztof Parzyszek | e4ce92c | 2017-12-20 20:49:43 +0000 | [diff] [blame] | 2255 | : buildVector32(Elem.drop_front(Num/2), dl, HalfTy, DAG); |
| Krzysztof Parzyszek | 7d37dd8 | 2017-12-06 16:40:37 +0000 | [diff] [blame] | 2256 | return DAG.getNode(HexagonISD::COMBINE, dl, VecTy, {H, L}); |
| Krzysztof Parzyszek | 942fa16 | 2017-11-22 20:56:23 +0000 | [diff] [blame] | 2257 | } |
| 2258 | |
| 2259 | SDValue |
| Krzysztof Parzyszek | 6a8e5f4 | 2017-11-29 19:58:10 +0000 | [diff] [blame] | 2260 | HexagonTargetLowering::extractVector(SDValue VecV, SDValue IdxV, |
| 2261 | const SDLoc &dl, MVT ValTy, MVT ResTy, |
| 2262 | SelectionDAG &DAG) const { |
| 2263 | MVT VecTy = ty(VecV); |
| 2264 | assert(!ValTy.isVector() || |
| 2265 | VecTy.getVectorElementType() == ValTy.getVectorElementType()); |
| 2266 | unsigned VecWidth = VecTy.getSizeInBits(); |
| 2267 | unsigned ValWidth = ValTy.getSizeInBits(); |
| 2268 | unsigned ElemWidth = VecTy.getVectorElementType().getSizeInBits(); |
| Krzysztof Parzyszek | 6a8e5f4 | 2017-11-29 19:58:10 +0000 | [diff] [blame] | 2269 | assert((VecWidth % ElemWidth) == 0); |
| Krzysztof Parzyszek | 3780a0e | 2018-01-23 17:53:59 +0000 | [diff] [blame] | 2270 | auto *IdxN = dyn_cast<ConstantSDNode>(IdxV); |
| 2271 | |
| 2272 | // Special case for v{8,4,2}i1 (the only boolean vectors legal in Hexagon |
| 2273 | // without any coprocessors). |
| 2274 | if (ElemWidth == 1) { |
| 2275 | assert(VecWidth == VecTy.getVectorNumElements() && "Sanity failure"); |
| 2276 | assert(VecWidth == 8 || VecWidth == 4 || VecWidth == 2); |
| 2277 | // Check if this is an extract of the lowest bit. |
| 2278 | if (IdxN) { |
| 2279 | // Extracting the lowest bit is a no-op, but it changes the type, |
| 2280 | // so it must be kept as an operation to avoid errors related to |
| 2281 | // type mismatches. |
| 2282 | if (IdxN->isNullValue() && ValTy.getSizeInBits() == 1) |
| 2283 | return DAG.getNode(HexagonISD::TYPECAST, dl, MVT::i1, VecV); |
| 2284 | } |
| 2285 | |
| 2286 | // If the value extracted is a single bit, use tstbit. |
| 2287 | if (ValWidth == 1) { |
| Krzysztof Parzyszek | 15efa98 | 2018-01-31 21:17:03 +0000 | [diff] [blame] | 2288 | SDValue A0 = getInstr(Hexagon::C2_tfrpr, dl, MVT::i32, {VecV}, DAG); |
| Krzysztof Parzyszek | 4e07509 | 2018-07-25 16:20:59 +0000 | [diff] [blame] | 2289 | SDValue M0 = DAG.getConstant(8 / VecWidth, dl, MVT::i32); |
| 2290 | SDValue I0 = DAG.getNode(ISD::MUL, dl, MVT::i32, IdxV, M0); |
| 2291 | return DAG.getNode(HexagonISD::TSTBIT, dl, MVT::i1, A0, I0); |
| Krzysztof Parzyszek | 3780a0e | 2018-01-23 17:53:59 +0000 | [diff] [blame] | 2292 | } |
| 2293 | |
| 2294 | // Each bool vector (v2i1, v4i1, v8i1) always occupies 8 bits in |
| 2295 | // a predicate register. The elements of the vector are repeated |
| 2296 | // in the register (if necessary) so that the total number is 8. |
| 2297 | // The extracted subvector will need to be expanded in such a way. |
| 2298 | unsigned Scale = VecWidth / ValWidth; |
| 2299 | |
| 2300 | // Generate (p2d VecV) >> 8*Idx to move the interesting bytes to |
| 2301 | // position 0. |
| 2302 | assert(ty(IdxV) == MVT::i32); |
| Krzysztof Parzyszek | 528aff3 | 2018-10-02 15:05:43 +0000 | [diff] [blame] | 2303 | unsigned VecRep = 8 / VecWidth; |
| Krzysztof Parzyszek | 3780a0e | 2018-01-23 17:53:59 +0000 | [diff] [blame] | 2304 | SDValue S0 = DAG.getNode(ISD::MUL, dl, MVT::i32, IdxV, |
| Krzysztof Parzyszek | 528aff3 | 2018-10-02 15:05:43 +0000 | [diff] [blame] | 2305 | DAG.getConstant(8*VecRep, dl, MVT::i32)); |
| Krzysztof Parzyszek | 3780a0e | 2018-01-23 17:53:59 +0000 | [diff] [blame] | 2306 | SDValue T0 = DAG.getNode(HexagonISD::P2D, dl, MVT::i64, VecV); |
| 2307 | SDValue T1 = DAG.getNode(ISD::SRL, dl, MVT::i64, T0, S0); |
| 2308 | while (Scale > 1) { |
| 2309 | // The longest possible subvector is at most 32 bits, so it is always |
| 2310 | // contained in the low subregister. |
| 2311 | T1 = DAG.getTargetExtractSubreg(Hexagon::isub_lo, dl, MVT::i32, T1); |
| 2312 | T1 = expandPredicate(T1, dl, DAG); |
| 2313 | Scale /= 2; |
| 2314 | } |
| 2315 | |
| 2316 | return DAG.getNode(HexagonISD::D2P, dl, ResTy, T1); |
| 2317 | } |
| 2318 | |
| 2319 | assert(VecWidth == 32 || VecWidth == 64); |
| Krzysztof Parzyszek | 6a8e5f4 | 2017-11-29 19:58:10 +0000 | [diff] [blame] | 2320 | |
| 2321 | // Cast everything to scalar integer types. |
| 2322 | MVT ScalarTy = tyScalar(VecTy); |
| 2323 | VecV = DAG.getBitcast(ScalarTy, VecV); |
| 2324 | |
| 2325 | SDValue WidthV = DAG.getConstant(ValWidth, dl, MVT::i32); |
| 2326 | SDValue ExtV; |
| 2327 | |
| Krzysztof Parzyszek | 3780a0e | 2018-01-23 17:53:59 +0000 | [diff] [blame] | 2328 | if (IdxN) { |
| 2329 | unsigned Off = IdxN->getZExtValue() * ElemWidth; |
| Krzysztof Parzyszek | 6a8e5f4 | 2017-11-29 19:58:10 +0000 | [diff] [blame] | 2330 | if (VecWidth == 64 && ValWidth == 32) { |
| 2331 | assert(Off == 0 || Off == 32); |
| 2332 | unsigned SubIdx = Off == 0 ? Hexagon::isub_lo : Hexagon::isub_hi; |
| 2333 | ExtV = DAG.getTargetExtractSubreg(SubIdx, dl, MVT::i32, VecV); |
| 2334 | } else if (Off == 0 && (ValWidth % 8) == 0) { |
| 2335 | ExtV = DAG.getZeroExtendInReg(VecV, dl, tyScalar(ValTy)); |
| 2336 | } else { |
| 2337 | SDValue OffV = DAG.getConstant(Off, dl, MVT::i32); |
| 2338 | // The return type of EXTRACTU must be the same as the type of the |
| 2339 | // input vector. |
| 2340 | ExtV = DAG.getNode(HexagonISD::EXTRACTU, dl, ScalarTy, |
| 2341 | {VecV, WidthV, OffV}); |
| 2342 | } |
| 2343 | } else { |
| 2344 | if (ty(IdxV) != MVT::i32) |
| 2345 | IdxV = DAG.getZExtOrTrunc(IdxV, dl, MVT::i32); |
| 2346 | SDValue OffV = DAG.getNode(ISD::MUL, dl, MVT::i32, IdxV, |
| 2347 | DAG.getConstant(ElemWidth, dl, MVT::i32)); |
| Krzysztof Parzyszek | b1b2960 | 2018-01-04 13:56:04 +0000 | [diff] [blame] | 2348 | ExtV = DAG.getNode(HexagonISD::EXTRACTU, dl, ScalarTy, |
| 2349 | {VecV, WidthV, OffV}); |
| Krzysztof Parzyszek | 6a8e5f4 | 2017-11-29 19:58:10 +0000 | [diff] [blame] | 2350 | } |
| 2351 | |
| 2352 | // Cast ExtV to the requested result type. |
| 2353 | ExtV = DAG.getZExtOrTrunc(ExtV, dl, tyScalar(ResTy)); |
| 2354 | ExtV = DAG.getBitcast(ResTy, ExtV); |
| 2355 | return ExtV; |
| 2356 | } |
| 2357 | |
| 2358 | SDValue |
| 2359 | HexagonTargetLowering::insertVector(SDValue VecV, SDValue ValV, SDValue IdxV, |
| 2360 | const SDLoc &dl, MVT ValTy, |
| 2361 | SelectionDAG &DAG) const { |
| 2362 | MVT VecTy = ty(VecV); |
| Krzysztof Parzyszek | 3780a0e | 2018-01-23 17:53:59 +0000 | [diff] [blame] | 2363 | if (VecTy.getVectorElementType() == MVT::i1) { |
| 2364 | MVT ValTy = ty(ValV); |
| 2365 | assert(ValTy.getVectorElementType() == MVT::i1); |
| 2366 | SDValue ValR = DAG.getNode(HexagonISD::P2D, dl, MVT::i64, ValV); |
| 2367 | unsigned VecLen = VecTy.getVectorNumElements(); |
| 2368 | unsigned Scale = VecLen / ValTy.getVectorNumElements(); |
| 2369 | assert(Scale > 1); |
| 2370 | |
| 2371 | for (unsigned R = Scale; R > 1; R /= 2) { |
| 2372 | ValR = contractPredicate(ValR, dl, DAG); |
| 2373 | ValR = DAG.getNode(HexagonISD::COMBINE, dl, MVT::i64, |
| 2374 | DAG.getUNDEF(MVT::i32), ValR); |
| 2375 | } |
| 2376 | // The longest possible subvector is at most 32 bits, so it is always |
| 2377 | // contained in the low subregister. |
| 2378 | ValR = DAG.getTargetExtractSubreg(Hexagon::isub_lo, dl, MVT::i32, ValR); |
| 2379 | |
| 2380 | unsigned ValBytes = 64 / Scale; |
| 2381 | SDValue Width = DAG.getConstant(ValBytes*8, dl, MVT::i32); |
| 2382 | SDValue Idx = DAG.getNode(ISD::MUL, dl, MVT::i32, IdxV, |
| 2383 | DAG.getConstant(8, dl, MVT::i32)); |
| 2384 | SDValue VecR = DAG.getNode(HexagonISD::P2D, dl, MVT::i64, VecV); |
| 2385 | SDValue Ins = DAG.getNode(HexagonISD::INSERT, dl, MVT::i32, |
| 2386 | {VecR, ValR, Width, Idx}); |
| 2387 | return DAG.getNode(HexagonISD::D2P, dl, VecTy, Ins); |
| 2388 | } |
| 2389 | |
| Krzysztof Parzyszek | 6a8e5f4 | 2017-11-29 19:58:10 +0000 | [diff] [blame] | 2390 | unsigned VecWidth = VecTy.getSizeInBits(); |
| 2391 | unsigned ValWidth = ValTy.getSizeInBits(); |
| 2392 | assert(VecWidth == 32 || VecWidth == 64); |
| 2393 | assert((VecWidth % ValWidth) == 0); |
| 2394 | |
| 2395 | // Cast everything to scalar integer types. |
| 2396 | MVT ScalarTy = MVT::getIntegerVT(VecWidth); |
| 2397 | // The actual type of ValV may be different than ValTy (which is related |
| 2398 | // to the vector type). |
| 2399 | unsigned VW = ty(ValV).getSizeInBits(); |
| 2400 | ValV = DAG.getBitcast(MVT::getIntegerVT(VW), ValV); |
| 2401 | VecV = DAG.getBitcast(ScalarTy, VecV); |
| 2402 | if (VW != VecWidth) |
| 2403 | ValV = DAG.getAnyExtOrTrunc(ValV, dl, ScalarTy); |
| 2404 | |
| 2405 | SDValue WidthV = DAG.getConstant(ValWidth, dl, MVT::i32); |
| 2406 | SDValue InsV; |
| 2407 | |
| 2408 | if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(IdxV)) { |
| 2409 | unsigned W = C->getZExtValue() * ValWidth; |
| 2410 | SDValue OffV = DAG.getConstant(W, dl, MVT::i32); |
| 2411 | InsV = DAG.getNode(HexagonISD::INSERT, dl, ScalarTy, |
| 2412 | {VecV, ValV, WidthV, OffV}); |
| 2413 | } else { |
| 2414 | if (ty(IdxV) != MVT::i32) |
| 2415 | IdxV = DAG.getZExtOrTrunc(IdxV, dl, MVT::i32); |
| 2416 | SDValue OffV = DAG.getNode(ISD::MUL, dl, MVT::i32, IdxV, WidthV); |
| Krzysztof Parzyszek | b1b2960 | 2018-01-04 13:56:04 +0000 | [diff] [blame] | 2417 | InsV = DAG.getNode(HexagonISD::INSERT, dl, ScalarTy, |
| 2418 | {VecV, ValV, WidthV, OffV}); |
| Krzysztof Parzyszek | 6a8e5f4 | 2017-11-29 19:58:10 +0000 | [diff] [blame] | 2419 | } |
| 2420 | |
| 2421 | return DAG.getNode(ISD::BITCAST, dl, VecTy, InsV); |
| 2422 | } |
| 2423 | |
| 2424 | SDValue |
| Krzysztof Parzyszek | 3780a0e | 2018-01-23 17:53:59 +0000 | [diff] [blame] | 2425 | HexagonTargetLowering::expandPredicate(SDValue Vec32, const SDLoc &dl, |
| 2426 | SelectionDAG &DAG) const { |
| 2427 | assert(ty(Vec32).getSizeInBits() == 32); |
| 2428 | if (isUndef(Vec32)) |
| 2429 | return DAG.getUNDEF(MVT::i64); |
| Krzysztof Parzyszek | 15efa98 | 2018-01-31 21:17:03 +0000 | [diff] [blame] | 2430 | return getInstr(Hexagon::S2_vsxtbh, dl, MVT::i64, {Vec32}, DAG); |
| Krzysztof Parzyszek | 3780a0e | 2018-01-23 17:53:59 +0000 | [diff] [blame] | 2431 | } |
| 2432 | |
| 2433 | SDValue |
| 2434 | HexagonTargetLowering::contractPredicate(SDValue Vec64, const SDLoc &dl, |
| 2435 | SelectionDAG &DAG) const { |
| 2436 | assert(ty(Vec64).getSizeInBits() == 64); |
| 2437 | if (isUndef(Vec64)) |
| 2438 | return DAG.getUNDEF(MVT::i32); |
| Krzysztof Parzyszek | 15efa98 | 2018-01-31 21:17:03 +0000 | [diff] [blame] | 2439 | return getInstr(Hexagon::S2_vtrunehb, dl, MVT::i32, {Vec64}, DAG); |
| Krzysztof Parzyszek | 3780a0e | 2018-01-23 17:53:59 +0000 | [diff] [blame] | 2440 | } |
| 2441 | |
| 2442 | SDValue |
| Krzysztof Parzyszek | e4ce92c | 2017-12-20 20:49:43 +0000 | [diff] [blame] | 2443 | HexagonTargetLowering::getZero(const SDLoc &dl, MVT Ty, SelectionDAG &DAG) |
| 2444 | const { |
| 2445 | if (Ty.isVector()) { |
| 2446 | assert(Ty.isInteger() && "Only integer vectors are supported here"); |
| 2447 | unsigned W = Ty.getSizeInBits(); |
| 2448 | if (W <= 64) |
| 2449 | return DAG.getBitcast(Ty, DAG.getConstant(0, dl, MVT::getIntegerVT(W))); |
| 2450 | return DAG.getNode(HexagonISD::VZERO, dl, Ty); |
| 2451 | } |
| 2452 | |
| 2453 | if (Ty.isInteger()) |
| 2454 | return DAG.getConstant(0, dl, Ty); |
| 2455 | if (Ty.isFloatingPoint()) |
| 2456 | return DAG.getConstantFP(0.0, dl, Ty); |
| 2457 | llvm_unreachable("Invalid type for zero"); |
| 2458 | } |
| 2459 | |
| 2460 | SDValue |
| Krzysztof Parzyszek | 942fa16 | 2017-11-22 20:56:23 +0000 | [diff] [blame] | 2461 | HexagonTargetLowering::LowerBUILD_VECTOR(SDValue Op, SelectionDAG &DAG) const { |
| Krzysztof Parzyszek | 7d37dd8 | 2017-12-06 16:40:37 +0000 | [diff] [blame] | 2462 | MVT VecTy = ty(Op); |
| Krzysztof Parzyszek | 3780a0e | 2018-01-23 17:53:59 +0000 | [diff] [blame] | 2463 | unsigned BW = VecTy.getSizeInBits(); |
| 2464 | const SDLoc &dl(Op); |
| 2465 | SmallVector<SDValue,8> Ops; |
| 2466 | for (unsigned i = 0, e = Op.getNumOperands(); i != e; ++i) |
| 2467 | Ops.push_back(Op.getOperand(i)); |
| 2468 | |
| 2469 | if (BW == 32) |
| 2470 | return buildVector32(Ops, dl, VecTy, DAG); |
| 2471 | if (BW == 64) |
| Krzysztof Parzyszek | e4ce92c | 2017-12-20 20:49:43 +0000 | [diff] [blame] | 2472 | return buildVector64(Ops, dl, VecTy, DAG); |
| Krzysztof Parzyszek | 3780a0e | 2018-01-23 17:53:59 +0000 | [diff] [blame] | 2473 | |
| 2474 | if (VecTy == MVT::v8i1 || VecTy == MVT::v4i1 || VecTy == MVT::v2i1) { |
| Krzysztof Parzyszek | ac83aab | 2019-08-16 16:16:27 +0000 | [diff] [blame] | 2475 | // Check if this is a special case or all-0 or all-1. |
| 2476 | bool All0 = true, All1 = true; |
| 2477 | for (SDValue P : Ops) { |
| 2478 | auto *CN = dyn_cast<ConstantSDNode>(P.getNode()); |
| 2479 | if (CN == nullptr) { |
| 2480 | All0 = All1 = false; |
| 2481 | break; |
| 2482 | } |
| 2483 | uint32_t C = CN->getZExtValue(); |
| 2484 | All0 &= (C == 0); |
| 2485 | All1 &= (C == 1); |
| 2486 | } |
| 2487 | if (All0) |
| 2488 | return DAG.getNode(HexagonISD::PFALSE, dl, VecTy); |
| 2489 | if (All1) |
| 2490 | return DAG.getNode(HexagonISD::PTRUE, dl, VecTy); |
| 2491 | |
| Krzysztof Parzyszek | 3780a0e | 2018-01-23 17:53:59 +0000 | [diff] [blame] | 2492 | // For each i1 element in the resulting predicate register, put 1 |
| 2493 | // shifted by the index of the element into a general-purpose register, |
| 2494 | // then or them together and transfer it back into a predicate register. |
| 2495 | SDValue Rs[8]; |
| 2496 | SDValue Z = getZero(dl, MVT::i32, DAG); |
| 2497 | // Always produce 8 bits, repeat inputs if necessary. |
| 2498 | unsigned Rep = 8 / VecTy.getVectorNumElements(); |
| 2499 | for (unsigned i = 0; i != 8; ++i) { |
| Simon Pilgrim | c1e2290 | 2018-01-23 21:22:16 +0000 | [diff] [blame] | 2500 | SDValue S = DAG.getConstant(1ull << i, dl, MVT::i32); |
| Krzysztof Parzyszek | 3780a0e | 2018-01-23 17:53:59 +0000 | [diff] [blame] | 2501 | Rs[i] = DAG.getSelect(dl, MVT::i32, Ops[i/Rep], S, Z); |
| 2502 | } |
| 2503 | for (ArrayRef<SDValue> A(Rs); A.size() != 1; A = A.drop_back(A.size()/2)) { |
| 2504 | for (unsigned i = 0, e = A.size()/2; i != e; ++i) |
| 2505 | Rs[i] = DAG.getNode(ISD::OR, dl, MVT::i32, Rs[2*i], Rs[2*i+1]); |
| 2506 | } |
| 2507 | // Move the value directly to a predicate register. |
| Krzysztof Parzyszek | 15efa98 | 2018-01-31 21:17:03 +0000 | [diff] [blame] | 2508 | return getInstr(Hexagon::C2_tfrrp, dl, VecTy, {Rs[0]}, DAG); |
| Krzysztof Parzyszek | 942fa16 | 2017-11-22 20:56:23 +0000 | [diff] [blame] | 2509 | } |
| 2510 | |
| 2511 | return SDValue(); |
| Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2512 | } |
| 2513 | |
| 2514 | SDValue |
| 2515 | HexagonTargetLowering::LowerCONCAT_VECTORS(SDValue Op, |
| 2516 | SelectionDAG &DAG) const { |
| Krzysztof Parzyszek | 7d37dd8 | 2017-12-06 16:40:37 +0000 | [diff] [blame] | 2517 | MVT VecTy = ty(Op); |
| Krzysztof Parzyszek | 3780a0e | 2018-01-23 17:53:59 +0000 | [diff] [blame] | 2518 | const SDLoc &dl(Op); |
| Krzysztof Parzyszek | 7d37dd8 | 2017-12-06 16:40:37 +0000 | [diff] [blame] | 2519 | if (VecTy.getSizeInBits() == 64) { |
| 2520 | assert(Op.getNumOperands() == 2); |
| Krzysztof Parzyszek | 3780a0e | 2018-01-23 17:53:59 +0000 | [diff] [blame] | 2521 | return DAG.getNode(HexagonISD::COMBINE, dl, VecTy, Op.getOperand(1), |
| Krzysztof Parzyszek | 7d37dd8 | 2017-12-06 16:40:37 +0000 | [diff] [blame] | 2522 | Op.getOperand(0)); |
| Krzysztof Parzyszek | 0bd55a7 | 2016-07-29 16:44:27 +0000 | [diff] [blame] | 2523 | } |
| 2524 | |
| Krzysztof Parzyszek | 3780a0e | 2018-01-23 17:53:59 +0000 | [diff] [blame] | 2525 | MVT ElemTy = VecTy.getVectorElementType(); |
| 2526 | if (ElemTy == MVT::i1) { |
| Krzysztof Parzyszek | 3780a0e | 2018-01-23 17:53:59 +0000 | [diff] [blame] | 2527 | assert(VecTy == MVT::v2i1 || VecTy == MVT::v4i1 || VecTy == MVT::v8i1); |
| 2528 | MVT OpTy = ty(Op.getOperand(0)); |
| 2529 | // Scale is how many times the operands need to be contracted to match |
| 2530 | // the representation in the target register. |
| 2531 | unsigned Scale = VecTy.getVectorNumElements() / OpTy.getVectorNumElements(); |
| 2532 | assert(Scale == Op.getNumOperands() && Scale > 1); |
| 2533 | |
| 2534 | // First, convert all bool vectors to integers, then generate pairwise |
| 2535 | // inserts to form values of doubled length. Up until there are only |
| 2536 | // two values left to concatenate, all of these values will fit in a |
| 2537 | // 32-bit integer, so keep them as i32 to use 32-bit inserts. |
| 2538 | SmallVector<SDValue,4> Words[2]; |
| 2539 | unsigned IdxW = 0; |
| 2540 | |
| 2541 | for (SDValue P : Op.getNode()->op_values()) { |
| 2542 | SDValue W = DAG.getNode(HexagonISD::P2D, dl, MVT::i64, P); |
| 2543 | for (unsigned R = Scale; R > 1; R /= 2) { |
| 2544 | W = contractPredicate(W, dl, DAG); |
| 2545 | W = DAG.getNode(HexagonISD::COMBINE, dl, MVT::i64, |
| 2546 | DAG.getUNDEF(MVT::i32), W); |
| 2547 | } |
| 2548 | W = DAG.getTargetExtractSubreg(Hexagon::isub_lo, dl, MVT::i32, W); |
| 2549 | Words[IdxW].push_back(W); |
| 2550 | } |
| 2551 | |
| 2552 | while (Scale > 2) { |
| 2553 | SDValue WidthV = DAG.getConstant(64 / Scale, dl, MVT::i32); |
| 2554 | Words[IdxW ^ 1].clear(); |
| 2555 | |
| 2556 | for (unsigned i = 0, e = Words[IdxW].size(); i != e; i += 2) { |
| 2557 | SDValue W0 = Words[IdxW][i], W1 = Words[IdxW][i+1]; |
| 2558 | // Insert W1 into W0 right next to the significant bits of W0. |
| 2559 | SDValue T = DAG.getNode(HexagonISD::INSERT, dl, MVT::i32, |
| 2560 | {W0, W1, WidthV, WidthV}); |
| 2561 | Words[IdxW ^ 1].push_back(T); |
| 2562 | } |
| 2563 | IdxW ^= 1; |
| 2564 | Scale /= 2; |
| 2565 | } |
| 2566 | |
| 2567 | // Another sanity check. At this point there should only be two words |
| 2568 | // left, and Scale should be 2. |
| 2569 | assert(Scale == 2 && Words[IdxW].size() == 2); |
| 2570 | |
| 2571 | SDValue WW = DAG.getNode(HexagonISD::COMBINE, dl, MVT::i64, |
| 2572 | Words[IdxW][1], Words[IdxW][0]); |
| 2573 | return DAG.getNode(HexagonISD::D2P, dl, VecTy, WW); |
| 2574 | } |
| 2575 | |
| Krzysztof Parzyszek | 0bd55a7 | 2016-07-29 16:44:27 +0000 | [diff] [blame] | 2576 | return SDValue(); |
| 2577 | } |
| 2578 | |
| 2579 | SDValue |
| Krzysztof Parzyszek | 6a8e5f4 | 2017-11-29 19:58:10 +0000 | [diff] [blame] | 2580 | HexagonTargetLowering::LowerEXTRACT_VECTOR_ELT(SDValue Op, |
| 2581 | SelectionDAG &DAG) const { |
| Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2582 | SDValue Vec = Op.getOperand(0); |
| Krzysztof Parzyszek | 6a8e5f4 | 2017-11-29 19:58:10 +0000 | [diff] [blame] | 2583 | MVT ElemTy = ty(Vec).getVectorElementType(); |
| 2584 | return extractVector(Vec, Op.getOperand(1), SDLoc(Op), ElemTy, ty(Op), DAG); |
| Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2585 | } |
| 2586 | |
| 2587 | SDValue |
| Krzysztof Parzyszek | 6a8e5f4 | 2017-11-29 19:58:10 +0000 | [diff] [blame] | 2588 | HexagonTargetLowering::LowerEXTRACT_SUBVECTOR(SDValue Op, |
| 2589 | SelectionDAG &DAG) const { |
| Krzysztof Parzyszek | 8abaf89 | 2018-02-06 20:22:20 +0000 | [diff] [blame] | 2590 | return extractVector(Op.getOperand(0), Op.getOperand(1), SDLoc(Op), |
| 2591 | ty(Op), ty(Op), DAG); |
| Krzysztof Parzyszek | 6a8e5f4 | 2017-11-29 19:58:10 +0000 | [diff] [blame] | 2592 | } |
| Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2593 | |
| Krzysztof Parzyszek | 6a8e5f4 | 2017-11-29 19:58:10 +0000 | [diff] [blame] | 2594 | SDValue |
| 2595 | HexagonTargetLowering::LowerINSERT_VECTOR_ELT(SDValue Op, |
| 2596 | SelectionDAG &DAG) const { |
| Krzysztof Parzyszek | 6a8e5f4 | 2017-11-29 19:58:10 +0000 | [diff] [blame] | 2597 | return insertVector(Op.getOperand(0), Op.getOperand(1), Op.getOperand(2), |
| Krzysztof Parzyszek | 8abaf89 | 2018-02-06 20:22:20 +0000 | [diff] [blame] | 2598 | SDLoc(Op), ty(Op).getVectorElementType(), DAG); |
| Krzysztof Parzyszek | 6a8e5f4 | 2017-11-29 19:58:10 +0000 | [diff] [blame] | 2599 | } |
| Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2600 | |
| Krzysztof Parzyszek | 6a8e5f4 | 2017-11-29 19:58:10 +0000 | [diff] [blame] | 2601 | SDValue |
| 2602 | HexagonTargetLowering::LowerINSERT_SUBVECTOR(SDValue Op, |
| 2603 | SelectionDAG &DAG) const { |
| 2604 | SDValue ValV = Op.getOperand(1); |
| 2605 | return insertVector(Op.getOperand(0), ValV, Op.getOperand(2), |
| 2606 | SDLoc(Op), ty(ValV), DAG); |
| Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2607 | } |
| 2608 | |
| Tim Northover | a441585 | 2013-08-06 09:12:35 +0000 | [diff] [blame] | 2609 | bool |
| 2610 | HexagonTargetLowering::allowTruncateForTailCall(Type *Ty1, Type *Ty2) const { |
| 2611 | // Assuming the caller does not have either a signext or zeroext modifier, and |
| 2612 | // only one value is accepted, any reasonable truncation is allowed. |
| 2613 | if (!Ty1->isIntegerTy() || !Ty2->isIntegerTy()) |
| 2614 | return false; |
| 2615 | |
| 2616 | // FIXME: in principle up to 64-bit could be made safe, but it would be very |
| 2617 | // fragile at the moment: any support for multiple value returns would be |
| 2618 | // liable to disallow tail calls involving i64 -> iN truncation in many cases. |
| 2619 | return Ty1->getPrimitiveSizeInBits() <= 32; |
| 2620 | } |
| 2621 | |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 2622 | SDValue |
| Krzysztof Parzyszek | 1df7059 | 2018-08-08 17:00:09 +0000 | [diff] [blame] | 2623 | HexagonTargetLowering::LowerLoad(SDValue Op, SelectionDAG &DAG) const { |
| 2624 | LoadSDNode *LN = cast<LoadSDNode>(Op.getNode()); |
| 2625 | unsigned ClaimAlign = LN->getAlignment(); |
| 2626 | validateConstPtrAlignment(LN->getBasePtr(), SDLoc(Op), ClaimAlign); |
| 2627 | // Call LowerUnalignedLoad for all loads, it recognizes loads that |
| 2628 | // don't need extra aligning. |
| 2629 | return LowerUnalignedLoad(Op, DAG); |
| 2630 | } |
| 2631 | |
| 2632 | SDValue |
| 2633 | HexagonTargetLowering::LowerStore(SDValue Op, SelectionDAG &DAG) const { |
| 2634 | StoreSDNode *SN = cast<StoreSDNode>(Op.getNode()); |
| 2635 | unsigned ClaimAlign = SN->getAlignment(); |
| 2636 | SDValue Ptr = SN->getBasePtr(); |
| 2637 | const SDLoc &dl(Op); |
| 2638 | validateConstPtrAlignment(Ptr, dl, ClaimAlign); |
| 2639 | |
| 2640 | MVT StoreTy = SN->getMemoryVT().getSimpleVT(); |
| 2641 | unsigned NeedAlign = Subtarget.getTypeAlignment(StoreTy); |
| 2642 | if (ClaimAlign < NeedAlign) |
| 2643 | return expandUnalignedStore(SN, DAG); |
| 2644 | return Op; |
| 2645 | } |
| 2646 | |
| 2647 | SDValue |
| Krzysztof Parzyszek | 2c3edf0 | 2018-03-07 17:27:18 +0000 | [diff] [blame] | 2648 | HexagonTargetLowering::LowerUnalignedLoad(SDValue Op, SelectionDAG &DAG) |
| 2649 | const { |
| 2650 | LoadSDNode *LN = cast<LoadSDNode>(Op.getNode()); |
| Krzysztof Parzyszek | 2c3edf0 | 2018-03-07 17:27:18 +0000 | [diff] [blame] | 2651 | MVT LoadTy = ty(Op); |
| 2652 | unsigned NeedAlign = Subtarget.getTypeAlignment(LoadTy); |
| Krzysztof Parzyszek | 1df7059 | 2018-08-08 17:00:09 +0000 | [diff] [blame] | 2653 | unsigned HaveAlign = LN->getAlignment(); |
| Krzysztof Parzyszek | 2c3edf0 | 2018-03-07 17:27:18 +0000 | [diff] [blame] | 2654 | if (HaveAlign >= NeedAlign) |
| 2655 | return Op; |
| Krzysztof Parzyszek | 2c3edf0 | 2018-03-07 17:27:18 +0000 | [diff] [blame] | 2656 | |
| 2657 | const SDLoc &dl(Op); |
| 2658 | const DataLayout &DL = DAG.getDataLayout(); |
| 2659 | LLVMContext &Ctx = *DAG.getContext(); |
| Krzysztof Parzyszek | 2c3edf0 | 2018-03-07 17:27:18 +0000 | [diff] [blame] | 2660 | |
| 2661 | // If the load aligning is disabled or the load can be broken up into two |
| 2662 | // smaller legal loads, do the default (target-independent) expansion. |
| 2663 | bool DoDefault = false; |
| Krzysztof Parzyszek | 480ab2b | 2018-03-08 18:15:13 +0000 | [diff] [blame] | 2664 | // Handle it in the default way if this is an indexed load. |
| 2665 | if (!LN->isUnindexed()) |
| 2666 | DoDefault = true; |
| 2667 | |
| Krzysztof Parzyszek | 2c3edf0 | 2018-03-07 17:27:18 +0000 | [diff] [blame] | 2668 | if (!AlignLoads) { |
| Simon Pilgrim | 266f439 | 2019-06-11 11:00:23 +0000 | [diff] [blame] | 2669 | if (allowsMemoryAccess(Ctx, DL, LN->getMemoryVT(), *LN->getMemOperand())) |
| Krzysztof Parzyszek | 2c3edf0 | 2018-03-07 17:27:18 +0000 | [diff] [blame] | 2670 | return Op; |
| 2671 | DoDefault = true; |
| 2672 | } |
| Simon Pilgrim | 266f439 | 2019-06-11 11:00:23 +0000 | [diff] [blame] | 2673 | if (!DoDefault && (2 * HaveAlign) == NeedAlign) { |
| Krzysztof Parzyszek | 2c3edf0 | 2018-03-07 17:27:18 +0000 | [diff] [blame] | 2674 | // The PartTy is the equivalent of "getLoadableTypeOfSize(HaveAlign)". |
| Simon Pilgrim | 266f439 | 2019-06-11 11:00:23 +0000 | [diff] [blame] | 2675 | MVT PartTy = HaveAlign <= 8 ? MVT::getIntegerVT(8 * HaveAlign) |
| Krzysztof Parzyszek | 2c3edf0 | 2018-03-07 17:27:18 +0000 | [diff] [blame] | 2676 | : MVT::getVectorVT(MVT::i8, HaveAlign); |
| Simon Pilgrim | 266f439 | 2019-06-11 11:00:23 +0000 | [diff] [blame] | 2677 | DoDefault = allowsMemoryAccess(Ctx, DL, PartTy, *LN->getMemOperand()); |
| Krzysztof Parzyszek | 2c3edf0 | 2018-03-07 17:27:18 +0000 | [diff] [blame] | 2678 | } |
| 2679 | if (DoDefault) { |
| 2680 | std::pair<SDValue, SDValue> P = expandUnalignedLoad(LN, DAG); |
| 2681 | return DAG.getMergeValues({P.first, P.second}, dl); |
| 2682 | } |
| 2683 | |
| 2684 | // The code below generates two loads, both aligned as NeedAlign, and |
| 2685 | // with the distance of NeedAlign between them. For that to cover the |
| 2686 | // bits that need to be loaded (and without overlapping), the size of |
| 2687 | // the loads should be equal to NeedAlign. This is true for all loadable |
| 2688 | // types, but add an assertion in case something changes in the future. |
| 2689 | assert(LoadTy.getSizeInBits() == 8*NeedAlign); |
| 2690 | |
| 2691 | unsigned LoadLen = NeedAlign; |
| 2692 | SDValue Base = LN->getBasePtr(); |
| 2693 | SDValue Chain = LN->getChain(); |
| 2694 | auto BO = getBaseAndOffset(Base); |
| 2695 | unsigned BaseOpc = BO.first.getOpcode(); |
| 2696 | if (BaseOpc == HexagonISD::VALIGNADDR && BO.second % LoadLen == 0) |
| 2697 | return Op; |
| 2698 | |
| 2699 | if (BO.second % LoadLen != 0) { |
| 2700 | BO.first = DAG.getNode(ISD::ADD, dl, MVT::i32, BO.first, |
| 2701 | DAG.getConstant(BO.second % LoadLen, dl, MVT::i32)); |
| 2702 | BO.second -= BO.second % LoadLen; |
| 2703 | } |
| 2704 | SDValue BaseNoOff = (BaseOpc != HexagonISD::VALIGNADDR) |
| 2705 | ? DAG.getNode(HexagonISD::VALIGNADDR, dl, MVT::i32, BO.first, |
| 2706 | DAG.getConstant(NeedAlign, dl, MVT::i32)) |
| 2707 | : BO.first; |
| 2708 | SDValue Base0 = DAG.getMemBasePlusOffset(BaseNoOff, BO.second, dl); |
| 2709 | SDValue Base1 = DAG.getMemBasePlusOffset(BaseNoOff, BO.second+LoadLen, dl); |
| 2710 | |
| 2711 | MachineMemOperand *WideMMO = nullptr; |
| 2712 | if (MachineMemOperand *MMO = LN->getMemOperand()) { |
| 2713 | MachineFunction &MF = DAG.getMachineFunction(); |
| 2714 | WideMMO = MF.getMachineMemOperand(MMO->getPointerInfo(), MMO->getFlags(), |
| 2715 | 2*LoadLen, LoadLen, MMO->getAAInfo(), MMO->getRanges(), |
| 2716 | MMO->getSyncScopeID(), MMO->getOrdering(), |
| 2717 | MMO->getFailureOrdering()); |
| 2718 | } |
| 2719 | |
| 2720 | SDValue Load0 = DAG.getLoad(LoadTy, dl, Chain, Base0, WideMMO); |
| 2721 | SDValue Load1 = DAG.getLoad(LoadTy, dl, Chain, Base1, WideMMO); |
| 2722 | |
| 2723 | SDValue Aligned = DAG.getNode(HexagonISD::VALIGN, dl, LoadTy, |
| 2724 | {Load1, Load0, BaseNoOff.getOperand(0)}); |
| 2725 | SDValue NewChain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, |
| 2726 | Load0.getValue(1), Load1.getValue(1)); |
| 2727 | SDValue M = DAG.getMergeValues({Aligned, NewChain}, dl); |
| 2728 | return M; |
| 2729 | } |
| 2730 | |
| 2731 | SDValue |
| Krzysztof Parzyszek | 5abf80c | 2019-07-01 15:50:09 +0000 | [diff] [blame] | 2732 | HexagonTargetLowering::LowerUAddSubO(SDValue Op, SelectionDAG &DAG) const { |
| 2733 | SDValue X = Op.getOperand(0), Y = Op.getOperand(1); |
| 2734 | auto *CY = dyn_cast<ConstantSDNode>(Y); |
| 2735 | if (!CY) |
| 2736 | return SDValue(); |
| 2737 | |
| 2738 | const SDLoc &dl(Op); |
| 2739 | SDVTList VTs = Op.getNode()->getVTList(); |
| 2740 | assert(VTs.NumVTs == 2); |
| 2741 | assert(VTs.VTs[1] == MVT::i1); |
| 2742 | unsigned Opc = Op.getOpcode(); |
| 2743 | |
| 2744 | if (CY) { |
| 2745 | uint32_t VY = CY->getZExtValue(); |
| 2746 | assert(VY != 0 && "This should have been folded"); |
| 2747 | // X +/- 1 |
| 2748 | if (VY != 1) |
| 2749 | return SDValue(); |
| 2750 | |
| 2751 | if (Opc == ISD::UADDO) { |
| 2752 | SDValue Op = DAG.getNode(ISD::ADD, dl, VTs.VTs[0], {X, Y}); |
| 2753 | SDValue Ov = DAG.getSetCC(dl, MVT::i1, Op, getZero(dl, ty(Op), DAG), |
| 2754 | ISD::SETEQ); |
| 2755 | return DAG.getMergeValues({Op, Ov}, dl); |
| 2756 | } |
| 2757 | if (Opc == ISD::USUBO) { |
| 2758 | SDValue Op = DAG.getNode(ISD::SUB, dl, VTs.VTs[0], {X, Y}); |
| 2759 | SDValue Ov = DAG.getSetCC(dl, MVT::i1, Op, |
| 2760 | DAG.getConstant(-1, dl, ty(Op)), ISD::SETEQ); |
| 2761 | return DAG.getMergeValues({Op, Ov}, dl); |
| 2762 | } |
| 2763 | } |
| 2764 | |
| 2765 | return SDValue(); |
| 2766 | } |
| 2767 | |
| 2768 | SDValue |
| Krzysztof Parzyszek | 0b6187c | 2018-06-01 14:00:32 +0000 | [diff] [blame] | 2769 | HexagonTargetLowering::LowerAddSubCarry(SDValue Op, SelectionDAG &DAG) const { |
| 2770 | const SDLoc &dl(Op); |
| 2771 | unsigned Opc = Op.getOpcode(); |
| 2772 | SDValue X = Op.getOperand(0), Y = Op.getOperand(1), C = Op.getOperand(2); |
| 2773 | |
| 2774 | if (Opc == ISD::ADDCARRY) |
| 2775 | return DAG.getNode(HexagonISD::ADDC, dl, Op.getNode()->getVTList(), |
| 2776 | { X, Y, C }); |
| 2777 | |
| 2778 | EVT CarryTy = C.getValueType(); |
| 2779 | SDValue SubC = DAG.getNode(HexagonISD::SUBC, dl, Op.getNode()->getVTList(), |
| 2780 | { X, Y, DAG.getLogicalNOT(dl, C, CarryTy) }); |
| 2781 | SDValue Out[] = { SubC.getValue(0), |
| 2782 | DAG.getLogicalNOT(dl, SubC.getValue(1), CarryTy) }; |
| 2783 | return DAG.getMergeValues(Out, dl); |
| 2784 | } |
| 2785 | |
| 2786 | SDValue |
| Jyotsna Verma | 5ed5181 | 2013-05-01 21:37:34 +0000 | [diff] [blame] | 2787 | HexagonTargetLowering::LowerEH_RETURN(SDValue Op, SelectionDAG &DAG) const { |
| 2788 | SDValue Chain = Op.getOperand(0); |
| 2789 | SDValue Offset = Op.getOperand(1); |
| 2790 | SDValue Handler = Op.getOperand(2); |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 2791 | SDLoc dl(Op); |
| Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 2792 | auto PtrVT = getPointerTy(DAG.getDataLayout()); |
| Jyotsna Verma | 5ed5181 | 2013-05-01 21:37:34 +0000 | [diff] [blame] | 2793 | |
| 2794 | // Mark function as containing a call to EH_RETURN. |
| 2795 | HexagonMachineFunctionInfo *FuncInfo = |
| 2796 | DAG.getMachineFunction().getInfo<HexagonMachineFunctionInfo>(); |
| 2797 | FuncInfo->setHasEHReturn(); |
| 2798 | |
| 2799 | unsigned OffsetReg = Hexagon::R28; |
| 2800 | |
| Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 2801 | SDValue StoreAddr = |
| 2802 | DAG.getNode(ISD::ADD, dl, PtrVT, DAG.getRegister(Hexagon::R30, PtrVT), |
| 2803 | DAG.getIntPtrConstant(4, dl)); |
| Justin Lebar | 9c37581 | 2016-07-15 18:27:10 +0000 | [diff] [blame] | 2804 | Chain = DAG.getStore(Chain, dl, Handler, StoreAddr, MachinePointerInfo()); |
| Jyotsna Verma | 5ed5181 | 2013-05-01 21:37:34 +0000 | [diff] [blame] | 2805 | Chain = DAG.getCopyToReg(Chain, dl, OffsetReg, Offset); |
| 2806 | |
| 2807 | // Not needed we already use it as explict input to EH_RETURN. |
| 2808 | // MF.getRegInfo().addLiveOut(OffsetReg); |
| 2809 | |
| 2810 | return DAG.getNode(HexagonISD::EH_RETURN, dl, MVT::Other, Chain); |
| 2811 | } |
| 2812 | |
| 2813 | SDValue |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 2814 | HexagonTargetLowering::LowerOperation(SDValue Op, SelectionDAG &DAG) const { |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 2815 | unsigned Opc = Op.getOpcode(); |
| Krzysztof Parzyszek | 88f1100 | 2018-02-06 14:24:57 +0000 | [diff] [blame] | 2816 | |
| 2817 | // Handle INLINEASM first. |
| Craig Topper | 784929d | 2019-02-08 20:48:56 +0000 | [diff] [blame] | 2818 | if (Opc == ISD::INLINEASM || Opc == ISD::INLINEASM_BR) |
| Krzysztof Parzyszek | 88f1100 | 2018-02-06 14:24:57 +0000 | [diff] [blame] | 2819 | return LowerINLINEASM(Op, DAG); |
| 2820 | |
| Krzysztof Parzyszek | 2c3edf0 | 2018-03-07 17:27:18 +0000 | [diff] [blame] | 2821 | if (isHvxOperation(Op)) { |
| 2822 | // If HVX lowering returns nothing, try the default lowering. |
| 2823 | if (SDValue V = LowerHvxOperation(Op, DAG)) |
| 2824 | return V; |
| 2825 | } |
| Krzysztof Parzyszek | 88f1100 | 2018-02-06 14:24:57 +0000 | [diff] [blame] | 2826 | |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 2827 | switch (Opc) { |
| 2828 | default: |
| 2829 | #ifndef NDEBUG |
| 2830 | Op.getNode()->dumpr(&DAG); |
| 2831 | if (Opc > HexagonISD::OP_BEGIN && Opc < HexagonISD::OP_END) |
| Krzysztof Parzyszek | e4ce92c | 2017-12-20 20:49:43 +0000 | [diff] [blame] | 2832 | errs() << "Error: check for a non-legal type in this operation\n"; |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 2833 | #endif |
| 2834 | llvm_unreachable("Should not custom lower this!"); |
| 2835 | case ISD::CONCAT_VECTORS: return LowerCONCAT_VECTORS(Op, DAG); |
| Krzysztof Parzyszek | 6a8e5f4 | 2017-11-29 19:58:10 +0000 | [diff] [blame] | 2836 | case ISD::INSERT_SUBVECTOR: return LowerINSERT_SUBVECTOR(Op, DAG); |
| 2837 | case ISD::INSERT_VECTOR_ELT: return LowerINSERT_VECTOR_ELT(Op, DAG); |
| 2838 | case ISD::EXTRACT_SUBVECTOR: return LowerEXTRACT_SUBVECTOR(Op, DAG); |
| 2839 | case ISD::EXTRACT_VECTOR_ELT: return LowerEXTRACT_VECTOR_ELT(Op, DAG); |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 2840 | case ISD::BUILD_VECTOR: return LowerBUILD_VECTOR(Op, DAG); |
| 2841 | case ISD::VECTOR_SHUFFLE: return LowerVECTOR_SHUFFLE(Op, DAG); |
| Krzysztof Parzyszek | 3780a0e | 2018-01-23 17:53:59 +0000 | [diff] [blame] | 2842 | case ISD::BITCAST: return LowerBITCAST(Op, DAG); |
| Krzysztof Parzyszek | 1df7059 | 2018-08-08 17:00:09 +0000 | [diff] [blame] | 2843 | case ISD::LOAD: return LowerLoad(Op, DAG); |
| 2844 | case ISD::STORE: return LowerStore(Op, DAG); |
| Krzysztof Parzyszek | 5abf80c | 2019-07-01 15:50:09 +0000 | [diff] [blame] | 2845 | case ISD::UADDO: |
| 2846 | case ISD::USUBO: return LowerUAddSubO(Op, DAG); |
| Krzysztof Parzyszek | 0b6187c | 2018-06-01 14:00:32 +0000 | [diff] [blame] | 2847 | case ISD::ADDCARRY: |
| 2848 | case ISD::SUBCARRY: return LowerAddSubCarry(Op, DAG); |
| Krzysztof Parzyszek | 4211334 | 2015-03-19 16:33:08 +0000 | [diff] [blame] | 2849 | case ISD::SRA: |
| 2850 | case ISD::SHL: |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 2851 | case ISD::SRL: return LowerVECTOR_SHIFT(Op, DAG); |
| Krzysztof Parzyszek | 3d67124 | 2018-06-12 12:49:36 +0000 | [diff] [blame] | 2852 | case ISD::ROTL: return LowerROTL(Op, DAG); |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 2853 | case ISD::ConstantPool: return LowerConstantPool(Op, DAG); |
| Krzysztof Parzyszek | 21dc8bd | 2015-12-18 20:19:30 +0000 | [diff] [blame] | 2854 | case ISD::JumpTable: return LowerJumpTable(Op, DAG); |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 2855 | case ISD::EH_RETURN: return LowerEH_RETURN(Op, DAG); |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 2856 | case ISD::RETURNADDR: return LowerRETURNADDR(Op, DAG); |
| 2857 | case ISD::FRAMEADDR: return LowerFRAMEADDR(Op, DAG); |
| Krzysztof Parzyszek | 7a737d1 | 2016-02-18 15:42:57 +0000 | [diff] [blame] | 2858 | case ISD::GlobalTLSAddress: return LowerGlobalTLSAddress(Op, DAG); |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 2859 | case ISD::ATOMIC_FENCE: return LowerATOMIC_FENCE(Op, DAG); |
| 2860 | case ISD::GlobalAddress: return LowerGLOBALADDRESS(Op, DAG); |
| 2861 | case ISD::BlockAddress: return LowerBlockAddress(Op, DAG); |
| Krzysztof Parzyszek | 21dc8bd | 2015-12-18 20:19:30 +0000 | [diff] [blame] | 2862 | case ISD::GLOBAL_OFFSET_TABLE: return LowerGLOBAL_OFFSET_TABLE(Op, DAG); |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 2863 | case ISD::VASTART: return LowerVASTART(Op, DAG); |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 2864 | case ISD::DYNAMIC_STACKALLOC: return LowerDYNAMIC_STACKALLOC(Op, DAG); |
| 2865 | case ISD::SETCC: return LowerSETCC(Op, DAG); |
| 2866 | case ISD::VSELECT: return LowerVSELECT(Op, DAG); |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 2867 | case ISD::INTRINSIC_WO_CHAIN: return LowerINTRINSIC_WO_CHAIN(Op, DAG); |
| Krzysztof Parzyszek | 6895b2c | 2016-02-18 13:58:38 +0000 | [diff] [blame] | 2868 | case ISD::INTRINSIC_VOID: return LowerINTRINSIC_VOID(Op, DAG); |
| Krzysztof Parzyszek | 6895b2c | 2016-02-18 13:58:38 +0000 | [diff] [blame] | 2869 | case ISD::PREFETCH: return LowerPREFETCH(Op, DAG); |
| Krzysztof Parzyszek | ab57c2b | 2017-02-22 22:28:47 +0000 | [diff] [blame] | 2870 | case ISD::READCYCLECOUNTER: return LowerREADCYCLECOUNTER(Op, DAG); |
| Krzysztof Parzyszek | 9eb085e | 2018-01-31 20:48:11 +0000 | [diff] [blame] | 2871 | break; |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 2872 | } |
| Krzysztof Parzyszek | 88f1100 | 2018-02-06 14:24:57 +0000 | [diff] [blame] | 2873 | |
| Krzysztof Parzyszek | 7d37dd8 | 2017-12-06 16:40:37 +0000 | [diff] [blame] | 2874 | return SDValue(); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 2875 | } |
| 2876 | |
| Krzysztof Parzyszek | 3780a0e | 2018-01-23 17:53:59 +0000 | [diff] [blame] | 2877 | void |
| Krzysztof Parzyszek | 1df7059 | 2018-08-08 17:00:09 +0000 | [diff] [blame] | 2878 | HexagonTargetLowering::LowerOperationWrapper(SDNode *N, |
| 2879 | SmallVectorImpl<SDValue> &Results, |
| 2880 | SelectionDAG &DAG) const { |
| 2881 | // We are only custom-lowering stores to verify the alignment of the |
| 2882 | // address if it is a compile-time constant. Since a store can be modified |
| 2883 | // during type-legalization (the value being stored may need legalization), |
| 2884 | // return empty Results here to indicate that we don't really make any |
| 2885 | // changes in the custom lowering. |
| 2886 | if (N->getOpcode() != ISD::STORE) |
| 2887 | return TargetLowering::LowerOperationWrapper(N, Results, DAG); |
| 2888 | } |
| 2889 | |
| 2890 | void |
| Krzysztof Parzyszek | 3780a0e | 2018-01-23 17:53:59 +0000 | [diff] [blame] | 2891 | HexagonTargetLowering::ReplaceNodeResults(SDNode *N, |
| 2892 | SmallVectorImpl<SDValue> &Results, |
| 2893 | SelectionDAG &DAG) const { |
| 2894 | const SDLoc &dl(N); |
| 2895 | switch (N->getOpcode()) { |
| 2896 | case ISD::SRL: |
| 2897 | case ISD::SRA: |
| 2898 | case ISD::SHL: |
| 2899 | return; |
| 2900 | case ISD::BITCAST: |
| 2901 | // Handle a bitcast from v8i1 to i8. |
| 2902 | if (N->getValueType(0) == MVT::i8) { |
| Krzysztof Parzyszek | 15efa98 | 2018-01-31 21:17:03 +0000 | [diff] [blame] | 2903 | SDValue P = getInstr(Hexagon::C2_tfrpr, dl, MVT::i32, |
| 2904 | N->getOperand(0), DAG); |
| Krzysztof Parzyszek | 0ce9319 | 2019-09-05 16:19:47 +0000 | [diff] [blame] | 2905 | SDValue T = DAG.getAnyExtOrTrunc(P, dl, MVT::i8); |
| 2906 | Results.push_back(T); |
| Krzysztof Parzyszek | 3780a0e | 2018-01-23 17:53:59 +0000 | [diff] [blame] | 2907 | } |
| 2908 | break; |
| 2909 | } |
| 2910 | } |
| 2911 | |
| Krzysztof Parzyszek | 8460301 | 2019-08-15 16:13:17 +0000 | [diff] [blame] | 2912 | SDValue |
| 2913 | HexagonTargetLowering::PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) |
| 2914 | const { |
| 2915 | SDValue Op(N, 0); |
| 2916 | if (isHvxOperation(Op)) { |
| 2917 | if (SDValue V = PerformHvxDAGCombine(N, DCI)) |
| 2918 | return V; |
| Krzysztof Parzyszek | ac83aab | 2019-08-16 16:16:27 +0000 | [diff] [blame] | 2919 | return SDValue(); |
| Krzysztof Parzyszek | 8460301 | 2019-08-15 16:13:17 +0000 | [diff] [blame] | 2920 | } |
| Krzysztof Parzyszek | ac83aab | 2019-08-16 16:16:27 +0000 | [diff] [blame] | 2921 | |
| 2922 | const SDLoc &dl(Op); |
| 2923 | unsigned Opc = Op.getOpcode(); |
| 2924 | |
| 2925 | if (Opc == HexagonISD::P2D) { |
| 2926 | SDValue P = Op.getOperand(0); |
| 2927 | switch (P.getOpcode()) { |
| 2928 | case HexagonISD::PTRUE: |
| 2929 | return DCI.DAG.getConstant(-1, dl, ty(Op)); |
| 2930 | case HexagonISD::PFALSE: |
| 2931 | return getZero(dl, ty(Op), DCI.DAG); |
| 2932 | default: |
| 2933 | break; |
| 2934 | } |
| 2935 | } else if (Opc == ISD::VSELECT) { |
| 2936 | // This is pretty much duplicated in HexagonISelLoweringHVX... |
| 2937 | // |
| 2938 | // (vselect (xor x, ptrue), v0, v1) -> (vselect x, v1, v0) |
| 2939 | SDValue Cond = Op.getOperand(0); |
| 2940 | if (Cond->getOpcode() == ISD::XOR) { |
| 2941 | SDValue C0 = Cond.getOperand(0), C1 = Cond.getOperand(1); |
| 2942 | if (C1->getOpcode() == HexagonISD::PTRUE) { |
| 2943 | SDValue VSel = DCI.DAG.getNode(ISD::VSELECT, dl, ty(Op), C0, |
| 2944 | Op.getOperand(2), Op.getOperand(1)); |
| 2945 | return VSel; |
| 2946 | } |
| 2947 | } |
| 2948 | } |
| 2949 | |
| Krzysztof Parzyszek | 8460301 | 2019-08-15 16:13:17 +0000 | [diff] [blame] | 2950 | return SDValue(); |
| 2951 | } |
| 2952 | |
| Krzysztof Parzyszek | 21dc8bd | 2015-12-18 20:19:30 +0000 | [diff] [blame] | 2953 | /// Returns relocation base for the given PIC jumptable. |
| 2954 | SDValue |
| 2955 | HexagonTargetLowering::getPICJumpTableRelocBase(SDValue Table, |
| 2956 | SelectionDAG &DAG) const { |
| 2957 | int Idx = cast<JumpTableSDNode>(Table)->getIndex(); |
| 2958 | EVT VT = Table.getValueType(); |
| 2959 | SDValue T = DAG.getTargetJumpTable(Idx, VT, HexagonII::MO_PCREL); |
| 2960 | return DAG.getNode(HexagonISD::AT_PCREL, SDLoc(Table), VT, T); |
| 2961 | } |
| 2962 | |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 2963 | //===----------------------------------------------------------------------===// |
| 2964 | // Inline Assembly Support |
| 2965 | //===----------------------------------------------------------------------===// |
| 2966 | |
| Krzysztof Parzyszek | ca3b532 | 2016-05-18 14:34:51 +0000 | [diff] [blame] | 2967 | TargetLowering::ConstraintType |
| 2968 | HexagonTargetLowering::getConstraintType(StringRef Constraint) const { |
| 2969 | if (Constraint.size() == 1) { |
| 2970 | switch (Constraint[0]) { |
| 2971 | case 'q': |
| 2972 | case 'v': |
| 2973 | if (Subtarget.useHVXOps()) |
| Krzysztof Parzyszek | 3ad0d01 | 2017-07-21 17:51:27 +0000 | [diff] [blame] | 2974 | return C_RegisterClass; |
| 2975 | break; |
| 2976 | case 'a': |
| 2977 | return C_RegisterClass; |
| 2978 | default: |
| Krzysztof Parzyszek | ca3b532 | 2016-05-18 14:34:51 +0000 | [diff] [blame] | 2979 | break; |
| 2980 | } |
| 2981 | } |
| 2982 | return TargetLowering::getConstraintType(Constraint); |
| 2983 | } |
| 2984 | |
| Krzysztof Parzyszek | fb4c417 | 2016-08-19 19:29:15 +0000 | [diff] [blame] | 2985 | std::pair<unsigned, const TargetRegisterClass*> |
| Eric Christopher | 11e4df7 | 2015-02-26 22:38:43 +0000 | [diff] [blame] | 2986 | HexagonTargetLowering::getRegForInlineAsmConstraint( |
| Benjamin Kramer | 9bfb627 | 2015-07-05 19:29:18 +0000 | [diff] [blame] | 2987 | const TargetRegisterInfo *TRI, StringRef Constraint, MVT VT) const { |
| Krzysztof Parzyszek | 08ff888 | 2015-11-26 18:38:27 +0000 | [diff] [blame] | 2988 | |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 2989 | if (Constraint.size() == 1) { |
| 2990 | switch (Constraint[0]) { |
| 2991 | case 'r': // R0-R31 |
| Krzysztof Parzyszek | fb4c417 | 2016-08-19 19:29:15 +0000 | [diff] [blame] | 2992 | switch (VT.SimpleTy) { |
| 2993 | default: |
| Krzysztof Parzyszek | 022922b | 2017-10-20 20:24:44 +0000 | [diff] [blame] | 2994 | return {0u, nullptr}; |
| Krzysztof Parzyszek | fb4c417 | 2016-08-19 19:29:15 +0000 | [diff] [blame] | 2995 | case MVT::i1: |
| 2996 | case MVT::i8: |
| 2997 | case MVT::i16: |
| 2998 | case MVT::i32: |
| 2999 | case MVT::f32: |
| Krzysztof Parzyszek | 022922b | 2017-10-20 20:24:44 +0000 | [diff] [blame] | 3000 | return {0u, &Hexagon::IntRegsRegClass}; |
| Krzysztof Parzyszek | fb4c417 | 2016-08-19 19:29:15 +0000 | [diff] [blame] | 3001 | case MVT::i64: |
| 3002 | case MVT::f64: |
| Krzysztof Parzyszek | 022922b | 2017-10-20 20:24:44 +0000 | [diff] [blame] | 3003 | return {0u, &Hexagon::DoubleRegsRegClass}; |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 3004 | } |
| Krzysztof Parzyszek | 3ad0d01 | 2017-07-21 17:51:27 +0000 | [diff] [blame] | 3005 | break; |
| 3006 | case 'a': // M0-M1 |
| Krzysztof Parzyszek | 022922b | 2017-10-20 20:24:44 +0000 | [diff] [blame] | 3007 | if (VT != MVT::i32) |
| 3008 | return {0u, nullptr}; |
| 3009 | return {0u, &Hexagon::ModRegsRegClass}; |
| Krzysztof Parzyszek | 08ff888 | 2015-11-26 18:38:27 +0000 | [diff] [blame] | 3010 | case 'q': // q0-q3 |
| Krzysztof Parzyszek | fcbb7d1 | 2017-03-02 17:50:24 +0000 | [diff] [blame] | 3011 | switch (VT.getSizeInBits()) { |
| Krzysztof Parzyszek | fb4c417 | 2016-08-19 19:29:15 +0000 | [diff] [blame] | 3012 | default: |
| Krzysztof Parzyszek | 022922b | 2017-10-20 20:24:44 +0000 | [diff] [blame] | 3013 | return {0u, nullptr}; |
| Krzysztof Parzyszek | fcbb7d1 | 2017-03-02 17:50:24 +0000 | [diff] [blame] | 3014 | case 512: |
| Krzysztof Parzyszek | fcbb7d1 | 2017-03-02 17:50:24 +0000 | [diff] [blame] | 3015 | case 1024: |
| Krzysztof Parzyszek | 022922b | 2017-10-20 20:24:44 +0000 | [diff] [blame] | 3016 | return {0u, &Hexagon::HvxQRRegClass}; |
| Krzysztof Parzyszek | fb4c417 | 2016-08-19 19:29:15 +0000 | [diff] [blame] | 3017 | } |
| Krzysztof Parzyszek | 3ad0d01 | 2017-07-21 17:51:27 +0000 | [diff] [blame] | 3018 | break; |
| Krzysztof Parzyszek | 08ff888 | 2015-11-26 18:38:27 +0000 | [diff] [blame] | 3019 | case 'v': // V0-V31 |
| Krzysztof Parzyszek | fcbb7d1 | 2017-03-02 17:50:24 +0000 | [diff] [blame] | 3020 | switch (VT.getSizeInBits()) { |
| Krzysztof Parzyszek | fb4c417 | 2016-08-19 19:29:15 +0000 | [diff] [blame] | 3021 | default: |
| Krzysztof Parzyszek | 022922b | 2017-10-20 20:24:44 +0000 | [diff] [blame] | 3022 | return {0u, nullptr}; |
| Krzysztof Parzyszek | fcbb7d1 | 2017-03-02 17:50:24 +0000 | [diff] [blame] | 3023 | case 512: |
| Krzysztof Parzyszek | 022922b | 2017-10-20 20:24:44 +0000 | [diff] [blame] | 3024 | return {0u, &Hexagon::HvxVRRegClass}; |
| Krzysztof Parzyszek | fcbb7d1 | 2017-03-02 17:50:24 +0000 | [diff] [blame] | 3025 | case 1024: |
| Krzysztof Parzyszek | d8b780d | 2018-06-20 13:56:09 +0000 | [diff] [blame] | 3026 | if (Subtarget.hasV60Ops() && Subtarget.useHVX128BOps()) |
| Krzysztof Parzyszek | 022922b | 2017-10-20 20:24:44 +0000 | [diff] [blame] | 3027 | return {0u, &Hexagon::HvxVRRegClass}; |
| 3028 | return {0u, &Hexagon::HvxWRRegClass}; |
| Krzysztof Parzyszek | fcbb7d1 | 2017-03-02 17:50:24 +0000 | [diff] [blame] | 3029 | case 2048: |
| Krzysztof Parzyszek | 022922b | 2017-10-20 20:24:44 +0000 | [diff] [blame] | 3030 | return {0u, &Hexagon::HvxWRRegClass}; |
| Krzysztof Parzyszek | fb4c417 | 2016-08-19 19:29:15 +0000 | [diff] [blame] | 3031 | } |
| Krzysztof Parzyszek | 3ad0d01 | 2017-07-21 17:51:27 +0000 | [diff] [blame] | 3032 | break; |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 3033 | default: |
| Krzysztof Parzyszek | 022922b | 2017-10-20 20:24:44 +0000 | [diff] [blame] | 3034 | return {0u, nullptr}; |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 3035 | } |
| 3036 | } |
| 3037 | |
| Eric Christopher | 11e4df7 | 2015-02-26 22:38:43 +0000 | [diff] [blame] | 3038 | return TargetLowering::getRegForInlineAsmConstraint(TRI, Constraint, VT); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 3039 | } |
| 3040 | |
| Sirish Pande | 69295b8 | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 3041 | /// isFPImmLegal - Returns true if the target can instruction select the |
| 3042 | /// specified FP immediate natively. If false, the legalizer will |
| 3043 | /// materialize the FP immediate as a load from a constant pool. |
| Adhemerval Zanella | 664c1ef | 2019-03-18 18:40:07 +0000 | [diff] [blame] | 3044 | bool HexagonTargetLowering::isFPImmLegal(const APFloat &Imm, EVT VT, |
| 3045 | bool ForCodeSize) const { |
| Krzysztof Parzyszek | 6bfc657 | 2018-10-19 17:31:11 +0000 | [diff] [blame] | 3046 | return true; |
| Sirish Pande | 69295b8 | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 3047 | } |
| 3048 | |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 3049 | /// isLegalAddressingMode - Return true if the addressing mode represented by |
| 3050 | /// 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] | 3051 | bool HexagonTargetLowering::isLegalAddressingMode(const DataLayout &DL, |
| 3052 | const AddrMode &AM, Type *Ty, |
| Jonas Paulsson | 024e319 | 2017-07-21 11:59:37 +0000 | [diff] [blame] | 3053 | unsigned AS, Instruction *I) const { |
| Krzysztof Parzyszek | ed4e782 | 2016-08-03 15:06:18 +0000 | [diff] [blame] | 3054 | if (Ty->isSized()) { |
| 3055 | // When LSR detects uses of the same base address to access different |
| 3056 | // types (e.g. unions), it will assume a conservative type for these |
| 3057 | // uses: |
| 3058 | // LSR Use: Kind=Address of void in addrspace(4294967295), ... |
| 3059 | // The type Ty passed here would then be "void". Skip the alignment |
| 3060 | // checks, but do not return false right away, since that confuses |
| 3061 | // LSR into crashing. |
| 3062 | unsigned A = DL.getABITypeAlignment(Ty); |
| 3063 | // The base offset must be a multiple of the alignment. |
| 3064 | if ((AM.BaseOffs % A) != 0) |
| 3065 | return false; |
| 3066 | // The shifted offset must fit in 11 bits. |
| 3067 | if (!isInt<11>(AM.BaseOffs >> Log2_32(A))) |
| 3068 | return false; |
| 3069 | } |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 3070 | |
| 3071 | // No global is ever allowed as a base. |
| Krzysztof Parzyszek | 952d951 | 2015-04-22 21:17:00 +0000 | [diff] [blame] | 3072 | if (AM.BaseGV) |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 3073 | return false; |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 3074 | |
| 3075 | int Scale = AM.Scale; |
| Krzysztof Parzyszek | 317d42c | 2016-08-01 20:31:50 +0000 | [diff] [blame] | 3076 | if (Scale < 0) |
| 3077 | Scale = -Scale; |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 3078 | switch (Scale) { |
| 3079 | case 0: // No scale reg, "r+i", "r", or just "i". |
| 3080 | break; |
| 3081 | default: // No scaled addressing mode. |
| 3082 | return false; |
| 3083 | } |
| 3084 | return true; |
| 3085 | } |
| 3086 | |
| Krzysztof Parzyszek | 21dc8bd | 2015-12-18 20:19:30 +0000 | [diff] [blame] | 3087 | /// Return true if folding a constant offset with the given GlobalAddress is |
| 3088 | /// legal. It is frequently not legal in PIC relocation models. |
| 3089 | bool HexagonTargetLowering::isOffsetFoldingLegal(const GlobalAddressSDNode *GA) |
| 3090 | const { |
| 3091 | return HTM.getRelocationModel() == Reloc::Static; |
| 3092 | } |
| 3093 | |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 3094 | /// isLegalICmpImmediate - Return true if the specified immediate is legal |
| 3095 | /// icmp immediate, that is the target has icmp instructions which can compare |
| 3096 | /// a register against the immediate without having to materialize the |
| 3097 | /// immediate into a register. |
| 3098 | bool HexagonTargetLowering::isLegalICmpImmediate(int64_t Imm) const { |
| 3099 | return Imm >= -512 && Imm <= 511; |
| 3100 | } |
| 3101 | |
| 3102 | /// IsEligibleForTailCallOptimization - Check whether the call is eligible |
| 3103 | /// for tail call optimization. Targets which want to do tail call |
| 3104 | /// optimization should implement this function. |
| 3105 | bool HexagonTargetLowering::IsEligibleForTailCallOptimization( |
| 3106 | SDValue Callee, |
| 3107 | CallingConv::ID CalleeCC, |
| Krzysztof Parzyszek | cfbe6ba | 2018-02-13 15:35:07 +0000 | [diff] [blame] | 3108 | bool IsVarArg, |
| 3109 | bool IsCalleeStructRet, |
| 3110 | bool IsCallerStructRet, |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 3111 | const SmallVectorImpl<ISD::OutputArg> &Outs, |
| 3112 | const SmallVectorImpl<SDValue> &OutVals, |
| 3113 | const SmallVectorImpl<ISD::InputArg> &Ins, |
| 3114 | SelectionDAG& DAG) const { |
| Matthias Braun | f1caa28 | 2017-12-15 22:22:58 +0000 | [diff] [blame] | 3115 | const Function &CallerF = DAG.getMachineFunction().getFunction(); |
| 3116 | CallingConv::ID CallerCC = CallerF.getCallingConv(); |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 3117 | bool CCMatch = CallerCC == CalleeCC; |
| 3118 | |
| 3119 | // *************************************************************************** |
| 3120 | // Look for obvious safe cases to perform tail call optimization that do not |
| 3121 | // require ABI changes. |
| 3122 | // *************************************************************************** |
| 3123 | |
| 3124 | // 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] | 3125 | if (!isa<GlobalAddressSDNode>(Callee) && |
| 3126 | !isa<ExternalSymbolSDNode>(Callee)) { |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 3127 | return false; |
| 3128 | } |
| 3129 | |
| Krzysztof Parzyszek | 0ba9754 | 2016-08-19 15:02:18 +0000 | [diff] [blame] | 3130 | // Do not optimize if the calling conventions do not match and the conventions |
| 3131 | // used are not C or Fast. |
| 3132 | if (!CCMatch) { |
| 3133 | bool R = (CallerCC == CallingConv::C || CallerCC == CallingConv::Fast); |
| 3134 | bool E = (CalleeCC == CallingConv::C || CalleeCC == CallingConv::Fast); |
| 3135 | // If R & E, then ok. |
| 3136 | if (!R || !E) |
| 3137 | return false; |
| 3138 | } |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 3139 | |
| 3140 | // Do not tail call optimize vararg calls. |
| Krzysztof Parzyszek | cfbe6ba | 2018-02-13 15:35:07 +0000 | [diff] [blame] | 3141 | if (IsVarArg) |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 3142 | return false; |
| 3143 | |
| 3144 | // Also avoid tail call optimization if either caller or callee uses struct |
| 3145 | // return semantics. |
| Krzysztof Parzyszek | cfbe6ba | 2018-02-13 15:35:07 +0000 | [diff] [blame] | 3146 | if (IsCalleeStructRet || IsCallerStructRet) |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 3147 | return false; |
| 3148 | |
| 3149 | // In addition to the cases above, we also disable Tail Call Optimization if |
| 3150 | // the calling convention code that at least one outgoing argument needs to |
| 3151 | // go on the stack. We cannot check that here because at this point that |
| 3152 | // information is not available. |
| 3153 | return true; |
| 3154 | } |
| Colin LeMahieu | 025f860 | 2014-12-08 21:19:18 +0000 | [diff] [blame] | 3155 | |
| Krzysztof Parzyszek | 3e409e1 | 2016-08-02 18:34:31 +0000 | [diff] [blame] | 3156 | /// Returns the target specific optimal type for load and store operations as |
| 3157 | /// a result of memset, memcpy, and memmove lowering. |
| 3158 | /// |
| 3159 | /// If DstAlign is zero that means it's safe to destination alignment can |
| 3160 | /// satisfy any constraint. Similarly if SrcAlign is zero it means there isn't |
| 3161 | /// a need to check it against alignment requirement, probably because the |
| 3162 | /// source does not need to be loaded. If 'IsMemset' is true, that means it's |
| 3163 | /// expanding a memset. If 'ZeroMemset' is true, that means it's a memset of |
| 3164 | /// zero. 'MemcpyStrSrc' indicates whether the memcpy source is constant so it |
| 3165 | /// does not need to be loaded. It returns EVT::Other if the type should be |
| 3166 | /// determined using generic target-independent logic. |
| 3167 | EVT HexagonTargetLowering::getOptimalMemOpType(uint64_t Size, |
| 3168 | unsigned DstAlign, unsigned SrcAlign, bool IsMemset, bool ZeroMemset, |
| Sjoerd Meijer | 180f1ae | 2019-04-30 08:38:12 +0000 | [diff] [blame] | 3169 | bool MemcpyStrSrc, const AttributeList &FuncAttributes) const { |
| Krzysztof Parzyszek | 3e409e1 | 2016-08-02 18:34:31 +0000 | [diff] [blame] | 3170 | |
| 3171 | auto Aligned = [](unsigned GivenA, unsigned MinA) -> bool { |
| 3172 | return (GivenA % MinA) == 0; |
| 3173 | }; |
| 3174 | |
| 3175 | if (Size >= 8 && Aligned(DstAlign, 8) && (IsMemset || Aligned(SrcAlign, 8))) |
| 3176 | return MVT::i64; |
| 3177 | if (Size >= 4 && Aligned(DstAlign, 4) && (IsMemset || Aligned(SrcAlign, 4))) |
| 3178 | return MVT::i32; |
| 3179 | if (Size >= 2 && Aligned(DstAlign, 2) && (IsMemset || Aligned(SrcAlign, 2))) |
| 3180 | return MVT::i16; |
| 3181 | |
| 3182 | return MVT::Other; |
| 3183 | } |
| 3184 | |
| Simon Pilgrim | 4e0648a | 2019-06-12 17:14:03 +0000 | [diff] [blame] | 3185 | bool HexagonTargetLowering::allowsMisalignedMemoryAccesses( |
| 3186 | EVT VT, unsigned AS, unsigned Align, MachineMemOperand::Flags Flags, |
| 3187 | bool *Fast) const { |
| Krzysztof Parzyszek | 2d65ea7 | 2016-03-28 15:43:03 +0000 | [diff] [blame] | 3188 | if (Fast) |
| 3189 | *Fast = false; |
| Krzysztof Parzyszek | cfbe6ba | 2018-02-13 15:35:07 +0000 | [diff] [blame] | 3190 | return Subtarget.isHVXVectorType(VT.getSimpleVT()); |
| Krzysztof Parzyszek | 2d65ea7 | 2016-03-28 15:43:03 +0000 | [diff] [blame] | 3191 | } |
| 3192 | |
| Krzysztof Parzyszek | 08ff888 | 2015-11-26 18:38:27 +0000 | [diff] [blame] | 3193 | std::pair<const TargetRegisterClass*, uint8_t> |
| 3194 | HexagonTargetLowering::findRepresentativeClass(const TargetRegisterInfo *TRI, |
| 3195 | MVT VT) const { |
| Krzysztof Parzyszek | cfbe6ba | 2018-02-13 15:35:07 +0000 | [diff] [blame] | 3196 | if (Subtarget.isHVXVectorType(VT, true)) { |
| 3197 | unsigned BitWidth = VT.getSizeInBits(); |
| 3198 | unsigned VecWidth = Subtarget.getVectorLength() * 8; |
| Krzysztof Parzyszek | 08ff888 | 2015-11-26 18:38:27 +0000 | [diff] [blame] | 3199 | |
| Krzysztof Parzyszek | cfbe6ba | 2018-02-13 15:35:07 +0000 | [diff] [blame] | 3200 | if (VT.getVectorElementType() == MVT::i1) |
| 3201 | return std::make_pair(&Hexagon::HvxQRRegClass, 1); |
| 3202 | if (BitWidth == VecWidth) |
| 3203 | return std::make_pair(&Hexagon::HvxVRRegClass, 1); |
| 3204 | assert(BitWidth == 2 * VecWidth); |
| 3205 | return std::make_pair(&Hexagon::HvxWRRegClass, 1); |
| Krzysztof Parzyszek | 08ff888 | 2015-11-26 18:38:27 +0000 | [diff] [blame] | 3206 | } |
| Krzysztof Parzyszek | cfbe6ba | 2018-02-13 15:35:07 +0000 | [diff] [blame] | 3207 | |
| 3208 | return TargetLowering::findRepresentativeClass(TRI, VT); |
| Krzysztof Parzyszek | 08ff888 | 2015-11-26 18:38:27 +0000 | [diff] [blame] | 3209 | } |
| 3210 | |
| Krzysztof Parzyszek | f070544 | 2018-11-02 14:17:47 +0000 | [diff] [blame] | 3211 | bool HexagonTargetLowering::shouldReduceLoadWidth(SDNode *Load, |
| 3212 | ISD::LoadExtType ExtTy, EVT NewVT) const { |
| Sanjay Patel | 0a51559 | 2018-11-10 20:05:31 +0000 | [diff] [blame] | 3213 | // TODO: This may be worth removing. Check regression tests for diffs. |
| 3214 | if (!TargetLoweringBase::shouldReduceLoadWidth(Load, ExtTy, NewVT)) |
| 3215 | return false; |
| 3216 | |
| Krzysztof Parzyszek | f070544 | 2018-11-02 14:17:47 +0000 | [diff] [blame] | 3217 | auto *L = cast<LoadSDNode>(Load); |
| 3218 | std::pair<SDValue,int> BO = getBaseAndOffset(L->getBasePtr()); |
| 3219 | // Small-data object, do not shrink. |
| 3220 | if (BO.first.getOpcode() == HexagonISD::CONST32_GP) |
| 3221 | return false; |
| 3222 | if (GlobalAddressSDNode *GA = dyn_cast<GlobalAddressSDNode>(BO.first)) { |
| 3223 | auto &HTM = static_cast<const HexagonTargetMachine&>(getTargetMachine()); |
| 3224 | const auto *GO = dyn_cast_or_null<const GlobalObject>(GA->getGlobal()); |
| 3225 | return !GO || !HTM.getObjFileLowering()->isGlobalInSmallSection(GO, HTM); |
| 3226 | } |
| 3227 | return true; |
| 3228 | } |
| 3229 | |
| Krzysztof Parzyszek | feaf7b8 | 2015-07-09 14:51:21 +0000 | [diff] [blame] | 3230 | Value *HexagonTargetLowering::emitLoadLinked(IRBuilder<> &Builder, Value *Addr, |
| 3231 | AtomicOrdering Ord) const { |
| 3232 | BasicBlock *BB = Builder.GetInsertBlock(); |
| 3233 | Module *M = BB->getParent()->getParent(); |
| Matt Arsenault | 3950833 | 2019-01-22 18:18:02 +0000 | [diff] [blame] | 3234 | auto PT = cast<PointerType>(Addr->getType()); |
| 3235 | Type *Ty = PT->getElementType(); |
| Krzysztof Parzyszek | feaf7b8 | 2015-07-09 14:51:21 +0000 | [diff] [blame] | 3236 | unsigned SZ = Ty->getPrimitiveSizeInBits(); |
| 3237 | assert((SZ == 32 || SZ == 64) && "Only 32/64-bit atomic loads supported"); |
| 3238 | Intrinsic::ID IntID = (SZ == 32) ? Intrinsic::hexagon_L2_loadw_locked |
| 3239 | : Intrinsic::hexagon_L4_loadd_locked; |
| James Y Knight | 7976eb5 | 2019-02-01 20:43:25 +0000 | [diff] [blame] | 3240 | Function *Fn = Intrinsic::getDeclaration(M, IntID); |
| Matt Arsenault | 3950833 | 2019-01-22 18:18:02 +0000 | [diff] [blame] | 3241 | |
| 3242 | PointerType *NewPtrTy |
| 3243 | = Builder.getIntNTy(SZ)->getPointerTo(PT->getAddressSpace()); |
| 3244 | Addr = Builder.CreateBitCast(Addr, NewPtrTy); |
| 3245 | |
| Matt Arsenault | 3950833 | 2019-01-22 18:18:02 +0000 | [diff] [blame] | 3246 | Value *Call = Builder.CreateCall(Fn, Addr, "larx"); |
| 3247 | |
| 3248 | return Builder.CreateBitCast(Call, Ty); |
| Krzysztof Parzyszek | feaf7b8 | 2015-07-09 14:51:21 +0000 | [diff] [blame] | 3249 | } |
| 3250 | |
| 3251 | /// Perform a store-conditional operation to Addr. Return the status of the |
| 3252 | /// store. This should be 0 if the store succeeded, non-zero otherwise. |
| 3253 | Value *HexagonTargetLowering::emitStoreConditional(IRBuilder<> &Builder, |
| 3254 | Value *Val, Value *Addr, AtomicOrdering Ord) const { |
| 3255 | BasicBlock *BB = Builder.GetInsertBlock(); |
| 3256 | Module *M = BB->getParent()->getParent(); |
| 3257 | Type *Ty = Val->getType(); |
| 3258 | unsigned SZ = Ty->getPrimitiveSizeInBits(); |
| Matt Arsenault | 3950833 | 2019-01-22 18:18:02 +0000 | [diff] [blame] | 3259 | |
| 3260 | Type *CastTy = Builder.getIntNTy(SZ); |
| Krzysztof Parzyszek | feaf7b8 | 2015-07-09 14:51:21 +0000 | [diff] [blame] | 3261 | assert((SZ == 32 || SZ == 64) && "Only 32/64-bit atomic stores supported"); |
| 3262 | Intrinsic::ID IntID = (SZ == 32) ? Intrinsic::hexagon_S2_storew_locked |
| 3263 | : Intrinsic::hexagon_S4_stored_locked; |
| James Y Knight | 7976eb5 | 2019-02-01 20:43:25 +0000 | [diff] [blame] | 3264 | Function *Fn = Intrinsic::getDeclaration(M, IntID); |
| Matt Arsenault | 3950833 | 2019-01-22 18:18:02 +0000 | [diff] [blame] | 3265 | |
| 3266 | unsigned AS = Addr->getType()->getPointerAddressSpace(); |
| 3267 | Addr = Builder.CreateBitCast(Addr, CastTy->getPointerTo(AS)); |
| 3268 | Val = Builder.CreateBitCast(Val, CastTy); |
| 3269 | |
| Krzysztof Parzyszek | feaf7b8 | 2015-07-09 14:51:21 +0000 | [diff] [blame] | 3270 | Value *Call = Builder.CreateCall(Fn, {Addr, Val}, "stcx"); |
| 3271 | Value *Cmp = Builder.CreateICmpEQ(Call, Builder.getInt32(0), ""); |
| 3272 | Value *Ext = Builder.CreateZExt(Cmp, Type::getInt32Ty(M->getContext())); |
| 3273 | return Ext; |
| 3274 | } |
| 3275 | |
| Ahmed Bougacha | 5246867 | 2015-09-11 17:08:28 +0000 | [diff] [blame] | 3276 | TargetLowering::AtomicExpansionKind |
| 3277 | HexagonTargetLowering::shouldExpandAtomicLoadInIR(LoadInst *LI) const { |
| Krzysztof Parzyszek | feaf7b8 | 2015-07-09 14:51:21 +0000 | [diff] [blame] | 3278 | // Do not expand loads and stores that don't exceed 64 bits. |
| Ahmed Bougacha | 5246867 | 2015-09-11 17:08:28 +0000 | [diff] [blame] | 3279 | return LI->getType()->getPrimitiveSizeInBits() > 64 |
| Tim Northover | f520eff | 2015-12-02 18:12:57 +0000 | [diff] [blame] | 3280 | ? AtomicExpansionKind::LLOnly |
| Ahmed Bougacha | 5246867 | 2015-09-11 17:08:28 +0000 | [diff] [blame] | 3281 | : AtomicExpansionKind::None; |
| Krzysztof Parzyszek | feaf7b8 | 2015-07-09 14:51:21 +0000 | [diff] [blame] | 3282 | } |
| 3283 | |
| 3284 | bool HexagonTargetLowering::shouldExpandAtomicStoreInIR(StoreInst *SI) const { |
| 3285 | // Do not expand loads and stores that don't exceed 64 bits. |
| 3286 | return SI->getValueOperand()->getType()->getPrimitiveSizeInBits() > 64; |
| 3287 | } |
| Krzysztof Parzyszek | f228c95 | 2016-06-22 16:07:10 +0000 | [diff] [blame] | 3288 | |
| Alex Bradbury | 79518b0 | 2018-09-19 14:51:42 +0000 | [diff] [blame] | 3289 | TargetLowering::AtomicExpansionKind |
| 3290 | HexagonTargetLowering::shouldExpandAtomicCmpXchgInIR( |
| 3291 | AtomicCmpXchgInst *AI) const { |
| Krzysztof Parzyszek | f228c95 | 2016-06-22 16:07:10 +0000 | [diff] [blame] | 3292 | const DataLayout &DL = AI->getModule()->getDataLayout(); |
| 3293 | unsigned Size = DL.getTypeStoreSize(AI->getCompareOperand()->getType()); |
| Alex Bradbury | 79518b0 | 2018-09-19 14:51:42 +0000 | [diff] [blame] | 3294 | if (Size >= 4 && Size <= 8) |
| 3295 | return AtomicExpansionKind::LLSC; |
| 3296 | return AtomicExpansionKind::None; |
| Krzysztof Parzyszek | f228c95 | 2016-06-22 16:07:10 +0000 | [diff] [blame] | 3297 | } |