Custom lower (S|U)MUL_LOHI -> MACC(S|U)
[oota-llvm.git] / lib / Target / XCore / XCoreISelLowering.h
1 //===-- XCoreISelLowering.h - XCore DAG Lowering Interface ------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines the interfaces that XCore uses to lower LLVM code into a
11 // selection DAG.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #ifndef XCOREISELLOWERING_H
16 #define XCOREISELLOWERING_H
17
18 #include "llvm/CodeGen/SelectionDAG.h"
19 #include "llvm/Target/TargetLowering.h"
20 #include "XCore.h"
21
22 namespace llvm {
23   
24   // Forward delcarations
25   class XCoreSubtarget;
26   class XCoreTargetMachine;
27   
28   namespace XCoreISD {
29     enum NodeType {
30       // Start the numbering where the builtin ops and target ops leave off.
31       FIRST_NUMBER = ISD::BUILTIN_OP_END,
32
33       // Branch and link (call)
34       BL,
35
36       // pc relative address
37       PCRelativeWrapper,
38
39       // dp relative address
40       DPRelativeWrapper,
41       
42       // cp relative address
43       CPRelativeWrapper,
44       
45       // Store word to stack
46       STWSP,
47
48       // Corresponds to retsp instruction
49       RETSP,
50       
51       // Corresponds to LADD instruction
52       LADD,
53
54       // Corresponds to LSUB instruction
55       LSUB,
56
57       // Corresponds to MACCU instruction
58       MACCU,
59
60       // Corresponds to MACCS instruction
61       MACCS,
62
63       // Jumptable branch.
64       BR_JT,
65
66       // Jumptable branch using long branches for each entry.
67       BR_JT32
68     };
69   }
70
71   //===--------------------------------------------------------------------===//
72   // TargetLowering Implementation
73   //===--------------------------------------------------------------------===//
74   class XCoreTargetLowering : public TargetLowering 
75   {
76   public:
77
78     explicit XCoreTargetLowering(XCoreTargetMachine &TM);
79
80     /// LowerOperation - Provide custom lowering hooks for some operations.
81     virtual SDValue LowerOperation(SDValue Op, SelectionDAG &DAG);
82
83     /// ReplaceNodeResults - Replace the results of node with an illegal result
84     /// type with new values built out of custom code.
85     ///
86     virtual void ReplaceNodeResults(SDNode *N, SmallVectorImpl<SDValue>&Results,
87                                     SelectionDAG &DAG);
88
89     /// getTargetNodeName - This method returns the name of a target specific 
90     //  DAG node.
91     virtual const char *getTargetNodeName(unsigned Opcode) const;
92   
93     virtual MachineBasicBlock *EmitInstrWithCustomInserter(MachineInstr *MI,
94                                                          MachineBasicBlock *MBB,
95                     DenseMap<MachineBasicBlock*, MachineBasicBlock*> *EM) const;
96
97     virtual bool isLegalAddressingMode(const AddrMode &AM,
98                                        const Type *Ty) const;
99
100     /// getFunctionAlignment - Return the Log2 alignment of this function.
101     virtual unsigned getFunctionAlignment(const Function *F) const;
102
103   private:
104     const XCoreTargetMachine &TM;
105     const XCoreSubtarget &Subtarget;
106   
107     // Lower Operand helpers
108     SDValue LowerCCCArguments(SDValue Chain,
109                               CallingConv::ID CallConv,
110                               bool isVarArg,
111                               const SmallVectorImpl<ISD::InputArg> &Ins,
112                               DebugLoc dl, SelectionDAG &DAG,
113                               SmallVectorImpl<SDValue> &InVals);
114     SDValue LowerCCCCallTo(SDValue Chain, SDValue Callee,
115                            CallingConv::ID CallConv, bool isVarArg,
116                            bool isTailCall,
117                            const SmallVectorImpl<ISD::OutputArg> &Outs,
118                            const SmallVectorImpl<ISD::InputArg> &Ins,
119                            DebugLoc dl, SelectionDAG &DAG,
120                            SmallVectorImpl<SDValue> &InVals);
121     SDValue LowerCallResult(SDValue Chain, SDValue InFlag,
122                             CallingConv::ID CallConv, bool isVarArg,
123                             const SmallVectorImpl<ISD::InputArg> &Ins,
124                             DebugLoc dl, SelectionDAG &DAG,
125                             SmallVectorImpl<SDValue> &InVals);
126     SDValue getReturnAddressFrameIndex(SelectionDAG &DAG);
127     SDValue getGlobalAddressWrapper(SDValue GA, GlobalValue *GV,
128                                     SelectionDAG &DAG);
129
130     // Lower Operand specifics
131     SDValue LowerLOAD(SDValue Op, SelectionDAG &DAG);
132     SDValue LowerSTORE(SDValue Op, SelectionDAG &DAG);
133     SDValue LowerGlobalAddress(SDValue Op, SelectionDAG &DAG);
134     SDValue LowerGlobalTLSAddress(SDValue Op, SelectionDAG &DAG);
135     SDValue LowerBlockAddress(SDValue Op, SelectionDAG &DAG);
136     SDValue LowerConstantPool(SDValue Op, SelectionDAG &DAG);
137     SDValue LowerBR_JT(SDValue Op, SelectionDAG &DAG);
138     SDValue LowerSELECT_CC(SDValue Op, SelectionDAG &DAG);
139     SDValue LowerVAARG(SDValue Op, SelectionDAG &DAG);
140     SDValue LowerVASTART(SDValue Op, SelectionDAG &DAG);
141     SDValue LowerUMUL_LOHI(SDValue Op, SelectionDAG &DAG);
142     SDValue LowerSMUL_LOHI(SDValue Op, SelectionDAG &DAG);
143     SDValue LowerFRAMEADDR(SDValue Op, SelectionDAG &DAG);
144   
145     // Inline asm support
146     std::vector<unsigned>
147     getRegClassForInlineAsmConstraint(const std::string &Constraint,
148               EVT VT) const;
149   
150     // Expand specifics
151     SDValue TryExpandADDSUBWithMul(SDNode *Op, SelectionDAG &DAG);
152     SDValue ExpandADDSUB(SDNode *Op, SelectionDAG &DAG);
153
154     virtual SDValue PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const;
155
156     virtual void computeMaskedBitsForTargetNode(const SDValue Op,
157                                                 const APInt &Mask,
158                                                 APInt &KnownZero,
159                                                 APInt &KnownOne,
160                                                 const SelectionDAG &DAG,
161                                                 unsigned Depth = 0) const;
162
163     virtual SDValue
164       LowerFormalArguments(SDValue Chain,
165                            CallingConv::ID CallConv,
166                            bool isVarArg,
167                            const SmallVectorImpl<ISD::InputArg> &Ins,
168                            DebugLoc dl, SelectionDAG &DAG,
169                            SmallVectorImpl<SDValue> &InVals);
170
171     virtual SDValue
172       LowerCall(SDValue Chain, SDValue Callee,
173                 CallingConv::ID CallConv, bool isVarArg,
174                 bool &isTailCall,
175                 const SmallVectorImpl<ISD::OutputArg> &Outs,
176                 const SmallVectorImpl<ISD::InputArg> &Ins,
177                 DebugLoc dl, SelectionDAG &DAG,
178                 SmallVectorImpl<SDValue> &InVals);
179
180     virtual SDValue
181       LowerReturn(SDValue Chain,
182                   CallingConv::ID CallConv, bool isVarArg,
183                   const SmallVectorImpl<ISD::OutputArg> &Outs,
184                   DebugLoc dl, SelectionDAG &DAG);
185
186     virtual bool
187       CanLowerReturn(CallingConv::ID CallConv, bool isVarArg,
188                      const SmallVectorImpl<EVT> &OutTys,
189                      const SmallVectorImpl<ISD::ArgFlagsTy> &ArgsFlags,
190                      SelectionDAG &DAG);
191   };
192 }
193
194 #endif // XCOREISELLOWERING_H