Working toward registration of register allocators.
[oota-llvm.git] / lib / CodeGen / Passes.cpp
1 //===-- Passes.cpp - Target independent code generation passes ------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines interfaces to access the target independent code
11 // generation passes provided by the LLVM backend.
12 //
13 //===---------------------------------------------------------------------===//
14
15 #include "llvm/CodeGen/Passes.h"
16 #include "llvm/Pass.h"
17 #include "llvm/Support/CommandLine.h"
18 #include <iostream>
19 using namespace llvm;
20
21 namespace {
22   enum RegAllocName { simple, local, linearscan };
23
24   static cl::opt<RegAllocName>
25   RegAlloc(
26     "regalloc",
27     cl::desc("Register allocator to use: (default = linearscan)"),
28     cl::Prefix,
29     cl::values(
30        clEnumVal(simple,        "  simple register allocator"),
31        clEnumVal(local,         "  local register allocator"),
32        clEnumVal(linearscan,    "  linear scan register allocator"),
33        clEnumValEnd),
34     cl::init(linearscan));
35 }
36
37
38 RegisterRegAlloc *RegisterRegAlloc::List = NULL;
39
40 /// Find - Finds a register allocator in registration list.
41 ///
42 RegisterRegAlloc::FunctionPassCtor RegisterRegAlloc::Find(const char *N) {
43   for (RegisterRegAlloc *RA = List; RA; RA = RA->Next) {
44     if (strcmp(N, RA->Name) == 0) return RA->Ctor;
45   }
46   return NULL;
47 }
48
49
50 #ifndef NDEBUG  
51 void RegisterRegAlloc::print() {
52   for (RegisterRegAlloc *RA = List; RA; RA = RA->Next) {
53     std::cerr << "RegAlloc:" << RA->Name << "\n";
54   }
55 }
56 #endif
57
58
59 static RegisterRegAlloc
60   simpleRegAlloc("simple", "  simple register allocator",
61                  createSimpleRegisterAllocator);
62
63 static RegisterRegAlloc
64   localRegAlloc("local", "  local register allocator",
65                 createLocalRegisterAllocator);
66
67 static RegisterRegAlloc
68   linearscanRegAlloc("linearscan", "linear scan register allocator",
69                      createLinearScanRegisterAllocator);
70
71
72 FunctionPass *llvm::createRegisterAllocator() {
73   const char *Names[] = {"simple", "local", "linearscan"};
74   const char *DefltName = "linearscan";
75   
76   RegisterRegAlloc::FunctionPassCtor Ctor =
77                     RegisterRegAlloc::Find(Names[RegAlloc]);
78   if (!Ctor) Ctor = RegisterRegAlloc::Find(DefltName);
79
80   assert(Ctor && "No register allocator found");
81   
82   return Ctor();
83 }
84
85