PIPS
interface.c
Go to the documentation of this file.
1 /*
2 
3  $Id: interface.c 23372 2017-05-05 15:35:30Z lossing $
4 
5  Copyright 1989-2016 MINES ParisTech
6 
7  This file is part of PIPS.
8 
9  PIPS is free software: you can redistribute it and/or modify it
10  under the terms of the GNU General Public License as published by
11  the Free Software Foundation, either version 3 of the License, or
12  any later version.
13 
14  PIPS is distributed in the hope that it will be useful, but WITHOUT ANY
15  WARRANTY; without even the implied warranty of MERCHANTABILITY or
16  FITNESS FOR A PARTICULAR PURPOSE.
17 
18  See the GNU General Public License for more details.
19 
20  You should have received a copy of the GNU General Public License
21  along with PIPS. If not, see <http://www.gnu.org/licenses/>.
22 
23 */
24 #ifdef HAVE_CONFIG_H
25  #include "pips_config.h"
26 #endif
27 /* package convex effects : Be'atrice Creusillet 5/97
28  *
29  * File: interface.c
30  * ~~~~~~~~~~~~~~~~~
31  *
32  * This File contains the interfaces with pipsmake which compute the various
33  * types of convex regions by using the generic functions.
34  *
35  */
36 
37 #include <stdio.h>
38 #include <string.h>
39 
40 #include "genC.h"
41 #include "linear.h"
42 #include "ri.h"
43 #include "effects.h"
44 #include "database.h"
45 
46 #include "ri-util.h"
47 #include "prettyprint.h"
48 #include "effects-util.h"
49 #include "constants.h"
50 #include "misc.h"
51 #include "text-util.h"
52 #include "text.h"
53 
54 #include "properties.h"
55 
56 #include "effects-generic.h"
57 #include "effects-convex.h"
58 
59 #include "callgraph.h"
60 
61 #include "resources.h"
62 
63 /******************************************************* CONVEX R/W REGIONS */
64 
65 bool summary_pointer_regions(const string module_name)
66 {
67  bool res;
68  set_constant_paths_p(false);
73  return res;
74 }
75 
76 
77 /* bool summary_regions(const char* module_name): computes the global
78  * regions of a module : global regions only use formal or common variables.
79  */
80 bool summary_regions(const string module_name)
81 {
82  bool res;
84  !get_bool_property("CONSTANT_PATH_EFFECTS"))
85  set_constant_paths_p(false);
86  else
92  return res;
93 }
94 
95 
96 bool may_pointer_regions(const string module_name)
97 {
98  bool res1, res2;
99  set_bool_property("MUST_REGIONS", false);
100 
101  set_constant_paths_p(false);
106 
110  return res1 && res2;
111 }
112 
113 /* bool may_regions(const char* module_name)
114  * input : the name of the current module
115  * output : nothing.
116  * modifies : computes the local regions of a module.
117  * comment : local regions can contain local variables.
118  */
119 bool may_regions(const string module_name)
120 {
121  bool res1, res2;
122 
123  set_bool_property("MUST_REGIONS", false);
124 
126  !get_bool_property("CONSTANT_PATH_EFFECTS"))
127  set_constant_paths_p(false);
128  else
129  set_constant_paths_p(true);
132 
135 
138 
140 
141  return res1 && res2;
142 }
143 
144 
145 bool must_pointer_regions(const string module_name)
146 {
147  bool res1, res2;
148  set_bool_property("MUST_REGIONS", true);
149 
150  set_constant_paths_p(false);
155 
158 
160  return res1 && res2;
161 }
162 
164 {
165  bool res1, res2;
166  set_bool_property("MUST_REGIONS", true);
167 
168  set_constant_paths_p(false);
173 
174  set_constant_paths_p(false);
178 
180  return res1 && res2;
181 }
182 
183 
184 /* bool must_regions(const char* module_name)
185  * input : the name of the current module
186  * output : nothing.
187  * modifies : computes the local regions of a module.
188  * comment : local regions can contain local variables.
189  */
190 bool must_regions(const string module_name)
191 {
192  bool res1, res2;
193 
194  set_bool_property("MUST_REGIONS", true);
195 
197  !get_bool_property("CONSTANT_PATH_EFFECTS"))
198  set_constant_paths_p(false);
199  else
200  set_constant_paths_p(true);
205 
207  !get_bool_property("CONSTANT_PATH_EFFECTS"))
208  set_constant_paths_p(false);
209  else
210  set_constant_paths_p(true);
215 
216  return res1 && res2;
217 }
218 
219 /* bool must_regions(const char* module_name)
220  * input : the name of the current module
221  * output : nothing.
222  * modifies : computes the local regions of a module.
223  * comment : local regions can contain local variables.
224  */
225 bool must_regions_with_points_to(const string module_name)
226 {
227  bool res1, res2;
228 
229  set_bool_property("MUST_REGIONS", true);
230 
231  set_constant_paths_p(true);
236 
237  set_constant_paths_p(true);
242 
243  return res1 && res2;
244 }
245 
246 /* bool must_regions(const char* module_name)
247  * input : the name of the current module
248  * output : nothing.
249  * modifies : computes the local regions of a module.
250  * comment : local regions can contain local variables.
251  */
253 {
254  bool res1, res2;
255 
256  set_bool_property("MUST_REGIONS", true);
257 
258  set_constant_paths_p(true);
263 
264  set_constant_paths_p(true);
269 
270  return res1 && res2;
271 }
272 
273 
274 
275 /******************************************************** CONVEX IN REGIONS */
276 
277 
278 /* bool in_summary_regions(const char* module_name):
279  * input : the name of the current module.
280  * output : nothing !
281  * modifies : the database.
282  * comment : computes the summary in regions of the current module, using the
283  * regions of its embedding statement.
284  */
285 bool in_summary_regions(const string module_name)
286 {
287  bool res;
289  !get_bool_property("CONSTANT_PATH_EFFECTS"))
290  set_constant_paths_p(false);
291  else
292  set_constant_paths_p(true);
297  return res;
298 }
299 
300 /* bool in_regions(const char* module_name):
301  * input : the name of the current module.
302  * output : nothing !
303  * modifies : the database.
304  * comment : computes the in regions of the current module.
305  */
306 bool in_regions(const string module_name)
307 {
308  bool res;
310  !get_bool_property("CONSTANT_PATH_EFFECTS"))
311  set_constant_paths_p(false);
312  else
313  set_constant_paths_p(true);
318  return res;
319 }
320 
321 
322 /******************************************************* CONVEX OUT REGIONS */
323 
324 bool out_summary_regions(const string module_name)
325 {
326  bool res;
327 
329  !get_bool_property("CONSTANT_PATH_EFFECTS"))
330  set_constant_paths_p(false);
331  else
332  set_constant_paths_p(true);
335  init_convex_rw_prettyprint(module_name); // for debugging
338 
339  return res;
340 }
341 
342 bool out_regions(const string module_name)
343 {
344  bool res;
346  !get_bool_property("CONSTANT_PATH_EFFECTS"))
347  set_constant_paths_p(false);
348  else
349  set_constant_paths_p(true);
354  return res;
355 }
356 
357 
358 
359 /******************************************* INTERFACES FOR LIVENESS ANALYSIS/FILTER */
360 
361 bool live_out_regions(const char* module_name)
362 {
363  bool ok;
364 // if (! c_module_p(module_name_to_entity(module_name))
365 // || !get_bool_property("CONSTANT_PATH_EFFECTS"))
366 // set_constant_paths_p(false);
367 // else
368 // set_constant_paths_p(true);
369 // set_methods_for_live_paths(module_name);
370  // ambiguous if we have to use simple or convex for the second arg
371  // anyway, it's not use.
373  return ok;
374 }
375 
376 
377 
378 /************************************************************** PRETTYPRINT */
379 
380 #define is_rw (1)
381 #define is_inout (2)
382 //#define is_copyinout (3)
383 //#define is_private (4)
384 
385 static bool
386 print_code_any_regions(
387  const char* module_name,
388  int what_tag,
389  bool is_user_view,
390  bool is_attached,
391  string resource_name,
392  string summary_resource_name,
393  string suffix)
394 {
395  bool ok;
397  switch(what_tag)
398  {
399  case is_rw:
401  break;
402  case is_inout:
404  break;
405  default:
406  pips_internal_error("unexpected tag %d", what_tag);
407  return false;
408  }
409 
412 
414  (module_name, resource_name, summary_resource_name, suffix, true);
415 
417  return ok;
418 }
419 
421 {
422  return print_code_any_regions(module_name, is_rw, false, false,
423  DBR_PROPER_POINTER_REGIONS, string_undefined, ".preg");
424 }
425 
426 bool print_code_pointer_regions(const string module_name)
427 {
428  return print_code_any_regions(module_name, is_rw, false, false,
429  DBR_POINTER_REGIONS, DBR_SUMMARY_POINTER_REGIONS, ".reg");
430 }
431 
433 {
434  return print_code_any_regions(module_name, is_rw, false, false,
435  DBR_INV_POINTER_REGIONS, DBR_SUMMARY_POINTER_REGIONS, ".reg");
436 }
437 
438 bool print_code_proper_regions(const string module_name)
439 {
440  return print_code_any_regions(module_name, is_rw, false, false,
441  DBR_PROPER_REGIONS, string_undefined, ".preg");
442 }
443 
444 bool print_source_proper_regions(const string module_name)
445 {
446  return print_code_any_regions(module_name, is_rw, true, false,
447  DBR_PROPER_REGIONS, string_undefined, ".upreg");
448 }
449 
450 bool print_code_regions(const string module_name)
451 {
452  return print_code_any_regions(module_name, is_rw, false, false,
453  DBR_REGIONS, DBR_SUMMARY_REGIONS, ".reg");
454 }
455 
456 bool print_source_regions(const string module_name)
457 {
458  return print_code_any_regions(module_name, is_rw, true, false,
459  DBR_REGIONS, DBR_SUMMARY_REGIONS, ".ureg");
460 }
461 
462 bool print_code_inv_regions(const string module_name)
463 {
464  return print_code_any_regions(module_name, is_rw, false, false,
465  DBR_INV_REGIONS, DBR_SUMMARY_REGIONS, ".reg");
466 }
467 
468 bool print_source_inv_regions(const string module_name)
469 {
470  return print_code_any_regions(module_name, is_rw, true, false,
471  DBR_INV_REGIONS, DBR_SUMMARY_REGIONS, ".ureg");
472 }
473 
474 bool print_code_in_regions(const string module_name)
475 {
476  return print_code_any_regions(module_name, is_inout, false, false,
477  DBR_IN_REGIONS, DBR_IN_SUMMARY_REGIONS, ".inreg");
478 }
479 
480 bool print_source_in_regions(const string module_name)
481 {
482  return print_code_any_regions(module_name, is_inout, true, false,
483  DBR_IN_REGIONS, DBR_IN_SUMMARY_REGIONS, ".uinreg");
484 }
485 
486 bool print_code_out_regions(const string module_name)
487 {
488  return print_code_any_regions(module_name, is_inout, false, false,
489  DBR_OUT_REGIONS, DBR_OUT_SUMMARY_REGIONS, ".outreg");
490 }
491 
492 bool print_source_out_regions(const string module_name)
493 {
494  return print_code_any_regions(module_name, is_inout, true, false,
495  DBR_OUT_REGIONS, DBR_OUT_SUMMARY_REGIONS, ".uoutreg");
496 }
497 
498 bool
500 {
501  return print_code_any_regions(module_name, is_inout, false, false,
502  DBR_LIVE_OUT_REGIONS, string_undefined, ".loutreg");
503 }
504 
505 //bool
506 //print_source_live_out_regions(const char* module_name)
507 //{
508 // return print_code_any_regions(module_name, is_inout, true, false,
509 // DBR_LIVE_OUT_REGIONS, string_undefined, ".uloutreg");
510 //}
511 
512 // NOT IMPLEMENTED
513 bool print_code_as_a_graph_regions(const string mod_name)
514 {
515  bool success;
516 
517  set_bool_property("PRETTYPRINT_UNSTRUCTURED_AS_A_GRAPH", true);
518  user_warning("print_code_as_a_graph_regions", "To be done...");
519  success = print_code /*_regions*/(mod_name);
520  set_bool_property("PRETTYPRINT_UNSTRUCTURED_AS_A_GRAPH", false);
521 
522  return success;
523 }
524 
525 bool print_code_as_a_graph_in_regions(const string mod_name)
526 {
527  bool success;
528 
529  set_bool_property("PRETTYPRINT_UNSTRUCTURED_AS_A_GRAPH", true);
530  user_warning("print_code_as_a_graph_regions", "To be done...");
531  success = print_code /*_in_regions*/(mod_name);
532  set_bool_property("PRETTYPRINT_UNSTRUCTURED_AS_A_GRAPH", false);
533 
534  return success;
535 }
536 
537 bool print_code_as_a_graph_out_regions(const string mod_name)
538 {
539  bool success;
540 
541  set_bool_property("PRETTYPRINT_UNSTRUCTURED_AS_A_GRAPH", true);
542  user_warning("print_code_as_a_graph_regions", "To be done...");
543  success = print_code /*_out_regions*/(mod_name);
544  set_bool_property("PRETTYPRINT_UNSTRUCTURED_AS_A_GRAPH", false);
545 
546  return success;
547 }
548 
549 /************* INTERFACES TO COMPUTE SIMPLE PROPER EFFECTS FROM OTHER PHASES */
550 
551 /* list regions_of_expression(expression e, transformer context)
552  * input : an expression and the current context
553  * output : the correpsonding list of regions.
554  * modifies : nothing.
555  * comment :
556  */
557 list
559 {
560  list le;
562  le = proper_effects_contract(le);
563  return le;
564 }
565 
566 /* list proper_effects_of_expression(expression e)
567  * input : an expression and the current context
568  * output : the correpsonding list of effects.
569  * modifies : nothing.
570  * comment :
571  */
572 list
574 {
575  list le;
576  bool context_stack_defined_p =
578 
579  if (!context_stack_defined_p)
580  {
583  }
585 
587 
589 
590  if (!context_stack_defined_p)
591  {
593  }
594 
595  return le;
596 }
597 
598 list
600 {
601  list le = NIL;
602  MAP(EXPRESSION, exp,
603  {
605  },
606  l_exp);
607  return le;
608 }
609 
610 
611 /*
612  * Print callgraph with regions
613  */
615 {
616  bool success = false;
618  return success;
619 }
620 
621 /*
622  * Print callgraph with IN regions
623  */
625 {
626  bool success = false;
628  return success;
629 }
630 
631 /*
632  * Print callgraph with OUT regions
633  */
635 {
636  bool success = false;
638  return success;
639 }
640 
641 
642 /********************************************************************** ICFG */
643 
644 #include "pips-libs.h"
645 #ifdef HAVE_PIPS_icfg_LIBRARY
646 #include "icfg.h"
647 
648 bool print_icfg_with_regions(const string module_name)
649 {
650  return generic_print_icfg(module_name, false, false, false,
652 }
653 
654 bool print_icfg_with_in_regions(const string module_name)
655 {
656  return generic_print_icfg(module_name, false, false, false,
658 }
659 
660 bool print_icfg_with_out_regions(const string module_name)
661 {
662  return generic_print_icfg(module_name, false, false, false,
664 }
665 
667 {
668  return generic_print_icfg(module_name, false, true, false,
670 }
671 
673 {
674  return generic_print_icfg(module_name, false, true, false,
676 }
677 
679 {
680  return generic_print_icfg(module_name, false, true, false,
682 }
683 
685 {
686  return generic_print_icfg(module_name, true, true, false,
688 }
689 
691 {
692  return generic_print_icfg(module_name, true, true, false,
694 }
695 
697 {
698  return generic_print_icfg(module_name, true, true, false,
700 }
701 
702 #endif // HAVE_PIPS_icfg_LIBRARY
bool print_decorated_call_graph(const string, text(*)(const string))
Definition: print.c:64
static bool is_user_view
useful
#define resource_name(x)
Definition: database.h:108
bool print_source_inv_regions(const string)
bool print_source_out_regions(const string)
bool must_regions(const string)
bool print_source_regions(const string)
bool print_icfg_with_control_regions(const string)
bool print_code_inv_regions(const string)
text get_text_regions(const string)
bool print_code_proper_pointer_regions(const string)
bool in_regions(const string)
bool print_call_graph_with_regions(const string)
bool print_icfg_with_control_out_regions(const string)
bool print_icfg_with_loops_regions(const string)
bool print_code_as_a_graph_in_regions(const string)
bool print_call_graph_with_out_regions(const string)
bool print_icfg_with_loops_out_regions(const string)
bool out_summary_regions(const string)
bool print_call_graph_with_in_regions(const string)
list regions_of_expression(expression, transformer)
bool print_code_as_a_graph_regions(const string)
void set_methods_for_convex_rw_pointer_effects(void)
Definition: methods.c:365
void set_methods_for_convex_effects(void)
methods.c
Definition: methods.c:235
list proper_regions_of_expression(expression, transformer)
bool must_pointer_regions_with_points_to(const string)
bool print_icfg_with_regions(const string)
bool may_pointer_regions(const string)
bool must_regions_with_pointer_values(const string)
bool must_pointer_regions(const string)
bool print_icfg_with_in_regions(const string)
bool print_code_out_regions(const string)
list proper_regions_of_expressions(list, transformer)
void init_convex_rw_prettyprint(const char *)
bool summary_regions(const string)
bool print_code_pointer_regions(const string)
bool summary_pointer_regions(const string)
cproto-generated files
bool print_source_proper_regions(const string)
bool print_icfg_with_loops_in_regions(const string)
bool print_code_live_out_regions(const char *)
bool live_out_regions(const char *)
void set_methods_for_convex_in_out_effects(void)
Definition: methods.c:469
void init_convex_inout_prettyprint(const char *)
bool print_code_inv_pointer_regions(const string)
bool print_code_regions(const string)
bool print_code_proper_regions(const string)
bool print_code_as_a_graph_out_regions(const string)
bool print_icfg_with_control_in_regions(const string)
bool must_regions_with_points_to(const string)
bool print_source_in_regions(const string)
void set_methods_for_convex_rw_effects(void)
Definition: methods.c:358
bool out_regions(const string)
bool print_code_in_regions(const string)
bool may_regions(const string)
bool in_summary_regions(const string)
bool print_icfg_with_out_regions(const string)
text get_text_in_regions(const string)
text get_text_out_regions(const string)
@ with_points_to
@ with_no_pointer_info
@ with_pointer_values
void free_effects_private_current_context_stack(void)
void set_is_user_view_p(bool)
bool live_out_region_engine(const char *, effects_representation_val)
void make_effects_private_current_context_stack(void)
bool in_effects_engine(const char *, effects_representation_val)
list proper_effects_contract(list)
bool out_effects_engine(const char *, effects_representation_val)
bool summary_in_effects_engine(const char *)
in_effects_engine.c
bool effects_private_current_context_stack_initialized_p(void)
bool summary_out_effects_engine(const char *)
bool summary_rw_effects_engine(const char *)
bool rw_effects_engine(const char *)
void set_prettyprint_with_attachments(bool)
list generic_proper_effects_of_expression(expression)
transformer effects_private_current_context_pop(void)
void generic_effects_reset_all_methods(void)
void set_pointer_info_kind(pointer_info_val)
methods.c
void effects_private_current_context_push(transformer)
bool proper_effects_engine(const char *)
bool print_source_or_code_with_any_effects_engine(const char *, string, string, string, bool)
void set_constant_paths_p(bool)
const char * module_name(const char *s)
Return the module part of an entity name.
Definition: entity_names.c:296
bool get_bool_property(const string)
FC 2015-07-20: yuk, moved out to prevent an include cycle dependency include "properties....
bool success
Definition: gpips-local.h:59
#define NIL
The empty list (nil in Lisp)
Definition: newgen_list.h:47
list gen_nconc(list cp1, list cp2)
physically concatenates CP1 and CP2 but do not duplicates the elements
Definition: list.c:344
#define MAP(_map_CASTER, _map_item, _map_code, _map_list)
Apply/map an instruction block on all the elements of a list (old fashioned)
Definition: newgen_list.h:226
bool generic_print_icfg(const string, bool, bool, bool, text(*)(const string))
Definition: icfg_scan.c:713
#define pips_internal_error
Definition: misc-local.h:149
#define user_warning(fn,...)
Definition: misc-local.h:262
#define string_undefined
Definition: newgen_types.h:40
bool print_code(const string)
Definition: print.c:272
void set_bool_property(const char *, bool)
bool c_module_p(entity m)
Test if a module "m" is written in C.
Definition: entity.c:2777
entity module_name_to_entity(const char *mn)
This is an alias for local_name_to_top_level_entity.
Definition: entity.c:1479
#define EXPRESSION(x)
EXPRESSION.
Definition: ri.h:1217
static bool ok
The structure used to build lists in NewGen.
Definition: newgen_list.h:41
Definition: delay.c:253
#define exp
Avoid some warnings from "gcc -Wshadow".
Definition: vasnprintf.c:207