Commit f4e92fe1 authored by peterssen's avatar peterssen Committed by Commit bot

Add ToSmi and Goto operations to FastAccessorAssembler.

BUG=chromium:508898

Review-Url: https://codereview.chromium.org/2237443002
Cr-Commit-Position: refs/heads/master@{#38745}
parent e4c67d3f
......@@ -34,11 +34,14 @@ class V8_EXPORT FastAccessorBuilder {
ValueId LoadInternalFieldUnchecked(ValueId value_id, int field_no);
ValueId LoadValue(ValueId value_id, int offset);
ValueId LoadObject(ValueId value_id, int offset);
ValueId ToSmi(ValueId value_id);
void ReturnValue(ValueId value_id);
void CheckFlagSetOrReturnNull(ValueId value_id, int mask);
void CheckNotZeroOrReturnNull(ValueId value_id);
LabelId MakeLabel();
void SetLabel(LabelId label_id);
void Goto(LabelId label_id);
void CheckNotZeroOrJump(ValueId value_id, LabelId label_id);
ValueId Call(v8::FunctionCallback callback, ValueId value_id);
......
......@@ -92,6 +92,9 @@ FastAccessorBuilder::ValueId FastAccessorBuilder::LoadObject(ValueId value_id,
return FromApi(this)->LoadObject(value_id, offset);
}
FastAccessorBuilder::ValueId FastAccessorBuilder::ToSmi(ValueId value_id) {
return FromApi(this)->ToSmi(value_id);
}
void FastAccessorBuilder::ReturnValue(ValueId value) {
FromApi(this)->ReturnValue(value);
......@@ -117,6 +120,9 @@ void FastAccessorBuilder::SetLabel(LabelId label_id) {
FromApi(this)->SetLabel(label_id);
}
void FastAccessorBuilder::Goto(LabelId label_id) {
FromApi(this)->Goto(label_id);
}
void FastAccessorBuilder::CheckNotZeroOrJump(ValueId value_id,
LabelId label_id) {
......
......@@ -108,6 +108,11 @@ FastAccessorAssembler::ValueId FastAccessorAssembler::LoadObject(ValueId value,
0, MachineType::AnyTagged()));
}
FastAccessorAssembler::ValueId FastAccessorAssembler::ToSmi(ValueId value) {
CHECK_EQ(kBuilding, state_);
return FromRaw(assembler_->SmiTag(FromId(value)));
}
void FastAccessorAssembler::ReturnValue(ValueId value) {
CHECK_EQ(kBuilding, state_);
assembler_->Return(FromId(value));
......@@ -149,6 +154,11 @@ void FastAccessorAssembler::SetLabel(LabelId label_id) {
assembler_->Bind(FromId(label_id));
}
void FastAccessorAssembler::Goto(LabelId label_id) {
CHECK_EQ(kBuilding, state_);
assembler_->Goto(FromId(label_id));
}
void FastAccessorAssembler::CheckNotZeroOrJump(ValueId value_id,
LabelId label_id) {
CHECK_EQ(kBuilding, state_);
......
......@@ -66,12 +66,16 @@ class FastAccessorAssembler {
ValueId LoadValue(ValueId value_id, int offset);
ValueId LoadObject(ValueId value_id, int offset);
// Converts a machine integer to a SMI.
ValueId ToSmi(ValueId value_id);
// Builder / assembler functions for control flow.
void ReturnValue(ValueId value_id);
void CheckFlagSetOrReturnNull(ValueId value_id, int mask);
void CheckNotZeroOrReturnNull(ValueId value_id);
LabelId MakeLabel();
void SetLabel(LabelId label_id);
void Goto(LabelId label_id);
void CheckNotZeroOrJump(ValueId value_id, LabelId label_id);
// C++ callback.
......
......@@ -400,3 +400,92 @@ TEST(FastAccessorCallback) {
CompileRun(FN_WARMUP("callbackparam", "return obj.param"));
ExpectInt32("callbackparam()", 1000);
}
TEST(FastAccessorToSmi) {
// Crankshaft support for fast accessors is not implemented; crankshafted
// code uses the slow accessor which breaks this test's expectations.
v8::internal::FLAG_always_opt = false;
LocalContext env;
v8::Isolate* isolate = env->GetIsolate();
v8::HandleScope scope(isolate);
v8::Local<v8::ObjectTemplate> foo = v8::ObjectTemplate::New(isolate);
foo->SetInternalFieldCount(1);
{
// Accessor load_smi.
auto builder = v8::experimental::FastAccessorBuilder::New(isolate);
// Read the variable and convert it to a Smi.
auto flags = builder->LoadValue(
builder->LoadInternalField(builder->GetReceiver(), 0), 0);
builder->ReturnValue(builder->ToSmi(flags));
foo->SetAccessorProperty(v8_str("load_smi"),
v8::FunctionTemplate::NewWithFastHandler(
isolate, NativePropertyAccessor, builder));
}
// Create an instance.
v8::Local<v8::Object> obj = foo->NewInstance(env.local()).ToLocalChecked();
uint32_t flags;
obj->SetAlignedPointerInInternalField(0, &flags);
CHECK(env->Global()->Set(env.local(), v8_str("obj"), obj).FromJust());
// Access flags.
CompileRun(FN_WARMUP("load_smi", "return obj.load_smi"));
flags = 54321;
ExpectInt32("load_smi()", 54321);
flags = 0;
ExpectInt32("load_smi()", 0);
flags = 123456789;
ExpectInt32("load_smi()", 123456789);
}
TEST(FastAccessorGoto) {
// Crankshaft support for fast accessors is not implemented; crankshafted
// code uses the slow accessor which breaks this test's expectations.
v8::internal::FLAG_always_opt = false;
LocalContext env;
v8::Isolate* isolate = env->GetIsolate();
v8::HandleScope scope(isolate);
v8::Local<v8::ObjectTemplate> foo = v8::ObjectTemplate::New(isolate);
foo->SetInternalFieldCount(1);
{
auto builder = v8::experimental::FastAccessorBuilder::New(isolate);
auto successLabel = builder->MakeLabel();
auto failLabel = builder->MakeLabel();
// The underlying raw assembler is clever enough to reject unreachable
// basic blocks, this instruction has no effect besides marking the failed
// return BB as reachable.
builder->CheckNotZeroOrJump(builder->IntegerConstant(1234), failLabel);
builder->Goto(successLabel);
builder->SetLabel(failLabel);
builder->ReturnValue(builder->IntegerConstant(0));
builder->SetLabel(successLabel);
builder->ReturnValue(builder->IntegerConstant(60707357));
foo->SetAccessorProperty(v8_str("goto_test"),
v8::FunctionTemplate::NewWithFastHandler(
isolate, NativePropertyAccessor, builder));
}
// Create an instance.
v8::Local<v8::Object> obj = foo->NewInstance(env.local()).ToLocalChecked();
CHECK(env->Global()->Set(env.local(), v8_str("obj"), obj).FromJust());
// Access flags.
CompileRun(FN_WARMUP("test", "return obj.goto_test"));
ExpectInt32("test()", 60707357);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment