Index: test/cctest/interpreter/test-bytecode-generator.cc |
diff --git a/test/cctest/interpreter/test-bytecode-generator.cc b/test/cctest/interpreter/test-bytecode-generator.cc |
index 3614c111115be784a60a4606ab19b8c152786296..486bc954ead4fa467dcbf91037a9a97802e9e287 100644 |
--- a/test/cctest/interpreter/test-bytecode-generator.cc |
+++ b/test/cctest/interpreter/test-bytecode-generator.cc |
@@ -2958,6 +2958,328 @@ TEST(ContextParameters) { |
} |
} |
+ |
+TEST(CountOperators) { |
+ InitializedHandleScope handle_scope; |
+ BytecodeGeneratorHelper helper; |
+ Zone zone; |
+ |
+ FeedbackVectorSpec feedback_spec(&zone); |
+ FeedbackVectorSlot slot1 = feedback_spec.AddLoadICSlot(); |
+ FeedbackVectorSlot slot2 = feedback_spec.AddStoreICSlot(); |
+ |
+ Handle<i::TypeFeedbackVector> vector = |
+ i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec); |
+ |
+ int closure = Register::function_closure().index(); |
+ int first_context_slot = Context::MIN_CONTEXT_SLOTS; |
+ |
+ int object_literal_flags = |
+ ObjectLiteral::kFastElements | ObjectLiteral::kDisableMementos; |
+ |
+ ExpectedSnippet<InstanceType> snippets[] = { |
+ {"var a = 1; return ++a;", |
+ 1 * kPointerSize, |
+ 1, |
+ 11, |
+ { |
+ B(LdaSmi8), U8(1), // |
+ B(Star), R(0), // |
+ B(Ldar), R(0), // |
+ B(ToNumber), // |
+ B(Inc), // |
+ B(Star), R(0), // |
+ B(Return), // |
+ }}, |
+ {"var a = 1; return a++;", |
+ 2 * kPointerSize, |
+ 1, |
+ 15, |
+ { |
+ B(LdaSmi8), U8(1), // |
+ B(Star), R(0), // |
+ B(Ldar), R(0), // |
+ B(ToNumber), // |
+ B(Star), R(1), // |
+ B(Inc), // |
+ B(Star), R(0), // |
+ B(Ldar), R(1), // |
+ B(Return), // |
+ }}, |
+ {"var a = 1; return --a;", |
+ 1 * kPointerSize, |
+ 1, |
+ 11, |
+ { |
+ B(LdaSmi8), U8(1), // |
+ B(Star), R(0), // |
+ B(Ldar), R(0), // |
+ B(ToNumber), // |
+ B(Dec), // |
+ B(Star), R(0), // |
+ B(Return), // |
+ }}, |
+ {"var a = 1; return a--;", |
+ 2 * kPointerSize, |
+ 1, |
+ 15, |
+ { |
+ B(LdaSmi8), U8(1), // |
+ B(Star), R(0), // |
+ B(Ldar), R(0), // |
+ B(ToNumber), // |
+ B(Star), R(1), // |
+ B(Dec), // |
+ B(Star), R(0), // |
+ B(Ldar), R(1), // |
+ B(Return), // |
+ }}, |
+ {"var a = { val: 1 }; return a.val++;", |
+ 4 * kPointerSize, |
+ 1, |
+ 29, |
+ { |
+ B(LdaConstant), U8(0), // |
+ B(CreateObjectLiteral), U8(0), U8(object_literal_flags), // |
+ B(Star), R(0), // |
+ B(Ldar), R(0), // |
+ B(Star), R(1), // |
+ B(LdaConstant), U8(1), // |
+ B(Star), R(2), // |
+ B(LoadICSloppy), R(1), U8(vector->GetIndex(slot1)), // |
+ B(ToNumber), // |
+ B(Star), R(3), // |
+ B(Inc), // |
+ B(StoreICSloppy), R(1), R(2), U8(vector->GetIndex(slot2)), // |
+ B(Ldar), R(3), // |
+ B(Return), // |
+ }, |
+ 2, |
+ {InstanceType::FIXED_ARRAY_TYPE, |
+ InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, |
+ {"var a = { val: 1 }; return --a.val;", |
+ 3 * kPointerSize, |
+ 1, |
+ 25, |
+ { |
+ B(LdaConstant), U8(0), // |
+ B(CreateObjectLiteral), U8(0), U8(object_literal_flags), // |
+ B(Star), R(0), // |
+ B(Ldar), R(0), // |
+ B(Star), R(1), // |
+ B(LdaConstant), U8(1), // |
+ B(Star), R(2), // |
+ B(LoadICSloppy), R(1), U8(vector->GetIndex(slot1)), // |
+ B(ToNumber), // |
+ B(Dec), // |
+ B(StoreICSloppy), R(1), R(2), U8(vector->GetIndex(slot2)), // |
+ B(Return), // |
+ }, |
+ 2, |
+ {InstanceType::FIXED_ARRAY_TYPE, |
+ InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, |
+ {"var name = 'var'; var a = { val: 1 }; return a[name]--;", |
+ 5 * kPointerSize, |
+ 1, |
+ 33, |
+ { |
+ B(LdaConstant), U8(0), // |
+ B(Star), R(0), // |
+ B(LdaConstant), U8(1), // |
+ B(CreateObjectLiteral), U8(0), U8(object_literal_flags), // |
+ B(Star), R(1), // |
+ B(Ldar), R(1), // |
+ B(Star), R(2), // |
+ B(Ldar), R(0), // |
+ B(Star), R(3), // |
+ B(KeyedLoadICSloppy), R(2), U8(3), // |
+ B(ToNumber), // |
+ B(Star), R(4), // |
+ B(Dec), // |
+ B(KeyedStoreICSloppy), R(2), R(3), U8(5), // |
+ B(Ldar), R(4), // |
+ B(Return), // |
+ }, |
+ 2, |
+ {InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE, |
+ InstanceType::FIXED_ARRAY_TYPE}}, |
+ {"var name = 'var'; var a = { val: 1 }; return ++a[name];", |
+ 4 * kPointerSize, |
+ 1, |
+ 29, |
+ { |
+ B(LdaConstant), U8(0), // |
+ B(Star), R(0), // |
+ B(LdaConstant), U8(1), // |
+ B(CreateObjectLiteral), U8(0), U8(object_literal_flags), // |
+ B(Star), R(1), // |
+ B(Ldar), R(1), // |
+ B(Star), R(2), // |
+ B(Ldar), R(0), // |
+ B(Star), R(3), // |
+ B(KeyedLoadICSloppy), R(2), U8(3), // |
+ B(ToNumber), // |
+ B(Inc), // |
+ B(KeyedStoreICSloppy), R(2), R(3), U8(5), // |
+ B(Return), // |
+ }, |
+ 2, |
+ {InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE, |
+ InstanceType::FIXED_ARRAY_TYPE}}, |
+ {"var a = 1; var b = function() { return a }; return ++a;", |
+ 2 * kPointerSize, |
+ 1, |
+ 27, |
+ { |
+ B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), // |
+ U8(1), // |
+ B(PushContext), R(1), // |
+ B(LdaSmi8), U8(1), // |
+ B(StaContextSlot), R(1), U8(first_context_slot), // |
+ B(LdaConstant), U8(0), // |
+ B(CreateClosure), U8(0), // |
+ B(Star), R(0), // |
+ B(LdaContextSlot), R(1), U8(first_context_slot), // |
+ B(ToNumber), // |
+ B(Inc), // |
+ B(StaContextSlot), R(1), U8(first_context_slot), // |
+ B(Return), // |
+ }, |
+ 1, |
+ {InstanceType::SHARED_FUNCTION_INFO_TYPE}}, |
+ {"var a = 1; var b = function() { return a }; return a--;", |
+ 3 * kPointerSize, |
+ 1, |
+ 31, |
+ { |
+ B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), // |
+ U8(1), // |
+ B(PushContext), R(1), // |
+ B(LdaSmi8), U8(1), // |
+ B(StaContextSlot), R(1), U8(first_context_slot), // |
+ B(LdaConstant), U8(0), // |
+ B(CreateClosure), U8(0), // |
+ B(Star), R(0), // |
+ B(LdaContextSlot), R(1), U8(first_context_slot), // |
+ B(ToNumber), // |
+ B(Star), R(2), // |
+ B(Dec), // |
+ B(StaContextSlot), R(1), U8(first_context_slot), // |
+ B(Ldar), R(2), // |
+ B(Return), // |
+ }, |
+ 1, |
+ {InstanceType::SHARED_FUNCTION_INFO_TYPE}}, |
+ }; |
+ |
+ for (size_t i = 0; i < arraysize(snippets); i++) { |
+ Handle<BytecodeArray> bytecode_array = |
+ helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); |
+ CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
+ } |
+} |
+ |
+ |
+TEST(GlobalCountOperators) { |
+ InitializedHandleScope handle_scope; |
+ BytecodeGeneratorHelper helper; |
+ Zone zone; |
+ |
+ int context = Register::function_context().index(); |
+ |
+ FeedbackVectorSpec feedback_spec(&zone); |
+ FeedbackVectorSlot slot1 = feedback_spec.AddLoadICSlot(); |
+ FeedbackVectorSlot slot2 = feedback_spec.AddStoreICSlot(); |
+ |
+ Handle<i::TypeFeedbackVector> vector = |
+ i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec); |
+ |
+ ExpectedSnippet<InstanceType> snippets[] = { |
+ {"var global = 1;\nfunction f() { return ++global; }\nf()", |
+ 0, |
+ 1, |
+ 7, |
+ { |
+ B(LdaGlobal), _, // |
+ B(ToNumber), // |
+ B(Inc), // |
+ B(StaGlobalSloppy), _, // |
+ B(Return), // |
+ }}, |
+ {"var global = 1;\nfunction f() { return global--; }\nf()", |
+ 1 * kPointerSize, |
+ 1, |
+ 11, |
+ { |
+ B(LdaGlobal), U8(4), // |
+ B(ToNumber), // |
+ B(Star), R(0), // |
+ B(Dec), // |
+ B(StaGlobalSloppy), _, // |
+ B(Ldar), R(0), // |
+ B(Return), // |
+ }}, |
+ {"unallocated = 1;\nfunction f() { return --unallocated; }\nf()", |
+ 3 * kPointerSize, |
+ 1, |
+ 30, |
+ { |
+ // TODO(rmcilroy): We could probably be more clever here and maintain |
+ // the value looked up on the global object and use it for the store |
+ // rather than having to reload it. |
+ B(LdaContextSlot), R(context), U8(Context::GLOBAL_OBJECT_INDEX), // |
+ B(Star), R(0), // |
+ B(LdaConstant), U8(0), // |
+ B(LoadICSloppy), R(0), U8(vector->GetIndex(slot1)), // |
+ B(ToNumber), // |
+ B(Dec), // |
+ B(Star), R(0), // |
+ B(LdaContextSlot), R(context), U8(Context::GLOBAL_OBJECT_INDEX), // |
+ B(Star), R(1), // |
+ B(LdaConstant), U8(0), // |
+ B(Star), R(2), // |
+ B(Ldar), R(0), // |
+ B(StoreICSloppy), R(1), R(2), U8(vector->GetIndex(slot2)), // |
+ B(Return), // |
+ }, |
+ 1, |
+ {InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, |
+ {"unallocated = 1;\nfunction f() { return unallocated++; }\nf()", |
+ 4 * kPointerSize, |
+ 1, |
+ 34, |
+ { |
+ // TODO(rmcilroy): We could probably be more clever here and maintain |
+ // the value looked up on the global object and use it for the store |
+ // rather than having to reload it. |
+ B(LdaContextSlot), R(context), U8(Context::GLOBAL_OBJECT_INDEX), // |
+ B(Star), R(0), // |
+ B(LdaConstant), U8(0), // |
+ B(LoadICSloppy), R(0), U8(vector->GetIndex(slot1)), // |
+ B(ToNumber), // |
+ B(Star), R(0), // |
+ B(Inc), // |
+ B(Star), R(1), // |
+ B(LdaContextSlot), R(context), U8(Context::GLOBAL_OBJECT_INDEX), // |
+ B(Star), R(2), // |
+ B(LdaConstant), U8(0), // |
+ B(Star), R(3), // |
+ B(Ldar), R(1), // |
+ B(StoreICSloppy), R(2), R(3), U8(vector->GetIndex(slot2)), // |
+ B(Ldar), R(0), // |
+ B(Return), // |
+ }, |
+ 1, |
+ {InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, |
+ }; |
+ |
+ for (size_t i = 0; i < arraysize(snippets); i++) { |
+ Handle<BytecodeArray> bytecode_array = |
+ helper.MakeBytecode(snippets[i].code_snippet, "f"); |
+ CheckBytecodeArrayEqual(snippets[i], bytecode_array, true); |
+ } |
+} |
+ |
} // namespace interpreter |
} // namespace internal |
} // namespace v8 |