blob: 81153f98dcae42a26e961e2492afcfac409b68e1 [file] [log] [blame]
Ben Murdoch014dc512016-03-22 12:00:34 +00001// Copyright 2015 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef V8_COMPILER_JS_CALL_REDUCER_H_
6#define V8_COMPILER_JS_CALL_REDUCER_H_
7
8#include "src/base/flags.h"
9#include "src/compiler/graph-reducer.h"
10
11namespace v8 {
12namespace internal {
13namespace compiler {
14
15// Forward declarations.
16class CommonOperatorBuilder;
17class JSGraph;
18class JSOperatorBuilder;
Ben Murdochf91f0612016-11-29 16:50:11 +000019class SimplifiedOperatorBuilder;
Ben Murdoch014dc512016-03-22 12:00:34 +000020
21// Performs strength reduction on {JSCallConstruct} and {JSCallFunction} nodes,
22// which might allow inlining or other optimizations to be performed afterwards.
Ben Murdochf3b273f2017-01-17 12:11:28 +000023class JSCallReducer final : public AdvancedReducer {
Ben Murdoch014dc512016-03-22 12:00:34 +000024 public:
25 // Flags that control the mode of operation.
26 enum Flag {
27 kNoFlags = 0u,
Ben Murdochf3b273f2017-01-17 12:11:28 +000028 kBailoutOnUninitialized = 1u << 0,
29 kDeoptimizationEnabled = 1u << 1
Ben Murdoch014dc512016-03-22 12:00:34 +000030 };
31 typedef base::Flags<Flag> Flags;
32
Ben Murdochf3b273f2017-01-17 12:11:28 +000033 JSCallReducer(Editor* editor, JSGraph* jsgraph, Flags flags,
Ben Murdochc8c1d9e2017-03-08 14:04:23 +000034 Handle<Context> native_context)
Ben Murdochf3b273f2017-01-17 12:11:28 +000035 : AdvancedReducer(editor),
36 jsgraph_(jsgraph),
37 flags_(flags),
38 native_context_(native_context) {}
Ben Murdoch014dc512016-03-22 12:00:34 +000039
40 Reduction Reduce(Node* node) final;
41
42 private:
43 Reduction ReduceArrayConstructor(Node* node);
44 Reduction ReduceNumberConstructor(Node* node);
45 Reduction ReduceFunctionPrototypeApply(Node* node);
46 Reduction ReduceFunctionPrototypeCall(Node* node);
Ben Murdochc8c1d9e2017-03-08 14:04:23 +000047 Reduction ReduceObjectPrototypeGetProto(Node* node);
Ben Murdoch014dc512016-03-22 12:00:34 +000048 Reduction ReduceJSCallConstruct(Node* node);
49 Reduction ReduceJSCallFunction(Node* node);
50
Ben Murdoch014dc512016-03-22 12:00:34 +000051 Graph* graph() const;
52 Flags flags() const { return flags_; }
53 JSGraph* jsgraph() const { return jsgraph_; }
54 Isolate* isolate() const;
Ben Murdochc8c1d9e2017-03-08 14:04:23 +000055 Handle<Context> native_context() const { return native_context_; }
Ben Murdoch014dc512016-03-22 12:00:34 +000056 CommonOperatorBuilder* common() const;
57 JSOperatorBuilder* javascript() const;
Ben Murdochf91f0612016-11-29 16:50:11 +000058 SimplifiedOperatorBuilder* simplified() const;
Ben Murdoch014dc512016-03-22 12:00:34 +000059
60 JSGraph* const jsgraph_;
61 Flags const flags_;
Ben Murdochc8c1d9e2017-03-08 14:04:23 +000062 Handle<Context> const native_context_;
Ben Murdoch014dc512016-03-22 12:00:34 +000063};
64
65DEFINE_OPERATORS_FOR_FLAGS(JSCallReducer::Flags)
66
67} // namespace compiler
68} // namespace internal
69} // namespace v8
70
71#endif // V8_COMPILER_JS_CALL_REDUCER_H_