mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-11-02 07:17:36 +00:00
[PBQP] Replace PBQPBuilder with composable constraints (PBQPRAConstraint).
This patch removes the PBQPBuilder class and its subclasses and replaces them with a composable constraints class: PBQPRAConstraint. This allows constraints that are only required for optimisation (e.g. coalescing, soft pairing) to be mixed and matched. This patch also introduces support for target writers to supply custom constraints for their targets by overriding a TargetSubtargetInfo method: std::unique_ptr<PBQPRAConstraints> getCustomPBQPConstraints() const; This patch should have no effect on allocations. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@219421 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -22,6 +22,7 @@
|
||||
#include <set>
|
||||
#include <type_traits>
|
||||
|
||||
namespace llvm {
|
||||
namespace PBQP {
|
||||
|
||||
template <typename CostT,
|
||||
@@ -104,6 +105,7 @@ private:
|
||||
MatrixCostPool matrixPool;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace PBQP
|
||||
} // namespace llvm
|
||||
|
||||
#endif
|
||||
|
||||
@@ -17,11 +17,12 @@
|
||||
|
||||
#include "llvm/ADT/ilist.h"
|
||||
#include "llvm/ADT/ilist_node.h"
|
||||
#include "llvm/Support/Compiler.h"
|
||||
#include "llvm/Support/Debug.h"
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <set>
|
||||
|
||||
namespace llvm {
|
||||
namespace PBQP {
|
||||
|
||||
class GraphBase {
|
||||
@@ -195,7 +196,7 @@ namespace PBQP {
|
||||
EdgeEntry& getEdge(EdgeId EId) { return Edges[EId]; }
|
||||
const EdgeEntry& getEdge(EdgeId EId) const { return Edges[EId]; }
|
||||
|
||||
NodeId addConstructedNode(const NodeEntry &N) {
|
||||
NodeId addConstructedNode(NodeEntry N) {
|
||||
NodeId NId = 0;
|
||||
if (!FreeNodeIds.empty()) {
|
||||
NId = FreeNodeIds.back();
|
||||
@@ -208,7 +209,7 @@ namespace PBQP {
|
||||
return NId;
|
||||
}
|
||||
|
||||
EdgeId addConstructedEdge(const EdgeEntry &E) {
|
||||
EdgeId addConstructedEdge(EdgeEntry E) {
|
||||
assert(findEdge(E.getN1Id(), E.getN2Id()) == invalidEdgeId() &&
|
||||
"Attempt to add duplicate edge.");
|
||||
EdgeId EId = 0;
|
||||
@@ -237,6 +238,12 @@ namespace PBQP {
|
||||
|
||||
class NodeItr {
|
||||
public:
|
||||
typedef std::forward_iterator_tag iterator_category;
|
||||
typedef NodeId value_type;
|
||||
typedef int difference_type;
|
||||
typedef NodeId* pointer;
|
||||
typedef NodeId& reference;
|
||||
|
||||
NodeItr(NodeId CurNId, const Graph &G)
|
||||
: CurNId(CurNId), EndNId(G.Nodes.size()), FreeNodeIds(G.FreeNodeIds) {
|
||||
this->CurNId = findNextInUse(CurNId); // Move to first in-use node id
|
||||
@@ -251,7 +258,7 @@ namespace PBQP {
|
||||
NodeId findNextInUse(NodeId NId) const {
|
||||
while (NId < EndNId &&
|
||||
std::find(FreeNodeIds.begin(), FreeNodeIds.end(), NId) !=
|
||||
FreeNodeIds.end()) {
|
||||
FreeNodeIds.end()) {
|
||||
++NId;
|
||||
}
|
||||
return NId;
|
||||
@@ -331,7 +338,10 @@ namespace PBQP {
|
||||
};
|
||||
|
||||
/// @brief Construct an empty PBQP graph.
|
||||
Graph() : Solver(nullptr) { }
|
||||
Graph() : Solver(nullptr) {}
|
||||
|
||||
/// @brief Construct an empty PBQP graph with the given graph metadata.
|
||||
Graph(GraphMetadata Metadata) : Metadata(Metadata), Solver(nullptr) {}
|
||||
|
||||
/// @brief Get a reference to the graph metadata.
|
||||
GraphMetadata& getMetadata() { return Metadata; }
|
||||
@@ -418,9 +428,7 @@ namespace PBQP {
|
||||
/// @brief Get a node's cost vector (const version).
|
||||
/// @param NId Node id.
|
||||
/// @return Node cost vector.
|
||||
const Vector& getNodeCosts(NodeId NId) const {
|
||||
return *getNode(NId).Costs;
|
||||
}
|
||||
const Vector& getNodeCosts(NodeId NId) const { return *getNode(NId).Costs; }
|
||||
|
||||
NodeMetadata& getNodeMetadata(NodeId NId) {
|
||||
return getNode(NId).Metadata;
|
||||
@@ -448,7 +456,9 @@ namespace PBQP {
|
||||
/// @brief Get an edge's cost matrix (const version).
|
||||
/// @param EId Edge id.
|
||||
/// @return Edge cost matrix.
|
||||
const Matrix& getEdgeCosts(EdgeId EId) const { return *getEdge(EId).Costs; }
|
||||
const Matrix& getEdgeCosts(EdgeId EId) const {
|
||||
return *getEdge(EId).Costs;
|
||||
}
|
||||
|
||||
EdgeMetadata& getEdgeMetadata(EdgeId NId) {
|
||||
return getEdge(NId).Metadata;
|
||||
@@ -507,7 +517,7 @@ namespace PBQP {
|
||||
NodeEntry &N = getNode(NId);
|
||||
// TODO: Can this be for-each'd?
|
||||
for (AdjEdgeItr AEItr = N.adjEdgesBegin(),
|
||||
AEEnd = N.adjEdgesEnd();
|
||||
AEEnd = N.adjEdgesEnd();
|
||||
AEItr != AEEnd;) {
|
||||
EdgeId EId = *AEItr;
|
||||
++AEItr;
|
||||
@@ -588,7 +598,7 @@ namespace PBQP {
|
||||
|
||||
/// @brief Dump a graph to an output stream.
|
||||
template <typename OStream>
|
||||
void dump(OStream &OS) {
|
||||
void dumpToStream(OStream &OS) {
|
||||
OS << nodeIds().size() << " " << edgeIds().size() << "\n";
|
||||
|
||||
for (auto NId : nodeIds()) {
|
||||
@@ -621,6 +631,11 @@ namespace PBQP {
|
||||
}
|
||||
}
|
||||
|
||||
/// @brief Dump this graph to dbgs().
|
||||
void dump() {
|
||||
dumpToStream(dbgs());
|
||||
}
|
||||
|
||||
/// @brief Print a representation of this graph in DOT format.
|
||||
/// @param OS Output stream to print on.
|
||||
template <typename OStream>
|
||||
@@ -645,6 +660,7 @@ namespace PBQP {
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace PBQP
|
||||
} // namespace llvm
|
||||
|
||||
#endif // LLVM_CODEGEN_PBQP_GRAPH_HPP
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#include <cassert>
|
||||
#include <functional>
|
||||
|
||||
namespace llvm {
|
||||
namespace PBQP {
|
||||
|
||||
typedef float PBQPNum;
|
||||
@@ -433,6 +434,7 @@ private:
|
||||
Metadata md;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace PBQP
|
||||
} // namespace llvm
|
||||
|
||||
#endif // LLVM_CODEGEN_PBQP_MATH_H
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#include "Math.h"
|
||||
#include "Solution.h"
|
||||
|
||||
namespace llvm {
|
||||
namespace PBQP {
|
||||
|
||||
/// \brief Reduce a node of degree one.
|
||||
@@ -186,6 +187,7 @@ namespace PBQP {
|
||||
return s;
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace PBQP
|
||||
} // namespace llvm
|
||||
|
||||
#endif
|
||||
|
||||
@@ -26,10 +26,13 @@
|
||||
#include <limits>
|
||||
#include <vector>
|
||||
|
||||
namespace llvm{
|
||||
namespace PBQP {
|
||||
|
||||
namespace RegAlloc {
|
||||
|
||||
/// @brief Spill option index.
|
||||
inline unsigned getSpillOptionIdx() { return 0; }
|
||||
|
||||
/// \brief Metadata to speed allocatability test.
|
||||
///
|
||||
/// Keeps track of the number of infinities in each row and column.
|
||||
@@ -81,6 +84,8 @@ namespace PBQP {
|
||||
|
||||
class NodeMetadata {
|
||||
public:
|
||||
typedef std::vector<unsigned> OptionToRegMap;
|
||||
|
||||
typedef enum { Unprocessed,
|
||||
OptimallyReducible,
|
||||
ConservativelyAllocatable,
|
||||
@@ -89,6 +94,14 @@ namespace PBQP {
|
||||
NodeMetadata() : RS(Unprocessed), DeniedOpts(0), OptUnsafeEdges(nullptr){}
|
||||
~NodeMetadata() { delete[] OptUnsafeEdges; }
|
||||
|
||||
void setVReg(unsigned VReg) { this->VReg = VReg; }
|
||||
unsigned getVReg() const { return VReg; }
|
||||
|
||||
void setOptionRegs(OptionToRegMap OptionRegs) {
|
||||
this->OptionRegs = std::move(OptionRegs);
|
||||
}
|
||||
const OptionToRegMap& getOptionRegs() const { return OptionRegs; }
|
||||
|
||||
void setup(const Vector& Costs) {
|
||||
NumOpts = Costs.getLength() - 1;
|
||||
OptUnsafeEdges = new unsigned[NumOpts]();
|
||||
@@ -124,6 +137,8 @@ namespace PBQP {
|
||||
unsigned NumOpts;
|
||||
unsigned DeniedOpts;
|
||||
unsigned* OptUnsafeEdges;
|
||||
unsigned VReg;
|
||||
OptionToRegMap OptionRegs;
|
||||
};
|
||||
|
||||
class RegAllocSolverImpl {
|
||||
@@ -144,7 +159,36 @@ namespace PBQP {
|
||||
typedef RegAlloc::NodeMetadata NodeMetadata;
|
||||
|
||||
struct EdgeMetadata { };
|
||||
struct GraphMetadata { };
|
||||
|
||||
class GraphMetadata {
|
||||
public:
|
||||
GraphMetadata(MachineFunction &MF,
|
||||
LiveIntervals &LIS,
|
||||
MachineBlockFrequencyInfo &MBFI)
|
||||
: MF(MF), LIS(LIS), MBFI(MBFI) {}
|
||||
|
||||
MachineFunction &MF;
|
||||
LiveIntervals &LIS;
|
||||
MachineBlockFrequencyInfo &MBFI;
|
||||
|
||||
void setNodeIdForVReg(unsigned VReg, GraphBase::NodeId NId) {
|
||||
VRegToNodeId[VReg] = NId;
|
||||
}
|
||||
|
||||
GraphBase::NodeId getNodeIdForVReg(unsigned VReg) const {
|
||||
auto VRegItr = VRegToNodeId.find(VReg);
|
||||
if (VRegItr == VRegToNodeId.end())
|
||||
return GraphBase::invalidNodeId();
|
||||
return VRegItr->second;
|
||||
}
|
||||
|
||||
void eraseNodeIdForVReg(unsigned VReg) {
|
||||
VRegToNodeId.erase(VReg);
|
||||
}
|
||||
|
||||
private:
|
||||
DenseMap<unsigned, NodeId> VRegToNodeId;
|
||||
};
|
||||
|
||||
typedef PBQP::Graph<RegAllocSolverImpl> Graph;
|
||||
|
||||
@@ -345,16 +389,21 @@ namespace PBQP {
|
||||
NodeSet NotProvablyAllocatableNodes;
|
||||
};
|
||||
|
||||
typedef Graph<RegAllocSolverImpl> Graph;
|
||||
class PBQPRAGraph : public PBQP::Graph<RegAllocSolverImpl> {
|
||||
private:
|
||||
typedef PBQP::Graph<RegAllocSolverImpl> BaseT;
|
||||
public:
|
||||
PBQPRAGraph(GraphMetadata Metadata) : BaseT(Metadata) {}
|
||||
};
|
||||
|
||||
inline Solution solve(Graph& G) {
|
||||
inline Solution solve(PBQPRAGraph& G) {
|
||||
if (G.empty())
|
||||
return Solution();
|
||||
RegAllocSolverImpl RegAllocSolver(G);
|
||||
return RegAllocSolver.solve();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
} // namespace RegAlloc
|
||||
} // namespace PBQP
|
||||
} // namespace llvm
|
||||
|
||||
#endif // LLVM_CODEGEN_PBQP_REGALLOCSOLVER_H
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#include "Math.h"
|
||||
#include <map>
|
||||
|
||||
namespace llvm {
|
||||
namespace PBQP {
|
||||
|
||||
/// \brief Represents a solution to a PBQP problem.
|
||||
@@ -87,6 +88,7 @@ namespace PBQP {
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace PBQP
|
||||
} // namespace llvm
|
||||
|
||||
#endif // LLVM_CODEGEN_PBQP_SOLUTION_H
|
||||
|
||||
Reference in New Issue
Block a user