1 /* Support routines for value queries. 2 Copyright (C) 2020-2021 Free Software Foundation, Inc. 3 Contributed by Aldy Hernandez <aldyh@redhat.com> and 4 Andrew Macleod <amacleod@redhat.com>. 5 6 This file is part of GCC. 7 8 GCC is free software; you can redistribute it and/or modify 9 it under the terms of the GNU General Public License as published by 10 the Free Software Foundation; either version 3, or (at your option) 11 any later version. 12 13 GCC is distributed in the hope that it will be useful, 14 but WITHOUT ANY WARRANTY; without even the implied warranty of 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 GNU General Public License for more details. 17 18 You should have received a copy of the GNU General Public License 19 along with GCC; see the file COPYING3. If not see 20 <http://www.gnu.org/licenses/>. */ 21 22 #ifndef GCC_QUERY_H 23 #define GCC_QUERY_H 24 25 // The value_query class is used by optimization passes that require 26 // valueizing SSA names in terms of a tree value, but have no neeed 27 // for ranges. 28 // 29 // value_of_expr must be provided. The default for value_on_edge and 30 // value_of_stmt is to call value_of_expr. 31 // 32 // This implies the valuation is global in nature. If a pass can make 33 // use of more specific information, it can override the other queries. 34 // 35 // Proper usage of the correct query in passes will enable other 36 // valuation mechanisms to produce more precise results. 37 38 class value_query 39 { 40 public: value_query()41 value_query () { } 42 // Return the singleton expression for NAME at a gimple statement, 43 // or NULL if none found. 44 virtual tree value_of_expr (tree name, gimple * = NULL) = 0; 45 // Return the singleton expression for NAME at an edge, or NULL if 46 // none found. 47 virtual tree value_on_edge (edge, tree name); 48 // Return the singleton expression for the LHS of a gimple 49 // statement, assuming an (optional) initial value of NAME. Returns 50 // NULL if none found. 51 // 52 // Note that this method calculates the range the LHS would have 53 // *after* the statement has executed. 54 virtual tree value_of_stmt (gimple *, tree name = NULL); 55 56 private: 57 DISABLE_COPY_AND_ASSIGN (value_query); 58 }; 59 60 // The range_query class is used by optimization passes which are 61 // range aware. 62 // 63 // range_of_expr must be provided. The default for range_on_edge and 64 // range_of_stmt is to call range_of_expr. If a pass can make use of 65 // more specific information, then it can override the other queries. 66 // 67 // The default for the value_* routines is to call the equivalent 68 // range_* routines, check if the range is a singleton, and return it 69 // if so. 70 // 71 // The get_value_range method is currently provided for compatibility 72 // with vr-values. It will be deprecated when possible. 73 74 class range_query : public value_query 75 { 76 public: 77 range_query (); 78 virtual ~range_query (); 79 80 virtual tree value_of_expr (tree name, gimple * = NULL) OVERRIDE; 81 virtual tree value_on_edge (edge, tree name) OVERRIDE; 82 virtual tree value_of_stmt (gimple *, tree name = NULL) OVERRIDE; 83 84 // These are the range equivalents of the value_* methods. Instead 85 // of returning a singleton, they calculate a range and return it in 86 // R. TRUE is returned on success or FALSE if no range was found. 87 // 88 // Note that range_of_expr must always return TRUE unless ranges are 89 // unsupported for NAME's type (supports_type_p is false). 90 virtual bool range_of_expr (irange &r, tree name, gimple * = NULL) = 0; 91 virtual bool range_on_edge (irange &r, edge, tree name); 92 virtual bool range_of_stmt (irange &r, gimple *, tree name = NULL); 93 94 // DEPRECATED: This method is used from vr-values. The plan is to 95 // rewrite all uses of it to the above API. 96 virtual const class value_range_equiv *get_value_range (const_tree, 97 gimple * = NULL); 98 99 protected: 100 class value_range_equiv *allocate_value_range_equiv (); 101 void free_value_range_equiv (class value_range_equiv *); 102 103 private: 104 class equiv_allocator *equiv_alloc; 105 }; 106 107 #endif // GCC_QUERY_H 108