| 161 | const opt::IRContext& linked_context); |
| 162 | |
| 163 | spv_result_t ShiftIdsInModules(const MessageConsumer& consumer, |
| 164 | std::vector<opt::Module*>* modules, |
| 165 | uint32_t* max_id_bound) { |
| 166 | spv_position_t position = {}; |
| 167 | |
| 168 | if (modules == nullptr) |
| 169 | return DiagnosticStream(position, consumer, "", SPV_ERROR_INVALID_DATA) |
| 170 | << "|modules| of ShiftIdsInModules should not be null."; |
| 171 | if (modules->empty()) |
| 172 | return DiagnosticStream(position, consumer, "", SPV_ERROR_INVALID_DATA) |
| 173 | << "|modules| of ShiftIdsInModules should not be empty."; |
| 174 | if (max_id_bound == nullptr) |
| 175 | return DiagnosticStream(position, consumer, "", SPV_ERROR_INVALID_DATA) |
| 176 | << "|max_id_bound| of ShiftIdsInModules should not be null."; |
| 177 | |
| 178 | const size_t id_bound = |
| 179 | std::accumulate(modules->begin(), modules->end(), static_cast<size_t>(1), |
| 180 | [](const size_t& accumulation, opt::Module* module) { |
| 181 | return accumulation + module->IdBound() - 1u; |
| 182 | }); |
| 183 | if (id_bound > std::numeric_limits<uint32_t>::max()) |
| 184 | return DiagnosticStream(position, consumer, "", SPV_ERROR_INVALID_DATA) |
| 185 | << "Too many IDs (" << id_bound |
| 186 | << "): combining all modules would overflow the 32-bit word of the " |
| 187 | "SPIR-V header."; |
| 188 | |
| 189 | *max_id_bound = static_cast<uint32_t>(id_bound); |
| 190 | |
| 191 | uint32_t id_offset = modules->front()->IdBound() - 1u; |
| 192 | for (auto module_iter = modules->begin() + 1; module_iter != modules->end(); |
| 193 | ++module_iter) { |
| 194 | Module* module = *module_iter; |
| 195 | module->ForEachInst([&id_offset](Instruction* insn) { |
| 196 | insn->ForEachId([&id_offset](uint32_t* id) { *id += id_offset; }); |
| 197 | }); |
| 198 | id_offset += module->IdBound() - 1u; |
| 199 | |
| 200 | // Invalidate the DefUseManager |
| 201 | module->context()->InvalidateAnalyses(opt::IRContext::kAnalysisDefUse); |
| 202 | } |
| 203 | |
| 204 | return SPV_SUCCESS; |
| 205 | } |
| 206 | |
| 207 | spv_result_t GenerateHeader(const MessageConsumer& consumer, |
| 208 | const std::vector<opt::Module*>& modules, |
no test coverage detected