1 | /* |
2 | * Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved. |
3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 | * |
5 | * This code is free software; you can redistribute it and/or modify it |
6 | * under the terms of the GNU General Public License version 2 only, as |
7 | * published by the Free Software Foundation. |
8 | * |
9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
12 | * version 2 for more details (a copy is included in the LICENSE file that |
13 | * accompanied this code). |
14 | * |
15 | * You should have received a copy of the GNU General Public License version |
16 | * 2 along with this work; if not, write to the Free Software Foundation, |
17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
18 | * |
19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
20 | * or visit www.oracle.com if you need additional information or have any |
21 | * questions. |
22 | * |
23 | */ |
24 | |
25 | #ifndef SHARE_OPTO_REPLACEDNODES_HPP |
26 | #define SHARE_OPTO_REPLACEDNODES_HPP |
27 | |
28 | #include "opto/connode.hpp" |
29 | |
30 | // During parsing, when a node is "improved", |
31 | // GraphKit::replace_in_map() is called to update the current map so |
32 | // that the improved node is used from that point |
33 | // on. GraphKit::replace_in_map() doesn't operate on the callers maps |
34 | // and so some optimization opportunities may be lost. The |
35 | // ReplacedNodes class addresses that problem. |
36 | // |
37 | // A ReplacedNodes object is a list of pair of nodes. Every |
38 | // SafePointNode carries a ReplacedNodes object. Every time |
39 | // GraphKit::replace_in_map() is called, a new pair of nodes is pushed |
40 | // on the list of replaced nodes. When control flow paths merge, their |
41 | // replaced nodes are also merged. When parsing exits a method to |
42 | // return to a caller, the replaced nodes on the exit path are used to |
43 | // update the caller's map. |
44 | class ReplacedNodes { |
45 | private: |
46 | class ReplacedNode { |
47 | private: |
48 | Node* _initial; |
49 | Node* _improved; |
50 | public: |
51 | ReplacedNode() : _initial(NULL), _improved(NULL) {} |
52 | ReplacedNode(Node* initial, Node* improved) : _initial(initial), _improved(improved) {} |
53 | Node* initial() const { return _initial; } |
54 | Node* improved() const { return _improved; } |
55 | |
56 | bool operator==(const ReplacedNode& other) { |
57 | return _initial == other._initial && _improved == other._improved; |
58 | } |
59 | }; |
60 | GrowableArray<ReplacedNode>* _replaced_nodes; |
61 | |
62 | void allocate_if_necessary(); |
63 | bool has_node(const ReplacedNode& r) const; |
64 | bool has_target_node(Node* n) const; |
65 | |
66 | public: |
67 | ReplacedNodes() |
68 | : _replaced_nodes(NULL) {} |
69 | |
70 | void clone(); |
71 | void record(Node* initial, Node* improved); |
72 | void transfer_from(const ReplacedNodes& other, uint idx); |
73 | void reset(); |
74 | void apply(Node* n, uint idx); |
75 | void merge_with(const ReplacedNodes& other); |
76 | bool is_empty() const; |
77 | void dump(outputStream *st) const; |
78 | void apply(Compile* C, Node* ctl); |
79 | }; |
80 | |
81 | #endif // SHARE_OPTO_REPLACEDNODES_HPP |
82 | |