Commit 70f2bd0d authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

[cleanup] Make {AreAliased} generic and variadic

This allows to have only one version of {AreAliased} which has a
clean implementation.

R=mstarzinger@chromium.org

Bug: v8:8015
Change-Id: I25c64a8c2077383129548773319799fac768521e
Reviewed-on: https://chromium-review.googlesource.com/1167290
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Reviewed-by: 's avatarMichael Starzinger <mstarzinger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#55007}
parent ecf51e34
...@@ -114,6 +114,16 @@ constexpr auto fold(Func func, Ts&&... more) -> ...@@ -114,6 +114,16 @@ constexpr auto fold(Func func, Ts&&... more) ->
std::forward<Ts>(more)...); std::forward<Ts>(more)...);
} }
// {is_same<Ts...>::value} is true if all Ts are the same, false otherwise.
template <typename... Ts>
struct is_same : public std::false_type {};
template <>
struct is_same<> : public std::true_type {};
template <typename T>
struct is_same<T> : public std::true_type {};
template <typename T, typename... Ts>
struct is_same<T, T, Ts...> : public is_same<T, Ts...> {};
} // namespace base } // namespace base
} // namespace v8 } // namespace v8
......
...@@ -130,58 +130,5 @@ void TurboAssemblerBase::RecordCommentForOffHeapTrampoline(int builtin_index) { ...@@ -130,58 +130,5 @@ void TurboAssemblerBase::RecordCommentForOffHeapTrampoline(int builtin_index) {
RecordComment(buffer_start); RecordComment(buffer_start);
} }
#ifdef DEBUG
bool AreAliased(Register reg1, Register reg2, Register reg3, Register reg4,
Register reg5, Register reg6, Register reg7, Register reg8,
Register reg9, Register reg10) {
int n_of_valid_regs = reg1.is_valid() + reg2.is_valid() + reg3.is_valid() +
reg4.is_valid() + reg5.is_valid() + reg6.is_valid() +
reg7.is_valid() + reg8.is_valid() + reg9.is_valid() +
reg10.is_valid();
RegList regs = 0;
if (reg1.is_valid()) regs |= reg1.bit();
if (reg2.is_valid()) regs |= reg2.bit();
if (reg3.is_valid()) regs |= reg3.bit();
if (reg4.is_valid()) regs |= reg4.bit();
if (reg5.is_valid()) regs |= reg5.bit();
if (reg6.is_valid()) regs |= reg6.bit();
if (reg7.is_valid()) regs |= reg7.bit();
if (reg8.is_valid()) regs |= reg8.bit();
if (reg9.is_valid()) regs |= reg9.bit();
if (reg10.is_valid()) regs |= reg10.bit();
int n_of_non_aliasing_regs = NumRegs(regs);
return n_of_valid_regs != n_of_non_aliasing_regs;
}
bool AreAliased(DoubleRegister reg1, DoubleRegister reg2, DoubleRegister reg3,
DoubleRegister reg4, DoubleRegister reg5, DoubleRegister reg6,
DoubleRegister reg7, DoubleRegister reg8, DoubleRegister reg9,
DoubleRegister reg10) {
int n_of_valid_regs = reg1.is_valid() + reg2.is_valid() + reg3.is_valid() +
reg4.is_valid() + reg5.is_valid() + reg6.is_valid() +
reg7.is_valid() + reg8.is_valid() + reg9.is_valid() +
reg10.is_valid();
RegList regs = 0;
if (reg1.is_valid()) regs |= reg1.bit();
if (reg2.is_valid()) regs |= reg2.bit();
if (reg3.is_valid()) regs |= reg3.bit();
if (reg4.is_valid()) regs |= reg4.bit();
if (reg5.is_valid()) regs |= reg5.bit();
if (reg6.is_valid()) regs |= reg6.bit();
if (reg7.is_valid()) regs |= reg7.bit();
if (reg8.is_valid()) regs |= reg8.bit();
if (reg9.is_valid()) regs |= reg9.bit();
if (reg10.is_valid()) regs |= reg10.bit();
int n_of_non_aliasing_regs = NumRegs(regs);
return n_of_valid_regs != n_of_non_aliasing_regs;
}
#endif // DEBUG
} // namespace internal } // namespace internal
} // namespace v8 } // namespace v8
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#define V8_TURBO_ASSEMBLER_H_ #define V8_TURBO_ASSEMBLER_H_
#include "src/assembler-arch.h" #include "src/assembler-arch.h"
#include "src/base/template-utils.h"
#include "src/heap/heap.h" #include "src/heap/heap.h"
namespace v8 { namespace v8 {
...@@ -116,16 +117,16 @@ class HardAbortScope BASE_EMBEDDED { ...@@ -116,16 +117,16 @@ class HardAbortScope BASE_EMBEDDED {
enum class StubCallMode { kCallOnHeapBuiltin, kCallWasmRuntimeStub }; enum class StubCallMode { kCallOnHeapBuiltin, kCallWasmRuntimeStub };
#ifdef DEBUG #ifdef DEBUG
bool AreAliased(Register reg1, Register reg2, Register reg3 = no_reg, template <typename RegType, typename... RegTypes,
Register reg4 = no_reg, Register reg5 = no_reg, // All arguments must be either Register or DoubleRegister.
Register reg6 = no_reg, Register reg7 = no_reg, typename = typename std::enable_if<
Register reg8 = no_reg, Register reg9 = no_reg, base::is_same<Register, RegType, RegTypes...>::value ||
Register reg10 = no_reg); base::is_same<DoubleRegister, RegType, RegTypes...>::value>::type>
bool AreAliased(DoubleRegister reg1, DoubleRegister reg2, inline bool AreAliased(RegType first_reg, RegTypes... regs) {
DoubleRegister reg3 = no_dreg, DoubleRegister reg4 = no_dreg, int num_different_regs = NumRegs(RegType::ListOf(first_reg, regs...));
DoubleRegister reg5 = no_dreg, DoubleRegister reg6 = no_dreg, int num_given_regs = sizeof...(regs) + 1;
DoubleRegister reg7 = no_dreg, DoubleRegister reg8 = no_dreg, return num_different_regs < num_given_regs;
DoubleRegister reg9 = no_dreg, DoubleRegister reg10 = no_dreg); }
#endif #endif
} // namespace internal } // namespace internal
......
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