PET auto scop detection

13 views
Skip to first unread message

Emil Vatai

unread,
Mar 14, 2025, 1:16:25 AMMar 14
to isl Development
stdio.h's FILE type breaks PET's scop autodetection because the functions add_field_types() (3055 line in scan.cc) and add_type() (3091 line in scan.cc) end up calling each other ad infinitum. E.g. this input
```
#include <stdio.h>
int main() {
  FILE *file = fopen("/dev/null", "a");
  fclose(file);
  return 0;
}
```
breaks a simple PET program calling `pet_transform_C_source()`

This is the PET program:
```
// scop_detector.c
#include <stddef.h>
#include <stdio.h>
#include <string.h>

#include <isl/ctx.h>
#include <isl/schedule.h>
#include <isl/schedule_node.h>
#include <isl/schedule_type.h>
#include <pet.h>

isl_printer *
transform(isl_printer *p, pet_scop *scop, void *user) {
  size_t *num_scops = user;
  isl_schedule *schedule = pet_scop_get_schedule(scop);
  isl_schedule_node *root = isl_schedule_get_root(schedule);
  printf("scop[%d]:\n%s\n", *num_scops, isl_schedule_node_to_str(root));
  (*num_scops)++;
  return p;
}

int main(int argc, char *argv[]) {
  char *input = argv[1];
  isl_ctx *ctx = isl_ctx_alloc_with_pet_options();
  FILE *output = fopen("/dev/null", "w");
  size_t num_scops = 0;
  if (argc > 2 && strncmp(argv[2], "-a", 3) == 0) {
    printf("Using auto detection\n");
    pet_options_set_autodetect(ctx, 1);
  }
  pet_transform_C_source(ctx, input, output, transform, &num_scops);
  printf("Number of scops detected: %d\n", num_scops);
  return 0;
}
```

Sven Verdoolaege

unread,
Mar 15, 2025, 9:41:44 AMMar 15
to Emil Vatai, isl Development
On Thu, Mar 13, 2025 at 10:16:24PM -0700, Emil Vatai wrote:
> stdio.h's FILE type breaks PET's scop autodetection because the functions
> add_field_types() (3055 line in scan.cc) and add_type() (3091 line in
> scan.cc) end up calling each other ad infinitum. E.g. this input

Thanks for the report.
Should be fixed now.

skimo

Emil Vatai

unread,
Mar 16, 2025, 7:16:30 AMMar 16
to sven.ver...@gmail.com, isl Development
Thanks! It works!
--
Emil Vatai
Reply all
Reply to author
Forward
0 new messages