[polly] 53bc35a - [polly] Tidy uses of raw_string_ostream (NFC)

Youngsuk Kim via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 17 08:02:06 PDT 2024


Author: Youngsuk Kim
Date: 2024-09-17T09:58:58-05:00
New Revision: 53bc35a80a844601c10c8bb75832cbee3ba841ac

URL: https://github.com/llvm/llvm-project/commit/53bc35a80a844601c10c8bb75832cbee3ba841ac
DIFF: https://github.com/llvm/llvm-project/commit/53bc35a80a844601c10c8bb75832cbee3ba841ac.diff

LOG: [polly] Tidy uses of raw_string_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: 
    polly/lib/Analysis/ScopDetectionDiagnostic.cpp
    polly/lib/Analysis/ScopInfo.cpp
    polly/lib/CodeGen/BlockGenerators.cpp
    polly/lib/Exchange/JSONExporter.cpp

Removed: 
    


################################################################################
diff  --git a/polly/lib/Analysis/ScopDetectionDiagnostic.cpp b/polly/lib/Analysis/ScopDetectionDiagnostic.cpp
index d2fbcf7319856a..14a6f074454f76 100644
--- a/polly/lib/Analysis/ScopDetectionDiagnostic.cpp
+++ b/polly/lib/Analysis/ScopDetectionDiagnostic.cpp
@@ -89,7 +89,6 @@ template <typename T> std::string operator+(Twine LHS, const T &RHS) {
   std::string Buf;
   raw_string_ostream fmt(Buf);
   fmt << RHS;
-  fmt.flush();
 
   return LHS.concat(Buf).str();
 }
@@ -669,7 +668,7 @@ std::string ReportAlias::formatInvalidAlias(std::string Prefix,
 
   OS << Suffix;
 
-  return OS.str();
+  return Message;
 }
 
 std::string ReportAlias::getRemarkName() const { return "Alias"; }

diff  --git a/polly/lib/Analysis/ScopInfo.cpp b/polly/lib/Analysis/ScopInfo.cpp
index 044d3573793f01..56ffb990faf1c2 100644
--- a/polly/lib/Analysis/ScopInfo.cpp
+++ b/polly/lib/Analysis/ScopInfo.cpp
@@ -1818,11 +1818,9 @@ std::pair<std::string, std::string> Scop::getEntryExitStr() const {
   raw_string_ostream EntryStr(EntryName);
 
   R.getEntry()->printAsOperand(EntryStr, false);
-  EntryStr.str();
 
   if (R.getExit()) {
     R.getExit()->printAsOperand(ExitStr, false);
-    ExitStr.str();
   } else
     ExitName = "FunctionExit";
 

diff  --git a/polly/lib/CodeGen/BlockGenerators.cpp b/polly/lib/CodeGen/BlockGenerators.cpp
index 004fa64c82db2b..c58763603cfa22 100644
--- a/polly/lib/CodeGen/BlockGenerators.cpp
+++ b/polly/lib/CodeGen/BlockGenerators.cpp
@@ -645,7 +645,7 @@ static std::string getInstName(Value *Val) {
   std::string Result;
   raw_string_ostream OS(Result);
   Val->printAsOperand(OS, false);
-  return OS.str();
+  return Result;
 }
 
 void BlockGenerator::generateBeginStmtTrace(ScopStmt &Stmt, LoopToScevMapT &LTS,

diff  --git a/polly/lib/Exchange/JSONExporter.cpp b/polly/lib/Exchange/JSONExporter.cpp
index 63fb06a634cc12..dfd63146edb5e2 100644
--- a/polly/lib/Exchange/JSONExporter.cpp
+++ b/polly/lib/Exchange/JSONExporter.cpp
@@ -116,12 +116,12 @@ static json::Array exportArrays(const Scop &S) {
     }
     for (; i < SAI->getNumberOfDimensions(); i++) {
       SAI->getDimensionSize(i)->print(RawStringOstream);
-      Sizes.push_back(RawStringOstream.str());
+      Sizes.push_back(Buffer);
       Buffer.clear();
     }
     Array["sizes"] = std::move(Sizes);
     SAI->getElementType()->print(RawStringOstream);
-    Array["type"] = RawStringOstream.str();
+    Array["type"] = Buffer;
     Buffer.clear();
     Arrays.push_back(std::move(Array));
   }
@@ -575,14 +575,14 @@ static bool areArraysEqual(ScopArrayInfo *SAI, const json::Object &Array) {
   for (unsigned i = 1; i < Array.getArray("sizes")->size(); i++) {
     SAI->getDimensionSize(i)->print(RawStringOstream);
     const json::Array &SizesArray = *Array.getArray("sizes");
-    if (RawStringOstream.str() != SizesArray[i].getAsString().value())
+    if (Buffer != SizesArray[i].getAsString().value())
       return false;
     Buffer.clear();
   }
 
   // Check if key 'type' 
diff ers from the current one or is not valid.
   SAI->getElementType()->print(RawStringOstream);
-  if (RawStringOstream.str() != Array.getString("type").value()) {
+  if (Buffer != Array.getString("type").value()) {
     errs() << "Array has not a valid type.\n";
     return false;
   }


        


More information about the llvm-commits mailing list