Permalink
Browse files

[CodeGen] Prepare to build Dimacs Graph

  • Loading branch information...
xiangzhai committed Dec 16, 2017
1 parent b90f387 commit 4ae37b1d6efeef0f76259f88103a4b9dbb68ed3c
@@ -26,6 +26,7 @@ namespace GCol {
class Graph {
public:
Graph() {};
Graph(int N) { resize(N); }
~Graph() { resize(0); }
@@ -33,6 +33,7 @@ namespace {
(void) llvm::createFastRegisterAllocator();
(void) llvm::createBasicRegisterAllocator();
(void) llvm::createGraphColoringRegisterAllocator();
(void) llvm::createGreedyRegisterAllocator();
(void) llvm::createDefaultPBQPRegisterAllocator();
@@ -134,6 +134,9 @@ namespace llvm {
/// the definition's live range.
extern char &LiveRangeShrinkID;
/// Graph Coloring register allocator.
extern char &RAGraphColoringID;
/// Greedy register allocator.
extern char &RAGreedyID;
@@ -164,6 +167,10 @@ namespace llvm {
///
FunctionPass *createBasicRegisterAllocator();
/// Graph Coloring register allocation pass - This pass implements a global
/// register allocator.
FunctionPass *createGraphColoringRegisterAllocator();
/// Greedy register allocation pass - This pass implements a global register
/// allocator for optimized builds.
///
@@ -7,8 +7,13 @@
//
//===----------------------------------------------------------------------===//
//
// This file defines the RAGraphColoring function pass, which provides a minimal
// implementation of the graph coloring register allocator.
// This file defines the RAGraphColoring function pass, which implements the
// Hybrid Evolutionary Algorithm of Galinier and Hao. The local search routines
// are based on the tabu search algorithm written by Ivo Bloechliger
// http://rose.epfl.ch/~bloechli/coloring/ The solutionByHEA code was written
// by R. Lewis http://www.rhydLewis.eu See: Lewis, R. (2015) A Guide to Graph
// Colouring: Algorithms and Applications. Berlin, Springer.
// ISBN: 978-3-319-25728-0. http://www.springer.com/us/book/9783319257280
//
//===----------------------------------------------------------------------===//
@@ -86,6 +91,8 @@ class RAGraphColoring : public MachineFunctionPass,
bool LRE_CanEraseVirtReg(unsigned) override;
void LRE_WillShrinkVirtReg(unsigned) override;
void solutionByHEA();
public:
RAGraphColoring();
@@ -311,8 +318,44 @@ unsigned RAGraphColoring::selectOrSplit(LiveInterval &VirtReg,
return 0;
}
void RAGraphColoring::solutionByHEA() {
GCol::Graph G;
int PopSize = 10, MaxIterations = 16, Verbose = 0, RandomSeed = 1,
ConstructiveAlg = 1, TargetCols = 2, XOverType = 1;
bool SolFound = false, DoKempeMutation = false, MeasuringDiversity = false;
unsigned long long MaxChecks = 100000000;
std::vector<int> Parents;
// This variable keeps count of the number of times information about the
// instance is looked up.
unsigned long long NumConfChecks = 0;
// TODO: Build Dimacs Graph
// Set the number of parents in each crossover and decide if the Kempe
// mutation is going to be used.
if (XOverType == 3)
Parents.resize(4);
else if (XOverType == 2)
DoKempeMutation = true;
else
Parents.resize(2);
// Set tabucol limit.
MaxIterations = MaxIterations * G.Nodes;
if (TargetCols < 2 || TargetCols > G.Nodes)
TargetCols = 2;
// Do a check to see if we have the empty graph. If so, return immediately.
if (G.Edges <= 0) {
if (Verbose) {
errs() << "Graph has no edges. Optimal solution is obviously using one colour.";
}
return;
}
}
bool RAGraphColoring::runOnMachineFunction(MachineFunction &mf) {
DEBUG(dbgs() << "********** BASIC REGISTER ALLOCATION **********\n"
DEBUG(dbgs() << "********** GRAPHCOLORING REGISTER ALLOCATION **********\n"
<< "********** Function: " << mf.getName() << '\n');
MF = &mf;
@@ -324,6 +367,8 @@ bool RAGraphColoring::runOnMachineFunction(MachineFunction &mf) {
SpillerInstance.reset(createInlineSpiller(*this, *MF, *VRM));
solutionByHEA();
allocatePhysRegs();
postOptimization();

0 comments on commit 4ae37b1

Please sign in to comment.