1//===-- NVPTXUtilities - Utilities -----------------------------*- C++ -*-====// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9// 10// This file contains the declaration of the NVVM specific utility functions. 11// 12//===----------------------------------------------------------------------===// 13 14#ifndef NVPTXUTILITIES_H 15#define NVPTXUTILITIES_H 16 17#include "llvm/IR/Function.h" 18#include "llvm/IR/GlobalVariable.h" 19#include "llvm/IR/IntrinsicInst.h" 20#include "llvm/IR/Value.h" 21#include <cstdarg> 22#include <set> 23#include <string> 24#include <vector> 25 26namespace llvm { 27 28#define NVCL_IMAGE2D_READONLY_FUNCNAME "__is_image2D_readonly" 29#define NVCL_IMAGE3D_READONLY_FUNCNAME "__is_image3D_readonly" 30 31bool findOneNVVMAnnotation(const llvm::GlobalValue *, std::string, unsigned &); 32bool findAllNVVMAnnotation(const llvm::GlobalValue *, std::string, 33 std::vector<unsigned> &); 34 35bool isTexture(const llvm::Value &); 36bool isSurface(const llvm::Value &); 37bool isSampler(const llvm::Value &); 38bool isImage(const llvm::Value &); 39bool isImageReadOnly(const llvm::Value &); 40bool isImageWriteOnly(const llvm::Value &); 41 42std::string getTextureName(const llvm::Value &); 43std::string getSurfaceName(const llvm::Value &); 44std::string getSamplerName(const llvm::Value &); 45 46bool getMaxNTIDx(const llvm::Function &, unsigned &); 47bool getMaxNTIDy(const llvm::Function &, unsigned &); 48bool getMaxNTIDz(const llvm::Function &, unsigned &); 49 50bool getReqNTIDx(const llvm::Function &, unsigned &); 51bool getReqNTIDy(const llvm::Function &, unsigned &); 52bool getReqNTIDz(const llvm::Function &, unsigned &); 53 54bool getMinCTASm(const llvm::Function &, unsigned &); 55bool isKernelFunction(const llvm::Function &); 56 57bool getAlign(const llvm::Function &, unsigned index, unsigned &); 58bool getAlign(const llvm::CallInst &, unsigned index, unsigned &); 59 60bool isBarrierIntrinsic(llvm::Intrinsic::ID); 61 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. 65/// 66template <typename T> inline std::vector<T> make_vector(T A, ...) { 67 va_list Args; 68 va_start(Args, A); 69 std::vector<T> Result; 70 Result.push_back(A); 71 while (T Val = va_arg(Args, T)) 72 Result.push_back(Val); 73 va_end(Args); 74 return Result; 75} 76 77bool isMemorySpaceTransferIntrinsic(Intrinsic::ID id); 78const Value *skipPointerTransfer(const Value *V, bool ignore_GEP_indices); 79const Value * 80skipPointerTransfer(const Value *V, std::set<const Value *> &processed); 81BasicBlock *getParentBlock(Value *v); 82Function *getParentFunction(Value *v); 83void dumpBlock(Value *v, char *blockName); 84Instruction *getInst(Value *base, char *instName); 85void dumpInst(Value *base, char *instName); 86void dumpInstRec(Value *v, std::set<Instruction *> *visited); 87void dumpInstRec(Value *v); 88void dumpParent(Value *v); 89 90} 91 92#endif 93