1 //===-- MSP430ISelLowering.h - MSP430 DAG Lowering Interface ----*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This file defines the interfaces that MSP430 uses to lower LLVM code into a
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_LIB_TARGET_MSP430_MSP430ISELLOWERING_H
15 #define LLVM_LIB_TARGET_MSP430_MSP430ISELLOWERING_H
18 #include "llvm/CodeGen/SelectionDAG.h"
19 #include "llvm/CodeGen/TargetLowering.h"
23 enum NodeType
: unsigned {
24 FIRST_NUMBER
= ISD::BUILTIN_OP_END
,
26 /// Return with a glue operand. Operand 0 is the chain operand.
29 /// Same as RET_GLUE, but used for returning from ISRs.
32 /// Y = R{R,L}A X, rotate right (left) arithmetically
35 /// Y = RRC X, rotate right via carry
38 /// Rotate right via carry, carry gets cleared beforehand by clrc
41 /// CALL - These operations represent an abstract call
42 /// instruction, which includes a bunch of information.
45 /// Wrapper - A wrapper node for TargetConstantPool, TargetExternalSymbol,
46 /// and TargetGlobalAddress.
49 /// CMP - Compare instruction.
52 /// SetCC - Operand 0 is condition code, and operand 1 is the flag
53 /// operand produced by a CMP instruction.
56 /// MSP430 conditional branches. Operand 0 is the chain operand, operand 1
57 /// is the block to branch if condition is true, operand 2 is the
58 /// condition code, and operand 3 is the flag operand produced by a CMP
62 /// SELECT_CC - Operand 0 and operand 1 are selection variable, operand 3
63 /// is condition code and operand 4 is flag operand.
66 /// DADD - Decimal addition with carry
67 /// TODO Nothing generates a node of this type yet.
72 class MSP430Subtarget
;
73 class MSP430TargetLowering
: public TargetLowering
{
75 explicit MSP430TargetLowering(const TargetMachine
&TM
,
76 const MSP430Subtarget
&STI
);
78 MVT
getScalarShiftAmountTy(const DataLayout
&, EVT
) const override
{
82 MVT::SimpleValueType
getCmpLibcallReturnType() const override
{
86 /// LowerOperation - Provide custom lowering hooks for some operations.
87 SDValue
LowerOperation(SDValue Op
, SelectionDAG
&DAG
) const override
;
89 /// getTargetNodeName - This method returns the name of a target specific
91 const char *getTargetNodeName(unsigned Opcode
) const override
;
93 SDValue
LowerShifts(SDValue Op
, SelectionDAG
&DAG
) const;
94 SDValue
LowerGlobalAddress(SDValue Op
, SelectionDAG
&DAG
) const;
95 SDValue
LowerBlockAddress(SDValue Op
, SelectionDAG
&DAG
) const;
96 SDValue
LowerExternalSymbol(SDValue Op
, SelectionDAG
&DAG
) const;
97 SDValue
LowerBR_CC(SDValue Op
, SelectionDAG
&DAG
) const;
98 SDValue
LowerSETCC(SDValue Op
, SelectionDAG
&DAG
) const;
99 SDValue
LowerSELECT_CC(SDValue Op
, SelectionDAG
&DAG
) const;
100 SDValue
LowerSIGN_EXTEND(SDValue Op
, SelectionDAG
&DAG
) const;
101 SDValue
LowerRETURNADDR(SDValue Op
, SelectionDAG
&DAG
) const;
102 SDValue
LowerFRAMEADDR(SDValue Op
, SelectionDAG
&DAG
) const;
103 SDValue
LowerVASTART(SDValue Op
, SelectionDAG
&DAG
) const;
104 SDValue
LowerJumpTable(SDValue Op
, SelectionDAG
&DAG
) const;
105 SDValue
getReturnAddressFrameIndex(SelectionDAG
&DAG
) const;
107 TargetLowering::ConstraintType
108 getConstraintType(StringRef Constraint
) const override
;
109 std::pair
<unsigned, const TargetRegisterClass
*>
110 getRegForInlineAsmConstraint(const TargetRegisterInfo
*TRI
,
111 StringRef Constraint
, MVT VT
) const override
;
113 /// isTruncateFree - Return true if it's free to truncate a value of type
114 /// Ty1 to type Ty2. e.g. On msp430 it's free to truncate a i16 value in
115 /// register R15W to i8 by referencing its sub-register R15B.
116 bool isTruncateFree(Type
*Ty1
, Type
*Ty2
) const override
;
117 bool isTruncateFree(EVT VT1
, EVT VT2
) const override
;
119 /// isZExtFree - Return true if any actual instruction that defines a value
120 /// of type Ty1 implicit zero-extends the value to Ty2 in the result
121 /// register. This does not necessarily include registers defined in unknown
122 /// ways, such as incoming arguments, or copies from unknown virtual
123 /// registers. Also, if isTruncateFree(Ty2, Ty1) is true, this does not
124 /// necessarily apply to truncate instructions. e.g. on msp430, all
125 /// instructions that define 8-bit values implicit zero-extend the result
127 bool isZExtFree(Type
*Ty1
, Type
*Ty2
) const override
;
128 bool isZExtFree(EVT VT1
, EVT VT2
) const override
;
130 bool isLegalICmpImmediate(int64_t) const override
;
131 bool shouldAvoidTransformToShift(EVT VT
, unsigned Amount
) const override
;
134 EmitInstrWithCustomInserter(MachineInstr
&MI
,
135 MachineBasicBlock
*BB
) const override
;
136 MachineBasicBlock
*EmitShiftInstr(MachineInstr
&MI
,
137 MachineBasicBlock
*BB
) const;
140 SDValue
LowerCCCCallTo(SDValue Chain
, SDValue Callee
,
141 CallingConv::ID CallConv
, bool isVarArg
,
143 const SmallVectorImpl
<ISD::OutputArg
> &Outs
,
144 const SmallVectorImpl
<SDValue
> &OutVals
,
145 const SmallVectorImpl
<ISD::InputArg
> &Ins
,
146 const SDLoc
&dl
, SelectionDAG
&DAG
,
147 SmallVectorImpl
<SDValue
> &InVals
) const;
149 SDValue
LowerCCCArguments(SDValue Chain
, CallingConv::ID CallConv
,
151 const SmallVectorImpl
<ISD::InputArg
> &Ins
,
152 const SDLoc
&dl
, SelectionDAG
&DAG
,
153 SmallVectorImpl
<SDValue
> &InVals
) const;
155 SDValue
LowerCallResult(SDValue Chain
, SDValue InGlue
,
156 CallingConv::ID CallConv
, bool isVarArg
,
157 const SmallVectorImpl
<ISD::InputArg
> &Ins
,
158 const SDLoc
&dl
, SelectionDAG
&DAG
,
159 SmallVectorImpl
<SDValue
> &InVals
) const;
162 LowerFormalArguments(SDValue Chain
, CallingConv::ID CallConv
, bool isVarArg
,
163 const SmallVectorImpl
<ISD::InputArg
> &Ins
,
164 const SDLoc
&dl
, SelectionDAG
&DAG
,
165 SmallVectorImpl
<SDValue
> &InVals
) const override
;
167 LowerCall(TargetLowering::CallLoweringInfo
&CLI
,
168 SmallVectorImpl
<SDValue
> &InVals
) const override
;
170 bool CanLowerReturn(CallingConv::ID CallConv
,
173 const SmallVectorImpl
<ISD::OutputArg
> &Outs
,
174 LLVMContext
&Context
) const override
;
176 SDValue
LowerReturn(SDValue Chain
, CallingConv::ID CallConv
, bool isVarArg
,
177 const SmallVectorImpl
<ISD::OutputArg
> &Outs
,
178 const SmallVectorImpl
<SDValue
> &OutVals
,
179 const SDLoc
&dl
, SelectionDAG
&DAG
) const override
;
181 bool getPostIndexedAddressParts(SDNode
*N
, SDNode
*Op
,
184 ISD::MemIndexedMode
&AM
,
185 SelectionDAG
&DAG
) const override
;