PIPS
control_counters.c File Reference
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "genC.h"
#include "linear.h"
#include "pipsdbm.h"
#include "ri-util.h"
#include "control.h"
+ Include dependency graph for control_counters.c:

Go to the source code of this file.

Data Structures

struct  acc_ctx
 Add Control Counter recursion context. More...
 

Functions

static statement make_increment_statement (entity module, entity var)
 generate: var = var + 1 (Fortran) or var++ (C) More...
 
static entity create_counter (entity module, const string name)
 create a new integer local variable in module using name as a prefix More...
 
static void add_counter (acc_ctx *c, string name, statement s)
 add a new counter at entry of statement s More...
 
static void test_rwt (test t, acc_ctx *c)
 add a counter to each branch of the test More...
 
static void loop_rwt (loop l, acc_ctx *c)
 add a counter to the loop body More...
 
static void whileloop_rwt (whileloop w, acc_ctx *c)
 add a counter to the loop body More...
 
static void forloop_rwt (forloop f, acc_ctx *c)
 add a counter to the loop body More...
 
static void add_counters (entity module, statement root)
 add control counter instrumentation assumes current module entity & statement are okay. More...
 
bool add_control_counters (const string module_name)
 instrument a module with control structure counters for test & loops More...
 

Function Documentation

◆ add_control_counters()

bool add_control_counters ( const string  module_name)

instrument a module with control structure counters for test & loops

control_counters.c

Parameters
module_nameodule_name

Definition at line 137 of file control_counters.c.

138 {
139  // get resources from database
141  statement stat =
142  (statement) db_get_memory_resource(DBR_CODE, module_name, true);
143 
146 
147  // do the job
148  add_counters(module, stat);
149 
150  // reset unique identifier for each statement
151  module_reorder(stat);
152 
153  // update resource
154  DB_PUT_MEMORY_RESOURCE(DBR_CODE, module_name, stat);
155 
156  // cleanup
159  return true;
160 }
struct _newgen_struct_statement_ * statement
Definition: cloning.h:21
static void add_counters(entity module, statement root)
add control counter instrumentation assumes current module entity & statement are okay.
const char * module_name(const char *s)
Return the module part of an entity name.
Definition: entity_names.c:296
void reset_current_module_entity(void)
Reset the current module entity.
Definition: static.c:97
void reset_current_module_statement(void)
Reset the current module statement.
Definition: static.c:221
statement set_current_module_statement(statement)
Set the current module statement.
Definition: static.c:165
entity set_current_module_entity(entity)
static.c
Definition: static.c:66
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
static char * module
Definition: pips.c:74
bool module_reorder(statement body)
Reorder a module and recompute order to statement if any.
Definition: reorder.c:244
entity module_name_to_entity(const char *mn)
This is an alias for local_name_to_top_level_entity.
Definition: entity.c:1479

References add_counters(), db_get_memory_resource(), DB_PUT_MEMORY_RESOURCE, module, module_name(), module_name_to_entity(), module_reorder(), reset_current_module_entity(), reset_current_module_statement(), set_current_module_entity(), and set_current_module_statement().

+ Here is the call graph for this function:

◆ add_counter()

static void add_counter ( acc_ctx c,
string  name,
statement  s 
)
static

add a new counter at entry of statement s

Definition at line 85 of file control_counters.c.

86 {
87  entity counter = create_counter(c->module, name);
88  insert_statement(s, make_increment_statement(c->module, counter), true);
89 }
static entity create_counter(entity module, const string name)
create a new integer local variable in module using name as a prefix
static statement make_increment_statement(entity module, entity var)
generate: var = var + 1 (Fortran) or var++ (C)
void insert_statement(statement, statement, bool)
This is the normal entry point.
Definition: statement.c:2570
entity module

References create_counter(), insert_statement(), make_increment_statement(), and acc_ctx::module.

Referenced by forloop_rwt(), loop_rwt(), test_rwt(), and whileloop_rwt().

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

◆ add_counters()

static void add_counters ( entity  module,
statement  root 
)
static

add control counter instrumentation assumes current module entity & statement are okay.

Definition at line 123 of file control_counters.c.

124 {
125  acc_ctx c = { module };
127  (root, &c,
132  NULL);
133 }
static void forloop_rwt(forloop f, acc_ctx *c)
add a counter to the loop body
static void test_rwt(test t, acc_ctx *c)
add a counter to each branch of the test
static void whileloop_rwt(whileloop w, acc_ctx *c)
add a counter to the loop body
static void loop_rwt(loop l, acc_ctx *c)
add a counter to the loop body
void gen_context_multi_recurse(void *o, void *context,...)
Multi-recursion with context function visitor.
Definition: genClib.c:3373
bool gen_true(__attribute__((unused)) gen_chunk *unused)
Return true and ignore the argument.
Definition: genClib.c:2780
#define forloop_domain
newgen_extensions_domain_defined
Definition: ri.h:178
#define test_domain
newgen_entity_domain_defined
Definition: ri.h:418
#define loop_domain
newgen_language_domain_defined
Definition: ri.h:218
#define whileloop_domain
newgen_variable_domain_defined
Definition: ri.h:466
Add Control Counter recursion context.

