[Mlir-commits] [mlir] 884221e - [mlir] Tidy uses of llvm::raw_stream_ostream (NFC)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Mon Sep 16 20:27:33 PDT 2024
Author: JOE1994
Date: 2024-09-16T23:23:25-04:00
New Revision: 884221eddb9d395830704fac79fd04008e02e368
URL: https://github.com/llvm/llvm-project/commit/884221eddb9d395830704fac79fd04008e02e368
DIFF: https://github.com/llvm/llvm-project/commit/884221eddb9d395830704fac79fd04008e02e368.diff
LOG: [mlir] Tidy uses of llvm::raw_stream_ostream (NFC)
As specified in the docs,
1) raw_string_ostream is always unbuffered and
2) the underlying buffer may be used directly
( 65b13610a5226b84889b923bae884ba395ad084d for further reference )
* Don't call raw_string_ostream::flush(), which is essentially a no-op.
* Avoid unneeded calls to raw_string_ostream::str(), to avoid excess indirection.
Added:
Modified:
mlir/lib/Debug/Observers/ActionProfiler.cpp
mlir/lib/Dialect/Bufferization/Transforms/OneShotAnalysis.cpp
mlir/lib/Dialect/LLVMIR/IR/LLVMAttrs.cpp
mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
mlir/lib/Dialect/LLVMIR/IR/NVVMDialect.cpp
mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp
mlir/lib/Dialect/Linalg/TransformOps/LinalgMatchOps.cpp
mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
mlir/lib/Dialect/SparseTensor/IR/Detail/Var.cpp
mlir/lib/Dialect/Traits.cpp
mlir/lib/Dialect/Transform/DebugExtension/DebugExtensionOps.cpp
mlir/lib/Dialect/Transform/IR/TransformOps.cpp
mlir/lib/ExecutionEngine/ExecutionEngine.cpp
mlir/lib/IR/Diagnostics.cpp
mlir/lib/Interfaces/DataLayoutInterfaces.cpp
mlir/lib/Interfaces/RuntimeVerifiableOpInterface.cpp
mlir/lib/Pass/Pass.cpp
mlir/lib/Pass/PassCrashRecovery.cpp
mlir/lib/Query/Matcher/RegistryManager.cpp
mlir/lib/Query/QueryParser.cpp
Removed:
################################################################################
diff --git a/mlir/lib/Debug/Observers/ActionProfiler.cpp b/mlir/lib/Debug/Observers/ActionProfiler.cpp
index 07bf9fd0ccc7db..a6b7d5e18aa077 100644
--- a/mlir/lib/Debug/Observers/ActionProfiler.cpp
+++ b/mlir/lib/Debug/Observers/ActionProfiler.cpp
@@ -58,6 +58,6 @@ void ActionProfiler::print(const ActionActiveStack *action,
if (printComma)
os << ",\n";
printComma = true;
- os << event.str();
+ os << str;
os.flush();
}
diff --git a/mlir/lib/Dialect/Bufferization/Transforms/OneShotAnalysis.cpp b/mlir/lib/Dialect/Bufferization/Transforms/OneShotAnalysis.cpp
index 975bfb4d41e0bc..d69c194c55f7d3 100644
--- a/mlir/lib/Dialect/Bufferization/Transforms/OneShotAnalysis.cpp
+++ b/mlir/lib/Dialect/Bufferization/Transforms/OneShotAnalysis.cpp
@@ -1299,7 +1299,7 @@ static void annotateOpsWithAliasSets(Operation *op,
std::string buffer;
llvm::raw_string_ostream stream(buffer);
alias.printAsOperand(stream, asmState);
- aliases.push_back(b.getStringAttr(stream.str()));
+ aliases.push_back(b.getStringAttr(buffer));
});
return b.getArrayAttr(aliases);
};
diff --git a/mlir/lib/Dialect/LLVMIR/IR/LLVMAttrs.cpp b/mlir/lib/Dialect/LLVMIR/IR/LLVMAttrs.cpp
index 6047c4a7ef5150..bd2164e640e7b8 100644
--- a/mlir/lib/Dialect/LLVMIR/IR/LLVMAttrs.cpp
+++ b/mlir/lib/Dialect/LLVMIR/IR/LLVMAttrs.cpp
@@ -326,7 +326,7 @@ std::string TargetFeaturesAttr::getFeaturesString() const {
llvm::raw_string_ostream ss(featuresString);
llvm::interleave(
getFeatures(), ss, [&](auto &feature) { ss << feature.strref(); }, ",");
- return ss.str();
+ return featuresString;
}
TargetFeaturesAttr TargetFeaturesAttr::featuresAt(Operation *op) {
diff --git a/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp b/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
index b4ef5d76770856..205d7494d4378c 100644
--- a/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
+++ b/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
@@ -3247,7 +3247,7 @@ LogicalResult LLVMDialect::verifyDataLayoutString(
std::string message;
llvm::raw_string_ostream messageStream(message);
llvm::logAllUnhandledErrors(maybeDataLayout.takeError(), messageStream);
- reportError("invalid data layout descriptor: " + messageStream.str());
+ reportError("invalid data layout descriptor: " + message);
return failure();
}
diff --git a/mlir/lib/Dialect/LLVMIR/IR/NVVMDialect.cpp b/mlir/lib/Dialect/LLVMIR/IR/NVVMDialect.cpp
index 2c7c3e9d535f7d..5ab64ea1b2097a 100644
--- a/mlir/lib/Dialect/LLVMIR/IR/NVVMDialect.cpp
+++ b/mlir/lib/Dialect/LLVMIR/IR/NVVMDialect.cpp
@@ -521,7 +521,7 @@ LogicalResult MmaOp::verify() {
}
errorStream << "but got ";
llvm::interleaveComma(operandTySeg, errorStream);
- return emitOpError(errorStream.str());
+ return emitOpError(errorMessage);
}
}
@@ -533,7 +533,7 @@ LogicalResult MmaOp::verify() {
<< "Could not match allowed types for the result; expected one of ";
llvm::interleaveComma(expectedResult, errorStream);
errorStream << " but got " << getResult().getType();
- return emitOpError(errorStream.str());
+ return emitOpError(errorMessage);
}
// Ensure that binary MMA variants have a b1 MMA operation defined.
@@ -967,7 +967,6 @@ std::string NVVM::WgmmaMmaAsyncOp::getPtx() {
}
ss << ";\n"
<< "}\n";
- ss.flush();
return ptx;
}
diff --git a/mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp b/mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp
index b888005625eda7..730c478c2883ef 100644
--- a/mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp
+++ b/mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp
@@ -2334,9 +2334,8 @@ std::string mlir::linalg::generateLibraryCallName(Operation *op) {
return std::string();
ss << "_";
}
- std::string res = ss.str();
- res.pop_back();
- return res;
+ name.pop_back();
+ return name;
}
//===----------------------------------------------------------------------===//
diff --git a/mlir/lib/Dialect/Linalg/TransformOps/LinalgMatchOps.cpp b/mlir/lib/Dialect/Linalg/TransformOps/LinalgMatchOps.cpp
index be4ab361083b9a..5460f50328a452 100644
--- a/mlir/lib/Dialect/Linalg/TransformOps/LinalgMatchOps.cpp
+++ b/mlir/lib/Dialect/Linalg/TransformOps/LinalgMatchOps.cpp
@@ -209,7 +209,7 @@ DiagnosedSilenceableFailure transform::MatchStructuredBodyOp::matchOperation(
os);
if (result)
return DiagnosedSilenceableFailure::success();
- return emitSilenceableError() << "contraction: " << os.str();
+ return emitSilenceableError() << "contraction: " << message;
}
return emitDefiniteFailure() << "unknown body condition";
}
@@ -226,7 +226,7 @@ LogicalResult transform::MatchStructuredBodyOp::verify() {
getElementwiseAttrName(),
getContractionAttrName()},
os);
- return emitOpError() << "only one of {" << os.str() << "} is allowed";
+ return emitOpError() << "only one of {" << attributeNames << "} is allowed";
}
if (std::optional<ArrayAttr> contractionAttr = getContraction()) {
diff --git a/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp b/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
index e4ed58f26016a5..db47276dcefe95 100644
--- a/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
+++ b/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
@@ -1258,7 +1258,7 @@ static void printCaptureType(OpAsmPrinter &p, Operation *op,
typeCap << "VLAType";
if (mapCaptureType.getValue() == mlir::omp::VariableCaptureKind::This)
typeCap << "This";
- p << typeCap.str();
+ p << typeCapStr;
}
static ParseResult parseCaptureType(OpAsmParser &parser,
diff --git a/mlir/lib/Dialect/SparseTensor/IR/Detail/Var.cpp b/mlir/lib/Dialect/SparseTensor/IR/Detail/Var.cpp
index 187b3b71e3458b..9e2e6ab3374d41 100644
--- a/mlir/lib/Dialect/SparseTensor/IR/Detail/Var.cpp
+++ b/mlir/lib/Dialect/SparseTensor/IR/Detail/Var.cpp
@@ -29,7 +29,7 @@ std::string Var::str() const {
std::string str;
llvm::raw_string_ostream os(str);
print(os);
- return os.str();
+ return str;
}
void Var::print(AsmPrinter &printer) const { print(printer.getStream()); }
diff --git a/mlir/lib/Dialect/Traits.cpp b/mlir/lib/Dialect/Traits.cpp
index 2efc157ce79617..a7aa25eae2644a 100644
--- a/mlir/lib/Dialect/Traits.cpp
+++ b/mlir/lib/Dialect/Traits.cpp
@@ -223,7 +223,7 @@ static std::string getShapeString(ArrayRef<int64_t> shape) {
},
"x");
ss << '\'';
- return ss.str();
+ return ret;
}
LogicalResult OpTrait::impl::verifyCompatibleOperandBroadcast(Operation *op) {
diff --git a/mlir/lib/Dialect/Transform/DebugExtension/DebugExtensionOps.cpp b/mlir/lib/Dialect/Transform/DebugExtension/DebugExtensionOps.cpp
index 94d4a96a07ad64..7ad017af485f95 100644
--- a/mlir/lib/Dialect/Transform/DebugExtension/DebugExtensionOps.cpp
+++ b/mlir/lib/Dialect/Transform/DebugExtension/DebugExtensionOps.cpp
@@ -60,10 +60,10 @@ DiagnosedSilenceableFailure transform::DebugEmitParamAsRemarkOp::apply(
os << *getMessage() << " ";
llvm::interleaveComma(state.getParams(getParam()), os);
if (!getAnchor()) {
- emitRemark() << os.str();
+ emitRemark() << str;
return DiagnosedSilenceableFailure::success();
}
for (Operation *payload : state.getPayloadOps(getAnchor()))
- ::mlir::emitRemark(payload->getLoc()) << os.str();
+ ::mlir::emitRemark(payload->getLoc()) << str;
return DiagnosedSilenceableFailure::success();
}
diff --git a/mlir/lib/Dialect/Transform/IR/TransformOps.cpp b/mlir/lib/Dialect/Transform/IR/TransformOps.cpp
index 14d97964964bb9..590cae9aa0d667 100644
--- a/mlir/lib/Dialect/Transform/IR/TransformOps.cpp
+++ b/mlir/lib/Dialect/Transform/IR/TransformOps.cpp
@@ -1967,7 +1967,7 @@ transform::MatchParamCmpIOp::apply(transform::TransformRewriter &rewriter,
std::string str;
llvm::raw_string_ostream os(str);
value.print(os, /*isSigned=*/true);
- return os.str();
+ return str;
};
ArrayRef<Attribute> params = state.getParams(getParam());
diff --git a/mlir/lib/ExecutionEngine/ExecutionEngine.cpp b/mlir/lib/ExecutionEngine/ExecutionEngine.cpp
index 19917ea4ff1dab..2ecc80400b3db4 100644
--- a/mlir/lib/ExecutionEngine/ExecutionEngine.cpp
+++ b/mlir/lib/ExecutionEngine/ExecutionEngine.cpp
@@ -432,7 +432,7 @@ Expected<void *> ExecutionEngine::lookup(StringRef name) const {
llvm::raw_string_ostream os(errorMessage);
llvm::handleAllErrors(expectedSymbol.takeError(),
[&os](llvm::ErrorInfoBase &ei) { ei.log(os); });
- return makeStringError(os.str());
+ return makeStringError(errorMessage);
}
if (void *fptr = expectedSymbol->toPtr<void *>())
diff --git a/mlir/lib/IR/Diagnostics.cpp b/mlir/lib/IR/Diagnostics.cpp
index 6b311a90e0de59..7eb3d5bcd07f19 100644
--- a/mlir/lib/IR/Diagnostics.cpp
+++ b/mlir/lib/IR/Diagnostics.cpp
@@ -146,7 +146,7 @@ Diagnostic &Diagnostic::appendOp(Operation &op, const OpPrintingFlags &flags) {
// multiple lines.
if (str.find('\n') != std::string::npos)
*this << '\n';
- return *this << os.str();
+ return *this << str;
}
/// Stream in a Value.
@@ -154,7 +154,7 @@ Diagnostic &Diagnostic::operator<<(Value val) {
std::string str;
llvm::raw_string_ostream os(str);
val.print(os, adjustPrintingFlags(OpPrintingFlags(), severity));
- return *this << os.str();
+ return *this << str;
}
/// Outputs this diagnostic to a stream.
@@ -168,7 +168,7 @@ std::string Diagnostic::str() const {
std::string str;
llvm::raw_string_ostream os(str);
print(os);
- return os.str();
+ return str;
}
/// Attaches a note to this diagnostic. A new location may be optionally
@@ -451,7 +451,7 @@ void SourceMgrDiagnosticHandler::emitDiagnostic(Location loc, Twine message,
if (!llvm::isa<UnknownLoc>(loc))
strOS << loc << ": ";
strOS << message;
- return mgr.PrintMessage(os, SMLoc(), getDiagKind(kind), strOS.str());
+ return mgr.PrintMessage(os, SMLoc(), getDiagKind(kind), str);
}
// Otherwise if we are displaying the source line, try to convert the file
@@ -469,7 +469,7 @@ void SourceMgrDiagnosticHandler::emitDiagnostic(Location loc, Twine message,
llvm::raw_string_ostream locOS(locStr);
locOS << fileLoc.getFilename().getValue() << ":" << fileLoc.getLine() << ":"
<< fileLoc.getColumn();
- llvm::SMDiagnostic diag(locOS.str(), getDiagKind(kind), message.str());
+ llvm::SMDiagnostic diag(locStr, getDiagKind(kind), message.str());
diag.print(nullptr, os);
}
@@ -637,7 +637,7 @@ struct ExpectedDiag {
regexOS << '(' << regexStr << ')';
strToProcess = strToProcess.drop_front(regexEndIt + 2);
}
- substringRegex = llvm::Regex(regexOS.str());
+ substringRegex = llvm::Regex(regexStr);
return success();
}
diff --git a/mlir/lib/Interfaces/DataLayoutInterfaces.cpp b/mlir/lib/Interfaces/DataLayoutInterfaces.cpp
index 2634245a4b7b1e..2158953c07110a 100644
--- a/mlir/lib/Interfaces/DataLayoutInterfaces.cpp
+++ b/mlir/lib/Interfaces/DataLayoutInterfaces.cpp
@@ -29,7 +29,7 @@ using namespace mlir;
os << "neither the scoping op nor the type class provide data layout "
"information for "
<< type;
- llvm::report_fatal_error(Twine(os.str()));
+ llvm::report_fatal_error(Twine(message));
}
/// Returns the bitwidth of the index type if specified in the param list.
diff --git a/mlir/lib/Interfaces/RuntimeVerifiableOpInterface.cpp b/mlir/lib/Interfaces/RuntimeVerifiableOpInterface.cpp
index 561e8d33868748..8aa194befb4205 100644
--- a/mlir/lib/Interfaces/RuntimeVerifiableOpInterface.cpp
+++ b/mlir/lib/Interfaces/RuntimeVerifiableOpInterface.cpp
@@ -30,7 +30,7 @@ RuntimeVerifiableOpInterface::generateErrorMessage(Operation *op,
stream << "\n^ " << msg;
stream << "\nLocation: ";
op->getLoc().print(stream);
- return stream.str();
+ return buffer;
}
} // namespace mlir
diff --git a/mlir/lib/Pass/Pass.cpp b/mlir/lib/Pass/Pass.cpp
index deca03ae137f4e..83b46e8f5680a0 100644
--- a/mlir/lib/Pass/Pass.cpp
+++ b/mlir/lib/Pass/Pass.cpp
@@ -66,7 +66,6 @@ LogicalResult Pass::initializeOptions(
std::string errStr;
llvm::raw_string_ostream os(errStr);
if (failed(passOptions.parseFromString(options, os))) {
- os.flush();
return errorHandler(errStr);
}
return success();
@@ -700,7 +699,7 @@ std::string OpToOpPassAdaptor::getAdaptorName() {
os << '\'' << pm.getOpAnchorName() << '\'';
});
os << ']';
- return os.str();
+ return name;
}
void OpToOpPassAdaptor::runOnOperation() {
diff --git a/mlir/lib/Pass/PassCrashRecovery.cpp b/mlir/lib/Pass/PassCrashRecovery.cpp
index af3071e2566018..8c6d865cb31dd9 100644
--- a/mlir/lib/Pass/PassCrashRecovery.cpp
+++ b/mlir/lib/Pass/PassCrashRecovery.cpp
@@ -321,7 +321,7 @@ void PassCrashReproducerGenerator::prepareReproducerFor(Pass *pass,
passOS << ")";
impl->activeContexts.push_back(std::make_unique<RecoveryReproducerContext>(
- passOS.str(), op, impl->streamFactory, impl->pmFlagVerifyPasses));
+ passStr, op, impl->streamFactory, impl->pmFlagVerifyPasses));
}
void PassCrashReproducerGenerator::prepareReproducerFor(
iterator_range<PassManager::pass_iterator> passes, Operation *op) {
@@ -331,7 +331,7 @@ void PassCrashReproducerGenerator::prepareReproducerFor(
passes, passOS, [&](Pass &pass) { pass.printAsTextualPipeline(passOS); });
impl->activeContexts.push_back(std::make_unique<RecoveryReproducerContext>(
- passOS.str(), op, impl->streamFactory, impl->pmFlagVerifyPasses));
+ passStr, op, impl->streamFactory, impl->pmFlagVerifyPasses));
}
void PassCrashReproducerGenerator::removeLastReproducerFor(Pass *pass,
diff --git a/mlir/lib/Query/Matcher/RegistryManager.cpp b/mlir/lib/Query/Matcher/RegistryManager.cpp
index 8c9197f4d00981..645db7109c2deb 100644
--- a/mlir/lib/Query/Matcher/RegistryManager.cpp
+++ b/mlir/lib/Query/Matcher/RegistryManager.cpp
@@ -124,7 +124,7 @@ RegistryManager::getMatcherCompletions(llvm::ArrayRef<ArgKind> acceptedTypes,
else if (argKinds[0][0] == ArgKind::String)
typedText += "\"";
- completions.emplace_back(typedText, os.str());
+ completions.emplace_back(typedText, decl);
}
return completions;
diff --git a/mlir/lib/Query/QueryParser.cpp b/mlir/lib/Query/QueryParser.cpp
index 8a034634c5b89a..13ee931cc5227f 100644
--- a/mlir/lib/Query/QueryParser.cpp
+++ b/mlir/lib/Query/QueryParser.cpp
@@ -123,7 +123,7 @@ makeInvalidQueryFromDiagnostics(const matcher::internal::Diagnostics &diag) {
std::string errStr;
llvm::raw_string_ostream os(errStr);
diag.print(os);
- return new InvalidQuery(os.str());
+ return new InvalidQuery(errStr);
}
} // namespace
More information about the Mlir-commits
mailing list