From 435075205330f7641757d0e98c4ed94e86c22e75 Mon Sep 17 00:00:00 2001 From: Paul Rigge Date: Mon, 26 Feb 2024 16:58:30 -0800 Subject: [PATCH] Drop our aliases for `DCHECK()`. Work towards google/xls#1318. PiperOrigin-RevId: 610570572 --- xls/common/bits_util.h | 4 ++-- xls/common/file/filesystem.cc | 2 +- xls/common/logging/logging.h | 11 +---------- xls/common/math_util.h | 8 ++++---- xls/contrib/xlscc/xlscc_logging.h | 5 ++--- xls/data_structures/inline_bitmap.h | 22 +++++++++++----------- xls/delay_model/delay_heap.cc | 10 +++++----- xls/dslx/type_system/concrete_type.cc | 2 +- xls/dslx/type_system/type_info.h | 2 +- xls/fuzzer/sample_runner_main.cc | 2 +- xls/ir/bits.h | 2 +- xls/ir/node_iterator.cc | 5 ++--- xls/ir/value.h | 2 +- xls/ir/value_utils.cc | 6 +++--- xls/ir/value_view.h | 4 ++-- xls/jit/BUILD | 1 + xls/jit/function_base_jit.cc | 8 +++----- xls/jit/type_layout.cc | 4 +++- xls/netlist/lib_parser.cc | 4 ++-- xls/netlist/lib_parser.h | 4 ++-- xls/passes/narrowing_pass.cc | 8 ++++---- xls/passes/strength_reduction_pass.cc | 4 ++-- 22 files changed, 55 insertions(+), 65 deletions(-) diff --git a/xls/common/bits_util.h b/xls/common/bits_util.h index 5fc4780f0f..7fc0766f31 100644 --- a/xls/common/bits_util.h +++ b/xls/common/bits_util.h @@ -26,8 +26,8 @@ constexpr int64_t kCharBit = 8; // Helper that generates an (unsigned) mask with "bit_count" low bits set. inline uint64_t Mask(int64_t bit_count) { - XLS_DCHECK_GE(bit_count, 0); - XLS_DCHECK_LE(bit_count, 64); + DCHECK_GE(bit_count, 0); + DCHECK_LE(bit_count, 64); return bit_count == 64 ? -1ULL : (1ULL << bit_count) - 1; } diff --git a/xls/common/file/filesystem.cc b/xls/common/file/filesystem.cc index 936dd735d5..c1c1ca108d 100644 --- a/xls/common/file/filesystem.cc +++ b/xls/common/file/filesystem.cc @@ -221,7 +221,7 @@ absl::Status ParseTextProto(std::string_view contents, // Needed for this to compile in OSS, for some reason std::string contents_owned(contents.begin(), contents.end()); const bool success = parser.ParseFromString(contents_owned, proto); - XLS_DCHECK_EQ(success, collector.status().ok()); + DCHECK_EQ(success, collector.status().ok()); return collector.status(); } diff --git a/xls/common/logging/logging.h b/xls/common/logging/logging.h index 0fb6488304..e3c0e14fb2 100644 --- a/xls/common/logging/logging.h +++ b/xls/common/logging/logging.h @@ -197,7 +197,7 @@ // ----------------------------------------------------------------------------- // // `XLS_CHECK` macros terminate the program with a fatal error if the specified -// condition is not true. Except for `XLS_DCHECK`, they are not controlled by +// condition is not true. Except for `DCHECK`, they are not controlled by // `NDEBUG` (cf. `assert`), so the check will be executed regardless of // compilation mode. `XLS_CHECK` and friends are thus useful for confirming // invariants in situations where continuing to run would be worse than @@ -229,17 +229,8 @@ #define XLS_QCHECK_GE(val1, val2) QCHECK_GE(val1, val2) #define XLS_QCHECK_GT(val1, val2) QCHECK_GT(val1, val2) -#define XLS_DCHECK(condition) DCHECK(condition) -#define XLS_DCHECK_EQ(val1, val2) DCHECK_EQ(val1, val2) -#define XLS_DCHECK_NE(val1, val2) DCHECK_NE(val1, val2) -#define XLS_DCHECK_LE(val1, val2) DCHECK_LE(val1, val2) -#define XLS_DCHECK_LT(val1, val2) DCHECK_LT(val1, val2) -#define XLS_DCHECK_GE(val1, val2) DCHECK_GE(val1, val2) -#define XLS_DCHECK_GT(val1, val2) DCHECK_GT(val1, val2) - #define XLS_CHECK_OK(val) CHECK_OK(val) #define XLS_QCHECK_OK(val) QCHECK_OK(val) -#define XLS_DCHECK_OK(val) DCHECK_OK(val) #endif // XLS_COMMON_LOGGING_LOGGING_H_ diff --git a/xls/common/math_util.h b/xls/common/math_util.h index ac15e83694..9d64cf1f5e 100644 --- a/xls/common/math_util.h +++ b/xls/common/math_util.h @@ -37,10 +37,10 @@ constexpr IntegralType CeilOrFloorOfRatio(IntegralType numerator, IntegralType denominator) { static_assert(std::numeric_limits::is_integer, "CeilOfRatio is only defined for integral types"); - XLS_DCHECK_NE(0, denominator) << "Division by zero is not supported."; - XLS_DCHECK(!std::numeric_limits::is_signed || - numerator != std::numeric_limits::min() || - denominator != -1) + DCHECK_NE(0, denominator) << "Division by zero is not supported."; + DCHECK(!std::numeric_limits::is_signed || + numerator != std::numeric_limits::min() || + denominator != -1) << "Dividing " << numerator << " by -1 is not supported: it would SIGFPE"; const IntegralType rounded_toward_zero = numerator / denominator; diff --git a/xls/contrib/xlscc/xlscc_logging.h b/xls/contrib/xlscc/xlscc_logging.h index 6fcf99758f..8ae09a7ecf 100644 --- a/xls/contrib/xlscc/xlscc_logging.h +++ b/xls/contrib/xlscc/xlscc_logging.h @@ -19,8 +19,7 @@ XLS_CHECK(condition) << ErrorMessage(loc, "") #define XLSCC_QCHECK(condition, loc) \ XLS_QCHECK(condition) << ErrorMessage(loc, "") -#define XLSCC_DCHECK(condition, loc) \ - XLS_DCHECK(condition) << ErrorMessage(loc, "") +#define XLSCC_DCHECK(condition, loc) DCHECK(condition) << ErrorMessage(loc, "") #define XLSCC_CHECK_EQ(val1, val2, loc) \ XLS_CHECK_EQ(val1, val2) << ErrorMessage(loc, "") @@ -62,6 +61,6 @@ #define XLSCC_CHECK_OK(val, loc) XLS_CHECK_EQ(val) << ErrorMessage(loc, "") #define XLSCC_QCHECK_OK(val, loc) XLS_QCHECK_EQ(val) << ErrorMessage(loc, "") -#define XLSCC_DCHECK_OK(val, loc) XLS_DCHECK_EQ(val) << ErrorMessage(loc), "" +#define XLSCC_DCHECK_OK(val, loc) DCHECK_EQ(val) << ErrorMessage(loc), "" #endif // XLSCC_COMMON_LOGGING_LOGGING_H_ diff --git a/xls/data_structures/inline_bitmap.h b/xls/data_structures/inline_bitmap.h index d3ba83a909..62798ec12c 100644 --- a/xls/data_structures/inline_bitmap.h +++ b/xls/data_structures/inline_bitmap.h @@ -95,7 +95,7 @@ class InlineBitmap { : bit_count_(bit_count), data_(CeilOfRatio(bit_count, kWordBits), fill ? ~uint64_t{0} : uint64_t{0}) { - XLS_DCHECK_GE(bit_count, 0); + DCHECK_GE(bit_count, 0); // If we initialized our data to zero, no need to mask out the bits past the // end of the bitmap; they're already zero. if (fill) { @@ -134,15 +134,15 @@ class InlineBitmap { return true; } inline bool Get(int64_t index) const { - XLS_DCHECK_GE(index, 0); - XLS_DCHECK_LT(index, bit_count()); + DCHECK_GE(index, 0); + DCHECK_LT(index, bit_count()); uint64_t word = data_[index / kWordBits]; uint64_t bitno = index % kWordBits; return (word >> bitno) & 1ULL; } inline void Set(int64_t index, bool value = true) { - XLS_DCHECK_GE(index, 0); - XLS_DCHECK_LT(index, bit_count()); + DCHECK_GE(index, 0); + DCHECK_LT(index, bit_count()); uint64_t& word = data_[index / kWordBits]; uint64_t bitno = index % kWordBits; if (value) { @@ -155,8 +155,8 @@ class InlineBitmap { // [lower_index, upper_index). inline void SetRange(int64_t lower_index, int64_t upper_index, bool value = true) { - XLS_DCHECK_GE(lower_index, 0); - XLS_DCHECK_LE(upper_index, bit_count()); + DCHECK_GE(lower_index, 0); + DCHECK_LE(upper_index, bit_count()); for (int64_t index = lower_index; index < upper_index; ++index) { Set(index, value); } @@ -172,11 +172,11 @@ class InlineBitmap { if (wordno == 0 && word_count() == 0) { return 0; } - XLS_DCHECK_LT(wordno, word_count()); + DCHECK_LT(wordno, word_count()); return data_[wordno]; } void SetWord(int64_t wordno, uint64_t value) { - XLS_DCHECK_LT(wordno, word_count()); + DCHECK_LT(wordno, word_count()); data_[wordno] = value & MaskForWord(wordno); } @@ -191,7 +191,7 @@ class InlineBitmap { // of word 0, byte 7 is mapped to the most significant bits of word 0, byte 8 // is mapped to the least significant bits of word 1, and so on. void SetByte(int64_t byteno, uint8_t value) { - XLS_DCHECK_LT(byteno, byte_count()); + DCHECK_LT(byteno, byte_count()); XLS_CHECK(kEndianness == Endianness::kLittleEndian); absl::bit_cast(data_.data())[byteno] = value; // Ensure the data is appropriately masked in case this byte writes to that @@ -201,7 +201,7 @@ class InlineBitmap { // Returns the byte at the given offset. Byte order is little-endian. uint8_t GetByte(int64_t byteno) const { - XLS_DCHECK_LT(byteno, byte_count()); + DCHECK_LT(byteno, byte_count()); XLS_CHECK(kEndianness == Endianness::kLittleEndian); return absl::bit_cast(data_.data())[byteno]; } diff --git a/xls/delay_model/delay_heap.cc b/xls/delay_model/delay_heap.cc index 1008e71df5..220d6ec085 100644 --- a/xls/delay_model/delay_heap.cc +++ b/xls/delay_model/delay_heap.cc @@ -41,8 +41,8 @@ DelayHeap::PathLength DelayHeap::MaxAmongPredecessors(Node* node) const { absl::Status DelayHeap::Add(Node* node) { XLS_CHECK(!contains(node)); - XLS_DCHECK(!std::any_of(successors(node).begin(), successors(node).end(), - [&](Node* n) { return contains(n); })); + DCHECK(!std::any_of(successors(node).begin(), successors(node).end(), + [&](Node* n) { return contains(n); })); XLS_ASSIGN_OR_RETURN(int64_t node_delay, delay_estimator_.GetOperationDelayInPs(node)); PathLength path = MaxAmongPredecessors(node); @@ -64,8 +64,8 @@ absl::Status DelayHeap::Add(Node* node) { } DelayHeap::FrontierSet::iterator DelayHeap::Remove(Node* node) { - XLS_DCHECK(!std::any_of(successors(node).begin(), successors(node).end(), - [&](Node* n) { return contains(n); })); + DCHECK(!std::any_of(successors(node).begin(), successors(node).end(), + [&](Node* n) { return contains(n); })); // Node must be on the frontier to be erased. auto it = frontier_.find(node); XLS_CHECK(it != frontier_.end()) @@ -97,7 +97,7 @@ absl::StatusOr DelayHeap::CriticalPathDelayAfterAdding( int64_t DelayHeap::CriticalPathDelayAfterRemoving(Node* node) const { XLS_CHECK(contains(node)); - XLS_DCHECK_EQ(frontier_.count(node), 1); + DCHECK_EQ(frontier_.count(node), 1); if (node != top()) { return CriticalPathDelay(); } diff --git a/xls/dslx/type_system/concrete_type.cc b/xls/dslx/type_system/concrete_type.cc index 24872a7de3..3e4259d22a 100644 --- a/xls/dslx/type_system/concrete_type.cc +++ b/xls/dslx/type_system/concrete_type.cc @@ -476,7 +476,7 @@ TupleType::TupleType(std::vector> members) : members_(std::move(members)) { #ifndef NDEBUG for (const auto& member : members_) { - XLS_DCHECK(member != nullptr); + DCHECK(member != nullptr); } #endif } diff --git a/xls/dslx/type_system/type_info.h b/xls/dslx/type_system/type_info.h index 5766b75217..b230a05563 100644 --- a/xls/dslx/type_system/type_info.h +++ b/xls/dslx/type_system/type_info.h @@ -376,7 +376,7 @@ inline absl::StatusOr TypeInfo::GetItemAs(const AstNode* key) const { absl::StrFormat("No type found for AST node: %s @ %s", key->ToString(), SpanToString(key->GetSpan()))); } - XLS_DCHECK(t.value() != nullptr); + DCHECK(t.value() != nullptr); auto* target = dynamic_cast(t.value()); if (target == nullptr) { return absl::FailedPreconditionError(absl::StrFormat( diff --git a/xls/fuzzer/sample_runner_main.cc b/xls/fuzzer/sample_runner_main.cc index 6a837f3b6f..211173542b 100644 --- a/xls/fuzzer/sample_runner_main.cc +++ b/xls/fuzzer/sample_runner_main.cc @@ -59,7 +59,7 @@ namespace { // returns the basename of the file. std::filesystem::path MaybeCopyFile(const std::filesystem::path& file_path, const std::filesystem::path& dir_path) { - XLS_DCHECK(std::filesystem::is_directory(dir_path)); + DCHECK(std::filesystem::is_directory(dir_path)); std::filesystem::path basename = file_path.filename(); if (file_path.parent_path() != dir_path) { std::filesystem::copy_file(file_path, dir_path / basename); diff --git a/xls/ir/bits.h b/xls/ir/bits.h index a7fc4f9737..bed627d176 100644 --- a/xls/ir/bits.h +++ b/xls/ir/bits.h @@ -134,7 +134,7 @@ class Bits { // As above, but retrieves with index "0" starting at the MSb side of the bit // vector. bool GetFromMsb(int64_t index) const { - XLS_DCHECK_LT(index, bit_count()); + DCHECK_LT(index, bit_count()); return bitmap_.Get(bit_count() - index - 1); } diff --git a/xls/ir/node_iterator.cc b/xls/ir/node_iterator.cc index 63e4b328b6..11085866da 100644 --- a/xls/ir/node_iterator.cc +++ b/xls/ir/node_iterator.cc @@ -76,8 +76,7 @@ void NodeIterator::Initialize() { }; auto add_to_order = [&](Node* r) { XLS_VLOG(5) << "Adding node to order: " << r; - XLS_DCHECK(all_users_scheduled(r)) - << r << " users size: " << r->users().size(); + DCHECK(all_users_scheduled(r)) << r << " users size: " << r->users().size(); ordered_->push_back(r); // We want to be careful to only bump down our operands once, since we're a @@ -111,7 +110,7 @@ void NodeIterator::Initialize() { // front. return_value = node; } else { - XLS_DCHECK(all_users_scheduled(node)); + DCHECK(all_users_scheduled(node)); XLS_VLOG(5) << "At start node was ready: " << node; seed_ready(node); } diff --git a/xls/ir/value.h b/xls/ir/value.h index 6d53a0b2f2..32e09df090 100644 --- a/xls/ir/value.h +++ b/xls/ir/value.h @@ -97,7 +97,7 @@ class Value { // type. static Value ArrayOwned(std::vector&& elements) { for (int64_t i = 1; i < elements.size(); ++i) { - XLS_DCHECK(elements[0].SameTypeAs(elements[i])); + DCHECK(elements[0].SameTypeAs(elements[i])); } return Value(ValueKind::kArray, std::move(elements)); } diff --git a/xls/ir/value_utils.cc b/xls/ir/value_utils.cc index 13b75c1c60..d5adb1b704 100644 --- a/xls/ir/value_utils.cc +++ b/xls/ir/value_utils.cc @@ -101,9 +101,9 @@ absl::StatusOr TupleToF32(const Value& v) { XLS_RET_CHECK_EQ(v.element(2).bits().bit_count(), 23); XLS_ASSIGN_OR_RETURN(uint32_t fraction, v.element(2).bits().ToUint64()); // Validate the values were all appropriate. - XLS_DCHECK_EQ(sign, sign & Mask(1)); - XLS_DCHECK_EQ(exp, exp & Mask(8)); - XLS_DCHECK_EQ(fraction, fraction & Mask(23)); + DCHECK_EQ(sign, sign & Mask(1)); + DCHECK_EQ(exp, exp & Mask(8)); + DCHECK_EQ(fraction, fraction & Mask(23)); // Reconstruct the float. uint32_t x = (sign << 31) | (exp << 23) | fraction; return absl::bit_cast(x); diff --git a/xls/ir/value_view.h b/xls/ir/value_view.h index c045a0bfb2..85c5c5ef94 100644 --- a/xls/ir/value_view.h +++ b/xls/ir/value_view.h @@ -255,7 +255,7 @@ class PackedBitsView { // should be incremented). PackedBitsView(uint8_t* buffer, int buffer_offset) : buffer_(buffer), buffer_offset_(buffer_offset) { - XLS_DCHECK(buffer_offset >= 0 && buffer_offset <= 7); + DCHECK(buffer_offset >= 0 && buffer_offset <= 7); } // Returns the XLS IR Type corresponding to this packed view. @@ -379,7 +379,7 @@ class PackedArrayView { // Returns the element at the given index in the array. ElementT Get(int index) { - XLS_DCHECK_LT(index, kNumElements); + DCHECK_LT(index, kNumElements); int64_t bit_increment = index * ElementT::kBitCount + buffer_offset_; int64_t byte_offset = bit_increment / kCharBit; int64_t bit_offset = bit_increment % kCharBit; diff --git a/xls/jit/BUILD b/xls/jit/BUILD index e15d7be2a6..f06cdd1863 100644 --- a/xls/jit/BUILD +++ b/xls/jit/BUILD @@ -657,6 +657,7 @@ cc_library( hdrs = ["type_layout.h"], deps = [ ":type_layout_cc_proto", + "@com_google_absl//absl/log:check", "@com_google_absl//absl/strings:str_format", "@com_google_absl//absl/types:span", "//xls/ir", diff --git a/xls/jit/function_base_jit.cc b/xls/jit/function_base_jit.cc index 112bb56c2c..004573a95a 100644 --- a/xls/jit/function_base_jit.cc +++ b/xls/jit/function_base_jit.cc @@ -1384,11 +1384,9 @@ int64_t JittedFunctionBase::RunUnalignedJittedFunction( InterpreterEvents* events, InstanceContext* instance_context, JitRuntime* jit_runtime, int64_t continuation) const { if constexpr (kForceZeroCopy) { - XLS_DCHECK_OK( - VerifyOffsetAlignments(inputs, input_buffer_abi_alignments())); - XLS_DCHECK_OK( - VerifyOffsetAlignments(outputs, output_buffer_abi_alignments())); - XLS_DCHECK(IsAligned(temp_buffer, temp_buffer_alignment_)); + DCHECK_OK(VerifyOffsetAlignments(inputs, input_buffer_abi_alignments())); + DCHECK_OK(VerifyOffsetAlignments(outputs, output_buffer_abi_alignments())); + DCHECK(IsAligned(temp_buffer, temp_buffer_alignment_)); } else { if (!VerifyOffsetAlignments(inputs, input_buffer_abi_alignments()).ok() || !VerifyOffsetAlignments(outputs, output_buffer_abi_alignments()).ok() || diff --git a/xls/jit/type_layout.cc b/xls/jit/type_layout.cc index 03c408f395..453fc0a743 100644 --- a/xls/jit/type_layout.cc +++ b/xls/jit/type_layout.cc @@ -20,6 +20,8 @@ #include #include +#include "absl/log/check.h" +#include "absl/strings/str_format.h" #include "xls/ir/ir_parser.h" #include "xls/ir/value_utils.h" @@ -48,7 +50,7 @@ static void LeafValueToNativeLayout(const Value& value, void TypeLayout::ValueToNativeLayout(const Value& value, uint8_t* buffer) const { - XLS_DCHECK(ValueConformsToType(value, type())) << absl::StreamFormat( + DCHECK(ValueConformsToType(value, type())) << absl::StreamFormat( "Value `%s` is not of type `%s`", value.ToString(), type()->ToString()); if (IsLeafValue(value)) { diff --git a/xls/netlist/lib_parser.cc b/xls/netlist/lib_parser.cc index 4b23fe4e23..39ed7cafdb 100644 --- a/xls/netlist/lib_parser.cc +++ b/xls/netlist/lib_parser.cc @@ -122,8 +122,8 @@ absl::StatusOr Scanner::ScanQuotedString() { } absl::Status Scanner::PeekInternal() { - XLS_DCHECK(!lookahead_.has_value()); - XLS_DCHECK(!cs_->AtEof()); + DCHECK(!lookahead_.has_value()); + DCHECK(!cs_->AtEof()); if (IsIdentifierStart(cs_->PeekCharOrDie())) { XLS_ASSIGN_OR_RETURN(lookahead_, ScanIdentifier()); DropWhitespaceAndComments(); diff --git a/xls/netlist/lib_parser.h b/xls/netlist/lib_parser.h index 78cef2d664..725868b9ba 100644 --- a/xls/netlist/lib_parser.h +++ b/xls/netlist/lib_parser.h @@ -75,10 +75,10 @@ class CharStream { } char PeekCharOrDie() { if (if_.has_value()) { - XLS_DCHECK(!if_->eof()); + DCHECK(!if_->eof()); return if_->peek(); } - XLS_DCHECK_LT(cursor_, text_.size()); + DCHECK_LT(cursor_, text_.size()); return text_[cursor_]; } char PopCharOrDie() { diff --git a/xls/passes/narrowing_pass.cc b/xls/passes/narrowing_pass.cc index 3f07072488..896f8e0e3a 100644 --- a/xls/passes/narrowing_pass.cc +++ b/xls/passes/narrowing_pass.cc @@ -526,7 +526,7 @@ class NarrowVisitor final : public DfsVisitorWithDefault { TernaryVector constant_bits = ternary_ops::BitsToTernary(elements[0].bits()); for (const Value& element : elements) { - XLS_DCHECK(element.IsBits()); + DCHECK(element.IsBits()); ternary_ops::UpdateWithIntersection(constant_bits, element.bits()); } @@ -608,7 +608,7 @@ class NarrowVisitor final : public DfsVisitorWithDefault { if (!current_unknown_slice.empty()) { XLS_RETURN_IF_ERROR(finish_unknown_slice()); } - XLS_DCHECK_GT(slices.size(), 1); + DCHECK_GT(slices.size(), 1); std::vector narrowed_elements; narrowed_elements.reserve(array_literal->value().elements().size()); @@ -668,7 +668,7 @@ class NarrowVisitor final : public DfsVisitorWithDefault { if (sliced_array.slices.size() == 1) { if (std::holds_alternative(sliced_array.slices[0])) { // This array can't be narrowed. - XLS_DCHECK_EQ(sliced_array.array_literal, literal); + DCHECK_EQ(sliced_array.array_literal, literal); return NoChange(); } @@ -731,7 +731,7 @@ class NarrowVisitor final : public DfsVisitorWithDefault { } else { XLS_CHECK(std::holds_alternative(slice)); Literal* constant_slice = std::get(slice); - XLS_DCHECK(constant_slice->value().IsBits()); + DCHECK(constant_slice->value().IsBits()); bit_slices.push_back(constant_slice); } } diff --git a/xls/passes/strength_reduction_pass.cc b/xls/passes/strength_reduction_pass.cc index 23a8a4b235..b3a6aeca76 100644 --- a/xls/passes/strength_reduction_pass.cc +++ b/xls/passes/strength_reduction_pass.cc @@ -83,8 +83,8 @@ absl::StatusOr MaybeSinkOperationIntoSelect( // bother. return false; } - XLS_DCHECK(!query_engine.IsFullyKnown(select_val)); - XLS_DCHECK(select_val->AllCases( + DCHECK(!query_engine.IsFullyKnown(select_val)); + DCHECK(select_val->AllCases( [&](Node* c) { return query_engine.IsFullyKnown(c); })); auto operands = node->operands();