blob: d9e4e7ed4ed0ccf56d15815fa347b5fa7b3bfc6c [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 Michel266bc8f2007-12-04 22:23:35 +000035 DFormAddr, ///< D-Form address "imm($r)"
Scott Michel9de5d0d2008-01-11 02:53:15 +000036 XFormAddr, ///< X-Form address "$r($r)"
Scott Michel266bc8f2007-12-04 22:23:35 +000037
38 LDRESULT, ///< Load result (value, chain)
39 CALL, ///< CALL instruction
40 SHUFB, ///< Vector shuffle (permute)
41 INSERT_MASK, ///< Insert element shuffle mask
42 CNTB, ///< Count leading ones in bytes
43 PROMOTE_SCALAR, ///< Promote scalar->vector
44 EXTRACT_ELT0, ///< Extract element 0
45 EXTRACT_ELT0_CHAINED, ///< Extract element 0, with chain
46 EXTRACT_I1_ZEXT, ///< Extract element 0 as i1, zero extend
47 EXTRACT_I1_SEXT, ///< Extract element 0 as i1, sign extend
48 EXTRACT_I8_ZEXT, ///< Extract element 0 as i8, zero extend
49 EXTRACT_I8_SEXT, ///< Extract element 0 as i8, sign extend
50 MPY, ///< 16-bit Multiply (low parts of a 32-bit)
51 MPYU, ///< Multiply Unsigned
52 MPYH, ///< Multiply High
53 MPYHH, ///< Multiply High-High
54 VEC_SHL, ///< Vector shift left
55 VEC_SRL, ///< Vector shift right (logical)
56 VEC_SRA, ///< Vector shift right (arithmetic)
57 VEC_ROTL, ///< Vector rotate left
58 VEC_ROTR, ///< Vector rotate right
59 ROTBYTES_RIGHT_Z, ///< Vector rotate right, by bytes, zero fill
60 ROTBYTES_RIGHT_S, ///< Vector rotate right, by bytes, sign fill
61 ROTBYTES_LEFT, ///< Rotate bytes (loads -> ROTQBYI)
62 ROTBYTES_LEFT_CHAINED, ///< Rotate bytes (loads -> ROTQBYI), with chain
63 FSMBI, ///< Form Select Mask for Bytes, Immediate
64 SELB, ///< Select bits -> (b & mask) | (a & ~mask)
65 SFPConstant, ///< Single precision floating point constant
66 FPInterp, ///< Floating point interpolate
67 FPRecipEst, ///< Floating point reciprocal estimate
68 SEXT32TO64, ///< Sign-extended 32-bit const -> 64-bits
69 LAST_SPUISD ///< Last user-defined instruction
70 };
71 }
72
73 /// Predicates that are used for node matching:
74 namespace SPU {
75 SDOperand get_vec_u18imm(SDNode *N, SelectionDAG &DAG,
76 MVT::ValueType ValueType);
77 SDOperand get_vec_i16imm(SDNode *N, SelectionDAG &DAG,
78 MVT::ValueType ValueType);
79 SDOperand get_vec_i10imm(SDNode *N, SelectionDAG &DAG,
80 MVT::ValueType ValueType);
81 SDOperand get_vec_i8imm(SDNode *N, SelectionDAG &DAG,
82 MVT::ValueType ValueType);
83 SDOperand get_ILHUvec_imm(SDNode *N, SelectionDAG &DAG,
84 MVT::ValueType ValueType);
85 SDOperand get_v4i32_imm(SDNode *N, SelectionDAG &DAG);
86 SDOperand get_v2i64_imm(SDNode *N, SelectionDAG &DAG);
87 }
88
89 class SPUTargetMachine; // forward dec'l.
90
91 class SPUTargetLowering :
92 public TargetLowering
93 {
94 int VarArgsFrameIndex; // FrameIndex for start of varargs area.
95 int ReturnAddrIndex; // FrameIndex for return slot.
96 SPUTargetMachine &SPUTM;
97
98 public:
99 SPUTargetLowering(SPUTargetMachine &TM);
100
101 /// getTargetNodeName() - This method returns the name of a target specific
102 /// DAG node.
103 virtual const char *getTargetNodeName(unsigned Opcode) const;
104
105 /// LowerOperation - Provide custom lowering hooks for some operations.
106 ///
107 virtual SDOperand LowerOperation(SDOperand Op, SelectionDAG &DAG);
108
109 virtual SDOperand PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const;
110
111 virtual void computeMaskedBitsForTargetNode(const SDOperand Op,
112 uint64_t Mask,
113 uint64_t &KnownZero,
114 uint64_t &KnownOne,
115 const SelectionDAG &DAG,
116 unsigned Depth = 0) const;
117
118 virtual MachineBasicBlock *InsertAtEndOfBasicBlock(MachineInstr *MI,
119 MachineBasicBlock *MBB);
120
121 ConstraintType getConstraintType(const std::string &ConstraintLetter) const;
122
123 std::pair<unsigned, const TargetRegisterClass*>
124 getRegForInlineAsmConstraint(const std::string &Constraint,
125 MVT::ValueType VT) const;
126
127 void LowerAsmOperandForConstraint(SDOperand Op, char ConstraintLetter,
128 std::vector<SDOperand> &Ops,
129 SelectionDAG &DAG);
130
131 /// isLegalAddressImmediate - Return true if the integer value can be used
132 /// as the offset of the target addressing mode.
133 virtual bool isLegalAddressImmediate(int64_t V, const Type *Ty) const;
134 virtual bool isLegalAddressImmediate(GlobalValue *) const;
135 };
136}
137
138#endif