LLVM 20.0.0git
NVPTXSubtarget.cpp
Go to the documentation of this file.
1//===- NVPTXSubtarget.cpp - NVPTX Subtarget Information -------------------===//
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 implements the NVPTX specific subclass of TargetSubtarget.
10//
11//===----------------------------------------------------------------------===//
12
13#include "NVPTXSubtarget.h"
15#include "NVPTXTargetMachine.h"
18
19using namespace llvm;
20
21#define DEBUG_TYPE "nvptx-subtarget"
22
23#define GET_SUBTARGETINFO_ENUM
24#define GET_SUBTARGETINFO_TARGET_DESC
25#define GET_SUBTARGETINFO_CTOR
26#include "NVPTXGenSubtargetInfo.inc"
27
28static cl::opt<bool>
29 NoF16Math("nvptx-no-f16-math", cl::Hidden,
30 cl::desc("NVPTX Specific: Disable generation of f16 math ops."),
31 cl::init(false));
32// Pin the vtable to this file.
33void NVPTXSubtarget::anchor() {}
34
36 StringRef FS) {
37 TargetName = std::string(CPU);
38
40
41 // Re-map SM version numbers, SmVersion carries the regular SMs which do
42 // have relative order, while FullSmVersion allows distinguishing sm_90 from
43 // sm_90a, which would *not* be a subset of sm_91.
44 SmVersion = getSmVersion();
45
46 // Set default to PTX 6.0 (CUDA 9.0)
47 if (PTXVersion == 0) {
48 PTXVersion = 60;
49 }
50
51 return *this;
52}
53
54NVPTXSubtarget::NVPTXSubtarget(const Triple &TT, const std::string &CPU,
55 const std::string &FS,
56 const NVPTXTargetMachine &TM)
57 : NVPTXGenSubtargetInfo(TT, CPU, /*TuneCPU*/ CPU, FS), PTXVersion(0),
58 FullSmVersion(200), SmVersion(getSmVersion()),
59 TLInfo(TM, initializeSubtargetDependencies(CPU, FS)) {
60 TSInfo = std::make_unique<NVPTXSelectionDAGInfo>();
61}
62
64
66 return TSInfo.get();
67}
68
70 return hasFP16Math() && NoF16Math == false;
71}
72
74 if (!hasBF16Math())
75 return false;
76
77 switch (Opcode) {
78 // Several BF16 instructions are available on sm_90 only.
79 case ISD::FADD:
80 case ISD::FMUL:
81 case ISD::FSUB:
82 case ISD::SELECT:
83 case ISD::SELECT_CC:
84 case ISD::SETCC:
85 case ISD::FEXP2:
86 case ISD::FCEIL:
87 case ISD::FFLOOR:
88 case ISD::FNEARBYINT:
89 case ISD::FRINT:
90 case ISD::FROUNDEVEN:
91 case ISD::FTRUNC:
92 return getSmVersion() >= 90 && getPTXVersion() >= 78;
93 // Several BF16 instructions are available on sm_80 only.
94 case ISD::FMINNUM:
95 case ISD::FMAXNUM:
98 case ISD::FMAXIMUM:
99 case ISD::FMINIMUM:
100 return getSmVersion() >= 80 && getPTXVersion() >= 70;
101 }
102 return true;
103}
104
106 std::string const &FailureMessage) const {
107 if (hasClusters())
108 return;
109
111 "NVPTX SM architecture \"{}\" and PTX version \"{}\" do not support {}. "
112 "Requires SM >= 90 and PTX >= 78.",
113 getFullSmVersion(), PTXVersion, FailureMessage));
114}
static cl::opt< bool > NoF16Math("nvptx-no-f16-math", cl::Hidden, cl::desc("NVPTX Specific: Disable generation of f16 math ops."), cl::init(false))
unsigned SmVersion
Definition: NVVMReflect.cpp:79
void failIfClustersUnsupported(std::string const &FailureMessage) const
std::string getTargetName() const
bool hasClusters() const
void ParseSubtargetFeatures(StringRef CPU, StringRef TuneCPU, StringRef FS)
unsigned getPTXVersion() const
~NVPTXSubtarget() override
bool hasNativeBF16Support(int Opcode) const
unsigned int getFullSmVersion() const
unsigned int getSmVersion() const
bool hasBF16Math() const
bool allowFP16Math() const
NVPTXSubtarget(const Triple &TT, const std::string &CPU, const std::string &FS, const NVPTXTargetMachine &TM)
This constructor initializes the data members to match that of the specified module.
NVPTXSubtarget & initializeSubtargetDependencies(StringRef CPU, StringRef FS)
const SelectionDAGTargetInfo * getSelectionDAGInfo() const override
bool hasFP16Math() const
Targets can subclass this to parameterize the SelectionDAG lowering and instruction selection process...
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:51
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
@ SETCC
SetCC operator - This evaluates to a true value iff the condition is true.
Definition: ISDOpcodes.h:780
@ FADD
Simple binary floating point operators.
Definition: ISDOpcodes.h:397
@ SELECT
Select(COND, TRUEVAL, FALSEVAL).
Definition: ISDOpcodes.h:757
@ FMINNUM_IEEE
FMINNUM_IEEE/FMAXNUM_IEEE - Perform floating-point minimumNumber or maximumNumber on two values,...
Definition: ISDOpcodes.h:1044
@ SELECT_CC
Select with condition operator - This selects between a true value and a false value (ops #2 and #3) ...
Definition: ISDOpcodes.h:772
@ FMINNUM
FMINNUM/FMAXNUM - Perform floating-point minimum or maximum on two values.
Definition: ISDOpcodes.h:1031
@ FMINIMUM
FMINIMUM/FMAXIMUM - NaN-propagating minimum/maximum that also treat -0.0 as less than 0....
Definition: ISDOpcodes.h:1050
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:443
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
auto formatv(bool Validate, const char *Fmt, Ts &&...Vals)
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition: Error.cpp:167