LLVM 20.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/Function.h"
22#include "llvm/IR/Value.h"
25#include <cstdarg>
26#include <set>
27#include <string>
28#include <vector>
29
30namespace llvm {
31
32class TargetMachine;
33
34void clearAnnotationCache(const Module *);
35
36bool isTexture(const Value &);
37bool isSurface(const Value &);
38bool isSampler(const Value &);
39bool isImage(const Value &);
40bool isImageReadOnly(const Value &);
41bool isImageWriteOnly(const Value &);
42bool isImageReadWrite(const Value &);
43bool isManaged(const Value &);
44
45StringRef getTextureName(const Value &);
46StringRef getSurfaceName(const Value &);
47StringRef getSamplerName(const Value &);
48
49std::optional<unsigned> getMaxNTIDx(const Function &);
50std::optional<unsigned> getMaxNTIDy(const Function &);
51std::optional<unsigned> getMaxNTIDz(const Function &);
52std::optional<unsigned> getMaxNTID(const Function &);
53
54std::optional<unsigned> getReqNTIDx(const Function &);
55std::optional<unsigned> getReqNTIDy(const Function &);
56std::optional<unsigned> getReqNTIDz(const Function &);
57std::optional<unsigned> getReqNTID(const Function &);
58
59std::optional<unsigned> getClusterDimx(const Function &);
60std::optional<unsigned> getClusterDimy(const Function &);
61std::optional<unsigned> getClusterDimz(const Function &);
62
63std::optional<unsigned> getMaxClusterRank(const Function &);
64std::optional<unsigned> getMinCTASm(const Function &);
65std::optional<unsigned> getMaxNReg(const Function &);
66bool isKernelFunction(const Function &);
67bool isParamGridConstant(const Value &);
68
69MaybeAlign getAlign(const Function &, unsigned);
70MaybeAlign getAlign(const CallInst &, unsigned);
71Function *getMaybeBitcastedCallee(const CallBase *CB);
72
73// PTX ABI requires all scalar argument/return values to have
74// bit-size as a power of two of at least 32 bits.
75inline unsigned promoteScalarArgumentSize(unsigned size) {
76 if (size <= 32)
77 return 32;
78 if (size <= 64)
79 return 64;
80 return size;
81}
82
83bool shouldEmitPTXNoReturn(const Value *V, const TargetMachine &TM);
84
85bool Isv2x16VT(EVT VT);
86
87namespace NVPTX {
89 std::string ValidName;
90 ValidName.reserve(Name.size() + 4);
91 for (char C : Name)
92 // While PTX also allows '%' at the start of identifiers, LLVM will throw a
93 // fatal error for '%' in symbol names in MCSymbol::print. Exclude for now.
94 if (isAlnum(C) || C == '_' || C == '$')
95 ValidName.push_back(C);
96 else
97 ValidName.append({'_', '$', '_'});
98
99 return ValidName;
100}
101
102inline std::string OrderingToString(Ordering Order) {
103 switch (Order) {
105 return "NotAtomic";
107 return "Relaxed";
109 return "Acquire";
111 return "Release";
113 return "AcquireRelease";
115 return "SequentiallyConsistent";
117 return "Volatile";
119 return "RelaxedMMIO";
120 }
121 report_fatal_error(formatv("Unknown NVPTX::Ordering \"{}\".",
122 static_cast<OrderingUnderlyingType>(Order)));
123}
124
126 O << OrderingToString(Order);
127 return O;
128}
129
130inline std::string ScopeToString(Scope S) {
131 switch (S) {
132 case Scope::Thread:
133 return "Thread";
134 case Scope::System:
135 return "System";
136 case Scope::Block:
137 return "Block";
138 case Scope::Cluster:
139 return "Cluster";
140 case Scope::Device:
141 return "Device";
142 }
143 report_fatal_error(formatv("Unknown NVPTX::Scope \"{}\".",
144 static_cast<ScopeUnderlyingType>(S)));
145}
146
148 O << ScopeToString(S);
149 return O;
150}
151
153 switch (A) {
155 return "generic";
157 return "global";
159 return "const";
161 return "shared";
163 return "param";
165 return "local";
166 }
167 report_fatal_error(formatv("Unknown NVPTX::AddressSpace \"{}\".",
168 static_cast<AddressSpaceUnderlyingType>(A)));
169}
170
173 return O;
174}
175
176} // namespace NVPTX
177} // namespace llvm
178
179#endif
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
std::string Name
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
@ 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)