This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH 5/9] ENABLE_CHECKING refactoring: pool allocators
- From: Mikhail Maltsev <maltsevm at gmail dot com>
- To: Richard Biener <richard dot guenther at gmail dot com>
- Cc: Bernd Schmidt <bschmidt at redhat dot com>, gcc-patches mailing list <gcc-patches at gcc dot gnu dot org>, Jeff Law <law at redhat dot com>
- Date: Mon, 26 Oct 2015 04:18:33 +0300
- Subject: Re: [PATCH 5/9] ENABLE_CHECKING refactoring: pool allocators
- Authentication-results: sourceware.org; auth=none
- References: <56130763 dot 4070206 at gmail dot com> <5613088F dot 9010903 at gmail dot com> <5613C17C dot 5090703 at redhat dot com> <CAFiYyc23VB_LiY1=9HzyBAc6wHgDuVfH+mgAqBum=-Xu=vPQ4g at mail dot gmail dot com> <562434C4 dot 30004 at gmail dot com> <CAFiYyc2LefXW0Cohvkft3mkbF--qD4Xc8ubeM-EVE9ooV2OBrw at mail dot gmail dot com>
On 10/21/2015 01:57 PM, Richard Biener wrote:
> Ugh (stupid templates).
>
> @@ -387,10 +389,10 @@ base_pool_allocator <TBlockAllocator>::allocate ()
> block = m_virgin_free_list;
> header = (allocation_pool_list*) allocation_object::get_data (block);
> header->next = NULL;
> -#ifdef ENABLE_CHECKING
> +
> /* Mark the element to be free. */
> - ((allocation_object*) block)->id = 0;
> -#endif
> + if (flag_checking)
> + ((allocation_object*) block)->id = 0;
>
> just set id to zero unconditionally. That'll be faster than checking
> flag_checking.
I fixed this and other issues, and committed the attached patch.
--
Regards,
Mikhail Maltsev
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 81d0e1c..d8a22c3 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,9 @@
+2015-10-26 Mikhail Maltsev <maltsevm@gmail.com>
+
+ * alloc-pool.h (base_pool_allocator::initialize, ::allocate): Remove
+ conditional compilation.
+ (base_pool_allocator::remove): Use flag_checking.
+
2015-10-25 John David Anglin <danglin@gcc.gnu.org>
* config/pa/som.h (EH_FRAME_THROUGH_COLLECT2): Define.
diff --git a/gcc/alloc-pool.h b/gcc/alloc-pool.h
index 70105ba..404b558 100644
--- a/gcc/alloc-pool.h
+++ b/gcc/alloc-pool.h
@@ -21,6 +21,7 @@ along with GCC; see the file COPYING3. If not see
#define ALLOC_POOL_H
#include "memory-block.h"
+#include "options.h" // for flag_checking
extern void dump_alloc_pool_statistics (void);
@@ -275,7 +276,6 @@ base_pool_allocator <TBlockAllocator>::initialize ()
m_elts_per_block = (TBlockAllocator::block_size - header_size) / size;
gcc_checking_assert (m_elts_per_block != 0);
-#ifdef ENABLE_CHECKING
/* Increase the last used ID and use it for this pool.
ID == 0 is used for free elements of pool so skip it. */
last_id++;
@@ -283,7 +283,6 @@ base_pool_allocator <TBlockAllocator>::initialize ()
last_id++;
m_id = last_id;
-#endif
}
/* Free all memory allocated for the given memory pool. */
@@ -387,10 +386,9 @@ base_pool_allocator <TBlockAllocator>::allocate ()
block = m_virgin_free_list;
header = (allocation_pool_list*) allocation_object::get_data (block);
header->next = NULL;
-#ifdef ENABLE_CHECKING
+
/* Mark the element to be free. */
((allocation_object*) block)->id = 0;
-#endif
VALGRIND_DISCARD (VALGRIND_MAKE_MEM_NOACCESS (header,size));
m_returned_free_list = header;
m_virgin_free_list += m_elt_size;
@@ -404,10 +402,8 @@ base_pool_allocator <TBlockAllocator>::allocate ()
m_returned_free_list = header->next;
m_elts_free--;
-#ifdef ENABLE_CHECKING
/* Set the ID for element. */
allocation_object::get_instance (header)->id = m_id;
-#endif
VALGRIND_DISCARD (VALGRIND_MAKE_MEM_UNDEFINED (header, size));
return (void *)(header);
@@ -418,26 +414,23 @@ template <typename TBlockAllocator>
inline void
base_pool_allocator <TBlockAllocator>::remove (void *object)
{
- gcc_checking_assert (m_initialized);
-
- allocation_pool_list *header;
- int size ATTRIBUTE_UNUSED;
- size = m_elt_size - offsetof (allocation_object, u.data);
-
-#ifdef ENABLE_CHECKING
- gcc_assert (object
+ if (flag_checking)
+ {
+ gcc_assert (m_initialized);
+ gcc_assert (object
/* Check if we free more than we allocated, which is Bad (TM). */
&& m_elts_free < m_elts_allocated
/* Check whether the PTR was allocated from POOL. */
&& m_id == allocation_object::get_instance (object)->id);
- memset (object, 0xaf, size);
+ int size = m_elt_size - offsetof (allocation_object, u.data);
+ memset (object, 0xaf, size);
+ }
/* Mark the element to be free. */
allocation_object::get_instance (object)->id = 0;
-#endif
- header = (allocation_pool_list*) object;
+ allocation_pool_list *header = (allocation_pool_list*) object;
header->next = m_returned_free_list;
m_returned_free_list = header;
VALGRIND_DISCARD (VALGRIND_MAKE_MEM_NOACCESS (object, size));