blob: f40f05d852a05a6ec583721bb2034be3280e504e [file] [log] [blame]
Ben Murdoch4a90d5f2016-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;
19
20
21// Performs strength reduction on {JSCallConstruct} and {JSCallFunction} nodes,
22// which might allow inlining or other optimizations to be performed afterwards.
Ben Murdoch097c5b22016-05-18 11:27:45 +010023class JSCallReducer final : public AdvancedReducer {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000024 public:
25 // Flags that control the mode of operation.
26 enum Flag {
27 kNoFlags = 0u,
28 kDeoptimizationEnabled = 1u << 0,
29 };
30 typedef base::Flags<Flag> Flags;
31
Ben Murdoch097c5b22016-05-18 11:27:45 +010032 JSCallReducer(Editor* editor, JSGraph* jsgraph, Flags flags,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000033 MaybeHandle<Context> native_context)
Ben Murdoch097c5b22016-05-18 11:27:45 +010034 : AdvancedReducer(editor),
35 jsgraph_(jsgraph),
36 flags_(flags),
37 native_context_(native_context) {}
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000038
39 Reduction Reduce(Node* node) final;
40
41 private:
42 Reduction ReduceArrayConstructor(Node* node);
43 Reduction ReduceNumberConstructor(Node* node);
44 Reduction ReduceFunctionPrototypeApply(Node* node);
45 Reduction ReduceFunctionPrototypeCall(Node* node);
46 Reduction ReduceJSCallConstruct(Node* node);
47 Reduction ReduceJSCallFunction(Node* node);
48
49 MaybeHandle<Context> GetNativeContext(Node* node);
50
51 Graph* graph() const;
52 Flags flags() const { return flags_; }
53 JSGraph* jsgraph() const { return jsgraph_; }
54 Isolate* isolate() const;
55 MaybeHandle<Context> native_context() const { return native_context_; }
56 CommonOperatorBuilder* common() const;
57 JSOperatorBuilder* javascript() const;
58
59 JSGraph* const jsgraph_;
60 Flags const flags_;
61 MaybeHandle<Context> const native_context_;
62};
63
64DEFINE_OPERATORS_FOR_FLAGS(JSCallReducer::Flags)
65
66} // namespace compiler
67} // namespace internal
68} // namespace v8
69
70#endif // V8_COMPILER_JS_CALL_REDUCER_H_