LLVM 24.0.0git
M68kISelLowering.h
Go to the documentation of this file.
1//===-- M68kISelLowering.h - M68k DAG Lowering Interface --------*- C++ -*-===//
2//
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
6//
7//===----------------------------------------------------------------------===//
8///
9/// \file
10/// This file defines the interfaces that M68k uses to lower LLVM code into a
11/// selection DAG.
12///
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_LIB_TARGET_M68K_M68KISELLOWERING_H
16#define LLVM_LIB_TARGET_M68K_M68KISELLOWERING_H
17
18#include "M68k.h"
19
23#include "llvm/IR/Function.h"
24
25#include <deque>
26
27namespace llvm {
28
29/// Define some predicates that are used for node matching.
30namespace M68k {
31
32/// Determines whether the callee is required to pop its
33/// own arguments. Callee pop is necessary to support tail calls.
34bool isCalleePop(CallingConv::ID CallingConv, bool IsVarArg, bool GuaranteeTCO);
35
36} // end namespace M68k
37
38//===--------------------------------------------------------------------===//
39// TargetLowering Implementation
40//===--------------------------------------------------------------------===//
41
42class M68kSubtarget;
43
45 const M68kSubtarget &Subtarget;
46 const M68kTargetMachine &TM;
47
48public:
49 explicit M68kTargetLowering(const M68kTargetMachine &TM,
50 const M68kSubtarget &STI);
51
53 const M68kSubtarget &STI);
54
55 /// Return the value type to use for ISD::SETCC.
57 EVT VT) const override;
58
59 /// EVT is not used in-tree, but is used by out-of-tree target.
60 virtual MVT getScalarShiftAmountTy(const DataLayout &, EVT) const override;
61
62 /// Provide custom lowering hooks for some operations.
63 SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const override;
64
65 /// Return the entry encoding for a jump table in the current function.
66 /// The returned value is a member of the MachineJumpTableInfo::JTEntryKind
67 /// enum.
68 unsigned getJumpTableEncoding() const override;
69
72 unsigned uid,
73 MCContext &Ctx) const override;
74
75 /// Returns relocation base for the given PIC jumptable.
77 SelectionDAG &DAG) const override;
78
79 /// This returns the relocation base for the given PIC jumptable,
80 /// the same as getPICJumpTableRelocBase, but as an MCExpr.
82 unsigned JTI,
83 MCContext &Ctx) const override;
84
85 ConstraintType getConstraintType(StringRef ConstraintStr) const override;
86
87 std::pair<unsigned, const TargetRegisterClass *>
89 StringRef Constraint, MVT VT) const override;
90
91 // Lower operand with C_Immediate and C_Other constraint type
93 std::vector<SDValue> &Ops,
94 SelectionDAG &DAG) const override;
95
98 MachineBasicBlock *MBB) const override;
99
101 bool IsVarArg) const;
102
104 shouldExpandAtomicRMWInIR(const AtomicRMWInst *RMW) const override;
105
106 /// If a physical register, this returns the register that receives the
107 /// exception address on entry to an EH pad.
110 const Constant *PersonalityFn) const override;
111
112 /// If a physical register, this returns the register that receives the
113 /// exception typeid on entry to a landing pad.
116 const Constant *PersonalityFn) const override;
117
119 getInlineAsmMemConstraint(StringRef ConstraintCode) const override;
120
121 // We need this for DAGCombiner to eliminate as many ISD::SELECT as possible.
122 // Otherwise we might end up with M68kISD::CMOV.
123 bool convertSelectOfConstantsToMath(EVT VT) const override { return true; }
124
125private:
126 unsigned GetAlignedArgumentStackSize(unsigned StackSize,
127 SelectionDAG &DAG) const;
128
129 bool isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const override {
130 // In many cases, `GA` doesn't give the correct offset to fold. It's
131 // hard to know if the real offset actually fits into the displacement
132 // of the perspective addressing mode.
133 // Thus, we disable offset folding altogether and leave that to ISel
134 // patterns.
135 return false;
136 }
137
138 SDValue getReturnAddressFrameIndex(SelectionDAG &DAG) const;
139
140 /// Emit a load of return address if tail call
141 /// optimization is performed and it is required.
142 SDValue EmitTailCallLoadRetAddr(SelectionDAG &DAG, SDValue &OutRetAddr,
143 SDValue Chain, bool IsTailCall, int FPDiff,
144 const SDLoc &DL) const;
145
146 /// Emit a store of the return address if tail call
147 /// optimization is performed and it is required (FPDiff!=0).
148 SDValue EmitTailCallStoreRetAddr(SelectionDAG &DAG, MachineFunction &MF,
149 SDValue Chain, SDValue RetAddrFrIdx,
150 EVT PtrVT, unsigned SlotSize, int FPDiff,
151 const SDLoc &DL) const;
152
153 SDValue LowerMemArgument(SDValue Chain, CallingConv::ID CallConv,
154 const SmallVectorImpl<ISD::InputArg> &ArgInfo,
155 const SDLoc &DL, SelectionDAG &DAG,
156 const CCValAssign &VA, MachineFrameInfo &MFI,
157 unsigned ArgIdx) const;
158
159 SDValue LowerMemOpCallTo(SDValue Chain, SDValue StackPtr, SDValue Arg,
160 const SDLoc &DL, SelectionDAG &DAG,
161 const CCValAssign &VA, ISD::ArgFlagsTy Flags) const;
162
163 SDValue LowerXALUO(SDValue Op, SelectionDAG &DAG) const;
164 SDValue LowerToBTST(SDValue And, ISD::CondCode CC, const SDLoc &DL,
165 SelectionDAG &DAG) const;
166 SDValue LowerSETCC(SDValue Op, SelectionDAG &DAG) const;
167 SDValue LowerSETCCCARRY(SDValue Op, SelectionDAG &DAG) const;
168 SDValue LowerSELECT(SDValue Op, SelectionDAG &DAG) const;
169 SDValue LowerBRCOND(SDValue Op, SelectionDAG &DAG) const;
170 SDValue LowerUADDO_USUBO_CARRY(SDValue Op, SelectionDAG &DAG) const;
171 SDValue LowerConstantPool(SDValue Op, SelectionDAG &DAG) const;
172 SDValue LowerJumpTable(SDValue Op, SelectionDAG &DAG) const;
173 SDValue LowerExternalSymbol(SDValue Op, SelectionDAG &DAG) const;
174 SDValue LowerBlockAddress(SDValue Op, SelectionDAG &DAG) const;
175 SDValue LowerGlobalAddress(const GlobalValue *GV, const SDLoc &DL,
176 int64_t Offset, SelectionDAG &DAG) const;
177 SDValue LowerGlobalAddress(SDValue Op, SelectionDAG &DAG) const;
178 SDValue LowerVASTART(SDValue Op, SelectionDAG &DAG) const;
179 SDValue LowerDYNAMIC_STACKALLOC(SDValue Op, SelectionDAG &DAG) const;
180 SDValue LowerShiftLeftParts(SDValue Op, SelectionDAG &DAG) const;
181 SDValue LowerShiftRightParts(SDValue Op, SelectionDAG &DAG, bool IsSRA) const;
182
183 SDValue LowerATOMICFENCE(SDValue Op, SelectionDAG &DAG) const;
184
186 CallingConv::ID CallConv, bool IsVarArg,
187 const SmallVectorImpl<ISD::InputArg> &Ins,
188 const SDLoc &DL, SelectionDAG &DAG,
189 SmallVectorImpl<SDValue> &InVals) const;
190 SDValue LowerGlobalTLSAddress(SDValue Op, SelectionDAG &DAG) const;
191
192 /// LowerFormalArguments - transform physical registers into virtual
193 /// registers and generate load operations for arguments places on the stack.
194 SDValue LowerFormalArguments(SDValue Chain, CallingConv::ID CCID,
195 bool IsVarArg,
196 const SmallVectorImpl<ISD::InputArg> &Ins,
197 const SDLoc &DL, SelectionDAG &DAG,
198 SmallVectorImpl<SDValue> &InVals) const override;
199
200 SDValue LowerCall(CallLoweringInfo &CLI,
201 SmallVectorImpl<SDValue> &InVals) const override;
202
203 bool CanLowerReturn(CallingConv::ID CallConv, MachineFunction &MF,
204 bool isVarArg,
205 const SmallVectorImpl<ISD::OutputArg> &Outs,
206 LLVMContext &Context, const Type *RetTy) const override;
207
208 /// Lower the result values of a call into the
209 /// appropriate copies out of appropriate physical registers.
210 SDValue LowerReturn(SDValue Chain, CallingConv::ID CCID, bool IsVarArg,
211 const SmallVectorImpl<ISD::OutputArg> &Outs,
212 const SmallVectorImpl<SDValue> &OutVals, const SDLoc &DL,
213 SelectionDAG &DAG) const override;
214
215 SDValue LowerExternalSymbolCall(SelectionDAG &DAG, SDLoc loc,
216 llvm::StringRef SymbolName,
217 ArgListTy &&ArgList) const;
218 SDValue getTLSGetAddr(GlobalAddressSDNode *GA, SelectionDAG &DAG,
219 unsigned TargetFlags) const;
220 SDValue getM68kReadTp(SDLoc Loc, SelectionDAG &DAG) const;
221
222 SDValue LowerTLSGeneralDynamic(GlobalAddressSDNode *GA,
223 SelectionDAG &DAG) const;
224 SDValue LowerTLSLocalDynamic(GlobalAddressSDNode *GA,
225 SelectionDAG &DAG) const;
226 SDValue LowerTLSInitialExec(GlobalAddressSDNode *GA, SelectionDAG &DAG) const;
227 SDValue LowerTLSLocalExec(GlobalAddressSDNode *GA, SelectionDAG &DAG) const;
228
229 bool decomposeMulByConstant(LLVMContext &Context, EVT VT,
230 SDValue C) const override;
231
232 MachineBasicBlock *EmitLoweredSelect(MachineInstr &I,
233 MachineBasicBlock *MBB) const;
234 MachineBasicBlock *EmitLoweredSegAlloca(MachineInstr &MI,
235 MachineBasicBlock *BB) const;
236
237 /// Emit nodes that will be selected as "test Op0,Op0", or something
238 /// equivalent, for use with the given M68k condition code.
239 SDValue EmitTest(SDValue Op0, unsigned M68kCC, const SDLoc &dl,
240 SelectionDAG &DAG) const;
241
242 /// Emit nodes that will be selected as "cmp Op0,Op1", or something
243 /// equivalent, for use with the given M68k condition code.
244 SDValue EmitCmp(SDValue Op0, SDValue Op1, unsigned M68kCC, const SDLoc &dl,
245 SelectionDAG &DAG) const;
246
247 /// Check whether the call is eligible for tail call optimization. Targets
248 /// that want to do tail call optimization should implement this function.
249 bool IsEligibleForTailCallOptimization(
250 SDValue Callee, CallingConv::ID CalleeCC, bool IsVarArg,
251 bool IsCalleeStructRet, bool IsCallerStructRet, Type *RetTy,
252 const SmallVectorImpl<ISD::OutputArg> &Outs,
253 const SmallVectorImpl<SDValue> &OutVals,
254 const SmallVectorImpl<ISD::InputArg> &Ins, SelectionDAG &DAG) const;
255
256 SDValue PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const override;
257};
258} // namespace llvm
259
260#endif // LLVM_LIB_TARGET_M68K_M68KISELLOWERING_H
static SDValue LowerBRCOND(SDValue Op, SelectionDAG &DAG)
return SDValue()
static SDValue LowerXALUO(SDValue Op, SelectionDAG &DAG)
static SDValue LowerVASTART(SDValue Op, SelectionDAG &DAG)
static SDValue LowerSETCCCARRY(SDValue Op, SelectionDAG &DAG)
MachineBasicBlock & MBB
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
IRTranslator LLVM IR MI
const AbstractManglingParser< Derived, Alloc >::OperatorInfo AbstractManglingParser< Derived, Alloc >::Ops[]
This file contains the entry points for global functions defined in the M68k target library,...
#define I(x, y, z)
Definition MD5.cpp:57
Register const TargetRegisterInfo * TRI
static void LowerMemOpCallTo(SelectionDAG &DAG, MachineFunction &MF, SDValue Chain, SDValue Arg, SDValue PtrOff, int SPDiff, unsigned ArgOffset, bool isPPC64, bool isTailCall, bool isVector, SmallVectorImpl< SDValue > &MemOpChains, SmallVectorImpl< TailCallArgumentInfo > &TailCallArguments, const SDLoc &dl)
LowerMemOpCallTo - Store the argument to the stack or remember it in case of tail calls.
RISCVCC::CondCode CC
static SDValue LowerDYNAMIC_STACKALLOC(SDValue Op, SelectionDAG &DAG, const SparcSubtarget *Subtarget)
This file describes how to lower LLVM code to machine code.
static SDValue EmitTailCallStoreRetAddr(SelectionDAG &DAG, MachineFunction &MF, SDValue Chain, SDValue RetAddrFrIdx, EVT PtrVT, unsigned SlotSize, int FPDiff, const SDLoc &dl)
Emit a store of the return address if tail call optimization is performed and it is required (FPDiff!...
static SDValue EmitTest(SDValue Op, X86::CondCode X86CC, const SDLoc &dl, SelectionDAG &DAG, const X86Subtarget &Subtarget)
Emit nodes that will be selected as "test Op0,Op0", or something equivalent.
static SDValue EmitCmp(SDValue Op0, SDValue Op1, X86::CondCode X86CC, const SDLoc &dl, SelectionDAG &DAG, const X86Subtarget &Subtarget)
Emit nodes that will be selected as "cmp Op0,Op1", or something equivalent.
static SDValue LowerCallResult(SDValue Chain, SDValue InGlue, const SmallVectorImpl< CCValAssign > &RVLocs, const SDLoc &dl, SelectionDAG &DAG, SmallVectorImpl< SDValue > &InVals)
LowerCallResult - Lower the result values of a call into the appropriate copies out of appropriate ph...
an instruction that atomically reads a memory location, combines it with another value,...
This is an important base class in LLVM.
Definition Constant.h:44
A parsed version of the target data layout string in and methods for querying it.
Definition DataLayout.h:63
This is an important class for using LLVM in a threaded context.
Definition LLVMContext.h:76
ConstraintType getConstraintType(StringRef ConstraintStr) const override
Given a constraint, return the type of constraint it is for this target.
void LowerAsmOperandForConstraint(SDValue Op, StringRef Constraint, std::vector< SDValue > &Ops, SelectionDAG &DAG) const override
Lower the specified operand into the Ops vector.
MachineBasicBlock * EmitInstrWithCustomInserter(MachineInstr &MI, MachineBasicBlock *MBB) const override
This method should be implemented by targets that mark instructions with the 'usesCustomInserter' fla...
AtomicExpansionKind shouldExpandAtomicRMWInIR(const AtomicRMWInst *RMW) const override
Returns how the IR-level AtomicExpand pass should expand the given AtomicRMW, if at all.
virtual MVT getScalarShiftAmountTy(const DataLayout &, EVT) const override
EVT is not used in-tree, but is used by out-of-tree target.
const MCExpr * LowerCustomJumpTableEntry(const MachineJumpTableInfo *MJTI, const MachineBasicBlock *MBB, unsigned uid, MCContext &Ctx) const override
SDValue getPICJumpTableRelocBase(SDValue Table, SelectionDAG &DAG) const override
Returns relocation base for the given PIC jumptable.
const MCExpr * getPICJumpTableRelocBaseExpr(const MachineFunction *MF, unsigned JTI, MCContext &Ctx) const override
This returns the relocation base for the given PIC jumptable, the same as getPICJumpTableRelocBase,...
bool convertSelectOfConstantsToMath(EVT VT) const override
Return true if a select of constants (select Cond, C1, C2) should be transformed into simple math ops...
CCAssignFn * getCCAssignFn(CallingConv::ID CC, bool Return, bool IsVarArg) const
static const M68kTargetLowering * create(const M68kTargetMachine &TM, const M68kSubtarget &STI)
M68kTargetLowering(const M68kTargetMachine &TM, const M68kSubtarget &STI)
InlineAsm::ConstraintCode getInlineAsmMemConstraint(StringRef ConstraintCode) const override
SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const override
Provide custom lowering hooks for some operations.
EVT getSetCCResultType(const DataLayout &DL, LLVMContext &Context, EVT VT) const override
Return the value type to use for ISD::SETCC.
Register getExceptionSelectorRegister(ExceptionHandling EH, const Constant *PersonalityFn) const override
If a physical register, this returns the register that receives the exception typeid on entry to a la...
unsigned getJumpTableEncoding() const override
Return the entry encoding for a jump table in the current function.
Register getExceptionPointerRegister(ExceptionHandling EH, const Constant *PersonalityFn) const override
If a physical register, this returns the register that receives the exception address on entry to an ...
std::pair< unsigned, const TargetRegisterClass * > getRegForInlineAsmConstraint(const TargetRegisterInfo *TRI, StringRef Constraint, MVT VT) const override
Given a physical register constraint (e.g.
Context object for machine code objects.
Definition MCContext.h:84
Base class for the full range of assembler expressions which are needed for parsing.
Definition MCExpr.h:31
Machine Value Type.
Representation of each machine instruction.
Wrapper class representing virtual and physical registers.
Definition Register.h:20
Unlike LLVM values, Selection DAG nodes may return multiple values as the result of a computation.
This is used to represent a portion of an LLVM function in a low-level Data Dependence DAG representa...
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
AtomicExpansionKind
Enum that specifies what an atomic load/AtomicRMWInst is expanded to, if at all.
TargetLowering(const TargetLowering &)=delete
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition CallingConv.h:24
CondCode
ISD::CondCode enum - These are ordered carefully to make the bitfields below work out,...
Define some predicates that are used for node matching.
bool isCalleePop(CallingConv::ID CallingConv, bool IsVarArg, bool GuaranteeTCO)
Determines whether the callee is required to pop its own arguments.
This is an optimization pass for GlobalISel generic memory operations.
@ Offset
Definition DWP.cpp:577
bool CCAssignFn(unsigned ValNo, MVT ValVT, MVT LocVT, CCValAssign::LocInfo LocInfo, ISD::ArgFlagsTy ArgFlags, Type *OrigTy, CCState &State)
CCAssignFn - This function assigns a location for Val, updating State to reflect the change.
@ And
Bitwise or logical AND of integers.
DWARFExpression::Operation Op
ExceptionHandling
Definition CodeGen.h:54
#define N
Extended Value Type.
Definition ValueTypes.h:35