OLD | NEW |
(Empty) | |
| 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 #include "src/compiler/js-operator.h" |
| 6 |
| 7 #include "src/base/lazy-instance.h" |
| 8 #include "src/compiler/opcodes.h" |
| 9 #include "src/compiler/operator.h" |
| 10 |
| 11 namespace v8 { |
| 12 namespace internal { |
| 13 namespace compiler { |
| 14 |
| 15 const CallFunctionParameters& CallFunctionParametersOf(const Operator* op) { |
| 16 DCHECK_EQ(IrOpcode::kJSCallFunction, op->opcode()); |
| 17 return OpParameter<CallFunctionParameters>(op); |
| 18 } |
| 19 |
| 20 |
| 21 const CallRuntimeParameters& CallRuntimeParametersOf(const Operator* op) { |
| 22 DCHECK_EQ(IrOpcode::kJSCallRuntime, op->opcode()); |
| 23 return OpParameter<CallRuntimeParameters>(op); |
| 24 } |
| 25 |
| 26 |
| 27 bool operator==(const ContextAccess& lhs, const ContextAccess& rhs) { |
| 28 return lhs.depth() == rhs.depth() && lhs.index() == rhs.index() && |
| 29 lhs.immutable() == rhs.immutable(); |
| 30 } |
| 31 |
| 32 |
| 33 bool operator!=(const ContextAccess& lhs, const ContextAccess& rhs) { |
| 34 return !(lhs == rhs); |
| 35 } |
| 36 |
| 37 |
| 38 const ContextAccess& ContextAccessOf(const Operator* op) { |
| 39 DCHECK(op->opcode() == IrOpcode::kJSLoadContext || |
| 40 op->opcode() == IrOpcode::kJSStoreContext); |
| 41 return OpParameter<ContextAccess>(op); |
| 42 } |
| 43 |
| 44 |
| 45 const LoadNamedParameters& LoadNamedParametersOf(const Operator* op) { |
| 46 DCHECK_EQ(IrOpcode::kJSLoadNamed, op->opcode()); |
| 47 return OpParameter<LoadNamedParameters>(op); |
| 48 } |
| 49 |
| 50 |
| 51 const StoreNamedParameters& StoreNamedParametersOf(const Operator* op) { |
| 52 DCHECK_EQ(IrOpcode::kJSStoreNamed, op->opcode()); |
| 53 return OpParameter<StoreNamedParameters>(op); |
| 54 } |
| 55 |
| 56 |
| 57 // Specialization for static parameters of type {ContextAccess}. |
| 58 template <> |
| 59 struct StaticParameterTraits<ContextAccess> { |
| 60 static OStream& PrintTo(OStream& os, const ContextAccess& access) { |
| 61 return os << access.depth() << "," << access.index() |
| 62 << (access.immutable() ? ",imm" : ""); |
| 63 } |
| 64 static int HashCode(const ContextAccess& access) { |
| 65 return (access.depth() << 16) | (access.index() & 0xffff); |
| 66 } |
| 67 static bool Equals(const ContextAccess& lhs, const ContextAccess& rhs) { |
| 68 return lhs == rhs; |
| 69 } |
| 70 }; |
| 71 |
| 72 |
| 73 // Specialization for static parameters of type {Runtime::FunctionId}. |
| 74 template <> |
| 75 struct StaticParameterTraits<Runtime::FunctionId> { |
| 76 static OStream& PrintTo(OStream& os, Runtime::FunctionId val) { |
| 77 const Runtime::Function* f = Runtime::FunctionForId(val); |
| 78 return os << (f->name ? f->name : "?Runtime?"); |
| 79 } |
| 80 static int HashCode(Runtime::FunctionId val) { return static_cast<int>(val); } |
| 81 static bool Equals(Runtime::FunctionId a, Runtime::FunctionId b) { |
| 82 return a == b; |
| 83 } |
| 84 }; |
| 85 |
| 86 |
| 87 #define SHARED_OP_LIST(V) \ |
| 88 V(Equal, Operator::kNoProperties, 2, 1) \ |
| 89 V(NotEqual, Operator::kNoProperties, 2, 1) \ |
| 90 V(StrictEqual, Operator::kPure, 2, 1) \ |
| 91 V(StrictNotEqual, Operator::kPure, 2, 1) \ |
| 92 V(LessThan, Operator::kNoProperties, 2, 1) \ |
| 93 V(GreaterThan, Operator::kNoProperties, 2, 1) \ |
| 94 V(LessThanOrEqual, Operator::kNoProperties, 2, 1) \ |
| 95 V(GreaterThanOrEqual, Operator::kNoProperties, 2, 1) \ |
| 96 V(BitwiseOr, Operator::kNoProperties, 2, 1) \ |
| 97 V(BitwiseXor, Operator::kNoProperties, 2, 1) \ |
| 98 V(BitwiseAnd, Operator::kNoProperties, 2, 1) \ |
| 99 V(ShiftLeft, Operator::kNoProperties, 2, 1) \ |
| 100 V(ShiftRight, Operator::kNoProperties, 2, 1) \ |
| 101 V(ShiftRightLogical, Operator::kNoProperties, 2, 1) \ |
| 102 V(Add, Operator::kNoProperties, 2, 1) \ |
| 103 V(Subtract, Operator::kNoProperties, 2, 1) \ |
| 104 V(Multiply, Operator::kNoProperties, 2, 1) \ |
| 105 V(Divide, Operator::kNoProperties, 2, 1) \ |
| 106 V(Modulus, Operator::kNoProperties, 2, 1) \ |
| 107 V(UnaryNot, Operator::kNoProperties, 1, 1) \ |
| 108 V(ToBoolean, Operator::kNoProperties, 1, 1) \ |
| 109 V(ToNumber, Operator::kNoProperties, 1, 1) \ |
| 110 V(ToString, Operator::kNoProperties, 1, 1) \ |
| 111 V(ToName, Operator::kNoProperties, 1, 1) \ |
| 112 V(ToObject, Operator::kNoProperties, 1, 1) \ |
| 113 V(Yield, Operator::kNoProperties, 1, 1) \ |
| 114 V(Create, Operator::kEliminatable, 0, 1) \ |
| 115 V(LoadProperty, Operator::kNoProperties, 2, 1) \ |
| 116 V(HasProperty, Operator::kNoProperties, 2, 1) \ |
| 117 V(TypeOf, Operator::kPure, 1, 1) \ |
| 118 V(InstanceOf, Operator::kNoProperties, 2, 1) \ |
| 119 V(Debugger, Operator::kNoProperties, 0, 0) \ |
| 120 V(CreateFunctionContext, Operator::kNoProperties, 1, 1) \ |
| 121 V(CreateWithContext, Operator::kNoProperties, 2, 1) \ |
| 122 V(CreateBlockContext, Operator::kNoProperties, 2, 1) \ |
| 123 V(CreateModuleContext, Operator::kNoProperties, 2, 1) \ |
| 124 V(CreateGlobalContext, Operator::kNoProperties, 2, 1) |
| 125 |
| 126 |
| 127 struct JSOperatorBuilderImpl FINAL { |
| 128 #define SHARED(Name, properties, value_input_count, value_output_count) \ |
| 129 struct Name##Operator FINAL : public SimpleOperator { \ |
| 130 Name##Operator() \ |
| 131 : SimpleOperator(IrOpcode::kJS##Name, properties, value_input_count, \ |
| 132 value_output_count, "JS" #Name) {} \ |
| 133 }; \ |
| 134 Name##Operator k##Name##Operator; |
| 135 SHARED_OP_LIST(SHARED) |
| 136 #undef SHARED |
| 137 }; |
| 138 |
| 139 |
| 140 static base::LazyInstance<JSOperatorBuilderImpl>::type kImpl = |
| 141 LAZY_INSTANCE_INITIALIZER; |
| 142 |
| 143 |
| 144 JSOperatorBuilder::JSOperatorBuilder(Zone* zone) |
| 145 : impl_(kImpl.Get()), zone_(zone) {} |
| 146 |
| 147 |
| 148 #define SHARED(Name, properties, value_input_count, value_output_count) \ |
| 149 const Operator* JSOperatorBuilder::Name() { return &impl_.k##Name##Operator; } |
| 150 SHARED_OP_LIST(SHARED) |
| 151 #undef SHARED |
| 152 |
| 153 |
| 154 const Operator* JSOperatorBuilder::CallFunction( |
| 155 CallFunctionParameters parameters) { |
| 156 return new (zone()) Operator1<CallFunctionParameters>( |
| 157 IrOpcode::kJSCallFunction, Operator::kNoProperties, |
| 158 static_cast<int>(parameters.arity()), 1, "JSCallFunction", parameters); |
| 159 } |
| 160 |
| 161 |
| 162 const Operator* JSOperatorBuilder::CallRuntime( |
| 163 CallRuntimeParameters parameters) { |
| 164 const Runtime::Function* f = Runtime::FunctionForId(parameters.id()); |
| 165 int arguments = static_cast<int>(parameters.arity()); |
| 166 DCHECK(f->nargs == -1 || f->nargs == arguments); |
| 167 return new (zone()) Operator1<CallRuntimeParameters>( |
| 168 IrOpcode::kJSCallRuntime, Operator::kNoProperties, arguments, |
| 169 f->result_size, "JSCallRuntime", parameters); |
| 170 } |
| 171 |
| 172 |
| 173 const Operator* JSOperatorBuilder::CallConstruct(int arguments) { |
| 174 return new (zone()) |
| 175 Operator1<int>(IrOpcode::kJSCallConstruct, Operator::kNoProperties, |
| 176 arguments, 1, "JSCallConstruct", arguments); |
| 177 } |
| 178 |
| 179 |
| 180 const Operator* JSOperatorBuilder::LoadNamed( |
| 181 const LoadNamedParameters& parameters) { |
| 182 return new (zone()) Operator1<LoadNamedParameters>( |
| 183 IrOpcode::kJSLoadNamed, Operator::kNoProperties, 1, 1, "JSLoadNamed", |
| 184 parameters); |
| 185 } |
| 186 |
| 187 |
| 188 const Operator* JSOperatorBuilder::StoreProperty(StrictMode strict_mode) { |
| 189 return new (zone()) |
| 190 Operator1<StrictMode>(IrOpcode::kJSStoreProperty, Operator::kNoProperties, |
| 191 3, 0, "JSStoreProperty", strict_mode); |
| 192 } |
| 193 |
| 194 |
| 195 const Operator* JSOperatorBuilder::StoreNamed( |
| 196 const StoreNamedParameters& parameters) { |
| 197 return new (zone()) Operator1<StoreNamedParameters>( |
| 198 IrOpcode::kJSStoreNamed, Operator::kNoProperties, 2, 0, "JSStoreNamed", |
| 199 parameters); |
| 200 } |
| 201 |
| 202 |
| 203 const Operator* JSOperatorBuilder::LoadContext(const ContextAccess& access) { |
| 204 return new (zone()) Operator1<ContextAccess>( |
| 205 IrOpcode::kJSLoadContext, Operator::kEliminatable | Operator::kNoWrite, 1, |
| 206 1, "JSLoadContext", access); |
| 207 } |
| 208 |
| 209 |
| 210 const Operator* JSOperatorBuilder::DeleteProperty(StrictMode strict_mode) { |
| 211 return new (zone()) Operator1<StrictMode>(IrOpcode::kJSDeleteProperty, |
| 212 Operator::kNoProperties, 2, 1, |
| 213 "JSDeleteProperty", strict_mode); |
| 214 } |
| 215 |
| 216 |
| 217 const Operator* JSOperatorBuilder::StoreContext(const ContextAccess& access) { |
| 218 return new (zone()) Operator1<ContextAccess>(IrOpcode::kJSStoreContext, |
| 219 Operator::kNoProperties, 2, 0, |
| 220 "JSStoreContext", access); |
| 221 } |
| 222 |
| 223 |
| 224 const Operator* JSOperatorBuilder::CreateCatchContext( |
| 225 const Unique<String>& name) { |
| 226 return new (zone()) Operator1<Unique<String> >( |
| 227 IrOpcode::kJSCreateCatchContext, Operator::kNoProperties, 1, 1, |
| 228 "JSCreateCatchContext", name); |
| 229 } |
| 230 |
| 231 } // namespace compiler |
| 232 } // namespace internal |
| 233 } // namespace v8 |
OLD | NEW |