OpenScop  0.9.1
scop.c
Go to the documentation of this file.
1 
2  /*+-----------------------------------------------------------------**
3  ** OpenScop Library **
4  **-----------------------------------------------------------------**
5  ** scop.c **
6  **-----------------------------------------------------------------**
7  ** First version: 30/04/2008 **
8  **-----------------------------------------------------------------**
9 
10 
11  *****************************************************************************
12  * OpenScop: Structures and formats for polyhedral tools to talk together *
13  *****************************************************************************
14  * ,___,,_,__,,__,,__,,__,,_,__,,_,__,,__,,___,_,__,,_,__, *
15  * / / / // // // // / / / // // / / // / /|,_, *
16  * / / / // // // // / / / // // / / // / / / /\ *
17  * |~~~|~|~~~|~~~|~~~|~~~|~|~~~|~|~~~|~~~|~~~|~|~~~|~|~~~|/_/ \ *
18  * | G |C| P | = | L | P |=| = |C| = | = | = |=| = |=| C |\ \ /\ *
19  * | R |l| o | = | e | l |=| = |a| = | = | = |=| = |=| L | \# \ /\ *
20  * | A |a| l | = | t | u |=| = |n| = | = | = |=| = |=| o | |\# \ \ *
21  * | P |n| l | = | s | t |=| = |d| = | = | = | | |=| o | | \# \ \ *
22  * | H | | y | | e | o | | = |l| | | = | | | | G | | \ \ \ *
23  * | I | | | | e | | | | | | | | | | | | | \ \ \ *
24  * | T | | | | | | | | | | | | | | | | | \ \ \ *
25  * | E | | | | | | | | | | | | | | | | | \ \ \ *
26  * | * |*| * | * | * | * |*| * |*| * | * | * |*| * |*| * | / \* \ \ *
27  * | O |p| e | n | S | c |o| p |-| L | i | b |r| a |r| y |/ \ \ / *
28  * '---'-'---'---'---'---'-'---'-'---'---'---'-'---'-'---' '--' *
29  * *
30  * Copyright (C) 2008 University Paris-Sud 11 and INRIA *
31  * *
32  * (3-clause BSD license) *
33  * Redistribution and use in source and binary forms, with or without *
34  * modification, are permitted provided that the following conditions *
35  * are met: *
36  * *
37  * 1. Redistributions of source code must retain the above copyright notice, *
38  * this list of conditions and the following disclaimer. *
39  * 2. Redistributions in binary form must reproduce the above copyright *
40  * notice, this list of conditions and the following disclaimer in the *
41  * documentation and/or other materials provided with the distribution. *
42  * 3. The name of the author may not be used to endorse or promote products *
43  * derived from this software without specific prior written permission. *
44  * *
45  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR *
46  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES *
47  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. *
48  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, *
49  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT *
50  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, *
51  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY *
52  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
53  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF *
54  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
55  * *
56  * OpenScop Library, a library to manipulate OpenScop formats and data *
57  * structures. Written by: *
58  * Cedric Bastoul <Cedric.Bastoul@u-psud.fr> and *
59  * Louis-Noel Pouchet <Louis-Noel.pouchet@inria.fr> *
60  * *
61  *****************************************************************************/
62 
63 # include <stdlib.h>
64 # include <stdio.h>
65 # include <ctype.h>
66 # include <string.h>
67 
68 #include <osl/macros.h>
69 #include <osl/util.h>
70 #include <osl/extensions/arrays.h>
71 #include <osl/extensions/textual.h>
72 #include <osl/strings.h>
73 #include <osl/relation.h>
74 #include <osl/interface.h>
75 #include <osl/generic.h>
76 #include <osl/statement.h>
77 #include <osl/scop.h>
78 
79 
80 /*+***************************************************************************
81  * Structure display functions *
82  *****************************************************************************/
83 
84 
95 void osl_scop_idump(FILE * file, osl_scop_p scop, int level) {
96  int j, first = 1;
97 
98  // Go to the right level.
99  for (j = 0; j < level; j++)
100  fprintf(file, "|\t");
101 
102  if (scop != NULL)
103  fprintf(file, "+-- osl_scop_t\n");
104  else
105  fprintf(file, "+-- NULL scop\n");
106 
107  while (scop != NULL) {
108  if (!first) {
109  // Go to the right level.
110  for (j = 0; j < level; j++)
111  fprintf(file, "|\t");
112  fprintf(file, "| osl_scop_t\n");
113  }
114  else
115  first = 0;
116 
117  // A blank line.
118  for (j = 0; j <= level+1; j++)
119  fprintf(file, "|\t");
120  fprintf(file, "\n");
121 
122  // Print the version.
123  for (j = 0; j < level; j++)
124  fprintf(file, "|\t");
125  fprintf(file, "|\tVersion: %d\n", scop->version);
126 
127  // A blank line.
128  for (j = 0; j <= level+1; j++)
129  fprintf(file, "|\t");
130  fprintf(file, "\n");
131 
132  // Print the language.
133  for (j = 0; j < level; j++)
134  fprintf(file, "|\t");
135  fprintf(file, "|\tLanguage: %s\n", scop->language);
136 
137  // A blank line.
138  for (j = 0; j <= level+1; j++)
139  fprintf(file, "|\t");
140  fprintf(file, "\n");
141 
142  // Print the context of the scop.
143  osl_relation_idump(file, scop->context, level+1);
144 
145  // Print the parameters.
146  osl_generic_idump(file, scop->parameters, level+1);
147 
148  // Print the statements.
149  osl_statement_idump(file, scop->statement, level+1);
150 
151  // Print the registered extension interfaces.
152  osl_interface_idump(file, scop->registry, level+1);
153 
154  // Print the extensions.
155  osl_generic_idump(file, scop->extension, level+1);
156 
157  scop = scop->next;
158 
159  // Next line.
160  if (scop != NULL) {
161  for (j = 0; j <= level; j++)
162  fprintf(file, "|\t");
163  fprintf(file, "V\n");
164  }
165  }
166 
167  // The last line.
168  for (j = 0; j <= level; j++)
169  fprintf(file, "|\t");
170  fprintf(file, "\n");
171 }
172 
173 
181 void osl_scop_dump(FILE * file, osl_scop_p scop) {
182  osl_scop_idump(file, scop, 0);
183 }
184 
185 
193 osl_names_p osl_scop_names(osl_scop_p scop) {
194  int nb_parameters = OSL_UNDEFINED;
195  int nb_iterators = OSL_UNDEFINED;
196  int nb_scattdims = OSL_UNDEFINED;
197  int nb_localdims = OSL_UNDEFINED;
198  int array_id = OSL_UNDEFINED;
199 
200  osl_scop_get_attributes(scop, &nb_parameters, &nb_iterators,
201  &nb_scattdims, &nb_localdims, &array_id);
202 
203  return osl_names_generate("P", nb_parameters,
204  "i", nb_iterators,
205  "c", nb_scattdims,
206  "l", nb_localdims,
207  "A", array_id);
208 }
209 
210 
218 void osl_scop_print(FILE * file, osl_scop_p scop) {
219  int parameters_backedup = 0;
220  int arrays_backedup = 0;
221  osl_strings_p parameters_backup = NULL;
222  osl_strings_p arrays_backup = NULL;
224  osl_arrays_p arrays;
225 
226  if (scop == NULL) {
227  fprintf(file, "# NULL scop\n");
228  return;
229  }
230  else {
231  fprintf(file, "# [File generated by the OpenScop Library %s]\n",
232  OSL_RELEASE);
233  }
234 
235  if (osl_scop_integrity_check(scop) == 0)
236  OSL_warning("OpenScop integrity check failed. Something may go wrong.");
237 
238  // Generate the names for the various dimensions.
239  names = osl_scop_names(scop);
240 
241  while (scop != NULL) {
242  // If possible, replace parameter names with scop parameter names.
243  if (osl_generic_has_URI(scop->parameters, OSL_URI_STRINGS)) {
244  parameters_backedup = 1;
245  parameters_backup = names->parameters;
246  names->parameters = scop->parameters->data;
247  }
248 
249  // If possible, replace array names with arrays extension names.
250  arrays = osl_generic_lookup(scop->extension, OSL_URI_ARRAYS);
251  if (arrays != NULL) {
252  arrays_backedup = 1;
253  arrays_backup = names->arrays;
254  names->arrays = osl_arrays_to_strings(arrays);
255  }
256 
257  fprintf(file, "\n<"OSL_URI_SCOP">\n\n");
258  fprintf(file, "# =============================================== "
259  "Global\n");
260  fprintf(file, "# Language\n");
261  fprintf(file, "%s\n\n", scop->language);
262 
263  fprintf(file, "# Context\n");
264  osl_relation_pprint(file, scop->context, names);
265  fprintf(file, "\n");
266 
268  osl_generic_has_URI(scop->parameters, OSL_URI_STRINGS),
269  "Parameters are");
270  osl_generic_print(file, scop->parameters);
271 
272  fprintf(file, "\n# Number of statements\n");
273  fprintf(file, "%d\n\n",osl_statement_number(scop->statement));
274 
275  osl_statement_pprint(file, scop->statement, names);
276 
277  if (scop->extension) {
278  fprintf(file, "# =============================================== "
279  "Extensions\n");
280  osl_generic_print(file, scop->extension);
281  }
282  fprintf(file, "\n</"OSL_URI_SCOP">\n\n");
283 
284  // If necessary, switch back parameter names.
285  if (parameters_backedup) {
286  parameters_backedup = 0;
287  names->parameters = parameters_backup;
288  }
289 
290  // If necessary, switch back array names.
291  if (arrays_backedup) {
292  arrays_backedup = 0;
293  osl_strings_free(names->arrays);
294  names->arrays = arrays_backup;
295  }
296 
297  scop = scop->next;
298  }
299 
300  osl_names_free(names);
301 }
302 
303 
311 void osl_scop_print_scoplib(FILE * file, osl_scop_p scop) {
312  int parameters_backedup = 0;
313  int arrays_backedup = 0;
314  osl_strings_p parameters_backup = NULL;
315  osl_strings_p arrays_backup = NULL;
317  osl_arrays_p arrays;
318 
319  if (scop == NULL) {
320  fprintf(file, "# NULL scop\n");
321  return;
322  }
323  else {
324  fprintf(file, "# [File generated by the OpenScop Library %s]\n"
325  "# [SCoPLib format]\n",
326  OSL_RELEASE);
327  }
328 
329  if (osl_scop_check_compatible_scoplib(scop) == 0) {
330  OSL_error("SCoP integrity check failed. Something may go wrong.");
331  exit(1);
332  }
333 
334  // Generate the names for the various dimensions.
335  names = osl_scop_names(scop);
336 
337  while (scop != NULL) {
338  // If possible, replace parameter names with scop parameter names.
339  if (osl_generic_has_URI(scop->parameters, OSL_URI_STRINGS)) {
340  parameters_backedup = 1;
341  parameters_backup = names->parameters;
342  names->parameters = scop->parameters->data;
343  }
344 
345  // If possible, replace array names with arrays extension names.
346  arrays = osl_generic_lookup(scop->extension, OSL_URI_ARRAYS);
347  if (arrays != NULL) {
348  arrays_backedup = 1;
349  arrays_backup = names->arrays;
350  names->arrays = osl_arrays_to_strings(arrays);
351  }
352 
353  fprintf(file, "\nSCoP\n\n");
354  fprintf(file, "# =============================================== "
355  "Global\n");
356  fprintf(file, "# Language\n");
357  fprintf(file, "%s\n\n", scop->language);
358 
359  fprintf(file, "# Context\n");
360 
361  osl_relation_pprint_scoplib(file, scop->context, names, 0, 0);
362  fprintf(file, "\n");
363 
365  osl_generic_has_URI(scop->parameters, OSL_URI_STRINGS),
366  "Parameters are");
367 
368  if (scop->parameters) {
369  fprintf(file, "# Parameter names\n");
370  osl_strings_print(file, scop->parameters->data);
371  }
372 
373  fprintf(file, "\n# Number of statements\n");
374  fprintf(file, "%d\n\n",osl_statement_number(scop->statement));
375 
376  osl_statement_pprint_scoplib(file, scop->statement, names);
377 
378  if (scop->extension) {
379  fprintf(file, "# =============================================== "
380  "Options\n");
381  osl_generic_print_options_scoplib(file, scop->extension);
382  }
383 
384  // If necessary, switch back parameter names.
385  if (parameters_backedup) {
386  parameters_backedup = 0;
387  names->parameters = parameters_backup;
388  }
389 
390  // If necessary, switch back array names.
391  if (arrays_backedup) {
392  arrays_backedup = 0;
393  osl_strings_free(names->arrays);
394  names->arrays = arrays_backup;
395  }
396 
397  scop = scop->next;
398  }
399 
400  osl_names_free(names);
401 }
402 
403 
404 /*****************************************************************************
405  * Reading function *
406  *****************************************************************************/
407 
408 
421 osl_scop_p osl_scop_pread(FILE * file, osl_interface_p registry,
422  int precision) {
423  osl_scop_p list = NULL, current = NULL, scop;
424  osl_statement_p stmt = NULL;
425  osl_statement_p prev = NULL;
426  osl_strings_p language;
427  int nb_statements;
428  char * tmp;
429  int first = 1;
430  int i;
431 
432  if (file == NULL)
433  return NULL;
434 
435  while(1) {
436  //
437  // I. START TAG
438  //
439  tmp = osl_util_read_uptotag(file, NULL, OSL_URI_SCOP);
440  if (tmp == NULL) {
441  OSL_debug("no more scop in the file");
442  break;
443  }
444  else {
445  free(tmp);
446  }
447 
448  scop = osl_scop_malloc();
449  scop->registry = osl_interface_clone(registry);
450 
451  //
452  // II. CONTEXT PART
453  //
454 
455  // Read the language.
456  language = osl_strings_read(file);
457  if (osl_strings_size(language) == 0)
458  OSL_error("no language (backend) specified");
459 
460  if (osl_strings_size(language) > 1)
461  OSL_warning("uninterpreted information (after language)");
462 
463  if (language != NULL) {
464  OSL_strdup(scop->language, language->string[0]);
465  osl_strings_free(language);
466  }
467 
468  // Read the context domain.
469  scop->context = osl_relation_pread(file, precision);
470 
471  // Read the parameters.
472  if (osl_util_read_int(file, NULL) > 0)
473  scop->parameters = osl_generic_read_one(file, scop->registry);
474 
475  //
476  // III. STATEMENT PART
477  //
478 
479  // Read the number of statements.
480  nb_statements = osl_util_read_int(file, NULL);
481 
482  for (i = 0; i < nb_statements; i++) {
483  // Read each statement.
484  stmt = osl_statement_pread(file, scop->registry, precision);
485  if (scop->statement == NULL)
486  scop->statement = stmt;
487  else
488  prev->next = stmt;
489  prev = stmt;
490  }
491 
492  //
493  // IV. EXTENSION PART (TO THE END TAG)
494  //
495 
496  // Read up the end tag (if any), and store extensions.
497  scop->extension = osl_generic_read(file, scop->registry);
498 
499  // Add the new scop to the list.
500  if (first) {
501  list = scop;
502  first = 0;
503  }
504  else {
505  current->next = scop;
506  }
507  current = scop;
508  }
509 
510  if (!osl_scop_integrity_check(list))
511  OSL_warning("scop integrity check failed");
512 
513  return list;
514 }
515 
516 
525 osl_scop_p osl_scop_read(FILE * foo) {
526  int precision = osl_util_get_precision();
528  osl_scop_p scop = osl_scop_pread(foo, registry, precision);
529 
530  osl_interface_free(registry);
531  return scop;
532 }
533 
534 
535 /*+***************************************************************************
536  * Memory allocation/deallocation functions *
537  *****************************************************************************/
538 
539 
547 osl_scop_p osl_scop_malloc(void) {
548  osl_scop_p scop;
549 
550  OSL_malloc(scop, osl_scop_p, sizeof(osl_scop_t));
551  scop->version = 1;
552  scop->language = NULL;
553  scop->context = NULL;
554  scop->parameters = NULL;
555  scop->statement = NULL;
556  scop->registry = NULL;
557  scop->extension = NULL;
558  scop->usr = NULL;
559  scop->next = NULL;
560 
561  return scop;
562 }
563 
564 
570 void osl_scop_free(osl_scop_p scop) {
571  osl_scop_p tmp;
572 
573  while (scop != NULL) {
574  if (scop->language != NULL)
575  free(scop->language);
576  osl_generic_free(scop->parameters);
577  osl_relation_free(scop->context);
578  osl_statement_free(scop->statement);
579  osl_interface_free(scop->registry);
580  osl_generic_free(scop->extension);
581 
582  tmp = scop->next;
583  free(scop);
584  scop = tmp;
585  }
586 }
587 
588 
589 /*+***************************************************************************
590  * Processing functions *
591  *****************************************************************************/
592 
593 
601 void osl_scop_add(osl_scop_p * location, osl_scop_p scop) {
602  while (*location != NULL)
603  location = &((*location)->next);
604 
605  *location = scop;
606 }
607 
608 
616 size_t osl_scop_number(osl_scop_p scop) {
617  size_t number = 0;
618 
619  while (scop != NULL) {
620  number++;
621  scop = scop->next;
622  }
623  return number;
624 }
625 
626 
635 osl_scop_p osl_scop_clone(osl_scop_p scop) {
636  osl_scop_p clone = NULL, node, previous = NULL;
637  int first = 1;
638 
639  while (scop != NULL) {
640  node = osl_scop_malloc();
641  node->version = scop->version;
642  if (scop->language != NULL)
643  OSL_strdup(node->language, scop->language);
644  node->context = osl_relation_clone(scop->context);
645  node->parameters = osl_generic_clone(scop->parameters);
646  node->statement = osl_statement_clone(scop->statement);
647  node->registry = osl_interface_clone(scop->registry);
648  node->extension = osl_generic_clone(scop->extension);
649 
650  if (first) {
651  first = 0;
652  clone = node;
653  previous = node;
654  }
655  else {
656  previous->next = node;
657  previous = previous->next;
658  }
659 
660  scop = scop->next;
661  }
662 
663  return clone;
664 }
665 
673 osl_scop_p osl_scop_remove_unions(osl_scop_p scop) {
674  osl_statement_p statement, new_statement, scop_statement_ptr;
675  osl_scop_p new_scop, scop_ptr, result = NULL;
676 
677  for ( ; scop != NULL; scop = scop->next) {
678  statement = scop->statement;
679  scop_statement_ptr = NULL;
680  new_scop = osl_scop_malloc();
681 
682  for ( ; statement != NULL; statement = statement->next) {
683  new_statement = osl_statement_remove_unions(statement);
684  if (!scop_statement_ptr) {
685  scop_statement_ptr = new_statement;
686  new_scop->statement = scop_statement_ptr;
687  } else {
688  scop_statement_ptr->next = new_statement;
689  scop_statement_ptr = scop_statement_ptr->next;
690  }
691  }
692  while (scop_statement_ptr && scop_statement_ptr->next != NULL)
693  scop_statement_ptr = scop_statement_ptr->next;
694 
695  new_scop->context = osl_relation_clone(scop->context);
696  new_scop->extension = osl_generic_clone(scop->extension);
697  if (scop->language != NULL) {
698  new_scop->language = (char *) malloc(strlen(scop->language) + 1);
699  new_scop->language = strcpy(new_scop->language, scop->language);
700  }
701  new_scop->parameters = osl_generic_clone(scop->parameters);
702  new_scop->registry = osl_interface_clone(scop->registry);
703  new_scop->version = scop->version;
704  if (!result) {
705  result = new_scop;
706  scop_ptr = new_scop;
707  } else {
708  scop_ptr->next = new_scop;
709  scop_ptr = scop_ptr->next;
710  }
711  }
712 
713  return result;
714 }
715 
724 int osl_scop_equal(osl_scop_p s1, osl_scop_p s2) {
725 
726  while ((s1 != NULL) && (s2 != NULL)) {
727  if (s1 == s2)
728  return 1;
729 
730  if (s1->version != s2->version) {
731  OSL_info("versions are not the same");
732  return 0;
733  }
734 
735  if (strcmp(s1->language, s2->language) != 0) {
736  OSL_info("languages are not the same");
737  return 0;
738  }
739 
740  if (!osl_relation_equal(s1->context, s2->context)) {
741  OSL_info("contexts are not the same");
742  return 0;
743  }
744 
745  if (!osl_generic_equal(s1->parameters, s2->parameters)) {
746  OSL_info("parameters are not the same");
747  return 0;
748  }
749 
750  if (!osl_statement_equal(s1->statement, s2->statement)) {
751  OSL_info("statements are not the same");
752  return 0;
753  }
754 
755  if (!osl_interface_equal(s1->registry, s2->registry)) {
756  OSL_info("registries are not the same");
757  return 0;
758  }
759 
760  if (!osl_generic_equal(s1->extension, s2->extension)) {
761  OSL_info("extensions are not the same");
762  return 0;
763  }
764 
765  s1 = s1->next;
766  s2 = s2->next;
767  }
768 
769  if (((s1 == NULL) && (s2 != NULL)) || ((s1 != NULL) && (s2 == NULL)))
770  return 0;
771 
772  return 1;
773 }
774 
775 
783 int osl_scop_integrity_check(osl_scop_p scop) {
784  int expected_nb_parameters;
785 
786 
787  while (scop != NULL) {
788  // Check the language.
789  if ((scop->language != NULL) &&
790  (!strcmp(scop->language, "caml") || !strcmp(scop->language, "Caml") ||
791  !strcmp(scop->language, "ocaml") || !strcmp(scop->language, "OCaml")))
792  fprintf(stderr, "[OpenScop] Alert: What ?! Caml ?! Are you sure ?!?!\n");
793 
794  // Check the context.
795  if (!osl_relation_integrity_check(scop->context,
799  OSL_UNDEFINED))
800  return 0;
801 
802  // Get the number of parameters.
803  if (scop->context != NULL)
804  expected_nb_parameters = scop->context->nb_parameters;
805  else
806  expected_nb_parameters = OSL_UNDEFINED;
807 
808  // TODO : check the number of parameter strings.
809 
810  if (!osl_statement_integrity_check(scop->statement,
811  expected_nb_parameters))
812  return 0;
813 
814  scop = scop->next;
815  }
816 
817  return 1;
818 }
819 
820 
828 int osl_scop_check_compatible_scoplib(osl_scop_p scop) {
829 
830  if (!osl_scop_integrity_check(scop))
831  return 0;
832  if (scop->next != NULL)
833  return 0;
834  if (scop == NULL || scop->statement == NULL)
835  return 1;
836 
837  osl_relation_p domain;
838  osl_statement_p statement;
839  osl_relation_p scattering;
840  int precision = scop->statement->scattering->precision;
841  int i, j;
842 
843  statement = scop->statement;
844  while (statement != NULL) {
845  scattering = statement->scattering;
846 
847  if (scattering->nb_local_dims != 0) {
848  OSL_error("Local dims in scattering matrix");
849  return 0;
850  }
851 
852  domain = statement->domain;
853  while (domain != NULL) {
854  if (domain->nb_local_dims != 0) {
855  OSL_error("Local dims in domain matrix");
856  return 0;
857  }
858  domain = domain->next;
859  }
860 
861  // Check if there is only the -Identity in the output_dims
862  // and the lines MUST be in the right order
863  for (i = 0 ; i < scattering->nb_rows ; i++) {
864  for (j = 0 ; j < scattering->nb_output_dims ; j++) {
865  if (i == j) { // -1
866  if (!osl_int_mone(precision, scattering->m[i][j+1])) {
867  OSL_error("Wrong -Identity");
868  return 0;
869  }
870  } else { // 0
871  if (!osl_int_zero(precision, scattering->m[i][j+1])) {
872  OSL_error("Wrong -Identity");
873  return 0;
874  }
875  }
876  }
877  }
878 
879  statement = statement->next;
880  }
881 
882  return 1;
883 }
884 
885 
892 int osl_scop_get_nb_parameters(osl_scop_p scop) {
893 
894  if (scop->context == NULL) {
895  OSL_debug("no context domain, assuming 0 parameters");
896  return 0;
897  }
898  else {
899  return scop->context->nb_parameters;
900  }
901 }
902 
903 
913 void osl_scop_register_extension(osl_scop_p scop, osl_interface_p interface) {
914  osl_generic_p textual, new;
915  char * extension_string;
916 
917  if ((interface != NULL) && (scop != NULL)) {
918  osl_interface_add(&scop->registry, interface);
919 
920  textual = osl_generic_lookup(scop->extension, interface->URI);
921  if (textual != NULL) {
922  extension_string = ((osl_textual_p)textual->data)->textual;
923  new = osl_generic_sread(&extension_string, interface);
924  osl_generic_add(&scop->extension, new);
925  }
926  }
927 }
928 
929 
948 void osl_scop_get_attributes(osl_scop_p scop,
949  int * nb_parameters,
950  int * nb_iterators,
951  int * nb_scattdims,
952  int * nb_localdims,
953  int * array_id) {
954  int local_nb_parameters = OSL_UNDEFINED;
955  int local_nb_iterators = OSL_UNDEFINED;
956  int local_nb_scattdims = OSL_UNDEFINED;
957  int local_nb_localdims = OSL_UNDEFINED;
958  int local_array_id = OSL_UNDEFINED;
959 
960  while (scop != NULL) {
961  osl_relation_get_attributes(scop->context,
962  &local_nb_parameters,
963  &local_nb_iterators,
964  &local_nb_scattdims,
965  &local_nb_localdims,
966  &local_array_id);
967 
968  osl_statement_get_attributes(scop->statement,
969  &local_nb_parameters,
970  &local_nb_iterators,
971  &local_nb_scattdims,
972  &local_nb_localdims,
973  &local_array_id);
974  // Update.
975  *nb_parameters = OSL_max(*nb_parameters, local_nb_parameters);
976  *nb_iterators = OSL_max(*nb_iterators, local_nb_iterators);
977  *nb_scattdims = OSL_max(*nb_scattdims, local_nb_scattdims);
978  *nb_localdims = OSL_max(*nb_localdims, local_nb_localdims);
979  *array_id = OSL_max(*array_id, local_array_id);
980  scop = scop->next;
981  }
982 }
983 
984 
992 void osl_scop_normalize_scattering(osl_scop_p scop) {
993  int max_scattering_dims = 0;
994  osl_statement_p statement;
995  osl_relation_p extended;
996 
997  if ((scop != NULL) && (scop->statement != NULL)) {
998  // Get the max number of scattering dimensions.
999  statement = scop->statement;
1000  while (statement != NULL) {
1001  if (statement->scattering != NULL) {
1002  max_scattering_dims = OSL_max(max_scattering_dims,
1003  statement->scattering->nb_output_dims);
1004  }
1005  statement = statement->next;
1006  }
1007 
1008  // Normalize.
1009  statement = scop->statement;
1010  while (statement != NULL) {
1011  if (statement->scattering != NULL) {
1012  extended = osl_relation_extend_output(statement->scattering,
1013  max_scattering_dims);
1014  osl_relation_free(statement->scattering);
1015  statement->scattering = extended;
1016  }
1017  statement = statement->next;
1018  }
1019  }
1020 }
1021 
size_t osl_scop_number(osl_scop_p scop)
Definition: scop.c:616
char * URI
Definition: interface.h:90
#define OSL_error(msg)
Definition: macros.h:149
osl_interface_p osl_interface_clone(osl_interface_p interface)
Definition: interface.c:314
osl_scop_p osl_scop_malloc(void)
Definition: scop.c:547
#define OSL_warning(msg)
Definition: macros.h:144
int osl_util_read_int(FILE *file, char **str)
Definition: util.c:140
void * osl_generic_lookup(osl_generic_p x, char const *const URI)
Definition: generic.c:687
void * data
Definition: generic.h:82
void osl_scop_register_extension(osl_scop_p scop, osl_interface_p interface)
Definition: scop.c:913
osl_relation_p osl_relation_extend_output(osl_relation_p relation, int dim)
Definition: relation.c:2939
osl_generic_p osl_generic_read_one(FILE *file, osl_interface_p registry)
Definition: generic.c:309
void osl_scop_free(osl_scop_p scop)
Definition: scop.c:570
struct osl_statement * next
Definition: statement.h:95
osl_strings_p parameters
Definition: names.h:82
void osl_scop_idump(FILE *file, osl_scop_p scop, int level)
Definition: scop.c:95
osl_names_p osl_names_generate(char *parameter_prefix, int nb_parameters, char *iterator_prefix, int nb_iterators, char *scatt_dim_prefix, int nb_scatt_dims, char *local_dim_prefix, int nb_local_dims, char *array_prefix, int nb_arrays)
Definition: names.c:206
int nb_output_dims
Definition: relation.h:109
char ** string
Definition: strings.h:82
int osl_statement_number(osl_statement_p statement)
Definition: statement.c:572
#define OSL_URI_STRINGS
Definition: strings.h:75
osl_relation_p scattering
Definition: statement.h:90
osl_statement_p osl_statement_pread(FILE *file, osl_interface_p registry, int precision)
Definition: statement.c:452
int osl_statement_equal(osl_statement_p s1, osl_statement_p s2)
Definition: statement.c:696
osl_scop_p osl_scop_remove_unions(osl_scop_p scop)
Definition: scop.c:673
osl_statement_p osl_statement_clone(osl_statement_p statement)
Definition: statement.c:628
osl_scop_p osl_scop_clone(osl_scop_p scop)
Definition: scop.c:635
#define OSL_info(msg)
Definition: macros.h:139
void osl_relation_free(osl_relation_p relation)
Definition: relation.c:1734
void osl_interface_free(osl_interface_p interface)
Definition: interface.c:237
void osl_relation_idump(FILE *file, osl_relation_p relation, int level)
Definition: relation.c:164
osl_int_t ** m
Definition: relation.h:114
osl_generic_p osl_generic_sread(char **input, osl_interface_p registry)
Definition: generic.c:243
void osl_statement_free(osl_statement_p statement)
Definition: statement.c:528
osl_generic_p osl_generic_clone(osl_generic_p generic)
Definition: generic.c:540
void osl_relation_pprint_scoplib(FILE *file, osl_relation_p relation, osl_names_p names, int print_nth_part, int add_fakeiter)
Definition: relation.c:1260
#define OSL_URI_SCOP
Definition: macros.h:72
#define OSL_debug(msg)
Definition: macros.h:133
void osl_relation_pprint(FILE *file, osl_relation_p relation, osl_names_p names)
Definition: relation.c:1242
int osl_scop_equal(osl_scop_p s1, osl_scop_p s2)
Definition: scop.c:724
#define OSL_TYPE_CONTEXT
Definition: macros.h:100
#define OSL_strdup(destination, source)
Definition: macros.h:169
void osl_statement_pprint_scoplib(FILE *file, osl_statement_p statement, osl_names_p names)
Definition: statement.c:288
void osl_scop_add(osl_scop_p *location, osl_scop_p scop)
Definition: scop.c:601
osl_scop_p osl_scop_pread(FILE *file, osl_interface_p registry, int precision)
Definition: scop.c:421
osl_names_p osl_scop_names(osl_scop_p scop)
Definition: scop.c:193
void osl_scop_get_attributes(osl_scop_p scop, int *nb_parameters, int *nb_iterators, int *nb_scattdims, int *nb_localdims, int *array_id)
Definition: scop.c:948
int osl_generic_equal(osl_generic_p x1, osl_generic_p x2)
Definition: generic.c:610
osl_relation_p domain
Definition: statement.h:89
osl_relation_p osl_relation_clone(osl_relation_p relation)
Definition: relation.c:1866
int osl_relation_equal(osl_relation_p r1, osl_relation_p r2)
Definition: relation.c:2438
osl_strings_p names
Definition: scatnames.h:88
#define OSL_URI_ARRAYS
Definition: arrays.h:77
void osl_statement_get_attributes(osl_statement_p statement, int *nb_parameters, int *nb_iterators, int *nb_scattdims, int *nb_localdims, int *array_id)
Definition: statement.c:840
osl_strings_p osl_strings_read(FILE *file)
Definition: strings.c:260
osl_statement_p osl_statement_remove_unions(osl_statement_p statement)
Definition: statement.c:650
void osl_interface_idump(FILE *file, osl_interface_p interface, int level)
Definition: interface.c:100
int osl_relation_integrity_check(osl_relation_p relation, int expected_type, int expected_nb_output_dims, int expected_nb_input_dims, int expected_nb_parameters)
Definition: relation.c:2543
osl_generic_p extension
Definition: statement.h:92
int osl_statement_integrity_check(osl_statement_p statement, int expected_nb_parameters)
Definition: statement.c:748
void osl_scop_print_scoplib(FILE *file, osl_scop_p scop)
Definition: scop.c:311
void osl_names_free(osl_names_p names)
Definition: names.c:172
#define OSL_max(x, y)
Definition: macros.h:181
int osl_interface_equal(osl_interface_p interface1, osl_interface_p interface2)
Definition: interface.c:328
void osl_strings_free(osl_strings_p strings)
Definition: strings.c:300
void osl_generic_idump(FILE *file, osl_generic_p generic, int level)
Definition: generic.c:89
void osl_scop_normalize_scattering(osl_scop_p scop)
Definition: scop.c:992
int osl_int_mone(int precision, osl_const_int_t value)
value == -1
Definition: int.c:1373
char * osl_util_read_uptotag(FILE *file, char **str, char *name)
Definition: util.c:391
int osl_scop_integrity_check(osl_scop_p scop)
Definition: scop.c:783
void osl_generic_print(FILE *file, osl_generic_p generic)
Definition: generic.c:196
osl_scop_p osl_scop_read(FILE *foo)
Definition: scop.c:525
void osl_generic_free(osl_generic_p generic)
Definition: generic.c:489
void osl_interface_add(osl_interface_p *list, osl_interface_p interface)
Definition: interface.c:177
size_t osl_strings_size(osl_const_strings_const_p strings)
Definition: strings.c:414
void osl_statement_pprint(FILE *file, osl_statement_p statement, osl_names_p names)
Definition: statement.c:199
struct osl_textual * osl_textual_p
Definition: textual.h:88
osl_strings_p arrays
Definition: names.h:86
int nb_local_dims
Definition: relation.h:111
void osl_relation_get_attributes(osl_relation_p relation, int *nb_parameters, int *nb_iterators, int *nb_scattdims, int *nb_localdims, int *array_id)
Definition: relation.c:2856
void osl_generic_print_options_scoplib(FILE *file, osl_generic_p generic)
Definition: generic.c:214
void osl_strings_print(FILE *file, osl_strings_p strings)
Definition: strings.c:167
void osl_scop_print(FILE *file, osl_scop_p scop)
Definition: scop.c:218
int precision
Definition: relation.h:106
int osl_util_get_precision(void)
Definition: util.c:517
int osl_scop_check_compatible_scoplib(osl_scop_p scop)
Definition: scop.c:828
#define OSL_UNDEFINED
Definition: macros.h:93
int osl_generic_has_URI(osl_const_generic_const_p x, char const *const URI)
Definition: generic.c:666
osl_relation_p osl_relation_pread(FILE *foo, int precision)
Definition: relation.c:1382
void osl_util_print_provided(FILE *file, int provided, char *title)
Definition: util.c:556
osl_interface_p osl_interface_get_default_registry(void)
Definition: interface.c:386
void osl_scop_dump(FILE *file, osl_scop_p scop)
Definition: scop.c:181
osl_generic_p osl_generic_read(FILE *file, osl_interface_p registry)
Definition: generic.c:350
void osl_statement_idump(FILE *file, osl_statement_p statement, int level)
Definition: statement.c:96
osl_strings_p osl_arrays_to_strings(osl_arrays_p arrays)
Definition: arrays.c:360
int osl_scop_get_nb_parameters(osl_scop_p scop)
Definition: scop.c:892
void osl_generic_add(osl_generic_p *list, osl_generic_p generic)
Definition: generic.c:375
struct osl_relation * next
Definition: relation.h:117
int osl_int_zero(int precision, osl_const_int_t value)
value == 0
Definition: int.c:1323
#define OSL_malloc(ptr, type, size)
Definition: macros.h:157