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

Go to the source code of this file.

Functions

entity find_label_entity (const char *module_name, const char *label_local_name)
 Pot-pourri of utilities for the internal representation. More...
 
string module_codefilename (entity e)
 To find resources (this should be located in workspace-util as it depends both on pipsdbm and ri-util. More...
 
string module_par_codefilename (entity e)
 
string module_fortranfilename (entity e)
 
string module_par_fortranfilename (entity e)
 
string module_pp_fortranfilename (entity e)
 
string module_predicat_fortranfilename (entity e)
 
string module_entitiesfilename (entity e)
 
entity find_ith_parameter (entity e, int i)
 
bool ith_parameter_p (entity f, entity v, int i)
 returns true if v is the ith formal parameter of function f More...
 
expression reference_ith_index (reference ref, int i)
 functions for references More...
 
bool comment_string_p (const string comment)
 Test if a string can be a Fortran 77 comment: More...
 
string string_remove_trailing_line_feed (string s)
 Remove trailing line feed if any. More...
 
string string_remove_trailing_line_feeds (string s)
 Remove trailing line feeds. More...
 
string string_strip_final_linefeeds (string s)
 Get rid of linefeed/newline at the end of a string. More...
 
string string_fuse_final_linefeeds (string s)
 Get rid of extra linefeed/newline at the end of a string. More...
 

Function Documentation

◆ comment_string_p()

bool comment_string_p ( const string  comment)

Test if a string can be a Fortran 77 comment:

If a line begins with a non-space character, claims it may be a Fortran comment. Assume empty line are comments.

Parameters
commentomment

Definition at line 159 of file util.c.

160 {
161  char c = *comment;
162  /* If a line begins with a non-space character, claims it may be a
163  Fortran comment. Assume empty line are comments. */
164  return c != '\0' && c != ' ' && c != '\t';
165 }
static void comment(string_buffer code, spoc_hardware_type hw, dagvtx v, int stage, int side, bool flip)
Definition: freia_spoc.c:52

References comment().

Referenced by get_declaration_comments(), and get_end_of_header_comments().

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

◆ find_ith_parameter()

entity find_ith_parameter ( entity  e,
int  i 
)

Definition at line 93 of file util.c.

94 {
96 
97  if (! entity_module_p(e)) {
98  pips_internal_error("entity %s is not a module",
99  entity_name(e));
100  }
101  while (pv != NIL) {
102  entity v = ENTITY(CAR(pv));
103  type tv = entity_type(v);
104  storage sv = entity_storage(v);
105  // FI: locations.c should be part of ri-util or a large entity library
106  value val = entity_initial(v); // To check location entities
107 
108  // FI: the initial value of formal parameters may be value_undefined...
109  // See Semantics-New/block01.c, formal parameter i of multiply
110  if (type_variable_p(tv)
111  && storage_formal_p(sv)
112  && (value_undefined_p(val) || !value_reference_p(val))) {
113  if (formal_offset(storage_formal(sv)) == i) {
114  return(v);
115  }
116  }
117 
118  pv = CDR(pv);
119  }
120 
121  return(entity_undefined);
122 }
#define NIL
The empty list (nil in Lisp)
Definition: newgen_list.h:47
#define CAR(pcons)
Get the value of the first element of a list.
Definition: newgen_list.h:92
#define CDR(pcons)
Get the list less its first element.
Definition: newgen_list.h:111
#define pips_internal_error
Definition: misc-local.h:149
bool entity_module_p(entity e)
Definition: entity.c:683
#define formal_offset(x)
Definition: ri.h:1408
#define value_undefined_p(x)
Definition: ri.h:3017
#define storage_formal_p(x)
Definition: ri.h:2522
#define ENTITY(x)
ENTITY.
Definition: ri.h:2755
#define entity_storage(x)
Definition: ri.h:2794
#define code_declarations(x)
Definition: ri.h:784
#define storage_formal(x)
Definition: ri.h:2524
#define entity_undefined
Definition: ri.h:2761
#define entity_name(x)
Definition: ri.h:2790
#define value_code(x)
Definition: ri.h:3067
#define value_reference_p(x)
Definition: ri.h:3083
#define entity_type(x)
Definition: ri.h:2792
#define type_variable_p(x)
Definition: ri.h:2947
#define entity_initial(x)
Definition: ri.h:2796
The structure used to build lists in NewGen.
Definition: newgen_list.h:41

References CAR, CDR, code_declarations, ENTITY, entity_initial, entity_module_p(), entity_name, entity_storage, entity_type, entity_undefined, formal_offset, NIL, pips_internal_error, storage_formal, storage_formal_p, type_variable_p, value_code, value_reference_p, and value_undefined_p.

Referenced by add_bound_arguments(), any_user_call_site_to_transformer(), compute_points_to_binded_set(), drop_distributed_arguments(), generic_substitute_formal_array_elements_in_transformer(), gpu_xml_dump(), hpfc_call_with_distributed_args_p(), hpfc_translate_call_with_distributed_args(), outliner_file(), RemoveDummyArguments(), update_overlaps_in_caller(), and words_parameters().

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

◆ find_label_entity()

entity find_label_entity ( const char *  module_name,
const char *  label_local_name 
)

Pot-pourri of utilities for the internal representation.

util.c

Some functions could be moved to non-generic files such as entity.c. To deal with labels

Parameters
module_nameodule_name
label_local_nameabel_local_name

Definition at line 43 of file util.c.

44 {
47 
48  pips_debug(5, "searched entity: %s\n", full);
49  void * found = gen_find_tabulated(full, entity_domain);
50  return (entity) (gen_chunk_undefined_p(found) ? entity_undefined : found);
51 }
const char * module_name(const char *s)
Return the module part of an entity name.
Definition: entity_names.c:296
#define gen_chunk_undefined_p(c)
Definition: genC.h:75
#define pips_debug
these macros use the GNU extensions that allow variadic macros, including with an empty list.
Definition: misc-local.h:145
#define LABEL_PREFIX
Definition: naming-local.h:31
#define MODULE_SEP_STRING
Definition: naming-local.h:30
string concatenate(const char *,...)
Return the concatenation of the given strings.
Definition: string.c:183
void * gen_find_tabulated(const char *, int)
Definition: tabulated.c:218
const char * label_local_name(entity e)
END_EOLE.
Definition: entity.c:604
#define entity_domain
newgen_syntax_domain_defined
Definition: ri.h:410
@ full
Definition: union-local.h:65

References concatenate(), entity_domain, entity_undefined, full, gen_chunk_undefined_p, gen_find_tabulated(), label_local_name(), LABEL_PREFIX, module_name(), MODULE_SEP_STRING, and pips_debug.

Referenced by find_statement_from_label_name(), full_unroll(), get_loop_execution_parallel(), inlining_regenerate_labels(), interactive_loop_transformation(), kernelize(), label_string_defined_in_current_module_p(), label_string_defined_in_statement_p(), loop_auto_unroll(), loop_expansion(), loop_expansion_init(), loop_pragma(), module_loops(), print_loopnest_dependence_cone(), set_loop_execution_parallel(), simdizer_auto_tile(), strip_mine(), symbolic_tiling(), unroll(), and words_regular_call().

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

◆ ith_parameter_p()

bool ith_parameter_p ( entity  f,
entity  v,
int  i 
)

returns true if v is the ith formal parameter of function f

Definition at line 125 of file util.c.

126 {
127  type tv = entity_type(v);
128  storage sv = entity_storage(v);
129 
130  if (! entity_module_p(f)) {
131  pips_internal_error("[ith_parameter_p] %s is not a module\n", entity_name(f));
132  }
133 
134  if (type_variable_p(tv) && storage_formal_p(sv)) {
135  formal fv = storage_formal(sv);
136  return(formal_function(fv) == f && formal_offset(fv) == i);
137  }
138 
139  return(false);
140 }
int f(int off1, int off2, int n, float r[n], float a[n], float b[n])
Definition: offsets.c:15
#define formal_function(x)
Definition: ri.h:1406

References entity_module_p(), entity_name, entity_storage, entity_type, f(), formal_function, formal_offset, pips_internal_error, storage_formal, storage_formal_p, and type_variable_p.

Referenced by add_parameter_aliases_for_this_call_site(), and formal_regions_backward_translation().

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

◆ module_codefilename()

string module_codefilename ( entity  e)

To find resources (this should be located in workspace-util as it depends both on pipsdbm and ri-util.

Definition at line 57 of file util.c.

58 {
60 }
string string_codefilename(const char *s)
Naming of files in the PIPS database.
Definition: file_names.c:37
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 entity_local_name(), and string_codefilename().

+ Here is the call graph for this function:

◆ module_entitiesfilename()

string module_entitiesfilename ( entity  e)

Definition at line 87 of file util.c.

88 {
90 }
string string_entitiesfilename(const char *s)
Definition: file_names.c:87

References entity_local_name(), and string_entitiesfilename().

+ Here is the call graph for this function:

◆ module_fortranfilename()

string module_fortranfilename ( entity  e)

Definition at line 67 of file util.c.

68 {
70 }
string string_fortranfilename(const char *s)
Definition: file_names.c:49

References entity_local_name(), and string_fortranfilename().

+ Here is the call graph for this function:

◆ module_par_codefilename()

string module_par_codefilename ( entity  e)

Definition at line 62 of file util.c.

63 {
65 }
string string_par_codefilename(const char *s)
Definition: file_names.c:43

References entity_local_name(), and string_par_codefilename().

+ Here is the call graph for this function:

◆ module_par_fortranfilename()

string module_par_fortranfilename ( entity  e)

Definition at line 72 of file util.c.

73 {
75 }
string string_par_fortranfilename(const char *s)
Definition: file_names.c:69

References entity_local_name(), and string_par_fortranfilename().

+ Here is the call graph for this function:

◆ module_pp_fortranfilename()

string module_pp_fortranfilename ( entity  e)

Definition at line 77 of file util.c.

78 {
80 }
string string_pp_fortranfilename(const char *s)
Definition: file_names.c:75

References entity_local_name(), and string_pp_fortranfilename().

+ Here is the call graph for this function:

◆ module_predicat_fortranfilename()

string module_predicat_fortranfilename ( entity  e)

Definition at line 82 of file util.c.

83 {
85 }
string string_predicat_fortranfilename(const char *s)
Definition: file_names.c:81

References entity_local_name(), and string_predicat_fortranfilename().

+ Here is the call graph for this function:

◆ reference_ith_index()

expression reference_ith_index ( reference  ref,
int  i 
)

functions for references

returns the ith index of an array reference

Parameters
refef

Definition at line 145 of file util.c.

146 {
147  int count = i;
148  cons *pi = reference_indices(ref);
149 
150  while (pi != NIL && --count > 0)
151  pi = CDR(pi);
152 
153  pips_assert("reference_ith_index", pi != NIL);
154 
155  return(EXPRESSION(CAR(pi)));
156 }
static int count
Definition: SDG.c:519
static reference ref
Current stmt (an integer)
Definition: adg_read_paf.c:163
#define pips_assert(what, predicate)
common macros, two flavors depending on NDEBUG
Definition: misc-local.h:172
#define EXPRESSION(x)
EXPRESSION.
Definition: ri.h:1217
#define reference_indices(x)
Definition: ri.h:2328

References CAR, CDR, count, EXPRESSION, NIL, pips_assert, ref, and reference_indices.

◆ string_fuse_final_linefeeds()

string string_fuse_final_linefeeds ( string  s)

Get rid of extra linefeed/newline at the end of a string.

This is sometimes useful to cleanup comments messed up by the lexical analyzer.

Warning: the argument s is updated if it ends up with LF

Definition at line 227 of file util.c.

228 {
229  int l = strlen(s)-1;
230 
231  while(l>=1 && *(s+l)=='\n' && *(s+l-1)=='\n') {
232  *(s+l) = '\000';
233  l--;
234  }
235 
236  return s;
237 }

◆ string_remove_trailing_line_feed()

string string_remove_trailing_line_feed ( string  s)

Remove trailing line feed if any.

Definition at line 169 of file util.c.

170 {
171  int sl = strlen(s);
172  if(sl>0) {
173  string ntl = s+sl-1;
174  if(sl>0 && *ntl=='\n') {
175  *ntl='\000';
176  }
177  }
178  return s;
179 }

◆ string_remove_trailing_line_feeds()

string string_remove_trailing_line_feeds ( string  s)

Remove trailing line feeds.

This function has been implemented three times. See below string_strip_final_linefeeds() and string_fuse_final_linefeeds().

Definition at line 186 of file util.c.

187 {
188  int sl = strlen(s);
189  if(sl>0) {
190  string ntl = s+sl-1;
191  while(sl>0 && *ntl=='\n') {
192  *ntl='\000';
193  ntl--;
194  sl--;
195  }
196  }
197  return s;
198 }

◆ string_strip_final_linefeeds()

string string_strip_final_linefeeds ( string  s)

Get rid of linefeed/newline at the end of a string.

This is sometimes useful to cleanup comments messed up by the lexical analyzer.

Warning: the argument s is updated if it ends up with LF

Definition at line 208 of file util.c.

209 {
210  int l = strlen(s)-1;
211 
212  while(l>=0 && *(s+l)=='\n') {
213  *(s+l) = '\000';
214  l--;
215  }
216 
217  return s;
218 }