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