[llvm-branch-commits] [llvm] 2b6a926 - [RISCV] Simplify mergeCondAndCode in RISCVCompressInstEmitter.cpp. NFC

Craig Topper via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Sat Jan 16 21:33:45 PST 2021


Author: Craig Topper
Date: 2021-01-16T20:59:48-08:00
New Revision: 2b6a92625fdf11928bff1a31cdc06d7dbd193f85

URL: https://github.com/llvm/llvm-project/commit/2b6a92625fdf11928bff1a31cdc06d7dbd193f85
DIFF: https://github.com/llvm/llvm-project/commit/2b6a92625fdf11928bff1a31cdc06d7dbd193f85.diff

LOG: [RISCV] Simplify mergeCondAndCode in RISCVCompressInstEmitter.cpp. NFC

Instead forming a std::string and returning it to pass into another
raw_ostream, just pass the raw_ostream as a parameter.

Take StringRef as arguments instead raw_string_ostream references
making the caller responsible for converting to strings. Use
StringRef operations instead of std::string::substr.a

Added: 
    

Modified: 
    llvm/utils/TableGen/RISCVCompressInstEmitter.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/utils/TableGen/RISCVCompressInstEmitter.cpp b/llvm/utils/TableGen/RISCVCompressInstEmitter.cpp
index 3e20a726866d..797295d2cdb6 100644
--- a/llvm/utils/TableGen/RISCVCompressInstEmitter.cpp
+++ b/llvm/utils/TableGen/RISCVCompressInstEmitter.cpp
@@ -537,20 +537,14 @@ static void printPredicates(std::vector<const Record *> &Predicates,
   }
 }
 
-static std::string mergeCondAndCode(raw_string_ostream &CondStream,
-                                    raw_string_ostream &CodeStream) {
-  std::string S;
-  raw_string_ostream CombinedStream(S);
-  CombinedStream.indent(4)
-      << "if ("
-      << CondStream.str().substr(
-             6, CondStream.str().length() -
-                    10) // remove first indentation and last '&&'.
-      << ") {\n";
-  CombinedStream << CodeStream.str();
+static void mergeCondAndCode(raw_ostream &CombinedStream, StringRef CondStr,
+                             StringRef CodeStr) {
+  // Remove first indentation and last '&&'.
+  CondStr = CondStr.drop_front(6).drop_back(4);
+  CombinedStream.indent(4) << "if (" << CondStr << ") {\n";
+  CombinedStream << CodeStr;
   CombinedStream.indent(4) << "  return true;\n";
   CombinedStream.indent(4) << "} // if\n";
-  return CombinedStream.str();
 }
 
 void RISCVCompressInstEmitter::emitCompressInstEmitter(raw_ostream &o,
@@ -812,7 +806,7 @@ void RISCVCompressInstEmitter::emitCompressInstEmitter(raw_ostream &o,
     }
     if (CompressOrUncompress)
       CodeStream.indent(6) << "OutInst.setLoc(MI.getLoc());\n";
-    CaseStream << mergeCondAndCode(CondStream, CodeStream);
+    mergeCondAndCode(CaseStream, CondStream.str(), CodeStream.str());
     PrevOp = CurOp;
   }
   Func << CaseStream.str() << "\n";


        


More information about the llvm-branch-commits mailing list