Upstream version 10.39.233.0
[platform/framework/web/crosswalk.git] / src / v8 / src / compiler / js-generic-lowering.h
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/v8.h"
9
10 #include "src/allocation.h"
11 #include "src/code-factory.h"
12 #include "src/compiler/graph.h"
13 #include "src/compiler/graph-reducer.h"
14 #include "src/compiler/js-graph.h"
15 #include "src/compiler/opcodes.h"
16
17 namespace v8 {
18 namespace internal {
19 namespace compiler {
20
21 // Forward declarations.
22 class CommonOperatorBuilder;
23 class MachineOperatorBuilder;
24 class Linkage;
25
26 // Lowers JS-level operators to runtime and IC calls in the "generic" case.
27 class JSGenericLowering : public Reducer {
28  public:
29   JSGenericLowering(CompilationInfo* info, JSGraph* graph);
30   virtual ~JSGenericLowering() {}
31
32   virtual Reduction Reduce(Node* node);
33
34  protected:
35 #define DECLARE_LOWER(x) void Lower##x(Node* node);
36   // Dispatched depending on opcode.
37   ALL_OP_LIST(DECLARE_LOWER)
38 #undef DECLARE_LOWER
39
40   // Helpers to create new constant nodes.
41   Node* SmiConstant(int immediate);
42   Node* Int32Constant(int immediate);
43   Node* CodeConstant(Handle<Code> code);
44   Node* FunctionConstant(Handle<JSFunction> function);
45   Node* ExternalConstant(ExternalReference ref);
46
47   // Helpers to patch existing nodes in the graph.
48   void PatchOperator(Node* node, const Operator* new_op);
49   void PatchInsertInput(Node* node, int index, Node* input);
50
51   // Helpers to replace existing nodes with a generic call.
52   void ReplaceWithCompareIC(Node* node, Token::Value token, bool pure);
53   void ReplaceWithStubCall(Node* node, Callable c, CallDescriptor::Flags flags);
54   void ReplaceWithBuiltinCall(Node* node, Builtins::JavaScript id, int args);
55   void ReplaceWithRuntimeCall(Node* node, Runtime::FunctionId f, int args = -1);
56
57   Zone* zone() const { return graph()->zone(); }
58   Isolate* isolate() const { return zone()->isolate(); }
59   JSGraph* jsgraph() const { return jsgraph_; }
60   Graph* graph() const { return jsgraph()->graph(); }
61   Linkage* linkage() const { return linkage_; }
62   CompilationInfo* info() const { return info_; }
63   CommonOperatorBuilder* common() const { return jsgraph()->common(); }
64   MachineOperatorBuilder* machine() const { return jsgraph()->machine(); }
65
66  private:
67   CompilationInfo* info_;
68   JSGraph* jsgraph_;
69   Linkage* linkage_;
70   SetOncePointer<Node> centrystub_constant_;
71 };
72
73 }  // namespace compiler
74 }  // namespace internal
75 }  // namespace v8
76
77 #endif  // V8_COMPILER_JS_GENERIC_LOWERING_H_