gimple-predict.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /* Gimple prediction routines.
  2. Copyright (C) 2007-2019 Free Software Foundation, Inc.
  3. This file is part of GCC.
  4. GCC is free software; you can redistribute it and/or modify it under
  5. the terms of the GNU General Public License as published by the Free
  6. Software Foundation; either version 3, or (at your option) any later
  7. version.
  8. GCC is distributed in the hope that it will be useful, but WITHOUT ANY
  9. WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  11. for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GCC; see the file COPYING3. If not see
  14. <http://www.gnu.org/licenses/>. */
  15. #ifndef GCC_GIMPLE_PREDICT_H
  16. #define GCC_GIMPLE_PREDICT_H
  17. #include "predict.h"
  18. /* Return the predictor of GIMPLE_PREDICT statement GS. */
  19. static inline enum br_predictor
  20. gimple_predict_predictor (gimple *gs)
  21. {
  22. GIMPLE_CHECK (gs, GIMPLE_PREDICT);
  23. return (enum br_predictor) (gs->subcode & ~GF_PREDICT_TAKEN);
  24. }
  25. /* Set the predictor of GIMPLE_PREDICT statement GS to PREDICT. */
  26. static inline void
  27. gimple_predict_set_predictor (gimple *gs, enum br_predictor predictor)
  28. {
  29. GIMPLE_CHECK (gs, GIMPLE_PREDICT);
  30. gs->subcode = (gs->subcode & GF_PREDICT_TAKEN)
  31. | (unsigned) predictor;
  32. }
  33. /* Return the outcome of GIMPLE_PREDICT statement GS. */
  34. static inline enum prediction
  35. gimple_predict_outcome (gimple *gs)
  36. {
  37. GIMPLE_CHECK (gs, GIMPLE_PREDICT);
  38. return (gs->subcode & GF_PREDICT_TAKEN) ? TAKEN : NOT_TAKEN;
  39. }
  40. /* Set the outcome of GIMPLE_PREDICT statement GS to OUTCOME. */
  41. static inline void
  42. gimple_predict_set_outcome (gimple *gs, enum prediction outcome)
  43. {
  44. GIMPLE_CHECK (gs, GIMPLE_PREDICT);
  45. if (outcome == TAKEN)
  46. gs->subcode |= GF_PREDICT_TAKEN;
  47. else
  48. gs->subcode &= ~GF_PREDICT_TAKEN;
  49. }
  50. /* Build a GIMPLE_PREDICT statement. PREDICT is one of the predictors from
  51. predict.def, OUTCOME is NOT_TAKEN or TAKEN. */
  52. inline gimple *
  53. gimple_build_predict (enum br_predictor predictor, enum prediction outcome)
  54. {
  55. gimple *p = gimple_alloc (GIMPLE_PREDICT, 0);
  56. /* Ensure all the predictors fit into the lower bits of the subcode. */
  57. gcc_assert ((int) END_PREDICTORS <= GF_PREDICT_TAKEN);
  58. gimple_predict_set_predictor (p, predictor);
  59. gimple_predict_set_outcome (p, outcome);
  60. return p;
  61. }
  62. /* Return true if GS is a GIMPLE_PREDICT statement. */
  63. static inline bool
  64. is_gimple_predict (const gimple *gs)
  65. {
  66. return gimple_code (gs) == GIMPLE_PREDICT;
  67. }
  68. #endif /* GCC_GIMPLE_PREDICT_H */