Skip to content

Commit

Permalink
Drop our aliases for DCHECK().
Browse files Browse the repository at this point in the history
Work towards google#1318.

PiperOrigin-RevId: 610570572
  • Loading branch information
grebe authored and copybara-github committed Feb 27, 2024
1 parent 31d30ca commit 4350752
Show file tree
Hide file tree
Showing 22 changed files with 55 additions and 65 deletions.
4 changes: 2 additions & 2 deletions xls/common/bits_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion xls/common/file/filesystem.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
11 changes: 1 addition & 10 deletions xls/common/logging/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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_
8 changes: 4 additions & 4 deletions xls/common/math_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ constexpr IntegralType CeilOrFloorOfRatio(IntegralType numerator,
IntegralType denominator) {
static_assert(std::numeric_limits<IntegralType>::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<IntegralType>::is_signed ||
numerator != std::numeric_limits<IntegralType>::min() ||
denominator != -1)
DCHECK_NE(0, denominator) << "Division by zero is not supported.";
DCHECK(!std::numeric_limits<IntegralType>::is_signed ||
numerator != std::numeric_limits<IntegralType>::min() ||
denominator != -1)
<< "Dividing " << numerator << " by -1 is not supported: it would SIGFPE";

const IntegralType rounded_toward_zero = numerator / denominator;
Expand Down
5 changes: 2 additions & 3 deletions xls/contrib/xlscc/xlscc_logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -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, "")
Expand Down Expand Up @@ -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_
22 changes: 11 additions & 11 deletions xls/data_structures/inline_bitmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand All @@ -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);
}
Expand All @@ -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);
}

Expand All @@ -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<uint8_t*>(data_.data())[byteno] = value;
// Ensure the data is appropriately masked in case this byte writes to that
Expand All @@ -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<uint8_t*>(data_.data())[byteno];
}
Expand Down
10 changes: 5 additions & 5 deletions xls/delay_model/delay_heap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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())
Expand Down Expand Up @@ -97,7 +97,7 @@ absl::StatusOr<int64_t> 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();
}
Expand Down
2 changes: 1 addition & 1 deletion xls/dslx/type_system/concrete_type.cc
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ TupleType::TupleType(std::vector<std::unique_ptr<ConcreteType>> members)
: members_(std::move(members)) {
#ifndef NDEBUG
for (const auto& member : members_) {
XLS_DCHECK(member != nullptr);
DCHECK(member != nullptr);
}
#endif
}
Expand Down
2 changes: 1 addition & 1 deletion xls/dslx/type_system/type_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ inline absl::StatusOr<T*> 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*>(t.value());
if (target == nullptr) {
return absl::FailedPreconditionError(absl::StrFormat(
Expand Down
2 changes: 1 addition & 1 deletion xls/fuzzer/sample_runner_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion xls/ir/bits.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
5 changes: 2 additions & 3 deletions xls/ir/node_iterator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion xls/ir/value.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class Value {
// type.
static Value ArrayOwned(std::vector<Value>&& 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));
}
Expand Down
6 changes: 3 additions & 3 deletions xls/ir/value_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ absl::StatusOr<float> 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<float>(x);
Expand Down
4 changes: 2 additions & 2 deletions xls/ir/value_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions xls/jit/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 3 additions & 5 deletions xls/jit/function_base_jit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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() ||
Expand Down
4 changes: 3 additions & 1 deletion xls/jit/type_layout.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#include <utility>
#include <vector>

#include "absl/log/check.h"
#include "absl/strings/str_format.h"
#include "xls/ir/ir_parser.h"
#include "xls/ir/value_utils.h"

Expand Down Expand Up @@ -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)) {
Expand Down
4 changes: 2 additions & 2 deletions xls/netlist/lib_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ absl::StatusOr<Token> 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();
Expand Down
4 changes: 2 additions & 2 deletions xls/netlist/lib_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
8 changes: 4 additions & 4 deletions xls/passes/narrowing_pass.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand Down Expand Up @@ -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<Value> narrowed_elements;
narrowed_elements.reserve(array_literal->value().elements().size());
Expand Down Expand Up @@ -668,7 +668,7 @@ class NarrowVisitor final : public DfsVisitorWithDefault {
if (sliced_array.slices.size() == 1) {
if (std::holds_alternative<NonconstantSlice>(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();
}

Expand Down Expand Up @@ -731,7 +731,7 @@ class NarrowVisitor final : public DfsVisitorWithDefault {
} else {
XLS_CHECK(std::holds_alternative<Literal*>(slice));
Literal* constant_slice = std::get<Literal*>(slice);
XLS_DCHECK(constant_slice->value().IsBits());
DCHECK(constant_slice->value().IsBits());
bit_slices.push_back(constant_slice);
}
}
Expand Down
4 changes: 2 additions & 2 deletions xls/passes/strength_reduction_pass.cc
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ absl::StatusOr<bool> 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();
Expand Down

0 comments on commit 4350752

Please sign in to comment.