@@ -551,31 +551,31 @@ class NodeChecker : public DfsVisitor {
551
551
552
552
absl::Status HandleEq (CompareOp* eq) override {
553
553
XLS_RETURN_IF_ERROR (ExpectOperandCount (eq, 2 ));
554
- XLS_RETURN_IF_ERROR (ExpectOperandsSameBitsType (eq));
554
+ XLS_RETURN_IF_ERROR (ExpectOperandsSameTypeNoToken (eq));
555
555
return ExpectHasBitsType (eq, /* expected_bit_count=*/ 1 );
556
556
}
557
557
558
558
absl::Status HandleUGe (CompareOp* ge) override {
559
559
XLS_RETURN_IF_ERROR (ExpectOperandCount (ge, 2 ));
560
- XLS_RETURN_IF_ERROR (ExpectOperandsSameBitsType (ge));
560
+ XLS_RETURN_IF_ERROR (ExpectOperandsAreBitsAndSameWidth (ge));
561
561
return ExpectHasBitsType (ge, /* expected_bit_count=*/ 1 );
562
562
}
563
563
564
564
absl::Status HandleUGt (CompareOp* gt) override {
565
565
XLS_RETURN_IF_ERROR (ExpectOperandCount (gt, 2 ));
566
- XLS_RETURN_IF_ERROR (ExpectOperandsSameBitsType (gt));
566
+ XLS_RETURN_IF_ERROR (ExpectOperandsAreBitsAndSameWidth (gt));
567
567
return ExpectHasBitsType (gt, /* expected_bit_count=*/ 1 );
568
568
}
569
569
570
570
absl::Status HandleSGe (CompareOp* ge) override {
571
571
XLS_RETURN_IF_ERROR (ExpectOperandCount (ge, 2 ));
572
- XLS_RETURN_IF_ERROR (ExpectOperandsSameBitsType (ge));
572
+ XLS_RETURN_IF_ERROR (ExpectOperandsAreBitsAndSameWidth (ge));
573
573
return ExpectHasBitsType (ge, /* expected_bit_count=*/ 1 );
574
574
}
575
575
576
576
absl::Status HandleSGt (CompareOp* gt) override {
577
577
XLS_RETURN_IF_ERROR (ExpectOperandCount (gt, 2 ));
578
- XLS_RETURN_IF_ERROR (ExpectOperandsSameBitsType (gt));
578
+ XLS_RETURN_IF_ERROR (ExpectOperandsAreBitsAndSameWidth (gt));
579
579
return ExpectHasBitsType (gt, /* expected_bit_count=*/ 1 );
580
580
}
581
581
@@ -715,24 +715,24 @@ class NodeChecker : public DfsVisitor {
715
715
716
716
absl::Status HandleULe (CompareOp* le) override {
717
717
XLS_RETURN_IF_ERROR (ExpectOperandCount (le, 2 ));
718
- XLS_RETURN_IF_ERROR (ExpectOperandsSameBitsType (le));
718
+ XLS_RETURN_IF_ERROR (ExpectOperandsAreBitsAndSameWidth (le));
719
719
return ExpectHasBitsType (le, /* expected_bit_count=*/ 1 );
720
720
}
721
721
722
722
absl::Status HandleULt (CompareOp* lt) override {
723
723
XLS_RETURN_IF_ERROR (ExpectOperandCount (lt, 2 ));
724
- XLS_RETURN_IF_ERROR (ExpectOperandsSameBitsType (lt));
724
+ XLS_RETURN_IF_ERROR (ExpectOperandsAreBitsAndSameWidth (lt));
725
725
return ExpectHasBitsType (lt, /* expected_bit_count=*/ 1 );
726
726
}
727
727
absl::Status HandleSLe (CompareOp* le) override {
728
728
XLS_RETURN_IF_ERROR (ExpectOperandCount (le, 2 ));
729
- XLS_RETURN_IF_ERROR (ExpectOperandsSameBitsType (le));
729
+ XLS_RETURN_IF_ERROR (ExpectOperandsAreBitsAndSameWidth (le));
730
730
return ExpectHasBitsType (le, /* expected_bit_count=*/ 1 );
731
731
}
732
732
733
733
absl::Status HandleSLt (CompareOp* lt) override {
734
734
XLS_RETURN_IF_ERROR (ExpectOperandCount (lt, 2 ));
735
- XLS_RETURN_IF_ERROR (ExpectOperandsSameBitsType (lt));
735
+ XLS_RETURN_IF_ERROR (ExpectOperandsAreBitsAndSameWidth (lt));
736
736
return ExpectHasBitsType (lt, /* expected_bit_count=*/ 1 );
737
737
}
738
738
@@ -836,7 +836,7 @@ class NodeChecker : public DfsVisitor {
836
836
837
837
absl::Status HandleNe (CompareOp* ne) override {
838
838
XLS_RETURN_IF_ERROR (ExpectOperandCount (ne, 2 ));
839
- XLS_RETURN_IF_ERROR (ExpectOperandsSameBitsType (ne));
839
+ XLS_RETURN_IF_ERROR (ExpectOperandsSameTypeNoToken (ne));
840
840
return ExpectHasBitsType (ne, /* expected_bit_count=*/ 1 );
841
841
}
842
842
@@ -1465,12 +1465,41 @@ class NodeChecker : public DfsVisitor {
1465
1465
return absl::OkStatus ();
1466
1466
}
1467
1467
1468
- // Verifies all operands are BitsType with the same bit count.
1469
- absl::Status ExpectOperandsSameBitsType (Node* node) const {
1468
+ // Verifies all operands are BitsType with the same bit count as the first
1469
+ // operand.
1470
+ absl::Status ExpectOperandsAreBitsAndSameWidth (Node* node) const {
1470
1471
if (node->operand_count () == 0 ) {
1471
1472
return absl::OkStatus ();
1472
1473
}
1474
+ XLS_RETURN_IF_ERROR (ExpectOperandHasBitsType (node, 0 ));
1473
1475
Type* type = node->operand (0 )->GetType ();
1476
+ // Already checked operand 0 is BitsType. Now check other operands.
1477
+ for (int64_t i = 1 ; i < node->operand_count (); ++i) {
1478
+ XLS_RETURN_IF_ERROR (ExpectOperandHasBitsType (node, i));
1479
+ if (node->operand (i)->GetType ()->AsBitsOrDie ()->bit_count () !=
1480
+ type->AsBitsOrDie ()->bit_count ()) {
1481
+ return absl::InternalError (absl::StrFormat (
1482
+ " Expected operand %d of %s to have bit count %d (same as operand "
1483
+ " 0), has bit count %d: %s" ,
1484
+ i, node->GetName (), type->AsBitsOrDie ()->bit_count (),
1485
+ node->operand (i)->GetType ()->AsBitsOrDie ()->bit_count (),
1486
+ node->ToString ()));
1487
+ }
1488
+ }
1489
+ return absl::OkStatus ();
1490
+ }
1491
+
1492
+ // Verifies all operands are the same type, and that type is not Token.
1493
+ absl::Status ExpectOperandsSameTypeNoToken (Node* node) const {
1494
+ if (node->operand_count () == 0 ) {
1495
+ return absl::OkStatus ();
1496
+ }
1497
+ Type* type = node->operand (0 )->GetType ();
1498
+ if (type->IsToken ()) {
1499
+ return absl::InternalError (absl::StrFormat (
1500
+ " Operand 0 of %s cannot be Token type for this operation: %s" ,
1501
+ node->GetName (), node->ToString ()));
1502
+ }
1474
1503
for (int64_t i = 1 ; i < node->operand_count (); ++i) {
1475
1504
XLS_RETURN_IF_ERROR (ExpectOperandHasType (node, i, type));
1476
1505
}
0 commit comments