LLVM 23.0.0git
NVPTXISelLowering.h
Go to the documentation of this file.
1//===-- NVPTXISelLowering.h - NVPTX 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// This file defines the interfaces that NVPTX uses to lower LLVM code into a
10// selection DAG.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_LIB_TARGET_NVPTX_NVPTXISELLOWERING_H
15#define LLVM_LIB_TARGET_NVPTX_NVPTXISELLOWERING_H
16
17#include "NVPTX.h"
21
22namespace llvm {
23
24class NVPTXSubtarget;
25
26//===--------------------------------------------------------------------===//
27// TargetLowering Implementation
28//===--------------------------------------------------------------------===//
30public:
31 explicit NVPTXTargetLowering(const NVPTXTargetMachine &TM,
32 const NVPTXSubtarget &STI);
33 SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const override;
34
36 const CallBase &I, MachineFunction &MF,
37 unsigned Intrinsic) const override;
38
39 // Helper for getting a function parameter name. Name is composed from
40 // its index and the function name.
41 std::string getParamName(const Function *F, unsigned Idx) const;
42
43 /// isLegalAddressingMode - Return true if the addressing mode represented
44 /// by AM is legal for this target, for a load/store of the specified type
45 /// Used to guide target specific optimizations, like loop strength
46 /// reduction (LoopStrengthReduce.cpp) and memory optimization for
47 /// address mode (CodeGenPrepare.cpp)
48 bool isLegalAddressingMode(const DataLayout &DL, const AddrMode &AM, Type *Ty,
49 unsigned AS,
50 Instruction *I = nullptr) const override;
51
52 bool isTruncateFree(Type *SrcTy, Type *DstTy) const override {
53 // Truncating 64-bit to 32-bit is free in SASS.
54 if (!SrcTy->isIntegerTy() || !DstTy->isIntegerTy())
55 return false;
56 return SrcTy->getPrimitiveSizeInBits() == 64 &&
57 DstTy->getPrimitiveSizeInBits() == 32;
58 }
59
61 EVT VT) const override {
62 if (VT.isVector())
63 return EVT::getVectorVT(Ctx, MVT::i1, VT.getVectorNumElements());
64 return MVT::i1;
65 }
66
67 ConstraintType getConstraintType(StringRef Constraint) const override;
68 std::pair<unsigned, const TargetRegisterClass *>
70 StringRef Constraint, MVT VT) const override;
71
73 bool isVarArg,
75 const SDLoc &dl, SelectionDAG &DAG,
76 SmallVectorImpl<SDValue> &InVals) const override;
77
78 SDValue LowerCall(CallLoweringInfo &CLI,
79 SmallVectorImpl<SDValue> &InVals) const override;
80
84
85 std::string getPrototype(const DataLayout &DL, Type *, const ArgListTy &,
87 const CallBase &CB, unsigned UniqueCallSite) const;
88
89 SDValue LowerReturn(SDValue Chain, CallingConv::ID CallConv, bool isVarArg,
91 const SmallVectorImpl<SDValue> &OutVals, const SDLoc &dl,
92 SelectionDAG &DAG) const override;
93
95 std::vector<SDValue> &Ops,
96 SelectionDAG &DAG) const override;
97
99
100 // PTX always uses 32-bit shift amounts
101 MVT getScalarShiftAmountTy(const DataLayout &, EVT) const override {
102 return MVT::i32;
103 }
104
106 getPreferredVectorAction(MVT VT) const override;
107
108 bool isShuffleMaskLegal(ArrayRef<int>, EVT VT) const override {
109 return isTypeLegal(VT);
110 }
111
112 // Get the degree of precision we want from 32-bit floating point division
113 // operations.
115 const SDNode &N) const;
116
117 // Get whether we should use a precise or approximate 32-bit floating point
118 // sqrt instruction.
119 bool usePrecSqrtF32(const SDNode *N = nullptr) const;
120
121 // Get whether we should use instructions that flush floating-point denormals
122 // to sign-preserving zero.
123 bool useF32FTZ(const MachineFunction &MF) const;
124
126 int &ExtraSteps, bool &UseOneConst,
127 bool Reciprocal) const override;
128
129 unsigned combineRepeatedFPDivisors() const override { return 2; }
130
131 bool allowFMA(MachineFunction &MF, CodeGenOptLevel OptLevel) const;
132
134 EVT) const override {
135 return true;
136 }
137
138 // The default is the same as pointer type, but brx.idx only accepts i32
139 MVT getJumpTableRegTy(const DataLayout &) const override { return MVT::i32; }
140
141 unsigned getJumpTableEncoding() const override;
142
143 bool enableAggressiveFMAFusion(EVT VT) const override { return true; }
144
145 // The default is to transform llvm.ctlz(x, false) (where false indicates that
146 // x == 0 is not undefined behavior) into a branch that checks whether x is 0
147 // and avoids calling ctlz in that case. We have a dedicated ctlz
148 // instruction, so we say that ctlz is cheap to speculate.
149 bool isCheapToSpeculateCtlz(Type *Ty) const override { return true; }
150
154
158
160 shouldExpandAtomicRMWInIR(const AtomicRMWInst *AI) const override;
161
162 bool aggressivelyPreferBuildVectorSources(EVT VecVT) const override {
163 // There's rarely any point of packing something into a vector type if we
164 // already have the source data.
165 return true;
166 }
167
168 bool shouldInsertFencesForAtomic(const Instruction *) const override;
169
172
174 AtomicOrdering Ord) const override;
176 AtomicOrdering Ord) const override;
177
178 unsigned getPreferredFPToIntOpcode(unsigned Op, EVT FromVT,
179 EVT ToVT) const override;
180
182 const APInt &DemandedElts,
183 const SelectionDAG &DAG,
184 unsigned Depth = 0) const override;
186 const APInt &DemandedElts,
187 KnownBits &Known,
188 TargetLoweringOpt &TLO,
189 unsigned Depth = 0) const override;
190
191private:
192 const NVPTXSubtarget &STI; // cache the subtarget here
193 mutable unsigned GlobalUniqueCallSite;
194
195 SDValue getParamSymbol(SelectionDAG &DAG, unsigned I, EVT T) const;
196 SDValue getCallParamSymbol(SelectionDAG &DAG, unsigned I, EVT T) const;
199
200 SDValue LowerBUILD_VECTOR(SDValue Op, SelectionDAG &DAG) const;
204 SDValue LowerINSERT_VECTOR_ELT(SDValue Op, SelectionDAG &DAG) const;
206
208
210 SDValue LowerFROUND32(SDValue Op, SelectionDAG &DAG) const;
211 SDValue LowerFROUND64(SDValue Op, SelectionDAG &DAG) const;
212
213 SDValue PromoteBinOpIfF32FTZ(SDValue Op, SelectionDAG &DAG) const;
214
215 SDValue LowerINT_TO_FP(SDValue Op, SelectionDAG &DAG) const;
216 SDValue LowerFP_TO_INT(SDValue Op, SelectionDAG &DAG) const;
217
218 SDValue LowerFP_ROUND(SDValue Op, SelectionDAG &DAG) const;
219 SDValue LowerFP_EXTEND(SDValue Op, SelectionDAG &DAG) const;
220
224 SDValue LowerSTOREi1(SDValue Op, SelectionDAG &DAG) const;
225
226 SDValue LowerShiftRightParts(SDValue Op, SelectionDAG &DAG) const;
227 SDValue LowerShiftLeftParts(SDValue Op, SelectionDAG &DAG) const;
228
229 SDValue LowerCopyToReg_128(SDValue Op, SelectionDAG &DAG) const;
230 unsigned getNumRegisters(LLVMContext &Context, EVT VT,
231 std::optional<MVT> RegisterVT) const override;
232 bool
233 splitValueIntoRegisterParts(SelectionDAG &DAG, const SDLoc &DL, SDValue Val,
234 SDValue *Parts, unsigned NumParts, MVT PartVT,
235 std::optional<CallingConv::ID> CC) const override;
236
237 void ReplaceNodeResults(SDNode *N, SmallVectorImpl<SDValue> &Results,
238 SelectionDAG &DAG) const override;
239 SDValue PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const override;
240
241 bool mayFoldFMULIntoFMA(SDNode *N, MachineFunction &MF,
242 CodeGenOptLevel OptLevel) const;
243 SDValue performScalarizeV2F32Op(SDNode *N, DAGCombinerInfo &DCI,
244 CodeGenOptLevel OptLevel) const;
245 SDValue performFADDCombineWithOperands(SDNode *N, SDValue N0, SDValue N1,
246 DAGCombinerInfo &DCI,
247 CodeGenOptLevel OptLevel) const;
248 SDValue performFADDCombine(SDNode *N, DAGCombinerInfo &DCI,
249 CodeGenOptLevel OptLevel) const;
250};
251
252} // namespace llvm
253
254#endif
static SDValue performFADDCombine(SDNode *N, TargetLowering::DAGCombinerInfo &DCI)
static SDValue LowerADDRSPACECAST(SDValue Op, SelectionDAG &DAG)
static SDValue LowerVECTOR_SHUFFLE(SDValue Op, SelectionDAG &DAG, const ARMSubtarget *ST)
static SDValue LowerCONCAT_VECTORS(SDValue Op, SelectionDAG &DAG, const ARMSubtarget *ST)
static SDValue LowerEXTRACT_VECTOR_ELT(SDValue Op, SelectionDAG &DAG, const ARMSubtarget *ST)
static SDValue LowerMLOAD(SDValue Op, SelectionDAG &DAG)
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Function Alias Analysis Results
Atomic ordering constants.
const AbstractManglingParser< Derived, Alloc >::OperatorInfo AbstractManglingParser< Derived, Alloc >::Ops[]
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
Register const TargetRegisterInfo * TRI
#define T
static SDValue LowerLOAD(SDValue Op, SelectionDAG &DAG)
static SDValue LowerSTORE(SDValue Op, SelectionDAG &DAG)
This file describes how to lower LLVM code to machine code.
static SDValue LowerBITCAST(SDValue Op, const X86Subtarget &Subtarget, SelectionDAG &DAG)
static SDValue LowerFROUND(SDValue Op, SelectionDAG &DAG)
ISD::FROUND is defined to round to nearest with ties rounding away from 0.
static SDValue LowerFCOPYSIGN(SDValue Op, SelectionDAG &DAG)
static SDValue LowerVECREDUCE(SDValue Op, const X86Subtarget &Subtarget, SelectionDAG &DAG, bool AllowScalarization)
Class for arbitrary precision integers.
Definition APInt.h:78
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
an instruction that atomically reads a memory location, combines it with another value,...
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
A parsed version of the target data layout string in and methods for querying it.
Definition DataLayout.h:64
Common base class shared among various IRBuilders.
Definition IRBuilder.h:114
This is an important class for using LLVM in a threaded context.
Definition LLVMContext.h:68
An instruction for reading from memory.
Machine Value Type.
AtomicOrdering atomicOperationOrderAfterFenceSplit(const Instruction *I) const override
bool enableAggressiveFMAFusion(EVT VT) const override
Return true if target always benefits from combining into FMA for a given value type.
ConstraintType getConstraintType(StringRef Constraint) const override
getConstraintType - Given a constraint letter, return the type of constraint it is for this target.
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...
const NVPTXTargetMachine * nvTM
bool SimplifyDemandedBitsForTargetNode(SDValue Op, const APInt &DemandedBits, const APInt &DemandedElts, KnownBits &Known, TargetLoweringOpt &TLO, unsigned Depth=0) const override
Attempt to simplify any target nodes based on the demanded bits/elts, returning true on success.
std::string getPrototype(const DataLayout &DL, Type *, const ArgListTy &, const SmallVectorImpl< ISD::OutputArg > &, const CallBase &CB, unsigned UniqueCallSite) const
AtomicExpansionKind shouldExpandAtomicRMWInIR(const AtomicRMWInst *AI) const override
Returns how the IR-level AtomicExpand pass should expand the given AtomicRMW, if at all.
NVPTXTargetLowering(const NVPTXTargetMachine &TM, const NVPTXSubtarget &STI)
MVT getJumpTableRegTy(const DataLayout &) const override
unsigned getPreferredFPToIntOpcode(unsigned Op, EVT FromVT, EVT ToVT) const override
bool useF32FTZ(const MachineFunction &MF) const
SDValue LowerSTACKSAVE(SDValue Op, SelectionDAG &DAG) const
unsigned combineRepeatedFPDivisors() const override
Indicate whether this target prefers to combine FDIVs with the same divisor.
SDValue getSqrtEstimate(SDValue Operand, SelectionDAG &DAG, int Enabled, int &ExtraSteps, bool &UseOneConst, bool Reciprocal) const override
Hooks for building estimates in place of slower divisions and square roots.
SDValue LowerReturn(SDValue Chain, CallingConv::ID CallConv, bool isVarArg, const SmallVectorImpl< ISD::OutputArg > &Outs, const SmallVectorImpl< SDValue > &OutVals, const SDLoc &dl, SelectionDAG &DAG) const override
This hook must be implemented to lower outgoing return values, described by the Outs array,...
SDValue LowerFormalArguments(SDValue Chain, CallingConv::ID CallConv, bool isVarArg, const SmallVectorImpl< ISD::InputArg > &Ins, const SDLoc &dl, SelectionDAG &DAG, SmallVectorImpl< SDValue > &InVals) const override
This hook must be implemented to lower the incoming (formal) arguments, described by the Ins array,...
AtomicExpansionKind shouldCastAtomicLoadInIR(LoadInst *LI) const override
Returns how the given (atomic) load should be cast by the IR-level AtomicExpand pass.
AtomicExpansionKind shouldCastAtomicStoreInIR(StoreInst *SI) const override
Returns how the given (atomic) store should be cast by the IR-level AtomicExpand pass into.
void LowerAsmOperandForConstraint(SDValue Op, StringRef Constraint, std::vector< SDValue > &Ops, SelectionDAG &DAG) const override
Lower the specified operand into the Ops vector.
SDValue LowerSTACKRESTORE(SDValue Op, SelectionDAG &DAG) const
bool aggressivelyPreferBuildVectorSources(EVT VecVT) const override
Instruction * emitTrailingFence(IRBuilderBase &Builder, Instruction *Inst, AtomicOrdering Ord) const override
bool isTruncateFree(Type *SrcTy, Type *DstTy) const override
Return true if it's free to truncate a value of type FromTy to type ToTy.
TargetLoweringBase::LegalizeTypeAction getPreferredVectorAction(MVT VT) const override
Return the preferred vector type legalization action.
NVPTX::DivPrecisionLevel getDivF32Level(const MachineFunction &MF, const SDNode &N) const
bool shouldInsertFencesForAtomic(const Instruction *) const override
Whether AtomicExpandPass should automatically insert fences and reduce ordering for this atomic.
SDValue LowerDYNAMIC_STACKALLOC(SDValue Op, SelectionDAG &DAG) const
MVT getScalarShiftAmountTy(const DataLayout &, EVT) const override
Return the type to use for a scalar shift opcode, given the shifted amount type.
EVT getSetCCResultType(const DataLayout &DL, LLVMContext &Ctx, EVT VT) const override
Return the ValueType of the result of SETCC operations.
std::pair< unsigned, const TargetRegisterClass * > getRegForInlineAsmConstraint(const TargetRegisterInfo *TRI, StringRef Constraint, MVT VT) const override
Given a physical register constraint (e.g.
bool isLegalAddressingMode(const DataLayout &DL, const AddrMode &AM, Type *Ty, unsigned AS, Instruction *I=nullptr) const override
isLegalAddressingMode - Return true if the addressing mode represented by AM is legal for this target...
Instruction * emitLeadingFence(IRBuilderBase &Builder, Instruction *Inst, AtomicOrdering Ord) const override
Inserts in the IR a target-specific intrinsic specifying a fence.
bool isCheapToSpeculateCtlz(Type *Ty) const override
Return true if it is cheap to speculate a call to intrinsic ctlz.
void getTgtMemIntrinsic(SmallVectorImpl< IntrinsicInfo > &Infos, const CallBase &I, MachineFunction &MF, unsigned Intrinsic) const override
Given an intrinsic, checks if on the target the intrinsic will need to map to a MemIntrinsicNode (tou...
bool isShuffleMaskLegal(ArrayRef< int >, EVT VT) const override
Targets can use this to indicate that they only support some VECTOR_SHUFFLE operations,...
bool allowFMA(MachineFunction &MF, CodeGenOptLevel OptLevel) const
bool usePrecSqrtF32(const SDNode *N=nullptr) const
unsigned getJumpTableEncoding() const override
Return the entry encoding for a jump table in the current function.
bool isFMAFasterThanFMulAndFAdd(const MachineFunction &MF, EVT) const override
Return true if an FMA operation is faster than a pair of fmul and fadd instructions.
SDValue LowerCall(CallLoweringInfo &CLI, SmallVectorImpl< SDValue > &InVals) const override
This hook must be implemented to lower calls into the specified DAG.
void computeKnownBitsForTargetNode(const SDValue Op, KnownBits &Known, const APInt &DemandedElts, const SelectionDAG &DAG, unsigned Depth=0) const override
Determine which of the bits specified in Mask are known to be either zero or one and return them in t...
std::string getParamName(const Function *F, unsigned Idx) const
Wrapper class for IR location info (IR ordering and DebugLoc) to be passed into SDNode creation funct...
Represents one node in the SelectionDAG.
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...
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
An instruction for storing to memory.
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
LegalizeTypeAction
This enum indicates whether a types are legal for a target, and if not, what action should be used to...
bool isTypeLegal(EVT VT) const
Return true if the target has native support for the specified value type.
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...
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
LLVM_ABI TypeSize getPrimitiveSizeInBits() const LLVM_READONLY
Return the basic size of this type if it is a primitive type.
Definition Type.cpp:197
bool isIntegerTy() const
True if this is an instance of IntegerType.
Definition Type.h:257
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition CallingConv.h:24
This namespace contains an enum with a value for every intrinsic/builtin function known by LLVM.
DivPrecisionLevel
Definition NVPTX.h:278
This is an optimization pass for GlobalISel generic memory operations.
CodeGenOptLevel
Code generation optimization level.
Definition CodeGen.h:82
AtomicOrdering
Atomic ordering for LLVM's memory model.
DWARFExpression::Operation Op
@ Enabled
Convert any .debug_str_offsets tables to DWARF64 if needed.
Definition DWP.h:31
#define N
Extended Value Type.
Definition ValueTypes.h:35
static EVT getVectorVT(LLVMContext &Context, EVT VT, unsigned NumElements, bool IsScalable=false)
Returns the EVT that represents a vector NumElements in length, where each element is of type VT.
Definition ValueTypes.h:70
bool isVector() const
Return true if this is a vector value type.
Definition ValueTypes.h:176
unsigned getVectorNumElements() const
Given a vector type, return the number of elements it contains.
Definition ValueTypes.h:359
This represents an addressing mode of: BaseGV + BaseOffs + BaseReg + Scale*ScaleReg + ScalableOffset*...