68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1 /* Function splitting pass
|
145
|
2 Copyright (C) 2010-2020 Free Software Foundation, Inc.
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
3 Contributed by Jan Hubicka <jh@suse.cz>
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
4
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
5 This file is part of GCC.
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
6
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
7 GCC is free software; you can redistribute it and/or modify it under
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
8 the terms of the GNU General Public License as published by the Free
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
9 Software Foundation; either version 3, or (at your option) any later
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
10 version.
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
11
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
15 for more details.
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
16
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
17 You should have received a copy of the GNU General Public License
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
18 along with GCC; see the file COPYING3. If not see
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
19 <http://www.gnu.org/licenses/>. */
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
20
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
21 /* The purpose of this pass is to split function bodies to improve
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
22 inlining. I.e. for function of the form:
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
23
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
24 func (...)
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
25 {
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
26 if (cheap_test)
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
27 something_small
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
28 else
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
29 something_big
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
30 }
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
31
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
32 Produce:
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
33
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
34 func.part (...)
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
35 {
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
36 something_big
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
37 }
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
38
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
39 func (...)
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
40 {
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
41 if (cheap_test)
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
42 something_small
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
43 else
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
44 func.part (...);
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
45 }
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
46
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
47 When func becomes inlinable and when cheap_test is often true, inlining func,
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
48 but not fund.part leads to performance improvement similar as inlining
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
49 original func while the code size growth is smaller.
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
50
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
51 The pass is organized in three stages:
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
52 1) Collect local info about basic block into BB_INFO structure and
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
53 compute function body estimated size and time.
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
54 2) Via DFS walk find all possible basic blocks where we can split
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
55 and chose best one.
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
56 3) If split point is found, split at the specified BB by creating a clone
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
57 and updating function to call it.
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
58
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
59 The decisions what functions to split are in execute_split_functions
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
60 and consider_split.
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
61
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
62 There are several possible future improvements for this pass including:
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
63
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
64 1) Splitting to break up large functions
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
65 2) Splitting to reduce stack frame usage
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
66 3) Allow split part of function to use values computed in the header part.
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
67 The values needs to be passed to split function, perhaps via same
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
68 interface as for nested functions or as argument.
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
69 4) Support for simple rematerialization. I.e. when split part use
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
70 value computed in header from function parameter in very cheap way, we
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
71 can just recompute it.
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
72 5) Support splitting of nested functions.
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
73 6) Support non-SSA arguments.
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
74 7) There is nothing preventing us from producing multiple parts of single function
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
75 when needed or splitting also the parts. */
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
76
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
77 #include "config.h"
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
78 #include "system.h"
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
79 #include "coretypes.h"
|
111
|
80 #include "backend.h"
|
|
81 #include "rtl.h"
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
82 #include "tree.h"
|
111
|
83 #include "gimple.h"
|
|
84 #include "cfghooks.h"
|
|
85 #include "alloc-pool.h"
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
86 #include "tree-pass.h"
|
111
|
87 #include "ssa.h"
|
|
88 #include "cgraph.h"
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
89 #include "diagnostic.h"
|
111
|
90 #include "fold-const.h"
|
|
91 #include "cfganal.h"
|
|
92 #include "calls.h"
|
|
93 #include "gimplify.h"
|
|
94 #include "gimple-iterator.h"
|
|
95 #include "gimplify-me.h"
|
|
96 #include "gimple-walk.h"
|
|
97 #include "symbol-summary.h"
|
|
98 #include "ipa-prop.h"
|
|
99 #include "tree-cfg.h"
|
|
100 #include "tree-into-ssa.h"
|
|
101 #include "tree-dfa.h"
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
102 #include "tree-inline.h"
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
103 #include "gimple-pretty-print.h"
|
111
|
104 #include "ipa-fnsummary.h"
|
|
105 #include "cfgloop.h"
|
145
|
106 #include "attribs.h"
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
107
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
108 /* Per basic block info. */
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
109
|
145
|
110 class split_bb_info
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
111 {
|
145
|
112 public:
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
113 unsigned int size;
|
131
|
114 sreal time;
|
111
|
115 };
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
116
|
111
|
117 static vec<split_bb_info> bb_info_vec;
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
118
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
119 /* Description of split point. */
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
120
|
145
|
121 class split_point
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
122 {
|
145
|
123 public:
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
124 /* Size of the partitions. */
|
131
|
125 sreal header_time, split_time;
|
|
126 unsigned int header_size, split_size;
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
127
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
128 /* SSA names that need to be passed into spit function. */
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
129 bitmap ssa_names_to_pass;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
130
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
131 /* Basic block where we split (that will become entry point of new function. */
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
132 basic_block entry_bb;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
133
|
131
|
134 /* Count for entering the split part.
|
|
135 This is not count of the entry_bb because it may be in loop. */
|
|
136 profile_count count;
|
|
137
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
138 /* Basic blocks we are splitting away. */
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
139 bitmap split_bbs;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
140
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
141 /* True when return value is computed on split part and thus it needs
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
142 to be returned. */
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
143 bool split_part_set_retval;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
144 };
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
145
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
146 /* Best split point found. */
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
147
|
145
|
148 class split_point best_split_point;
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
149
|
111
|
150 /* Set of basic blocks that are not allowed to dominate a split point. */
|
|
151
|
|
152 static bitmap forbidden_dominators;
|
|
153
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
154 static tree find_retval (basic_block return_bb);
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
155
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
156 /* Callback for walk_stmt_load_store_addr_ops. If T is non-SSA automatic
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
157 variable, check it if it is present in bitmap passed via DATA. */
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
158
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
159 static bool
|
111
|
160 test_nonssa_use (gimple *, tree t, tree, void *data)
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
161 {
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
162 t = get_base_address (t);
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
163
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
164 if (!t || is_gimple_reg (t))
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
165 return false;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
166
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
167 if (TREE_CODE (t) == PARM_DECL
|
111
|
168 || (VAR_P (t)
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
169 && auto_var_in_fn_p (t, current_function_decl))
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
170 || TREE_CODE (t) == RESULT_DECL
|
145
|
171 /* Normal labels are part of CFG and will be handled gratefully.
|
111
|
172 Forced labels however can be used directly by statements and
|
|
173 need to stay in one partition along with their uses. */
|
|
174 || (TREE_CODE (t) == LABEL_DECL
|
|
175 && FORCED_LABEL (t)))
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
176 return bitmap_bit_p ((bitmap)data, DECL_UID (t));
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
177
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
178 /* For DECL_BY_REFERENCE, the return value is actually a pointer. We want
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
179 to pretend that the value pointed to is actual result decl. */
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
180 if ((TREE_CODE (t) == MEM_REF || INDIRECT_REF_P (t))
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
181 && TREE_CODE (TREE_OPERAND (t, 0)) == SSA_NAME
|
111
|
182 && SSA_NAME_VAR (TREE_OPERAND (t, 0))
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
183 && TREE_CODE (SSA_NAME_VAR (TREE_OPERAND (t, 0))) == RESULT_DECL
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
184 && DECL_BY_REFERENCE (DECL_RESULT (current_function_decl)))
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
185 return
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
186 bitmap_bit_p ((bitmap)data,
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
187 DECL_UID (DECL_RESULT (current_function_decl)));
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
188
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
189 return false;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
190 }
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
191
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
192 /* Dump split point CURRENT. */
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
193
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
194 static void
|
145
|
195 dump_split_point (FILE * file, class split_point *current)
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
196 {
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
197 fprintf (file,
|
111
|
198 "Split point at BB %i\n"
|
131
|
199 " header time: %f header size: %i\n"
|
|
200 " split time: %f split size: %i\n bbs: ",
|
|
201 current->entry_bb->index, current->header_time.to_double (),
|
|
202 current->header_size, current->split_time.to_double (),
|
|
203 current->split_size);
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
204 dump_bitmap (file, current->split_bbs);
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
205 fprintf (file, " SSA names to pass: ");
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
206 dump_bitmap (file, current->ssa_names_to_pass);
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
207 }
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
208
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
209 /* Look for all BBs in header that might lead to the split part and verify
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
210 that they are not defining any non-SSA var used by the split part.
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
211 Parameters are the same as for consider_split. */
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
212
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
213 static bool
|
145
|
214 verify_non_ssa_vars (class split_point *current, bitmap non_ssa_vars,
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
215 basic_block return_bb)
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
216 {
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
217 bitmap seen = BITMAP_ALLOC (NULL);
|
111
|
218 vec<basic_block> worklist = vNULL;
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
219 edge e;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
220 edge_iterator ei;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
221 bool ok = true;
|
111
|
222 basic_block bb;
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
223
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
224 FOR_EACH_EDGE (e, ei, current->entry_bb->preds)
|
111
|
225 if (e->src != ENTRY_BLOCK_PTR_FOR_FN (cfun)
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
226 && !bitmap_bit_p (current->split_bbs, e->src->index))
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
227 {
|
111
|
228 worklist.safe_push (e->src);
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
229 bitmap_set_bit (seen, e->src->index);
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
230 }
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
231
|
111
|
232 while (!worklist.is_empty ())
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
233 {
|
111
|
234 bb = worklist.pop ();
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
235 FOR_EACH_EDGE (e, ei, bb->preds)
|
111
|
236 if (e->src != ENTRY_BLOCK_PTR_FOR_FN (cfun)
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
237 && bitmap_set_bit (seen, e->src->index))
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
238 {
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
239 gcc_checking_assert (!bitmap_bit_p (current->split_bbs,
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
240 e->src->index));
|
111
|
241 worklist.safe_push (e->src);
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
242 }
|
111
|
243 for (gimple_stmt_iterator bsi = gsi_start_bb (bb); !gsi_end_p (bsi);
|
|
244 gsi_next (&bsi))
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
245 {
|
111
|
246 gimple *stmt = gsi_stmt (bsi);
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
247 if (is_gimple_debug (stmt))
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
248 continue;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
249 if (walk_stmt_load_store_addr_ops
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
250 (stmt, non_ssa_vars, test_nonssa_use, test_nonssa_use,
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
251 test_nonssa_use))
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
252 {
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
253 ok = false;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
254 goto done;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
255 }
|
111
|
256 if (glabel *label_stmt = dyn_cast <glabel *> (stmt))
|
|
257 if (test_nonssa_use (stmt, gimple_label_label (label_stmt),
|
|
258 NULL_TREE, non_ssa_vars))
|
|
259 {
|
|
260 ok = false;
|
|
261 goto done;
|
|
262 }
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
263 }
|
111
|
264 for (gphi_iterator bsi = gsi_start_phis (bb); !gsi_end_p (bsi);
|
|
265 gsi_next (&bsi))
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
266 {
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
267 if (walk_stmt_load_store_addr_ops
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
268 (gsi_stmt (bsi), non_ssa_vars, test_nonssa_use, test_nonssa_use,
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
269 test_nonssa_use))
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
270 {
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
271 ok = false;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
272 goto done;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
273 }
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
274 }
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
275 FOR_EACH_EDGE (e, ei, bb->succs)
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
276 {
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
277 if (e->dest != return_bb)
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
278 continue;
|
111
|
279 for (gphi_iterator bsi = gsi_start_phis (return_bb);
|
|
280 !gsi_end_p (bsi);
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
281 gsi_next (&bsi))
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
282 {
|
111
|
283 gphi *stmt = bsi.phi ();
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
284 tree op = gimple_phi_arg_def (stmt, e->dest_idx);
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
285
|
111
|
286 if (virtual_operand_p (gimple_phi_result (stmt)))
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
287 continue;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
288 if (TREE_CODE (op) != SSA_NAME
|
111
|
289 && test_nonssa_use (stmt, op, op, non_ssa_vars))
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
290 {
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
291 ok = false;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
292 goto done;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
293 }
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
294 }
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
295 }
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
296 }
|
111
|
297
|
|
298 /* Verify that the rest of function does not define any label
|
|
299 used by the split part. */
|
|
300 FOR_EACH_BB_FN (bb, cfun)
|
|
301 if (!bitmap_bit_p (current->split_bbs, bb->index)
|
|
302 && !bitmap_bit_p (seen, bb->index))
|
|
303 {
|
|
304 gimple_stmt_iterator bsi;
|
|
305 for (bsi = gsi_start_bb (bb); !gsi_end_p (bsi); gsi_next (&bsi))
|
|
306 if (glabel *label_stmt = dyn_cast <glabel *> (gsi_stmt (bsi)))
|
|
307 {
|
|
308 if (test_nonssa_use (label_stmt,
|
|
309 gimple_label_label (label_stmt),
|
|
310 NULL_TREE, non_ssa_vars))
|
|
311 {
|
|
312 ok = false;
|
|
313 goto done;
|
|
314 }
|
|
315 }
|
|
316 else
|
|
317 break;
|
|
318 }
|
|
319
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
320 done:
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
321 BITMAP_FREE (seen);
|
111
|
322 worklist.release ();
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
323 return ok;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
324 }
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
325
|
111
|
326 /* If STMT is a call, check the callee against a list of forbidden
|
|
327 predicate functions. If a match is found, look for uses of the
|
|
328 call result in condition statements that compare against zero.
|
|
329 For each such use, find the block targeted by the condition
|
|
330 statement for the nonzero result, and set the bit for this block
|
|
331 in the forbidden dominators bitmap. The purpose of this is to avoid
|
|
332 selecting a split point where we are likely to lose the chance
|
|
333 to optimize away an unused function call. */
|
|
334
|
|
335 static void
|
|
336 check_forbidden_calls (gimple *stmt)
|
|
337 {
|
|
338 imm_use_iterator use_iter;
|
|
339 use_operand_p use_p;
|
|
340 tree lhs;
|
|
341
|
|
342 /* At the moment, __builtin_constant_p is the only forbidden
|
|
343 predicate function call (see PR49642). */
|
|
344 if (!gimple_call_builtin_p (stmt, BUILT_IN_CONSTANT_P))
|
|
345 return;
|
|
346
|
|
347 lhs = gimple_call_lhs (stmt);
|
|
348
|
|
349 if (!lhs || TREE_CODE (lhs) != SSA_NAME)
|
|
350 return;
|
|
351
|
|
352 FOR_EACH_IMM_USE_FAST (use_p, use_iter, lhs)
|
|
353 {
|
|
354 tree op1;
|
|
355 basic_block use_bb, forbidden_bb;
|
|
356 enum tree_code code;
|
|
357 edge true_edge, false_edge;
|
|
358 gcond *use_stmt;
|
|
359
|
|
360 use_stmt = dyn_cast <gcond *> (USE_STMT (use_p));
|
|
361 if (!use_stmt)
|
|
362 continue;
|
|
363
|
|
364 /* Assuming canonical form for GIMPLE_COND here, with constant
|
|
365 in second position. */
|
|
366 op1 = gimple_cond_rhs (use_stmt);
|
|
367 code = gimple_cond_code (use_stmt);
|
|
368 use_bb = gimple_bb (use_stmt);
|
|
369
|
|
370 extract_true_false_edges_from_block (use_bb, &true_edge, &false_edge);
|
|
371
|
|
372 /* We're only interested in comparisons that distinguish
|
|
373 unambiguously from zero. */
|
|
374 if (!integer_zerop (op1) || code == LE_EXPR || code == GE_EXPR)
|
|
375 continue;
|
|
376
|
|
377 if (code == EQ_EXPR)
|
|
378 forbidden_bb = false_edge->dest;
|
|
379 else
|
|
380 forbidden_bb = true_edge->dest;
|
|
381
|
|
382 bitmap_set_bit (forbidden_dominators, forbidden_bb->index);
|
|
383 }
|
|
384 }
|
|
385
|
|
386 /* If BB is dominated by any block in the forbidden dominators set,
|
|
387 return TRUE; else FALSE. */
|
|
388
|
|
389 static bool
|
|
390 dominated_by_forbidden (basic_block bb)
|
|
391 {
|
|
392 unsigned dom_bb;
|
|
393 bitmap_iterator bi;
|
|
394
|
|
395 EXECUTE_IF_SET_IN_BITMAP (forbidden_dominators, 1, dom_bb, bi)
|
|
396 {
|
|
397 if (dominated_by_p (CDI_DOMINATORS, bb,
|
|
398 BASIC_BLOCK_FOR_FN (cfun, dom_bb)))
|
|
399 return true;
|
|
400 }
|
|
401
|
|
402 return false;
|
|
403 }
|
|
404
|
|
405 /* For give split point CURRENT and return block RETURN_BB return 1
|
|
406 if ssa name VAL is set by split part and 0 otherwise. */
|
|
407 static bool
|
145
|
408 split_part_set_ssa_name_p (tree val, class split_point *current,
|
111
|
409 basic_block return_bb)
|
|
410 {
|
|
411 if (TREE_CODE (val) != SSA_NAME)
|
|
412 return false;
|
|
413
|
|
414 return (!SSA_NAME_IS_DEFAULT_DEF (val)
|
|
415 && (bitmap_bit_p (current->split_bbs,
|
|
416 gimple_bb (SSA_NAME_DEF_STMT (val))->index)
|
|
417 || gimple_bb (SSA_NAME_DEF_STMT (val)) == return_bb));
|
|
418 }
|
|
419
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
420 /* We found an split_point CURRENT. NON_SSA_VARS is bitmap of all non ssa
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
421 variables used and RETURN_BB is return basic block.
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
422 See if we can split function here. */
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
423
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
424 static void
|
145
|
425 consider_split (class split_point *current, bitmap non_ssa_vars,
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
426 basic_block return_bb)
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
427 {
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
428 tree parm;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
429 unsigned int num_args = 0;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
430 unsigned int call_overhead;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
431 edge e;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
432 edge_iterator ei;
|
111
|
433 gphi_iterator bsi;
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
434 unsigned int i;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
435 tree retval;
|
111
|
436 bool back_edge = false;
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
437
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
438 if (dump_file && (dump_flags & TDF_DETAILS))
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
439 dump_split_point (dump_file, current);
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
440
|
131
|
441 current->count = profile_count::zero ();
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
442 FOR_EACH_EDGE (e, ei, current->entry_bb->preds)
|
111
|
443 {
|
|
444 if (e->flags & EDGE_DFS_BACK)
|
|
445 back_edge = true;
|
|
446 if (!bitmap_bit_p (current->split_bbs, e->src->index))
|
131
|
447 current->count += e->count ();
|
111
|
448 }
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
449
|
131
|
450 /* Do not split when we would end up calling function anyway.
|
|
451 Compares are three state, use !(...<...) to also give up when outcome
|
|
452 is unknown. */
|
|
453 if (!(current->count
|
|
454 < (ENTRY_BLOCK_PTR_FOR_FN (cfun)->count.apply_scale
|
145
|
455 (param_partial_inlining_entry_probability, 100))))
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
456 {
|
145
|
457 /* When profile is guessed, we cannot expect it to give us
|
|
458 realistic estimate on likeliness of function taking the
|
111
|
459 complex path. As a special case, when tail of the function is
|
|
460 a loop, enable splitting since inlining code skipping the loop
|
|
461 is likely noticeable win. */
|
|
462 if (back_edge
|
|
463 && profile_status_for_fn (cfun) != PROFILE_READ
|
131
|
464 && current->count
|
|
465 < ENTRY_BLOCK_PTR_FOR_FN (cfun)->count)
|
111
|
466 {
|
|
467 if (dump_file && (dump_flags & TDF_DETAILS))
|
131
|
468 {
|
|
469 fprintf (dump_file,
|
|
470 " Split before loop, accepting despite low counts");
|
|
471 current->count.dump (dump_file);
|
|
472 fprintf (dump_file, " ");
|
|
473 ENTRY_BLOCK_PTR_FOR_FN (cfun)->count.dump (dump_file);
|
|
474 }
|
111
|
475 }
|
|
476 else
|
|
477 {
|
|
478 if (dump_file && (dump_flags & TDF_DETAILS))
|
|
479 fprintf (dump_file,
|
|
480 " Refused: incoming frequency is too large.\n");
|
|
481 return;
|
|
482 }
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
483 }
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
484
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
485 if (!current->header_size)
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
486 {
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
487 if (dump_file && (dump_flags & TDF_DETAILS))
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
488 fprintf (dump_file, " Refused: header empty\n");
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
489 return;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
490 }
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
491
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
492 /* Verify that PHI args on entry are either virtual or all their operands
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
493 incoming from header are the same. */
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
494 for (bsi = gsi_start_phis (current->entry_bb); !gsi_end_p (bsi); gsi_next (&bsi))
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
495 {
|
111
|
496 gphi *stmt = bsi.phi ();
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
497 tree val = NULL;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
498
|
111
|
499 if (virtual_operand_p (gimple_phi_result (stmt)))
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
500 continue;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
501 for (i = 0; i < gimple_phi_num_args (stmt); i++)
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
502 {
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
503 edge e = gimple_phi_arg_edge (stmt, i);
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
504 if (!bitmap_bit_p (current->split_bbs, e->src->index))
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
505 {
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
506 tree edge_val = gimple_phi_arg_def (stmt, i);
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
507 if (val && edge_val != val)
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
508 {
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
509 if (dump_file && (dump_flags & TDF_DETAILS))
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
510 fprintf (dump_file,
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
511 " Refused: entry BB has PHI with multiple variants\n");
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
512 return;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
513 }
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
514 val = edge_val;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
515 }
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
516 }
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
517 }
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
518
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
519
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
520 /* See what argument we will pass to the split function and compute
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
521 call overhead. */
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
522 call_overhead = eni_size_weights.call_cost;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
523 for (parm = DECL_ARGUMENTS (current_function_decl); parm;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
524 parm = DECL_CHAIN (parm))
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
525 {
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
526 if (!is_gimple_reg (parm))
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
527 {
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
528 if (bitmap_bit_p (non_ssa_vars, DECL_UID (parm)))
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
529 {
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
530 if (dump_file && (dump_flags & TDF_DETAILS))
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
531 fprintf (dump_file,
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
532 " Refused: need to pass non-ssa param values\n");
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
533 return;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
534 }
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
535 }
|
111
|
536 else
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
537 {
|
111
|
538 tree ddef = ssa_default_def (cfun, parm);
|
|
539 if (ddef
|
|
540 && bitmap_bit_p (current->ssa_names_to_pass,
|
|
541 SSA_NAME_VERSION (ddef)))
|
|
542 {
|
|
543 if (!VOID_TYPE_P (TREE_TYPE (parm)))
|
|
544 call_overhead += estimate_move_cost (TREE_TYPE (parm), false);
|
|
545 num_args++;
|
|
546 }
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
547 }
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
548 }
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
549 if (!VOID_TYPE_P (TREE_TYPE (current_function_decl)))
|
111
|
550 call_overhead += estimate_move_cost (TREE_TYPE (current_function_decl),
|
|
551 false);
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
552
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
553 if (current->split_size <= call_overhead)
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
554 {
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
555 if (dump_file && (dump_flags & TDF_DETAILS))
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
556 fprintf (dump_file,
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
557 " Refused: split size is smaller than call overhead\n");
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
558 return;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
559 }
|
131
|
560 /* FIXME: The logic here is not very precise, because inliner does use
|
|
561 inline predicates to reduce function body size. We add 10 to anticipate
|
|
562 that. Next stage1 we should try to be more meaningful here. */
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
563 if (current->header_size + call_overhead
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
564 >= (unsigned int)(DECL_DECLARED_INLINE_P (current_function_decl)
|
145
|
565 ? param_max_inline_insns_single
|
|
566 : param_max_inline_insns_auto) + 10)
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
567 {
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
568 if (dump_file && (dump_flags & TDF_DETAILS))
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
569 fprintf (dump_file,
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
570 " Refused: header size is too large for inline candidate\n");
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
571 return;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
572 }
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
573
|
111
|
574 /* Splitting functions brings the target out of comdat group; this will
|
|
575 lead to code duplication if the function is reused by other unit.
|
|
576 Limit this duplication. This is consistent with limit in tree-sra.c
|
|
577 FIXME: with LTO we ought to be able to do better! */
|
|
578 if (DECL_ONE_ONLY (current_function_decl)
|
145
|
579 && current->split_size >= (unsigned int) param_max_inline_insns_auto + 10)
|
111
|
580 {
|
|
581 if (dump_file && (dump_flags & TDF_DETAILS))
|
|
582 fprintf (dump_file,
|
|
583 " Refused: function is COMDAT and tail is too large\n");
|
|
584 return;
|
|
585 }
|
|
586 /* For comdat functions also reject very small tails; those will likely get
|
|
587 inlined back and we do not want to risk the duplication overhead.
|
|
588 FIXME: with LTO we ought to be able to do better! */
|
|
589 if (DECL_ONE_ONLY (current_function_decl)
|
|
590 && current->split_size
|
145
|
591 <= (unsigned int) param_early_inlining_insns / 2)
|
111
|
592 {
|
|
593 if (dump_file && (dump_flags & TDF_DETAILS))
|
|
594 fprintf (dump_file,
|
|
595 " Refused: function is COMDAT and tail is too small\n");
|
|
596 return;
|
|
597 }
|
|
598
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
599 /* FIXME: we currently can pass only SSA function parameters to the split
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
600 arguments. Once parm_adjustment infrastructure is supported by cloning,
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
601 we can pass more than that. */
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
602 if (num_args != bitmap_count_bits (current->ssa_names_to_pass))
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
603 {
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
604
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
605 if (dump_file && (dump_flags & TDF_DETAILS))
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
606 fprintf (dump_file,
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
607 " Refused: need to pass non-param values\n");
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
608 return;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
609 }
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
610
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
611 /* When there are non-ssa vars used in the split region, see if they
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
612 are used in the header region. If so, reject the split.
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
613 FIXME: we can use nested function support to access both. */
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
614 if (!bitmap_empty_p (non_ssa_vars)
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
615 && !verify_non_ssa_vars (current, non_ssa_vars, return_bb))
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
616 {
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
617 if (dump_file && (dump_flags & TDF_DETAILS))
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
618 fprintf (dump_file,
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
619 " Refused: split part has non-ssa uses\n");
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
620 return;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
621 }
|
111
|
622
|
|
623 /* If the split point is dominated by a forbidden block, reject
|
|
624 the split. */
|
|
625 if (!bitmap_empty_p (forbidden_dominators)
|
|
626 && dominated_by_forbidden (current->entry_bb))
|
|
627 {
|
|
628 if (dump_file && (dump_flags & TDF_DETAILS))
|
|
629 fprintf (dump_file,
|
|
630 " Refused: split point dominated by forbidden block\n");
|
|
631 return;
|
|
632 }
|
|
633
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
634 /* See if retval used by return bb is computed by header or split part.
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
635 When it is computed by split part, we need to produce return statement
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
636 in the split part and add code to header to pass it around.
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
637
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
638 This is bit tricky to test:
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
639 1) When there is no return_bb or no return value, we always pass
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
640 value around.
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
641 2) Invariants are always computed by caller.
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
642 3) For SSA we need to look if defining statement is in header or split part
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
643 4) For non-SSA we need to look where the var is computed. */
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
644 retval = find_retval (return_bb);
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
645 if (!retval)
|
111
|
646 {
|
|
647 /* If there is a return_bb with no return value in function returning
|
|
648 value by reference, also make the split part return void, otherwise
|
|
649 we expansion would try to create a non-POD temporary, which is
|
|
650 invalid. */
|
|
651 if (return_bb != EXIT_BLOCK_PTR_FOR_FN (cfun)
|
|
652 && DECL_RESULT (current_function_decl)
|
|
653 && DECL_BY_REFERENCE (DECL_RESULT (current_function_decl)))
|
|
654 current->split_part_set_retval = false;
|
|
655 else
|
|
656 current->split_part_set_retval = true;
|
|
657 }
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
658 else if (is_gimple_min_invariant (retval))
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
659 current->split_part_set_retval = false;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
660 /* Special case is value returned by reference we record as if it was non-ssa
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
661 set to result_decl. */
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
662 else if (TREE_CODE (retval) == SSA_NAME
|
111
|
663 && SSA_NAME_VAR (retval)
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
664 && TREE_CODE (SSA_NAME_VAR (retval)) == RESULT_DECL
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
665 && DECL_BY_REFERENCE (DECL_RESULT (current_function_decl)))
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
666 current->split_part_set_retval
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
667 = bitmap_bit_p (non_ssa_vars, DECL_UID (SSA_NAME_VAR (retval)));
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
668 else if (TREE_CODE (retval) == SSA_NAME)
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
669 current->split_part_set_retval
|
111
|
670 = split_part_set_ssa_name_p (retval, current, return_bb);
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
671 else if (TREE_CODE (retval) == PARM_DECL)
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
672 current->split_part_set_retval = false;
|
111
|
673 else if (VAR_P (retval)
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
674 || TREE_CODE (retval) == RESULT_DECL)
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
675 current->split_part_set_retval
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
676 = bitmap_bit_p (non_ssa_vars, DECL_UID (retval));
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
677 else
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
678 current->split_part_set_retval = true;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
679
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
680 /* split_function fixes up at most one PHI non-virtual PHI node in return_bb,
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
681 for the return value. If there are other PHIs, give up. */
|
111
|
682 if (return_bb != EXIT_BLOCK_PTR_FOR_FN (cfun))
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
683 {
|
111
|
684 gphi_iterator psi;
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
685
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
686 for (psi = gsi_start_phis (return_bb); !gsi_end_p (psi); gsi_next (&psi))
|
111
|
687 if (!virtual_operand_p (gimple_phi_result (psi.phi ()))
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
688 && !(retval
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
689 && current->split_part_set_retval
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
690 && TREE_CODE (retval) == SSA_NAME
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
691 && !DECL_BY_REFERENCE (DECL_RESULT (current_function_decl))
|
111
|
692 && SSA_NAME_DEF_STMT (retval) == psi.phi ()))
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
693 {
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
694 if (dump_file && (dump_flags & TDF_DETAILS))
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
695 fprintf (dump_file,
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
696 " Refused: return bb has extra PHIs\n");
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
697 return;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
698 }
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
699 }
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
700
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
701 if (dump_file && (dump_flags & TDF_DETAILS))
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
702 fprintf (dump_file, " Accepted!\n");
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
703
|
131
|
704 /* At the moment chose split point with lowest count and that leaves
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
705 out smallest size of header.
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
706 In future we might re-consider this heuristics. */
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
707 if (!best_split_point.split_bbs
|
131
|
708 || best_split_point.count
|
|
709 > current->count
|
|
710 || (best_split_point.count == current->count
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
711 && best_split_point.split_size < current->split_size))
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
712
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
713 {
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
714 if (dump_file && (dump_flags & TDF_DETAILS))
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
715 fprintf (dump_file, " New best split point!\n");
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
716 if (best_split_point.ssa_names_to_pass)
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
717 {
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
718 BITMAP_FREE (best_split_point.ssa_names_to_pass);
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
719 BITMAP_FREE (best_split_point.split_bbs);
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
720 }
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
721 best_split_point = *current;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
722 best_split_point.ssa_names_to_pass = BITMAP_ALLOC (NULL);
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
723 bitmap_copy (best_split_point.ssa_names_to_pass,
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
724 current->ssa_names_to_pass);
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
725 best_split_point.split_bbs = BITMAP_ALLOC (NULL);
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
726 bitmap_copy (best_split_point.split_bbs, current->split_bbs);
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
727 }
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
728 }
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
729
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
730 /* Return basic block containing RETURN statement. We allow basic blocks
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
731 of the form:
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
732 <retval> = tmp_var;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
733 return <retval>
|
145
|
734 but return_bb cannot be more complex than this (except for
|
111
|
735 -fsanitize=thread we allow TSAN_FUNC_EXIT () internal call in there).
|
|
736 If nothing is found, return the exit block.
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
737
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
738 When there are multiple RETURN statement, chose one with return value,
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
739 since that one is more likely shared by multiple code paths.
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
740
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
741 Return BB is special, because for function splitting it is the only
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
742 basic block that is duplicated in between header and split part of the
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
743 function.
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
744
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
745 TODO: We might support multiple return blocks. */
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
746
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
747 static basic_block
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
748 find_return_bb (void)
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
749 {
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
750 edge e;
|
111
|
751 basic_block return_bb = EXIT_BLOCK_PTR_FOR_FN (cfun);
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
752 gimple_stmt_iterator bsi;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
753 bool found_return = false;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
754 tree retval = NULL_TREE;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
755
|
111
|
756 if (!single_pred_p (EXIT_BLOCK_PTR_FOR_FN (cfun)))
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
757 return return_bb;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
758
|
111
|
759 e = single_pred_edge (EXIT_BLOCK_PTR_FOR_FN (cfun));
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
760 for (bsi = gsi_last_bb (e->src); !gsi_end_p (bsi); gsi_prev (&bsi))
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
761 {
|
111
|
762 gimple *stmt = gsi_stmt (bsi);
|
|
763 if (gimple_code (stmt) == GIMPLE_LABEL
|
|
764 || is_gimple_debug (stmt)
|
|
765 || gimple_clobber_p (stmt))
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
766 ;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
767 else if (gimple_code (stmt) == GIMPLE_ASSIGN
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
768 && found_return
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
769 && gimple_assign_single_p (stmt)
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
770 && (auto_var_in_fn_p (gimple_assign_rhs1 (stmt),
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
771 current_function_decl)
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
772 || is_gimple_min_invariant (gimple_assign_rhs1 (stmt)))
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
773 && retval == gimple_assign_lhs (stmt))
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
774 ;
|
111
|
775 else if (greturn *return_stmt = dyn_cast <greturn *> (stmt))
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
776 {
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
777 found_return = true;
|
111
|
778 retval = gimple_return_retval (return_stmt);
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
779 }
|
111
|
780 /* For -fsanitize=thread, allow also TSAN_FUNC_EXIT () in the return
|
|
781 bb. */
|
|
782 else if ((flag_sanitize & SANITIZE_THREAD)
|
|
783 && gimple_call_internal_p (stmt, IFN_TSAN_FUNC_EXIT))
|
|
784 ;
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
785 else
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
786 break;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
787 }
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
788 if (gsi_end_p (bsi) && found_return)
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
789 return_bb = e->src;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
790
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
791 return return_bb;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
792 }
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
793
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
794 /* Given return basic block RETURN_BB, see where return value is really
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
795 stored. */
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
796 static tree
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
797 find_retval (basic_block return_bb)
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
798 {
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
799 gimple_stmt_iterator bsi;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
800 for (bsi = gsi_start_bb (return_bb); !gsi_end_p (bsi); gsi_next (&bsi))
|
111
|
801 if (greturn *return_stmt = dyn_cast <greturn *> (gsi_stmt (bsi)))
|
|
802 return gimple_return_retval (return_stmt);
|
|
803 else if (gimple_code (gsi_stmt (bsi)) == GIMPLE_ASSIGN
|
|
804 && !gimple_clobber_p (gsi_stmt (bsi)))
|
|
805 return gimple_assign_rhs1 (gsi_stmt (bsi));
|
|
806 return NULL;
|
|
807 }
|
|
808
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
809 /* Callback for walk_stmt_load_store_addr_ops. If T is non-SSA automatic
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
810 variable, mark it as used in bitmap passed via DATA.
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
811 Return true when access to T prevents splitting the function. */
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
812
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
813 static bool
|
111
|
814 mark_nonssa_use (gimple *, tree t, tree, void *data)
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
815 {
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
816 t = get_base_address (t);
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
817
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
818 if (!t || is_gimple_reg (t))
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
819 return false;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
820
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
821 /* At present we can't pass non-SSA arguments to split function.
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
822 FIXME: this can be relaxed by passing references to arguments. */
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
823 if (TREE_CODE (t) == PARM_DECL)
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
824 {
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
825 if (dump_file && (dump_flags & TDF_DETAILS))
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
826 fprintf (dump_file,
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
827 "Cannot split: use of non-ssa function parameter.\n");
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
828 return true;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
829 }
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
830
|
111
|
831 if ((VAR_P (t) && auto_var_in_fn_p (t, current_function_decl))
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
832 || TREE_CODE (t) == RESULT_DECL
|
111
|
833 || (TREE_CODE (t) == LABEL_DECL && FORCED_LABEL (t)))
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
834 bitmap_set_bit ((bitmap)data, DECL_UID (t));
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
835
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
836 /* For DECL_BY_REFERENCE, the return value is actually a pointer. We want
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
837 to pretend that the value pointed to is actual result decl. */
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
838 if ((TREE_CODE (t) == MEM_REF || INDIRECT_REF_P (t))
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
839 && TREE_CODE (TREE_OPERAND (t, 0)) == SSA_NAME
|
111
|
840 && SSA_NAME_VAR (TREE_OPERAND (t, 0))
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
841 && TREE_CODE (SSA_NAME_VAR (TREE_OPERAND (t, 0))) == RESULT_DECL
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
842 && DECL_BY_REFERENCE (DECL_RESULT (current_function_decl)))
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
843 return
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
844 bitmap_bit_p ((bitmap)data,
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
845 DECL_UID (DECL_RESULT (current_function_decl)));
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
846
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
847 return false;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
848 }
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
849
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
850 /* Compute local properties of basic block BB we collect when looking for
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
851 split points. We look for ssa defs and store them in SET_SSA_NAMES,
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
852 for ssa uses and store them in USED_SSA_NAMES and for any non-SSA automatic
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
853 vars stored in NON_SSA_VARS.
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
854
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
855 When BB has edge to RETURN_BB, collect uses in RETURN_BB too.
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
856
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
857 Return false when BB contains something that prevents it from being put into
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
858 split function. */
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
859
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
860 static bool
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
861 visit_bb (basic_block bb, basic_block return_bb,
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
862 bitmap set_ssa_names, bitmap used_ssa_names,
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
863 bitmap non_ssa_vars)
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
864 {
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
865 edge e;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
866 edge_iterator ei;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
867 bool can_split = true;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
868
|
111
|
869 for (gimple_stmt_iterator bsi = gsi_start_bb (bb); !gsi_end_p (bsi);
|
|
870 gsi_next (&bsi))
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
871 {
|
111
|
872 gimple *stmt = gsi_stmt (bsi);
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
873 tree op;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
874 ssa_op_iter iter;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
875 tree decl;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
876
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
877 if (is_gimple_debug (stmt))
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
878 continue;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
879
|
111
|
880 if (gimple_clobber_p (stmt))
|
|
881 continue;
|
|
882
|
145
|
883 /* FIXME: We can split regions containing EH. We cannot however
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
884 split RESX, EH_DISPATCH and EH_POINTER referring to same region
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
885 into different partitions. This would require tracking of
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
886 EH regions and checking in consider_split_point if they
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
887 are not used elsewhere. */
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
888 if (gimple_code (stmt) == GIMPLE_RESX)
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
889 {
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
890 if (dump_file && (dump_flags & TDF_DETAILS))
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
891 fprintf (dump_file, "Cannot split: resx.\n");
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
892 can_split = false;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
893 }
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
894 if (gimple_code (stmt) == GIMPLE_EH_DISPATCH)
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
895 {
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
896 if (dump_file && (dump_flags & TDF_DETAILS))
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
897 fprintf (dump_file, "Cannot split: eh dispatch.\n");
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
898 can_split = false;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
899 }
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
900
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
901 /* Check builtins that prevent splitting. */
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
902 if (gimple_code (stmt) == GIMPLE_CALL
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
903 && (decl = gimple_call_fndecl (stmt)) != NULL_TREE
|
131
|
904 && fndecl_built_in_p (decl, BUILT_IN_NORMAL))
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
905 switch (DECL_FUNCTION_CODE (decl))
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
906 {
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
907 /* FIXME: once we will allow passing non-parm values to split part,
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
908 we need to be sure to handle correct builtin_stack_save and
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
909 builtin_stack_restore. At the moment we are safe; there is no
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
910 way to store builtin_stack_save result in non-SSA variable
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
911 since all calls to those are compiler generated. */
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
912 case BUILT_IN_APPLY:
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
913 case BUILT_IN_APPLY_ARGS:
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
914 case BUILT_IN_VA_START:
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
915 if (dump_file && (dump_flags & TDF_DETAILS))
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
916 fprintf (dump_file,
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
917 "Cannot split: builtin_apply and va_start.\n");
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
918 can_split = false;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
919 break;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
920 case BUILT_IN_EH_POINTER:
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
921 if (dump_file && (dump_flags & TDF_DETAILS))
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
922 fprintf (dump_file, "Cannot split: builtin_eh_pointer.\n");
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
923 can_split = false;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
924 break;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
925 default:
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
926 break;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
927 }
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
928
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
929 FOR_EACH_SSA_TREE_OPERAND (op, stmt, iter, SSA_OP_DEF)
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
930 bitmap_set_bit (set_ssa_names, SSA_NAME_VERSION (op));
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
931 FOR_EACH_SSA_TREE_OPERAND (op, stmt, iter, SSA_OP_USE)
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
932 bitmap_set_bit (used_ssa_names, SSA_NAME_VERSION (op));
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
933 can_split &= !walk_stmt_load_store_addr_ops (stmt, non_ssa_vars,
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
934 mark_nonssa_use,
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
935 mark_nonssa_use,
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
936 mark_nonssa_use);
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
937 }
|
111
|
938 for (gphi_iterator bsi = gsi_start_phis (bb); !gsi_end_p (bsi);
|
|
939 gsi_next (&bsi))
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
940 {
|
111
|
941 gphi *stmt = bsi.phi ();
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
942 unsigned int i;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
943
|
111
|
944 if (virtual_operand_p (gimple_phi_result (stmt)))
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
945 continue;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
946 bitmap_set_bit (set_ssa_names,
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
947 SSA_NAME_VERSION (gimple_phi_result (stmt)));
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
948 for (i = 0; i < gimple_phi_num_args (stmt); i++)
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
949 {
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
950 tree op = gimple_phi_arg_def (stmt, i);
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
951 if (TREE_CODE (op) == SSA_NAME)
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
952 bitmap_set_bit (used_ssa_names, SSA_NAME_VERSION (op));
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
953 }
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
954 can_split &= !walk_stmt_load_store_addr_ops (stmt, non_ssa_vars,
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
955 mark_nonssa_use,
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
956 mark_nonssa_use,
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
957 mark_nonssa_use);
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
958 }
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
959 /* Record also uses coming from PHI operand in return BB. */
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
960 FOR_EACH_EDGE (e, ei, bb->succs)
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
961 if (e->dest == return_bb)
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
962 {
|
111
|
963 for (gphi_iterator bsi = gsi_start_phis (return_bb);
|
|
964 !gsi_end_p (bsi);
|
|
965 gsi_next (&bsi))
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
966 {
|
111
|
967 gphi *stmt = bsi.phi ();
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
968 tree op = gimple_phi_arg_def (stmt, e->dest_idx);
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
969
|
111
|
970 if (virtual_operand_p (gimple_phi_result (stmt)))
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
971 continue;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
972 if (TREE_CODE (op) == SSA_NAME)
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
973 bitmap_set_bit (used_ssa_names, SSA_NAME_VERSION (op));
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
974 else
|
111
|
975 can_split &= !mark_nonssa_use (stmt, op, op, non_ssa_vars);
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
976 }
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
977 }
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
978 return can_split;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
979 }
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
980
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
981 /* Stack entry for recursive DFS walk in find_split_point. */
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
982
|
145
|
983 class stack_entry
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
984 {
|
145
|
985 public:
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
986 /* Basic block we are examining. */
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
987 basic_block bb;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
988
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
989 /* SSA names set and used by the BB and all BBs reachable
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
990 from it via DFS walk. */
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
991 bitmap set_ssa_names, used_ssa_names;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
992 bitmap non_ssa_vars;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
993
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
994 /* All BBS visited from this BB via DFS walk. */
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
995 bitmap bbs_visited;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
996
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
997 /* Last examined edge in DFS walk. Since we walk unoriented graph,
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
998 the value is up to sum of incoming and outgoing edges of BB. */
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
999 unsigned int edge_num;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1000
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1001 /* Stack entry index of earliest BB reachable from current BB
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1002 or any BB visited later in DFS walk. */
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1003 int earliest;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1004
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1005 /* Overall time and size of all BBs reached from this BB in DFS walk. */
|
131
|
1006 sreal overall_time;
|
|
1007 int overall_size;
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1008
|
145
|
1009 /* When false we cannot split on this BB. */
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1010 bool can_split;
|
111
|
1011 };
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1012
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1013
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1014 /* Find all articulations and call consider_split on them.
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1015 OVERALL_TIME and OVERALL_SIZE is time and size of the function.
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1016
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1017 We perform basic algorithm for finding an articulation in a graph
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1018 created from CFG by considering it to be an unoriented graph.
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1019
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1020 The articulation is discovered via DFS walk. We collect earliest
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1021 basic block on stack that is reachable via backward edge. Articulation
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1022 is any basic block such that there is no backward edge bypassing it.
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1023 To reduce stack usage we maintain heap allocated stack in STACK vector.
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1024 AUX pointer of BB is set to index it appears in the stack or -1 once
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1025 it is visited and popped off the stack.
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1026
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1027 The algorithm finds articulation after visiting the whole component
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1028 reachable by it. This makes it convenient to collect information about
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1029 the component used by consider_split. */
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1030
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1031 static void
|
131
|
1032 find_split_points (basic_block return_bb, sreal overall_time, int overall_size)
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1033 {
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1034 stack_entry first;
|
111
|
1035 vec<stack_entry> stack = vNULL;
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1036 basic_block bb;
|
145
|
1037 class split_point current;
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1038
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1039 current.header_time = overall_time;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1040 current.header_size = overall_size;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1041 current.split_time = 0;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1042 current.split_size = 0;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1043 current.ssa_names_to_pass = BITMAP_ALLOC (NULL);
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1044
|
111
|
1045 first.bb = ENTRY_BLOCK_PTR_FOR_FN (cfun);
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1046 first.edge_num = 0;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1047 first.overall_time = 0;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1048 first.overall_size = 0;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1049 first.earliest = INT_MAX;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1050 first.set_ssa_names = 0;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1051 first.used_ssa_names = 0;
|
111
|
1052 first.non_ssa_vars = 0;
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1053 first.bbs_visited = 0;
|
111
|
1054 first.can_split = false;
|
|
1055 stack.safe_push (first);
|
|
1056 ENTRY_BLOCK_PTR_FOR_FN (cfun)->aux = (void *)(intptr_t)-1;
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1057
|
111
|
1058 while (!stack.is_empty ())
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1059 {
|
111
|
1060 stack_entry *entry = &stack.last ();
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1061
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1062 /* We are walking an acyclic graph, so edge_num counts
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1063 succ and pred edges together. However when considering
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1064 articulation, we want to have processed everything reachable
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1065 from articulation but nothing that reaches into it. */
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1066 if (entry->edge_num == EDGE_COUNT (entry->bb->succs)
|
111
|
1067 && entry->bb != ENTRY_BLOCK_PTR_FOR_FN (cfun))
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1068 {
|
111
|
1069 int pos = stack.length ();
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1070 entry->can_split &= visit_bb (entry->bb, return_bb,
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1071 entry->set_ssa_names,
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1072 entry->used_ssa_names,
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1073 entry->non_ssa_vars);
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1074 if (pos <= entry->earliest && !entry->can_split
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1075 && dump_file && (dump_flags & TDF_DETAILS))
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1076 fprintf (dump_file,
|
145
|
1077 "found articulation at bb %i but cannot split\n",
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1078 entry->bb->index);
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1079 if (pos <= entry->earliest && entry->can_split)
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1080 {
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1081 if (dump_file && (dump_flags & TDF_DETAILS))
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1082 fprintf (dump_file, "found articulation at bb %i\n",
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1083 entry->bb->index);
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1084 current.entry_bb = entry->bb;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1085 current.ssa_names_to_pass = BITMAP_ALLOC (NULL);
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1086 bitmap_and_compl (current.ssa_names_to_pass,
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1087 entry->used_ssa_names, entry->set_ssa_names);
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1088 current.header_time = overall_time - entry->overall_time;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1089 current.header_size = overall_size - entry->overall_size;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1090 current.split_time = entry->overall_time;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1091 current.split_size = entry->overall_size;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1092 current.split_bbs = entry->bbs_visited;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1093 consider_split (¤t, entry->non_ssa_vars, return_bb);
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1094 BITMAP_FREE (current.ssa_names_to_pass);
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1095 }
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1096 }
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1097 /* Do actual DFS walk. */
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1098 if (entry->edge_num
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1099 < (EDGE_COUNT (entry->bb->succs)
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1100 + EDGE_COUNT (entry->bb->preds)))
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1101 {
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1102 edge e;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1103 basic_block dest;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1104 if (entry->edge_num < EDGE_COUNT (entry->bb->succs))
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1105 {
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1106 e = EDGE_SUCC (entry->bb, entry->edge_num);
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1107 dest = e->dest;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1108 }
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1109 else
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1110 {
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1111 e = EDGE_PRED (entry->bb, entry->edge_num
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1112 - EDGE_COUNT (entry->bb->succs));
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1113 dest = e->src;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1114 }
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1115
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1116 entry->edge_num++;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1117
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1118 /* New BB to visit, push it to the stack. */
|
111
|
1119 if (dest != return_bb && dest != EXIT_BLOCK_PTR_FOR_FN (cfun)
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1120 && !dest->aux)
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1121 {
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1122 stack_entry new_entry;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1123
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1124 new_entry.bb = dest;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1125 new_entry.edge_num = 0;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1126 new_entry.overall_time
|
111
|
1127 = bb_info_vec[dest->index].time;
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1128 new_entry.overall_size
|
111
|
1129 = bb_info_vec[dest->index].size;
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1130 new_entry.earliest = INT_MAX;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1131 new_entry.set_ssa_names = BITMAP_ALLOC (NULL);
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1132 new_entry.used_ssa_names = BITMAP_ALLOC (NULL);
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1133 new_entry.bbs_visited = BITMAP_ALLOC (NULL);
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1134 new_entry.non_ssa_vars = BITMAP_ALLOC (NULL);
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1135 new_entry.can_split = true;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1136 bitmap_set_bit (new_entry.bbs_visited, dest->index);
|
111
|
1137 stack.safe_push (new_entry);
|
|
1138 dest->aux = (void *)(intptr_t)stack.length ();
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1139 }
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1140 /* Back edge found, record the earliest point. */
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1141 else if ((intptr_t)dest->aux > 0
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1142 && (intptr_t)dest->aux < entry->earliest)
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1143 entry->earliest = (intptr_t)dest->aux;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1144 }
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1145 /* We are done with examining the edges. Pop off the value from stack
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1146 and merge stuff we accumulate during the walk. */
|
111
|
1147 else if (entry->bb != ENTRY_BLOCK_PTR_FOR_FN (cfun))
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1148 {
|
111
|
1149 stack_entry *prev = &stack[stack.length () - 2];
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1150
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1151 entry->bb->aux = (void *)(intptr_t)-1;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1152 prev->can_split &= entry->can_split;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1153 if (prev->set_ssa_names)
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1154 {
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1155 bitmap_ior_into (prev->set_ssa_names, entry->set_ssa_names);
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1156 bitmap_ior_into (prev->used_ssa_names, entry->used_ssa_names);
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1157 bitmap_ior_into (prev->bbs_visited, entry->bbs_visited);
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1158 bitmap_ior_into (prev->non_ssa_vars, entry->non_ssa_vars);
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1159 }
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1160 if (prev->earliest > entry->earliest)
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1161 prev->earliest = entry->earliest;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1162 prev->overall_time += entry->overall_time;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1163 prev->overall_size += entry->overall_size;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1164 BITMAP_FREE (entry->set_ssa_names);
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1165 BITMAP_FREE (entry->used_ssa_names);
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1166 BITMAP_FREE (entry->bbs_visited);
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1167 BITMAP_FREE (entry->non_ssa_vars);
|
111
|
1168 stack.pop ();
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1169 }
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1170 else
|
111
|
1171 stack.pop ();
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1172 }
|
111
|
1173 ENTRY_BLOCK_PTR_FOR_FN (cfun)->aux = NULL;
|
|
1174 FOR_EACH_BB_FN (bb, cfun)
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1175 bb->aux = NULL;
|
111
|
1176 stack.release ();
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1177 BITMAP_FREE (current.ssa_names_to_pass);
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1178 }
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1179
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1180 /* Split function at SPLIT_POINT. */
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1181
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1182 static void
|
145
|
1183 split_function (basic_block return_bb, class split_point *split_point,
|
111
|
1184 bool add_tsan_func_exit)
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1185 {
|
111
|
1186 vec<tree> args_to_pass = vNULL;
|
|
1187 bitmap args_to_skip;
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1188 tree parm;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1189 int num = 0;
|
111
|
1190 cgraph_node *node, *cur_node = cgraph_node::get (current_function_decl);
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1191 basic_block call_bb;
|
111
|
1192 gcall *call, *tsan_func_exit_call = NULL;
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1193 edge e;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1194 edge_iterator ei;
|
131
|
1195 tree retval = NULL, real_retval = NULL;
|
111
|
1196 gimple *last_stmt = NULL;
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1197 unsigned int i;
|
111
|
1198 tree arg, ddef;
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1199
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1200 if (dump_file)
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1201 {
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1202 fprintf (dump_file, "\n\nSplitting function at:\n");
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1203 dump_split_point (dump_file, split_point);
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1204 }
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1205
|
145
|
1206 if (cur_node->can_change_signature)
|
111
|
1207 args_to_skip = BITMAP_ALLOC (NULL);
|
|
1208 else
|
|
1209 args_to_skip = NULL;
|
|
1210
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1211 /* Collect the parameters of new function and args_to_skip bitmap. */
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1212 for (parm = DECL_ARGUMENTS (current_function_decl);
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1213 parm; parm = DECL_CHAIN (parm), num++)
|
111
|
1214 if (args_to_skip
|
|
1215 && (!is_gimple_reg (parm)
|
|
1216 || (ddef = ssa_default_def (cfun, parm)) == NULL_TREE
|
|
1217 || !bitmap_bit_p (split_point->ssa_names_to_pass,
|
|
1218 SSA_NAME_VERSION (ddef))))
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1219 bitmap_set_bit (args_to_skip, num);
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1220 else
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1221 {
|
111
|
1222 /* This parm might not have been used up to now, but is going to be
|
|
1223 used, hence register it. */
|
|
1224 if (is_gimple_reg (parm))
|
|
1225 arg = get_or_create_ssa_default_def (cfun, parm);
|
|
1226 else
|
|
1227 arg = parm;
|
|
1228
|
|
1229 if (!useless_type_conversion_p (DECL_ARG_TYPE (parm), TREE_TYPE (arg)))
|
|
1230 arg = fold_convert (DECL_ARG_TYPE (parm), arg);
|
|
1231 args_to_pass.safe_push (arg);
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1232 }
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1233
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1234 /* See if the split function will return. */
|
111
|
1235 bool split_part_return_p = false;
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1236 FOR_EACH_EDGE (e, ei, return_bb->preds)
|
111
|
1237 {
|
|
1238 if (bitmap_bit_p (split_point->split_bbs, e->src->index))
|
|
1239 split_part_return_p = true;
|
|
1240 }
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1241
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1242 /* Add return block to what will become the split function.
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1243 We do not return; no return block is needed. */
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1244 if (!split_part_return_p)
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1245 ;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1246 /* We have no return block, so nothing is needed. */
|
111
|
1247 else if (return_bb == EXIT_BLOCK_PTR_FOR_FN (cfun))
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1248 ;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1249 /* When we do not want to return value, we need to construct
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1250 new return block with empty return statement.
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1251 FIXME: Once we are able to change return type, we should change function
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1252 to return void instead of just outputting function with undefined return
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1253 value. For structures this affects quality of codegen. */
|
111
|
1254 else if ((retval = find_retval (return_bb))
|
|
1255 && !split_point->split_part_set_retval)
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1256 {
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1257 bool redirected = true;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1258 basic_block new_return_bb = create_basic_block (NULL, 0, return_bb);
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1259 gimple_stmt_iterator gsi = gsi_start_bb (new_return_bb);
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1260 gsi_insert_after (&gsi, gimple_build_return (NULL), GSI_NEW_STMT);
|
111
|
1261 new_return_bb->count = profile_count::zero ();
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1262 while (redirected)
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1263 {
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1264 redirected = false;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1265 FOR_EACH_EDGE (e, ei, return_bb->preds)
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1266 if (bitmap_bit_p (split_point->split_bbs, e->src->index))
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1267 {
|
131
|
1268 new_return_bb->count += e->count ();
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1269 redirect_edge_and_branch (e, new_return_bb);
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1270 redirected = true;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1271 break;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1272 }
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1273 }
|
111
|
1274 e = make_single_succ_edge (new_return_bb, EXIT_BLOCK_PTR_FOR_FN (cfun), 0);
|
|
1275 add_bb_to_loop (new_return_bb, current_loops->tree_root);
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1276 bitmap_set_bit (split_point->split_bbs, new_return_bb->index);
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1277 }
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1278 /* When we pass around the value, use existing return block. */
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1279 else
|
131
|
1280 bitmap_set_bit (split_point->split_bbs, return_bb->index);
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1281
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1282 /* If RETURN_BB has virtual operand PHIs, they must be removed and the
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1283 virtual operand marked for renaming as we change the CFG in a way that
|
111
|
1284 tree-inline is not able to compensate for.
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1285
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1286 Note this can happen whether or not we have a return value. If we have
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1287 a return value, then RETURN_BB may have PHIs for real operands too. */
|
111
|
1288 if (return_bb != EXIT_BLOCK_PTR_FOR_FN (cfun))
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1289 {
|
111
|
1290 bool phi_p = false;
|
|
1291 for (gphi_iterator gsi = gsi_start_phis (return_bb);
|
|
1292 !gsi_end_p (gsi);)
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1293 {
|
111
|
1294 gphi *stmt = gsi.phi ();
|
|
1295 if (!virtual_operand_p (gimple_phi_result (stmt)))
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1296 {
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1297 gsi_next (&gsi);
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1298 continue;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1299 }
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1300 mark_virtual_phi_result_for_renaming (stmt);
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1301 remove_phi_node (&gsi, true);
|
111
|
1302 phi_p = true;
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1303 }
|
111
|
1304 /* In reality we have to rename the reaching definition of the
|
|
1305 virtual operand at return_bb as we will eventually release it
|
|
1306 when we remove the code region we outlined.
|
|
1307 So we have to rename all immediate virtual uses of that region
|
|
1308 if we didn't see a PHI definition yet. */
|
|
1309 /* ??? In real reality we want to set the reaching vdef of the
|
|
1310 entry of the SESE region as the vuse of the call and the reaching
|
|
1311 vdef of the exit of the SESE region as the vdef of the call. */
|
|
1312 if (!phi_p)
|
|
1313 for (gimple_stmt_iterator gsi = gsi_start_bb (return_bb);
|
|
1314 !gsi_end_p (gsi);
|
|
1315 gsi_next (&gsi))
|
|
1316 {
|
|
1317 gimple *stmt = gsi_stmt (gsi);
|
|
1318 if (gimple_vuse (stmt))
|
|
1319 {
|
|
1320 gimple_set_vuse (stmt, NULL_TREE);
|
|
1321 update_stmt (stmt);
|
|
1322 }
|
|
1323 if (gimple_vdef (stmt))
|
|
1324 break;
|
|
1325 }
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1326 }
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1327
|
145
|
1328 ipa_param_adjustments *adjustments;
|
|
1329 bool skip_return = (!split_part_return_p
|
|
1330 || !split_point->split_part_set_retval);
|
|
1331 /* TODO: Perhaps get rid of args_to_skip entirely, after we make sure the
|
|
1332 debug info generation and discrepancy avoiding works well too. */
|
|
1333 if ((args_to_skip && !bitmap_empty_p (args_to_skip))
|
|
1334 || skip_return)
|
|
1335 {
|
|
1336 vec<ipa_adjusted_param, va_gc> *new_params = NULL;
|
|
1337 unsigned j;
|
|
1338 for (parm = DECL_ARGUMENTS (current_function_decl), j = 0;
|
|
1339 parm; parm = DECL_CHAIN (parm), j++)
|
|
1340 if (!args_to_skip || !bitmap_bit_p (args_to_skip, j))
|
|
1341 {
|
|
1342 ipa_adjusted_param adj;
|
|
1343 memset (&adj, 0, sizeof (adj));
|
|
1344 adj.op = IPA_PARAM_OP_COPY;
|
|
1345 adj.base_index = j;
|
|
1346 adj.prev_clone_index = j;
|
|
1347 vec_safe_push (new_params, adj);
|
|
1348 }
|
|
1349 adjustments = new ipa_param_adjustments (new_params, j, skip_return);
|
|
1350 }
|
|
1351 else
|
|
1352 adjustments = NULL;
|
|
1353
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1354 /* Now create the actual clone. */
|
111
|
1355 cgraph_edge::rebuild_edges ();
|
|
1356 node = cur_node->create_version_clone_with_body
|
145
|
1357 (vNULL, NULL, adjustments,
|
111
|
1358 split_point->split_bbs, split_point->entry_bb, "part");
|
145
|
1359 delete adjustments;
|
111
|
1360 node->split_part = true;
|
|
1361
|
|
1362 if (cur_node->same_comdat_group)
|
|
1363 {
|
|
1364 /* TODO: call is versionable if we make sure that all
|
|
1365 callers are inside of a comdat group. */
|
|
1366 cur_node->calls_comdat_local = 1;
|
|
1367 node->add_to_same_comdat_group (cur_node);
|
|
1368 }
|
|
1369
|
|
1370
|
|
1371 /* Let's take a time profile for splitted function. */
|
145
|
1372 if (cur_node->tp_first_run)
|
|
1373 node->tp_first_run = cur_node->tp_first_run + 1;
|
111
|
1374
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1375 /* For usual cloning it is enough to clear builtin only when signature
|
145
|
1376 changes. For partial inlining we however cannot expect the part
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1377 of builtin implementation to have same semantic as the whole. */
|
131
|
1378 if (fndecl_built_in_p (node->decl))
|
145
|
1379 set_decl_built_in_function (node->decl, NOT_BUILT_IN, 0);
|
111
|
1380
|
|
1381 /* If return_bb contains any clobbers that refer to SSA_NAMEs
|
|
1382 set in the split part, remove them. Also reset debug stmts that
|
|
1383 refer to SSA_NAMEs set in the split part. */
|
|
1384 if (return_bb != EXIT_BLOCK_PTR_FOR_FN (cfun))
|
|
1385 {
|
|
1386 gimple_stmt_iterator gsi = gsi_start_bb (return_bb);
|
|
1387 while (!gsi_end_p (gsi))
|
|
1388 {
|
|
1389 tree op;
|
|
1390 ssa_op_iter iter;
|
|
1391 gimple *stmt = gsi_stmt (gsi);
|
|
1392 bool remove = false;
|
|
1393 if (gimple_clobber_p (stmt) || is_gimple_debug (stmt))
|
|
1394 FOR_EACH_SSA_TREE_OPERAND (op, stmt, iter, SSA_OP_USE)
|
|
1395 {
|
|
1396 basic_block bb = gimple_bb (SSA_NAME_DEF_STMT (op));
|
|
1397 if (op != retval
|
|
1398 && bb
|
|
1399 && bb != return_bb
|
|
1400 && bitmap_bit_p (split_point->split_bbs, bb->index))
|
|
1401 {
|
|
1402 if (is_gimple_debug (stmt))
|
|
1403 {
|
|
1404 gimple_debug_bind_reset_value (stmt);
|
|
1405 update_stmt (stmt);
|
|
1406 }
|
|
1407 else
|
|
1408 remove = true;
|
|
1409 break;
|
|
1410 }
|
|
1411 }
|
|
1412 if (remove)
|
|
1413 gsi_remove (&gsi, true);
|
|
1414 else
|
|
1415 gsi_next (&gsi);
|
|
1416 }
|
|
1417 }
|
|
1418
|
|
1419 /* If the original function is declared inline, there is no point in issuing
|
|
1420 a warning for the non-inlinable part. */
|
|
1421 DECL_NO_INLINE_WARNING_P (node->decl) = 1;
|
|
1422 cur_node->remove_callees ();
|
|
1423 cur_node->remove_all_references ();
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1424 if (!split_part_return_p)
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1425 TREE_THIS_VOLATILE (node->decl) = 1;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1426 if (dump_file)
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1427 dump_function_to_file (node->decl, dump_file, dump_flags);
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1428
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1429 /* Create the basic block we place call into. It is the entry basic block
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1430 split after last label. */
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1431 call_bb = split_point->entry_bb;
|
111
|
1432 for (gimple_stmt_iterator gsi = gsi_start_bb (call_bb); !gsi_end_p (gsi);)
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1433 if (gimple_code (gsi_stmt (gsi)) == GIMPLE_LABEL)
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1434 {
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1435 last_stmt = gsi_stmt (gsi);
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1436 gsi_next (&gsi);
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1437 }
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1438 else
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1439 break;
|
131
|
1440 call_bb->count = split_point->count;
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1441 e = split_block (split_point->entry_bb, last_stmt);
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1442 remove_edge (e);
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1443
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1444 /* Produce the call statement. */
|
111
|
1445 gimple_stmt_iterator gsi = gsi_last_bb (call_bb);
|
|
1446 FOR_EACH_VEC_ELT (args_to_pass, i, arg)
|
|
1447 if (!is_gimple_val (arg))
|
|
1448 {
|
|
1449 arg = force_gimple_operand_gsi (&gsi, arg, true, NULL_TREE,
|
|
1450 false, GSI_CONTINUE_LINKING);
|
|
1451 args_to_pass[i] = arg;
|
|
1452 }
|
|
1453 call = gimple_build_call_vec (node->decl, args_to_pass);
|
|
1454 gimple_set_block (call, DECL_INITIAL (current_function_decl));
|
|
1455 args_to_pass.release ();
|
|
1456
|
|
1457 /* For optimized away parameters, add on the caller side
|
|
1458 before the call
|
|
1459 DEBUG D#X => parm_Y(D)
|
|
1460 stmts and associate D#X with parm in decl_debug_args_lookup
|
|
1461 vector to say for debug info that if parameter parm had been passed,
|
|
1462 it would have value parm_Y(D). */
|
|
1463 if (args_to_skip)
|
|
1464 {
|
|
1465 vec<tree, va_gc> **debug_args = NULL;
|
|
1466 unsigned i = 0, len = 0;
|
131
|
1467 if (MAY_HAVE_DEBUG_BIND_STMTS)
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1468 {
|
111
|
1469 debug_args = decl_debug_args_lookup (node->decl);
|
|
1470 if (debug_args)
|
|
1471 len = vec_safe_length (*debug_args);
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1472 }
|
111
|
1473 for (parm = DECL_ARGUMENTS (current_function_decl), num = 0;
|
|
1474 parm; parm = DECL_CHAIN (parm), num++)
|
|
1475 if (bitmap_bit_p (args_to_skip, num) && is_gimple_reg (parm))
|
|
1476 {
|
|
1477 tree ddecl;
|
|
1478 gimple *def_temp;
|
|
1479
|
131
|
1480 /* This needs to be done even without
|
|
1481 MAY_HAVE_DEBUG_BIND_STMTS, otherwise if it didn't exist
|
|
1482 before, we'd end up with different SSA_NAME_VERSIONs
|
|
1483 between -g and -g0. */
|
111
|
1484 arg = get_or_create_ssa_default_def (cfun, parm);
|
131
|
1485 if (!MAY_HAVE_DEBUG_BIND_STMTS || debug_args == NULL)
|
111
|
1486 continue;
|
|
1487
|
|
1488 while (i < len && (**debug_args)[i] != DECL_ORIGIN (parm))
|
|
1489 i += 2;
|
|
1490 if (i >= len)
|
|
1491 continue;
|
|
1492 ddecl = (**debug_args)[i + 1];
|
|
1493 def_temp
|
|
1494 = gimple_build_debug_bind (ddecl, unshare_expr (arg), call);
|
|
1495 gsi_insert_after (&gsi, def_temp, GSI_NEW_STMT);
|
|
1496 }
|
145
|
1497 BITMAP_FREE (args_to_skip);
|
111
|
1498 }
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1499
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1500 /* We avoid address being taken on any variable used by split part,
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1501 so return slot optimization is always possible. Moreover this is
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1502 required to make DECL_BY_REFERENCE work. */
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1503 if (aggregate_value_p (DECL_RESULT (current_function_decl),
|
111
|
1504 TREE_TYPE (current_function_decl))
|
|
1505 && (!is_gimple_reg_type (TREE_TYPE (DECL_RESULT (current_function_decl)))
|
|
1506 || DECL_BY_REFERENCE (DECL_RESULT (current_function_decl))))
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1507 gimple_call_set_return_slot_opt (call, true);
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1508
|
111
|
1509 if (add_tsan_func_exit)
|
|
1510 tsan_func_exit_call = gimple_build_call_internal (IFN_TSAN_FUNC_EXIT, 0);
|
|
1511
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1512 /* Update return value. This is bit tricky. When we do not return,
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1513 do nothing. When we return we might need to update return_bb
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1514 or produce a new return statement. */
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1515 if (!split_part_return_p)
|
111
|
1516 {
|
|
1517 gsi_insert_after (&gsi, call, GSI_NEW_STMT);
|
|
1518 if (tsan_func_exit_call)
|
|
1519 gsi_insert_after (&gsi, tsan_func_exit_call, GSI_NEW_STMT);
|
|
1520 }
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1521 else
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1522 {
|
111
|
1523 e = make_single_succ_edge (call_bb, return_bb,
|
|
1524 return_bb == EXIT_BLOCK_PTR_FOR_FN (cfun)
|
|
1525 ? 0 : EDGE_FALLTHRU);
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1526
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1527 /* If there is return basic block, see what value we need to store
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1528 return value into and put call just before it. */
|
111
|
1529 if (return_bb != EXIT_BLOCK_PTR_FOR_FN (cfun))
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1530 {
|
111
|
1531 real_retval = retval;
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1532 if (real_retval && split_point->split_part_set_retval)
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1533 {
|
111
|
1534 gphi_iterator psi;
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1535
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1536 /* See if we need new SSA_NAME for the result.
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1537 When DECL_BY_REFERENCE is true, retval is actually pointer to
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1538 return value and it is constant in whole function. */
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1539 if (TREE_CODE (retval) == SSA_NAME
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1540 && !DECL_BY_REFERENCE (DECL_RESULT (current_function_decl)))
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1541 {
|
111
|
1542 retval = copy_ssa_name (retval, call);
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1543
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1544 /* See if there is PHI defining return value. */
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1545 for (psi = gsi_start_phis (return_bb);
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1546 !gsi_end_p (psi); gsi_next (&psi))
|
111
|
1547 if (!virtual_operand_p (gimple_phi_result (psi.phi ())))
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1548 break;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1549
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1550 /* When there is PHI, just update its value. */
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1551 if (TREE_CODE (retval) == SSA_NAME
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1552 && !gsi_end_p (psi))
|
111
|
1553 add_phi_arg (psi.phi (), retval, e, UNKNOWN_LOCATION);
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1554 /* Otherwise update the return BB itself.
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1555 find_return_bb allows at most one assignment to return value,
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1556 so update first statement. */
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1557 else
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1558 {
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1559 gimple_stmt_iterator bsi;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1560 for (bsi = gsi_start_bb (return_bb); !gsi_end_p (bsi);
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1561 gsi_next (&bsi))
|
111
|
1562 if (greturn *return_stmt
|
|
1563 = dyn_cast <greturn *> (gsi_stmt (bsi)))
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1564 {
|
111
|
1565 gimple_return_set_retval (return_stmt, retval);
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1566 break;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1567 }
|
111
|
1568 else if (gimple_code (gsi_stmt (bsi)) == GIMPLE_ASSIGN
|
|
1569 && !gimple_clobber_p (gsi_stmt (bsi)))
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1570 {
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1571 gimple_assign_set_rhs1 (gsi_stmt (bsi), retval);
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1572 break;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1573 }
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1574 update_stmt (gsi_stmt (bsi));
|
111
|
1575 /* Also adjust clobbers and debug stmts in return_bb. */
|
|
1576 for (bsi = gsi_start_bb (return_bb); !gsi_end_p (bsi);
|
|
1577 gsi_next (&bsi))
|
|
1578 {
|
|
1579 gimple *stmt = gsi_stmt (bsi);
|
|
1580 if (gimple_clobber_p (stmt)
|
|
1581 || is_gimple_debug (stmt))
|
|
1582 {
|
|
1583 ssa_op_iter iter;
|
|
1584 use_operand_p use_p;
|
|
1585 bool update = false;
|
|
1586 FOR_EACH_SSA_USE_OPERAND (use_p, stmt, iter,
|
|
1587 SSA_OP_USE)
|
|
1588 if (USE_FROM_PTR (use_p) == real_retval)
|
|
1589 {
|
|
1590 SET_USE (use_p, retval);
|
|
1591 update = true;
|
|
1592 }
|
|
1593 if (update)
|
|
1594 update_stmt (stmt);
|
|
1595 }
|
|
1596 }
|
|
1597 }
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1598 }
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1599 if (DECL_BY_REFERENCE (DECL_RESULT (current_function_decl)))
|
111
|
1600 {
|
|
1601 gimple_call_set_lhs (call, build_simple_mem_ref (retval));
|
|
1602 gsi_insert_after (&gsi, call, GSI_NEW_STMT);
|
|
1603 }
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1604 else
|
111
|
1605 {
|
|
1606 tree restype;
|
|
1607 restype = TREE_TYPE (DECL_RESULT (current_function_decl));
|
|
1608 gsi_insert_after (&gsi, call, GSI_NEW_STMT);
|
|
1609 if (!useless_type_conversion_p (TREE_TYPE (retval), restype))
|
|
1610 {
|
|
1611 gimple *cpy;
|
|
1612 tree tem = create_tmp_reg (restype);
|
|
1613 tem = make_ssa_name (tem, call);
|
|
1614 cpy = gimple_build_assign (retval, NOP_EXPR, tem);
|
|
1615 gsi_insert_after (&gsi, cpy, GSI_NEW_STMT);
|
|
1616 retval = tem;
|
|
1617 }
|
|
1618 gimple_call_set_lhs (call, retval);
|
|
1619 update_stmt (call);
|
|
1620 }
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1621 }
|
111
|
1622 else
|
|
1623 gsi_insert_after (&gsi, call, GSI_NEW_STMT);
|
|
1624 if (tsan_func_exit_call)
|
|
1625 gsi_insert_after (&gsi, tsan_func_exit_call, GSI_NEW_STMT);
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1626 }
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1627 /* We don't use return block (there is either no return in function or
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1628 multiple of them). So create new basic block with return statement.
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1629 */
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1630 else
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1631 {
|
111
|
1632 greturn *ret;
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1633 if (split_point->split_part_set_retval
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1634 && !VOID_TYPE_P (TREE_TYPE (TREE_TYPE (current_function_decl))))
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1635 {
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1636 retval = DECL_RESULT (current_function_decl);
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1637
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1638 /* We use temporary register to hold value when aggregate_value_p
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1639 is false. Similarly for DECL_BY_REFERENCE we must avoid extra
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1640 copy. */
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1641 if (!aggregate_value_p (retval, TREE_TYPE (current_function_decl))
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1642 && !DECL_BY_REFERENCE (retval))
|
111
|
1643 retval = create_tmp_reg (TREE_TYPE (retval));
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1644 if (is_gimple_reg (retval))
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1645 {
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1646 /* When returning by reference, there is only one SSA name
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1647 assigned to RESULT_DECL (that is pointer to return value).
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1648 Look it up or create new one if it is missing. */
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1649 if (DECL_BY_REFERENCE (retval))
|
111
|
1650 retval = get_or_create_ssa_default_def (cfun, retval);
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1651 /* Otherwise produce new SSA name for return value. */
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1652 else
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1653 retval = make_ssa_name (retval, call);
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1654 }
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1655 if (DECL_BY_REFERENCE (DECL_RESULT (current_function_decl)))
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1656 gimple_call_set_lhs (call, build_simple_mem_ref (retval));
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1657 else
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1658 gimple_call_set_lhs (call, retval);
|
111
|
1659 gsi_insert_after (&gsi, call, GSI_NEW_STMT);
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1660 }
|
111
|
1661 else
|
|
1662 {
|
|
1663 gsi_insert_after (&gsi, call, GSI_NEW_STMT);
|
|
1664 if (retval
|
|
1665 && is_gimple_reg_type (TREE_TYPE (retval))
|
|
1666 && !is_gimple_val (retval))
|
|
1667 {
|
|
1668 gassign *g
|
|
1669 = gimple_build_assign (make_ssa_name (TREE_TYPE (retval)),
|
|
1670 retval);
|
|
1671 retval = gimple_assign_lhs (g);
|
|
1672 gsi_insert_after (&gsi, g, GSI_NEW_STMT);
|
|
1673 }
|
|
1674 }
|
|
1675 if (tsan_func_exit_call)
|
|
1676 gsi_insert_after (&gsi, tsan_func_exit_call, GSI_NEW_STMT);
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1677 ret = gimple_build_return (retval);
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1678 gsi_insert_after (&gsi, ret, GSI_NEW_STMT);
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1679 }
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1680 }
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1681 free_dominance_info (CDI_DOMINATORS);
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1682 free_dominance_info (CDI_POST_DOMINATORS);
|
111
|
1683 compute_fn_summary (node, true);
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1684 }
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1685
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1686 /* Execute function splitting pass. */
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1687
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1688 static unsigned int
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1689 execute_split_functions (void)
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1690 {
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1691 gimple_stmt_iterator bsi;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1692 basic_block bb;
|
131
|
1693 sreal overall_time = 0;
|
|
1694 int overall_size = 0;
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1695 int todo = 0;
|
111
|
1696 struct cgraph_node *node = cgraph_node::get (current_function_decl);
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1697
|
111
|
1698 if (flags_from_decl_or_type (current_function_decl)
|
|
1699 & (ECF_NORETURN|ECF_MALLOC))
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1700 {
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1701 if (dump_file)
|
111
|
1702 fprintf (dump_file, "Not splitting: noreturn/malloc function.\n");
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1703 return 0;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1704 }
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1705 if (MAIN_NAME_P (DECL_NAME (current_function_decl)))
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1706 {
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1707 if (dump_file)
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1708 fprintf (dump_file, "Not splitting: main function.\n");
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1709 return 0;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1710 }
|
131
|
1711 if (node->frequency == NODE_FREQUENCY_UNLIKELY_EXECUTED)
|
|
1712 {
|
|
1713 if (dump_file)
|
|
1714 fprintf (dump_file, "Not splitting: function is unlikely executed.\n");
|
|
1715 return 0;
|
|
1716 }
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1717 /* This can be relaxed; function might become inlinable after splitting
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1718 away the uninlinable part. */
|
111
|
1719 if (ipa_fn_summaries
|
131
|
1720 && ipa_fn_summaries->get (node)
|
111
|
1721 && !ipa_fn_summaries->get (node)->inlinable)
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1722 {
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1723 if (dump_file)
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1724 fprintf (dump_file, "Not splitting: not inlinable.\n");
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1725 return 0;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1726 }
|
111
|
1727 if (DECL_DISREGARD_INLINE_LIMITS (node->decl))
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1728 {
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1729 if (dump_file)
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1730 fprintf (dump_file, "Not splitting: disregarding inline limits.\n");
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1731 return 0;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1732 }
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1733 /* This can be relaxed; most of versioning tests actually prevents
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1734 a duplication. */
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1735 if (!tree_versionable_function_p (current_function_decl))
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1736 {
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1737 if (dump_file)
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1738 fprintf (dump_file, "Not splitting: not versionable.\n");
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1739 return 0;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1740 }
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1741 /* FIXME: we could support this. */
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1742 if (DECL_STRUCT_FUNCTION (current_function_decl)->static_chain_decl)
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1743 {
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1744 if (dump_file)
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1745 fprintf (dump_file, "Not splitting: nested function.\n");
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1746 return 0;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1747 }
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1748
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1749 /* See if it makes sense to try to split.
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1750 It makes sense to split if we inline, that is if we have direct calls to
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1751 handle or direct calls are possibly going to appear as result of indirect
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1752 inlining or LTO. Also handle -fprofile-generate as LTO to allow non-LTO
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1753 training for LTO -fprofile-use build.
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1754
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1755 Note that we are not completely conservative about disqualifying functions
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1756 called once. It is possible that the caller is called more then once and
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1757 then inlining would still benefit. */
|
111
|
1758 if ((!node->callers
|
|
1759 /* Local functions called once will be completely inlined most of time. */
|
145
|
1760 || (!node->callers->next_caller && node->local))
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1761 && !node->address_taken
|
111
|
1762 && !node->has_aliases_p ()
|
|
1763 && (!flag_lto || !node->externally_visible))
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1764 {
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1765 if (dump_file)
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1766 fprintf (dump_file, "Not splitting: not called directly "
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1767 "or called once.\n");
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1768 return 0;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1769 }
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1770
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1771 /* FIXME: We can actually split if splitting reduces call overhead. */
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1772 if (!flag_inline_small_functions
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1773 && !DECL_DECLARED_INLINE_P (current_function_decl))
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1774 {
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1775 if (dump_file)
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1776 fprintf (dump_file, "Not splitting: not autoinlining and function"
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1777 " is not inline.\n");
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1778 return 0;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1779 }
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1780
|
145
|
1781 if (lookup_attribute ("noinline", DECL_ATTRIBUTES (current_function_decl)))
|
|
1782 {
|
|
1783 if (dump_file)
|
|
1784 fprintf (dump_file, "Not splitting: function is noinline.\n");
|
|
1785 return 0;
|
|
1786 }
|
|
1787 if (lookup_attribute ("section", DECL_ATTRIBUTES (current_function_decl)))
|
|
1788 {
|
|
1789 if (dump_file)
|
|
1790 fprintf (dump_file, "Not splitting: function is in user defined "
|
|
1791 "section.\n");
|
|
1792 return 0;
|
|
1793 }
|
|
1794
|
111
|
1795 /* We enforce splitting after loop headers when profile info is not
|
|
1796 available. */
|
|
1797 if (profile_status_for_fn (cfun) != PROFILE_READ)
|
|
1798 mark_dfs_back_edges ();
|
|
1799
|
|
1800 /* Initialize bitmap to track forbidden calls. */
|
|
1801 forbidden_dominators = BITMAP_ALLOC (NULL);
|
|
1802 calculate_dominance_info (CDI_DOMINATORS);
|
|
1803
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1804 /* Compute local info about basic blocks and determine function size/time. */
|
111
|
1805 bb_info_vec.safe_grow_cleared (last_basic_block_for_fn (cfun) + 1);
|
131
|
1806 best_split_point.split_bbs = NULL;
|
111
|
1807 basic_block return_bb = find_return_bb ();
|
|
1808 int tsan_exit_found = -1;
|
|
1809 FOR_EACH_BB_FN (bb, cfun)
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1810 {
|
131
|
1811 sreal time = 0;
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1812 int size = 0;
|
131
|
1813 sreal freq = bb->count.to_sreal_scale
|
|
1814 (ENTRY_BLOCK_PTR_FOR_FN (cfun)->count);
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1815
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1816 if (dump_file && (dump_flags & TDF_DETAILS))
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1817 fprintf (dump_file, "Basic block %i\n", bb->index);
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1818
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1819 for (bsi = gsi_start_bb (bb); !gsi_end_p (bsi); gsi_next (&bsi))
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1820 {
|
131
|
1821 sreal this_time;
|
|
1822 int this_size;
|
111
|
1823 gimple *stmt = gsi_stmt (bsi);
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1824
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1825 this_size = estimate_num_insns (stmt, &eni_size_weights);
|
131
|
1826 this_time = (sreal)estimate_num_insns (stmt, &eni_time_weights)
|
|
1827 * freq;
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1828 size += this_size;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1829 time += this_time;
|
111
|
1830 check_forbidden_calls (stmt);
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1831
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1832 if (dump_file && (dump_flags & TDF_DETAILS))
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1833 {
|
131
|
1834 fprintf (dump_file, " freq:%4.2f size:%3i time:%4.2f ",
|
|
1835 freq.to_double (), this_size, this_time.to_double ());
|
111
|
1836 print_gimple_stmt (dump_file, stmt, 0);
|
|
1837 }
|
|
1838
|
|
1839 if ((flag_sanitize & SANITIZE_THREAD)
|
|
1840 && gimple_call_internal_p (stmt, IFN_TSAN_FUNC_EXIT))
|
|
1841 {
|
|
1842 /* We handle TSAN_FUNC_EXIT for splitting either in the
|
|
1843 return_bb, or in its immediate predecessors. */
|
|
1844 if ((bb != return_bb && !find_edge (bb, return_bb))
|
|
1845 || (tsan_exit_found != -1
|
|
1846 && tsan_exit_found != (bb != return_bb)))
|
|
1847 {
|
|
1848 if (dump_file)
|
|
1849 fprintf (dump_file, "Not splitting: TSAN_FUNC_EXIT"
|
|
1850 " in unexpected basic block.\n");
|
|
1851 BITMAP_FREE (forbidden_dominators);
|
|
1852 bb_info_vec.release ();
|
|
1853 return 0;
|
|
1854 }
|
|
1855 tsan_exit_found = bb != return_bb;
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1856 }
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1857 }
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1858 overall_time += time;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1859 overall_size += size;
|
111
|
1860 bb_info_vec[bb->index].time = time;
|
|
1861 bb_info_vec[bb->index].size = size;
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1862 }
|
111
|
1863 find_split_points (return_bb, overall_time, overall_size);
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1864 if (best_split_point.split_bbs)
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1865 {
|
111
|
1866 split_function (return_bb, &best_split_point, tsan_exit_found == 1);
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1867 BITMAP_FREE (best_split_point.ssa_names_to_pass);
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1868 BITMAP_FREE (best_split_point.split_bbs);
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1869 todo = TODO_update_ssa | TODO_cleanup_cfg;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1870 }
|
111
|
1871 BITMAP_FREE (forbidden_dominators);
|
|
1872 bb_info_vec.release ();
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1873 return todo;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1874 }
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1875
|
111
|
1876 namespace {
|
|
1877
|
|
1878 const pass_data pass_data_split_functions =
|
|
1879 {
|
|
1880 GIMPLE_PASS, /* type */
|
|
1881 "fnsplit", /* name */
|
|
1882 OPTGROUP_NONE, /* optinfo_flags */
|
|
1883 TV_IPA_FNSPLIT, /* tv_id */
|
|
1884 PROP_cfg, /* properties_required */
|
|
1885 0, /* properties_provided */
|
|
1886 0, /* properties_destroyed */
|
|
1887 0, /* todo_flags_start */
|
|
1888 0, /* todo_flags_finish */
|
|
1889 };
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1890
|
111
|
1891 class pass_split_functions : public gimple_opt_pass
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1892 {
|
111
|
1893 public:
|
|
1894 pass_split_functions (gcc::context *ctxt)
|
|
1895 : gimple_opt_pass (pass_data_split_functions, ctxt)
|
|
1896 {}
|
|
1897
|
|
1898 /* opt_pass methods: */
|
|
1899 virtual bool gate (function *);
|
|
1900 virtual unsigned int execute (function *)
|
|
1901 {
|
|
1902 return execute_split_functions ();
|
|
1903 }
|
|
1904
|
|
1905 }; // class pass_split_functions
|
|
1906
|
|
1907 bool
|
|
1908 pass_split_functions::gate (function *)
|
|
1909 {
|
|
1910 /* When doing profile feedback, we want to execute the pass after profiling
|
|
1911 is read. So disable one in early optimization. */
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1912 return (flag_partial_inlining
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1913 && !profile_arc_flag && !flag_branch_probabilities);
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1914 }
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1915
|
111
|
1916 } // anon namespace
|
|
1917
|
|
1918 gimple_opt_pass *
|
|
1919 make_pass_split_functions (gcc::context *ctxt)
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1920 {
|
111
|
1921 return new pass_split_functions (ctxt);
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1922 }
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1923
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1924 /* Execute function splitting pass. */
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1925
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1926 static unsigned int
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1927 execute_feedback_split_functions (void)
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1928 {
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1929 unsigned int retval = execute_split_functions ();
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1930 if (retval)
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1931 retval |= TODO_rebuild_cgraph_edges;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1932 return retval;
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1933 }
|
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1934
|
111
|
1935 namespace {
|
|
1936
|
|
1937 const pass_data pass_data_feedback_split_functions =
|
|
1938 {
|
|
1939 GIMPLE_PASS, /* type */
|
|
1940 "feedback_fnsplit", /* name */
|
|
1941 OPTGROUP_NONE, /* optinfo_flags */
|
|
1942 TV_IPA_FNSPLIT, /* tv_id */
|
|
1943 PROP_cfg, /* properties_required */
|
|
1944 0, /* properties_provided */
|
|
1945 0, /* properties_destroyed */
|
|
1946 0, /* todo_flags_start */
|
|
1947 0, /* todo_flags_finish */
|
|
1948 };
|
|
1949
|
|
1950 class pass_feedback_split_functions : public gimple_opt_pass
|
68
Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1951 {
|
111
|
1952 public:
|
|
1953 pass_feedback_split_functions (gcc::context *ctxt)
|
|
1954 : gimple_opt_pass (pass_data_feedback_split_functions, ctxt)
|
|
1955 {}
|
|
1956
|
|
1957 /* opt_pass methods: */
|
|
1958 virtual bool gate (function *);
|
|
1959 virtual unsigned int execute (function *)
|
|
1960 {
|
|
1961 return execute_feedback_split_functions ();
|
|
1962 }
|
|
1963
|
|
1964 }; // class pass_feedback_split_functions
|
|
1965
|
|
1966 bool
|
|
1967 pass_feedback_split_functions::gate (function *)
|
|
1968 {
|
|
1969 /* We don't need to split when profiling at all, we are producing
|
|
1970 lousy code anyway. */
|
|
1971 return (flag_partial_inlining
|
|
1972 && flag_branch_probabilities);
|
|
1973 }
|
|
1974
|
|
1975 } // anon namespace
|
|
1976
|
|
1977 gimple_opt_pass *
|
|
1978 make_pass_feedback_split_functions (gcc::context *ctxt)
|
|
1979 {
|
|
1980 return new pass_feedback_split_functions (ctxt);
|
|
1981 }
|