blob: 38ee431f15b94957c5a38c6426c7e4fd4ef6f1a1 [file] [log] [blame]
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001// 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
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008#include "src/code-factory.h"
Ben Murdochb8a8cc12014-11-26 15:28:44 +00009#include "src/compiler/graph-reducer.h"
Emily Bernierd0a1eb72015-03-24 16:35:39 -040010#include "src/compiler/linkage.h"
Ben Murdochb8a8cc12014-11-26 15:28:44 +000011#include "src/compiler/opcodes.h"
12
13namespace v8 {
14namespace internal {
15namespace compiler {
16
17// Forward declarations.
18class CommonOperatorBuilder;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000019class JSGraph;
Ben Murdochb8a8cc12014-11-26 15:28:44 +000020class MachineOperatorBuilder;
21class Linkage;
22
Emily Bernierd0a1eb72015-03-24 16:35:39 -040023
Ben Murdochb8a8cc12014-11-26 15:28:44 +000024// Lowers JS-level operators to runtime and IC calls in the "generic" case.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000025class JSGenericLowering final : public Reducer {
Ben Murdochb8a8cc12014-11-26 15:28:44 +000026 public:
Ben Murdochc5610432016-08-08 18:44:38 +010027 explicit JSGenericLowering(JSGraph* jsgraph);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000028 ~JSGenericLowering() final;
Ben Murdochb8a8cc12014-11-26 15:28:44 +000029
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000030 Reduction Reduce(Node* node) final;
Ben Murdochb8a8cc12014-11-26 15:28:44 +000031
32 protected:
33#define DECLARE_LOWER(x) void Lower##x(Node* node);
34 // Dispatched depending on opcode.
Emily Bernierd0a1eb72015-03-24 16:35:39 -040035 JS_OP_LIST(DECLARE_LOWER)
Ben Murdochb8a8cc12014-11-26 15:28:44 +000036#undef DECLARE_LOWER
37
Ben Murdochb8a8cc12014-11-26 15:28:44 +000038 // Helpers to replace existing nodes with a generic call.
Ben Murdochb8a8cc12014-11-26 15:28:44 +000039 void ReplaceWithStubCall(Node* node, Callable c, CallDescriptor::Flags flags);
Ben Murdochc5610432016-08-08 18:44:38 +010040 void ReplaceWithStubCall(Node* node, Callable c, CallDescriptor::Flags flags,
41 Operator::Properties properties);
Ben Murdochb8a8cc12014-11-26 15:28:44 +000042 void ReplaceWithRuntimeCall(Node* node, Runtime::FunctionId f, int args = -1);
43
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000044 Zone* zone() const;
45 Isolate* isolate() const;
Ben Murdochb8a8cc12014-11-26 15:28:44 +000046 JSGraph* jsgraph() const { return jsgraph_; }
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000047 Graph* graph() const;
48 CommonOperatorBuilder* common() const;
49 MachineOperatorBuilder* machine() const;
Ben Murdochb8a8cc12014-11-26 15:28:44 +000050
51 private:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000052 JSGraph* const jsgraph_;
Ben Murdochb8a8cc12014-11-26 15:28:44 +000053};
54
55} // namespace compiler
56} // namespace internal
57} // namespace v8
58
59#endif // V8_COMPILER_JS_GENERIC_LOWERING_H_