blob: e7d0976ca58e17798c4c3a7cdbf3b3ec7d1716a5 [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
Craig Topper79aa3412012-03-17 18:46:09 +000018#include "SPU.h"
Scott Michel266bc8f2007-12-04 22:23:35 +000019#include "llvm/Target/TargetLowering.h"
20#include "llvm/CodeGen/SelectionDAG.h"
Scott Michel266bc8f2007-12-04 22:23:35 +000021
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,
Scott Michel02d711b2008-12-30 23:28:25 +0000124 APInt &KnownZero,
Dan Gohmanfd29e0e2008-02-13 00:35:47 +0000125 APInt &KnownOne,
Scott Michel266bc8f2007-12-04 22:23:35 +0000126 const SelectionDAG &DAG,
127 unsigned Depth = 0) const;
128
Scott Michelf0569be2008-12-27 04:51:36 +0000129 virtual unsigned ComputeNumSignBitsForTargetNode(SDValue Op,
130 unsigned Depth = 0) const;
131
Scott Michel266bc8f2007-12-04 22:23:35 +0000132 ConstraintType getConstraintType(const std::string &ConstraintLetter) const;
133
John Thompson44ab89e2010-10-29 17:29:13 +0000134 /// Examine constraint string and operand type and determine a weight value.
135 /// The operand object must already have been set up with the operand type.
136 ConstraintWeight getSingleConstraintMatchWeight(
137 AsmOperandInfo &info, const char *constraint) const;
138
Scott Michel02d711b2008-12-30 23:28:25 +0000139 std::pair<unsigned, const TargetRegisterClass*>
Scott Michel266bc8f2007-12-04 22:23:35 +0000140 getRegForInlineAsmConstraint(const std::string &Constraint,
Owen Andersone50ed302009-08-10 22:56:29 +0000141 EVT VT) const;
Scott Michel266bc8f2007-12-04 22:23:35 +0000142
Eric Christopher100c8332011-06-02 23:16:42 +0000143 void LowerAsmOperandForConstraint(SDValue Op, std::string &Constraint,
Dan Gohman475871a2008-07-27 21:46:04 +0000144 std::vector<SDValue> &Ops,
Scott Michel203b2d62008-04-30 00:30:08 +0000145 SelectionDAG &DAG) const;
146
Scott Michel266bc8f2007-12-04 22:23:35 +0000147 /// isLegalAddressImmediate - Return true if the integer value can be used
148 /// as the offset of the target addressing mode.
Chris Lattnerdb125cf2011-07-18 04:54:35 +0000149 virtual bool isLegalAddressImmediate(int64_t V, Type *Ty) const;
Scott Michel266bc8f2007-12-04 22:23:35 +0000150 virtual bool isLegalAddressImmediate(GlobalValue *) const;
Dan Gohman6520e202008-10-18 02:06:02 +0000151
152 virtual bool isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const;
Bill Wendling20c568f2009-06-30 22:38:32 +0000153
Dan Gohman98ca4f22009-08-05 01:29:28 +0000154 virtual SDValue
155 LowerFormalArguments(SDValue Chain,
Sandeep Patel65c3c8f2009-09-02 08:44:58 +0000156 CallingConv::ID CallConv, bool isVarArg,
Dan Gohman98ca4f22009-08-05 01:29:28 +0000157 const SmallVectorImpl<ISD::InputArg> &Ins,
158 DebugLoc dl, SelectionDAG &DAG,
Dan Gohmand858e902010-04-17 15:26:15 +0000159 SmallVectorImpl<SDValue> &InVals) const;
Dan Gohman98ca4f22009-08-05 01:29:28 +0000160
161 virtual SDValue
Justin Holewinskid2ea0e12012-05-25 16:35:28 +0000162 LowerCall(TargetLowering::CallLoweringInfo &CLI,
Dan Gohmand858e902010-04-17 15:26:15 +0000163 SmallVectorImpl<SDValue> &InVals) const;
Dan Gohman98ca4f22009-08-05 01:29:28 +0000164
165 virtual SDValue
166 LowerReturn(SDValue Chain,
Sandeep Patel65c3c8f2009-09-02 08:44:58 +0000167 CallingConv::ID CallConv, bool isVarArg,
Dan Gohman98ca4f22009-08-05 01:29:28 +0000168 const SmallVectorImpl<ISD::OutputArg> &Outs,
Dan Gohmanc9403652010-07-07 15:54:55 +0000169 const SmallVectorImpl<SDValue> &OutVals,
Dan Gohmand858e902010-04-17 15:26:15 +0000170 DebugLoc dl, SelectionDAG &DAG) const;
Kalle Raiskila8a52fa62010-10-07 16:24:35 +0000171
172 virtual bool isLegalICmpImmediate(int64_t Imm) const;
173
Owen Anderson95771af2011-02-25 21:41:48 +0000174 virtual bool isLegalAddressingMode(const AddrMode &AM,
Chris Lattnerdb125cf2011-07-18 04:54:35 +0000175 Type *Ty) const;
Scott Michel266bc8f2007-12-04 22:23:35 +0000176 };
177}
178
179#endif