blob: a2b10b0ac74f16356390b0e8ee2430385cdf4443 [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"
21#include "llvm/Target/TargetLowering.h"
22
23namespace llvm {
24namespace SystemZISD {
Richard Sandifordc2312692014-03-06 10:38:30 +000025enum {
26 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
Richard Sandifordc2312692014-03-06 10:38:30 +000086 // Extracts the value of a 32-bit access register. Operand 0 is
87 // the number of the register.
88 EXTRACT_ACCESS,
Ulrich Weigand5f613df2013-05-06 16:15:19 +000089
Richard Sandifordc2312692014-03-06 10:38:30 +000090 // Wrappers around the ISD opcodes of the same name. The output and
91 // first input operands are GR128s. The trailing numbers are the
92 // widths of the second operand in bits.
93 UMUL_LOHI64,
94 SDIVREM32,
95 SDIVREM64,
96 UDIVREM32,
97 UDIVREM64,
Ulrich Weigand5f613df2013-05-06 16:15:19 +000098
Richard Sandifordc2312692014-03-06 10:38:30 +000099 // Use a series of MVCs to copy bytes from one memory location to another.
100 // The operands are:
101 // - the target address
102 // - the source address
103 // - the constant length
104 //
105 // This isn't a memory opcode because we'd need to attach two
106 // MachineMemOperands rather than one.
107 MVC,
Richard Sandifordd131ff82013-07-08 09:35:23 +0000108
Richard Sandifordc2312692014-03-06 10:38:30 +0000109 // Like MVC, but implemented as a loop that handles X*256 bytes
110 // followed by straight-line code to handle the rest (if any).
111 // The value of X is passed as an additional operand.
112 MVC_LOOP,
Richard Sandiford5e318f02013-08-27 09:54:29 +0000113
Richard Sandifordc2312692014-03-06 10:38:30 +0000114 // Similar to MVC and MVC_LOOP, but for logic operations (AND, OR, XOR).
115 NC,
116 NC_LOOP,
117 OC,
118 OC_LOOP,
119 XC,
120 XC_LOOP,
Richard Sandiford178273a2013-09-05 10:36:45 +0000121
Richard Sandifordc2312692014-03-06 10:38:30 +0000122 // Use CLC to compare two blocks of memory, with the same comments
123 // as for MVC and MVC_LOOP.
124 CLC,
125 CLC_LOOP,
Richard Sandiford761703a2013-08-12 10:17:33 +0000126
Richard Sandifordc2312692014-03-06 10:38:30 +0000127 // Use an MVST-based sequence to implement stpcpy().
128 STPCPY,
Richard Sandifordbb83a502013-08-16 11:29:37 +0000129
Richard Sandifordc2312692014-03-06 10:38:30 +0000130 // Use a CLST-based sequence to implement strcmp(). The two input operands
131 // are the addresses of the strings to compare.
132 STRCMP,
Richard Sandifordca232712013-08-16 11:21:54 +0000133
Richard Sandifordc2312692014-03-06 10:38:30 +0000134 // Use an SRST-based sequence to search a block of memory. The first
135 // operand is the end address, the second is the start, and the third
136 // is the character to search for. CC is set to 1 on success and 2
137 // on failure.
138 SEARCH_STRING,
Richard Sandiford0dec06a2013-08-16 11:41:43 +0000139
Richard Sandifordc2312692014-03-06 10:38:30 +0000140 // Store the CC value in bits 29 and 28 of an integer.
141 IPM,
Richard Sandiford564681c2013-08-12 10:28:10 +0000142
Richard Sandifordc2312692014-03-06 10:38:30 +0000143 // Perform a serialization operation. (BCR 15,0 or BCR 14,0.)
144 SERIALIZE,
Richard Sandiford9afe6132013-12-10 10:36:34 +0000145
Richard Sandifordc2312692014-03-06 10:38:30 +0000146 // Wrappers around the inner loop of an 8- or 16-bit ATOMIC_SWAP or
147 // ATOMIC_LOAD_<op>.
148 //
149 // Operand 0: the address of the containing 32-bit-aligned field
150 // Operand 1: the second operand of <op>, in the high bits of an i32
151 // for everything except ATOMIC_SWAPW
152 // Operand 2: how many bits to rotate the i32 left to bring the first
153 // operand into the high bits
154 // Operand 3: the negative of operand 2, for rotating the other way
155 // Operand 4: the width of the field in bits (8 or 16)
156 ATOMIC_SWAPW = ISD::FIRST_TARGET_MEMORY_OPCODE,
157 ATOMIC_LOADW_ADD,
158 ATOMIC_LOADW_SUB,
159 ATOMIC_LOADW_AND,
160 ATOMIC_LOADW_OR,
161 ATOMIC_LOADW_XOR,
162 ATOMIC_LOADW_NAND,
163 ATOMIC_LOADW_MIN,
164 ATOMIC_LOADW_MAX,
165 ATOMIC_LOADW_UMIN,
166 ATOMIC_LOADW_UMAX,
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000167
Richard Sandifordc2312692014-03-06 10:38:30 +0000168 // A wrapper around the inner loop of an ATOMIC_CMP_SWAP.
169 //
170 // Operand 0: the address of the containing 32-bit-aligned field
171 // Operand 1: the compare value, in the low bits of an i32
172 // Operand 2: the swap value, in the low bits of an i32
173 // Operand 3: how many bits to rotate the i32 left to bring the first
174 // operand into the high bits
175 // Operand 4: the negative of operand 2, for rotating the other way
176 // Operand 5: the width of the field in bits (8 or 16)
177 ATOMIC_CMP_SWAPW,
Richard Sandiford03481332013-08-23 11:36:42 +0000178
Richard Sandifordc2312692014-03-06 10:38:30 +0000179 // Prefetch from the second operand using the 4-bit control code in
180 // the first operand. The code is 1 for a load prefetch and 2 for
181 // a store prefetch.
182 PREFETCH
183};
Richard Sandiford54b36912013-09-27 15:14:04 +0000184
Richard Sandifordc2312692014-03-06 10:38:30 +0000185// Return true if OPCODE is some kind of PC-relative address.
186inline bool isPCREL(unsigned Opcode) {
187 return Opcode == PCREL_WRAPPER || Opcode == PCREL_OFFSET;
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000188}
Richard Sandifordc2312692014-03-06 10:38:30 +0000189} // end namespace SystemZISD
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000190
Richard Sandiford5bc670b2013-09-06 11:51:39 +0000191namespace SystemZICMP {
Richard Sandifordc2312692014-03-06 10:38:30 +0000192// Describes whether an integer comparison needs to be signed or unsigned,
193// or whether either type is OK.
194enum {
195 Any,
196 UnsignedOnly,
197 SignedOnly
198};
199} // end namespace SystemZICMP
Richard Sandiford5bc670b2013-09-06 11:51:39 +0000200
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000201class SystemZSubtarget;
202class SystemZTargetMachine;
203
204class SystemZTargetLowering : public TargetLowering {
205public:
Eric Christophera6734172015-01-31 00:06:45 +0000206 explicit SystemZTargetLowering(const TargetMachine &TM,
207 const SystemZSubtarget &STI);
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000208
209 // Override TargetLowering.
Richard Sandifordb4d67b52014-03-06 12:03:36 +0000210 MVT getScalarShiftAmountTy(EVT LHSTy) const override {
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000211 return MVT::i32;
212 }
Richard Sandifordb4d67b52014-03-06 12:03:36 +0000213 EVT getSetCCResultType(LLVMContext &, EVT) const override;
214 bool isFMAFasterThanFMulAndFAdd(EVT VT) const override;
215 bool isFPImmLegal(const APFloat &Imm, EVT VT) const override;
216 bool isLegalAddressingMode(const AddrMode &AM, Type *Ty) const override;
Matt Arsenault6f2a5262014-07-27 17:46:40 +0000217 bool allowsMisalignedMemoryAccesses(EVT VT, unsigned AS,
218 unsigned Align,
219 bool *Fast) const override;
Richard Sandifordb4d67b52014-03-06 12:03:36 +0000220 bool isTruncateFree(Type *, Type *) const override;
221 bool isTruncateFree(EVT, EVT) const override;
222 const char *getTargetNodeName(unsigned Opcode) const override;
223 std::pair<unsigned, const TargetRegisterClass *>
Eric Christopher11e4df72015-02-26 22:38:43 +0000224 getRegForInlineAsmConstraint(const TargetRegisterInfo *TRI,
225 const std::string &Constraint,
226 MVT VT) const override;
Richard Sandifordb4d67b52014-03-06 12:03:36 +0000227 TargetLowering::ConstraintType
Craig Topper73156022014-03-02 09:09:27 +0000228 getConstraintType(const std::string &Constraint) const override;
Richard Sandifordb4d67b52014-03-06 12:03:36 +0000229 TargetLowering::ConstraintWeight
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000230 getSingleConstraintMatchWeight(AsmOperandInfo &info,
Craig Topper73156022014-03-02 09:09:27 +0000231 const char *constraint) const override;
Richard Sandifordb4d67b52014-03-06 12:03:36 +0000232 void LowerAsmOperandForConstraint(SDValue Op,
233 std::string &Constraint,
234 std::vector<SDValue> &Ops,
235 SelectionDAG &DAG) const override;
236 MachineBasicBlock *EmitInstrWithCustomInserter(MachineInstr *MI,
237 MachineBasicBlock *BB) const
238 override;
239 SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const override;
240 bool allowTruncateForTailCall(Type *, Type *) const override;
241 bool mayBeEmittedAsTailCall(CallInst *CI) const override;
242 SDValue LowerFormalArguments(SDValue Chain, CallingConv::ID CallConv,
243 bool isVarArg,
244 const SmallVectorImpl<ISD::InputArg> &Ins,
245 SDLoc DL, SelectionDAG &DAG,
246 SmallVectorImpl<SDValue> &InVals) const override;
247 SDValue LowerCall(CallLoweringInfo &CLI,
248 SmallVectorImpl<SDValue> &InVals) const override;
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000249
Richard Sandifordb4d67b52014-03-06 12:03:36 +0000250 SDValue LowerReturn(SDValue Chain, CallingConv::ID CallConv, bool IsVarArg,
251 const SmallVectorImpl<ISD::OutputArg> &Outs,
252 const SmallVectorImpl<SDValue> &OutVals,
253 SDLoc DL, SelectionDAG &DAG) const override;
254 SDValue prepareVolatileOrAtomicLoad(SDValue Chain, SDLoc DL,
255 SelectionDAG &DAG) const override;
Richard Sandiford95bc5f92014-03-07 11:34:35 +0000256 SDValue PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const override;
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000257
258private:
259 const SystemZSubtarget &Subtarget;
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000260
261 // Implement LowerOperation for individual opcodes.
Richard Sandifordf722a8e302013-10-16 11:10:55 +0000262 SDValue lowerSETCC(SDValue Op, SelectionDAG &DAG) const;
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000263 SDValue lowerBR_CC(SDValue Op, SelectionDAG &DAG) const;
264 SDValue lowerSELECT_CC(SDValue Op, SelectionDAG &DAG) const;
265 SDValue lowerGlobalAddress(GlobalAddressSDNode *Node,
266 SelectionDAG &DAG) const;
Ulrich Weigand7db69182015-02-18 09:13:27 +0000267 SDValue lowerTLSGetOffset(GlobalAddressSDNode *Node,
268 SelectionDAG &DAG, unsigned Opcode,
269 SDValue GOTOffset) const;
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000270 SDValue lowerGlobalTLSAddress(GlobalAddressSDNode *Node,
271 SelectionDAG &DAG) const;
272 SDValue lowerBlockAddress(BlockAddressSDNode *Node,
273 SelectionDAG &DAG) const;
274 SDValue lowerJumpTable(JumpTableSDNode *JT, SelectionDAG &DAG) const;
275 SDValue lowerConstantPool(ConstantPoolSDNode *CP, SelectionDAG &DAG) const;
276 SDValue lowerVASTART(SDValue Op, SelectionDAG &DAG) const;
277 SDValue lowerVACOPY(SDValue Op, SelectionDAG &DAG) const;
278 SDValue lowerDYNAMIC_STACKALLOC(SDValue Op, SelectionDAG &DAG) const;
Richard Sandiford7d86e472013-08-21 09:34:56 +0000279 SDValue lowerSMUL_LOHI(SDValue Op, SelectionDAG &DAG) const;
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000280 SDValue lowerUMUL_LOHI(SDValue Op, SelectionDAG &DAG) const;
281 SDValue lowerSDIVREM(SDValue Op, SelectionDAG &DAG) const;
282 SDValue lowerUDIVREM(SDValue Op, SelectionDAG &DAG) const;
283 SDValue lowerBITCAST(SDValue Op, SelectionDAG &DAG) const;
284 SDValue lowerOR(SDValue Op, SelectionDAG &DAG) const;
Richard Sandifordbef3d7a2013-12-10 10:49:34 +0000285 SDValue lowerATOMIC_LOAD(SDValue Op, SelectionDAG &DAG) const;
286 SDValue lowerATOMIC_STORE(SDValue Op, SelectionDAG &DAG) const;
287 SDValue lowerATOMIC_LOAD_OP(SDValue Op, SelectionDAG &DAG,
288 unsigned Opcode) const;
Richard Sandiford41350a52013-12-24 15:18:04 +0000289 SDValue lowerATOMIC_LOAD_SUB(SDValue Op, SelectionDAG &DAG) const;
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000290 SDValue lowerATOMIC_CMP_SWAP(SDValue Op, SelectionDAG &DAG) const;
Richard Sandiford9afe6132013-12-10 10:36:34 +0000291 SDValue lowerLOAD_SEQUENCE_POINT(SDValue Op, SelectionDAG &DAG) const;
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000292 SDValue lowerSTACKSAVE(SDValue Op, SelectionDAG &DAG) const;
293 SDValue lowerSTACKRESTORE(SDValue Op, SelectionDAG &DAG) const;
Richard Sandiford03481332013-08-23 11:36:42 +0000294 SDValue lowerPREFETCH(SDValue Op, SelectionDAG &DAG) const;
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000295
Richard Sandiford0fb90ab2013-05-28 10:41:11 +0000296 // If the last instruction before MBBI in MBB was some form of COMPARE,
297 // try to replace it with a COMPARE AND BRANCH just before MBBI.
298 // CCMask and Target are the BRC-like operands for the branch.
299 // Return true if the change was made.
300 bool convertPrevCompareToBranch(MachineBasicBlock *MBB,
301 MachineBasicBlock::iterator MBBI,
302 unsigned CCMask,
303 MachineBasicBlock *Target) const;
304
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000305 // Implement EmitInstrWithCustomInserter for individual operation types.
306 MachineBasicBlock *emitSelect(MachineInstr *MI,
307 MachineBasicBlock *BB) const;
Richard Sandifordb86a8342013-06-27 09:27:40 +0000308 MachineBasicBlock *emitCondStore(MachineInstr *MI,
309 MachineBasicBlock *BB,
Richard Sandiforda68e6f52013-07-25 08:57:02 +0000310 unsigned StoreOpcode, unsigned STOCOpcode,
311 bool Invert) const;
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000312 MachineBasicBlock *emitExt128(MachineInstr *MI,
313 MachineBasicBlock *MBB,
314 bool ClearEven, unsigned SubReg) const;
315 MachineBasicBlock *emitAtomicLoadBinary(MachineInstr *MI,
316 MachineBasicBlock *BB,
317 unsigned BinOpcode, unsigned BitSize,
318 bool Invert = false) const;
319 MachineBasicBlock *emitAtomicLoadMinMax(MachineInstr *MI,
320 MachineBasicBlock *MBB,
321 unsigned CompareOpcode,
322 unsigned KeepOldMask,
323 unsigned BitSize) const;
324 MachineBasicBlock *emitAtomicCmpSwapW(MachineInstr *MI,
325 MachineBasicBlock *BB) const;
Richard Sandiford564681c2013-08-12 10:28:10 +0000326 MachineBasicBlock *emitMemMemWrapper(MachineInstr *MI,
327 MachineBasicBlock *BB,
328 unsigned Opcode) const;
Richard Sandifordca232712013-08-16 11:21:54 +0000329 MachineBasicBlock *emitStringWrapper(MachineInstr *MI,
330 MachineBasicBlock *BB,
331 unsigned Opcode) const;
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000332};
333} // end namespace llvm
334
Benjamin Kramera7c40ef2014-08-13 16:26:38 +0000335#endif