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