blob: 82f10270db3d6909933083c20026209fb74f22ca [file] [log] [blame]
Scott Michel6e22c652007-12-04 22:23:35 +00001//===-- SPUISelLowering.h - Cell SPU DAG Lowering Interface -----*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattnerf3ebc3f2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Scott Michel6e22c652007-12-04 22:23:35 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file defines the interfaces that Cell SPU uses to lower LLVM code into
11// a selection DAG.
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef SPU_ISELLOWERING_H
16#define SPU_ISELLOWERING_H
17
18#include "llvm/Target/TargetLowering.h"
19#include "llvm/CodeGen/SelectionDAG.h"
20#include "SPU.h"
21
22namespace llvm {
23 namespace SPUISD {
24 enum NodeType {
25 // Start the numbering where the builting ops and target ops leave off.
Dan Gohmaned1cf1a2008-09-23 18:42:32 +000026 FIRST_NUMBER = ISD::BUILTIN_OP_END,
Scott Michel41236c02008-12-30 23:28:25 +000027
Scott Michel6e22c652007-12-04 22:23:35 +000028 // Pseudo instructions:
29 RET_FLAG, ///< Return with flag, matched by bi instruction
Scott Michel41236c02008-12-30 23:28:25 +000030
Scott Michel6e22c652007-12-04 22:23:35 +000031 Hi, ///< High address component (upper 16)
32 Lo, ///< Low address component (lower 16)
33 PCRelAddr, ///< Program counter relative address
Scott Michel8d5841a2008-01-11 02:53:15 +000034 AFormAddr, ///< A-form address (local store)
Scott Michelceae3bb2008-01-29 02:16:57 +000035 IndirectAddr, ///< D-Form "imm($r)" and X-form "$r($r)"
Scott Michel6e22c652007-12-04 22:23:35 +000036
37 LDRESULT, ///< Load result (value, chain)
38 CALL, ///< CALL instruction
39 SHUFB, ///< Vector shuffle (permute)
Scott Michel0be03392008-11-22 23:50:42 +000040 SHUFFLE_MASK, ///< Shuffle mask
Scott Michelbb713ae2008-01-30 02:55:46 +000041 CNTB, ///< Count leading ones in bytes
Scott Michel82335272008-12-27 04:51:36 +000042 PREFSLOT2VEC, ///< Promote scalar->vector
Scott Michelefc8c7a2008-11-24 17:11:17 +000043 VEC2PREFSLOT, ///< Extract element 0
Kalle Raiskila0a9dd402010-11-12 10:14:03 +000044 SHL_BITS, ///< Shift quad left, by bits
45 SHL_BYTES, ///< Shift quad left, by bytes
46 SRL_BYTES, ///< Shift quad right, by bytes. Insert zeros.
Scott Michelbb713ae2008-01-30 02:55:46 +000047 VEC_ROTL, ///< Vector rotate left
48 VEC_ROTR, ///< Vector rotate right
Scott Michelbb713ae2008-01-30 02:55:46 +000049 ROTBYTES_LEFT, ///< Rotate bytes (loads -> ROTQBYI)
Scott Micheld831cc42008-06-02 22:18:03 +000050 ROTBYTES_LEFT_BITS, ///< Rotate bytes left by bit shift count
51 SELECT_MASK, ///< Select Mask (FSM, FSMB, FSMH, FSMBI)
Scott Michelbb713ae2008-01-30 02:55:46 +000052 SELB, ///< Select bits -> (b & mask) | (a & ~mask)
Scott Michela292fc62009-01-15 04:41:47 +000053 // Markers: These aren't used to generate target-dependent nodes, but
54 // are used during instruction selection.
55 ADD64_MARKER, ///< i64 addition marker
56 SUB64_MARKER, ///< i64 subtraction marker
57 MUL64_MARKER, ///< i64 multiply marker
Scott Michelbb713ae2008-01-30 02:55:46 +000058 LAST_SPUISD ///< Last user-defined instruction
Scott Michel6e22c652007-12-04 22:23:35 +000059 };
60 }
61
Scott Michel9e3e4a92009-01-26 03:31:40 +000062 //! Utility functions specific to CellSPU:
Scott Michel6e22c652007-12-04 22:23:35 +000063 namespace SPU {
Dan Gohman2ce6f2a2008-07-27 21:46:04 +000064 SDValue get_vec_u18imm(SDNode *N, SelectionDAG &DAG,
Owen Anderson53aa7a92009-08-10 22:56:29 +000065 EVT ValueType);
Dan Gohman2ce6f2a2008-07-27 21:46:04 +000066 SDValue get_vec_i16imm(SDNode *N, SelectionDAG &DAG,
Owen Anderson53aa7a92009-08-10 22:56:29 +000067 EVT ValueType);
Dan Gohman2ce6f2a2008-07-27 21:46:04 +000068 SDValue get_vec_i10imm(SDNode *N, SelectionDAG &DAG,
Owen Anderson53aa7a92009-08-10 22:56:29 +000069 EVT ValueType);
Dan Gohman2ce6f2a2008-07-27 21:46:04 +000070 SDValue get_vec_i8imm(SDNode *N, SelectionDAG &DAG,
Owen Anderson53aa7a92009-08-10 22:56:29 +000071 EVT ValueType);
Dan Gohman2ce6f2a2008-07-27 21:46:04 +000072 SDValue get_ILHUvec_imm(SDNode *N, SelectionDAG &DAG,
Owen Anderson53aa7a92009-08-10 22:56:29 +000073 EVT ValueType);
Dan Gohman2ce6f2a2008-07-27 21:46:04 +000074 SDValue get_v4i32_imm(SDNode *N, SelectionDAG &DAG);
75 SDValue get_v2i64_imm(SDNode *N, SelectionDAG &DAG);
Scott Michela292fc62009-01-15 04:41:47 +000076
77 SDValue LowerConstantPool(SDValue Op, SelectionDAG &DAG,
78 const SPUTargetMachine &TM);
Owen Anderson53aa7a92009-08-10 22:56:29 +000079 //! Simplify a EVT::v2i64 constant splat to CellSPU-ready form
80 SDValue LowerV2I64Splat(EVT OpVT, SelectionDAG &DAG, uint64_t splat,
Dale Johannesen9f3f72f2009-02-06 01:31:28 +000081 DebugLoc dl);
Scott Michel6e22c652007-12-04 22:23:35 +000082 }
83
84 class SPUTargetMachine; // forward dec'l.
Scott Michel41236c02008-12-30 23:28:25 +000085
Scott Michel6e22c652007-12-04 22:23:35 +000086 class SPUTargetLowering :
87 public TargetLowering
88 {
89 int VarArgsFrameIndex; // FrameIndex for start of varargs area.
Scott Michel6e22c652007-12-04 22:23:35 +000090 SPUTargetMachine &SPUTM;
91
92 public:
Scott Michela292fc62009-01-15 04:41:47 +000093 //! The venerable constructor
94 /*!
95 This is where the CellSPU backend sets operation handling (i.e., legal,
96 custom, expand or promote.)
97 */
Scott Michel6e22c652007-12-04 22:23:35 +000098 SPUTargetLowering(SPUTargetMachine &TM);
Scott Michel41236c02008-12-30 23:28:25 +000099
Scott Michela292fc62009-01-15 04:41:47 +0000100 //! Get the target machine
101 SPUTargetMachine &getSPUTargetMachine() {
102 return SPUTM;
103 }
104
Scott Michel6e22c652007-12-04 22:23:35 +0000105 /// getTargetNodeName() - This method returns the name of a target specific
106 /// DAG node.
107 virtual const char *getTargetNodeName(unsigned Opcode) const;
Scott Michela6729e82008-03-10 15:42:14 +0000108
109 /// getSetCCResultType - Return the ValueType for ISD::SETCC
Owen Anderson9f944592009-08-11 20:47:22 +0000110 virtual MVT::SimpleValueType getSetCCResultType(EVT VT) const;
Scott Michel41236c02008-12-30 23:28:25 +0000111
Scott Michelabad22c2008-11-10 23:43:06 +0000112 //! Custom lowering hooks
Dan Gohman21cea8a2010-04-17 15:26:15 +0000113 virtual SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const;
Scott Michelabad22c2008-11-10 23:43:06 +0000114
Duncan Sands6ed40142008-12-01 11:39:25 +0000115 //! Custom lowering hook for nodes with illegal result types.
116 virtual void ReplaceNodeResults(SDNode *N, SmallVectorImpl<SDValue>&Results,
Dan Gohman21cea8a2010-04-17 15:26:15 +0000117 SelectionDAG &DAG) const;
Duncan Sands6ed40142008-12-01 11:39:25 +0000118
Dan Gohman2ce6f2a2008-07-27 21:46:04 +0000119 virtual SDValue PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const;
Scott Michel6e22c652007-12-04 22:23:35 +0000120
Dan Gohman2ce6f2a2008-07-27 21:46:04 +0000121 virtual void computeMaskedBitsForTargetNode(const SDValue Op,
Dan Gohmane1d9ee62008-02-13 22:28:48 +0000122 const APInt &Mask,
Scott Michel41236c02008-12-30 23:28:25 +0000123 APInt &KnownZero,
Dan Gohmanf990faf2008-02-13 00:35:47 +0000124 APInt &KnownOne,
Scott Michel6e22c652007-12-04 22:23:35 +0000125 const SelectionDAG &DAG,
126 unsigned Depth = 0) const;
127
Scott Michel82335272008-12-27 04:51:36 +0000128 virtual unsigned ComputeNumSignBitsForTargetNode(SDValue Op,
129 unsigned Depth = 0) const;
130
Scott Michel6e22c652007-12-04 22:23:35 +0000131 ConstraintType getConstraintType(const std::string &ConstraintLetter) const;
132
John Thompsone8360b72010-10-29 17:29:13 +0000133 /// Examine constraint string and operand type and determine a weight value.
134 /// The operand object must already have been set up with the operand type.
135 ConstraintWeight getSingleConstraintMatchWeight(
136 AsmOperandInfo &info, const char *constraint) const;
137
Scott Michel41236c02008-12-30 23:28:25 +0000138 std::pair<unsigned, const TargetRegisterClass*>
Scott Michel6e22c652007-12-04 22:23:35 +0000139 getRegForInlineAsmConstraint(const std::string &Constraint,
Owen Anderson53aa7a92009-08-10 22:56:29 +0000140 EVT VT) const;
Scott Michel6e22c652007-12-04 22:23:35 +0000141
Dan Gohman2ce6f2a2008-07-27 21:46:04 +0000142 void LowerAsmOperandForConstraint(SDValue Op, char ConstraintLetter,
143 std::vector<SDValue> &Ops,
Scott Michelc3a19102008-04-30 00:30:08 +0000144 SelectionDAG &DAG) const;
145
Scott Michel6e22c652007-12-04 22:23:35 +0000146 /// isLegalAddressImmediate - Return true if the integer value can be used
147 /// as the offset of the target addressing mode.
148 virtual bool isLegalAddressImmediate(int64_t V, const Type *Ty) const;
149 virtual bool isLegalAddressImmediate(GlobalValue *) const;
Dan Gohman2fe6bee2008-10-18 02:06:02 +0000150
151 virtual bool isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const;
Bill Wendling31ceb1b2009-06-30 22:38:32 +0000152
Bill Wendling512ff732009-07-01 18:50:55 +0000153 /// getFunctionAlignment - Return the Log2 alignment of this function.
Bill Wendling31ceb1b2009-06-30 22:38:32 +0000154 virtual unsigned getFunctionAlignment(const Function *F) const;
Dan Gohmanf9bbcd12009-08-05 01:29:28 +0000155
156 virtual SDValue
157 LowerFormalArguments(SDValue Chain,
Sandeep Patel68c5f472009-09-02 08:44:58 +0000158 CallingConv::ID CallConv, bool isVarArg,
Dan Gohmanf9bbcd12009-08-05 01:29:28 +0000159 const SmallVectorImpl<ISD::InputArg> &Ins,
160 DebugLoc dl, SelectionDAG &DAG,
Dan Gohman21cea8a2010-04-17 15:26:15 +0000161 SmallVectorImpl<SDValue> &InVals) const;
Dan Gohmanf9bbcd12009-08-05 01:29:28 +0000162
163 virtual SDValue
Evan Cheng6f36a082010-02-02 23:55:14 +0000164 LowerCall(SDValue Chain, SDValue Callee,
Sandeep Patel68c5f472009-09-02 08:44:58 +0000165 CallingConv::ID CallConv, bool isVarArg,
Evan Cheng67a69dd2010-01-27 00:07:07 +0000166 bool &isTailCall,
Dan Gohmanf9bbcd12009-08-05 01:29:28 +0000167 const SmallVectorImpl<ISD::OutputArg> &Outs,
Dan Gohmanfe7532a2010-07-07 15:54:55 +0000168 const SmallVectorImpl<SDValue> &OutVals,
Dan Gohmanf9bbcd12009-08-05 01:29:28 +0000169 const SmallVectorImpl<ISD::InputArg> &Ins,
170 DebugLoc dl, SelectionDAG &DAG,
Dan Gohman21cea8a2010-04-17 15:26:15 +0000171 SmallVectorImpl<SDValue> &InVals) const;
Dan Gohmanf9bbcd12009-08-05 01:29:28 +0000172
173 virtual SDValue
174 LowerReturn(SDValue Chain,
Sandeep Patel68c5f472009-09-02 08:44:58 +0000175 CallingConv::ID CallConv, bool isVarArg,
Dan Gohmanf9bbcd12009-08-05 01:29:28 +0000176 const SmallVectorImpl<ISD::OutputArg> &Outs,
Dan Gohmanfe7532a2010-07-07 15:54:55 +0000177 const SmallVectorImpl<SDValue> &OutVals,
Dan Gohman21cea8a2010-04-17 15:26:15 +0000178 DebugLoc dl, SelectionDAG &DAG) const;
Kalle Raiskilaa8450222010-10-07 16:24:35 +0000179
180 virtual bool isLegalICmpImmediate(int64_t Imm) const;
181
182 virtual bool isLegalAddressingMode(const AddrMode &AM,
183 const Type *Ty) const;
Scott Michel6e22c652007-12-04 22:23:35 +0000184 };
185}
186
187#endif