blob: 9831777873a151118481ce190522dcd596e3a971 [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
41 // Signed integer and floating-point comparisons. The operands are the
42 // two values to compare.
43 CMP,
44
45 // Likewise unsigned integer comparison.
46 UCMP,
47
48 // Branches if a condition is true. Operand 0 is the chain operand;
49 // operand 1 is the 4-bit condition-code mask, with bit N in
50 // big-endian order meaning "branch if CC=N"; operand 2 is the
51 // target block and operand 3 is the flag operand.
52 BR_CCMASK,
53
54 // Selects between operand 0 and operand 1. Operand 2 is the
55 // mask of condition-code values for which operand 0 should be
56 // chosen over operand 1; it has the same form as BR_CCMASK.
57 // Operand 3 is the flag operand.
58 SELECT_CCMASK,
59
60 // Evaluates to the gap between the stack pointer and the
61 // base of the dynamically-allocatable area.
62 ADJDYNALLOC,
63
64 // Extracts the value of a 32-bit access register. Operand 0 is
65 // the number of the register.
66 EXTRACT_ACCESS,
67
68 // Wrappers around the ISD opcodes of the same name. The output and
69 // first input operands are GR128s. The trailing numbers are the
70 // widths of the second operand in bits.
71 UMUL_LOHI64,
Richard Sandiforde6e78852013-07-02 15:40:22 +000072 SDIVREM32,
Ulrich Weigand5f613df2013-05-06 16:15:19 +000073 SDIVREM64,
74 UDIVREM32,
75 UDIVREM64,
76
Richard Sandiford5e318f02013-08-27 09:54:29 +000077 // Use a series of MVCs to copy bytes from one memory location to another.
78 // The operands are:
79 // - the target address
80 // - the source address
81 // - the constant length
82 //
Richard Sandifordd131ff82013-07-08 09:35:23 +000083 // This isn't a memory opcode because we'd need to attach two
84 // MachineMemOperands rather than one.
85 MVC,
86
Richard Sandiford5e318f02013-08-27 09:54:29 +000087 // Like MVC, but implemented as a loop that handles X*256 bytes
88 // followed by straight-line code to handle the rest (if any).
89 // The value of X is passed as an additional operand.
90 MVC_LOOP,
91
Richard Sandiford761703a2013-08-12 10:17:33 +000092 // Use CLC to compare two blocks of memory, with the same comments
Richard Sandiford5e318f02013-08-27 09:54:29 +000093 // as for MVC and MVC_LOOP.
Richard Sandiford761703a2013-08-12 10:17:33 +000094 CLC,
Richard Sandiford5e318f02013-08-27 09:54:29 +000095 CLC_LOOP,
Richard Sandiford761703a2013-08-12 10:17:33 +000096
Richard Sandifordbb83a502013-08-16 11:29:37 +000097 // Use an MVST-based sequence to implement stpcpy().
98 STPCPY,
99
Richard Sandifordca232712013-08-16 11:21:54 +0000100 // Use a CLST-based sequence to implement strcmp(). The two input operands
101 // are the addresses of the strings to compare.
102 STRCMP,
103
Richard Sandiford0dec06a2013-08-16 11:41:43 +0000104 // Use an SRST-based sequence to search a block of memory. The first
105 // operand is the end address, the second is the start, and the third
106 // is the character to search for. CC is set to 1 on success and 2
107 // on failure.
108 SEARCH_STRING,
109
Richard Sandiford564681c2013-08-12 10:28:10 +0000110 // Store the CC value in bits 29 and 28 of an integer.
111 IPM,
112
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000113 // Wrappers around the inner loop of an 8- or 16-bit ATOMIC_SWAP or
114 // ATOMIC_LOAD_<op>.
115 //
116 // Operand 0: the address of the containing 32-bit-aligned field
117 // Operand 1: the second operand of <op>, in the high bits of an i32
118 // for everything except ATOMIC_SWAPW
119 // Operand 2: how many bits to rotate the i32 left to bring the first
120 // operand into the high bits
121 // Operand 3: the negative of operand 2, for rotating the other way
122 // Operand 4: the width of the field in bits (8 or 16)
123 ATOMIC_SWAPW = ISD::FIRST_TARGET_MEMORY_OPCODE,
124 ATOMIC_LOADW_ADD,
125 ATOMIC_LOADW_SUB,
126 ATOMIC_LOADW_AND,
127 ATOMIC_LOADW_OR,
128 ATOMIC_LOADW_XOR,
129 ATOMIC_LOADW_NAND,
130 ATOMIC_LOADW_MIN,
131 ATOMIC_LOADW_MAX,
132 ATOMIC_LOADW_UMIN,
133 ATOMIC_LOADW_UMAX,
134
135 // A wrapper around the inner loop of an ATOMIC_CMP_SWAP.
136 //
137 // Operand 0: the address of the containing 32-bit-aligned field
138 // Operand 1: the compare value, in the low bits of an i32
139 // Operand 2: the swap value, in the low bits of an i32
140 // Operand 3: how many bits to rotate the i32 left to bring the first
141 // operand into the high bits
142 // Operand 4: the negative of operand 2, for rotating the other way
143 // Operand 5: the width of the field in bits (8 or 16)
Richard Sandiford03481332013-08-23 11:36:42 +0000144 ATOMIC_CMP_SWAPW,
145
146 // Prefetch from the second operand using the 4-bit control code in
147 // the first operand. The code is 1 for a load prefetch and 2 for
148 // a store prefetch.
149 PREFETCH
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000150 };
151}
152
153class SystemZSubtarget;
154class SystemZTargetMachine;
155
156class SystemZTargetLowering : public TargetLowering {
157public:
158 explicit SystemZTargetLowering(SystemZTargetMachine &TM);
159
160 // Override TargetLowering.
161 virtual MVT getScalarShiftAmountTy(EVT LHSTy) const LLVM_OVERRIDE {
162 return MVT::i32;
163 }
Richard Sandiford791bea42013-07-31 12:58:26 +0000164 virtual EVT getSetCCResultType(LLVMContext &, EVT) const LLVM_OVERRIDE {
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000165 return MVT::i32;
166 }
Stephen Lin73de7bf2013-07-09 18:16:56 +0000167 virtual bool isFMAFasterThanFMulAndFAdd(EVT VT) const LLVM_OVERRIDE;
Richard Sandiford791bea42013-07-31 12:58:26 +0000168 virtual bool isFPImmLegal(const APFloat &Imm, EVT VT) const LLVM_OVERRIDE;
169 virtual bool isLegalAddressingMode(const AddrMode &AM, Type *Ty) const
170 LLVM_OVERRIDE;
171 virtual bool allowsUnalignedMemoryAccesses(EVT VT, bool *Fast) const
172 LLVM_OVERRIDE;
Richard Sandiford709bda62013-08-19 12:42:31 +0000173 virtual bool isTruncateFree(Type *, Type *) const LLVM_OVERRIDE;
174 virtual bool isTruncateFree(EVT, EVT) const LLVM_OVERRIDE;
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000175 virtual const char *getTargetNodeName(unsigned Opcode) const LLVM_OVERRIDE;
176 virtual std::pair<unsigned, const TargetRegisterClass *>
177 getRegForInlineAsmConstraint(const std::string &Constraint,
Chad Rosier295bd432013-06-22 18:37:38 +0000178 MVT VT) const LLVM_OVERRIDE;
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000179 virtual TargetLowering::ConstraintType
180 getConstraintType(const std::string &Constraint) const LLVM_OVERRIDE;
181 virtual TargetLowering::ConstraintWeight
182 getSingleConstraintMatchWeight(AsmOperandInfo &info,
183 const char *constraint) const LLVM_OVERRIDE;
184 virtual void
185 LowerAsmOperandForConstraint(SDValue Op,
186 std::string &Constraint,
187 std::vector<SDValue> &Ops,
188 SelectionDAG &DAG) const LLVM_OVERRIDE;
189 virtual MachineBasicBlock *
190 EmitInstrWithCustomInserter(MachineInstr *MI,
191 MachineBasicBlock *BB) const LLVM_OVERRIDE;
192 virtual SDValue LowerOperation(SDValue Op,
193 SelectionDAG &DAG) const LLVM_OVERRIDE;
Richard Sandiford709bda62013-08-19 12:42:31 +0000194 virtual bool allowTruncateForTailCall(Type *, Type *) const LLVM_OVERRIDE;
195 virtual bool mayBeEmittedAsTailCall(CallInst *CI) const LLVM_OVERRIDE;
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000196 virtual SDValue
197 LowerFormalArguments(SDValue Chain,
198 CallingConv::ID CallConv, bool isVarArg,
199 const SmallVectorImpl<ISD::InputArg> &Ins,
Andrew Trickef9de2a2013-05-25 02:42:55 +0000200 SDLoc DL, SelectionDAG &DAG,
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000201 SmallVectorImpl<SDValue> &InVals) const LLVM_OVERRIDE;
202 virtual SDValue
203 LowerCall(CallLoweringInfo &CLI,
204 SmallVectorImpl<SDValue> &InVals) const LLVM_OVERRIDE;
205
206 virtual SDValue
207 LowerReturn(SDValue Chain,
208 CallingConv::ID CallConv, bool IsVarArg,
209 const SmallVectorImpl<ISD::OutputArg> &Outs,
210 const SmallVectorImpl<SDValue> &OutVals,
Andrew Trickef9de2a2013-05-25 02:42:55 +0000211 SDLoc DL, SelectionDAG &DAG) const LLVM_OVERRIDE;
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000212
213private:
214 const SystemZSubtarget &Subtarget;
215 const SystemZTargetMachine &TM;
216
217 // Implement LowerOperation for individual opcodes.
218 SDValue lowerBR_CC(SDValue Op, SelectionDAG &DAG) const;
219 SDValue lowerSELECT_CC(SDValue Op, SelectionDAG &DAG) const;
220 SDValue lowerGlobalAddress(GlobalAddressSDNode *Node,
221 SelectionDAG &DAG) const;
222 SDValue lowerGlobalTLSAddress(GlobalAddressSDNode *Node,
223 SelectionDAG &DAG) const;
224 SDValue lowerBlockAddress(BlockAddressSDNode *Node,
225 SelectionDAG &DAG) const;
226 SDValue lowerJumpTable(JumpTableSDNode *JT, SelectionDAG &DAG) const;
227 SDValue lowerConstantPool(ConstantPoolSDNode *CP, SelectionDAG &DAG) const;
228 SDValue lowerVASTART(SDValue Op, SelectionDAG &DAG) const;
229 SDValue lowerVACOPY(SDValue Op, SelectionDAG &DAG) const;
230 SDValue lowerDYNAMIC_STACKALLOC(SDValue Op, SelectionDAG &DAG) const;
Richard Sandiford7d86e472013-08-21 09:34:56 +0000231 SDValue lowerSMUL_LOHI(SDValue Op, SelectionDAG &DAG) const;
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000232 SDValue lowerUMUL_LOHI(SDValue Op, SelectionDAG &DAG) const;
233 SDValue lowerSDIVREM(SDValue Op, SelectionDAG &DAG) const;
234 SDValue lowerUDIVREM(SDValue Op, SelectionDAG &DAG) const;
235 SDValue lowerBITCAST(SDValue Op, SelectionDAG &DAG) const;
236 SDValue lowerOR(SDValue Op, SelectionDAG &DAG) const;
237 SDValue lowerATOMIC_LOAD(SDValue Op, SelectionDAG &DAG,
238 unsigned Opcode) const;
239 SDValue lowerATOMIC_CMP_SWAP(SDValue Op, SelectionDAG &DAG) const;
240 SDValue lowerSTACKSAVE(SDValue Op, SelectionDAG &DAG) const;
241 SDValue lowerSTACKRESTORE(SDValue Op, SelectionDAG &DAG) const;
Richard Sandiford03481332013-08-23 11:36:42 +0000242 SDValue lowerPREFETCH(SDValue Op, SelectionDAG &DAG) const;
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000243
Richard Sandiford0fb90ab2013-05-28 10:41:11 +0000244 // If the last instruction before MBBI in MBB was some form of COMPARE,
245 // try to replace it with a COMPARE AND BRANCH just before MBBI.
246 // CCMask and Target are the BRC-like operands for the branch.
247 // Return true if the change was made.
248 bool convertPrevCompareToBranch(MachineBasicBlock *MBB,
249 MachineBasicBlock::iterator MBBI,
250 unsigned CCMask,
251 MachineBasicBlock *Target) const;
252
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000253 // Implement EmitInstrWithCustomInserter for individual operation types.
254 MachineBasicBlock *emitSelect(MachineInstr *MI,
255 MachineBasicBlock *BB) const;
Richard Sandifordb86a8342013-06-27 09:27:40 +0000256 MachineBasicBlock *emitCondStore(MachineInstr *MI,
257 MachineBasicBlock *BB,
Richard Sandiforda68e6f52013-07-25 08:57:02 +0000258 unsigned StoreOpcode, unsigned STOCOpcode,
259 bool Invert) const;
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000260 MachineBasicBlock *emitExt128(MachineInstr *MI,
261 MachineBasicBlock *MBB,
262 bool ClearEven, unsigned SubReg) const;
263 MachineBasicBlock *emitAtomicLoadBinary(MachineInstr *MI,
264 MachineBasicBlock *BB,
265 unsigned BinOpcode, unsigned BitSize,
266 bool Invert = false) const;
267 MachineBasicBlock *emitAtomicLoadMinMax(MachineInstr *MI,
268 MachineBasicBlock *MBB,
269 unsigned CompareOpcode,
270 unsigned KeepOldMask,
271 unsigned BitSize) const;
272 MachineBasicBlock *emitAtomicCmpSwapW(MachineInstr *MI,
273 MachineBasicBlock *BB) const;
Richard Sandiford564681c2013-08-12 10:28:10 +0000274 MachineBasicBlock *emitMemMemWrapper(MachineInstr *MI,
275 MachineBasicBlock *BB,
276 unsigned Opcode) const;
Richard Sandifordca232712013-08-16 11:21:54 +0000277 MachineBasicBlock *emitStringWrapper(MachineInstr *MI,
278 MachineBasicBlock *BB,
279 unsigned Opcode) const;
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000280};
281} // end namespace llvm
282
283#endif // LLVM_TARGET_SystemZ_ISELLOWERING_H