blob: 9ffae152ac08b76b168c0303c55327896110fda4 [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 Murdochda12d292016-06-02 14:46:10 +010023class JSCallReducer final : public Reducer {
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 Murdochda12d292016-06-02 14:46:10 +010032 JSCallReducer(JSGraph* jsgraph, Flags flags,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000033 MaybeHandle<Context> native_context)
Ben Murdochda12d292016-06-02 14:46:10 +010034 : jsgraph_(jsgraph), flags_(flags), native_context_(native_context) {}
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000035
36 Reduction Reduce(Node* node) final;
37
38 private:
39 Reduction ReduceArrayConstructor(Node* node);
40 Reduction ReduceNumberConstructor(Node* node);
41 Reduction ReduceFunctionPrototypeApply(Node* node);
42 Reduction ReduceFunctionPrototypeCall(Node* node);
43 Reduction ReduceJSCallConstruct(Node* node);
44 Reduction ReduceJSCallFunction(Node* node);
45
46 MaybeHandle<Context> GetNativeContext(Node* node);
47
48 Graph* graph() const;
49 Flags flags() const { return flags_; }
50 JSGraph* jsgraph() const { return jsgraph_; }
51 Isolate* isolate() const;
52 MaybeHandle<Context> native_context() const { return native_context_; }
53 CommonOperatorBuilder* common() const;
54 JSOperatorBuilder* javascript() const;
55
56 JSGraph* const jsgraph_;
57 Flags const flags_;
58 MaybeHandle<Context> const native_context_;
59};
60
61DEFINE_OPERATORS_FOR_FLAGS(JSCallReducer::Flags)
62
63} // namespace compiler
64} // namespace internal
65} // namespace v8
66
67#endif // V8_COMPILER_JS_CALL_REDUCER_H_