[llvm-commits] [llvm] r59449 - in /llvm/trunk: include/llvm/CompilerDriver/Common.td include/llvm/CompilerDriver/Plugin.h tools/llvmc2/driver/Plugin.cpp utils/TableGen/LLVMCConfigurationEmitter.cpp

Mikhail Glushenkov foldr at codedgers.com
Mon Nov 17 09:30:25 PST 2008


Author: foldr
Date: Mon Nov 17 11:30:25 2008
New Revision: 59449

URL: http://llvm.org/viewvc/llvm-project?rev=59449&view=rev
Log:
Support dependencies between plugins by priority-sorting.

Modified:
    llvm/trunk/include/llvm/CompilerDriver/Common.td
    llvm/trunk/include/llvm/CompilerDriver/Plugin.h
    llvm/trunk/tools/llvmc2/driver/Plugin.cpp
    llvm/trunk/utils/TableGen/LLVMCConfigurationEmitter.cpp

Modified: llvm/trunk/include/llvm/CompilerDriver/Common.td
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CompilerDriver/Common.td?rev=59449&r1=59448&r2=59449&view=diff

==============================================================================
--- llvm/trunk/include/llvm/CompilerDriver/Common.td (original)
+++ llvm/trunk/include/llvm/CompilerDriver/Common.td Mon Nov 17 11:30:25 2008
@@ -65,6 +65,11 @@
 def inc_weight;
 def dec_weight;
 
+// Used to specify plugin priority.
+class PluginPriority<int p> {
+      int priority = p;
+}
+
 // Option list - used to specify aliases and sometimes help strings.
 class OptionList<list<dag> l> {
       list<dag> options = l;

Modified: llvm/trunk/include/llvm/CompilerDriver/Plugin.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CompilerDriver/Plugin.h?rev=59449&r1=59448&r2=59449&view=diff

==============================================================================
--- llvm/trunk/include/llvm/CompilerDriver/Plugin.h (original)
+++ llvm/trunk/include/llvm/CompilerDriver/Plugin.h Mon Nov 17 11:30:25 2008
@@ -24,6 +24,11 @@
   /// BasePlugin - An abstract base class for all LLVMC plugins.
   struct BasePlugin {
 
+    /// Priority - Plugin priority, useful for handling dependencies
+    /// between plugins. Plugins with lower priorities are loaded
+    /// first.
+    virtual int Priority() const = 0;
+
     /// PopulateLanguageMap - The auto-generated function that fills in
     /// the language map (map from file extensions to language names).
     virtual void PopulateLanguageMap(LanguageMap&) const = 0;

Modified: llvm/trunk/tools/llvmc2/driver/Plugin.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvmc2/driver/Plugin.cpp?rev=59449&r1=59448&r2=59449&view=diff

==============================================================================
--- llvm/trunk/tools/llvmc2/driver/Plugin.cpp (original)
+++ llvm/trunk/tools/llvmc2/driver/Plugin.cpp Mon Nov 17 11:30:25 2008
@@ -13,6 +13,7 @@
 
 #include "llvm/CompilerDriver/Plugin.h"
 
+#include <algorithm>
 #include <vector>
 
 namespace {
@@ -27,6 +28,13 @@
   static bool pluginListInitialized = false;
   typedef std::vector<const llvmc::BasePlugin*> PluginList;
   static PluginList Plugins;
+
+  struct ByPriority {
+    bool operator()(const llvmc::BasePlugin* lhs,
+                    const llvmc::BasePlugin* rhs) {
+      return lhs->Priority() < rhs->Priority();
+    }
+  };
 }
 
 namespace llvmc {
@@ -36,6 +44,7 @@
       for (PluginRegistry::iterator B = PluginRegistry::begin(),
              E = PluginRegistry::end(); B != E; ++B)
         Plugins.push_back(B->instantiate());
+      std::sort(Plugins.begin(), Plugins.end(), ByPriority());
     }
     pluginListInitialized = true;
   }

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

==============================================================================
--- llvm/trunk/utils/TableGen/LLVMCConfigurationEmitter.cpp (original)
+++ llvm/trunk/utils/TableGen/LLVMCConfigurationEmitter.cpp Mon Nov 17 11:30:25 2008
@@ -771,7 +771,7 @@
                                        GlobalOptionDescriptions& OptDescs)
 {
   // Iterate over a properties list of every Tool definition
-  for (;B!=E;++B) {
+  for (; B!=E; ++B) {
     RecordVector::value_type T = *B;
     // Throws an exception if the value does not exist.
     ListInit* PropList = T->getValueAsListInit("options");
@@ -1701,9 +1701,10 @@
 }
 
 /// EmitRegisterPlugin - Emit code to register this plugin.
-void EmitRegisterPlugin(std::ostream& O) {
+void EmitRegisterPlugin(int Priority, std::ostream& O) {
   O << "namespace {\n\n"
-    << "struct Plugin : public llvmc::BasePlugin {\n"
+    << "struct Plugin : public llvmc::BasePlugin {\n\n"
+    << Indent1 << "int Priority() const { return " << Priority << "; }\n\n"
     << Indent1 << "void PopulateLanguageMap(LanguageMap& langMap) const\n"
     << Indent1 << "{ PopulateLanguageMapLocal(langMap); }\n\n"
     << Indent1
@@ -1777,6 +1778,15 @@
   ToolProps.erase(new_end, ToolProps.end());
 }
 
+int CalculatePriority(RecordVector::const_iterator B,
+                      RecordVector::const_iterator E) {
+  int total = 0;
+  for (; B!=E; ++B) {
+    total += static_cast<int>((*B)->getValueAsInt("priority"));
+  }
+  return total;
+}
+
 // End of anonymous namespace
 }
 
@@ -1799,7 +1809,8 @@
   GlobalOptionDescriptions OptDescs;
   CollectToolProperties(Tools.begin(), Tools.end(), ToolProps, OptDescs);
 
-  RecordVector OptionLists = Records.getAllDerivedDefinitions("OptionList");
+  const RecordVector& OptionLists =
+    Records.getAllDerivedDefinitions("OptionList");
   CollectPropertiesFromOptionLists(OptionLists.begin(), OptionLists.end(),
                                    OptDescs);
 
@@ -1841,7 +1852,10 @@
   EmitPopulateCompilationGraph(CompilationGraphRecord, ToolProps, O);
 
   // Emit code for plugin registration.
-  EmitRegisterPlugin(O);
+  const RecordVector& Priorities =
+    Records.getAllDerivedDefinitions("PluginPriority");
+  EmitRegisterPlugin(CalculatePriority(Priorities.begin(), Priorities.end()),
+                     O);
 
   // EOF
   } catch (std::exception& Error) {





More information about the llvm-commits mailing list