diff options
| author | River Riddle <riverriddle@google.com> | 2019-05-06 09:46:11 -0700 |
|---|---|---|
| committer | Mehdi Amini <joker.eph@gmail.com> | 2019-05-10 19:22:24 -0700 |
| commit | 3df7a802655bba0f8596bc0ac90296ecdc635e12 (patch) | |
| tree | f24ff3ac0b1a55909aff3991cc00b40dfbe6b1df /mlir/lib | |
| parent | fb8a0fc25e88380c683258f5d25f0e74ade21658 (diff) | |
| download | bcm5719-llvm-3df7a802655bba0f8596bc0ac90296ecdc635e12.tar.gz bcm5719-llvm-3df7a802655bba0f8596bc0ac90296ecdc635e12.zip | |
Simplify the emission of various diagnostics emitted by the different dialects (Affine/Standard/etc.) by using the new stream interface instead of Twine.
--
PiperOrigin-RevId: 246842016
Diffstat (limited to 'mlir/lib')
| -rw-r--r-- | mlir/lib/Dialect/Traits.cpp | 8 | ||||
| -rw-r--r-- | mlir/lib/IR/Diagnostics.cpp | 3 | ||||
| -rw-r--r-- | mlir/lib/LLVMIR/IR/LLVMDialect.cpp | 4 | ||||
| -rw-r--r-- | mlir/lib/LLVMIR/Transforms/ConvertToLLVMDialect.cpp | 7 | ||||
| -rw-r--r-- | mlir/lib/Linalg/IR/LinalgOps.cpp | 20 | ||||
| -rw-r--r-- | mlir/lib/Quantization/IR/QuantTypes.cpp | 19 | ||||
| -rw-r--r-- | mlir/lib/Quantization/Utils/FakeQuantSupport.cpp | 8 | ||||
| -rw-r--r-- | mlir/lib/VectorOps/VectorOps.cpp | 30 |
8 files changed, 45 insertions, 54 deletions
diff --git a/mlir/lib/Dialect/Traits.cpp b/mlir/lib/Dialect/Traits.cpp index 40092b2242a..8988dcdb39a 100644 --- a/mlir/lib/Dialect/Traits.cpp +++ b/mlir/lib/Dialect/Traits.cpp @@ -203,10 +203,10 @@ LogicalResult OpTrait::impl::verifyCompatibleOperandBroadcast(Operation *op) { retType.isa<UnrankedTensorType>() || isSameShapedVectorOrTensor(retType, broadcastedType); if (!hasCompatRetType) - return op->emitOpError( - llvm::formatv("result type '{0}' does not have the same shape as the " - "broadcasted type '{1}' computed from the operand types", - retType, broadcastedType)); + return op->emitOpError() + << "result type '" << retType + << "' does not have the same shape as the broadcasted type '" + << broadcastedType << "' computed from the operand types"; return success(); } diff --git a/mlir/lib/IR/Diagnostics.cpp b/mlir/lib/IR/Diagnostics.cpp index 35ad35e90d5..877be72d3c2 100644 --- a/mlir/lib/IR/Diagnostics.cpp +++ b/mlir/lib/IR/Diagnostics.cpp @@ -44,6 +44,9 @@ Type DiagnosticArgument::getAsType() const { /// Outputs this argument to a stream. void DiagnosticArgument::print(raw_ostream &os) const { switch (kind) { + case DiagnosticArgumentKind::Double: + os << getAsDouble(); + break; case DiagnosticArgumentKind::Integer: os << getAsInteger(); break; diff --git a/mlir/lib/LLVMIR/IR/LLVMDialect.cpp b/mlir/lib/LLVMIR/IR/LLVMDialect.cpp index a28b3b8464b..20d5463a6b7 100644 --- a/mlir/lib/LLVMIR/IR/LLVMDialect.cpp +++ b/mlir/lib/LLVMIR/IR/LLVMDialect.cpp @@ -902,8 +902,8 @@ LogicalResult LLVMDialect::verifyFunctionArgAttribute(Function *func, NamedAttribute argAttr) { // Check that llvm.noalias is a boolean attribute. if (argAttr.first == "llvm.noalias" && !argAttr.second.isa<BoolAttr>()) - return func->emitError( - "llvm.noalias argument attribute of non boolean type"); + return func->emitError() + << "llvm.noalias argument attribute of non boolean type"; return success(); } diff --git a/mlir/lib/LLVMIR/Transforms/ConvertToLLVMDialect.cpp b/mlir/lib/LLVMIR/Transforms/ConvertToLLVMDialect.cpp index 587bd6b405a..5f57ebc9613 100644 --- a/mlir/lib/LLVMIR/Transforms/ConvertToLLVMDialect.cpp +++ b/mlir/lib/LLVMIR/Transforms/ConvertToLLVMDialect.cpp @@ -1133,11 +1133,8 @@ Type LLVMLowering::convertType(Type t) { return result; auto *mlirContext = llvmDialect->getContext(); - std::string message; - llvm::raw_string_ostream os(message); - os << "unsupported type: "; - t.print(os); - mlirContext->emitError(UnknownLoc::get(mlirContext), os.str()); + mlirContext->emitError(UnknownLoc::get(mlirContext)) + << "unsupported type: " << t; return {}; } diff --git a/mlir/lib/Linalg/IR/LinalgOps.cpp b/mlir/lib/Linalg/IR/LinalgOps.cpp index d8f9b134373..958218d1a87 100644 --- a/mlir/lib/Linalg/IR/LinalgOps.cpp +++ b/mlir/lib/Linalg/IR/LinalgOps.cpp @@ -167,24 +167,24 @@ LogicalResult mlir::SliceOp::verify() { return emitOpError("first operand must come from a ViewOp"); unsigned rank = getBaseViewRank(); if (llvm::size(getIndexings()) != rank) { - return emitOpError("requires at least a view operand followed by " + - Twine(rank) + " indexings"); + return emitOpError("requires at least a view operand followed by ") + << rank << " indexings"; } unsigned index = 0; for (auto indexing : getIndexings()) { if (!indexing->getType().isa<RangeType>() && !indexing->getType().isa<IndexType>()) { - return emitOpError(Twine(index) + - "^th index must be of range or index type"); + return emitOpError() << index + << "^th index must be of range or index type"; } if (indexing->getType().isa<IndexType>()) --rank; ++index; } if (getRank() != rank) { - return emitOpError("the rank of the view must be the number of its range " - "indices (" + - Twine(rank) + ") but got: " + Twine(getRank())); + return emitOpError() + << "the rank of the view must be the number of its range indices (" + << rank << ") but got: " << getRank(); } return success(); } @@ -296,13 +296,13 @@ LogicalResult mlir::ViewOp::verify() { unsigned index = 0; for (auto indexing : getIndexings()) { if (!indexing->getType().isa<RangeType>()) { - return emitOpError(Twine(index) + "^th index must be of range type"); + return emitOpError() << index << "^th index must be of range type"; } ++index; } if (getViewType().getRank() != index) - return emitOpError( - "the rank of the view must be the number of its indexings"); + return emitOpError() + << "the rank of the view must be the number of its indexings"; return success(); } diff --git a/mlir/lib/Quantization/IR/QuantTypes.cpp b/mlir/lib/Quantization/IR/QuantTypes.cpp index efe0924168b..88ba4aedaa9 100644 --- a/mlir/lib/Quantization/IR/QuantTypes.cpp +++ b/mlir/lib/Quantization/IR/QuantTypes.cpp @@ -50,8 +50,7 @@ LogicalResult QuantizedType::verifyConstructionInvariants( // Verify storage width. if (integralWidth == 0 || integralWidth > MaxStorageBits) { if (loc) { - context->emitError(*loc, - "illegal storage type size: " + Twine(integralWidth)); + context->emitError(*loc, "illegal storage type size: ") << integralWidth; } return failure(); } @@ -67,9 +66,8 @@ LogicalResult QuantizedType::verifyConstructionInvariants( storageTypeMin < defaultIntegerMin || storageTypeMax > defaultIntegerMax) { if (loc) { - context->emitError(*loc, "illegal storage min and storage max: (" + - Twine(storageTypeMin) + ":" + - Twine(storageTypeMax) + ")"); + context->emitError(*loc, "illegal storage min and storage max: (") + << storageTypeMin << ":" << storageTypeMax << ")"; } return failure(); } @@ -313,8 +311,7 @@ LogicalResult UniformQuantizedType::verifyConstructionInvariants( // Verify scale. if (scale <= 0.0 || std::isinf(scale) || std::isnan(scale)) { if (loc) { - context->emitError(*loc, - "illegal scale: " + Twine(std::to_string(scale))); + context->emitError(*loc) << "illegal scale: " << scale; } return failure(); } @@ -383,9 +380,8 @@ LogicalResult UniformQuantizedPerAxisType::verifyConstructionInvariants( // Ensure that the number of scales and zeroPoints match. if (scales.size() != zeroPoints.size()) { if (loc) { - context->emitError(*loc, "illegal number of scales and zeroPoints: " + - Twine(scales.size()) + ", " + - Twine(zeroPoints.size())); + context->emitError(*loc, "illegal number of scales and zeroPoints: ") + << scales.size() << ", " << zeroPoints.size(); } return failure(); } @@ -394,8 +390,7 @@ LogicalResult UniformQuantizedPerAxisType::verifyConstructionInvariants( for (double scale : scales) { if (scale <= 0.0 || std::isinf(scale) || std::isnan(scale)) { if (loc) { - context->emitError(*loc, - "illegal scale: " + Twine(std::to_string(scale))); + context->emitError(*loc) << "illegal scale: " << scale; } return failure(); } diff --git a/mlir/lib/Quantization/Utils/FakeQuantSupport.cpp b/mlir/lib/Quantization/Utils/FakeQuantSupport.cpp index 3c61e484829..26e88b90d07 100644 --- a/mlir/lib/Quantization/Utils/FakeQuantSupport.cpp +++ b/mlir/lib/Quantization/Utils/FakeQuantSupport.cpp @@ -44,8 +44,7 @@ UniformQuantizedType mlir::quant::fakeQuantAttrsToType(Location loc, qmin = -32768; qmax = 32767; } else { - ctx->emitError(loc, - "unsupported FakeQuant number of bits: " + Twine(numBits)); + ctx->emitError(loc, "unsupported FakeQuant number of bits: ") << numBits; return nullptr; } @@ -56,9 +55,8 @@ UniformQuantizedType mlir::quant::fakeQuantAttrsToType(Location loc, // Range must straddle zero. if (rmin > 0.0 || rmax < 0.0) { - return (ctx->emitError(loc, "FakeQuant range must straddle zero: [" + - Twine(std::to_string(rmin)) + "," + - Twine(std::to_string(rmax)) + "]"), + return (ctx->emitError(loc, "FakeQuant range must straddle zero: [") + << rmin << "," << rmax << "]", nullptr); } diff --git a/mlir/lib/VectorOps/VectorOps.cpp b/mlir/lib/VectorOps/VectorOps.cpp index 263a0b359ba..6f416930b1f 100644 --- a/mlir/lib/VectorOps/VectorOps.cpp +++ b/mlir/lib/VectorOps/VectorOps.cpp @@ -195,9 +195,9 @@ LogicalResult VectorTransferReadOp::verify() { (optionalPaddingValue ? 1 : 0); // Checks on the actual operands and their types. if (getNumOperands() != expectedNumOperands) { - return emitOpError("expects " + Twine(expectedNumOperands) + " operands " + - "(of which " + Twine(memrefType.getRank()) + - " indices)"); + return emitOpError("expects ") + << expectedNumOperands << " operands (of which " + << memrefType.getRank() << " indices)"; } // Consistency of padding value with vector type. if (optionalPaddingValue) { @@ -221,8 +221,8 @@ LogicalResult VectorTransferReadOp::verify() { ++numIndices; } if (numIndices != memrefType.getRank()) { - return emitOpError("requires at least a memref operand followed by " + - Twine(memrefType.getRank()) + " indices"); + return emitOpError("requires at least a memref operand followed by ") + << memrefType.getRank() << " indices"; } // Consistency of AffineMap attribute. @@ -242,9 +242,8 @@ LogicalResult VectorTransferReadOp::verify() { } if (permutationMap.getNumResults() != vectorType.getRank()) { return emitOpError("requires a permutation_map with result dims of the " - "same rank as the vector type (" + - Twine(permutationMap.getNumResults()) + " vs " + - Twine(vectorType.getRank())); + "same rank as the vector type (") + << permutationMap.getNumResults() << " vs " << vectorType.getRank(); } return verifyPermutationMap(permutationMap, [this](Twine t) { return emitOpError(t); }); @@ -340,9 +339,9 @@ LogicalResult VectorTransferWriteOp::verify() { Offsets::FirstIndexOffset + memrefType.getRank(); // Checks on the actual operands and their types. if (getNumOperands() != expectedNumOperands) { - return emitOpError("expects " + Twine(expectedNumOperands) + " operands " + - "(of which " + Twine(memrefType.getRank()) + - " indices)"); + return emitOpError() << "expects " << expectedNumOperands + << " operands (of which " << memrefType.getRank() + << " indices)"; } // Consistency of indices types. unsigned numIndices = 0; @@ -354,8 +353,8 @@ LogicalResult VectorTransferWriteOp::verify() { numIndices++; } if (numIndices != memrefType.getRank()) { - return emitOpError("requires at least a memref operand followed by " + - Twine(memrefType.getRank()) + " indices"); + return emitOpError("requires at least a memref operand followed by ") + << memrefType.getRank() << " indices"; } // Consistency of AffineMap attribute. @@ -375,9 +374,8 @@ LogicalResult VectorTransferWriteOp::verify() { } if (permutationMap.getNumResults() != vectorType.getRank()) { return emitOpError("requires a permutation_map with result dims of the " - "same rank as the vector type (" + - Twine(permutationMap.getNumResults()) + " vs " + - Twine(vectorType.getRank())); + "same rank as the vector type (") + << permutationMap.getNumResults() << " vs " << vectorType.getRank(); } return verifyPermutationMap(permutationMap, [this](Twine t) { return emitOpError(t); }); |

