Branch data Line data Source code
1 : : /* Header file for gimple range inference.
2 : : Copyright (C) 2022-2024 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_GIMPLE_RANGE_SIDE_H
22 : : #define GCC_GIMPLE_RANGE_SIDE_H
23 : :
24 : : // Inferred ranges are ranges which are applied to use operands as a by product
25 : : // of executing an operation.
26 : :
27 : : // This class manages an on-demand summary of inferred ranges for a statement.
28 : : // It can be instantiated as required and provides a list of inferred ranges.
29 : : // New inferred ranges should be added in the constructor of this class.
30 : :
31 : 3346905529 : class gimple_infer_range
32 : : {
33 : : public:
34 : : gimple_infer_range (gimple *s, bool use_rangeops = false);
35 : : gimple_infer_range (tree name, vrange &r);
36 : 369464981 : inline unsigned num () const { return num_args; }
37 : 36084067 : inline tree name (unsigned index) const
38 : 36084067 : { gcc_checking_assert (index < num_args); return m_names[index]; }
39 : 34368603 : inline const vrange& range (unsigned index) const
40 : 34368603 : { gcc_checking_assert (index < num_args); return m_ranges[index]; }
41 : : private:
42 : : void add_range (tree name, vrange &range);
43 : : void add_nonzero (tree name);
44 : : void check_assume_func (gcall *call);
45 : : unsigned num_args;
46 : : static const int size_limit = 10;
47 : : tree m_names[size_limit];
48 : : value_range m_ranges[size_limit];
49 : : inline void bump_index () { if (num_args < size_limit - 1) num_args++; }
50 : : friend class non_null_wrapper;
51 : : };
52 : :
53 : : // This is the basic infer oracle API. Default functionaility does nothing.
54 : :
55 : : class infer_range_oracle
56 : : {
57 : : public:
58 : 25528574 : infer_range_oracle () { }
59 : 26089686 : virtual ~infer_range_oracle () { }
60 : 0 : virtual void add_ranges (gimple *, gimple_infer_range &) { }
61 : 0 : virtual bool has_range_p (basic_block, tree = NULL_TREE) { return false; }
62 : 0 : virtual bool maybe_adjust_range (vrange &, tree, basic_block)
63 : 0 : { return false; }
64 : : };
65 : :
66 : : // This class manages a list of inferred ranges for each basic block.
67 : : // As inferences are made, they can be registered to a block and later
68 : : // queried. When constructed with a TRUE flag, immediate uses chains are
69 : : // followed the first time a name is referenced and block populated if
70 : : // there are any inferred ranges.
71 : :
72 : : class infer_range_manager : public infer_range_oracle
73 : : {
74 : : public:
75 : : infer_range_manager (bool do_search);
76 : : virtual ~infer_range_manager ();
77 : : virtual void add_ranges (gimple *s, gimple_infer_range &ir);
78 : : virtual bool has_range_p (basic_block bb, tree name = NULL_TREE);
79 : : virtual bool maybe_adjust_range (vrange &r, tree name, basic_block bb);
80 : : private:
81 : : void add_range (tree name, gimple *s, const vrange &r);
82 : : void add_nonzero (tree name, gimple *s);
83 : : class exit_range_head
84 : : {
85 : : public:
86 : : bitmap m_names; // list of names with an outgoing range.
87 : : class exit_range *head;
88 : : int m_num_ranges;
89 : : exit_range *find_ptr (tree name);
90 : : };
91 : : void register_all_uses (tree name);
92 : : vec <exit_range_head> m_on_exit;
93 : : const vrange &get_nonzero (tree name);
94 : : vec <vrange *> m_nonzero;
95 : : bitmap m_seen;
96 : : bitmap_obstack m_bitmaps;
97 : : struct obstack m_list_obstack;
98 : : class vrange_allocator *m_range_allocator;
99 : : };
100 : :
101 : : #endif // GCC_GIMPLE_RANGE_SIDE_H
|