PIPS
add_stuff_to_module.c
Go to the documentation of this file.
1 /* Simple phases to show how to add stuff to a module: a comment, a call,...
2 
3  Pedagogical, but also useful for RK for a project...
4 
5  Ronan.Keryell@hpc-project.com
6  François Irigoin
7 */
8 
9 #ifdef HAVE_CONFIG_H
10  #include "pips_config.h"
11 #endif
12 #include "genC.h" // for NewGen
13 #include "linear.h" // for the C3 Linear library
14 #include "ri.h" // for the internal representation
15 #include "ri-util.h" // and its "methods"
16 #include "misc.h" // for debug_on()
17 #include "control.h" // for module_reorder()
18 #include "callgraph.h" // for compute_callees()
19 #include "properties.h" // for get_string_property()
20 #include "pipsdbm.h"
21 #include "resources.h"
22 
23 
24 /** @defgroup Pedagogical_phases Pedagogical phases in PIPS
25 
26  This module introduces some pedagogical minimal phases to dive into
27  PIPS development, with some examples of programming and documentation
28  style (such as this module itself!)
29 
30  @{
31 */
32 
33 /** Add a comment at the begin of a module code.
34 
35  It is a pedagogical phase but is also used for CUDA generation.
36 
37  @param module_name is the name of the module to apply this phase on.
38 
39  @return a bool which is true if it works. Well, indeed this phase
40  assumes to always work...
41 */
43  /* Use this module name and this environment variable to set */
44 
46  "PREPEND_COMMENT_DEBUG_LEVEL");
47 
48  // Get the value of the property containing the comment to be prepended
49  const char* comment = get_string_property("PREPEND_COMMENT");
50 
52 
53  /* Put back the new statement for the module */
55 }
56 
57 
58 /** This function adds a call to ficticious global function "MY_TRACK" as
59  first executabble statement of module "mn" in C89 style. It is not
60  supposed to be of any use beyond training new comers to PIPS.
61 
62  Function "MY_TRACK" is assumed to take no arguments and to return
63  no results. No source code is available for it.
64 
65  It is written to show how to use Newgen primitives in PIPS PPoPP
66  2010 tutorial, not to be used. See make_empty_subroutine() in
67  ri-util/entity.c for a similar function which might be moved into
68  ri-util/module.c.
69 
70  @param mn is the name of the module to apply this phase on.
71 
72  @return true as we assume it always works, although repetitive
73  calls to make_entity() with the same global name might
74  fail:-). Not tested on Fortran code. No non-regression tests for
75  it either.
76  */
77 bool prepend_call(string mn) {
78  type rt = make_type_void(NIL);
79  functional ft = make_functional(NIL, rt);
80  type t = make_type_functional(ft);
83  make_language_c());
84  value v = make_value_code(co);
85  const char* name = get_string_property("PREPEND_CALL");
88  name,
89  NULL));
90  /* This works only once. So use FindOrCreateEntity() instead... or
91  rely on functions in library ri-util. */
92  entity f = make_entity(ffn, t, st, v);
93  call ca = make_call(f, NIL);
97  "PREPEND_CALL_DEBUG_LEVEL");
98  pips_assert("f really is an entity", check_entity(f));
102 }
103 
104 static void do_add_pragma(statement s, statement p) {
105  if(return_statement_p(s)){
106  insert_statement(s,copy_statement(p),true);
107  }
108 }
109 
110 bool add_pragma(const string mn) {
111  const char* pragma_name = get_string_property("PRAGMA_NAME");
112  bool prepend = get_bool_property("PRAGMA_PREPEND");
113  statement pragma_s = make_empty_statement();
114  add_pragma_str_to_statement(pragma_s, pragma_name, true);
115  statement module_statement = PIPS_PHASE_PRELUDE(mn, "ADD_PRAGMA_DEBUG_LEVEL");
116  insert_statement(module_statement, pragma_s, prepend);
117  if(!prepend) /* a bit more complex: the directive must be added just before any return statement, if any */ {
119  }
121 }
122 
123 
124 /** End of this group
125  @} */
functional make_functional(list a1, type a2)
Definition: ri.c:1109
call make_call(entity a1, list a2)
Definition: ri.c:269
value make_value_code(code _field_)
Definition: ri.c:2835
storage make_storage_rom(void)
Definition: ri.c:2285
type make_type_functional(functional _field_)
Definition: ri.c:2718
type make_type_void(list _field_)
Definition: ri.c:2727
statement copy_statement(statement p)
STATEMENT.
Definition: ri.c:2186
entity check_entity(entity p)
Definition: ri.c:2527
instruction make_instruction_call(call _field_)
Definition: ri.c:1184
code make_code(list a1, string a2, sequence a3, list a4, language a5)
Definition: ri.c:353
language make_language_c(void)
Definition: ri.c:1253
sequence make_sequence(list a)
Definition: ri.c:2125
static statement module_statement
Definition: alias_check.c:125
callees compute_callees(const statement stat)
Recompute the callees of a module statement.
Definition: callgraph.c:355
const char * module_name(const char *s)
Return the module part of an entity name.
Definition: entity_names.c:296
char * get_string_property(const char *)
bool get_bool_property(const string)
FC 2015-07-20: yuk, moved out to prevent an include cycle dependency include "properties....
static void comment(string_buffer code, spoc_hardware_type hw, dagvtx v, int stage, int side, bool flip)
Definition: freia_spoc.c:52
#define gen_context_recurse(start, ctxt, domain_number, flt, rwt)
Definition: genC.h:285
static void do_add_pragma(statement s, statement p)
bool prepend_call(string mn)
This function adds a call to ficticious global function "MY_TRACK" as first executabble statement of ...
bool add_pragma(const string mn)
bool prepend_comment(char *module_name)
Add a comment at the begin of a module code.
statement instruction_to_statement(instruction)
Build a statement from a give instruction.
Definition: statement.c:597
bool gen_true2(__attribute__((unused)) gen_chunk *u1, __attribute__((unused)) void *u2)
Definition: genClib.c:2785
#define NIL
The empty list (nil in Lisp)
Definition: newgen_list.h:47
#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.
#define DB_PUT_MEMORY_RESOURCE(res_name, own_name, res_val)
conform to old interface.
Definition: pipsdbm-local.h:66
void insert_comments_to_statement(statement, const char *)
Insert a comment string (if non empty) at the beginning of the comments of a statement.
Definition: statement.c:1916
bool return_statement_p(statement)
Test if a statement is a C or Fortran "return".
Definition: statement.c:172
void insert_statement(statement, statement, bool)
This is the normal entry point.
Definition: statement.c:2570
#define pips_assert(what, predicate)
common macros, two flavors depending on NDEBUG
Definition: misc-local.h:172
#define TOP_LEVEL_MODULE_NAME
Module containing the global variables in Fortran and C.
Definition: naming-local.h:101
#define MODULE_SEP_STRING
Definition: naming-local.h:30
string concatenate(const char *,...)
Return the concatenation of the given strings.
Definition: string.c:183
int f(int off1, int off2, int n, float r[n], float a[n], float b[n])
Definition: offsets.c:15
#define make_entity(n, t, s, i)
#define make_empty_statement
An alias for make_empty_block_statement.
void add_pragma_str_to_statement(statement st, const char *s, bool copy_flag)
Add a string as a pragma to a statement.
Definition: pragma.c:425
#define statement_domain
newgen_sizeofexpression_domain_defined
Definition: ri.h:362
char * strdup()