PIPS
freia-utils.c File Reference
#include <stdint.h>
#include <stdlib.h>
#include "genC.h"
#include "misc.h"
#include "freia.h"
#include "freia_spoc.h"
#include "linear.h"
#include "ri.h"
#include "effects.h"
#include "ri-util.h"
#include "effects-util.h"
#include "properties.h"
#include "pipsdbm.h"
#include "freia_spoc_private.h"
#include "hwac.h"
#include "effects-generic.h"
+ Include dependency graph for freia-utils.c:

Go to the source code of this file.

Data Structures

struct  occs_ctx
 
struct  related_ctx
 

Macros

#define T   true
 
#define F   false
 
#define NO_POC   { { spoc_poc_unused, 0 }, { spoc_poc_unused, 0 } }
 
#define NO_MES   { measure_none, measure_none }
 
#define NOPE_SPOC   { spoc_nothing, NO_POC, alu_unused, NO_MES }
 
#define NOPE_TRPX   { 0, 0, 0, 0, 0, 0, false, false, NULL }
 
#define NOPE_OPCL   { F, F, NULL, NULL }
 
#define NOPE_SIGMAC   { "Id", "nop", "width, height", F, 0 }
 
#define NOPE_MPPA   {"MPPA_KERNEL_NOP"}
 
#define NO_SPOC   { spoc_not_implemented, NO_POC, alu_unused, NO_MES }
 
#define NO_TRPX   { 0, 0, 0, 0, 0, -1, false, false, NULL }
 
#define NO_OPCL   { F, F, NULL, NULL }
 
#define NO_SIGMAC   { "not_implemented", NULL, NULL, F, 0 }
 
#define NO_MPPA   {"MPPA_KERNEL_NOP"}
 
#define TRPX_OP(c, op)   { 0, 0, 0, 0, 0, c, true, false, "TERAPIX_UCODE_" op }
 
#define TRPX_IO(c, op)   { 0, 0, 0, 0, 0, c, true, true, "TERAPIX_UCODE_" op }
 
#define TRPX_NG(c, op)   { 1, 1, 1, 1, 0, c, false, false, "TERAPIX_UCODE_" op }
 
#define TRPX_MS(m, c, op)   { 0, 0, 0, 0, m, c, true, false, "TERAPIX_UCODE_" op }
 
#define OPCL(op)   { T, F, "PIXEL_" op, NULL }
 
#define OPCLK(op, init)   { F, T, "PIXEL_" op, "PIXEL_" init }
 
#define SGC_W(ag, pref)   { #ag, #pref, "width", T, 1 }
 
#define SGC_WH(ag, pref)   { #ag, #pref, "width, height", F, 0 }
 
#define MPPA(kernel)   {#kernel}
 
#define TY_INT   "int32_t"
 
#define TY_PIN   "int32_t *"
 
#define TY_CIP   "const int32_t *"
 
#define TY_UIN   "uint32_t"
 
#define TY_PUI   "uint32_t *"
 
#define NO_PARAM   { NULL, NULL, NULL }
 
#define FREIA_AIPO_API_SIZE   (sizeof(*FREIA_AIPO_API)/sizeof(freia_api_t))
 
#define E_WRITE(v)   (v)
 
#define E_READ(v)   ((void*)(((_int)v)+1))
 

Functions

const freia_api_thwac_freia_api (const char *function)
 freia-utils.c More...
 
int hwac_freia_api_index (const string function)
 returns the index of the description of an AIPO function More...
 
const freia_api_tget_freia_api (int index)
 
const freia_api_tget_freia_api_vtx (dagvtx v)
 
static string get_var (string prefix, int *params)
 
string what_operation (const _int type)
 
string what_operation_shape (const _int type)
 SPoC: set shape depending on hardware component used by vertex. More...
 
void freia_spoc_set_operation (const freia_api_t *api, _int *type, _int *id)
 ??? beurk: I keep the operation as two ints for code regeneration. More...
 
list freia_get_params (const freia_api_t *api, list args)
 get freia further parameters, skipping image ones More...
 
list freia_get_vertex_params (const dagvtx v)
 
expression freia_get_nth_scalar_param (const dagvtx v, int n)
 
int freia_max_pixel_value (void)
 
list freia_extract_params (const int napi, list args, string_buffer head, string_buffer head2, hash_table params, int *nparams)
 returns an allocated expression list of the parameters only (i.e. More...
 
call freia_ok (void)
 build all is well freia constant More...
 
bool freia_assignment_p (const entity e)
 tell whether it is an assignment to ignore? More...
 
statement freia_copy_image (const entity source, const entity target)
 
void hwac_replace_statement (statement s, call newc, bool kill)
 replace statement contents with call to c, or continue if kill More...
 
void hwac_kill_statement (statement s)
 remove contents of statement s. More...
 
bool freia_image_variable_p (const entity var)
 rather approximative? More...
 
static entity get_assigned_variable (const statement s)
 for "ret = freia_aipo_*()": return the 'ret' variable... More...
 
bool entity_freia_api_p (const entity f)
 returns whether the entity is a freia API (AIPO) function. More...
 
bool freia_statement_aipo_call_p (const statement s)
 returns whether the statement is a FREIA call. More...
 
static void set_add_scalars (set s, const statement stat, const bool written)
 append simple scalar entities with written/read effects to s scalars assigned to are ignored (return status). More...
 
static bool real_freia_scalar_rw_dep (const statement s, const statement t, list *vars)
 is there a simple scalar (no image) rw dependency from s to t? WW deps are ignored... More...
 
void freia_init_dep_cache (void)
 
void freia_close_dep_cache (void)
 
bool freia_scalar_rw_dep (const statement s, const statement t, list *vars)
 
static bool lexpression_equal_p (const list l1, const list l2)
 
call freia_statement_to_call (const statement s)
 return the actual function call from a statement, dealing with assign and returns... More...
 
static bool is_freia_this_call (const statement s, const string fname)
 
bool is_freia_alloc (const statement s)
 
bool is_freia_dealloc (const statement s)
 
bool same_constant_parameters (const dagvtx v1, const dagvtx v2)
 tell whether v1 and v2 point to statements with the same parameters. More...
 
entity freia_create_helper_function (const string function_name, list lparams)
 
int freia_substitute_by_helper_call (dag d, set global_remainings, set remainings, list ls, const string function_name, list lparams, set helpers, int preceeding)
 substitute those statement in ls that are in dag d and accelerated by a call to function_name(lparams) also update sets of remainings and global_remainings More...
 
static statement find_aipo_statement (list ls, bool before)
 
void freia_insert_added_stats (list ls, list stats, bool before)
 insert statements to actual code sequence in "ls" BEWARE that ls is assumed to be in reverse order... More...
 
void freia_add_image_arguments (list limg, list *lparams)
 prepend limg images in front of the argument list limg is consummed by the operation. More...
 
static int reference_argument_number (const reference r, const list le)
 return the argument number, starting from 1, of this reference or 0 if not found. More...
 
static bool reference_written_p (const reference r, const hash_table signatures)
 tell about the image effect. More...
 
static bool check_ref (reference r, occs_ctx *ctx)
 hack to help replace use-def chains which did not work initially with C. More...
 
static void check_ref2 (reference r, occs_ctx *ctx)
 
static bool check_stmt (statement s, occs_ctx *ctx)
 
hash_table freia_build_image_occurrences (statement s, set image_occs_stats, hash_table image_stats, const hash_table signatures)
 
void freia_clean_image_occurrences (hash_table occs)
 cleanup occurrence data structure More...
 
bool freia_aipo_spoc_implemented (const freia_api_t *api)
 whether api available with SPoC More...
 
bool freia_aipo_terapix_implemented (const freia_api_t *api)
 whether api available with Ter@pix More...
 
bool freia_convolution_p (dagvtx v)
 is it the convolution special case? More...
 
bool freia_convolution_width_height (dagvtx v, _int *pw, _int *ph, bool check)
 get width & height of convolution More...
 
static void clean_stats_to_image (hash_table s2i)
 
static statement image_free (entity v)
 generate statement: "freia_free(v);" More...
 
static bool related_images_p (const entity img1, const entity img2, const hash_table new_images)
 is there an effect to this image or related images in the statement? More...
 
static bool related_effect (statement s, struct related_ctx *ctx)
 
static bool some_related_image_effect (statement s, entity img, hash_table new_images, hash_table image_stats, bool write_only)
 
static bool only_minor_statements_in_between (entity image, hash_table new_images, hash_table image_stats, list ls, statement s1, list l2, set image_occurences)
 tell whether there is no image processing statements between s1 and l2 More...
 
list freia_allocate_new_images_if_needed (list ls, list images, const hash_table occs, const hash_table init, const hash_table signatures)
 insert image allocation if needed, for intermediate image inserted before if an image is used only twice, then it is switched back to the initial one More...
 
int freia_aipo_count (dag d, int *pa, int *pc)
 
static void oi_call_rwt (call c, set images)
 
static void oi_stmt_rwt (statement s, set images)
 
set freia_compute_output_images (entity module, statement s)
 
set freia_compute_current_output_images (void)
 
static string stat_nb (statement s)
 
void freia_migrate_statements (sequence sq, const set stats, const set before)
 
static bool freia_extract_kernel (expression e, bool strict, intptr_t *k00, intptr_t *k10, intptr_t *k20, intptr_t *k01, intptr_t *k11, intptr_t *k21, intptr_t *k02, intptr_t *k12, intptr_t *k22)
 extract values from a kernel definition return 9 values, expected to be 0/1 elsewhere... More...
 
bool freia_extract_kernel_vtx (dagvtx v, bool strict, intptr_t *k00, intptr_t *k10, intptr_t *k20, intptr_t *k01, intptr_t *k11, intptr_t *k21, intptr_t *k02, intptr_t *k12, intptr_t *k22)
 vertex-based version More...
 
string helper_file_name (string func_name, string suffix)
 return malloc'ed "foo.database/Src/%{module}_helper_functions.c" should it depend on the target? no, because we could mix targets? More...
 

Variables

static const freia_api_t FREIA_AIPO_API []
 !!! there are some underlying assumptions when using this structure: only one of ALU/POC/MES is used per AIPO. More...
 
static hash_table dep_cache = NULL
 

Macro Definition Documentation

◆ E_READ

#define E_READ (   v)    ((void*)(((_int)v)+1))

Definition at line 1248 of file freia-utils.c.

◆ E_WRITE

#define E_WRITE (   v)    (v)

Definition at line 1247 of file freia-utils.c.

◆ F

#define F   false

Definition at line 51 of file freia-utils.c.

◆ FREIA_AIPO_API_SIZE

#define FREIA_AIPO_API_SIZE   (sizeof(*FREIA_AIPO_API)/sizeof(freia_api_t))

Definition at line 450 of file freia-utils.c.

◆ MPPA

#define MPPA (   kernel)    {#kernel}

Definition at line 83 of file freia-utils.c.

◆ NO_MES

#define NO_MES   { measure_none, measure_none }

Definition at line 54 of file freia-utils.c.

◆ NO_MPPA

#define NO_MPPA   {"MPPA_KERNEL_NOP"}

Definition at line 68 of file freia-utils.c.

◆ NO_OPCL

#define NO_OPCL   { F, F, NULL, NULL }

Definition at line 66 of file freia-utils.c.

◆ NO_PARAM

#define NO_PARAM   { NULL, NULL, NULL }

Definition at line 92 of file freia-utils.c.

◆ NO_POC

#define NO_POC   { { spoc_poc_unused, 0 }, { spoc_poc_unused, 0 } }

Definition at line 53 of file freia-utils.c.

◆ NO_SIGMAC

#define NO_SIGMAC   { "not_implemented", NULL, NULL, F, 0 }

Definition at line 67 of file freia-utils.c.

◆ NO_SPOC

#define NO_SPOC   { spoc_not_implemented, NO_POC, alu_unused, NO_MES }

Definition at line 64 of file freia-utils.c.

◆ NO_TRPX

#define NO_TRPX   { 0, 0, 0, 0, 0, -1, false, false, NULL }

Definition at line 65 of file freia-utils.c.

◆ NOPE_MPPA

#define NOPE_MPPA   {"MPPA_KERNEL_NOP"}

Definition at line 61 of file freia-utils.c.

◆ NOPE_OPCL

#define NOPE_OPCL   { F, F, NULL, NULL }

Definition at line 59 of file freia-utils.c.

◆ NOPE_SIGMAC

#define NOPE_SIGMAC   { "Id", "nop", "width, height", F, 0 }

Definition at line 60 of file freia-utils.c.

◆ NOPE_SPOC

#define NOPE_SPOC   { spoc_nothing, NO_POC, alu_unused, NO_MES }

Definition at line 57 of file freia-utils.c.

◆ NOPE_TRPX

#define NOPE_TRPX   { 0, 0, 0, 0, 0, 0, false, false, NULL }

Definition at line 58 of file freia-utils.c.

◆ OPCL

#define OPCL (   op)    { T, F, "PIXEL_" op, NULL }

Definition at line 77 of file freia-utils.c.

◆ OPCLK

#define OPCLK (   op,
  init 
)    { F, T, "PIXEL_" op, "PIXEL_" init }

Definition at line 78 of file freia-utils.c.

◆ SGC_W

#define SGC_W (   ag,
  pref 
)    { #ag, #pref, "width", T, 1 }

Definition at line 80 of file freia-utils.c.

◆ SGC_WH

#define SGC_WH (   ag,
  pref 
)    { #ag, #pref, "width, height", F, 0 }

Definition at line 81 of file freia-utils.c.

◆ T

#define T   true

Definition at line 50 of file freia-utils.c.

◆ TRPX_IO

#define TRPX_IO (   c,
  op 
)    { 0, 0, 0, 0, 0, c, true, true, "TERAPIX_UCODE_" op }

Definition at line 71 of file freia-utils.c.

◆ TRPX_MS

