2006-09-04 04:16:09 +00:00
|
|
|
//===-- LLVMTargetMachine.cpp - Implement the LLVMTargetMachine class -----===//
|
|
|
|
//
|
|
|
|
// 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.
|
2006-09-04 04:16:09 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements the LLVMTargetMachine class.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "llvm/Target/TargetMachine.h"
|
|
|
|
#include "llvm/PassManager.h"
|
|
|
|
#include "llvm/Pass.h"
|
2007-03-31 00:24:43 +00:00
|
|
|
#include "llvm/Assembly/PrintModulePass.h"
|
2009-08-13 23:48:47 +00:00
|
|
|
#include "llvm/CodeGen/AsmPrinter.h"
|
2006-09-04 04:16:09 +00:00
|
|
|
#include "llvm/CodeGen/Passes.h"
|
2008-08-17 12:56:54 +00:00
|
|
|
#include "llvm/CodeGen/GCStrategy.h"
|
2009-07-31 18:16:33 +00:00
|
|
|
#include "llvm/CodeGen/MachineFunctionAnalysis.h"
|
2006-09-04 04:16:09 +00:00
|
|
|
#include "llvm/Target/TargetOptions.h"
|
2009-08-22 20:48:53 +00:00
|
|
|
#include "llvm/MC/MCAsmInfo.h"
|
2009-07-15 23:48:37 +00:00
|
|
|
#include "llvm/Target/TargetRegistry.h"
|
2006-09-04 04:16:09 +00:00
|
|
|
#include "llvm/Transforms/Scalar.h"
|
2007-03-31 00:24:43 +00:00
|
|
|
#include "llvm/Support/CommandLine.h"
|
2009-07-14 20:18:05 +00:00
|
|
|
#include "llvm/Support/FormattedStream.h"
|
2006-09-04 04:16:09 +00:00
|
|
|
using namespace llvm;
|
|
|
|
|
2008-09-25 01:14:49 +00:00
|
|
|
namespace llvm {
|
|
|
|
bool EnableFastISel;
|
|
|
|
}
|
|
|
|
|
2007-06-19 05:47:49 +00:00
|
|
|
static cl::opt<bool> PrintLSR("print-lsr-output", cl::Hidden,
|
|
|
|
cl::desc("Print LLVM IR produced by the loop-reduce pass"));
|
|
|
|
static cl::opt<bool> PrintISelInput("print-isel-input", cl::Hidden,
|
|
|
|
cl::desc("Print LLVM IR input to isel pass"));
|
2007-07-20 21:56:13 +00:00
|
|
|
static cl::opt<bool> PrintEmittedAsm("print-emitted-asm", cl::Hidden,
|
|
|
|
cl::desc("Dump emitter generated instructions as assembly"));
|
2008-01-07 01:33:09 +00:00
|
|
|
static cl::opt<bool> PrintGCInfo("print-gc", cl::Hidden,
|
|
|
|
cl::desc("Dump garbage collector data"));
|
2009-09-16 20:25:11 +00:00
|
|
|
static cl::opt<bool> HoistConstants("hoist-constants", cl::Hidden,
|
|
|
|
cl::desc("Hoist constants out of loops"));
|
2009-05-16 00:33:53 +00:00
|
|
|
static cl::opt<bool> VerifyMachineCode("verify-machineinstrs", cl::Hidden,
|
|
|
|
cl::desc("Verify generated machine code"),
|
|
|
|
cl::init(getenv("LLVM_VERIFY_MACHINEINSTRS")!=NULL));
|
2007-06-19 05:47:49 +00:00
|
|
|
|
2009-09-25 21:38:11 +00:00
|
|
|
// This is not enabled by default due to 1) high compile time cost, 2) it's not
|
|
|
|
// beneficial to all targets. The plan is to let targets decide whether this
|
|
|
|
// is enabled.
|
2008-01-14 19:00:06 +00:00
|
|
|
static cl::opt<bool>
|
2009-09-25 21:38:11 +00:00
|
|
|
EnablePostRAScheduler("post-RA-scheduler",
|
|
|
|
cl::desc("Enable scheduling after register allocation"),
|
|
|
|
cl::init(false));
|
2008-01-14 19:00:06 +00:00
|
|
|
|
2008-10-01 20:39:19 +00:00
|
|
|
// Enable or disable FastISel. Both options are needed, because
|
|
|
|
// FastISel is enabled by default with -fast, and we wish to be
|
2009-08-26 15:57:57 +00:00
|
|
|
// able to enable or disable fast-isel independently from -O0.
|
2008-10-07 23:00:56 +00:00
|
|
|
static cl::opt<cl::boolOrDefault>
|
2008-10-01 20:39:19 +00:00
|
|
|
EnableFastISelOption("fast-isel", cl::Hidden,
|
2009-08-26 15:57:57 +00:00
|
|
|
cl::desc("Enable the \"fast\" instruction selector"));
|
2008-09-25 01:14:49 +00:00
|
|
|
|
2009-08-12 07:22:17 +00:00
|
|
|
|
|
|
|
LLVMTargetMachine::LLVMTargetMachine(const Target &T,
|
|
|
|
const std::string &TargetTriple)
|
|
|
|
: TargetMachine(T) {
|
|
|
|
AsmInfo = T.createAsmInfo(TargetTriple);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2007-02-08 01:36:53 +00:00
|
|
|
FileModel::Model
|
2008-03-11 22:29:46 +00:00
|
|
|
LLVMTargetMachine::addPassesToEmitFile(PassManagerBase &PM,
|
2009-07-14 20:18:05 +00:00
|
|
|
formatted_raw_ostream &Out,
|
2007-02-08 01:36:53 +00:00
|
|
|
CodeGenFileType FileType,
|
2009-04-29 23:29:43 +00:00
|
|
|
CodeGenOpt::Level OptLevel) {
|
2008-09-25 00:37:07 +00:00
|
|
|
// Add common CodeGen passes.
|
2009-04-29 00:15:41 +00:00
|
|
|
if (addCommonCodeGenPasses(PM, OptLevel))
|
2007-02-08 01:36:53 +00:00
|
|
|
return FileModel::Error;
|
|
|
|
|
2006-11-07 19:33:46 +00:00
|
|
|
// Fold redundant debug labels.
|
|
|
|
PM.add(createDebugLabelFoldingPass());
|
2008-09-25 00:37:07 +00:00
|
|
|
|
|
|
|
if (PrintMachineCode)
|
2009-08-23 03:13:20 +00:00
|
|
|
PM.add(createMachineFunctionPrinterPass(errs()));
|
2007-02-08 01:36:53 +00:00
|
|
|
|
2009-04-29 00:15:41 +00:00
|
|
|
if (addPreEmitPass(PM, OptLevel) && PrintMachineCode)
|
2009-08-23 03:13:20 +00:00
|
|
|
PM.add(createMachineFunctionPrinterPass(errs()));
|
2007-02-08 01:36:53 +00:00
|
|
|
|
2009-04-29 23:29:43 +00:00
|
|
|
if (OptLevel != CodeGenOpt::None)
|
2009-05-07 05:42:24 +00:00
|
|
|
PM.add(createCodePlacementOptPass());
|
2008-02-28 23:29:57 +00:00
|
|
|
|
2006-09-04 04:16:09 +00:00
|
|
|
switch (FileType) {
|
2007-02-08 01:36:53 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
case TargetMachine::AssemblyFile:
|
2009-04-29 00:15:41 +00:00
|
|
|
if (addAssemblyEmitter(PM, OptLevel, getAsmVerbosityDefault(), Out))
|
2007-02-08 01:36:53 +00:00
|
|
|
return FileModel::Error;
|
|
|
|
return FileModel::AsmFile;
|
|
|
|
case TargetMachine::ObjectFile:
|
|
|
|
if (getMachOWriterInfo())
|
|
|
|
return FileModel::MachOFile;
|
|
|
|
else if (getELFWriterInfo())
|
|
|
|
return FileModel::ElfFile;
|
2006-09-04 04:16:09 +00:00
|
|
|
}
|
2007-02-08 01:36:53 +00:00
|
|
|
|
|
|
|
return FileModel::Error;
|
|
|
|
}
|
2008-09-25 00:37:07 +00:00
|
|
|
|
2009-07-15 23:34:19 +00:00
|
|
|
bool LLVMTargetMachine::addAssemblyEmitter(PassManagerBase &PM,
|
|
|
|
CodeGenOpt::Level OptLevel,
|
|
|
|
bool Verbose,
|
|
|
|
formatted_raw_ostream &Out) {
|
2009-08-13 19:38:51 +00:00
|
|
|
FunctionPass *Printer =
|
2009-08-22 20:48:53 +00:00
|
|
|
getTarget().createAsmPrinter(Out, *this, getMCAsmInfo(), Verbose);
|
2009-07-15 23:34:19 +00:00
|
|
|
if (!Printer)
|
2009-07-15 23:54:01 +00:00
|
|
|
return true;
|
|
|
|
|
2009-07-15 23:34:19 +00:00
|
|
|
PM.add(Printer);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2007-02-08 01:36:53 +00:00
|
|
|
/// addPassesToEmitFileFinish - If the passes to emit the specified file had to
|
|
|
|
/// be split up (e.g., to add an object writer pass), this method can be used to
|
|
|
|
/// finish up adding passes to emit the file, if necessary.
|
2008-03-11 22:29:46 +00:00
|
|
|
bool LLVMTargetMachine::addPassesToEmitFileFinish(PassManagerBase &PM,
|
2007-02-08 01:36:53 +00:00
|
|
|
MachineCodeEmitter *MCE,
|
2009-04-29 23:29:43 +00:00
|
|
|
CodeGenOpt::Level OptLevel) {
|
2007-02-08 01:36:53 +00:00
|
|
|
if (MCE)
|
2009-07-15 22:33:19 +00:00
|
|
|
addSimpleCodeEmitter(PM, OptLevel, *MCE);
|
|
|
|
if (PrintEmittedAsm)
|
|
|
|
addAssemblyEmitter(PM, OptLevel, true, ferrs());
|
2008-09-25 00:37:07 +00:00
|
|
|
|
2008-08-17 18:44:35 +00:00
|
|
|
PM.add(createGCInfoDeleter());
|
2007-02-08 01:36:53 +00:00
|
|
|
|
2006-09-04 04:16:09 +00:00
|
|
|
return false; // success!
|
|
|
|
}
|
|
|
|
|
2009-05-30 20:51:52 +00:00
|
|
|
/// addPassesToEmitFileFinish - If the passes to emit the specified file had to
|
|
|
|
/// be split up (e.g., to add an object writer pass), this method can be used to
|
|
|
|
/// finish up adding passes to emit the file, if necessary.
|
|
|
|
bool LLVMTargetMachine::addPassesToEmitFileFinish(PassManagerBase &PM,
|
|
|
|
JITCodeEmitter *JCE,
|
|
|
|
CodeGenOpt::Level OptLevel) {
|
|
|
|
if (JCE)
|
2009-07-15 22:33:19 +00:00
|
|
|
addSimpleCodeEmitter(PM, OptLevel, *JCE);
|
|
|
|
if (PrintEmittedAsm)
|
|
|
|
addAssemblyEmitter(PM, OptLevel, true, ferrs());
|
2009-05-30 20:51:52 +00:00
|
|
|
|
|
|
|
PM.add(createGCInfoDeleter());
|
|
|
|
|
|
|
|
return false; // success!
|
|
|
|
}
|
|
|
|
|
2009-07-06 05:09:34 +00:00
|
|
|
/// addPassesToEmitFileFinish - If the passes to emit the specified file had to
|
|
|
|
/// be split up (e.g., to add an object writer pass), this method can be used to
|
|
|
|
/// finish up adding passes to emit the file, if necessary.
|
|
|
|
bool LLVMTargetMachine::addPassesToEmitFileFinish(PassManagerBase &PM,
|
|
|
|
ObjectCodeEmitter *OCE,
|
|
|
|
CodeGenOpt::Level OptLevel) {
|
|
|
|
if (OCE)
|
2009-07-15 22:33:19 +00:00
|
|
|
addSimpleCodeEmitter(PM, OptLevel, *OCE);
|
|
|
|
if (PrintEmittedAsm)
|
|
|
|
addAssemblyEmitter(PM, OptLevel, true, ferrs());
|
2009-07-06 05:09:34 +00:00
|
|
|
|
|
|
|
PM.add(createGCInfoDeleter());
|
|
|
|
|
|
|
|
return false; // success!
|
|
|
|
}
|
|
|
|
|
2006-09-04 04:16:09 +00:00
|
|
|
/// addPassesToEmitMachineCode - Add passes to the specified pass manager to
|
|
|
|
/// get machine code emitted. This uses a MachineCodeEmitter object to handle
|
|
|
|
/// actually outputting the machine code and resolving things like the address
|
|
|
|
/// of functions. This method should returns true if machine code emission is
|
|
|
|
/// not supported.
|
|
|
|
///
|
2008-03-11 22:29:46 +00:00
|
|
|
bool LLVMTargetMachine::addPassesToEmitMachineCode(PassManagerBase &PM,
|
2006-09-04 04:16:09 +00:00
|
|
|
MachineCodeEmitter &MCE,
|
2009-04-29 23:29:43 +00:00
|
|
|
CodeGenOpt::Level OptLevel) {
|
2008-09-25 00:37:07 +00:00
|
|
|
// Add common CodeGen passes.
|
2009-04-29 00:15:41 +00:00
|
|
|
if (addCommonCodeGenPasses(PM, OptLevel))
|
2008-09-25 00:37:07 +00:00
|
|
|
return true;
|
|
|
|
|
2009-04-29 00:15:41 +00:00
|
|
|
if (addPreEmitPass(PM, OptLevel) && PrintMachineCode)
|
2009-08-23 03:13:20 +00:00
|
|
|
PM.add(createMachineFunctionPrinterPass(errs()));
|
2008-09-25 00:37:07 +00:00
|
|
|
|
2009-07-15 22:33:19 +00:00
|
|
|
addCodeEmitter(PM, OptLevel, MCE);
|
|
|
|
if (PrintEmittedAsm)
|
|
|
|
addAssemblyEmitter(PM, OptLevel, true, ferrs());
|
2008-09-25 00:37:07 +00:00
|
|
|
|
|
|
|
PM.add(createGCInfoDeleter());
|
|
|
|
|
|
|
|
return false; // success!
|
|
|
|
}
|
|
|
|
|
2009-05-30 20:51:52 +00:00
|
|
|
/// addPassesToEmitMachineCode - Add passes to the specified pass manager to
|
|
|
|
/// get machine code emitted. This uses a MachineCodeEmitter object to handle
|
|
|
|
/// actually outputting the machine code and resolving things like the address
|
|
|
|
/// of functions. This method should returns true if machine code emission is
|
|
|
|
/// not supported.
|
|
|
|
///
|
|
|
|
bool LLVMTargetMachine::addPassesToEmitMachineCode(PassManagerBase &PM,
|
|
|
|
JITCodeEmitter &JCE,
|
|
|
|
CodeGenOpt::Level OptLevel) {
|
|
|
|
// Add common CodeGen passes.
|
|
|
|
if (addCommonCodeGenPasses(PM, OptLevel))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (addPreEmitPass(PM, OptLevel) && PrintMachineCode)
|
2009-08-23 03:13:20 +00:00
|
|
|
PM.add(createMachineFunctionPrinterPass(errs()));
|
2009-05-30 20:51:52 +00:00
|
|
|
|
2009-07-15 22:33:19 +00:00
|
|
|
addCodeEmitter(PM, OptLevel, JCE);
|
|
|
|
if (PrintEmittedAsm)
|
|
|
|
addAssemblyEmitter(PM, OptLevel, true, ferrs());
|
2009-05-30 20:51:52 +00:00
|
|
|
|
|
|
|
PM.add(createGCInfoDeleter());
|
|
|
|
|
|
|
|
return false; // success!
|
|
|
|
}
|
|
|
|
|
2009-05-16 00:33:53 +00:00
|
|
|
static void printAndVerify(PassManagerBase &PM,
|
|
|
|
bool allowDoubleDefs = false) {
|
|
|
|
if (PrintMachineCode)
|
2009-08-23 03:13:20 +00:00
|
|
|
PM.add(createMachineFunctionPrinterPass(errs()));
|
2009-05-16 00:33:53 +00:00
|
|
|
|
|
|
|
if (VerifyMachineCode)
|
|
|
|
PM.add(createMachineVerifierPass(allowDoubleDefs));
|
|
|
|
}
|
|
|
|
|
2009-04-29 23:29:43 +00:00
|
|
|
/// addCommonCodeGenPasses - Add standard LLVM codegen passes used for both
|
|
|
|
/// emitting to assembly files or machine code output.
|
2008-09-25 00:37:07 +00:00
|
|
|
///
|
2009-04-29 00:15:41 +00:00
|
|
|
bool LLVMTargetMachine::addCommonCodeGenPasses(PassManagerBase &PM,
|
2009-04-29 23:29:43 +00:00
|
|
|
CodeGenOpt::Level OptLevel) {
|
2006-09-04 04:16:09 +00:00
|
|
|
// Standard LLVM-Level Passes.
|
2008-09-25 00:37:07 +00:00
|
|
|
|
2006-09-04 04:16:09 +00:00
|
|
|
// Run loop strength reduction before anything else.
|
2009-04-29 23:29:43 +00:00
|
|
|
if (OptLevel != CodeGenOpt::None) {
|
2007-03-31 04:18:03 +00:00
|
|
|
PM.add(createLoopStrengthReducePass(getTargetLowering()));
|
|
|
|
if (PrintLSR)
|
2008-10-22 03:25:22 +00:00
|
|
|
PM.add(createPrintFunctionPass("\n\n*** Code after LSR ***\n", &errs()));
|
2007-03-31 04:18:03 +00:00
|
|
|
}
|
2008-09-25 00:37:07 +00:00
|
|
|
|
2009-05-22 20:36:31 +00:00
|
|
|
// Turn exception handling constructs into something the code generators can
|
|
|
|
// handle.
|
2009-08-22 20:48:53 +00:00
|
|
|
switch (getMCAsmInfo()->getExceptionHandlingType())
|
2009-08-11 00:09:57 +00:00
|
|
|
{
|
|
|
|
case ExceptionHandling::SjLj:
|
2009-08-17 16:41:22 +00:00
|
|
|
// SjLj piggy-backs on dwarf for this bit. The cleanups done apply to both
|
|
|
|
PM.add(createDwarfEHPass(getTargetLowering(), OptLevel==CodeGenOpt::None));
|
|
|
|
PM.add(createSjLjEHPass(getTargetLowering()));
|
|
|
|
break;
|
2009-08-11 00:09:57 +00:00
|
|
|
case ExceptionHandling::Dwarf:
|
2009-05-22 20:36:31 +00:00
|
|
|
PM.add(createDwarfEHPass(getTargetLowering(), OptLevel==CodeGenOpt::None));
|
2009-08-11 00:09:57 +00:00
|
|
|
break;
|
|
|
|
case ExceptionHandling::None:
|
|
|
|
PM.add(createLowerInvokePass(getTargetLowering()));
|
|
|
|
break;
|
|
|
|
}
|
2009-05-22 20:36:31 +00:00
|
|
|
|
|
|
|
PM.add(createGCLoweringPass());
|
2008-09-25 00:37:07 +00:00
|
|
|
|
2006-09-04 04:16:09 +00:00
|
|
|
// Make sure that no unreachable blocks are instruction selected.
|
|
|
|
PM.add(createUnreachableBlockEliminationPass());
|
2007-02-08 01:36:53 +00:00
|
|
|
|
2009-09-16 20:25:11 +00:00
|
|
|
if (OptLevel != CodeGenOpt::None) {
|
|
|
|
if (HoistConstants)
|
|
|
|
PM.add(createCodeGenLICMPass());
|
2007-03-31 04:18:03 +00:00
|
|
|
PM.add(createCodeGenPreparePass(getTargetLowering()));
|
2009-09-16 20:25:11 +00:00
|
|
|
}
|
2007-03-31 04:18:03 +00:00
|
|
|
|
2008-11-13 01:02:14 +00:00
|
|
|
PM.add(createStackProtectorPass(getTargetLowering()));
|
2008-11-04 02:10:20 +00:00
|
|
|
|
2007-03-31 04:18:03 +00:00
|
|
|
if (PrintISelInput)
|
2008-10-21 23:33:38 +00:00
|
|
|
PM.add(createPrintFunctionPass("\n\n"
|
|
|
|
"*** Final LLVM Code input to ISel ***\n",
|
2008-10-22 03:25:22 +00:00
|
|
|
&errs()));
|
2007-03-31 04:18:03 +00:00
|
|
|
|
2008-09-25 00:37:07 +00:00
|
|
|
// Standard Lower-Level Passes.
|
|
|
|
|
2009-07-31 18:16:33 +00:00
|
|
|
// Set up a MachineFunction for the rest of CodeGen to work on.
|
|
|
|
PM.add(new MachineFunctionAnalysis(*this, OptLevel));
|
|
|
|
|
2008-10-01 20:39:19 +00:00
|
|
|
// Enable FastISel with -fast, but allow that to be overridden.
|
2008-10-07 23:00:56 +00:00
|
|
|
if (EnableFastISelOption == cl::BOU_TRUE ||
|
2009-04-29 23:29:43 +00:00
|
|
|
(OptLevel == CodeGenOpt::None && EnableFastISelOption != cl::BOU_FALSE))
|
2008-10-01 20:39:19 +00:00
|
|
|
EnableFastISel = true;
|
|
|
|
|
2006-09-04 04:16:09 +00:00
|
|
|
// Ask the target for an isel.
|
2009-04-29 00:15:41 +00:00
|
|
|
if (addInstSelector(PM, OptLevel))
|
2006-09-04 04:16:09 +00:00
|
|
|
return true;
|
2007-02-08 01:36:53 +00:00
|
|
|
|
2006-09-04 04:16:09 +00:00
|
|
|
// Print the instruction selected machine code...
|
2009-05-16 00:33:53 +00:00
|
|
|
printAndVerify(PM, /* allowDoubleDefs= */ true);
|
Initial commit of the machine code LICM pass. It successfully hoists this:
_foo:
li r2, 0
LBB1_1: ; bb
li r5, 0
stw r5, 0(r3)
addi r2, r2, 1
addi r3, r3, 4
cmplw cr0, r2, r4
bne cr0, LBB1_1 ; bb
LBB1_2: ; return
blr
to:
_foo:
li r2, 0
li r5, 0
LBB1_1: ; bb
stw r5, 0(r3)
addi r2, r2, 1
addi r3, r3, 4
cmplw cr0, r2, r4
bne cr0, LBB1_1 ; bb
LBB1_2: ; return
blr
ZOMG!! :-)
Moar to come...
llvm-svn: 44687
2007-12-07 21:42:31 +00:00
|
|
|
|
2009-04-29 23:29:43 +00:00
|
|
|
if (OptLevel != CodeGenOpt::None) {
|
2008-01-04 08:11:03 +00:00
|
|
|
PM.add(createMachineLICMPass());
|
2008-01-05 06:14:16 +00:00
|
|
|
PM.add(createMachineSinkingPass());
|
2009-07-13 23:44:01 +00:00
|
|
|
printAndVerify(PM, /* allowDoubleDefs= */ true);
|
2009-02-09 08:45:39 +00:00
|
|
|
}
|
Initial commit of the machine code LICM pass. It successfully hoists this:
_foo:
li r2, 0
LBB1_1: ; bb
li r5, 0
stw r5, 0(r3)
addi r2, r2, 1
addi r3, r3, 4
cmplw cr0, r2, r4
bne cr0, LBB1_1 ; bb
LBB1_2: ; return
blr
to:
_foo:
li r2, 0
li r5, 0
LBB1_1: ; bb
stw r5, 0(r3)
addi r2, r2, 1
addi r3, r3, 4
cmplw cr0, r2, r4
bne cr0, LBB1_1 ; bb
LBB1_2: ; return
blr
ZOMG!! :-)
Moar to come...
llvm-svn: 44687
2007-12-07 21:42:31 +00:00
|
|
|
|
2008-04-23 18:26:03 +00:00
|
|
|
// Run pre-ra passes.
|
2009-05-16 00:33:53 +00:00
|
|
|
if (addPreRegAlloc(PM, OptLevel))
|
2009-08-15 13:10:15 +00:00
|
|
|
printAndVerify(PM, /* allowDoubleDefs= */ true);
|
2008-04-23 18:26:03 +00:00
|
|
|
|
2008-06-04 09:18:41 +00:00
|
|
|
// Perform register allocation.
|
2006-09-04 04:16:09 +00:00
|
|
|
PM.add(createRegisterAllocator());
|
2008-06-04 09:18:41 +00:00
|
|
|
|
|
|
|
// Perform stack slot coloring.
|
2009-04-29 23:29:43 +00:00
|
|
|
if (OptLevel != CodeGenOpt::None)
|
2009-08-05 07:26:17 +00:00
|
|
|
// FIXME: Re-enable coloring with register when it's capable of adding
|
|
|
|
// kill markers.
|
|
|
|
PM.add(createStackSlotColoringPass(false));
|
2008-06-04 09:18:41 +00:00
|
|
|
|
2009-05-16 00:33:53 +00:00
|
|
|
printAndVerify(PM); // Print the register-allocated code
|
2008-09-25 00:37:07 +00:00
|
|
|
|
2008-06-04 09:18:41 +00:00
|
|
|
// Run post-ra passes.
|
2009-05-16 00:33:53 +00:00
|
|
|
if (addPostRegAlloc(PM, OptLevel))
|
|
|
|
printAndVerify(PM);
|
2008-09-25 00:37:07 +00:00
|
|
|
|
2007-07-27 07:36:14 +00:00
|
|
|
PM.add(createLowerSubregsPass());
|
2009-05-16 00:33:53 +00:00
|
|
|
printAndVerify(PM);
|
2007-02-08 01:36:53 +00:00
|
|
|
|
2006-09-04 04:16:09 +00:00
|
|
|
// Insert prolog/epilog code. Eliminate abstract frame index references...
|
|
|
|
PM.add(createPrologEpilogCodeInserter());
|
2009-05-16 00:33:53 +00:00
|
|
|
printAndVerify(PM);
|
2008-09-25 00:37:07 +00:00
|
|
|
|
2007-07-13 17:13:54 +00:00
|
|
|
// Second pass scheduler.
|
2009-09-25 21:38:11 +00:00
|
|
|
if (OptLevel != CodeGenOpt::None && EnablePostRAScheduler) {
|
2007-07-13 17:31:29 +00:00
|
|
|
PM.add(createPostRAScheduler());
|
2009-05-16 00:33:53 +00:00
|
|
|
printAndVerify(PM);
|
2008-11-20 19:54:21 +00:00
|
|
|
}
|
|
|
|
|
2008-12-18 01:36:42 +00:00
|
|
|
// Branch folding must be run after regalloc and prolog/epilog insertion.
|
2009-05-16 00:33:53 +00:00
|
|
|
if (OptLevel != CodeGenOpt::None) {
|
2008-12-18 01:36:42 +00:00
|
|
|
PM.add(createBranchFoldingPass(getEnableTailMergeDefault()));
|
2009-05-16 00:33:53 +00:00
|
|
|
printAndVerify(PM);
|
|
|
|
}
|
2008-12-18 01:36:42 +00:00
|
|
|
|
2008-01-07 01:33:09 +00:00
|
|
|
PM.add(createGCMachineCodeAnalysisPass());
|
2009-05-16 00:33:53 +00:00
|
|
|
printAndVerify(PM);
|
2008-09-25 00:37:07 +00:00
|
|
|
|
2008-01-07 01:33:09 +00:00
|
|
|
if (PrintGCInfo)
|
2009-08-23 03:13:20 +00:00
|
|
|
PM.add(createGCInfoPrinter(errs()));
|
2007-02-08 01:36:53 +00:00
|
|
|
|
2008-09-25 00:37:07 +00:00
|
|
|
return false;
|
2006-09-04 04:16:09 +00:00
|
|
|
}
|