2003-12-28 15:59:53 +08:00
|
|
|
//===-- Passes.cpp - Target independent code generation passes ------------===//
|
2005-04-22 06:36:52 +08:00
|
|
|
//
|
2003-10-21 03:43:21 +08:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-30 04:36:04 +08:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-04-22 06:36:52 +08:00
|
|
|
//
|
2003-10-21 03:43:21 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2003-10-03 00:57:49 +08:00
|
|
|
//
|
|
|
|
// This file defines interfaces to access the target independent code
|
|
|
|
// generation passes provided by the LLVM backend.
|
|
|
|
//
|
|
|
|
//===---------------------------------------------------------------------===//
|
|
|
|
|
2006-08-02 20:30:23 +08:00
|
|
|
#include "llvm/CodeGen/RegAllocRegistry.h"
|
2003-10-03 00:57:49 +08:00
|
|
|
#include "llvm/CodeGen/Passes.h"
|
2012-02-04 10:56:45 +08:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2006-08-01 22:21:23 +08:00
|
|
|
|
2003-12-28 15:59:53 +08:00
|
|
|
using namespace llvm;
|
2003-11-12 06:41:34 +08:00
|
|
|
|
2012-02-04 10:56:45 +08:00
|
|
|
//===---------------------------------------------------------------------===//
|
|
|
|
/// TargetPassConfig
|
|
|
|
//===---------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
INITIALIZE_PASS(TargetPassConfig, "targetpassconfig",
|
|
|
|
"Target Pass Configuration", false, false)
|
|
|
|
char TargetPassConfig::ID = 0;
|
|
|
|
|
|
|
|
// Out of line virtual method.
|
|
|
|
TargetPassConfig::~TargetPassConfig() {}
|
|
|
|
|
|
|
|
TargetPassConfig::TargetPassConfig(TargetMachine *tm, PassManagerBase &pm,
|
|
|
|
bool DisableVerifyFlag)
|
|
|
|
: ImmutablePass(ID), TM(tm), PM(pm), DisableVerify(DisableVerifyFlag) {
|
|
|
|
// Register all target independent codegen passes to activate their PassIDs,
|
|
|
|
// including this pass itself.
|
|
|
|
initializeCodeGen(*PassRegistry::getPassRegistry());
|
|
|
|
}
|
|
|
|
|
|
|
|
/// createPassConfig - Create a pass configuration object to be used by
|
|
|
|
/// addPassToEmitX methods for generating a pipeline of CodeGen passes.
|
|
|
|
///
|
|
|
|
/// Targets may override this to extend TargetPassConfig.
|
|
|
|
TargetPassConfig *LLVMTargetMachine::createPassConfig(PassManagerBase &PM,
|
|
|
|
bool DisableVerify) {
|
|
|
|
return new TargetPassConfig(this, PM, DisableVerify);
|
|
|
|
}
|
|
|
|
|
|
|
|
TargetPassConfig::TargetPassConfig()
|
|
|
|
: ImmutablePass(ID), PM(*(PassManagerBase*)0) {
|
|
|
|
llvm_unreachable("TargetPassConfig should not be constructed on-the-fly");
|
|
|
|
}
|
|
|
|
|
2006-08-02 20:30:23 +08:00
|
|
|
//===---------------------------------------------------------------------===//
|
|
|
|
///
|
|
|
|
/// RegisterRegAlloc class - Track the registration of register allocators.
|
|
|
|
///
|
|
|
|
//===---------------------------------------------------------------------===//
|
|
|
|
MachinePassRegistry RegisterRegAlloc::Registry;
|
|
|
|
|
2010-05-28 07:57:25 +08:00
|
|
|
static FunctionPass *createDefaultRegisterAllocator() { return 0; }
|
|
|
|
static RegisterRegAlloc
|
|
|
|
defaultRegAlloc("default",
|
|
|
|
"pick register allocator based on -O option",
|
|
|
|
createDefaultRegisterAllocator);
|
2006-08-02 20:30:23 +08:00
|
|
|
|
|
|
|
//===---------------------------------------------------------------------===//
|
|
|
|
///
|
|
|
|
/// RegAlloc command line options.
|
|
|
|
///
|
|
|
|
//===---------------------------------------------------------------------===//
|
2008-05-13 08:00:25 +08:00
|
|
|
static cl::opt<RegisterRegAlloc::FunctionPassCtor, false,
|
|
|
|
RegisterPassParser<RegisterRegAlloc> >
|
|
|
|
RegAlloc("regalloc",
|
2010-05-28 07:57:25 +08:00
|
|
|
cl::init(&createDefaultRegisterAllocator),
|
|
|
|
cl::desc("Register allocator to use"));
|
2006-07-28 04:05:00 +08:00
|
|
|
|
2006-08-02 20:30:23 +08:00
|
|
|
|
|
|
|
//===---------------------------------------------------------------------===//
|
|
|
|
///
|
|
|
|
/// createRegisterAllocator - choose the appropriate register allocator.
|
|
|
|
///
|
|
|
|
//===---------------------------------------------------------------------===//
|
2010-05-28 07:57:25 +08:00
|
|
|
FunctionPass *llvm::createRegisterAllocator(CodeGenOpt::Level OptLevel) {
|
2006-08-02 02:29:48 +08:00
|
|
|
RegisterRegAlloc::FunctionPassCtor Ctor = RegisterRegAlloc::getDefault();
|
2010-05-28 07:57:25 +08:00
|
|
|
|
2006-08-01 22:21:23 +08:00
|
|
|
if (!Ctor) {
|
2006-08-02 20:30:23 +08:00
|
|
|
Ctor = RegAlloc;
|
|
|
|
RegisterRegAlloc::setDefault(RegAlloc);
|
2006-08-01 22:21:23 +08:00
|
|
|
}
|
2010-05-28 07:57:25 +08: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 08:39:06 +08:00
|
|
|
return createFastRegisterAllocator();
|
2010-05-28 07:57:25 +08:00
|
|
|
default:
|
2011-04-30 09:37:54 +08:00
|
|
|
return createGreedyRegisterAllocator();
|
2010-05-28 07:57:25 +08:00
|
|
|
}
|
2006-07-28 04:05:00 +08:00
|
|
|
}
|