#define TRPX_MS (   m,
  c,
  op 
)    { 0, 0, 0, 0, m, c, true, false, "TERAPIX_UCODE_" op }

Definition at line 75 of file freia-utils.c.

◆ TRPX_NG

#define TRPX_NG (   c,
  op 
)    { 1, 1, 1, 1, 0, c, false, false, "TERAPIX_UCODE_" op }

Definition at line 72 of file freia-utils.c.

◆ TRPX_OP

#define TRPX_OP (   c,
  op 
)    { 0, 0, 0, 0, 0, c, true, false, "TERAPIX_UCODE_" op }

Definition at line 70 of file freia-utils.c.

◆ TY_CIP

#define TY_CIP   "const int32_t *"

Definition at line 88 of file freia-utils.c.

◆ TY_INT

#define TY_INT   "int32_t"

Definition at line 86 of file freia-utils.c.

◆ TY_PIN

#define TY_PIN   "int32_t *"

Definition at line 87 of file freia-utils.c.

◆ TY_PUI

#define TY_PUI   "uint32_t *"

Definition at line 90 of file freia-utils.c.

◆ TY_UIN

#define TY_UIN   "uint32_t"

Definition at line 89 of file freia-utils.c.

Function Documentation

◆ check_ref()

static bool check_ref ( reference  r,
occs_ctx ctx 
)
static

hack to help replace use-def chains which did not work initially with C.

occurrences is: <image entity> -> { set of statements } this is really a ugly hack, sorry! ??? I should also consider declarations, but as they should only contain image allocations so there should be no problem.

Definition at line 1328 of file freia-utils.c.

1329 {
1330  entity v = reference_variable(r);
1331  if (freia_image_variable_p(v))
1332  {
1333  // ensure that target set exists
1334  if (!hash_defined_p(ctx->occs, v))
1335  {
1337  hash_put(ctx->occs, E_READ(v), set_make(set_pointer));
1338  }
1339  bool written = reference_written_p(r, ctx->signatures);
1340  set stats = (set) hash_get(ctx->occs, written? E_WRITE(v): E_READ(v));
1341  // get containing statement
1342  statement up = ctx->enclosing? ctx->enclosing:
1344  // which MUST exist?
1345  pips_assert("some containing statement", up);
1346  if (ctx->image_stats) {
1347  set sop = (set) hash_get(ctx->image_stats,
1348  written? E_WRITE(up): E_READ(up));
1349  set_add_element(sop, sop, (void*) v);
1350  }
1351  // store result
1352  set_add_element(stats, stats, (void*) up);
1353  if (ctx->image_occs_stats)
1355 
1356  pips_debug(9, "entity %s in statement %"_intFMT"\n",
1357  entity_name(v), statement_number(up));
1358  }
1359  return true;
1360 }
static bool written
Definition: alias_check.c:512
struct _newgen_struct_statement_ * statement
Definition: cloning.h:21
#define E_WRITE(v)
Definition: freia-utils.c:1247
bool freia_image_variable_p(const entity var)
rather approximative?
Definition: freia-utils.c:768
static bool reference_written_p(const reference r, const hash_table signatures)
tell about the image effect.
Definition: freia-utils.c:1267
#define E_READ(v)
Definition: freia-utils.c:1248
gen_chunk * gen_get_ancestor(int, const void *)
return the first ancestor object found of the given type.
Definition: genClib.c:3560
void * hash_get(const hash_table htp, const void *key)
this function retrieves in the hash table pointed to by htp the couple whose key is equal to key.
Definition: hash.c:449
void hash_put(hash_table htp, const void *key, const void *val)
This functions stores a couple (key,val) in the hash table pointed to by htp.
Definition: hash.c:364
bool hash_defined_p(const hash_table htp, const void *key)
true if key has e value in htp.
Definition: hash.c:484
#define pips_debug
these macros use the GNU extensions that allow variadic macros, including with an empty list.
Definition: misc-local.h:145
#define pips_assert(what, predicate)
common macros, two flavors depending on NDEBUG
Definition: misc-local.h:172
struct _set_chunk * set
Definition: newgen_set.h:38
@ set_pointer
Definition: newgen_set.h:44
set set_make(set_type)
Create an empty set of any type but hash_private.
Definition: set.c:102
set set_add_element(set, const set, const void *)
Definition: set.c:152
#define _intFMT
Definition: newgen_types.h:57
#define reference_variable(x)
Definition: ri.h:2326
#define statement_domain
newgen_sizeofexpression_domain_defined
Definition: ri.h:362
#define entity_name(x)
Definition: ri.h:2790
#define statement_number(x)
Definition: ri.h:2452
FI: I do not understand why the type is duplicated at the set level.
Definition: set.c:59
hash_table image_stats
Definition: freia-utils.c:1316
statement enclosing
Definition: freia-utils.c:1311
const hash_table signatures
Definition: freia-utils.c:1318
set image_occs_stats
Definition: freia-utils.c:1313
hash_table occs
Definition: freia-utils.c:1309

References _intFMT, E_READ, E_WRITE, occs_ctx::enclosing, entity_name, freia_image_variable_p(), gen_get_ancestor(), hash_defined_p(), hash_get(), hash_put(), occs_ctx::image_occs_stats, occs_ctx::image_stats, occs_ctx::occs, pips_assert, pips_debug, reference_variable, reference_written_p(), set_add_element(), set_make(), set_pointer, occs_ctx::signatures, statement_domain, statement_number, and written.

Referenced by check_ref2(), and freia_build_image_occurrences().

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

◆ check_ref2()

static void check_ref2 ( reference  r,
occs_ctx ctx 
)
static

Definition at line 1362 of file freia-utils.c.

1363 {
1364  (void) check_ref(r, ctx);
1365 }
static bool check_ref(reference r, occs_ctx *ctx)
hack to help replace use-def chains which did not work initially with C.
Definition: freia-utils.c:1328

References check_ref().

Referenced by check_stmt().

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

◆ check_stmt()

static bool check_stmt ( statement  s,
occs_ctx ctx 
)
static

Definition at line 1367 of file freia-utils.c.

1368 {
1369  // ensure existing set
1370  if (ctx->image_stats) {
1371  pips_debug(8, "creating for statement %"_intFMT"\n",
1372  statement_number(s));
1375  }
1376  ctx->enclosing = s;
1380  ctx->enclosing = NULL;
1381  return true;
1382 }
static void check_ref2(reference r, occs_ctx *ctx)
Definition: freia-utils.c:1362
#define gen_context_recurse(start, ctxt, domain_number, flt, rwt)
Definition: genC.h:285
bool gen_true2(__attribute__((unused)) gen_chunk *u1, __attribute__((unused)) void *u2)
Definition: genClib.c:2785
#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 reference_domain
newgen_range_domain_defined
Definition: ri.h:338
#define statement_declarations(x)
Definition: ri.h:2460
#define entity_initial(x)
Definition: ri.h:2796

References _intFMT, check_ref2(), E_READ, E_WRITE, occs_ctx::enclosing, entity_initial, FOREACH, gen_context_recurse, gen_true2(), hash_put(), occs_ctx::image_stats, pips_debug, reference_domain, set_make(), set_pointer, statement_declarations, and statement_number.

Referenced by freia_build_image_occurrences().

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

◆ clean_stats_to_image()

static void clean_stats_to_image ( hash_table  s2i)
static

Definition at line 1463 of file freia-utils.c.

1464 {
1465  HASH_FOREACH(statement, st, set, imgs, s2i)
1466  set_free(imgs);
1467  hash_table_free(s2i);
1468 }
void hash_table_free(hash_table htp)
this function deletes a hash table that is no longer useful.
Definition: hash.c:327
#define HASH_FOREACH(key_type, k, value_type, v, ht)
Definition: newgen_hash.h:71
void set_free(set)
Definition: set.c:332

References HASH_FOREACH, hash_table_free(), and set_free().

Referenced by freia_allocate_new_images_if_needed().

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

◆ entity_freia_api_p()

bool entity_freia_api_p ( const entity  f)

returns whether the entity is a freia API (AIPO) function.

Definition at line 806 of file freia-utils.c.

807 {
808  // very partial...
809  return strncmp(entity_local_name(f), AIPO, strlen(AIPO))==0;
810 }
#define AIPO
Definition: freia.h:51
int f(int off1, int off2, int n, float r[n], float a[n], float b[n])
Definition: offsets.c:15
const char * entity_local_name(entity e)
entity_local_name modified so that it does not core when used in vect_fprint, since someone thought t...
Definition: entity.c:453

References AIPO, entity_local_name(), and f().

Referenced by dag_append_freia_call(), fcs_call_flt(), and freia_statement_aipo_call_p().

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

◆ find_aipo_statement()

static statement find_aipo_statement ( list  ls,
bool  before 
)
static

Definition at line 1147 of file freia-utils.c.

1148 {
1149  pips_assert("some statements", ls);
1150  pips_debug(8, "choosing among %d statements\n", (int) gen_length(ls));
1151 
1152  statement found = NULL;
1153 
1154  FOREACH(statement, s, ls)
1155  {
1156  pips_debug(8, "stmt %" _intFMT "\n", statement_number(s));
1157  if (before)
1158  {
1159  if (!found || statement_number(found)>statement_number(s))
1160  found = s;
1161  }
1162  else // after
1163  {
1164  if (!found || statement_number(found)<statement_number(s))
1165  found = s;
1166  }
1167  }
1168 
1169  // ??? au pif
1170  if (!found && ls)
1171  {
1172  pips_debug(8, "no aipo call found... backup plan?\n");
1173  if (before)
1174  found = STATEMENT(CAR(gen_last(ls))); // list is reversed...
1175  else
1176  found = STATEMENT(CAR(ls));
1177  }
1178 
1179  return found;
1180 }
size_t gen_length(const list l)
Definition: list.c:150
#define CAR(pcons)
Get the value of the first element of a list.
Definition: newgen_list.h:92
list gen_last(list l)
Return the last element of a list.
Definition: list.c:578
#define STATEMENT(x)
STATEMENT.
Definition: ri.h:2413

References _intFMT, CAR, FOREACH, gen_last(), gen_length(), pips_assert, pips_debug, STATEMENT, and statement_number.

Referenced by freia_insert_added_stats().

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

◆ freia_add_image_arguments()

void freia_add_image_arguments ( list  limg,
list lparams 
)

prepend limg images in front of the argument list limg is consummed by the operation.

Parameters
limgimg
lparamsparams

Definition at line 1233 of file freia-utils.c.

1236 {
1237  list largs = NIL;
1238  limg = gen_nreverse(limg);
1239  FOREACH(entity, e, limg)
1240  largs = CONS(expression, entity_to_expression(e), largs);
1241  gen_free_list(limg), limg = NIL;
1242  *lparams = gen_nconc(largs, *lparams);
1243 }
list gen_nreverse(list cp)
reverse a list in place
Definition: list.c:304
#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
list gen_nconc(list cp1, list cp2)
physically concatenates CP1 and CP2 but do not duplicates the elements
Definition: list.c:344
void gen_free_list(list l)
free the spine of the list
Definition: list.c:327
list lparams
Array bounds.
Definition: reindexing.c:111
expression entity_to_expression(entity e)
if v is a constant, returns a constant call.
Definition: expression.c:165
The structure used to build lists in NewGen.
Definition: newgen_list.h:41

References CONS, entity_to_expression(), FOREACH, gen_free_list(), gen_nconc(), gen_nreverse(), lparams, and NIL.

Referenced by freia_spoc_pipeline(), freia_terapix_call(), and opencl_compile_mergeable_dag().

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

◆ freia_aipo_count()

int freia_aipo_count ( dag  d,
int pa,
int pc 
)
Returns
the number for FREIA AIPO ops in dag
Parameters
paa
pcc

Definition at line 1823 of file freia-utils.c.

1824 {
1825  int aipos = 0, copies = 0;
1826  FOREACH(dagvtx, v, dag_vertices(d))
1827  {
1828  string op = dagvtx_function_name(v);
1829  if (strncmp(op, AIPO, strlen(AIPO))==0) aipos++;
1830  // handle exceptions afterwards
1831  if (same_string_p(op, AIPO "copy")) copies++, aipos--;
1832  else if (same_string_p(op, AIPO "cast")) copies++, aipos--;
1833  else if (same_string_p(op, AIPO "scalar_copy")) aipos--;
1834  }
1835  *pa = aipos, *pc = copies;
1836  return aipos+copies;
1837 }
string dagvtx_function_name(const dagvtx v)
Definition: dag-utils.c:126
#define dag_vertices(x)
#define same_string_p(s1, s2)

References AIPO, dag_vertices, dagvtx_function_name(), FOREACH, and same_string_p.

Referenced by freia_opencl_compile_calls().

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

◆ freia_aipo_spoc_implemented()

bool freia_aipo_spoc_implemented ( const freia_api_t api)

whether api available with SPoC

Parameters
apipi

Definition at line 1418 of file freia-utils.c.

1419 {
1420  pips_assert("some api", api!=NULL);
1421  return api->spoc.used!=spoc_not_implemented;
1422 }
@ spoc_not_implemented
Definition: freia_spoc.h:58
spoc_hw_t spoc
Definition: freia.h:89
uint32_t used
Definition: freia_spoc.h:162

References pips_assert, freia_api_t::spoc, spoc_not_implemented, and spoc_hw_t::used.

◆ freia_aipo_terapix_implemented()

bool freia_aipo_terapix_implemented ( const freia_api_t api)

whether api available with Ter@pix

Parameters
apipi

Definition at line 1426 of file freia-utils.c.

1427 {
1428  pips_assert("some api", api!=NULL);
1429  // some special cases are handled manually
1430  if (same_string_p(api->function_name, "undefined") ||
1431  // this one is inserted to deal with replicated measures
1432  same_string_p(api->function_name, AIPO "scalar_copy"))
1433  return true;
1434  return api->terapix.cost!=-1;
1435 }
string function_name
Definition: freia.h:73
terapix_hw_t terapix
Definition: freia.h:90

