LLVM  16.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 
20 
21 namespace llvm {
22 class CSKYSubtarget;
23 
24 namespace CSKYISD {
25 enum NodeType : unsigned {
27  NIE,
28  NIR,
29  RET,
35  // i32, i32 <-- f64
37  // f64 < -- i32, i32
39 };
40 }
41 
43  const CSKYSubtarget &Subtarget;
44 
45 public:
46  explicit CSKYTargetLowering(const TargetMachine &TM,
47  const CSKYSubtarget &STI);
48 
49  SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const override;
50 
52  EVT VT) const override;
53 
54 private:
55  SDValue LowerFormalArguments(SDValue Chain, CallingConv::ID CallConv,
56  bool IsVarArg,
58  const SDLoc &DL, SelectionDAG &DAG,
59  SmallVectorImpl<SDValue> &InVals) const override;
60 
61  bool CanLowerReturn(CallingConv::ID CallConv, MachineFunction &MF,
62  bool IsVarArg,
64  LLVMContext &Context) const override;
65 
66  SDValue LowerReturn(SDValue Chain, CallingConv::ID CallConv, bool IsVarArg,
68  const SmallVectorImpl<SDValue> &OutVals, const SDLoc &DL,
69  SelectionDAG &DAG) const override;
70 
72  SmallVectorImpl<SDValue> &InVals) const override;
73 
74  const char *getTargetNodeName(unsigned Opcode) const override;
75 
76  /// If a physical register, this returns the register that receives the
77  /// exception address on entry to an EH pad.
78  Register
79  getExceptionPointerRegister(const Constant *PersonalityFn) const override;
80 
81  /// If a physical register, this returns the register that receives the
82  /// exception typeid on entry to a landing pad.
83  Register
84  getExceptionSelectorRegister(const Constant *PersonalityFn) const override;
85 
86  bool isSelectSupported(SelectSupportKind Kind) const override {
87  // CSKY does not support scalar condition selects on vectors.
88  return (Kind != ScalarCondVectorVal);
89  }
90 
91  ConstraintType getConstraintType(StringRef Constraint) const override;
92 
93  std::pair<unsigned, const TargetRegisterClass *>
94  getRegForInlineAsmConstraint(const TargetRegisterInfo *TRI,
95  StringRef Constraint, MVT VT) const override;
96 
98  EmitInstrWithCustomInserter(MachineInstr &MI,
99  MachineBasicBlock *BB) const override;
100 
101  SDValue getTargetNode(GlobalAddressSDNode *N, SDLoc DL, EVT Ty,
102  SelectionDAG &DAG, unsigned Flags) const;
103 
104  SDValue getTargetNode(ExternalSymbolSDNode *N, SDLoc DL, EVT Ty,
105  SelectionDAG &DAG, unsigned Flags) const;
106 
107  SDValue getTargetNode(JumpTableSDNode *N, SDLoc DL, EVT Ty, SelectionDAG &DAG,
108  unsigned Flags) const;
109 
110  SDValue getTargetNode(BlockAddressSDNode *N, SDLoc DL, EVT Ty,
111  SelectionDAG &DAG, unsigned Flags) const;
112 
113  SDValue getTargetNode(ConstantPoolSDNode *N, SDLoc DL, EVT Ty,
114  SelectionDAG &DAG, unsigned Flags) const;
115 
116  SDValue getTargetConstantPoolValue(GlobalAddressSDNode *N, EVT Ty,
117  SelectionDAG &DAG, unsigned Flags) const;
118 
119  SDValue getTargetConstantPoolValue(ExternalSymbolSDNode *N, EVT Ty,
120  SelectionDAG &DAG, unsigned Flags) const;
121 
122  SDValue getTargetConstantPoolValue(JumpTableSDNode *N, EVT Ty,
123  SelectionDAG &DAG, unsigned Flags) const;
124 
125  SDValue getTargetConstantPoolValue(BlockAddressSDNode *N, EVT Ty,
126  SelectionDAG &DAG, unsigned Flags) const;
127 
128  SDValue getTargetConstantPoolValue(ConstantPoolSDNode *N, EVT Ty,
129  SelectionDAG &DAG, unsigned Flags) const;
130 
131  template <class NodeTy, bool IsCall = false>
132  SDValue getAddr(NodeTy *N, SelectionDAG &DAG, bool IsLocal = true) const {
133  SDLoc DL(N);
134  EVT Ty = getPointerTy(DAG.getDataLayout());
135 
136  unsigned Flag = CSKYII::MO_None;
137  bool IsPIC = isPositionIndependent();
138 
139  if (IsPIC)
140  Flag = IsLocal ? CSKYII::MO_GOTOFF
141  : IsCall ? CSKYII::MO_PLT32
143 
144  SDValue TCPV = getTargetConstantPoolValue(N, Ty, DAG, Flag);
145  SDValue TV = getTargetNode(N, DL, Ty, DAG, Flag);
146  SDValue Addr = DAG.getNode(CSKYISD::LOAD_ADDR, DL, Ty, {TV, TCPV});
147 
148  if (!IsPIC)
149  return Addr;
150 
151  SDValue Result =
152  DAG.getNode(ISD::ADD, DL, Ty, {DAG.getGLOBAL_OFFSET_TABLE(Ty), Addr});
153  if (IsLocal)
154  return Result;
155 
156  return DAG.getLoad(Ty, DL, DAG.getEntryNode(), Result,
158  }
159 
160  SDValue LowerGlobalAddress(SDValue Op, SelectionDAG &DAG) const;
161  SDValue LowerExternalSymbol(SDValue Op, SelectionDAG &DAG) const;
162  SDValue LowerGlobalTLSAddress(SDValue Op, SelectionDAG &DAG) const;
163  SDValue LowerBlockAddress(SDValue Op, SelectionDAG &DAG) const;
164  SDValue LowerConstantPool(SDValue Op, SelectionDAG &DAG) const;
165  SDValue LowerJumpTable(SDValue Op, SelectionDAG &DAG) const;
166  SDValue LowerVASTART(SDValue Op, SelectionDAG &DAG) const;
167  SDValue LowerFRAMEADDR(SDValue Op, SelectionDAG &DAG) const;
168  SDValue LowerRETURNADDR(SDValue Op, SelectionDAG &DAG) const;
169 
170  SDValue getStaticTLSAddr(GlobalAddressSDNode *N, SelectionDAG &DAG,
171  bool UseGOT) const;
172  SDValue getDynamicTLSAddr(GlobalAddressSDNode *N, SelectionDAG &DAG) const;
173 
174  CCAssignFn *CCAssignFnForCall(CallingConv::ID CC, bool IsVarArg) const;
175  CCAssignFn *CCAssignFnForReturn(CallingConv::ID CC, bool IsVarArg) const;
176 };
177 
178 } // namespace llvm
179 
180 #endif // LLVM_LIB_TARGET_CSKY_CSKYISELLOWERING_H
llvm::SelectionDAG::getGLOBAL_OFFSET_TABLE
SDValue getGLOBAL_OFFSET_TABLE(EVT VT)
Return a GLOBAL_OFFSET_TABLE node. This does not have a useful SDLoc.
Definition: SelectionDAG.h:1036
llvm::CSKYISD::FIRST_NUMBER
@ FIRST_NUMBER
Definition: CSKYISelLowering.h:26
MI
IRTranslator LLVM IR MI
Definition: IRTranslator.cpp:108
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
llvm::SDLoc
Wrapper class for IR location info (IR ordering and DebugLoc) to be passed into SDNode creation funct...
Definition: SelectionDAGNodes.h:1106
llvm::DataLayout
A parsed version of the target data layout string in and methods for querying it.
Definition: DataLayout.h:113
llvm::TargetLowering::ConstraintType
ConstraintType
Definition: TargetLowering.h:4554
CSKYBaseInfo.h
llvm::CSKYISD::NIR
@ NIR
Definition: CSKYISelLowering.h:28
llvm::TargetRegisterInfo
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
Definition: TargetRegisterInfo.h:237
llvm::TargetLowering::isPositionIndependent
bool isPositionIndependent() const
Definition: TargetLowering.cpp:46
llvm::CSKYISD::CALL
@ CALL
Definition: CSKYISelLowering.h:30
llvm::BlockAddressSDNode
Definition: SelectionDAGNodes.h:2195
llvm::CSKYISD::RET
@ RET
Definition: CSKYISelLowering.h:29
TRI
unsigned const TargetRegisterInfo * TRI
Definition: MachineSink.cpp:1628
llvm::CSKYTargetLowering::getSetCCResultType
EVT getSetCCResultType(const DataLayout &DL, LLVMContext &Context, EVT VT) const override
Return the ValueType of the result of SETCC operations.
Definition: CSKYISelLowering.cpp:187
Context
LLVMContext & Context
Definition: NVVMIntrRange.cpp:66
TargetLowering.h
llvm::SelectionDAG::getLoad
SDValue getLoad(EVT VT, const SDLoc &dl, SDValue Chain, SDValue Ptr, MachinePointerInfo PtrInfo, MaybeAlign Alignment=MaybeAlign(), MachineMemOperand::Flags MMOFlags=MachineMemOperand::MONone, const AAMDNodes &AAInfo=AAMDNodes(), const MDNode *Ranges=nullptr)
Loads are not normal binary operators: their result type is not determined by their operands,...
Definition: SelectionDAG.cpp:7988
llvm::CSKYII::MO_GOT32
@ MO_GOT32
Definition: CSKYBaseInfo.h:43
llvm::ExternalSymbolSDNode
Definition: SelectionDAGNodes.h:2237
llvm::SelectionDAG
This is used to represent a portion of an LLVM function in a low-level Data Dependence DAG representa...
Definition: SelectionDAG.h:220
llvm::EVT
Extended Value Type.
Definition: ValueTypes.h:34
llvm::JumpTableSDNode
Definition: SelectionDAGNodes.h:1862
llvm::TargetLowering
This class defines information used to lower LLVM code to legal SelectionDAG operators that the targe...
Definition: TargetLowering.h:3490
llvm::MachinePointerInfo::getGOT
static MachinePointerInfo getGOT(MachineFunction &MF)
Return a MachinePointerInfo record that refers to a GOT entry.
Definition: MachineOperand.cpp:1028
llvm::MCID::Flag
Flag
These should be considered private to the implementation of the MCInstrDesc class.
Definition: MCInstrDesc.h:147
llvm::CSKYSubtarget
Definition: CSKYSubtarget.h:30
llvm::CallingConv::ID
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition: CallingConv.h:24
llvm::MachineBasicBlock
Definition: MachineBasicBlock.h:94
llvm::CSKYISD::LOAD_ADDR
@ LOAD_ADDR
Definition: CSKYISelLowering.h:34
llvm::CCAssignFn
bool CCAssignFn(unsigned ValNo, MVT ValVT, MVT LocVT, CCValAssign::LocInfo LocInfo, ISD::ArgFlagsTy ArgFlags, CCState &State)
CCAssignFn - This function assigns a location for Val, updating State to reflect the change.
Definition: CallingConvLower.h:175
llvm::Constant
This is an important base class in LLVM.
Definition: Constant.h:41
llvm::CSKYII::MO_GOTOFF
@ MO_GOTOFF
Definition: CSKYBaseInfo.h:44
llvm::CSKYTargetLowering::LowerOperation
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...
Definition: CSKYISelLowering.cpp:161
llvm::MachineInstr
Representation of each machine instruction.
Definition: MachineInstr.h:66
llvm::CSKYII::MO_None
@ MO_None
Definition: CSKYBaseInfo.h:41
Addr
uint64_t Addr
Definition: ELFObjHandler.cpp:79
llvm::LLVMContext
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:67
llvm::SelectionDAG::getNode
SDValue getNode(unsigned Opcode, const SDLoc &DL, EVT VT, ArrayRef< SDUse > Ops)
Gets or creates the specified node.
Definition: SelectionDAG.cpp:9072
llvm::TargetLowering::CallLoweringInfo
This structure contains all information that is necessary for lowering calls.
Definition: TargetLowering.h:4138
llvm::TargetMachine
Primary interface to the complete machine description for the target machine.
Definition: TargetMachine.h:76
llvm::MVT
Machine Value Type.
Definition: MachineValueType.h:31
llvm::CSKYISD::BITCAST_FROM_LOHI
@ BITCAST_FROM_LOHI
Definition: CSKYISelLowering.h:38
llvm::MachineFunction
Definition: MachineFunction.h:257
llvm::ConstantPoolSDNode
Definition: SelectionDAGNodes.h:1883
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
DL
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Definition: AArch64SLSHardening.cpp:76
llvm::CSKYISD::TAILReg
@ TAILReg
Definition: CSKYISelLowering.h:33
CC
auto CC
Definition: RISCVRedundantCopyElimination.cpp:79
llvm::ISD::BUILTIN_OP_END
@ BUILTIN_OP_END
BUILTIN_OP_END - This must be the last enum value in this list.
Definition: ISDOpcodes.h:1307
llvm::Register
Wrapper class representing virtual and physical registers.
Definition: Register.h:19
llvm::GlobalAddressSDNode
Definition: SelectionDAGNodes.h:1759
CallingConvLower.h
llvm::CSKYISD::CALLReg
@ CALLReg
Definition: CSKYISelLowering.h:31
llvm::AMDGPU::SendMsg::Op
Op
Definition: SIDefines.h:348
llvm::SelectionDAG::getEntryNode
SDValue getEntryNode() const
Return the token chain corresponding to the entry of the function.
Definition: SelectionDAG.h:548
llvm::SelectionDAG::getDataLayout
const DataLayout & getDataLayout() const
Definition: SelectionDAG.h:469
llvm::SDValue
Unlike LLVM values, Selection DAG nodes may return multiple values as the result of a computation.
Definition: SelectionDAGNodes.h:145
llvm::CSKYISD::TAIL
@ TAIL
Definition: CSKYISelLowering.h:32
llvm::ISD::ADD
@ ADD
Simple integer binary arithmetic operators.
Definition: ISDOpcodes.h:239
llvm::TargetLoweringBase::ScalarCondVectorVal
@ ScalarCondVectorVal
Definition: TargetLowering.h:239
N
#define N
llvm::CSKYTargetLowering::CSKYTargetLowering
CSKYTargetLowering(const TargetMachine &TM, const CSKYSubtarget &STI)
Definition: CSKYISelLowering.cpp:36
llvm::MipsISD::Ins
@ Ins
Definition: MipsISelLowering.h:160
llvm::SmallVectorImpl
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: APFloat.h:42
TM
const char LLVMTargetMachineRef TM
Definition: PassBuilderBindings.cpp:47
llvm::SelectionDAG::getMachineFunction
MachineFunction & getMachineFunction() const
Definition: SelectionDAG.h:466
BB
Common register allocation spilling lr str ldr sxth r3 ldr mla r4 can lr mov lr str ldr sxth r3 mla r4 and then merge mul and lr str ldr sxth r3 mla r4 It also increase the likelihood the store may become dead bb27 Successors according to LLVM BB
Definition: README.txt:39
llvm::CSKYISD::NIE
@ NIE
Definition: CSKYISelLowering.h:27
llvm::CSKYII::MO_PLT32
@ MO_PLT32
Definition: CSKYBaseInfo.h:45
llvm::CSKYISD::BITCAST_TO_LOHI
@ BITCAST_TO_LOHI
Definition: CSKYISelLowering.h:36
llvm::CSKYISD::NodeType
NodeType
Definition: CSKYISelLowering.h:25
llvm::TargetLoweringBase::SelectSupportKind
SelectSupportKind
Enum that describes what type of support for selects the target has.
Definition: TargetLowering.h:237
llvm::TargetLoweringBase::getPointerTy
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...
Definition: TargetLowering.h:356
llvm::CSKYTargetLowering
Definition: CSKYISelLowering.h:42