PIPS
openmp_generation.c File Reference
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include "boolean.h"
#include <stdbool.h>
#include "genC.h"
#include "linear.h"
#include "ri.h"
#include "effects.h"
#include "database.h"
#include "misc.h"
#include "text.h"
#include "text-util.h"
#include "ri-util.h"
#include "effects-util.h"
#include "accel-util.h"
#include "effects-generic.h"
#include "effects-simple.h"
#include "pipsdbm.h"
#include "resources.h"
#include "control.h"
#include "conversion.h"
#include "properties.h"
#include "transformations.h"
#include "effects-convex.h"
#include "complexity_ri.h"
#include "dg.h"
#include "graph.h"
#include "ricedg.h"
#include "chains.h"
#include "task_parallelization.h"
+ Include dependency graph for openmp_generation.c:

Go to the source code of this file.

Typedefs

typedef dg_arc_label arc_label
 Instantiation of the dependence graph: More...
 
typedef dg_vertex_label vertex_label
 

Functions

static void gen_omp_taskwait (statement stmt)
 
static void gen_omp_parallel (statement stmt)
 
static bool gen_synchronization (statement stmt, bool nested_p, int length)
 
static bool gen_openmp (statement stmt, bool nested_p)
 
bool openmp_task_generation (char *module_name)
 OpenMP generation pass. More...
 

Variables

static bool omp_parallel = false
 

Typedef Documentation

◆ arc_label

Instantiation of the dependence graph:

Definition at line 41 of file openmp_generation.c.

◆ vertex_label

Definition at line 42 of file openmp_generation.c.

Function Documentation

◆ gen_omp_parallel()

static void gen_omp_parallel ( statement  stmt)
static

Definition at line 61 of file openmp_generation.c.

61  {
62  string data = strdup(concatenate( "omp parallel default(shared) ",NULL));
64  list stmts = sequence_statements(statement_sequence(stmt)), body = NIL, decls = NIL;
66  FOREACH(STATEMENT, st, stmts){
68  decls = CONS(STATEMENT, st, decls);
69  else
70  if(!return_statement_p(st))
71  body = CONS(STATEMENT, st, body);
72  else
73  return_st = st;
74  }
75  if(gen_length(body)>0){
76  st_body = make_block_statement(gen_nreverse(body));
77  add_pragma_str_to_statement (st_body, data, true);
78  decls = CONS(STATEMENT, st_body, decls);
79  }
80  if(gen_length(decls)>0){
82  }
83  }
84  else
86  return;
87 }
statement return_st
Definition: HBDSC.c:53
instruction make_instruction_sequence(sequence _field_)
Definition: ri.c:1169
sequence make_sequence(list a)
Definition: ri.c:2125
statement make_block_statement(list)
Make a block statement from a list of statement.
Definition: statement.c:616
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
size_t gen_length(const list l)
Definition: list.c:150
#define CONS(_t_, _i_, _l_)
List element cell constructor (insert an element at the beginning of a list)
Definition: newgen_list.h:150
#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
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
bool return_statement_p(statement)
Test if a statement is a C or Fortran "return".
Definition: statement.c:172
bool declaration_statement_p(statement)
Had to be optimized according to Beatrice Creusillet.
Definition: statement.c:224
string concatenate(const char *,...)
Return the concatenation of the given strings.
Definition: string.c:183
void add_pragma_str_to_statement(statement st, const char *s, bool copy_flag)
Add a string as a pragma to a statement.
Definition: pragma.c:425
#define sequence_statements(x)
Definition: ri.h:2360
#define statement_instruction(x)
Definition: ri.h:2458
#define statement_undefined
Definition: ri.h:2419
#define STATEMENT(x)
STATEMENT.
Definition: ri.h:2413
char * strdup()
The structure used to build lists in NewGen.
Definition: newgen_list.h:41
Definition: statement.c:54

References add_pragma_str_to_statement(), concatenate(), CONS, declaration_statement_p(), FOREACH, gen_length(), gen_nreverse(), make_block_statement(), make_instruction_sequence(), make_sequence(), NIL, return_st, return_statement_p(), sequence_statements, STATEMENT, statement_instruction, statement_sequence(), statement_sequence_p(), statement_undefined, and strdup().

