V8 Project
js-generic-lowering.h
Go to the documentation of this file.
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"
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:
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.
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:
71 };
72 
73 } // namespace compiler
74 } // namespace internal
75 } // namespace v8
76 
77 #endif // V8_COMPILER_JS_GENERIC_LOWERING_H_
Isolate * isolate() const
Definition: zone.h:68
void ReplaceWithBuiltinCall(Node *node, Builtins::JavaScript id, int args)
MachineOperatorBuilder * machine() const
Node * FunctionConstant(Handle< JSFunction > function)
void ReplaceWithRuntimeCall(Node *node, Runtime::FunctionId f, int args=-1)
Node * ExternalConstant(ExternalReference ref)
void PatchOperator(Node *node, const Operator *new_op)
CommonOperatorBuilder * common() const
void ReplaceWithCompareIC(Node *node, Token::Value token, bool pure)
void PatchInsertInput(Node *node, int index, Node *input)
void ReplaceWithStubCall(Node *node, Callable c, CallDescriptor::Flags flags)
JSGenericLowering(CompilationInfo *info, JSGraph *graph)
MachineOperatorBuilder * machine()
Definition: js-graph.h:88
CommonOperatorBuilder * common()
Definition: js-graph.h:87
#define DECLARE_LOWER(x)
Debugger support for the V8 JavaScript engine.
Definition: accessors.cc:20
#define ALL_OP_LIST(V)
Definition: opcodes.h:233