blob: 36e05cb7f237d931f97ab7d355e06bb949076dc8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
|
Client Code . Generated . libgccjit.so
. code .
. . JIT API . JIT "Frontend". (libbackend.a)
....................................................................................
│ . . . .
──────────────────────────> . .
. . │ . .
. . V . .
. . ──> libgccjit.c .
. . │ (error-checking).
. . │ .
. . ──> jit-recording.c
. . (record API calls)
. . <─────── .
. . │ . .
<─────────────────────────── . .
│ . . . .
│ . . . .
V . . gcc_jit_context_compile .
──────────────────────────> . .
. . │ start of recording::context::compile ()
. . │ . .
. . │ start of playback::context::compile ()
. . │ (create tempdir) .
. . │ . .
. . │ ACQUIRE MUTEX .
. . │ . .
. . V───────────────────────> toplev::main (for now)
. . . . │
. . . . (various code)
. . . . │
. . . . V
. . . <───────────────── langhook:parse_file
. . . │ .
. . . │ (jit_langhook_parse_file)
. . . │ .
..........................................│..................VVVVVVVVVVVVV...
. . . │ . No GC in here
. . . │ jit-playback.c
. . . │ (playback of API calls)
. . . ───────────────> creation of functions,
. . . . types, expression trees
. . . <──────────────── etc
. . . │(handle_locations: add locations to
. . . │ linemap and associate them with trees)
. . . │ .
. . . │ . No GC in here
..........................................│..................AAAAAAAAAAAAA...
. . . │ for each function
. . . ──> postprocess
. . . │ .
. . . ────────────> cgraph_finalize_function
. . . <────────────
. . . <── .
. . . │ .
. . . ──────────────────> (end of
. . . . │ langhook_parse_file)
. . . . │
. . . . (various code)
. . . . │
. . . . ↓
. . . <───────────────── langhook:write_globals
. . . │ .
. . . │ (jit_langhook_write_globals)
. . . │ .
. . . │ .
. . . ──────────────────> finalize_compilation_unit
. . . . │
. . . . (the middle─end and backend)
. . . . ↓
. . <───────────────────────────── end of toplev::main
. . │ . .
. . V───────────────────────> toplev::finalize
. . . . │ (purge internal state)
. . <──────────────────────── end of toplev::finalize
. . │ . .
. . V─> playback::context::postprocess:
. . │ . .
. . │ (assuming an in-memory compile):
. . │ . .
. . --> Convert assembler to DSO, via embedded
. . copy of driver:
. . driver::main ()
. . invocation of "as"
. . invocation of "ld"
. . driver::finalize ()
. . <----
. . │ . .
. . │ . Load DSO (dlopen "fake.so")
. . │ . .
. . │ . Bundle it up in a jit::result
. . <── . .
. . │ . .
. . │ RELEASE MUTEX .
. . │ . .
. . │ end of playback::context::compile ()
. . │ . .
. . │ playback::context dtor
. . ──> . .
. . │ Normally we cleanup the tempdir here:
. . │ ("fake.so" is unlinked from the
. . │ filesystem at this point)
. . │ If the client code requested debuginfo, the
. . │ cleanup happens later (in gcc_jit_result_release)
. . │ to make it easier on the debugger (see PR jit/64206)
. . <── . .
. . │ . .
. . │ end of recording::context::compile ()
<─────────────────────────── . .
│ . . . .
V . . gcc_jit_result_get_code .
──────────────────────────> . .
. . │ dlsym () within loaded DSO
<─────────────────────────── . .
Get (void*). . . .
│ . . . .
│ Call it . . . .
───────────────> . . .
. │ . . .
. │ . . .
<─────────────── . . .
│ . . . .
etc│ . . . .
│ . . . .
V . . gcc_jit_result_release .
──────────────────────────> . .
. . │ dlclose () the loaded DSO
. . │ (code becomes uncallable)
. . │ . .
. . │ If the client code requested debuginfo, then
. . │ cleanup of the tempdir was delayed.
. . │ If that was the case, clean it up now.
<─────────────────────────── . .
│ . . . .
|