LLVM 21.0.0git
NVPTXUtilities.h
Go to the documentation of this file.
1//===-- NVPTXUtilities - Utilities -----------------------------*- 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 contains the declaration of the NVVM specific utility functions.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_LIB_TARGET_NVPTX_NVPTXUTILITIES_H
14#define LLVM_LIB_TARGET_NVPTX_NVPTXUTILITIES_H
15
16#include "NVPTX.h"
19#include "llvm/IR/CallingConv.h"
20#include "llvm/IR/Function.h"
23#include "llvm/IR/Value.h"
26#include <cstdarg>
27#include <set>
28#include <string>
29#include <vector>
30
31namespace llvm {
32
33class TargetMachine;
34
35void clearAnnotationCache(const Module *);
36
37bool isTexture(const Value &);
38bool isSurface(const Value &);
39bool isSampler(const Value &);
40bool isImage(const Value &);
41bool isImageReadOnly(const Value &);
42bool isImageWriteOnly(const Value &);
43bool isImageReadWrite(const Value &);
44bool isManaged(const Value &);
45
46StringRef getTextureName(const Value &);
47StringRef getSurfaceName(const Value &);
48StringRef getSamplerName(const Value &);
49
50std::optional<unsigned> getMaxNTIDx(const Function &);
51std::optional<unsigned> getMaxNTIDy(const Function &);
52std::optional<unsigned> getMaxNTIDz(const Function &);
53std::optional<unsigned> getMaxNTID(const Function &);
54
55std::optional<unsigned> getReqNTIDx(const Function &);
56std::optional<unsigned> getReqNTIDy(const Function &);
57std::optional<unsigned> getReqNTIDz(const Function &);
58std::optional<unsigned> getReqNTID(const Function &);
59
60std::optional<unsigned> getClusterDimx(const Function &);
61std::optional<unsigned> getClusterDimy(const Function &);
62std::optional<unsigned> getClusterDimz(const Function &);
63
64std::optional<unsigned> getMaxClusterRank(const Function &);
65std::optional<unsigned> getMinCTASm(const Function &);
66std::optional<unsigned> getMaxNReg(const Function &);
67
68inline bool isKernelFunction(const Function &F) {
69 return F.getCallingConv() == CallingConv::PTX_Kernel;
70}
71
72bool isParamGridConstant(const Value &);
73
74MaybeAlign getAlign(const Function &, unsigned);
75MaybeAlign getAlign(const CallInst &, unsigned);
76Function *getMaybeBitcastedCallee(const CallBase *CB);
77
78// PTX ABI requires all scalar argument/return values to have
79// bit-size as a power of two of at least 32 bits.
80inline unsigned promoteScalarArgumentSize(unsigned size) {
81 if (size <= 32)
82 return 32;
83 if (size <= 64)
84 return 64;
85 return size;
86}
87
88bool shouldEmitPTXNoReturn(const Value *V, const TargetMachine &TM);
89
90bool Isv2x16VT(EVT VT);
91
92namespace NVPTX {
94 std::string ValidName;
95 ValidName.reserve(Name.size() + 4);
96 for (char C : Name)
97 // While PTX also allows '%' at the start of identifiers, LLVM will throw a
98 // fatal error for '%' in symbol names in MCSymbol::print. Exclude for now.
99 if (isAlnum(C) || C == '_' || C == '$')
100 ValidName.push_back(C);
101 else
102 ValidName.append({'_', '$', '_'});
103
104 return ValidName;
105}
106
107inline std::string OrderingToString(Ordering Order) {
108 switch (Order) {
110 return "NotAtomic";
112 return "Relaxed";
114 return "Acquire";
116 return "Release";
118 return "AcquireRelease";
120 return "SequentiallyConsistent";
122 return "Volatile";
124 return "RelaxedMMIO";
125 }
126 report_fatal_error(formatv("Unknown NVPTX::Ordering \"{}\".",
127 static_cast<OrderingUnderlyingType>(Order)));
128}
129
131 O << OrderingToString(Order);
132 return O;
133}
134
135inline std::string ScopeToString(Scope S) {
136 switch (S) {
137 case Scope::Thread:
138 return "Thread";
139 case Scope::System:
140 return "System";
141 case Scope::Block:
142 return "Block";
143 case Scope::Cluster:
144 return "Cluster";
145 case Scope::Device:
146 return "Device";
147 }
148 report_fatal_error(formatv("Unknown NVPTX::Scope \"{}\".",
149 static_cast<ScopeUnderlyingType>(S)));
150}
151
153 O << ScopeToString(S);
154 return O;
155}
156
158 switch (A) {
160 return "generic";
162 return "global";
164 return "const";
166 return "shared";
168 return "param";
170 return "local";
171 }
172 report_fatal_error(formatv("Unknown NVPTX::AddressSpace \"{}\".",
173 static_cast<AddressSpaceUnderlyingType>(A)));
174}
175
178 return O;
179}
180
181} // namespace NVPTX
182} // namespace llvm
183
184#endif
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
std::string Name
#define F(x, y, z)
Definition: MD5.cpp:55
Machine Check Debug Module
This file contains some functions that are useful when dealing with strings.
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:51
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
@ PTX_Kernel
Call to a PTX kernel. Passes all arguments in parameter space.
Definition: CallingConv.h:125
@ C
The default llvm calling convention, compatible with C.
Definition: CallingConv.h:34
raw_ostream & operator<<(raw_ostream &O, Ordering Order)
std::string ScopeToString(Scope S)
AddressSpace
Definition: NVPTX.h:143
@ Global
Definition: NVPTX.h:145
@ Shared
Definition: NVPTX.h:146
@ Generic
Definition: NVPTX.h:144
unsigned int AddressSpaceUnderlyingType
Definition: NVPTX.h:142
std::string OrderingToString(Ordering Order)
unsigned int OrderingUnderlyingType
Definition: NVPTX.h:115
unsigned int ScopeUnderlyingType
Definition: NVPTX.h:132
@ System
Definition: NVPTX.h:138
@ Cluster
Definition: NVPTX.h:136
@ Thread
Definition: NVPTX.h:134
@ Device
Definition: NVPTX.h:137
std::string AddressSpaceToString(AddressSpace A)
@ RelaxedMMIO
Definition: NVPTX.h:128
@ Acquire
Definition: NVPTX.h:122
@ Relaxed
Definition: NVPTX.h:120
@ AcquireRelease
Definition: NVPTX.h:124
@ NotAtomic
Definition: NVPTX.h:117
@ Volatile
Definition: NVPTX.h:127
@ Release
Definition: NVPTX.h:123
@ SequentiallyConsistent
Definition: NVPTX.h:125
std::string getValidPTXIdentifier(StringRef Name)
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
bool isManaged(const Value &V)
bool shouldEmitPTXNoReturn(const Value *V, const TargetMachine &TM)
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
Definition: STLExtras.h:1697
std::optional< unsigned > getMaxNReg(const Function &F)
bool Isv2x16VT(EVT VT)
std::optional< unsigned > getMaxNTIDy(const Function &F)
bool isParamGridConstant(const Value &V)
StringRef getSamplerName(const Value &V)
bool isImageReadWrite(const Value &V)
bool isImageReadOnly(const Value &V)
std::optional< unsigned > getMaxNTIDz(const Function &F)
MaybeAlign getAlign(const Function &F, unsigned Index)
std::optional< unsigned > getMaxNTIDx(const Function &F)
std::optional< unsigned > getMinCTASm(const Function &F)
auto formatv(bool Validate, const char *Fmt, Ts &&...Vals)
bool isImage(const Value &V)
bool isSampler(const Value &V)
unsigned promoteScalarArgumentSize(unsigned size)
void clearAnnotationCache(const Module *Mod)
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition: Error.cpp:167
std::optional< unsigned > getReqNTIDy(const Function &F)
bool isSurface(const Value &V)
std::optional< unsigned > getMaxClusterRank(const Function &F)
StringRef getTextureName(const Value &V)
std::optional< unsigned > getClusterDimx(const Function &F)
StringRef getSurfaceName(const Value &V)
std::optional< unsigned > getClusterDimy(const Function &F)
bool isKernelFunction(const Function &F)
bool isTexture(const Value &V)
Function * getMaybeBitcastedCallee(const CallBase *CB)
bool isImageWriteOnly(const Value &V)
std::optional< unsigned > getReqNTIDz(const Function &F)
std::optional< unsigned > getReqNTIDx(const Function &F)
std::optional< unsigned > getClusterDimz(const Function &F)
std::optional< unsigned > getReqNTID(const Function &F)
std::optional< unsigned > getMaxNTID(const Function &F)