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 "llvm/IR/Function.h"
17 #include "llvm/IR/GlobalVariable.h"
18 #include "llvm/IR/IntrinsicInst.h"
19 #include "llvm/IR/Value.h"
20 #include <cstdarg>
21 #include <set>
22 #include <string>
23 #include <vector>
24 
25 namespace llvm {
26 
27 class TargetMachine;
28 
29 void clearAnnotationCache(const Module *);
30 
31 bool findOneNVVMAnnotation(const GlobalValue *, const std::string &,
32                            unsigned &);
33 bool findAllNVVMAnnotation(const GlobalValue *, const std::string &,
34                            std::vector<unsigned> &);
35 
36 bool isTexture(const Value &);
37 bool isSurface(const Value &);
38 bool isSampler(const Value &);
39 bool isImage(const Value &);
40 bool isImageReadOnly(const Value &);
41 bool isImageWriteOnly(const Value &);
42 bool isImageReadWrite(const Value &);
43 bool isManaged(const Value &);
44 
45 std::string getTextureName(const Value &);
46 std::string getSurfaceName(const Value &);
47 std::string getSamplerName(const Value &);
48 
49 bool getMaxNTIDx(const Function &, unsigned &);
50 bool getMaxNTIDy(const Function &, unsigned &);
51 bool getMaxNTIDz(const Function &, unsigned &);
52 
53 bool getReqNTIDx(const Function &, unsigned &);
54 bool getReqNTIDy(const Function &, unsigned &);
55 bool getReqNTIDz(const Function &, unsigned &);
56 
57 bool getMinCTASm(const Function &, unsigned &);
58 bool getMaxNReg(const Function &, unsigned &);
59 bool isKernelFunction(const Function &);
60 
61 bool getAlign(const Function &, unsigned index, unsigned &);
62 bool getAlign(const CallInst &, unsigned index, unsigned &);
63 Function *getMaybeBitcastedCallee(const CallBase *CB);
64 
65 // PTX ABI requires all scalar argument/return values to have
66 // bit-size as a power of two of at least 32 bits.
67 inline unsigned promoteScalarArgumentSize(unsigned size) {
68   if (size <= 32)
69     return 32;
70   else if (size <= 64)
71     return 64;
72   else
73     return size;
74 }
75 
76 bool shouldEmitPTXNoReturn(const Value *V, const TargetMachine &TM);
77 }
78 
79 #endif
80