blob: 3c7586e612bf34832ffb1de308918fe410b16b09 [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) {
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
37bool 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
47bool 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
54bool clspv::IsImageWrite(StringRef name) {
55 return clspv::IsFloatImageWrite(name) || clspv::IsUintImageWrite(name) ||
56 clspv::IsIntImageWrite(name);
57}
58
59bool 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
64bool 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
69bool 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
75bool clspv::IsGetImageHeight(StringRef name) {
76 return name.startswith("_Z16get_image_height14ocl_image2d_ro") ||
alan-bakerce179f12019-12-06 19:02:22 -050077 name.startswith("_Z16get_image_height14ocl_image2d_wo") ||
78 name.startswith("_Z16get_image_height14ocl_image3d_ro") ||
79 name.startswith("_Z16get_image_height14ocl_image3d_wo");
alan-bakerf67468c2019-11-25 15:51:49 -050080}
81
82bool clspv::IsGetImageWidth(StringRef name) {
83 return name.startswith("_Z15get_image_width14ocl_image2d_ro") ||
alan-bakerce179f12019-12-06 19:02:22 -050084 name.startswith("_Z15get_image_width14ocl_image2d_wo") ||
85 name.startswith("_Z15get_image_width14ocl_image3d_ro") ||
86 name.startswith("_Z15get_image_width14ocl_image3d_wo");
87}
88
89bool clspv::IsGetImageDepth(StringRef name) {
90 return name.startswith("_Z15get_image_depth14ocl_image3d_ro") ||
91 name.startswith("_Z15get_image_depth14ocl_image3d_wo");
92}
93
94bool clspv::IsGetImageDim(StringRef name) {
95 return name.startswith("_Z13get_image_dim14ocl_image2d_ro") ||
96 name.startswith("_Z13get_image_dim14ocl_image2d_wo") ||
97 name.startswith("_Z13get_image_dim14ocl_image3d_ro") ||
98 name.startswith("_Z13get_image_dim14ocl_image3d_wo");
99}
100
101bool clspv::IsImageQuery(StringRef name) {
102 return clspv::IsGetImageHeight(name) || clspv::IsGetImageWidth(name) ||
103 clspv::IsGetImageDepth(name) || clspv::IsGetImageDim(name);
alan-bakerf67468c2019-11-25 15:51:49 -0500104}