0

I want to apply clang optimizations to a source file then generate its AST. I tried passing -O3 flag but it seems that it is ignored.

For example I assume that for this snipped of program:

#include <stdio.h>
int main(void) {
  int a = 5 + 5;
  for (int i = 0; i < 10; i++) { }
  printf("%i\n", a);
  return 0;
}

Many optimizations can be applied, like removing the for loop converting 5 + 5 to 10.

When I dump the AST using clang -O3 -Xclang -ast-dump -fsyntax-only a.c I get the same AST without the optimization flag.

My goal is create a TranslationUnit with flag optimizations passed.

user2232305
  • 319
  • 2
  • 11

1 Answers1

2

Maybe optimizations don't result into another AST? See if what you are looking for are IR dumps after each llvm optimization.

Grzegorz Adam Hankiewicz
  • 7,349
  • 1
  • 36
  • 78