PIPS
cast_at_call_sites.c
Go to the documentation of this file.
1 /*
2 
3  $Id: cast_at_call_sites.c 23065 2016-03-02 09:05:50Z coelho $
4 
5  Copyright 1989-2016 MINES ParisTech
6  Copyright 2010 HPC-Project
7 
8  This file is part of PIPS.
9 
10  PIPS is free software: you can redistribute it and/or modify it
11  under the terms of the GNU General Public License as published by
12  the Free Software Foundation, either version 3 of the License, or
13  any later version.
14 
15  PIPS is distributed in the hope that it will be useful, but WITHOUT ANY
16  WARRANTY; without even the implied warranty of MERCHANTABILITY or
17  FITNESS FOR A PARTICULAR PURPOSE.
18 
19  See the GNU General Public License for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with PIPS. If not, see <http://www.gnu.org/licenses/>.
23 
24  */
25 
26 // do not compile unless required
27 #include "phases.h"
28 #ifdef BUILDER_CAST_AT_CALL_SITES
29 
30 #ifdef HAVE_CONFIG_H
31 #include "pips_config.h"
32 #endif
33 
34 #include <stdio.h>
35 #include <string.h>
36 
37 #include "genC.h"
38 #include "linear.h"
39 
40 #include "misc.h"
41 #include "properties.h"
42 #include "pipsdbm.h"
43 
44 #include "ri.h"
45 #include "ri-util.h"
46 
47 #include "control.h" // PIPS_PHASE_POSTLUDE
48 #include "callgraph.h"
49 
50 /**
51  * This pass force call site params to be casted
52  */
53 bool cast_at_call_sites(const string mod_name) {
54  // Use this module name and this environment variable to set
56  "CAST_AT_CALL_SITES_DEBUG_LEVEL");
57 
59 
60  list callers =
61  callees_callees((callees)db_get_memory_resource(DBR_CALLERS,mod_name,true));
62  list callers_statement = callers_to_statements(callers);
63  list call_sites = callers_to_call_sites(callers_statement,m);
64  /* we may have to change the call sites, prepare iterators over call sites arguments here */
65  FOREACH(CALL,c,call_sites) {
66  list args = call_arguments(c);
68  expression * arg = (expression*)REFCAR(args);
69  type type_in_func_prototype = parameter_type(p);
70 
71  if(!pointer_type_p(type_in_func_prototype) && array_type_p(type_in_func_prototype)) {
72  type t = copy_type(type_in_func_prototype);
73  variable v = type_variable(t);
75  type_in_func_prototype = make_type_variable(make_variable(make_basic_pointer(t),NIL,NIL));
76  }
77 
78 
79  *arg = make_expression(make_syntax_cast(make_cast(copy_type(type_in_func_prototype),
80  *arg)),
82  POP(args);
83  }
84  }
85  for (list citer = callers, siter = callers_statement; !ENDP(citer); POP(citer), POP(siter))
86  DB_PUT_MEMORY_RESOURCE(DBR_CODE, STRING(CAR(citer)),STATEMENT(CAR(siter)));
87 
88  // Put back the new statement module
90 }
91 
92 #endif // BUILDER_CAST_AT_CALL_SITES
cast make_cast(type a1, expression a2)
Definition: ri.c:311
expression make_expression(syntax a1, normalized a2)
Definition: ri.c:886
type make_type_variable(variable _field_)
Definition: ri.c:2715
type copy_type(type p)
TYPE.
Definition: ri.c:2655
basic make_basic_pointer(type _field_)
Definition: ri.c:179
variable make_variable(basic a1, list a2, list a3)
Definition: ri.c:2895
syntax make_syntax_cast(cast _field_)
Definition: ri.c:2503
static statement module_statement
Definition: alias_check.c:125
list callers_to_call_sites(list callers_statement, entity called_module)
given a list callers_statement of module statements returns a list of calls to module called_module
Definition: callgraph.c:149
list callers_to_statements(list callers)
given a list callers of module name calling module called module return a list of their body
Definition: callgraph.c:163
#define STRING(x)
Definition: genC.h:87
entity get_current_module_entity(void)
Get the entity of the current module.
Definition: static.c:85
#define ENDP(l)
Test if a list is empty.
Definition: newgen_list.h:66
#define POP(l)
Modify a list pointer to point on the next element of the list.
Definition: newgen_list.h:59
#define REFCAR(pc)
Get the adress of the first element of a list.
Definition: newgen_list.h:119
#define NIL
The empty list (nil in Lisp)
Definition: newgen_list.h:47
#define CAR(pcons)
Get the value of the first element of a list.
Definition: newgen_list.h:92
#define FOREACH(_fe_CASTER, _fe_item, _fe_list)
Apply/map an instruction block on all the elements of a list.
Definition: newgen_list.h:179
#define CDR(pcons)
Get the list less its first element.
Definition: newgen_list.h:111
#define PIPS_PHASE_POSTLUDE(new_module_statement)
End a transformation phase by putting back into PIPS the (possibly) modified statement.
#define PIPS_PHASE_PRELUDE(module_name, debug_env_var)
Start a phase that use a module CODE.
string db_get_memory_resource(const char *rname, const char *oname, bool pure)
Return the pointer to the resource, whatever it is.
Definition: database.c:755
#define DB_PUT_MEMORY_RESOURCE(res_name, own_name, res_val)
conform to old interface.
Definition: pipsdbm-local.h:66
bool array_type_p(type)
Definition: type.c:2942
bool pointer_type_p(type)
Check for scalar pointers.
Definition: type.c:2993
#define normalized_undefined
Definition: ri.h:1745
#define parameter_type(x)
Definition: ri.h:1819
#define callees_callees(x)
Definition: ri.h:675
#define type_functional(x)
Definition: ri.h:2952
#define type_variable(x)
Definition: ri.h:2949
#define functional_parameters(x)
Definition: ri.h:1442
#define PARAMETER(x)
PARAMETER.
Definition: ri.h:1788
#define variable_dimensions(x)
Definition: ri.h:3122
#define CALL(x)
CALL.
Definition: ri.h:679
#define call_arguments(x)
Definition: ri.h:711
#define entity_type(x)
Definition: ri.h:2792
#define STATEMENT(x)
STATEMENT.
Definition: ri.h:2413
The structure used to build lists in NewGen.
Definition: newgen_list.h:41
bool cast_at_call_sites(const string)
cast_at_call_sites.c