alan-baker | f67468c | 2019-11-25 15:51:49 -0500 | [diff] [blame^] | 1 | // Copyright 2019 The Clspv Authors. All rights reserved. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | #ifndef CLSPV_LIB_BUILTINS_H_ |
| 16 | #define CLSPV_LIB_BUILTINS_H_ |
| 17 | |
| 18 | #include "llvm/ADT/StringRef.h" |
| 19 | #include "llvm/IR/Function.h" |
| 20 | |
| 21 | namespace clspv { |
| 22 | |
| 23 | // Returns true if the function is an OpenCL image builtin. |
| 24 | bool IsImageBuiltin(llvm::StringRef name); |
| 25 | inline bool IsImageBuiltin(llvm::Function *f) { |
| 26 | return IsImageBuiltin(f->getName()); |
| 27 | } |
| 28 | |
| 29 | // Returns true if the function is an OpenCL sampled image read. |
| 30 | bool IsSampledImageRead(llvm::StringRef name); |
| 31 | inline bool IsSampledImageRead(llvm::Function *f) { |
| 32 | return IsSampledImageRead(f->getName()); |
| 33 | } |
| 34 | |
| 35 | // Returns true if the function is an OpenCL sampled image read of float type. |
| 36 | bool IsFloatSampledImageRead(llvm::StringRef name); |
| 37 | inline bool IsFloatSampledImageRead(llvm::Function *f) { |
| 38 | return IsFloatSampledImageRead(f->getName()); |
| 39 | } |
| 40 | |
| 41 | // Returns true if the function is an OpenCL sampled image read of uint type. |
| 42 | bool IsUintSampledImageRead(llvm::StringRef name); |
| 43 | inline bool IsUintSampledImageRead(llvm::Function *f) { |
| 44 | return IsUintSampledImageRead(f->getName()); |
| 45 | } |
| 46 | |
| 47 | // Returns true if the function is an OpenCL sampled image read of int type. |
| 48 | bool IsIntSampledImageRead(llvm::StringRef name); |
| 49 | inline bool IsIntSampledImageRead(llvm::Function *f) { |
| 50 | return IsIntSampledImageRead(f->getName()); |
| 51 | } |
| 52 | |
| 53 | // Returns true if the function is an OpenCL image write. |
| 54 | bool IsImageWrite(llvm::StringRef name); |
| 55 | inline bool IsImageWrite(llvm::Function *f) { |
| 56 | return IsImageWrite(f->getName()); |
| 57 | } |
| 58 | |
| 59 | // Returns true if the function is an OpenCL image write of float type. |
| 60 | bool IsFloatImageWrite(llvm::StringRef name); |
| 61 | inline bool IsFloatImageWrite(llvm::Function *f) { |
| 62 | return IsFloatImageWrite(f->getName()); |
| 63 | } |
| 64 | |
| 65 | // Returns true if the function is an OpenCL image write of uint type. |
| 66 | bool IsUintImageWrite(llvm::StringRef name); |
| 67 | inline bool IsUintImageWrite(llvm::Function *f) { |
| 68 | return IsUintImageWrite(f->getName()); |
| 69 | } |
| 70 | |
| 71 | // Returns true if the function is an OpenCL image write of int type. |
| 72 | bool IsIntImageWrite(llvm::StringRef name); |
| 73 | inline bool IsIntImageWrite(llvm::Function *f) { |
| 74 | return IsIntImageWrite(f->getName()); |
| 75 | } |
| 76 | |
| 77 | // Returns true if the function is an OpenCL image height query. |
| 78 | bool IsGetImageHeight(llvm::StringRef name); |
| 79 | inline bool IsGetImageHeight(llvm::Function *f) { |
| 80 | return IsGetImageHeight(f->getName()); |
| 81 | } |
| 82 | |
| 83 | // Returns true if the function is an OpenCL image width query. |
| 84 | bool IsGetImageWidth(llvm::StringRef name); |
| 85 | inline bool IsGetImageWidth(llvm::Function *f) { |
| 86 | return IsGetImageWidth(f->getName()); |
| 87 | } |
| 88 | |
| 89 | } // namespace clspv |
| 90 | |
| 91 | #endif // CLSPV_LIB_BUILTINS_H_ |