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"
18#include "llvm/IR/Function.h"
21#include "llvm/IR/Value.h"
23#include <cstdarg>
24#include <set>
25#include <string>
26#include <vector>
27
28namespace llvm {
29
30class TargetMachine;
31
32void clearAnnotationCache(const Module *);
33
34bool findOneNVVMAnnotation(const GlobalValue *, const std::string &,
35 unsigned &);
36bool findAllNVVMAnnotation(const GlobalValue *, const std::string &,
37 std::vector<unsigned> &);
38
39bool isTexture(const Value &);
40bool isSurface(const Value &);
41bool isSampler(const Value &);
42bool isImage(const Value &);
43bool isImageReadOnly(const Value &);
44bool isImageWriteOnly(const Value &);
45bool isImageReadWrite(const Value &);
46bool isManaged(const Value &);
47
48std::string getTextureName(const Value &);
49std::string getSurfaceName(const Value &);
50std::string getSamplerName(const Value &);
51
52std::optional<unsigned> getMaxNTIDx(const Function &);
53std::optional<unsigned> getMaxNTIDy(const Function &);
54std::optional<unsigned> getMaxNTIDz(const Function &);
55std::optional<unsigned> getMaxNTID(const Function &F);
56
57std::optional<unsigned> getReqNTIDx(const Function &);
58std::optional<unsigned> getReqNTIDy(const Function &);
59std::optional<unsigned> getReqNTIDz(const Function &);
60std::optional<unsigned> getReqNTID(const Function &);
61
62bool getMaxClusterRank(const Function &, unsigned &);
63bool getMinCTASm(const Function &, unsigned &);
64bool getMaxNReg(const Function &, unsigned &);
65bool isKernelFunction(const Function &);
66bool isParamGridConstant(const Value &);
67
68MaybeAlign getAlign(const Function &, unsigned);
69MaybeAlign getAlign(const CallInst &, unsigned);
70Function *getMaybeBitcastedCallee(const CallBase *CB);
71
72// PTX ABI requires all scalar argument/return values to have
73// bit-size as a power of two of at least 32 bits.
74inline unsigned promoteScalarArgumentSize(unsigned size) {
75 if (size <= 32)
76 return 32;
77 else if (size <= 64)
78 return 64;
79 else
80 return size;
81}
82
83bool shouldEmitPTXNoReturn(const Value *V, const TargetMachine &TM);
84
85bool Isv2x16VT(EVT VT);
86
87namespace NVPTX {
88
89inline std::string OrderingToCString(Ordering Order) {
90 switch (Order) {
92 return "NotAtomic";
94 return "Relaxed";
96 return "Acquire";
98 return "Release";
99 // case Ordering::AcquireRelease: return "AcquireRelease";
101 return "SequentiallyConsistent";
103 return "Volatile";
105 return "RelaxedMMIO";
106 }
107 report_fatal_error("unknown ordering");
108}
109
111 O << OrderingToCString(Order);
112 return O;
113}
114
115} // namespace NVPTX
116} // namespace llvm
117
118#endif
#define F(x, y, z)
Definition: MD5.cpp:55
Machine Check Debug Module
const char LLVMTargetMachineRef TM
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
raw_ostream & operator<<(raw_ostream &O, Ordering Order)
std::string OrderingToCString(Ordering Order)
@ RelaxedMMIO
Definition: NVPTX.h:124
@ Acquire
Definition: NVPTX.h:118
@ Relaxed
Definition: NVPTX.h:116
@ NotAtomic
Definition: NVPTX.h:113
@ Volatile
Definition: NVPTX.h:123
@ Release
Definition: NVPTX.h:119
@ SequentiallyConsistent
Definition: NVPTX.h:121
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
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:1680
bool Isv2x16VT(EVT VT)
std::optional< unsigned > getMaxNTIDy(const Function &F)
std::string getSamplerName(const Value &val)
bool isParamGridConstant(const Value &V)
bool getMinCTASm(const Function &F, unsigned &x)
bool isImage(const Value &val)
std::optional< unsigned > getMaxNTIDz(const Function &F)
MaybeAlign getAlign(const Function &F, unsigned Index)
std::optional< unsigned > getMaxNTIDx(const Function &F)
bool isImageReadOnly(const Value &val)
bool isManaged(const Value &val)
unsigned promoteScalarArgumentSize(unsigned size)
bool isSurface(const Value &val)
bool findAllNVVMAnnotation(const GlobalValue *gv, const std::string &prop, std::vector< unsigned > &retval)
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::string getSurfaceName(const Value &val)
std::optional< unsigned > getReqNTIDy(const Function &F)
bool getMaxNReg(const Function &F, unsigned &x)
bool isTexture(const Value &val)
bool isImageWriteOnly(const Value &val)
bool isImageReadWrite(const Value &val)
std::string getTextureName(const Value &val)
bool isKernelFunction(const Function &F)
Function * getMaybeBitcastedCallee(const CallBase *CB)
bool findOneNVVMAnnotation(const GlobalValue *gv, const std::string &prop, unsigned &retval)
std::optional< unsigned > getReqNTIDz(const Function &F)
std::optional< unsigned > getReqNTIDx(const Function &F)
bool isSampler(const Value &val)
bool getMaxClusterRank(const Function &F, unsigned &x)
std::optional< unsigned > getReqNTID(const Function &F)
std::optional< unsigned > getMaxNTID(const Function &F)