Support dependencies between plugins by priority-sorting.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@59449 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/tools/llvmc2/driver/Plugin.cpp b/tools/llvmc2/driver/Plugin.cpp
index c9b3960..17c7086 100644
--- a/tools/llvmc2/driver/Plugin.cpp
+++ b/tools/llvmc2/driver/Plugin.cpp
@@ -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;
   }