blob: 6fef319e06e2f9f01a2b0e53a9fc9980e842b2ff [file] [log] [blame]
alan-bakerf67468c2019-11-25 15:51:49 -05001// 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
17using namespace llvm;
18
19bool clspv::IsImageBuiltin(StringRef name) {
alan-baker75090e42020-02-20 11:21:04 -050020 return clspv::IsSampledImageRead(name) || clspv::IsUnsampledImageRead(name) ||
21 clspv::IsImageWrite(name) || clspv::IsImageQuery(name);
alan-bakerf67468c2019-11-25 15:51:49 -050022}
23
24bool clspv::IsSampledImageRead(StringRef name) {
25 return clspv::IsFloatSampledImageRead(name) ||
26 clspv::IsUintSampledImageRead(name) ||
27 clspv::IsIntSampledImageRead(name);
28}
29
30bool clspv::IsFloatSampledImageRead(StringRef name) {
alan-bakerf906d2b2019-12-10 11:26:23 -050031 return name.startswith("_Z11read_imagef14ocl_image1d_ro11ocl_samplerf") ||
32 name.startswith("_Z11read_imagef14ocl_image2d_ro11ocl_samplerDv2_f") ||
alan-bakerf67468c2019-11-25 15:51:49 -050033 name.startswith("_Z11read_imagef14ocl_image3d_ro11ocl_samplerDv4_f") ||
alan-bakerf906d2b2019-12-10 11:26:23 -050034 name.startswith("_Z11read_imagef14ocl_image1d_ro11ocl_sampleri") ||
alan-bakerf67468c2019-11-25 15:51:49 -050035 name.startswith("_Z11read_imagef14ocl_image2d_ro11ocl_samplerDv2_i") ||
36 name.startswith("_Z11read_imagef14ocl_image3d_ro11ocl_samplerDv4_i");
37}
38
39bool clspv::IsUintSampledImageRead(StringRef name) {
alan-bakerf906d2b2019-12-10 11:26:23 -050040 return name.startswith("_Z12read_imageui14ocl_image1d_ro11ocl_samplerf") ||
41 name.startswith(
alan-bakerf67468c2019-11-25 15:51:49 -050042 "_Z12read_imageui14ocl_image2d_ro11ocl_samplerDv2_f") ||
43 name.startswith(
44 "_Z12read_imageui14ocl_image3d_ro11ocl_samplerDv4_f") ||
alan-bakerf906d2b2019-12-10 11:26:23 -050045 name.startswith("_Z12read_imageui14ocl_image1d_ro11ocl_sampleri") ||
alan-bakerf67468c2019-11-25 15:51:49 -050046 name.startswith(
47 "_Z12read_imageui14ocl_image2d_ro11ocl_samplerDv2_i") ||
48 name.startswith("_Z12read_imageui14ocl_image3d_ro11ocl_samplerDv4_i");
49}
50
51bool clspv::IsIntSampledImageRead(StringRef name) {
alan-bakerf906d2b2019-12-10 11:26:23 -050052 return name.startswith("_Z11read_imagei14ocl_image1d_ro11ocl_samplerf") ||
53 name.startswith("_Z11read_imagei14ocl_image2d_ro11ocl_samplerDv2_f") ||
alan-bakerf67468c2019-11-25 15:51:49 -050054 name.startswith("_Z11read_imagei14ocl_image3d_ro11ocl_samplerDv4_f") ||
alan-bakerf906d2b2019-12-10 11:26:23 -050055 name.startswith("_Z11read_imagei14ocl_image1d_ro11ocl_sampleri") ||
alan-bakerf67468c2019-11-25 15:51:49 -050056 name.startswith("_Z11read_imagei14ocl_image2d_ro11ocl_samplerDv2_i") ||
57 name.startswith("_Z11read_imagei14ocl_image3d_ro11ocl_samplerDv4_i");
58}
59
alan-baker75090e42020-02-20 11:21:04 -050060bool clspv::IsUnsampledImageRead(StringRef name) {
61 return clspv::IsFloatUnsampledImageRead(name) ||
62 clspv::IsUintUnsampledImageRead(name) ||
63 clspv::IsIntUnsampledImageRead(name);
64}
65
66bool clspv::IsFloatUnsampledImageRead(StringRef name) {
67 return name.startswith("_Z11read_imagef14ocl_image1d_roi") ||
68 name.startswith("_Z11read_imagef14ocl_image2d_roDv2_i") ||
69 name.startswith("_Z11read_imagef14ocl_image3d_roDv4_i");
70}
71
72bool clspv::IsUintUnsampledImageRead(StringRef name) {
73 return name.startswith("_Z12read_imageui14ocl_image1d_roi") ||
74 name.startswith("_Z12read_imageui14ocl_image2d_roDv2_i") ||
75 name.startswith("_Z12read_imageui14ocl_image3d_roDv4_i");
76}
77
78bool clspv::IsIntUnsampledImageRead(StringRef name) {
79 return name.startswith("_Z11read_imagei14ocl_image1d_roi") ||
80 name.startswith("_Z11read_imagei14ocl_image2d_roDv2_i") ||
81 name.startswith("_Z11read_imagei14ocl_image3d_roDv4_i");
82}
83
alan-bakerf67468c2019-11-25 15:51:49 -050084bool clspv::IsImageWrite(StringRef name) {
85 return clspv::IsFloatImageWrite(name) || clspv::IsUintImageWrite(name) ||
86 clspv::IsIntImageWrite(name);
87}
88
89bool clspv::IsFloatImageWrite(StringRef name) {
alan-bakerf906d2b2019-12-10 11:26:23 -050090 return name.startswith("_Z12write_imagef14ocl_image1d_woiDv4_f") ||
91 name.startswith("_Z12write_imagef14ocl_image2d_woDv2_iDv4_f") ||
alan-bakerf67468c2019-11-25 15:51:49 -050092 name.startswith("_Z12write_imagef14ocl_image3d_woDv4_iDv4_f");
93}
94
95bool clspv::IsUintImageWrite(StringRef name) {
alan-bakerf906d2b2019-12-10 11:26:23 -050096 return name.startswith("_Z13write_imageui14ocl_image1d_woiDv4_j") ||
97 name.startswith("_Z13write_imageui14ocl_image2d_woDv2_iDv4_j") ||
alan-bakerf67468c2019-11-25 15:51:49 -050098 name.startswith("_Z13write_imageui14ocl_image3d_woDv4_iDv4_j");
99}
100
101bool clspv::IsIntImageWrite(StringRef name) {
102 // Odd mangling for 3d writes.
alan-bakerf906d2b2019-12-10 11:26:23 -0500103 return name.startswith("_Z12write_imagei14ocl_image1d_woiDv4_i") ||
104 name.startswith("_Z12write_imagei14ocl_image2d_woDv2_iDv4_i") ||
alan-bakerf67468c2019-11-25 15:51:49 -0500105 name.startswith("_Z12write_imagei14ocl_image3d_woDv4_iS0_");
106}
107
108bool clspv::IsGetImageHeight(StringRef name) {
109 return name.startswith("_Z16get_image_height14ocl_image2d_ro") ||
alan-bakerce179f12019-12-06 19:02:22 -0500110 name.startswith("_Z16get_image_height14ocl_image2d_wo") ||
111 name.startswith("_Z16get_image_height14ocl_image3d_ro") ||
112 name.startswith("_Z16get_image_height14ocl_image3d_wo");
alan-bakerf67468c2019-11-25 15:51:49 -0500113}
114
115bool clspv::IsGetImageWidth(StringRef name) {
alan-bakerf906d2b2019-12-10 11:26:23 -0500116 return name.startswith("_Z15get_image_width14ocl_image1d_ro") ||
117 name.startswith("_Z15get_image_width14ocl_image1d_wo") ||
118 name.startswith("_Z15get_image_width14ocl_image2d_ro") ||
alan-bakerce179f12019-12-06 19:02:22 -0500119 name.startswith("_Z15get_image_width14ocl_image2d_wo") ||
120 name.startswith("_Z15get_image_width14ocl_image3d_ro") ||
121 name.startswith("_Z15get_image_width14ocl_image3d_wo");
122}
123
124bool clspv::IsGetImageDepth(StringRef name) {
125 return name.startswith("_Z15get_image_depth14ocl_image3d_ro") ||
126 name.startswith("_Z15get_image_depth14ocl_image3d_wo");
127}
128
129bool clspv::IsGetImageDim(StringRef name) {
130 return name.startswith("_Z13get_image_dim14ocl_image2d_ro") ||
131 name.startswith("_Z13get_image_dim14ocl_image2d_wo") ||
132 name.startswith("_Z13get_image_dim14ocl_image3d_ro") ||
133 name.startswith("_Z13get_image_dim14ocl_image3d_wo");
134}
135
136bool clspv::IsImageQuery(StringRef name) {
137 return clspv::IsGetImageHeight(name) || clspv::IsGetImageWidth(name) ||
138 clspv::IsGetImageDepth(name) || clspv::IsGetImageDim(name);
alan-bakerf67468c2019-11-25 15:51:49 -0500139}