5 #ifndef V8_COMPILER_GRAPH_REDUCER_H_ 6 #define V8_COMPILER_GRAPH_REDUCER_H_ 8 #include "src/base/compiler-specific.h" 9 #include "src/compiler/node-marker.h" 10 #include "src/globals.h" 11 #include "src/zone/zone-containers.h" 27 enum class Decision : uint8_t { kUnknown, kTrue, kFalse };
32 explicit Reduction(
Node* replacement =
nullptr) : replacement_(replacement) {}
34 Node* replacement()
const {
return replacement_; }
35 bool Changed()
const {
return replacement() !=
nullptr; }
52 virtual const char* reducer_name()
const = 0;
60 virtual void Finalize();
76 virtual ~
Editor() =
default;
79 virtual void Replace(
Node* node,
Node* replacement) = 0;
81 virtual void Revisit(
Node* node) = 0;
85 virtual void ReplaceWithValue(
Node* node,
Node* value,
Node* effect,
93 static Reduction Replace(
Node* node) {
return Reducer::Replace(node); }
96 void Replace(
Node* node,
Node* replacement) {
97 DCHECK_NOT_NULL(editor_);
98 editor_->Replace(node, replacement);
100 void Revisit(Node* node) {
101 DCHECK_NOT_NULL(editor_);
102 editor_->Revisit(node);
104 void ReplaceWithValue(Node* node, Node* value, Node* effect =
nullptr,
105 Node* control =
nullptr) {
106 DCHECK_NOT_NULL(editor_);
107 editor_->ReplaceWithValue(node, value, effect, control);
113 void RelaxEffectsAndControls(Node* node) {
114 ReplaceWithValue(node, node,
nullptr,
nullptr);
119 void RelaxControls(Node* node) {
120 ReplaceWithValue(node, node, node,
nullptr);
124 Editor*
const editor_;
130 :
public NON_EXPORTED_BASE(AdvancedReducer::Editor) {
135 Graph* graph()
const {
return graph_; }
137 void AddReducer(
Reducer* reducer);
140 void ReduceNode(
Node*
const);
145 enum class State : uint8_t;
157 void Replace(
Node* node,
Node* replacement)
final;
162 void ReplaceWithValue(
Node* node,
Node* value,
Node* effect,
163 Node* control)
final;
172 void Push(
Node* node);
175 bool Recurse(
Node* node);
176 void Revisit(
Node* node)
final;
192 #endif // V8_COMPILER_GRAPH_REDUCER_H_