1 | // Copyright (c) 2018 Google LLC. |
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 "source/val/validate.h" |
16 | |
17 | #include "source/val/function.h" |
18 | #include "source/val/validation_state.h" |
19 | |
20 | namespace spvtools { |
21 | namespace val { |
22 | |
23 | spv_result_t ValidateExecutionLimitations(ValidationState_t& _, |
24 | const Instruction* inst) { |
25 | if (inst->opcode() != SpvOpFunction) { |
26 | return SPV_SUCCESS; |
27 | } |
28 | |
29 | const auto func = _.function(inst->id()); |
30 | if (!func) { |
31 | return _.diag(SPV_ERROR_INTERNAL, inst) |
32 | << "Internal error: missing function id " << inst->id() << "." ; |
33 | } |
34 | |
35 | for (uint32_t entry_id : _.FunctionEntryPoints(inst->id())) { |
36 | const auto* models = _.GetExecutionModels(entry_id); |
37 | if (models) { |
38 | if (models->empty()) { |
39 | return _.diag(SPV_ERROR_INTERNAL, inst) |
40 | << "Internal error: empty execution models for function id " |
41 | << entry_id << "." ; |
42 | } |
43 | for (const auto model : *models) { |
44 | std::string reason; |
45 | if (!func->IsCompatibleWithExecutionModel(model, &reason)) { |
46 | return _.diag(SPV_ERROR_INVALID_ID, inst) |
47 | << "OpEntryPoint Entry Point <id> '" << _.getIdName(entry_id) |
48 | << "'s callgraph contains function <id> " |
49 | << _.getIdName(inst->id()) |
50 | << ", which cannot be used with the current execution " |
51 | "model:\n" |
52 | << reason; |
53 | } |
54 | } |
55 | } |
56 | |
57 | std::string reason; |
58 | if (!func->CheckLimitations(_, _.function(entry_id), &reason)) { |
59 | return _.diag(SPV_ERROR_INVALID_ID, inst) |
60 | << "OpEntryPoint Entry Point <id> '" << _.getIdName(entry_id) |
61 | << "'s callgraph contains function <id> " |
62 | << _.getIdName(inst->id()) |
63 | << ", which cannot be used with the current execution " |
64 | "modes:\n" |
65 | << reason; |
66 | } |
67 | } |
68 | return SPV_SUCCESS; |
69 | } |
70 | |
71 | } // namespace val |
72 | } // namespace spvtools |
73 | |