blob: be20cd619969ea226a624cbd246ea954417cb919 [file] [log] [blame]
Ulrich Weigand5f613df2013-05-06 16:15:19 +00001//===-- SystemZISelLowering.h - SystemZ DAG lowering interface --*- C++ -*-===//
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 defines the interfaces that SystemZ uses to lower LLVM code into a
11// selection DAG.
12//
13//===----------------------------------------------------------------------===//
14
Benjamin Kramera7c40ef2014-08-13 16:26:38 +000015#ifndef LLVM_LIB_TARGET_SYSTEMZ_SYSTEMZISELLOWERING_H
16#define LLVM_LIB_TARGET_SYSTEMZ_SYSTEMZISELLOWERING_H
Ulrich Weigand5f613df2013-05-06 16:15:19 +000017
18#include "SystemZ.h"
Richard Sandiford0fb90ab2013-05-28 10:41:11 +000019#include "llvm/CodeGen/MachineBasicBlock.h"
Ulrich Weigand5f613df2013-05-06 16:15:19 +000020#include "llvm/CodeGen/SelectionDAG.h"
David Blaikieb3bde2e2017-11-17 01:07:10 +000021#include "llvm/CodeGen/TargetLowering.h"
Ulrich Weigand5f613df2013-05-06 16:15:19 +000022
23namespace llvm {
24namespace SystemZISD {
Matthias Braund04893f2015-05-07 21:33:59 +000025enum NodeType : unsigned {
Richard Sandifordc2312692014-03-06 10:38:30 +000026 FIRST_NUMBER = ISD::BUILTIN_OP_END,
Ulrich Weigand5f613df2013-05-06 16:15:19 +000027
Richard Sandifordc2312692014-03-06 10:38:30 +000028 // Return with a flag operand. Operand 0 is the chain operand.
29 RET_FLAG,
Ulrich Weigand5f613df2013-05-06 16:15:19 +000030
Richard Sandifordc2312692014-03-06 10:38:30 +000031 // Calls a function. Operand 0 is the chain operand and operand 1
32 // is the target address. The arguments start at operand 2.
33 // There is an optional glue operand at the end.
34 CALL,
35 SIBCALL,
Ulrich Weigand5f613df2013-05-06 16:15:19 +000036
Ulrich Weigand7db69182015-02-18 09:13:27 +000037 // TLS calls. Like regular calls, except operand 1 is the TLS symbol.
38 // (The call target is implicitly __tls_get_offset.)
39 TLS_GDCALL,
40 TLS_LDCALL,
41
Richard Sandifordc2312692014-03-06 10:38:30 +000042 // Wraps a TargetGlobalAddress that should be loaded using PC-relative
43 // accesses (LARL). Operand 0 is the address.
44 PCREL_WRAPPER,
Ulrich Weigand5f613df2013-05-06 16:15:19 +000045
Richard Sandifordc2312692014-03-06 10:38:30 +000046 // Used in cases where an offset is applied to a TargetGlobalAddress.
47 // Operand 0 is the full TargetGlobalAddress and operand 1 is a
48 // PCREL_WRAPPER for an anchor point. This is used so that we can
49 // cheaply refer to either the full address or the anchor point
50 // as a register base.
51 PCREL_OFFSET,
Richard Sandiford54b36912013-09-27 15:14:04 +000052
Richard Sandifordc2312692014-03-06 10:38:30 +000053 // Integer absolute.
54 IABS,
Richard Sandiford57485472013-12-13 15:35:00 +000055
Richard Sandifordc2312692014-03-06 10:38:30 +000056 // Integer comparisons. There are three operands: the two values
57 // to compare, and an integer of type SystemZICMP.
58 ICMP,
Ulrich Weigand5f613df2013-05-06 16:15:19 +000059
Richard Sandifordc2312692014-03-06 10:38:30 +000060 // Floating-point comparisons. The two operands are the values to compare.
61 FCMP,
Ulrich Weigand5f613df2013-05-06 16:15:19 +000062
Richard Sandifordc2312692014-03-06 10:38:30 +000063 // Test under mask. The first operand is ANDed with the second operand
64 // and the condition codes are set on the result. The third operand is
65 // a boolean that is true if the condition codes need to distinguish
66 // between CCMASK_TM_MIXED_MSB_0 and CCMASK_TM_MIXED_MSB_1 (which the
67 // register forms do but the memory forms don't).
68 TM,
Richard Sandiford35b9be22013-08-28 10:31:43 +000069
Richard Sandifordc2312692014-03-06 10:38:30 +000070 // Branches if a condition is true. Operand 0 is the chain operand;
71 // operand 1 is the 4-bit condition-code mask, with bit N in
72 // big-endian order meaning "branch if CC=N"; operand 2 is the
73 // target block and operand 3 is the flag operand.
74 BR_CCMASK,
Ulrich Weigand5f613df2013-05-06 16:15:19 +000075
Richard Sandifordc2312692014-03-06 10:38:30 +000076 // Selects between operand 0 and operand 1. Operand 2 is the
77 // mask of condition-code values for which operand 0 should be
78 // chosen over operand 1; it has the same form as BR_CCMASK.
79 // Operand 3 is the flag operand.
80 SELECT_CCMASK,
Ulrich Weigand5f613df2013-05-06 16:15:19 +000081
Richard Sandifordc2312692014-03-06 10:38:30 +000082 // Evaluates to the gap between the stack pointer and the
83 // base of the dynamically-allocatable area.
84 ADJDYNALLOC,
Ulrich Weigand5f613df2013-05-06 16:15:19 +000085
Ulrich Weigandb4012182015-03-31 12:56:33 +000086 // Count number of bits set in operand 0 per byte.
87 POPCNT,
88
Ulrich Weigand43579cf2017-07-05 13:17:31 +000089 // Wrappers around the ISD opcodes of the same name. The output is GR128.
90 // Input operands may be GR64 or GR32, depending on the instruction.
Ulrich Weigand2b3482f2017-07-17 17:41:11 +000091 SMUL_LOHI,
Ulrich Weigand43579cf2017-07-05 13:17:31 +000092 UMUL_LOHI,
93 SDIVREM,
94 UDIVREM,
Ulrich Weigand5f613df2013-05-06 16:15:19 +000095
Richard Sandifordc2312692014-03-06 10:38:30 +000096 // Use a series of MVCs to copy bytes from one memory location to another.
97 // The operands are:
98 // - the target address
99 // - the source address
100 // - the constant length
101 //
102 // This isn't a memory opcode because we'd need to attach two
103 // MachineMemOperands rather than one.
104 MVC,
Richard Sandifordd131ff82013-07-08 09:35:23 +0000105
Richard Sandifordc2312692014-03-06 10:38:30 +0000106 // Like MVC, but implemented as a loop that handles X*256 bytes
107 // followed by straight-line code to handle the rest (if any).
108 // The value of X is passed as an additional operand.
109 MVC_LOOP,
Richard Sandiford5e318f02013-08-27 09:54:29 +0000110
Richard Sandifordc2312692014-03-06 10:38:30 +0000111 // Similar to MVC and MVC_LOOP, but for logic operations (AND, OR, XOR).
112 NC,
113 NC_LOOP,
114 OC,
115 OC_LOOP,
116 XC,
117 XC_LOOP,
Richard Sandiford178273a2013-09-05 10:36:45 +0000118
Richard Sandifordc2312692014-03-06 10:38:30 +0000119 // Use CLC to compare two blocks of memory, with the same comments
120 // as for MVC and MVC_LOOP.
121 CLC,
122 CLC_LOOP,
Richard Sandiford761703a2013-08-12 10:17:33 +0000123
Richard Sandifordc2312692014-03-06 10:38:30 +0000124 // Use an MVST-based sequence to implement stpcpy().
125 STPCPY,
Richard Sandifordbb83a502013-08-16 11:29:37 +0000126
Richard Sandifordc2312692014-03-06 10:38:30 +0000127 // Use a CLST-based sequence to implement strcmp(). The two input operands
128 // are the addresses of the strings to compare.
129 STRCMP,
Richard Sandifordca232712013-08-16 11:21:54 +0000130
Richard Sandifordc2312692014-03-06 10:38:30 +0000131 // Use an SRST-based sequence to search a block of memory. The first
132 // operand is the end address, the second is the start, and the third
133 // is the character to search for. CC is set to 1 on success and 2
134 // on failure.
135 SEARCH_STRING,
Richard Sandiford0dec06a2013-08-16 11:41:43 +0000136
Richard Sandifordc2312692014-03-06 10:38:30 +0000137 // Store the CC value in bits 29 and 28 of an integer.
138 IPM,
Richard Sandiford564681c2013-08-12 10:28:10 +0000139
Ulrich Weiganda9ac6d62016-04-04 12:45:44 +0000140 // Compiler barrier only; generate a no-op.
141 MEMBARRIER,
142
Ulrich Weigand57c85f52015-04-01 12:51:43 +0000143 // Transaction begin. The first operand is the chain, the second
144 // the TDB pointer, and the third the immediate control field.
145 // Returns chain and glue.
146 TBEGIN,
147 TBEGIN_NOFLOAT,
148
149 // Transaction end. Just the chain operand. Returns chain and glue.
150 TEND,
151
Ulrich Weigandce4c1092015-05-05 19:25:42 +0000152 // Create a vector constant by filling byte N of the result with bit
153 // 15-N of the single operand.
154 BYTE_MASK,
155
156 // Create a vector constant by replicating an element-sized RISBG-style mask.
157 // The first operand specifies the starting set bit and the second operand
158 // specifies the ending set bit. Both operands count from the MSB of the
159 // element.
160 ROTATE_MASK,
161
162 // Replicate a GPR scalar value into all elements of a vector.
163 REPLICATE,
164
165 // Create a vector from two i64 GPRs.
166 JOIN_DWORDS,
167
168 // Replicate one element of a vector into all elements. The first operand
169 // is the vector and the second is the index of the element to replicate.
170 SPLAT,
171
172 // Interleave elements from the high half of operand 0 and the high half
173 // of operand 1.
174 MERGE_HIGH,
175
176 // Likewise for the low halves.
177 MERGE_LOW,
178
179 // Concatenate the vectors in the first two operands, shift them left
180 // by the third operand, and take the first half of the result.
181 SHL_DOUBLE,
182
183 // Take one element of the first v2i64 operand and the one element of
184 // the second v2i64 operand and concatenate them to form a v2i64 result.
185 // The third operand is a 4-bit value of the form 0A0B, where A and B
186 // are the element selectors for the first operand and second operands
187 // respectively.
188 PERMUTE_DWORDS,
189
190 // Perform a general vector permute on vector operands 0 and 1.
191 // Each byte of operand 2 controls the corresponding byte of the result,
192 // in the same way as a byte-level VECTOR_SHUFFLE mask.
193 PERMUTE,
194
195 // Pack vector operands 0 and 1 into a single vector with half-sized elements.
196 PACK,
197
Ulrich Weigandc1708b22015-05-05 19:31:09 +0000198 // Likewise, but saturate the result and set CC. PACKS_CC does signed
199 // saturation and PACKLS_CC does unsigned saturation.
200 PACKS_CC,
201 PACKLS_CC,
202
Ulrich Weigandcd2a1b52015-05-05 19:29:21 +0000203 // Unpack the first half of vector operand 0 into double-sized elements.
204 // UNPACK_HIGH sign-extends and UNPACKL_HIGH zero-extends.
205 UNPACK_HIGH,
206 UNPACKL_HIGH,
207
208 // Likewise for the second half.
209 UNPACK_LOW,
210 UNPACKL_LOW,
211
Ulrich Weigandce4c1092015-05-05 19:25:42 +0000212 // Shift each element of vector operand 0 by the number of bits specified
213 // by scalar operand 1.
214 VSHL_BY_SCALAR,
215 VSRL_BY_SCALAR,
216 VSRA_BY_SCALAR,
217
218 // For each element of the output type, sum across all sub-elements of
219 // operand 0 belonging to the corresponding element, and add in the
220 // rightmost sub-element of the corresponding element of operand 1.
221 VSUM,
222
223 // Compare integer vector operands 0 and 1 to produce the usual 0/-1
224 // vector result. VICMPE is for equality, VICMPH for "signed greater than"
225 // and VICMPHL for "unsigned greater than".
226 VICMPE,
227 VICMPH,
228 VICMPHL,
229
Ulrich Weigandc1708b22015-05-05 19:31:09 +0000230 // Likewise, but also set the condition codes on the result.
231 VICMPES,
232 VICMPHS,
233 VICMPHLS,
234
Ulrich Weigandcd808232015-05-05 19:26:48 +0000235 // Compare floating-point vector operands 0 and 1 to preoduce the usual 0/-1
236 // vector result. VFCMPE is for "ordered and equal", VFCMPH for "ordered and
237 // greater than" and VFCMPHE for "ordered and greater than or equal to".
238 VFCMPE,
239 VFCMPH,
240 VFCMPHE,
241
Ulrich Weigandc1708b22015-05-05 19:31:09 +0000242 // Likewise, but also set the condition codes on the result.
243 VFCMPES,
244 VFCMPHS,
245 VFCMPHES,
246
247 // Test floating-point data class for vectors.
248 VFTCI,
249
Ulrich Weigand80b3af72015-05-05 19:27:45 +0000250 // Extend the even f32 elements of vector operand 0 to produce a vector
251 // of f64 elements.
252 VEXTEND,
253
254 // Round the f64 elements of vector operand 0 to f32s and store them in the
255 // even elements of the result.
256 VROUND,
257
Ulrich Weigandc1708b22015-05-05 19:31:09 +0000258 // AND the two vector operands together and set CC based on the result.
259 VTM,
260
261 // String operations that set CC as a side-effect.
262 VFAE_CC,
263 VFAEZ_CC,
264 VFEE_CC,
265 VFEEZ_CC,
266 VFENE_CC,
267 VFENEZ_CC,
268 VISTR_CC,
269 VSTRC_CC,
270 VSTRCZ_CC,
271
Marcin Koscielnicki32e87342016-07-02 02:20:40 +0000272 // Test Data Class.
273 //
274 // Operand 0: the value to test
275 // Operand 1: the bit mask
276 TDC,
277
Richard Sandifordc2312692014-03-06 10:38:30 +0000278 // Wrappers around the inner loop of an 8- or 16-bit ATOMIC_SWAP or
279 // ATOMIC_LOAD_<op>.
280 //
281 // Operand 0: the address of the containing 32-bit-aligned field
282 // Operand 1: the second operand of <op>, in the high bits of an i32
283 // for everything except ATOMIC_SWAPW
284 // Operand 2: how many bits to rotate the i32 left to bring the first
285 // operand into the high bits
286 // Operand 3: the negative of operand 2, for rotating the other way
287 // Operand 4: the width of the field in bits (8 or 16)
288 ATOMIC_SWAPW = ISD::FIRST_TARGET_MEMORY_OPCODE,
289 ATOMIC_LOADW_ADD,
290 ATOMIC_LOADW_SUB,
291 ATOMIC_LOADW_AND,
292 ATOMIC_LOADW_OR,
293 ATOMIC_LOADW_XOR,
294 ATOMIC_LOADW_NAND,
295 ATOMIC_LOADW_MIN,
296 ATOMIC_LOADW_MAX,
297 ATOMIC_LOADW_UMIN,
298 ATOMIC_LOADW_UMAX,
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000299
Richard Sandifordc2312692014-03-06 10:38:30 +0000300 // A wrapper around the inner loop of an ATOMIC_CMP_SWAP.
301 //
302 // Operand 0: the address of the containing 32-bit-aligned field
303 // Operand 1: the compare value, in the low bits of an i32
304 // Operand 2: the swap value, in the low bits of an i32
305 // Operand 3: how many bits to rotate the i32 left to bring the first
306 // operand into the high bits
307 // Operand 4: the negative of operand 2, for rotating the other way
308 // Operand 5: the width of the field in bits (8 or 16)
309 ATOMIC_CMP_SWAPW,
Richard Sandiford03481332013-08-23 11:36:42 +0000310
Ulrich Weigand0f1de042017-09-28 16:22:54 +0000311 // Atomic compare-and-swap returning glue (condition code).
312 // Val, OUTCHAIN, glue = ATOMIC_CMP_SWAP(INCHAIN, ptr, cmp, swap)
313 ATOMIC_CMP_SWAP,
314
Ulrich Weiganda11f63a2017-08-04 18:57:58 +0000315 // 128-bit atomic load.
316 // Val, OUTCHAIN = ATOMIC_LOAD_128(INCHAIN, ptr)
317 ATOMIC_LOAD_128,
318
319 // 128-bit atomic store.
320 // OUTCHAIN = ATOMIC_STORE_128(INCHAIN, val, ptr)
321 ATOMIC_STORE_128,
322
323 // 128-bit atomic compare-and-swap.
Ulrich Weigand0f1de042017-09-28 16:22:54 +0000324 // Val, OUTCHAIN, glue = ATOMIC_CMP_SWAP(INCHAIN, ptr, cmp, swap)
Ulrich Weiganda11f63a2017-08-04 18:57:58 +0000325 ATOMIC_CMP_SWAP_128,
326
Bryan Chan28b759c2016-05-16 20:32:22 +0000327 // Byte swapping load.
328 //
329 // Operand 0: the address to load from
330 // Operand 1: the type of load (i16, i32, i64)
331 LRV,
332
333 // Byte swapping store.
334 //
335 // Operand 0: the value to store
336 // Operand 1: the address to store to
337 // Operand 2: the type of store (i16, i32, i64)
338 STRV,
339
Richard Sandifordc2312692014-03-06 10:38:30 +0000340 // Prefetch from the second operand using the 4-bit control code in
341 // the first operand. The code is 1 for a load prefetch and 2 for
342 // a store prefetch.
343 PREFETCH
344};
Richard Sandiford54b36912013-09-27 15:14:04 +0000345
Richard Sandifordc2312692014-03-06 10:38:30 +0000346// Return true if OPCODE is some kind of PC-relative address.
347inline bool isPCREL(unsigned Opcode) {
348 return Opcode == PCREL_WRAPPER || Opcode == PCREL_OFFSET;
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000349}
Richard Sandifordc2312692014-03-06 10:38:30 +0000350} // end namespace SystemZISD
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000351
Richard Sandiford5bc670b2013-09-06 11:51:39 +0000352namespace SystemZICMP {
Richard Sandifordc2312692014-03-06 10:38:30 +0000353// Describes whether an integer comparison needs to be signed or unsigned,
354// or whether either type is OK.
355enum {
356 Any,
357 UnsignedOnly,
358 SignedOnly
359};
360} // end namespace SystemZICMP
Richard Sandiford5bc670b2013-09-06 11:51:39 +0000361
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000362class SystemZSubtarget;
363class SystemZTargetMachine;
364
365class SystemZTargetLowering : public TargetLowering {
366public:
Eric Christophera6734172015-01-31 00:06:45 +0000367 explicit SystemZTargetLowering(const TargetMachine &TM,
368 const SystemZSubtarget &STI);
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000369
370 // Override TargetLowering.
Mehdi Aminieaabc512015-07-09 15:12:23 +0000371 MVT getScalarShiftAmountTy(const DataLayout &, EVT) const override {
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000372 return MVT::i32;
373 }
Mehdi Amini44ede332015-07-09 02:09:04 +0000374 MVT getVectorIdxTy(const DataLayout &DL) const override {
Ulrich Weigandce4c1092015-05-05 19:25:42 +0000375 // Only the lower 12 bits of an element index are used, so we don't
376 // want to clobber the upper 32 bits of a GPR unnecessarily.
377 return MVT::i32;
378 }
Ulrich Weigandcd2a1b52015-05-05 19:29:21 +0000379 TargetLoweringBase::LegalizeTypeAction getPreferredVectorAction(EVT VT)
380 const override {
381 // Widen subvectors to the full width rather than promoting integer
382 // elements. This is better because:
383 //
384 // (a) it means that we can handle the ABI for passing and returning
385 // sub-128 vectors without having to handle them as legal types.
386 //
387 // (b) we don't have instructions to extend on load and truncate on store,
388 // so promoting the integers is less efficient.
389 //
390 // (c) there are no multiplication instructions for the widest integer
391 // type (v2i64).
Sanjay Patel1ed771f2016-09-14 16:37:15 +0000392 if (VT.getScalarSizeInBits() % 8 == 0)
Ulrich Weigandcd2a1b52015-05-05 19:29:21 +0000393 return TypeWidenVector;
394 return TargetLoweringBase::getPreferredVectorAction(VT);
395 }
Mehdi Amini44ede332015-07-09 02:09:04 +0000396 EVT getSetCCResultType(const DataLayout &DL, LLVMContext &,
397 EVT) const override;
Richard Sandifordb4d67b52014-03-06 12:03:36 +0000398 bool isFMAFasterThanFMulAndFAdd(EVT VT) const override;
399 bool isFPImmLegal(const APFloat &Imm, EVT VT) const override;
Ulrich Weigand1f6666a2015-03-31 12:52:27 +0000400 bool isLegalICmpImmediate(int64_t Imm) const override;
401 bool isLegalAddImmediate(int64_t Imm) const override;
Mehdi Amini0cdec1e2015-07-09 02:09:40 +0000402 bool isLegalAddressingMode(const DataLayout &DL, const AddrMode &AM, Type *Ty,
Jonas Paulsson024e3192017-07-21 11:59:37 +0000403 unsigned AS,
404 Instruction *I = nullptr) const override;
Matt Arsenault6f2a5262014-07-27 17:46:40 +0000405 bool allowsMisalignedMemoryAccesses(EVT VT, unsigned AS,
406 unsigned Align,
407 bool *Fast) const override;
Richard Sandifordb4d67b52014-03-06 12:03:36 +0000408 bool isTruncateFree(Type *, Type *) const override;
409 bool isTruncateFree(EVT, EVT) const override;
410 const char *getTargetNodeName(unsigned Opcode) const override;
411 std::pair<unsigned, const TargetRegisterClass *>
Eric Christopher11e4df72015-02-26 22:38:43 +0000412 getRegForInlineAsmConstraint(const TargetRegisterInfo *TRI,
Benjamin Kramer9bfb6272015-07-05 19:29:18 +0000413 StringRef Constraint, MVT VT) const override;
Richard Sandifordb4d67b52014-03-06 12:03:36 +0000414 TargetLowering::ConstraintType
Benjamin Kramer9bfb6272015-07-05 19:29:18 +0000415 getConstraintType(StringRef Constraint) const override;
Richard Sandifordb4d67b52014-03-06 12:03:36 +0000416 TargetLowering::ConstraintWeight
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000417 getSingleConstraintMatchWeight(AsmOperandInfo &info,
Craig Topper73156022014-03-02 09:09:27 +0000418 const char *constraint) const override;
Richard Sandifordb4d67b52014-03-06 12:03:36 +0000419 void LowerAsmOperandForConstraint(SDValue Op,
420 std::string &Constraint,
421 std::vector<SDValue> &Ops,
422 SelectionDAG &DAG) const override;
Daniel Sandersbf5b80f2015-03-16 13:13:41 +0000423
Benjamin Kramer9bfb6272015-07-05 19:29:18 +0000424 unsigned getInlineAsmMemConstraint(StringRef ConstraintCode) const override {
Daniel Sanders2eeace22015-03-17 16:16:14 +0000425 if (ConstraintCode.size() == 1) {
426 switch(ConstraintCode[0]) {
427 default:
428 break;
Ulrich Weigandd39e9dc2017-11-09 16:31:57 +0000429 case 'o':
430 return InlineAsm::Constraint_o;
Daniel Sanders2eeace22015-03-17 16:16:14 +0000431 case 'Q':
432 return InlineAsm::Constraint_Q;
433 case 'R':
434 return InlineAsm::Constraint_R;
435 case 'S':
436 return InlineAsm::Constraint_S;
437 case 'T':
438 return InlineAsm::Constraint_T;
439 }
440 }
441 return TargetLowering::getInlineAsmMemConstraint(ConstraintCode);
Daniel Sandersbf5b80f2015-03-16 13:13:41 +0000442 }
443
Joseph Tremouletf748c892015-11-07 01:11:31 +0000444 /// If a physical register, this returns the register that receives the
445 /// exception address on entry to an EH pad.
446 unsigned
447 getExceptionPointerRegister(const Constant *PersonalityFn) const override {
448 return SystemZ::R6D;
449 }
450
451 /// If a physical register, this returns the register that receives the
452 /// exception typeid on entry to a landing pad.
453 unsigned
454 getExceptionSelectorRegister(const Constant *PersonalityFn) const override {
455 return SystemZ::R7D;
456 }
457
Marcin Koscielnickiaef3b5b2016-04-24 13:57:49 +0000458 /// Override to support customized stack guard loading.
459 bool useLoadStackGuardNode() const override {
460 return true;
461 }
462 void insertSSPDeclarations(Module &M) const override {
463 }
464
Duncan P. N. Exon Smithe4f5e4f2016-06-30 22:52:52 +0000465 MachineBasicBlock *
466 EmitInstrWithCustomInserter(MachineInstr &MI,
467 MachineBasicBlock *BB) const override;
Richard Sandifordb4d67b52014-03-06 12:03:36 +0000468 SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const override;
Ulrich Weiganda11f63a2017-08-04 18:57:58 +0000469 void LowerOperationWrapper(SDNode *N, SmallVectorImpl<SDValue> &Results,
470 SelectionDAG &DAG) const override;
471 void ReplaceNodeResults(SDNode *N, SmallVectorImpl<SDValue>&Results,
472 SelectionDAG &DAG) const override;
Richard Sandifordb4d67b52014-03-06 12:03:36 +0000473 bool allowTruncateForTailCall(Type *, Type *) const override;
Matt Arsenault31380752017-04-18 21:16:46 +0000474 bool mayBeEmittedAsTailCall(const CallInst *CI) const override;
Richard Sandifordb4d67b52014-03-06 12:03:36 +0000475 SDValue LowerFormalArguments(SDValue Chain, CallingConv::ID CallConv,
476 bool isVarArg,
477 const SmallVectorImpl<ISD::InputArg> &Ins,
Benjamin Kramerbdc49562016-06-12 15:39:02 +0000478 const SDLoc &DL, SelectionDAG &DAG,
Richard Sandifordb4d67b52014-03-06 12:03:36 +0000479 SmallVectorImpl<SDValue> &InVals) const override;
480 SDValue LowerCall(CallLoweringInfo &CLI,
481 SmallVectorImpl<SDValue> &InVals) const override;
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000482
Ulrich Weiganda887f062015-08-13 13:37:06 +0000483 bool CanLowerReturn(CallingConv::ID CallConv, MachineFunction &MF,
484 bool isVarArg,
485 const SmallVectorImpl<ISD::OutputArg> &Outs,
486 LLVMContext &Context) const override;
Richard Sandifordb4d67b52014-03-06 12:03:36 +0000487 SDValue LowerReturn(SDValue Chain, CallingConv::ID CallConv, bool IsVarArg,
488 const SmallVectorImpl<ISD::OutputArg> &Outs,
Benjamin Kramerbdc49562016-06-12 15:39:02 +0000489 const SmallVectorImpl<SDValue> &OutVals, const SDLoc &DL,
490 SelectionDAG &DAG) const override;
Richard Sandiford95bc5f92014-03-07 11:34:35 +0000491 SDValue PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const override;
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000492
Ulrich Weigand9eb858c2018-01-19 20:49:05 +0000493 /// Determine which of the bits specified in Mask are known to be either
494 /// zero or one and return them in the KnownZero/KnownOne bitsets.
495 void computeKnownBitsForTargetNode(const SDValue Op,
496 KnownBits &Known,
497 const APInt &DemandedElts,
498 const SelectionDAG &DAG,
499 unsigned Depth = 0) const override;
500
Marcin Koscielnickibbac8902016-05-10 16:49:04 +0000501 ISD::NodeType getExtendForAtomicOps() const override {
502 return ISD::ANY_EXTEND;
503 }
504
Bryan Chan893110e2016-04-28 00:17:23 +0000505 bool supportSwiftError() const override {
506 return true;
507 }
508
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000509private:
510 const SystemZSubtarget &Subtarget;
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000511
512 // Implement LowerOperation for individual opcodes.
Ulrich Weigand33435c42017-07-17 17:42:48 +0000513 SDValue getVectorCmp(SelectionDAG &DAG, unsigned Opcode,
514 const SDLoc &DL, EVT VT,
515 SDValue CmpOp0, SDValue CmpOp1) const;
516 SDValue lowerVectorSETCC(SelectionDAG &DAG, const SDLoc &DL,
517 EVT VT, ISD::CondCode CC,
518 SDValue CmpOp0, SDValue CmpOp1) const;
Richard Sandifordf722a8e302013-10-16 11:10:55 +0000519 SDValue lowerSETCC(SDValue Op, SelectionDAG &DAG) const;
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000520 SDValue lowerBR_CC(SDValue Op, SelectionDAG &DAG) const;
521 SDValue lowerSELECT_CC(SDValue Op, SelectionDAG &DAG) const;
522 SDValue lowerGlobalAddress(GlobalAddressSDNode *Node,
523 SelectionDAG &DAG) const;
Ulrich Weigand7db69182015-02-18 09:13:27 +0000524 SDValue lowerTLSGetOffset(GlobalAddressSDNode *Node,
525 SelectionDAG &DAG, unsigned Opcode,
526 SDValue GOTOffset) const;
Marcin Koscielnickif12609c2016-04-20 01:03:48 +0000527 SDValue lowerThreadPointer(const SDLoc &DL, SelectionDAG &DAG) const;
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000528 SDValue lowerGlobalTLSAddress(GlobalAddressSDNode *Node,
529 SelectionDAG &DAG) const;
530 SDValue lowerBlockAddress(BlockAddressSDNode *Node,
531 SelectionDAG &DAG) const;
532 SDValue lowerJumpTable(JumpTableSDNode *JT, SelectionDAG &DAG) const;
533 SDValue lowerConstantPool(ConstantPoolSDNode *CP, SelectionDAG &DAG) const;
Ulrich Weigandf557d082016-04-04 12:44:55 +0000534 SDValue lowerFRAMEADDR(SDValue Op, SelectionDAG &DAG) const;
535 SDValue lowerRETURNADDR(SDValue Op, SelectionDAG &DAG) const;
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000536 SDValue lowerVASTART(SDValue Op, SelectionDAG &DAG) const;
537 SDValue lowerVACOPY(SDValue Op, SelectionDAG &DAG) const;
538 SDValue lowerDYNAMIC_STACKALLOC(SDValue Op, SelectionDAG &DAG) const;
Marcin Koscielnicki9de88d92016-05-04 23:31:26 +0000539 SDValue lowerGET_DYNAMIC_AREA_OFFSET(SDValue Op, SelectionDAG &DAG) const;
Richard Sandiford7d86e472013-08-21 09:34:56 +0000540 SDValue lowerSMUL_LOHI(SDValue Op, SelectionDAG &DAG) const;
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000541 SDValue lowerUMUL_LOHI(SDValue Op, SelectionDAG &DAG) const;
542 SDValue lowerSDIVREM(SDValue Op, SelectionDAG &DAG) const;
543 SDValue lowerUDIVREM(SDValue Op, SelectionDAG &DAG) const;
544 SDValue lowerBITCAST(SDValue Op, SelectionDAG &DAG) const;
545 SDValue lowerOR(SDValue Op, SelectionDAG &DAG) const;
Ulrich Weigandb4012182015-03-31 12:56:33 +0000546 SDValue lowerCTPOP(SDValue Op, SelectionDAG &DAG) const;
Ulrich Weiganda9ac6d62016-04-04 12:45:44 +0000547 SDValue lowerATOMIC_FENCE(SDValue Op, SelectionDAG &DAG) const;
Richard Sandifordbef3d7a2013-12-10 10:49:34 +0000548 SDValue lowerATOMIC_LOAD(SDValue Op, SelectionDAG &DAG) const;
549 SDValue lowerATOMIC_STORE(SDValue Op, SelectionDAG &DAG) const;
550 SDValue lowerATOMIC_LOAD_OP(SDValue Op, SelectionDAG &DAG,
551 unsigned Opcode) const;
Richard Sandiford41350a52013-12-24 15:18:04 +0000552 SDValue lowerATOMIC_LOAD_SUB(SDValue Op, SelectionDAG &DAG) const;
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000553 SDValue lowerATOMIC_CMP_SWAP(SDValue Op, SelectionDAG &DAG) const;
554 SDValue lowerSTACKSAVE(SDValue Op, SelectionDAG &DAG) const;
555 SDValue lowerSTACKRESTORE(SDValue Op, SelectionDAG &DAG) const;
Richard Sandiford03481332013-08-23 11:36:42 +0000556 SDValue lowerPREFETCH(SDValue Op, SelectionDAG &DAG) const;
Ulrich Weigand57c85f52015-04-01 12:51:43 +0000557 SDValue lowerINTRINSIC_W_CHAIN(SDValue Op, SelectionDAG &DAG) const;
Ulrich Weigandc1708b22015-05-05 19:31:09 +0000558 SDValue lowerINTRINSIC_WO_CHAIN(SDValue Op, SelectionDAG &DAG) const;
Ulrich Weigandce4c1092015-05-05 19:25:42 +0000559 SDValue lowerBUILD_VECTOR(SDValue Op, SelectionDAG &DAG) const;
560 SDValue lowerVECTOR_SHUFFLE(SDValue Op, SelectionDAG &DAG) const;
561 SDValue lowerSCALAR_TO_VECTOR(SDValue Op, SelectionDAG &DAG) const;
Ulrich Weigandcd808232015-05-05 19:26:48 +0000562 SDValue lowerINSERT_VECTOR_ELT(SDValue Op, SelectionDAG &DAG) const;
563 SDValue lowerEXTRACT_VECTOR_ELT(SDValue Op, SelectionDAG &DAG) const;
Ulrich Weigandcd2a1b52015-05-05 19:29:21 +0000564 SDValue lowerExtendVectorInreg(SDValue Op, SelectionDAG &DAG,
NAKAMURA Takumi0a7d0ad2015-09-22 11:15:07 +0000565 unsigned UnpackHigh) const;
Ulrich Weigandce4c1092015-05-05 19:25:42 +0000566 SDValue lowerShift(SDValue Op, SelectionDAG &DAG, unsigned ByScalar) const;
567
Jonas Paulssoncad72ef2017-04-07 12:35:11 +0000568 bool canTreatAsByteVector(EVT VT) const;
Benjamin Kramerbdc49562016-06-12 15:39:02 +0000569 SDValue combineExtract(const SDLoc &DL, EVT ElemVT, EVT VecVT, SDValue OrigOp,
Ulrich Weigandce4c1092015-05-05 19:25:42 +0000570 unsigned Index, DAGCombinerInfo &DCI,
571 bool Force) const;
Benjamin Kramerbdc49562016-06-12 15:39:02 +0000572 SDValue combineTruncateExtract(const SDLoc &DL, EVT TruncVT, SDValue Op,
Ulrich Weigandce4c1092015-05-05 19:25:42 +0000573 DAGCombinerInfo &DCI) const;
Ulrich Weigand849a59f2018-01-19 20:52:04 +0000574 SDValue combineZERO_EXTEND(SDNode *N, DAGCombinerInfo &DCI) const;
Marcin Koscielnicki68747ac2016-06-30 00:08:54 +0000575 SDValue combineSIGN_EXTEND(SDNode *N, DAGCombinerInfo &DCI) const;
Ulrich Weigand849a59f2018-01-19 20:52:04 +0000576 SDValue combineSIGN_EXTEND_INREG(SDNode *N, DAGCombinerInfo &DCI) const;
Marcin Koscielnicki68747ac2016-06-30 00:08:54 +0000577 SDValue combineMERGE(SDNode *N, DAGCombinerInfo &DCI) const;
578 SDValue combineSTORE(SDNode *N, DAGCombinerInfo &DCI) const;
579 SDValue combineEXTRACT_VECTOR_ELT(SDNode *N, DAGCombinerInfo &DCI) const;
580 SDValue combineJOIN_DWORDS(SDNode *N, DAGCombinerInfo &DCI) const;
581 SDValue combineFP_ROUND(SDNode *N, DAGCombinerInfo &DCI) const;
582 SDValue combineBSWAP(SDNode *N, DAGCombinerInfo &DCI) const;
Elliot Colpbc2cfc22016-07-06 18:13:11 +0000583 SDValue combineSHIFTROT(SDNode *N, DAGCombinerInfo &DCI) const;
Ulrich Weigand31112892018-01-19 20:54:18 +0000584 SDValue combineBR_CCMASK(SDNode *N, DAGCombinerInfo &DCI) const;
585 SDValue combineSELECT_CCMASK(SDNode *N, DAGCombinerInfo &DCI) const;
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000586
Richard Sandiford0fb90ab2013-05-28 10:41:11 +0000587 // If the last instruction before MBBI in MBB was some form of COMPARE,
588 // try to replace it with a COMPARE AND BRANCH just before MBBI.
589 // CCMask and Target are the BRC-like operands for the branch.
590 // Return true if the change was made.
591 bool convertPrevCompareToBranch(MachineBasicBlock *MBB,
592 MachineBasicBlock::iterator MBBI,
593 unsigned CCMask,
594 MachineBasicBlock *Target) const;
595
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000596 // Implement EmitInstrWithCustomInserter for individual operation types.
Ulrich Weigand524f2762016-11-28 13:34:08 +0000597 MachineBasicBlock *emitSelect(MachineInstr &MI, MachineBasicBlock *BB,
598 unsigned LOCROpcode) const;
Duncan P. N. Exon Smithe4f5e4f2016-06-30 22:52:52 +0000599 MachineBasicBlock *emitCondStore(MachineInstr &MI, MachineBasicBlock *BB,
Richard Sandiforda68e6f52013-07-25 08:57:02 +0000600 unsigned StoreOpcode, unsigned STOCOpcode,
601 bool Invert) const;
Ulrich Weiganda11f63a2017-08-04 18:57:58 +0000602 MachineBasicBlock *emitPair128(MachineInstr &MI,
603 MachineBasicBlock *MBB) const;
Duncan P. N. Exon Smithe4f5e4f2016-06-30 22:52:52 +0000604 MachineBasicBlock *emitExt128(MachineInstr &MI, MachineBasicBlock *MBB,
Ulrich Weigand43579cf2017-07-05 13:17:31 +0000605 bool ClearEven) const;
Duncan P. N. Exon Smithe4f5e4f2016-06-30 22:52:52 +0000606 MachineBasicBlock *emitAtomicLoadBinary(MachineInstr &MI,
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000607 MachineBasicBlock *BB,
608 unsigned BinOpcode, unsigned BitSize,
609 bool Invert = false) const;
Duncan P. N. Exon Smithe4f5e4f2016-06-30 22:52:52 +0000610 MachineBasicBlock *emitAtomicLoadMinMax(MachineInstr &MI,
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000611 MachineBasicBlock *MBB,
612 unsigned CompareOpcode,
613 unsigned KeepOldMask,
614 unsigned BitSize) const;
Duncan P. N. Exon Smithe4f5e4f2016-06-30 22:52:52 +0000615 MachineBasicBlock *emitAtomicCmpSwapW(MachineInstr &MI,
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000616 MachineBasicBlock *BB) const;
Duncan P. N. Exon Smithe4f5e4f2016-06-30 22:52:52 +0000617 MachineBasicBlock *emitMemMemWrapper(MachineInstr &MI, MachineBasicBlock *BB,
Richard Sandiford564681c2013-08-12 10:28:10 +0000618 unsigned Opcode) const;
Duncan P. N. Exon Smithe4f5e4f2016-06-30 22:52:52 +0000619 MachineBasicBlock *emitStringWrapper(MachineInstr &MI, MachineBasicBlock *BB,
Richard Sandifordca232712013-08-16 11:21:54 +0000620 unsigned Opcode) const;
Duncan P. N. Exon Smithe4f5e4f2016-06-30 22:52:52 +0000621 MachineBasicBlock *emitTransactionBegin(MachineInstr &MI,
Ulrich Weigand57c85f52015-04-01 12:51:43 +0000622 MachineBasicBlock *MBB,
Duncan P. N. Exon Smithe4f5e4f2016-06-30 22:52:52 +0000623 unsigned Opcode, bool NoFloat) const;
624 MachineBasicBlock *emitLoadAndTestCmp0(MachineInstr &MI,
NAKAMURA Takumi50df0c22015-11-02 01:38:12 +0000625 MachineBasicBlock *MBB,
626 unsigned Opcode) const;
Jonas Paulsson11d251c2017-05-10 13:03:25 +0000627
628 const TargetRegisterClass *getRepRegClassFor(MVT VT) const override;
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000629};
630} // end namespace llvm
631
Benjamin Kramera7c40ef2014-08-13 16:26:38 +0000632#endif