blob: 0eed9b0cfc525a2f7a28b7df97c49b69be4ea55e [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
Scott Michela59d4692008-02-23 18:41:37 +000044 SHLQUAD_L_BITS, ///< Rotate quad left, by bits
45 SHLQUAD_L_BYTES, ///< Rotate quad left, by bytes
Scott Michel7f9ba9b2008-01-30 02:55:46 +000046 VEC_SHL, ///< Vector shift left
47 VEC_SRL, ///< Vector shift right (logical)
48 VEC_SRA, ///< Vector shift right (arithmetic)
49 VEC_ROTL, ///< Vector rotate left
50 VEC_ROTR, ///< Vector rotate right
Scott Michel7f9ba9b2008-01-30 02:55:46 +000051 ROTBYTES_LEFT, ///< Rotate bytes (loads -> ROTQBYI)
Scott Michel8bf61e82008-06-02 22:18:03 +000052 ROTBYTES_LEFT_BITS, ///< Rotate bytes left by bit shift count
53 SELECT_MASK, ///< Select Mask (FSM, FSMB, FSMH, FSMBI)
Scott Michel7f9ba9b2008-01-30 02:55:46 +000054 SELB, ///< Select bits -> (b & mask) | (a & ~mask)
Scott Michelf0569be2008-12-27 04:51:36 +000055 GATHER_BITS, ///< Gather bits from bytes/words/halfwords
Scott Michel8bf61e82008-06-02 22:18:03 +000056 ADD_EXTENDED, ///< Add extended, with carry
57 CARRY_GENERATE, ///< Carry generate for ADD_EXTENDED
58 SUB_EXTENDED, ///< Subtract extended, with borrow
59 BORROW_GENERATE, ///< Borrow generate for SUB_EXTENDED
Scott Michel7f9ba9b2008-01-30 02:55:46 +000060 SEXT32TO64, ///< Sign-extended 32-bit const -> 64-bits
61 LAST_SPUISD ///< Last user-defined instruction
Scott Michel266bc8f2007-12-04 22:23:35 +000062 };
63 }
64
65 /// Predicates that are used for node matching:
66 namespace SPU {
Dan Gohman475871a2008-07-27 21:46:04 +000067 SDValue get_vec_u18imm(SDNode *N, SelectionDAG &DAG,
Duncan Sands83ec4b62008-06-06 12:08:01 +000068 MVT ValueType);
Dan Gohman475871a2008-07-27 21:46:04 +000069 SDValue get_vec_i16imm(SDNode *N, SelectionDAG &DAG,
Duncan Sands83ec4b62008-06-06 12:08:01 +000070 MVT ValueType);
Dan Gohman475871a2008-07-27 21:46:04 +000071 SDValue get_vec_i10imm(SDNode *N, SelectionDAG &DAG,
Duncan Sands83ec4b62008-06-06 12:08:01 +000072 MVT ValueType);
Dan Gohman475871a2008-07-27 21:46:04 +000073 SDValue get_vec_i8imm(SDNode *N, SelectionDAG &DAG,
Duncan Sands83ec4b62008-06-06 12:08:01 +000074 MVT ValueType);
Dan Gohman475871a2008-07-27 21:46:04 +000075 SDValue get_ILHUvec_imm(SDNode *N, SelectionDAG &DAG,
Duncan Sands83ec4b62008-06-06 12:08:01 +000076 MVT ValueType);
Dan Gohman475871a2008-07-27 21:46:04 +000077 SDValue get_v4i32_imm(SDNode *N, SelectionDAG &DAG);
78 SDValue get_v2i64_imm(SDNode *N, SelectionDAG &DAG);
Scott Michel266bc8f2007-12-04 22:23:35 +000079 }
80
81 class SPUTargetMachine; // forward dec'l.
Scott Michel02d711b2008-12-30 23:28:25 +000082
Scott Michel266bc8f2007-12-04 22:23:35 +000083 class SPUTargetLowering :
84 public TargetLowering
85 {
86 int VarArgsFrameIndex; // FrameIndex for start of varargs area.
87 int ReturnAddrIndex; // FrameIndex for return slot.
88 SPUTargetMachine &SPUTM;
89
90 public:
91 SPUTargetLowering(SPUTargetMachine &TM);
Scott Michel02d711b2008-12-30 23:28:25 +000092
Scott Michel266bc8f2007-12-04 22:23:35 +000093 /// getTargetNodeName() - This method returns the name of a target specific
94 /// DAG node.
95 virtual const char *getTargetNodeName(unsigned Opcode) const;
Scott Michel5b8f82e2008-03-10 15:42:14 +000096
97 /// getSetCCResultType - Return the ValueType for ISD::SETCC
Dan Gohman475871a2008-07-27 21:46:04 +000098 virtual MVT getSetCCResultType(const SDValue &) const;
Scott Michel02d711b2008-12-30 23:28:25 +000099
Scott Michel73ce1c52008-11-10 23:43:06 +0000100 //! Custom lowering hooks
Dan Gohman475871a2008-07-27 21:46:04 +0000101 virtual SDValue LowerOperation(SDValue Op, SelectionDAG &DAG);
Scott Michel73ce1c52008-11-10 23:43:06 +0000102
Duncan Sands1607f052008-12-01 11:39:25 +0000103 //! Custom lowering hook for nodes with illegal result types.
104 virtual void ReplaceNodeResults(SDNode *N, SmallVectorImpl<SDValue>&Results,
105 SelectionDAG &DAG);
106
Dan Gohman475871a2008-07-27 21:46:04 +0000107 virtual SDValue PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const;
Scott Michel266bc8f2007-12-04 22:23:35 +0000108
Dan Gohman475871a2008-07-27 21:46:04 +0000109 virtual void computeMaskedBitsForTargetNode(const SDValue Op,
Dan Gohman977a76f2008-02-13 22:28:48 +0000110 const APInt &Mask,
Scott Michel02d711b2008-12-30 23:28:25 +0000111 APInt &KnownZero,
Dan Gohmanfd29e0e2008-02-13 00:35:47 +0000112 APInt &KnownOne,
Scott Michel266bc8f2007-12-04 22:23:35 +0000113 const SelectionDAG &DAG,
114 unsigned Depth = 0) const;
115
Scott Michelf0569be2008-12-27 04:51:36 +0000116 virtual unsigned ComputeNumSignBitsForTargetNode(SDValue Op,
117 unsigned Depth = 0) const;
118
Scott Michel266bc8f2007-12-04 22:23:35 +0000119 ConstraintType getConstraintType(const std::string &ConstraintLetter) const;
120
Scott Michel02d711b2008-12-30 23:28:25 +0000121 std::pair<unsigned, const TargetRegisterClass*>
Scott Michel266bc8f2007-12-04 22:23:35 +0000122 getRegForInlineAsmConstraint(const std::string &Constraint,
Duncan Sands83ec4b62008-06-06 12:08:01 +0000123 MVT VT) const;
Scott Michel266bc8f2007-12-04 22:23:35 +0000124
Dan Gohman475871a2008-07-27 21:46:04 +0000125 void LowerAsmOperandForConstraint(SDValue Op, char ConstraintLetter,
Scott Michel02d711b2008-12-30 23:28:25 +0000126 bool hasMemory,
Dan Gohman475871a2008-07-27 21:46:04 +0000127 std::vector<SDValue> &Ops,
Scott Michel203b2d62008-04-30 00:30:08 +0000128 SelectionDAG &DAG) const;
129
Scott Michel266bc8f2007-12-04 22:23:35 +0000130 /// isLegalAddressImmediate - Return true if the integer value can be used
131 /// as the offset of the target addressing mode.
132 virtual bool isLegalAddressImmediate(int64_t V, const Type *Ty) const;
133 virtual bool isLegalAddressImmediate(GlobalValue *) const;
Dan Gohman6520e202008-10-18 02:06:02 +0000134
135 virtual bool isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const;
Scott Michel266bc8f2007-12-04 22:23:35 +0000136 };
137}
138
139#endif