Skip to content

Commit d71461c

Browse files
committed
[MachineBlockPlacement] Clean up data structures a bit.
No functionality change intended. llvm-svn: 300059
1 parent 592dbea commit d71461c

File tree

1 file changed

+17
-21
lines changed

1 file changed

+17
-21
lines changed

Diff for: llvm/lib/CodeGen/MachineBlockPlacement.cpp

+17-21
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@
5050
#include "llvm/Target/TargetLowering.h"
5151
#include "llvm/Target/TargetSubtargetInfo.h"
5252
#include <algorithm>
53-
#include <forward_list>
5453
#include <functional>
5554
#include <utility>
5655
using namespace llvm;
@@ -459,7 +458,7 @@ class MachineBlockPlacement : public MachineFunctionPass {
459458
/// Get the best pair of non-conflicting edges.
460459
static std::pair<WeightedEdge, WeightedEdge> getBestNonConflictingEdges(
461460
const MachineBasicBlock *BB,
462-
SmallVector<SmallVector<WeightedEdge, 8>, 2> &Edges);
461+
MutableArrayRef<SmallVector<WeightedEdge, 8>> Edges);
463462
/// Returns true if a block can tail duplicate into all unplaced
464463
/// predecessors. Filters based on loop.
465464
bool canTailDuplicateUnplacedPreds(
@@ -882,8 +881,8 @@ std::pair<MachineBlockPlacement::WeightedEdge,
882881
MachineBlockPlacement::WeightedEdge>
883882
MachineBlockPlacement::getBestNonConflictingEdges(
884883
const MachineBasicBlock *BB,
885-
SmallVector<SmallVector<MachineBlockPlacement::WeightedEdge, 8>, 2>
886-
&Edges) {
884+
MutableArrayRef<SmallVector<MachineBlockPlacement::WeightedEdge, 8>>
885+
Edges) {
887886
// Sort the edges, and then for each successor, find the best incoming
888887
// predecessor. If the best incoming predecessors aren't the same,
889888
// then that is clearly the best layout. If there is a conflict, one of the
@@ -941,7 +940,7 @@ MachineBlockPlacement::getBestTrellisSuccessor(
941940
return Result;
942941

943942
// Collect the edge frequencies of all edges that form the trellis.
944-
SmallVector<SmallVector<WeightedEdge, 8>, 2> Edges(2);
943+
SmallVector<WeightedEdge, 8> Edges[2];
945944
int SuccIndex = 0;
946945
for (auto Succ : ViableSuccs) {
947946
for (MachineBasicBlock *SuccPred : Succ->predecessors()) {
@@ -1085,23 +1084,20 @@ bool MachineBlockPlacement::canTailDuplicateUnplacedPreds(
10851084
/// We believe that 2 and 3 are common enough to justify the small margin in 1.
10861085
void MachineBlockPlacement::precomputeTriangleChains() {
10871086
struct TriangleChain {
1088-
unsigned Count;
1089-
std::forward_list<MachineBasicBlock*> Edges;
1090-
TriangleChain(MachineBasicBlock* src, MachineBasicBlock *dst) {
1091-
Edges.push_front(src);
1092-
Edges.push_front(dst);
1093-
Count = 1;
1094-
}
1087+
std::vector<MachineBasicBlock *> Edges;
1088+
TriangleChain(MachineBasicBlock *src, MachineBasicBlock *dst)
1089+
: Edges({src, dst}) {}
10951090

10961091
void append(MachineBasicBlock *dst) {
1097-
assert(!Edges.empty() && Edges.front()->isSuccessor(dst) &&
1092+
assert(getKey()->isSuccessor(dst) &&
10981093
"Attempting to append a block that is not a successor.");
1099-
Edges.push_front(dst);
1100-
++Count;
1094+
Edges.push_back(dst);
11011095
}
11021096

1103-
MachineBasicBlock *getKey() {
1104-
return Edges.front();
1097+
unsigned count() const { return Edges.size() - 1; }
1098+
1099+
MachineBasicBlock *getKey() const {
1100+
return Edges.back();
11051101
}
11061102
};
11071103

@@ -1174,11 +1170,11 @@ void MachineBlockPlacement::precomputeTriangleChains() {
11741170
// Benchmarking has shown that due to branch correlation duplicating 2 or
11751171
// more triangles is profitable, despite the calculations assuming
11761172
// independence.
1177-
if (Chain.Count < TriangleChainCount)
1173+
if (Chain.count() < TriangleChainCount)
11781174
continue;
1179-
MachineBasicBlock *dst = Chain.Edges.front();
1180-
Chain.Edges.pop_front();
1181-
for (MachineBasicBlock *src : Chain.Edges) {
1175+
MachineBasicBlock *dst = Chain.Edges.back();
1176+
Chain.Edges.pop_back();
1177+
for (MachineBasicBlock *src : reverse(Chain.Edges)) {
11821178
DEBUG(dbgs() << "Marking edge: " << getBlockName(src) << "->" <<
11831179
getBlockName(dst) << " as pre-computed based on triangles.\n");
11841180
ComputedEdges[src] = { dst, true };

0 commit comments

Comments
 (0)