1 //===-- NVPTXUtilities - Utilities -----------------------------*- C++ -*-====//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file contains the declaration of the NVVM specific utility functions.
12 //===----------------------------------------------------------------------===//
14 #ifndef NVPTXUTILITIES_H
15 #define NVPTXUTILITIES_H
17 #include "llvm/IR/Function.h"
18 #include "llvm/IR/GlobalVariable.h"
19 #include "llvm/IR/IntrinsicInst.h"
20 #include "llvm/IR/Value.h"
28 #define NVCL_IMAGE2D_READONLY_FUNCNAME "__is_image2D_readonly"
29 #define NVCL_IMAGE3D_READONLY_FUNCNAME "__is_image3D_readonly"
31 bool findOneNVVMAnnotation(const llvm::GlobalValue *, std::string, unsigned &);
32 bool findAllNVVMAnnotation(const llvm::GlobalValue *, std::string,
33 std::vector<unsigned> &);
35 bool isTexture(const llvm::Value &);
36 bool isSurface(const llvm::Value &);
37 bool isSampler(const llvm::Value &);
38 bool isImage(const llvm::Value &);
39 bool isImageReadOnly(const llvm::Value &);
40 bool isImageWriteOnly(const llvm::Value &);
42 std::string getTextureName(const llvm::Value &);
43 std::string getSurfaceName(const llvm::Value &);
44 std::string getSamplerName(const llvm::Value &);
46 bool getMaxNTIDx(const llvm::Function &, unsigned &);
47 bool getMaxNTIDy(const llvm::Function &, unsigned &);
48 bool getMaxNTIDz(const llvm::Function &, unsigned &);
50 bool getReqNTIDx(const llvm::Function &, unsigned &);
51 bool getReqNTIDy(const llvm::Function &, unsigned &);
52 bool getReqNTIDz(const llvm::Function &, unsigned &);
54 bool getMinCTASm(const llvm::Function &, unsigned &);
55 bool isKernelFunction(const llvm::Function &);
57 bool getAlign(const llvm::Function &, unsigned index, unsigned &);
58 bool getAlign(const llvm::CallInst &, unsigned index, unsigned &);
60 bool isBarrierIntrinsic(llvm::Intrinsic::ID);
62 /// make_vector - Helper function which is useful for building temporary vectors
63 /// to pass into type construction of CallInst ctors. This turns a null
64 /// terminated list of pointers (or other value types) into a real live vector.
66 template <typename T> inline std::vector<T> make_vector(T A, ...) {
69 std::vector<T> Result;
71 while (T Val = va_arg(Args, T))
72 Result.push_back(Val);
77 bool isMemorySpaceTransferIntrinsic(Intrinsic::ID id);
78 const Value *skipPointerTransfer(const Value *V, bool ignore_GEP_indices);
80 skipPointerTransfer(const Value *V, std::set<const Value *> &processed);
81 BasicBlock *getParentBlock(Value *v);
82 Function *getParentFunction(Value *v);
83 void dumpBlock(Value *v, char *blockName);
84 Instruction *getInst(Value *base, char *instName);
85 void dumpInst(Value *base, char *instName);
86 void dumpInstRec(Value *v, std::set<Instruction *> *visited);
87 void dumpInstRec(Value *v);
88 void dumpParent(Value *v);