function_utils.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // Copyright (c) 2017 Google Inc.
  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. #ifndef TEST_OPT_FUNCTION_UTILS_H_
  15. #define TEST_OPT_FUNCTION_UTILS_H_
  16. #include "source/opt/function.h"
  17. #include "source/opt/module.h"
  18. namespace spvtest {
  19. inline spvtools::opt::Function* GetFunction(spvtools::opt::Module* module,
  20. uint32_t id) {
  21. for (spvtools::opt::Function& f : *module) {
  22. if (f.result_id() == id) {
  23. return &f;
  24. }
  25. }
  26. return nullptr;
  27. }
  28. inline const spvtools::opt::Function* GetFunction(
  29. const spvtools::opt::Module* module, uint32_t id) {
  30. for (const spvtools::opt::Function& f : *module) {
  31. if (f.result_id() == id) {
  32. return &f;
  33. }
  34. }
  35. return nullptr;
  36. }
  37. inline const spvtools::opt::BasicBlock* GetBasicBlock(
  38. const spvtools::opt::Function* fn, uint32_t id) {
  39. for (const spvtools::opt::BasicBlock& bb : *fn) {
  40. if (bb.id() == id) {
  41. return &bb;
  42. }
  43. }
  44. return nullptr;
  45. }
  46. } // namespace spvtest
  47. #endif // TEST_OPT_FUNCTION_UTILS_H_