@@ -3,61 +3,63 @@ open SimplifiedAnalysis
33open GStoreWideningHelper
44
55(* *
6- This analysis proceeds in steps, with the steps building on each other.
6+ This analysis proceeds in steps, with the steps building on each other.
77
8- For the sake of this analysis, we are assuming that all variables are of integer type.
9- This allows us to keep the analysis simple in the beginning.
8+ For the sake of this analysis, we are assuming that all variables are of integer type.
9+ This allows us to keep the analysis simple in the beginning.
1010
1111
12- 1) First, a simple interval analysis is implemented which tracks intervals
13- for local variables only.
12+ 1) First, a simple interval analysis is implemented which tracks intervals
13+ for local variables only.
1414
1515 The majority of the code is already provided, there is one place where
16- changes need to be made, namely the handling of branches.
16+ changes need to be made, namely the handling of branches.
1717 It is marked with TODO: 1).
1818
19- 2) Then the analysis is extended to also track values for globals via global store widening
19+ 2) Then the analysis is extended to also track values for globals via global store widening
2020
2121 To this end, one should fix which set of globals to track, and their domain.
2222 Then, assignment and evaluation functions should be changed appropriately.
2323 These are marked with TODO: 2).
24-
25- 3) Define a helper analysis which tracks for each variable which thread ids are used to write to it,
24+
25+ 3) Define a helper analysis which tracks for each variable which thread ids are used to write to it,
2626 and use this information to determine whether a variable is effectively local
2727 (i.e., only written by one thread).
2828
29- This requires modifying the domain to store thread ids, and modifying the assign function
30- to record thread ids for global variables.
29+ This requires modifying the domain to store thread ids, and modifying the assign function
30+ to record thread ids for global variables.
3131 Then, the query function should be modified to check whether there is only one thread
32- accessing this variable, and whether it is the current one.
32+ accessing this variable, and whether it is the current one.
3333 These are marked with TODO: 3).
34-
35- 4) Modify the first analysis to exploit the information from the helper analysis to
34+
35+ 4) Modify the first analysis to exploit the information from the helper analysis to
3636 track the values of effectively local variables more precisely in the thread that
3737 owns them, while keeping applying global store widening to obtain the perspective
3838 of other threads.
3939
4040 This will amount to modifying some of the places changed in step 2)
4141
42-
43- After modifying things, don't forget to compile by running `make`
42+
43+ After modifying things, don't forget to compile by running `make`
4444
4545 There are regression tests for this analysis, which you can run by calling:
4646 - ./regtest.sh 99 05
4747 - ./regtest.sh 99 06
48+ - ./regtest.sh 99 07
4849
49- After fixing the TODO: 1), the first regression test should pass.
50- After fixing the TODO: 2), both the first and the second tests should pass.
50+ After fixing the TODO: 1), the first regression test should pass.
51+ After fixing the TODO: 2), both the first and the second tests should pass.
52+ After fixing the last TODO:, all three tests should pass
5153
52- Running a regression test also produces a visualization of the analysis results as a HTML file in the folder
53- result.
54+ Running a regression test also produces a visualization of the analysis results as a HTML file in the folder
55+ result.
5456
55- You can access these by spinning up a HTTP server for the result directory,
56- e.g., by calling `python3 -m http.server --directory result`.
57- Then open `index.xml` in your browser.
57+ You can access these by spinning up a HTTP server for the result directory,
58+ e.g., by calling `python3 -m http.server --directory result`.
59+ Then open `index.xml` in your browser.
5860
59- (When using devcontainer, VSCode will automatically detect the server and
60- provide a link to open the visualization in your browser.)
61+ (When using devcontainer, VSCode will automatically detect the server and
62+ provide a link to open the visualization in your browser.)
6163
6264*)
6365
@@ -80,7 +82,7 @@ module GStoreWideningAnalysis: SimplifiedSpec = struct
8082 (* Evaluate a single variable given a local state *)
8183 let eval_varinfo man state v =
8284 if v.vglob then
83- (* * TODO: 2) Modify so that we store values for globals *)
85+ (* TODO: 2) Modify so that we get values for globals *)
8486 top_of_var v
8587 else
8688 D. find v state
@@ -236,7 +238,7 @@ module GStoreWideningAnalysis: SimplifiedSpec = struct
236238 ) (D. bot () ) f.sformals
237239end
238240
239- module ThreadSet = ConcDomain. ThreadSet
241+ module ThreadSet = ConcDomain. ThreadSet
240242
241243module EffectivelyLocalAnalysis :SimplifiedSpec = struct
242244 let name = " effectivelyLocal"
@@ -252,20 +254,24 @@ module EffectivelyLocalAnalysis:SimplifiedSpec = struct
252254 let startcontext = ()
253255
254256 let assign man state lval rval =
255- let tid = ThreadId. get_current_unlift (SimplifiedAnalysis. ask_of_man man) in
256- let singleton_set = ThreadSet. singleton tid in
257- match is_tracked_lval lval with
258- | Some v ->
259- (* TODO: 3) check if this is a global variable and if it is, record the thread id *)
257+ (* When the global initializers are evaluated, no threads exists yet *)
258+ if ! AnalysisState. global_initialization then
260259 state
261- | None ->
262- state
263-
260+ else
261+ let tid = ThreadId. get_current_unlift (SimplifiedAnalysis. ask_of_man man) in
262+ let singleton_set = ThreadSet. singleton tid in
263+ match is_tracked_lval lval with
264+ | Some v ->
265+ (* TODO: 3) check if this is a global variable and if it is, record the thread id *)
266+ state
267+ | None ->
268+ state
269+
264270 let query man state (type a ) (q : a Queries.t ): a Queries.result =
265271 match q with
266272 | Queries. TutorialEffectivelyLocal v ->
267273 (* TODO: 3) Get the current thread id, and check whether there is only one thread
268- accessing this variable, and whether it is the current one *)
274+ accessing this variable, and whether it is the current one *)
269275 Queries.Result. top q
270276 | _ -> Queries.Result. top q
271277
0 commit comments