Referenced by openmp_task_generation().

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

◆ gen_omp_taskwait()

static void gen_omp_taskwait ( statement  stmt)
static

Definition at line 51 of file openmp_generation.c.

52 {
54  string data = strdup(concatenate( "omp taskwait ",NULL));
57  list list_stmts = CONS(STATEMENT, st, CONS(STATEMENT, copy_statement(stmt), NIL));
59  return;
60 }
statement copy_statement(statement p)
STATEMENT.
Definition: ri.c:2186
synchronization make_synchronization_none(void)
Definition: ri.c:2424
statement make_continue_statement(entity)
Definition: statement.c:953
entity entity_empty_label(void)
Definition: entity.c:1105
#define statement_synchronization(x)
Definition: ri.h:2466

References add_pragma_str_to_statement(), concatenate(), CONS, copy_statement(), entity_empty_label(), gen_nreverse(), make_continue_statement(), make_instruction_sequence(), make_sequence(), make_synchronization_none(), NIL, STATEMENT, statement_instruction, statement_synchronization, and strdup().

Referenced by gen_synchronization().

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

◆ gen_openmp()

static bool gen_openmp ( statement  stmt,
bool  nested_p 
)
static

Definition at line 119 of file openmp_generation.c.

119  {
121  switch(instruction_tag(inst))
122  {
124  {
125  MAPL(stmt_ptr,
126  {
127  statement st = STATEMENT(CAR( stmt_ptr));
128  bool nested_p_local = gen_synchronization(st,nested_p, gen_length(sequence_statements(statement_sequence(stmt))));
129  gen_openmp(st, nested_p_local);
130  },
131  instruction_block(inst));
132  break;
133  }
134  case is_instruction_test :
135  {
136  test t = instruction_test(inst);
137  bool nested_p_t = gen_synchronization(test_true(t),nested_p,1);
138  bool nested_p_f = gen_synchronization(test_false(t),nested_p,1);
139  gen_openmp(test_true(t), nested_p_t);
140  gen_openmp(test_false(t), nested_p_f);
141  break;
142  }
143  case is_instruction_loop :
144  {
145  loop l = statement_loop(stmt);
146  statement body = loop_body(l);
147  nested_p = gen_synchronization(body,nested_p,1);
148  gen_openmp(body, nested_p);
149  break;
150  }
151  default:
152  break;
153  }
154  return true;
155 }
#define CAR(pcons)
Get the value of the first element of a list.
Definition: newgen_list.h:92
#define MAPL(_map_list_cp, _code, _l)
Apply some code on the addresses of all the elements of a list.
Definition: newgen_list.h:203
loop statement_loop(statement)
Get the loop of a statement.
Definition: statement.c:1374
static bool gen_openmp(statement stmt, bool nested_p)
static bool gen_synchronization(statement stmt, bool nested_p, int length)
#define is_instruction_block
soft block->sequence transition
#define instruction_block(i)
#define loop_body(x)
Definition: ri.h:1644
#define test_false(x)
Definition: ri.h:2837
@ is_instruction_test
Definition: ri.h:1470
@ is_instruction_loop
Definition: ri.h:1471
#define instruction_tag(x)
Definition: ri.h:1511
#define test_true(x)
Definition: ri.h:2835
#define instruction_test(x)
Definition: ri.h:1517

References CAR, gen_length(), gen_synchronization(), instruction_block, instruction_tag, instruction_test, is_instruction_block, is_instruction_loop, is_instruction_test, loop_body, MAPL, sequence_statements, STATEMENT, statement_instruction, statement_loop(), statement_sequence(), test_false, and test_true.

Referenced by openmp_task_generation().

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

◆ gen_synchronization()

static bool gen_synchronization ( statement  stmt,
bool  nested_p,
int  length 
)
static

Definition at line 89 of file openmp_generation.c.

