1 | // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file |
2 | // for details. All rights reserved. Use of this source code is governed by a |
3 | // BSD-style license that can be found in the LICENSE file. |
4 | |
5 | #ifndef RUNTIME_VM_COMPILER_BACKEND_BRANCH_OPTIMIZER_H_ |
6 | #define RUNTIME_VM_COMPILER_BACKEND_BRANCH_OPTIMIZER_H_ |
7 | |
8 | #if defined(DART_PRECOMPILED_RUNTIME) |
9 | #error "AOT runtime should not use compiler sources (including header files)" |
10 | #endif // defined(DART_PRECOMPILED_RUNTIME) |
11 | |
12 | #include "vm/allocation.h" |
13 | |
14 | namespace dart { |
15 | |
16 | class BlockEntryInstr; |
17 | class FlowGraph; |
18 | class FunctionEntryInstr; |
19 | class JoinEntryInstr; |
20 | class Zone; |
21 | class TargetEntryInstr; |
22 | class Value; |
23 | class BranchInstr; |
24 | |
25 | // Rewrite branches to eliminate materialization of boolean values after |
26 | // inlining, and to expose other optimizations (e.g., constant folding of |
27 | // branches, unreachable code elimination). |
28 | class BranchSimplifier : public AllStatic { |
29 | public: |
30 | static void Simplify(FlowGraph* flow_graph); |
31 | |
32 | // Replace a block entry instruction with a join entry instruction. Does |
33 | // not update the original target's predecessors to point to the new block |
34 | // and does not replace the target in already computed block order lists. |
35 | static JoinEntryInstr* ToJoinEntry(Zone* zone, BlockEntryInstr* target); |
36 | |
37 | // Replace a block entry instruction with a target entry instruction. Does |
38 | // not update the original target's predecessors to point to the new block and |
39 | // does not replace the target in already computed block order lists. |
40 | static TargetEntryInstr* ToTargetEntry(Zone* zone, BlockEntryInstr* target); |
41 | |
42 | private: |
43 | // Match an instance of the pattern to rewrite. See the implementation |
44 | // for the patterns that are handled by this pass. |
45 | static bool Match(JoinEntryInstr* block); |
46 | |
47 | // Duplicate a branch while replacing its comparison's left and right |
48 | // inputs. |
49 | static BranchInstr* CloneBranch(Zone* zone, |
50 | BranchInstr* branch, |
51 | Value* new_left, |
52 | Value* new_right); |
53 | }; |
54 | |
55 | // Rewrite diamond control flow patterns that materialize values to use more |
56 | // efficient branchless code patterns if such are supported on the current |
57 | // platform. |
58 | class IfConverter : public AllStatic { |
59 | public: |
60 | static void Simplify(FlowGraph* flow_graph); |
61 | }; |
62 | |
63 | } // namespace dart |
64 | |
65 | #endif // RUNTIME_VM_COMPILER_BACKEND_BRANCH_OPTIMIZER_H_ |
66 | |