[TableGen] Remove raw_string_ostream by just emitting the header for the switch the...
authorCraig Topper <craig.topper@gmail.com>
Wed, 30 Dec 2015 06:00:22 +0000 (06:00 +0000)
committerCraig Topper <craig.topper@gmail.com>
Wed, 30 Dec 2015 06:00:22 +0000 (06:00 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@256627 91177308-0d34-0410-b5e6-96231b3b80d8

utils/TableGen/AsmMatcherEmitter.cpp

index a6b5fb39eb394d9ba2f5580fb77c1e5f1afd30c9..08c540ddcd1454bf9704ca8ddf73afbde98eeaa2 100644 (file)
@@ -2119,12 +2119,7 @@ static void emitIsSubclass(CodeGenTarget &Target,
   OS << "  if (A == B)\n";
   OS << "    return true;\n\n";
 
   OS << "  if (A == B)\n";
   OS << "    return true;\n\n";
 
-  std::string OStr;
-  raw_string_ostream SS(OStr);
-  unsigned Count = 0;
-  SS << "  switch (A) {\n";
-  SS << "  default:\n";
-  SS << "    return false;\n";
+  bool EmittedSwitch = false;
   for (const auto &A : Infos) {
     std::vector<StringRef> SuperClasses;
     for (const auto &B : Infos) {
   for (const auto &A : Infos) {
     std::vector<StringRef> SuperClasses;
     for (const auto &B : Infos) {
@@ -2134,33 +2129,38 @@ static void emitIsSubclass(CodeGenTarget &Target,
 
     if (SuperClasses.empty())
       continue;
 
     if (SuperClasses.empty())
       continue;
-    ++Count;
 
 
-    SS << "\n  case " << A.Name << ":\n";
+    // If this is the first SuperClass, emit the switch header.
+    if (!EmittedSwitch) {
+      OS << "  switch (A) {\n"
+      OS << "  default:\n";
+      OS << "    return false;\n";
+      EmittedSwitch = true;
+    }
+
+    OS << "\n  case " << A.Name << ":\n";
 
     if (SuperClasses.size() == 1) {
 
     if (SuperClasses.size() == 1) {
-      SS << "    return B == " << SuperClasses.back().str() << ";\n";
+      OS << "    return B == " << SuperClasses.back().str() << ";\n";
       continue;
     }
 
     if (!SuperClasses.empty()) {
       continue;
     }
 
     if (!SuperClasses.empty()) {
-      SS << "    switch (B) {\n";
-      SS << "    default: return false;\n";
+      OS << "    switch (B) {\n";
+      OS << "    default: return false;\n";
       for (StringRef SC : SuperClasses)
       for (StringRef SC : SuperClasses)
-        SS << "    case " << SC << ": return true;\n";
-      SS << "    }\n";
+        OS << "    case " << SC << ": return true;\n";
+      OS << "    }\n";
     } else {
       // No case statement to emit
     } else {
       // No case statement to emit
-      SS << "    return false;\n";
+      OS << "    return false;\n";
     }
   }
     }
   }
-  SS << "  }\n";
+  OS << "  }\n";
 
 
-  // If there were case statements emitted into the string stream, write them
-  // to the output stream, otherwise write the default.
-  if (Count)
-    OS << SS.str();
-  else
+  // If there were case statements emitted into the string stream write the
+  // default.
+  if (!EmittedSwitch)
     OS << "  return false;\n";
 
   OS << "}\n\n";
     OS << "  return false;\n";
 
   OS << "}\n\n";