Commit 41450ffd authored by bmeurer's avatar bmeurer Committed by Commit bot

[turbofan] Reduce boilerplate around HeapNumber allocation in stubs.

R=jarin@chromium.org

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

Cr-Commit-Position: refs/heads/master@{#35012}
parent 208415d6
......@@ -2098,11 +2098,7 @@ void Builtins::Generate_MathSqrt(compiler::CodeStubAssembler* assembler) {
{
Node* x = var_fsqrt_x.value();
Node* value = assembler->Float64Sqrt(x);
Node* result = assembler->Allocate(HeapNumber::kSize,
compiler::CodeStubAssembler::kNone);
assembler->StoreMapNoWriteBarrier(result,
assembler->HeapNumberMapConstant());
assembler->StoreHeapNumberValue(result, value);
Node* result = assembler->AllocateHeapNumberWithValue(value);
assembler->Return(result);
}
}
......
......@@ -465,26 +465,19 @@ Handle<Code> TurboFanCodeStub::GenerateCode() {
void AllocateHeapNumberStub::GenerateAssembly(
compiler::CodeStubAssembler* assembler) const {
compiler::Node* result = assembler->Allocate(
HeapNumber::kSize, compiler::CodeStubAssembler::kNone);
compiler::Node* map_offset =
assembler->IntPtrConstant(HeapObject::kMapOffset - kHeapObjectTag);
compiler::Node* map = assembler->IntPtrAdd(result, map_offset);
assembler->StoreNoWriteBarrier(
MachineRepresentation::kTagged, map,
assembler->HeapConstant(isolate()->factory()->heap_number_map()));
typedef compiler::Node Node;
Node* result = assembler->AllocateHeapNumber();
assembler->Return(result);
}
void AllocateMutableHeapNumberStub::GenerateAssembly(
compiler::CodeStubAssembler* assembler) const {
compiler::Node* result = assembler->Allocate(
HeapNumber::kSize, compiler::CodeStubAssembler::kNone);
compiler::Node* map_offset =
assembler->IntPtrConstant(HeapObject::kMapOffset - kHeapObjectTag);
compiler::Node* map = assembler->IntPtrAdd(result, map_offset);
assembler->StoreNoWriteBarrier(
MachineRepresentation::kTagged, map,
typedef compiler::Node Node;
Node* result = assembler->Allocate(HeapNumber::kSize);
assembler->StoreMapNoWriteBarrier(
result,
assembler->HeapConstant(isolate()->factory()->mutable_heap_number_map()));
assembler->Return(result);
}
......@@ -867,11 +860,7 @@ void AddStub::GenerateAssembly(compiler::CodeStubAssembler* assembler) const {
Node* rhs_value = var_fadd_rhs.value();
Node* value = assembler->Float64Add(lhs_value, rhs_value);
// TODO(bmeurer): Introduce a ChangeFloat64ToTagged.
Node* result = assembler->Allocate(HeapNumber::kSize,
compiler::CodeStubAssembler::kNone);
assembler->StoreMapNoWriteBarrier(result,
assembler->HeapNumberMapConstant());
assembler->StoreHeapNumberValue(result, value);
Node* result = assembler->AllocateHeapNumberWithValue(value);
assembler->Return(result);
}
}
......@@ -1039,11 +1028,7 @@ void SubtractStub::GenerateAssembly(
Node* rhs_value = var_fsub_rhs.value();
Node* value = assembler->Float64Sub(lhs_value, rhs_value);
// TODO(bmeurer): Introduce a ChangeFloat64ToTagged.
Node* result = assembler->Allocate(HeapNumber::kSize,
compiler::CodeStubAssembler::kNone);
assembler->StoreMapNoWriteBarrier(result,
assembler->HeapNumberMapConstant());
assembler->StoreHeapNumberValue(result, value);
Node* result = assembler->AllocateHeapNumberWithValue(value);
assembler->Return(result);
}
}
......
......@@ -438,6 +438,18 @@ Node* CodeStubAssembler::Allocate(int size_in_bytes, AllocationFlags flags) {
limit_address);
}
Node* CodeStubAssembler::AllocateHeapNumber() {
Node* result = Allocate(HeapNumber::kSize, kNone);
StoreMapNoWriteBarrier(result, HeapNumberMapConstant());
return result;
}
Node* CodeStubAssembler::AllocateHeapNumberWithValue(Node* value) {
Node* result = AllocateHeapNumber();
StoreHeapNumberValue(result, value);
return result;
}
Node* CodeStubAssembler::Load(MachineType rep, Node* base) {
return raw_assembler_->Load(rep, base);
}
......
......@@ -305,7 +305,11 @@ class CodeStubAssembler {
Node* LoadFixedArrayElementConstantIndex(Node* object, int index);
// Allocate an object of the given size.
Node* Allocate(int size, AllocationFlags flags);
Node* Allocate(int size, AllocationFlags flags = kNone);
// Allocate a HeapNumber without initializing its value.
Node* AllocateHeapNumber();
// Allocate a HeapNumber with a specific value.
Node* AllocateHeapNumberWithValue(Node* value);
// Store an array element to a FixedArray.
Node* StoreFixedArrayElementNoWriteBarrier(Node* object, Node* index,
......
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