Daniel Koch | 5a97e3a | 2020-03-17 15:30:19 -0400 | [diff] [blame^] | 1 | // Copyright (c) 2015-2020 The Khronos Group Inc. |
| 2 | // Modifications Copyright (C) 2020 Advanced Micro Devices, Inc. All rights |
| 3 | // reserved. |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 4 | // |
David Neto | 9fc8658 | 2016-09-01 15:33:59 -0400 | [diff] [blame] | 5 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | // you may not use this file except in compliance with the License. |
| 7 | // You may obtain a copy of the License at |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 8 | // |
David Neto | 9fc8658 | 2016-09-01 15:33:59 -0400 | [diff] [blame] | 9 | // http://www.apache.org/licenses/LICENSE-2.0 |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 10 | // |
David Neto | 9fc8658 | 2016-09-01 15:33:59 -0400 | [diff] [blame] | 11 | // Unless required by applicable law or agreed to in writing, software |
| 12 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | // See the License for the specific language governing permissions and |
| 15 | // limitations under the License. |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 16 | |
dan sinclair | eda2cfb | 2018-08-03 15:06:09 -0400 | [diff] [blame] | 17 | #include "source/operand.h" |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 18 | |
| 19 | #include <assert.h> |
| 20 | #include <string.h> |
alan-baker | 45fb696 | 2019-05-10 11:02:01 -0400 | [diff] [blame] | 21 | |
Chris Forbes | 78338d5 | 2017-06-27 16:28:22 -0700 | [diff] [blame] | 22 | #include <algorithm> |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 23 | |
Jaebaek Seo | dd37d73 | 2020-01-23 17:04:30 -0500 | [diff] [blame] | 24 | #include "DebugInfo.h" |
| 25 | #include "OpenCLDebugInfo100.h" |
dan sinclair | eda2cfb | 2018-08-03 15:06:09 -0400 | [diff] [blame] | 26 | #include "source/macro.h" |
| 27 | #include "source/spirv_constant.h" |
| 28 | #include "source/spirv_target_env.h" |
David Neto | ba73a7c | 2016-01-06 13:08:39 -0500 | [diff] [blame] | 29 | |
David Neto | 00fa393 | 2018-02-09 14:29:02 -0500 | [diff] [blame] | 30 | // For now, assume unified1 contains up to SPIR-V 1.3 and no later |
| 31 | // SPIR-V version. |
| 32 | // TODO(dneto): Make one set of tables, but with version tags on a |
| 33 | // per-item basis. https://github.com/KhronosGroup/SPIRV-Tools/issues/1195 |
| 34 | |
David Neto | 00fa393 | 2018-02-09 14:29:02 -0500 | [diff] [blame] | 35 | #include "operand.kinds-unified1.inc" |
David Neto | 64f36ea | 2019-12-19 17:16:26 -0500 | [diff] [blame] | 36 | #include "spirv-tools/libspirv.h" |
Lei Zhang | 16981f8 | 2017-09-21 17:24:57 -0400 | [diff] [blame] | 37 | |
Lei Zhang | 1ef6b19 | 2018-03-14 13:06:18 -0400 | [diff] [blame] | 38 | static const spv_operand_table_t kOperandTable = { |
| 39 | ARRAY_SIZE(pygen_variable_OperandInfoTable), |
| 40 | pygen_variable_OperandInfoTable}; |
Lei Zhang | 063dbea | 2017-10-25 12:15:51 -0400 | [diff] [blame] | 41 | |
| 42 | spv_result_t spvOperandTableGet(spv_operand_table* pOperandTable, |
Lei Zhang | 1ef6b19 | 2018-03-14 13:06:18 -0400 | [diff] [blame] | 43 | spv_target_env) { |
Lei Zhang | 063dbea | 2017-10-25 12:15:51 -0400 | [diff] [blame] | 44 | if (!pOperandTable) return SPV_ERROR_INVALID_POINTER; |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 45 | |
Lei Zhang | 1ef6b19 | 2018-03-14 13:06:18 -0400 | [diff] [blame] | 46 | *pOperandTable = &kOperandTable; |
| 47 | return SPV_SUCCESS; |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 48 | } |
| 49 | |
Lei Zhang | 1ef6b19 | 2018-03-14 13:06:18 -0400 | [diff] [blame] | 50 | spv_result_t spvOperandTableNameLookup(spv_target_env env, |
| 51 | const spv_operand_table table, |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 52 | const spv_operand_type_t type, |
David Neto | 388c40d | 2015-09-16 16:42:56 -0400 | [diff] [blame] | 53 | const char* name, |
| 54 | const size_t nameLength, |
| 55 | spv_operand_desc* pEntry) { |
Lei Zhang | 4005670 | 2015-09-11 14:31:27 -0400 | [diff] [blame] | 56 | if (!table) return SPV_ERROR_INVALID_TABLE; |
| 57 | if (!name || !pEntry) return SPV_ERROR_INVALID_POINTER; |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 58 | |
alan-baker | 45fb696 | 2019-05-10 11:02:01 -0400 | [diff] [blame] | 59 | const auto version = spvVersionForTargetEnv(env); |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 60 | for (uint64_t typeIndex = 0; typeIndex < table->count; ++typeIndex) { |
Lei Zhang | ca1bf94 | 2016-04-27 16:47:13 -0400 | [diff] [blame] | 61 | const auto& group = table->types[typeIndex]; |
| 62 | if (type != group.type) continue; |
| 63 | for (uint64_t index = 0; index < group.count; ++index) { |
| 64 | const auto& entry = group.entries[index]; |
David Neto | 363bfca | 2018-06-05 23:07:51 -0700 | [diff] [blame] | 65 | // We consider the current operand as available as long as |
Lei Zhang | 1ef6b19 | 2018-03-14 13:06:18 -0400 | [diff] [blame] | 66 | // 1. The target environment satisfies the minimal requirement of the |
| 67 | // operand; or |
David Neto | 363bfca | 2018-06-05 23:07:51 -0700 | [diff] [blame] | 68 | // 2. There is at least one extension enabling this operand; or |
| 69 | // 3. There is at least one capability enabling this operand. |
Lei Zhang | 1ef6b19 | 2018-03-14 13:06:18 -0400 | [diff] [blame] | 70 | // |
| 71 | // Note that the second rule assumes the extension enabling this operand |
| 72 | // is indeed requested in the SPIR-V code; checking that should be |
| 73 | // validator's work. |
alan-baker | 45fb696 | 2019-05-10 11:02:01 -0400 | [diff] [blame] | 74 | if (((version >= entry.minVersion && version <= entry.lastVersion) || |
David Neto | 363bfca | 2018-06-05 23:07:51 -0700 | [diff] [blame] | 75 | entry.numExtensions > 0u || entry.numCapabilities > 0u) && |
Lei Zhang | 1ef6b19 | 2018-03-14 13:06:18 -0400 | [diff] [blame] | 76 | nameLength == strlen(entry.name) && |
Lei Zhang | ca1bf94 | 2016-04-27 16:47:13 -0400 | [diff] [blame] | 77 | !strncmp(entry.name, name, nameLength)) { |
| 78 | *pEntry = &entry; |
| 79 | return SPV_SUCCESS; |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 80 | } |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | return SPV_ERROR_INVALID_LOOKUP; |
| 85 | } |
| 86 | |
Lei Zhang | 1ef6b19 | 2018-03-14 13:06:18 -0400 | [diff] [blame] | 87 | spv_result_t spvOperandTableValueLookup(spv_target_env env, |
| 88 | const spv_operand_table table, |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 89 | const spv_operand_type_t type, |
| 90 | const uint32_t value, |
Dejan Mircevski | 50babb2 | 2015-09-29 10:56:32 -0400 | [diff] [blame] | 91 | spv_operand_desc* pEntry) { |
Lei Zhang | 4005670 | 2015-09-11 14:31:27 -0400 | [diff] [blame] | 92 | if (!table) return SPV_ERROR_INVALID_TABLE; |
| 93 | if (!pEntry) return SPV_ERROR_INVALID_POINTER; |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 94 | |
alan-baker | 45fb696 | 2019-05-10 11:02:01 -0400 | [diff] [blame] | 95 | spv_operand_desc_t needle = {"", value, 0, nullptr, 0, nullptr, {}, ~0u, ~0u}; |
Lei Zhang | 1ef6b19 | 2018-03-14 13:06:18 -0400 | [diff] [blame] | 96 | |
| 97 | auto comp = [](const spv_operand_desc_t& lhs, const spv_operand_desc_t& rhs) { |
| 98 | return lhs.value < rhs.value; |
| 99 | }; |
| 100 | |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 101 | for (uint64_t typeIndex = 0; typeIndex < table->count; ++typeIndex) { |
Lei Zhang | ca1bf94 | 2016-04-27 16:47:13 -0400 | [diff] [blame] | 102 | const auto& group = table->types[typeIndex]; |
| 103 | if (type != group.type) continue; |
Lei Zhang | 1ef6b19 | 2018-03-14 13:06:18 -0400 | [diff] [blame] | 104 | |
| 105 | const auto beg = group.entries; |
| 106 | const auto end = group.entries + group.count; |
| 107 | |
| 108 | // We need to loop here because there can exist multiple symbols for the |
| 109 | // same operand value, and they can be introduced in different target |
| 110 | // environments, which means they can have different minimal version |
| 111 | // requirements. For example, SubgroupEqMaskKHR can exist in any SPIR-V |
| 112 | // version as long as the SPV_KHR_shader_ballot extension is there; but |
| 113 | // starting from SPIR-V 1.3, SubgroupEqMask, which has the same numeric |
| 114 | // value as SubgroupEqMaskKHR, is available in core SPIR-V without extension |
| 115 | // requirements. |
| 116 | // Assumes the underlying table is already sorted ascendingly according to |
| 117 | // opcode value. |
alan-baker | 45fb696 | 2019-05-10 11:02:01 -0400 | [diff] [blame] | 118 | const auto version = spvVersionForTargetEnv(env); |
Lei Zhang | 1ef6b19 | 2018-03-14 13:06:18 -0400 | [diff] [blame] | 119 | for (auto it = std::lower_bound(beg, end, needle, comp); |
| 120 | it != end && it->value == value; ++it) { |
David Neto | 363bfca | 2018-06-05 23:07:51 -0700 | [diff] [blame] | 121 | // We consider the current operand as available as long as |
Lei Zhang | 1ef6b19 | 2018-03-14 13:06:18 -0400 | [diff] [blame] | 122 | // 1. The target environment satisfies the minimal requirement of the |
| 123 | // operand; or |
David Neto | 363bfca | 2018-06-05 23:07:51 -0700 | [diff] [blame] | 124 | // 2. There is at least one extension enabling this operand; or |
| 125 | // 3. There is at least one capability enabling this operand. |
Lei Zhang | 1ef6b19 | 2018-03-14 13:06:18 -0400 | [diff] [blame] | 126 | // |
| 127 | // Note that the second rule assumes the extension enabling this operand |
| 128 | // is indeed requested in the SPIR-V code; checking that should be |
| 129 | // validator's work. |
alan-baker | 45fb696 | 2019-05-10 11:02:01 -0400 | [diff] [blame] | 130 | if ((version >= it->minVersion && version <= it->lastVersion) || |
David Neto | 363bfca | 2018-06-05 23:07:51 -0700 | [diff] [blame] | 131 | it->numExtensions > 0u || it->numCapabilities > 0u) { |
Lei Zhang | 1ef6b19 | 2018-03-14 13:06:18 -0400 | [diff] [blame] | 132 | *pEntry = it; |
Lei Zhang | ca1bf94 | 2016-04-27 16:47:13 -0400 | [diff] [blame] | 133 | return SPV_SUCCESS; |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 134 | } |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | return SPV_ERROR_INVALID_LOOKUP; |
| 139 | } |
| 140 | |
Dejan Mircevski | 50babb2 | 2015-09-29 10:56:32 -0400 | [diff] [blame] | 141 | const char* spvOperandTypeStr(spv_operand_type_t type) { |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 142 | switch (type) { |
| 143 | case SPV_OPERAND_TYPE_ID: |
David Neto | fadbf62 | 2015-09-14 17:07:11 -0400 | [diff] [blame] | 144 | case SPV_OPERAND_TYPE_OPTIONAL_ID: |
David Neto | fadbf62 | 2015-09-14 17:07:11 -0400 | [diff] [blame] | 145 | return "ID"; |
David Neto | 201caf7 | 2015-11-04 17:38:17 -0500 | [diff] [blame] | 146 | case SPV_OPERAND_TYPE_TYPE_ID: |
| 147 | return "type ID"; |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 148 | case SPV_OPERAND_TYPE_RESULT_ID: |
| 149 | return "result ID"; |
Lei Zhang | 6483bd7 | 2015-10-14 17:02:39 -0400 | [diff] [blame] | 150 | case SPV_OPERAND_TYPE_LITERAL_INTEGER: |
David Neto | 201caf7 | 2015-11-04 17:38:17 -0500 | [diff] [blame] | 151 | case SPV_OPERAND_TYPE_OPTIONAL_LITERAL_INTEGER: |
| 152 | case SPV_OPERAND_TYPE_OPTIONAL_LITERAL_NUMBER: |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 153 | return "literal number"; |
David Neto | 201caf7 | 2015-11-04 17:38:17 -0500 | [diff] [blame] | 154 | case SPV_OPERAND_TYPE_OPTIONAL_TYPED_LITERAL_INTEGER: |
| 155 | return "possibly multi-word literal integer"; |
| 156 | case SPV_OPERAND_TYPE_TYPED_LITERAL_NUMBER: |
| 157 | return "possibly multi-word literal number"; |
| 158 | case SPV_OPERAND_TYPE_EXTENSION_INSTRUCTION_NUMBER: |
| 159 | return "extension instruction number"; |
David Neto | 0f166be | 2015-11-11 01:56:49 -0500 | [diff] [blame] | 160 | case SPV_OPERAND_TYPE_SPEC_CONSTANT_OP_NUMBER: |
| 161 | return "OpSpecConstantOp opcode"; |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 162 | case SPV_OPERAND_TYPE_LITERAL_STRING: |
David Neto | 201caf7 | 2015-11-04 17:38:17 -0500 | [diff] [blame] | 163 | case SPV_OPERAND_TYPE_OPTIONAL_LITERAL_STRING: |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 164 | return "literal string"; |
| 165 | case SPV_OPERAND_TYPE_SOURCE_LANGUAGE: |
Dejan Mircevski | d2c81cf | 2015-10-09 11:06:10 -0400 | [diff] [blame] | 166 | return "source language"; |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 167 | case SPV_OPERAND_TYPE_EXECUTION_MODEL: |
| 168 | return "execution model"; |
| 169 | case SPV_OPERAND_TYPE_ADDRESSING_MODEL: |
| 170 | return "addressing model"; |
| 171 | case SPV_OPERAND_TYPE_MEMORY_MODEL: |
| 172 | return "memory model"; |
| 173 | case SPV_OPERAND_TYPE_EXECUTION_MODE: |
| 174 | return "execution mode"; |
| 175 | case SPV_OPERAND_TYPE_STORAGE_CLASS: |
| 176 | return "storage class"; |
| 177 | case SPV_OPERAND_TYPE_DIMENSIONALITY: |
| 178 | return "dimensionality"; |
| 179 | case SPV_OPERAND_TYPE_SAMPLER_ADDRESSING_MODE: |
David Neto | d9ad050 | 2015-11-24 18:37:24 -0500 | [diff] [blame] | 180 | return "sampler addressing mode"; |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 181 | case SPV_OPERAND_TYPE_SAMPLER_FILTER_MODE: |
| 182 | return "sampler filter mode"; |
David Neto | b30a0c5 | 2015-09-16 15:56:43 -0400 | [diff] [blame] | 183 | case SPV_OPERAND_TYPE_SAMPLER_IMAGE_FORMAT: |
Dejan Mircevski | 971b344 | 2015-10-13 12:54:47 -0400 | [diff] [blame] | 184 | return "image format"; |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 185 | case SPV_OPERAND_TYPE_FP_FAST_MATH_MODE: |
Dejan Mircevski | 355cc0c | 2015-10-13 15:02:03 -0400 | [diff] [blame] | 186 | return "floating-point fast math mode"; |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 187 | case SPV_OPERAND_TYPE_FP_ROUNDING_MODE: |
Dejan Mircevski | 355cc0c | 2015-10-13 15:02:03 -0400 | [diff] [blame] | 188 | return "floating-point rounding mode"; |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 189 | case SPV_OPERAND_TYPE_LINKAGE_TYPE: |
| 190 | return "linkage type"; |
| 191 | case SPV_OPERAND_TYPE_ACCESS_QUALIFIER: |
David Neto | 2889a0c | 2016-02-15 13:50:00 -0500 | [diff] [blame] | 192 | case SPV_OPERAND_TYPE_OPTIONAL_ACCESS_QUALIFIER: |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 193 | return "access qualifier"; |
| 194 | case SPV_OPERAND_TYPE_FUNCTION_PARAMETER_ATTRIBUTE: |
| 195 | return "function parameter attribute"; |
| 196 | case SPV_OPERAND_TYPE_DECORATION: |
| 197 | return "decoration"; |
| 198 | case SPV_OPERAND_TYPE_BUILT_IN: |
Dejan Mircevski | d7b0f83 | 2015-10-13 15:39:38 -0400 | [diff] [blame] | 199 | return "built-in"; |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 200 | case SPV_OPERAND_TYPE_SELECTION_CONTROL: |
| 201 | return "selection control"; |
| 202 | case SPV_OPERAND_TYPE_LOOP_CONTROL: |
| 203 | return "loop control"; |
| 204 | case SPV_OPERAND_TYPE_FUNCTION_CONTROL: |
| 205 | return "function control"; |
David Neto | 64a9be9 | 2015-11-18 15:48:32 -0500 | [diff] [blame] | 206 | case SPV_OPERAND_TYPE_MEMORY_SEMANTICS_ID: |
David Neto | d9ad050 | 2015-11-24 18:37:24 -0500 | [diff] [blame] | 207 | return "memory semantics ID"; |
David Neto | 201caf7 | 2015-11-04 17:38:17 -0500 | [diff] [blame] | 208 | case SPV_OPERAND_TYPE_MEMORY_ACCESS: |
David Neto | 78c3b43 | 2015-08-27 13:03:52 -0400 | [diff] [blame] | 209 | case SPV_OPERAND_TYPE_OPTIONAL_MEMORY_ACCESS: |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 210 | return "memory access"; |
David Neto | 64a9be9 | 2015-11-18 15:48:32 -0500 | [diff] [blame] | 211 | case SPV_OPERAND_TYPE_SCOPE_ID: |
David Neto | d9ad050 | 2015-11-24 18:37:24 -0500 | [diff] [blame] | 212 | return "scope ID"; |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 213 | case SPV_OPERAND_TYPE_GROUP_OPERATION: |
| 214 | return "group operation"; |
| 215 | case SPV_OPERAND_TYPE_KERNEL_ENQ_FLAGS: |
| 216 | return "kernel enqeue flags"; |
David Neto | 4799482 | 2015-08-27 13:11:01 -0400 | [diff] [blame] | 217 | case SPV_OPERAND_TYPE_KERNEL_PROFILING_INFO: |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 218 | return "kernel profiling info"; |
| 219 | case SPV_OPERAND_TYPE_CAPABILITY: |
| 220 | return "capability"; |
Daniel Koch | 5a97e3a | 2020-03-17 15:30:19 -0400 | [diff] [blame^] | 221 | case SPV_OPERAND_TYPE_RAY_FLAGS: |
| 222 | return "ray flags"; |
| 223 | case SPV_OPERAND_TYPE_RAY_QUERY_INTERSECTION: |
| 224 | return "ray query intersection"; |
| 225 | case SPV_OPERAND_TYPE_RAY_QUERY_COMMITTED_INTERSECTION_TYPE: |
| 226 | return "ray query committed intersection type"; |
| 227 | case SPV_OPERAND_TYPE_RAY_QUERY_CANDIDATE_INTERSECTION_TYPE: |
| 228 | return "ray query candidate intersection type"; |
David Neto | 201caf7 | 2015-11-04 17:38:17 -0500 | [diff] [blame] | 229 | case SPV_OPERAND_TYPE_IMAGE: |
David Neto | ee1b3bb | 2015-09-18 11:19:18 -0400 | [diff] [blame] | 230 | case SPV_OPERAND_TYPE_OPTIONAL_IMAGE: |
David Neto | d9ad050 | 2015-11-24 18:37:24 -0500 | [diff] [blame] | 231 | return "image"; |
David Neto | 201caf7 | 2015-11-04 17:38:17 -0500 | [diff] [blame] | 232 | case SPV_OPERAND_TYPE_OPTIONAL_CIV: |
| 233 | return "context-insensitive value"; |
David Neto | 59de610 | 2017-12-03 12:30:08 -0500 | [diff] [blame] | 234 | case SPV_OPERAND_TYPE_DEBUG_INFO_FLAGS: |
| 235 | return "debug info flags"; |
| 236 | case SPV_OPERAND_TYPE_DEBUG_BASE_TYPE_ATTRIBUTE_ENCODING: |
| 237 | return "debug base type encoding"; |
| 238 | case SPV_OPERAND_TYPE_DEBUG_COMPOSITE_TYPE: |
| 239 | return "debug composite type"; |
| 240 | case SPV_OPERAND_TYPE_DEBUG_TYPE_QUALIFIER: |
| 241 | return "debug type qualifier"; |
| 242 | case SPV_OPERAND_TYPE_DEBUG_OPERATION: |
| 243 | return "debug operation"; |
David Neto | 64f36ea | 2019-12-19 17:16:26 -0500 | [diff] [blame] | 244 | case SPV_OPERAND_TYPE_CLDEBUG100_DEBUG_INFO_FLAGS: |
| 245 | return "OpenCL.DebugInfo.100 debug info flags"; |
| 246 | case SPV_OPERAND_TYPE_CLDEBUG100_DEBUG_BASE_TYPE_ATTRIBUTE_ENCODING: |
| 247 | return "OpenCL.DebugInfo.100 debug base type encoding"; |
| 248 | case SPV_OPERAND_TYPE_CLDEBUG100_DEBUG_COMPOSITE_TYPE: |
| 249 | return "OpenCL.DebugInfo.100 debug composite type"; |
| 250 | case SPV_OPERAND_TYPE_CLDEBUG100_DEBUG_TYPE_QUALIFIER: |
| 251 | return "OpenCL.DebugInfo.100 debug type qualifier"; |
| 252 | case SPV_OPERAND_TYPE_CLDEBUG100_DEBUG_OPERATION: |
| 253 | return "OpenCL.DebugInfo.100 debug operation"; |
| 254 | case SPV_OPERAND_TYPE_CLDEBUG100_DEBUG_IMPORTED_ENTITY: |
| 255 | return "OpenCL.DebugInfo.100 debug imported entity"; |
David Neto | 201caf7 | 2015-11-04 17:38:17 -0500 | [diff] [blame] | 256 | |
| 257 | // The next values are for values returned from an instruction, not actually |
| 258 | // an operand. So the specific strings don't matter. But let's add them |
| 259 | // for completeness and ease of testing. |
| 260 | case SPV_OPERAND_TYPE_IMAGE_CHANNEL_ORDER: |
| 261 | return "image channel order"; |
| 262 | case SPV_OPERAND_TYPE_IMAGE_CHANNEL_DATA_TYPE: |
| 263 | return "image channel data type"; |
| 264 | |
David Neto | 78c3b43 | 2015-08-27 13:03:52 -0400 | [diff] [blame] | 265 | case SPV_OPERAND_TYPE_NONE: |
| 266 | return "NONE"; |
Kenneth Benzie (Benie) | 83e5a29 | 2015-05-22 18:26:19 +0100 | [diff] [blame] | 267 | default: |
| 268 | assert(0 && "Unhandled operand type!"); |
| 269 | break; |
| 270 | } |
| 271 | return "unknown"; |
| 272 | } |
David Neto | 78c3b43 | 2015-08-27 13:03:52 -0400 | [diff] [blame] | 273 | |
Chris Forbes | 78338d5 | 2017-06-27 16:28:22 -0700 | [diff] [blame] | 274 | void spvPushOperandTypes(const spv_operand_type_t* types, |
| 275 | spv_operand_pattern_t* pattern) { |
David Neto | 78c3b43 | 2015-08-27 13:03:52 -0400 | [diff] [blame] | 276 | const spv_operand_type_t* endTypes; |
dan sinclair | 84846b7 | 2018-07-10 13:09:46 -0400 | [diff] [blame] | 277 | for (endTypes = types; *endTypes != SPV_OPERAND_TYPE_NONE; ++endTypes) { |
| 278 | } |
| 279 | |
Chris Forbes | 78338d5 | 2017-06-27 16:28:22 -0700 | [diff] [blame] | 280 | while (endTypes-- != types) { |
Lei Zhang | 16981f8 | 2017-09-21 17:24:57 -0400 | [diff] [blame] | 281 | pattern->push_back(*endTypes); |
Chris Forbes | 78338d5 | 2017-06-27 16:28:22 -0700 | [diff] [blame] | 282 | } |
David Neto | 78c3b43 | 2015-08-27 13:03:52 -0400 | [diff] [blame] | 283 | } |
| 284 | |
Lei Zhang | 1ef6b19 | 2018-03-14 13:06:18 -0400 | [diff] [blame] | 285 | void spvPushOperandTypesForMask(spv_target_env env, |
| 286 | const spv_operand_table operandTable, |
Chris Forbes | 78338d5 | 2017-06-27 16:28:22 -0700 | [diff] [blame] | 287 | const spv_operand_type_t type, |
| 288 | const uint32_t mask, |
| 289 | spv_operand_pattern_t* pattern) { |
| 290 | // Scan from highest bits to lowest bits because we will append in LIFO |
| 291 | // fashion, and we need the operands for lower order bits to be consumed first |
Lei Zhang | 16981f8 | 2017-09-21 17:24:57 -0400 | [diff] [blame] | 292 | for (uint32_t candidate_bit = (1u << 31u); candidate_bit; |
| 293 | candidate_bit >>= 1) { |
David Neto | 5bf88fc | 2015-09-17 17:06:10 -0400 | [diff] [blame] | 294 | if (candidate_bit & mask) { |
| 295 | spv_operand_desc entry = nullptr; |
Lei Zhang | 1ef6b19 | 2018-03-14 13:06:18 -0400 | [diff] [blame] | 296 | if (SPV_SUCCESS == spvOperandTableValueLookup(env, operandTable, type, |
David Neto | 5bf88fc | 2015-09-17 17:06:10 -0400 | [diff] [blame] | 297 | candidate_bit, &entry)) { |
Chris Forbes | 78338d5 | 2017-06-27 16:28:22 -0700 | [diff] [blame] | 298 | spvPushOperandTypes(entry->operandTypes, pattern); |
David Neto | 5bf88fc | 2015-09-17 17:06:10 -0400 | [diff] [blame] | 299 | } |
| 300 | } |
| 301 | } |
| 302 | } |
| 303 | |
David Neto | 0dbe184 | 2017-12-03 14:26:16 -0500 | [diff] [blame] | 304 | bool spvOperandIsConcrete(spv_operand_type_t type) { |
| 305 | if (spvIsIdType(type) || spvOperandIsConcreteMask(type)) { |
| 306 | return true; |
| 307 | } |
| 308 | switch (type) { |
| 309 | case SPV_OPERAND_TYPE_LITERAL_INTEGER: |
| 310 | case SPV_OPERAND_TYPE_EXTENSION_INSTRUCTION_NUMBER: |
| 311 | case SPV_OPERAND_TYPE_SPEC_CONSTANT_OP_NUMBER: |
| 312 | case SPV_OPERAND_TYPE_TYPED_LITERAL_NUMBER: |
| 313 | case SPV_OPERAND_TYPE_LITERAL_STRING: |
| 314 | case SPV_OPERAND_TYPE_SOURCE_LANGUAGE: |
| 315 | case SPV_OPERAND_TYPE_EXECUTION_MODEL: |
| 316 | case SPV_OPERAND_TYPE_ADDRESSING_MODEL: |
| 317 | case SPV_OPERAND_TYPE_MEMORY_MODEL: |
| 318 | case SPV_OPERAND_TYPE_EXECUTION_MODE: |
| 319 | case SPV_OPERAND_TYPE_STORAGE_CLASS: |
| 320 | case SPV_OPERAND_TYPE_DIMENSIONALITY: |
| 321 | case SPV_OPERAND_TYPE_SAMPLER_ADDRESSING_MODE: |
| 322 | case SPV_OPERAND_TYPE_SAMPLER_FILTER_MODE: |
| 323 | case SPV_OPERAND_TYPE_SAMPLER_IMAGE_FORMAT: |
| 324 | case SPV_OPERAND_TYPE_IMAGE_CHANNEL_ORDER: |
| 325 | case SPV_OPERAND_TYPE_IMAGE_CHANNEL_DATA_TYPE: |
| 326 | case SPV_OPERAND_TYPE_FP_ROUNDING_MODE: |
| 327 | case SPV_OPERAND_TYPE_LINKAGE_TYPE: |
| 328 | case SPV_OPERAND_TYPE_ACCESS_QUALIFIER: |
| 329 | case SPV_OPERAND_TYPE_FUNCTION_PARAMETER_ATTRIBUTE: |
| 330 | case SPV_OPERAND_TYPE_DECORATION: |
| 331 | case SPV_OPERAND_TYPE_BUILT_IN: |
| 332 | case SPV_OPERAND_TYPE_GROUP_OPERATION: |
| 333 | case SPV_OPERAND_TYPE_KERNEL_ENQ_FLAGS: |
| 334 | case SPV_OPERAND_TYPE_KERNEL_PROFILING_INFO: |
| 335 | case SPV_OPERAND_TYPE_CAPABILITY: |
Daniel Koch | 5a97e3a | 2020-03-17 15:30:19 -0400 | [diff] [blame^] | 336 | case SPV_OPERAND_TYPE_RAY_FLAGS: |
| 337 | case SPV_OPERAND_TYPE_RAY_QUERY_INTERSECTION: |
| 338 | case SPV_OPERAND_TYPE_RAY_QUERY_COMMITTED_INTERSECTION_TYPE: |
| 339 | case SPV_OPERAND_TYPE_RAY_QUERY_CANDIDATE_INTERSECTION_TYPE: |
David Neto | 59de610 | 2017-12-03 12:30:08 -0500 | [diff] [blame] | 340 | case SPV_OPERAND_TYPE_DEBUG_BASE_TYPE_ATTRIBUTE_ENCODING: |
| 341 | case SPV_OPERAND_TYPE_DEBUG_COMPOSITE_TYPE: |
| 342 | case SPV_OPERAND_TYPE_DEBUG_TYPE_QUALIFIER: |
| 343 | case SPV_OPERAND_TYPE_DEBUG_OPERATION: |
David Neto | 64f36ea | 2019-12-19 17:16:26 -0500 | [diff] [blame] | 344 | case SPV_OPERAND_TYPE_CLDEBUG100_DEBUG_BASE_TYPE_ATTRIBUTE_ENCODING: |
| 345 | case SPV_OPERAND_TYPE_CLDEBUG100_DEBUG_COMPOSITE_TYPE: |
| 346 | case SPV_OPERAND_TYPE_CLDEBUG100_DEBUG_TYPE_QUALIFIER: |
| 347 | case SPV_OPERAND_TYPE_CLDEBUG100_DEBUG_OPERATION: |
| 348 | case SPV_OPERAND_TYPE_CLDEBUG100_DEBUG_IMPORTED_ENTITY: |
David Neto | 0dbe184 | 2017-12-03 14:26:16 -0500 | [diff] [blame] | 349 | return true; |
| 350 | default: |
| 351 | break; |
| 352 | } |
| 353 | return false; |
| 354 | } |
| 355 | |
David Neto | b526756 | 2016-02-02 12:05:34 -0500 | [diff] [blame] | 356 | bool spvOperandIsConcreteMask(spv_operand_type_t type) { |
David Neto | 0dbe184 | 2017-12-03 14:26:16 -0500 | [diff] [blame] | 357 | switch (type) { |
| 358 | case SPV_OPERAND_TYPE_IMAGE: |
| 359 | case SPV_OPERAND_TYPE_FP_FAST_MATH_MODE: |
| 360 | case SPV_OPERAND_TYPE_SELECTION_CONTROL: |
| 361 | case SPV_OPERAND_TYPE_LOOP_CONTROL: |
| 362 | case SPV_OPERAND_TYPE_FUNCTION_CONTROL: |
| 363 | case SPV_OPERAND_TYPE_MEMORY_ACCESS: |
David Neto | 59de610 | 2017-12-03 12:30:08 -0500 | [diff] [blame] | 364 | case SPV_OPERAND_TYPE_DEBUG_INFO_FLAGS: |
David Neto | 64f36ea | 2019-12-19 17:16:26 -0500 | [diff] [blame] | 365 | case SPV_OPERAND_TYPE_CLDEBUG100_DEBUG_INFO_FLAGS: |
David Neto | 0dbe184 | 2017-12-03 14:26:16 -0500 | [diff] [blame] | 366 | return true; |
| 367 | default: |
| 368 | break; |
| 369 | } |
| 370 | return false; |
David Neto | b526756 | 2016-02-02 12:05:34 -0500 | [diff] [blame] | 371 | } |
| 372 | |
David Neto | 78c3b43 | 2015-08-27 13:03:52 -0400 | [diff] [blame] | 373 | bool spvOperandIsOptional(spv_operand_type_t type) { |
David Neto | 201caf7 | 2015-11-04 17:38:17 -0500 | [diff] [blame] | 374 | return SPV_OPERAND_TYPE_FIRST_OPTIONAL_TYPE <= type && |
| 375 | type <= SPV_OPERAND_TYPE_LAST_OPTIONAL_TYPE; |
David Neto | 78c3b43 | 2015-08-27 13:03:52 -0400 | [diff] [blame] | 376 | } |
| 377 | |
| 378 | bool spvOperandIsVariable(spv_operand_type_t type) { |
David Neto | 201caf7 | 2015-11-04 17:38:17 -0500 | [diff] [blame] | 379 | return SPV_OPERAND_TYPE_FIRST_VARIABLE_TYPE <= type && |
| 380 | type <= SPV_OPERAND_TYPE_LAST_VARIABLE_TYPE; |
David Neto | 78c3b43 | 2015-08-27 13:03:52 -0400 | [diff] [blame] | 381 | } |
| 382 | |
David Neto | 78c3b43 | 2015-08-27 13:03:52 -0400 | [diff] [blame] | 383 | bool spvExpandOperandSequenceOnce(spv_operand_type_t type, |
| 384 | spv_operand_pattern_t* pattern) { |
| 385 | switch (type) { |
| 386 | case SPV_OPERAND_TYPE_VARIABLE_ID: |
Chris Forbes | 78338d5 | 2017-06-27 16:28:22 -0700 | [diff] [blame] | 387 | pattern->push_back(type); |
| 388 | pattern->push_back(SPV_OPERAND_TYPE_OPTIONAL_ID); |
David Neto | 78c3b43 | 2015-08-27 13:03:52 -0400 | [diff] [blame] | 389 | return true; |
Lei Zhang | 6483bd7 | 2015-10-14 17:02:39 -0400 | [diff] [blame] | 390 | case SPV_OPERAND_TYPE_VARIABLE_LITERAL_INTEGER: |
Chris Forbes | 78338d5 | 2017-06-27 16:28:22 -0700 | [diff] [blame] | 391 | pattern->push_back(type); |
| 392 | pattern->push_back(SPV_OPERAND_TYPE_OPTIONAL_LITERAL_INTEGER); |
David Neto | 78c3b43 | 2015-08-27 13:03:52 -0400 | [diff] [blame] | 393 | return true; |
Lei Zhang | 6483bd7 | 2015-10-14 17:02:39 -0400 | [diff] [blame] | 394 | case SPV_OPERAND_TYPE_VARIABLE_LITERAL_INTEGER_ID: |
David Neto | 201caf7 | 2015-11-04 17:38:17 -0500 | [diff] [blame] | 395 | // Represents Zero or more (Literal number, Id) pairs, |
| 396 | // where the literal number must be a scalar integer. |
Chris Forbes | 78338d5 | 2017-06-27 16:28:22 -0700 | [diff] [blame] | 397 | pattern->push_back(type); |
| 398 | pattern->push_back(SPV_OPERAND_TYPE_ID); |
| 399 | pattern->push_back(SPV_OPERAND_TYPE_OPTIONAL_TYPED_LITERAL_INTEGER); |
David Neto | 78c3b43 | 2015-08-27 13:03:52 -0400 | [diff] [blame] | 400 | return true; |
Lei Zhang | 6483bd7 | 2015-10-14 17:02:39 -0400 | [diff] [blame] | 401 | case SPV_OPERAND_TYPE_VARIABLE_ID_LITERAL_INTEGER: |
David Neto | 561dc4e | 2015-09-25 14:23:29 -0400 | [diff] [blame] | 402 | // Represents Zero or more (Id, Literal number) pairs. |
Chris Forbes | 78338d5 | 2017-06-27 16:28:22 -0700 | [diff] [blame] | 403 | pattern->push_back(type); |
| 404 | pattern->push_back(SPV_OPERAND_TYPE_LITERAL_INTEGER); |
| 405 | pattern->push_back(SPV_OPERAND_TYPE_OPTIONAL_ID); |
David Neto | 78c3b43 | 2015-08-27 13:03:52 -0400 | [diff] [blame] | 406 | return true; |
David Neto | 78c3b43 | 2015-08-27 13:03:52 -0400 | [diff] [blame] | 407 | default: |
| 408 | break; |
| 409 | } |
| 410 | return false; |
| 411 | } |
| 412 | |
Dejan Mircevski | 50babb2 | 2015-09-29 10:56:32 -0400 | [diff] [blame] | 413 | spv_operand_type_t spvTakeFirstMatchableOperand( |
| 414 | spv_operand_pattern_t* pattern) { |
David Neto | 78c3b43 | 2015-08-27 13:03:52 -0400 | [diff] [blame] | 415 | assert(!pattern->empty()); |
| 416 | spv_operand_type_t result; |
| 417 | do { |
Chris Forbes | 78338d5 | 2017-06-27 16:28:22 -0700 | [diff] [blame] | 418 | result = pattern->back(); |
| 419 | pattern->pop_back(); |
Dejan Mircevski | 50babb2 | 2015-09-29 10:56:32 -0400 | [diff] [blame] | 420 | } while (spvExpandOperandSequenceOnce(result, pattern)); |
David Neto | 78c3b43 | 2015-08-27 13:03:52 -0400 | [diff] [blame] | 421 | return result; |
| 422 | } |
Dejan Mircevski | 903f9d6 | 2015-09-28 17:04:39 -0400 | [diff] [blame] | 423 | |
Dejan Mircevski | 897bff9 | 2015-09-29 10:38:18 -0400 | [diff] [blame] | 424 | spv_operand_pattern_t spvAlternatePatternFollowingImmediate( |
| 425 | const spv_operand_pattern_t& pattern) { |
Lei Zhang | 16981f8 | 2017-09-21 17:24:57 -0400 | [diff] [blame] | 426 | auto it = |
| 427 | std::find(pattern.crbegin(), pattern.crend(), SPV_OPERAND_TYPE_RESULT_ID); |
Chris Forbes | 78338d5 | 2017-06-27 16:28:22 -0700 | [diff] [blame] | 428 | if (it != pattern.crend()) { |
Lei Zhang | 16981f8 | 2017-09-21 17:24:57 -0400 | [diff] [blame] | 429 | spv_operand_pattern_t alternatePattern(it - pattern.crbegin() + 2, |
| 430 | SPV_OPERAND_TYPE_OPTIONAL_CIV); |
Chris Forbes | 78338d5 | 2017-06-27 16:28:22 -0700 | [diff] [blame] | 431 | alternatePattern[1] = SPV_OPERAND_TYPE_RESULT_ID; |
| 432 | return alternatePattern; |
Dejan Mircevski | 903f9d6 | 2015-09-28 17:04:39 -0400 | [diff] [blame] | 433 | } |
Chris Forbes | 78338d5 | 2017-06-27 16:28:22 -0700 | [diff] [blame] | 434 | |
Dejan Mircevski | 897bff9 | 2015-09-29 10:38:18 -0400 | [diff] [blame] | 435 | // No result-id found, so just expect CIVs. |
Lei Zhang | 16981f8 | 2017-09-21 17:24:57 -0400 | [diff] [blame] | 436 | return {SPV_OPERAND_TYPE_OPTIONAL_CIV}; |
Dejan Mircevski | 903f9d6 | 2015-09-28 17:04:39 -0400 | [diff] [blame] | 437 | } |
Dejan Mircevski | 961f5dc | 2016-01-15 11:25:11 -0500 | [diff] [blame] | 438 | |
| 439 | bool spvIsIdType(spv_operand_type_t type) { |
| 440 | switch (type) { |
| 441 | case SPV_OPERAND_TYPE_ID: |
| 442 | case SPV_OPERAND_TYPE_TYPE_ID: |
| 443 | case SPV_OPERAND_TYPE_RESULT_ID: |
| 444 | case SPV_OPERAND_TYPE_MEMORY_SEMANTICS_ID: |
| 445 | case SPV_OPERAND_TYPE_SCOPE_ID: |
| 446 | return true; |
| 447 | default: |
| 448 | return false; |
| 449 | } |
Dejan Mircevski | 961f5dc | 2016-01-15 11:25:11 -0500 | [diff] [blame] | 450 | } |
Andrey Tuganov | b36acbe | 2017-08-09 14:01:12 -0400 | [diff] [blame] | 451 | |
Alastair Donaldson | 3b13040 | 2018-11-26 22:06:21 +0000 | [diff] [blame] | 452 | bool spvIsInIdType(spv_operand_type_t type) { |
| 453 | if (!spvIsIdType(type)) { |
| 454 | // If it is not an ID it cannot be an input ID. |
| 455 | return false; |
| 456 | } |
| 457 | switch (type) { |
| 458 | // Blacklist non-input IDs. |
| 459 | case SPV_OPERAND_TYPE_TYPE_ID: |
| 460 | case SPV_OPERAND_TYPE_RESULT_ID: |
| 461 | return false; |
| 462 | default: |
| 463 | return true; |
| 464 | } |
| 465 | } |
| 466 | |
Andrey Tuganov | b36acbe | 2017-08-09 14:01:12 -0400 | [diff] [blame] | 467 | std::function<bool(unsigned)> spvOperandCanBeForwardDeclaredFunction( |
| 468 | SpvOp opcode) { |
| 469 | std::function<bool(unsigned index)> out; |
| 470 | switch (opcode) { |
| 471 | case SpvOpExecutionMode: |
Lei Zhang | efcc33e | 2018-05-16 08:43:50 -0400 | [diff] [blame] | 472 | case SpvOpExecutionModeId: |
Andrey Tuganov | b36acbe | 2017-08-09 14:01:12 -0400 | [diff] [blame] | 473 | case SpvOpEntryPoint: |
| 474 | case SpvOpName: |
| 475 | case SpvOpMemberName: |
| 476 | case SpvOpSelectionMerge: |
| 477 | case SpvOpDecorate: |
| 478 | case SpvOpMemberDecorate: |
David Neto | 5f69f75 | 2018-03-05 13:34:13 -0500 | [diff] [blame] | 479 | case SpvOpDecorateId: |
| 480 | case SpvOpDecorateStringGOOGLE: |
| 481 | case SpvOpMemberDecorateStringGOOGLE: |
Andrey Tuganov | b36acbe | 2017-08-09 14:01:12 -0400 | [diff] [blame] | 482 | case SpvOpTypeStruct: |
| 483 | case SpvOpBranch: |
| 484 | case SpvOpLoopMerge: |
| 485 | out = [](unsigned) { return true; }; |
| 486 | break; |
| 487 | case SpvOpGroupDecorate: |
| 488 | case SpvOpGroupMemberDecorate: |
| 489 | case SpvOpBranchConditional: |
| 490 | case SpvOpSwitch: |
| 491 | out = [](unsigned index) { return index != 0; }; |
| 492 | break; |
| 493 | |
| 494 | case SpvOpFunctionCall: |
| 495 | // The Function parameter. |
| 496 | out = [](unsigned index) { return index == 2; }; |
| 497 | break; |
| 498 | |
| 499 | case SpvOpPhi: |
| 500 | out = [](unsigned index) { return index > 1; }; |
| 501 | break; |
| 502 | |
| 503 | case SpvOpEnqueueKernel: |
| 504 | // The Invoke parameter. |
| 505 | out = [](unsigned index) { return index == 8; }; |
| 506 | break; |
| 507 | |
| 508 | case SpvOpGetKernelNDrangeSubGroupCount: |
| 509 | case SpvOpGetKernelNDrangeMaxSubGroupSize: |
| 510 | // The Invoke parameter. |
| 511 | out = [](unsigned index) { return index == 3; }; |
| 512 | break; |
| 513 | |
| 514 | case SpvOpGetKernelWorkGroupSize: |
| 515 | case SpvOpGetKernelPreferredWorkGroupSizeMultiple: |
| 516 | // The Invoke parameter. |
| 517 | out = [](unsigned index) { return index == 2; }; |
| 518 | break; |
| 519 | case SpvOpTypeForwardPointer: |
| 520 | out = [](unsigned index) { return index == 0; }; |
| 521 | break; |
alan-baker | 899735f | 2020-01-07 13:55:46 -0500 | [diff] [blame] | 522 | case SpvOpTypeArray: |
| 523 | out = [](unsigned index) { return index == 1; }; |
| 524 | break; |
Andrey Tuganov | b36acbe | 2017-08-09 14:01:12 -0400 | [diff] [blame] | 525 | default: |
| 526 | out = [](unsigned) { return false; }; |
| 527 | break; |
| 528 | } |
| 529 | return out; |
| 530 | } |
Jaebaek Seo | dd37d73 | 2020-01-23 17:04:30 -0500 | [diff] [blame] | 531 | |
| 532 | std::function<bool(unsigned)> spvDbgInfoExtOperandCanBeForwardDeclaredFunction( |
| 533 | spv_ext_inst_type_t ext_type, uint32_t key) { |
| 534 | // TODO(https://gitlab.khronos.org/spirv/SPIR-V/issues/532): Forward |
| 535 | // references for debug info instructions are still in discussion. We must |
| 536 | // update the following lines of code when we conclude the spec. |
| 537 | std::function<bool(unsigned index)> out; |
| 538 | if (ext_type == SPV_EXT_INST_TYPE_OPENCL_DEBUGINFO_100) { |
| 539 | switch (OpenCLDebugInfo100Instructions(key)) { |
| 540 | case OpenCLDebugInfo100DebugFunction: |
| 541 | out = [](unsigned index) { return index == 13; }; |
| 542 | break; |
| 543 | case OpenCLDebugInfo100DebugTypeComposite: |
| 544 | out = [](unsigned index) { return index >= 13; }; |
| 545 | break; |
| 546 | default: |
| 547 | out = [](unsigned) { return false; }; |
| 548 | break; |
| 549 | } |
| 550 | } else { |
| 551 | switch (DebugInfoInstructions(key)) { |
| 552 | case DebugInfoDebugFunction: |
| 553 | out = [](unsigned index) { return index == 13; }; |
| 554 | break; |
| 555 | case DebugInfoDebugTypeComposite: |
| 556 | out = [](unsigned index) { return index >= 12; }; |
| 557 | break; |
| 558 | default: |
| 559 | out = [](unsigned) { return false; }; |
| 560 | break; |
| 561 | } |
| 562 | } |
| 563 | return out; |
| 564 | } |