blob: 98224638d11ac77a2e691c0a8b96bd1d0e43b057 [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
15#ifndef LLVM_TARGET_SystemZ_ISELLOWERING_H
16#define LLVM_TARGET_SystemZ_ISELLOWERING_H
17
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 {
25 enum {
26 FIRST_NUMBER = ISD::BUILTIN_OP_END,
27
28 // Return with a flag operand. Operand 0 is the chain operand.
29 RET_FLAG,
30
31 // 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,
Richard Sandiford709bda62013-08-19 12:42:31 +000035 SIBCALL,
Ulrich Weigand5f613df2013-05-06 16:15:19 +000036
37 // Wraps a TargetGlobalAddress that should be loaded using PC-relative
38 // accesses (LARL). Operand 0 is the address.
39 PCREL_WRAPPER,
40
Richard Sandiford5bc670b2013-09-06 11:51:39 +000041 // Integer comparisons. There are three operands: the two values
42 // to compare, and an integer of type SystemZICMP.
43 ICMP,
Ulrich Weigand5f613df2013-05-06 16:15:19 +000044
Richard Sandiford5bc670b2013-09-06 11:51:39 +000045 // Floating-point comparisons. The two operands are the values to compare.
46 FCMP,
Ulrich Weigand5f613df2013-05-06 16:15:19 +000047
Richard Sandiford35b9be22013-08-28 10:31:43 +000048 // Test under mask. The first operand is ANDed with the second operand
Richard Sandiforda9eb9972013-09-10 10:20:32 +000049 // and the condition codes are set on the result. The third operand is
50 // a boolean that is true if the condition codes need to distinguish
51 // between CCMASK_TM_MIXED_MSB_0 and CCMASK_TM_MIXED_MSB_1 (which the
52 // register forms do but the memory forms don't).
Richard Sandiford35b9be22013-08-28 10:31:43 +000053 TM,
54
Ulrich Weigand5f613df2013-05-06 16:15:19 +000055 // Branches if a condition is true. Operand 0 is the chain operand;
56 // operand 1 is the 4-bit condition-code mask, with bit N in
57 // big-endian order meaning "branch if CC=N"; operand 2 is the
58 // target block and operand 3 is the flag operand.
59 BR_CCMASK,
60
61 // Selects between operand 0 and operand 1. Operand 2 is the
62 // mask of condition-code values for which operand 0 should be
63 // chosen over operand 1; it has the same form as BR_CCMASK.
64 // Operand 3 is the flag operand.
65 SELECT_CCMASK,
66
67 // Evaluates to the gap between the stack pointer and the
68 // base of the dynamically-allocatable area.
69 ADJDYNALLOC,
70
71 // Extracts the value of a 32-bit access register. Operand 0 is
72 // the number of the register.
73 EXTRACT_ACCESS,
74
75 // Wrappers around the ISD opcodes of the same name. The output and
76 // first input operands are GR128s. The trailing numbers are the
77 // widths of the second operand in bits.
78 UMUL_LOHI64,
Richard Sandiforde6e78852013-07-02 15:40:22 +000079 SDIVREM32,
Ulrich Weigand5f613df2013-05-06 16:15:19 +000080 SDIVREM64,
81 UDIVREM32,
82 UDIVREM64,
83
Richard Sandiford5e318f02013-08-27 09:54:29 +000084 // Use a series of MVCs to copy bytes from one memory location to another.
85 // The operands are:
86 // - the target address
87 // - the source address
88 // - the constant length
89 //
Richard Sandifordd131ff82013-07-08 09:35:23 +000090 // This isn't a memory opcode because we'd need to attach two
91 // MachineMemOperands rather than one.
92 MVC,
93
Richard Sandiford5e318f02013-08-27 09:54:29 +000094 // Like MVC, but implemented as a loop that handles X*256 bytes
95 // followed by straight-line code to handle the rest (if any).
96 // The value of X is passed as an additional operand.
97 MVC_LOOP,
98
Richard Sandiford178273a2013-09-05 10:36:45 +000099 // Similar to MVC and MVC_LOOP, but for logic operations (AND, OR, XOR).
100 NC,
101 NC_LOOP,
102 OC,
103 OC_LOOP,
104 XC,
105 XC_LOOP,
106
Richard Sandiford761703a2013-08-12 10:17:33 +0000107 // Use CLC to compare two blocks of memory, with the same comments
Richard Sandiford5e318f02013-08-27 09:54:29 +0000108 // as for MVC and MVC_LOOP.
Richard Sandiford761703a2013-08-12 10:17:33 +0000109 CLC,
Richard Sandiford5e318f02013-08-27 09:54:29 +0000110 CLC_LOOP,
Richard Sandiford761703a2013-08-12 10:17:33 +0000111
Richard Sandifordbb83a502013-08-16 11:29:37 +0000112 // Use an MVST-based sequence to implement stpcpy().
113 STPCPY,
114
Richard Sandifordca232712013-08-16 11:21:54 +0000115 // Use a CLST-based sequence to implement strcmp(). The two input operands
116 // are the addresses of the strings to compare.
117 STRCMP,
118
Richard Sandiford0dec06a2013-08-16 11:41:43 +0000119 // Use an SRST-based sequence to search a block of memory. The first
120 // operand is the end address, the second is the start, and the third
121 // is the character to search for. CC is set to 1 on success and 2
122 // on failure.
123 SEARCH_STRING,
124
Richard Sandiford564681c2013-08-12 10:28:10 +0000125 // Store the CC value in bits 29 and 28 of an integer.
126 IPM,
127
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000128 // Wrappers around the inner loop of an 8- or 16-bit ATOMIC_SWAP or
129 // ATOMIC_LOAD_<op>.
130 //
131 // Operand 0: the address of the containing 32-bit-aligned field
132 // Operand 1: the second operand of <op>, in the high bits of an i32
133 // for everything except ATOMIC_SWAPW
134 // Operand 2: how many bits to rotate the i32 left to bring the first
135 // operand into the high bits
136 // Operand 3: the negative of operand 2, for rotating the other way
137 // Operand 4: the width of the field in bits (8 or 16)
138 ATOMIC_SWAPW = ISD::FIRST_TARGET_MEMORY_OPCODE,
139 ATOMIC_LOADW_ADD,
140 ATOMIC_LOADW_SUB,
141 ATOMIC_LOADW_AND,
142 ATOMIC_LOADW_OR,
143 ATOMIC_LOADW_XOR,
144 ATOMIC_LOADW_NAND,
145 ATOMIC_LOADW_MIN,
146 ATOMIC_LOADW_MAX,
147 ATOMIC_LOADW_UMIN,
148 ATOMIC_LOADW_UMAX,
149
150 // A wrapper around the inner loop of an ATOMIC_CMP_SWAP.
151 //
152 // Operand 0: the address of the containing 32-bit-aligned field
153 // Operand 1: the compare value, in the low bits of an i32
154 // Operand 2: the swap value, in the low bits of an i32
155 // Operand 3: how many bits to rotate the i32 left to bring the first
156 // operand into the high bits
157 // Operand 4: the negative of operand 2, for rotating the other way
158 // Operand 5: the width of the field in bits (8 or 16)
Richard Sandiford03481332013-08-23 11:36:42 +0000159 ATOMIC_CMP_SWAPW,
160
161 // Prefetch from the second operand using the 4-bit control code in
162 // the first operand. The code is 1 for a load prefetch and 2 for
163 // a store prefetch.
164 PREFETCH
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000165 };
166}
167
Richard Sandiford5bc670b2013-09-06 11:51:39 +0000168namespace SystemZICMP {
169 // Describes whether an integer comparison needs to be signed or unsigned,
170 // or whether either type is OK.
171 enum {
172 Any,
173 UnsignedOnly,
174 SignedOnly
175 };
176}
177
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000178class SystemZSubtarget;
179class SystemZTargetMachine;
180
181class SystemZTargetLowering : public TargetLowering {
182public:
183 explicit SystemZTargetLowering(SystemZTargetMachine &TM);
184
185 // Override TargetLowering.
186 virtual MVT getScalarShiftAmountTy(EVT LHSTy) const LLVM_OVERRIDE {
187 return MVT::i32;
188 }
Richard Sandiford791bea42013-07-31 12:58:26 +0000189 virtual EVT getSetCCResultType(LLVMContext &, EVT) const LLVM_OVERRIDE {
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000190 return MVT::i32;
191 }
Stephen Lin73de7bf2013-07-09 18:16:56 +0000192 virtual bool isFMAFasterThanFMulAndFAdd(EVT VT) const LLVM_OVERRIDE;
Richard Sandiford791bea42013-07-31 12:58:26 +0000193 virtual bool isFPImmLegal(const APFloat &Imm, EVT VT) const LLVM_OVERRIDE;
194 virtual bool isLegalAddressingMode(const AddrMode &AM, Type *Ty) const
195 LLVM_OVERRIDE;
196 virtual bool allowsUnalignedMemoryAccesses(EVT VT, bool *Fast) const
197 LLVM_OVERRIDE;
Richard Sandiford709bda62013-08-19 12:42:31 +0000198 virtual bool isTruncateFree(Type *, Type *) const LLVM_OVERRIDE;
199 virtual bool isTruncateFree(EVT, EVT) const LLVM_OVERRIDE;
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000200 virtual const char *getTargetNodeName(unsigned Opcode) const LLVM_OVERRIDE;
201 virtual std::pair<unsigned, const TargetRegisterClass *>
202 getRegForInlineAsmConstraint(const std::string &Constraint,
Chad Rosier295bd432013-06-22 18:37:38 +0000203 MVT VT) const LLVM_OVERRIDE;
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000204 virtual TargetLowering::ConstraintType
205 getConstraintType(const std::string &Constraint) const LLVM_OVERRIDE;
206 virtual TargetLowering::ConstraintWeight
207 getSingleConstraintMatchWeight(AsmOperandInfo &info,
208 const char *constraint) const LLVM_OVERRIDE;
209 virtual void
210 LowerAsmOperandForConstraint(SDValue Op,
211 std::string &Constraint,
212 std::vector<SDValue> &Ops,
213 SelectionDAG &DAG) const LLVM_OVERRIDE;
214 virtual MachineBasicBlock *
215 EmitInstrWithCustomInserter(MachineInstr *MI,
216 MachineBasicBlock *BB) const LLVM_OVERRIDE;
217 virtual SDValue LowerOperation(SDValue Op,
218 SelectionDAG &DAG) const LLVM_OVERRIDE;
Richard Sandiford709bda62013-08-19 12:42:31 +0000219 virtual bool allowTruncateForTailCall(Type *, Type *) const LLVM_OVERRIDE;
220 virtual bool mayBeEmittedAsTailCall(CallInst *CI) const LLVM_OVERRIDE;
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000221 virtual SDValue
222 LowerFormalArguments(SDValue Chain,
223 CallingConv::ID CallConv, bool isVarArg,
224 const SmallVectorImpl<ISD::InputArg> &Ins,
Andrew Trickef9de2a2013-05-25 02:42:55 +0000225 SDLoc DL, SelectionDAG &DAG,
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000226 SmallVectorImpl<SDValue> &InVals) const LLVM_OVERRIDE;
227 virtual SDValue
228 LowerCall(CallLoweringInfo &CLI,
229 SmallVectorImpl<SDValue> &InVals) const LLVM_OVERRIDE;
230
231 virtual SDValue
232 LowerReturn(SDValue Chain,
233 CallingConv::ID CallConv, bool IsVarArg,
234 const SmallVectorImpl<ISD::OutputArg> &Outs,
235 const SmallVectorImpl<SDValue> &OutVals,
Andrew Trickef9de2a2013-05-25 02:42:55 +0000236 SDLoc DL, SelectionDAG &DAG) const LLVM_OVERRIDE;
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000237
238private:
239 const SystemZSubtarget &Subtarget;
240 const SystemZTargetMachine &TM;
241
242 // Implement LowerOperation for individual opcodes.
243 SDValue lowerBR_CC(SDValue Op, SelectionDAG &DAG) const;
244 SDValue lowerSELECT_CC(SDValue Op, SelectionDAG &DAG) const;
245 SDValue lowerGlobalAddress(GlobalAddressSDNode *Node,
246 SelectionDAG &DAG) const;
247 SDValue lowerGlobalTLSAddress(GlobalAddressSDNode *Node,
248 SelectionDAG &DAG) const;
249 SDValue lowerBlockAddress(BlockAddressSDNode *Node,
250 SelectionDAG &DAG) const;
251 SDValue lowerJumpTable(JumpTableSDNode *JT, SelectionDAG &DAG) const;
252 SDValue lowerConstantPool(ConstantPoolSDNode *CP, SelectionDAG &DAG) const;
253 SDValue lowerVASTART(SDValue Op, SelectionDAG &DAG) const;
254 SDValue lowerVACOPY(SDValue Op, SelectionDAG &DAG) const;
255 SDValue lowerDYNAMIC_STACKALLOC(SDValue Op, SelectionDAG &DAG) const;
Richard Sandiford7d86e472013-08-21 09:34:56 +0000256 SDValue lowerSMUL_LOHI(SDValue Op, SelectionDAG &DAG) const;
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000257 SDValue lowerUMUL_LOHI(SDValue Op, SelectionDAG &DAG) const;
258 SDValue lowerSDIVREM(SDValue Op, SelectionDAG &DAG) const;
259 SDValue lowerUDIVREM(SDValue Op, SelectionDAG &DAG) const;
260 SDValue lowerBITCAST(SDValue Op, SelectionDAG &DAG) const;
261 SDValue lowerOR(SDValue Op, SelectionDAG &DAG) const;
262 SDValue lowerATOMIC_LOAD(SDValue Op, SelectionDAG &DAG,
263 unsigned Opcode) const;
264 SDValue lowerATOMIC_CMP_SWAP(SDValue Op, SelectionDAG &DAG) const;
265 SDValue lowerSTACKSAVE(SDValue Op, SelectionDAG &DAG) const;
266 SDValue lowerSTACKRESTORE(SDValue Op, SelectionDAG &DAG) const;
Richard Sandiford03481332013-08-23 11:36:42 +0000267 SDValue lowerPREFETCH(SDValue Op, SelectionDAG &DAG) const;
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000268
Richard Sandiford0fb90ab2013-05-28 10:41:11 +0000269 // If the last instruction before MBBI in MBB was some form of COMPARE,
270 // try to replace it with a COMPARE AND BRANCH just before MBBI.
271 // CCMask and Target are the BRC-like operands for the branch.
272 // Return true if the change was made.
273 bool convertPrevCompareToBranch(MachineBasicBlock *MBB,
274 MachineBasicBlock::iterator MBBI,
275 unsigned CCMask,
276 MachineBasicBlock *Target) const;
277
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000278 // Implement EmitInstrWithCustomInserter for individual operation types.
279 MachineBasicBlock *emitSelect(MachineInstr *MI,
280 MachineBasicBlock *BB) const;
Richard Sandifordb86a8342013-06-27 09:27:40 +0000281 MachineBasicBlock *emitCondStore(MachineInstr *MI,
282 MachineBasicBlock *BB,
Richard Sandiforda68e6f52013-07-25 08:57:02 +0000283 unsigned StoreOpcode, unsigned STOCOpcode,
284 bool Invert) const;
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000285 MachineBasicBlock *emitExt128(MachineInstr *MI,
286 MachineBasicBlock *MBB,
287 bool ClearEven, unsigned SubReg) const;
288 MachineBasicBlock *emitAtomicLoadBinary(MachineInstr *MI,
289 MachineBasicBlock *BB,
290 unsigned BinOpcode, unsigned BitSize,
291 bool Invert = false) const;
292 MachineBasicBlock *emitAtomicLoadMinMax(MachineInstr *MI,
293 MachineBasicBlock *MBB,
294 unsigned CompareOpcode,
295 unsigned KeepOldMask,
296 unsigned BitSize) const;
297 MachineBasicBlock *emitAtomicCmpSwapW(MachineInstr *MI,
298 MachineBasicBlock *BB) const;
Richard Sandiford564681c2013-08-12 10:28:10 +0000299 MachineBasicBlock *emitMemMemWrapper(MachineInstr *MI,
300 MachineBasicBlock *BB,
301 unsigned Opcode) const;
Richard Sandifordca232712013-08-16 11:21:54 +0000302 MachineBasicBlock *emitStringWrapper(MachineInstr *MI,
303 MachineBasicBlock *BB,
304 unsigned Opcode) const;
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000305};
306} // end namespace llvm
307
308#endif // LLVM_TARGET_SystemZ_ISELLOWERING_H