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/compiler/graph.h"
12 #include "src/compiler/js-graph.h"
13 #include "src/compiler/lowering-builder.h"
14 #include "src/compiler/opcodes.h"
15 #include "src/unique.h"
20 // Forward declarations.
21 class HydrogenCodeStub;
25 // Forward declarations.
26 class CommonOperatorBuilder;
27 class MachineOperatorBuilder;
30 // Lowers JS-level operators to runtime and IC calls in the "generic" case.
31 class JSGenericLowering : public LoweringBuilder {
33 JSGenericLowering(CompilationInfo* info, JSGraph* graph,
34 MachineOperatorBuilder* machine,
35 SourcePositionTable* source_positions);
36 virtual ~JSGenericLowering() {}
38 virtual void Lower(Node* node);
41 // Dispatched depending on opcode.
42 #define DECLARE_LOWER(x) Node* Lower##x(Node* node);
43 ALL_OP_LIST(DECLARE_LOWER)
46 // Helpers to create new constant nodes.
47 Node* SmiConstant(int immediate);
48 Node* Int32Constant(int immediate);
49 Node* CodeConstant(Handle<Code> code);
50 Node* FunctionConstant(Handle<JSFunction> function);
51 Node* ExternalConstant(ExternalReference ref);
53 // Helpers to patch existing nodes in the graph.
54 void PatchOperator(Node* node, Operator* new_op);
55 void PatchInsertInput(Node* node, int index, Node* input);
57 // Helpers to replace existing nodes with a generic call.
58 void ReplaceWithCompareIC(Node* node, Token::Value token, bool pure);
59 void ReplaceWithICStubCall(Node* node, HydrogenCodeStub* stub);
60 void ReplaceWithBuiltinCall(Node* node, Builtins::JavaScript id, int args);
61 void ReplaceWithRuntimeCall(Node* node, Runtime::FunctionId f, int args = -1);
63 Zone* zone() const { return graph()->zone(); }
64 Isolate* isolate() const { return zone()->isolate(); }
65 JSGraph* jsgraph() const { return jsgraph_; }
66 Graph* graph() const { return jsgraph()->graph(); }
67 Linkage* linkage() const { return linkage_; }
68 CompilationInfo* info() const { return info_; }
69 CommonOperatorBuilder* common() const { return jsgraph()->common(); }
70 MachineOperatorBuilder* machine() const { return machine_; }
73 CompilationInfo* info_;
76 MachineOperatorBuilder* machine_;
77 SetOncePointer<Node> centrystub_constant_;
81 } // namespace v8::internal::compiler
83 #endif // V8_COMPILER_JS_GENERIC_LOWERING_H_