mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-08-22 10:29:35 +00:00
Add a debug option to dump PBQP graphs during register allocation.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@153483 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
eb6dd23c95
commit
20df03ccd5
@ -350,6 +350,43 @@ namespace PBQP {
|
|||||||
numNodes = numEdges = 0;
|
numNodes = numEdges = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// \brief Dump a graph to an output stream.
|
||||||
|
template <typename OStream>
|
||||||
|
void dump(OStream &os) {
|
||||||
|
os << getNumNodes() << " " << getNumEdges() << "\n";
|
||||||
|
|
||||||
|
for (NodeItr nodeItr = nodesBegin(), nodeEnd = nodesEnd();
|
||||||
|
nodeItr != nodeEnd; ++nodeItr) {
|
||||||
|
const Vector& v = getNodeCosts(nodeItr);
|
||||||
|
os << "\n" << v.getLength() << "\n";
|
||||||
|
assert(v.getLength() != 0 && "Empty vector in graph.");
|
||||||
|
os << v[0];
|
||||||
|
for (unsigned i = 1; i < v.getLength(); ++i) {
|
||||||
|
os << " " << v[i];
|
||||||
|
}
|
||||||
|
os << "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
for (EdgeItr edgeItr = edgesBegin(), edgeEnd = edgesEnd();
|
||||||
|
edgeItr != edgeEnd; ++edgeItr) {
|
||||||
|
unsigned n1 = std::distance(nodesBegin(), getEdgeNode1(edgeItr));
|
||||||
|
unsigned n2 = std::distance(nodesBegin(), getEdgeNode2(edgeItr));
|
||||||
|
assert(n1 != n2 && "PBQP graphs shound not have self-edges.");
|
||||||
|
const Matrix& m = getEdgeCosts(edgeItr);
|
||||||
|
os << "\n" << n1 << " " << n2 << "\n"
|
||||||
|
<< m.getRows() << " " << m.getCols() << "\n";
|
||||||
|
assert(m.getRows() != 0 && "No rows in matrix.");
|
||||||
|
assert(m.getCols() != 0 && "No cols in matrix.");
|
||||||
|
for (unsigned i = 0; i < m.getRows(); ++i) {
|
||||||
|
os << m[i][0];
|
||||||
|
for (unsigned j = 1; j < m.getCols(); ++j) {
|
||||||
|
os << " " << m[i][j];
|
||||||
|
}
|
||||||
|
os << "\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// \brief Print a representation of this graph in DOT format.
|
/// \brief Print a representation of this graph in DOT format.
|
||||||
/// @param os Output stream to print on.
|
/// @param os Output stream to print on.
|
||||||
template <typename OStream>
|
template <typename OStream>
|
||||||
|
@ -36,6 +36,7 @@
|
|||||||
#include "Spiller.h"
|
#include "Spiller.h"
|
||||||
#include "VirtRegMap.h"
|
#include "VirtRegMap.h"
|
||||||
#include "RegisterCoalescer.h"
|
#include "RegisterCoalescer.h"
|
||||||
|
#include "llvm/Module.h"
|
||||||
#include "llvm/Analysis/AliasAnalysis.h"
|
#include "llvm/Analysis/AliasAnalysis.h"
|
||||||
#include "llvm/CodeGen/CalcSpillWeights.h"
|
#include "llvm/CodeGen/CalcSpillWeights.h"
|
||||||
#include "llvm/CodeGen/LiveIntervalAnalysis.h"
|
#include "llvm/CodeGen/LiveIntervalAnalysis.h"
|
||||||
@ -56,6 +57,7 @@
|
|||||||
#include <limits>
|
#include <limits>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <set>
|
#include <set>
|
||||||
|
#include <sstream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
@ -69,6 +71,13 @@ pbqpCoalescing("pbqp-coalescing",
|
|||||||
cl::desc("Attempt coalescing during PBQP register allocation."),
|
cl::desc("Attempt coalescing during PBQP register allocation."),
|
||||||
cl::init(false), cl::Hidden);
|
cl::init(false), cl::Hidden);
|
||||||
|
|
||||||
|
#ifndef NDEBUG
|
||||||
|
static cl::opt<bool>
|
||||||
|
pbqpDumpGraphs("pbqp-dump-graphs",
|
||||||
|
cl::desc("Dump graphs for each function/round in the compilation unit."),
|
||||||
|
cl::init(false), cl::Hidden);
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
///
|
///
|
||||||
@ -667,6 +676,12 @@ bool RegAllocPBQP::runOnMachineFunction(MachineFunction &MF) {
|
|||||||
// Find the vreg intervals in need of allocation.
|
// Find the vreg intervals in need of allocation.
|
||||||
findVRegIntervalsToAlloc();
|
findVRegIntervalsToAlloc();
|
||||||
|
|
||||||
|
const Function* func = mf->getFunction();
|
||||||
|
std::string fqn =
|
||||||
|
func->getParent()->getModuleIdentifier() + "." +
|
||||||
|
func->getName().str();
|
||||||
|
(void)fqn;
|
||||||
|
|
||||||
// If there are non-empty intervals allocate them using pbqp.
|
// If there are non-empty intervals allocate them using pbqp.
|
||||||
if (!vregsToAlloc.empty()) {
|
if (!vregsToAlloc.empty()) {
|
||||||
|
|
||||||
@ -678,6 +693,20 @@ bool RegAllocPBQP::runOnMachineFunction(MachineFunction &MF) {
|
|||||||
|
|
||||||
std::auto_ptr<PBQPRAProblem> problem =
|
std::auto_ptr<PBQPRAProblem> problem =
|
||||||
builder->build(mf, lis, loopInfo, vregsToAlloc);
|
builder->build(mf, lis, loopInfo, vregsToAlloc);
|
||||||
|
|
||||||
|
#ifndef NDEBUG
|
||||||
|
if (pbqpDumpGraphs) {
|
||||||
|
std::ostringstream rs;
|
||||||
|
rs << round;
|
||||||
|
std::string graphFileName(fqn + "." + rs.str() + ".pbqpgraph");
|
||||||
|
std::string tmp;
|
||||||
|
raw_fd_ostream os(graphFileName.c_str(), tmp);
|
||||||
|
DEBUG(dbgs() << "Dumping graph for round " << round << " to \""
|
||||||
|
<< graphFileName << "\"\n");
|
||||||
|
problem->getGraph().dump(os);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
PBQP::Solution solution =
|
PBQP::Solution solution =
|
||||||
PBQP::HeuristicSolver<PBQP::Heuristics::Briggs>::solve(
|
PBQP::HeuristicSolver<PBQP::Heuristics::Briggs>::solve(
|
||||||
problem->getGraph());
|
problem->getGraph());
|
||||||
|
Loading…
Reference in New Issue
Block a user