blob: d5bfac4ca75bde8c498f075383bdaceeaa30fa38 [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
65 FSMBI, ///< Form Select Mask for Bytes, Immediate
66 SELB, ///< Select bits -> (b & mask) | (a & ~mask)
Scott Michel266bc8f2007-12-04 22:23:35 +000067 FPInterp, ///< Floating point interpolate
Scott Michel7f9ba9b2008-01-30 02:55:46 +000068 FPRecipEst, ///< Floating point reciprocal estimate
69 SEXT32TO64, ///< Sign-extended 32-bit const -> 64-bits
70 LAST_SPUISD ///< Last user-defined instruction
Scott Michel266bc8f2007-12-04 22:23:35 +000071 };
72 }
73
74 /// Predicates that are used for node matching:
75 namespace SPU {
76 SDOperand get_vec_u18imm(SDNode *N, SelectionDAG &DAG,
77 MVT::ValueType ValueType);
78 SDOperand get_vec_i16imm(SDNode *N, SelectionDAG &DAG,
79 MVT::ValueType ValueType);
80 SDOperand get_vec_i10imm(SDNode *N, SelectionDAG &DAG,
81 MVT::ValueType ValueType);
82 SDOperand get_vec_i8imm(SDNode *N, SelectionDAG &DAG,
83 MVT::ValueType ValueType);
84 SDOperand get_ILHUvec_imm(SDNode *N, SelectionDAG &DAG,
85 MVT::ValueType ValueType);
86 SDOperand get_v4i32_imm(SDNode *N, SelectionDAG &DAG);
87 SDOperand get_v2i64_imm(SDNode *N, SelectionDAG &DAG);
88 }
89
90 class SPUTargetMachine; // forward dec'l.
91
92 class SPUTargetLowering :
93 public TargetLowering
94 {
95 int VarArgsFrameIndex; // FrameIndex for start of varargs area.
96 int ReturnAddrIndex; // FrameIndex for return slot.
97 SPUTargetMachine &SPUTM;
98
99 public:
100 SPUTargetLowering(SPUTargetMachine &TM);
101
102 /// getTargetNodeName() - This method returns the name of a target specific
103 /// DAG node.
104 virtual const char *getTargetNodeName(unsigned Opcode) const;
Scott Michel5b8f82e2008-03-10 15:42:14 +0000105
106 /// getSetCCResultType - Return the ValueType for ISD::SETCC
Scott Michel78c47fa2008-03-10 16:58:52 +0000107 virtual MVT::ValueType getSetCCResultType(const SDOperand &) const;
Scott Michel266bc8f2007-12-04 22:23:35 +0000108
109 /// LowerOperation - Provide custom lowering hooks for some operations.
110 ///
111 virtual SDOperand LowerOperation(SDOperand Op, SelectionDAG &DAG);
112
113 virtual SDOperand PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const;
114
115 virtual void computeMaskedBitsForTargetNode(const SDOperand Op,
Dan Gohman977a76f2008-02-13 22:28:48 +0000116 const APInt &Mask,
Dan Gohmanfd29e0e2008-02-13 00:35:47 +0000117 APInt &KnownZero,
118 APInt &KnownOne,
Scott Michel266bc8f2007-12-04 22:23:35 +0000119 const SelectionDAG &DAG,
120 unsigned Depth = 0) const;
121
Scott Michel266bc8f2007-12-04 22:23:35 +0000122 ConstraintType getConstraintType(const std::string &ConstraintLetter) const;
123
124 std::pair<unsigned, const TargetRegisterClass*>
125 getRegForInlineAsmConstraint(const std::string &Constraint,
126 MVT::ValueType VT) const;
127
128 void LowerAsmOperandForConstraint(SDOperand Op, char ConstraintLetter,
129 std::vector<SDOperand> &Ops,
130 SelectionDAG &DAG);
131
132 /// isLegalAddressImmediate - Return true if the integer value can be used
133 /// as the offset of the target addressing mode.
134 virtual bool isLegalAddressImmediate(int64_t V, const Type *Ty) const;
135 virtual bool isLegalAddressImmediate(GlobalValue *) const;
136 };
137}
138
139#endif