2003-12-28 07:59:53 +00:00
|
|
|
//===-- Passes.cpp - Target independent code generation passes ------------===//
|
2005-04-21 22:36:52 +00:00
|
|
|
//
|
2003-10-20 19:43:21 +00:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 20:36:04 +00:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-04-21 22:36:52 +00:00
|
|
|
//
|
2003-10-20 19:43:21 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2003-10-02 16:57:49 +00:00
|
|
|
//
|
|
|
|
// This file defines interfaces to access the target independent code
|
|
|
|
// generation passes provided by the LLVM backend.
|
|
|
|
//
|
|
|
|
//===---------------------------------------------------------------------===//
|
|
|
|
|
2006-08-02 12:30:23 +00:00
|
|
|
#include "llvm/CodeGen/RegAllocRegistry.h"
|
2003-10-02 16:57:49 +00:00
|
|
|
#include "llvm/CodeGen/Passes.h"
|
2006-08-01 14:21:23 +00:00
|
|
|
|
2003-12-28 07:59:53 +00:00
|
|
|
using namespace llvm;
|
2003-11-11 22:41:34 +00:00
|
|
|
|
2006-08-02 12:30:23 +00:00
|
|
|
//===---------------------------------------------------------------------===//
|
|
|
|
///
|
|
|
|
/// RegisterRegAlloc class - Track the registration of register allocators.
|
|
|
|
///
|
|
|
|
//===---------------------------------------------------------------------===//
|
|
|
|
MachinePassRegistry RegisterRegAlloc::Registry;
|
|
|
|
|
2010-05-27 23:57:25 +00:00
|
|
|
static FunctionPass *createDefaultRegisterAllocator() { return 0; }
|
|
|
|
static RegisterRegAlloc
|
|
|
|
defaultRegAlloc("default",
|
|
|
|
"pick register allocator based on -O option",
|
|
|
|
createDefaultRegisterAllocator);
|
2006-08-02 12:30:23 +00:00
|
|
|
|
|
|
|
//===---------------------------------------------------------------------===//
|
|
|
|
///
|
|
|
|
/// RegAlloc command line options.
|
|
|
|
///
|
|
|
|
//===---------------------------------------------------------------------===//
|
2008-05-13 00:00:25 +00:00
|
|
|
static cl::opt<RegisterRegAlloc::FunctionPassCtor, false,
|
|
|
|
RegisterPassParser<RegisterRegAlloc> >
|
|
|
|
RegAlloc("regalloc",
|
2010-05-27 23:57:25 +00:00
|
|
|
cl::init(&createDefaultRegisterAllocator),
|
|
|
|
cl::desc("Register allocator to use"));
|
2006-07-27 20:05:00 +00:00
|
|
|
|
2006-08-02 12:30:23 +00:00
|
|
|
|
|
|
|
//===---------------------------------------------------------------------===//
|
|
|
|
///
|
|
|
|
/// createRegisterAllocator - choose the appropriate register allocator.
|
|
|
|
///
|
|
|
|
//===---------------------------------------------------------------------===//
|
2010-05-27 23:57:25 +00:00
|
|
|
FunctionPass *llvm::createRegisterAllocator(CodeGenOpt::Level OptLevel) {
|
2006-08-01 18:29:48 +00:00
|
|
|
RegisterRegAlloc::FunctionPassCtor Ctor = RegisterRegAlloc::getDefault();
|
2010-05-27 23:57:25 +00:00
|
|
|
|
2006-08-01 14:21:23 +00:00
|
|
|
if (!Ctor) {
|
2006-08-02 12:30:23 +00:00
|
|
|
Ctor = RegAlloc;
|
|
|
|
RegisterRegAlloc::setDefault(RegAlloc);
|
2006-08-01 14:21:23 +00:00
|
|
|
}
|
2010-05-27 23:57:25 +00:00
|
|
|
|
2011-04-19 17:17:58 +00:00
|
|
|
// This forces linking of the greedy register allocator, so -regalloc=greedy
|
|
|
|
// works in clang.
|
|
|
|
if (Ctor == createGreedyRegisterAllocator)
|
|
|
|
return createGreedyRegisterAllocator();
|
|
|
|
|
2010-05-27 23:57:25 +00:00
|
|
|
if (Ctor != createDefaultRegisterAllocator)
|
|
|
|
return Ctor();
|
|
|
|
|
|
|
|
// When the 'default' allocator is requested, pick one based on OptLevel.
|
|
|
|
switch (OptLevel) {
|
|
|
|
case CodeGenOpt::None:
|
2010-06-03 00:39:06 +00:00
|
|
|
return createFastRegisterAllocator();
|
2010-05-27 23:57:25 +00:00
|
|
|
default:
|
|
|
|
return createLinearScanRegisterAllocator();
|
|
|
|
}
|
2006-07-27 20:05:00 +00:00
|
|
|
}
|