[Mlir-commits] [mlir] 123e8c7 - [mlir] Don't call llvm::raw_string_ostream::flush() (NFC)

Youngsuk Kim llvmlistbot at llvm.org
Sun Sep 22 13:41:29 PDT 2024


Author: Youngsuk Kim
Date: 2024-09-22T15:37:34-05:00
New Revision: 123e8c735d0765a12e65f1daefcbe23a059e26fd

URL: https://github.com/llvm/llvm-project/commit/123e8c735d0765a12e65f1daefcbe23a059e26fd
DIFF: https://github.com/llvm/llvm-project/commit/123e8c735d0765a12e65f1daefcbe23a059e26fd.diff

LOG: [mlir] Don't call llvm::raw_string_ostream::flush() (NFC)

Don't call raw_string_ostream::flush(), which is essentially a no-op.
As specified in the docs, raw_string_ostream is always unbuffered.
( 65b13610a5226b84889b923bae884ba395ad084d for further reference )

Added: 
    

Modified: 
    mlir/lib/Conversion/NVGPUToNVVM/NVGPUToNVVM.cpp
    mlir/lib/Dialect/LLVMIR/IR/BasicPtxBuilderInterface.cpp
    mlir/lib/Dialect/Transform/IR/TransformDialect.cpp
    mlir/lib/Dialect/XeGPU/IR/XeGPUOps.cpp
    mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
    mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
    mlir/unittests/Support/IndentedOstreamTest.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Conversion/NVGPUToNVVM/NVGPUToNVVM.cpp b/mlir/lib/Conversion/NVGPUToNVVM/NVGPUToNVVM.cpp
index cf984ca3293c06..ab47c9ae8fe79b 100644
--- a/mlir/lib/Conversion/NVGPUToNVVM/NVGPUToNVVM.cpp
+++ b/mlir/lib/Conversion/NVGPUToNVVM/NVGPUToNVVM.cpp
@@ -495,7 +495,6 @@ static std::string buildMmaSparseAsmConstraintString(unsigned matASize,
   // The final operand is for the sparsity metadata.
   // The sparsity selector appears as direct literal.
   ss << "r";
-  ss.flush();
   return str;
 }
 
@@ -535,7 +534,6 @@ static std::string buildMmaSparseAsmString(
   ss << "$" << asmArgIdx++ << ",";
   assert(metaDataSelector <= 1);
   ss << "0x" << metaDataSelector << ";";
-  ss.flush();
   return asmStr;
 }
 

diff  --git a/mlir/lib/Dialect/LLVMIR/IR/BasicPtxBuilderInterface.cpp b/mlir/lib/Dialect/LLVMIR/IR/BasicPtxBuilderInterface.cpp
index 961944cd93b4de..b109f00c3da13a 100644
--- a/mlir/lib/Dialect/LLVMIR/IR/BasicPtxBuilderInterface.cpp
+++ b/mlir/lib/Dialect/LLVMIR/IR/BasicPtxBuilderInterface.cpp
@@ -99,14 +99,12 @@ void PtxBuilder::insertValue(Value v, PTXRegisterMod itype) {
       } else {
         ss << getModifier() << getRegisterType(t) << ",";
       }
-      ss.flush();
     }
     return;
   }
   // Handle Scalars
   addValue(v);
   ss << getModifier() << getRegisterType(v) << ",";
-  ss.flush();
 }
 
 LLVM::InlineAsmOp PtxBuilder::build() {

diff  --git a/mlir/lib/Dialect/Transform/IR/TransformDialect.cpp b/mlir/lib/Dialect/Transform/IR/TransformDialect.cpp
index e628430ff861ed..497ceb19f1a215 100644
--- a/mlir/lib/Dialect/Transform/IR/TransformDialect.cpp
+++ b/mlir/lib/Dialect/Transform/IR/TransformDialect.cpp
@@ -111,7 +111,6 @@ void transform::TransformDialect::reportDuplicateTypeRegistration(
   llvm::raw_string_ostream msg(buffer);
   msg << "extensible dialect type '" << mnemonic
       << "' is already registered with a 
diff erent implementation";
-  msg.flush();
   llvm::report_fatal_error(StringRef(buffer));
 }
 
@@ -121,7 +120,6 @@ void transform::TransformDialect::reportDuplicateOpRegistration(
   llvm::raw_string_ostream msg(buffer);
   msg << "extensible dialect operation '" << opName
       << "' is already registered with a mismatching TypeID";
-  msg.flush();
   llvm::report_fatal_error(StringRef(buffer));
 }
 

diff  --git a/mlir/lib/Dialect/XeGPU/IR/XeGPUOps.cpp b/mlir/lib/Dialect/XeGPU/IR/XeGPUOps.cpp
index 8e185b8d2586d9..9c517337a3aa57 100644
--- a/mlir/lib/Dialect/XeGPU/IR/XeGPUOps.cpp
+++ b/mlir/lib/Dialect/XeGPU/IR/XeGPUOps.cpp
@@ -37,7 +37,6 @@ static std::string makeString(T array, bool breakline = false) {
       os << "\n\t\t";
   }
   os << array.back() << "]";
-  os.flush();
   return buf;
 }
 

