Introducing plugable register allocators and instruction schedulers.
[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/MachinePassRegistry.h"
16 #include "llvm/CodeGen/Passes.h"
17 #include "llvm/Support/CommandLine.h"
18 #include <iostream>
19
20 using namespace llvm;
21
22 namespace {
23   cl::opt<const char *, false, RegisterPassParser<RegisterRegAlloc> >
24   RegAlloc("regalloc",
25            cl::init("linearscan"),
26            cl::desc("Register allocator to use: (default = linearscan)")); 
27 }
28
29 FunctionPass *llvm::createRegisterAllocator() {
30   RegisterRegAlloc::FunctionPassCtor Ctor = RegisterRegAlloc::getCache();
31   
32   if (!Ctor) {
33     Ctor = RegisterRegAlloc::FindCtor(RegAlloc);
34     assert(Ctor && "No register allocator found");
35     if (!Ctor) Ctor = RegisterRegAlloc::FirstCtor();
36     RegisterRegAlloc::setCache(Ctor);
37   }
38   
39   assert(Ctor && "No register allocator found");
40   
41   return Ctor();
42 }