Skip to content

Commit 15fafe7

Browse files
authored
Merge pull request #328 from GuillaumeGomez/gimple-output
Set the correct gimple output format
2 parents e39f3a2 + 3e61cc3 commit 15fafe7

File tree

1 file changed

+32
-2
lines changed

1 file changed

+32
-2
lines changed

doc/gimple.md

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,17 @@ also add the calls we need to generate the GIMPLE:
3333
```C
3434
int main() {
3535
gcc_jit_context *ctxt = gcc_jit_context_acquire();
36+
// To set `-O3`, update it depending on your needs.
37+
gcc_jit_context_set_int_option(ctxt, GCC_JIT_INT_OPTION_OPTIMIZATION_LEVEL, 3);
38+
// Very important option to generate the gimple format.
39+
gcc_jit_context_set_bool_option(ctxt, GCC_JIT_BOOL_OPTION_DUMP_INITIAL_GIMPLE, 1);
3640
create_code(ctxt, NULL);
41+
3742
gcc_jit_context_compile(ctxt);
38-
gcc_jit_context_dump_to_file(ctxt, "tmp.gimple", 1);
43+
// If you want to compile to assembly (or any other format) directly, you can
44+
// use the following call instead:
45+
// gcc_jit_context_compile_to_file(ctxt, GCC_JIT_OUTPUT_KIND_ASSEMBLER, "out.s");
46+
3947
return 0;
4048
}
4149
```
@@ -52,7 +60,7 @@ And finally when you run it:
5260
LD_LIBRARY_PATH=`pwd`/gcc-build/gcc LIBRARY_PATH=`pwd`/gcc-build/gcc ./out
5361
```
5462

55-
You should now have a file named `tmp.gimple` which contains:
63+
It should display:
5664

5765
```c
5866
__attribute__((const))
@@ -79,3 +87,25 @@ int xxx ()
7987
return D.3394;
8088
}
8189
```
90+
91+
An alternative way to generate the GIMPLE is to replace:
92+
93+
```c
94+
gcc_jit_context_set_bool_option(ctxt, GCC_JIT_BOOL_OPTION_DUMP_INITIAL_GIMPLE, 1);
95+
```
96+
97+
with:
98+
99+
```c
100+
gcc_jit_context_add_command_line_option(ctxt, "-fdump-tree-gimple");
101+
```
102+
103+
(although you can have both at the same time too). Then you can compile it like previously. Only one difference: before executing it, I recommend to run:
104+
105+
```console
106+
rm -rf /tmp/libgccjit-*
107+
```
108+
109+
to make it easier for you to know which folder to look into.
110+
111+
Once the execution is done, you should now have a file with path looking like `/tmp/libgccjit-9OFqkD/fake.c.006t.gimple` which contains the GIMPLE format.

0 commit comments

Comments
 (0)