References AIPO, terapix_hw_t::cost, freia_api_t::function_name, pips_assert, same_string_p, and freia_api_t::terapix.

Referenced by dagvtx_terapix_priority().

+ Here is the caller graph for this function:

◆ freia_allocate_new_images_if_needed()

list freia_allocate_new_images_if_needed ( list  ls,
list  images,
const hash_table  occs,
const hash_table  init,
const hash_table  signatures 
)

insert image allocation if needed, for intermediate image inserted before if an image is used only twice, then it is switched back to the initial one

This could/should be improved:

  • temporary images kept could be reused if possible, instead of new ones
  • not sure about the condition to move back to the initial image
Parameters
lslist of statements to consider
imageslist of entities to check and maybe allocate
initnew image -> initial image
signatureshelper -> _int # written args ahead (may be NULL)
Returns
list of actually allocated images
Parameters
lss
imagesmages
occsccs
initnit
signaturesignatures

Definition at line 1650 of file freia-utils.c.

1659 {
1660  // check for used images
1661  set img_stats = set_make(set_pointer);
1662  hash_table image_stats_detailed = hash_table_make(hash_pointer, 0);
1663  sequence sq = make_sequence(ls);
1664  hash_table newoccs =
1665  freia_build_image_occurrences((statement) sq, img_stats,
1666  image_stats_detailed, signatures);
1667  sequence_statements(sq) = NIL;
1668  free_sequence(sq);
1669 
1670  list allocated = NIL;
1671  FOREACH(entity, v, images)
1672  {
1673  if (!hash_defined_p(newoccs, v))
1674  // no written occurences, the image is not kept
1675  continue;
1676 
1677  if (get_bool_property("FREIA_REUSE_INITIAL_IMAGES"))
1678  {
1679  set where_write = (set) hash_get(newoccs, E_WRITE(v));
1680  set where_read = (set) hash_get(newoccs, E_READ(v));
1681  int nw = set_size(where_write), nr = set_size(where_read);
1682 
1683  pips_debug(6, "image %s used %d+%d statements\n", entity_name(v), nw, nr);
1684 
1685  // ??? should be used once only in the statement if written!
1686  // how to I know about W/R for helper functions?
1687  // its siblings should also be take into account
1688 
1689  // n>1 ??
1690  // if used only twice, substitude back to initial variable???
1691  // well, it may depends whether the the initial variable is used?
1692  // there is possibly something intelligent to do here, but it should
1693  // be checked carefully...
1694  if (nw==1 && nr>=1 && hash_defined_p(init, v))
1695  {
1696  entity old = (entity) hash_get(init, v);
1697 
1698  // get statements
1699  list l1 = set_to_list(where_write), l2 = set_to_list(where_read);
1700  statement s1 = STATEMENT(CAR(l1));
1701  gen_free_list(l1), l1 = NIL;
1702 
1703  // does not interact with possibly used old
1704  // if we could differentiate read & write, we could do better,
1705  // but the information is not currently available.
1706  bool skip = false;
1707  if (hash_defined_p(newoccs, old))
1708  {
1709  set old_write = (set) hash_get(newoccs, E_WRITE(old));
1710  set old_read = (set) hash_get(newoccs, E_READ(old));
1711  if (set_belong_p(old_write, s1))
1712  skip = true;
1713  else
1714  {
1715  FOREACH(statement, s2, l2)
1716  if (set_belong_p(old_read, s2))
1717  skip = true;
1718  }
1719  // note that we can handle a read in s1 and a write in s2
1720  }
1721 
1722  pips_debug(7, "testing for %s -> %s: %s\n",
1724  skip?"skip":"ok");
1725 
1726  // do we want to switch back?
1727  if (!skip &&
1728  only_minor_statements_in_between(v, init, image_stats_detailed,
1729  ls, s1, l2, img_stats))
1730  {
1731  // yes, they are successive, just remove?? Am I that sure???
1732  // ??? hmmm, maybe we could have :
1733  // X = stuff(...)
1734  // X_1 = stuff(...)
1735  // ... = stuff(X_1, ...)
1736  // ... = stuff(X...)
1737  // where X_1 -> X is just a bad idea because it overwrites X?
1738  // I'm not sure this can happen with AIPO, as X would be X_2
1739  // and will not be changed?
1740  pips_debug(7, "substituting back %s by %s\n",
1742 
1743  // we can perform any substitution here
1744  // note that it may be generated helper functions
1745  freia_switch_image_in_statement(s1, v, old, true);
1746  FOREACH(statement, s2, l2)
1747  freia_switch_image_in_statement(s2, v, old, false);
1748 
1749  // create/update uses of "old" to avoid interactions
1750  if (!hash_defined_p(newoccs, old))
1751  {
1752  hash_put(newoccs, E_WRITE(old), set_make(set_pointer));
1753  hash_put(newoccs, E_READ(old), set_make(set_pointer));
1754  }
1755  set old_write = (set) hash_get(newoccs, E_WRITE(old));
1756  set_add_element(old_write, old_write, s1);
1757  set old_read = (set) hash_get(newoccs, E_READ(old));
1758  FOREACH(statement, s2, l2)
1759  set_add_element(old_read, old_read, s2);
1760  }
1761  else
1762  allocated = CONS(entity, v, allocated);
1763  }
1764  else
1765  allocated = CONS(entity, v, allocated);
1766  }
1767  else
1768  allocated = CONS(entity, v, allocated);
1769  }
1770 
1771  clean_stats_to_image(image_stats_detailed);
1773  set_free(img_stats);
1774 
1775  // allocate those which are finally used
1776  if (allocated)
1777  {
1778  pips_assert("some statements", ls!=NIL);
1779  statement first = STATEMENT(CAR(ls));
1780  statement last = STATEMENT(CAR(gen_last(ls)));
1781  pips_assert("at least two statements", first!=last);
1782 
1783  // insert free_image(v)...
1784  // should insert image allocation statement as the same time
1785  // currently the allocation/deallocation may not be in the same scope!!!
1786  FOREACH(entity, v, images)
1787  {
1788  pips_debug(7, "allocating image %s\n", entity_name(v));
1789  // add_declaration_statement(first, v); // NO, returned
1790  // insert_statement(first, image_alloc(v), true); // NO, init
1791  // ??? deallocation should be at end of allocation block...
1792  entity model = (entity) hash_get(init, v);
1793  bool before = false;
1794  // find free_image(model) in the code
1795  statement fs = freia_memory_management_statement(model, occs, false);
1796  if (!fs)
1797  {
1798  pips_user_warning("not quite sure where to put %s deallocation\n",
1799  entity_name(v));
1800  // hmmm... try at the program level
1802  if (statement_sequence_p(ms))
1803  {
1804  fs = STATEMENT(
1806  // hmmm... does not seem to work properly
1807  //if (statement_call_p(s) &&
1808  // ENTITY_C_RETURN_P(call_function(statement_call(s))))
1809  before = true;
1810  }
1811  }
1812  insert_statement(fs? fs: last, image_free(v), before);
1813  }
1814  }
1815 
1816  return allocated;
1817 }
sequence make_sequence(list a)
Definition: ri.c:2125
void free_sequence(sequence p)
Definition: ri.c:2092
struct _newgen_struct_entity_ * entity
Definition: abc_private.h:14
statement freia_memory_management_statement(entity image, const hash_table occs, bool alloc)
Definition: dag-utils.c:2587
void freia_switch_image_in_statement(statement s, entity old, entity img, bool write)
switch read or written image in statement if this is an AIPO call, only substitute output or input de...
Definition: dag-utils.c:2746
bool get_bool_property(const string)
FC 2015-07-20: yuk, moved out to prevent an include cycle dependency include "properties....
static void clean_stats_to_image(hash_table s2i)
Definition: freia-utils.c:1463
hash_table freia_build_image_occurrences(statement s, set image_occs_stats, hash_table image_stats, const hash_table signatures)
Definition: freia-utils.c:1388
static statement image_free(entity v)
generate statement: "freia_free(v);"
Definition: freia-utils.c:1484
static bool only_minor_statements_in_between(entity image, hash_table new_images, hash_table image_stats, list ls, statement s1, list l2, set image_occurences)
tell whether there is no image processing statements between s1 and l2
Definition: freia-utils.c:1572
void freia_clean_image_occurrences(hash_table occs)
cleanup occurrence data structure
Definition: freia-utils.c:1407
statement get_current_module_statement(void)
Get the current module statement.
Definition: static.c:208
sequence statement_sequence(statement)
Get the sequence of a statement sequence.
Definition: statement.c:1328
bool statement_sequence_p(statement)
Statement classes induced from instruction type.
Definition: statement.c:335
void insert_statement(statement, statement, bool)
This is the normal entry point.
Definition: statement.c:2570
hash_table hash_table_make(hash_key_type key_type, size_t size)
Definition: hash.c:294
#define pips_user_warning
Definition: misc-local.h:146
@ hash_pointer
Definition: newgen_hash.h:32
list set_to_list(const set)
create a list from a set the set is not freed
Definition: set.c:436
int set_size(const set)
returns the number of items in s.
Definition: set.c:359
bool set_belong_p(const set, const void *)
Definition: set.c:194
static int init
Maximal value set for Fortran 77.
Definition: entity.c:320
#define sequence_statements(x)
Definition: ri.h:2360
s1
Definition: set.c:247

References CAR, clean_stats_to_image(), CONS, E_READ, E_WRITE, entity_local_name(), entity_name, FOREACH, free_sequence(), freia_build_image_occurrences(), freia_clean_image_occurrences(), freia_memory_management_statement(), freia_switch_image_in_statement(), gen_free_list(), gen_last(), get_bool_property(), get_current_module_statement(), hash_defined_p(), hash_get(), hash_pointer, hash_put(), hash_table_make(), image_free(), init, insert_statement(), make_sequence(), NIL, only_minor_statements_in_between(), pips_assert, pips_debug, pips_user_warning, s1, sequence_statements, set_add_element(), set_belong_p(), set_free(), set_make(), set_pointer, set_size(), set_to_list(), STATEMENT, statement_sequence(), and statement_sequence_p().

Referenced by freia_aipo_compile_calls(), freia_mppa_compile_calls(), freia_opencl_compile_calls(), and sc_delimiter().

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

◆ freia_assignment_p()

bool freia_assignment_p ( const entity  e)

tell whether it is an assignment to ignore?

Definition at line 703 of file freia-utils.c.

704 {
706 }
#define ENTITY_ASSIGN_P(e)
#define ENTITY_BITWISE_OR_UPDATE_P(e)

References ENTITY_ASSIGN_P, and ENTITY_BITWISE_OR_UPDATE_P.

Referenced by fcs_call_flt(), freia_statement_aipo_call_p(), freia_statement_to_call(), get_assigned_variable(), and hwac_replace_statement().

+ Here is the caller graph for this function:

◆ freia_build_image_occurrences()

hash_table freia_build_image_occurrences ( statement  s,
set  image_occs_stats,
hash_table  image_stats,
const hash_table  signatures 
)
Parameters
image_occs_statsset of statements with image occurences (may be NULL)
signatureshelper entity -> (_int) # out args
Returns
build occurrence hash table: { entity -> set of statements }
Parameters
image_occs_statsmage_occs_stats
image_statsmage_stats
signaturesignatures

Definition at line 1388 of file freia-utils.c.

1393 {
1394  pips_debug(7, "entering\n");
1395  occs_ctx ctx = { hash_table_make(hash_pointer, 0), NULL,
1396  image_occs_stats, image_stats, signatures };
1397  gen_context_multi_recurse(s, &ctx,
1400  NULL);
1401  pips_debug(7, "done\n");
1402  return ctx.occs;
1403 }
static bool check_stmt(statement s, occs_ctx *ctx)
Definition: freia-utils.c:1367
void gen_context_multi_recurse(void *o, void *context,...)
Multi-recursion with context function visitor.
Definition: genClib.c:3373
void gen_null(__attribute__((unused)) void *unused)
Ignore the argument.
Definition: genClib.c:2752

References check_ref(), check_stmt(), gen_context_multi_recurse(), gen_null(), hash_pointer, hash_table_make(), occs_ctx::occs, pips_debug, reference_domain, and statement_domain.

Referenced by freia_allocate_new_images_if_needed(), and freia_compile().

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

◆ freia_clean_image_occurrences()

void freia_clean_image_occurrences ( hash_table  occs)

cleanup occurrence data structure

Parameters
occsccs

Definition at line 1407 of file freia-utils.c.

1408 {
1409  HASH_FOREACH(entity, v, set, s, occs)
1410  set_free(s);
1411  hash_table_free(occs);
1412 }

References HASH_FOREACH, hash_table_free(), and set_free().

Referenced by freia_allocate_new_images_if_needed(), and freia_compile().

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

◆ freia_close_dep_cache()

void freia_close_dep_cache ( void  )

Definition at line 915 of file freia-utils.c.

916 {
917  pips_assert("dep_cache is not NULL", dep_cache);
918 
920  HASH_FOREACH(statement, s2, list, l, h)
921  if (l) gen_free_list(l);
922  hash_table_free(h);
923  }
924 
926 }
static hash_table dep_cache
Definition: freia-utils.c:907

References dep_cache, gen_free_list(), HASH_FOREACH, hash_table_free(), pips_assert, and s1.

Referenced by freia_compile().

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

◆ freia_compute_current_output_images()

set freia_compute_current_output_images ( void  )

Definition at line 1885 of file freia-utils.c.

1886 {
1889 }
set freia_compute_output_images(entity module, statement s)
Definition: freia-utils.c:1866
entity get_current_module_entity(void)
Get the entity of the current module.
Definition: static.c:85

References freia_compute_output_images(), get_current_module_entity(), and get_current_module_statement().

Referenced by freia_compile().

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

◆ freia_compute_output_images()

set freia_compute_output_images ( entity  module,
statement  s 
)
Returns
the set of images which are output somehow this is a little bit simplistic... read output effects of statement?
Parameters
moduleodule

Definition at line 1866 of file freia-utils.c.

1867 {
1868  set images = set_make(set_pointer);
1869 
1870  // image formal parameters
1872  {
1873  if (freia_image_variable_p(var))
1874  set_add_element(images, images, var);
1875  }
1876 
1877  // some image uses in the code
1878  gen_context_multi_recurse(s, images,
1881  NULL);
1882  return images;
1883 }
static void oi_call_rwt(call c, set images)
Definition: freia-utils.c:1841
static void oi_stmt_rwt(statement s, set images)
Definition: freia-utils.c:1855
bool gen_true(__attribute__((unused)) gen_chunk *unused)
Return true and ignore the argument.
Definition: genClib.c:2780
static char * module
Definition: pips.c:74
#define module_functional_parameters(func)
#define call_domain
newgen_callees_domain_defined
Definition: ri.h:58

References call_domain, FOREACH, freia_image_variable_p(), gen_context_multi_recurse(), gen_true(), module, module_functional_parameters, oi_call_rwt(), oi_stmt_rwt(), set_add_element(), set_make(), set_pointer, and statement_domain.

Referenced by freia_compute_current_output_images().

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

◆ freia_convolution_p()

bool freia_convolution_p ( dagvtx  v)

is it the convolution special case?

Definition at line 1441 of file freia-utils.c.

1442 {
1443  return same_string_p(dagvtx_operation(v), "convolution");
1444 }
string dagvtx_operation(const dagvtx v)
Definition: dag-utils.c:134

References dagvtx_operation(), and same_string_p.

Referenced by dag_terapix_measures(), sc_inst(), sigmac_params_decl(), terapix_gram_management(), terapix_macro_code(), and update_erosions().

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

◆ freia_convolution_width_height()

bool freia_convolution_width_height ( dagvtx  v,
_int pw,
_int ph,
bool  check 
)

get width & height of convolution

Returns
whether they could be extracted
Parameters
pww
phh
checkheck

Definition at line 1449 of file freia-utils.c.

1450 {
1451  // pips_assert("vertex is convolution", ...)
1452  list largs = freia_get_vertex_params(v);
1453  if (check) pips_assert("3 args to convolution", gen_length(largs)==3);
1454  bool bw = expression_integer_value(EXPRESSION(CAR(CDR(largs))), pw);
1455  if (check) pips_assert("constant convolution width", bw);
1456  if (check) pips_assert("odd convolution width", ((*pw)%2)==1);
1457  bool bh = expression_integer_value(EXPRESSION(CAR(CDR(CDR(largs)))), ph);
1458  if (check) pips_assert("constant convolution height", bh);
1459  if (check) pips_assert("odd convolution height", ((*ph)%2)==1);
1460  return bw && bh;
1461 }
list freia_get_vertex_params(const dagvtx v)
Definition: freia-utils.c:578
#define CDR(pcons)
Get the list less its first element.
Definition: newgen_list.h:111
bool expression_integer_value(expression e, intptr_t *pval)
Definition: eval.c:792
#define EXPRESSION(x)
EXPRESSION.
Definition: ri.h:1217

References CAR, CDR, EXPRESSION, expression_integer_value(), freia_get_vertex_params(), gen_length(), and pips_assert.

Referenced by dag_terapix_measures(), terapix_gram_management(), terapix_macro_code(), and update_erosions().

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

◆ freia_copy_image()

statement freia_copy_image ( const entity  source,
const entity  target 
)
Returns
"freia_aipo_copy(target, source);"
Parameters
sourceource
targetarget

Definition at line 710 of file freia-utils.c.

711 {
712  return call_to_statement(
715  CONS(expression, entity_to_expression(source), NIL))));
716 }
call make_call(entity a1, list a2)
Definition: ri.c:269
#define call_to_statement(c)
entity local_name_to_top_level_entity(const char *n)
This function try to find a top-level entity from a local name.
Definition: entity.c:1450

