blob: 814c9ba97a1865cbd0ca7d7b5bf4b7e3fca6bf2c [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.
26 FIRST_NUMBER = ISD::BUILTIN_OP_END+SPU::INSTRUCTION_LIST_END,
27
28 // Pseudo instructions:
29 RET_FLAG, ///< Return with flag, matched by bi instruction
30
31 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)
40 INSERT_MASK, ///< Insert element shuffle mask
Scott Michel7f9ba9b2008-01-30 02:55:46 +000041 CNTB, ///< Count leading ones in bytes
Scott Michel266bc8f2007-12-04 22:23:35 +000042 PROMOTE_SCALAR, ///< Promote scalar->vector
43 EXTRACT_ELT0, ///< Extract element 0
Scott Michel7f9ba9b2008-01-30 02:55:46 +000044 EXTRACT_ELT0_CHAINED, ///< Extract element 0, with chain
Scott Michel266bc8f2007-12-04 22:23:35 +000045 EXTRACT_I1_ZEXT, ///< Extract element 0 as i1, zero extend
46 EXTRACT_I1_SEXT, ///< Extract element 0 as i1, sign extend
47 EXTRACT_I8_ZEXT, ///< Extract element 0 as i8, zero extend
48 EXTRACT_I8_SEXT, ///< Extract element 0 as i8, sign extend
Scott Michel7f9ba9b2008-01-30 02:55:46 +000049 MPY, ///< 16-bit Multiply (low parts of a 32-bit)
50 MPYU, ///< Multiply Unsigned
51 MPYH, ///< Multiply High
52 MPYHH, ///< Multiply High-High
Scott Michela59d4692008-02-23 18:41:37 +000053 SHLQUAD_L_BITS, ///< Rotate quad left, by bits
54 SHLQUAD_L_BYTES, ///< Rotate quad left, by bytes
Scott Michel7f9ba9b2008-01-30 02:55:46 +000055 VEC_SHL, ///< Vector shift left
56 VEC_SRL, ///< Vector shift right (logical)
57 VEC_SRA, ///< Vector shift right (arithmetic)
58 VEC_ROTL, ///< Vector rotate left
59 VEC_ROTR, ///< Vector rotate right
Scott Michela59d4692008-02-23 18:41:37 +000060 ROTQUAD_RZ_BYTES, ///< Rotate quad right, by bytes, zero fill
61 ROTQUAD_RZ_BITS, ///< Rotate quad right, by bits, zero fill
Scott Michel266bc8f2007-12-04 22:23:35 +000062 ROTBYTES_RIGHT_S, ///< Vector rotate right, by bytes, sign fill
Scott Michel7f9ba9b2008-01-30 02:55:46 +000063 ROTBYTES_LEFT, ///< Rotate bytes (loads -> ROTQBYI)
64 ROTBYTES_LEFT_CHAINED, ///< Rotate bytes (loads -> ROTQBYI), with chain
Scott Michel8bf61e82008-06-02 22:18:03 +000065 ROTBYTES_LEFT_BITS, ///< Rotate bytes left by bit shift count
66 SELECT_MASK, ///< Select Mask (FSM, FSMB, FSMH, FSMBI)
Scott Michel7f9ba9b2008-01-30 02:55:46 +000067 SELB, ///< Select bits -> (b & mask) | (a & ~mask)
Scott Michel8bf61e82008-06-02 22:18:03 +000068 ADD_EXTENDED, ///< Add extended, with carry
69 CARRY_GENERATE, ///< Carry generate for ADD_EXTENDED
70 SUB_EXTENDED, ///< Subtract extended, with borrow
71 BORROW_GENERATE, ///< Borrow generate for SUB_EXTENDED
Scott Michel266bc8f2007-12-04 22:23:35 +000072 FPInterp, ///< Floating point interpolate
Scott Michel7f9ba9b2008-01-30 02:55:46 +000073 FPRecipEst, ///< Floating point reciprocal estimate
74 SEXT32TO64, ///< Sign-extended 32-bit const -> 64-bits
75 LAST_SPUISD ///< Last user-defined instruction
Scott Michel266bc8f2007-12-04 22:23:35 +000076 };
77 }
78
79 /// Predicates that are used for node matching:
80 namespace SPU {
Dan Gohman475871a2008-07-27 21:46:04 +000081 SDValue get_vec_u18imm(SDNode *N, SelectionDAG &DAG,
Duncan Sands83ec4b62008-06-06 12:08:01 +000082 MVT ValueType);
Dan Gohman475871a2008-07-27 21:46:04 +000083 SDValue get_vec_i16imm(SDNode *N, SelectionDAG &DAG,
Duncan Sands83ec4b62008-06-06 12:08:01 +000084 MVT ValueType);
Dan Gohman475871a2008-07-27 21:46:04 +000085 SDValue get_vec_i10imm(SDNode *N, SelectionDAG &DAG,
Duncan Sands83ec4b62008-06-06 12:08:01 +000086 MVT ValueType);
Dan Gohman475871a2008-07-27 21:46:04 +000087 SDValue get_vec_i8imm(SDNode *N, SelectionDAG &DAG,
Duncan Sands83ec4b62008-06-06 12:08:01 +000088 MVT ValueType);
Dan Gohman475871a2008-07-27 21:46:04 +000089 SDValue get_ILHUvec_imm(SDNode *N, SelectionDAG &DAG,
Duncan Sands83ec4b62008-06-06 12:08:01 +000090 MVT ValueType);
Dan Gohman475871a2008-07-27 21:46:04 +000091 SDValue get_v4i32_imm(SDNode *N, SelectionDAG &DAG);
92 SDValue get_v2i64_imm(SDNode *N, SelectionDAG &DAG);
Scott Michel266bc8f2007-12-04 22:23:35 +000093 }
94
95 class SPUTargetMachine; // forward dec'l.
96
97 class SPUTargetLowering :
98 public TargetLowering
99 {
100 int VarArgsFrameIndex; // FrameIndex for start of varargs area.
101 int ReturnAddrIndex; // FrameIndex for return slot.
102 SPUTargetMachine &SPUTM;
103
104 public:
105 SPUTargetLowering(SPUTargetMachine &TM);
106
107 /// getTargetNodeName() - This method returns the name of a target specific
108 /// DAG node.
109 virtual const char *getTargetNodeName(unsigned Opcode) const;
Scott Michel5b8f82e2008-03-10 15:42:14 +0000110
111 /// getSetCCResultType - Return the ValueType for ISD::SETCC
Dan Gohman475871a2008-07-27 21:46:04 +0000112 virtual MVT getSetCCResultType(const SDValue &) const;
Scott Michel266bc8f2007-12-04 22:23:35 +0000113
114 /// LowerOperation - Provide custom lowering hooks for some operations.
115 ///
Dan Gohman475871a2008-07-27 21:46:04 +0000116 virtual SDValue LowerOperation(SDValue Op, SelectionDAG &DAG);
Scott Michel266bc8f2007-12-04 22:23:35 +0000117
Dan Gohman475871a2008-07-27 21:46:04 +0000118 virtual SDValue PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const;
Scott Michel266bc8f2007-12-04 22:23:35 +0000119
Dan Gohman475871a2008-07-27 21:46:04 +0000120 virtual void computeMaskedBitsForTargetNode(const SDValue Op,
Dan Gohman977a76f2008-02-13 22:28:48 +0000121 const APInt &Mask,
Dan Gohmanfd29e0e2008-02-13 00:35:47 +0000122 APInt &KnownZero,
123 APInt &KnownOne,
Scott Michel266bc8f2007-12-04 22:23:35 +0000124 const SelectionDAG &DAG,
125 unsigned Depth = 0) const;
126
Scott Michel266bc8f2007-12-04 22:23:35 +0000127 ConstraintType getConstraintType(const std::string &ConstraintLetter) const;
128
129 std::pair<unsigned, const TargetRegisterClass*>
130 getRegForInlineAsmConstraint(const std::string &Constraint,
Duncan Sands83ec4b62008-06-06 12:08:01 +0000131 MVT VT) const;
Scott Michel266bc8f2007-12-04 22:23:35 +0000132
Dan Gohman475871a2008-07-27 21:46:04 +0000133 void LowerAsmOperandForConstraint(SDValue Op, char ConstraintLetter,
134 std::vector<SDValue> &Ops,
Scott Michel203b2d62008-04-30 00:30:08 +0000135 SelectionDAG &DAG) const;
136
Scott Michel266bc8f2007-12-04 22:23:35 +0000137 /// isLegalAddressImmediate - Return true if the integer value can be used
138 /// as the offset of the target addressing mode.
139 virtual bool isLegalAddressImmediate(int64_t V, const Type *Ty) const;
140 virtual bool isLegalAddressImmediate(GlobalValue *) const;
141 };
142}
143
144#endif