 Chromium Code Reviews
 Chromium Code Reviews Issue 10701054:
  Enable stub generation using Hydrogen/Lithium (again)  (Closed) 
  Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
    
  
    Issue 10701054:
  Enable stub generation using Hydrogen/Lithium (again)  (Closed) 
  Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge| Index: src/code-stubs.cc | 
| diff --git a/src/code-stubs.cc b/src/code-stubs.cc | 
| index 7a720592db20bf8117b833071f08b7d6815ebf4b..0f346cb0f14b8a0433bdd84183454b7b0821f29a 100644 | 
| --- a/src/code-stubs.cc | 
| +++ b/src/code-stubs.cc | 
| @@ -32,6 +32,8 @@ | 
| #include "stub-cache.h" | 
| #include "factory.h" | 
| #include "gdb-jit.h" | 
| +#include "hydrogen.h" | 
| +#include "lithium.h" | 
| #include "macro-assembler.h" | 
| namespace v8 { | 
| @@ -48,17 +50,53 @@ bool CodeStub::FindCodeInCache(Code** code_out) { | 
| } | 
| -void CodeStub::GenerateCode(MacroAssembler* masm) { | 
| - // Update the static counter each time a new code stub is generated. | 
| - masm->isolate()->counters()->code_stubs()->Increment(); | 
| +Handle<Code> HydrogenCodeStub::GenerateCode() { | 
| + Isolate* isolate = Isolate::Current(); | 
| + CompilationInfoWithZone info(isolate); | 
| + if (FLAG_trace_hydrogen) { | 
| + PrintF("-----------------------------------------------------------\n"); | 
| + PrintF("Compiling stub using hydrogen\n"); | 
| + HTracer::Instance()->TraceCompilation(&info); | 
| + } | 
| + HGraph graph(&info); | 
| + Generate(&graph); | 
| + graph.OrderBlocks(); | 
| + graph.AssignDominators(); | 
| + graph.CollectPhis(); | 
| + graph.InsertRepresentationChanges(); | 
| + graph.EliminateRedundantBoundsChecks(); | 
| + LChunk* chunk = LChunk::NewChunk(&graph); | 
| + ASSERT(chunk != NULL); | 
| + Handle<Code> stub = chunk->Codegen(Code::COMPILED_STUB); | 
| + stub->Print(); | 
| 
Jakob Kummerow
2012/11/19 12:36:00
Don't forget to remove this (or surround with "if
 
danno
2012/11/26 17:16:18
Done.
 | 
| + return stub; | 
| +} | 
| + | 
| + | 
| +void KeyedLoadFastElementStub::Generate(HGraph* graph) { | 
| + Zone* zone = graph->zone(); | 
| + HInstruction* receiver = new(zone) HParameter(0, KEYED_LOAD_IC_PARAMETER); | 
| + graph->entry_block()->AddInstruction(receiver); | 
| + graph->start_environment()->Push(receiver); | 
| + HInstruction* key = new(zone) HParameter(1, KEYED_LOAD_IC_PARAMETER); | 
| + graph->entry_block()->AddInstruction(key); | 
| + graph->start_environment()->Push(key); | 
| + | 
| + graph->entry_block()->AddSimulate(BailoutId::StubEntry()); | 
| - // Nested stubs are not allowed for leaves. | 
| - AllowStubCallsScope allow_scope(masm, false); | 
| + HBasicBlock* next_block = graph->CreateBasicBlock(); | 
| + next_block->SetInitialEnvironment(graph->start_environment()); | 
| + HGoto* jump = new(zone) HGoto(next_block); | 
| + graph->entry_block()->Finish(jump); | 
| - // Generate the code for the stub. | 
| - masm->set_generating_stub(true); | 
| - NoCurrentFrameScope scope(masm); | 
| - Generate(masm); | 
| + HInstruction* load = HGraphBuilder::BuildUncheckedMonomorphicElementAccess( | 
| + graph, | 
| + next_block, receiver, key, NULL, NULL, | 
| + is_js_array(), elements_kind(), false, zone); | 
| + next_block->AddInstruction(load); | 
| + | 
| + HReturn* ret = new(zone) HReturn(load); | 
| + next_block->Finish(ret); | 
| } | 
| @@ -72,8 +110,7 @@ SmartArrayPointer<const char> CodeStub::GetName() { | 
| } | 
| -void CodeStub::RecordCodeGeneration(Code* code, MacroAssembler* masm) { | 
| - Isolate* isolate = masm->isolate(); | 
| +void CodeStub::RecordCodeGeneration(Code* code, Isolate* isolate) { | 
| SmartArrayPointer<const char> name = GetName(); | 
| PROFILE(isolate, CodeCreateEvent(Logger::STUB_TAG, code, *name)); | 
| GDBJIT(AddCode(GDBJITInterface::STUB, *name, code)); | 
| @@ -87,6 +124,40 @@ int CodeStub::GetCodeKind() { | 
| } | 
| +Handle<Code> PlatformCodeStub::GenerateCode() { | 
| + Isolate* isolate = Isolate::Current(); | 
| + Factory* factory = isolate->factory(); | 
| + | 
| + // Generate the new code. | 
| + MacroAssembler masm(isolate, NULL, 256); | 
| + | 
| + { | 
| + // Update the static counter each time a new code stub is generated. | 
| + isolate->counters()->code_stubs()->Increment(); | 
| + | 
| + // Nested stubs are not allowed for leaves. | 
| + AllowStubCallsScope allow_scope(&masm, false); | 
| + | 
| + // Generate the code for the stub. | 
| + masm.set_generating_stub(true); | 
| + NoCurrentFrameScope scope(&masm); | 
| + Generate(&masm); | 
| + } | 
| + | 
| + // Create the code object. | 
| + CodeDesc desc; | 
| + masm.GetCode(&desc); | 
| + | 
| + // Copy the generated code into a heap object. | 
| + Code::Flags flags = Code::ComputeFlags( | 
| + static_cast<Code::Kind>(GetCodeKind()), | 
| + GetICState()); | 
| + Handle<Code> new_object = factory->NewCode( | 
| + desc, flags, masm.CodeObject(), NeedsImmovableCode()); | 
| + return new_object; | 
| +} | 
| + | 
| + | 
| Handle<Code> CodeStub::GetCode() { | 
| Isolate* isolate = Isolate::Current(); | 
| Factory* factory = isolate->factory(); | 
| @@ -102,23 +173,10 @@ Handle<Code> CodeStub::GetCode() { | 
| { | 
| HandleScope scope(isolate); | 
| - // Generate the new code. | 
| - MacroAssembler masm(isolate, NULL, 256); | 
| - GenerateCode(&masm); | 
| - | 
| - // Create the code object. | 
| - CodeDesc desc; | 
| - masm.GetCode(&desc); | 
| - | 
| - // Copy the generated code into a heap object. | 
| - Code::Flags flags = Code::ComputeFlags( | 
| - static_cast<Code::Kind>(GetCodeKind()), | 
| - GetICState()); | 
| - Handle<Code> new_object = factory->NewCode( | 
| - desc, flags, masm.CodeObject(), NeedsImmovableCode()); | 
| + Handle<Code> new_object = GenerateCode(); | 
| new_object->set_major_key(MajorKey()); | 
| FinishCode(new_object); | 
| - RecordCodeGeneration(*new_object, &masm); | 
| + RecordCodeGeneration(*new_object, isolate); | 
| #ifdef ENABLE_DISASSEMBLER | 
| if (FLAG_print_code_stubs) { | 
| @@ -261,7 +319,8 @@ void InstanceofStub::PrintName(StringStream* stream) { | 
| } | 
| -void JSEntryStub::FinishCode(Handle<Code> code) { | 
| +void JSEntryStub:: | 
| +FinishCode(Handle<Code> code) { | 
| Handle<FixedArray> handler_table = | 
| code->GetIsolate()->factory()->NewFixedArray(1, TENURED); | 
| handler_table->set(0, Smi::FromInt(handler_offset_)); | 
| @@ -269,36 +328,8 @@ void JSEntryStub::FinishCode(Handle<Code> code) { | 
| } | 
| -void KeyedLoadElementStub::Generate(MacroAssembler* masm) { | 
| - switch (elements_kind_) { | 
| - case FAST_ELEMENTS: | 
| - case FAST_HOLEY_ELEMENTS: | 
| - case FAST_SMI_ELEMENTS: | 
| - case FAST_HOLEY_SMI_ELEMENTS: | 
| - KeyedLoadStubCompiler::GenerateLoadFastElement(masm); | 
| - break; | 
| - case FAST_DOUBLE_ELEMENTS: | 
| - case FAST_HOLEY_DOUBLE_ELEMENTS: | 
| - KeyedLoadStubCompiler::GenerateLoadFastDoubleElement(masm); | 
| - break; | 
| - case EXTERNAL_BYTE_ELEMENTS: | 
| - case EXTERNAL_UNSIGNED_BYTE_ELEMENTS: | 
| - case EXTERNAL_SHORT_ELEMENTS: | 
| - case EXTERNAL_UNSIGNED_SHORT_ELEMENTS: | 
| - case EXTERNAL_INT_ELEMENTS: | 
| - case EXTERNAL_UNSIGNED_INT_ELEMENTS: | 
| - case EXTERNAL_FLOAT_ELEMENTS: | 
| - case EXTERNAL_DOUBLE_ELEMENTS: | 
| - case EXTERNAL_PIXEL_ELEMENTS: | 
| - KeyedLoadStubCompiler::GenerateLoadExternalArray(masm, elements_kind_); | 
| - break; | 
| - case DICTIONARY_ELEMENTS: | 
| - KeyedLoadStubCompiler::GenerateLoadDictionaryElement(masm); | 
| - break; | 
| - case NON_STRICT_ARGUMENTS_ELEMENTS: | 
| - UNREACHABLE(); | 
| - break; | 
| - } | 
| +void KeyedLoadDictionaryElementStub::Generate(MacroAssembler* masm) { | 
| + KeyedLoadStubCompiler::GenerateLoadDictionaryElement(masm); | 
| } |