References AIPO, call_to_statement, CONS, entity_to_expression(), local_name_to_top_level_entity(), make_call(), and NIL.

Referenced by freia_dag_optimize().

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

◆ freia_create_helper_function()

entity freia_create_helper_function ( const string  function_name,
list  lparams 
)
Parameters
function_nameunction_name
lparamsparams

Definition at line 1030 of file freia-utils.c.

1031 {
1032  // build helper entity
1033  entity example = local_name_to_top_level_entity("freia_aipo_add");
1034  pips_assert("example is a function", entity_function_p(example));
1035  entity helper = make_empty_function(function_name,
1037  make_language_c());
1038 
1039  // update type of parameters
1040  list larg_params = NIL;
1042  {
1043  debug_on("RI_UTILS_DEBUG_LEVEL");
1045  debug_off();
1046  larg_params = CONS(parameter,
1047  make_parameter(t,
1048  make_mode_value(),
1049  make_dummy_unknown()),
1050  larg_params);
1051  }
1052  larg_params = gen_nreverse(larg_params);
1053  module_functional_parameters(helper) = larg_params;
1054 
1055  return helper;
1056 }
parameter make_parameter(type a1, mode a2, dummy a3)
Definition: ri.c:1495
type copy_type(type p)
TYPE.
Definition: ri.c:2655
language make_language_c(void)
Definition: ri.c:1253
dummy make_dummy_unknown(void)
Definition: ri.c:617
mode make_mode_value(void)
Definition: ri.c:1353
#define debug_on(env)
Definition: misc-local.h:157
#define debug_off()
Definition: misc-local.h:160
bool entity_function_p(entity e)
Definition: entity.c:724
entity make_empty_function(const char *name, type r, language l)
Definition: entity.c:283
type expression_to_user_type(expression)
Preserve typedef'ed types when possible.
Definition: type.c:2645
#define functional_result(x)
Definition: ri.h:1444
#define type_functional(x)
Definition: ri.h:2952
#define entity_type(x)
Definition: ri.h:2792

References CONS, copy_type(), debug_off, debug_on, entity_function_p(), entity_type, expression_to_user_type(), FOREACH, functional_result, gen_nreverse(), local_name_to_top_level_entity(), lparams, make_dummy_unknown(), make_empty_function(), make_language_c(), make_mode_value(), make_parameter(), module_functional_parameters, NIL, pips_assert, and type_functional.

Referenced by freia_substitute_by_helper_call(), mppa_call_helper(), opencl_generate_special_kernel_ops(), and sc_delimiter().

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

◆ freia_extract_kernel()

static bool freia_extract_kernel ( expression  e,
bool  strict,
intptr_t k00,
intptr_t k10,
intptr_t k20,
intptr_t k01,
intptr_t k11,
intptr_t k21,
intptr_t k02,
intptr_t k12,
intptr_t k22 
)
static

extract values from a kernel definition return 9 values, expected to be 0/1 elsewhere...

Returns
whether it succeeded

Definition at line 1957 of file freia-utils.c.

1963 {
1964  // set default value anyway
1965  *k00 = 1, *k10 = 1, *k20 = 1,
1966  *k01 = 1, *k11 = 1, *k21 = 1,
1967  *k02 = 1, *k12 = 1, *k22 = 1;
1968 
1969  // analyse kernel
1970  if (!expression_reference_p(e)) return !strict;
1971  entity var = expression_variable(e);
1972  // ??? should check const...
1973  value val = entity_initial(var);
1974  if (!value_expression_p(val)) return !strict;
1975  expression ival = value_expression(val);
1976  if (!brace_expression_p(ival)) return !strict;
1978  pips_assert("must be a 3x3 kernel...", gen_length(iargs)==9);
1979  if (!expression_integer_value(EXPRESSION(CAR(iargs)), k00) && strict)
1980  return false;
1981  iargs = CDR(iargs);
1982  if (!expression_integer_value(EXPRESSION(CAR(iargs)), k10) && strict)
1983  return false;
1984  iargs = CDR(iargs);
1985  if (!expression_integer_value(EXPRESSION(CAR(iargs)), k20) && strict)
1986  return false;
1987  iargs = CDR(iargs);
1988  if (!expression_integer_value(EXPRESSION(CAR(iargs)), k01) && strict)
1989  return false;
1990  iargs = CDR(iargs);
1991  if (!expression_integer_value(EXPRESSION(CAR(iargs)), k11) && strict)
1992  return false;
1993  iargs = CDR(iargs);
1994  if (!expression_integer_value(EXPRESSION(CAR(iargs)), k21) && strict)
1995  return false;
1996  iargs = CDR(iargs);
1997  if (!expression_integer_value(EXPRESSION(CAR(iargs)), k02) && strict)
1998  return false;
1999  iargs = CDR(iargs);
2000  if (!expression_integer_value(EXPRESSION(CAR(iargs)), k12) && strict)
2001  return false;
2002  iargs = CDR(iargs);
2003  if (!expression_integer_value(EXPRESSION(CAR(iargs)), k22) && strict)
2004  return false;
2005  iargs = CDR(iargs);
2006  pips_assert("end of list reached", iargs==NIL);
2007  return true;
2008 }
bool brace_expression_p(expression e)
Return bool indicating if expression e is a brace expression.
Definition: expression.c:3384
bool expression_reference_p(expression e)
Test if an expression is a reference.
Definition: expression.c:528
entity expression_variable(expression e)
Definition: expression.c:532
#define syntax_call(x)
Definition: ri.h:2736
#define call_arguments(x)
Definition: ri.h:711
#define value_expression_p(x)
Definition: ri.h:3080
#define expression_syntax(x)
Definition: ri.h:1247
#define value_expression(x)
Definition: ri.h:3082

References brace_expression_p(), call_arguments, CAR, CDR, entity_initial, EXPRESSION, expression_integer_value(), expression_reference_p(), expression_syntax, expression_variable(), gen_length(), NIL, pips_assert, syntax_call, value_expression, and value_expression_p.

Referenced by freia_extract_kernel_vtx().

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

◆ freia_extract_kernel_vtx()

bool freia_extract_kernel_vtx ( dagvtx  v,
bool  strict,
intptr_t k00,
intptr_t k10,
intptr_t k20,
intptr_t k01,
intptr_t k11,
intptr_t k21,
intptr_t k02,
intptr_t k12,
intptr_t k22 
)

vertex-based version

Parameters
stricttrict
k0000
k1010
k2020
k0101
k1111
k2121
k0202
k1212
k2222

Definition at line 2012 of file freia-utils.c.

2017 {
2018  list largs = freia_get_vertex_params(v);
2019  // for convolution there is one kernel & two args
2020  // pips_assert("one kernel", gen_length(largs)==1);
2021  expression e = EXPRESSION(CAR(largs));
2022  return freia_extract_kernel(e, strict, k00, k10, k20,
2023  k01, k11, k21, k02, k12, k22);
2024 }
static bool freia_extract_kernel(expression e, bool strict, intptr_t *k00, intptr_t *k10, intptr_t *k20, intptr_t *k01, intptr_t *k11, intptr_t *k21, intptr_t *k02, intptr_t *k12, intptr_t *k22)
extract values from a kernel definition return 9 values, expected to be 0/1 elsewhere....
Definition: freia-utils.c:1957

References CAR, EXPRESSION, freia_extract_kernel(), and freia_get_vertex_params().

Referenced by constant_image_p(), copy_image_p(), dagvtx_constant_kernel_p(), erosion_optimization(), mppa_compile_dag(), mppa_helper_args_params(), opencl_compile_mergeable_dag(), opencl_generate_special_kernel_ops(), opencl_merge_and_compile(), sc_kernel_compute_loop(), and sc_print_kernel().

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

◆ freia_extract_params()

list freia_extract_params ( const int  napi,
list  args,
string_buffer  head,
string_buffer  head2,
hash_table  params,
int nparams 
)

returns an allocated expression list of the parameters only (i.e.

do not include the input & output images). params maps variables (if so) to already present parameters names. the extraction function allocs new parameter names if necessary. of expression

Parameters
napiapi
argsrgs
headead
head2ead2
paramsarams
nparamsparams

Definition at line 612 of file freia-utils.c.

619 {
620  const freia_api_t * api = get_freia_api(napi);
621  args = freia_get_params(api, args);
622  list res = NIL;
623  bool merge = get_bool_property("FREIA_MERGE_ARGUMENTS");
624 
625  // important shortcut, taken when ops are switched to "copy" for
626  // some reason, then the next assert would not be consistent.
627  if (api->arg_misc_in==0 && api->arg_misc_out==0)
628  return NIL;
629 
630  pips_assert("number of arguments is okay",
631  gen_length(args)==api->arg_misc_in+api->arg_misc_out);
632 
633  for (unsigned int i = 0; i<api->arg_misc_in; i++)
634  {
635  expression e = EXPRESSION(CAR(args));
636  args = CDR(args);
637 
638  if (params)
639  {
640  // ??? if the expression is a constant,
641  // the parameter could be skipped as well?
642  entity var = expression_to_entity(e);
643  if (merge && !entity_undefined_p(var) && entity_variable_p(var))
644  {
645  if (!hash_defined_p(params, var))
646  {
647  // choose new name
648  string name = get_var("pi", nparams);
649  if (head) sb_cat(head, ",\n ", api->arg_in_types[i], " ", name);
650  if (head2) sb_cat(head2, ", ", api->arg_in_types[i], " ", name);
651  hash_put(params, e, name);
652  res = CONS(expression, copy_expression(e), res);
653  // keep record for the *variable* as well...
654  hash_put(params, var, name);
655  }
656  else
657  {
658  // skip argument, just record its where it is found
659  hash_put(params, e, hash_get(params, var));
660  }
661  }
662  else
663  {
664  // append and record new parameter
665  string name = get_var("pi", nparams);
666  if (head) sb_cat(head, ",\n ", api->arg_in_types[i], " ", name);
667  if (head2) sb_cat(head2, ", ", api->arg_in_types[i], " ", name);
668  hash_put(params, e, name);
669  res = CONS(expression, copy_expression(e), res);
670  }
671  }
672  else
673  res = CONS(expression, copy_expression(e), res);
674  }
675 
676  for (unsigned int i = 0; i<api->arg_misc_out; i++)
677  {
678  expression e = EXPRESSION(CAR(args));
679  args = CDR(args);
680  string name = get_var("po", nparams);
681  if (head) sb_cat(head, ",\n ", api->arg_out_types[i], " ", name);
682  if (head2) sb_cat(head2, ", ", api->arg_out_types[i], " ", name);
683  if (params)
684  hash_put(params, e, name);
685  else
686  free(name);
687  res = CONS(expression, copy_expression(e), res);
688  }
689 
690  return gen_nreverse(res);
691 }
expression copy_expression(expression p)
EXPRESSION.
Definition: ri.c:850
struct paramStruct params
static string get_var(string prefix, int *params)
Definition: freia-utils.c:491
list freia_get_params(const freia_api_t *api, list args)
get freia further parameters, skipping image ones
Definition: freia-utils.c:569
const freia_api_t * get_freia_api(int index)
Definition: freia-utils.c:477
#define sb_cat(args...)
Definition: freia.h:42
void free(void *)
#define entity_variable_p(e)
An entity_variable_p(e) may hide a typedef and hence a functional type.
entity expression_to_entity(expression e)
just returns the entity of an expression, or entity_undefined
Definition: expression.c:3140
#define entity_undefined_p(x)
Definition: ri.h:2762
FREIA API function name -> SPoC hardware description (and others?)
Definition: freia.h:71
unsigned int arg_misc_in
Definition: freia.h:83
string arg_out_types[3]
Definition: freia.h:85
string arg_in_types[3]
Definition: freia.h:86
unsigned int arg_misc_out
Definition: freia.h:82