90 {
92  switch(synchronization_tag(sync)){
94  if(length>1){
95  add_pragma_str_to_statement(stmt, "omp task", true);
96  if(!omp_parallel)
97  omp_parallel = true;
98  }
99  break;
101  if(!nested_p){
102  add_pragma_str_to_statement(stmt, "omp single", true);
103  nested_p = true;
104  }
105  else
106  {
109  }
110  if(!omp_parallel)
111  omp_parallel = true;
112  break;
113  default:
114  break;
115  }
116  return nested_p;
117 }
static bool omp_parallel
static void gen_omp_taskwait(statement stmt)
@ is_synchronization_barrier
Definition: ri.h:2626
@ is_synchronization_spawn
Definition: ri.h:2625
#define synchronization_tag(x)
Definition: ri.h:2651

References add_pragma_str_to_statement(), gen_length(), gen_omp_taskwait(), is_synchronization_barrier, is_synchronization_spawn, omp_parallel, sequence_statements, statement_sequence(), statement_synchronization, and synchronization_tag.

Referenced by gen_openmp().

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

◆ openmp_task_generation()

bool openmp_task_generation ( char *  module_name)

OpenMP generation pass.

openmp_generation.c

Parameters
module_nameodule_name

Definition at line 160 of file openmp_generation.c.

161 {
162  statement module_stat_i = (statement)db_get_memory_resource(DBR_SHARED_SPIRE_CODE, module_name, true);
163  statement module_stat = copy_statement(module_stat_i);
164  set_ordering_to_statement(module_stat);
166  set_current_module_statement(module_stat);
167  gen_openmp(module_stat, false);
168  if(omp_parallel)
169  gen_omp_parallel(module_stat);
171  insert_statement(module_stat, return_st, false);
172  module_reorder(module_stat);
173  DB_PUT_MEMORY_RESOURCE(DBR_PARALLELIZED_CODE, module_name, module_stat);
177  return true;
178 }
struct _newgen_struct_statement_ * statement
Definition: cloning.h:21
const char * module_name(const char *s)
Return the module part of an entity name.
Definition: entity_names.c:296
void reset_current_module_entity(void)
Reset the current module entity.
Definition: static.c:97
void reset_current_module_statement(void)
Reset the current module statement.
Definition: static.c:221
statement set_current_module_statement(statement)
Set the current module statement.
Definition: static.c:165
entity set_current_module_entity(entity)
static.c
Definition: static.c:66
string db_get_memory_resource(const char *rname, const char *oname, bool pure)
Return the pointer to the resource, whatever it is.
Definition: database.c:755
#define DB_PUT_MEMORY_RESOURCE(res_name, own_name, res_val)
conform to old interface.
Definition: pipsdbm-local.h:66
void insert_statement(statement, statement, bool)
This is the normal entry point.
Definition: statement.c:2570
static void gen_omp_parallel(statement stmt)
hash_table set_ordering_to_statement(statement s)
To be used instead of initialize_ordering_to_statement() to make sure that the hash table ots is in s...
Definition: ordering.c:172
void reset_ordering_to_statement(void)
Reset the mapping from ordering to statement.
Definition: ordering.c:185
bool module_reorder(statement body)
Reorder a module and recompute order to statement if any.
Definition: reorder.c:244
entity module_name_to_entity(const char *mn)
This is an alias for local_name_to_top_level_entity.
Definition: entity.c:1479
#define statement_undefined_p(x)
Definition: ri.h:2420

References copy_statement(), db_get_memory_resource(), DB_PUT_MEMORY_RESOURCE, gen_omp_parallel(), gen_openmp(), insert_statement(), module_name(), module_name_to_entity(), module_reorder(), omp_parallel, reset_current_module_entity(), reset_current_module_statement(), reset_ordering_to_statement(), return_st, set_current_module_entity(), set_current_module_statement(), set_ordering_to_statement(), and statement_undefined_p.

+ Here is the call graph for this function:

Variable Documentation

◆ omp_parallel

bool omp_parallel = false
static

Definition at line 48 of file openmp_generation.c.

Referenced by gen_synchronization(), and openmp_task_generation().