Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(68)

Side by Side Diff: src/compiler/js-operator.h

Issue 426233002: Land the Fan (disabled) (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2013 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_OPERATOR_H_
6 #define V8_COMPILER_JS_OPERATOR_H_
7
8 #include "src/compiler/opcodes.h"
9 #include "src/compiler/operator.h"
10 #include "src/unique.h"
11 #include "src/zone.h"
12
13 namespace v8 {
14 namespace internal {
15 namespace compiler {
16
17 // Defines the location of a context slot relative to a specific scope. This is
18 // used as a parameter by JSLoadContext and JSStoreContext operators and allows
19 // accessing a context-allocated variable without keeping track of the scope.
20 class ContextAccess {
21 public:
22 ContextAccess(int depth, int index, bool immutable)
23 : immutable_(immutable), depth_(depth), index_(index) {
24 ASSERT(0 <= depth && depth <= kMaxUInt16);
25 ASSERT(0 <= index && static_cast<uint32_t>(index) <= kMaxUInt32);
26 }
27 int depth() const { return depth_; }
28 int index() const { return index_; }
29 bool immutable() const { return immutable_; }
30
31 private:
32 // For space reasons, we keep this tightly packed, otherwise we could just use
33 // a simple int/int/bool POD.
34 const bool immutable_;
35 const uint16_t depth_;
36 const uint32_t index_;
37 };
38
39 // Defines the arity and the call flags for a JavaScript function call. This is
40 // used as a parameter by JSCall operators.
41 struct CallParameters {
42 int arity;
43 CallFunctionFlags flags;
44 };
45
46 // Interface for building JavaScript-level operators, e.g. directly from the
47 // AST. Most operators have no parameters, thus can be globally shared for all
48 // graphs.
49 class JSOperatorBuilder {
50 public:
51 explicit JSOperatorBuilder(Zone* zone) : zone_(zone) { }
52
53 #define SIMPLE(name, properties, inputs, outputs) \
54 return new (zone_) \
55 SimpleOperator(IrOpcode::k##name, properties, inputs, outputs, #name);
56
57 #define NOPROPS(name, inputs, outputs) \
58 SIMPLE(name, Operator::kNoProperties, inputs, outputs)
59
60 #define OP1(name, ptype, pname, properties, inputs, outputs) \
61 return new(zone_) Operator1<ptype>( \
62 IrOpcode::k##name, properties, inputs, outputs, #name, pname)
63
64 #define BINOP(name) NOPROPS(name, 2, 1)
65 #define UNOP(name) NOPROPS(name, 1, 1)
66
67 #define PURE_BINOP(name) SIMPLE(name, Operator::kPure, 2, 1)
68
69 Operator* Equal() { BINOP(JSEqual); }
70 Operator* NotEqual() { BINOP(JSNotEqual); }
71 Operator* StrictEqual() { PURE_BINOP(JSStrictEqual); }
72 Operator* StrictNotEqual() { PURE_BINOP(JSStrictNotEqual); }
73 Operator* LessThan() { BINOP(JSLessThan); }
74 Operator* GreaterThan() { BINOP(JSGreaterThan); }
75 Operator* LessThanOrEqual() { BINOP(JSLessThanOrEqual); }
76 Operator* GreaterThanOrEqual() { BINOP(JSGreaterThanOrEqual); }
77 Operator* BitwiseOr() { BINOP(JSBitwiseOr); }
78 Operator* BitwiseXor() { BINOP(JSBitwiseXor); }
79 Operator* BitwiseAnd() { BINOP(JSBitwiseAnd); }
80 Operator* ShiftLeft() { BINOP(JSShiftLeft); }
81 Operator* ShiftRight() { BINOP(JSShiftRight); }
82 Operator* ShiftRightLogical() { BINOP(JSShiftRightLogical); }
83 Operator* Add() { BINOP(JSAdd); }
84 Operator* Subtract() { BINOP(JSSubtract); }
85 Operator* Multiply() { BINOP(JSMultiply); }
86 Operator* Divide() { BINOP(JSDivide); }
87 Operator* Modulus() { BINOP(JSModulus); }
88
89 Operator* UnaryNot() { UNOP(JSUnaryNot); }
90 Operator* ToBoolean() { UNOP(JSToBoolean); }
91 Operator* ToNumber() { UNOP(JSToNumber); }
92 Operator* ToString() { UNOP(JSToString); }
93 Operator* ToName() { UNOP(JSToName); }
94 Operator* ToObject() { UNOP(JSToObject); }
95 Operator* Yield() { UNOP(JSYield); }
96
97 Operator* Create() { SIMPLE(JSCreate, Operator::kEliminatable, 0, 1); }
98
99 Operator* Call(int arguments, CallFunctionFlags flags) {
100 CallParameters parameters = {arguments, flags};
101 OP1(JSCallFunction, CallParameters, parameters,
102 Operator::kNoProperties, arguments, 1);
103 }
104
105 Operator* CallNew(int arguments) {
106 return new (zone_)
107 Operator1<int>(IrOpcode::kJSCallConstruct, Operator::kNoProperties,
108 arguments, 1, "JSCallConstruct", arguments);
109 }
110
111 Operator* LoadProperty() { BINOP(JSLoadProperty); }
112 Operator* LoadNamed(PrintableUnique<Name> name) {
113 OP1(JSLoadNamed, PrintableUnique<Name>, name,
114 Operator::kNoProperties, 1, 1);
115 }
116
117 Operator* StoreProperty() { NOPROPS(JSStoreProperty, 3, 0); }
118 Operator* StoreNamed(PrintableUnique<Name> name) {
119 OP1(JSStoreNamed, PrintableUnique<Name>, name,
120 Operator::kNoProperties, 2, 0);
121 }
122
123 Operator* DeleteProperty(StrictMode strict_mode) {
124 OP1(JSDeleteProperty, StrictMode, strict_mode,
125 Operator::kNoProperties, 2, 1);
126 }
127
128 Operator* HasProperty() { NOPROPS(JSHasProperty, 2, 1); }
129
130 Operator* LoadContext(uint16_t depth, uint32_t index, bool immutable) {
131 ContextAccess access(depth, index, immutable);
132 OP1(JSLoadContext, ContextAccess,
133 access, Operator::kEliminatable | Operator::kNoWrite, 1, 1);
134 }
135 Operator* StoreContext(uint16_t depth, uint32_t index) {
136 ContextAccess access(depth, index, false);
137 OP1(JSStoreContext, ContextAccess,
138 access, Operator::kNoProperties, 2, 1);
139 }
140
141 Operator* TypeOf() { SIMPLE(JSTypeOf, Operator::kPure, 1, 1); }
142 Operator* InstanceOf() { NOPROPS(JSInstanceOf, 2, 1); }
143 Operator* Debugger() { NOPROPS(JSDebugger, 0, 0); }
144
145 // TODO(titzer): nail down the static parts of each of these context flavors.
146 Operator* CreateFunctionContext() { NOPROPS(JSCreateFunctionContext, 1, 1); }
147 Operator* CreateCatchContext(PrintableUnique<String> name) {
148 OP1(JSCreateCatchContext, PrintableUnique<String>, name,
149 Operator::kNoProperties, 1, 1);
150 }
151 Operator* CreateWithContext() { NOPROPS(JSCreateWithContext, 2, 1); }
152 Operator* CreateBlockContext() { NOPROPS(JSCreateBlockContext, 2, 1); }
153 Operator* CreateModuleContext() { NOPROPS(JSCreateModuleContext, 2, 1); }
154 Operator* CreateGlobalContext() { NOPROPS(JSCreateGlobalContext, 2, 1); }
155
156 Operator* Runtime(Runtime::FunctionId function, int arguments) {
157 const Runtime::Function* f = Runtime::FunctionForId(function);
158 ASSERT(f->nargs == -1 || f->nargs == arguments);
159 OP1(JSCallRuntime, Runtime::FunctionId, function,
160 Operator::kNoProperties, arguments, f->result_size);
161 }
162
163 #undef SIMPLE
164 #undef NOPROPS
165 #undef OP1
166 #undef BINOP
167 #undef UNOP
168
169 private:
170 Zone* zone_;
171 };
172
173 // Specialization for static parameters of type {ContextAccess}.
174 template <>
175 struct StaticParameterTraits<ContextAccess> {
176 static OStream& PrintTo(OStream& os, ContextAccess val) { // NOLINT
177 return os << val.depth() << "," << val.index()
178 << (val.immutable() ? ",imm" : "");
179 }
180 static int HashCode(ContextAccess val) {
181 return (val.depth() << 16) | (val.index() & 0xffff);
182 }
183 static bool Equals(ContextAccess a, ContextAccess b) {
184 return a.immutable() == b.immutable() && a.depth() == b.depth() &&
185 a.index() == b.index();
186 }
187 };
188
189 // Specialization for static parameters of type {Runtime::FunctionId}.
190 template <>
191 struct StaticParameterTraits<Runtime::FunctionId> {
192 static OStream& PrintTo(OStream& os, Runtime::FunctionId val) { // NOLINT
193 const Runtime::Function* f = Runtime::FunctionForId(val);
194 return os << (f->name ? f->name : "?Runtime?");
195 }
196 static int HashCode(Runtime::FunctionId val) {
197 return static_cast<int>(val);
198 }
199 static bool Equals(Runtime::FunctionId a, Runtime::FunctionId b) {
200 return a == b;
201 }
202 };
203
204 } } } // namespace v8::internal::compiler
205
206 #endif // V8_COMPILER_JS_OPERATOR_H_
OLDNEW
« no previous file with comments | « src/compiler/js-graph.cc ('k') | src/compiler/js-typed-lowering.h » ('j') | src/lithium-inl.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698