diff  --git a/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp b/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
index fcb329eb7a92c1..cc0de5bc838c99 100644
--- a/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
+++ b/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
@@ -195,7 +195,6 @@ translateDataLayout(DataLayoutSpecInterface attribute,
       bool isLittleEndian =
           value.getValue() == DLTIDialect::kDataLayoutEndiannessLittle;
       layoutStream << "-" << (isLittleEndian ? "e" : "E");
-      layoutStream.flush();
       continue;
     }
     if (key.getValue() == DLTIDialect::kDataLayoutProgramMemorySpaceKey) {
@@ -205,7 +204,6 @@ translateDataLayout(DataLayoutSpecInterface attribute,
       if (space == 0)
         continue;
       layoutStream << "-P" << space;
-      layoutStream.flush();
       continue;
     }
     if (key.getValue() == DLTIDialect::kDataLayoutGlobalMemorySpaceKey) {
@@ -215,7 +213,6 @@ translateDataLayout(DataLayoutSpecInterface attribute,
       if (space == 0)
         continue;
       layoutStream << "-G" << space;
-      layoutStream.flush();
       continue;
     }
     if (key.getValue() == DLTIDialect::kDataLayoutAllocaMemorySpaceKey) {
@@ -225,7 +222,6 @@ translateDataLayout(DataLayoutSpecInterface attribute,
       if (space == 0)
         continue;
       layoutStream << "-A" << space;
-      layoutStream.flush();
       continue;
     }
     if (key.getValue() == DLTIDialect::kDataLayoutStackAlignmentKey) {
@@ -235,7 +231,6 @@ translateDataLayout(DataLayoutSpecInterface attribute,
       if (alignment == 0)
         continue;
       layoutStream << "-S" << alignment;
-      layoutStream.flush();
       continue;
     }
     emitError(*loc) << "unsupported data layout key " << key;
@@ -293,7 +288,6 @@ translateDataLayout(DataLayoutSpecInterface attribute,
     if (failed(result))
       return failure();
   }
-  layoutStream.flush();
   StringRef layoutSpec(llvmDataLayout);
   if (layoutSpec.starts_with("-"))
     layoutSpec = layoutSpec.drop_front();

diff  --git a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
index c3edd00ed14e7d..cbe8a055958567 100644
--- a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
+++ b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
@@ -1411,7 +1411,6 @@ void OpEmitter::genPropertiesSupport() {
         // Backward compat for now, TODO: Remove at some point.
         os << "   if (!attr) attr = dict.get(\"result_segment_sizes\");";
       }
-      os.flush();
 
       setPropMethod << "{\n"
                     << formatv(propFromAttrFmt,
@@ -1445,7 +1444,6 @@ void OpEmitter::genPropertiesSupport() {
         // Backward compat for now
         os << "   if (!attr) attr = dict.get(\"result_segment_sizes\");";
       }
-      os.flush();
 
       setPropMethod << formatv(R"decl(
   {{
@@ -4188,10 +4186,8 @@ OpOperandAdaptorEmitter::OpOperandAdaptorEmitter(
                     "    bool operator!=(const Properties &rhs) const {\n"
                     "      return !(*this == rhs);\n"
                     "    }\n";
-    comparatorOs.flush();
     os << comparator;
     os << "  };\n";
-    os.flush();
 
     genericAdaptorBase.declare<ExtraClassDeclaration>(std::move(declarations));
   }

diff  --git a/mlir/unittests/Support/IndentedOstreamTest.cpp b/mlir/unittests/Support/IndentedOstreamTest.cpp
index 804a7e475e096f..df1edb7c03b138 100644
--- a/mlir/unittests/Support/IndentedOstreamTest.cpp
+++ b/mlir/unittests/Support/IndentedOstreamTest.cpp
@@ -17,7 +17,6 @@ TEST(FormatTest, SingleLine) {
   llvm::raw_string_ostream os(str);
   raw_indented_ostream ros(os);
   ros << 10;
-  ros.flush();
   EXPECT_THAT(str, StrEq("10"));
 }
 
@@ -30,7 +29,6 @@ TEST(FormatTest, SimpleMultiLine) {
   ros << "\n";
   ros << "c";
   ros << "\n";
-  ros.flush();
   EXPECT_THAT(str, StrEq("ab\nc\n"));
 }
 
@@ -43,7 +41,6 @@ TEST(FormatTest, SimpleMultiLineIndent) {
   ros << "\n";
   ros << "c";
   ros << "\n";
-  ros.flush();
   EXPECT_THAT(str, StrEq("  a    b\n    c\n"));
 }
 
@@ -62,7 +59,6 @@ TEST(FormatTest, SingleRegion) {
     }
   }
   ros << "after";
-  ros.flush();
   const auto *expected =
       R"(before
   inside 10
@@ -79,7 +75,6 @@ after)";
   ros.scope().os << "inside " << 10 << "\n   two\n";
   ros.scope().os.scope("{\n", "\n}\n").os << "inner inner";
   ros << "after";
-  ros.flush();
   EXPECT_THAT(os.str(), StrEq(expected));
 }
 
@@ -99,7 +94,6 @@ TEST(FormatTest, Reindent) {
                  
   )";
   ros.printReindented(desc);
-  ros.flush();
   const auto *expected =
       R"(First line
         second line
@@ -120,7 +114,6 @@ TEST(FormatTest, ReindentLineEndings) {
   const auto *desc =
       "\r\n\r\n\r\n         First line\r\n                 second line";
   ros.printReindented(desc);
-  ros.flush();
   const auto *expected = "First line\r\n        second line";
   EXPECT_THAT(str, StrEq(expected));
 }


        


More information about the Mlir-commits mailing list