validate_execution_limitations.cpp 2.0 KB

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