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 // Provide the default CPU if we don't have one.
38 TargetName = std::string(CPU.empty() ? "sm_30" : CPU);
39
40 ParseSubtargetFeatures(TargetName, /*TuneCPU*/ TargetName, FS);
41
42 // Re-map SM version numbers, SmVersion carries the regular SMs which do
43 // have relative order, while FullSmVersion allows distinguishing sm_90 from
44 // sm_90a, which would *not* be a subset of sm_91.
45 SmVersion = getSmVersion();
46
47 // Set default to PTX 6.0 (CUDA 9.0)
48 if (PTXVersion == 0) {
49 PTXVersion = 60;
50 }
51
52 return *this;
53}
54
55NVPTXSubtarget::NVPTXSubtarget(const Triple &TT, const std::string &CPU,
56 const std::string &FS,
57 const NVPTXTargetMachine &TM)
58 : NVPTXGenSubtargetInfo(TT, CPU, /*TuneCPU*/ CPU, FS), PTXVersion(0),
59 FullSmVersion(200), SmVersion(getSmVersion()),
60 TLInfo(TM, initializeSubtargetDependencies(CPU, FS)) {
61 TSInfo = std::make_unique<NVPTXSelectionDAGInfo>();
62}
63
65
67 return TSInfo.get();
68}
69
71 return hasFP16Math() && NoF16Math == false;
72}
73
75 std::string const &FailureMessage) const {
76 if (hasClusters())
77 return;
78
80 "NVPTX SM architecture \"{}\" and PTX version \"{}\" do not support {}. "
81 "Requires SM >= 90 and PTX >= 78.",
82 getFullSmVersion(), PTXVersion, FailureMessage));
83}
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:78
void failIfClustersUnsupported(std::string const &FailureMessage) const
bool hasClusters() const
void ParseSubtargetFeatures(StringRef CPU, StringRef TuneCPU, StringRef FS)
~NVPTXSubtarget() override
unsigned int getFullSmVersion() const
unsigned int getSmVersion() 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
constexpr bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:147
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
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