|
50 | 50 | #include "llvm/Target/TargetLowering.h"
|
51 | 51 | #include "llvm/Target/TargetSubtargetInfo.h"
|
52 | 52 | #include <algorithm>
|
53 |
| -#include <forward_list> |
54 | 53 | #include <functional>
|
55 | 54 | #include <utility>
|
56 | 55 | using namespace llvm;
|
@@ -459,7 +458,7 @@ class MachineBlockPlacement : public MachineFunctionPass {
|
459 | 458 | /// Get the best pair of non-conflicting edges.
|
460 | 459 | static std::pair<WeightedEdge, WeightedEdge> getBestNonConflictingEdges(
|
461 | 460 | const MachineBasicBlock *BB,
|
462 |
| - SmallVector<SmallVector<WeightedEdge, 8>, 2> &Edges); |
| 461 | + MutableArrayRef<SmallVector<WeightedEdge, 8>> Edges); |
463 | 462 | /// Returns true if a block can tail duplicate into all unplaced
|
464 | 463 | /// predecessors. Filters based on loop.
|
465 | 464 | bool canTailDuplicateUnplacedPreds(
|
@@ -882,8 +881,8 @@ std::pair<MachineBlockPlacement::WeightedEdge,
|
882 | 881 | MachineBlockPlacement::WeightedEdge>
|
883 | 882 | MachineBlockPlacement::getBestNonConflictingEdges(
|
884 | 883 | const MachineBasicBlock *BB,
|
885 |
| - SmallVector<SmallVector<MachineBlockPlacement::WeightedEdge, 8>, 2> |
886 |
| - &Edges) { |
| 884 | + MutableArrayRef<SmallVector<MachineBlockPlacement::WeightedEdge, 8>> |
| 885 | + Edges) { |
887 | 886 | // Sort the edges, and then for each successor, find the best incoming
|
888 | 887 | // predecessor. If the best incoming predecessors aren't the same,
|
889 | 888 | // then that is clearly the best layout. If there is a conflict, one of the
|
@@ -941,7 +940,7 @@ MachineBlockPlacement::getBestTrellisSuccessor(
|
941 | 940 | return Result;
|
942 | 941 |
|
943 | 942 | // 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]; |
945 | 944 | int SuccIndex = 0;
|
946 | 945 | for (auto Succ : ViableSuccs) {
|
947 | 946 | for (MachineBasicBlock *SuccPred : Succ->predecessors()) {
|
@@ -1085,23 +1084,20 @@ bool MachineBlockPlacement::canTailDuplicateUnplacedPreds(
|
1085 | 1084 | /// We believe that 2 and 3 are common enough to justify the small margin in 1.
|
1086 | 1085 | void MachineBlockPlacement::precomputeTriangleChains() {
|
1087 | 1086 | 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}) {} |
1095 | 1090 |
|
1096 | 1091 | void append(MachineBasicBlock *dst) {
|
1097 |
| - assert(!Edges.empty() && Edges.front()->isSuccessor(dst) && |
| 1092 | + assert(getKey()->isSuccessor(dst) && |
1098 | 1093 | "Attempting to append a block that is not a successor.");
|
1099 |
| - Edges.push_front(dst); |
1100 |
| - ++Count; |
| 1094 | + Edges.push_back(dst); |
1101 | 1095 | }
|
1102 | 1096 |
|
1103 |
| - MachineBasicBlock *getKey() { |
1104 |
| - return Edges.front(); |
| 1097 | + unsigned count() const { return Edges.size() - 1; } |
| 1098 | + |
| 1099 | + MachineBasicBlock *getKey() const { |
| 1100 | + return Edges.back(); |
1105 | 1101 | }
|
1106 | 1102 | };
|
1107 | 1103 |
|
@@ -1174,11 +1170,11 @@ void MachineBlockPlacement::precomputeTriangleChains() {
|
1174 | 1170 | // Benchmarking has shown that due to branch correlation duplicating 2 or
|
1175 | 1171 | // more triangles is profitable, despite the calculations assuming
|
1176 | 1172 | // independence.
|
1177 |
| - if (Chain.Count < TriangleChainCount) |
| 1173 | + if (Chain.count() < TriangleChainCount) |
1178 | 1174 | 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)) { |
1182 | 1178 | DEBUG(dbgs() << "Marking edge: " << getBlockName(src) << "->" <<
|
1183 | 1179 | getBlockName(dst) << " as pre-computed based on triangles.\n");
|
1184 | 1180 | ComputedEdges[src] = { dst, true };
|
|
0 commit comments