xref: /freebsd/contrib/llvm-project/llvm/lib/Target/SystemZ/SystemZISelLowering.h (revision 0fca6ea1d4eea4c934cfff25ac9ee8ad6fe95583)
10b57cec5SDimitry Andric //===-- SystemZISelLowering.h - SystemZ DAG lowering interface --*- C++ -*-===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric //
90b57cec5SDimitry Andric // This file defines the interfaces that SystemZ uses to lower LLVM code into a
100b57cec5SDimitry Andric // selection DAG.
110b57cec5SDimitry Andric //
120b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
130b57cec5SDimitry Andric 
140b57cec5SDimitry Andric #ifndef LLVM_LIB_TARGET_SYSTEMZ_SYSTEMZISELLOWERING_H
150b57cec5SDimitry Andric #define LLVM_LIB_TARGET_SYSTEMZ_SYSTEMZISELLOWERING_H
160b57cec5SDimitry Andric 
170b57cec5SDimitry Andric #include "SystemZ.h"
180b57cec5SDimitry Andric #include "SystemZInstrInfo.h"
190b57cec5SDimitry Andric #include "llvm/CodeGen/MachineBasicBlock.h"
200b57cec5SDimitry Andric #include "llvm/CodeGen/SelectionDAG.h"
210b57cec5SDimitry Andric #include "llvm/CodeGen/TargetLowering.h"
22bdd1243dSDimitry Andric #include <optional>
230b57cec5SDimitry Andric 
240b57cec5SDimitry Andric namespace llvm {
250b57cec5SDimitry Andric namespace SystemZISD {
260b57cec5SDimitry Andric enum NodeType : unsigned {
270b57cec5SDimitry Andric   FIRST_NUMBER = ISD::BUILTIN_OP_END,
280b57cec5SDimitry Andric 
2906c3fb27SDimitry Andric   // Return with a glue operand.  Operand 0 is the chain operand.
3006c3fb27SDimitry Andric   RET_GLUE,
310b57cec5SDimitry Andric 
320b57cec5SDimitry Andric   // Calls a function.  Operand 0 is the chain operand and operand 1
330b57cec5SDimitry Andric   // is the target address.  The arguments start at operand 2.
340b57cec5SDimitry Andric   // There is an optional glue operand at the end.
350b57cec5SDimitry Andric   CALL,
360b57cec5SDimitry Andric   SIBCALL,
370b57cec5SDimitry Andric 
380b57cec5SDimitry Andric   // TLS calls.  Like regular calls, except operand 1 is the TLS symbol.
390b57cec5SDimitry Andric   // (The call target is implicitly __tls_get_offset.)
400b57cec5SDimitry Andric   TLS_GDCALL,
410b57cec5SDimitry Andric   TLS_LDCALL,
420b57cec5SDimitry Andric 
430b57cec5SDimitry Andric   // Wraps a TargetGlobalAddress that should be loaded using PC-relative
440b57cec5SDimitry Andric   // accesses (LARL).  Operand 0 is the address.
450b57cec5SDimitry Andric   PCREL_WRAPPER,
460b57cec5SDimitry Andric 
470b57cec5SDimitry Andric   // Used in cases where an offset is applied to a TargetGlobalAddress.
480b57cec5SDimitry Andric   // Operand 0 is the full TargetGlobalAddress and operand 1 is a
490b57cec5SDimitry Andric   // PCREL_WRAPPER for an anchor point.  This is used so that we can
500b57cec5SDimitry Andric   // cheaply refer to either the full address or the anchor point
510b57cec5SDimitry Andric   // as a register base.
520b57cec5SDimitry Andric   PCREL_OFFSET,
530b57cec5SDimitry Andric 
540b57cec5SDimitry Andric   // Integer comparisons.  There are three operands: the two values
550b57cec5SDimitry Andric   // to compare, and an integer of type SystemZICMP.
560b57cec5SDimitry Andric   ICMP,
570b57cec5SDimitry Andric 
580b57cec5SDimitry Andric   // Floating-point comparisons.  The two operands are the values to compare.
590b57cec5SDimitry Andric   FCMP,
600b57cec5SDimitry Andric 
610b57cec5SDimitry Andric   // Test under mask.  The first operand is ANDed with the second operand
620b57cec5SDimitry Andric   // and the condition codes are set on the result.  The third operand is
630b57cec5SDimitry Andric   // a boolean that is true if the condition codes need to distinguish
640b57cec5SDimitry Andric   // between CCMASK_TM_MIXED_MSB_0 and CCMASK_TM_MIXED_MSB_1 (which the
650b57cec5SDimitry Andric   // register forms do but the memory forms don't).
660b57cec5SDimitry Andric   TM,
670b57cec5SDimitry Andric 
680b57cec5SDimitry Andric   // Branches if a condition is true.  Operand 0 is the chain operand;
690b57cec5SDimitry Andric   // operand 1 is the 4-bit condition-code mask, with bit N in
700b57cec5SDimitry Andric   // big-endian order meaning "branch if CC=N"; operand 2 is the
710b57cec5SDimitry Andric   // target block and operand 3 is the flag operand.
720b57cec5SDimitry Andric   BR_CCMASK,
730b57cec5SDimitry Andric 
740b57cec5SDimitry Andric   // Selects between operand 0 and operand 1.  Operand 2 is the
750b57cec5SDimitry Andric   // mask of condition-code values for which operand 0 should be
760b57cec5SDimitry Andric   // chosen over operand 1; it has the same form as BR_CCMASK.
770b57cec5SDimitry Andric   // Operand 3 is the flag operand.
780b57cec5SDimitry Andric   SELECT_CCMASK,
790b57cec5SDimitry Andric 
800b57cec5SDimitry Andric   // Evaluates to the gap between the stack pointer and the
810b57cec5SDimitry Andric   // base of the dynamically-allocatable area.
820b57cec5SDimitry Andric   ADJDYNALLOC,
830b57cec5SDimitry Andric 
845ffd83dbSDimitry Andric   // For allocating stack space when using stack clash protector.
855ffd83dbSDimitry Andric   // Allocation is performed by block, and each block is probed.
865ffd83dbSDimitry Andric   PROBED_ALLOCA,
875ffd83dbSDimitry Andric 
880b57cec5SDimitry Andric   // Count number of bits set in operand 0 per byte.
890b57cec5SDimitry Andric   POPCNT,
900b57cec5SDimitry Andric 
910b57cec5SDimitry Andric   // Wrappers around the ISD opcodes of the same name.  The output is GR128.
920b57cec5SDimitry Andric   // Input operands may be GR64 or GR32, depending on the instruction.
930b57cec5SDimitry Andric   SMUL_LOHI,
940b57cec5SDimitry Andric   UMUL_LOHI,
950b57cec5SDimitry Andric   SDIVREM,
960b57cec5SDimitry Andric   UDIVREM,
970b57cec5SDimitry Andric 
980b57cec5SDimitry Andric   // Add/subtract with overflow/carry.  These have the same operands as
990b57cec5SDimitry Andric   // the corresponding standard operations, except with the carry flag
1000b57cec5SDimitry Andric   // replaced by a condition code value.
1010b57cec5SDimitry Andric   SADDO, SSUBO, UADDO, USUBO, ADDCARRY, SUBCARRY,
1020b57cec5SDimitry Andric 
1030b57cec5SDimitry Andric   // Set the condition code from a boolean value in operand 0.
1040b57cec5SDimitry Andric   // Operand 1 is a mask of all condition-code values that may result of this
1050b57cec5SDimitry Andric   // operation, operand 2 is a mask of condition-code values that may result
1060b57cec5SDimitry Andric   // if the boolean is true.
1070b57cec5SDimitry Andric   // Note that this operation is always optimized away, we will never
1080b57cec5SDimitry Andric   // generate any code for it.
1090b57cec5SDimitry Andric   GET_CCMASK,
1100b57cec5SDimitry Andric 
1110b57cec5SDimitry Andric   // Use a series of MVCs to copy bytes from one memory location to another.
1120b57cec5SDimitry Andric   // The operands are:
1130b57cec5SDimitry Andric   // - the target address
1140b57cec5SDimitry Andric   // - the source address
1150b57cec5SDimitry Andric   // - the constant length
1160b57cec5SDimitry Andric   //
1170b57cec5SDimitry Andric   // This isn't a memory opcode because we'd need to attach two
1180b57cec5SDimitry Andric   // MachineMemOperands rather than one.
1190b57cec5SDimitry Andric   MVC,
1200b57cec5SDimitry Andric 
121349cc55cSDimitry Andric   // Similar to MVC, but for logic operations (AND, OR, XOR).
1220b57cec5SDimitry Andric   NC,
1230b57cec5SDimitry Andric   OC,
1240b57cec5SDimitry Andric   XC,
1250b57cec5SDimitry Andric 
1260b57cec5SDimitry Andric   // Use CLC to compare two blocks of memory, with the same comments
127349cc55cSDimitry Andric   // as for MVC.
1280b57cec5SDimitry Andric   CLC,
1290b57cec5SDimitry Andric 
1300eae32dcSDimitry Andric   // Use MVC to set a block of memory after storing the first byte.
1310eae32dcSDimitry Andric   MEMSET_MVC,
1320eae32dcSDimitry Andric 
1330b57cec5SDimitry Andric   // Use an MVST-based sequence to implement stpcpy().
1340b57cec5SDimitry Andric   STPCPY,
1350b57cec5SDimitry Andric 
1360b57cec5SDimitry Andric   // Use a CLST-based sequence to implement strcmp().  The two input operands
1370b57cec5SDimitry Andric   // are the addresses of the strings to compare.
1380b57cec5SDimitry Andric   STRCMP,
1390b57cec5SDimitry Andric 
1400b57cec5SDimitry Andric   // Use an SRST-based sequence to search a block of memory.  The first
1410b57cec5SDimitry Andric   // operand is the end address, the second is the start, and the third
1420b57cec5SDimitry Andric   // is the character to search for.  CC is set to 1 on success and 2
1430b57cec5SDimitry Andric   // on failure.
1440b57cec5SDimitry Andric   SEARCH_STRING,
1450b57cec5SDimitry Andric 
1460b57cec5SDimitry Andric   // Store the CC value in bits 29 and 28 of an integer.
1470b57cec5SDimitry Andric   IPM,
1480b57cec5SDimitry Andric 
1490b57cec5SDimitry Andric   // Transaction begin.  The first operand is the chain, the second
1500b57cec5SDimitry Andric   // the TDB pointer, and the third the immediate control field.
1510b57cec5SDimitry Andric   // Returns CC value and chain.
1520b57cec5SDimitry Andric   TBEGIN,
1530b57cec5SDimitry Andric   TBEGIN_NOFLOAT,
1540b57cec5SDimitry Andric 
1550b57cec5SDimitry Andric   // Transaction end.  Just the chain operand.  Returns CC value and chain.
1560b57cec5SDimitry Andric   TEND,
1570b57cec5SDimitry Andric 
1580b57cec5SDimitry Andric   // Create a vector constant by filling byte N of the result with bit
1590b57cec5SDimitry Andric   // 15-N of the single operand.
1600b57cec5SDimitry Andric   BYTE_MASK,
1610b57cec5SDimitry Andric 
1620b57cec5SDimitry Andric   // Create a vector constant by replicating an element-sized RISBG-style mask.
1630b57cec5SDimitry Andric   // The first operand specifies the starting set bit and the second operand
1640b57cec5SDimitry Andric   // specifies the ending set bit.  Both operands count from the MSB of the
1650b57cec5SDimitry Andric   // element.
1660b57cec5SDimitry Andric   ROTATE_MASK,
1670b57cec5SDimitry Andric 
1680b57cec5SDimitry Andric   // Replicate a GPR scalar value into all elements of a vector.
1690b57cec5SDimitry Andric   REPLICATE,
1700b57cec5SDimitry Andric 
1710b57cec5SDimitry Andric   // Create a vector from two i64 GPRs.
1720b57cec5SDimitry Andric   JOIN_DWORDS,
1730b57cec5SDimitry Andric 
1740b57cec5SDimitry Andric   // Replicate one element of a vector into all elements.  The first operand
1750b57cec5SDimitry Andric   // is the vector and the second is the index of the element to replicate.
1760b57cec5SDimitry Andric   SPLAT,
1770b57cec5SDimitry Andric 
1780b57cec5SDimitry Andric   // Interleave elements from the high half of operand 0 and the high half
1790b57cec5SDimitry Andric   // of operand 1.
1800b57cec5SDimitry Andric   MERGE_HIGH,
1810b57cec5SDimitry Andric 
1820b57cec5SDimitry Andric   // Likewise for the low halves.
1830b57cec5SDimitry Andric   MERGE_LOW,
1840b57cec5SDimitry Andric 
1850b57cec5SDimitry Andric   // Concatenate the vectors in the first two operands, shift them left
1860b57cec5SDimitry Andric   // by the third operand, and take the first half of the result.
1870b57cec5SDimitry Andric   SHL_DOUBLE,
1880b57cec5SDimitry Andric 
1890b57cec5SDimitry Andric   // Take one element of the first v2i64 operand and the one element of
1900b57cec5SDimitry Andric   // the second v2i64 operand and concatenate them to form a v2i64 result.
1910b57cec5SDimitry Andric   // The third operand is a 4-bit value of the form 0A0B, where A and B
1920b57cec5SDimitry Andric   // are the element selectors for the first operand and second operands
1930b57cec5SDimitry Andric   // respectively.
1940b57cec5SDimitry Andric   PERMUTE_DWORDS,
1950b57cec5SDimitry Andric 
1960b57cec5SDimitry Andric   // Perform a general vector permute on vector operands 0 and 1.
1970b57cec5SDimitry Andric   // Each byte of operand 2 controls the corresponding byte of the result,
1980b57cec5SDimitry Andric   // in the same way as a byte-level VECTOR_SHUFFLE mask.
1990b57cec5SDimitry Andric   PERMUTE,
2000b57cec5SDimitry Andric 
2010b57cec5SDimitry Andric   // Pack vector operands 0 and 1 into a single vector with half-sized elements.
2020b57cec5SDimitry Andric   PACK,
2030b57cec5SDimitry Andric 
2040b57cec5SDimitry Andric   // Likewise, but saturate the result and set CC.  PACKS_CC does signed
2050b57cec5SDimitry Andric   // saturation and PACKLS_CC does unsigned saturation.
2060b57cec5SDimitry Andric   PACKS_CC,
2070b57cec5SDimitry Andric   PACKLS_CC,
2080b57cec5SDimitry Andric 
2090b57cec5SDimitry Andric   // Unpack the first half of vector operand 0 into double-sized elements.
2100b57cec5SDimitry Andric   // UNPACK_HIGH sign-extends and UNPACKL_HIGH zero-extends.
2110b57cec5SDimitry Andric   UNPACK_HIGH,
2120b57cec5SDimitry Andric   UNPACKL_HIGH,
2130b57cec5SDimitry Andric 
2140b57cec5SDimitry Andric   // Likewise for the second half.
2150b57cec5SDimitry Andric   UNPACK_LOW,
2160b57cec5SDimitry Andric   UNPACKL_LOW,
2170b57cec5SDimitry Andric 
2185f757f3fSDimitry Andric   // Shift/rotate each element of vector operand 0 by the number of bits
2195f757f3fSDimitry Andric   // specified by scalar operand 1.
2200b57cec5SDimitry Andric   VSHL_BY_SCALAR,
2210b57cec5SDimitry Andric   VSRL_BY_SCALAR,
2220b57cec5SDimitry Andric   VSRA_BY_SCALAR,
2235f757f3fSDimitry Andric   VROTL_BY_SCALAR,
2240b57cec5SDimitry Andric 
2250b57cec5SDimitry Andric   // For each element of the output type, sum across all sub-elements of
2260b57cec5SDimitry Andric   // operand 0 belonging to the corresponding element, and add in the
2270b57cec5SDimitry Andric   // rightmost sub-element of the corresponding element of operand 1.
2280b57cec5SDimitry Andric   VSUM,
2290b57cec5SDimitry Andric 
2305f757f3fSDimitry Andric   // Compute carry/borrow indication for add/subtract.
2315f757f3fSDimitry Andric   VACC, VSCBI,
2325f757f3fSDimitry Andric   // Add/subtract with carry/borrow.
2335f757f3fSDimitry Andric   VAC, VSBI,
2345f757f3fSDimitry Andric   // Compute carry/borrow indication for add/subtract with carry/borrow.
2355f757f3fSDimitry Andric   VACCC, VSBCBI,
2365f757f3fSDimitry Andric 
2370b57cec5SDimitry Andric   // Compare integer vector operands 0 and 1 to produce the usual 0/-1
2380b57cec5SDimitry Andric   // vector result.  VICMPE is for equality, VICMPH for "signed greater than"
2390b57cec5SDimitry Andric   // and VICMPHL for "unsigned greater than".
2400b57cec5SDimitry Andric   VICMPE,
2410b57cec5SDimitry Andric   VICMPH,
2420b57cec5SDimitry Andric   VICMPHL,
2430b57cec5SDimitry Andric 
2440b57cec5SDimitry Andric   // Likewise, but also set the condition codes on the result.
2450b57cec5SDimitry Andric   VICMPES,
2460b57cec5SDimitry Andric   VICMPHS,
2470b57cec5SDimitry Andric   VICMPHLS,
2480b57cec5SDimitry Andric 
249480093f4SDimitry Andric   // Compare floating-point vector operands 0 and 1 to produce the usual 0/-1
2500b57cec5SDimitry Andric   // vector result.  VFCMPE is for "ordered and equal", VFCMPH for "ordered and
2510b57cec5SDimitry Andric   // greater than" and VFCMPHE for "ordered and greater than or equal to".
2520b57cec5SDimitry Andric   VFCMPE,
2530b57cec5SDimitry Andric   VFCMPH,
2540b57cec5SDimitry Andric   VFCMPHE,
2550b57cec5SDimitry Andric 
2560b57cec5SDimitry Andric   // Likewise, but also set the condition codes on the result.
2570b57cec5SDimitry Andric   VFCMPES,
2580b57cec5SDimitry Andric   VFCMPHS,
2590b57cec5SDimitry Andric   VFCMPHES,
2600b57cec5SDimitry Andric 
2610b57cec5SDimitry Andric   // Test floating-point data class for vectors.
2620b57cec5SDimitry Andric   VFTCI,
2630b57cec5SDimitry Andric 
2640b57cec5SDimitry Andric   // Extend the even f32 elements of vector operand 0 to produce a vector
2650b57cec5SDimitry Andric   // of f64 elements.
2660b57cec5SDimitry Andric   VEXTEND,
2670b57cec5SDimitry Andric 
2680b57cec5SDimitry Andric   // Round the f64 elements of vector operand 0 to f32s and store them in the
2690b57cec5SDimitry Andric   // even elements of the result.
2700b57cec5SDimitry Andric   VROUND,
2710b57cec5SDimitry Andric 
2720b57cec5SDimitry Andric   // AND the two vector operands together and set CC based on the result.
2730b57cec5SDimitry Andric   VTM,
2740b57cec5SDimitry Andric 
2755f757f3fSDimitry Andric   // i128 high integer comparisons.
2765f757f3fSDimitry Andric   SCMP128HI,
2775f757f3fSDimitry Andric   UCMP128HI,
2785f757f3fSDimitry Andric 
2790b57cec5SDimitry Andric   // String operations that set CC as a side-effect.
2800b57cec5SDimitry Andric   VFAE_CC,
2810b57cec5SDimitry Andric   VFAEZ_CC,
2820b57cec5SDimitry Andric   VFEE_CC,
2830b57cec5SDimitry Andric   VFEEZ_CC,
2840b57cec5SDimitry Andric   VFENE_CC,
2850b57cec5SDimitry Andric   VFENEZ_CC,
2860b57cec5SDimitry Andric   VISTR_CC,
2870b57cec5SDimitry Andric   VSTRC_CC,
2880b57cec5SDimitry Andric   VSTRCZ_CC,
2890b57cec5SDimitry Andric   VSTRS_CC,
2900b57cec5SDimitry Andric   VSTRSZ_CC,
2910b57cec5SDimitry Andric 
2920b57cec5SDimitry Andric   // Test Data Class.
2930b57cec5SDimitry Andric   //
2940b57cec5SDimitry Andric   // Operand 0: the value to test
2950b57cec5SDimitry Andric   // Operand 1: the bit mask
2960b57cec5SDimitry Andric   TDC,
2970b57cec5SDimitry Andric 
29806c3fb27SDimitry Andric   // z/OS XPLINK ADA Entry
29906c3fb27SDimitry Andric   // Wraps a TargetGlobalAddress that should be loaded from a function's
30006c3fb27SDimitry Andric   // AssociatedData Area (ADA). Tha ADA is passed to the function by the
30106c3fb27SDimitry Andric   // caller in the XPLink ABI defined register R5.
30206c3fb27SDimitry Andric   // Operand 0: the GlobalValue/External Symbol
30306c3fb27SDimitry Andric   // Operand 1: the ADA register
30406c3fb27SDimitry Andric   // Operand 2: the offset (0 for the first and 8 for the second element in the
30506c3fb27SDimitry Andric   // function descriptor)
30606c3fb27SDimitry Andric   ADA_ENTRY,
30706c3fb27SDimitry Andric 
308480093f4SDimitry Andric   // Strict variants of scalar floating-point comparisons.
309480093f4SDimitry Andric   // Quiet and signaling versions.
310480093f4SDimitry Andric   STRICT_FCMP = ISD::FIRST_TARGET_STRICTFP_OPCODE,
311480093f4SDimitry Andric   STRICT_FCMPS,
312480093f4SDimitry Andric 
313480093f4SDimitry Andric   // Strict variants of vector floating-point comparisons.
314480093f4SDimitry Andric   // Quiet and signaling versions.
315480093f4SDimitry Andric   STRICT_VFCMPE,
316480093f4SDimitry Andric   STRICT_VFCMPH,
317480093f4SDimitry Andric   STRICT_VFCMPHE,
318480093f4SDimitry Andric   STRICT_VFCMPES,
319480093f4SDimitry Andric   STRICT_VFCMPHS,
320480093f4SDimitry Andric   STRICT_VFCMPHES,
321480093f4SDimitry Andric 
322480093f4SDimitry Andric   // Strict variants of VEXTEND and VROUND.
323480093f4SDimitry Andric   STRICT_VEXTEND,
324480093f4SDimitry Andric   STRICT_VROUND,
325480093f4SDimitry Andric 
3260b57cec5SDimitry Andric   // Wrappers around the inner loop of an 8- or 16-bit ATOMIC_SWAP or
3270b57cec5SDimitry Andric   // ATOMIC_LOAD_<op>.
3280b57cec5SDimitry Andric   //
3290b57cec5SDimitry Andric   // Operand 0: the address of the containing 32-bit-aligned field
3300b57cec5SDimitry Andric   // Operand 1: the second operand of <op>, in the high bits of an i32
3310b57cec5SDimitry Andric   //            for everything except ATOMIC_SWAPW
3320b57cec5SDimitry Andric   // Operand 2: how many bits to rotate the i32 left to bring the first
3330b57cec5SDimitry Andric   //            operand into the high bits
3340b57cec5SDimitry Andric   // Operand 3: the negative of operand 2, for rotating the other way
3350b57cec5SDimitry Andric   // Operand 4: the width of the field in bits (8 or 16)
3360b57cec5SDimitry Andric   ATOMIC_SWAPW = ISD::FIRST_TARGET_MEMORY_OPCODE,
3370b57cec5SDimitry Andric   ATOMIC_LOADW_ADD,
3380b57cec5SDimitry Andric   ATOMIC_LOADW_SUB,
3390b57cec5SDimitry Andric   ATOMIC_LOADW_AND,
3400b57cec5SDimitry Andric   ATOMIC_LOADW_OR,
3410b57cec5SDimitry Andric   ATOMIC_LOADW_XOR,
3420b57cec5SDimitry Andric   ATOMIC_LOADW_NAND,
3430b57cec5SDimitry Andric   ATOMIC_LOADW_MIN,
3440b57cec5SDimitry Andric   ATOMIC_LOADW_MAX,
3450b57cec5SDimitry Andric   ATOMIC_LOADW_UMIN,
3460b57cec5SDimitry Andric   ATOMIC_LOADW_UMAX,
3470b57cec5SDimitry Andric 
3480b57cec5SDimitry Andric   // A wrapper around the inner loop of an ATOMIC_CMP_SWAP.
3490b57cec5SDimitry Andric   //
3500b57cec5SDimitry Andric   // Operand 0: the address of the containing 32-bit-aligned field
3510b57cec5SDimitry Andric   // Operand 1: the compare value, in the low bits of an i32
3520b57cec5SDimitry Andric   // Operand 2: the swap value, in the low bits of an i32
3530b57cec5SDimitry Andric   // Operand 3: how many bits to rotate the i32 left to bring the first
3540b57cec5SDimitry Andric   //            operand into the high bits
3550b57cec5SDimitry Andric   // Operand 4: the negative of operand 2, for rotating the other way
3560b57cec5SDimitry Andric   // Operand 5: the width of the field in bits (8 or 16)
3570b57cec5SDimitry Andric   ATOMIC_CMP_SWAPW,
3580b57cec5SDimitry Andric 
3590b57cec5SDimitry Andric   // Atomic compare-and-swap returning CC value.
3600b57cec5SDimitry Andric   // Val, CC, OUTCHAIN = ATOMIC_CMP_SWAP(INCHAIN, ptr, cmp, swap)
3610b57cec5SDimitry Andric   ATOMIC_CMP_SWAP,
3620b57cec5SDimitry Andric 
3630b57cec5SDimitry Andric   // 128-bit atomic load.
3640b57cec5SDimitry Andric   // Val, OUTCHAIN = ATOMIC_LOAD_128(INCHAIN, ptr)
3650b57cec5SDimitry Andric   ATOMIC_LOAD_128,
3660b57cec5SDimitry Andric 
3670b57cec5SDimitry Andric   // 128-bit atomic store.
3680b57cec5SDimitry Andric   // OUTCHAIN = ATOMIC_STORE_128(INCHAIN, val, ptr)
3690b57cec5SDimitry Andric   ATOMIC_STORE_128,
3700b57cec5SDimitry Andric 
3710b57cec5SDimitry Andric   // 128-bit atomic compare-and-swap.
3720b57cec5SDimitry Andric   // Val, CC, OUTCHAIN = ATOMIC_CMP_SWAP(INCHAIN, ptr, cmp, swap)
3730b57cec5SDimitry Andric   ATOMIC_CMP_SWAP_128,
3740b57cec5SDimitry Andric 
3750b57cec5SDimitry Andric   // Byte swapping load/store.  Same operands as regular load/store.
3760b57cec5SDimitry Andric   LRV, STRV,
3770b57cec5SDimitry Andric 
3780b57cec5SDimitry Andric   // Element swapping load/store.  Same operands as regular load/store.
3790b57cec5SDimitry Andric   VLER, VSTER,
3800b57cec5SDimitry Andric 
381*0fca6ea1SDimitry Andric   // Use STORE CLOCK FAST to store current TOD clock value.
382*0fca6ea1SDimitry Andric   STCKF,
383*0fca6ea1SDimitry Andric 
3840b57cec5SDimitry Andric   // Prefetch from the second operand using the 4-bit control code in
3850b57cec5SDimitry Andric   // the first operand.  The code is 1 for a load prefetch and 2 for
3860b57cec5SDimitry Andric   // a store prefetch.
3870b57cec5SDimitry Andric   PREFETCH
3880b57cec5SDimitry Andric };
3890b57cec5SDimitry Andric 
3900b57cec5SDimitry Andric // Return true if OPCODE is some kind of PC-relative address.
isPCREL(unsigned Opcode)3910b57cec5SDimitry Andric inline bool isPCREL(unsigned Opcode) {
3920b57cec5SDimitry Andric   return Opcode == PCREL_WRAPPER || Opcode == PCREL_OFFSET;
3930b57cec5SDimitry Andric }
3940b57cec5SDimitry Andric } // end namespace SystemZISD
3950b57cec5SDimitry Andric 
3960b57cec5SDimitry Andric namespace SystemZICMP {
3970b57cec5SDimitry Andric // Describes whether an integer comparison needs to be signed or unsigned,
3980b57cec5SDimitry Andric // or whether either type is OK.
3990b57cec5SDimitry Andric enum {
4000b57cec5SDimitry Andric   Any,
4010b57cec5SDimitry Andric   UnsignedOnly,
4020b57cec5SDimitry Andric   SignedOnly
4030b57cec5SDimitry Andric };
4040b57cec5SDimitry Andric } // end namespace SystemZICMP
4050b57cec5SDimitry Andric 
4060b57cec5SDimitry Andric class SystemZSubtarget;
4070b57cec5SDimitry Andric 
4080b57cec5SDimitry Andric class SystemZTargetLowering : public TargetLowering {
4090b57cec5SDimitry Andric public:
4100b57cec5SDimitry Andric   explicit SystemZTargetLowering(const TargetMachine &TM,
4110b57cec5SDimitry Andric                                  const SystemZSubtarget &STI);
4120b57cec5SDimitry Andric 
4135ffd83dbSDimitry Andric   bool useSoftFloat() const override;
4145ffd83dbSDimitry Andric 
4150b57cec5SDimitry Andric   // Override TargetLowering.
getScalarShiftAmountTy(const DataLayout &,EVT)4160b57cec5SDimitry Andric   MVT getScalarShiftAmountTy(const DataLayout &, EVT) const override {
4170b57cec5SDimitry Andric     return MVT::i32;
4180b57cec5SDimitry Andric   }
getVectorIdxTy(const DataLayout & DL)4190b57cec5SDimitry Andric   MVT getVectorIdxTy(const DataLayout &DL) const override {
4200b57cec5SDimitry Andric     // Only the lower 12 bits of an element index are used, so we don't
4210b57cec5SDimitry Andric     // want to clobber the upper 32 bits of a GPR unnecessarily.
4220b57cec5SDimitry Andric     return MVT::i32;
4230b57cec5SDimitry Andric   }
getPreferredVectorAction(MVT VT)4240b57cec5SDimitry Andric   TargetLoweringBase::LegalizeTypeAction getPreferredVectorAction(MVT VT)
4250b57cec5SDimitry Andric     const override {
4260b57cec5SDimitry Andric     // Widen subvectors to the full width rather than promoting integer
4270b57cec5SDimitry Andric     // elements.  This is better because:
4280b57cec5SDimitry Andric     //
4290b57cec5SDimitry Andric     // (a) it means that we can handle the ABI for passing and returning
4300b57cec5SDimitry Andric     //     sub-128 vectors without having to handle them as legal types.
4310b57cec5SDimitry Andric     //
4320b57cec5SDimitry Andric     // (b) we don't have instructions to extend on load and truncate on store,
4330b57cec5SDimitry Andric     //     so promoting the integers is less efficient.
4340b57cec5SDimitry Andric     //
4350b57cec5SDimitry Andric     // (c) there are no multiplication instructions for the widest integer
4360b57cec5SDimitry Andric     //     type (v2i64).
4370b57cec5SDimitry Andric     if (VT.getScalarSizeInBits() % 8 == 0)
4380b57cec5SDimitry Andric       return TypeWidenVector;
4390b57cec5SDimitry Andric     return TargetLoweringBase::getPreferredVectorAction(VT);
4400b57cec5SDimitry Andric   }
441fe6060f1SDimitry Andric   unsigned
getNumRegisters(LLVMContext & Context,EVT VT,std::optional<MVT> RegisterVT)442fe6060f1SDimitry Andric   getNumRegisters(LLVMContext &Context, EVT VT,
443bdd1243dSDimitry Andric                   std::optional<MVT> RegisterVT) const override {
444fe6060f1SDimitry Andric     // i128 inline assembly operand.
44581ad6265SDimitry Andric     if (VT == MVT::i128 && RegisterVT && *RegisterVT == MVT::Untyped)
446fe6060f1SDimitry Andric       return 1;
447fe6060f1SDimitry Andric     return TargetLowering::getNumRegisters(Context, VT);
448fe6060f1SDimitry Andric   }
getRegisterTypeForCallingConv(LLVMContext & Context,CallingConv::ID CC,EVT VT)4495f757f3fSDimitry Andric   MVT getRegisterTypeForCallingConv(LLVMContext &Context, CallingConv::ID CC,
4505f757f3fSDimitry Andric                                     EVT VT) const override {
4515f757f3fSDimitry Andric     // 128-bit single-element vector types are passed like other vectors,
4525f757f3fSDimitry Andric     // not like their element type.
4535f757f3fSDimitry Andric     if (VT.isVector() && VT.getSizeInBits() == 128 &&
4545f757f3fSDimitry Andric         VT.getVectorNumElements() == 1)
4555f757f3fSDimitry Andric       return MVT::v16i8;
4565f757f3fSDimitry Andric     return TargetLowering::getRegisterTypeForCallingConv(Context, CC, VT);
4575f757f3fSDimitry Andric   }
isCheapToSpeculateCtlz(Type *)458bdd1243dSDimitry Andric   bool isCheapToSpeculateCtlz(Type *) const override { return true; }
isCheapToSpeculateCttz(Type *)4595f757f3fSDimitry Andric   bool isCheapToSpeculateCttz(Type *) const override { return true; }
preferZeroCompareBranch()460fe6060f1SDimitry Andric   bool preferZeroCompareBranch() const override { return true; }
isMaskAndCmp0FoldingBeneficial(const Instruction & AndI)461fe6060f1SDimitry Andric   bool isMaskAndCmp0FoldingBeneficial(const Instruction &AndI) const override {
462fe6060f1SDimitry Andric     ConstantInt* Mask = dyn_cast<ConstantInt>(AndI.getOperand(1));
463fe6060f1SDimitry Andric     return Mask && Mask->getValue().isIntN(16);
464fe6060f1SDimitry Andric   }
convertSetCCLogicToBitwiseLogic(EVT VT)465fe6060f1SDimitry Andric   bool convertSetCCLogicToBitwiseLogic(EVT VT) const override {
466fe6060f1SDimitry Andric     return VT.isScalarInteger();
467fe6060f1SDimitry Andric   }
4680b57cec5SDimitry Andric   EVT getSetCCResultType(const DataLayout &DL, LLVMContext &,
4690b57cec5SDimitry Andric                          EVT) const override;
470480093f4SDimitry Andric   bool isFMAFasterThanFMulAndFAdd(const MachineFunction &MF,
471480093f4SDimitry Andric                                   EVT VT) const override;
4720b57cec5SDimitry Andric   bool isFPImmLegal(const APFloat &Imm, EVT VT,
4730b57cec5SDimitry Andric                     bool ForCodeSize) const override;
ShouldShrinkFPConstant(EVT VT)4741fd87a68SDimitry Andric   bool ShouldShrinkFPConstant(EVT VT) const override {
4751fd87a68SDimitry Andric     // Do not shrink 64-bit FP constpool entries since LDEB is slower than
4761fd87a68SDimitry Andric     // LD, and having the full constant in memory enables reg/mem opcodes.
4771fd87a68SDimitry Andric     return VT != MVT::f64;
4781fd87a68SDimitry Andric   }
479bdd1243dSDimitry Andric   bool hasInlineStackProbe(const MachineFunction &MF) const override;
480*0fca6ea1SDimitry Andric   AtomicExpansionKind shouldCastAtomicLoadInIR(LoadInst *LI) const override;
481*0fca6ea1SDimitry Andric   AtomicExpansionKind shouldCastAtomicStoreInIR(StoreInst *SI) const override;
4825f757f3fSDimitry Andric   AtomicExpansionKind
4835f757f3fSDimitry Andric   shouldExpandAtomicRMWInIR(AtomicRMWInst *RMW) const override;
4840b57cec5SDimitry Andric   bool isLegalICmpImmediate(int64_t Imm) const override;
4850b57cec5SDimitry Andric   bool isLegalAddImmediate(int64_t Imm) const override;
4860b57cec5SDimitry Andric   bool isLegalAddressingMode(const DataLayout &DL, const AddrMode &AM, Type *Ty,
4870b57cec5SDimitry Andric                              unsigned AS,
4880b57cec5SDimitry Andric                              Instruction *I = nullptr) const override;
489fe6060f1SDimitry Andric   bool allowsMisalignedMemoryAccesses(EVT VT, unsigned AS, Align Alignment,
4900b57cec5SDimitry Andric                                       MachineMemOperand::Flags Flags,
491bdd1243dSDimitry Andric                                       unsigned *Fast) const override;
49281ad6265SDimitry Andric   bool
49381ad6265SDimitry Andric   findOptimalMemOpLowering(std::vector<EVT> &MemOps, unsigned Limit,
49481ad6265SDimitry Andric                            const MemOp &Op, unsigned DstAS, unsigned SrcAS,
49581ad6265SDimitry Andric                            const AttributeList &FuncAttributes) const override;
49681ad6265SDimitry Andric   EVT getOptimalMemOpType(const MemOp &Op,
49781ad6265SDimitry Andric                           const AttributeList &FuncAttributes) const override;
4980b57cec5SDimitry Andric   bool isTruncateFree(Type *, Type *) const override;
isTruncateFree(EVT,EVT)4990b57cec5SDimitry Andric   bool isTruncateFree(EVT, EVT) const override;
5005ffd83dbSDimitry Andric 
5015ffd83dbSDimitry Andric   bool shouldFormOverflowOp(unsigned Opcode, EVT VT,
5025ffd83dbSDimitry Andric                             bool MathUsed) const override {
5035ffd83dbSDimitry Andric     // Form add and sub with overflow intrinsics regardless of any extra
5045ffd83dbSDimitry Andric     // users of the math result.
5055ffd83dbSDimitry Andric     return VT == MVT::i32 || VT == MVT::i64;
5065ffd83dbSDimitry Andric   }
5075ffd83dbSDimitry Andric 
shouldConsiderGEPOffsetSplit()50881ad6265SDimitry Andric   bool shouldConsiderGEPOffsetSplit() const override { return true; }
50981ad6265SDimitry Andric 
shouldExpandCmpUsingSelects()510*0fca6ea1SDimitry Andric   bool shouldExpandCmpUsingSelects() const override { return true; }
511*0fca6ea1SDimitry Andric 
5120b57cec5SDimitry Andric   const char *getTargetNodeName(unsigned Opcode) const override;
5130b57cec5SDimitry Andric   std::pair<unsigned, const TargetRegisterClass *>
5140b57cec5SDimitry Andric   getRegForInlineAsmConstraint(const TargetRegisterInfo *TRI,
5150b57cec5SDimitry Andric                                StringRef Constraint, MVT VT) const override;
5160b57cec5SDimitry Andric   TargetLowering::ConstraintType
5170b57cec5SDimitry Andric   getConstraintType(StringRef Constraint) const override;
5180b57cec5SDimitry Andric   TargetLowering::ConstraintWeight
5190b57cec5SDimitry Andric     getSingleConstraintMatchWeight(AsmOperandInfo &info,
5200b57cec5SDimitry Andric                                    const char *constraint) const override;
5215f757f3fSDimitry Andric   void LowerAsmOperandForConstraint(SDValue Op, StringRef Constraint,
5220b57cec5SDimitry Andric                                     std::vector<SDValue> &Ops,
5230b57cec5SDimitry Andric                                     SelectionDAG &DAG) const override;
5240b57cec5SDimitry Andric 
5255f757f3fSDimitry Andric   InlineAsm::ConstraintCode
getInlineAsmMemConstraint(StringRef ConstraintCode)5265f757f3fSDimitry Andric   getInlineAsmMemConstraint(StringRef ConstraintCode) const override {
5270b57cec5SDimitry Andric     if (ConstraintCode.size() == 1) {
5280b57cec5SDimitry Andric       switch(ConstraintCode[0]) {
5290b57cec5SDimitry Andric       default:
5300b57cec5SDimitry Andric         break;
5310b57cec5SDimitry Andric       case 'o':
5325f757f3fSDimitry Andric         return InlineAsm::ConstraintCode::o;
5330b57cec5SDimitry Andric       case 'Q':
5345f757f3fSDimitry Andric         return InlineAsm::ConstraintCode::Q;
5350b57cec5SDimitry Andric       case 'R':
5365f757f3fSDimitry Andric         return InlineAsm::ConstraintCode::R;
5370b57cec5SDimitry Andric       case 'S':
5385f757f3fSDimitry Andric         return InlineAsm::ConstraintCode::S;
5390b57cec5SDimitry Andric       case 'T':
5405f757f3fSDimitry Andric         return InlineAsm::ConstraintCode::T;
5410b57cec5SDimitry Andric       }
54281ad6265SDimitry Andric     } else if (ConstraintCode.size() == 2 && ConstraintCode[0] == 'Z') {
54381ad6265SDimitry Andric       switch (ConstraintCode[1]) {
54481ad6265SDimitry Andric       default:
54581ad6265SDimitry Andric         break;
54681ad6265SDimitry Andric       case 'Q':
5475f757f3fSDimitry Andric         return InlineAsm::ConstraintCode::ZQ;
54881ad6265SDimitry Andric       case 'R':
5495f757f3fSDimitry Andric         return InlineAsm::ConstraintCode::ZR;
55081ad6265SDimitry Andric       case 'S':
5515f757f3fSDimitry Andric         return InlineAsm::ConstraintCode::ZS;
55281ad6265SDimitry Andric       case 'T':
5535f757f3fSDimitry Andric         return InlineAsm::ConstraintCode::ZT;
55481ad6265SDimitry Andric       }
5550b57cec5SDimitry Andric     }
5560b57cec5SDimitry Andric     return TargetLowering::getInlineAsmMemConstraint(ConstraintCode);
5570b57cec5SDimitry Andric   }
5580b57cec5SDimitry Andric 
5595ffd83dbSDimitry Andric   Register getRegisterByName(const char *RegName, LLT VT,
5605ffd83dbSDimitry Andric                              const MachineFunction &MF) const override;
5615ffd83dbSDimitry Andric 
5620b57cec5SDimitry Andric   /// If a physical register, this returns the register that receives the
5630b57cec5SDimitry Andric   /// exception address on entry to an EH pad.
5645ffd83dbSDimitry Andric   Register
565cb14a3feSDimitry Andric   getExceptionPointerRegister(const Constant *PersonalityFn) const override;
5660b57cec5SDimitry Andric 
5670b57cec5SDimitry Andric   /// If a physical register, this returns the register that receives the
5680b57cec5SDimitry Andric   /// exception typeid on entry to a landing pad.
5695ffd83dbSDimitry Andric   Register
570cb14a3feSDimitry Andric   getExceptionSelectorRegister(const Constant *PersonalityFn) const override;
5710b57cec5SDimitry Andric 
5720b57cec5SDimitry Andric   /// Override to support customized stack guard loading.
useLoadStackGuardNode()5730b57cec5SDimitry Andric   bool useLoadStackGuardNode() const override {
5740b57cec5SDimitry Andric     return true;
5750b57cec5SDimitry Andric   }
insertSSPDeclarations(Module & M)5760b57cec5SDimitry Andric   void insertSSPDeclarations(Module &M) const override {
5770b57cec5SDimitry Andric   }
5780b57cec5SDimitry Andric 
5790b57cec5SDimitry Andric   MachineBasicBlock *
5800b57cec5SDimitry Andric   EmitInstrWithCustomInserter(MachineInstr &MI,
5810b57cec5SDimitry Andric                               MachineBasicBlock *BB) const override;
5820b57cec5SDimitry Andric   SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const override;
5830b57cec5SDimitry Andric   void LowerOperationWrapper(SDNode *N, SmallVectorImpl<SDValue> &Results,
5840b57cec5SDimitry Andric                              SelectionDAG &DAG) const override;
5850b57cec5SDimitry Andric   void ReplaceNodeResults(SDNode *N, SmallVectorImpl<SDValue>&Results,
5860b57cec5SDimitry Andric                           SelectionDAG &DAG) const override;
5870b57cec5SDimitry Andric   const MCPhysReg *getScratchRegisters(CallingConv::ID CC) const override;
5880b57cec5SDimitry Andric   bool allowTruncateForTailCall(Type *, Type *) const override;
5890b57cec5SDimitry Andric   bool mayBeEmittedAsTailCall(const CallInst *CI) const override;
590bdd1243dSDimitry Andric   bool splitValueIntoRegisterParts(
591bdd1243dSDimitry Andric       SelectionDAG & DAG, const SDLoc &DL, SDValue Val, SDValue *Parts,
592bdd1243dSDimitry Andric       unsigned NumParts, MVT PartVT, std::optional<CallingConv::ID> CC)
593bdd1243dSDimitry Andric       const override;
594bdd1243dSDimitry Andric   SDValue joinRegisterPartsIntoValue(
595bdd1243dSDimitry Andric       SelectionDAG & DAG, const SDLoc &DL, const SDValue *Parts,
596bdd1243dSDimitry Andric       unsigned NumParts, MVT PartVT, EVT ValueVT,
597bdd1243dSDimitry Andric       std::optional<CallingConv::ID> CC) const override;
5980b57cec5SDimitry Andric   SDValue LowerFormalArguments(SDValue Chain, CallingConv::ID CallConv,
5990b57cec5SDimitry Andric                                bool isVarArg,
6000b57cec5SDimitry Andric                                const SmallVectorImpl<ISD::InputArg> &Ins,
6010b57cec5SDimitry Andric                                const SDLoc &DL, SelectionDAG &DAG,
6020b57cec5SDimitry Andric                                SmallVectorImpl<SDValue> &InVals) const override;
6030b57cec5SDimitry Andric   SDValue LowerCall(CallLoweringInfo &CLI,
6040b57cec5SDimitry Andric                     SmallVectorImpl<SDValue> &InVals) const override;
6050b57cec5SDimitry Andric 
60681ad6265SDimitry Andric   std::pair<SDValue, SDValue>
60781ad6265SDimitry Andric   makeExternalCall(SDValue Chain, SelectionDAG &DAG, const char *CalleeName,
60881ad6265SDimitry Andric                    EVT RetVT, ArrayRef<SDValue> Ops, CallingConv::ID CallConv,
60981ad6265SDimitry Andric                    bool IsSigned, SDLoc DL, bool DoesNotReturn,
61081ad6265SDimitry Andric                    bool IsReturnValueUsed) const;
61181ad6265SDimitry Andric 
6120b57cec5SDimitry Andric   bool CanLowerReturn(CallingConv::ID CallConv, MachineFunction &MF,
6130b57cec5SDimitry Andric                       bool isVarArg,
6140b57cec5SDimitry Andric                       const SmallVectorImpl<ISD::OutputArg> &Outs,
6150b57cec5SDimitry Andric                       LLVMContext &Context) const override;
6160b57cec5SDimitry Andric   SDValue LowerReturn(SDValue Chain, CallingConv::ID CallConv, bool IsVarArg,
6170b57cec5SDimitry Andric                       const SmallVectorImpl<ISD::OutputArg> &Outs,
6180b57cec5SDimitry Andric                       const SmallVectorImpl<SDValue> &OutVals, const SDLoc &DL,
6190b57cec5SDimitry Andric                       SelectionDAG &DAG) const override;
6200b57cec5SDimitry Andric   SDValue PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const override;
6210b57cec5SDimitry Andric 
6220b57cec5SDimitry Andric   /// Determine which of the bits specified in Mask are known to be either
6230b57cec5SDimitry Andric   /// zero or one and return them in the KnownZero/KnownOne bitsets.
6240b57cec5SDimitry Andric   void computeKnownBitsForTargetNode(const SDValue Op,
6250b57cec5SDimitry Andric                                      KnownBits &Known,
6260b57cec5SDimitry Andric                                      const APInt &DemandedElts,
6270b57cec5SDimitry Andric                                      const SelectionDAG &DAG,
6280b57cec5SDimitry Andric                                      unsigned Depth = 0) const override;
6290b57cec5SDimitry Andric 
6300b57cec5SDimitry Andric   /// Determine the number of bits in the operation that are sign bits.
6310b57cec5SDimitry Andric   unsigned ComputeNumSignBitsForTargetNode(SDValue Op,
6320b57cec5SDimitry Andric                                            const APInt &DemandedElts,
6330b57cec5SDimitry Andric                                            const SelectionDAG &DAG,
6340b57cec5SDimitry Andric                                            unsigned Depth) const override;
6350b57cec5SDimitry Andric 
63606c3fb27SDimitry Andric   bool isGuaranteedNotToBeUndefOrPoisonForTargetNode(
63706c3fb27SDimitry Andric       SDValue Op, const APInt &DemandedElts, const SelectionDAG &DAG,
63806c3fb27SDimitry Andric       bool PoisonOnly, unsigned Depth) const override;
63906c3fb27SDimitry Andric 
getExtendForAtomicOps()6400b57cec5SDimitry Andric   ISD::NodeType getExtendForAtomicOps() const override {
6410b57cec5SDimitry Andric     return ISD::ANY_EXTEND;
6420b57cec5SDimitry Andric   }
getExtendForAtomicCmpSwapArg()643fe6060f1SDimitry Andric   ISD::NodeType getExtendForAtomicCmpSwapArg() const override {
644fe6060f1SDimitry Andric     return ISD::ZERO_EXTEND;
645fe6060f1SDimitry Andric   }
6460b57cec5SDimitry Andric 
supportSwiftError()6470b57cec5SDimitry Andric   bool supportSwiftError() const override {
6480b57cec5SDimitry Andric     return true;
6490b57cec5SDimitry Andric   }
6500b57cec5SDimitry Andric 
651bdd1243dSDimitry Andric   unsigned getStackProbeSize(const MachineFunction &MF) const;
6525ffd83dbSDimitry Andric 
6530b57cec5SDimitry Andric private:
6540b57cec5SDimitry Andric   const SystemZSubtarget &Subtarget;
6550b57cec5SDimitry Andric 
6560b57cec5SDimitry Andric   // Implement LowerOperation for individual opcodes.
6570b57cec5SDimitry Andric   SDValue getVectorCmp(SelectionDAG &DAG, unsigned Opcode,
6580b57cec5SDimitry Andric                        const SDLoc &DL, EVT VT,
659480093f4SDimitry Andric                        SDValue CmpOp0, SDValue CmpOp1, SDValue Chain) const;
6600b57cec5SDimitry Andric   SDValue lowerVectorSETCC(SelectionDAG &DAG, const SDLoc &DL,
6610b57cec5SDimitry Andric                            EVT VT, ISD::CondCode CC,
662480093f4SDimitry Andric                            SDValue CmpOp0, SDValue CmpOp1,
663480093f4SDimitry Andric                            SDValue Chain = SDValue(),
664480093f4SDimitry Andric                            bool IsSignaling = false) const;
6650b57cec5SDimitry Andric   SDValue lowerSETCC(SDValue Op, SelectionDAG &DAG) const;
666480093f4SDimitry Andric   SDValue lowerSTRICT_FSETCC(SDValue Op, SelectionDAG &DAG,
667480093f4SDimitry Andric                              bool IsSignaling) const;
6680b57cec5SDimitry Andric   SDValue lowerBR_CC(SDValue Op, SelectionDAG &DAG) const;
6690b57cec5SDimitry Andric   SDValue lowerSELECT_CC(SDValue Op, SelectionDAG &DAG) const;
6700b57cec5SDimitry Andric   SDValue lowerGlobalAddress(GlobalAddressSDNode *Node,
6710b57cec5SDimitry Andric                              SelectionDAG &DAG) const;
6720b57cec5SDimitry Andric   SDValue lowerTLSGetOffset(GlobalAddressSDNode *Node,
6730b57cec5SDimitry Andric                             SelectionDAG &DAG, unsigned Opcode,
6740b57cec5SDimitry Andric                             SDValue GOTOffset) const;
6750b57cec5SDimitry Andric   SDValue lowerThreadPointer(const SDLoc &DL, SelectionDAG &DAG) const;
6760b57cec5SDimitry Andric   SDValue lowerGlobalTLSAddress(GlobalAddressSDNode *Node,
6770b57cec5SDimitry Andric                                 SelectionDAG &DAG) const;
6780b57cec5SDimitry Andric   SDValue lowerBlockAddress(BlockAddressSDNode *Node,
6790b57cec5SDimitry Andric                             SelectionDAG &DAG) const;
6800b57cec5SDimitry Andric   SDValue lowerJumpTable(JumpTableSDNode *JT, SelectionDAG &DAG) const;
6810b57cec5SDimitry Andric   SDValue lowerConstantPool(ConstantPoolSDNode *CP, SelectionDAG &DAG) const;
6820b57cec5SDimitry Andric   SDValue lowerFRAMEADDR(SDValue Op, SelectionDAG &DAG) const;
6830b57cec5SDimitry Andric   SDValue lowerRETURNADDR(SDValue Op, SelectionDAG &DAG) const;
6840b57cec5SDimitry Andric   SDValue lowerVASTART(SDValue Op, SelectionDAG &DAG) const;
68581ad6265SDimitry Andric   SDValue lowerVASTART_ELF(SDValue Op, SelectionDAG &DAG) const;
68681ad6265SDimitry Andric   SDValue lowerVASTART_XPLINK(SDValue Op, SelectionDAG &DAG) const;
6870b57cec5SDimitry Andric   SDValue lowerVACOPY(SDValue Op, SelectionDAG &DAG) const;
6880b57cec5SDimitry Andric   SDValue lowerDYNAMIC_STACKALLOC(SDValue Op, SelectionDAG &DAG) const;
68981ad6265SDimitry Andric   SDValue lowerDYNAMIC_STACKALLOC_ELF(SDValue Op, SelectionDAG &DAG) const;
69081ad6265SDimitry Andric   SDValue lowerDYNAMIC_STACKALLOC_XPLINK(SDValue Op, SelectionDAG &DAG) const;
6910b57cec5SDimitry Andric   SDValue lowerGET_DYNAMIC_AREA_OFFSET(SDValue Op, SelectionDAG &DAG) const;
6920b57cec5SDimitry Andric   SDValue lowerSMUL_LOHI(SDValue Op, SelectionDAG &DAG) const;
6930b57cec5SDimitry Andric   SDValue lowerUMUL_LOHI(SDValue Op, SelectionDAG &DAG) const;
6940b57cec5SDimitry Andric   SDValue lowerSDIVREM(SDValue Op, SelectionDAG &DAG) const;
6950b57cec5SDimitry Andric   SDValue lowerUDIVREM(SDValue Op, SelectionDAG &DAG) const;
6960b57cec5SDimitry Andric   SDValue lowerXALUO(SDValue Op, SelectionDAG &DAG) const;
69706c3fb27SDimitry Andric   SDValue lowerUADDSUBO_CARRY(SDValue Op, SelectionDAG &DAG) const;
6980b57cec5SDimitry Andric   SDValue lowerBITCAST(SDValue Op, SelectionDAG &DAG) const;
6990b57cec5SDimitry Andric   SDValue lowerOR(SDValue Op, SelectionDAG &DAG) const;
7000b57cec5SDimitry Andric   SDValue lowerCTPOP(SDValue Op, SelectionDAG &DAG) const;
701*0fca6ea1SDimitry Andric   SDValue lowerVECREDUCE_ADD(SDValue Op, SelectionDAG &DAG) const;
7020b57cec5SDimitry Andric   SDValue lowerATOMIC_FENCE(SDValue Op, SelectionDAG &DAG) const;
703*0fca6ea1SDimitry Andric   SDValue lowerATOMIC_LDST_I128(SDValue Op, SelectionDAG &DAG) const;
7040b57cec5SDimitry Andric   SDValue lowerATOMIC_LOAD_OP(SDValue Op, SelectionDAG &DAG,
7050b57cec5SDimitry Andric                               unsigned Opcode) const;
7060b57cec5SDimitry Andric   SDValue lowerATOMIC_LOAD_SUB(SDValue Op, SelectionDAG &DAG) const;
7070b57cec5SDimitry Andric   SDValue lowerATOMIC_CMP_SWAP(SDValue Op, SelectionDAG &DAG) const;
7080b57cec5SDimitry Andric   SDValue lowerSTACKSAVE(SDValue Op, SelectionDAG &DAG) const;
7090b57cec5SDimitry Andric   SDValue lowerSTACKRESTORE(SDValue Op, SelectionDAG &DAG) const;
7100b57cec5SDimitry Andric   SDValue lowerPREFETCH(SDValue Op, SelectionDAG &DAG) const;
7110b57cec5SDimitry Andric   SDValue lowerINTRINSIC_W_CHAIN(SDValue Op, SelectionDAG &DAG) const;
7120b57cec5SDimitry Andric   SDValue lowerINTRINSIC_WO_CHAIN(SDValue Op, SelectionDAG &DAG) const;
7130b57cec5SDimitry Andric   bool isVectorElementLoad(SDValue Op) const;
7140b57cec5SDimitry Andric   SDValue buildVector(SelectionDAG &DAG, const SDLoc &DL, EVT VT,
7150b57cec5SDimitry Andric                       SmallVectorImpl<SDValue> &Elems) const;
7160b57cec5SDimitry Andric   SDValue lowerBUILD_VECTOR(SDValue Op, SelectionDAG &DAG) const;
7170b57cec5SDimitry Andric   SDValue lowerVECTOR_SHUFFLE(SDValue Op, SelectionDAG &DAG) const;
7180b57cec5SDimitry Andric   SDValue lowerSCALAR_TO_VECTOR(SDValue Op, SelectionDAG &DAG) const;
7190b57cec5SDimitry Andric   SDValue lowerINSERT_VECTOR_ELT(SDValue Op, SelectionDAG &DAG) const;
7200b57cec5SDimitry Andric   SDValue lowerEXTRACT_VECTOR_ELT(SDValue Op, SelectionDAG &DAG) const;
7215ffd83dbSDimitry Andric   SDValue lowerSIGN_EXTEND_VECTOR_INREG(SDValue Op, SelectionDAG &DAG) const;
7225ffd83dbSDimitry Andric   SDValue lowerZERO_EXTEND_VECTOR_INREG(SDValue Op, SelectionDAG &DAG) const;
7230b57cec5SDimitry Andric   SDValue lowerShift(SDValue Op, SelectionDAG &DAG, unsigned ByScalar) const;
72481ad6265SDimitry Andric   SDValue lowerIS_FPCLASS(SDValue Op, SelectionDAG &DAG) const;
725bdd1243dSDimitry Andric   SDValue lowerGET_ROUNDING(SDValue Op, SelectionDAG &DAG) const;
726*0fca6ea1SDimitry Andric   SDValue lowerREADCYCLECOUNTER(SDValue Op, SelectionDAG &DAG) const;
7270b57cec5SDimitry Andric 
7280b57cec5SDimitry Andric   bool canTreatAsByteVector(EVT VT) const;
7290b57cec5SDimitry Andric   SDValue combineExtract(const SDLoc &DL, EVT ElemVT, EVT VecVT, SDValue OrigOp,
7300b57cec5SDimitry Andric                          unsigned Index, DAGCombinerInfo &DCI,
7310b57cec5SDimitry Andric                          bool Force) const;
7320b57cec5SDimitry Andric   SDValue combineTruncateExtract(const SDLoc &DL, EVT TruncVT, SDValue Op,
7330b57cec5SDimitry Andric                                  DAGCombinerInfo &DCI) const;
7340b57cec5SDimitry Andric   SDValue combineZERO_EXTEND(SDNode *N, DAGCombinerInfo &DCI) const;
7350b57cec5SDimitry Andric   SDValue combineSIGN_EXTEND(SDNode *N, DAGCombinerInfo &DCI) const;
7360b57cec5SDimitry Andric   SDValue combineSIGN_EXTEND_INREG(SDNode *N, DAGCombinerInfo &DCI) const;
7370b57cec5SDimitry Andric   SDValue combineMERGE(SDNode *N, DAGCombinerInfo &DCI) const;
7380b57cec5SDimitry Andric   bool canLoadStoreByteSwapped(EVT VT) const;
7390b57cec5SDimitry Andric   SDValue combineLOAD(SDNode *N, DAGCombinerInfo &DCI) const;
7400b57cec5SDimitry Andric   SDValue combineSTORE(SDNode *N, DAGCombinerInfo &DCI) const;
7410b57cec5SDimitry Andric   SDValue combineVECTOR_SHUFFLE(SDNode *N, DAGCombinerInfo &DCI) const;
7420b57cec5SDimitry Andric   SDValue combineEXTRACT_VECTOR_ELT(SDNode *N, DAGCombinerInfo &DCI) const;
7430b57cec5SDimitry Andric   SDValue combineJOIN_DWORDS(SDNode *N, DAGCombinerInfo &DCI) const;
7440b57cec5SDimitry Andric   SDValue combineFP_ROUND(SDNode *N, DAGCombinerInfo &DCI) const;
7450b57cec5SDimitry Andric   SDValue combineFP_EXTEND(SDNode *N, DAGCombinerInfo &DCI) const;
7465ffd83dbSDimitry Andric   SDValue combineINT_TO_FP(SDNode *N, DAGCombinerInfo &DCI) const;
7470b57cec5SDimitry Andric   SDValue combineBSWAP(SDNode *N, DAGCombinerInfo &DCI) const;
7480b57cec5SDimitry Andric   SDValue combineBR_CCMASK(SDNode *N, DAGCombinerInfo &DCI) const;
7490b57cec5SDimitry Andric   SDValue combineSELECT_CCMASK(SDNode *N, DAGCombinerInfo &DCI) const;
7500b57cec5SDimitry Andric   SDValue combineGET_CCMASK(SDNode *N, DAGCombinerInfo &DCI) const;
7510b57cec5SDimitry Andric   SDValue combineIntDIVREM(SDNode *N, DAGCombinerInfo &DCI) const;
7525ffd83dbSDimitry Andric   SDValue combineINTRINSIC(SDNode *N, DAGCombinerInfo &DCI) const;
7530b57cec5SDimitry Andric 
7540b57cec5SDimitry Andric   SDValue unwrapAddress(SDValue N) const override;
7550b57cec5SDimitry Andric 
7560b57cec5SDimitry Andric   // If the last instruction before MBBI in MBB was some form of COMPARE,
7570b57cec5SDimitry Andric   // try to replace it with a COMPARE AND BRANCH just before MBBI.
7580b57cec5SDimitry Andric   // CCMask and Target are the BRC-like operands for the branch.
7590b57cec5SDimitry Andric   // Return true if the change was made.
7600b57cec5SDimitry Andric   bool convertPrevCompareToBranch(MachineBasicBlock *MBB,
7610b57cec5SDimitry Andric                                   MachineBasicBlock::iterator MBBI,
7620b57cec5SDimitry Andric                                   unsigned CCMask,
7630b57cec5SDimitry Andric                                   MachineBasicBlock *Target) const;
7640b57cec5SDimitry Andric 
7650b57cec5SDimitry Andric   // Implement EmitInstrWithCustomInserter for individual operation types.
766*0fca6ea1SDimitry Andric   MachineBasicBlock *emitAdjCallStack(MachineInstr &MI,
767*0fca6ea1SDimitry Andric                                       MachineBasicBlock *BB) const;
7680b57cec5SDimitry Andric   MachineBasicBlock *emitSelect(MachineInstr &MI, MachineBasicBlock *BB) const;
7690b57cec5SDimitry Andric   MachineBasicBlock *emitCondStore(MachineInstr &MI, MachineBasicBlock *BB,
7700b57cec5SDimitry Andric                                    unsigned StoreOpcode, unsigned STOCOpcode,
7710b57cec5SDimitry Andric                                    bool Invert) const;
7725f757f3fSDimitry Andric   MachineBasicBlock *emitICmp128Hi(MachineInstr &MI, MachineBasicBlock *BB,
7735f757f3fSDimitry Andric                                    bool Unsigned) const;
7740b57cec5SDimitry Andric   MachineBasicBlock *emitPair128(MachineInstr &MI,
7750b57cec5SDimitry Andric                                  MachineBasicBlock *MBB) const;
7760b57cec5SDimitry Andric   MachineBasicBlock *emitExt128(MachineInstr &MI, MachineBasicBlock *MBB,
7770b57cec5SDimitry Andric                                 bool ClearEven) const;
7780b57cec5SDimitry Andric   MachineBasicBlock *emitAtomicLoadBinary(MachineInstr &MI,
7790b57cec5SDimitry Andric                                           MachineBasicBlock *BB,
7805f757f3fSDimitry Andric                                           unsigned BinOpcode,
7810b57cec5SDimitry Andric                                           bool Invert = false) const;
7820b57cec5SDimitry Andric   MachineBasicBlock *emitAtomicLoadMinMax(MachineInstr &MI,
7830b57cec5SDimitry Andric                                           MachineBasicBlock *MBB,
7840b57cec5SDimitry Andric                                           unsigned CompareOpcode,
7855f757f3fSDimitry Andric                                           unsigned KeepOldMask) const;
7860b57cec5SDimitry Andric   MachineBasicBlock *emitAtomicCmpSwapW(MachineInstr &MI,
7870b57cec5SDimitry Andric                                         MachineBasicBlock *BB) const;
7880b57cec5SDimitry Andric   MachineBasicBlock *emitMemMemWrapper(MachineInstr &MI, MachineBasicBlock *BB,
7890eae32dcSDimitry Andric                                        unsigned Opcode,
7900eae32dcSDimitry Andric                                        bool IsMemset = false) const;
7910b57cec5SDimitry Andric   MachineBasicBlock *emitStringWrapper(MachineInstr &MI, MachineBasicBlock *BB,
7920b57cec5SDimitry Andric                                        unsigned Opcode) const;
7930b57cec5SDimitry Andric   MachineBasicBlock *emitTransactionBegin(MachineInstr &MI,
7940b57cec5SDimitry Andric                                           MachineBasicBlock *MBB,
7950b57cec5SDimitry Andric                                           unsigned Opcode, bool NoFloat) const;
7960b57cec5SDimitry Andric   MachineBasicBlock *emitLoadAndTestCmp0(MachineInstr &MI,
7970b57cec5SDimitry Andric                                          MachineBasicBlock *MBB,
7980b57cec5SDimitry Andric                                          unsigned Opcode) const;
7995ffd83dbSDimitry Andric   MachineBasicBlock *emitProbedAlloca(MachineInstr &MI,
8005ffd83dbSDimitry Andric                                       MachineBasicBlock *MBB) const;
8010b57cec5SDimitry Andric 
802e8d8bef9SDimitry Andric   SDValue getBackchainAddress(SDValue SP, SelectionDAG &DAG) const;
803e8d8bef9SDimitry Andric 
8045ffd83dbSDimitry Andric   MachineMemOperand::Flags
8055ffd83dbSDimitry Andric   getTargetMMOFlags(const Instruction &I) const override;
8060b57cec5SDimitry Andric   const TargetRegisterClass *getRepRegClassFor(MVT VT) const override;
8070b57cec5SDimitry Andric };
8080b57cec5SDimitry Andric 
8090b57cec5SDimitry Andric struct SystemZVectorConstantInfo {
8100b57cec5SDimitry Andric private:
8110b57cec5SDimitry Andric   APInt IntBits;             // The 128 bits as an integer.
8120b57cec5SDimitry Andric   APInt SplatBits;           // Smallest splat value.
8130b57cec5SDimitry Andric   APInt SplatUndef;          // Bits correspoding to undef operands of the BVN.
8140b57cec5SDimitry Andric   unsigned SplatBitSize = 0;
8150b57cec5SDimitry Andric   bool isFP128 = false;
8160b57cec5SDimitry Andric public:
8170b57cec5SDimitry Andric   unsigned Opcode = 0;
8180b57cec5SDimitry Andric   SmallVector<unsigned, 2> OpVals;
8190b57cec5SDimitry Andric   MVT VecVT;
82081ad6265SDimitry Andric   SystemZVectorConstantInfo(APInt IntImm);
SystemZVectorConstantInfoSystemZVectorConstantInfo82181ad6265SDimitry Andric   SystemZVectorConstantInfo(APFloat FPImm)
82281ad6265SDimitry Andric       : SystemZVectorConstantInfo(FPImm.bitcastToAPInt()) {
82381ad6265SDimitry Andric     isFP128 = (&FPImm.getSemantics() == &APFloat::IEEEquad());
82481ad6265SDimitry Andric   }
8250b57cec5SDimitry Andric   SystemZVectorConstantInfo(BuildVectorSDNode *BVN);
8260b57cec5SDimitry Andric   bool isVectorConstantLegal(const SystemZSubtarget &Subtarget);
8270b57cec5SDimitry Andric };
8280b57cec5SDimitry Andric 
8290b57cec5SDimitry Andric } // end namespace llvm
8300b57cec5SDimitry Andric 
8310b57cec5SDimitry Andric #endif
832