Line data Source code
1 : /* Header file for gimple range phi analysis.
2 : Copyright (C) 2023-2026 Free Software Foundation, Inc.
3 : Contributed by Andrew MacLeod <amacleod@redhat.com>.
4 :
5 : This file is part of GCC.
6 :
7 : GCC is free software; you can redistribute it and/or modify it under
8 : the terms of the GNU General Public License as published by the Free
9 : Software Foundation; either version 3, or (at your option) any later
10 : version.
11 :
12 : GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 : WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 : FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 : for more details.
16 :
17 : You should have received a copy of the GNU General Public License
18 : along with GCC; see the file COPYING3. If not see
19 : <http://www.gnu.org/licenses/>. */
20 :
21 : #ifndef GCC_SSA_RANGE_PHI_H
22 : #define GCC_SSA_RANGE_PHI_H
23 :
24 : // -------------------------------------------------------------------------
25 :
26 : // A PHI_GROUP consists of a set of SSA_NAMES which are all PHI_DEFS, and
27 : // their arguemnts contain nothing but other PHI defintions, with at most
28 : // 2 exceptions:
29 : // 1 - An initial value. This is either a constant, or another non-phi name
30 : // with a single incoming edge to the cycle group
31 : // 2 - A modifier statement which adjusts the value. ie, name2 = phi_name + 1
32 : // The initial range is used to create one bound and the modifier is examined
33 : // to determine the other bound.
34 : // All members of the PHI cycle will be given the same range.
35 : //
36 : // For example, given the follwoing sequences:
37 : // qa_20 = qa_10 + 1;
38 : // qa_9 = PHI <qa_10(3), qa_20(4)>
39 : // qa_10 = PHI <0(2), qa_9(5)>
40 : //
41 : // We can determine the following group:
42 : //
43 : // PHI cycle members qa_9, qa_10
44 : // Initial value : 0
45 : // modifier stmt: qa_20 = qa_10 + 1;
46 : //
47 : // Based on just this analysis, We can project that qa_9 and qa_10 will have
48 : // a range of [0, +INF].
49 :
50 1792164 : class phi_group
51 : {
52 : public:
53 : phi_group (bitmap bm, irange &init_range, gimple *mod, range_query *q);
54 : phi_group (const phi_group &g);
55 0 : const_bitmap group () const { return m_group; }
56 834978 : const vrange &range () const { return m_vr; }
57 : gimple *modifier_stmt () const { return m_modifier; }
58 : void dump (FILE *);
59 : protected:
60 : bool calculate_using_modifier (range_query *q);
61 : bool refine_using_relation (relation_kind k);
62 : static unsigned is_modifier_p (gimple *s, const bitmap bm, tree *op = NULL);
63 : bitmap m_group;
64 : gimple *m_modifier; // Single stmt which modifies phi group.
65 : unsigned m_modifier_op; // Operand of group member in modifier stmt.
66 : tree m_modifier_name; // Name of modifier operand ssa-name.
67 : int_range_max m_vr;
68 : friend class phi_analyzer;
69 : };
70 :
71 : // The phi anlyzer will return the group that name belongs to.
72 : // If inforamtion is not known about a name yet, analysis is conducted by
73 : // looking at the arguments to PHIS and following them to their defs to
74 : // determine whether the conditions are met to form a new group.
75 :
76 : class phi_analyzer
77 : {
78 : public:
79 : phi_analyzer (range_query &);
80 : ~phi_analyzer ();
81 : phi_group *operator[] (tree name);
82 : void dump (FILE *f);
83 : protected:
84 : phi_group *group (tree name) const;
85 : void process_phi (gphi *phi, range_query &query);
86 : vec<tree> m_work;
87 :
88 : bitmap m_simple; // Processed, not part of a group.
89 : bitmap m_current; // Potential group currently being analyzed.
90 : vec<phi_group *> m_phi_groups;
91 : vec<phi_group *> m_tab;
92 : bitmap_obstack m_bitmaps;
93 : };
94 :
95 : // Invoke a phi analyzer. It will process all the current PHI nodes and try
96 : // to form groups with initial values. Then export any ranges found
97 : // to set_range_info. When finished, it will simply dispose of itself.
98 :
99 : void phi_analysis (range_query &q);
100 :
101 : #endif // GCC_SSA_RANGE_PHI_H
|