1 | /* |
2 | * Copyright (C) 2015-2018 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. ``AS IS'' AND ANY |
14 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR |
17 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
18 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
19 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
20 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
21 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
24 | */ |
25 | |
26 | #include "config.h" |
27 | #include "B3Generate.h" |
28 | |
29 | #if ENABLE(B3_JIT) |
30 | |
31 | #include "AirCode.h" |
32 | #include "AirGenerate.h" |
33 | #include "AirInstInlines.h" |
34 | #include "B3Common.h" |
35 | #include "B3DuplicateTails.h" |
36 | #include "B3EliminateCommonSubexpressions.h" |
37 | #include "B3EliminateDeadCode.h" |
38 | #include "B3FixSSA.h" |
39 | #include "B3FoldPathConstants.h" |
40 | #include "B3HoistLoopInvariantValues.h" |
41 | #include "B3InferSwitches.h" |
42 | #include "B3LegalizeMemoryOffsets.h" |
43 | #include "B3LowerMacros.h" |
44 | #include "B3LowerMacrosAfterOptimizations.h" |
45 | #include "B3LowerToAir.h" |
46 | #include "B3MoveConstants.h" |
47 | #include "B3OptimizeAssociativeExpressionTrees.h" |
48 | #include "B3Procedure.h" |
49 | #include "B3PureCSE.h" |
50 | #include "B3ReduceDoubleToFloat.h" |
51 | #include "B3ReduceLoopStrength.h" |
52 | #include "B3ReduceStrength.h" |
53 | #include "B3TimingScope.h" |
54 | #include "B3Validate.h" |
55 | #include "PCToCodeOriginMap.h" |
56 | |
57 | namespace JSC { namespace B3 { |
58 | |
59 | void prepareForGeneration(Procedure& procedure) |
60 | { |
61 | TimingScope timingScope("prepareForGeneration" ); |
62 | |
63 | generateToAir(procedure); |
64 | Air::prepareForGeneration(procedure.code()); |
65 | } |
66 | |
67 | void generate(Procedure& procedure, CCallHelpers& jit) |
68 | { |
69 | Air::generate(procedure.code(), jit); |
70 | } |
71 | |
72 | void generateToAir(Procedure& procedure) |
73 | { |
74 | TimingScope timingScope("generateToAir" ); |
75 | |
76 | if (shouldDumpIR(B3Mode) && !shouldDumpIRAtEachPhase(B3Mode)) { |
77 | dataLog("Initial B3:\n" ); |
78 | dataLog(procedure); |
79 | } |
80 | |
81 | // We don't require the incoming IR to have predecessors computed. |
82 | procedure.resetReachability(); |
83 | |
84 | if (shouldValidateIR()) |
85 | validate(procedure); |
86 | |
87 | if (procedure.optLevel() >= 2) { |
88 | reduceDoubleToFloat(procedure); |
89 | reduceStrength(procedure); |
90 | hoistLoopInvariantValues(procedure); |
91 | if (eliminateCommonSubexpressions(procedure)) |
92 | eliminateCommonSubexpressions(procedure); |
93 | eliminateDeadCode(procedure); |
94 | inferSwitches(procedure); |
95 | reduceLoopStrength(procedure); |
96 | if (Options::useB3TailDup()) |
97 | duplicateTails(procedure); |
98 | fixSSA(procedure); |
99 | foldPathConstants(procedure); |
100 | // FIXME: Add more optimizations here. |
101 | // https://bugs.webkit.org/show_bug.cgi?id=150507 |
102 | } else if (procedure.optLevel() >= 1) { |
103 | // FIXME: Explore better "quick mode" optimizations. |
104 | reduceStrength(procedure); |
105 | } |
106 | |
107 | // This puts the IR in quirks mode. |
108 | lowerMacros(procedure); |
109 | |
110 | if (procedure.optLevel() >= 2) { |
111 | optimizeAssociativeExpressionTrees(procedure); |
112 | reduceStrength(procedure); |
113 | |
114 | // FIXME: Add more optimizations here. |
115 | // https://bugs.webkit.org/show_bug.cgi?id=150507 |
116 | } |
117 | |
118 | lowerMacrosAfterOptimizations(procedure); |
119 | legalizeMemoryOffsets(procedure); |
120 | moveConstants(procedure); |
121 | eliminateDeadCode(procedure); |
122 | |
123 | // FIXME: We should run pureCSE here to clean up some platform specific changes from the previous phases. |
124 | // https://bugs.webkit.org/show_bug.cgi?id=164873 |
125 | |
126 | if (shouldValidateIR()) |
127 | validate(procedure); |
128 | |
129 | // If we're doing super verbose dumping, the phase scope of any phase will already do a dump. |
130 | // Note that lowerToAir() acts like a phase in this regard. |
131 | if (shouldDumpIR(B3Mode) && !shouldDumpIRAtEachPhase(B3Mode)) { |
132 | dataLog("B3 after " , procedure.lastPhaseName(), ", before generation:\n" ); |
133 | dataLog(procedure); |
134 | } |
135 | |
136 | lowerToAir(procedure); |
137 | } |
138 | |
139 | } } // namespace JSC::B3 |
140 | |
141 | #endif // ENABLE(B3_JIT) |
142 | |
143 | |