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