LLVM 24.0.0git
CSKYISelLowering.h
Go to the documentation of this file.
1//===-- CSKYISelLowering.cpp - CSKY DAG Lowering Implementation ----------===//
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// This file defines the interfaces that CSKY uses to lower LLVM code into a
10// selection DAG.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_LIB_TARGET_CSKY_CSKYISELLOWERING_H
15#define LLVM_LIB_TARGET_CSKY_CSKYISELLOWERING_H
16
21
22namespace llvm {
23class CSKYSubtarget;
24
26 const CSKYSubtarget &Subtarget;
27
28public:
29 explicit CSKYTargetLowering(const TargetMachine &TM,
30 const CSKYSubtarget &STI);
31
32 SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const override;
33
35 EVT VT) const override;
36
37private:
38 SDValue LowerFormalArguments(SDValue Chain, CallingConv::ID CallConv,
39 bool IsVarArg,
41 const SDLoc &DL, SelectionDAG &DAG,
42 SmallVectorImpl<SDValue> &InVals) const override;
43
44 bool CanLowerReturn(CallingConv::ID CallConv, MachineFunction &MF,
45 bool IsVarArg,
47 LLVMContext &Context, const Type *RetTy) const override;
48
49 SDValue LowerReturn(SDValue Chain, CallingConv::ID CallConv, bool IsVarArg,
51 const SmallVectorImpl<SDValue> &OutVals, const SDLoc &DL,
52 SelectionDAG &DAG) const override;
53
55 SmallVectorImpl<SDValue> &InVals) const override;
56
57 /// If a physical register, this returns the register that receives the
58 /// exception address on entry to an EH pad.
60 getExceptionPointerRegister(ExceptionHandling EH,
61 const Constant *PersonalityFn) const override;
62
63 /// If a physical register, this returns the register that receives the
64 /// exception typeid on entry to a landing pad.
66 getExceptionSelectorRegister(ExceptionHandling EH,
67 const Constant *PersonalityFn) const override;
68
69 bool isSelectSupported(SelectSupportKind Kind) const override {
70 // CSKY does not support scalar condition selects on vectors.
71 return (Kind != ScalarCondVectorVal);
72 }
73
74 ConstraintType getConstraintType(StringRef Constraint) const override;
75
76 std::pair<unsigned, const TargetRegisterClass *>
77 getRegForInlineAsmConstraint(const TargetRegisterInfo *TRI,
78 StringRef Constraint, MVT VT) const override;
79
81 EmitInstrWithCustomInserter(MachineInstr &MI,
82 MachineBasicBlock *BB) const override;
83
84 SDValue getTargetNode(GlobalAddressSDNode *N, SDLoc DL, EVT Ty,
85 SelectionDAG &DAG, unsigned Flags) const;
86
87 SDValue getTargetNode(ExternalSymbolSDNode *N, SDLoc DL, EVT Ty,
88 SelectionDAG &DAG, unsigned Flags) const;
89
90 SDValue getTargetNode(JumpTableSDNode *N, SDLoc DL, EVT Ty, SelectionDAG &DAG,
91 unsigned Flags) const;
92
93 SDValue getTargetNode(BlockAddressSDNode *N, SDLoc DL, EVT Ty,
94 SelectionDAG &DAG, unsigned Flags) const;
95
96 SDValue getTargetNode(ConstantPoolSDNode *N, SDLoc DL, EVT Ty,
97 SelectionDAG &DAG, unsigned Flags) const;
98
99 SDValue getTargetConstantPoolValue(GlobalAddressSDNode *N, EVT Ty,
100 SelectionDAG &DAG, unsigned Flags) const;
101
102 SDValue getTargetConstantPoolValue(ExternalSymbolSDNode *N, EVT Ty,
103 SelectionDAG &DAG, unsigned Flags) const;
104
105 SDValue getTargetConstantPoolValue(JumpTableSDNode *N, EVT Ty,
106 SelectionDAG &DAG, unsigned Flags) const;
107
108 SDValue getTargetConstantPoolValue(BlockAddressSDNode *N, EVT Ty,
109 SelectionDAG &DAG, unsigned Flags) const;
110
111 SDValue getTargetConstantPoolValue(ConstantPoolSDNode *N, EVT Ty,
112 SelectionDAG &DAG, unsigned Flags) const;
113
114 template <class NodeTy, bool IsCall = false>
115 SDValue getAddr(NodeTy *N, SelectionDAG &DAG, bool IsLocal = true) const {
116 SDLoc DL(N);
117 EVT Ty = getPointerTy(DAG.getDataLayout());
118
119 unsigned Flag = CSKYII::MO_None;
120 bool IsPIC = isPositionIndependent();
121
122 if (IsPIC)
123 Flag = IsLocal ? CSKYII::MO_GOTOFF
124 : IsCall ? CSKYII::MO_PLT32
126
127 SDValue TCPV = getTargetConstantPoolValue(N, Ty, DAG, Flag);
128 SDValue TV = getTargetNode(N, DL, Ty, DAG, Flag);
129 SDValue Addr = DAG.getNode(CSKYISD::LOAD_ADDR, DL, Ty, {TV, TCPV});
130
131 if (!IsPIC)
132 return Addr;
133
134 SDValue Result =
135 DAG.getNode(ISD::ADD, DL, Ty, {DAG.getGLOBAL_OFFSET_TABLE(Ty), Addr});
136 if (IsLocal)
137 return Result;
138
139 return DAG.getLoad(Ty, DL, DAG.getEntryNode(), Result,
141 }
142
143 SDValue LowerGlobalAddress(SDValue Op, SelectionDAG &DAG) const;
144 SDValue LowerExternalSymbol(SDValue Op, SelectionDAG &DAG) const;
145 SDValue LowerGlobalTLSAddress(SDValue Op, SelectionDAG &DAG) const;
146 SDValue LowerBlockAddress(SDValue Op, SelectionDAG &DAG) const;
147 SDValue LowerConstantPool(SDValue Op, SelectionDAG &DAG) const;
148 SDValue LowerJumpTable(SDValue Op, SelectionDAG &DAG) const;
149 SDValue LowerVASTART(SDValue Op, SelectionDAG &DAG) const;
150 SDValue LowerFRAMEADDR(SDValue Op, SelectionDAG &DAG) const;
151 SDValue LowerRETURNADDR(SDValue Op, SelectionDAG &DAG) const;
152
153 SDValue getStaticTLSAddr(GlobalAddressSDNode *N, SelectionDAG &DAG,
154 bool UseGOT) const;
155 SDValue getDynamicTLSAddr(GlobalAddressSDNode *N, SelectionDAG &DAG) const;
156
157 CCAssignFn *CCAssignFnForCall(CallingConv::ID CC, bool IsVarArg) const;
158 CCAssignFn *CCAssignFnForReturn(CallingConv::ID CC, bool IsVarArg) const;
159
160 bool decomposeMulByConstant(LLVMContext &Context, EVT VT,
161 SDValue C) const override;
162 bool isCheapToSpeculateCttz(Type *Ty) const override;
163 bool isCheapToSpeculateCtlz(Type *Ty) const override;
164};
165
166} // namespace llvm
167
168#endif // LLVM_LIB_TARGET_CSKY_CSKYISELLOWERING_H
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
IRTranslator LLVM IR MI
Register const TargetRegisterInfo * TRI
This file describes how to lower LLVM code to machine code.
CSKYTargetLowering(const TargetMachine &TM, const CSKYSubtarget &STI)
EVT getSetCCResultType(const DataLayout &DL, LLVMContext &Context, EVT VT) const override
Return the ValueType of the result of SETCC operations.
SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const override
This callback is invoked for operations that are unsupported by the target, which are registered to u...
This is an important base class in LLVM.
Definition Constant.h:43
A parsed version of the target data layout string in and methods for querying it.
Definition DataLayout.h:64
This is an important class for using LLVM in a threaded context.
Definition LLVMContext.h:68
Machine Value Type.
Representation of each machine instruction.
Wrapper class representing virtual and physical registers.
Definition Register.h:20
Wrapper class for IR location info (IR ordering and DebugLoc) to be passed into SDNode creation funct...
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...
SDValue getGLOBAL_OFFSET_TABLE(EVT VT)
Return a GLOBAL_OFFSET_TABLE node. This does not have a useful SDLoc.
const DataLayout & getDataLayout() const
LLVM_ABI SDValue getLoad(EVT VT, const SDLoc &dl, SDValue Chain, SDValue Ptr, MachinePointerInfo PtrInfo, MaybeAlign Alignment=MaybeAlign(), MachineMemOperand::Flags MMOFlags=MachineMemOperand::MONone, const MMOMetadata &Metadata=MMOMetadata())
Loads are not normal binary operators: their result type is not determined by their operands,...
LLVM_ABI SDValue getNode(unsigned Opcode, const SDLoc &DL, EVT VT, ArrayRef< SDUse > Ops)
Gets or creates the specified node.
MachineFunction & getMachineFunction() const
SDValue getEntryNode() const
Return the token chain corresponding to the entry of the function.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
SelectSupportKind
Enum that describes what type of support for selects the target has.
virtual MVT getPointerTy(const DataLayout &DL, uint32_t AS=0) const
Return the pointer type for the given address space, defaults to the pointer type from the data layou...
bool isPositionIndependent() const
TargetLowering(const TargetLowering &)=delete
Primary interface to the complete machine description for the target machine.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition CallingConv.h:24
@ ADD
Simple integer binary arithmetic operators.
Definition ISDOpcodes.h:264
This is an optimization pass for GlobalISel generic memory operations.
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.
DWARFExpression::Operation Op
ExceptionHandling
Definition CodeGen.h:54
#define N
Extended Value Type.
Definition ValueTypes.h:35
static LLVM_ABI MachinePointerInfo getGOT(MachineFunction &MF)
Return a MachinePointerInfo record that refers to a GOT entry.
This structure contains all information that is necessary for lowering calls.