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.
5 #ifndef V8_COMPILER_JS_GENERIC_LOWERING_H_
6 #define V8_COMPILER_JS_GENERIC_LOWERING_H_
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"
21 // Forward declarations.
22 class CommonOperatorBuilder;
23 class MachineOperatorBuilder;
26 // Lowers JS-level operators to runtime and IC calls in the "generic" case.
27 class JSGenericLowering : public Reducer {
29 JSGenericLowering(CompilationInfo* info, JSGraph* graph);
30 virtual ~JSGenericLowering() {}
32 virtual Reduction Reduce(Node* node);
35 #define DECLARE_LOWER(x) void Lower##x(Node* node);
36 // Dispatched depending on opcode.
37 ALL_OP_LIST(DECLARE_LOWER)
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);
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);
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);
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(); }
67 CompilationInfo* info_;
70 SetOncePointer<Node> centrystub_constant_;
73 } // namespace compiler
74 } // namespace internal
77 #endif // V8_COMPILER_JS_GENERIC_LOWERING_H_