From 095b41c6eedb3acc908dc63ee91ff77944c07d75 Mon Sep 17 00:00:00 2001 From: JOE1994 Date: Sun, 15 Sep 2024 21:12:09 -0400 Subject: [PATCH] [mlir] Reland 5a6e52d6ef96d2bcab6dc50bdb369662ff17d2a0 with update (NFC) Excluded updates to mlir/lib/AsmParser/Parser.cpp , which caused LIT failure "FAIL: MLIR::completion.test" on multiple buildbots. --- mlir/lib/Bindings/Python/IRAttributes.cpp | 4 ++-- mlir/lib/TableGen/CodeGenHelpers.cpp | 2 +- mlir/lib/TableGen/Predicate.cpp | 2 +- mlir/lib/Target/LLVM/ModuleToObject.cpp | 2 +- mlir/lib/Target/LLVMIR/ConvertFromLLVMIR.cpp | 2 +- .../LLVMIR/Dialect/LLVMIR/LLVMToLLVMIRTranslation.cpp | 2 +- mlir/lib/Target/LLVMIR/Dialect/OpenMPCommon.cpp | 2 +- mlir/lib/Target/LLVMIR/ModuleImport.cpp | 4 ++-- mlir/lib/Target/SPIRV/Serialization/SerializeOps.cpp | 2 +- mlir/lib/Target/SPIRV/Serialization/Serializer.cpp | 4 ++-- mlir/lib/Tools/PDLL/Parser/Parser.cpp | 3 +-- mlir/lib/Tools/mlir-opt/MlirOptMain.cpp | 3 +-- mlir/lib/Transforms/ViewOpGraph.cpp | 6 +++--- 13 files changed, 18 insertions(+), 20 deletions(-) diff --git a/mlir/lib/Bindings/Python/IRAttributes.cpp b/mlir/lib/Bindings/Python/IRAttributes.cpp index bfdd4a520af2..ead81a76c053 100644 --- a/mlir/lib/Bindings/Python/IRAttributes.cpp +++ b/mlir/lib/Bindings/Python/IRAttributes.cpp @@ -708,7 +708,7 @@ public: llvm::raw_string_ostream os(message); os << "Expected a static ShapedType for the shaped_type parameter: " << py::repr(py::cast(*explicitType)); - throw py::value_error(os.str()); + throw py::value_error(message); } shapedType = *explicitType; } else { @@ -732,7 +732,7 @@ public: os << "All attributes must be of the same type and match " << "the type parameter: expected=" << py::repr(py::cast(shapedType)) << ", but got=" << py::repr(py::cast(attrType)); - throw py::value_error(os.str()); + throw py::value_error(message); } } diff --git a/mlir/lib/TableGen/CodeGenHelpers.cpp b/mlir/lib/TableGen/CodeGenHelpers.cpp index 7e7640303a12..2f13887aa0bb 100644 --- a/mlir/lib/TableGen/CodeGenHelpers.cpp +++ b/mlir/lib/TableGen/CodeGenHelpers.cpp @@ -315,5 +315,5 @@ std::string mlir::tblgen::escapeString(StringRef value) { std::string ret; llvm::raw_string_ostream os(ret); os.write_escaped(value); - return os.str(); + return ret; } diff --git a/mlir/lib/TableGen/Predicate.cpp b/mlir/lib/TableGen/Predicate.cpp index 8beb7720cb31..3c3c475f4d36 100644 --- a/mlir/lib/TableGen/Predicate.cpp +++ b/mlir/lib/TableGen/Predicate.cpp @@ -301,7 +301,7 @@ static std::string combineBinary(ArrayRef children, for (unsigned i = 1; i < size; ++i) { os << ' ' << combiner << " (" << children[i] << ')'; } - return os.str(); + return str; } // Prepend negation to the only condition in the predicate expression list. diff --git a/mlir/lib/Target/LLVM/ModuleToObject.cpp b/mlir/lib/Target/LLVM/ModuleToObject.cpp index d94c10de8d7c..77391341adaa 100644 --- a/mlir/lib/Target/LLVM/ModuleToObject.cpp +++ b/mlir/lib/Target/LLVM/ModuleToObject.cpp @@ -182,7 +182,7 @@ ModuleToObject::translateToISA(llvm::Module &llvmModule, codegenPasses.run(llvmModule); } - return stream.str(); + return targetISA; } void ModuleToObject::setDataLayoutAndTriple(llvm::Module &module) { diff --git a/mlir/lib/Target/LLVMIR/ConvertFromLLVMIR.cpp b/mlir/lib/Target/LLVMIR/ConvertFromLLVMIR.cpp index 7e2da1e0303c..0784c3c95e47 100644 --- a/mlir/lib/Target/LLVMIR/ConvertFromLLVMIR.cpp +++ b/mlir/lib/Target/LLVMIR/ConvertFromLLVMIR.cpp @@ -50,7 +50,7 @@ void registerFromLLVMIRTranslation() { std::string errStr; llvm::raw_string_ostream errStream(errStr); err.print(/*ProgName=*/"", errStream); - emitError(UnknownLoc::get(context)) << errStream.str(); + emitError(UnknownLoc::get(context)) << errStr; return {}; } if (llvm::verifyModule(*llvmModule, &llvm::errs())) diff --git a/mlir/lib/Target/LLVMIR/Dialect/LLVMIR/LLVMToLLVMIRTranslation.cpp b/mlir/lib/Target/LLVMIR/Dialect/LLVMIR/LLVMToLLVMIRTranslation.cpp index bdb15a290209..d948ff5eaf17 100644 --- a/mlir/lib/Target/LLVMIR/Dialect/LLVMIR/LLVMToLLVMIRTranslation.cpp +++ b/mlir/lib/Target/LLVMIR/Dialect/LLVMIR/LLVMToLLVMIRTranslation.cpp @@ -62,7 +62,7 @@ static std::string diagStr(const llvm::Type *type) { std::string str; llvm::raw_string_ostream os(str); type->print(os); - return os.str(); + return str; } /// Get the declaration of an overloaded llvm intrinsic. First we get the diff --git a/mlir/lib/Target/LLVMIR/Dialect/OpenMPCommon.cpp b/mlir/lib/Target/LLVMIR/Dialect/OpenMPCommon.cpp index 2145b953b64e..1595bd28a760 100644 --- a/mlir/lib/Target/LLVMIR/Dialect/OpenMPCommon.cpp +++ b/mlir/lib/Target/LLVMIR/Dialect/OpenMPCommon.cpp @@ -25,7 +25,7 @@ mlir::LLVM::createSourceLocStrFromLocation(Location loc, std::string locStr; llvm::raw_string_ostream locOS(locStr); locOS << loc; - return builder.getOrCreateSrcLocStr(locOS.str(), strLen); + return builder.getOrCreateSrcLocStr(locStr, strLen); } llvm::Constant * diff --git a/mlir/lib/Target/LLVMIR/ModuleImport.cpp b/mlir/lib/Target/LLVMIR/ModuleImport.cpp index d1732cb80892..21f2050cbceb 100644 --- a/mlir/lib/Target/LLVMIR/ModuleImport.cpp +++ b/mlir/lib/Target/LLVMIR/ModuleImport.cpp @@ -55,7 +55,7 @@ static std::string diag(const llvm::Value &value) { std::string str; llvm::raw_string_ostream os(str); os << value; - return os.str(); + return str; } // Utility to print an LLVM metadata node as a string for passing @@ -66,7 +66,7 @@ static std::string diagMD(const llvm::Metadata *node, std::string str; llvm::raw_string_ostream os(str); node->print(os, module, /*IsForDebug=*/true); - return os.str(); + return str; } /// Returns the name of the global_ctors global variables. diff --git a/mlir/lib/Target/SPIRV/Serialization/SerializeOps.cpp b/mlir/lib/Target/SPIRV/Serialization/SerializeOps.cpp index 6c28c04fc1e0..4c15523a05fa 100644 --- a/mlir/lib/Target/SPIRV/Serialization/SerializeOps.cpp +++ b/mlir/lib/Target/SPIRV/Serialization/SerializeOps.cpp @@ -137,7 +137,7 @@ Serializer::processSpecConstantOperationOp(spirv::SpecConstantOperationOp op) { std::string enclosedOpName; llvm::raw_string_ostream rss(enclosedOpName); rss << "Op" << enclosedOp.getName().stripDialect(); - auto enclosedOpcode = spirv::symbolizeOpcode(rss.str()); + auto enclosedOpcode = spirv::symbolizeOpcode(enclosedOpName); if (!enclosedOpcode) { op.emitError("Couldn't find op code for op ") diff --git a/mlir/lib/Target/SPIRV/Serialization/Serializer.cpp b/mlir/lib/Target/SPIRV/Serialization/Serializer.cpp index b0feda0517ca..7719eb68b2c2 100644 --- a/mlir/lib/Target/SPIRV/Serialization/Serializer.cpp +++ b/mlir/lib/Target/SPIRV/Serialization/Serializer.cpp @@ -915,7 +915,7 @@ uint32_t Serializer::prepareConstantInt(Location loc, IntegerAttr intAttr, value.print(rss, /*isSigned=*/false); emitError(loc, "cannot serialize ") - << bitwidth << "-bit integer literal: " << rss.str(); + << bitwidth << "-bit integer literal: " << valueStr; return 0; } } @@ -968,7 +968,7 @@ uint32_t Serializer::prepareConstantFp(Location loc, FloatAttr floatAttr, value.print(rss); emitError(loc, "cannot serialize ") - << floatAttr.getType() << "-typed float literal: " << rss.str(); + << floatAttr.getType() << "-typed float literal: " << valueStr; return 0; } diff --git a/mlir/lib/Tools/PDLL/Parser/Parser.cpp b/mlir/lib/Tools/PDLL/Parser/Parser.cpp index 2f842df48826..575fb4aacd94 100644 --- a/mlir/lib/Tools/PDLL/Parser/Parser.cpp +++ b/mlir/lib/Tools/PDLL/Parser/Parser.cpp @@ -148,9 +148,8 @@ private: std::string docStr; { llvm::raw_string_ostream docOS(docStr); - std::string tmpDocStr = doc.str(); raw_indented_ostream(docOS).printReindented( - StringRef(tmpDocStr).rtrim(" \t")); + StringRef(docStr).rtrim(" \t")); } return docStr; } diff --git a/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp b/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp index 0b88d31f41a7..5a7b17672c51 100644 --- a/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp +++ b/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp @@ -312,8 +312,7 @@ static LogicalResult doVerifyRoundTrip(Operation *op, FallbackAsmResourceMap fallbackResourceMap; ParserConfig parseConfig(&roundtripContext, /*verifyAfterParse=*/true, &fallbackResourceMap); - roundtripModule = - parseSourceString(ostream.str(), parseConfig); + roundtripModule = parseSourceString(buffer, parseConfig); if (!roundtripModule) { op->emitOpError() << "failed to parse " << testType << " content back, cannot verify round-trip.\n"; diff --git a/mlir/lib/Transforms/ViewOpGraph.cpp b/mlir/lib/Transforms/ViewOpGraph.cpp index 82e9863ab40b..fa0af7665ba4 100644 --- a/mlir/lib/Transforms/ViewOpGraph.cpp +++ b/mlir/lib/Transforms/ViewOpGraph.cpp @@ -46,7 +46,7 @@ static std::string strFromOs(function_ref func) { std::string buf; llvm::raw_string_ostream os(buf); func(os); - return os.str(); + return buf; } /// Escape special characters such as '\n' and quotation marks. @@ -199,7 +199,7 @@ private: std::string buf; llvm::raw_string_ostream ss(buf); attr.print(ss); - os << truncateString(ss.str()); + os << truncateString(buf); } /// Append an edge to the list of edges. @@ -262,7 +262,7 @@ private: std::string buf; llvm::raw_string_ostream ss(buf); interleaveComma(op->getResultTypes(), ss); - os << truncateString(ss.str()) << ")"; + os << truncateString(buf) << ")"; } // Print attributes.