[llvm-commits] [llvm] r51752 - in /llvm/trunk: tools/llvmc2/CompilationGraph.cpp tools/llvmc2/Tool.h utils/TableGen/LLVMCConfigurationEmitter.cpp

Mikhail Glushenkov foldr at codedgers.com
Thu May 29 23:24:49 PDT 2008


Author: foldr
Date: Fri May 30 01:24:49 2008
New Revision: 51752

URL: http://llvm.org/viewvc/llvm-project?rev=51752&view=rev
Log:
A small optimization: use static char* array instead of StrVector.

Modified:
    llvm/trunk/tools/llvmc2/CompilationGraph.cpp
    llvm/trunk/tools/llvmc2/Tool.h
    llvm/trunk/utils/TableGen/LLVMCConfigurationEmitter.cpp

Modified: llvm/trunk/tools/llvmc2/CompilationGraph.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvmc2/CompilationGraph.cpp?rev=51752&r1=51751&r2=51752&view=diff

==============================================================================
--- llvm/trunk/tools/llvmc2/CompilationGraph.cpp (original)
+++ llvm/trunk/tools/llvmc2/CompilationGraph.cpp Fri May 30 01:24:49 2008
@@ -123,10 +123,9 @@
 void CompilationGraph::insertEdge(const std::string& A, Edge* Edg) {
   Node& B = getNode(Edg->ToolName());
   if (A == "root") {
-    const StrVector& InputLanguages = B.ToolPtr->InputLanguages();
-    for (StrVector::const_iterator B = InputLanguages.begin(),
-           E = InputLanguages.end(); B != E; ++B)
-      ToolsMap[*B].push_back(IntrusiveRefCntPtr<Edge>(Edg));
+    const char** InLangs = B.ToolPtr->InputLanguages();
+    for (;*InLangs; ++InLangs)
+      ToolsMap[*InLangs].push_back(IntrusiveRefCntPtr<Edge>(Edg));
     NodesMap["root"].AddEdge(Edg);
   }
   else {
@@ -392,15 +391,17 @@
         return N->ToolPtr->OutputLanguage();
       }
       else {
-        const StrVector& InputLanguages = I->ToolPtr->InputLanguages();
+        const char** InLangs = I->ToolPtr->InputLanguages();
         std::string ret;
 
-        for (StrVector::const_iterator B = InputLanguages.begin(),
-               E = InputLanguages.end(); B != E; ++B) {
-          if (llvm::next(B) != E)
-            ret += *B + ", ";
-          else
-            ret += *B;
+        for (; *InLangs; ++InLangs) {
+          if (*(InLangs + 1)) {
+            ret += *InLangs;
+            ret +=  ", ";
+          }
+          else {
+            ret += *InLangs;
+          }
         }
 
         return ret;

Modified: llvm/trunk/tools/llvmc2/Tool.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvmc2/Tool.h?rev=51752&r1=51751&r2=51752&view=diff

==============================================================================
--- llvm/trunk/tools/llvmc2/Tool.h (original)
+++ llvm/trunk/tools/llvmc2/Tool.h Fri May 30 01:24:49 2008
@@ -42,10 +42,10 @@
                                    const llvm::sys::Path& outFile,
                                    const InputLanguagesSet& InLangs) const = 0;
 
-    virtual const char* Name() const = 0;
-    virtual StrVector InputLanguages() const = 0;
-    virtual const char* OutputLanguage() const = 0;
-    virtual const char* OutputSuffix() const = 0;
+    virtual const char*  Name() const = 0;
+    virtual const char** InputLanguages() const = 0;
+    virtual const char*  OutputLanguage() const = 0;
+    virtual const char*  OutputSuffix() const = 0;
 
     virtual bool IsLast() const = 0;
     virtual bool IsJoin() const = 0;

Modified: llvm/trunk/utils/TableGen/LLVMCConfigurationEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/LLVMCConfigurationEmitter.cpp?rev=51752&r1=51751&r2=51752&view=diff

==============================================================================
--- llvm/trunk/utils/TableGen/LLVMCConfigurationEmitter.cpp (original)
+++ llvm/trunk/utils/TableGen/LLVMCConfigurationEmitter.cpp Fri May 30 01:24:49 2008
@@ -1058,7 +1058,7 @@
   O << Indent2 << "const sys::Path& outFile,\n"
     << Indent2 << "const InputLanguagesSet& InLangs) const\n"
     << Indent1 << "{\n"
-    << Indent2 << "std::string cmd;\n"
+    << Indent2 << "const char* cmd;\n"
     << Indent2 << "std::vector<std::string> vec;\n";
 
   // cmd_line is either a string or a 'case' construct.
@@ -1130,15 +1130,8 @@
 /// EmitInOutLanguageMethods - Emit the [Input,Output]Language()
 /// methods for a given Tool class.
 void EmitInOutLanguageMethods (const ToolProperties& P, std::ostream& O) {
-  O << Indent1 << "StrVector InputLanguages() const {\n"
-    << Indent2 << "StrVector ret;\n";
-
-  for (StrVector::const_iterator B = P.InLanguage.begin(),
-         E = P.InLanguage.end(); B != E; ++B) {
-    O << Indent2 << "ret.push_back(\"" << *B << "\");\n";
-  }
-
-  O << Indent2 << "return ret;\n"
+  O << Indent1 << "const char** InputLanguages() const {\n"
+    << Indent2 << "return InputLanguages_;\n"
     << Indent1 << "}\n\n";
 
   O << Indent1 << "const char* OutputLanguage() const {\n"
@@ -1187,6 +1180,16 @@
   O << Indent1 << "}\n\n";
 }
 
+/// EmitStaticMemberDefinitions - Emit static member definitions for a
+/// given Tool class.
+void EmitStaticMemberDefinitions(const ToolProperties& P, std::ostream& O) {
+  O << "const char* " << P.Name << "::InputLanguages_[] = {";
+  for (StrVector::const_iterator B = P.InLanguage.begin(),
+         E = P.InLanguage.end(); B != E; ++B)
+    O << '\"' << *B << "\", ";
+  O << "0};\n\n";
+}
+
 /// EmitToolClassDefinition - Emit a Tool class definition.
 void EmitToolClassDefinition (const ToolProperties& P,
                               const GlobalOptionDescriptions& OptDescs,
@@ -1200,8 +1203,11 @@
     O << "JoinTool";
   else
     O << "Tool";
-  O << " {\npublic:\n";
 
+  O << "{\nprivate:\n"
+    << Indent1 << "static const char* InputLanguages_[];\n\n";
+
+  O << "public:\n";
   EmitNameMethod(P, O);
   EmitInOutLanguageMethods(P, O);
   EmitOutputSuffixMethod(P, O);
@@ -1210,7 +1216,10 @@
   EmitIsLastMethod(P, O);
 
   // Close class definition
-  O << "};\n\n";
+  O << "};\n";
+
+  EmitStaticMemberDefinitions(P, O);
+
 }
 
 /// EmitOptionDescriptions - Iterate over a list of option





More information about the llvm-commits mailing list