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