References forloop_domain, forloop_rwt(), gen_context_multi_recurse(), gen_true(), loop_domain, loop_rwt(), module, test_domain, test_rwt(), whileloop_domain, and whileloop_rwt().

Referenced by add_control_counters().

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

◆ create_counter()

static entity create_counter ( entity  module,
const string  name 
)
static

create a new integer local variable in module using name as a prefix

Definition at line 66 of file control_counters.c.

67 {
68  // build name (could also insert: entity_local_name(module))
69  string full = strdup(concatenate("_", name, "_", NULL));
70  // create an integer counter
71  entity var =
73  // cleanup
74  free(full), full=NULL;
75  // initialized to zero
78  // add as a local variable
80  return var;
81 }
value make_value_expression(expression _field_)
Definition: ri.c:2850
basic make_basic_int(intptr_t _field_)
Definition: ri.c:158
void free_value(value p)
Definition: ri.c:2787
void free(void *)
string concatenate(const char *,...)
Return the concatenation of the given strings.
Definition: string.c:183
expression int_to_expression(_int i)
transform an int into an expression and generate the corresponding entity if necessary; it is not cle...
Definition: expression.c:1188
void AddEntityToCurrentModule(entity)
Add a variable entity to the current module declarations.
Definition: variable.c:260
entity make_new_scalar_variable_with_prefix(const char *, entity, basic)
Create a new scalar variable of type b in the given module.
Definition: variable.c:592
#define entity_initial(x)
Definition: ri.h:2796
char * strdup()
@ full
Definition: union-local.h:65

References AddEntityToCurrentModule(), concatenate(), entity_initial, free(), free_value(), full, int_to_expression(), make_basic_int(), make_new_scalar_variable_with_prefix(), make_value_expression(), module, and strdup().

Referenced by add_counter().

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

◆ forloop_rwt()

static void forloop_rwt ( forloop  f,
acc_ctx c 
)
static

add a counter to the loop body

Definition at line 115 of file control_counters.c.

116 {
117  add_counter(c, "for", forloop_body(f));
118 }
static void add_counter(acc_ctx *c, string name, statement s)
add a new counter at entry of statement s
int f(int off1, int off2, int n, float r[n], float a[n], float b[n])
Definition: offsets.c:15
#define forloop_body(x)
Definition: ri.h:1372

References add_counter(), f(), and forloop_body.

Referenced by add_counters().

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

◆ loop_rwt()

static void loop_rwt ( loop  l,
acc_ctx c 
)
static

add a counter to the loop body

Definition at line 101 of file control_counters.c.

102 {
103  add_counter(c, "do", loop_body(l));
104 }
#define loop_body(x)
Definition: ri.h:1644

References add_counter(), and loop_body.

Referenced by add_counters().

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

◆ make_increment_statement()

static statement make_increment_statement ( entity  module,
entity  var 
)
static

generate: var = var + 1 (Fortran) or var++ (C)

Definition at line 49 of file control_counters.c.

50 {
56  int_to_expression(1)));
57  else // this is probably C
58  return make_call_statement
62 }
#define NIL
The empty list (nil in Lisp)
Definition: newgen_list.h:47
#define CONS(_t_, _i_, _l_)
List element cell constructor (insert an element at the beginning of a list)
Definition: newgen_list.h:150
statement make_assign_statement(expression, expression)
Definition: statement.c:583
statement make_call_statement(string, list, entity, string)
This function is limited to intrinsics calls...
Definition: statement.c:1274
#define PLUS_OPERATOR_NAME
#define POST_INCREMENT_OPERATOR_NAME
Definition: ri-util-local.h:97
#define empty_comments
Empty comments (i.e.
bool fortran_module_p(entity m)
Test if a module is in Fortran.
Definition: entity.c:2799
entity entity_intrinsic(const char *name)
FI: I do not understand this function name (see next one!).
Definition: entity.c:1292
expression entity_to_expression(entity e)
if v is a constant, returns a constant call.
Definition: expression.c:165
expression MakeBinaryCall(entity f, expression eg, expression ed)
Creates a call expression to a function with 2 arguments.
Definition: expression.c:354
#define entity_undefined
Definition: ri.h:2761

References CONS, empty_comments, entity_intrinsic(), entity_to_expression(), entity_undefined, fortran_module_p(), int_to_expression(), make_assign_statement(), make_call_statement(), MakeBinaryCall(), module, NIL, PLUS_OPERATOR_NAME, and POST_INCREMENT_OPERATOR_NAME.

Referenced by add_counter().

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

◆ test_rwt()

static void test_rwt ( test  t,
acc_ctx c 
)
static

add a counter to each branch of the test

Definition at line 93 of file control_counters.c.

94 {
95  add_counter(c, "if_then", test_true(t));
96  add_counter(c, "if_else", test_false(t));
97 }
#define test_false(x)
Definition: ri.h:2837
#define test_true(x)
Definition: ri.h:2835

References add_counter(), test_false, and test_true.

Referenced by add_counters().

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

◆ whileloop_rwt()

static void whileloop_rwt ( whileloop  w,
acc_ctx c 
)
static

add a counter to the loop body

Definition at line 108 of file control_counters.c.

109 {
110  add_counter(c, "while", whileloop_body(w));
111 }
#define whileloop_body(x)
Definition: ri.h:3162

References add_counter(), and whileloop_body.

Referenced by add_counters().

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