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
5#ifndef V8_COMPILER_JS_GENERIC_LOWERING_H_
6#define V8_COMPILER_JS_GENERIC_LOWERING_H_
7
8#include "src/code-factory.h"
9#include "src/compiler/graph-reducer.h"
10#include "src/compiler/linkage.h"
11#include "src/compiler/opcodes.h"
12
13namespace v8 {
14namespace internal {
15namespace compiler {
16
17// Forward declarations.
18class CommonOperatorBuilder;
19class JSGraph;
20class MachineOperatorBuilder;
21class Linkage;
22
23
24// Lowers JS-level operators to runtime and IC calls in the "generic" case.
25class JSGenericLowering final : public Reducer {
26 public:
27  JSGenericLowering(bool is_typing_enabled, JSGraph* jsgraph);
28  ~JSGenericLowering() final;
29
30  Reduction Reduce(Node* node) final;
31
32 protected:
33#define DECLARE_LOWER(x) void Lower##x(Node* node);
34  // Dispatched depending on opcode.
35  JS_OP_LIST(DECLARE_LOWER)
36#undef DECLARE_LOWER
37
38  // Helpers to replace existing nodes with a generic call.
39  void ReplaceWithCompareIC(Node* node, Token::Value token, Strength strength);
40  void ReplaceWithStubCall(Node* node, Callable c, CallDescriptor::Flags flags);
41  void ReplaceWithRuntimeCall(Node* node, Runtime::FunctionId f, int args = -1);
42
43  Zone* zone() const;
44  Isolate* isolate() const;
45  JSGraph* jsgraph() const { return jsgraph_; }
46  Graph* graph() const;
47  CommonOperatorBuilder* common() const;
48  MachineOperatorBuilder* machine() const;
49
50 private:
51  bool const is_typing_enabled_;
52  JSGraph* const jsgraph_;
53};
54
55}  // namespace compiler
56}  // namespace internal
57}  // namespace v8
58
59#endif  // V8_COMPILER_JS_GENERIC_LOWERING_H_
60