rtl-ssa: Add some helpers for removing accesses

This adds some helpers to access-utils.h for removing accesses from an
access_array.  This is needed by the upcoming aarch64 load/store pair
fusion pass.

gcc/ChangeLog:

	* rtl-ssa/access-utils.h (filter_accesses): New.
	(remove_regno_access): New.
	(check_remove_regno_access): New.
	* rtl-ssa/accesses.cc (rtl_ssa::remove_note_accesses_base): Use
	new filter_accesses helper.
This commit is contained in:
Alex Coplan 2023-11-01 21:45:39 +00:00
parent a49befbd2c
commit fea27dfd22
2 changed files with 46 additions and 8 deletions

View File

@ -78,6 +78,46 @@ drop_memory_access (T accesses)
return T (arr.begin (), accesses.size () - 1);
}
// Filter ACCESSES to return an access_array of only those accesses that
// satisfy PREDICATE. Alocate the new array above WATERMARK.
template<typename T, typename FilterPredicate>
inline T
filter_accesses (obstack_watermark &watermark,
T accesses,
FilterPredicate predicate)
{
access_array_builder builder (watermark);
builder.reserve (accesses.size ());
for (auto access : accesses)
if (predicate (access))
builder.quick_push (access);
return T (builder.finish ());
}
// Given an array of ACCESSES, remove any access with regno REGNO.
// Allocate the new access array above WM.
template<typename T>
inline T
remove_regno_access (obstack_watermark &watermark,
T accesses, unsigned int regno)
{
using Access = decltype (accesses[0]);
auto pred = [regno](Access a) { return a->regno () != regno; };
return filter_accesses (watermark, accesses, pred);
}
// As above, but additionally check that we actually did remove an access.
template<typename T>
inline T
check_remove_regno_access (obstack_watermark &watermark,
T accesses, unsigned regno)
{
auto orig_size = accesses.size ();
auto result = remove_regno_access (watermark, accesses, regno);
gcc_assert (result.size () < orig_size);
return result;
}
// If sorted array ACCESSES includes a reference to REGNO, return the
// access, otherwise return null.
template<typename T>

View File

@ -1597,16 +1597,14 @@ access_array
rtl_ssa::remove_note_accesses_base (obstack_watermark &watermark,
access_array accesses)
{
auto predicate = [](access_info *a) {
return !a->only_occurs_in_notes ();
};
for (access_info *access : accesses)
if (access->only_occurs_in_notes ())
{
access_array_builder builder (watermark);
builder.reserve (accesses.size ());
for (access_info *access2 : accesses)
if (!access2->only_occurs_in_notes ())
builder.quick_push (access2);
return builder.finish ();
}
return filter_accesses (watermark, accesses, predicate);
return accesses;
}