blob: 00affafd0c3bcf5ab8d8eda2c00900ec00ee178d [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) {
20 return clspv::IsSampledImageRead(name) || clspv::IsImageWrite(name) ||
alan-bakerce179f12019-12-06 19:02:22 -050021 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
60bool clspv::IsImageWrite(StringRef name) {
61 return clspv::IsFloatImageWrite(name) || clspv::IsUintImageWrite(name) ||
62 clspv::IsIntImageWrite(name);
63}
64
65bool clspv::IsFloatImageWrite(StringRef name) {
alan-bakerf906d2b2019-12-10 11:26:23 -050066 return name.startswith("_Z12write_imagef14ocl_image1d_woiDv4_f") ||
67 name.startswith("_Z12write_imagef14ocl_image2d_woDv2_iDv4_f") ||
alan-bakerf67468c2019-11-25 15:51:49 -050068 name.startswith("_Z12write_imagef14ocl_image3d_woDv4_iDv4_f");
69}
70
71bool clspv::IsUintImageWrite(StringRef name) {
alan-bakerf906d2b2019-12-10 11:26:23 -050072 return name.startswith("_Z13write_imageui14ocl_image1d_woiDv4_j") ||
73 name.startswith("_Z13write_imageui14ocl_image2d_woDv2_iDv4_j") ||
alan-bakerf67468c2019-11-25 15:51:49 -050074 name.startswith("_Z13write_imageui14ocl_image3d_woDv4_iDv4_j");
75}
76
77bool clspv::IsIntImageWrite(StringRef name) {
78 // Odd mangling for 3d writes.
alan-bakerf906d2b2019-12-10 11:26:23 -050079 return name.startswith("_Z12write_imagei14ocl_image1d_woiDv4_i") ||
80 name.startswith("_Z12write_imagei14ocl_image2d_woDv2_iDv4_i") ||
alan-bakerf67468c2019-11-25 15:51:49 -050081 name.startswith("_Z12write_imagei14ocl_image3d_woDv4_iS0_");
82}
83
84bool clspv::IsGetImageHeight(StringRef name) {
85 return name.startswith("_Z16get_image_height14ocl_image2d_ro") ||
alan-bakerce179f12019-12-06 19:02:22 -050086 name.startswith("_Z16get_image_height14ocl_image2d_wo") ||
87 name.startswith("_Z16get_image_height14ocl_image3d_ro") ||
88 name.startswith("_Z16get_image_height14ocl_image3d_wo");
alan-bakerf67468c2019-11-25 15:51:49 -050089}
90
91bool clspv::IsGetImageWidth(StringRef name) {
alan-bakerf906d2b2019-12-10 11:26:23 -050092 return name.startswith("_Z15get_image_width14ocl_image1d_ro") ||
93 name.startswith("_Z15get_image_width14ocl_image1d_wo") ||
94 name.startswith("_Z15get_image_width14ocl_image2d_ro") ||
alan-bakerce179f12019-12-06 19:02:22 -050095 name.startswith("_Z15get_image_width14ocl_image2d_wo") ||
96 name.startswith("_Z15get_image_width14ocl_image3d_ro") ||
97 name.startswith("_Z15get_image_width14ocl_image3d_wo");
98}
99
100bool clspv::IsGetImageDepth(StringRef name) {
101 return name.startswith("_Z15get_image_depth14ocl_image3d_ro") ||
102 name.startswith("_Z15get_image_depth14ocl_image3d_wo");
103}
104
105bool clspv::IsGetImageDim(StringRef name) {
106 return name.startswith("_Z13get_image_dim14ocl_image2d_ro") ||
107 name.startswith("_Z13get_image_dim14ocl_image2d_wo") ||
108 name.startswith("_Z13get_image_dim14ocl_image3d_ro") ||
109 name.startswith("_Z13get_image_dim14ocl_image3d_wo");
110}
111
112bool clspv::IsImageQuery(StringRef name) {
113 return clspv::IsGetImageHeight(name) || clspv::IsGetImageWidth(name) ||
114 clspv::IsGetImageDepth(name) || clspv::IsGetImageDim(name);
alan-bakerf67468c2019-11-25 15:51:49 -0500115}