[llvm] r300059 - [MachineBlockPlacement] Clean up data structures a bit.

Benjamin Kramer via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 12 06:26:28 PDT 2017


Author: d0k
Date: Wed Apr 12 08:26:28 2017
New Revision: 300059

URL: http://llvm.org/viewvc/llvm-project?rev=300059&view=rev
Log:
[MachineBlockPlacement] Clean up data structures a bit.

No functionality change intended.

Modified:
    llvm/trunk/lib/CodeGen/MachineBlockPlacement.cpp

Modified: llvm/trunk/lib/CodeGen/MachineBlockPlacement.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachineBlockPlacement.cpp?rev=300059&r1=300058&r2=300059&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/MachineBlockPlacement.cpp (original)
+++ llvm/trunk/lib/CodeGen/MachineBlockPlacement.cpp Wed Apr 12 08:26:28 2017
@@ -50,7 +50,6 @@
 #include "llvm/Target/TargetLowering.h"
 #include "llvm/Target/TargetSubtargetInfo.h"
 #include <algorithm>
-#include <forward_list>
 #include <functional>
 #include <utility>
 using namespace llvm;
@@ -459,7 +458,7 @@ class MachineBlockPlacement : public Mac
   /// Get the best pair of non-conflicting edges.
   static std::pair<WeightedEdge, WeightedEdge> getBestNonConflictingEdges(
       const MachineBasicBlock *BB,
-      SmallVector<SmallVector<WeightedEdge, 8>, 2> &Edges);
+      MutableArrayRef<SmallVector<WeightedEdge, 8>> Edges);
   /// Returns true if a block can tail duplicate into all unplaced
   /// predecessors. Filters based on loop.
   bool canTailDuplicateUnplacedPreds(
@@ -882,8 +881,8 @@ std::pair<MachineBlockPlacement::Weighte
           MachineBlockPlacement::WeightedEdge>
 MachineBlockPlacement::getBestNonConflictingEdges(
     const MachineBasicBlock *BB,
-    SmallVector<SmallVector<MachineBlockPlacement::WeightedEdge, 8>, 2>
-        &Edges) {
+    MutableArrayRef<SmallVector<MachineBlockPlacement::WeightedEdge, 8>>
+        Edges) {
   // Sort the edges, and then for each successor, find the best incoming
   // predecessor. If the best incoming predecessors aren't the same,
   // then that is clearly the best layout. If there is a conflict, one of the
@@ -941,7 +940,7 @@ MachineBlockPlacement::getBestTrellisSuc
     return Result;
 
   // Collect the edge frequencies of all edges that form the trellis.
-  SmallVector<SmallVector<WeightedEdge, 8>, 2> Edges(2);
+  SmallVector<WeightedEdge, 8> Edges[2];
   int SuccIndex = 0;
   for (auto Succ : ViableSuccs) {
     for (MachineBasicBlock *SuccPred : Succ->predecessors()) {
@@ -1085,23 +1084,20 @@ bool MachineBlockPlacement::canTailDupli
 /// We believe that 2 and 3 are common enough to justify the small margin in 1.
 void MachineBlockPlacement::precomputeTriangleChains() {
   struct TriangleChain {
-    unsigned Count;
-    std::forward_list<MachineBasicBlock*> Edges;
-    TriangleChain(MachineBasicBlock* src, MachineBasicBlock *dst) {
-      Edges.push_front(src);
-      Edges.push_front(dst);
-      Count = 1;
-    }
+    std::vector<MachineBasicBlock *> Edges;
+    TriangleChain(MachineBasicBlock *src, MachineBasicBlock *dst)
+        : Edges({src, dst}) {}
 
     void append(MachineBasicBlock *dst) {
-      assert(!Edges.empty() && Edges.front()->isSuccessor(dst) &&
+      assert(getKey()->isSuccessor(dst) &&
              "Attempting to append a block that is not a successor.");
-      Edges.push_front(dst);
-      ++Count;
+      Edges.push_back(dst);
     }
 
-    MachineBasicBlock *getKey() {
-      return Edges.front();
+    unsigned count() const { return Edges.size() - 1; }
+
+    MachineBasicBlock *getKey() const {
+      return Edges.back();
     }
   };
 
@@ -1174,11 +1170,11 @@ void MachineBlockPlacement::precomputeTr
     // Benchmarking has shown that due to branch correlation duplicating 2 or
     // more triangles is profitable, despite the calculations assuming
     // independence.
-    if (Chain.Count < TriangleChainCount)
+    if (Chain.count() < TriangleChainCount)
       continue;
-    MachineBasicBlock *dst = Chain.Edges.front();
-    Chain.Edges.pop_front();
-    for (MachineBasicBlock *src : Chain.Edges) {
+    MachineBasicBlock *dst = Chain.Edges.back();
+    Chain.Edges.pop_back();
+    for (MachineBasicBlock *src : reverse(Chain.Edges)) {
       DEBUG(dbgs() << "Marking edge: " << getBlockName(src) << "->" <<
             getBlockName(dst) << " as pre-computed based on triangles.\n");
       ComputedEdges[src] = { dst, true };




More information about the llvm-commits mailing list