Justin Holewinski | 49683f3 | 2012-05-04 20:18:50 +0000 | [diff] [blame] | 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/Value.h" |
| 18 | #include "llvm/GlobalVariable.h" |
| 19 | #include "llvm/Function.h" |
| 20 | #include "llvm/IntrinsicInst.h" |
| 21 | #include <cstdarg> |
| 22 | #include <set> |
| 23 | #include <string> |
| 24 | #include <vector> |
| 25 | |
| 26 | namespace llvm |
| 27 | { |
| 28 | |
| 29 | #define NVCL_IMAGE2D_READONLY_FUNCNAME "__is_image2D_readonly" |
| 30 | #define NVCL_IMAGE3D_READONLY_FUNCNAME "__is_image3D_readonly" |
| 31 | |
| 32 | bool findOneNVVMAnnotation(const llvm::GlobalValue *, std::string, unsigned &); |
| 33 | bool findAllNVVMAnnotation(const llvm::GlobalValue *, std::string, |
| 34 | std::vector<unsigned> &); |
| 35 | |
| 36 | bool isTexture(const llvm::Value &); |
| 37 | bool isSurface(const llvm::Value &); |
| 38 | bool isSampler(const llvm::Value &); |
| 39 | bool isImage(const llvm::Value &); |
| 40 | bool isImageReadOnly(const llvm::Value &); |
| 41 | bool isImageWriteOnly(const llvm::Value &); |
| 42 | |
| 43 | std::string getTextureName(const llvm::Value &); |
| 44 | std::string getSurfaceName(const llvm::Value &); |
| 45 | std::string getSamplerName(const llvm::Value &); |
| 46 | |
| 47 | bool getMaxNTIDx(const llvm::Function &, unsigned &); |
| 48 | bool getMaxNTIDy(const llvm::Function &, unsigned &); |
| 49 | bool getMaxNTIDz(const llvm::Function &, unsigned &); |
| 50 | |
| 51 | bool getReqNTIDx(const llvm::Function &, unsigned &); |
| 52 | bool getReqNTIDy(const llvm::Function &, unsigned &); |
| 53 | bool getReqNTIDz(const llvm::Function &, unsigned &); |
| 54 | |
| 55 | bool getMinCTASm(const llvm::Function &, unsigned &); |
| 56 | bool isKernelFunction(const llvm::Function &); |
| 57 | |
| 58 | bool getAlign(const llvm::Function &, unsigned index, unsigned &); |
| 59 | bool getAlign(const llvm::CallInst &, unsigned index, unsigned &); |
| 60 | |
| 61 | bool isBarrierIntrinsic(llvm::Intrinsic::ID); |
| 62 | |
| 63 | /// make_vector - Helper function which is useful for building temporary vectors |
| 64 | /// to pass into type construction of CallInst ctors. This turns a null |
| 65 | /// terminated list of pointers (or other value types) into a real live vector. |
| 66 | /// |
| 67 | template<typename T> |
| 68 | inline std::vector<T> make_vector(T A, ...) { |
| 69 | va_list Args; |
| 70 | va_start(Args, A); |
| 71 | std::vector<T> Result; |
| 72 | Result.push_back(A); |
| 73 | while (T Val = va_arg(Args, T)) |
| 74 | Result.push_back(Val); |
| 75 | va_end(Args); |
| 76 | return Result; |
| 77 | } |
| 78 | |
| 79 | bool isMemorySpaceTransferIntrinsic(Intrinsic::ID id); |
| 80 | const Value *skipPointerTransfer(const Value *V, bool ignore_GEP_indices); |
| 81 | const Value *skipPointerTransfer(const Value *V, |
| 82 | std::set<const Value *> &processed); |
| 83 | BasicBlock *getParentBlock(Value *v); |
| 84 | Function *getParentFunction(Value *v); |
| 85 | void dumpBlock(Value *v, char *blockName); |
| 86 | Instruction *getInst(Value *base, char *instName); |
| 87 | void dumpInst(Value *base, char *instName); |
| 88 | void dumpInstRec(Value *v, std::set<Instruction *> *visited); |
| 89 | void dumpInstRec(Value *v); |
| 90 | void dumpParent(Value *v); |
| 91 | |
| 92 | } |
| 93 | |
| 94 | #endif |