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