From: Benjamin Kramer Date: Wed, 12 Apr 2017 13:26:28 +0000 (+0000) Subject: [MachineBlockPlacement] Clean up data structures a bit. X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d71461c2095c685a9fc612a58945fe995f7eee8a;p=platform%2Fupstream%2Fllvm.git [MachineBlockPlacement] Clean up data structures a bit. No functionality change intended. llvm-svn: 300059 --- diff --git a/llvm/lib/CodeGen/MachineBlockPlacement.cpp b/llvm/lib/CodeGen/MachineBlockPlacement.cpp index 1a9a166..6c1381b 100644 --- a/llvm/lib/CodeGen/MachineBlockPlacement.cpp +++ b/llvm/lib/CodeGen/MachineBlockPlacement.cpp @@ -50,7 +50,6 @@ #include "llvm/Target/TargetLowering.h" #include "llvm/Target/TargetSubtargetInfo.h" #include -#include #include #include using namespace llvm; @@ -459,7 +458,7 @@ class MachineBlockPlacement : public MachineFunctionPass { /// Get the best pair of non-conflicting edges. static std::pair getBestNonConflictingEdges( const MachineBasicBlock *BB, - SmallVector, 2> &Edges); + MutableArrayRef> 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::getBestNonConflictingEdges( const MachineBasicBlock *BB, - SmallVector, 2> - &Edges) { + MutableArrayRef> + 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::getBestTrellisSuccessor( return Result; // Collect the edge frequencies of all edges that form the trellis. - SmallVector, 2> Edges(2); + SmallVector Edges[2]; int SuccIndex = 0; for (auto Succ : ViableSuccs) { for (MachineBasicBlock *SuccPred : Succ->predecessors()) { @@ -1085,23 +1084,20 @@ bool MachineBlockPlacement::canTailDuplicateUnplacedPreds( /// 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 Edges; - TriangleChain(MachineBasicBlock* src, MachineBasicBlock *dst) { - Edges.push_front(src); - Edges.push_front(dst); - Count = 1; - } + std::vector 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::precomputeTriangleChains() { // 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 };