blob: aa4a1687278a0c135974ae165cdfaf59bf323c37 [file] [log] [blame]
Scott Michel266bc8f2007-12-04 22:23:35 +00001//===-- SPUISelLowering.h - Cell SPU DAG Lowering Interface -----*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-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 Michel266bc8f2007-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 Gohman0ba2bcf2008-09-23 18:42:32 +000026 FIRST_NUMBER = ISD::BUILTIN_OP_END,
Scott Michel02d711b2008-12-30 23:28:25 +000027
Scott Michel266bc8f2007-12-04 22:23:35 +000028 // Pseudo instructions:
29 RET_FLAG, ///< Return with flag, matched by bi instruction
Scott Michel02d711b2008-12-30 23:28:25 +000030
Scott Michel266bc8f2007-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 Michel9de5d0d2008-01-11 02:53:15 +000034 AFormAddr, ///< A-form address (local store)
Scott Michel053c1da2008-01-29 02:16:57 +000035 IndirectAddr, ///< D-Form "imm($r)" and X-form "$r($r)"
Scott Michel266bc8f2007-12-04 22:23:35 +000036
37 LDRESULT, ///< Load result (value, chain)
38 CALL, ///< CALL instruction
39 SHUFB, ///< Vector shuffle (permute)
Scott Michel7a1c9e92008-11-22 23:50:42 +000040 SHUFFLE_MASK, ///< Shuffle mask
Scott Michel7f9ba9b2008-01-30 02:55:46 +000041 CNTB, ///< Count leading ones in bytes
Scott Michelf0569be2008-12-27 04:51:36 +000042 PREFSLOT2VEC, ///< Promote scalar->vector
Scott Michel104de432008-11-24 17:11:17 +000043 VEC2PREFSLOT, ///< Extract element 0
Kalle Raiskila7ea1ab52010-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 Michel7f9ba9b2008-01-30 02:55:46 +000047 VEC_ROTL, ///< Vector rotate left
48 VEC_ROTR, ///< Vector rotate right
Scott Michel7f9ba9b2008-01-30 02:55:46 +000049 ROTBYTES_LEFT, ///< Rotate bytes (loads -> ROTQBYI)
Scott Michel8bf61e82008-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 Michel7f9ba9b2008-01-30 02:55:46 +000052 SELB, ///< Select bits -> (b & mask) | (a & ~mask)
Scott Michel94bd57e2009-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 Michel7f9ba9b2008-01-30 02:55:46 +000058 LAST_SPUISD ///< Last user-defined instruction
Scott Michel266bc8f2007-12-04 22:23:35 +000059 };
60 }
61
Scott Michelc9c8b2a2009-01-26 03:31:40 +000062 //! Utility functions specific to CellSPU:
Scott Michel266bc8f2007-12-04 22:23:35 +000063 namespace SPU {
Dan Gohman475871a2008-07-27 21:46:04 +000064 SDValue get_vec_u18imm(SDNode *N, SelectionDAG &DAG,
Owen Andersone50ed302009-08-10 22:56:29 +000065 EVT ValueType);
Dan Gohman475871a2008-07-27 21:46:04 +000066 SDValue get_vec_i16imm(SDNode *N, SelectionDAG &DAG,
Owen Andersone50ed302009-08-10 22:56:29 +000067 EVT ValueType);
Dan Gohman475871a2008-07-27 21:46:04 +000068 SDValue get_vec_i10imm(SDNode *N, SelectionDAG &DAG,
Owen Andersone50ed302009-08-10 22:56:29 +000069 EVT ValueType);
Dan Gohman475871a2008-07-27 21:46:04 +000070 SDValue get_vec_i8imm(SDNode *N, SelectionDAG &DAG,
Owen Andersone50ed302009-08-10 22:56:29 +000071 EVT ValueType);
Dan Gohman475871a2008-07-27 21:46:04 +000072 SDValue get_ILHUvec_imm(SDNode *N, SelectionDAG &DAG,
Owen Andersone50ed302009-08-10 22:56:29 +000073 EVT ValueType);
Dan Gohman475871a2008-07-27 21:46:04 +000074 SDValue get_v4i32_imm(SDNode *N, SelectionDAG &DAG);
75 SDValue get_v2i64_imm(SDNode *N, SelectionDAG &DAG);
Scott Michel94bd57e2009-01-15 04:41:47 +000076
77 SDValue LowerConstantPool(SDValue Op, SelectionDAG &DAG,
78 const SPUTargetMachine &TM);
Owen Andersone50ed302009-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 Johannesened2eee62009-02-06 01:31:28 +000081 DebugLoc dl);
Scott Michel266bc8f2007-12-04 22:23:35 +000082 }
83
84 class SPUTargetMachine; // forward dec'l.
Scott Michel02d711b2008-12-30 23:28:25 +000085
Scott Michel266bc8f2007-12-04 22:23:35 +000086 class SPUTargetLowering :
87 public TargetLowering
88 {
89 int VarArgsFrameIndex; // FrameIndex for start of varargs area.
Scott Michel266bc8f2007-12-04 22:23:35 +000090 SPUTargetMachine &SPUTM;
91
92 public:
Scott Michel94bd57e2009-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 Michel266bc8f2007-12-04 22:23:35 +000098 SPUTargetLowering(SPUTargetMachine &TM);
Scott Michel02d711b2008-12-30 23:28:25 +000099
Scott Michel94bd57e2009-01-15 04:41:47 +0000100 //! Get the target machine
101 SPUTargetMachine &getSPUTargetMachine() {
102 return SPUTM;
103 }
104
Scott Michel266bc8f2007-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 Michel5b8f82e2008-03-10 15:42:14 +0000108
109 /// getSetCCResultType - Return the ValueType for ISD::SETCC
Duncan Sands28b77e92011-09-06 19:07:46 +0000110 virtual EVT getSetCCResultType(EVT VT) const;
Scott Michel02d711b2008-12-30 23:28:25 +0000111
Owen Anderson95771af2011-02-25 21:41:48 +0000112 virtual MVT getShiftAmountTy(EVT LHSTy) const { return MVT::i32; }
113
Scott Michel73ce1c52008-11-10 23:43:06 +0000114 //! Custom lowering hooks
Dan Gohmand858e902010-04-17 15:26:15 +0000115 virtual SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const;
Scott Michel73ce1c52008-11-10 23:43:06 +0000116
Duncan Sands1607f052008-12-01 11:39:25 +0000117 //! Custom lowering hook for nodes with illegal result types.
118 virtual void ReplaceNodeResults(SDNode *N, SmallVectorImpl<SDValue>&Results,
Dan Gohmand858e902010-04-17 15:26:15 +0000119 SelectionDAG &DAG) const;
Duncan Sands1607f052008-12-01 11:39:25 +0000120
Dan Gohman475871a2008-07-27 21:46:04 +0000121 virtual SDValue PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const;
Scott Michel266bc8f2007-12-04 22:23:35 +0000122
Dan Gohman475871a2008-07-27 21:46:04 +0000123 virtual void computeMaskedBitsForTargetNode(const SDValue Op,
Dan Gohman977a76f2008-02-13 22:28:48 +0000124 const APInt &Mask,
Scott Michel02d711b2008-12-30 23:28:25 +0000125 APInt &KnownZero,
Dan Gohmanfd29e0e2008-02-13 00:35:47 +0000126 APInt &KnownOne,
Scott Michel266bc8f2007-12-04 22:23:35 +0000127 const SelectionDAG &DAG,
128 unsigned Depth = 0) const;
129
Scott Michelf0569be2008-12-27 04:51:36 +0000130 virtual unsigned ComputeNumSignBitsForTargetNode(SDValue Op,
131 unsigned Depth = 0) const;
132
Scott Michel266bc8f2007-12-04 22:23:35 +0000133 ConstraintType getConstraintType(const std::string &ConstraintLetter) const;
134
John Thompson44ab89e2010-10-29 17:29:13 +0000135 /// Examine constraint string and operand type and determine a weight value.
136 /// The operand object must already have been set up with the operand type.
137 ConstraintWeight getSingleConstraintMatchWeight(
138 AsmOperandInfo &info, const char *constraint) const;
139
Scott Michel02d711b2008-12-30 23:28:25 +0000140 std::pair<unsigned, const TargetRegisterClass*>
Scott Michel266bc8f2007-12-04 22:23:35 +0000141 getRegForInlineAsmConstraint(const std::string &Constraint,
Owen Andersone50ed302009-08-10 22:56:29 +0000142 EVT VT) const;
Scott Michel266bc8f2007-12-04 22:23:35 +0000143
Eric Christopher100c8332011-06-02 23:16:42 +0000144 void LowerAsmOperandForConstraint(SDValue Op, std::string &Constraint,
Dan Gohman475871a2008-07-27 21:46:04 +0000145 std::vector<SDValue> &Ops,
Scott Michel203b2d62008-04-30 00:30:08 +0000146 SelectionDAG &DAG) const;
147
Scott Michel266bc8f2007-12-04 22:23:35 +0000148 /// isLegalAddressImmediate - Return true if the integer value can be used
149 /// as the offset of the target addressing mode.
Chris Lattnerdb125cf2011-07-18 04:54:35 +0000150 virtual bool isLegalAddressImmediate(int64_t V, Type *Ty) const;
Scott Michel266bc8f2007-12-04 22:23:35 +0000151 virtual bool isLegalAddressImmediate(GlobalValue *) const;
Dan Gohman6520e202008-10-18 02:06:02 +0000152
153 virtual bool isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const;
Bill Wendling20c568f2009-06-30 22:38:32 +0000154
Dan Gohman98ca4f22009-08-05 01:29:28 +0000155 virtual SDValue
156 LowerFormalArguments(SDValue Chain,
Sandeep Patel65c3c8f2009-09-02 08:44:58 +0000157 CallingConv::ID CallConv, bool isVarArg,
Dan Gohman98ca4f22009-08-05 01:29:28 +0000158 const SmallVectorImpl<ISD::InputArg> &Ins,
159 DebugLoc dl, SelectionDAG &DAG,
Dan Gohmand858e902010-04-17 15:26:15 +0000160 SmallVectorImpl<SDValue> &InVals) const;
Dan Gohman98ca4f22009-08-05 01:29:28 +0000161
162 virtual SDValue
Evan Cheng022d9e12010-02-02 23:55:14 +0000163 LowerCall(SDValue Chain, SDValue Callee,
Sandeep Patel65c3c8f2009-09-02 08:44:58 +0000164 CallingConv::ID CallConv, bool isVarArg,
Evan Cheng0c439eb2010-01-27 00:07:07 +0000165 bool &isTailCall,
Dan Gohman98ca4f22009-08-05 01:29:28 +0000166 const SmallVectorImpl<ISD::OutputArg> &Outs,
Dan Gohmanc9403652010-07-07 15:54:55 +0000167 const SmallVectorImpl<SDValue> &OutVals,
Dan Gohman98ca4f22009-08-05 01:29:28 +0000168 const SmallVectorImpl<ISD::InputArg> &Ins,
169 DebugLoc dl, SelectionDAG &DAG,
Dan Gohmand858e902010-04-17 15:26:15 +0000170 SmallVectorImpl<SDValue> &InVals) const;
Dan Gohman98ca4f22009-08-05 01:29:28 +0000171
172 virtual SDValue
173 LowerReturn(SDValue Chain,
Sandeep Patel65c3c8f2009-09-02 08:44:58 +0000174 CallingConv::ID CallConv, bool isVarArg,
Dan Gohman98ca4f22009-08-05 01:29:28 +0000175 const SmallVectorImpl<ISD::OutputArg> &Outs,
Dan Gohmanc9403652010-07-07 15:54:55 +0000176 const SmallVectorImpl<SDValue> &OutVals,
Dan Gohmand858e902010-04-17 15:26:15 +0000177 DebugLoc dl, SelectionDAG &DAG) const;
Kalle Raiskila8a52fa62010-10-07 16:24:35 +0000178
179 virtual bool isLegalICmpImmediate(int64_t Imm) const;
180
Owen Anderson95771af2011-02-25 21:41:48 +0000181 virtual bool isLegalAddressingMode(const AddrMode &AM,
Chris Lattnerdb125cf2011-07-18 04:54:35 +0000182 Type *Ty) const;
Scott Michel266bc8f2007-12-04 22:23:35 +0000183 };
184}
185
186#endif