References freia_api_t::arg_in_types, freia_api_t::arg_misc_in, freia_api_t::arg_misc_out, freia_api_t::arg_out_types, CAR, CDR, CONS, copy_expression(), entity_undefined_p, entity_variable_p, EXPRESSION, expression_to_entity(), free(), freia_get_params(), gen_length(), gen_nreverse(), get_bool_property(), get_freia_api(), get_var(), hash_defined_p(), hash_get(), hash_put(), NIL, params, pips_assert, and sb_cat.

Referenced by freia_spoc_pipeline(), freia_terapix_call(), opencl_compile_mergeable_dag(), same_constant_parameters(), and sc_get_params_values().

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

◆ freia_get_nth_scalar_param()

expression freia_get_nth_scalar_param ( const dagvtx  v,
int  n 
)

Definition at line 589 of file freia-utils.c.

590 {
592 }
list gen_nthcdr(int n, const list lx)
caution: the first item is 0! was: return( (n<=0) ? l : gen_nthcdr( n-1, CDR( l ))) ; if n>gen_length...
Definition: list.c:700

References CAR, EXPRESSION, freia_get_vertex_params(), and gen_nthcdr().

Referenced by constant_image_p(), copy_image_p(), and propagate_constant_image().

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

◆ freia_get_params()

list freia_get_params ( const freia_api_t api,
list  args 
)

get freia further parameters, skipping image ones

Parameters
apipi
argsrgs

Definition at line 569 of file freia-utils.c.

570 {
571  int skip = api->arg_img_in + api->arg_img_out;
572  while (skip--) args = CDR(args);
573  pips_assert("number of scalar args is ok",
574  gen_length(args)==api->arg_misc_in+api->arg_misc_out);
575  return args;
576 }
unsigned int arg_img_out
Definition: freia.h:79
unsigned int arg_img_in
Definition: freia.h:80

References freia_api_t::arg_img_in, freia_api_t::arg_img_out, freia_api_t::arg_misc_in, freia_api_t::arg_misc_out, CDR, gen_length(), and pips_assert.

Referenced by freia_extract_params(), and freia_get_vertex_params().

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

◆ freia_get_vertex_params()

list freia_get_vertex_params ( const dagvtx  v)

Definition at line 578 of file freia-utils.c.

579 {
580  const vtxcontent vc = dagvtx_content(v);
581  pips_assert("there is a statement",
584  const call c = freia_statement_to_call(s);
585  const freia_api_t * api = dagvtx_freia_api(v);
586  return freia_get_params(api, call_arguments(c));
587 }
call freia_statement_to_call(const statement s)
return the actual function call from a statement, dealing with assign and returns....
Definition: freia-utils.c:973
#define dagvtx_freia_api(v)
Definition: freia.h:97
#define pstatement_statement_p(x)
#define dagvtx_content(x)
#define pstatement_statement(x)
#define vtxcontent_source(x)

References call_arguments, dagvtx_content, dagvtx_freia_api, freia_get_params(), freia_statement_to_call(), pips_assert, pstatement_statement, pstatement_statement_p, and vtxcontent_source.

Referenced by freia_convolution_width_height(), freia_extract_kernel_vtx(), freia_get_nth_scalar_param(), freia_terapix_call(), gram_param(), has_vtx_dynamic_params(), mppa_compile_dag(), mppa_helper_args_params(), sc_delimiter(), sc_inst(), sc_kernel_specific_agent(), sigmac_params_decl(), spoc_alu_conf(), spoc_measure_conf(), spoc_poc_conf(), spoc_th_conf(), and terapix_gram_management().

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

◆ freia_image_variable_p()

bool freia_image_variable_p ( const entity  var)

rather approximative?

Parameters
varar

Definition at line 768 of file freia-utils.c.

769 {
770  bool is_image = false;
771  if (var && var!=entity_undefined &&
772  entity_variable_p(var) && entity_pointer_p(var))
773  {
774  type t = ultimate_type(entity_type(var));
776  if (basic_pointer_p(b))
777  {
778  t = basic_pointer(b);
780  is_image = basic_typedef_p(b) &&
782  "$" FREIA_IMAGE_TYPE);
783  }
784  }
785 
786  pips_debug(8, "%s is%s an image\n", entity_name(var), is_image? "": " not");
787  return is_image;
788 }
#define FREIA_IMAGE_TYPE
Definition: freia.h:46
bool entity_pointer_p(entity e)
Definition: entity.c:745
type ultimate_type(type)
Definition: type.c:3466
#define basic_pointer(x)
Definition: ri.h:637
#define basic_typedef_p(x)
Definition: ri.h:641
#define type_variable(x)
Definition: ri.h:2949
#define basic_pointer_p(x)
Definition: ri.h:635
#define basic_typedef(x)
Definition: ri.h:643
#define entity_undefined
Definition: ri.h:2761
#define variable_basic(x)
Definition: ri.h:3120

References basic_pointer, basic_pointer_p, basic_typedef, basic_typedef_p, entity_local_name(), entity_name, entity_pointer_p(), entity_type, entity_undefined, entity_variable_p, FREIA_IMAGE_TYPE, pips_debug, same_string_p, type_variable, ultimate_type(), and variable_basic.

Referenced by check_ref(), collect_images(), fis_call_flt(), freia_compute_output_images(), freia_shuffle_move_forward(), freia_some_effects_on_images(), image_ref_flt(), oi_call_rwt(), ref_count_rwt(), seq_rwt(), and set_add_scalars().

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

◆ freia_init_dep_cache()

void freia_init_dep_cache ( void  )

Definition at line 909 of file freia-utils.c.

910 {
911  pips_assert("dep_cache is NULL", !dep_cache);
913 }

References dep_cache, hash_pointer, hash_table_make(), and pips_assert.

Referenced by freia_compile().

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

◆ freia_insert_added_stats()

void freia_insert_added_stats ( list  ls,
list  stats,
bool  before 
)

insert statements to actual code sequence in "ls" BEWARE that ls is assumed to be in reverse order...

Parameters
lss
statstats
beforeefore

Definition at line 1185 of file freia-utils.c.

