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