Skip to content

Commit f185cfd

Browse files
authored
Merge pull request #862 from NathanJPhillips/bugfix/inlining-errors
Fixed inefficiency and failure to pass on parameter
2 parents cdf7180 + cd72883 commit f185cfd

File tree

1 file changed

+49
-9
lines changed

1 file changed

+49
-9
lines changed

src/goto-programs/goto_inline.cpp

Lines changed: 49 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,20 @@ void goto_inline(
123123
Function: goto_partial_inline
124124
125125
Inputs:
126+
goto_model:
127+
Source of the symbol table and function map to use.
128+
message_handler:
129+
Message handler used by goto_inlinet.
130+
smallfunc_limit:
131+
The maximum number of instructions in functions to be inlined.
132+
adjust_function:
133+
Tell goto_inlinet to adjust function.
126134
127135
Outputs:
128136
129137
Purpose:
138+
Inline all function calls to functions either marked as "inlined" or
139+
smaller than smallfunc_limit (by instruction count).
130140
131141
\*******************************************************************/
132142

@@ -150,10 +160,23 @@ void goto_partial_inline(
150160
Function: goto_partial_inline
151161
152162
Inputs:
163+
goto_functions:
164+
The function map to use to find functions containing calls and function
165+
bodies.
166+
ns:
167+
Namespace used by goto_inlinet.
168+
message_handler:
169+
Message handler used by goto_inlinet.
170+
smallfunc_limit:
171+
The maximum number of instructions in functions to be inlined.
172+
adjust_function:
173+
Tell goto_inlinet to adjust function.
153174
154175
Outputs:
155176
156177
Purpose:
178+
Inline all function calls to functions either marked as "inlined" or
179+
smaller than smallfunc_limit (by instruction count).
157180
158181
\*******************************************************************/
159182

@@ -182,6 +205,10 @@ void goto_partial_inline(
182205
if(!goto_function.body_available())
183206
continue;
184207

208+
if(f_it->first==goto_functions.entry_point())
209+
// Don't inline any function calls made from the _start function.
210+
continue;
211+
185212
goto_programt &goto_program=goto_function.body;
186213

187214
goto_inlinet::call_listt &call_list=inline_map[f_it->first];
@@ -195,10 +222,10 @@ void goto_partial_inline(
195222
exprt function_expr;
196223
exprt::operandst arguments;
197224
exprt constrain;
198-
199225
goto_inlinet::get_call(i_it, lhs, function_expr, arguments, constrain);
200226

201227
if(function_expr.id()!=ID_symbol)
228+
// Can't handle pointers to functions
202229
continue;
203230

204231
const symbol_exprt &symbol_expr=to_symbol_expr(function_expr);
@@ -208,17 +235,14 @@ void goto_partial_inline(
208235
goto_functions.function_map.find(id);
209236

210237
if(f_it==goto_functions.function_map.end())
238+
// Function not loaded, can't check size
211239
continue;
212240

213241
// called function
214242
const goto_functiont &goto_function=f_it->second;
215243

216-
// We can't take functions without bodies to find functions
217-
// inside them to be inlined.
218-
// We also don't allow for the _start function to have any of its
219-
// function calls to be inlined
220-
if(!goto_function.body_available() ||
221-
f_it->first==goto_functions.entry_point())
244+
if(!goto_function.body_available())
245+
// The bodies of functions that don't have bodies can't be inlined.
222246
continue;
223247

224248
const goto_programt &goto_program=goto_function.body;
@@ -240,36 +264,52 @@ void goto_partial_inline(
240264
Function: goto_function_inline
241265
242266
Inputs:
267+
goto_model: Source of the symbol table and function map to use.
268+
function: The function whose calls to inline.
269+
message_handler: Message handler used by goto_inlinet.
270+
adjust_function: Tell goto_inlinet to adjust function.
271+
caching: Tell goto_inlinet to cache.
243272
244273
Outputs:
245274
246275
Purpose:
276+
Inline all function calls made from a particular function
247277
248278
\*******************************************************************/
249279

250280
void goto_function_inline(
251281
goto_modelt &goto_model,
252282
const irep_idt function,
253283
message_handlert &message_handler,
254-
bool adjust_function)
284+
bool adjust_function,
285+
bool caching)
255286
{
256287
const namespacet ns(goto_model.symbol_table);
257288
goto_function_inline(
258289
goto_model.goto_functions,
259290
function,
260291
ns,
261-
message_handler);
292+
message_handler,
293+
adjust_function,
294+
caching);
262295
}
263296

264297
/*******************************************************************\
265298
266299
Function: goto_function_inline
267300
268301
Inputs:
302+
goto_functions: The function map to use to find function bodies.
303+
function: The function whose calls to inline.
304+
ns: Namespace used by goto_inlinet.
305+
message_handler: Message handler used by goto_inlinet.
306+
adjust_function: Tell goto_inlinet to adjust function.
307+
caching: Tell goto_inlinet to cache.
269308
270309
Outputs:
271310
272311
Purpose:
312+
Inline all function calls made from a particular function
273313
274314
\*******************************************************************/
275315

0 commit comments

Comments
 (0)