1// RTL SSA classes related to changing instructions -*- C++ -*-
2// Copyright (C) 2020-2024 Free Software Foundation, Inc.
3//
4// This file is part of GCC.
5//
6// GCC is free software; you can redistribute it and/or modify it under
7// the terms of the GNU General Public License as published by the Free
8// Software Foundation; either version 3, or (at your option) any later
9// version.
10//
11// GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12// WARRANTY; without even the implied warranty of MERCHANTABILITY or
13// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14// for more details.
15//
16// You should have received a copy of the GNU General Public License
17// along with GCC; see the file COPYING3. If not see
18// <http://www.gnu.org/licenses/>.
19
20namespace rtl_ssa {
21
22// A class that describes a change that we're considering making to an
23// instruction. There are three choices:
24//
25// (1) delete the instruction
26// (2) replace the instruction with a new instruction in-place
27// (3) replace the instruction with a new instruction at a different location
28//
29// Anything related to the "new instruction" is irrelevant for (1).
30//
31// The class doesn't actually change anything itself, it simply records
32// something that we might do.
33class insn_change
34{
35 friend class function_info;
36
37public:
38 enum delete_action { DELETE };
39
40 // Construct a possible change to INSN.
41 insn_change (insn_info *insn);
42
43 // Construct a possible deletion of INSN.
44 insn_change (insn_info *insn, delete_action);
45
46 // The instruction that we would change.
47 insn_info *insn () const { return m_insn; }
48
49 // The rtx_insn of the instruction that we would change.
50 rtx_insn *rtl () const { return m_insn->rtl (); }
51
52 // The basic block that contains insn ().
53 bb_info *bb () const { return m_insn->bb (); }
54
55 // The extended basic block that contains insn ().
56 ebb_info *ebb () const { return m_insn->ebb (); }
57
58 // The uid of the instruction that we would change.
59 unsigned int insn_uid () const { return m_insn->uid (); }
60
61 // The list of things that the original instruction defined and used.
62 def_array old_defs () const { return m_insn->defs (); }
63 use_array old_uses () const { return m_insn->uses (); }
64
65 // The cost of the original instruction, as calculated by the target.
66 unsigned int old_cost () const { return m_insn->cost (); }
67
68 // Return true if the original instruction would simply be deleted,
69 // rather than being replaced by a new instruction.
70 bool is_deletion () const { return m_is_deletion; }
71
72 // Print a description of the change to PP.
73 void print (pretty_printer *pp) const;
74
75 // Return an insn_change for deleting INSN.
76 static insn_change delete_insn (insn_info *insn) { return { insn, DELETE }; }
77
78private:
79 // The value returned by insn ().
80 insn_info *m_insn;
81
82public:
83 // The list of things that the new instruction would define and use.
84 def_array new_defs;
85 use_array new_uses;
86
87 // The range of instructions after which the instruction could be placed.
88 // The range can include INSN itself: placing the instruction after either
89 // INSN or INSN->prev_nondebug_insn () is equivalent to not moving the
90 // instruction.
91 insn_range_info move_range;
92
93 // The cost that the new instruction would have, as calculated by the target.
94 unsigned int new_cost;
95
96private:
97 // The value returned by is_deletion ().
98 bool m_is_deletion;
99};
100
101// A class that represents a closure of the two-argument form of
102// insn_is_changing. See the comment above the one-argument form
103// for details.
104class insn_is_changing_closure
105{
106public:
107 insn_is_changing_closure (array_slice<insn_change *const> changes);
108 bool operator() (const insn_info *) const;
109
110private:
111 array_slice<insn_change *const> m_changes;
112};
113
114void pp_insn_change (pretty_printer *, const insn_change &);
115
116}
117
118void dump (FILE *, const rtl_ssa::insn_change &);
119
120void DEBUG_FUNCTION debug (const rtl_ssa::insn_change &);
121

source code of gcc/rtl-ssa/changes.h