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