1 | /* |
2 | * Copyright (C) 2016 Apple Inc. All rights reserved. |
3 | * |
4 | * Redistribution and use in source and binary forms, with or without |
5 | * modification, are permitted provided that the following conditions |
6 | * are met: |
7 | * 1. Redistributions of source code must retain the above copyright |
8 | * notice, this list of conditions and the following disclaimer. |
9 | * 2. Redistributions in binary form must reproduce the above copyright |
10 | * notice, this list of conditions and the following disclaimer in the |
11 | * documentation and/or other materials provided with the distribution. |
12 | * |
13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' |
14 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
15 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS |
17 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
18 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
19 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
20 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
21 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
22 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
23 | * THE POSSIBILITY OF SUCH DAMAGE. |
24 | */ |
25 | |
26 | #pragma once |
27 | |
28 | #if ENABLE(DFG_JIT) |
29 | |
30 | namespace JSC { namespace DFG { |
31 | |
32 | class Graph; |
33 | |
34 | // Picks up groups of barriers that could be executed in any order with respect to each other and |
35 | // places then at the earliest point in the program where the cluster would be correct. This phase |
36 | // makes only the first of the cluster be a FencedStoreBarrier while the rest are normal |
37 | // StoreBarriers. This phase also removes redundant barriers - for example, the cluster may end up |
38 | // with two or more barriers on the same object, in which case it is totally safe for us to drop |
39 | // one of them. The reason why this is sound hinges on the "earliest point where the cluster would |
40 | // be correct" property. For example, take this input: |
41 | // |
42 | // a: Call() |
43 | // b: PutByOffset(@o, @o, @x) |
44 | // c: FencedStoreBarrier(@o) |
45 | // d: PutByOffset(@o, @o, @y) |
46 | // e: FencedStoreBarrier(@o) |
47 | // f: PutByOffset(@p, @p, @z) |
48 | // g: FencedStoreBarrier(@p) |
49 | // h: GetByOffset(@q) |
50 | // i: Call() |
51 | // |
52 | // The cluster of barriers is @c, @e, and @g. All of the barriers are between two doesGC effects: |
53 | // the calls at @a and @i. Because there are no doesGC effects between @a and @i and there is no |
54 | // possible control flow entry into this sequence between @ and @i, we could could just execute all |
55 | // of the barriers just before @i in any order. The earliest point where the cluster would be |
56 | // correct is just after @f, since that's the last operation that needs a barrier. We use the |
57 | // earliest to reduce register pressure. When the barriers are clustered just after @f, we get: |
58 | // |
59 | // a: Call() |
60 | // b: PutByOffset(@o, @o, @x) |
61 | // d: PutByOffset(@o, @o, @y) |
62 | // f: PutByOffset(@p, @p, @z) |
63 | // c: FencedStoreBarrier(@o) |
64 | // e: FencedStoreBarrier(@o) |
65 | // g: FencedStoreBarrier(@p) |
66 | // h: GetByOffset(@q) |
67 | // i: Call() |
68 | // |
69 | // This phase does more. It takes advantage of the clustering to remove fences and remove redundant |
70 | // barriers. So this phase will output this: |
71 | // |
72 | // a: Call() |
73 | // b: PutByOffset(@o, @o, @x) |
74 | // d: PutByOffset(@o, @o, @y) |
75 | // f: PutByOffset(@p, @p, @z) |
76 | // c: FencedStoreBarrier(@o) |
77 | // g: StoreBarrier(@p) |
78 | // h: GetByOffset(@q) |
79 | // i: Call() |
80 | // |
81 | // This optimization improves both overall throughput and the throughput while the concurrent GC is |
82 | // running. In the former, we are simplifying instruction selection for all but the first fence. In |
83 | // the latter, we are reducing the cost of all but the first barrier. The first barrier will awlays |
84 | // take slow path when there is concurrent GC activity, since the slow path contains the fence. But |
85 | // all of the other barriers will only take slow path if they really need to remember the object. |
86 | bool performStoreBarrierClustering(Graph&); |
87 | |
88 | } } // namespace JSC::DFG |
89 | |
90 | #endif // ENABLE(DFG_JIT) |
91 | |
92 | |