use_starpu_unlikely.cocci 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // StarPU --- Runtime system for heterogeneous multicore architectures.
  2. //
  3. // Copyright (C) 2012 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. // OpenCL and CUDA functions are not very likely to fail, so we probably want
  16. // to use branch predictions when checking their return value. This Coccinelle
  17. // script tries to find places where this can be done.
  18. virtual context
  19. virtual org
  20. virtual patch
  21. virtual report
  22. @r@
  23. identifier ret;
  24. statement S;
  25. position p;
  26. @@
  27. if@p(
  28. (
  29. ret != CL_SUCCESS
  30. |
  31. ret != cudaSuccess
  32. )
  33. ) S
  34. @depends on context@
  35. position r.p;
  36. statement r.S;
  37. @@
  38. * if @p(...)
  39. S
  40. @script:python depends on org@
  41. p << r.p;
  42. @@
  43. coccilib.org.print_todo(p[0], "Use STARPU_UNLIKELY")
  44. @depends on patch@
  45. position r.p;
  46. expression E;
  47. statement r.S;
  48. @@
  49. - if@p(E)
  50. + if (STARPU_UNLIKELY(E))
  51. S
  52. @script:python depends on report@
  53. p << r.p;
  54. @@
  55. coccilib.report.print_report(p[0], "Use STARPU_UNLIKELY")