1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission.
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 #include "code-stubs.h"
38 static LChunk* OptimizeGraph(HGraph* graph) {
39 DisallowHeapAllocation no_allocation;
40 DisallowHandleAllocation no_handles;
41 DisallowHandleDereference no_deref;
43 ASSERT(graph != NULL);
44 SmartArrayPointer<char> bailout_reason;
45 if (!graph->Optimize(&bailout_reason)) {
46 FATAL(bailout_reason.is_empty() ? "unknown" : *bailout_reason);
48 LChunk* chunk = LChunk::NewChunk(graph);
50 FATAL(graph->info()->bailout_reason());
56 class CodeStubGraphBuilderBase : public HGraphBuilder {
58 CodeStubGraphBuilderBase(Isolate* isolate, HydrogenCodeStub* stub)
59 : HGraphBuilder(&info_),
60 arguments_length_(NULL),
63 descriptor_ = stub->GetInterfaceDescriptor(isolate);
64 parameters_.Reset(new HParameter*[descriptor_->register_param_count_]);
66 virtual bool BuildGraph();
69 virtual HValue* BuildCodeStub() = 0;
70 HParameter* GetParameter(int parameter) {
71 ASSERT(parameter < descriptor_->register_param_count_);
72 return parameters_[parameter];
74 HValue* GetArgumentsLength() {
75 // This is initialized in BuildGraph()
76 ASSERT(arguments_length_ != NULL);
77 return arguments_length_;
79 CompilationInfo* info() { return &info_; }
80 HydrogenCodeStub* stub() { return info_.code_stub(); }
81 HContext* context() { return context_; }
82 Isolate* isolate() { return info_.isolate(); }
84 class ArrayContextChecker {
86 ArrayContextChecker(HGraphBuilder* builder, HValue* constructor,
87 HValue* array_function)
89 checker_.If<HCompareObjectEqAndBranch, HValue*>(constructor,
94 ~ArrayContextChecker() {
108 HValue* BuildArrayConstructor(ElementsKind kind,
109 ContextCheckMode context_mode,
110 AllocationSiteOverrideMode override_mode,
111 ArgumentClass argument_class);
112 HValue* BuildInternalArrayConstructor(ElementsKind kind,
113 ArgumentClass argument_class);
116 HValue* BuildArraySingleArgumentConstructor(JSArrayBuilder* builder);
117 HValue* BuildArrayNArgumentsConstructor(JSArrayBuilder* builder,
120 SmartArrayPointer<HParameter*> parameters_;
121 HValue* arguments_length_;
122 CompilationInfoWithZone info_;
123 CodeStubInterfaceDescriptor* descriptor_;
128 bool CodeStubGraphBuilderBase::BuildGraph() {
129 // Update the static counter each time a new code stub is generated.
130 isolate()->counters()->code_stubs()->Increment();
132 if (FLAG_trace_hydrogen) {
133 const char* name = CodeStub::MajorName(stub()->MajorKey(), false);
134 PrintF("-----------------------------------------------------------\n");
135 PrintF("Compiling stub %s using hydrogen\n", name);
136 isolate()->GetHTracer()->TraceCompilation(&info_);
139 Zone* zone = this->zone();
140 int param_count = descriptor_->register_param_count_;
141 HEnvironment* start_environment = graph()->start_environment();
142 HBasicBlock* next_block = CreateBasicBlock(start_environment);
143 current_block()->Goto(next_block);
144 next_block->SetJoinId(BailoutId::StubEntry());
145 set_current_block(next_block);
147 HConstant* undefined_constant = new(zone) HConstant(
148 isolate()->factory()->undefined_value());
149 AddInstruction(undefined_constant);
150 graph()->set_undefined_constant(undefined_constant);
152 for (int i = 0; i < param_count; ++i) {
154 new(zone) HParameter(i, HParameter::REGISTER_PARAMETER);
155 AddInstruction(param);
156 start_environment->Bind(i, param);
157 parameters_[i] = param;
160 HInstruction* stack_parameter_count;
161 if (descriptor_->stack_parameter_count_ != NULL) {
162 ASSERT(descriptor_->environment_length() == (param_count + 1));
163 stack_parameter_count = new(zone) HParameter(param_count,
164 HParameter::REGISTER_PARAMETER,
165 Representation::Integer32());
166 stack_parameter_count->set_type(HType::Smi());
167 // It's essential to bind this value to the environment in case of deopt.
168 AddInstruction(stack_parameter_count);
169 start_environment->Bind(param_count, stack_parameter_count);
170 arguments_length_ = stack_parameter_count;
172 ASSERT(descriptor_->environment_length() == param_count);
173 stack_parameter_count = graph()->GetConstantMinus1();
174 arguments_length_ = graph()->GetConstant0();
177 context_ = new(zone) HContext();
178 AddInstruction(context_);
179 start_environment->BindContext(context_);
181 AddSimulate(BailoutId::StubEntry());
183 NoObservableSideEffectsScope no_effects(this);
185 HValue* return_value = BuildCodeStub();
187 // We might have extra expressions to pop from the stack in addition to the
189 HInstruction* stack_pop_count = stack_parameter_count;
190 if (descriptor_->function_mode_ == JS_FUNCTION_STUB_MODE) {
191 if (!stack_parameter_count->IsConstant() &&
192 descriptor_->hint_stack_parameter_count_ < 0) {
193 HInstruction* amount = graph()->GetConstant1();
194 stack_pop_count = AddInstruction(
195 HAdd::New(zone, context_, stack_parameter_count, amount));
196 stack_pop_count->ChangeRepresentation(Representation::Integer32());
197 stack_pop_count->ClearFlag(HValue::kCanOverflow);
199 int count = descriptor_->hint_stack_parameter_count_;
200 stack_pop_count = AddInstruction(new(zone) HConstant(count));
204 if (current_block() != NULL) {
205 HReturn* hreturn_instruction = new(zone) HReturn(return_value,
208 current_block()->Finish(hreturn_instruction);
209 set_current_block(NULL);
215 template <class Stub>
216 class CodeStubGraphBuilder: public CodeStubGraphBuilderBase {
218 explicit CodeStubGraphBuilder(Stub* stub)
219 : CodeStubGraphBuilderBase(Isolate::Current(), stub) {}
222 virtual HValue* BuildCodeStub() {
223 if (casted_stub()->IsUninitialized()) {
224 return BuildCodeUninitializedStub();
226 return BuildCodeInitializedStub();
230 virtual HValue* BuildCodeInitializedStub() {
235 virtual HValue* BuildCodeUninitializedStub() {
236 // Force a deopt that falls back to the runtime.
237 HValue* undefined = graph()->GetConstantUndefined();
238 IfBuilder builder(this);
239 builder.IfNot<HCompareObjectEqAndBranch, HValue*>(undefined, undefined);
245 Stub* casted_stub() { return static_cast<Stub*>(stub()); }
249 Handle<Code> HydrogenCodeStub::GenerateLightweightMissCode(Isolate* isolate) {
250 Factory* factory = isolate->factory();
252 // Generate the new code.
253 MacroAssembler masm(isolate, NULL, 256);
256 // Update the static counter each time a new code stub is generated.
257 isolate->counters()->code_stubs()->Increment();
259 // Nested stubs are not allowed for leaves.
260 AllowStubCallsScope allow_scope(&masm, false);
262 // Generate the code for the stub.
263 masm.set_generating_stub(true);
264 NoCurrentFrameScope scope(&masm);
265 GenerateLightweightMiss(&masm);
268 // Create the code object.
272 // Copy the generated code into a heap object.
273 Code::Flags flags = Code::ComputeFlags(
279 Handle<Code> new_object = factory->NewCode(
280 desc, flags, masm.CodeObject(), NeedsImmovableCode());
285 template <class Stub>
286 static Handle<Code> DoGenerateCode(Stub* stub) {
287 Isolate* isolate = Isolate::Current();
288 CodeStub::Major major_key =
289 static_cast<HydrogenCodeStub*>(stub)->MajorKey();
290 CodeStubInterfaceDescriptor* descriptor =
291 isolate->code_stub_interface_descriptor(major_key);
292 if (descriptor->register_param_count_ < 0) {
293 stub->InitializeInterfaceDescriptor(isolate, descriptor);
296 // If we are uninitialized we can use a light-weight stub to enter
297 // the runtime that is significantly faster than using the standard
298 // stub-failure deopt mechanism.
299 if (stub->IsUninitialized() && descriptor->has_miss_handler()) {
300 ASSERT(descriptor->stack_parameter_count_ == NULL);
301 return stub->GenerateLightweightMissCode(isolate);
303 CodeStubGraphBuilder<Stub> builder(stub);
304 LChunk* chunk = OptimizeGraph(builder.CreateGraph());
305 return chunk->Codegen();
310 HValue* CodeStubGraphBuilder<FastCloneShallowArrayStub>::BuildCodeStub() {
311 Zone* zone = this->zone();
312 Factory* factory = isolate()->factory();
313 HValue* undefined = graph()->GetConstantUndefined();
314 AllocationSiteMode alloc_site_mode = casted_stub()->allocation_site_mode();
315 FastCloneShallowArrayStub::Mode mode = casted_stub()->mode();
316 int length = casted_stub()->length();
318 HInstruction* boilerplate =
319 AddInstruction(new(zone) HLoadKeyed(GetParameter(0),
324 IfBuilder checker(this);
325 checker.IfNot<HCompareObjectEqAndBranch, HValue*>(boilerplate, undefined);
328 if (mode == FastCloneShallowArrayStub::CLONE_ANY_ELEMENTS) {
329 HValue* elements = AddLoadElements(boilerplate);
331 IfBuilder if_fixed_cow(this);
332 if_fixed_cow.IfCompareMap(elements, factory->fixed_cow_array_map());
334 environment()->Push(BuildCloneShallowArray(context(),
338 0/*copy-on-write*/));
341 IfBuilder if_fixed(this);
342 if_fixed.IfCompareMap(elements, factory->fixed_array_map());
344 environment()->Push(BuildCloneShallowArray(context(),
350 environment()->Push(BuildCloneShallowArray(context(),
353 FAST_DOUBLE_ELEMENTS,
356 ElementsKind elements_kind = casted_stub()->ComputeElementsKind();
357 environment()->Push(BuildCloneShallowArray(context(),
364 HValue* result = environment()->Pop();
370 Handle<Code> FastCloneShallowArrayStub::GenerateCode() {
371 return DoGenerateCode(this);
376 HValue* CodeStubGraphBuilder<FastCloneShallowObjectStub>::BuildCodeStub() {
377 Zone* zone = this->zone();
378 HValue* undefined = graph()->GetConstantUndefined();
380 HInstruction* boilerplate =
381 AddInstruction(new(zone) HLoadKeyed(GetParameter(0),
386 IfBuilder checker(this);
387 checker.IfNot<HCompareObjectEqAndBranch, HValue*>(boilerplate, undefined);
390 int size = JSObject::kHeaderSize + casted_stub()->length() * kPointerSize;
391 HValue* boilerplate_size =
392 AddInstruction(new(zone) HInstanceSize(boilerplate));
393 HValue* size_in_words =
394 AddInstruction(new(zone) HConstant(size >> kPointerSizeLog2));
395 checker.IfCompare(boilerplate_size, size_in_words, Token::EQ);
398 HValue* size_in_bytes = AddInstruction(new(zone) HConstant(size));
399 HAllocate::Flags flags = HAllocate::CAN_ALLOCATE_IN_NEW_SPACE;
400 if (isolate()->heap()->ShouldGloballyPretenure()) {
401 flags = static_cast<HAllocate::Flags>(
402 flags | HAllocate::CAN_ALLOCATE_IN_OLD_POINTER_SPACE);
405 HInstruction* object = AddInstruction(new(zone)
406 HAllocate(context(), size_in_bytes, HType::JSObject(), flags));
408 for (int i = 0; i < size; i += kPointerSize) {
409 HObjectAccess access = HObjectAccess::ForJSObjectOffset(i);
410 AddStore(object, access, AddLoad(boilerplate, access));
418 Handle<Code> FastCloneShallowObjectStub::GenerateCode() {
419 return DoGenerateCode(this);
424 HValue* CodeStubGraphBuilder<KeyedLoadFastElementStub>::BuildCodeStub() {
425 HInstruction* load = BuildUncheckedMonomorphicElementAccess(
426 GetParameter(0), GetParameter(1), NULL, NULL,
427 casted_stub()->is_js_array(), casted_stub()->elements_kind(),
428 false, NEVER_RETURN_HOLE, STANDARD_STORE);
433 Handle<Code> KeyedLoadFastElementStub::GenerateCode() {
434 return DoGenerateCode(this);
439 HValue* CodeStubGraphBuilder<LoadFieldStub>::BuildCodeStub() {
440 HObjectAccess access = casted_stub()->is_inobject() ?
441 HObjectAccess::ForJSObjectOffset(casted_stub()->offset()) :
442 HObjectAccess::ForBackingStoreOffset(casted_stub()->offset());
443 return AddInstruction(BuildLoadNamedField(GetParameter(0), access,
444 casted_stub()->representation()));
448 Handle<Code> LoadFieldStub::GenerateCode() {
449 return DoGenerateCode(this);
454 HValue* CodeStubGraphBuilder<KeyedLoadFieldStub>::BuildCodeStub() {
455 HObjectAccess access = casted_stub()->is_inobject() ?
456 HObjectAccess::ForJSObjectOffset(casted_stub()->offset()) :
457 HObjectAccess::ForBackingStoreOffset(casted_stub()->offset());
458 return AddInstruction(BuildLoadNamedField(GetParameter(0), access,
459 casted_stub()->representation()));
463 Handle<Code> KeyedLoadFieldStub::GenerateCode() {
464 return DoGenerateCode(this);
469 HValue* CodeStubGraphBuilder<KeyedStoreFastElementStub>::BuildCodeStub() {
470 BuildUncheckedMonomorphicElementAccess(
471 GetParameter(0), GetParameter(1), GetParameter(2), NULL,
472 casted_stub()->is_js_array(), casted_stub()->elements_kind(),
473 true, NEVER_RETURN_HOLE, casted_stub()->store_mode());
475 return GetParameter(2);
479 Handle<Code> KeyedStoreFastElementStub::GenerateCode() {
480 return DoGenerateCode(this);
485 HValue* CodeStubGraphBuilder<TransitionElementsKindStub>::BuildCodeStub() {
486 Zone* zone = this->zone();
488 HValue* js_array = GetParameter(0);
489 HValue* map = GetParameter(1);
491 info()->MarkAsSavesCallerDoubles();
493 AddInstruction(new(zone) HTrapAllocationMemento(js_array));
495 HInstruction* array_length =
496 AddLoad(js_array, HObjectAccess::ForArrayLength());
497 array_length->set_type(HType::Smi());
499 ElementsKind to_kind = casted_stub()->to_kind();
500 BuildNewSpaceArrayCheck(array_length, to_kind);
502 IfBuilder if_builder(this);
504 if_builder.IfCompare(array_length, graph()->GetConstant0(), Token::EQ);
507 // Nothing to do, just change the map.
511 HInstruction* elements = AddLoadElements(js_array);
513 HInstruction* elements_length = AddLoadFixedArrayLength(elements);
515 HValue* new_elements = BuildAllocateElementsAndInitializeElementsHeader(
516 context(), to_kind, elements_length);
518 BuildCopyElements(context(), elements,
519 casted_stub()->from_kind(), new_elements,
520 to_kind, array_length, elements_length);
522 AddStore(js_array, HObjectAccess::ForElementsPointer(), new_elements);
526 AddStore(js_array, HObjectAccess::ForMap(), map);
532 Handle<Code> TransitionElementsKindStub::GenerateCode() {
533 return DoGenerateCode(this);
536 HValue* CodeStubGraphBuilderBase::BuildArrayConstructor(
538 ContextCheckMode context_mode,
539 AllocationSiteOverrideMode override_mode,
540 ArgumentClass argument_class) {
541 HValue* constructor = GetParameter(ArrayConstructorStubBase::kConstructor);
542 if (context_mode == CONTEXT_CHECK_REQUIRED) {
543 HInstruction* array_function = BuildGetArrayFunction(context());
544 ArrayContextChecker checker(this, constructor, array_function);
547 HValue* property_cell = GetParameter(ArrayConstructorStubBase::kPropertyCell);
548 JSArrayBuilder array_builder(this, kind, property_cell, constructor,
550 HValue* result = NULL;
551 switch (argument_class) {
553 result = array_builder.AllocateEmptyArray();
556 result = BuildArraySingleArgumentConstructor(&array_builder);
559 result = BuildArrayNArgumentsConstructor(&array_builder, kind);
567 HValue* CodeStubGraphBuilderBase::BuildInternalArrayConstructor(
568 ElementsKind kind, ArgumentClass argument_class) {
569 HValue* constructor = GetParameter(
570 InternalArrayConstructorStubBase::kConstructor);
571 JSArrayBuilder array_builder(this, kind, constructor);
573 HValue* result = NULL;
574 switch (argument_class) {
576 result = array_builder.AllocateEmptyArray();
579 result = BuildArraySingleArgumentConstructor(&array_builder);
582 result = BuildArrayNArgumentsConstructor(&array_builder, kind);
589 HValue* CodeStubGraphBuilderBase::BuildArraySingleArgumentConstructor(
590 JSArrayBuilder* array_builder) {
591 // Smi check and range check on the input arg.
592 HValue* constant_one = graph()->GetConstant1();
593 HValue* constant_zero = graph()->GetConstant0();
595 HInstruction* elements = AddInstruction(
596 new(zone()) HArgumentsElements(false));
597 HInstruction* argument = AddInstruction(
598 new(zone()) HAccessArgumentsAt(elements, constant_one, constant_zero));
600 HConstant* max_alloc_length =
601 new(zone()) HConstant(JSObject::kInitialMaxFastElementArray);
602 AddInstruction(max_alloc_length);
603 const int initial_capacity = JSArray::kPreallocatedArrayElements;
604 HConstant* initial_capacity_node = new(zone()) HConstant(initial_capacity);
605 AddInstruction(initial_capacity_node);
607 HBoundsCheck* checked_arg = Add<HBoundsCheck>(argument, max_alloc_length);
608 IfBuilder if_builder(this);
609 if_builder.IfCompare(checked_arg, constant_zero, Token::EQ);
611 Push(initial_capacity_node); // capacity
612 Push(constant_zero); // length
614 Push(checked_arg); // capacity
615 Push(checked_arg); // length
618 // Figure out total size
619 HValue* length = Pop();
620 HValue* capacity = Pop();
621 return array_builder->AllocateArray(capacity, length, true);
625 HValue* CodeStubGraphBuilderBase::BuildArrayNArgumentsConstructor(
626 JSArrayBuilder* array_builder, ElementsKind kind) {
627 // We need to fill with the hole if it's a smi array in the multi-argument
628 // case because we might have to bail out while copying arguments into
629 // the array because they aren't compatible with a smi array.
630 // If it's a double array, no problem, and if it's fast then no
631 // problem either because doubles are boxed.
632 HValue* length = GetArgumentsLength();
633 bool fill_with_hole = IsFastSmiElementsKind(kind);
634 HValue* new_object = array_builder->AllocateArray(length,
637 HValue* elements = array_builder->GetElementsLocation();
638 ASSERT(elements != NULL);
640 // Now populate the elements correctly.
641 LoopBuilder builder(this,
643 LoopBuilder::kPostIncrement);
644 HValue* start = graph()->GetConstant0();
645 HValue* key = builder.BeginBody(start, length, Token::LT);
646 HInstruction* argument_elements = AddInstruction(
647 new(zone()) HArgumentsElements(false));
648 HInstruction* argument = AddInstruction(new(zone()) HAccessArgumentsAt(
649 argument_elements, length, key));
651 AddInstruction(new(zone()) HStoreKeyed(elements, key, argument, kind));
658 HValue* CodeStubGraphBuilder<ArrayNoArgumentConstructorStub>::BuildCodeStub() {
659 ElementsKind kind = casted_stub()->elements_kind();
660 ContextCheckMode context_mode = casted_stub()->context_mode();
661 AllocationSiteOverrideMode override_mode = casted_stub()->override_mode();
662 return BuildArrayConstructor(kind, context_mode, override_mode, NONE);
666 Handle<Code> ArrayNoArgumentConstructorStub::GenerateCode() {
667 return DoGenerateCode(this);
672 HValue* CodeStubGraphBuilder<ArraySingleArgumentConstructorStub>::
674 ElementsKind kind = casted_stub()->elements_kind();
675 ContextCheckMode context_mode = casted_stub()->context_mode();
676 AllocationSiteOverrideMode override_mode = casted_stub()->override_mode();
677 return BuildArrayConstructor(kind, context_mode, override_mode, SINGLE);
681 Handle<Code> ArraySingleArgumentConstructorStub::GenerateCode() {
682 return DoGenerateCode(this);
687 HValue* CodeStubGraphBuilder<ArrayNArgumentsConstructorStub>::BuildCodeStub() {
688 ElementsKind kind = casted_stub()->elements_kind();
689 ContextCheckMode context_mode = casted_stub()->context_mode();
690 AllocationSiteOverrideMode override_mode = casted_stub()->override_mode();
691 return BuildArrayConstructor(kind, context_mode, override_mode, MULTIPLE);
695 Handle<Code> ArrayNArgumentsConstructorStub::GenerateCode() {
696 return DoGenerateCode(this);
701 HValue* CodeStubGraphBuilder<InternalArrayNoArgumentConstructorStub>::
703 ElementsKind kind = casted_stub()->elements_kind();
704 return BuildInternalArrayConstructor(kind, NONE);
708 Handle<Code> InternalArrayNoArgumentConstructorStub::GenerateCode() {
709 return DoGenerateCode(this);
714 HValue* CodeStubGraphBuilder<InternalArraySingleArgumentConstructorStub>::
716 ElementsKind kind = casted_stub()->elements_kind();
717 return BuildInternalArrayConstructor(kind, SINGLE);
721 Handle<Code> InternalArraySingleArgumentConstructorStub::GenerateCode() {
722 return DoGenerateCode(this);
727 HValue* CodeStubGraphBuilder<InternalArrayNArgumentsConstructorStub>::
729 ElementsKind kind = casted_stub()->elements_kind();
730 return BuildInternalArrayConstructor(kind, MULTIPLE);
734 Handle<Code> InternalArrayNArgumentsConstructorStub::GenerateCode() {
735 return DoGenerateCode(this);
740 HValue* CodeStubGraphBuilder<CompareNilICStub>::BuildCodeInitializedStub() {
741 Isolate* isolate = graph()->isolate();
742 CompareNilICStub* stub = casted_stub();
743 HIfContinuation continuation;
744 Handle<Map> sentinel_map(isolate->heap()->meta_map());
746 CompareNilICStub::StateToType(isolate, stub->GetState(), sentinel_map);
747 BuildCompareNil(GetParameter(0), type, RelocInfo::kNoPosition, &continuation);
748 IfBuilder if_nil(this, &continuation);
750 if (continuation.IsFalseReachable()) {
752 if_nil.Return(graph()->GetConstant0());
755 return continuation.IsTrueReachable()
756 ? graph()->GetConstant1()
757 : graph()->GetConstantUndefined();
761 Handle<Code> CompareNilICStub::GenerateCode() {
762 return DoGenerateCode(this);
767 HValue* CodeStubGraphBuilder<ToBooleanStub>::BuildCodeInitializedStub() {
768 ToBooleanStub* stub = casted_stub();
770 IfBuilder if_true(this);
771 if_true.If<HBranch>(GetParameter(0), stub->GetTypes());
773 if_true.Return(graph()->GetConstant1());
776 return graph()->GetConstant0();
780 Handle<Code> ToBooleanStub::GenerateCode() {
781 return DoGenerateCode(this);
785 } } // namespace v8::internal