Commit 6946d1de authored by Teodor Dutu's avatar Teodor Dutu Committed by V8 LUCI CQ

[csa] Enable allocation folding for builtins

This also allows allocation folding to be tested in cctests.

Bug: v8:13070
Change-Id: I7b6991461dd7ad4423539b33f59a05d6b247c3e7
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3891257
Auto-Submit: Teo Dutu <teodutu@google.com>
Commit-Queue: Teo Dutu <teodutu@google.com>
Reviewed-by: 's avatarIgor Sheludko <ishell@chromium.org>
Cr-Commit-Position: refs/heads/main@{#83169}
parent 602e566e
......@@ -79,6 +79,7 @@ void OptimizedCompilationInfo::ConfigureFlags() {
case CodeKind::BUILTIN:
case CodeKind::FOR_TESTING:
if (v8_flags.turbo_splitting) set_splitting();
if (v8_flags.enable_allocation_folding) set_allocation_folding();
#if ENABLE_GDB_JIT_INTERFACE && DEBUG
set_source_positions();
#endif // ENABLE_GDB_JIT_INTERFACE && DEBUG
......
......@@ -1912,6 +1912,63 @@ TEST(AllocateJSObjectFromMap) {
}
}
TEST(AllocationFoldingCSA) {
Isolate* isolate(CcTest::InitIsolateOnce());
const int kNumParams = 1;
const int kNumArrays = 7;
CodeAssemblerTester asm_tester(isolate, kNumParams + 1,
CodeKind::FOR_TESTING); // Include receiver.
CodeStubAssembler m(asm_tester.state());
{
TNode<IntPtrT> length = m.SmiUntag(m.Parameter<Smi>(1));
TNode<FixedArray> result = m.UncheckedCast<FixedArray>(m.AllocateFixedArray(
PACKED_ELEMENTS, length, CodeStubAssembler::AllocationFlag::kNone));
for (int i = 1; i <= kNumArrays; ++i) {
int array_length = i * kTaggedSize;
TNode<ByteArray> array =
m.AllocateByteArray(m.UintPtrConstant(array_length));
m.StoreFixedArrayElement(result, i - 1, array);
}
m.Return(result);
}
FunctionTester ft(asm_tester.GenerateCode(), kNumParams);
{
auto fixed_array_length = Handle<Smi>(Smi::FromInt(kNumArrays), isolate);
Handle<FixedArray> result =
Handle<FixedArray>::cast(ft.Call(fixed_array_length).ToHandleChecked());
CHECK_EQ(result->length(), kNumArrays);
if (V8_COMPRESS_POINTERS_8GB_BOOL) {
CHECK(IsAligned(result->address(), kObjectAlignment8GbHeap));
} else {
CHECK(IsAligned(result->address(), kTaggedSize));
}
ByteArray prev_array;
for (int i = 1; i <= kNumArrays; ++i) {
ByteArray current_array = ByteArray::cast(result->get(i - 1));
if (V8_COMPRESS_POINTERS_8GB_BOOL) {
CHECK(IsAligned(current_array.address(), kObjectAlignment8GbHeap));
} else {
CHECK(IsAligned(current_array.address(), kTaggedSize));
}
CHECK_EQ(current_array.length(), i * kTaggedSize);
if (i != 1) {
// TODO(v8:13070): Align prev_array.AllocatedSize() to the allocation
// size.
CHECK_EQ(prev_array.address() + prev_array.AllocatedSize(),
current_array.address());
}
prev_array = current_array;
}
#ifdef VERIFY_HEAP
HeapVerifier::VerifyHeap(isolate->heap());
#endif
}
}
namespace {
template <typename Dictionary>
......
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