[llvm] Revert "[Support] Recycler: Enforce minimum allocation size" (PR #121735)

Akshat Oke via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 6 00:20:04 PST 2025


https://github.com/optimisan created https://github.com/llvm/llvm-project/pull/121735

Reverts llvm/llvm-project#121425

>From b2c2fcf5269e820431cbc776aca163a79b4046f6 Mon Sep 17 00:00:00 2001
From: Akshat Oke <Akshat.Oke at amd.com>
Date: Mon, 6 Jan 2025 13:49:47 +0530
Subject: [PATCH] Revert "[Support] Recycler: Enforce minimum allocation size
 (#121425)"

This reverts commit 34e8aff480dd9cd0372a7c14d13dfca5d3cd1a24.
---
 llvm/include/llvm/Support/Recycler.h    |  2 --
 llvm/unittests/Support/CMakeLists.txt   |  1 -
 llvm/unittests/Support/RecyclerTest.cpp | 46 -------------------------
 3 files changed, 49 deletions(-)
 delete mode 100644 llvm/unittests/Support/RecyclerTest.cpp

diff --git a/llvm/include/llvm/Support/Recycler.h b/llvm/include/llvm/Support/Recycler.h
index 1b9ee2084148d0..bbd9ae321ae30c 100644
--- a/llvm/include/llvm/Support/Recycler.h
+++ b/llvm/include/llvm/Support/Recycler.h
@@ -85,8 +85,6 @@ class Recycler {
                   "Recycler allocation alignment is less than object align!");
     static_assert(sizeof(SubClass) <= Size,
                   "Recycler allocation size is less than object size!");
-    static_assert(Size >= sizeof(FreeNode) &&
-                  "Recycler size must be at least sizeof(FreeNode)");
     return FreeList ? reinterpret_cast<SubClass *>(pop_val())
                     : static_cast<SubClass *>(Allocator.Allocate(Size, Align));
   }
diff --git a/llvm/unittests/Support/CMakeLists.txt b/llvm/unittests/Support/CMakeLists.txt
index 6de81658264420..d64f89847aa8e7 100644
--- a/llvm/unittests/Support/CMakeLists.txt
+++ b/llvm/unittests/Support/CMakeLists.txt
@@ -69,7 +69,6 @@ add_llvm_unittest(SupportTests
   PerThreadBumpPtrAllocatorTest.cpp
   ProcessTest.cpp
   ProgramTest.cpp
-  RecyclerTest.cpp
   RegexTest.cpp
   ReverseIterationTest.cpp
   ReplaceFileTest.cpp
diff --git a/llvm/unittests/Support/RecyclerTest.cpp b/llvm/unittests/Support/RecyclerTest.cpp
deleted file mode 100644
index 8cd763c0b83f8a..00000000000000
--- a/llvm/unittests/Support/RecyclerTest.cpp
+++ /dev/null
@@ -1,46 +0,0 @@
-//===--- unittest/Support/RecyclerTest.cpp --------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-#include "llvm/Support/Recycler.h"
-#include "llvm/Support/AllocatorBase.h"
-#include "gtest/gtest.h"
-
-using namespace llvm;
-
-namespace {
-
-struct Object1 {
-  char Data[1];
-};
-
-class DecoratedMallocAllocator : public MallocAllocator {
-public:
-  int DeallocCount = 0;
-
-  template <typename T> void Deallocate(T *Ptr) {
-    DeallocCount++;
-    MallocAllocator::Deallocate(Ptr);
-  }
-};
-
-TEST(RecyclerTest, RecycleAllocation) {
-  DecoratedMallocAllocator Allocator;
-  // Recycler needs size to be atleast 8 bytes.
-  Recycler<Object1, 8, 8> R;
-  Object1 *A1 = R.Allocate(Allocator);
-  Object1 *A2 = R.Allocate(Allocator);
-  R.Deallocate(Allocator, A2);
-  Object1 *A3 = R.Allocate(Allocator);
-  EXPECT_EQ(A2, A3); // reuse the deallocated object.
-  R.Deallocate(Allocator, A1);
-  R.Deallocate(Allocator, A3);
-  R.clear(Allocator); // Should deallocate A1 and A3.
-  EXPECT_EQ(Allocator.DeallocCount, 2);
-}
-
-} // end anonymous namespace



More information about the llvm-commits mailing list