PIPS
Pedagogical phases in PIPS

Simple phases to show how to add stuff to a module: a comment, a call,... More...

Functions

bool prepend_comment (char *module_name)
 Add a comment at the begin of a module code. More...
 
bool prepend_call (string mn)
 This function adds a call to ficticious global function "MY_TRACK" as first executabble statement of module "mn" in C89 style. More...
 
static void do_add_pragma (statement s, statement p)
 
bool add_pragma (const string mn)
 

Detailed Description

Simple phases to show how to add stuff to a module: a comment, a call,...

Pedagogical, but also useful for RK for a project...

Ronan.nosp@m..Ker.nosp@m.yell@.nosp@m.hpc-.nosp@m.proje.nosp@m.ct.c.nosp@m.om François Irigoin

This module introduces some pedagogical minimal phases to dive into PIPS development, with some examples of programming and documentation style (such as this module itself!)

Function Documentation

◆ add_pragma()

bool add_pragma ( const string  mn)

a bit more complex: the directive must be added just before any return statement, if any

Definition at line 110 of file add_stuff_to_module.c.

110  {
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 }
static statement module_statement
Definition: alias_check.c:125
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....
#define gen_context_recurse(start, ctxt, domain_number, flt, rwt)
Definition: genC.h:285
static void do_add_pragma(statement s, statement p)
bool gen_true2(__attribute__((unused)) gen_chunk *u1, __attribute__((unused)) void *u2)
Definition: genClib.c:2785
#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.
void insert_statement(statement, statement, bool)
This is the normal entry point.
Definition: statement.c:2570
#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

References add_pragma_str_to_statement(), do_add_pragma(), gen_context_recurse, gen_true2(), get_bool_property(), get_string_property(), insert_statement(), make_empty_statement, module_statement, PIPS_PHASE_POSTLUDE, PIPS_PHASE_PRELUDE, and statement_domain.

+ Here is the call graph for this function:

◆ do_add_pragma()

static void do_add_pragma ( statement  s,
statement  p 
)
static

Definition at line 104 of file add_stuff_to_module.c.

104  {
105  if(return_statement_p(s)){
106  insert_statement(s,copy_statement(p),true);
107  }
108 }
statement copy_statement(statement p)
STATEMENT.
Definition: ri.c:2186
bool return_statement_p(statement)
Test if a statement is a C or Fortran "return".
Definition: statement.c:172

References copy_statement(), insert_statement(), and return_statement_p().

Referenced by add_pragma().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ prepend_call()

bool prepend_call ( string  mn)

This function adds a call to ficticious global function "MY_TRACK" as first executabble statement of module "mn" in C89 style.

It is not supposed to be of any use beyond training new comers to PIPS.

Function "MY_TRACK" is assumed to take no arguments and to return no results. No source code is available for it.

It is written to show how to use Newgen primitives in PIPS PPoPP 2010 tutorial, not to be used. See make_empty_subroutine() in ri-util/entity.c for a similar function which might be moved into ri-util/module.c.

Parameters
mnis the name of the module to apply this phase on.
Returns
true as we assume it always works, although repetitive calls to make_entity() with the same global name might fail:-). Not tested on Fortran code. No non-regression tests for it either.

This works only once. So use FindOrCreateEntity() instead... or rely on functions in library ri-util.

Definition at line 77 of file add_stuff_to_module.c.

77  {
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 }
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
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
callees compute_callees(const statement stat)
Recompute the callees of a module statement.
Definition: callgraph.c:355
statement instruction_to_statement(instruction)
Build a statement from a give instruction.
Definition: statement.c:597
#define NIL
The empty list (nil in Lisp)
Definition: newgen_list.h:47
#define DB_PUT_MEMORY_RESOURCE(res_name, own_name, res_val)
conform to old interface.
Definition: pipsdbm-local.h:66
#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)
char * strdup()

References check_entity(), compute_callees(), concatenate(), DB_PUT_MEMORY_RESOURCE, f(), get_string_property(), insert_statement(), instruction_to_statement(), make_call(), make_code(), make_entity, make_functional(), make_instruction_call(), make_language_c(), make_sequence(), make_storage_rom(), make_type_functional(), make_type_void(), make_value_code(), MODULE_SEP_STRING, module_statement, NIL, pips_assert, PIPS_PHASE_POSTLUDE, PIPS_PHASE_PRELUDE, strdup(), and TOP_LEVEL_MODULE_NAME.

+ Here is the call graph for this function:

◆ prepend_comment()

bool prepend_comment ( char *  module_name)

Add a comment at the begin of a module code.

It is a pedagogical phase but is also used for CUDA generation.

Parameters
module_nameis the name of the module to apply this phase on.
Returns
a bool which is true if it works. Well, indeed this phase assumes to always work...

Use this module name and this environment variable to set

Put back the new statement for the module

Definition at line 42 of file add_stuff_to_module.c.

42  {
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 }
const char * module_name(const char *s)
Return the module part of an entity name.
Definition: entity_names.c:296
static void comment(string_buffer code, spoc_hardware_type hw, dagvtx v, int stage, int side, bool flip)
Definition: freia_spoc.c:52
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

References comment(), get_string_property(), insert_comments_to_statement(), module_name(), module_statement, PIPS_PHASE_POSTLUDE, and PIPS_PHASE_PRELUDE.

+ Here is the call graph for this function: