1f4a2713aSLionel Sambuc //===-- SparcISelLowering.h - Sparc DAG Lowering Interface ------*- C++ -*-===//
2f4a2713aSLionel Sambuc //
3f4a2713aSLionel Sambuc //                     The LLVM Compiler Infrastructure
4f4a2713aSLionel Sambuc //
5f4a2713aSLionel Sambuc // This file is distributed under the University of Illinois Open Source
6f4a2713aSLionel Sambuc // License. See LICENSE.TXT for details.
7f4a2713aSLionel Sambuc //
8f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
9f4a2713aSLionel Sambuc //
10f4a2713aSLionel Sambuc // This file defines the interfaces that Sparc uses to lower LLVM code into a
11f4a2713aSLionel Sambuc // selection DAG.
12f4a2713aSLionel Sambuc //
13f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
14f4a2713aSLionel Sambuc 
15*0a6a1f1dSLionel Sambuc #ifndef LLVM_LIB_TARGET_SPARC_SPARCISELLOWERING_H
16*0a6a1f1dSLionel Sambuc #define LLVM_LIB_TARGET_SPARC_SPARCISELLOWERING_H
17f4a2713aSLionel Sambuc 
18f4a2713aSLionel Sambuc #include "Sparc.h"
19f4a2713aSLionel Sambuc #include "llvm/Target/TargetLowering.h"
20f4a2713aSLionel Sambuc 
21f4a2713aSLionel Sambuc namespace llvm {
22f4a2713aSLionel Sambuc   class SparcSubtarget;
23f4a2713aSLionel Sambuc 
24f4a2713aSLionel Sambuc   namespace SPISD {
25f4a2713aSLionel Sambuc     enum {
26f4a2713aSLionel Sambuc       FIRST_NUMBER = ISD::BUILTIN_OP_END,
27f4a2713aSLionel Sambuc       CMPICC,      // Compare two GPR operands, set icc+xcc.
28f4a2713aSLionel Sambuc       CMPFCC,      // Compare two FP operands, set fcc.
29f4a2713aSLionel Sambuc       BRICC,       // Branch to dest on icc condition
30f4a2713aSLionel Sambuc       BRXCC,       // Branch to dest on xcc condition (64-bit only).
31f4a2713aSLionel Sambuc       BRFCC,       // Branch to dest on fcc condition
32f4a2713aSLionel Sambuc       SELECT_ICC,  // Select between two values using the current ICC flags.
33f4a2713aSLionel Sambuc       SELECT_XCC,  // Select between two values using the current XCC flags.
34f4a2713aSLionel Sambuc       SELECT_FCC,  // Select between two values using the current FCC flags.
35f4a2713aSLionel Sambuc 
36f4a2713aSLionel Sambuc       Hi, Lo,      // Hi/Lo operations, typically on a global address.
37f4a2713aSLionel Sambuc 
38f4a2713aSLionel Sambuc       FTOI,        // FP to Int within a FP register.
39f4a2713aSLionel Sambuc       ITOF,        // Int to FP within a FP register.
40f4a2713aSLionel Sambuc       FTOX,        // FP to Int64 within a FP register.
41f4a2713aSLionel Sambuc       XTOF,        // Int64 to FP within a FP register.
42f4a2713aSLionel Sambuc 
43f4a2713aSLionel Sambuc       CALL,        // A call instruction.
44f4a2713aSLionel Sambuc       RET_FLAG,    // Return with a flag operand.
45f4a2713aSLionel Sambuc       GLOBAL_BASE_REG, // Global base reg for PIC.
46f4a2713aSLionel Sambuc       FLUSHW,      // FLUSH register windows to stack.
47f4a2713aSLionel Sambuc 
48f4a2713aSLionel Sambuc       TLS_ADD,     // For Thread Local Storage (TLS).
49f4a2713aSLionel Sambuc       TLS_LD,
50f4a2713aSLionel Sambuc       TLS_CALL
51f4a2713aSLionel Sambuc     };
52f4a2713aSLionel Sambuc   }
53f4a2713aSLionel Sambuc 
54f4a2713aSLionel Sambuc   class SparcTargetLowering : public TargetLowering {
55f4a2713aSLionel Sambuc     const SparcSubtarget *Subtarget;
56f4a2713aSLionel Sambuc   public:
57f4a2713aSLionel Sambuc     SparcTargetLowering(TargetMachine &TM);
58*0a6a1f1dSLionel Sambuc     SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const override;
59f4a2713aSLionel Sambuc 
60*0a6a1f1dSLionel Sambuc     /// computeKnownBitsForTargetNode - Determine which of the bits specified
61f4a2713aSLionel Sambuc     /// in Mask are known to be either zero or one and return them in the
62f4a2713aSLionel Sambuc     /// KnownZero/KnownOne bitsets.
63*0a6a1f1dSLionel Sambuc     void computeKnownBitsForTargetNode(const SDValue Op,
64f4a2713aSLionel Sambuc                                        APInt &KnownZero,
65f4a2713aSLionel Sambuc                                        APInt &KnownOne,
66f4a2713aSLionel Sambuc                                        const SelectionDAG &DAG,
67*0a6a1f1dSLionel Sambuc                                        unsigned Depth = 0) const override;
68f4a2713aSLionel Sambuc 
69*0a6a1f1dSLionel Sambuc     MachineBasicBlock *
70f4a2713aSLionel Sambuc       EmitInstrWithCustomInserter(MachineInstr *MI,
71*0a6a1f1dSLionel Sambuc                                   MachineBasicBlock *MBB) const override;
72f4a2713aSLionel Sambuc 
73*0a6a1f1dSLionel Sambuc     const char *getTargetNodeName(unsigned Opcode) const override;
74f4a2713aSLionel Sambuc 
75*0a6a1f1dSLionel Sambuc     ConstraintType getConstraintType(const std::string &Constraint) const override;
76*0a6a1f1dSLionel Sambuc     ConstraintWeight
77*0a6a1f1dSLionel Sambuc     getSingleConstraintMatchWeight(AsmOperandInfo &info,
78*0a6a1f1dSLionel Sambuc                                    const char *constraint) const override;
79*0a6a1f1dSLionel Sambuc     void LowerAsmOperandForConstraint(SDValue Op,
80*0a6a1f1dSLionel Sambuc                                       std::string &Constraint,
81*0a6a1f1dSLionel Sambuc                                       std::vector<SDValue> &Ops,
82*0a6a1f1dSLionel Sambuc                                       SelectionDAG &DAG) const override;
83f4a2713aSLionel Sambuc     std::pair<unsigned, const TargetRegisterClass*>
84*0a6a1f1dSLionel Sambuc     getRegForInlineAsmConstraint(const std::string &Constraint, MVT VT) const override;
85f4a2713aSLionel Sambuc 
86*0a6a1f1dSLionel Sambuc     bool isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const override;
getScalarShiftAmountTy(EVT LHSTy)87*0a6a1f1dSLionel Sambuc     MVT getScalarShiftAmountTy(EVT LHSTy) const override { return MVT::i32; }
88f4a2713aSLionel Sambuc 
89*0a6a1f1dSLionel Sambuc     /// getSetCCResultType - Return the ISD::SETCC ValueType
90*0a6a1f1dSLionel Sambuc     EVT getSetCCResultType(LLVMContext &Context, EVT VT) const override;
91*0a6a1f1dSLionel Sambuc 
92*0a6a1f1dSLionel Sambuc     SDValue
93f4a2713aSLionel Sambuc       LowerFormalArguments(SDValue Chain,
94f4a2713aSLionel Sambuc                            CallingConv::ID CallConv,
95f4a2713aSLionel Sambuc                            bool isVarArg,
96f4a2713aSLionel Sambuc                            const SmallVectorImpl<ISD::InputArg> &Ins,
97f4a2713aSLionel Sambuc                            SDLoc dl, SelectionDAG &DAG,
98*0a6a1f1dSLionel Sambuc                            SmallVectorImpl<SDValue> &InVals) const override;
99f4a2713aSLionel Sambuc     SDValue LowerFormalArguments_32(SDValue Chain,
100f4a2713aSLionel Sambuc                                     CallingConv::ID CallConv,
101f4a2713aSLionel Sambuc                                     bool isVarArg,
102f4a2713aSLionel Sambuc                                     const SmallVectorImpl<ISD::InputArg> &Ins,
103f4a2713aSLionel Sambuc                                     SDLoc dl, SelectionDAG &DAG,
104f4a2713aSLionel Sambuc                                     SmallVectorImpl<SDValue> &InVals) const;
105f4a2713aSLionel Sambuc     SDValue LowerFormalArguments_64(SDValue Chain,
106f4a2713aSLionel Sambuc                                     CallingConv::ID CallConv,
107f4a2713aSLionel Sambuc                                     bool isVarArg,
108f4a2713aSLionel Sambuc                                     const SmallVectorImpl<ISD::InputArg> &Ins,
109f4a2713aSLionel Sambuc                                     SDLoc dl, SelectionDAG &DAG,
110f4a2713aSLionel Sambuc                                     SmallVectorImpl<SDValue> &InVals) const;
111f4a2713aSLionel Sambuc 
112*0a6a1f1dSLionel Sambuc     SDValue
113f4a2713aSLionel Sambuc       LowerCall(TargetLowering::CallLoweringInfo &CLI,
114*0a6a1f1dSLionel Sambuc                 SmallVectorImpl<SDValue> &InVals) const override;
115f4a2713aSLionel Sambuc     SDValue LowerCall_32(TargetLowering::CallLoweringInfo &CLI,
116f4a2713aSLionel Sambuc                          SmallVectorImpl<SDValue> &InVals) const;
117f4a2713aSLionel Sambuc     SDValue LowerCall_64(TargetLowering::CallLoweringInfo &CLI,
118f4a2713aSLionel Sambuc                          SmallVectorImpl<SDValue> &InVals) const;
119f4a2713aSLionel Sambuc 
120*0a6a1f1dSLionel Sambuc     SDValue
121f4a2713aSLionel Sambuc       LowerReturn(SDValue Chain,
122f4a2713aSLionel Sambuc                   CallingConv::ID CallConv, bool isVarArg,
123f4a2713aSLionel Sambuc                   const SmallVectorImpl<ISD::OutputArg> &Outs,
124f4a2713aSLionel Sambuc                   const SmallVectorImpl<SDValue> &OutVals,
125*0a6a1f1dSLionel Sambuc                   SDLoc dl, SelectionDAG &DAG) const override;
126f4a2713aSLionel Sambuc     SDValue LowerReturn_32(SDValue Chain,
127f4a2713aSLionel Sambuc                            CallingConv::ID CallConv, bool IsVarArg,
128f4a2713aSLionel Sambuc                            const SmallVectorImpl<ISD::OutputArg> &Outs,
129f4a2713aSLionel Sambuc                            const SmallVectorImpl<SDValue> &OutVals,
130f4a2713aSLionel Sambuc                            SDLoc DL, SelectionDAG &DAG) const;
131f4a2713aSLionel Sambuc     SDValue LowerReturn_64(SDValue Chain,
132f4a2713aSLionel Sambuc                            CallingConv::ID CallConv, bool IsVarArg,
133f4a2713aSLionel Sambuc                            const SmallVectorImpl<ISD::OutputArg> &Outs,
134f4a2713aSLionel Sambuc                            const SmallVectorImpl<SDValue> &OutVals,
135f4a2713aSLionel Sambuc                            SDLoc DL, SelectionDAG &DAG) const;
136f4a2713aSLionel Sambuc 
137f4a2713aSLionel Sambuc     SDValue LowerGlobalAddress(SDValue Op, SelectionDAG &DAG) const;
138f4a2713aSLionel Sambuc     SDValue LowerGlobalTLSAddress(SDValue Op, SelectionDAG &DAG) const;
139f4a2713aSLionel Sambuc     SDValue LowerConstantPool(SDValue Op, SelectionDAG &DAG) const;
140f4a2713aSLionel Sambuc     SDValue LowerBlockAddress(SDValue Op, SelectionDAG &DAG) const;
141f4a2713aSLionel Sambuc 
142f4a2713aSLionel Sambuc     unsigned getSRetArgSize(SelectionDAG &DAG, SDValue Callee) const;
143f4a2713aSLionel Sambuc     SDValue withTargetFlags(SDValue Op, unsigned TF, SelectionDAG &DAG) const;
144f4a2713aSLionel Sambuc     SDValue makeHiLoPair(SDValue Op, unsigned HiTF, unsigned LoTF,
145f4a2713aSLionel Sambuc                          SelectionDAG &DAG) const;
146f4a2713aSLionel Sambuc     SDValue makeAddress(SDValue Op, SelectionDAG &DAG) const;
147f4a2713aSLionel Sambuc 
148f4a2713aSLionel Sambuc     SDValue LowerF128_LibCallArg(SDValue Chain, ArgListTy &Args,
149f4a2713aSLionel Sambuc                                  SDValue Arg, SDLoc DL,
150f4a2713aSLionel Sambuc                                  SelectionDAG &DAG) const;
151f4a2713aSLionel Sambuc     SDValue LowerF128Op(SDValue Op, SelectionDAG &DAG,
152f4a2713aSLionel Sambuc                         const char *LibFuncName,
153f4a2713aSLionel Sambuc                         unsigned numArgs) const;
154f4a2713aSLionel Sambuc     SDValue LowerF128Compare(SDValue LHS, SDValue RHS,
155f4a2713aSLionel Sambuc                              unsigned &SPCC,
156f4a2713aSLionel Sambuc                              SDLoc DL,
157f4a2713aSLionel Sambuc                              SelectionDAG &DAG) const;
158f4a2713aSLionel Sambuc 
ShouldShrinkFPConstant(EVT VT)159*0a6a1f1dSLionel Sambuc     bool ShouldShrinkFPConstant(EVT VT) const override {
160f4a2713aSLionel Sambuc       // Do not shrink FP constpool if VT == MVT::f128.
161f4a2713aSLionel Sambuc       // (ldd, call _Q_fdtoq) is more expensive than two ldds.
162f4a2713aSLionel Sambuc       return VT != MVT::f128;
163f4a2713aSLionel Sambuc     }
164f4a2713aSLionel Sambuc 
165*0a6a1f1dSLionel Sambuc     void ReplaceNodeResults(SDNode *N,
166f4a2713aSLionel Sambuc                                     SmallVectorImpl<SDValue>& Results,
167*0a6a1f1dSLionel Sambuc                                     SelectionDAG &DAG) const override;
168*0a6a1f1dSLionel Sambuc 
169*0a6a1f1dSLionel Sambuc     MachineBasicBlock *expandSelectCC(MachineInstr *MI, MachineBasicBlock *BB,
170*0a6a1f1dSLionel Sambuc                                       unsigned BROpcode) const;
171*0a6a1f1dSLionel Sambuc     MachineBasicBlock *expandAtomicRMW(MachineInstr *MI,
172*0a6a1f1dSLionel Sambuc                                        MachineBasicBlock *BB,
173*0a6a1f1dSLionel Sambuc                                        unsigned Opcode,
174*0a6a1f1dSLionel Sambuc                                        unsigned CondCode = 0) const;
175f4a2713aSLionel Sambuc   };
176f4a2713aSLionel Sambuc } // end namespace llvm
177f4a2713aSLionel Sambuc 
178f4a2713aSLionel Sambuc #endif    // SPARC_ISELLOWERING_H
179