mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-02 22:32:38 +00:00
fc93ae629e
The new graph structure replaces the node and edge linked lists with vectors. Free lists (well, free vectors) are used for fast insertion/deletion. The ultimate aim is to make PBQP graphs cheap to clone. The motivation is that the PBQP solver destructively consumes input graphs while computing a solution, forcing the graph to be fully reconstructed for each round of PBQP. This imposes a high cost on large functions, which often require several rounds of solving/spilling to find a final register allocation. If we can cheaply clone the PBQP graph and incrementally update it between rounds then hopefully we can reduce this cost. Further, once we begin pooling matrix/vector values (future work), we can cache some PBQP solver metadata and share it between cloned graphs, allowing the PBQP solver to re-use some of the computation done in earlier rounds. For now this is just a data structure update. The allocator and solver still use the graph the same way as before, fully reconstructing it between each round. I expect no material change from this update, although it may change the iteration order of the nodes, causing ties in the solver to break in different directions, and this could perturb the generated allocations (hopefully in a completely benign way). Thanks very much to Arnaud Allard de Grandmaison for encouraging me to get back to work on this, and for a lot of discussion and many useful PBQP test cases. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@194300 91177308-0d34-0410-b5e6-96231b3b80d8
93 lines
3.0 KiB
C++
93 lines
3.0 KiB
C++
//===-- Solution.h ------- PBQP Solution ------------------------*- C++ -*-===//
|
|
//
|
|
// The LLVM Compiler Infrastructure
|
|
//
|
|
// This file is distributed under the University of Illinois Open Source
|
|
// License. See LICENSE.TXT for details.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
// PBQP Solution class.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef LLVM_CODEGEN_PBQP_SOLUTION_H
|
|
#define LLVM_CODEGEN_PBQP_SOLUTION_H
|
|
|
|
#include "Graph.h"
|
|
#include "Math.h"
|
|
#include <map>
|
|
|
|
namespace PBQP {
|
|
|
|
/// \brief Represents a solution to a PBQP problem.
|
|
///
|
|
/// To get the selection for each node in the problem use the getSelection method.
|
|
class Solution {
|
|
private:
|
|
|
|
typedef std::map<Graph::NodeId, unsigned> SelectionsMap;
|
|
SelectionsMap selections;
|
|
|
|
unsigned r0Reductions, r1Reductions, r2Reductions, rNReductions;
|
|
|
|
public:
|
|
|
|
/// \brief Initialise an empty solution.
|
|
Solution()
|
|
: r0Reductions(0), r1Reductions(0), r2Reductions(0), rNReductions(0) {}
|
|
|
|
/// \brief Number of nodes for which selections have been made.
|
|
/// @return Number of nodes for which selections have been made.
|
|
unsigned numNodes() const { return selections.size(); }
|
|
|
|
/// \brief Records a reduction via the R0 rule. Should be called from the
|
|
/// solver only.
|
|
void recordR0() { ++r0Reductions; }
|
|
|
|
/// \brief Returns the number of R0 reductions applied to solve the problem.
|
|
unsigned numR0Reductions() const { return r0Reductions; }
|
|
|
|
/// \brief Records a reduction via the R1 rule. Should be called from the
|
|
/// solver only.
|
|
void recordR1() { ++r1Reductions; }
|
|
|
|
/// \brief Returns the number of R1 reductions applied to solve the problem.
|
|
unsigned numR1Reductions() const { return r1Reductions; }
|
|
|
|
/// \brief Records a reduction via the R2 rule. Should be called from the
|
|
/// solver only.
|
|
void recordR2() { ++r2Reductions; }
|
|
|
|
/// \brief Returns the number of R2 reductions applied to solve the problem.
|
|
unsigned numR2Reductions() const { return r2Reductions; }
|
|
|
|
/// \brief Records a reduction via the RN rule. Should be called from the
|
|
/// solver only.
|
|
void recordRN() { ++ rNReductions; }
|
|
|
|
/// \brief Returns the number of RN reductions applied to solve the problem.
|
|
unsigned numRNReductions() const { return rNReductions; }
|
|
|
|
/// \brief Set the selection for a given node.
|
|
/// @param nItr Node iterator.
|
|
/// @param selection Selection for nItr.
|
|
void setSelection(Graph::NodeId nodeId, unsigned selection) {
|
|
selections[nodeId] = selection;
|
|
}
|
|
|
|
/// \brief Get a node's selection.
|
|
/// @param nItr Node iterator.
|
|
/// @return The selection for nItr;
|
|
unsigned getSelection(Graph::NodeId nodeId) const {
|
|
SelectionsMap::const_iterator sItr = selections.find(nodeId);
|
|
assert(sItr != selections.end() && "No selection for node.");
|
|
return sItr->second;
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
#endif // LLVM_CODEGEN_PBQP_SOLUTION_H
|