11d09d56fe1e3f3faadd4bf4ccf3e585ddb3c3b07Ulrich Weigand//===-- SystemZISelLowering.h - SystemZ DAG lowering interface --*- C++ -*-===//
21d09d56fe1e3f3faadd4bf4ccf3e585ddb3c3b07Ulrich Weigand//
31d09d56fe1e3f3faadd4bf4ccf3e585ddb3c3b07Ulrich Weigand//                     The LLVM Compiler Infrastructure
41d09d56fe1e3f3faadd4bf4ccf3e585ddb3c3b07Ulrich Weigand//
51d09d56fe1e3f3faadd4bf4ccf3e585ddb3c3b07Ulrich Weigand// This file is distributed under the University of Illinois Open Source
61d09d56fe1e3f3faadd4bf4ccf3e585ddb3c3b07Ulrich Weigand// License. See LICENSE.TXT for details.
71d09d56fe1e3f3faadd4bf4ccf3e585ddb3c3b07Ulrich Weigand//
81d09d56fe1e3f3faadd4bf4ccf3e585ddb3c3b07Ulrich Weigand//===----------------------------------------------------------------------===//
91d09d56fe1e3f3faadd4bf4ccf3e585ddb3c3b07Ulrich Weigand//
101d09d56fe1e3f3faadd4bf4ccf3e585ddb3c3b07Ulrich Weigand// This file defines the interfaces that SystemZ uses to lower LLVM code into a
111d09d56fe1e3f3faadd4bf4ccf3e585ddb3c3b07Ulrich Weigand// selection DAG.
121d09d56fe1e3f3faadd4bf4ccf3e585ddb3c3b07Ulrich Weigand//
131d09d56fe1e3f3faadd4bf4ccf3e585ddb3c3b07Ulrich Weigand//===----------------------------------------------------------------------===//
141d09d56fe1e3f3faadd4bf4ccf3e585ddb3c3b07Ulrich Weigand
151d09d56fe1e3f3faadd4bf4ccf3e585ddb3c3b07Ulrich Weigand#ifndef LLVM_TARGET_SystemZ_ISELLOWERING_H
161d09d56fe1e3f3faadd4bf4ccf3e585ddb3c3b07Ulrich Weigand#define LLVM_TARGET_SystemZ_ISELLOWERING_H
171d09d56fe1e3f3faadd4bf4ccf3e585ddb3c3b07Ulrich Weigand
181d09d56fe1e3f3faadd4bf4ccf3e585ddb3c3b07Ulrich Weigand#include "SystemZ.h"
19d50bcb2162a529534da42748ab4a418bfc9aaf06Richard Sandiford#include "llvm/CodeGen/MachineBasicBlock.h"
201d09d56fe1e3f3faadd4bf4ccf3e585ddb3c3b07Ulrich Weigand#include "llvm/CodeGen/SelectionDAG.h"
211d09d56fe1e3f3faadd4bf4ccf3e585ddb3c3b07Ulrich Weigand#include "llvm/Target/TargetLowering.h"
221d09d56fe1e3f3faadd4bf4ccf3e585ddb3c3b07Ulrich Weigand
231d09d56fe1e3f3faadd4bf4ccf3e585ddb3c3b07Ulrich Weigandnamespace llvm {
241d09d56fe1e3f3faadd4bf4ccf3e585ddb3c3b07Ulrich Weigandnamespace SystemZISD {
2536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hinesenum {
2636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  FIRST_NUMBER = ISD::BUILTIN_OP_END,
2736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
2836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  // Return with a flag operand.  Operand 0 is the chain operand.
2936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  RET_FLAG,
3036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
3136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  // Calls a function.  Operand 0 is the chain operand and operand 1
3236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  // is the target address.  The arguments start at operand 2.
3336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  // There is an optional glue operand at the end.
3436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  CALL,
3536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  SIBCALL,
3636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
3736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  // Wraps a TargetGlobalAddress that should be loaded using PC-relative
3836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  // accesses (LARL).  Operand 0 is the address.
3936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  PCREL_WRAPPER,
4036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
4136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  // Used in cases where an offset is applied to a TargetGlobalAddress.
4236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  // Operand 0 is the full TargetGlobalAddress and operand 1 is a
4336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  // PCREL_WRAPPER for an anchor point.  This is used so that we can
4436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  // cheaply refer to either the full address or the anchor point
4536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  // as a register base.
4636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  PCREL_OFFSET,
4736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
4836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  // Integer absolute.
4936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  IABS,
5036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
5136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  // Integer comparisons.  There are three operands: the two values
5236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  // to compare, and an integer of type SystemZICMP.
5336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  ICMP,
5436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
5536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  // Floating-point comparisons.  The two operands are the values to compare.
5636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  FCMP,
5736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
5836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  // Test under mask.  The first operand is ANDed with the second operand
5936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  // and the condition codes are set on the result.  The third operand is
6036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  // a boolean that is true if the condition codes need to distinguish
6136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  // between CCMASK_TM_MIXED_MSB_0 and CCMASK_TM_MIXED_MSB_1 (which the
6236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  // register forms do but the memory forms don't).
6336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  TM,
6436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
6536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  // Branches if a condition is true.  Operand 0 is the chain operand;
6636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  // operand 1 is the 4-bit condition-code mask, with bit N in
6736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  // big-endian order meaning "branch if CC=N"; operand 2 is the
6836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  // target block and operand 3 is the flag operand.
6936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  BR_CCMASK,
7036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
7136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  // Selects between operand 0 and operand 1.  Operand 2 is the
7236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  // mask of condition-code values for which operand 0 should be
7336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  // chosen over operand 1; it has the same form as BR_CCMASK.
7436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  // Operand 3 is the flag operand.
7536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  SELECT_CCMASK,
7636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
7736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  // Evaluates to the gap between the stack pointer and the
7836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  // base of the dynamically-allocatable area.
7936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  ADJDYNALLOC,
8036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
8136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  // Extracts the value of a 32-bit access register.  Operand 0 is
8236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  // the number of the register.
8336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  EXTRACT_ACCESS,
8436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
8536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  // Wrappers around the ISD opcodes of the same name.  The output and
8636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  // first input operands are GR128s.  The trailing numbers are the
8736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  // widths of the second operand in bits.
8836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  UMUL_LOHI64,
8936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  SDIVREM32,
9036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  SDIVREM64,
9136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  UDIVREM32,
9236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  UDIVREM64,
9336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
9436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  // Use a series of MVCs to copy bytes from one memory location to another.
9536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  // The operands are:
9636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  // - the target address
9736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  // - the source address
9836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  // - the constant length
9936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  //
10036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  // This isn't a memory opcode because we'd need to attach two
10136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  // MachineMemOperands rather than one.
10236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  MVC,
10336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
10436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  // Like MVC, but implemented as a loop that handles X*256 bytes
10536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  // followed by straight-line code to handle the rest (if any).
10636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  // The value of X is passed as an additional operand.
10736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  MVC_LOOP,
10836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
10936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  // Similar to MVC and MVC_LOOP, but for logic operations (AND, OR, XOR).
11036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  NC,
11136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  NC_LOOP,
11236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  OC,
11336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  OC_LOOP,
11436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  XC,
11536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  XC_LOOP,
11636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
11736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  // Use CLC to compare two blocks of memory, with the same comments
11836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  // as for MVC and MVC_LOOP.
11936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  CLC,
12036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  CLC_LOOP,
12136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
12236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  // Use an MVST-based sequence to implement stpcpy().
12336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  STPCPY,
12436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
12536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  // Use a CLST-based sequence to implement strcmp().  The two input operands
12636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  // are the addresses of the strings to compare.
12736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  STRCMP,
12836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
12936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  // Use an SRST-based sequence to search a block of memory.  The first
13036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  // operand is the end address, the second is the start, and the third
13136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  // is the character to search for.  CC is set to 1 on success and 2
13236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  // on failure.
13336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  SEARCH_STRING,
13436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
13536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  // Store the CC value in bits 29 and 28 of an integer.
13636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  IPM,
13736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
13836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  // Perform a serialization operation.  (BCR 15,0 or BCR 14,0.)
13936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  SERIALIZE,
14036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
14136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  // Wrappers around the inner loop of an 8- or 16-bit ATOMIC_SWAP or
14236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  // ATOMIC_LOAD_<op>.
14336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  //
14436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  // Operand 0: the address of the containing 32-bit-aligned field
14536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  // Operand 1: the second operand of <op>, in the high bits of an i32
14636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  //            for everything except ATOMIC_SWAPW
14736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  // Operand 2: how many bits to rotate the i32 left to bring the first
14836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  //            operand into the high bits
14936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  // Operand 3: the negative of operand 2, for rotating the other way
15036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  // Operand 4: the width of the field in bits (8 or 16)
15136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  ATOMIC_SWAPW = ISD::FIRST_TARGET_MEMORY_OPCODE,
15236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  ATOMIC_LOADW_ADD,
15336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  ATOMIC_LOADW_SUB,
15436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  ATOMIC_LOADW_AND,
15536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  ATOMIC_LOADW_OR,
15636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  ATOMIC_LOADW_XOR,
15736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  ATOMIC_LOADW_NAND,
15836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  ATOMIC_LOADW_MIN,
15936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  ATOMIC_LOADW_MAX,
16036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  ATOMIC_LOADW_UMIN,
16136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  ATOMIC_LOADW_UMAX,
16236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
16336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  // A wrapper around the inner loop of an ATOMIC_CMP_SWAP.
16436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  //
16536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  // Operand 0: the address of the containing 32-bit-aligned field
16636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  // Operand 1: the compare value, in the low bits of an i32
16736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  // Operand 2: the swap value, in the low bits of an i32
16836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  // Operand 3: how many bits to rotate the i32 left to bring the first
16936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  //            operand into the high bits
17036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  // Operand 4: the negative of operand 2, for rotating the other way
17136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  // Operand 5: the width of the field in bits (8 or 16)
17236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  ATOMIC_CMP_SWAPW,
17336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
17436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  // Prefetch from the second operand using the 4-bit control code in
17536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  // the first operand.  The code is 1 for a load prefetch and 2 for
17636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  // a store prefetch.
17736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  PREFETCH
17836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines};
17936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
18036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines// Return true if OPCODE is some kind of PC-relative address.
18136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hinesinline bool isPCREL(unsigned Opcode) {
18236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  return Opcode == PCREL_WRAPPER || Opcode == PCREL_OFFSET;
1831d09d56fe1e3f3faadd4bf4ccf3e585ddb3c3b07Ulrich Weigand}
18436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines} // end namespace SystemZISD
1851d09d56fe1e3f3faadd4bf4ccf3e585ddb3c3b07Ulrich Weigand
186aff1c6427ce22125adfa29de4145030aa3214a2eRichard Sandifordnamespace SystemZICMP {
18736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines// Describes whether an integer comparison needs to be signed or unsigned,
18836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines// or whether either type is OK.
18936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hinesenum {
19036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Any,
19136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  UnsignedOnly,
19236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  SignedOnly
19336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines};
19436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines} // end namespace SystemZICMP
195aff1c6427ce22125adfa29de4145030aa3214a2eRichard Sandiford
1961d09d56fe1e3f3faadd4bf4ccf3e585ddb3c3b07Ulrich Weigandclass SystemZSubtarget;
1971d09d56fe1e3f3faadd4bf4ccf3e585ddb3c3b07Ulrich Weigandclass SystemZTargetMachine;
1981d09d56fe1e3f3faadd4bf4ccf3e585ddb3c3b07Ulrich Weigand
1991d09d56fe1e3f3faadd4bf4ccf3e585ddb3c3b07Ulrich Weigandclass SystemZTargetLowering : public TargetLowering {
2001d09d56fe1e3f3faadd4bf4ccf3e585ddb3c3b07Ulrich Weigandpublic:
201cd81d94322a39503e4a3e87b6ee03d4fcb3465fbStephen Hines  explicit SystemZTargetLowering(const TargetMachine &TM);
2021d09d56fe1e3f3faadd4bf4ccf3e585ddb3c3b07Ulrich Weigand
2031d09d56fe1e3f3faadd4bf4ccf3e585ddb3c3b07Ulrich Weigand  // Override TargetLowering.
20436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  MVT getScalarShiftAmountTy(EVT LHSTy) const override {
2051d09d56fe1e3f3faadd4bf4ccf3e585ddb3c3b07Ulrich Weigand    return MVT::i32;
2061d09d56fe1e3f3faadd4bf4ccf3e585ddb3c3b07Ulrich Weigand  }
20736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  EVT getSetCCResultType(LLVMContext &, EVT) const override;
20836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  bool isFMAFasterThanFMulAndFAdd(EVT VT) const override;
20936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  bool isFPImmLegal(const APFloat &Imm, EVT VT) const override;
21036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  bool isLegalAddressingMode(const AddrMode &AM, Type *Ty) const override;
21136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  bool allowsUnalignedMemoryAccesses(EVT VT, unsigned AS,
21236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines                                     bool *Fast) const override;
21336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  bool isTruncateFree(Type *, Type *) const override;
21436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  bool isTruncateFree(EVT, EVT) const override;
21536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  const char *getTargetNodeName(unsigned Opcode) const override;
21636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  std::pair<unsigned, const TargetRegisterClass *>
2171d09d56fe1e3f3faadd4bf4ccf3e585ddb3c3b07Ulrich Weigand    getRegForInlineAsmConstraint(const std::string &Constraint,
21836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines                                 MVT VT) const override;
21936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  TargetLowering::ConstraintType
22036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    getConstraintType(const std::string &Constraint) const override;
22136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  TargetLowering::ConstraintWeight
2221d09d56fe1e3f3faadd4bf4ccf3e585ddb3c3b07Ulrich Weigand    getSingleConstraintMatchWeight(AsmOperandInfo &info,
22336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines                                   const char *constraint) const override;
22436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  void LowerAsmOperandForConstraint(SDValue Op,
22536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines                                    std::string &Constraint,
22636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines                                    std::vector<SDValue> &Ops,
22736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines                                    SelectionDAG &DAG) const override;
22836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  MachineBasicBlock *EmitInstrWithCustomInserter(MachineInstr *MI,
22936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines                                                 MachineBasicBlock *BB) const
23036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    override;
23136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const override;
23236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  bool allowTruncateForTailCall(Type *, Type *) const override;
23336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  bool mayBeEmittedAsTailCall(CallInst *CI) const override;
23436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  SDValue LowerFormalArguments(SDValue Chain, CallingConv::ID CallConv,
23536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines                               bool isVarArg,
23636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines                               const SmallVectorImpl<ISD::InputArg> &Ins,
23736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines                               SDLoc DL, SelectionDAG &DAG,
23836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines                               SmallVectorImpl<SDValue> &InVals) const override;
23936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  SDValue LowerCall(CallLoweringInfo &CLI,
24036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines                    SmallVectorImpl<SDValue> &InVals) const override;
24136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
24236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  SDValue LowerReturn(SDValue Chain, CallingConv::ID CallConv, bool IsVarArg,
24336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines                      const SmallVectorImpl<ISD::OutputArg> &Outs,
24436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines                      const SmallVectorImpl<SDValue> &OutVals,
24536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines                      SDLoc DL, SelectionDAG &DAG) const override;
24636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  SDValue prepareVolatileOrAtomicLoad(SDValue Chain, SDLoc DL,
24736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines                                      SelectionDAG &DAG) const override;
24836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  SDValue PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const override;
2491d09d56fe1e3f3faadd4bf4ccf3e585ddb3c3b07Ulrich Weigand
2501d09d56fe1e3f3faadd4bf4ccf3e585ddb3c3b07Ulrich Weigandprivate:
2511d09d56fe1e3f3faadd4bf4ccf3e585ddb3c3b07Ulrich Weigand  const SystemZSubtarget &Subtarget;
2521d09d56fe1e3f3faadd4bf4ccf3e585ddb3c3b07Ulrich Weigand
2531d09d56fe1e3f3faadd4bf4ccf3e585ddb3c3b07Ulrich Weigand  // Implement LowerOperation for individual opcodes.
254d1a4f579bf45aec933c79292b6b9663581438738Richard Sandiford  SDValue lowerSETCC(SDValue Op, SelectionDAG &DAG) const;
2551d09d56fe1e3f3faadd4bf4ccf3e585ddb3c3b07Ulrich Weigand  SDValue lowerBR_CC(SDValue Op, SelectionDAG &DAG) const;
2561d09d56fe1e3f3faadd4bf4ccf3e585ddb3c3b07Ulrich Weigand  SDValue lowerSELECT_CC(SDValue Op, SelectionDAG &DAG) const;
2571d09d56fe1e3f3faadd4bf4ccf3e585ddb3c3b07Ulrich Weigand  SDValue lowerGlobalAddress(GlobalAddressSDNode *Node,
2581d09d56fe1e3f3faadd4bf4ccf3e585ddb3c3b07Ulrich Weigand                             SelectionDAG &DAG) const;
2591d09d56fe1e3f3faadd4bf4ccf3e585ddb3c3b07Ulrich Weigand  SDValue lowerGlobalTLSAddress(GlobalAddressSDNode *Node,
2601d09d56fe1e3f3faadd4bf4ccf3e585ddb3c3b07Ulrich Weigand                                SelectionDAG &DAG) const;
2611d09d56fe1e3f3faadd4bf4ccf3e585ddb3c3b07Ulrich Weigand  SDValue lowerBlockAddress(BlockAddressSDNode *Node,
2621d09d56fe1e3f3faadd4bf4ccf3e585ddb3c3b07Ulrich Weigand                            SelectionDAG &DAG) const;
2631d09d56fe1e3f3faadd4bf4ccf3e585ddb3c3b07Ulrich Weigand  SDValue lowerJumpTable(JumpTableSDNode *JT, SelectionDAG &DAG) const;
2641d09d56fe1e3f3faadd4bf4ccf3e585ddb3c3b07Ulrich Weigand  SDValue lowerConstantPool(ConstantPoolSDNode *CP, SelectionDAG &DAG) const;
2651d09d56fe1e3f3faadd4bf4ccf3e585ddb3c3b07Ulrich Weigand  SDValue lowerVASTART(SDValue Op, SelectionDAG &DAG) const;
2661d09d56fe1e3f3faadd4bf4ccf3e585ddb3c3b07Ulrich Weigand  SDValue lowerVACOPY(SDValue Op, SelectionDAG &DAG) const;
2671d09d56fe1e3f3faadd4bf4ccf3e585ddb3c3b07Ulrich Weigand  SDValue lowerDYNAMIC_STACKALLOC(SDValue Op, SelectionDAG &DAG) const;
268df40f8e8ad0aa93defa44b8a136e8d871cfd44eaRichard Sandiford  SDValue lowerSMUL_LOHI(SDValue Op, SelectionDAG &DAG) const;
2691d09d56fe1e3f3faadd4bf4ccf3e585ddb3c3b07Ulrich Weigand  SDValue lowerUMUL_LOHI(SDValue Op, SelectionDAG &DAG) const;
2701d09d56fe1e3f3faadd4bf4ccf3e585ddb3c3b07Ulrich Weigand  SDValue lowerSDIVREM(SDValue Op, SelectionDAG &DAG) const;
2711d09d56fe1e3f3faadd4bf4ccf3e585ddb3c3b07Ulrich Weigand  SDValue lowerUDIVREM(SDValue Op, SelectionDAG &DAG) const;
2721d09d56fe1e3f3faadd4bf4ccf3e585ddb3c3b07Ulrich Weigand  SDValue lowerBITCAST(SDValue Op, SelectionDAG &DAG) const;
2731d09d56fe1e3f3faadd4bf4ccf3e585ddb3c3b07Ulrich Weigand  SDValue lowerOR(SDValue Op, SelectionDAG &DAG) const;
27436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  SDValue lowerATOMIC_LOAD(SDValue Op, SelectionDAG &DAG) const;
27536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  SDValue lowerATOMIC_STORE(SDValue Op, SelectionDAG &DAG) const;
27636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  SDValue lowerATOMIC_LOAD_OP(SDValue Op, SelectionDAG &DAG,
27736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines                              unsigned Opcode) const;
27836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  SDValue lowerATOMIC_LOAD_SUB(SDValue Op, SelectionDAG &DAG) const;
2791d09d56fe1e3f3faadd4bf4ccf3e585ddb3c3b07Ulrich Weigand  SDValue lowerATOMIC_CMP_SWAP(SDValue Op, SelectionDAG &DAG) const;
28036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  SDValue lowerLOAD_SEQUENCE_POINT(SDValue Op, SelectionDAG &DAG) const;
2811d09d56fe1e3f3faadd4bf4ccf3e585ddb3c3b07Ulrich Weigand  SDValue lowerSTACKSAVE(SDValue Op, SelectionDAG &DAG) const;
2821d09d56fe1e3f3faadd4bf4ccf3e585ddb3c3b07Ulrich Weigand  SDValue lowerSTACKRESTORE(SDValue Op, SelectionDAG &DAG) const;
283a550b51bac50493db75a7b5788a3f2c3b62fd913Richard Sandiford  SDValue lowerPREFETCH(SDValue Op, SelectionDAG &DAG) const;
2841d09d56fe1e3f3faadd4bf4ccf3e585ddb3c3b07Ulrich Weigand
285d50bcb2162a529534da42748ab4a418bfc9aaf06Richard Sandiford  // If the last instruction before MBBI in MBB was some form of COMPARE,
286d50bcb2162a529534da42748ab4a418bfc9aaf06Richard Sandiford  // try to replace it with a COMPARE AND BRANCH just before MBBI.
287d50bcb2162a529534da42748ab4a418bfc9aaf06Richard Sandiford  // CCMask and Target are the BRC-like operands for the branch.
288d50bcb2162a529534da42748ab4a418bfc9aaf06Richard Sandiford  // Return true if the change was made.
289d50bcb2162a529534da42748ab4a418bfc9aaf06Richard Sandiford  bool convertPrevCompareToBranch(MachineBasicBlock *MBB,
290d50bcb2162a529534da42748ab4a418bfc9aaf06Richard Sandiford                                  MachineBasicBlock::iterator MBBI,
291d50bcb2162a529534da42748ab4a418bfc9aaf06Richard Sandiford                                  unsigned CCMask,
292d50bcb2162a529534da42748ab4a418bfc9aaf06Richard Sandiford                                  MachineBasicBlock *Target) const;
293d50bcb2162a529534da42748ab4a418bfc9aaf06Richard Sandiford
2941d09d56fe1e3f3faadd4bf4ccf3e585ddb3c3b07Ulrich Weigand  // Implement EmitInstrWithCustomInserter for individual operation types.
2951d09d56fe1e3f3faadd4bf4ccf3e585ddb3c3b07Ulrich Weigand  MachineBasicBlock *emitSelect(MachineInstr *MI,
2961d09d56fe1e3f3faadd4bf4ccf3e585ddb3c3b07Ulrich Weigand                                MachineBasicBlock *BB) const;
297722e9e6d0a5b67d136be40bc015abc5b0b32f97bRichard Sandiford  MachineBasicBlock *emitCondStore(MachineInstr *MI,
298722e9e6d0a5b67d136be40bc015abc5b0b32f97bRichard Sandiford                                   MachineBasicBlock *BB,
299b284e1bf08d24deb20b7deab71fce6f3034cc89aRichard Sandiford                                   unsigned StoreOpcode, unsigned STOCOpcode,
300b284e1bf08d24deb20b7deab71fce6f3034cc89aRichard Sandiford                                   bool Invert) const;
3011d09d56fe1e3f3faadd4bf4ccf3e585ddb3c3b07Ulrich Weigand  MachineBasicBlock *emitExt128(MachineInstr *MI,
3021d09d56fe1e3f3faadd4bf4ccf3e585ddb3c3b07Ulrich Weigand                                MachineBasicBlock *MBB,
3031d09d56fe1e3f3faadd4bf4ccf3e585ddb3c3b07Ulrich Weigand                                bool ClearEven, unsigned SubReg) const;
3041d09d56fe1e3f3faadd4bf4ccf3e585ddb3c3b07Ulrich Weigand  MachineBasicBlock *emitAtomicLoadBinary(MachineInstr *MI,
3051d09d56fe1e3f3faadd4bf4ccf3e585ddb3c3b07Ulrich Weigand                                          MachineBasicBlock *BB,
3061d09d56fe1e3f3faadd4bf4ccf3e585ddb3c3b07Ulrich Weigand                                          unsigned BinOpcode, unsigned BitSize,
3071d09d56fe1e3f3faadd4bf4ccf3e585ddb3c3b07Ulrich Weigand                                          bool Invert = false) const;
3081d09d56fe1e3f3faadd4bf4ccf3e585ddb3c3b07Ulrich Weigand  MachineBasicBlock *emitAtomicLoadMinMax(MachineInstr *MI,
3091d09d56fe1e3f3faadd4bf4ccf3e585ddb3c3b07Ulrich Weigand                                          MachineBasicBlock *MBB,
3101d09d56fe1e3f3faadd4bf4ccf3e585ddb3c3b07Ulrich Weigand                                          unsigned CompareOpcode,
3111d09d56fe1e3f3faadd4bf4ccf3e585ddb3c3b07Ulrich Weigand                                          unsigned KeepOldMask,
3121d09d56fe1e3f3faadd4bf4ccf3e585ddb3c3b07Ulrich Weigand                                          unsigned BitSize) const;
3131d09d56fe1e3f3faadd4bf4ccf3e585ddb3c3b07Ulrich Weigand  MachineBasicBlock *emitAtomicCmpSwapW(MachineInstr *MI,
3141d09d56fe1e3f3faadd4bf4ccf3e585ddb3c3b07Ulrich Weigand                                        MachineBasicBlock *BB) const;
315ac168b8bc8773a083a10902f64e4ae57a925aee4Richard Sandiford  MachineBasicBlock *emitMemMemWrapper(MachineInstr *MI,
316ac168b8bc8773a083a10902f64e4ae57a925aee4Richard Sandiford                                       MachineBasicBlock *BB,
317ac168b8bc8773a083a10902f64e4ae57a925aee4Richard Sandiford                                       unsigned Opcode) const;
318e1b2af731e2a45344a7c502232f66c55cd746da0Richard Sandiford  MachineBasicBlock *emitStringWrapper(MachineInstr *MI,
319e1b2af731e2a45344a7c502232f66c55cd746da0Richard Sandiford                                       MachineBasicBlock *BB,
320e1b2af731e2a45344a7c502232f66c55cd746da0Richard Sandiford                                       unsigned Opcode) const;
3211d09d56fe1e3f3faadd4bf4ccf3e585ddb3c3b07Ulrich Weigand};
3221d09d56fe1e3f3faadd4bf4ccf3e585ddb3c3b07Ulrich Weigand} // end namespace llvm
3231d09d56fe1e3f3faadd4bf4ccf3e585ddb3c3b07Ulrich Weigand
3241d09d56fe1e3f3faadd4bf4ccf3e585ddb3c3b07Ulrich Weigand#endif // LLVM_TARGET_SystemZ_ISELLOWERING_H
325