blob: 39d5c905f826416f11ce9c8ded4e9023386f4a70 [file] [log] [blame]
Daniel Dunbar85e44e22008-10-21 23:49:24 +00001//===--- Backend.cpp - Interface to LLVM backend technologies -------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "ASTConsumers.h"
Daniel Dunbar85e44e22008-10-21 23:49:24 +000011#include "clang/AST/ASTContext.h"
12#include "clang/AST/ASTConsumer.h"
13#include "clang/AST/TranslationUnit.h"
14#include "clang/Basic/TargetInfo.h"
15#include "clang/CodeGen/ModuleBuilder.h"
Daniel Dunbar68952de2009-03-02 06:16:29 +000016#include "clang/Frontend/CompileOptions.h"
Daniel Dunbar85e44e22008-10-21 23:49:24 +000017#include "llvm/Module.h"
18#include "llvm/ModuleProvider.h"
19#include "llvm/PassManager.h"
20#include "llvm/ADT/OwningPtr.h"
21#include "llvm/Assembly/PrintModulePass.h"
Daniel Dunbaraa7a0662008-10-23 05:50:47 +000022#include "llvm/Analysis/CallGraph.h"
23#include "llvm/Analysis/Verifier.h"
Daniel Dunbar85e44e22008-10-21 23:49:24 +000024#include "llvm/Bitcode/ReaderWriter.h"
25#include "llvm/CodeGen/RegAllocRegistry.h"
26#include "llvm/CodeGen/SchedulerRegistry.h"
Daniel Dunbar85e44e22008-10-21 23:49:24 +000027#include "llvm/Support/raw_ostream.h"
Daniel Dunbar85e44e22008-10-21 23:49:24 +000028#include "llvm/Support/Compiler.h"
Chris Lattner2193db22009-02-18 01:37:30 +000029#include "llvm/Support/Timer.h"
Daniel Dunbar85e44e22008-10-21 23:49:24 +000030#include "llvm/System/Path.h"
31#include "llvm/System/Program.h"
Daniel Dunbar9101a632009-02-17 19:47:34 +000032#include "llvm/Target/SubtargetFeature.h"
Daniel Dunbar85e44e22008-10-21 23:49:24 +000033#include "llvm/Target/TargetData.h"
34#include "llvm/Target/TargetMachine.h"
35#include "llvm/Target/TargetMachineRegistry.h"
Daniel Dunbaraa7a0662008-10-23 05:50:47 +000036#include "llvm/Transforms/Scalar.h"
37#include "llvm/Transforms/IPO.h"
Daniel Dunbar85e44e22008-10-21 23:49:24 +000038using namespace clang;
39using namespace llvm;
40
41namespace {
Chris Lattnerc309ade2009-03-05 08:00:35 +000042 class VISIBILITY_HIDDEN BackendConsumer : public ASTConsumer {
Daniel Dunbar85e44e22008-10-21 23:49:24 +000043 BackendAction Action;
Daniel Dunbaraa7a0662008-10-23 05:50:47 +000044 CompileOptions CompileOpts;
Daniel Dunbar85e44e22008-10-21 23:49:24 +000045 const std::string &InputFile;
46 std::string OutputFile;
Chris Lattnerc309ade2009-03-05 08:00:35 +000047 ASTContext *Context;
Daniel Dunbar1a27a192008-10-29 08:50:02 +000048
Chris Lattner2193db22009-02-18 01:37:30 +000049 Timer LLVMIRGeneration;
50 Timer CodeGenerationTime;
51
Daniel Dunbar85e44e22008-10-21 23:49:24 +000052 llvm::OwningPtr<CodeGenerator> Gen;
53
54 llvm::Module *TheModule;
55 llvm::TargetData *TheTargetData;
56 llvm::raw_ostream *AsmOutStream;
57
Nuno Lopes74d92782008-10-24 22:51:00 +000058 mutable llvm::ModuleProvider *ModuleProvider;
Daniel Dunbar85e44e22008-10-21 23:49:24 +000059 mutable FunctionPassManager *CodeGenPasses;
60 mutable PassManager *PerModulePasses;
61 mutable FunctionPassManager *PerFunctionPasses;
62
63 FunctionPassManager *getCodeGenPasses() const;
64 PassManager *getPerModulePasses() const;
65 FunctionPassManager *getPerFunctionPasses() const;
66
67 void CreatePasses();
68
69 /// AddEmitPasses - Add passes necessary to emit assembly or LLVM
70 /// IR.
71 ///
Daniel Dunbar85e44e22008-10-21 23:49:24 +000072 /// \return True on success. On failure \arg Error will be set to
73 /// a user readable error message.
Daniel Dunbar655d5092008-10-23 05:59:43 +000074 bool AddEmitPasses(std::string &Error);
Daniel Dunbar85e44e22008-10-21 23:49:24 +000075
76 void EmitAssembly();
77
78 public:
79 BackendConsumer(BackendAction action, Diagnostic &Diags,
Daniel Dunbar9101a632009-02-17 19:47:34 +000080 const LangOptions &langopts, const CompileOptions &compopts,
Chris Lattner88cbb9b2009-03-09 22:00:34 +000081 const std::string &infile, const std::string &outfile) :
Daniel Dunbar85e44e22008-10-21 23:49:24 +000082 Action(action),
Daniel Dunbaraa7a0662008-10-23 05:50:47 +000083 CompileOpts(compopts),
Daniel Dunbar85e44e22008-10-21 23:49:24 +000084 InputFile(infile),
85 OutputFile(outfile),
Chris Lattner2193db22009-02-18 01:37:30 +000086 LLVMIRGeneration("LLVM IR Generation Time"),
87 CodeGenerationTime("Code Generation Time"),
Chris Lattnerf04a7562009-03-26 05:00:52 +000088 Gen(CreateLLVMCodeGen(Diags, InputFile, compopts)),
Nuno Lopes74d92782008-10-24 22:51:00 +000089 TheModule(0), TheTargetData(0), AsmOutStream(0), ModuleProvider(0),
Chris Lattnere8f70712009-02-18 01:23:44 +000090 CodeGenPasses(0), PerModulePasses(0), PerFunctionPasses(0) {
91
Chris Lattner2193db22009-02-18 01:37:30 +000092 // Enable -time-passes if -ftime-report is enabled.
Chris Lattnere8f70712009-02-18 01:23:44 +000093 llvm::TimePassesIsEnabled = CompileOpts.TimePasses;
94 }
Daniel Dunbar85e44e22008-10-21 23:49:24 +000095
96 ~BackendConsumer() {
Daniel Dunbar85e44e22008-10-21 23:49:24 +000097 delete AsmOutStream;
98 delete TheTargetData;
Nuno Lopes74d92782008-10-24 22:51:00 +000099 delete ModuleProvider;
Daniel Dunbar85e44e22008-10-21 23:49:24 +0000100 delete CodeGenPasses;
101 delete PerModulePasses;
102 delete PerFunctionPasses;
103 }
104
Chris Lattnerfb88a5f2009-03-28 02:18:25 +0000105 virtual void Initialize(ASTContext &Ctx) {
106 Context = &Ctx;
Chris Lattner2193db22009-02-18 01:37:30 +0000107
108 if (CompileOpts.TimePasses)
109 LLVMIRGeneration.startTimer();
110
Chris Lattnerfb88a5f2009-03-28 02:18:25 +0000111 Gen->Initialize(Ctx);
Daniel Dunbar85e44e22008-10-21 23:49:24 +0000112
113 TheModule = Gen->GetModule();
Nuno Lopesd41e2b12008-10-24 23:27:18 +0000114 ModuleProvider = new ExistingModuleProvider(TheModule);
Chris Lattnerfb88a5f2009-03-28 02:18:25 +0000115 TheTargetData = new llvm::TargetData(Ctx.Target.getTargetDescription());
Chris Lattner2193db22009-02-18 01:37:30 +0000116
117 if (CompileOpts.TimePasses)
118 LLVMIRGeneration.stopTimer();
Daniel Dunbar85e44e22008-10-21 23:49:24 +0000119 }
120
121 virtual void HandleTopLevelDecl(Decl *D) {
Chris Lattnerc309ade2009-03-05 08:00:35 +0000122 PrettyStackTraceDecl CrashInfo(D, SourceLocation(),
123 Context->getSourceManager(),
124 "LLVM IR generation of declaration");
Chris Lattner2193db22009-02-18 01:37:30 +0000125 if (CompileOpts.TimePasses)
126 LLVMIRGeneration.startTimer();
127
Daniel Dunbar85e44e22008-10-21 23:49:24 +0000128 Gen->HandleTopLevelDecl(D);
Chris Lattner2193db22009-02-18 01:37:30 +0000129
130 if (CompileOpts.TimePasses)
131 LLVMIRGeneration.stopTimer();
Daniel Dunbar85e44e22008-10-21 23:49:24 +0000132 }
133
134 virtual void HandleTranslationUnit(TranslationUnit& TU) {
Chris Lattnerc309ade2009-03-05 08:00:35 +0000135 {
Chris Lattner4e164172009-03-06 06:46:31 +0000136 PrettyStackTraceString CrashInfo("Per-file LLVM IR generation");
Chris Lattnerc309ade2009-03-05 08:00:35 +0000137 if (CompileOpts.TimePasses)
138 LLVMIRGeneration.startTimer();
Chris Lattner2193db22009-02-18 01:37:30 +0000139
Chris Lattnerc309ade2009-03-05 08:00:35 +0000140 Gen->HandleTranslationUnit(TU);
Daniel Dunbar622d6d02008-11-11 06:35:39 +0000141
Chris Lattnerc309ade2009-03-05 08:00:35 +0000142 if (CompileOpts.TimePasses)
143 LLVMIRGeneration.stopTimer();
144 }
Chris Lattner2193db22009-02-18 01:37:30 +0000145
Chris Lattnerc309ade2009-03-05 08:00:35 +0000146 // EmitAssembly times and registers crash info itself.
Chris Lattner2193db22009-02-18 01:37:30 +0000147 EmitAssembly();
148
Daniel Dunbar622d6d02008-11-11 06:35:39 +0000149 // Force a flush here in case we never get released.
150 if (AsmOutStream)
151 AsmOutStream->flush();
Daniel Dunbar85e44e22008-10-21 23:49:24 +0000152 }
153
154 virtual void HandleTagDeclDefinition(TagDecl *D) {
Chris Lattnerc309ade2009-03-05 08:00:35 +0000155 PrettyStackTraceDecl CrashInfo(D, SourceLocation(),
156 Context->getSourceManager(),
157 "LLVM IR generation of declaration");
Daniel Dunbar85e44e22008-10-21 23:49:24 +0000158 Gen->HandleTagDeclDefinition(D);
159 }
160 };
161}
162
163FunctionPassManager *BackendConsumer::getCodeGenPasses() const {
164 if (!CodeGenPasses) {
Nuno Lopes74d92782008-10-24 22:51:00 +0000165 CodeGenPasses = new FunctionPassManager(ModuleProvider);
Daniel Dunbar85e44e22008-10-21 23:49:24 +0000166 CodeGenPasses->add(new TargetData(*TheTargetData));
167 }
168
169 return CodeGenPasses;
170}
171
172PassManager *BackendConsumer::getPerModulePasses() const {
173 if (!PerModulePasses) {
174 PerModulePasses = new PassManager();
175 PerModulePasses->add(new TargetData(*TheTargetData));
176 }
177
178 return PerModulePasses;
179}
180
181FunctionPassManager *BackendConsumer::getPerFunctionPasses() const {
182 if (!PerFunctionPasses) {
Nuno Lopesd41e2b12008-10-24 23:27:18 +0000183 PerFunctionPasses = new FunctionPassManager(ModuleProvider);
Daniel Dunbar85e44e22008-10-21 23:49:24 +0000184 PerFunctionPasses->add(new TargetData(*TheTargetData));
185 }
186
187 return PerFunctionPasses;
188}
189
Daniel Dunbar655d5092008-10-23 05:59:43 +0000190bool BackendConsumer::AddEmitPasses(std::string &Error) {
Daniel Dunbard999a8e2009-02-26 22:39:37 +0000191 if (Action == Backend_EmitNothing)
192 return true;
193
Daniel Dunbar85e44e22008-10-21 23:49:24 +0000194 if (OutputFile == "-" || (InputFile == "-" && OutputFile.empty())) {
Daniel Dunbar85e44e22008-10-21 23:49:24 +0000195 AsmOutStream = new raw_stdout_ostream();
196 sys::Program::ChangeStdoutToBinary();
197 } else {
198 if (OutputFile.empty()) {
199 llvm::sys::Path Path(InputFile);
200 Path.eraseSuffix();
201 if (Action == Backend_EmitBC) {
202 Path.appendSuffix("bc");
203 } else if (Action == Backend_EmitLL) {
204 Path.appendSuffix("ll");
205 } else {
206 Path.appendSuffix("s");
207 }
208 OutputFile = Path.toString();
209 }
210
Daniel Dunbar8fc9ba62008-11-13 05:09:21 +0000211 AsmOutStream = new raw_fd_ostream(OutputFile.c_str(), true, Error);
Daniel Dunbar85e44e22008-10-21 23:49:24 +0000212 if (!Error.empty())
213 return false;
214 }
215
216 if (Action == Backend_EmitBC) {
Daniel Dunbare5dbb072008-10-22 17:40:45 +0000217 getPerModulePasses()->add(createBitcodeWriterPass(*AsmOutStream));
Daniel Dunbar85e44e22008-10-21 23:49:24 +0000218 } else if (Action == Backend_EmitLL) {
Daniel Dunbar092a7442008-10-22 03:28:13 +0000219 getPerModulePasses()->add(createPrintModulePass(AsmOutStream));
Daniel Dunbar85e44e22008-10-21 23:49:24 +0000220 } else {
Daniel Dunbar655d5092008-10-23 05:59:43 +0000221 bool Fast = CompileOpts.OptimizationLevel == 0;
222
Daniel Dunbaraed93f22008-10-22 18:29:51 +0000223 // Create the TargetMachine for generating code.
224 const TargetMachineRegistry::entry *TME =
225 TargetMachineRegistry::getClosestStaticTargetForModule(*TheModule, Error);
226 if (!TME) {
227 Error = std::string("Unable to get target machine: ") + Error;
228 return false;
229 }
Daniel Dunbar9101a632009-02-17 19:47:34 +0000230
231 std::string FeaturesStr;
232 if (CompileOpts.CPU.size() || CompileOpts.Features.size()) {
233 SubtargetFeatures Features;
234 Features.setCPU(CompileOpts.CPU);
235 for (std::vector<std::string>::iterator
236 it = CompileOpts.Features.begin(),
237 ie = CompileOpts.Features.end(); it != ie; ++it)
238 Features.AddFeature(*it);
239 FeaturesStr = Features.getString();
240 }
241 TargetMachine *TM = TME->CtorFn(*TheModule, FeaturesStr);
Daniel Dunbaraed93f22008-10-22 18:29:51 +0000242
243 // Set register scheduler & allocation policy.
244 RegisterScheduler::setDefault(createDefaultScheduler);
245 RegisterRegAlloc::setDefault(Fast ? createLocalRegisterAllocator :
246 createLinearScanRegisterAllocator);
247
Daniel Dunbar85e44e22008-10-21 23:49:24 +0000248 // From llvm-gcc:
249 // If there are passes we have to run on the entire module, we do codegen
250 // as a separate "pass" after that happens.
251 // FIXME: This is disabled right now until bugs can be worked out. Reenable
252 // this for fast -O0 compiles!
253 FunctionPassManager *PM = getCodeGenPasses();
254
255 // Normal mode, emit a .s file by running the code generator.
256 // Note, this also adds codegenerator level optimization passes.
257 switch (TM->addPassesToEmitFile(*PM, *AsmOutStream,
258 TargetMachine::AssemblyFile, Fast)) {
259 default:
260 case FileModel::Error:
261 Error = "Unable to interface with target machine!\n";
262 return false;
263 case FileModel::AsmFile:
264 break;
265 }
266
267 if (TM->addPassesToEmitFileFinish(*CodeGenPasses, 0, Fast)) {
268 Error = "Unable to interface with target machine!\n";
269 return false;
270 }
271 }
272
273 return true;
274}
275
276void BackendConsumer::CreatePasses() {
Daniel Dunbaraa7a0662008-10-23 05:50:47 +0000277 // In -O0 if checking is disabled, we don't even have per-function passes.
278 if (CompileOpts.VerifyModule)
279 getPerFunctionPasses()->add(createVerifierPass());
280
281 if (CompileOpts.OptimizationLevel > 0) {
282 FunctionPassManager *PM = getPerFunctionPasses();
283 PM->add(createCFGSimplificationPass());
284 if (CompileOpts.OptimizationLevel == 1)
285 PM->add(createPromoteMemoryToRegisterPass());
286 else
287 PM->add(createScalarReplAggregatesPass());
288 PM->add(createInstructionCombiningPass());
289 }
290
291 // For now we always create per module passes.
292 PassManager *PM = getPerModulePasses();
293 if (CompileOpts.OptimizationLevel > 0) {
294 if (CompileOpts.UnitAtATime)
295 PM->add(createRaiseAllocationsPass()); // call %malloc -> malloc inst
296 PM->add(createCFGSimplificationPass()); // Clean up disgusting code
297 PM->add(createPromoteMemoryToRegisterPass()); // Kill useless allocas
298 if (CompileOpts.UnitAtATime) {
299 PM->add(createGlobalOptimizerPass()); // Optimize out global vars
300 PM->add(createGlobalDCEPass()); // Remove unused fns and globs
301 PM->add(createIPConstantPropagationPass()); // IP Constant Propagation
302 PM->add(createDeadArgEliminationPass()); // Dead argument elimination
303 }
304 PM->add(createInstructionCombiningPass()); // Clean up after IPCP & DAE
305 PM->add(createCFGSimplificationPass()); // Clean up after IPCP & DAE
306 if (CompileOpts.UnitAtATime) {
307 PM->add(createPruneEHPass()); // Remove dead EH info
Bill Wendlingaccd9b72008-12-31 19:51:31 +0000308 PM->add(createFunctionAttrsPass()); // Set readonly/readnone attrs
Daniel Dunbaraa7a0662008-10-23 05:50:47 +0000309 }
310 if (CompileOpts.InlineFunctions)
311 PM->add(createFunctionInliningPass()); // Inline small functions
312 else
313 PM->add(createAlwaysInlinerPass()); // Respect always_inline
314 if (CompileOpts.OptimizationLevel > 2)
315 PM->add(createArgumentPromotionPass()); // Scalarize uninlined fn args
316 if (CompileOpts.SimplifyLibCalls)
317 PM->add(createSimplifyLibCallsPass()); // Library Call Optimizations
318 PM->add(createInstructionCombiningPass()); // Cleanup for scalarrepl.
319 PM->add(createJumpThreadingPass()); // Thread jumps.
320 PM->add(createCFGSimplificationPass()); // Merge & remove BBs
321 PM->add(createScalarReplAggregatesPass()); // Break up aggregate allocas
322 PM->add(createInstructionCombiningPass()); // Combine silly seq's
323 PM->add(createCondPropagationPass()); // Propagate conditionals
324 PM->add(createTailCallEliminationPass()); // Eliminate tail calls
325 PM->add(createCFGSimplificationPass()); // Merge & remove BBs
326 PM->add(createReassociatePass()); // Reassociate expressions
327 PM->add(createLoopRotatePass()); // Rotate Loop
328 PM->add(createLICMPass()); // Hoist loop invariants
329 PM->add(createLoopUnswitchPass(CompileOpts.OptimizeSize ? true : false));
Devang Patel62237e72008-11-26 05:01:52 +0000330// PM->add(createLoopIndexSplitPass()); // Split loop index
Daniel Dunbaraa7a0662008-10-23 05:50:47 +0000331 PM->add(createInstructionCombiningPass());
332 PM->add(createIndVarSimplifyPass()); // Canonicalize indvars
333 PM->add(createLoopDeletionPass()); // Delete dead loops
334 if (CompileOpts.UnrollLoops)
335 PM->add(createLoopUnrollPass()); // Unroll small loops
336 PM->add(createInstructionCombiningPass()); // Clean up after the unroller
337 PM->add(createGVNPass()); // Remove redundancies
338 PM->add(createMemCpyOptPass()); // Remove memcpy / form memset
339 PM->add(createSCCPPass()); // Constant prop with SCCP
340
341 // Run instcombine after redundancy elimination to exploit opportunities
342 // opened up by them.
343 PM->add(createInstructionCombiningPass());
344 PM->add(createCondPropagationPass()); // Propagate conditionals
345 PM->add(createDeadStoreEliminationPass()); // Delete dead stores
346 PM->add(createAggressiveDCEPass()); // Delete dead instructions
347 PM->add(createCFGSimplificationPass()); // Merge & remove BBs
348
349 if (CompileOpts.UnitAtATime) {
350 PM->add(createStripDeadPrototypesPass()); // Get rid of dead prototypes
351 PM->add(createDeadTypeEliminationPass()); // Eliminate dead types
352 }
353
354 if (CompileOpts.OptimizationLevel > 1 && CompileOpts.UnitAtATime)
355 PM->add(createConstantMergePass()); // Merge dup global constants
356 } else {
Daniel Dunbar160cb622008-11-13 05:29:02 +0000357 PM->add(createAlwaysInlinerPass());
Daniel Dunbaraa7a0662008-10-23 05:50:47 +0000358 }
Daniel Dunbar85e44e22008-10-21 23:49:24 +0000359}
360
361/// EmitAssembly - Handle interaction with LLVM backend to generate
362/// actual machine code.
363void BackendConsumer::EmitAssembly() {
364 // Silently ignore if we weren't initialized for some reason.
365 if (!TheModule || !TheTargetData)
366 return;
Chris Lattner2193db22009-02-18 01:37:30 +0000367
Chris Lattner908789c2009-02-18 18:22:50 +0000368
Chris Lattner908789c2009-02-18 18:22:50 +0000369 TimeRegion Region(CompileOpts.TimePasses ? &CodeGenerationTime : 0);
Daniel Dunbar85e44e22008-10-21 23:49:24 +0000370
Daniel Dunbarbc147792008-10-27 20:40:41 +0000371 // Make sure IR generation is happy with the module. This is
372 // released by the module provider.
Daniel Dunbar85e44e22008-10-21 23:49:24 +0000373 Module *M = Gen->ReleaseModule();
374 if (!M) {
Daniel Dunbarbc147792008-10-27 20:40:41 +0000375 // The module has been released by IR gen on failures, do not
376 // double free.
377 ModuleProvider->releaseModule();
Daniel Dunbar85e44e22008-10-21 23:49:24 +0000378 TheModule = 0;
379 return;
380 }
381
382 assert(TheModule == M && "Unexpected module change during IR generation");
383
384 CreatePasses();
385
386 std::string Error;
Daniel Dunbar655d5092008-10-23 05:59:43 +0000387 if (!AddEmitPasses(Error)) {
Daniel Dunbar85e44e22008-10-21 23:49:24 +0000388 // FIXME: Don't fail this way.
389 llvm::cerr << "ERROR: " << Error << "\n";
390 ::exit(1);
391 }
392
393 // Run passes. For now we do all passes at once, but eventually we
394 // would like to have the option of streaming code generation.
395
396 if (PerFunctionPasses) {
Chris Lattner4e164172009-03-06 06:46:31 +0000397 PrettyStackTraceString CrashInfo("Per-function optimization");
Chris Lattnerc309ade2009-03-05 08:00:35 +0000398
Daniel Dunbar85e44e22008-10-21 23:49:24 +0000399 PerFunctionPasses->doInitialization();
400 for (Module::iterator I = M->begin(), E = M->end(); I != E; ++I)
401 if (!I->isDeclaration())
402 PerFunctionPasses->run(*I);
403 PerFunctionPasses->doFinalization();
404 }
405
Chris Lattnerc309ade2009-03-05 08:00:35 +0000406 if (PerModulePasses) {
Chris Lattner4e164172009-03-06 06:46:31 +0000407 PrettyStackTraceString CrashInfo("Per-module optimization passes");
Daniel Dunbar85e44e22008-10-21 23:49:24 +0000408 PerModulePasses->run(*M);
Chris Lattnerc309ade2009-03-05 08:00:35 +0000409 }
Daniel Dunbar85e44e22008-10-21 23:49:24 +0000410
411 if (CodeGenPasses) {
Chris Lattner4e164172009-03-06 06:46:31 +0000412 PrettyStackTraceString CrashInfo("Code generation");
Daniel Dunbar85e44e22008-10-21 23:49:24 +0000413 CodeGenPasses->doInitialization();
414 for (Module::iterator I = M->begin(), E = M->end(); I != E; ++I)
415 if (!I->isDeclaration())
416 CodeGenPasses->run(*I);
417 CodeGenPasses->doFinalization();
418 }
419}
420
421ASTConsumer *clang::CreateBackendConsumer(BackendAction Action,
422 Diagnostic &Diags,
Daniel Dunbar9101a632009-02-17 19:47:34 +0000423 const LangOptions &LangOpts,
Daniel Dunbaraa7a0662008-10-23 05:50:47 +0000424 const CompileOptions &CompileOpts,
Daniel Dunbar85e44e22008-10-21 23:49:24 +0000425 const std::string& InFile,
Chris Lattner88cbb9b2009-03-09 22:00:34 +0000426 const std::string& OutFile) {
Chris Lattner57ff05c2009-02-12 01:50:58 +0000427 // FIXME: If optimizing, disable all debug info generation. The LLVM
428 // optimizer and backend is not ready to handle it when optimizations
429 // are enabled.
430 if (CompileOpts.OptimizationLevel > 0)
Chris Lattner88cbb9b2009-03-09 22:00:34 +0000431 const_cast<CompileOptions&>(CompileOpts).DebugInfo = false;
Daniel Dunbar9101a632009-02-17 19:47:34 +0000432
433 return new BackendConsumer(Action, Diags, LangOpts, CompileOpts,
Chris Lattner88cbb9b2009-03-09 22:00:34 +0000434 InFile, OutFile);
Daniel Dunbar85e44e22008-10-21 23:49:24 +0000435}