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