1 /* Header file for gimple range inference.
2 Copyright (C) 2022-2024 Free Software Foundation, Inc.
3 Contributed by Andrew MacLeod <amacleod@redhat.com>.
5 This file is part of GCC.
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
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
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/>. */
21 #ifndef GCC_GIMPLE_RANGE_SIDE_H
22 #define GCC_GIMPLE_RANGE_SIDE_H
24 // Inferred ranges are ranges which are applied to use operands as a by product
25 // of executing an operation.
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.
31 class gimple_infer_range
34 gimple_infer_range (gimple
*s
, bool use_rangeops
= false);
35 gimple_infer_range (tree name
, vrange
&r
);
36 inline unsigned num () const { return num_args
; }
37 inline tree
name (unsigned index
) const
38 { gcc_checking_assert (index
< num_args
); return m_names
[index
]; }
39 inline const vrange
& range (unsigned index
) const
40 { gcc_checking_assert (index
< num_args
); return m_ranges
[index
]; }
42 void add_range (tree name
, vrange
&range
);
43 void add_nonzero (tree name
);
44 void check_assume_func (gcall
*call
);
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
;
53 // This is the basic infer oracle API. Default functionaility does nothing.
55 class infer_range_oracle
58 infer_range_oracle () { }
59 virtual ~infer_range_oracle () { }
60 virtual void add_ranges (gimple
*, gimple_infer_range
&) { }
61 virtual bool has_range_p (basic_block
, tree
= NULL_TREE
) { return false; }
62 virtual bool maybe_adjust_range (vrange
&, tree
, basic_block
)
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.
72 class infer_range_manager
: public infer_range_oracle
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
);
81 void add_range (tree name
, gimple
*s
, const vrange
&r
);
82 void add_nonzero (tree name
, gimple
*s
);
86 bitmap m_names
; // list of names with an outgoing range.
87 class exit_range
*head
;
89 exit_range
*find_ptr (tree name
);
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
;
96 bitmap_obstack m_bitmaps
;
97 struct obstack m_list_obstack
;
98 class vrange_allocator
*m_range_allocator
;
101 #endif // GCC_GIMPLE_RANGE_SIDE_H