1186 {
1187  if (stats)
1188  {
1189  statement sref = find_aipo_statement(ls, before);
1190  pips_debug(8, "sref for %s is %" _intFMT "\n",
1191  before? "before": "after", statement_number(sref));
1192  instruction iref = statement_instruction(sref);
1193  statement newstat = instruction_to_statement(iref);
1194  // transfer comments and some cleanup...
1195  statement_comments(newstat) = statement_comments(sref);
1198  // pretty ugly because return must be handled especially...
1199  // ??? not sure that it is ok if !before?
1200  if (instruction_call_p(iref) &&
1202  {
1203  call c = instruction_call(iref);
1205  {
1206  // must split return...
1207  pips_internal_error("return splitting not implemented yet...");
1208  }
1209  else
1210  {
1211  if (before)
1212  stats = gen_nconc(stats, CONS(statement, newstat, NIL));
1213  else
1214  // ???
1215  stats = CONS(statement, newstat, stats);
1216  }
1217  }
1218  else
1219  {
1220  if (before)
1221  stats = CONS(statement, newstat, stats);
1222  else
1223  stats = gen_nconc(stats, CONS(statement, newstat, NIL));
1224  }
1225  statement_instruction(sref) =
1227  }
1228 }
instruction make_instruction_sequence(sequence _field_)
Definition: ri.c:1169
static statement find_aipo_statement(list ls, bool before)
Definition: freia-utils.c:1147
statement instruction_to_statement(instruction)
Build a statement from a give instruction.
Definition: statement.c:597
bool expression_constant_p(expression)
HPFC module by Fabien COELHO.
Definition: expression.c:2453
#define pips_internal_error
Definition: misc-local.h:149
#define string_undefined
Definition: newgen_types.h:40
#define STATEMENT_NUMBER_UNDEFINED
default values
#define ENTITY_C_RETURN_P(e)
#define call_function(x)
Definition: ri.h:709
#define instruction_call_p(x)
Definition: ri.h:1527
#define statement_instruction(x)
Definition: ri.h:2458
#define statement_comments(x)
Definition: ri.h:2456
#define instruction_call(x)
Definition: ri.h:1529

References _intFMT, call_arguments, call_function, CAR, CONS, ENTITY_C_RETURN_P, EXPRESSION, expression_constant_p(), find_aipo_statement(), gen_nconc(), instruction_call, instruction_call_p, instruction_to_statement(), make_instruction_sequence(), make_sequence(), NIL, pips_debug, pips_internal_error, statement_comments, statement_instruction, statement_number, STATEMENT_NUMBER_UNDEFINED, and string_undefined.

Referenced by freia_aipo_compile_calls(), freia_mppa_compile_calls(), freia_opencl_compile_calls(), and sc_delimiter().

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

◆ freia_max_pixel_value()

int freia_max_pixel_value ( void  )

Definition at line 594 of file freia-utils.c.

595 {
596  int bpp = FREIA_DEFAULT_BPP;
597  switch (bpp)
598  {
599  case 8: return 0xff;
600  case 16: return 0xffff;
601  default:
602  pips_user_error("expecting 8 or 16 for pixel size, got %d", bpp);
603  return 0;
604  }
605 }
#define FREIA_DEFAULT_BPP
Definition: freia.h:53
#define pips_user_error
Definition: misc-local.h:147

References FREIA_DEFAULT_BPP, and pips_user_error.

Referenced by constant_image_p(), and copy_image_p().

+ Here is the caller graph for this function:

◆ freia_migrate_statements()

void freia_migrate_statements ( sequence  sq,
const set  stats,
const set  before 
)
Parameters
sqq
statstats
beforeefore

Definition at line 1905 of file freia-utils.c.

1906 {
1907  ifdebug(4) {
1908  pips_debug(4, "migrating %d statements in %p\n", set_size(stats), sq);
1909  set_fprint(stderr, "stats", stats, (gen_string_func_t) stat_nb);
1910  set_fprint(stderr, "before", before, (gen_string_func_t) stat_nb);
1911  }
1912 
1913  // nothing to do
1914  if (sq==NULL)
1915  {
1916  pips_assert("nothing to migrate", set_size(stats)<=1);
1917  return;
1918  }
1919 
1920  // nothing to do either
1921  if (set_size(stats)==0)
1922  return;
1923 
1924  // build before/in/end statement lists in reverse order
1925  list lbefore = NIL, lin = NIL, lend = NIL;
1927  {
1928  if (set_belong_p(stats, s))
1929  lin = CONS(statement, s, lin);
1930  else
1931  {
1932  if (before && set_belong_p(before, s))
1933  lbefore = CONS(statement, s, lbefore);
1934  else
1935  {
1936  if (lin)
1937  lend = CONS(statement, s, lend);
1938  else
1939  lbefore = CONS(statement, s, lbefore);
1940  }
1941  }
1942  }
1943 
1944  // check consistency
1945  pips_assert("all statements seen", set_size(stats)==(int) gen_length(lin));
1946 
1947  // update sequence
1949  lin = gen_nconc(gen_nreverse(lin), gen_nreverse(lend));
1950  sequence_statements(sq) = gen_nconc(gen_nreverse(lbefore), lin);
1951 }
static string stat_nb(statement s)
Definition: freia-utils.c:1893
void set_fprint(FILE *, string, const set, gen_string_func_t)
print set s to file stream out.
Definition: set.c:524
string(* gen_string_func_t)(const void *)
Definition: newgen_types.h:111
#define ifdebug(n)
Definition: sg.c:47
static int lend()
return 1 for 'end' alone on card (up to col.
Definition: split_file.c:242

References CONS, FOREACH, gen_free_list(), gen_length(), gen_nconc(), gen_nreverse(), ifdebug, lend(), NIL, pips_assert, pips_debug, sequence_statements, set_belong_p(), set_fprint(), set_size(), and stat_nb().

Referenced by freia_mppa_compile_calls(), freia_opencl_compile_calls(), migrate_statements(), and sc_delimiter().

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

◆ freia_ok()

call freia_ok ( void  )

build all is well freia constant

Definition at line 695 of file freia-utils.c.

696 {
697  // how to build the "FREIA_OK" enum value constant?
699 }

References local_name_to_top_level_entity(), make_call(), and NIL.

Referenced by freia_cleanup_status(), hwac_kill_statement(), mppa_call_helper(), and sc_delimiter().

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

◆ freia_scalar_rw_dep()

bool freia_scalar_rw_dep ( const statement  s,
const statement  t,
list vars 
)
Parameters
varsars

Definition at line 929 of file freia-utils.c.

930 {
931  pips_assert("dep_cache is not NULL", dep_cache);
932 
933  // short circuit
934  if (s==t || !s || !t) return false;
935 
936  // first level
937  if (!hash_defined_p(dep_cache, s))
940 
941  // second level
942  if (!hash_defined_p(h, t)) {
943  list l = NIL;
944  real_freia_scalar_rw_dep(s, t, &l);
945  hash_put(h, t, l);
946  }
947 
948  list l = (list) hash_get(h, t);
949  if (vars) *vars = gen_copy_seq(l);
950  return l!=NIL;
951 }
static bool real_freia_scalar_rw_dep(const statement s, const statement t, list *vars)
is there a simple scalar (no image) rw dependency from s to t? WW deps are ignored....
Definition: freia-utils.c:881
list gen_copy_seq(list l)
Copy a list structure.
Definition: list.c:501
struct __hash_table * hash_table
Define hash_table structure which is hidden.
Definition: newgen_hash.h:43
struct cons * list
Definition: newgen_types.h:106

References dep_cache, gen_copy_seq(), hash_defined_p(), hash_get(), hash_pointer, hash_put(), hash_table_make(), NIL, pips_assert, and real_freia_scalar_rw_dep().

Referenced by all_previous_stats_with_deps_are_computed(), any_scalar_dep(), and dagvtx_dot().

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

◆ freia_spoc_set_operation()

void freia_spoc_set_operation ( const freia_api_t api,
_int type,
_int id 
)

??? beurk: I keep the operation as two ints for code regeneration.

Parameters
apipi
typeype
idd

Definition at line 545 of file freia-utils.c.

546 {
547  pips_assert("no type set", *type == spoc_type_nop);
548 
549  // set type which is enough for staging?
550  if (api->spoc.used==spoc_not_implemented)
551  *type = spoc_type_sni;
552  else if (api->spoc.used & spoc_alu)
553  *type = spoc_type_alu;
554  else if (api->spoc.used & (spoc_poc_0|spoc_poc_1))
555  *type = spoc_type_poc;
556  else if (api->spoc.used & (spoc_th_0|spoc_th_1))
557  *type = spoc_type_thr;
558  else if (api->spoc.used & (spoc_measure_0|spoc_measure_1))
559  *type = spoc_type_mes;
560  else
561  *type = spoc_type_nop; // e.g. for copy? (...)
562 
563  // set details
565 }
int hwac_freia_api_index(const string function)
returns the index of the description of an AIPO function
Definition: freia-utils.c:471
@ spoc_measure_0
Definition: freia_spoc.h:50
@ spoc_th_0
Definition: freia_spoc.h:47
@ spoc_measure_1
Definition: freia_spoc.h:51
@ spoc_alu
Definition: freia_spoc.h:45
@ spoc_poc_1
Definition: freia_spoc.h:43
@ spoc_poc_0
Definition: freia_spoc.h:42
@ spoc_th_1
Definition: freia_spoc.h:48
@ spoc_type_sni
Definition: freia_spoc.h:172
@ spoc_type_mes
Definition: freia_spoc.h:179
@ spoc_type_nop
Definition: freia_spoc.h:174
@ spoc_type_thr
Definition: freia_spoc.h:178
@ spoc_type_alu
Definition: freia_spoc.h:177
@ spoc_type_poc
Definition: freia_spoc.h:176

References freia_api_t::function_name, hwac_freia_api_index(), pips_assert, freia_api_t::spoc, spoc_alu, spoc_measure_0, spoc_measure_1, spoc_not_implemented, spoc_poc_0, spoc_poc_1, spoc_th_0, spoc_th_1, spoc_type_alu, spoc_type_mes, spoc_type_nop, spoc_type_poc, spoc_type_sni, spoc_type_thr, and spoc_hw_t::used.

Referenced by dag_append_freia_call().

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

◆ freia_statement_aipo_call_p()

bool freia_statement_aipo_call_p ( const statement  s)

returns whether the statement is a FREIA call.

Definition at line 814 of file freia-utils.c.

815 {
816  // very partial as well
818  if (instruction_call_p(i)) {
819  call c = instruction_call(i);
820  entity called = call_function(c);
821  if (entity_freia_api_p(called))
822  return true;
823  else if (freia_assignment_p(called))
824  {
825  list la = call_arguments(c);
826  pips_assert("2 arguments to assign", gen_length(la));
828  if (syntax_call_p(op2))
830  }
831  else if (ENTITY_C_RETURN_P(called))
832  {
833  list la = call_arguments(c);
834  if (gen_length(la)==1) {
836  if (syntax_call_p(op))
838  }
839  }
840  }
841  return false;
842 }
bool entity_freia_api_p(const entity f)
returns whether the entity is a freia API (AIPO) function.
Definition: freia-utils.c:806
bool freia_assignment_p(const entity e)
tell whether it is an assignment to ignore?
Definition: freia-utils.c:703
#define syntax_call_p(x)
Definition: ri.h:2734

References call_arguments, call_function, CAR, CDR, ENTITY_C_RETURN_P, entity_freia_api_p(), EXPRESSION, expression_syntax, freia_assignment_p(), gen_length(), instruction_call, instruction_call_p, pips_assert, statement_instruction, syntax_call, and syntax_call_p.

Referenced by clean_list_head(), freia_cleanup_sequence_rec(), freia_reduction_variable(), fsi_seq_flt(), fsi_stmt_flt(), and set_add_scalars().

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

◆ freia_statement_to_call()

call freia_statement_to_call ( const statement  s)

return the actual function call from a statement, dealing with assign and returns...

return NULL if not a call.

Definition at line 973 of file freia-utils.c.

974 {
975  // sanity check, somehow redundant
977  call c = instruction_call_p(i)? instruction_call(i): NULL;
978  if (c && freia_assignment_p(call_function(c)))
979  {
980  list args = call_arguments(c);
981  pips_assert("2 args", gen_length(args) == 2);
982  syntax sy = expression_syntax(EXPRESSION(CAR(CDR(args))));
983  c = syntax_call_p(sy)? syntax_call(sy): NULL;
984  }
985  else if (c && ENTITY_C_RETURN_P(call_function(c)))
986  {
987  list args = call_arguments(c);
988  pips_assert("one arg", gen_length(args)==1);
989  syntax sy = expression_syntax(EXPRESSION(CAR(args)));
990  c = syntax_call_p(sy)? syntax_call(sy): NULL;
991  }
992  return c;
993 }

References call_arguments, call_function, CAR, CDR, ENTITY_C_RETURN_P, EXPRESSION, expression_syntax, freia_assignment_p(), gen_length(), instruction_call, instruction_call_p, pips_assert, statement_instruction, syntax_call, and syntax_call_p.

Referenced by any_use_statement(), dag_append_freia_call(), dag_normalize(), dagvtx_copy_list_dot(), fcs_count(), freia_alloc_stat_p(), freia_cleanup_sequence_rec(), freia_get_vertex_params(), freia_reduction_variable(), freia_spoc_pipeline(), freia_stmt_free_p(), freia_terapix_call(), get_upper_model(), is_freia_this_call(), maybe_unroll_while_rwt(), opencl_compile_mergeable_dag(), opencl_generate_special_kernel_ops(), same_constant_parameters(), sc_get_params_values(), set_aipo_call(), and substitute_image_in_statement().

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

◆ freia_substitute_by_helper_call()

int freia_substitute_by_helper_call ( dag  d,
set  global_remainings,
set  remainings,
list  ls,
const string  function_name,
list  lparams,
set  helpers,
int  preceeding 
)

substitute those statement in ls that are in dag d and accelerated by a call to function_name(lparams) also update sets of remainings and global_remainings

the function must chose one of the statements? the current implementation is a buggy mess. it should be fully re-thought from scratch.

what should be done, is to chose the FIRST statement after the LAST dependency of the compiled statements? at least it must exist beacause one of the dependent statement must appear after that, but is it enough for all possible graph? so maybe we should do a topological sort of all the statements and reshuffle everything instead of trying to preserver the initial code as much as possible?

Parameters
global_remainingslobal_remainings
remainingsemainings
lsof statement
function_nameunction_name
lparamsparams
helperselpers
preceedingreceeding

Definition at line 1073 of file freia-utils.c.

1083 {
1084  pips_debug(7, "%d statements, must come after statement %d\n",
1085  (int) gen_length(ls), preceeding);
1086 
1087  // buid the set of statements that are not yet computed
1088  set not_dones = set_make(set_pointer), dones = set_make(set_pointer);
1089  if (d)
1090  {
1091  FOREACH(dagvtx, vs, dag_vertices(d))
1092  {
1094  if (pstatement_statement_p(ps))
1095  set_add_element(not_dones, not_dones, pstatement_statement(ps));
1096  }
1097  }
1098  // dones: those statements which are handled by this helper
1099  set_difference(dones, remainings, not_dones);
1100  // now update remainings & global_remainings
1101  set_difference(remainings, remainings, dones);
1102  set_difference(global_remainings, global_remainings, dones);
1103 
1104  // replace first statement of dones in ls,
1105  // which comes after the preceeding ones.
1106  statement found = NULL, sos = NULL;
1107  FOREACH(statement, sc, ls)
1108  {
1109  pips_debug(5, "in statement %" _intFMT "\n", statement_number(sc));
1110  if (set_belong_p(dones, sc))
1111  {
1112  sos = sos? (statement_number(sc)<statement_number(sos)? sc: sos): sc;
1113  if (statement_number(sc)>preceeding)
1114  {
1115  pips_assert("statement is a call", statement_call_p(sc));
1116  found = found?
1117  (statement_number(sc)<statement_number(found)? sc: found): sc;
1118  }
1119  }
1120  }
1121 
1122  if (!found)
1123  {
1124  pips_user_warning("no statement found after preceeding insertion, "
1125  "using first statement as backup...\n");
1126  // use backup
1127  found = sos;
1128  }
1129 
1130  pips_assert("some statement found", found);
1131 
1132  // create and record helper function
1133  entity helper = freia_create_helper_function(function_name, lparams);
1134  set_add_element(helpers, helpers, helper);
1135 
1136  // substitute by call to helper
1137  call c = make_call(helper, lparams);
1138 
1139  hwac_replace_statement(found, c, false);
1140 
1141  set_free(not_dones);
1142  set_free(dones);
1143 
1144  return statement_number(found);
1145 }
entity freia_create_helper_function(const string function_name, list lparams)
Definition: freia-utils.c:1030
void hwac_replace_statement(statement s, call newc, bool kill)
replace statement contents with call to c, or continue if kill
Definition: freia-utils.c:720
bool statement_call_p(statement)
Definition: statement.c:364
set set_difference(set, const set, const set)
Definition: set.c:256

References _intFMT, dag_vertices, dagvtx_content, FOREACH, freia_create_helper_function(), gen_length(), hwac_replace_statement(), lparams, make_call(), pips_assert, pips_debug, pips_user_warning, pstatement_statement, pstatement_statement_p, set_add_element(), set_belong_p(), set_difference(), set_free(), set_make(), set_pointer, statement_call_p(), statement_number, and vtxcontent_source.

Referenced by freia_trpx_compile_one_dag(), and opencl_compile_mergeable_dag().

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

◆ get_assigned_variable()

static entity get_assigned_variable ( const statement  s)
static

for "ret = freia_aipo_*()": return the 'ret' variable...

return NULL if not an assignment

Definition at line 793 of file freia-utils.c.

794 {
795  entity assigned = NULL;
796  pips_assert("statement is a call", statement_call_p(s));
798  entity called = call_function(c);
799  if (freia_assignment_p(called))
801  return assigned;
802 }

References call_arguments, call_function, CAR, EXPRESSION, expression_to_entity(), freia_assignment_p(), instruction_call, pips_assert, statement_call_p(), and statement_instruction.

Referenced by set_add_scalars().

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

◆ get_freia_api()

const freia_api_t* get_freia_api ( int  index)
Parameters
indexndex

Definition at line 477 of file freia-utils.c.

478 {
479  // pips_assert("index exists", index>=0 && index<(int) FREIA_AIPO_API_SIZE);
480  return &FREIA_AIPO_API[index];
481 }
static const freia_api_t FREIA_AIPO_API[]
!!! there are some underlying assumptions when using this structure: only one of ALU/POC/MES is used ...
Definition: freia-utils.c:99

References FREIA_AIPO_API.

Referenced by commutative_operation_p(), constant_image_p(), copy_image_p(), dagvtx_compact_operation(), dagvtx_function_name(), dagvtx_is_measurement_p(), dagvtx_is_operator_p(), freia_extract_params(), freia_spoc_pipeline(), freia_terapix_call(), get_freia_api_vtx(), opencl_compile_mergeable_dag(), and propagate_constant_image().

+ Here is the caller graph for this function:

◆ get_freia_api_vtx()

const freia_api_t* get_freia_api_vtx ( dagvtx  v)

Definition at line 483 of file freia-utils.c.

484 {
486 }
#define vtxcontent_opid(x)

References dagvtx_content, get_freia_api(), and vtxcontent_opid.

Referenced by dagvtx_constant_kernel_p(), has_vtx_dynamic_params(), mppa_compile_dag(), opencl_generate_special_kernel_ops(), opencl_merge_and_compile(), sc_delimiter(), sc_inst(), sc_vtx_tostring(), sigmac_name_instances(), and sigmac_params_decl().

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

◆ get_var()

static string get_var ( string  prefix,
int params 
)
static
Returns
new allocated variable name using provided prefix. *params is incremented as a side effect.

Definition at line 491 of file freia-utils.c.

492 {
493  return strdup(cat(prefix, i2a((*params)++)));
494 }
#define cat(args...)
Definition: freia.h:41
char * i2a(int)
I2A (Integer TO Ascii) yields a string for a given Integer.
Definition: string.c:121
static const char * prefix
char * strdup()

References cat, i2a(), params, prefix, and strdup().

Referenced by freia_extract_params().

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

◆ helper_file_name()

string helper_file_name ( string  func_name,
string  suffix 
)

return malloc'ed "foo.database/Src/%{module}_helper_functions.c" should it depend on the target? no, because we could mix targets?

Parameters
func_nameunc_name
suffixuffix

Definition at line 2029 of file freia-utils.c.

2030 {
2031  string src_dir = db_get_directory_name_for_module(func_name);
2032  string fn = strdup(cat(src_dir, "/", func_name, HELPER "functions.", suffix));
2033  free(src_dir);
2034  return fn;
2035 }
#define HELPER
Definition: freia.h:38
string db_get_directory_name_for_module(const char *name)
returns the allocated and mkdir'ed directory for module name
Definition: lowlevel.c:150

References cat, db_get_directory_name_for_module(), free(), HELPER, and strdup().

Referenced by freia_compile(), and sc_delimiter().

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

◆ hwac_freia_api()

const freia_api_t* hwac_freia_api ( const char *  function)

freia-utils.c

Returns
the description of a FREIA AIPO API function. may be moved elswhere. raise an error if not found.
Parameters
functionunction

Definition at line 455 of file freia-utils.c.

456 {
457  static hash_table cache = NULL;
458  if (!cache)
459  {
460  const freia_api_t * api;
461  cache = hash_table_make(hash_string, 0);
462  for (api = FREIA_AIPO_API; api->function_name; api++)
463  hash_put(cache, api->function_name, api);
464  }
465  return (const freia_api_t *)
466  (hash_defined_p(cache, function)? hash_get(cache, function): NULL);
467 }
@ hash_string
Definition: newgen_hash.h:32

References FREIA_AIPO_API, freia_api_t::function_name, hash_defined_p(), hash_get(), hash_put(), hash_string, and hash_table_make().

Referenced by dag_append_freia_call(), freia_cleanup_sequence_rec(), freia_terapix_call(), hwac_freia_api_index(), reference_written_p(), sio_call_flt(), and swis_call_flt().

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

◆ hwac_freia_api_index()

int hwac_freia_api_index ( const string  function)

returns the index of the description of an AIPO function

Parameters
functionunction

Definition at line 471 of file freia-utils.c.

472 {
473  const freia_api_t * api = hwac_freia_api(function);
474  return api? (api - FREIA_AIPO_API): -1;
475 }
const freia_api_t * hwac_freia_api(const char *function)
freia-utils.c
Definition: freia-utils.c:455

References FREIA_AIPO_API, and hwac_freia_api().

Referenced by commutative_operation_p(), dag_normalize(), freia_spoc_set_operation(), set_aipo_call(), switch_vertex_to_a_copy(), and switch_vertex_to_assign().

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

◆ hwac_kill_statement()

void hwac_kill_statement ( statement  s)

remove contents of statement s.

Definition at line 761 of file freia-utils.c.

762 {
763  hwac_replace_statement(s, freia_ok(), true);
764 }
call freia_ok(void)
build all is well freia constant
Definition: freia-utils.c:695

References freia_ok(), and hwac_replace_statement().

Referenced by freia_dag_optimize(), freia_spoc_pipeline(), freia_terapix_call(), and opencl_compile_mergeable_dag().

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

◆ hwac_replace_statement()

void hwac_replace_statement ( statement  s,
call  newc,
bool  kill 
)

replace statement contents with call to c, or continue if kill

Parameters
newcewc
killill

Definition at line 720 of file freia-utils.c.

721 {
723  pips_assert("must kill a call", instruction_call_p(old));
724  call c = instruction_call(old);
725  entity called = call_function(c);
726  if (ENTITY_C_RETURN_P(called))
727  {
728  // replace argument list
731  }
732  else if (freia_assignment_p(called))
733  {
734  // new second argument
735  list largs = call_arguments(c);
736  pips_assert("two arguments to assignment", gen_length(largs)==2);
737  expression first = EXPRESSION(CAR(largs));
738  free_expression(EXPRESSION(CAR(CDR(largs))));
739  gen_free_list(largs), largs = NIL;
740  call_arguments(c) =
742  }
743  else
744  {
745  free_instruction(old);
746  if (kill)
747  {
748  // ??? in C, it is not a do nothing instruction!
750  free_call(newc);
751  }
752  else
753  {
755  }
756  }
757 }
instruction make_instruction_call(call _field_)
Definition: ri.c:1184
void free_expression(expression p)
Definition: ri.c:853
void free_instruction(instruction p)
Definition: ri.c:1118
void free_call(call p)
Definition: ri.c:236
void gen_full_free_list(list l)
Definition: genClib.c:1023
instruction make_continue_instruction()
Creates a CONTINUE instruction, that is the FORTRAN nop, the ";" in C or the "pass" in Python for exa...
Definition: instruction.c:79
expression call_to_expression(call c)
Build an expression that call a function or procedure.
Definition: expression.c:309

References call_arguments, call_function, call_to_expression(), CAR, CDR, CONS, ENTITY_C_RETURN_P, EXPRESSION, free_call(), free_expression(), free_instruction(), freia_assignment_p(), gen_free_list(), gen_full_free_list(), gen_length(), instruction_call, instruction_call_p, make_continue_instruction(), make_instruction_call(), NIL, pips_assert, and statement_instruction.

Referenced by freia_substitute_by_helper_call(), hwac_kill_statement(), mppa_call_helper(), and sc_delimiter().

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

◆ image_free()

static statement image_free ( entity  v)
static

generate statement: "freia_free(v);"

Definition at line 1484 of file freia-utils.c.

1485 {
1486  return call_to_statement(
1489 }
#define FREIA_FREE
Definition: freia.h:49

References call_to_statement, CONS, entity_to_expression(), FREIA_FREE, local_name_to_top_level_entity(), make_call(), and NIL.

Referenced by freia_allocate_new_images_if_needed().

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

◆ is_freia_alloc()

bool is_freia_alloc ( const statement  s)

Definition at line 1002 of file freia-utils.c.

1003 {
1004  return is_freia_this_call(s, FREIA_ALLOC);
1005 }
static bool is_freia_this_call(const statement s, const string fname)
Definition: freia-utils.c:995
#define FREIA_ALLOC
Definition: freia.h:48

References FREIA_ALLOC, and is_freia_this_call().

Referenced by freia_cmp_statement(), freia_memory_management_statement(), and get_upper_model().

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

◆ is_freia_dealloc()

bool is_freia_dealloc ( const statement  s)

Definition at line 1007 of file freia-utils.c.

1008 {
1009  return is_freia_this_call(s, FREIA_FREE);
1010 }

References FREIA_FREE, and is_freia_this_call().

Referenced by freia_cleanup_sequence_rec(), freia_cmp_statement(), and freia_memory_management_statement().

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

◆ is_freia_this_call()

static bool is_freia_this_call ( const statement  s,
const string  fname 
)
static

Definition at line 995 of file freia-utils.c.

996 {
998  const char* called = c? entity_user_name(call_function(c)): "";
999  return same_string_p(called, fname);
1000 }
const char * entity_user_name(entity e)
Since entity_local_name may contain PIPS special characters such as prefixes (label,...
Definition: entity.c:487

References call_function, entity_user_name(), freia_statement_to_call(), and same_string_p.

Referenced by is_freia_alloc(), and is_freia_dealloc().

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

◆ lexpression_equal_p()

static bool lexpression_equal_p ( const list  l1,
const list  l2 
)
static

Definition at line 953 of file freia-utils.c.

954 {
955  bool equal = true;
956  int n1 = gen_length(l1), n2 = gen_length(l2);
957  if (n1==n2) {
958  list p1 = (list) l1, p2 = (list) l2;
959  while (equal && p1 && p2) {
961  equal = false;
962  p1 = CDR(p1), p2 = CDR(p2);
963  }
964  }
965  else
966  equal = false;
967  return equal;
968 }
bool expression_equal_p(expression e1, expression e2)
Syntactic equality e1==e2.
Definition: expression.c:1347

References CAR, CDR, EXPRESSION, expression_equal_p(), and gen_length().

Referenced by same_constant_parameters().

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

◆ oi_call_rwt()

static void oi_call_rwt ( call  c,
set  images 
)
static

Definition at line 1841 of file freia-utils.c.

1842 {
1843  entity called = call_function(c);
1844  list args = call_arguments(c);
1845  if (!args) return;
1846  if (ENTITY_RETURN_P(called) ||
1848  {
1849  entity var = expression_to_entity(EXPRESSION(CAR(args)));
1850  if (freia_image_variable_p(var))
1851  set_add_element(images, images, var);
1852  }
1853 }
#define FREIA_OUTPUT
Definition: freia.h:47
#define ENTITY_RETURN_P(e)

References call_arguments, call_function, CAR, entity_local_name(), ENTITY_RETURN_P, EXPRESSION, expression_to_entity(), freia_image_variable_p(), FREIA_OUTPUT, same_string_p, and set_add_element().

Referenced by freia_compute_output_images(), and oi_stmt_rwt().

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

◆ oi_stmt_rwt()

static void oi_stmt_rwt ( statement  s,
set  images 
)
static

Definition at line 1855 of file freia-utils.c.

1856 {
1858  gen_context_recurse(entity_initial(var), images,
1860 }

References call_domain, entity_initial, FOREACH, gen_context_recurse, gen_true2(), oi_call_rwt(), and statement_declarations.

Referenced by freia_compute_output_images().

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

◆ only_minor_statements_in_between()

static bool only_minor_statements_in_between ( entity  image,
hash_table  new_images,
hash_table  image_stats,
list  ls,
statement  s1,
list  l2,
set  image_occurences 
)
static

tell whether there is no image processing statements between s1 and l2

Definition at line 1572 of file freia-utils.c.

1587 {
1588  bool s1_seen = false, in_sequence = false;
1589  pips_assert("consistent statement & list", !gen_in_list_p(s1, l2));
1590  int n2 = gen_length(l2);
1591 
1592  ifdebug(8) {
1593  pips_debug(8, "img=%s s=%"_intFMT"\nls = (\n",
1595  FOREACH(statement, sls, ls)
1596  pips_debug(8, " - %"_intFMT" %s\n", statement_number(sls),
1597  sls==s1? "!": gen_in_list_p(sls, l2)? "*": "");
1598  pips_debug(8, ")\n");
1599  }
1600 
1601  // scan the sequence list, looking for s1 & l2 statements
1602  FOREACH(statement, s, ls)
1603  {
1604  if (!in_sequence && s==s1)
1605  in_sequence = true, s1_seen = true;
1606  else if (in_sequence && gen_in_list_p(s, l2))
1607  {
1608  n2--;
1609  if (n2) {
1610  // we are still going on, BUT we must check that this statement
1611  // does not rewrite the image we are interested in and may change back.
1612  if (some_related_image_effect(s, image, new_images, image_stats, true))
1613  return false;
1614  }
1615  // we stop when we have seen all intermediate statements
1616  else
1617  return true;
1618  }
1619  else if (in_sequence && set_belong_p(image_occurences, s))
1620  {
1621  // let us try to do something intelligent here...
1622  // if images are unrelated to "image", then there will be no interaction
1623  if (some_related_image_effect(s, image, new_images, image_stats, false))
1624  return false;
1625  }
1626  }
1627 
1628  // ??? should really be an error...
1629  pips_user_warning("should not get there: s1 seen=%s, seq=%s, n2=%d\n",
1630  bool_to_string(s1_seen), bool_to_string(in_sequence), n2);
1631 
1632  // let us be optimistic, this is a prototype
1633  return true;
1634 }
static bool some_related_image_effect(statement s, entity img, hash_table new_images, hash_table image_stats, bool write_only)
Definition: freia-utils.c:1558
bool gen_in_list_p(const void *vo, const list lx)
tell whether vo belongs to lx
Definition: list.c:734
string bool_to_string(bool)
Definition: string.c:243
code taken from http://fast-edge.googlecode.com and adapted to c99
Definition: erode_dilate.c:33

References _intFMT, bool_to_string(), entity_local_name(), FOREACH, gen_in_list_p(), gen_length(), ifdebug, related_ctx::image_stats, related_ctx::new_images, pips_assert, pips_debug, pips_user_warning, s1, set_belong_p(), some_related_image_effect(), and statement_number.

Referenced by freia_allocate_new_images_if_needed().

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

◆ real_freia_scalar_rw_dep()

static bool real_freia_scalar_rw_dep ( const statement  s,
const statement  t,
list vars 
)
static

is there a simple scalar (no image) rw dependency from s to t? WW deps are ignored...

should be okay of computed in order?

Parameters
ssource statement
ttarget statement
varsif set, return list of scalars which hold the dependencies

Definition at line 881 of file freia-utils.c.

882 {
883  // pips_assert("distinct statements", s!=t);
884  if (s==t || !s || !t) return false;
885  // I should really use entities_may_conflict_p...
886  set reads = set_make(set_pointer), writes = set_make(set_pointer);
887  set_add_scalars(writes, s, true);
888  set_add_scalars(reads, t, false);
889  set inter = set_make(set_pointer);
890  set_intersection(inter, reads, writes);
891  bool rw_dep = !set_empty_p(inter);
892  if (vars)
894  set_free(reads);
895  set_free(writes);
896  set_free(inter);
897  pips_debug(8, "%" _intFMT " %sdependent from %" _intFMT "\n",
898  statement_number(t), rw_dep? "": "in", statement_number(s));
899  return rw_dep;
900 }
static void set_add_scalars(set s, const statement stat, const bool written)
append simple scalar entities with written/read effects to s scalars assigned to are ignored (return ...
Definition: freia-utils.c:850
bool set_empty_p(const set)
tell whether set s is empty.
Definition: set.c:367
set set_intersection(set, const set, const set)
Definition: set.c:229
list set_to_sorted_list(const set, gen_cmp_func_t)
Definition: set.c:447
int(* gen_cmp_func_t)(const void *, const void *)
Definition: newgen_types.h:114
int compare_entities(const entity *pe1, const entity *pe2)
Comparison function for qsort.
Definition: entity.c:1328

References _intFMT, compare_entities(), pips_debug, set_add_scalars(), set_empty_p(), set_free(), set_intersection(), set_make(), set_pointer, set_to_sorted_list(), and statement_number.

Referenced by freia_scalar_rw_dep().

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

◆ reference_argument_number()

static int reference_argument_number ( const reference  r,
const list  le 
)
static

return the argument number, starting from 1, of this reference or 0 if not found.

Definition at line 1253 of file freia-utils.c.

1254 {
1255  int n = 0, i=0;
1256  FOREACH(expression, e, le)
1257  {
1258  i++;
1260  n = i;
1261  }
1262  return n;
1263 }
reference expression_reference(expression e)
Short cut, meaningful only if expression_reference_p(e) holds.
Definition: expression.c:1832

References expression_reference(), expression_reference_p(), and FOREACH.

Referenced by reference_written_p().

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

◆ reference_written_p()

static bool reference_written_p ( const reference  r,
const hash_table  signatures 
)
static

tell about the image effect.

if in doubt, return true.

Definition at line 1267 of file freia-utils.c.

1270 {
1271  const char* why = "default", *func = "?";
1272  bool written = false;
1274  if (c)
1275  {
1276  entity called = call_function(c);
1277  func = entity_local_name(called);
1279  if (n==0)
1280  written=true, why = "not found";
1281  else
1282  {
1283  const freia_api_t * api = hwac_freia_api(entity_local_name(called));
1284  if (api)
1285  written = n <= (int) api->arg_img_out, why = "api";
1286  else
1287  if (signatures && hash_defined_p(signatures, called))
1288  written = n <= (_int) hash_get(signatures, called), why = "sig";
1289  else
1290  written = true, why = "no sig";
1291  }
1292  }
1293  else
1294  // in doubt, assume a write effect?
1295  pips_internal_error("reference to %s outside of a call?\n",
1297 
1298  pips_debug(8, "reference to %s is %s (%s in %s)\n",
1300  written? "written": "read", why, func);
1301 
1302  return written;
1303 }
void const char const char const int
static int reference_argument_number(const reference r, const list le)
return the argument number, starting from 1, of this reference or 0 if not found.
Definition: freia-utils.c:1253
if(!(yy_init))
Definition: genread_lex.c:1029
intptr_t _int
_INT
Definition: newgen_types.h:53
struct _newgen_struct_call_ * call
Definition: ri.h:63

References freia_api_t::arg_img_out, call_arguments, call_domain, call_function, entity_local_name(), gen_get_ancestor(), hash_defined_p(), hash_get(), hwac_freia_api(), if(), int, pips_debug, pips_internal_error, reference_argument_number(), reference_variable, and written.

Referenced by check_ref().

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

◆ related_effect()

static bool related_effect ( statement  s,
struct related_ctx ctx 
)
static

Definition at line 1524 of file freia-utils.c.

1525 {
1526  pips_debug(8, "on statement %"_intFMT"\n", statement_number(s));
1527  entity written = NULL;
1529  {
1530  if (related_images_p(ctx->img, w, ctx->new_images))
1531  {
1532  pips_debug(8, "W relation for %s & %s\n",
1534  ctx->some_effect = true;
1535  gen_recurse_stop(NULL);
1536  return false;
1537  }
1538  written = w;
1539  }
1540  if (!ctx->write_only)
1541  {
1542  pips_assert("some written stuff", written);
1543  SET_FOREACH(entity, r, (set) hash_get(ctx->image_stats, E_READ(s)))
1544  {
1545  if (related_images_p(ctx->img, r, ctx->new_images))
1546  {
1547  pips_debug(8, "R relation for %s & %s\n",
1549  ctx->some_effect = true;
1550  gen_recurse_stop(NULL);
1551  return false;
1552  }
1553  }
1554  }
1555  return true;
1556 }
static bool related_images_p(const entity img1, const entity img2, const hash_table new_images)
is there an effect to this image or related images in the statement?
Definition: freia-utils.c:1504
void gen_recurse_stop(void *obj)
Tells the recursion not to go in this object.
Definition: genClib.c:3251
#define SET_FOREACH(type_name, the_item, the_set)
enumerate set elements in their internal order.
Definition: newgen_set.h:78
const hash_table new_images
Definition: freia-utils.c:1493
const hash_table image_stats
Definition: freia-utils.c:1494
const entity img
Definition: freia-utils.c:1492
bool some_effect
Definition: freia-utils.c:1496

References _intFMT, E_READ, E_WRITE, entity_local_name(), gen_recurse_stop(), hash_get(), related_ctx::image_stats, related_ctx::img, related_ctx::new_images, pips_assert, pips_debug, related_images_p(), SET_FOREACH, related_ctx::some_effect, statement_number, related_ctx::write_only, and written.

Referenced by some_related_image_effect().

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

◆ related_images_p()

static bool related_images_p ( const entity  img1,
const entity  img2,
const hash_table  new_images 
)
static

is there an effect to this image or related images in the statement?

are img1 and img2 related?

Definition at line 1504 of file freia-utils.c.

1506 {
1507  entity oimg1 = NULL, oimg2 = NULL;
1508  if (img1==img2) return true;
1509  if (hash_defined_p(new_images, img1))
1510  oimg1 = (entity) hash_get(new_images, img1);
1511  if (hash_defined_p(new_images, img2))
1512  oimg2 = (entity) hash_get(new_images, img2);
1513 
1514  pips_debug(9, "images: %s -> %s / %s -> %s\n",
1515  entity_local_name(img1), oimg1? entity_local_name(oimg1): "NONE",
1516  entity_local_name(img2), oimg2? entity_local_name(oimg2): "NONE");
1517 
1518  if (oimg1 && oimg1==img2) return true;
1519  if (oimg2 && img1==oimg2) return true;
1520  // this is really the one which should be triggered?
1521  return oimg1 && oimg2 && oimg1==oimg2;
1522 }

References entity_local_name(), hash_defined_p(), hash_get(), and pips_debug.

Referenced by related_effect().

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

◆ same_constant_parameters()

bool same_constant_parameters ( const dagvtx  v1,
const dagvtx  v2 
)

tell whether v1 and v2 point to statements with the same parameters.

Parameters
v11
v22

Definition at line 1014 of file freia-utils.c.

1015 {
1016  call
1019  list
1020  lp1 = freia_extract_params
1021  (dagvtx_opid(v1), call_arguments(c1), NULL, NULL, NULL, NULL),
1022  lp2 = freia_extract_params
1023  (dagvtx_opid(v1), call_arguments(c2), NULL, NULL, NULL, NULL);
1024  bool same = lexpression_equal_p(lp1, lp2);
1025  gen_free_list(lp1), gen_free_list(lp2);
1026  // should also check that there is no w effects on parameters in between
1027  return same;
1028 }
statement dagvtx_statement(const dagvtx v)
return statement if any, or NULL (for input nodes).
Definition: dag-utils.c:56
_int dagvtx_opid(const dagvtx v)
Definition: dag-utils.c:121
list freia_extract_params(const int napi, list args, string_buffer head, string_buffer head2, hash_table params, int *nparams)
returns an allocated expression list of the parameters only (i.e.
Definition: freia-utils.c:613
static bool lexpression_equal_p(const list l1, const list l2)
Definition: freia-utils.c:953

References call_arguments, dagvtx_opid(), dagvtx_statement(), freia_extract_params(), freia_statement_to_call(), gen_free_list(), and lexpression_equal_p().

Referenced by freia_dag_optimize().

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

◆ set_add_scalars()

static void set_add_scalars ( set  s,
const statement  stat,
const bool  written 
)
static

append simple scalar entities with written/read effects to s scalars assigned to are ignored (return status).

no attempt at managing aliasing or the like...

Definition at line 850 of file freia-utils.c.

851 {
853  entity skip = NULL;
854 
855  // skip assigned variable of AIPO calls
856  if (freia_statement_aipo_call_p(stat))
857  skip = get_assigned_variable(stat);
858 
859  FOREACH(effect, e, effects_effects(efs))
860  {
861  if (!malloc_effect_p(e) &&
862  ((written && effect_write_p(e)) || (!written && effect_read_p(e))))
863  {
865  if (entity_variable_p(var) && var!=skip &&
867  set_add_element(s, s, var);
868  }
869  }
870 }
effects load_cumulated_rw_effects(statement)
#define effect_any_reference(e)
FI: cannot be used as a left hand side.
#define effect_write_p(eff)
#define effect_read_p(eff)
#define effect_scalar_p(eff) entity_scalar_p(effect_entity(eff))
bool malloc_effect_p(effect)
Definition: effects.c:478
#define effects_effects(x)
Definition: effects.h:710
static entity get_assigned_variable(const statement s)
for "ret = freia_aipo_*()": return the 'ret' variable...
Definition: freia-utils.c:793
bool freia_statement_aipo_call_p(const statement s)
returns whether the statement is a FREIA call.
Definition: freia-utils.c:814
bool entity_scalar_p(entity)
The concrete type of e is a scalar type.
Definition: variable.c:1113

References effect_any_reference, effect_read_p, effect_write_p, effects_effects, entity_pointer_p(), entity_scalar_p(), entity_variable_p, FOREACH, freia_image_variable_p(), freia_statement_aipo_call_p(), get_assigned_variable(), load_cumulated_rw_effects(), malloc_effect_p(), reference_variable, set_add_element(), and written.

Referenced by real_freia_scalar_rw_dep().

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

◆ some_related_image_effect()

static bool some_related_image_effect ( statement  s,
entity  img,
hash_table  new_images,
hash_table  image_stats,
bool  write_only 
)
static

Definition at line 1558 of file freia-utils.c.

1564 {
1565  struct related_ctx ctx = { img, new_images, image_stats, write_only, false };
1567  return ctx.some_effect;
1568 }
static bool related_effect(statement s, struct related_ctx *ctx)
Definition: freia-utils.c:1524
void gen_null2(__attribute__((unused)) void *u1, __attribute__((unused)) void *u2)
idem with 2 args, to please overpeaky compiler checks
Definition: genClib.c:2758

References gen_context_recurse, gen_null2(), related_ctx::image_stats, related_ctx::img, related_ctx::new_images, related_effect(), related_ctx::some_effect, statement_domain, and related_ctx::write_only.

Referenced by only_minor_statements_in_between().

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

◆ stat_nb()

static string stat_nb ( statement  s)
static

Definition at line 1893 of file freia-utils.c.

1894 {
1895  return i2a((int) statement_number(s));
1896 }

References i2a(), and statement_number.

Referenced by freia_migrate_statements().

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

◆ what_operation()

string what_operation ( const _int  type)
Returns
a string which describes the type of operation (i.e. the hardware used by the function for spoc).

Definition at line 499 of file freia-utils.c.

500 {
501  switch (type)
502  {
503  case spoc_type_sni: return "sni";
504  case spoc_type_oth: return "other";
505  case spoc_type_nop: return "none";
506  case spoc_type_inp: return "input";
507  case spoc_type_poc: return "poc";
508  case spoc_type_alu: return "alu";
509  case spoc_type_mes: return "measure";
510  case spoc_type_thr: return "threshold";
511  case spoc_type_out: return "output";
512  default: return "unexpected value...";
513  }
514 }
@ spoc_type_out
Definition: freia_spoc.h:180
@ spoc_type_oth
Definition: freia_spoc.h:173
@ spoc_type_inp
Definition: freia_spoc.h:175

References spoc_type_alu, spoc_type_inp, spoc_type_mes, spoc_type_nop, spoc_type_oth, spoc_type_out, spoc_type_poc, spoc_type_sni, and spoc_type_thr.

Referenced by basic_spoc_conf(), comment(), dagvtx_dump(), generate_wiring(), print_op_schedule(), and where_to_perform_operation().

+ Here is the caller graph for this function:

◆ what_operation_shape()

string what_operation_shape ( const _int  type)

SPoC: set shape depending on hardware component used by vertex.

Definition at line 518 of file freia-utils.c.

519 {
520  string shape;
521  switch (type)
522  {
523  case spoc_type_oth:
524  shape = "shape=none"; break;
525  case spoc_type_poc:
526  shape = "shape=box"; break;
527  case spoc_type_alu:
528  shape = "shape=trapezium,orientation=270"; break;
529  case spoc_type_thr:
530  shape = "shape=parallelogram"; break;
531  case spoc_type_mes:
532  shape = "shape=diamond"; break;
533  // these should not happen
534  case spoc_type_out:
535  case spoc_type_inp:
536  case spoc_type_nop:
537  default:
538  shape = "shape=circle";
539  }
540  return shape;
541 }

References spoc_type_alu, spoc_type_inp, spoc_type_mes, spoc_type_nop, spoc_type_oth, spoc_type_out, spoc_type_poc, and spoc_type_thr.

Referenced by dagvtx_dot().

+ Here is the caller graph for this function:

Variable Documentation

◆ dep_cache

hash_table dep_cache = NULL
static

Definition at line 907 of file freia-utils.c.

Referenced by freia_close_dep_cache(), freia_init_dep_cache(), and freia_scalar_rw_dep().

◆ FREIA_AIPO_API

const freia_api_t FREIA_AIPO_API[]
static

!!! there are some underlying assumptions when using this structure: only one of ALU/POC/MES is used per AIPO.

only the first of two POC or MES is used per AIPO. ??? conversions between 8/16 bits images are definitely not handled here.

Definition at line 99 of file freia-utils.c.

Referenced by get_freia_api(), hwac_freia_api(), and hwac_freia_api_index().