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) { |
alan-baker | 75090e4 | 2020-02-20 11:21:04 -0500 | [diff] [blame] | 20 | return clspv::IsSampledImageRead(name) || clspv::IsUnsampledImageRead(name) || |
| 21 | clspv::IsImageWrite(name) || clspv::IsImageQuery(name); |
alan-baker | f67468c | 2019-11-25 15:51:49 -0500 | [diff] [blame] | 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) { |
alan-baker | f906d2b | 2019-12-10 11:26:23 -0500 | [diff] [blame] | 31 | return name.startswith("_Z11read_imagef14ocl_image1d_ro11ocl_samplerf") || |
| 32 | name.startswith("_Z11read_imagef14ocl_image2d_ro11ocl_samplerDv2_f") || |
alan-baker | f67468c | 2019-11-25 15:51:49 -0500 | [diff] [blame] | 33 | name.startswith("_Z11read_imagef14ocl_image3d_ro11ocl_samplerDv4_f") || |
alan-baker | 7150a1d | 2020-02-25 08:31:06 -0500 | [diff] [blame^] | 34 | name.startswith( |
| 35 | "_Z11read_imagef20ocl_image1d_array_ro11ocl_samplerDv2_f") || |
| 36 | name.startswith( |
| 37 | "_Z11read_imagef20ocl_image2d_array_ro11ocl_samplerDv4_f") || |
alan-baker | f906d2b | 2019-12-10 11:26:23 -0500 | [diff] [blame] | 38 | name.startswith("_Z11read_imagef14ocl_image1d_ro11ocl_sampleri") || |
alan-baker | f67468c | 2019-11-25 15:51:49 -0500 | [diff] [blame] | 39 | name.startswith("_Z11read_imagef14ocl_image2d_ro11ocl_samplerDv2_i") || |
alan-baker | 7150a1d | 2020-02-25 08:31:06 -0500 | [diff] [blame^] | 40 | name.startswith("_Z11read_imagef14ocl_image3d_ro11ocl_samplerDv4_i") || |
| 41 | name.startswith( |
| 42 | "_Z11read_imagef20ocl_image1d_array_ro11ocl_samplerDv2_i") || |
| 43 | name.startswith( |
| 44 | "_Z11read_imagef20ocl_image2d_array_ro11ocl_samplerDv4_i"); |
alan-baker | f67468c | 2019-11-25 15:51:49 -0500 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | bool clspv::IsUintSampledImageRead(StringRef name) { |
alan-baker | f906d2b | 2019-12-10 11:26:23 -0500 | [diff] [blame] | 48 | return name.startswith("_Z12read_imageui14ocl_image1d_ro11ocl_samplerf") || |
| 49 | name.startswith( |
alan-baker | f67468c | 2019-11-25 15:51:49 -0500 | [diff] [blame] | 50 | "_Z12read_imageui14ocl_image2d_ro11ocl_samplerDv2_f") || |
| 51 | name.startswith( |
| 52 | "_Z12read_imageui14ocl_image3d_ro11ocl_samplerDv4_f") || |
alan-baker | 7150a1d | 2020-02-25 08:31:06 -0500 | [diff] [blame^] | 53 | name.startswith( |
| 54 | "_Z12read_imageui20ocl_image1d_array_ro11ocl_samplerDv2_f") || |
| 55 | name.startswith( |
| 56 | "_Z12read_imageui20ocl_image2d_array_ro11ocl_samplerDv4_f") || |
alan-baker | f906d2b | 2019-12-10 11:26:23 -0500 | [diff] [blame] | 57 | name.startswith("_Z12read_imageui14ocl_image1d_ro11ocl_sampleri") || |
alan-baker | f67468c | 2019-11-25 15:51:49 -0500 | [diff] [blame] | 58 | name.startswith( |
| 59 | "_Z12read_imageui14ocl_image2d_ro11ocl_samplerDv2_i") || |
alan-baker | 7150a1d | 2020-02-25 08:31:06 -0500 | [diff] [blame^] | 60 | name.startswith( |
| 61 | "_Z12read_imageui14ocl_image3d_ro11ocl_samplerDv4_i") || |
| 62 | name.startswith( |
| 63 | "_Z12read_imageui20ocl_image1d_array_ro11ocl_samplerDv2_i") || |
| 64 | name.startswith( |
| 65 | "_Z12read_imageui20ocl_image2d_array_ro11ocl_samplerDv4_i"); |
alan-baker | f67468c | 2019-11-25 15:51:49 -0500 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | bool clspv::IsIntSampledImageRead(StringRef name) { |
alan-baker | f906d2b | 2019-12-10 11:26:23 -0500 | [diff] [blame] | 69 | return name.startswith("_Z11read_imagei14ocl_image1d_ro11ocl_samplerf") || |
| 70 | name.startswith("_Z11read_imagei14ocl_image2d_ro11ocl_samplerDv2_f") || |
alan-baker | f67468c | 2019-11-25 15:51:49 -0500 | [diff] [blame] | 71 | name.startswith("_Z11read_imagei14ocl_image3d_ro11ocl_samplerDv4_f") || |
alan-baker | 7150a1d | 2020-02-25 08:31:06 -0500 | [diff] [blame^] | 72 | name.startswith( |
| 73 | "_Z11read_imagei20ocl_image1d_array_ro11ocl_samplerDv2_f") || |
| 74 | name.startswith( |
| 75 | "_Z11read_imagei20ocl_image2d_array_ro11ocl_samplerDv4_f") || |
alan-baker | f906d2b | 2019-12-10 11:26:23 -0500 | [diff] [blame] | 76 | name.startswith("_Z11read_imagei14ocl_image1d_ro11ocl_sampleri") || |
alan-baker | f67468c | 2019-11-25 15:51:49 -0500 | [diff] [blame] | 77 | name.startswith("_Z11read_imagei14ocl_image2d_ro11ocl_samplerDv2_i") || |
alan-baker | 7150a1d | 2020-02-25 08:31:06 -0500 | [diff] [blame^] | 78 | name.startswith("_Z11read_imagei14ocl_image3d_ro11ocl_samplerDv4_i") || |
| 79 | name.startswith( |
| 80 | "_Z11read_imagei20ocl_image1d_array_ro11ocl_samplerDv2_i") || |
| 81 | name.startswith( |
| 82 | "_Z11read_imagei20ocl_image2d_array_ro11ocl_samplerDv4_i"); |
alan-baker | f67468c | 2019-11-25 15:51:49 -0500 | [diff] [blame] | 83 | } |
| 84 | |
alan-baker | 75090e4 | 2020-02-20 11:21:04 -0500 | [diff] [blame] | 85 | bool clspv::IsUnsampledImageRead(StringRef name) { |
| 86 | return clspv::IsFloatUnsampledImageRead(name) || |
| 87 | clspv::IsUintUnsampledImageRead(name) || |
| 88 | clspv::IsIntUnsampledImageRead(name); |
| 89 | } |
| 90 | |
| 91 | bool clspv::IsFloatUnsampledImageRead(StringRef name) { |
| 92 | return name.startswith("_Z11read_imagef14ocl_image1d_roi") || |
| 93 | name.startswith("_Z11read_imagef14ocl_image2d_roDv2_i") || |
alan-baker | 7150a1d | 2020-02-25 08:31:06 -0500 | [diff] [blame^] | 94 | name.startswith("_Z11read_imagef14ocl_image3d_roDv4_i") || |
| 95 | name.startswith("_Z11read_imagef20ocl_image1d_array_roDv2_i") || |
| 96 | name.startswith("_Z11read_imagef20ocl_image2d_array_roDv4_i"); |
alan-baker | 75090e4 | 2020-02-20 11:21:04 -0500 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | bool clspv::IsUintUnsampledImageRead(StringRef name) { |
| 100 | return name.startswith("_Z12read_imageui14ocl_image1d_roi") || |
| 101 | name.startswith("_Z12read_imageui14ocl_image2d_roDv2_i") || |
alan-baker | 7150a1d | 2020-02-25 08:31:06 -0500 | [diff] [blame^] | 102 | name.startswith("_Z12read_imageui14ocl_image3d_roDv4_i") || |
| 103 | name.startswith("_Z12read_imageui20ocl_image1d_array_roDv2_i") || |
| 104 | name.startswith("_Z12read_imageui20ocl_image2d_array_roDv4_i"); |
alan-baker | 75090e4 | 2020-02-20 11:21:04 -0500 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | bool clspv::IsIntUnsampledImageRead(StringRef name) { |
| 108 | return name.startswith("_Z11read_imagei14ocl_image1d_roi") || |
| 109 | name.startswith("_Z11read_imagei14ocl_image2d_roDv2_i") || |
alan-baker | 7150a1d | 2020-02-25 08:31:06 -0500 | [diff] [blame^] | 110 | name.startswith("_Z11read_imagei14ocl_image3d_roDv4_i") || |
| 111 | name.startswith("_Z11read_imagei20ocl_image1d_array_roDv2_i") || |
| 112 | name.startswith("_Z11read_imagei20ocl_image2d_array_roDv4_i"); |
alan-baker | 75090e4 | 2020-02-20 11:21:04 -0500 | [diff] [blame] | 113 | } |
| 114 | |
alan-baker | f67468c | 2019-11-25 15:51:49 -0500 | [diff] [blame] | 115 | bool clspv::IsImageWrite(StringRef name) { |
| 116 | return clspv::IsFloatImageWrite(name) || clspv::IsUintImageWrite(name) || |
| 117 | clspv::IsIntImageWrite(name); |
| 118 | } |
| 119 | |
| 120 | bool clspv::IsFloatImageWrite(StringRef name) { |
alan-baker | f906d2b | 2019-12-10 11:26:23 -0500 | [diff] [blame] | 121 | return name.startswith("_Z12write_imagef14ocl_image1d_woiDv4_f") || |
| 122 | name.startswith("_Z12write_imagef14ocl_image2d_woDv2_iDv4_f") || |
alan-baker | 7150a1d | 2020-02-25 08:31:06 -0500 | [diff] [blame^] | 123 | name.startswith("_Z12write_imagef14ocl_image3d_woDv4_iDv4_f") || |
| 124 | name.startswith("_Z12write_imagef20ocl_image1d_array_woDv2_iDv4_f") || |
| 125 | name.startswith("_Z12write_imagef20ocl_image2d_array_woDv4_iDv4_f"); |
alan-baker | f67468c | 2019-11-25 15:51:49 -0500 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | bool clspv::IsUintImageWrite(StringRef name) { |
alan-baker | f906d2b | 2019-12-10 11:26:23 -0500 | [diff] [blame] | 129 | return name.startswith("_Z13write_imageui14ocl_image1d_woiDv4_j") || |
| 130 | name.startswith("_Z13write_imageui14ocl_image2d_woDv2_iDv4_j") || |
alan-baker | 7150a1d | 2020-02-25 08:31:06 -0500 | [diff] [blame^] | 131 | name.startswith("_Z13write_imageui14ocl_image3d_woDv4_iDv4_j") || |
| 132 | name.startswith("_Z13write_imageui20ocl_image1d_array_woDv2_iDv4_j") || |
| 133 | name.startswith("_Z13write_imageui20ocl_image2d_array_woDv4_iDv4_j"); |
alan-baker | f67468c | 2019-11-25 15:51:49 -0500 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | bool clspv::IsIntImageWrite(StringRef name) { |
alan-baker | 7150a1d | 2020-02-25 08:31:06 -0500 | [diff] [blame^] | 137 | // Odd mangling for 2d array and 3d writes. |
alan-baker | f906d2b | 2019-12-10 11:26:23 -0500 | [diff] [blame] | 138 | return name.startswith("_Z12write_imagei14ocl_image1d_woiDv4_i") || |
| 139 | name.startswith("_Z12write_imagei14ocl_image2d_woDv2_iDv4_i") || |
alan-baker | 7150a1d | 2020-02-25 08:31:06 -0500 | [diff] [blame^] | 140 | name.startswith("_Z12write_imagei14ocl_image3d_woDv4_iS0_") || |
| 141 | name.startswith("_Z12write_imagei20ocl_image1d_array_woDv2_iDv4_i") || |
| 142 | name.startswith("_Z12write_imagei20ocl_image2d_array_woDv4_iS0_"); |
alan-baker | f67468c | 2019-11-25 15:51:49 -0500 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | bool clspv::IsGetImageHeight(StringRef name) { |
| 146 | return name.startswith("_Z16get_image_height14ocl_image2d_ro") || |
alan-baker | ce179f1 | 2019-12-06 19:02:22 -0500 | [diff] [blame] | 147 | name.startswith("_Z16get_image_height14ocl_image2d_wo") || |
| 148 | name.startswith("_Z16get_image_height14ocl_image3d_ro") || |
alan-baker | 7150a1d | 2020-02-25 08:31:06 -0500 | [diff] [blame^] | 149 | name.startswith("_Z16get_image_height14ocl_image3d_wo") || |
| 150 | name.startswith("_Z16get_image_height20ocl_image2d_array_ro") || |
| 151 | name.startswith("_Z16get_image_height20ocl_image2d_array_wo"); |
alan-baker | f67468c | 2019-11-25 15:51:49 -0500 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | bool clspv::IsGetImageWidth(StringRef name) { |
alan-baker | f906d2b | 2019-12-10 11:26:23 -0500 | [diff] [blame] | 155 | return name.startswith("_Z15get_image_width14ocl_image1d_ro") || |
| 156 | name.startswith("_Z15get_image_width14ocl_image1d_wo") || |
| 157 | name.startswith("_Z15get_image_width14ocl_image2d_ro") || |
alan-baker | ce179f1 | 2019-12-06 19:02:22 -0500 | [diff] [blame] | 158 | name.startswith("_Z15get_image_width14ocl_image2d_wo") || |
| 159 | name.startswith("_Z15get_image_width14ocl_image3d_ro") || |
alan-baker | 7150a1d | 2020-02-25 08:31:06 -0500 | [diff] [blame^] | 160 | name.startswith("_Z15get_image_width14ocl_image3d_wo") || |
| 161 | name.startswith("_Z15get_image_width20ocl_image1d_array_ro") || |
| 162 | name.startswith("_Z15get_image_width20ocl_image1d_array_wo") || |
| 163 | name.startswith("_Z15get_image_width20ocl_image2d_array_ro") || |
| 164 | name.startswith("_Z15get_image_width20ocl_image2d_array_wo"); |
alan-baker | ce179f1 | 2019-12-06 19:02:22 -0500 | [diff] [blame] | 165 | } |
| 166 | |
| 167 | bool clspv::IsGetImageDepth(StringRef name) { |
| 168 | return name.startswith("_Z15get_image_depth14ocl_image3d_ro") || |
| 169 | name.startswith("_Z15get_image_depth14ocl_image3d_wo"); |
| 170 | } |
| 171 | |
| 172 | bool clspv::IsGetImageDim(StringRef name) { |
| 173 | return name.startswith("_Z13get_image_dim14ocl_image2d_ro") || |
| 174 | name.startswith("_Z13get_image_dim14ocl_image2d_wo") || |
| 175 | name.startswith("_Z13get_image_dim14ocl_image3d_ro") || |
alan-baker | 7150a1d | 2020-02-25 08:31:06 -0500 | [diff] [blame^] | 176 | name.startswith("_Z13get_image_dim14ocl_image3d_wo") || |
| 177 | name.startswith("_Z13get_image_dim20ocl_image2d_array_ro") || |
| 178 | name.startswith("_Z13get_image_dim20ocl_image2d_array_wo"); |
alan-baker | ce179f1 | 2019-12-06 19:02:22 -0500 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | bool clspv::IsImageQuery(StringRef name) { |
| 182 | return clspv::IsGetImageHeight(name) || clspv::IsGetImageWidth(name) || |
| 183 | clspv::IsGetImageDepth(name) || clspv::IsGetImageDim(name); |
alan-baker | f67468c | 2019-11-25 15:51:49 -0500 | [diff] [blame] | 184 | } |