use_starpu_unlikely.cocci 1.4 KB

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