X87: The IC exposes a register definition.

port r22011

original commit message:
  Centralize a register definition in an IC that provides:
  1) symbolic names for the register (like, edx == receiver)
  2) defines ordering when passed on the stack

  Code that implements or uses the IC should use this definition instead of "knowing" what the registers are. Or at least have the definition to validate it's assumptions.

  As a side effect of avoiding runtime static initializers (enforced by tools/check-static-initializers.sh, neat), I gave ownership of the registers array to CodeStubInterfaceDescriptor. This prompted a cleanup of that struct

BUG=
R=weiliang.lin@intel.com

Review URL: https://codereview.chromium.org/358773002

Patch from Chunyang Dai <chunyang.dai@intel.com>.

git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@22028 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
weiliang.lin@intel.com 2014-06-26 05:43:16 +00:00
parent 8313c523b3
commit 8ff53a8d62
4 changed files with 130 additions and 170 deletions

View File

@ -21,169 +21,120 @@ namespace internal {
void FastNewClosureStub::InitializeInterfaceDescriptor( void FastNewClosureStub::InitializeInterfaceDescriptor(
CodeStubInterfaceDescriptor* descriptor) { CodeStubInterfaceDescriptor* descriptor) {
static Register registers[] = { ebx }; Register registers[] = { ebx };
descriptor->register_param_count_ = 1; descriptor->Initialize(
descriptor->register_params_ = registers; ARRAY_SIZE(registers), registers,
descriptor->deoptimization_handler_ = Runtime::FunctionForId(Runtime::kNewClosureFromStubFailure)->entry);
Runtime::FunctionForId(Runtime::kNewClosureFromStubFailure)->entry;
} }
void FastNewContextStub::InitializeInterfaceDescriptor( void FastNewContextStub::InitializeInterfaceDescriptor(
CodeStubInterfaceDescriptor* descriptor) { CodeStubInterfaceDescriptor* descriptor) {
static Register registers[] = { edi }; Register registers[] = { edi };
descriptor->register_param_count_ = 1; descriptor->Initialize(ARRAY_SIZE(registers), registers);
descriptor->register_params_ = registers;
descriptor->deoptimization_handler_ = NULL;
} }
void ToNumberStub::InitializeInterfaceDescriptor( void ToNumberStub::InitializeInterfaceDescriptor(
CodeStubInterfaceDescriptor* descriptor) { CodeStubInterfaceDescriptor* descriptor) {
static Register registers[] = { eax }; Register registers[] = { eax };
descriptor->register_param_count_ = 1; descriptor->Initialize(ARRAY_SIZE(registers), registers);
descriptor->register_params_ = registers;
descriptor->deoptimization_handler_ = NULL;
} }
void NumberToStringStub::InitializeInterfaceDescriptor( void NumberToStringStub::InitializeInterfaceDescriptor(
CodeStubInterfaceDescriptor* descriptor) { CodeStubInterfaceDescriptor* descriptor) {
static Register registers[] = { eax }; Register registers[] = { eax };
descriptor->register_param_count_ = 1; descriptor->Initialize(
descriptor->register_params_ = registers; ARRAY_SIZE(registers), registers,
descriptor->deoptimization_handler_ = Runtime::FunctionForId(Runtime::kNumberToStringRT)->entry);
Runtime::FunctionForId(Runtime::kNumberToStringRT)->entry;
} }
void FastCloneShallowArrayStub::InitializeInterfaceDescriptor( void FastCloneShallowArrayStub::InitializeInterfaceDescriptor(
CodeStubInterfaceDescriptor* descriptor) { CodeStubInterfaceDescriptor* descriptor) {
static Register registers[] = { eax, ebx, ecx }; Register registers[] = { eax, ebx, ecx };
descriptor->register_param_count_ = 3; Representation representations[] = {
descriptor->register_params_ = registers; Representation::Tagged(),
static Representation representations[] = { Representation::Smi(),
Representation::Tagged(), Representation::Tagged() };
Representation::Smi(),
Representation::Tagged() }; descriptor->Initialize(
descriptor->register_param_representations_ = representations; ARRAY_SIZE(registers), registers,
descriptor->deoptimization_handler_ = Runtime::FunctionForId(
Runtime::FunctionForId(Runtime::kCreateArrayLiteralStubBailout)->entry; Runtime::kCreateArrayLiteralStubBailout)->entry,
representations);
} }
void FastCloneShallowObjectStub::InitializeInterfaceDescriptor( void FastCloneShallowObjectStub::InitializeInterfaceDescriptor(
CodeStubInterfaceDescriptor* descriptor) { CodeStubInterfaceDescriptor* descriptor) {
static Register registers[] = { eax, ebx, ecx, edx }; Register registers[] = { eax, ebx, ecx, edx };
descriptor->register_param_count_ = 4; descriptor->Initialize(
descriptor->register_params_ = registers; ARRAY_SIZE(registers), registers,
descriptor->deoptimization_handler_ = Runtime::FunctionForId(Runtime::kCreateObjectLiteral)->entry);
Runtime::FunctionForId(Runtime::kCreateObjectLiteral)->entry;
} }
void CreateAllocationSiteStub::InitializeInterfaceDescriptor( void CreateAllocationSiteStub::InitializeInterfaceDescriptor(
CodeStubInterfaceDescriptor* descriptor) { CodeStubInterfaceDescriptor* descriptor) {
static Register registers[] = { ebx, edx }; Register registers[] = { ebx, edx };
descriptor->register_param_count_ = 2; descriptor->Initialize(ARRAY_SIZE(registers), registers);
descriptor->register_params_ = registers;
descriptor->deoptimization_handler_ = NULL;
}
void KeyedLoadFastElementStub::InitializeInterfaceDescriptor(
CodeStubInterfaceDescriptor* descriptor) {
static Register registers[] = { edx, ecx };
descriptor->register_param_count_ = 2;
descriptor->register_params_ = registers;
descriptor->deoptimization_handler_ =
FUNCTION_ADDR(KeyedLoadIC_MissFromStubFailure);
}
void KeyedLoadDictionaryElementStub::InitializeInterfaceDescriptor(
CodeStubInterfaceDescriptor* descriptor) {
static Register registers[] = { edx, ecx };
descriptor->register_param_count_ = 2;
descriptor->register_params_ = registers;
descriptor->deoptimization_handler_ =
FUNCTION_ADDR(KeyedLoadIC_MissFromStubFailure);
} }
void RegExpConstructResultStub::InitializeInterfaceDescriptor( void RegExpConstructResultStub::InitializeInterfaceDescriptor(
CodeStubInterfaceDescriptor* descriptor) { CodeStubInterfaceDescriptor* descriptor) {
static Register registers[] = { ecx, ebx, eax }; Register registers[] = { ecx, ebx, eax };
descriptor->register_param_count_ = 3; descriptor->Initialize(
descriptor->register_params_ = registers; ARRAY_SIZE(registers), registers,
descriptor->deoptimization_handler_ = Runtime::FunctionForId(Runtime::kRegExpConstructResult)->entry);
Runtime::FunctionForId(Runtime::kRegExpConstructResult)->entry;
}
void KeyedLoadGenericElementStub::InitializeInterfaceDescriptor(
CodeStubInterfaceDescriptor* descriptor) {
static Register registers[] = { edx, ecx };
descriptor->register_param_count_ = 2;
descriptor->register_params_ = registers;
descriptor->deoptimization_handler_ =
Runtime::FunctionForId(Runtime::kKeyedGetProperty)->entry;
} }
void LoadFieldStub::InitializeInterfaceDescriptor( void LoadFieldStub::InitializeInterfaceDescriptor(
CodeStubInterfaceDescriptor* descriptor) { CodeStubInterfaceDescriptor* descriptor) {
static Register registers[] = { edx }; Register registers[] = { edx };
descriptor->register_param_count_ = 1; descriptor->Initialize(ARRAY_SIZE(registers), registers);
descriptor->register_params_ = registers;
descriptor->deoptimization_handler_ = NULL;
} }
void KeyedLoadFieldStub::InitializeInterfaceDescriptor( void KeyedLoadFieldStub::InitializeInterfaceDescriptor(
CodeStubInterfaceDescriptor* descriptor) { CodeStubInterfaceDescriptor* descriptor) {
static Register registers[] = { edx }; Register registers[] = { edx };
descriptor->register_param_count_ = 1; descriptor->Initialize(ARRAY_SIZE(registers), registers);
descriptor->register_params_ = registers;
descriptor->deoptimization_handler_ = NULL;
} }
void StringLengthStub::InitializeInterfaceDescriptor( void StringLengthStub::InitializeInterfaceDescriptor(
CodeStubInterfaceDescriptor* descriptor) { CodeStubInterfaceDescriptor* descriptor) {
static Register registers[] = { edx, ecx }; Register registers[] = { edx, ecx };
descriptor->register_param_count_ = 2; descriptor->Initialize(ARRAY_SIZE(registers), registers);
descriptor->register_params_ = registers;
descriptor->deoptimization_handler_ = NULL;
} }
void KeyedStringLengthStub::InitializeInterfaceDescriptor( void KeyedStringLengthStub::InitializeInterfaceDescriptor(
CodeStubInterfaceDescriptor* descriptor) { CodeStubInterfaceDescriptor* descriptor) {
static Register registers[] = { edx, ecx }; Register registers[] = { edx, ecx };
descriptor->register_param_count_ = 2; descriptor->Initialize(ARRAY_SIZE(registers), registers);
descriptor->register_params_ = registers;
descriptor->deoptimization_handler_ = NULL;
} }
void KeyedStoreFastElementStub::InitializeInterfaceDescriptor( void KeyedStoreFastElementStub::InitializeInterfaceDescriptor(
CodeStubInterfaceDescriptor* descriptor) { CodeStubInterfaceDescriptor* descriptor) {
static Register registers[] = { edx, ecx, eax }; Register registers[] = { edx, ecx, eax };
descriptor->register_param_count_ = 3; descriptor->Initialize(
descriptor->register_params_ = registers; ARRAY_SIZE(registers), registers,
descriptor->deoptimization_handler_ = FUNCTION_ADDR(KeyedStoreIC_MissFromStubFailure));
FUNCTION_ADDR(KeyedStoreIC_MissFromStubFailure);
} }
void TransitionElementsKindStub::InitializeInterfaceDescriptor( void TransitionElementsKindStub::InitializeInterfaceDescriptor(
CodeStubInterfaceDescriptor* descriptor) { CodeStubInterfaceDescriptor* descriptor) {
static Register registers[] = { eax, ebx }; Register registers[] = { eax, ebx };
descriptor->register_param_count_ = 2; descriptor->Initialize(
descriptor->register_params_ = registers; ARRAY_SIZE(registers), registers,
descriptor->deoptimization_handler_ = Runtime::FunctionForId(Runtime::kTransitionElementsKind)->entry);
Runtime::FunctionForId(Runtime::kTransitionElementsKind)->entry;
} }
@ -195,29 +146,31 @@ static void InitializeArrayConstructorDescriptor(
// eax -- number of arguments // eax -- number of arguments
// edi -- function // edi -- function
// ebx -- allocation site with elements kind // ebx -- allocation site with elements kind
static Register registers_variable_args[] = { edi, ebx, eax }; Address deopt_handler = Runtime::FunctionForId(
static Register registers_no_args[] = { edi, ebx }; Runtime::kArrayConstructor)->entry;
if (constant_stack_parameter_count == 0) { if (constant_stack_parameter_count == 0) {
descriptor->register_param_count_ = 2; Register registers[] = { edi, ebx };
descriptor->register_params_ = registers_no_args; descriptor->Initialize(ARRAY_SIZE(registers), registers,
deopt_handler,
NULL,
constant_stack_parameter_count,
JS_FUNCTION_STUB_MODE);
} else { } else {
// stack param count needs (constructor pointer, and single argument) // stack param count needs (constructor pointer, and single argument)
descriptor->handler_arguments_mode_ = PASS_ARGUMENTS; Register registers[] = { edi, ebx, eax };
descriptor->stack_parameter_count_ = eax; Representation representations[] = {
descriptor->register_param_count_ = 3;
descriptor->register_params_ = registers_variable_args;
static Representation representations[] = {
Representation::Tagged(), Representation::Tagged(),
Representation::Tagged(), Representation::Tagged(),
Representation::Integer32() }; Representation::Integer32() };
descriptor->register_param_representations_ = representations; descriptor->Initialize(ARRAY_SIZE(registers), registers,
eax,
deopt_handler,
representations,
constant_stack_parameter_count,
JS_FUNCTION_STUB_MODE,
PASS_ARGUMENTS);
} }
descriptor->hint_stack_parameter_count_ = constant_stack_parameter_count;
descriptor->function_mode_ = JS_FUNCTION_STUB_MODE;
descriptor->deoptimization_handler_ =
Runtime::FunctionForId(Runtime::kArrayConstructor)->entry;
} }
@ -227,28 +180,30 @@ static void InitializeInternalArrayConstructorDescriptor(
// register state // register state
// eax -- number of arguments // eax -- number of arguments
// edi -- constructor function // edi -- constructor function
static Register registers_variable_args[] = { edi, eax }; Address deopt_handler = Runtime::FunctionForId(
static Register registers_no_args[] = { edi }; Runtime::kInternalArrayConstructor)->entry;
if (constant_stack_parameter_count == 0) { if (constant_stack_parameter_count == 0) {
descriptor->register_param_count_ = 1; Register registers[] = { edi };
descriptor->register_params_ = registers_no_args; descriptor->Initialize(ARRAY_SIZE(registers), registers,
deopt_handler,
NULL,
constant_stack_parameter_count,
JS_FUNCTION_STUB_MODE);
} else { } else {
// stack param count needs (constructor pointer, and single argument) // stack param count needs (constructor pointer, and single argument)
descriptor->handler_arguments_mode_ = PASS_ARGUMENTS; Register registers[] = { edi, eax };
descriptor->stack_parameter_count_ = eax; Representation representations[] = {
descriptor->register_param_count_ = 2;
descriptor->register_params_ = registers_variable_args;
static Representation representations[] = {
Representation::Tagged(), Representation::Tagged(),
Representation::Integer32() }; Representation::Integer32() };
descriptor->register_param_representations_ = representations; descriptor->Initialize(ARRAY_SIZE(registers), registers,
eax,
deopt_handler,
representations,
constant_stack_parameter_count,
JS_FUNCTION_STUB_MODE,
PASS_ARGUMENTS);
} }
descriptor->hint_stack_parameter_count_ = constant_stack_parameter_count;
descriptor->function_mode_ = JS_FUNCTION_STUB_MODE;
descriptor->deoptimization_handler_ =
Runtime::FunctionForId(Runtime::kInternalArrayConstructor)->entry;
} }
@ -290,22 +245,18 @@ void InternalArrayNArgumentsConstructorStub::InitializeInterfaceDescriptor(
void CompareNilICStub::InitializeInterfaceDescriptor( void CompareNilICStub::InitializeInterfaceDescriptor(
CodeStubInterfaceDescriptor* descriptor) { CodeStubInterfaceDescriptor* descriptor) {
static Register registers[] = { eax }; Register registers[] = { eax };
descriptor->register_param_count_ = 1; descriptor->Initialize(ARRAY_SIZE(registers), registers,
descriptor->register_params_ = registers; FUNCTION_ADDR(CompareNilIC_Miss));
descriptor->deoptimization_handler_ =
FUNCTION_ADDR(CompareNilIC_Miss);
descriptor->SetMissHandler( descriptor->SetMissHandler(
ExternalReference(IC_Utility(IC::kCompareNilIC_Miss), isolate())); ExternalReference(IC_Utility(IC::kCompareNilIC_Miss), isolate()));
} }
void ToBooleanStub::InitializeInterfaceDescriptor( void ToBooleanStub::InitializeInterfaceDescriptor(
CodeStubInterfaceDescriptor* descriptor) { CodeStubInterfaceDescriptor* descriptor) {
static Register registers[] = { eax }; Register registers[] = { eax };
descriptor->register_param_count_ = 1; descriptor->Initialize(ARRAY_SIZE(registers), registers,
descriptor->register_params_ = registers; FUNCTION_ADDR(ToBooleanIC_Miss));
descriptor->deoptimization_handler_ =
FUNCTION_ADDR(ToBooleanIC_Miss);
descriptor->SetMissHandler( descriptor->SetMissHandler(
ExternalReference(IC_Utility(IC::kToBooleanIC_Miss), isolate())); ExternalReference(IC_Utility(IC::kToBooleanIC_Miss), isolate()));
} }
@ -313,30 +264,25 @@ void ToBooleanStub::InitializeInterfaceDescriptor(
void StoreGlobalStub::InitializeInterfaceDescriptor( void StoreGlobalStub::InitializeInterfaceDescriptor(
CodeStubInterfaceDescriptor* descriptor) { CodeStubInterfaceDescriptor* descriptor) {
static Register registers[] = { edx, ecx, eax }; Register registers[] = { edx, ecx, eax };
descriptor->register_param_count_ = 3; descriptor->Initialize(ARRAY_SIZE(registers), registers,
descriptor->register_params_ = registers; FUNCTION_ADDR(StoreIC_MissFromStubFailure));
descriptor->deoptimization_handler_ =
FUNCTION_ADDR(StoreIC_MissFromStubFailure);
} }
void ElementsTransitionAndStoreStub::InitializeInterfaceDescriptor( void ElementsTransitionAndStoreStub::InitializeInterfaceDescriptor(
CodeStubInterfaceDescriptor* descriptor) { CodeStubInterfaceDescriptor* descriptor) {
static Register registers[] = { eax, ebx, ecx, edx }; Register registers[] = { eax, ebx, ecx, edx };
descriptor->register_param_count_ = 4; descriptor->Initialize(ARRAY_SIZE(registers), registers,
descriptor->register_params_ = registers; FUNCTION_ADDR(ElementsTransitionAndStoreIC_Miss));
descriptor->deoptimization_handler_ =
FUNCTION_ADDR(ElementsTransitionAndStoreIC_Miss);
} }
void BinaryOpICStub::InitializeInterfaceDescriptor( void BinaryOpICStub::InitializeInterfaceDescriptor(
CodeStubInterfaceDescriptor* descriptor) { CodeStubInterfaceDescriptor* descriptor) {
static Register registers[] = { edx, eax }; Register registers[] = { edx, eax };
descriptor->register_param_count_ = 2; descriptor->Initialize(ARRAY_SIZE(registers), registers,
descriptor->register_params_ = registers; FUNCTION_ADDR(BinaryOpIC_Miss));
descriptor->deoptimization_handler_ = FUNCTION_ADDR(BinaryOpIC_Miss);
descriptor->SetMissHandler( descriptor->SetMissHandler(
ExternalReference(IC_Utility(IC::kBinaryOpIC_Miss), isolate())); ExternalReference(IC_Utility(IC::kBinaryOpIC_Miss), isolate()));
} }
@ -344,21 +290,18 @@ void BinaryOpICStub::InitializeInterfaceDescriptor(
void BinaryOpWithAllocationSiteStub::InitializeInterfaceDescriptor( void BinaryOpWithAllocationSiteStub::InitializeInterfaceDescriptor(
CodeStubInterfaceDescriptor* descriptor) { CodeStubInterfaceDescriptor* descriptor) {
static Register registers[] = { ecx, edx, eax }; Register registers[] = { ecx, edx, eax };
descriptor->register_param_count_ = 3; descriptor->Initialize(ARRAY_SIZE(registers), registers,
descriptor->register_params_ = registers; FUNCTION_ADDR(BinaryOpIC_MissWithAllocationSite));
descriptor->deoptimization_handler_ =
FUNCTION_ADDR(BinaryOpIC_MissWithAllocationSite);
} }
void StringAddStub::InitializeInterfaceDescriptor( void StringAddStub::InitializeInterfaceDescriptor(
CodeStubInterfaceDescriptor* descriptor) { CodeStubInterfaceDescriptor* descriptor) {
static Register registers[] = { edx, eax }; Register registers[] = { edx, eax };
descriptor->register_param_count_ = 2; descriptor->Initialize(
descriptor->register_params_ = registers; ARRAY_SIZE(registers), registers,
descriptor->deoptimization_handler_ = Runtime::FunctionForId(Runtime::kStringAdd)->entry);
Runtime::FunctionForId(Runtime::kStringAdd)->entry;
} }
@ -454,18 +397,18 @@ void HydrogenCodeStub::GenerateLightweightMiss(MacroAssembler* masm) {
isolate()->counters()->code_stubs()->Increment(); isolate()->counters()->code_stubs()->Increment();
CodeStubInterfaceDescriptor* descriptor = GetInterfaceDescriptor(); CodeStubInterfaceDescriptor* descriptor = GetInterfaceDescriptor();
int param_count = descriptor->register_param_count_; int param_count = descriptor->register_param_count();
{ {
// Call the runtime system in a fresh internal frame. // Call the runtime system in a fresh internal frame.
FrameScope scope(masm, StackFrame::INTERNAL); FrameScope scope(masm, StackFrame::INTERNAL);
ASSERT(descriptor->register_param_count_ == 0 || ASSERT(descriptor->register_param_count() == 0 ||
eax.is(descriptor->register_params_[param_count - 1])); eax.is(descriptor->GetParameterRegister(param_count - 1)));
// Push arguments // Push arguments
for (int i = 0; i < param_count; ++i) { for (int i = 0; i < param_count; ++i) {
__ push(descriptor->register_params_[i]); __ push(descriptor->GetParameterRegister(i));
} }
ExternalReference miss = descriptor->miss_handler(); ExternalReference miss = descriptor->miss_handler();
__ CallExternalReference(miss, descriptor->register_param_count_); __ CallExternalReference(miss, descriptor->register_param_count());
} }
__ ret(0); __ ret(0);

View File

@ -199,7 +199,7 @@ void Deoptimizer::FillInputFrame(Address tos, JavaScriptFrame* frame) {
void Deoptimizer::SetPlatformCompiledStubRegisters( void Deoptimizer::SetPlatformCompiledStubRegisters(
FrameDescription* output_frame, CodeStubInterfaceDescriptor* descriptor) { FrameDescription* output_frame, CodeStubInterfaceDescriptor* descriptor) {
intptr_t handler = intptr_t handler =
reinterpret_cast<intptr_t>(descriptor->deoptimization_handler_); reinterpret_cast<intptr_t>(descriptor->deoptimization_handler());
int params = descriptor->GetHandlerParameterCount(); int params = descriptor->GetHandlerParameterCount();
output_frame->SetRegister(eax.code(), params); output_frame->SetRegister(eax.code(), params);
output_frame->SetRegister(ebx.code(), handler); output_frame->SetRegister(ebx.code(), handler);

View File

@ -1025,6 +1025,19 @@ void KeyedLoadIC::GenerateMiss(MacroAssembler* masm) {
} }
// IC register specifications
const Register LoadIC::ReceiverRegister() { return edx; }
const Register LoadIC::NameRegister() { return ecx; }
const Register KeyedLoadIC::ReceiverRegister() {
return LoadIC::ReceiverRegister();
}
const Register KeyedLoadIC::NameRegister() { return LoadIC::NameRegister(); }
void KeyedLoadIC::GenerateRuntimeGetProperty(MacroAssembler* masm) { void KeyedLoadIC::GenerateRuntimeGetProperty(MacroAssembler* masm) {
// ----------- S t a t e ------------- // ----------- S t a t e -------------
// -- ecx : key // -- ecx : key

View File

@ -1282,14 +1282,18 @@ Handle<Code> LoadStubCompiler::CompileLoadNonexistent(Handle<HeapType> type,
Register* LoadStubCompiler::registers() { Register* LoadStubCompiler::registers() {
// receiver, name, scratch1, scratch2, scratch3, scratch4. // receiver, name, scratch1, scratch2, scratch3, scratch4.
static Register registers[] = { edx, ecx, ebx, eax, edi, no_reg }; Register receiver = LoadIC::ReceiverRegister();
Register name = LoadIC::NameRegister();
static Register registers[] = { receiver, name, ebx, eax, edi, no_reg };
return registers; return registers;
} }
Register* KeyedLoadStubCompiler::registers() { Register* KeyedLoadStubCompiler::registers() {
// receiver, name, scratch1, scratch2, scratch3, scratch4. // receiver, name, scratch1, scratch2, scratch3, scratch4.
static Register registers[] = { edx, ecx, ebx, eax, edi, no_reg }; Register receiver = KeyedLoadIC::ReceiverRegister();
Register name = KeyedLoadIC::NameRegister();
static Register registers[] = { receiver, name, ebx, eax, edi, no_reg };
return registers; return registers;
} }