blob: 4098ff34b38125dac199e88a282d478d9e7ca352 [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,
35
36 // Wraps a TargetGlobalAddress that should be loaded using PC-relative
37 // accesses (LARL). Operand 0 is the address.
38 PCREL_WRAPPER,
39
40 // Signed integer and floating-point comparisons. The operands are the
41 // two values to compare.
42 CMP,
43
44 // Likewise unsigned integer comparison.
45 UCMP,
46
47 // Branches if a condition is true. Operand 0 is the chain operand;
48 // operand 1 is the 4-bit condition-code mask, with bit N in
49 // big-endian order meaning "branch if CC=N"; operand 2 is the
50 // target block and operand 3 is the flag operand.
51 BR_CCMASK,
52
53 // Selects between operand 0 and operand 1. Operand 2 is the
54 // mask of condition-code values for which operand 0 should be
55 // chosen over operand 1; it has the same form as BR_CCMASK.
56 // Operand 3 is the flag operand.
57 SELECT_CCMASK,
58
59 // Evaluates to the gap between the stack pointer and the
60 // base of the dynamically-allocatable area.
61 ADJDYNALLOC,
62
63 // Extracts the value of a 32-bit access register. Operand 0 is
64 // the number of the register.
65 EXTRACT_ACCESS,
66
67 // Wrappers around the ISD opcodes of the same name. The output and
68 // first input operands are GR128s. The trailing numbers are the
69 // widths of the second operand in bits.
70 UMUL_LOHI64,
Richard Sandiforde6e78852013-07-02 15:40:22 +000071 SDIVREM32,
Ulrich Weigand5f613df2013-05-06 16:15:19 +000072 SDIVREM64,
73 UDIVREM32,
74 UDIVREM64,
75
Richard Sandifordd131ff82013-07-08 09:35:23 +000076 // Use MVC to copy bytes from one memory location to another.
77 // The first operand is the target address, the second operand is the
78 // source address, and the third operand is the constant length.
79 // This isn't a memory opcode because we'd need to attach two
80 // MachineMemOperands rather than one.
81 MVC,
82
Richard Sandiford761703a2013-08-12 10:17:33 +000083 // Use CLC to compare two blocks of memory, with the same comments
84 // as for MVC.
85 CLC,
86
Ulrich Weigand5f613df2013-05-06 16:15:19 +000087 // Wrappers around the inner loop of an 8- or 16-bit ATOMIC_SWAP or
88 // ATOMIC_LOAD_<op>.
89 //
90 // Operand 0: the address of the containing 32-bit-aligned field
91 // Operand 1: the second operand of <op>, in the high bits of an i32
92 // for everything except ATOMIC_SWAPW
93 // Operand 2: how many bits to rotate the i32 left to bring the first
94 // operand into the high bits
95 // Operand 3: the negative of operand 2, for rotating the other way
96 // Operand 4: the width of the field in bits (8 or 16)
97 ATOMIC_SWAPW = ISD::FIRST_TARGET_MEMORY_OPCODE,
98 ATOMIC_LOADW_ADD,
99 ATOMIC_LOADW_SUB,
100 ATOMIC_LOADW_AND,
101 ATOMIC_LOADW_OR,
102 ATOMIC_LOADW_XOR,
103 ATOMIC_LOADW_NAND,
104 ATOMIC_LOADW_MIN,
105 ATOMIC_LOADW_MAX,
106 ATOMIC_LOADW_UMIN,
107 ATOMIC_LOADW_UMAX,
108
109 // A wrapper around the inner loop of an ATOMIC_CMP_SWAP.
110 //
111 // Operand 0: the address of the containing 32-bit-aligned field
112 // Operand 1: the compare value, in the low bits of an i32
113 // Operand 2: the swap value, in the low bits of an i32
114 // Operand 3: how many bits to rotate the i32 left to bring the first
115 // operand into the high bits
116 // Operand 4: the negative of operand 2, for rotating the other way
117 // Operand 5: the width of the field in bits (8 or 16)
118 ATOMIC_CMP_SWAPW
119 };
120}
121
122class SystemZSubtarget;
123class SystemZTargetMachine;
124
125class SystemZTargetLowering : public TargetLowering {
126public:
127 explicit SystemZTargetLowering(SystemZTargetMachine &TM);
128
129 // Override TargetLowering.
130 virtual MVT getScalarShiftAmountTy(EVT LHSTy) const LLVM_OVERRIDE {
131 return MVT::i32;
132 }
Richard Sandiford791bea42013-07-31 12:58:26 +0000133 virtual EVT getSetCCResultType(LLVMContext &, EVT) const LLVM_OVERRIDE {
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000134 return MVT::i32;
135 }
Stephen Lin73de7bf2013-07-09 18:16:56 +0000136 virtual bool isFMAFasterThanFMulAndFAdd(EVT VT) const LLVM_OVERRIDE;
Richard Sandiford791bea42013-07-31 12:58:26 +0000137 virtual bool isFPImmLegal(const APFloat &Imm, EVT VT) const LLVM_OVERRIDE;
138 virtual bool isLegalAddressingMode(const AddrMode &AM, Type *Ty) const
139 LLVM_OVERRIDE;
140 virtual bool allowsUnalignedMemoryAccesses(EVT VT, bool *Fast) const
141 LLVM_OVERRIDE;
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000142 virtual const char *getTargetNodeName(unsigned Opcode) const LLVM_OVERRIDE;
143 virtual std::pair<unsigned, const TargetRegisterClass *>
144 getRegForInlineAsmConstraint(const std::string &Constraint,
Chad Rosier295bd432013-06-22 18:37:38 +0000145 MVT VT) const LLVM_OVERRIDE;
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000146 virtual TargetLowering::ConstraintType
147 getConstraintType(const std::string &Constraint) const LLVM_OVERRIDE;
148 virtual TargetLowering::ConstraintWeight
149 getSingleConstraintMatchWeight(AsmOperandInfo &info,
150 const char *constraint) const LLVM_OVERRIDE;
151 virtual void
152 LowerAsmOperandForConstraint(SDValue Op,
153 std::string &Constraint,
154 std::vector<SDValue> &Ops,
155 SelectionDAG &DAG) const LLVM_OVERRIDE;
156 virtual MachineBasicBlock *
157 EmitInstrWithCustomInserter(MachineInstr *MI,
158 MachineBasicBlock *BB) const LLVM_OVERRIDE;
159 virtual SDValue LowerOperation(SDValue Op,
160 SelectionDAG &DAG) const LLVM_OVERRIDE;
161 virtual SDValue
162 LowerFormalArguments(SDValue Chain,
163 CallingConv::ID CallConv, bool isVarArg,
164 const SmallVectorImpl<ISD::InputArg> &Ins,
Andrew Trickef9de2a2013-05-25 02:42:55 +0000165 SDLoc DL, SelectionDAG &DAG,
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000166 SmallVectorImpl<SDValue> &InVals) const LLVM_OVERRIDE;
167 virtual SDValue
168 LowerCall(CallLoweringInfo &CLI,
169 SmallVectorImpl<SDValue> &InVals) const LLVM_OVERRIDE;
170
171 virtual SDValue
172 LowerReturn(SDValue Chain,
173 CallingConv::ID CallConv, bool IsVarArg,
174 const SmallVectorImpl<ISD::OutputArg> &Outs,
175 const SmallVectorImpl<SDValue> &OutVals,
Andrew Trickef9de2a2013-05-25 02:42:55 +0000176 SDLoc DL, SelectionDAG &DAG) const LLVM_OVERRIDE;
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000177
178private:
179 const SystemZSubtarget &Subtarget;
180 const SystemZTargetMachine &TM;
181
182 // Implement LowerOperation for individual opcodes.
183 SDValue lowerBR_CC(SDValue Op, SelectionDAG &DAG) const;
184 SDValue lowerSELECT_CC(SDValue Op, SelectionDAG &DAG) const;
185 SDValue lowerGlobalAddress(GlobalAddressSDNode *Node,
186 SelectionDAG &DAG) const;
187 SDValue lowerGlobalTLSAddress(GlobalAddressSDNode *Node,
188 SelectionDAG &DAG) const;
189 SDValue lowerBlockAddress(BlockAddressSDNode *Node,
190 SelectionDAG &DAG) const;
191 SDValue lowerJumpTable(JumpTableSDNode *JT, SelectionDAG &DAG) const;
192 SDValue lowerConstantPool(ConstantPoolSDNode *CP, SelectionDAG &DAG) const;
193 SDValue lowerVASTART(SDValue Op, SelectionDAG &DAG) const;
194 SDValue lowerVACOPY(SDValue Op, SelectionDAG &DAG) const;
195 SDValue lowerDYNAMIC_STACKALLOC(SDValue Op, SelectionDAG &DAG) const;
196 SDValue lowerUMUL_LOHI(SDValue Op, SelectionDAG &DAG) const;
197 SDValue lowerSDIVREM(SDValue Op, SelectionDAG &DAG) const;
198 SDValue lowerUDIVREM(SDValue Op, SelectionDAG &DAG) const;
199 SDValue lowerBITCAST(SDValue Op, SelectionDAG &DAG) const;
200 SDValue lowerOR(SDValue Op, SelectionDAG &DAG) const;
201 SDValue lowerATOMIC_LOAD(SDValue Op, SelectionDAG &DAG,
202 unsigned Opcode) const;
203 SDValue lowerATOMIC_CMP_SWAP(SDValue Op, SelectionDAG &DAG) const;
204 SDValue lowerSTACKSAVE(SDValue Op, SelectionDAG &DAG) const;
205 SDValue lowerSTACKRESTORE(SDValue Op, SelectionDAG &DAG) const;
206
Richard Sandiford0fb90ab2013-05-28 10:41:11 +0000207 // If the last instruction before MBBI in MBB was some form of COMPARE,
208 // try to replace it with a COMPARE AND BRANCH just before MBBI.
209 // CCMask and Target are the BRC-like operands for the branch.
210 // Return true if the change was made.
211 bool convertPrevCompareToBranch(MachineBasicBlock *MBB,
212 MachineBasicBlock::iterator MBBI,
213 unsigned CCMask,
214 MachineBasicBlock *Target) const;
215
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000216 // Implement EmitInstrWithCustomInserter for individual operation types.
217 MachineBasicBlock *emitSelect(MachineInstr *MI,
218 MachineBasicBlock *BB) const;
Richard Sandifordb86a8342013-06-27 09:27:40 +0000219 MachineBasicBlock *emitCondStore(MachineInstr *MI,
220 MachineBasicBlock *BB,
Richard Sandiforda68e6f52013-07-25 08:57:02 +0000221 unsigned StoreOpcode, unsigned STOCOpcode,
222 bool Invert) const;
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000223 MachineBasicBlock *emitExt128(MachineInstr *MI,
224 MachineBasicBlock *MBB,
225 bool ClearEven, unsigned SubReg) const;
226 MachineBasicBlock *emitAtomicLoadBinary(MachineInstr *MI,
227 MachineBasicBlock *BB,
228 unsigned BinOpcode, unsigned BitSize,
229 bool Invert = false) const;
230 MachineBasicBlock *emitAtomicLoadMinMax(MachineInstr *MI,
231 MachineBasicBlock *MBB,
232 unsigned CompareOpcode,
233 unsigned KeepOldMask,
234 unsigned BitSize) const;
235 MachineBasicBlock *emitAtomicCmpSwapW(MachineInstr *MI,
236 MachineBasicBlock *BB) const;
Richard Sandifordd131ff82013-07-08 09:35:23 +0000237 MachineBasicBlock *emitMVCWrapper(MachineInstr *MI,
238 MachineBasicBlock *BB) const;
Ulrich Weigand5f613df2013-05-06 16:15:19 +0000239};
240} // end namespace llvm
241
242#endif // LLVM_TARGET_SystemZ_ISELLOWERING_H