js-generic-lowering.h 2.36 KB
Newer Older
1 2 3 4 5 6
// Copyright 2014 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef V8_COMPILER_JS_GENERIC_LOWERING_H_
#define V8_COMPILER_JS_GENERIC_LOWERING_H_

7
#include "src/codegen/code-factory.h"
8
#include "src/compiler/graph-reducer.h"
9
#include "src/compiler/linkage.h"
10 11 12 13 14 15 16 17
#include "src/compiler/opcodes.h"

namespace v8 {
namespace internal {
namespace compiler {

// Forward declarations.
class CommonOperatorBuilder;
18
class JSGraph;
19 20 21
class MachineOperatorBuilder;
class Linkage;

22

23
// Lowers JS-level operators to runtime and IC calls in the "generic" case.
24
class JSGenericLowering final : public AdvancedReducer {
25
 public:
26
  JSGenericLowering(JSGraph* jsgraph, Editor* editor, JSHeapBroker* broker);
27
  ~JSGenericLowering() final;
28

29 30
  const char* reducer_name() const override { return "JSGenericLowering"; }

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 38 39
#undef DECLARE_LOWER

  // Helpers to replace existing nodes with a generic call.
40
  void ReplaceWithBuiltinCall(Node* node, Builtin builtin);
41 42 43 44 45
  void ReplaceWithBuiltinCall(Node* node, Callable c,
                              CallDescriptor::Flags flags);
  void ReplaceWithBuiltinCall(Node* node, Callable c,
                              CallDescriptor::Flags flags,
                              Operator::Properties properties);
46 47
  void ReplaceWithRuntimeCall(Node* node, Runtime::FunctionId f, int args = -1);

48
  void ReplaceUnaryOpWithBuiltinCall(Node* node,
49 50
                                     Builtin builtin_without_feedback,
                                     Builtin builtin_with_feedback);
51
  void ReplaceBinaryOpWithBuiltinCall(Node* node,
52 53
                                      Builtin builtin_without_feedback,
                                      Builtin builtin_with_feedback);
54

55 56
  Zone* zone() const;
  Isolate* isolate() const;
57
  JSGraph* jsgraph() const { return jsgraph_; }
58 59 60
  Graph* graph() const;
  CommonOperatorBuilder* common() const;
  MachineOperatorBuilder* machine() const;
61
  JSHeapBroker* broker() const { return broker_; }
62 63

 private:
64
  JSGraph* const jsgraph_;
65
  JSHeapBroker* const broker_;
66
};
67 68 69 70

}  // namespace compiler
}  // namespace internal
}  // namespace v8
71 72

#endif  // V8_COMPILER_JS_GENERIC_LOWERING_H_