1 //===-- Passes.cpp - Target independent code generation passes ------------===//
3 // The LLVM Compiler Infrastructure
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.
8 //===----------------------------------------------------------------------===//
10 // This file defines interfaces to access the target independent code
11 // generation passes provided by the LLVM backend.
13 //===---------------------------------------------------------------------===//
15 #include "llvm/CodeGen/Passes.h"
16 #include "llvm/Pass.h"
17 #include "llvm/Support/CommandLine.h"
22 enum RegAllocName { simple, local, linearscan };
24 static cl::opt<RegAllocName>
27 cl::desc("Register allocator to use: (default = linearscan)"),
30 clEnumVal(simple, " simple register allocator"),
31 clEnumVal(local, " local register allocator"),
32 clEnumVal(linearscan, " linear scan register allocator"),
34 cl::init(linearscan));
38 RegisterRegAlloc *RegisterRegAlloc::List = NULL;
40 /// Find - Finds a register allocator in registration list.
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;
51 void RegisterRegAlloc::print() {
52 for (RegisterRegAlloc *RA = List; RA; RA = RA->Next) {
53 std::cerr << "RegAlloc:" << RA->Name << "\n";
59 static RegisterRegAlloc
60 simpleRegAlloc("simple", " simple register allocator",
61 createSimpleRegisterAllocator);
63 static RegisterRegAlloc
64 localRegAlloc("local", " local register allocator",
65 createLocalRegisterAllocator);
67 static RegisterRegAlloc
68 linearscanRegAlloc("linearscan", "linear scan register allocator",
69 createLinearScanRegisterAllocator);
72 FunctionPass *llvm::createRegisterAllocator() {
73 const char *Names[] = {"simple", "local", "linearscan"};
74 const char *DefltName = "linearscan";
76 RegisterRegAlloc::FunctionPassCtor Ctor =
77 RegisterRegAlloc::Find(Names[RegAlloc]);
78 if (!Ctor) Ctor = RegisterRegAlloc::Find(DefltName);
80 assert(Ctor && "No register allocator found");