blob: 64e28fb764f593ab82dd4825121a4fd29a01fd51 [file] [log] [blame]
Chris Lattner47877052006-09-04 04:16:09 +00001//===-- LLVMTargetMachine.cpp - Implement the LLVMTargetMachine class -----===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Chris Lattner47877052006-09-04 04:16:09 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the LLVMTargetMachine class.
11//
12//===----------------------------------------------------------------------===//
13
14#include "llvm/Target/TargetMachine.h"
15#include "llvm/PassManager.h"
16#include "llvm/Pass.h"
Chris Lattner31442f92007-03-31 00:24:43 +000017#include "llvm/Assembly/PrintModulePass.h"
Daniel Dunbar78945782009-08-13 23:48:47 +000018#include "llvm/CodeGen/AsmPrinter.h"
Chris Lattner47877052006-09-04 04:16:09 +000019#include "llvm/CodeGen/Passes.h"
Gordon Henriksen5a29c9e2008-08-17 12:56:54 +000020#include "llvm/CodeGen/GCStrategy.h"
Dan Gohmanad2afc22009-07-31 18:16:33 +000021#include "llvm/CodeGen/MachineFunctionAnalysis.h"
Chris Lattner47877052006-09-04 04:16:09 +000022#include "llvm/Target/TargetOptions.h"
Chris Lattneraf76e592009-08-22 20:48:53 +000023#include "llvm/MC/MCAsmInfo.h"
Daniel Dunbar6d823cd2009-07-15 23:48:37 +000024#include "llvm/Target/TargetRegistry.h"
Chris Lattner47877052006-09-04 04:16:09 +000025#include "llvm/Transforms/Scalar.h"
Chris Lattner31442f92007-03-31 00:24:43 +000026#include "llvm/Support/CommandLine.h"
David Greene71847812009-07-14 20:18:05 +000027#include "llvm/Support/FormattedStream.h"
Chris Lattner47877052006-09-04 04:16:09 +000028using namespace llvm;
29
Dan Gohman2c4bf112008-09-25 01:14:49 +000030namespace llvm {
31 bool EnableFastISel;
32}
33
Chris Lattner85ef2542007-06-19 05:47:49 +000034static cl::opt<bool> PrintLSR("print-lsr-output", cl::Hidden,
35 cl::desc("Print LLVM IR produced by the loop-reduce pass"));
36static cl::opt<bool> PrintISelInput("print-isel-input", cl::Hidden,
37 cl::desc("Print LLVM IR input to isel pass"));
Evan Cheng8bd60352007-07-20 21:56:13 +000038static cl::opt<bool> PrintEmittedAsm("print-emitted-asm", cl::Hidden,
39 cl::desc("Dump emitter generated instructions as assembly"));
Gordon Henriksen93f96d02008-01-07 01:33:09 +000040static cl::opt<bool> PrintGCInfo("print-gc", cl::Hidden,
41 cl::desc("Dump garbage collector data"));
Dan Gohman6f65d792009-09-16 20:25:11 +000042static cl::opt<bool> HoistConstants("hoist-constants", cl::Hidden,
43 cl::desc("Hoist constants out of loops"));
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +000044static cl::opt<bool> VerifyMachineCode("verify-machineinstrs", cl::Hidden,
45 cl::desc("Verify generated machine code"),
46 cl::init(getenv("LLVM_VERIFY_MACHINEINSTRS")!=NULL));
Chris Lattner85ef2542007-06-19 05:47:49 +000047
Evan Cheng48301102009-09-25 21:38:11 +000048// This is not enabled by default due to 1) high compile time cost, 2) it's not
49// beneficial to all targets. The plan is to let targets decide whether this
50// is enabled.
Chris Lattner459525d2008-01-14 19:00:06 +000051static cl::opt<bool>
Evan Cheng48301102009-09-25 21:38:11 +000052EnablePostRAScheduler("post-RA-scheduler",
53 cl::desc("Enable scheduling after register allocation"),
54 cl::init(false));
Chris Lattner459525d2008-01-14 19:00:06 +000055
Dan Gohmandc756852008-10-01 20:39:19 +000056// Enable or disable FastISel. Both options are needed, because
57// FastISel is enabled by default with -fast, and we wish to be
Dan Gohmane29fea42009-08-26 15:57:57 +000058// able to enable or disable fast-isel independently from -O0.
Dan Gohmaneb0d6ab2008-10-07 23:00:56 +000059static cl::opt<cl::boolOrDefault>
Dan Gohmandc756852008-10-01 20:39:19 +000060EnableFastISelOption("fast-isel", cl::Hidden,
Dan Gohmane29fea42009-08-26 15:57:57 +000061 cl::desc("Enable the \"fast\" instruction selector"));
Dan Gohman2c4bf112008-09-25 01:14:49 +000062
Chris Lattnera7ac47c2009-08-12 07:22:17 +000063
64LLVMTargetMachine::LLVMTargetMachine(const Target &T,
65 const std::string &TargetTriple)
66 : TargetMachine(T) {
67 AsmInfo = T.createAsmInfo(TargetTriple);
68}
69
70
71
Bill Wendling04523ea2007-02-08 01:36:53 +000072FileModel::Model
Dan Gohmanbfae8312008-03-11 22:29:46 +000073LLVMTargetMachine::addPassesToEmitFile(PassManagerBase &PM,
David Greene71847812009-07-14 20:18:05 +000074 formatted_raw_ostream &Out,
Bill Wendling04523ea2007-02-08 01:36:53 +000075 CodeGenFileType FileType,
Bill Wendling98a366d2009-04-29 23:29:43 +000076 CodeGenOpt::Level OptLevel) {
Dan Gohman02dae4b2008-09-25 00:37:07 +000077 // Add common CodeGen passes.
Bill Wendlingbe8cc2a2009-04-29 00:15:41 +000078 if (addCommonCodeGenPasses(PM, OptLevel))
Bill Wendling04523ea2007-02-08 01:36:53 +000079 return FileModel::Error;
80
Jim Laskey9d4209f2006-11-07 19:33:46 +000081 // Fold redundant debug labels.
82 PM.add(createDebugLabelFoldingPass());
Dan Gohman02dae4b2008-09-25 00:37:07 +000083
84 if (PrintMachineCode)
Chris Lattnercf143a42009-08-23 03:13:20 +000085 PM.add(createMachineFunctionPrinterPass(errs()));
Bill Wendling04523ea2007-02-08 01:36:53 +000086
Bill Wendlingbe8cc2a2009-04-29 00:15:41 +000087 if (addPreEmitPass(PM, OptLevel) && PrintMachineCode)
Chris Lattnercf143a42009-08-23 03:13:20 +000088 PM.add(createMachineFunctionPrinterPass(errs()));
Bill Wendling04523ea2007-02-08 01:36:53 +000089
Bill Wendling98a366d2009-04-29 23:29:43 +000090 if (OptLevel != CodeGenOpt::None)
Evan Chengbbf1db72009-05-07 05:42:24 +000091 PM.add(createCodePlacementOptPass());
Evan Chengd703ed62008-02-28 23:29:57 +000092
Chris Lattner47877052006-09-04 04:16:09 +000093 switch (FileType) {
Bill Wendling04523ea2007-02-08 01:36:53 +000094 default:
95 break;
96 case TargetMachine::AssemblyFile:
Bill Wendlingbe8cc2a2009-04-29 00:15:41 +000097 if (addAssemblyEmitter(PM, OptLevel, getAsmVerbosityDefault(), Out))
Bill Wendling04523ea2007-02-08 01:36:53 +000098 return FileModel::Error;
99 return FileModel::AsmFile;
100 case TargetMachine::ObjectFile:
101 if (getMachOWriterInfo())
102 return FileModel::MachOFile;
103 else if (getELFWriterInfo())
104 return FileModel::ElfFile;
Chris Lattner47877052006-09-04 04:16:09 +0000105 }
Bill Wendling04523ea2007-02-08 01:36:53 +0000106
107 return FileModel::Error;
108}
Dan Gohman02dae4b2008-09-25 00:37:07 +0000109
Daniel Dunbar5d77cad2009-07-15 23:34:19 +0000110bool LLVMTargetMachine::addAssemblyEmitter(PassManagerBase &PM,
111 CodeGenOpt::Level OptLevel,
112 bool Verbose,
113 formatted_raw_ostream &Out) {
Daniel Dunbar67d894e2009-08-13 19:38:51 +0000114 FunctionPass *Printer =
Chris Lattneraf76e592009-08-22 20:48:53 +0000115 getTarget().createAsmPrinter(Out, *this, getMCAsmInfo(), Verbose);
Daniel Dunbar5d77cad2009-07-15 23:34:19 +0000116 if (!Printer)
Daniel Dunbar36129db2009-07-15 23:54:01 +0000117 return true;
118
Daniel Dunbar5d77cad2009-07-15 23:34:19 +0000119 PM.add(Printer);
120 return false;
121}
122
Bill Wendling04523ea2007-02-08 01:36:53 +0000123/// addPassesToEmitFileFinish - If the passes to emit the specified file had to
124/// be split up (e.g., to add an object writer pass), this method can be used to
125/// finish up adding passes to emit the file, if necessary.
Dan Gohmanbfae8312008-03-11 22:29:46 +0000126bool LLVMTargetMachine::addPassesToEmitFileFinish(PassManagerBase &PM,
Bill Wendling04523ea2007-02-08 01:36:53 +0000127 MachineCodeEmitter *MCE,
Bill Wendling98a366d2009-04-29 23:29:43 +0000128 CodeGenOpt::Level OptLevel) {
Bill Wendling04523ea2007-02-08 01:36:53 +0000129 if (MCE)
Daniel Dunbarcfe9a602009-07-15 22:33:19 +0000130 addSimpleCodeEmitter(PM, OptLevel, *MCE);
131 if (PrintEmittedAsm)
132 addAssemblyEmitter(PM, OptLevel, true, ferrs());
Dan Gohman02dae4b2008-09-25 00:37:07 +0000133
Gordon Henriksen5eca0752008-08-17 18:44:35 +0000134 PM.add(createGCInfoDeleter());
Bill Wendling04523ea2007-02-08 01:36:53 +0000135
Chris Lattner47877052006-09-04 04:16:09 +0000136 return false; // success!
137}
138
Bruno Cardoso Lopesa3f99f92009-05-30 20:51:52 +0000139/// addPassesToEmitFileFinish - If the passes to emit the specified file had to
140/// be split up (e.g., to add an object writer pass), this method can be used to
141/// finish up adding passes to emit the file, if necessary.
142bool LLVMTargetMachine::addPassesToEmitFileFinish(PassManagerBase &PM,
143 JITCodeEmitter *JCE,
144 CodeGenOpt::Level OptLevel) {
145 if (JCE)
Daniel Dunbarcfe9a602009-07-15 22:33:19 +0000146 addSimpleCodeEmitter(PM, OptLevel, *JCE);
147 if (PrintEmittedAsm)
148 addAssemblyEmitter(PM, OptLevel, true, ferrs());
Bruno Cardoso Lopesa3f99f92009-05-30 20:51:52 +0000149
150 PM.add(createGCInfoDeleter());
151
Bruno Cardoso Lopesa3f99f92009-05-30 20:51:52 +0000152 return false; // success!
153}
154
Bruno Cardoso Lopesac57e6e2009-07-06 05:09:34 +0000155/// addPassesToEmitFileFinish - If the passes to emit the specified file had to
156/// be split up (e.g., to add an object writer pass), this method can be used to
157/// finish up adding passes to emit the file, if necessary.
158bool LLVMTargetMachine::addPassesToEmitFileFinish(PassManagerBase &PM,
159 ObjectCodeEmitter *OCE,
160 CodeGenOpt::Level OptLevel) {
161 if (OCE)
Daniel Dunbarcfe9a602009-07-15 22:33:19 +0000162 addSimpleCodeEmitter(PM, OptLevel, *OCE);
163 if (PrintEmittedAsm)
164 addAssemblyEmitter(PM, OptLevel, true, ferrs());
Bruno Cardoso Lopesac57e6e2009-07-06 05:09:34 +0000165
166 PM.add(createGCInfoDeleter());
167
Bruno Cardoso Lopesac57e6e2009-07-06 05:09:34 +0000168 return false; // success!
169}
170
Chris Lattner47877052006-09-04 04:16:09 +0000171/// addPassesToEmitMachineCode - Add passes to the specified pass manager to
172/// get machine code emitted. This uses a MachineCodeEmitter object to handle
173/// actually outputting the machine code and resolving things like the address
174/// of functions. This method should returns true if machine code emission is
175/// not supported.
176///
Dan Gohmanbfae8312008-03-11 22:29:46 +0000177bool LLVMTargetMachine::addPassesToEmitMachineCode(PassManagerBase &PM,
Chris Lattner47877052006-09-04 04:16:09 +0000178 MachineCodeEmitter &MCE,
Bill Wendling98a366d2009-04-29 23:29:43 +0000179 CodeGenOpt::Level OptLevel) {
Dan Gohman02dae4b2008-09-25 00:37:07 +0000180 // Add common CodeGen passes.
Bill Wendlingbe8cc2a2009-04-29 00:15:41 +0000181 if (addCommonCodeGenPasses(PM, OptLevel))
Dan Gohman02dae4b2008-09-25 00:37:07 +0000182 return true;
183
Bill Wendlingbe8cc2a2009-04-29 00:15:41 +0000184 if (addPreEmitPass(PM, OptLevel) && PrintMachineCode)
Chris Lattnercf143a42009-08-23 03:13:20 +0000185 PM.add(createMachineFunctionPrinterPass(errs()));
Dan Gohman02dae4b2008-09-25 00:37:07 +0000186
Daniel Dunbarcfe9a602009-07-15 22:33:19 +0000187 addCodeEmitter(PM, OptLevel, MCE);
188 if (PrintEmittedAsm)
189 addAssemblyEmitter(PM, OptLevel, true, ferrs());
Dan Gohman02dae4b2008-09-25 00:37:07 +0000190
191 PM.add(createGCInfoDeleter());
192
Dan Gohman02dae4b2008-09-25 00:37:07 +0000193 return false; // success!
194}
195
Bruno Cardoso Lopesa3f99f92009-05-30 20:51:52 +0000196/// addPassesToEmitMachineCode - Add passes to the specified pass manager to
197/// get machine code emitted. This uses a MachineCodeEmitter object to handle
198/// actually outputting the machine code and resolving things like the address
199/// of functions. This method should returns true if machine code emission is
200/// not supported.
201///
202bool LLVMTargetMachine::addPassesToEmitMachineCode(PassManagerBase &PM,
203 JITCodeEmitter &JCE,
204 CodeGenOpt::Level OptLevel) {
205 // Add common CodeGen passes.
206 if (addCommonCodeGenPasses(PM, OptLevel))
207 return true;
208
209 if (addPreEmitPass(PM, OptLevel) && PrintMachineCode)
Chris Lattnercf143a42009-08-23 03:13:20 +0000210 PM.add(createMachineFunctionPrinterPass(errs()));
Bruno Cardoso Lopesa3f99f92009-05-30 20:51:52 +0000211
Daniel Dunbarcfe9a602009-07-15 22:33:19 +0000212 addCodeEmitter(PM, OptLevel, JCE);
213 if (PrintEmittedAsm)
214 addAssemblyEmitter(PM, OptLevel, true, ferrs());
Bruno Cardoso Lopesa3f99f92009-05-30 20:51:52 +0000215
216 PM.add(createGCInfoDeleter());
217
Bruno Cardoso Lopesa3f99f92009-05-30 20:51:52 +0000218 return false; // success!
219}
220
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000221static void printAndVerify(PassManagerBase &PM,
222 bool allowDoubleDefs = false) {
223 if (PrintMachineCode)
Chris Lattnercf143a42009-08-23 03:13:20 +0000224 PM.add(createMachineFunctionPrinterPass(errs()));
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000225
226 if (VerifyMachineCode)
227 PM.add(createMachineVerifierPass(allowDoubleDefs));
228}
229
Bill Wendling98a366d2009-04-29 23:29:43 +0000230/// addCommonCodeGenPasses - Add standard LLVM codegen passes used for both
231/// emitting to assembly files or machine code output.
Dan Gohman02dae4b2008-09-25 00:37:07 +0000232///
Bill Wendlingbe8cc2a2009-04-29 00:15:41 +0000233bool LLVMTargetMachine::addCommonCodeGenPasses(PassManagerBase &PM,
Bill Wendling98a366d2009-04-29 23:29:43 +0000234 CodeGenOpt::Level OptLevel) {
Chris Lattner47877052006-09-04 04:16:09 +0000235 // Standard LLVM-Level Passes.
Dan Gohman02dae4b2008-09-25 00:37:07 +0000236
Chris Lattner47877052006-09-04 04:16:09 +0000237 // Run loop strength reduction before anything else.
Bill Wendling98a366d2009-04-29 23:29:43 +0000238 if (OptLevel != CodeGenOpt::None) {
Chris Lattnerc8d288f2007-03-31 04:18:03 +0000239 PM.add(createLoopStrengthReducePass(getTargetLowering()));
240 if (PrintLSR)
Daniel Dunbar3b0da262008-10-22 03:25:22 +0000241 PM.add(createPrintFunctionPass("\n\n*** Code after LSR ***\n", &errs()));
Chris Lattnerc8d288f2007-03-31 04:18:03 +0000242 }
Dan Gohman02dae4b2008-09-25 00:37:07 +0000243
Duncan Sandsb0f1e172009-05-22 20:36:31 +0000244 // Turn exception handling constructs into something the code generators can
245 // handle.
Chris Lattneraf76e592009-08-22 20:48:53 +0000246 switch (getMCAsmInfo()->getExceptionHandlingType())
Jim Grosbach1b747ad2009-08-11 00:09:57 +0000247 {
Jim Grosbach1b747ad2009-08-11 00:09:57 +0000248 case ExceptionHandling::SjLj:
Jim Grosbach8b818d72009-08-17 16:41:22 +0000249 // SjLj piggy-backs on dwarf for this bit. The cleanups done apply to both
250 PM.add(createDwarfEHPass(getTargetLowering(), OptLevel==CodeGenOpt::None));
251 PM.add(createSjLjEHPass(getTargetLowering()));
252 break;
Jim Grosbach1b747ad2009-08-11 00:09:57 +0000253 case ExceptionHandling::Dwarf:
Duncan Sandsb0f1e172009-05-22 20:36:31 +0000254 PM.add(createDwarfEHPass(getTargetLowering(), OptLevel==CodeGenOpt::None));
Jim Grosbach1b747ad2009-08-11 00:09:57 +0000255 break;
256 case ExceptionHandling::None:
257 PM.add(createLowerInvokePass(getTargetLowering()));
258 break;
259 }
Duncan Sandsb0f1e172009-05-22 20:36:31 +0000260
261 PM.add(createGCLoweringPass());
Dan Gohman02dae4b2008-09-25 00:37:07 +0000262
Chris Lattner47877052006-09-04 04:16:09 +0000263 // Make sure that no unreachable blocks are instruction selected.
264 PM.add(createUnreachableBlockEliminationPass());
Bill Wendling04523ea2007-02-08 01:36:53 +0000265
Dan Gohman6f65d792009-09-16 20:25:11 +0000266 if (OptLevel != CodeGenOpt::None) {
267 if (HoistConstants)
268 PM.add(createCodeGenLICMPass());
Chris Lattnerc8d288f2007-03-31 04:18:03 +0000269 PM.add(createCodeGenPreparePass(getTargetLowering()));
Dan Gohman6f65d792009-09-16 20:25:11 +0000270 }
Chris Lattnerc8d288f2007-03-31 04:18:03 +0000271
Bill Wendlinge9e6bdf2008-11-13 01:02:14 +0000272 PM.add(createStackProtectorPass(getTargetLowering()));
Bill Wendling2b58ce52008-11-04 02:10:20 +0000273
Chris Lattnerc8d288f2007-03-31 04:18:03 +0000274 if (PrintISelInput)
Daniel Dunbarf4db3a52008-10-21 23:33:38 +0000275 PM.add(createPrintFunctionPass("\n\n"
276 "*** Final LLVM Code input to ISel ***\n",
Daniel Dunbar3b0da262008-10-22 03:25:22 +0000277 &errs()));
Chris Lattnerc8d288f2007-03-31 04:18:03 +0000278
Dan Gohman02dae4b2008-09-25 00:37:07 +0000279 // Standard Lower-Level Passes.
280
Dan Gohmanad2afc22009-07-31 18:16:33 +0000281 // Set up a MachineFunction for the rest of CodeGen to work on.
282 PM.add(new MachineFunctionAnalysis(*this, OptLevel));
283
Dan Gohmandc756852008-10-01 20:39:19 +0000284 // Enable FastISel with -fast, but allow that to be overridden.
Dan Gohmaneb0d6ab2008-10-07 23:00:56 +0000285 if (EnableFastISelOption == cl::BOU_TRUE ||
Bill Wendling98a366d2009-04-29 23:29:43 +0000286 (OptLevel == CodeGenOpt::None && EnableFastISelOption != cl::BOU_FALSE))
Dan Gohmandc756852008-10-01 20:39:19 +0000287 EnableFastISel = true;
288
Chris Lattner47877052006-09-04 04:16:09 +0000289 // Ask the target for an isel.
Bill Wendlingbe8cc2a2009-04-29 00:15:41 +0000290 if (addInstSelector(PM, OptLevel))
Chris Lattner47877052006-09-04 04:16:09 +0000291 return true;
Bill Wendling04523ea2007-02-08 01:36:53 +0000292
Chris Lattner47877052006-09-04 04:16:09 +0000293 // Print the instruction selected machine code...
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000294 printAndVerify(PM, /* allowDoubleDefs= */ true);
Bill Wendling0f940c92007-12-07 21:42:31 +0000295
Bill Wendling98a366d2009-04-29 23:29:43 +0000296 if (OptLevel != CodeGenOpt::None) {
Bill Wendlingcc8f6032008-01-04 08:11:03 +0000297 PM.add(createMachineLICMPass());
Chris Lattner3c42f122008-01-05 06:14:16 +0000298 PM.add(createMachineSinkingPass());
Evan Cheng8799dbe2009-07-13 23:44:01 +0000299 printAndVerify(PM, /* allowDoubleDefs= */ true);
Evan Cheng8f0d99e2009-02-09 08:45:39 +0000300 }
Bill Wendling0f940c92007-12-07 21:42:31 +0000301
Anton Korobeynikovb013f502008-04-23 18:26:03 +0000302 // Run pre-ra passes.
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000303 if (addPreRegAlloc(PM, OptLevel))
Jakob Stoklund Olesen4af85b22009-08-15 13:10:15 +0000304 printAndVerify(PM, /* allowDoubleDefs= */ true);
Anton Korobeynikovb013f502008-04-23 18:26:03 +0000305
Evan Cheng3f32d652008-06-04 09:18:41 +0000306 // Perform register allocation.
Chris Lattner47877052006-09-04 04:16:09 +0000307 PM.add(createRegisterAllocator());
Evan Cheng3f32d652008-06-04 09:18:41 +0000308
309 // Perform stack slot coloring.
Bill Wendling98a366d2009-04-29 23:29:43 +0000310 if (OptLevel != CodeGenOpt::None)
Evan Cheng6248fa42009-08-05 07:26:17 +0000311 // FIXME: Re-enable coloring with register when it's capable of adding
312 // kill markers.
313 PM.add(createStackSlotColoringPass(false));
Evan Cheng3f32d652008-06-04 09:18:41 +0000314
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000315 printAndVerify(PM); // Print the register-allocated code
Dan Gohman02dae4b2008-09-25 00:37:07 +0000316
Evan Cheng3f32d652008-06-04 09:18:41 +0000317 // Run post-ra passes.
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000318 if (addPostRegAlloc(PM, OptLevel))
319 printAndVerify(PM);
Dan Gohman02dae4b2008-09-25 00:37:07 +0000320
Christopher Lambada779f2007-07-27 07:36:14 +0000321 PM.add(createLowerSubregsPass());
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000322 printAndVerify(PM);
Bill Wendling04523ea2007-02-08 01:36:53 +0000323
Chris Lattner47877052006-09-04 04:16:09 +0000324 // Insert prolog/epilog code. Eliminate abstract frame index references...
325 PM.add(createPrologEpilogCodeInserter());
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000326 printAndVerify(PM);
Dan Gohman02dae4b2008-09-25 00:37:07 +0000327
Dale Johannesene7e7d0d2007-07-13 17:13:54 +0000328 // Second pass scheduler.
Evan Cheng48301102009-09-25 21:38:11 +0000329 if (OptLevel != CodeGenOpt::None && EnablePostRAScheduler) {
Dale Johannesen72f15962007-07-13 17:31:29 +0000330 PM.add(createPostRAScheduler());
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000331 printAndVerify(PM);
Dan Gohman5ce09732008-11-20 19:54:21 +0000332 }
333
Dan Gohman23b0d492008-12-18 01:36:42 +0000334 // Branch folding must be run after regalloc and prolog/epilog insertion.
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000335 if (OptLevel != CodeGenOpt::None) {
Dan Gohman23b0d492008-12-18 01:36:42 +0000336 PM.add(createBranchFoldingPass(getEnableTailMergeDefault()));
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000337 printAndVerify(PM);
338 }
Dan Gohman23b0d492008-12-18 01:36:42 +0000339
Gordon Henriksen93f96d02008-01-07 01:33:09 +0000340 PM.add(createGCMachineCodeAnalysisPass());
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000341 printAndVerify(PM);
Dan Gohman02dae4b2008-09-25 00:37:07 +0000342
Gordon Henriksen93f96d02008-01-07 01:33:09 +0000343 if (PrintGCInfo)
Chris Lattnercf143a42009-08-23 03:13:20 +0000344 PM.add(createGCInfoPrinter(errs()));
Bill Wendling04523ea2007-02-08 01:36:53 +0000345
Dan Gohman02dae4b2008-09-25 00:37:07 +0000346 return false;
Chris Lattner47877052006-09-04 04:16:09 +0000347}