Commit 09fd7c71 authored by Jakob Gruber's avatar Jakob Gruber Committed by Commit Bot

Use the new CONSTEXPR_DCHECK macro

Introduced in https://crrev.com/c/2250243.

CONSTEXPR_DCHECK(cond) replaces the longer

 #if V8_HAS_CXX14_CONSTEXPR
     DCHECK(cond);
 #endif

pattern.

Change-Id: I636e5b4b40bffb29b2e82c81285b2ef78a822745
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2250244Reviewed-by: 's avatarClemens Backes <clemensb@chromium.org>
Commit-Queue: Jakob Gruber <jgruber@chromium.org>
Cr-Commit-Position: refs/heads/master@{#68402}
parent 3864e1f2
......@@ -52,9 +52,7 @@ class BitField final {
// Returns a type U with the bit field value encoded.
static constexpr U encode(T value) {
#if V8_HAS_CXX14_CONSTEXPR
DCHECK(is_valid(value));
#endif
CONSTEXPR_DCHECK(is_valid(value));
return static_cast<U>(value) << kShift;
}
......
......@@ -145,9 +145,7 @@ constexpr inline bool IsPowerOfTwo(T value) {
template <typename T,
typename = typename std::enable_if<std::is_integral<T>::value>::type>
inline constexpr int WhichPowerOfTwo(T value) {
#if V8_HAS_CXX14_CONSTEXPR
DCHECK(IsPowerOfTwo(value));
#endif
CONSTEXPR_DCHECK(IsPowerOfTwo(value));
#if V8_HAS_BUILTIN_CTZ
STATIC_ASSERT(sizeof(T) <= 8);
return sizeof(T) == 8 ? __builtin_ctzll(static_cast<uint64_t>(value))
......
......@@ -15,9 +15,7 @@ namespace base {
// branch.
template <typename T, typename U>
inline constexpr bool IsInRange(T value, U lower_limit, U higher_limit) {
#if V8_HAS_CXX14_CONSTEXPR
DCHECK_LE(lower_limit, higher_limit);
#endif
CONSTEXPR_DCHECK(lower_limit <= higher_limit);
STATIC_ASSERT(sizeof(U) <= sizeof(T));
using unsigned_T = typename std::make_unsigned<T>::type;
// Use static_cast to support enum classes.
......
......@@ -63,9 +63,7 @@ class EnumSet {
explicit constexpr EnumSet(T bits) : bits_(bits) {}
static constexpr T Mask(E element) {
#if V8_HAS_CXX14_CONSTEXPR
DCHECK_GT(sizeof(T) * 8, static_cast<int>(element));
#endif
CONSTEXPR_DCHECK(sizeof(T) * 8 > static_cast<size_t>(element));
return T{1} << static_cast<typename std::underlying_type<E>::type>(element);
}
......
......@@ -558,44 +558,32 @@ class OPTIONAL_DECLSPEC_EMPTY_BASES Optional
}
constexpr const T* operator->() const {
#if V8_HAS_CXX14_CONSTEXPR
DCHECK(storage_.is_populated_);
#endif
CONSTEXPR_DCHECK(storage_.is_populated_);
return &storage_.value_;
}
constexpr T* operator->() {
#if V8_HAS_CXX14_CONSTEXPR
DCHECK(storage_.is_populated_);
#endif
CONSTEXPR_DCHECK(storage_.is_populated_);
return &storage_.value_;
}
constexpr const T& operator*() const& {
#if V8_HAS_CXX14_CONSTEXPR
DCHECK(storage_.is_populated_);
#endif
CONSTEXPR_DCHECK(storage_.is_populated_);
return storage_.value_;
}
constexpr T& operator*() & {
#if V8_HAS_CXX14_CONSTEXPR
DCHECK(storage_.is_populated_);
#endif
CONSTEXPR_DCHECK(storage_.is_populated_);
return storage_.value_;
}
constexpr const T&& operator*() const&& {
#if V8_HAS_CXX14_CONSTEXPR
DCHECK(storage_.is_populated_);
#endif
CONSTEXPR_DCHECK(storage_.is_populated_);
return std::move(storage_.value_);
}
constexpr T&& operator*() && {
#if V8_HAS_CXX14_CONSTEXPR
DCHECK(storage_.is_populated_);
#endif
CONSTEXPR_DCHECK(storage_.is_populated_);
return std::move(storage_.value_);
}
......
......@@ -92,9 +92,7 @@ class CPURegister : public RegisterBase<CPURegister, kRegAfterLast> {
}
static constexpr CPURegister Create(int code, int size, RegisterType type) {
#if V8_HAS_CXX14_CONSTEXPR
DCHECK(IsValid(code, size, type));
#endif
CONSTEXPR_DCHECK(IsValid(code, size, type));
return CPURegister{code, size, type};
}
......@@ -304,9 +302,7 @@ class VRegister : public CPURegister {
}
static constexpr VRegister Create(int code, int size, int lane_count = 1) {
#if V8_HAS_CXX14_CONSTEXPR
DCHECK(IsValidLaneCount(lane_count));
#endif
CONSTEXPR_DCHECK(IsValidLaneCount(lane_count));
return VRegister(CPURegister::Create(code, size, CPURegister::kVRegister),
lane_count);
}
......
......@@ -5,6 +5,7 @@
#ifndef V8_CODEGEN_REGISTER_H_
#define V8_CODEGEN_REGISTER_H_
#include "src/base/bounds.h"
#include "src/codegen/reglist.h"
namespace v8 {
......@@ -32,10 +33,7 @@ class RegisterBase {
static constexpr SubType no_reg() { return SubType{kCode_no_reg}; }
static constexpr SubType from_code(int code) {
#if V8_HAS_CXX14_CONSTEXPR
DCHECK_LE(0, code);
DCHECK_GT(kNumRegisters, code);
#endif
CONSTEXPR_DCHECK(base::IsInRange(code, 0, kNumRegisters - 1));
return SubType{code};
}
......@@ -47,9 +45,7 @@ class RegisterBase {
constexpr bool is_valid() const { return reg_code_ != kCode_no_reg; }
constexpr int code() const {
#if V8_HAS_CXX14_CONSTEXPR
DCHECK(is_valid());
#endif
CONSTEXPR_DCHECK(is_valid());
return reg_code_;
}
......
......@@ -30,18 +30,14 @@ struct InstanceRangeChecker {
template <InstanceType upper_limit>
struct InstanceRangeChecker<FIRST_TYPE, upper_limit> {
static constexpr bool Check(InstanceType value) {
#if V8_HAS_CXX14_CONSTEXPR
DCHECK_LE(FIRST_TYPE, value);
#endif
CONSTEXPR_DCHECK(FIRST_TYPE <= value);
return value <= upper_limit;
}
};
template <InstanceType lower_limit>
struct InstanceRangeChecker<lower_limit, LAST_TYPE> {
static constexpr bool Check(InstanceType value) {
#if V8_HAS_CXX14_CONSTEXPR
DCHECK_GE(LAST_TYPE, value);
#endif
CONSTEXPR_DCHECK(LAST_TYPE >= value);
return value >= lower_limit;
}
};
......
......@@ -40,9 +40,7 @@ class InternalIndex {
return static_cast<uint32_t>(entry_);
}
constexpr int as_int() const {
#if V8_HAS_CXX14_CONSTEXPR
DCHECK_LE(entry_, std::numeric_limits<int>::max());
#endif
CONSTEXPR_DCHECK(entry_ <= std::numeric_limits<int>::max());
return static_cast<int>(entry_);
}
......
......@@ -89,9 +89,7 @@ inline constexpr uint16_t ToLatin1Lower(uint16_t ch) {
// Does not work for U+00DF (sharp-s), U+00B5 (micron), U+00FF.
inline constexpr uint16_t ToLatin1Upper(uint16_t ch) {
#if V8_HAS_CXX14_CONSTEXPR
DCHECK(ch != 0xDF && ch != 0xB5 && ch != 0xFF);
#endif
CONSTEXPR_DCHECK(ch != 0xDF && ch != 0xB5 && ch != 0xFF);
return ch &
~((IsAsciiLower(ch) || (((ch & 0xE0) == 0xE0) && ch != 0xF7)) << 5);
}
......
......@@ -26,9 +26,7 @@ class Smi : public Object {
// in that we want them to be constexprs.
constexpr Smi() : Object() {}
explicit constexpr Smi(Address ptr) : Object(ptr) {
#if V8_HAS_CXX14_CONSTEXPR
DCHECK(HAS_SMI_TAG(ptr));
#endif
CONSTEXPR_DCHECK(HAS_SMI_TAG(ptr));
}
// Returns the integer value.
......@@ -45,9 +43,7 @@ class Smi : public Object {
// Convert a value to a Smi object.
static inline constexpr Smi FromInt(int value) {
#if V8_HAS_CXX14_CONSTEXPR
DCHECK(Smi::IsValid(value));
#endif
CONSTEXPR_DCHECK(Smi::IsValid(value));
return Smi(Internals::IntToSmi(value));
}
......@@ -73,10 +69,8 @@ class Smi : public Object {
// Returns whether value can be represented in a Smi.
static inline bool constexpr IsValid(intptr_t value) {
#if V8_HAS_CXX14_CONSTEXPR
DCHECK_EQ(Internals::IsValidSmi(value),
value >= kMinValue && value <= kMaxValue);
#endif
CONSTEXPR_DCHECK(Internals::IsValidSmi(value) ==
(value >= kMinValue && value <= kMaxValue));
return Internals::IsValidSmi(value);
}
......
......@@ -88,9 +88,8 @@ class TaggedImpl {
// Returns true if this tagged value is a strong pointer to a HeapObject.
constexpr inline bool IsStrong() const {
#if V8_HAS_CXX14_CONSTEXPR
DCHECK_IMPLIES(!kCanBeWeak, !IsSmi() == HAS_STRONG_HEAP_OBJECT_TAG(ptr_));
#endif
CONSTEXPR_DCHECK(kCanBeWeak ||
(!IsSmi() == HAS_STRONG_HEAP_OBJECT_TAG(ptr_)));
return kCanBeWeak ? HAS_STRONG_HEAP_OBJECT_TAG(ptr_) : !IsSmi();
}
......
......@@ -38,9 +38,7 @@ class TaggedIndex : public Object {
// special in that we want them to be constexprs.
constexpr TaggedIndex() : Object() {}
explicit constexpr TaggedIndex(Address ptr) : Object(ptr) {
#if V8_HAS_CXX14_CONSTEXPR
DCHECK(HAS_SMI_TAG(ptr));
#endif
CONSTEXPR_DCHECK(HAS_SMI_TAG(ptr));
}
// Returns the integer value.
......@@ -51,9 +49,7 @@ class TaggedIndex : public Object {
// Convert a value to a TaggedIndex object.
static inline TaggedIndex FromIntptr(intptr_t value) {
#if V8_HAS_CXX14_CONSTEXPR
DCHECK(TaggedIndex::IsValid(value));
#endif
CONSTEXPR_DCHECK(TaggedIndex::IsValid(value));
return TaggedIndex((static_cast<Address>(value) << kSmiTagSize) | kSmiTag);
}
......
......@@ -28,9 +28,7 @@ class Vector {
constexpr Vector() : start_(nullptr), length_(0) {}
constexpr Vector(T* data, size_t length) : start_(data), length_(length) {
#if V8_HAS_CXX14_CONSTEXPR
DCHECK(length == 0 || data != nullptr);
#endif
CONSTEXPR_DCHECK(length == 0 || data != nullptr);
}
static Vector<T> New(size_t length) {
......
......@@ -65,30 +65,22 @@ class ValueType {
constexpr ValueType() : bit_field_(KindField::encode(kStmt)) {}
explicit constexpr ValueType(Kind kind)
: bit_field_(KindField::encode(kind)) {
#if V8_HAS_CXX14_CONSTEXPR
DCHECK(!has_immediate());
#endif
CONSTEXPR_DCHECK(!has_immediate());
}
constexpr ValueType(Kind kind, uint32_t ref_index)
: bit_field_(KindField::encode(kind) | RefIndexField::encode(ref_index)) {
#if V8_HAS_CXX14_CONSTEXPR
DCHECK(has_immediate());
#endif
CONSTEXPR_DCHECK(has_immediate());
}
constexpr Kind kind() const { return KindField::decode(bit_field_); }
constexpr uint32_t ref_index() const {
#if V8_HAS_CXX14_CONSTEXPR
DCHECK(has_immediate());
#endif
CONSTEXPR_DCHECK(has_immediate());
return RefIndexField::decode(bit_field_);
}
constexpr int element_size_log2() const {
#if V8_HAS_CXX14_CONSTEXPR
DCHECK_NE(kStmt, kind());
DCHECK_NE(kBottom, kind());
#endif
CONSTEXPR_DCHECK(kStmt != kind());
CONSTEXPR_DCHECK(kBottom != kind());
constexpr int kElementSizeLog2[] = {
#define ELEM_SIZE_LOG2(kind, log2Size, ...) log2Size,
......@@ -119,9 +111,7 @@ class ValueType {
}
constexpr ValueTypeCode value_type_code() const {
#if V8_HAS_CXX14_CONSTEXPR
DCHECK_NE(kBottom, kind());
#endif
CONSTEXPR_DCHECK(kBottom != kind());
constexpr ValueTypeCode kValueTypeCode[] = {
#define TYPE_CODE(kind, log2Size, code, ...) kLocal##code,
......@@ -133,9 +123,7 @@ class ValueType {
}
constexpr MachineType machine_type() const {
#if V8_HAS_CXX14_CONSTEXPR
DCHECK_NE(kBottom, kind());
#endif
CONSTEXPR_DCHECK(kBottom != kind());
constexpr MachineType kMachineType[] = {
#define MACH_TYPE(kind, log2Size, code, machineType, ...) \
......
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