1 //===-- Passes.cpp - Target independent code generation passes ------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // 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/RegAllocRegistry.h"
16 #include "llvm/CodeGen/Passes.h"
20 //===---------------------------------------------------------------------===//
22 /// RegisterRegAlloc class - Track the registration of register allocators.
24 //===---------------------------------------------------------------------===//
25 MachinePassRegistry
RegisterRegAlloc::Registry
;
27 static FunctionPass
*createDefaultRegisterAllocator() { return 0; }
28 static RegisterRegAlloc
29 defaultRegAlloc("default",
30 "pick register allocator based on -O option",
31 createDefaultRegisterAllocator
);
33 //===---------------------------------------------------------------------===//
35 /// RegAlloc command line options.
37 //===---------------------------------------------------------------------===//
38 static cl::opt
<RegisterRegAlloc::FunctionPassCtor
, false,
39 RegisterPassParser
<RegisterRegAlloc
> >
41 cl::init(&createDefaultRegisterAllocator
),
42 cl::desc("Register allocator to use"));
45 //===---------------------------------------------------------------------===//
47 /// createRegisterAllocator - choose the appropriate register allocator.
49 //===---------------------------------------------------------------------===//
50 FunctionPass
*llvm::createRegisterAllocator(CodeGenOpt::Level OptLevel
) {
51 RegisterRegAlloc::FunctionPassCtor Ctor
= RegisterRegAlloc::getDefault();
55 RegisterRegAlloc::setDefault(RegAlloc
);
58 // This forces linking of the greedy register allocator, so -regalloc=greedy
60 if (Ctor
== createGreedyRegisterAllocator
)
61 return createGreedyRegisterAllocator();
63 if (Ctor
!= createDefaultRegisterAllocator
)
66 // When the 'default' allocator is requested, pick one based on OptLevel.
68 case CodeGenOpt::None
:
69 return createFastRegisterAllocator();
71 return createLinearScanRegisterAllocator();