Skip to content

Commit 884221e

Browse files
committed
[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 ( 65b1361 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.
1 parent 64aaf05 commit 884221e

File tree

20 files changed

+30
-33
lines changed

20 files changed

+30
-33
lines changed

mlir/lib/Debug/Observers/ActionProfiler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,6 @@ void ActionProfiler::print(const ActionActiveStack *action,
5858
if (printComma)
5959
os << ",\n";
6060
printComma = true;
61-
os << event.str();
61+
os << str;
6262
os.flush();
6363
}

mlir/lib/Dialect/Bufferization/Transforms/OneShotAnalysis.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1299,7 +1299,7 @@ static void annotateOpsWithAliasSets(Operation *op,
12991299
std::string buffer;
13001300
llvm::raw_string_ostream stream(buffer);
13011301
alias.printAsOperand(stream, asmState);
1302-
aliases.push_back(b.getStringAttr(stream.str()));
1302+
aliases.push_back(b.getStringAttr(buffer));
13031303
});
13041304
return b.getArrayAttr(aliases);
13051305
};

mlir/lib/Dialect/LLVMIR/IR/LLVMAttrs.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ std::string TargetFeaturesAttr::getFeaturesString() const {
326326
llvm::raw_string_ostream ss(featuresString);
327327
llvm::interleave(
328328
getFeatures(), ss, [&](auto &feature) { ss << feature.strref(); }, ",");
329-
return ss.str();
329+
return featuresString;
330330
}
331331

332332
TargetFeaturesAttr TargetFeaturesAttr::featuresAt(Operation *op) {

mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3247,7 +3247,7 @@ LogicalResult LLVMDialect::verifyDataLayoutString(
32473247
std::string message;
32483248
llvm::raw_string_ostream messageStream(message);
32493249
llvm::logAllUnhandledErrors(maybeDataLayout.takeError(), messageStream);
3250-
reportError("invalid data layout descriptor: " + messageStream.str());
3250+
reportError("invalid data layout descriptor: " + message);
32513251
return failure();
32523252
}
32533253

mlir/lib/Dialect/LLVMIR/IR/NVVMDialect.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ LogicalResult MmaOp::verify() {
521521
}
522522
errorStream << "but got ";
523523
llvm::interleaveComma(operandTySeg, errorStream);
524-
return emitOpError(errorStream.str());
524+
return emitOpError(errorMessage);
525525
}
526526
}
527527

@@ -533,7 +533,7 @@ LogicalResult MmaOp::verify() {
533533
<< "Could not match allowed types for the result; expected one of ";
534534
llvm::interleaveComma(expectedResult, errorStream);
535535
errorStream << " but got " << getResult().getType();
536-
return emitOpError(errorStream.str());
536+
return emitOpError(errorMessage);
537537
}
538538

539539
// Ensure that binary MMA variants have a b1 MMA operation defined.
@@ -967,7 +967,6 @@ std::string NVVM::WgmmaMmaAsyncOp::getPtx() {
967967
}
968968
ss << ";\n"
969969
<< "}\n";
970-
ss.flush();
971970
return ptx;
972971
}
973972

mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2334,9 +2334,8 @@ std::string mlir::linalg::generateLibraryCallName(Operation *op) {
23342334
return std::string();
23352335
ss << "_";
23362336
}
2337-
std::string res = ss.str();
2338-
res.pop_back();
2339-
return res;
2337+
name.pop_back();
2338+
return name;
23402339
}
23412340

23422341
//===----------------------------------------------------------------------===//

mlir/lib/Dialect/Linalg/TransformOps/LinalgMatchOps.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ DiagnosedSilenceableFailure transform::MatchStructuredBodyOp::matchOperation(
209209
os);
210210
if (result)
211211
return DiagnosedSilenceableFailure::success();
212-
return emitSilenceableError() << "contraction: " << os.str();
212+
return emitSilenceableError() << "contraction: " << message;
213213
}
214214
return emitDefiniteFailure() << "unknown body condition";
215215
}
@@ -226,7 +226,7 @@ LogicalResult transform::MatchStructuredBodyOp::verify() {
226226
getElementwiseAttrName(),
227227
getContractionAttrName()},
228228
os);
229-
return emitOpError() << "only one of {" << os.str() << "} is allowed";
229+
return emitOpError() << "only one of {" << attributeNames << "} is allowed";
230230
}
231231

232232
if (std::optional<ArrayAttr> contractionAttr = getContraction()) {

mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1258,7 +1258,7 @@ static void printCaptureType(OpAsmPrinter &p, Operation *op,
12581258
typeCap << "VLAType";
12591259
if (mapCaptureType.getValue() == mlir::omp::VariableCaptureKind::This)
12601260
typeCap << "This";
1261-
p << typeCap.str();
1261+
p << typeCapStr;
12621262
}
12631263

12641264
static ParseResult parseCaptureType(OpAsmParser &parser,

mlir/lib/Dialect/SparseTensor/IR/Detail/Var.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ std::string Var::str() const {
2929
std::string str;
3030
llvm::raw_string_ostream os(str);
3131
print(os);
32-
return os.str();
32+
return str;
3333
}
3434

3535
void Var::print(AsmPrinter &printer) const { print(printer.getStream()); }

mlir/lib/Dialect/Traits.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ static std::string getShapeString(ArrayRef<int64_t> shape) {
223223
},
224224
"x");
225225
ss << '\'';
226-
return ss.str();
226+
return ret;
227227
}
228228

229229
LogicalResult OpTrait::impl::verifyCompatibleOperandBroadcast(Operation *op) {

0 commit comments

Comments
 (0)