LLVM  8.0.1
NVPTXISelLowering.h
Go to the documentation of this file.
1 //===-- NVPTXISelLowering.h - NVPTX DAG Lowering Interface ------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines the interfaces that NVPTX uses to lower LLVM code into a
11 // selection DAG.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #ifndef LLVM_LIB_TARGET_NVPTX_NVPTXISELLOWERING_H
16 #define LLVM_LIB_TARGET_NVPTX_NVPTXISELLOWERING_H
17 
18 #include "NVPTX.h"
21 
22 namespace llvm {
23 namespace NVPTXISD {
24 enum NodeType : unsigned {
25  // Start the numbering from where ISD NodeType finishes.
62 
65  LDGV2, // LDG.v2
66  LDGV4, // LDG.v4
67  LDUV2, // LDU.v2
68  LDUV4, // LDU.v4
77  StoreParamS32, // to sext and store a <32bit value, not used currently
78  StoreParamU32, // to zext and store a <32bit value, not used currently
82 
83  // Texture intrinsics
252 
253  // Surface intrinsics
265 
277 
289 
301 
313 
325 
337 
349 
361 
373 
385 
397 
409 
421 
433 };
434 }
435 
436 class NVPTXSubtarget;
437 
438 //===--------------------------------------------------------------------===//
439 // TargetLowering Implementation
440 //===--------------------------------------------------------------------===//
442 public:
443  explicit NVPTXTargetLowering(const NVPTXTargetMachine &TM,
444  const NVPTXSubtarget &STI);
445  SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const override;
446 
447  SDValue LowerGlobalAddress(SDValue Op, SelectionDAG &DAG) const;
448 
449  const char *getTargetNodeName(unsigned Opcode) const override;
450 
451  bool getTgtMemIntrinsic(IntrinsicInfo &Info, const CallInst &I,
452  MachineFunction &MF,
453  unsigned Intrinsic) const override;
454 
455  /// isLegalAddressingMode - Return true if the addressing mode represented
456  /// by AM is legal for this target, for a load/store of the specified type
457  /// Used to guide target specific optimizations, like loop strength
458  /// reduction (LoopStrengthReduce.cpp) and memory optimization for
459  /// address mode (CodeGenPrepare.cpp)
460  bool isLegalAddressingMode(const DataLayout &DL, const AddrMode &AM, Type *Ty,
461  unsigned AS,
462  Instruction *I = nullptr) const override;
463 
464  bool isTruncateFree(Type *SrcTy, Type *DstTy) const override {
465  // Truncating 64-bit to 32-bit is free in SASS.
466  if (!SrcTy->isIntegerTy() || !DstTy->isIntegerTy())
467  return false;
468  return SrcTy->getPrimitiveSizeInBits() == 64 &&
469  DstTy->getPrimitiveSizeInBits() == 32;
470  }
471 
473  EVT VT) const override {
474  if (VT.isVector())
475  return EVT::getVectorVT(Ctx, MVT::i1, VT.getVectorNumElements());
476  return MVT::i1;
477  }
478 
479  ConstraintType getConstraintType(StringRef Constraint) const override;
480  std::pair<unsigned, const TargetRegisterClass *>
481  getRegForInlineAsmConstraint(const TargetRegisterInfo *TRI,
482  StringRef Constraint, MVT VT) const override;
483 
484  SDValue LowerFormalArguments(SDValue Chain, CallingConv::ID CallConv,
485  bool isVarArg,
487  const SDLoc &dl, SelectionDAG &DAG,
488  SmallVectorImpl<SDValue> &InVals) const override;
489 
490  SDValue LowerCall(CallLoweringInfo &CLI,
491  SmallVectorImpl<SDValue> &InVals) const override;
492 
493  std::string getPrototype(const DataLayout &DL, Type *, const ArgListTy &,
495  unsigned retAlignment,
496  ImmutableCallSite CS) const;
497 
498  SDValue LowerReturn(SDValue Chain, CallingConv::ID CallConv, bool isVarArg,
500  const SmallVectorImpl<SDValue> &OutVals, const SDLoc &dl,
501  SelectionDAG &DAG) const override;
502 
503  void LowerAsmOperandForConstraint(SDValue Op, std::string &Constraint,
504  std::vector<SDValue> &Ops,
505  SelectionDAG &DAG) const override;
506 
508 
509  // PTX always uses 32-bit shift amounts
510  MVT getScalarShiftAmountTy(const DataLayout &, EVT) const override {
511  return MVT::i32;
512  }
513 
515  getPreferredVectorAction(MVT VT) const override;
516 
517  // Get the degree of precision we want from 32-bit floating point division
518  // operations.
519  //
520  // 0 - Use ptx div.approx
521  // 1 - Use ptx.div.full (approximate, but less so than div.approx)
522  // 2 - Use IEEE-compliant div instructions, if available.
523  int getDivF32Level() const;
524 
525  // Get whether we should use a precise or approximate 32-bit floating point
526  // sqrt instruction.
527  bool usePrecSqrtF32() const;
528 
529  // Get whether we should use instructions that flush floating-point denormals
530  // to sign-preserving zero.
531  bool useF32FTZ(const MachineFunction &MF) const;
532 
533  SDValue getSqrtEstimate(SDValue Operand, SelectionDAG &DAG, int Enabled,
534  int &ExtraSteps, bool &UseOneConst,
535  bool Reciprocal) const override;
536 
537  unsigned combineRepeatedFPDivisors() const override { return 2; }
538 
539  bool allowFMA(MachineFunction &MF, CodeGenOpt::Level OptLevel) const;
540  bool allowUnsafeFPMath(MachineFunction &MF) const;
541 
542  bool isFMAFasterThanFMulAndFAdd(EVT) const override { return true; }
543 
544  bool enableAggressiveFMAFusion(EVT VT) const override { return true; }
545 
546  // The default is to transform llvm.ctlz(x, false) (where false indicates that
547  // x == 0 is not undefined behavior) into a branch that checks whether x is 0
548  // and avoids calling ctlz in that case. We have a dedicated ctlz
549  // instruction, so we say that ctlz is cheap to speculate.
550  bool isCheapToSpeculateCtlz() const override { return true; }
551 
552 private:
553  const NVPTXSubtarget &STI; // cache the subtarget here
554  SDValue getParamSymbol(SelectionDAG &DAG, int idx, EVT) const;
555 
556  SDValue LowerBUILD_VECTOR(SDValue Op, SelectionDAG &DAG) const;
559 
560  SDValue LowerLOAD(SDValue Op, SelectionDAG &DAG) const;
561  SDValue LowerLOADi1(SDValue Op, SelectionDAG &DAG) const;
562 
563  SDValue LowerSTORE(SDValue Op, SelectionDAG &DAG) const;
564  SDValue LowerSTOREi1(SDValue Op, SelectionDAG &DAG) const;
565  SDValue LowerSTOREVector(SDValue Op, SelectionDAG &DAG) const;
566 
567  SDValue LowerShiftRightParts(SDValue Op, SelectionDAG &DAG) const;
568  SDValue LowerShiftLeftParts(SDValue Op, SelectionDAG &DAG) const;
569 
570  SDValue LowerSelect(SDValue Op, SelectionDAG &DAG) const;
571 
572  void ReplaceNodeResults(SDNode *N, SmallVectorImpl<SDValue> &Results,
573  SelectionDAG &DAG) const override;
574  SDValue PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const override;
575 
576  unsigned getArgumentAlignment(SDValue Callee, ImmutableCallSite CS, Type *Ty,
577  unsigned Idx, const DataLayout &DL) const;
578 };
579 } // namespace llvm
580 
581 #endif
static SDValue LowerEXTRACT_VECTOR_ELT(SDValue Op, SelectionDAG &DAG)
unsigned combineRepeatedFPDivisors() const override
Indicate whether this target prefers to combine FDIVs with the same divisor.
BUILTIN_OP_END - This must be the last enum value in this list.
Definition: ISDOpcodes.h:877
A parsed version of the target data layout string in and methods for querying it. ...
Definition: DataLayout.h:111
This represents an addressing mode of: BaseGV + BaseOffs + BaseReg + Scale*ScaleReg If BaseGV is null...
This class represents lattice values for constants.
Definition: AllocatorList.h:24
bool isFMAFasterThanFMulAndFAdd(EVT) const override
Return true if an FMA operation is faster than a pair of fmul and fadd instructions.
EVT getSetCCResultType(const DataLayout &DL, LLVMContext &Ctx, EVT VT) const override
Return the ValueType of the result of SETCC operations.
bool isCheapToSpeculateCtlz() const override
Return true if it is cheap to speculate a call to intrinsic ctlz.
This class represents a function call, abstracting a target machine&#39;s calling convention.
Function Alias Analysis Results
bool enableAggressiveFMAFusion(EVT VT) const override
Return true if target always beneficiates from combining into FMA for a given value type...
unsigned const TargetRegisterInfo * TRI
static SDValue LowerCONCAT_VECTORS(SDValue Op, SelectionDAG &DAG)
MVT getScalarShiftAmountTy(const DataLayout &, EVT) const override
EVT is not used in-tree, but is used by out-of-tree target.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: APFloat.h:42
bool isIntegerTy() const
True if this is an instance of IntegerType.
Definition: Type.h:197
This class defines information used to lower LLVM code to legal SelectionDAG operators that the targe...
amdgpu Simplify well known AMD library false Value * Callee
Analysis containing CSE Info
Definition: CSEInfo.cpp:21
static SDValue LowerSTORE(SDValue Op, SelectionDAG &DAG)
Machine Value Type.
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:46
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:69
unsigned getVectorNumElements() const
Given a vector type, return the number of elements it contains.
Definition: ValueTypes.h:273
std::vector< ArgListEntry > ArgListTy
Extended Value Type.
Definition: ValueTypes.h:34
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
This structure contains all information that is necessary for lowering calls.
This is used to represent a portion of an LLVM function in a low-level Data Dependence DAG representa...
Definition: SelectionDAG.h:222
Wrapper class for IR location info (IR ordering and DebugLoc) to be passed into SDNode creation funct...
static const int FIRST_TARGET_MEMORY_OPCODE
FIRST_TARGET_MEMORY_OPCODE - Target-specific pre-isel operations which do not reference a specific me...
Definition: ISDOpcodes.h:884
Represents one node in the SelectionDAG.
static bool Enabled
Definition: Statistic.cpp:51
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:73
NVPTXTargetMachine.
bool isVector() const
Return true if this is a vector value type.
Definition: ValueTypes.h:151
Establish a view to a call site for examination.
Definition: CallSite.h:711
#define I(x, y, z)
Definition: MD5.cpp:58
#define N
LegalizeTypeAction
This enum indicates whether a types are legal for a target, and if not, what action should be used to...
unsigned getPrimitiveSizeInBits() const LLVM_READONLY
Return the basic size of this type if it is a primitive type.
Definition: Type.cpp:115
static SDValue LowerLOAD(SDValue Op, SelectionDAG &DAG)
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
Unlike LLVM values, Selection DAG nodes may return multiple values as the result of a computation...
This file describes how to lower LLVM code to machine code.
bool isTruncateFree(Type *SrcTy, Type *DstTy) const override
Return true if it&#39;s free to truncate a value of type FromTy to type ToTy.
const NVPTXTargetMachine * nvTM