blob: 500abcef9292b8ad599c1b534ce412be730bd1c8 [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
49 // and the condition codes are set on the result.
50 TM,
51
Ulrich Weigand5f613df2013-05-06 16:15:19 +000052 // Branches if a condition is true. Operand 0 is the chain operand;
53 // operand 1 is the 4-bit condition-code mask, with bit N in
54 // big-endian order meaning "branch if CC=N"; operand 2 is the
55 // target block and operand 3 is the flag operand.
56 BR_CCMASK,
57
58 // Selects between operand 0 and operand 1. Operand 2 is the
59 // mask of condition-code values for which operand 0 should be
60 // chosen over operand 1; it has the same form as BR_CCMASK.
61 // Operand 3 is the flag operand.
62 SELECT_CCMASK,
63
64 // Evaluates to the gap between the stack pointer and the
65 // base of the dynamically-allocatable area.
66 ADJDYNALLOC,
67
68 // Extracts the value of a 32-bit access register. Operand 0 is
69 // the number of the register.
70 EXTRACT_ACCESS,
71
72 // Wrappers around the ISD opcodes of the same name. The output and
73 // first input operands are GR128s. The trailing numbers are the
74 // widths of the second operand in bits.
75 UMUL_LOHI64,
Richard Sandiforde6e78852013-07-02 15:40:22 +000076 SDIVREM32,
Ulrich Weigand5f613df2013-05-06 16:15:19 +000077 SDIVREM64,
78 UDIVREM32,
79 UDIVREM64,
80
Richard Sandiford5e318f02013-08-27 09:54:29 +000081 // Use a series of MVCs to copy bytes from one memory location to another.
82 // The operands are:
83 // - the target address
84 // - the source address
85 // - the constant length
86 //
Richard Sandifordd131ff82013-07-08 09:35:23 +000087 // This isn't a memory opcode because we'd need to attach two
88 // MachineMemOperands rather than one.
89 MVC,
90
Richard Sandiford5e318f02013-08-27 09:54:29 +000091 // Like MVC, but implemented as a loop that handles X*256 bytes
92 // followed by straight-line code to handle the rest (if any).
93 // The value of X is passed as an additional operand.
94 MVC_LOOP,
95
Richard Sandiford178273a2013-09-05 10:36:45 +000096 // Similar to MVC and MVC_LOOP, but for logic operations (AND, OR, XOR).
97 NC,
98 NC_LOOP,
99 OC,
100 OC_LOOP,
101 XC,
102 XC_LOOP,
103
Richard Sandiford761703a2013-08-12 10:17:33 +0000104 // Use CLC to compare two blocks of memory, with the same comments
Richard Sandiford5e318f02013-08-27 09:54:29 +0000105 // as for MVC and MVC_LOOP.
Richard Sandiford761703a2013-08-12 10:17:33 +0000106 CLC,
Richard Sandiford5e318f02013-08-27 09:54:29 +0000107 CLC_LOOP,
Richard Sandiford761703a2013-08-12 10:17:33 +0000108
Richard Sandifordbb83a502013-08-16 11:29:37 +0000109 // Use an MVST-based sequence to implement stpcpy().
110 STPCPY,
111
Richard Sandifordca232712013-08-16 11:21:54 +0000112 // Use a CLST-based sequence to implement strcmp(). The two input operands
113 // are the addresses of the strings to compare.
114 STRCMP,
115
Richard Sandiford0dec06a2013-08-16 11:41:43 +0000116 // Use an SRST-based sequence to search a block of memory. The first
117 // operand is the end address, the second is the start, and the third
118 // is the character to search for. CC is set to 1 on success and 2
119 // on failure.
120 SEARCH_STRING,
121
Richard Sandiford564681c2013-08-12 10:28:10 +0000122 // Store the CC value in bits 29 and 28 of an integer.
123 IPM,
124
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000125 // Wrappers around the inner loop of an 8- or 16-bit ATOMIC_SWAP or
126 // ATOMIC_LOAD_<op>.
127 //
128 // Operand 0: the address of the containing 32-bit-aligned field
129 // Operand 1: the second operand of <op>, in the high bits of an i32
130 // for everything except ATOMIC_SWAPW
131 // Operand 2: how many bits to rotate the i32 left to bring the first
132 // operand into the high bits
133 // Operand 3: the negative of operand 2, for rotating the other way
134 // Operand 4: the width of the field in bits (8 or 16)
135 ATOMIC_SWAPW = ISD::FIRST_TARGET_MEMORY_OPCODE,
136 ATOMIC_LOADW_ADD,
137 ATOMIC_LOADW_SUB,
138 ATOMIC_LOADW_AND,
139 ATOMIC_LOADW_OR,
140 ATOMIC_LOADW_XOR,
141 ATOMIC_LOADW_NAND,
142 ATOMIC_LOADW_MIN,
143 ATOMIC_LOADW_MAX,
144 ATOMIC_LOADW_UMIN,
145 ATOMIC_LOADW_UMAX,
146
147 // A wrapper around the inner loop of an ATOMIC_CMP_SWAP.
148 //
149 // Operand 0: the address of the containing 32-bit-aligned field
150 // Operand 1: the compare value, in the low bits of an i32
151 // Operand 2: the swap value, in the low bits of an i32
152 // Operand 3: how many bits to rotate the i32 left to bring the first
153 // operand into the high bits
154 // Operand 4: the negative of operand 2, for rotating the other way
155 // Operand 5: the width of the field in bits (8 or 16)
Richard Sandiford03481332013-08-23 11:36:42 +0000156 ATOMIC_CMP_SWAPW,
157
158 // Prefetch from the second operand using the 4-bit control code in
159 // the first operand. The code is 1 for a load prefetch and 2 for
160 // a store prefetch.
161 PREFETCH
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000162 };
163}
164
Richard Sandiford5bc670b2013-09-06 11:51:39 +0000165namespace SystemZICMP {
166 // Describes whether an integer comparison needs to be signed or unsigned,
167 // or whether either type is OK.
168 enum {
169 Any,
170 UnsignedOnly,
171 SignedOnly
172 };
173}
174
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000175class SystemZSubtarget;
176class SystemZTargetMachine;
177
178class SystemZTargetLowering : public TargetLowering {
179public:
180 explicit SystemZTargetLowering(SystemZTargetMachine &TM);
181
182 // Override TargetLowering.
183 virtual MVT getScalarShiftAmountTy(EVT LHSTy) const LLVM_OVERRIDE {
184 return MVT::i32;
185 }
Richard Sandiford791bea42013-07-31 12:58:26 +0000186 virtual EVT getSetCCResultType(LLVMContext &, EVT) const LLVM_OVERRIDE {
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000187 return MVT::i32;
188 }
Stephen Lin73de7bf2013-07-09 18:16:56 +0000189 virtual bool isFMAFasterThanFMulAndFAdd(EVT VT) const LLVM_OVERRIDE;
Richard Sandiford791bea42013-07-31 12:58:26 +0000190 virtual bool isFPImmLegal(const APFloat &Imm, EVT VT) const LLVM_OVERRIDE;
191 virtual bool isLegalAddressingMode(const AddrMode &AM, Type *Ty) const
192 LLVM_OVERRIDE;
193 virtual bool allowsUnalignedMemoryAccesses(EVT VT, bool *Fast) const
194 LLVM_OVERRIDE;
Richard Sandiford709bda62013-08-19 12:42:31 +0000195 virtual bool isTruncateFree(Type *, Type *) const LLVM_OVERRIDE;
196 virtual bool isTruncateFree(EVT, EVT) const LLVM_OVERRIDE;
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000197 virtual const char *getTargetNodeName(unsigned Opcode) const LLVM_OVERRIDE;
198 virtual std::pair<unsigned, const TargetRegisterClass *>
199 getRegForInlineAsmConstraint(const std::string &Constraint,
Chad Rosier295bd432013-06-22 18:37:38 +0000200 MVT VT) const LLVM_OVERRIDE;
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000201 virtual TargetLowering::ConstraintType
202 getConstraintType(const std::string &Constraint) const LLVM_OVERRIDE;
203 virtual TargetLowering::ConstraintWeight
204 getSingleConstraintMatchWeight(AsmOperandInfo &info,
205 const char *constraint) const LLVM_OVERRIDE;
206 virtual void
207 LowerAsmOperandForConstraint(SDValue Op,
208 std::string &Constraint,
209 std::vector<SDValue> &Ops,
210 SelectionDAG &DAG) const LLVM_OVERRIDE;
211 virtual MachineBasicBlock *
212 EmitInstrWithCustomInserter(MachineInstr *MI,
213 MachineBasicBlock *BB) const LLVM_OVERRIDE;
214 virtual SDValue LowerOperation(SDValue Op,
215 SelectionDAG &DAG) const LLVM_OVERRIDE;
Richard Sandiford709bda62013-08-19 12:42:31 +0000216 virtual bool allowTruncateForTailCall(Type *, Type *) const LLVM_OVERRIDE;
217 virtual bool mayBeEmittedAsTailCall(CallInst *CI) const LLVM_OVERRIDE;
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000218 virtual SDValue
219 LowerFormalArguments(SDValue Chain,
220 CallingConv::ID CallConv, bool isVarArg,
221 const SmallVectorImpl<ISD::InputArg> &Ins,
Andrew Trickef9de2a2013-05-25 02:42:55 +0000222 SDLoc DL, SelectionDAG &DAG,
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000223 SmallVectorImpl<SDValue> &InVals) const LLVM_OVERRIDE;
224 virtual SDValue
225 LowerCall(CallLoweringInfo &CLI,
226 SmallVectorImpl<SDValue> &InVals) const LLVM_OVERRIDE;
227
228 virtual SDValue
229 LowerReturn(SDValue Chain,
230 CallingConv::ID CallConv, bool IsVarArg,
231 const SmallVectorImpl<ISD::OutputArg> &Outs,
232 const SmallVectorImpl<SDValue> &OutVals,
Andrew Trickef9de2a2013-05-25 02:42:55 +0000233 SDLoc DL, SelectionDAG &DAG) const LLVM_OVERRIDE;
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000234
235private:
236 const SystemZSubtarget &Subtarget;
237 const SystemZTargetMachine &TM;
238
239 // Implement LowerOperation for individual opcodes.
240 SDValue lowerBR_CC(SDValue Op, SelectionDAG &DAG) const;
241 SDValue lowerSELECT_CC(SDValue Op, SelectionDAG &DAG) const;
242 SDValue lowerGlobalAddress(GlobalAddressSDNode *Node,
243 SelectionDAG &DAG) const;
244 SDValue lowerGlobalTLSAddress(GlobalAddressSDNode *Node,
245 SelectionDAG &DAG) const;
246 SDValue lowerBlockAddress(BlockAddressSDNode *Node,
247 SelectionDAG &DAG) const;
248 SDValue lowerJumpTable(JumpTableSDNode *JT, SelectionDAG &DAG) const;
249 SDValue lowerConstantPool(ConstantPoolSDNode *CP, SelectionDAG &DAG) const;
250 SDValue lowerVASTART(SDValue Op, SelectionDAG &DAG) const;
251 SDValue lowerVACOPY(SDValue Op, SelectionDAG &DAG) const;
252 SDValue lowerDYNAMIC_STACKALLOC(SDValue Op, SelectionDAG &DAG) const;
Richard Sandiford7d86e472013-08-21 09:34:56 +0000253 SDValue lowerSMUL_LOHI(SDValue Op, SelectionDAG &DAG) const;
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000254 SDValue lowerUMUL_LOHI(SDValue Op, SelectionDAG &DAG) const;
255 SDValue lowerSDIVREM(SDValue Op, SelectionDAG &DAG) const;
256 SDValue lowerUDIVREM(SDValue Op, SelectionDAG &DAG) const;
257 SDValue lowerBITCAST(SDValue Op, SelectionDAG &DAG) const;
258 SDValue lowerOR(SDValue Op, SelectionDAG &DAG) const;
259 SDValue lowerATOMIC_LOAD(SDValue Op, SelectionDAG &DAG,
260 unsigned Opcode) const;
261 SDValue lowerATOMIC_CMP_SWAP(SDValue Op, SelectionDAG &DAG) const;
262 SDValue lowerSTACKSAVE(SDValue Op, SelectionDAG &DAG) const;
263 SDValue lowerSTACKRESTORE(SDValue Op, SelectionDAG &DAG) const;
Richard Sandiford03481332013-08-23 11:36:42 +0000264 SDValue lowerPREFETCH(SDValue Op, SelectionDAG &DAG) const;
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000265
Richard Sandiford0fb90ab2013-05-28 10:41:11 +0000266 // If the last instruction before MBBI in MBB was some form of COMPARE,
267 // try to replace it with a COMPARE AND BRANCH just before MBBI.
268 // CCMask and Target are the BRC-like operands for the branch.
269 // Return true if the change was made.
270 bool convertPrevCompareToBranch(MachineBasicBlock *MBB,
271 MachineBasicBlock::iterator MBBI,
272 unsigned CCMask,
273 MachineBasicBlock *Target) const;
274
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000275 // Implement EmitInstrWithCustomInserter for individual operation types.
276 MachineBasicBlock *emitSelect(MachineInstr *MI,
277 MachineBasicBlock *BB) const;
Richard Sandifordb86a8342013-06-27 09:27:40 +0000278 MachineBasicBlock *emitCondStore(MachineInstr *MI,
279 MachineBasicBlock *BB,
Richard Sandiforda68e6f52013-07-25 08:57:02 +0000280 unsigned StoreOpcode, unsigned STOCOpcode,
281 bool Invert) const;
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000282 MachineBasicBlock *emitExt128(MachineInstr *MI,
283 MachineBasicBlock *MBB,
284 bool ClearEven, unsigned SubReg) const;
285 MachineBasicBlock *emitAtomicLoadBinary(MachineInstr *MI,
286 MachineBasicBlock *BB,
287 unsigned BinOpcode, unsigned BitSize,
288 bool Invert = false) const;
289 MachineBasicBlock *emitAtomicLoadMinMax(MachineInstr *MI,
290 MachineBasicBlock *MBB,
291 unsigned CompareOpcode,
292 unsigned KeepOldMask,
293 unsigned BitSize) const;
294 MachineBasicBlock *emitAtomicCmpSwapW(MachineInstr *MI,
295 MachineBasicBlock *BB) const;
Richard Sandiford564681c2013-08-12 10:28:10 +0000296 MachineBasicBlock *emitMemMemWrapper(MachineInstr *MI,
297 MachineBasicBlock *BB,
298 unsigned Opcode) const;
Richard Sandifordca232712013-08-16 11:21:54 +0000299 MachineBasicBlock *emitStringWrapper(MachineInstr *MI,
300 MachineBasicBlock *BB,
301 unsigned Opcode) const;
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000302};
303} // end namespace llvm
304
305#endif // LLVM_TARGET_SystemZ_ISELLOWERING_H