Simplify the emission of various diagnostics created in Analysis/ and Transforms...
authorRiver Riddle <riverriddle@google.com>
Tue, 7 May 2019 04:59:40 +0000 (21:59 -0700)
committerMehdi Amini <joker.eph@gmail.com>
Sat, 11 May 2019 02:23:07 +0000 (19:23 -0700)
--

PiperOrigin-RevId: 246955332

mlir/lib/Analysis/Utils.cpp
mlir/lib/Analysis/Verifier.cpp
mlir/lib/Transforms/DialectConversion.cpp
mlir/lib/Transforms/DmaGeneration.cpp
mlir/lib/Transforms/LoopTiling.cpp

index b2d004b..aba14bd 100644 (file)
@@ -398,8 +398,8 @@ LogicalResult mlir::boundCheckLoadOrStoreOp(LoadOrStoreOpPointer loadOrStoreOp,
     ucst.addConstantLowerBound(r, dimSize);
     outOfBounds = !ucst.isEmpty();
     if (outOfBounds && emitError) {
-      loadOrStoreOp.emitOpError(
-          "memref out of upper bound access along dimension #" + Twine(r + 1));
+      loadOrStoreOp.emitOpError()
+          << "memref out of upper bound access along dimension #" << (r + 1);
     }
 
     // Check for a negative index.
@@ -409,8 +409,8 @@ LogicalResult mlir::boundCheckLoadOrStoreOp(LoadOrStoreOpPointer loadOrStoreOp,
     lcst.addConstantUpperBound(r, -1);
     outOfBounds = !lcst.isEmpty();
     if (outOfBounds && emitError) {
-      loadOrStoreOp.emitOpError(
-          "memref out of lower bound access along dimension #" + Twine(r + 1));
+      loadOrStoreOp.emitOpError()
+          << "memref out of lower bound access along dimension #" << (r + 1);
     }
   }
   return failure(outOfBounds);
index 6d0b91d..6d49dce 100644 (file)
@@ -349,8 +349,8 @@ LogicalResult FuncVerifier::verifyOpDominance(Operation &op) {
     if (domInfo->properlyDominates(operand, &op))
       continue;
 
-    auto diag = op.emitError("operand #" + Twine(operandNo) +
-                             " does not dominate this use");
+    auto diag = op.emitError("operand #")
+                << operandNo << " does not dominate this use";
     if (auto *useOp = operand->getDefiningOp())
       diag.attachNote(useOp->getLoc()) << "operand defined here";
     return failure();
index 831a68a..344007f 100644 (file)
@@ -158,8 +158,7 @@ impl::FunctionConversion::convertOp(DialectOpConversion *converter,
 
   auto results = converter->rewrite(op, operands, builder);
   if (results.size() != op->getNumResults())
-    return (op->emitError("rewriting produced a different number of results"),
-            failure());
+    return op->emitError("rewriting produced a different number of results");
 
   for (unsigned i = 0, e = results.size(); i < e; ++i)
     mapping.map(op->getResult(i), results[i]);
index f589053..fd05c30 100644 (file)
@@ -211,13 +211,9 @@ static bool getFullMemRefAsRegion(Operation *opInst, unsigned numParamLoopIVs,
   return true;
 }
 
-static void emitRemarkForBlock(Block &block, const Twine &message) {
+static InFlightDiagnostic emitRemarkForBlock(Block &block) {
   auto *op = block.getContainingOp();
-  if (!op) {
-    block.getFunction()->emitRemark(message);
-  } else {
-    op->emitRemark(message);
-  }
+  return op ? op->emitRemark() : block.getFunction()->emitRemark();
 }
 
 /// Creates a buffer in the faster memory space for the specified region;
@@ -356,11 +352,10 @@ bool DmaGeneration::generateDma(const MemRefRegion &region, Block *block,
     fastBufferMap[memref] = fastMemRef;
     // fastMemRefType is a constant shaped memref.
     *sizeInBytes = getMemRefSizeInBytes(fastMemRefType).getValue();
-    LLVM_DEBUG(std::string ss; llvm::raw_string_ostream oss(ss);
-               oss << "Creating DMA buffer of type " << fastMemRefType;
-               oss << " and size " << llvm::divideCeil(*sizeInBytes, 1024)
-                   << " KiB\n";
-               emitRemarkForBlock(*block, oss.str()));
+    LLVM_DEBUG(emitRemarkForBlock(*block)
+               << "Creating DMA buffer of type " << fastMemRefType
+               << " and size " << llvm::divideCeil(*sizeInBytes, 1024)
+               << " KiB\n");
   } else {
     // Reuse the one already created.
     fastMemRef = fastBufferMap[memref];
@@ -741,9 +736,9 @@ uint64_t DmaGeneration::runOnBlock(Block::iterator begin, Block::iterator end) {
   AffineForOp forOp;
   uint64_t sizeInKib = llvm::divideCeil(totalDmaBuffersSizeInBytes, 1024);
   if (llvm::DebugFlag && (forOp = begin->dyn_cast<AffineForOp>())) {
-    forOp.emitRemark(
-        Twine(sizeInKib) +
-        " KiB of DMA buffers in fast memory space for this block\n");
+    forOp.emitRemark()
+        << sizeInKib
+        << " KiB of DMA buffers in fast memory space for this block\n";
   }
 
   if (totalDmaBuffersSizeInBytes > fastMemCapacityBytes) {
index 4eb1ce2..303193b 100644 (file)
@@ -397,13 +397,10 @@ void LoopTiling::runOnFunction() {
     SmallVector<unsigned, 6> tileSizes;
     getTileSizes(band, &tileSizes);
     if (llvm::DebugFlag) {
-      std::stringstream msg;
-      msg << "using tile sizes [";
+      auto diag = band[0].emitRemark("using tile sizes [");
       for (auto tSize : tileSizes)
-        msg << tSize << " ";
-      msg << "]\n";
-      auto rootForOp = band[0];
-      rootForOp.emitRemark(msg.str());
+        diag << tSize << " ";
+      diag << "]\n";
     }
     if (failed(tileCodeGen(band, tileSizes)))
       return signalPassFailure();