use_starpu_unlikely.cocci 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2012 Inria
  4. * Copyright (C) 2012,2015,2017 CNRS
  5. *
  6. * StarPU is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU Lesser General Public License as published by
  8. * the Free Software Foundation; either version 2.1 of the License, or (at
  9. * your option) any later version.
  10. *
  11. * StarPU is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  14. *
  15. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  16. */
  17. // OpenCL and CUDA functions are not very likely to fail, so we probably want
  18. // to use branch predictions when checking their return value. This Coccinelle
  19. // script tries to find places where this can be done.
  20. virtual context
  21. virtual org
  22. virtual patch
  23. virtual report
  24. @r@
  25. identifier ret;
  26. statement S;
  27. position p;
  28. @@
  29. if@p(
  30. (
  31. ret != CL_SUCCESS
  32. |
  33. ret != cudaSuccess
  34. )
  35. ) S
  36. @depends on context@
  37. position r.p;
  38. statement r.S;
  39. @@
  40. * if @p(...)
  41. S
  42. @script:python depends on org@
  43. p << r.p;
  44. @@
  45. coccilib.org.print_todo(p[0], "Use STARPU_UNLIKELY")
  46. @depends on patch@
  47. position r.p;
  48. expression E;
  49. statement r.S;
  50. @@
  51. - if@p(E)
  52. + if (STARPU_UNLIKELY(E))
  53. S
  54. @script:python depends on report@
  55. p << r.p;
  56. @@
  57. coccilib.report.print_report(p[0], "Use STARPU_UNLIKELY")