blob: 1234cb7fd9ab5e53552e7ec7c38797fedba7335b [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"));
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +000042static cl::opt<bool> VerifyMachineCode("verify-machineinstrs", cl::Hidden,
43 cl::desc("Verify generated machine code"),
44 cl::init(getenv("LLVM_VERIFY_MACHINEINSTRS")!=NULL));
Chris Lattner85ef2542007-06-19 05:47:49 +000045
Dan Gohmandc756852008-10-01 20:39:19 +000046// Enable or disable FastISel. Both options are needed, because
47// FastISel is enabled by default with -fast, and we wish to be
Dan Gohmane29fea42009-08-26 15:57:57 +000048// able to enable or disable fast-isel independently from -O0.
Dan Gohmaneb0d6ab2008-10-07 23:00:56 +000049static cl::opt<cl::boolOrDefault>
Dan Gohmandc756852008-10-01 20:39:19 +000050EnableFastISelOption("fast-isel", cl::Hidden,
Dan Gohmane29fea42009-08-26 15:57:57 +000051 cl::desc("Enable the \"fast\" instruction selector"));
Dan Gohman2c4bf112008-09-25 01:14:49 +000052
Chris Lattnera7ac47c2009-08-12 07:22:17 +000053
54LLVMTargetMachine::LLVMTargetMachine(const Target &T,
55 const std::string &TargetTriple)
56 : TargetMachine(T) {
57 AsmInfo = T.createAsmInfo(TargetTriple);
58}
59
60
61
Bill Wendling04523ea2007-02-08 01:36:53 +000062FileModel::Model
Dan Gohmanbfae8312008-03-11 22:29:46 +000063LLVMTargetMachine::addPassesToEmitFile(PassManagerBase &PM,
David Greene71847812009-07-14 20:18:05 +000064 formatted_raw_ostream &Out,
Bill Wendling04523ea2007-02-08 01:36:53 +000065 CodeGenFileType FileType,
Bill Wendling98a366d2009-04-29 23:29:43 +000066 CodeGenOpt::Level OptLevel) {
Dan Gohman02dae4b2008-09-25 00:37:07 +000067 // Add common CodeGen passes.
Bill Wendlingbe8cc2a2009-04-29 00:15:41 +000068 if (addCommonCodeGenPasses(PM, OptLevel))
Bill Wendling04523ea2007-02-08 01:36:53 +000069 return FileModel::Error;
70
Jim Laskey9d4209f2006-11-07 19:33:46 +000071 // Fold redundant debug labels.
72 PM.add(createDebugLabelFoldingPass());
Dan Gohman02dae4b2008-09-25 00:37:07 +000073
74 if (PrintMachineCode)
Chris Lattnercf143a42009-08-23 03:13:20 +000075 PM.add(createMachineFunctionPrinterPass(errs()));
Bill Wendling04523ea2007-02-08 01:36:53 +000076
Bill Wendlingbe8cc2a2009-04-29 00:15:41 +000077 if (addPreEmitPass(PM, OptLevel) && PrintMachineCode)
Chris Lattnercf143a42009-08-23 03:13:20 +000078 PM.add(createMachineFunctionPrinterPass(errs()));
Bill Wendling04523ea2007-02-08 01:36:53 +000079
Bill Wendling98a366d2009-04-29 23:29:43 +000080 if (OptLevel != CodeGenOpt::None)
Evan Chengbbf1db72009-05-07 05:42:24 +000081 PM.add(createCodePlacementOptPass());
Evan Chengd703ed62008-02-28 23:29:57 +000082
Chris Lattner47877052006-09-04 04:16:09 +000083 switch (FileType) {
Bill Wendling04523ea2007-02-08 01:36:53 +000084 default:
85 break;
86 case TargetMachine::AssemblyFile:
Bill Wendlingbe8cc2a2009-04-29 00:15:41 +000087 if (addAssemblyEmitter(PM, OptLevel, getAsmVerbosityDefault(), Out))
Bill Wendling04523ea2007-02-08 01:36:53 +000088 return FileModel::Error;
89 return FileModel::AsmFile;
90 case TargetMachine::ObjectFile:
91 if (getMachOWriterInfo())
92 return FileModel::MachOFile;
93 else if (getELFWriterInfo())
94 return FileModel::ElfFile;
Chris Lattner47877052006-09-04 04:16:09 +000095 }
Bill Wendling04523ea2007-02-08 01:36:53 +000096
97 return FileModel::Error;
98}
Dan Gohman02dae4b2008-09-25 00:37:07 +000099
Daniel Dunbar5d77cad2009-07-15 23:34:19 +0000100bool LLVMTargetMachine::addAssemblyEmitter(PassManagerBase &PM,
101 CodeGenOpt::Level OptLevel,
102 bool Verbose,
103 formatted_raw_ostream &Out) {
Daniel Dunbar67d894e2009-08-13 19:38:51 +0000104 FunctionPass *Printer =
Chris Lattneraf76e592009-08-22 20:48:53 +0000105 getTarget().createAsmPrinter(Out, *this, getMCAsmInfo(), Verbose);
Daniel Dunbar5d77cad2009-07-15 23:34:19 +0000106 if (!Printer)
Daniel Dunbar36129db2009-07-15 23:54:01 +0000107 return true;
108
Daniel Dunbar5d77cad2009-07-15 23:34:19 +0000109 PM.add(Printer);
110 return false;
111}
112
Bill Wendling04523ea2007-02-08 01:36:53 +0000113/// addPassesToEmitFileFinish - If the passes to emit the specified file had to
114/// be split up (e.g., to add an object writer pass), this method can be used to
115/// finish up adding passes to emit the file, if necessary.
Dan Gohmanbfae8312008-03-11 22:29:46 +0000116bool LLVMTargetMachine::addPassesToEmitFileFinish(PassManagerBase &PM,
Bill Wendling04523ea2007-02-08 01:36:53 +0000117 MachineCodeEmitter *MCE,
Bill Wendling98a366d2009-04-29 23:29:43 +0000118 CodeGenOpt::Level OptLevel) {
Bill Wendling04523ea2007-02-08 01:36:53 +0000119 if (MCE)
Daniel Dunbarcfe9a602009-07-15 22:33:19 +0000120 addSimpleCodeEmitter(PM, OptLevel, *MCE);
121 if (PrintEmittedAsm)
122 addAssemblyEmitter(PM, OptLevel, true, ferrs());
Dan Gohman02dae4b2008-09-25 00:37:07 +0000123
Gordon Henriksen5eca0752008-08-17 18:44:35 +0000124 PM.add(createGCInfoDeleter());
Bill Wendling04523ea2007-02-08 01:36:53 +0000125
Chris Lattner47877052006-09-04 04:16:09 +0000126 return false; // success!
127}
128
Bruno Cardoso Lopesa3f99f92009-05-30 20:51:52 +0000129/// addPassesToEmitFileFinish - If the passes to emit the specified file had to
130/// be split up (e.g., to add an object writer pass), this method can be used to
131/// finish up adding passes to emit the file, if necessary.
132bool LLVMTargetMachine::addPassesToEmitFileFinish(PassManagerBase &PM,
133 JITCodeEmitter *JCE,
134 CodeGenOpt::Level OptLevel) {
135 if (JCE)
Daniel Dunbarcfe9a602009-07-15 22:33:19 +0000136 addSimpleCodeEmitter(PM, OptLevel, *JCE);
137 if (PrintEmittedAsm)
138 addAssemblyEmitter(PM, OptLevel, true, ferrs());
Bruno Cardoso Lopesa3f99f92009-05-30 20:51:52 +0000139
140 PM.add(createGCInfoDeleter());
141
Bruno Cardoso Lopesa3f99f92009-05-30 20:51:52 +0000142 return false; // success!
143}
144
Bruno Cardoso Lopesac57e6e2009-07-06 05:09:34 +0000145/// addPassesToEmitFileFinish - If the passes to emit the specified file had to
146/// be split up (e.g., to add an object writer pass), this method can be used to
147/// finish up adding passes to emit the file, if necessary.
148bool LLVMTargetMachine::addPassesToEmitFileFinish(PassManagerBase &PM,
149 ObjectCodeEmitter *OCE,
150 CodeGenOpt::Level OptLevel) {
151 if (OCE)
Daniel Dunbarcfe9a602009-07-15 22:33:19 +0000152 addSimpleCodeEmitter(PM, OptLevel, *OCE);
153 if (PrintEmittedAsm)
154 addAssemblyEmitter(PM, OptLevel, true, ferrs());
Bruno Cardoso Lopesac57e6e2009-07-06 05:09:34 +0000155
156 PM.add(createGCInfoDeleter());
157
Bruno Cardoso Lopesac57e6e2009-07-06 05:09:34 +0000158 return false; // success!
159}
160
Chris Lattner47877052006-09-04 04:16:09 +0000161/// addPassesToEmitMachineCode - Add passes to the specified pass manager to
162/// get machine code emitted. This uses a MachineCodeEmitter object to handle
163/// actually outputting the machine code and resolving things like the address
164/// of functions. This method should returns true if machine code emission is
165/// not supported.
166///
Dan Gohmanbfae8312008-03-11 22:29:46 +0000167bool LLVMTargetMachine::addPassesToEmitMachineCode(PassManagerBase &PM,
Chris Lattner47877052006-09-04 04:16:09 +0000168 MachineCodeEmitter &MCE,
Bill Wendling98a366d2009-04-29 23:29:43 +0000169 CodeGenOpt::Level OptLevel) {
Dan Gohman02dae4b2008-09-25 00:37:07 +0000170 // Add common CodeGen passes.
Bill Wendlingbe8cc2a2009-04-29 00:15:41 +0000171 if (addCommonCodeGenPasses(PM, OptLevel))
Dan Gohman02dae4b2008-09-25 00:37:07 +0000172 return true;
173
Bill Wendlingbe8cc2a2009-04-29 00:15:41 +0000174 if (addPreEmitPass(PM, OptLevel) && PrintMachineCode)
Chris Lattnercf143a42009-08-23 03:13:20 +0000175 PM.add(createMachineFunctionPrinterPass(errs()));
Dan Gohman02dae4b2008-09-25 00:37:07 +0000176
Daniel Dunbarcfe9a602009-07-15 22:33:19 +0000177 addCodeEmitter(PM, OptLevel, MCE);
178 if (PrintEmittedAsm)
179 addAssemblyEmitter(PM, OptLevel, true, ferrs());
Dan Gohman02dae4b2008-09-25 00:37:07 +0000180
181 PM.add(createGCInfoDeleter());
182
Dan Gohman02dae4b2008-09-25 00:37:07 +0000183 return false; // success!
184}
185
Bruno Cardoso Lopesa3f99f92009-05-30 20:51:52 +0000186/// addPassesToEmitMachineCode - Add passes to the specified pass manager to
187/// get machine code emitted. This uses a MachineCodeEmitter object to handle
188/// actually outputting the machine code and resolving things like the address
189/// of functions. This method should returns true if machine code emission is
190/// not supported.
191///
192bool LLVMTargetMachine::addPassesToEmitMachineCode(PassManagerBase &PM,
193 JITCodeEmitter &JCE,
194 CodeGenOpt::Level OptLevel) {
195 // Add common CodeGen passes.
196 if (addCommonCodeGenPasses(PM, OptLevel))
197 return true;
198
199 if (addPreEmitPass(PM, OptLevel) && PrintMachineCode)
Chris Lattnercf143a42009-08-23 03:13:20 +0000200 PM.add(createMachineFunctionPrinterPass(errs()));
Bruno Cardoso Lopesa3f99f92009-05-30 20:51:52 +0000201
Daniel Dunbarcfe9a602009-07-15 22:33:19 +0000202 addCodeEmitter(PM, OptLevel, JCE);
203 if (PrintEmittedAsm)
204 addAssemblyEmitter(PM, OptLevel, true, ferrs());
Bruno Cardoso Lopesa3f99f92009-05-30 20:51:52 +0000205
206 PM.add(createGCInfoDeleter());
207
Bruno Cardoso Lopesa3f99f92009-05-30 20:51:52 +0000208 return false; // success!
209}
210
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000211static void printAndVerify(PassManagerBase &PM,
212 bool allowDoubleDefs = false) {
213 if (PrintMachineCode)
Chris Lattnercf143a42009-08-23 03:13:20 +0000214 PM.add(createMachineFunctionPrinterPass(errs()));
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000215
216 if (VerifyMachineCode)
217 PM.add(createMachineVerifierPass(allowDoubleDefs));
218}
219
Bill Wendling98a366d2009-04-29 23:29:43 +0000220/// addCommonCodeGenPasses - Add standard LLVM codegen passes used for both
221/// emitting to assembly files or machine code output.
Dan Gohman02dae4b2008-09-25 00:37:07 +0000222///
Bill Wendlingbe8cc2a2009-04-29 00:15:41 +0000223bool LLVMTargetMachine::addCommonCodeGenPasses(PassManagerBase &PM,
Bill Wendling98a366d2009-04-29 23:29:43 +0000224 CodeGenOpt::Level OptLevel) {
Chris Lattner47877052006-09-04 04:16:09 +0000225 // Standard LLVM-Level Passes.
Dan Gohman02dae4b2008-09-25 00:37:07 +0000226
Chris Lattner47877052006-09-04 04:16:09 +0000227 // Run loop strength reduction before anything else.
Bill Wendling98a366d2009-04-29 23:29:43 +0000228 if (OptLevel != CodeGenOpt::None) {
Chris Lattnerc8d288f2007-03-31 04:18:03 +0000229 PM.add(createLoopStrengthReducePass(getTargetLowering()));
230 if (PrintLSR)
Daniel Dunbar3b0da262008-10-22 03:25:22 +0000231 PM.add(createPrintFunctionPass("\n\n*** Code after LSR ***\n", &errs()));
Chris Lattnerc8d288f2007-03-31 04:18:03 +0000232 }
Dan Gohman02dae4b2008-09-25 00:37:07 +0000233
Duncan Sandsb0f1e172009-05-22 20:36:31 +0000234 // Turn exception handling constructs into something the code generators can
235 // handle.
Chris Lattneraf76e592009-08-22 20:48:53 +0000236 switch (getMCAsmInfo()->getExceptionHandlingType())
Jim Grosbach1b747ad2009-08-11 00:09:57 +0000237 {
Jim Grosbach1b747ad2009-08-11 00:09:57 +0000238 case ExceptionHandling::SjLj:
Jim Grosbach8b818d72009-08-17 16:41:22 +0000239 // SjLj piggy-backs on dwarf for this bit. The cleanups done apply to both
Bill Wendling8bedf972009-10-29 00:37:35 +0000240 PM.add(createDwarfEHPass(getTargetLowering(), OptLevel==CodeGenOpt::None));
Jim Grosbach8b818d72009-08-17 16:41:22 +0000241 PM.add(createSjLjEHPass(getTargetLowering()));
242 break;
Jim Grosbach1b747ad2009-08-11 00:09:57 +0000243 case ExceptionHandling::Dwarf:
Bill Wendling8bedf972009-10-29 00:37:35 +0000244 PM.add(createDwarfEHPass(getTargetLowering(), OptLevel==CodeGenOpt::None));
Jim Grosbach1b747ad2009-08-11 00:09:57 +0000245 break;
246 case ExceptionHandling::None:
247 PM.add(createLowerInvokePass(getTargetLowering()));
248 break;
249 }
Duncan Sandsb0f1e172009-05-22 20:36:31 +0000250
251 PM.add(createGCLoweringPass());
Dan Gohman02dae4b2008-09-25 00:37:07 +0000252
Chris Lattner47877052006-09-04 04:16:09 +0000253 // Make sure that no unreachable blocks are instruction selected.
254 PM.add(createUnreachableBlockEliminationPass());
Bill Wendling04523ea2007-02-08 01:36:53 +0000255
Dan Gohman9f476e32009-10-31 14:35:41 +0000256 if (OptLevel != CodeGenOpt::None)
Chris Lattnerc8d288f2007-03-31 04:18:03 +0000257 PM.add(createCodeGenPreparePass(getTargetLowering()));
258
Bill Wendlinge9e6bdf2008-11-13 01:02:14 +0000259 PM.add(createStackProtectorPass(getTargetLowering()));
Bill Wendling2b58ce52008-11-04 02:10:20 +0000260
Chris Lattnerc8d288f2007-03-31 04:18:03 +0000261 if (PrintISelInput)
Daniel Dunbarf4db3a52008-10-21 23:33:38 +0000262 PM.add(createPrintFunctionPass("\n\n"
263 "*** Final LLVM Code input to ISel ***\n",
Daniel Dunbar3b0da262008-10-22 03:25:22 +0000264 &errs()));
Chris Lattnerc8d288f2007-03-31 04:18:03 +0000265
Dan Gohman02dae4b2008-09-25 00:37:07 +0000266 // Standard Lower-Level Passes.
267
Dan Gohmanad2afc22009-07-31 18:16:33 +0000268 // Set up a MachineFunction for the rest of CodeGen to work on.
269 PM.add(new MachineFunctionAnalysis(*this, OptLevel));
270
Dan Gohmandc756852008-10-01 20:39:19 +0000271 // Enable FastISel with -fast, but allow that to be overridden.
Dan Gohmaneb0d6ab2008-10-07 23:00:56 +0000272 if (EnableFastISelOption == cl::BOU_TRUE ||
Bill Wendling98a366d2009-04-29 23:29:43 +0000273 (OptLevel == CodeGenOpt::None && EnableFastISelOption != cl::BOU_FALSE))
Dan Gohmandc756852008-10-01 20:39:19 +0000274 EnableFastISel = true;
275
Chris Lattner47877052006-09-04 04:16:09 +0000276 // Ask the target for an isel.
Bill Wendlingbe8cc2a2009-04-29 00:15:41 +0000277 if (addInstSelector(PM, OptLevel))
Chris Lattner47877052006-09-04 04:16:09 +0000278 return true;
Bill Wendling04523ea2007-02-08 01:36:53 +0000279
Chris Lattner47877052006-09-04 04:16:09 +0000280 // Print the instruction selected machine code...
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000281 printAndVerify(PM, /* allowDoubleDefs= */ true);
Bill Wendling0f940c92007-12-07 21:42:31 +0000282
Bill Wendling98a366d2009-04-29 23:29:43 +0000283 if (OptLevel != CodeGenOpt::None) {
Bill Wendlingcc8f6032008-01-04 08:11:03 +0000284 PM.add(createMachineLICMPass());
Chris Lattner3c42f122008-01-05 06:14:16 +0000285 PM.add(createMachineSinkingPass());
Evan Cheng8799dbe2009-07-13 23:44:01 +0000286 printAndVerify(PM, /* allowDoubleDefs= */ true);
Evan Cheng8f0d99e2009-02-09 08:45:39 +0000287 }
Bill Wendling0f940c92007-12-07 21:42:31 +0000288
Anton Korobeynikovb013f502008-04-23 18:26:03 +0000289 // Run pre-ra passes.
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000290 if (addPreRegAlloc(PM, OptLevel))
Jakob Stoklund Olesen4af85b22009-08-15 13:10:15 +0000291 printAndVerify(PM, /* allowDoubleDefs= */ true);
Anton Korobeynikovb013f502008-04-23 18:26:03 +0000292
Evan Cheng3f32d652008-06-04 09:18:41 +0000293 // Perform register allocation.
Chris Lattner47877052006-09-04 04:16:09 +0000294 PM.add(createRegisterAllocator());
Evan Cheng3f32d652008-06-04 09:18:41 +0000295
296 // Perform stack slot coloring.
Bill Wendling98a366d2009-04-29 23:29:43 +0000297 if (OptLevel != CodeGenOpt::None)
Evan Cheng6248fa42009-08-05 07:26:17 +0000298 // FIXME: Re-enable coloring with register when it's capable of adding
299 // kill markers.
300 PM.add(createStackSlotColoringPass(false));
Evan Cheng3f32d652008-06-04 09:18:41 +0000301
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000302 printAndVerify(PM); // Print the register-allocated code
Dan Gohman02dae4b2008-09-25 00:37:07 +0000303
Evan Cheng3f32d652008-06-04 09:18:41 +0000304 // Run post-ra passes.
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000305 if (addPostRegAlloc(PM, OptLevel))
306 printAndVerify(PM);
Dan Gohman02dae4b2008-09-25 00:37:07 +0000307
Christopher Lambada779f2007-07-27 07:36:14 +0000308 PM.add(createLowerSubregsPass());
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000309 printAndVerify(PM);
Bill Wendling04523ea2007-02-08 01:36:53 +0000310
Chris Lattner47877052006-09-04 04:16:09 +0000311 // Insert prolog/epilog code. Eliminate abstract frame index references...
312 PM.add(createPrologEpilogCodeInserter());
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000313 printAndVerify(PM);
Dan Gohman02dae4b2008-09-25 00:37:07 +0000314
Evan Cheng629adde2009-09-30 08:49:50 +0000315 // Run pre-sched2 passes.
316 if (addPreSched2(PM, OptLevel))
317 printAndVerify(PM);
318
Dale Johannesene7e7d0d2007-07-13 17:13:54 +0000319 // Second pass scheduler.
David Goodwin0dad89f2009-09-30 00:10:16 +0000320 if (OptLevel != CodeGenOpt::None) {
Evan Chengfa163542009-10-16 21:06:15 +0000321 PM.add(createPostRAScheduler(OptLevel));
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000322 printAndVerify(PM);
Dan Gohman5ce09732008-11-20 19:54:21 +0000323 }
324
Dan Gohman23b0d492008-12-18 01:36:42 +0000325 // Branch folding must be run after regalloc and prolog/epilog insertion.
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000326 if (OptLevel != CodeGenOpt::None) {
Bob Wilsona5971032009-10-28 20:46:46 +0000327 PM.add(createBranchFoldingPass(getEnableTailMergeDefault()));
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000328 printAndVerify(PM);
329 }
Dan Gohman23b0d492008-12-18 01:36:42 +0000330
Gordon Henriksen93f96d02008-01-07 01:33:09 +0000331 PM.add(createGCMachineCodeAnalysisPass());
Jakob Stoklund Olesen48872e02009-05-16 00:33:53 +0000332 printAndVerify(PM);
Dan Gohman02dae4b2008-09-25 00:37:07 +0000333
Gordon Henriksen93f96d02008-01-07 01:33:09 +0000334 if (PrintGCInfo)
Chris Lattnercf143a42009-08-23 03:13:20 +0000335 PM.add(createGCInfoPrinter(errs()));
Bill Wendling04523ea2007-02-08 01:36:53 +0000336
Dan Gohman02dae4b2008-09-25 00:37:07 +0000337 return false;
Chris Lattner47877052006-09-04 04:16:09 +0000338}