V8 Project
js-operator.h
Go to the documentation of this file.
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/linkage.h"
9 #include "src/compiler/opcodes.h"
10 #include "src/compiler/operator.h"
11 #include "src/unique.h"
12 #include "src/zone.h"
13 
14 namespace v8 {
15 namespace internal {
16 namespace compiler {
17 
18 // Defines the location of a context slot relative to a specific scope. This is
19 // used as a parameter by JSLoadContext and JSStoreContext operators and allows
20 // accessing a context-allocated variable without keeping track of the scope.
22  public:
25  DCHECK(0 <= depth && depth <= kMaxUInt16);
26  DCHECK(0 <= index && static_cast<uint32_t>(index) <= kMaxUInt32);
27  }
28  int depth() const { return depth_; }
29  int index() const { return index_; }
30  bool immutable() const { return immutable_; }
31 
32  private:
33  // For space reasons, we keep this tightly packed, otherwise we could just use
34  // a simple int/int/bool POD.
35  const bool immutable_;
38 };
39 
40 // Defines the property being loaded from an object by a named load. This is
41 // used as a parameter by JSLoadNamed operators.
45 };
46 
47 // Defines the arity and the call flags for a JavaScript function call. This is
48 // used as a parameter by JSCall operators.
50  int arity;
52 };
53 
54 // Defines the property being stored to an object by a named store. This is
55 // used as a parameter by JSStoreNamed operators.
59 };
60 
61 // Interface for building JavaScript-level operators, e.g. directly from the
62 // AST. Most operators have no parameters, thus can be globally shared for all
63 // graphs.
65  public:
66  explicit JSOperatorBuilder(Zone* zone) : zone_(zone) {}
67 
68 #define SIMPLE(name, properties, inputs, outputs) \
69  return new (zone_) \
70  SimpleOperator(IrOpcode::k##name, properties, inputs, outputs, #name);
71 
72 #define NOPROPS(name, inputs, outputs) \
73  SIMPLE(name, Operator::kNoProperties, inputs, outputs)
74 
75 #define OP1(name, ptype, pname, properties, inputs, outputs) \
76  return new (zone_) Operator1<ptype>(IrOpcode::k##name, properties, inputs, \
77  outputs, #name, pname)
78 
79 #define BINOP(name) NOPROPS(name, 2, 1)
80 #define UNOP(name) NOPROPS(name, 1, 1)
81 
82 #define PURE_BINOP(name) SIMPLE(name, Operator::kPure, 2, 1)
83 
84  const Operator* Equal() { BINOP(JSEqual); }
85  const Operator* NotEqual() { BINOP(JSNotEqual); }
86  const Operator* StrictEqual() { PURE_BINOP(JSStrictEqual); }
87  const Operator* StrictNotEqual() { PURE_BINOP(JSStrictNotEqual); }
88  const Operator* LessThan() { BINOP(JSLessThan); }
89  const Operator* GreaterThan() { BINOP(JSGreaterThan); }
90  const Operator* LessThanOrEqual() { BINOP(JSLessThanOrEqual); }
91  const Operator* GreaterThanOrEqual() { BINOP(JSGreaterThanOrEqual); }
92  const Operator* BitwiseOr() { BINOP(JSBitwiseOr); }
93  const Operator* BitwiseXor() { BINOP(JSBitwiseXor); }
94  const Operator* BitwiseAnd() { BINOP(JSBitwiseAnd); }
95  const Operator* ShiftLeft() { BINOP(JSShiftLeft); }
96  const Operator* ShiftRight() { BINOP(JSShiftRight); }
97  const Operator* ShiftRightLogical() { BINOP(JSShiftRightLogical); }
98  const Operator* Add() { BINOP(JSAdd); }
99  const Operator* Subtract() { BINOP(JSSubtract); }
100  const Operator* Multiply() { BINOP(JSMultiply); }
101  const Operator* Divide() { BINOP(JSDivide); }
102  const Operator* Modulus() { BINOP(JSModulus); }
103 
104  const Operator* UnaryNot() { UNOP(JSUnaryNot); }
105  const Operator* ToBoolean() { UNOP(JSToBoolean); }
106  const Operator* ToNumber() { UNOP(JSToNumber); }
107  const Operator* ToString() { UNOP(JSToString); }
108  const Operator* ToName() { UNOP(JSToName); }
109  const Operator* ToObject() { UNOP(JSToObject); }
110  const Operator* Yield() { UNOP(JSYield); }
111 
112  const Operator* Create() { SIMPLE(JSCreate, Operator::kEliminatable, 0, 1); }
113 
114  const Operator* Call(int arguments, CallFunctionFlags flags) {
115  CallParameters parameters = {arguments, flags};
116  OP1(JSCallFunction, CallParameters, parameters, Operator::kNoProperties,
117  arguments, 1);
118  }
119 
120  const Operator* CallNew(int arguments) {
121  return new (zone_)
122  Operator1<int>(IrOpcode::kJSCallConstruct, Operator::kNoProperties,
123  arguments, 1, "JSCallConstruct", arguments);
124  }
125 
126  const Operator* LoadProperty() { BINOP(JSLoadProperty); }
128  ContextualMode contextual_mode = NOT_CONTEXTUAL) {
129  LoadNamedParameters parameters = {name, contextual_mode};
130  OP1(JSLoadNamed, LoadNamedParameters, parameters, Operator::kNoProperties,
131  1, 1);
132  }
133 
134  const Operator* StoreProperty(StrictMode strict_mode) {
135  OP1(JSStoreProperty, StrictMode, strict_mode, Operator::kNoProperties, 3,
136  0);
137  }
138 
140  StoreNamedParameters parameters = {strict_mode, name};
141  OP1(JSStoreNamed, StoreNamedParameters, parameters, Operator::kNoProperties,
142  2, 0);
143  }
144 
145  const Operator* DeleteProperty(StrictMode strict_mode) {
146  OP1(JSDeleteProperty, StrictMode, strict_mode, Operator::kNoProperties, 2,
147  1);
148  }
149 
150  const Operator* HasProperty() { NOPROPS(JSHasProperty, 2, 1); }
151 
152  const Operator* LoadContext(uint16_t depth, uint32_t index, bool immutable) {
153  ContextAccess access(depth, index, immutable);
154  OP1(JSLoadContext, ContextAccess, access,
156  }
157  const Operator* StoreContext(uint16_t depth, uint32_t index) {
158  ContextAccess access(depth, index, false);
159  OP1(JSStoreContext, ContextAccess, access, Operator::kNoProperties, 2, 0);
160  }
161 
162  const Operator* TypeOf() { SIMPLE(JSTypeOf, Operator::kPure, 1, 1); }
163  const Operator* InstanceOf() { NOPROPS(JSInstanceOf, 2, 1); }
164  const Operator* Debugger() { NOPROPS(JSDebugger, 0, 0); }
165 
166  // TODO(titzer): nail down the static parts of each of these context flavors.
168  NOPROPS(JSCreateFunctionContext, 1, 1);
169  }
171  OP1(JSCreateCatchContext, Unique<String>, name, Operator::kNoProperties, 1,
172  1);
173  }
174  const Operator* CreateWithContext() { NOPROPS(JSCreateWithContext, 2, 1); }
175  const Operator* CreateBlockContext() { NOPROPS(JSCreateBlockContext, 2, 1); }
177  NOPROPS(JSCreateModuleContext, 2, 1);
178  }
180  NOPROPS(JSCreateGlobalContext, 2, 1);
181  }
182 
183  const Operator* Runtime(Runtime::FunctionId function, int arguments) {
184  const Runtime::Function* f = Runtime::FunctionForId(function);
185  DCHECK(f->nargs == -1 || f->nargs == arguments);
186  OP1(JSCallRuntime, Runtime::FunctionId, function, Operator::kNoProperties,
187  arguments, f->result_size);
188  }
189 
190 #undef SIMPLE
191 #undef NOPROPS
192 #undef OP1
193 #undef BINOP
194 #undef UNOP
195 
196  private:
198 };
199 
200 // Specialization for static parameters of type {ContextAccess}.
201 template <>
203  static OStream& PrintTo(OStream& os, ContextAccess val) { // NOLINT
204  return os << val.depth() << "," << val.index()
205  << (val.immutable() ? ",imm" : "");
206  }
207  static int HashCode(ContextAccess val) {
208  return (val.depth() << 16) | (val.index() & 0xffff);
209  }
210  static bool Equals(ContextAccess a, ContextAccess b) {
211  return a.immutable() == b.immutable() && a.depth() == b.depth() &&
212  a.index() == b.index();
213  }
214 };
215 
216 // Specialization for static parameters of type {Runtime::FunctionId}.
217 template <>
218 struct StaticParameterTraits<Runtime::FunctionId> {
219  static OStream& PrintTo(OStream& os, Runtime::FunctionId val) { // NOLINT
221  return os << (f->name ? f->name : "?Runtime?");
222  }
223  static int HashCode(Runtime::FunctionId val) { return static_cast<int>(val); }
225  return a == b;
226  }
227 };
228 
229 } // namespace compiler
230 } // namespace internal
231 } // namespace v8
232 
233 #endif // V8_COMPILER_JS_OPERATOR_H_
static const Function * FunctionForId(FunctionId id)
Definition: runtime.cc:9312
ContextAccess(int depth, int index, bool immutable)
Definition: js-operator.h:23
const Operator * CreateCatchContext(Unique< String > name)
Definition: js-operator.h:170
const Operator * LoadNamed(Unique< Name > name, ContextualMode contextual_mode=NOT_CONTEXTUAL)
Definition: js-operator.h:127
const Operator * Runtime(Runtime::FunctionId function, int arguments)
Definition: js-operator.h:183
const Operator * LoadContext(uint16_t depth, uint32_t index, bool immutable)
Definition: js-operator.h:152
const Operator * StoreProperty(StrictMode strict_mode)
Definition: js-operator.h:134
const Operator * CallNew(int arguments)
Definition: js-operator.h:120
const Operator * StoreContext(uint16_t depth, uint32_t index)
Definition: js-operator.h:157
const Operator * DeleteProperty(StrictMode strict_mode)
Definition: js-operator.h:145
const Operator * Call(int arguments, CallFunctionFlags flags)
Definition: js-operator.h:114
const Operator * StoreNamed(StrictMode strict_mode, Unique< Name > name)
Definition: js-operator.h:139
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes enable context specialization in TurboFan execution budget before interrupt is triggered max percentage of megamorphic generic ICs to allow optimization enable use of SAHF instruction if enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable use of MLS instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long enable alignment of csp to bytes on platforms which prefer the register to always be expose gc extension under the specified name show built in functions in stack traces use random jit cookie to mask large constants minimum length for automatic enable preparsing CPU profiler sampling interval in microseconds trace out of bounds accesses to external arrays default size of stack region v8 is allowed to maximum length of function source code printed in a stack trace min size of a semi the new space consists of two semi spaces print one trace line following each garbage collection do not print trace line after scavenger collection print cumulative GC statistics in name
#define PURE_BINOP(name)
Definition: js-operator.h:82
#define OP1(name, ptype, pname, properties, inputs, outputs)
Definition: js-operator.h:75
#define SIMPLE(name, properties, inputs, outputs)
Definition: js-operator.h:68
#define UNOP(name)
Definition: js-operator.h:80
#define BINOP(name)
Definition: js-operator.h:79
#define NOPROPS(name, inputs, outputs)
Definition: js-operator.h:72
#define DCHECK(condition)
Definition: logging.h:205
unsigned short uint16_t
Definition: unicode.cc:23
@ NOT_CONTEXTUAL
Definition: objects.h:174
const int kMaxUInt16
Definition: globals.h:117
const uint32_t kMaxUInt32
Definition: globals.h:120
Debugger support for the V8 JavaScript engine.
Definition: accessors.cc:20
static bool Equals(ContextAccess a, ContextAccess b)
Definition: js-operator.h:210
static OStream & PrintTo(OStream &os, ContextAccess val)
Definition: js-operator.h:203
static OStream & PrintTo(OStream &os, Runtime::FunctionId val)
Definition: js-operator.h:219
static bool Equals(Runtime::FunctionId a, Runtime::FunctionId b)
Definition: js-operator.h:224