1 //===-- XCoreISelLowering.h - XCore 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 XCore uses to lower LLVM code into a
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_LIB_TARGET_XCORE_XCOREISELLOWERING_H
15 #define LLVM_LIB_TARGET_XCORE_XCOREISELLOWERING_H
18 #include "llvm/CodeGen/SelectionDAG.h"
19 #include "llvm/CodeGen/TargetLowering.h"
23 // Forward delcarations
27 enum NodeType
: unsigned {
28 // Start the numbering where the builtin ops and target ops leave off.
29 FIRST_NUMBER
= ISD::BUILTIN_OP_END
,
31 // Branch and link (call)
34 // pc relative address
37 // dp relative address
40 // cp relative address
43 // Load word from stack
46 // Store word to stack
49 // Corresponds to retsp instruction
52 // Corresponds to LADD instruction
55 // Corresponds to LSUB instruction
58 // Corresponds to LMUL instruction
61 // Corresponds to MACCU instruction
64 // Corresponds to MACCS instruction
67 // Corresponds to CRC8 instruction
73 // Jumptable branch using long branches for each entry.
76 // Offset from frame pointer to the first (possible) on-stack argument
79 // Exception handler return. The stack is restored to the first
80 // followed by a jump to the second argument.
85 //===--------------------------------------------------------------------===//
86 // TargetLowering Implementation
87 //===--------------------------------------------------------------------===//
88 class XCoreTargetLowering
: public TargetLowering
91 explicit XCoreTargetLowering(const TargetMachine
&TM
,
92 const XCoreSubtarget
&Subtarget
);
94 using TargetLowering::isZExtFree
;
95 bool isZExtFree(SDValue Val
, EVT VT2
) const override
;
98 unsigned getJumpTableEncoding() const override
;
99 MVT
getScalarShiftAmountTy(const DataLayout
&DL
, EVT
) const override
{
103 /// LowerOperation - Provide custom lowering hooks for some operations.
104 SDValue
LowerOperation(SDValue Op
, SelectionDAG
&DAG
) const override
;
106 /// ReplaceNodeResults - Replace the results of node with an illegal result
107 /// type with new values built out of custom code.
109 void ReplaceNodeResults(SDNode
*N
, SmallVectorImpl
<SDValue
>&Results
,
110 SelectionDAG
&DAG
) const override
;
112 /// getTargetNodeName - This method returns the name of a target specific
114 const char *getTargetNodeName(unsigned Opcode
) const override
;
117 EmitInstrWithCustomInserter(MachineInstr
&MI
,
118 MachineBasicBlock
*MBB
) const override
;
120 bool isLegalAddressingMode(const DataLayout
&DL
, const AddrMode
&AM
,
121 Type
*Ty
, unsigned AS
,
122 Instruction
*I
= nullptr) const override
;
124 /// If a physical register, this returns the register that receives the
125 /// exception address on entry to an EH pad.
127 getExceptionPointerRegister(const Constant
*PersonalityFn
) const override
{
131 /// If a physical register, this returns the register that receives the
132 /// exception typeid on entry to a landing pad.
134 getExceptionSelectorRegister(const Constant
*PersonalityFn
) const override
{
139 const TargetMachine
&TM
;
140 const XCoreSubtarget
&Subtarget
;
142 // Lower Operand helpers
143 SDValue
LowerCCCArguments(SDValue Chain
, CallingConv::ID CallConv
,
145 const SmallVectorImpl
<ISD::InputArg
> &Ins
,
146 const SDLoc
&dl
, SelectionDAG
&DAG
,
147 SmallVectorImpl
<SDValue
> &InVals
) const;
148 SDValue
LowerCCCCallTo(SDValue Chain
, SDValue Callee
,
149 CallingConv::ID CallConv
, bool isVarArg
,
151 const SmallVectorImpl
<ISD::OutputArg
> &Outs
,
152 const SmallVectorImpl
<SDValue
> &OutVals
,
153 const SmallVectorImpl
<ISD::InputArg
> &Ins
,
154 const SDLoc
&dl
, SelectionDAG
&DAG
,
155 SmallVectorImpl
<SDValue
> &InVals
) const;
156 SDValue
getReturnAddressFrameIndex(SelectionDAG
&DAG
) const;
157 SDValue
getGlobalAddressWrapper(SDValue GA
, const GlobalValue
*GV
,
158 SelectionDAG
&DAG
) const;
159 SDValue
lowerLoadWordFromAlignedBasePlusOffset(const SDLoc
&DL
,
160 SDValue Chain
, SDValue Base
,
162 SelectionDAG
&DAG
) const;
164 // Lower Operand specifics
165 SDValue
LowerLOAD(SDValue Op
, SelectionDAG
&DAG
) const;
166 SDValue
LowerSTORE(SDValue Op
, SelectionDAG
&DAG
) const;
167 SDValue
LowerEH_RETURN(SDValue Op
, SelectionDAG
&DAG
) const;
168 SDValue
LowerGlobalAddress(SDValue Op
, SelectionDAG
&DAG
) const;
169 SDValue
LowerGlobalTLSAddress(SDValue Op
, SelectionDAG
&DAG
) const;
170 SDValue
LowerBlockAddress(SDValue Op
, SelectionDAG
&DAG
) const;
171 SDValue
LowerConstantPool(SDValue Op
, SelectionDAG
&DAG
) const;
172 SDValue
LowerBR_JT(SDValue Op
, SelectionDAG
&DAG
) const;
173 SDValue
LowerVAARG(SDValue Op
, SelectionDAG
&DAG
) const;
174 SDValue
LowerVASTART(SDValue Op
, SelectionDAG
&DAG
) const;
175 SDValue
LowerUMUL_LOHI(SDValue Op
, SelectionDAG
&DAG
) const;
176 SDValue
LowerSMUL_LOHI(SDValue Op
, SelectionDAG
&DAG
) const;
177 SDValue
LowerFRAMEADDR(SDValue Op
, SelectionDAG
&DAG
) const;
178 SDValue
LowerFRAME_TO_ARGS_OFFSET(SDValue Op
, SelectionDAG
&DAG
) const;
179 SDValue
LowerRETURNADDR(SDValue Op
, SelectionDAG
&DAG
) const;
180 SDValue
LowerINIT_TRAMPOLINE(SDValue Op
, SelectionDAG
&DAG
) const;
181 SDValue
LowerADJUST_TRAMPOLINE(SDValue Op
, SelectionDAG
&DAG
) const;
182 SDValue
LowerINTRINSIC_WO_CHAIN(SDValue Op
, SelectionDAG
&DAG
) const;
183 SDValue
LowerATOMIC_FENCE(SDValue Op
, SelectionDAG
&DAG
) const;
184 SDValue
LowerATOMIC_LOAD(SDValue Op
, SelectionDAG
&DAG
) const;
185 SDValue
LowerATOMIC_STORE(SDValue Op
, SelectionDAG
&DAG
) const;
187 MachineMemOperand::Flags
getTargetMMOFlags(
188 const Instruction
&I
) const override
;
190 // Inline asm support
191 std::pair
<unsigned, const TargetRegisterClass
*>
192 getRegForInlineAsmConstraint(const TargetRegisterInfo
*TRI
,
193 StringRef Constraint
, MVT VT
) const override
;
196 SDValue
TryExpandADDWithMul(SDNode
*Op
, SelectionDAG
&DAG
) const;
197 SDValue
ExpandADDSUB(SDNode
*Op
, SelectionDAG
&DAG
) const;
199 SDValue
PerformDAGCombine(SDNode
*N
, DAGCombinerInfo
&DCI
) const override
;
201 void computeKnownBitsForTargetNode(const SDValue Op
,
203 const APInt
&DemandedElts
,
204 const SelectionDAG
&DAG
,
205 unsigned Depth
= 0) const override
;
208 LowerFormalArguments(SDValue Chain
, CallingConv::ID CallConv
, bool isVarArg
,
209 const SmallVectorImpl
<ISD::InputArg
> &Ins
,
210 const SDLoc
&dl
, SelectionDAG
&DAG
,
211 SmallVectorImpl
<SDValue
> &InVals
) const override
;
214 LowerCall(TargetLowering::CallLoweringInfo
&CLI
,
215 SmallVectorImpl
<SDValue
> &InVals
) const override
;
217 SDValue
LowerReturn(SDValue Chain
, CallingConv::ID CallConv
, bool isVarArg
,
218 const SmallVectorImpl
<ISD::OutputArg
> &Outs
,
219 const SmallVectorImpl
<SDValue
> &OutVals
,
220 const SDLoc
&dl
, SelectionDAG
&DAG
) const override
;
223 CanLowerReturn(CallingConv::ID CallConv
, MachineFunction
&MF
,
225 const SmallVectorImpl
<ISD::OutputArg
> &ArgsFlags
,
226 LLVMContext
&Context
) const override
;
227 bool shouldInsertFencesForAtomic(const Instruction
*I
) const override
{