[Mlir-commits] [mlir] 7de8488 - [MLIR] Printing a null Value.

Uday Bondhugula llvmlistbot at llvm.org
Mon Jan 3 18:43:28 PST 2022


Author: Stanislav Funiak
Date: 2022-01-04T08:13:03+05:30
New Revision: 7de8488c3d7e9f4a5e2d05007e5ea17482a02410

URL: https://github.com/llvm/llvm-project/commit/7de8488c3d7e9f4a5e2d05007e5ea17482a02410
DIFF: https://github.com/llvm/llvm-project/commit/7de8488c3d7e9f4a5e2d05007e5ea17482a02410.diff

LOG: [MLIR] Printing a null Value.

This diff adds support to printing a Value when it is null. We encounter this situation when debugging the PDL bytcode execution (where a null Value is perfectly valid). Currently, the AsmPrinter crashes (with an assert in a cast) when it encounters such Value.

We follow the same format used in other printed entities (e.g., null attribute).

Reviewed By: mehdi_amini, bondhugula

Differential Revision: https://reviews.llvm.org/D116084

Added: 
    

Modified: 
    mlir/lib/IR/AsmPrinter.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/lib/IR/AsmPrinter.cpp b/mlir/lib/IR/AsmPrinter.cpp
index 376e5c16fe6c3..7be787f51f8fa 100644
--- a/mlir/lib/IR/AsmPrinter.cpp
+++ b/mlir/lib/IR/AsmPrinter.cpp
@@ -935,7 +935,7 @@ SSANameState::SSANameState(
 void SSANameState::printValueID(Value value, bool printResultNo,
                                 raw_ostream &stream) const {
   if (!value) {
-    stream << "<<NULL>>";
+    stream << "<<NULL VALUE>>";
     return;
   }
 
@@ -2826,6 +2826,11 @@ void IntegerSet::print(raw_ostream &os) const {
 }
 
 void Value::print(raw_ostream &os) {
+  if (!impl) {
+    os << "<<NULL VALUE>>";
+    return;
+  }
+
   if (auto *op = getDefiningOp())
     return op->print(os);
   // TODO: Improve BlockArgument print'ing.
@@ -2834,6 +2839,11 @@ void Value::print(raw_ostream &os) {
      << "' at index: " << arg.getArgNumber();
 }
 void Value::print(raw_ostream &os, AsmState &state) {
+  if (!impl) {
+    os << "<<NULL VALUE>>";
+    return;
+  }
+
   if (auto *op = getDefiningOp())
     return op->print(os, state);
 


        


More information about the Mlir-commits mailing list