• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===-- Passes.cpp - Target independent code generation passes ------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // 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/RegAllocRegistry.h"
16 #include "llvm/CodeGen/Passes.h"
17 
18 using namespace llvm;
19 
20 //===---------------------------------------------------------------------===//
21 ///
22 /// RegisterRegAlloc class - Track the registration of register allocators.
23 ///
24 //===---------------------------------------------------------------------===//
25 MachinePassRegistry RegisterRegAlloc::Registry;
26 
createDefaultRegisterAllocator()27 static FunctionPass *createDefaultRegisterAllocator() { return 0; }
28 static RegisterRegAlloc
29 defaultRegAlloc("default",
30                 "pick register allocator based on -O option",
31                 createDefaultRegisterAllocator);
32 
33 //===---------------------------------------------------------------------===//
34 ///
35 /// RegAlloc command line options.
36 ///
37 //===---------------------------------------------------------------------===//
38 static cl::opt<RegisterRegAlloc::FunctionPassCtor, false,
39                RegisterPassParser<RegisterRegAlloc> >
40 RegAlloc("regalloc",
41          cl::init(&createDefaultRegisterAllocator),
42          cl::desc("Register allocator to use"));
43 
44 
45 //===---------------------------------------------------------------------===//
46 ///
47 /// createRegisterAllocator - choose the appropriate register allocator.
48 ///
49 //===---------------------------------------------------------------------===//
createRegisterAllocator(CodeGenOpt::Level OptLevel)50 FunctionPass *llvm::createRegisterAllocator(CodeGenOpt::Level OptLevel) {
51   RegisterRegAlloc::FunctionPassCtor Ctor = RegisterRegAlloc::getDefault();
52 
53   if (!Ctor) {
54     Ctor = RegAlloc;
55     RegisterRegAlloc::setDefault(RegAlloc);
56   }
57 
58   // This forces linking of the linear scan register allocator,
59   // so -regalloc=linearscan still works in clang.
60   if (Ctor == createLinearScanRegisterAllocator)
61     return createLinearScanRegisterAllocator();
62 
63   if (Ctor != createDefaultRegisterAllocator)
64     return Ctor();
65 
66   // When the 'default' allocator is requested, pick one based on OptLevel.
67   switch (OptLevel) {
68   case CodeGenOpt::None:
69     return createFastRegisterAllocator();
70   default:
71     return createGreedyRegisterAllocator();
72   }
73 }
74