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 | #include "Builtins.h" |
| 16 | |
| 17 | using namespace llvm; |
| 18 | |
| 19 | bool clspv::IsImageBuiltin(StringRef name) { |
| 20 | return clspv::IsSampledImageRead(name) || clspv::IsImageWrite(name) || |
| 21 | clspv::IsGetImageHeight(name) || clspv::IsGetImageWidth(name); |
| 22 | } |
| 23 | |
| 24 | bool clspv::IsSampledImageRead(StringRef name) { |
| 25 | return clspv::IsFloatSampledImageRead(name) || |
| 26 | clspv::IsUintSampledImageRead(name) || |
| 27 | clspv::IsIntSampledImageRead(name); |
| 28 | } |
| 29 | |
| 30 | bool clspv::IsFloatSampledImageRead(StringRef name) { |
| 31 | return name.startswith("_Z11read_imagef14ocl_image2d_ro11ocl_samplerDv2_f") || |
| 32 | name.startswith("_Z11read_imagef14ocl_image3d_ro11ocl_samplerDv4_f") || |
| 33 | name.startswith("_Z11read_imagef14ocl_image2d_ro11ocl_samplerDv2_i") || |
| 34 | name.startswith("_Z11read_imagef14ocl_image3d_ro11ocl_samplerDv4_i"); |
| 35 | } |
| 36 | |
| 37 | bool clspv::IsUintSampledImageRead(StringRef name) { |
| 38 | return name.startswith( |
| 39 | "_Z12read_imageui14ocl_image2d_ro11ocl_samplerDv2_f") || |
| 40 | name.startswith( |
| 41 | "_Z12read_imageui14ocl_image3d_ro11ocl_samplerDv4_f") || |
| 42 | name.startswith( |
| 43 | "_Z12read_imageui14ocl_image2d_ro11ocl_samplerDv2_i") || |
| 44 | name.startswith("_Z12read_imageui14ocl_image3d_ro11ocl_samplerDv4_i"); |
| 45 | } |
| 46 | |
| 47 | bool clspv::IsIntSampledImageRead(StringRef name) { |
| 48 | return name.startswith("_Z11read_imagei14ocl_image2d_ro11ocl_samplerDv2_f") || |
| 49 | name.startswith("_Z11read_imagei14ocl_image3d_ro11ocl_samplerDv4_f") || |
| 50 | name.startswith("_Z11read_imagei14ocl_image2d_ro11ocl_samplerDv2_i") || |
| 51 | name.startswith("_Z11read_imagei14ocl_image3d_ro11ocl_samplerDv4_i"); |
| 52 | } |
| 53 | |
| 54 | bool clspv::IsImageWrite(StringRef name) { |
| 55 | return clspv::IsFloatImageWrite(name) || clspv::IsUintImageWrite(name) || |
| 56 | clspv::IsIntImageWrite(name); |
| 57 | } |
| 58 | |
| 59 | bool clspv::IsFloatImageWrite(StringRef name) { |
| 60 | return name.startswith("_Z12write_imagef14ocl_image2d_woDv2_iDv4_f") || |
| 61 | name.startswith("_Z12write_imagef14ocl_image3d_woDv4_iDv4_f"); |
| 62 | } |
| 63 | |
| 64 | bool clspv::IsUintImageWrite(StringRef name) { |
| 65 | return name.startswith("_Z13write_imageui14ocl_image2d_woDv2_iDv4_j") || |
| 66 | name.startswith("_Z13write_imageui14ocl_image3d_woDv4_iDv4_j"); |
| 67 | } |
| 68 | |
| 69 | bool clspv::IsIntImageWrite(StringRef name) { |
| 70 | // Odd mangling for 3d writes. |
| 71 | return name.startswith("_Z12write_imagei14ocl_image2d_woDv2_iDv4_i") || |
| 72 | name.startswith("_Z12write_imagei14ocl_image3d_woDv4_iS0_"); |
| 73 | } |
| 74 | |
| 75 | bool clspv::IsGetImageHeight(StringRef name) { |
| 76 | return name.startswith("_Z16get_image_height14ocl_image2d_ro") || |
| 77 | name.startswith("_Z16get_image_height14ocl_image2d_wo"); |
| 78 | } |
| 79 | |
| 80 | bool clspv::IsGetImageWidth(StringRef name) { |
| 81 | return name.startswith("_Z15get_image_width14ocl_image2d_ro") || |
| 82 | name.startswith("_Z15get_image_width14ocl_image2d_wo"); |
| 83 | } |