1// Copyright 2014 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#ifndef V8_COMPILER_JS_GENERIC_LOWERING_H_
5#define V8_COMPILER_JS_GENERIC_LOWERING_H_
6
7#include "src/codegen/code-factory.h"
8#include "src/compiler/graph-reducer.h"
9#include "src/compiler/linkage.h"
10#include "src/compiler/opcodes.h"
11
12namespace v8 {
13namespace internal {
14namespace compiler {
15
16// Forward declarations.
17class CommonOperatorBuilder;
18class JSGraph;
19class MachineOperatorBuilder;
20class Linkage;
21
22
23// Lowers JS-level operators to runtime and IC calls in the "generic" case.
24class JSGenericLowering final : public AdvancedReducer {
25 public:
26  JSGenericLowering(JSGraph* jsgraph, Editor* editor, JSHeapBroker* broker);
27  ~JSGenericLowering() final;
28
29  const char* reducer_name() const override { return "JSGenericLowering"; }
30
31  Reduction Reduce(Node* node) final;
32
33 protected:
34#define DECLARE_LOWER(x, ...) void Lower##x(Node* node);
35  // Dispatched depending on opcode.
36  JS_OP_LIST(DECLARE_LOWER)
37#undef DECLARE_LOWER
38
39  // Helpers to replace existing nodes with a generic call.
40  void ReplaceWithBuiltinCall(Node* node, Builtin builtin);
41  void ReplaceWithBuiltinCall(Node* node, Callable c,
42                              CallDescriptor::Flags flags);
43  void ReplaceWithBuiltinCall(Node* node, Callable c,
44                              CallDescriptor::Flags flags,
45                              Operator::Properties properties);
46  void ReplaceWithRuntimeCall(Node* node, Runtime::FunctionId f, int args = -1);
47
48  void ReplaceUnaryOpWithBuiltinCall(Node* node,
49                                     Builtin builtin_without_feedback,
50                                     Builtin builtin_with_feedback);
51  void ReplaceBinaryOpWithBuiltinCall(Node* node,
52                                      Builtin builtin_without_feedback,
53                                      Builtin builtin_with_feedback);
54
55  Zone* zone() const;
56  Isolate* isolate() const;
57  JSGraph* jsgraph() const { return jsgraph_; }
58  Graph* graph() const;
59  CommonOperatorBuilder* common() const;
60  MachineOperatorBuilder* machine() const;
61  JSHeapBroker* broker() const { return broker_; }
62
63 private:
64  JSGraph* const jsgraph_;
65  JSHeapBroker* const broker_;
66};
67
68}  // namespace compiler
69}  // namespace internal
70}  // namespace v8
71
72#endif  // V8_COMPILER_JS_GENERIC_LOWERING_H_
73