blob: 13aecf171718e29d9dcba0eb45d5d6472df848ae [file] [log] [blame]
Daniel Dunbard69bacc2008-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
Eli Friedman39d7c4d2009-05-18 22:50:54 +000010#include "clang/Frontend/ASTConsumers.h"
Daniel Dunbard69bacc2008-10-21 23:49:24 +000011#include "clang/CodeGen/ModuleBuilder.h"
Daniel Dunbare1bd4e62009-03-02 06:16:29 +000012#include "clang/Frontend/CompileOptions.h"
Chris Lattner682bf922009-03-29 16:50:03 +000013#include "clang/AST/ASTContext.h"
14#include "clang/AST/ASTConsumer.h"
15#include "clang/AST/DeclGroup.h"
16#include "clang/Basic/TargetInfo.h"
Daniel Dunbard69bacc2008-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 Dunbar70f92432008-10-23 05:50:47 +000022#include "llvm/Analysis/CallGraph.h"
23#include "llvm/Analysis/Verifier.h"
Daniel Dunbard69bacc2008-10-21 23:49:24 +000024#include "llvm/Bitcode/ReaderWriter.h"
25#include "llvm/CodeGen/RegAllocRegistry.h"
26#include "llvm/CodeGen/SchedulerRegistry.h"
Daniel Dunbard69bacc2008-10-21 23:49:24 +000027#include "llvm/Support/Compiler.h"
Chris Lattner03eacc72009-07-14 20:39:15 +000028#include "llvm/Support/FormattedStream.h"
Daniel Dunbar10d861e2009-06-03 18:01:18 +000029#include "llvm/Support/StandardPasses.h"
Chris Lattner6f114eb2009-02-18 01:37:30 +000030#include "llvm/Support/Timer.h"
Daniel Dunbard69bacc2008-10-21 23:49:24 +000031#include "llvm/System/Path.h"
32#include "llvm/System/Program.h"
Daniel Dunbara034ba82009-02-17 19:47:34 +000033#include "llvm/Target/SubtargetFeature.h"
Daniel Dunbard69bacc2008-10-21 23:49:24 +000034#include "llvm/Target/TargetData.h"
35#include "llvm/Target/TargetMachine.h"
Daniel Dunbarf7d47c02009-07-15 20:25:38 +000036#include "llvm/Target/TargetRegistry.h"
Daniel Dunbard69bacc2008-10-21 23:49:24 +000037using namespace clang;
38using namespace llvm;
39
40namespace {
Chris Lattner49f28ca2009-03-05 08:00:35 +000041 class VISIBILITY_HIDDEN BackendConsumer : public ASTConsumer {
Daniel Dunbard69bacc2008-10-21 23:49:24 +000042 BackendAction Action;
Daniel Dunbar70f92432008-10-23 05:50:47 +000043 CompileOptions CompileOpts;
Eli Friedman66d6f042009-05-18 22:20:00 +000044 llvm::raw_ostream *AsmOutStream;
Chris Lattner03eacc72009-07-14 20:39:15 +000045 llvm::formatted_raw_ostream FormattedOutStream;
Chris Lattner49f28ca2009-03-05 08:00:35 +000046 ASTContext *Context;
Daniel Dunbar90f41302008-10-29 08:50:02 +000047
Chris Lattner6f114eb2009-02-18 01:37:30 +000048 Timer LLVMIRGeneration;
49 Timer CodeGenerationTime;
Mike Stump1eb44332009-09-09 15:08:12 +000050
Daniel Dunbard69bacc2008-10-21 23:49:24 +000051 llvm::OwningPtr<CodeGenerator> Gen;
Mike Stump1eb44332009-09-09 15:08:12 +000052
Daniel Dunbard69bacc2008-10-21 23:49:24 +000053 llvm::Module *TheModule;
54 llvm::TargetData *TheTargetData;
Daniel Dunbard69bacc2008-10-21 23:49:24 +000055
Nuno Lopesdd492672008-10-24 22:51:00 +000056 mutable llvm::ModuleProvider *ModuleProvider;
Daniel Dunbard69bacc2008-10-21 23:49:24 +000057 mutable FunctionPassManager *CodeGenPasses;
58 mutable PassManager *PerModulePasses;
59 mutable FunctionPassManager *PerFunctionPasses;
60
61 FunctionPassManager *getCodeGenPasses() const;
62 PassManager *getPerModulePasses() const;
63 FunctionPassManager *getPerFunctionPasses() const;
64
65 void CreatePasses();
66
67 /// AddEmitPasses - Add passes necessary to emit assembly or LLVM
68 /// IR.
69 ///
Daniel Dunbard69bacc2008-10-21 23:49:24 +000070 /// \return True on success. On failure \arg Error will be set to
71 /// a user readable error message.
Daniel Dunbar4c877cc2008-10-23 05:59:43 +000072 bool AddEmitPasses(std::string &Error);
Daniel Dunbard69bacc2008-10-21 23:49:24 +000073
74 void EmitAssembly();
Mike Stump1eb44332009-09-09 15:08:12 +000075
76 public:
77 BackendConsumer(BackendAction action, Diagnostic &Diags,
Daniel Dunbara034ba82009-02-17 19:47:34 +000078 const LangOptions &langopts, const CompileOptions &compopts,
Owen Anderson42253cc2009-07-01 17:00:06 +000079 const std::string &infile, llvm::raw_ostream* OS,
Owen Anderson8f1ca782009-07-01 23:14:14 +000080 LLVMContext& C) :
Mike Stump1eb44332009-09-09 15:08:12 +000081 Action(action),
Daniel Dunbar70f92432008-10-23 05:50:47 +000082 CompileOpts(compopts),
Chris Lattner03eacc72009-07-14 20:39:15 +000083 AsmOutStream(OS),
Chris Lattner6f114eb2009-02-18 01:37:30 +000084 LLVMIRGeneration("LLVM IR Generation Time"),
85 CodeGenerationTime("Code Generation Time"),
Owen Anderson42253cc2009-07-01 17:00:06 +000086 Gen(CreateLLVMCodeGen(Diags, infile, compopts, C)),
Eli Friedman66d6f042009-05-18 22:20:00 +000087 TheModule(0), TheTargetData(0), ModuleProvider(0),
Chris Lattner44502662009-02-18 01:23:44 +000088 CodeGenPasses(0), PerModulePasses(0), PerFunctionPasses(0) {
Mike Stump1eb44332009-09-09 15:08:12 +000089
Chris Lattner03eacc72009-07-14 20:39:15 +000090 if (AsmOutStream)
91 FormattedOutStream.setStream(*AsmOutStream,
92 formatted_raw_ostream::PRESERVE_STREAM);
Mike Stump1eb44332009-09-09 15:08:12 +000093
Chris Lattner6f114eb2009-02-18 01:37:30 +000094 // Enable -time-passes if -ftime-report is enabled.
Chris Lattner44502662009-02-18 01:23:44 +000095 llvm::TimePassesIsEnabled = CompileOpts.TimePasses;
96 }
Daniel Dunbard69bacc2008-10-21 23:49:24 +000097
98 ~BackendConsumer() {
Daniel Dunbard69bacc2008-10-21 23:49:24 +000099 delete TheTargetData;
Nuno Lopesdd492672008-10-24 22:51:00 +0000100 delete ModuleProvider;
Daniel Dunbard69bacc2008-10-21 23:49:24 +0000101 delete CodeGenPasses;
102 delete PerModulePasses;
103 delete PerFunctionPasses;
104 }
105
Chris Lattner7bb0da02009-03-28 02:18:25 +0000106 virtual void Initialize(ASTContext &Ctx) {
107 Context = &Ctx;
Mike Stump1eb44332009-09-09 15:08:12 +0000108
Chris Lattner6f114eb2009-02-18 01:37:30 +0000109 if (CompileOpts.TimePasses)
110 LLVMIRGeneration.startTimer();
Mike Stump1eb44332009-09-09 15:08:12 +0000111
Chris Lattner7bb0da02009-03-28 02:18:25 +0000112 Gen->Initialize(Ctx);
Daniel Dunbard69bacc2008-10-21 23:49:24 +0000113
114 TheModule = Gen->GetModule();
Nuno Lopes7d43a312008-10-24 23:27:18 +0000115 ModuleProvider = new ExistingModuleProvider(TheModule);
Chris Lattner7bb0da02009-03-28 02:18:25 +0000116 TheTargetData = new llvm::TargetData(Ctx.Target.getTargetDescription());
Mike Stump1eb44332009-09-09 15:08:12 +0000117
Chris Lattner6f114eb2009-02-18 01:37:30 +0000118 if (CompileOpts.TimePasses)
119 LLVMIRGeneration.stopTimer();
Daniel Dunbard69bacc2008-10-21 23:49:24 +0000120 }
Mike Stump1eb44332009-09-09 15:08:12 +0000121
Chris Lattner682bf922009-03-29 16:50:03 +0000122 virtual void HandleTopLevelDecl(DeclGroupRef D) {
123 PrettyStackTraceDecl CrashInfo(*D.begin(), SourceLocation(),
Chris Lattner49f28ca2009-03-05 08:00:35 +0000124 Context->getSourceManager(),
125 "LLVM IR generation of declaration");
Mike Stump1eb44332009-09-09 15:08:12 +0000126
Chris Lattner6f114eb2009-02-18 01:37:30 +0000127 if (CompileOpts.TimePasses)
128 LLVMIRGeneration.startTimer();
Chris Lattner682bf922009-03-29 16:50:03 +0000129
Daniel Dunbard69bacc2008-10-21 23:49:24 +0000130 Gen->HandleTopLevelDecl(D);
Chris Lattner6f114eb2009-02-18 01:37:30 +0000131
132 if (CompileOpts.TimePasses)
133 LLVMIRGeneration.stopTimer();
Daniel Dunbard69bacc2008-10-21 23:49:24 +0000134 }
Mike Stump1eb44332009-09-09 15:08:12 +0000135
Chris Lattnerdacbc5d2009-03-28 04:11:33 +0000136 virtual void HandleTranslationUnit(ASTContext &C) {
Chris Lattner49f28ca2009-03-05 08:00:35 +0000137 {
Chris Lattner14f234e2009-03-06 06:46:31 +0000138 PrettyStackTraceString CrashInfo("Per-file LLVM IR generation");
Chris Lattner49f28ca2009-03-05 08:00:35 +0000139 if (CompileOpts.TimePasses)
140 LLVMIRGeneration.startTimer();
Chris Lattner6f114eb2009-02-18 01:37:30 +0000141
Chris Lattnerdacbc5d2009-03-28 04:11:33 +0000142 Gen->HandleTranslationUnit(C);
Daniel Dunbard68ba0e2008-11-11 06:35:39 +0000143
Chris Lattner49f28ca2009-03-05 08:00:35 +0000144 if (CompileOpts.TimePasses)
145 LLVMIRGeneration.stopTimer();
146 }
Chris Lattner6f114eb2009-02-18 01:37:30 +0000147
Chris Lattner49f28ca2009-03-05 08:00:35 +0000148 // EmitAssembly times and registers crash info itself.
Chris Lattner6f114eb2009-02-18 01:37:30 +0000149 EmitAssembly();
Mike Stump1eb44332009-09-09 15:08:12 +0000150
Daniel Dunbard68ba0e2008-11-11 06:35:39 +0000151 // Force a flush here in case we never get released.
152 if (AsmOutStream)
Chris Lattner03eacc72009-07-14 20:39:15 +0000153 FormattedOutStream.flush();
Daniel Dunbard69bacc2008-10-21 23:49:24 +0000154 }
Mike Stump1eb44332009-09-09 15:08:12 +0000155
Daniel Dunbard69bacc2008-10-21 23:49:24 +0000156 virtual void HandleTagDeclDefinition(TagDecl *D) {
Chris Lattner49f28ca2009-03-05 08:00:35 +0000157 PrettyStackTraceDecl CrashInfo(D, SourceLocation(),
158 Context->getSourceManager(),
159 "LLVM IR generation of declaration");
Daniel Dunbard69bacc2008-10-21 23:49:24 +0000160 Gen->HandleTagDeclDefinition(D);
161 }
Douglas Gregorb6c8c8b2009-04-21 17:11:58 +0000162
163 virtual void CompleteTentativeDefinition(VarDecl *D) {
164 Gen->CompleteTentativeDefinition(D);
165 }
Mike Stump1eb44332009-09-09 15:08:12 +0000166 };
Daniel Dunbard69bacc2008-10-21 23:49:24 +0000167}
168
169FunctionPassManager *BackendConsumer::getCodeGenPasses() const {
170 if (!CodeGenPasses) {
Nuno Lopesdd492672008-10-24 22:51:00 +0000171 CodeGenPasses = new FunctionPassManager(ModuleProvider);
Daniel Dunbard69bacc2008-10-21 23:49:24 +0000172 CodeGenPasses->add(new TargetData(*TheTargetData));
173 }
174
175 return CodeGenPasses;
176}
177
178PassManager *BackendConsumer::getPerModulePasses() const {
179 if (!PerModulePasses) {
180 PerModulePasses = new PassManager();
181 PerModulePasses->add(new TargetData(*TheTargetData));
182 }
183
184 return PerModulePasses;
185}
186
187FunctionPassManager *BackendConsumer::getPerFunctionPasses() const {
188 if (!PerFunctionPasses) {
Nuno Lopes7d43a312008-10-24 23:27:18 +0000189 PerFunctionPasses = new FunctionPassManager(ModuleProvider);
Daniel Dunbard69bacc2008-10-21 23:49:24 +0000190 PerFunctionPasses->add(new TargetData(*TheTargetData));
191 }
192
193 return PerFunctionPasses;
194}
195
Daniel Dunbar4c877cc2008-10-23 05:59:43 +0000196bool BackendConsumer::AddEmitPasses(std::string &Error) {
Daniel Dunbare8e26002009-02-26 22:39:37 +0000197 if (Action == Backend_EmitNothing)
198 return true;
199
Daniel Dunbard69bacc2008-10-21 23:49:24 +0000200 if (Action == Backend_EmitBC) {
Dan Gohmanb8d42392009-09-26 15:06:14 +0000201 getPerModulePasses()->add(createBitcodeWriterPass(FormattedOutStream));
Daniel Dunbard69bacc2008-10-21 23:49:24 +0000202 } else if (Action == Backend_EmitLL) {
Dan Gohmanb8d42392009-09-26 15:06:14 +0000203 getPerModulePasses()->add(createPrintModulePass(&FormattedOutStream));
Daniel Dunbard69bacc2008-10-21 23:49:24 +0000204 } else {
Daniel Dunbar4c877cc2008-10-23 05:59:43 +0000205 bool Fast = CompileOpts.OptimizationLevel == 0;
206
Daniel Dunbar8b7650e2008-10-22 18:29:51 +0000207 // Create the TargetMachine for generating code.
Daniel Dunbar82cfa7a2009-07-26 01:27:26 +0000208 std::string Triple = TheModule->getTargetTriple();
Daniel Dunbar9ab76fa2009-08-03 04:21:41 +0000209 const llvm::Target *TheTarget = TargetRegistry::lookupTarget(Triple, Error);
Daniel Dunbarf7d47c02009-07-15 20:25:38 +0000210 if (!TheTarget) {
Daniel Dunbar8b7650e2008-10-22 18:29:51 +0000211 Error = std::string("Unable to get target machine: ") + Error;
212 return false;
213 }
Daniel Dunbara034ba82009-02-17 19:47:34 +0000214
215 std::string FeaturesStr;
216 if (CompileOpts.CPU.size() || CompileOpts.Features.size()) {
217 SubtargetFeatures Features;
218 Features.setCPU(CompileOpts.CPU);
Mike Stump1eb44332009-09-09 15:08:12 +0000219 for (std::vector<std::string>::iterator
Daniel Dunbara034ba82009-02-17 19:47:34 +0000220 it = CompileOpts.Features.begin(),
221 ie = CompileOpts.Features.end(); it != ie; ++it)
222 Features.AddFeature(*it);
223 FeaturesStr = Features.getString();
224 }
Daniel Dunbar2b1f59f2009-08-04 04:02:57 +0000225 TargetMachine *TM = TheTarget->createTargetMachine(Triple, FeaturesStr);
Mike Stump1eb44332009-09-09 15:08:12 +0000226
Daniel Dunbar8b7650e2008-10-22 18:29:51 +0000227 // Set register scheduler & allocation policy.
228 RegisterScheduler::setDefault(createDefaultScheduler);
Mike Stump1eb44332009-09-09 15:08:12 +0000229 RegisterRegAlloc::setDefault(Fast ? createLocalRegisterAllocator :
230 createLinearScanRegisterAllocator);
Daniel Dunbar8b7650e2008-10-22 18:29:51 +0000231
Daniel Dunbard69bacc2008-10-21 23:49:24 +0000232 // From llvm-gcc:
233 // If there are passes we have to run on the entire module, we do codegen
234 // as a separate "pass" after that happens.
235 // FIXME: This is disabled right now until bugs can be worked out. Reenable
236 // this for fast -O0 compiles!
237 FunctionPassManager *PM = getCodeGenPasses();
Bill Wendling6e9b8f62009-04-29 23:53:23 +0000238 CodeGenOpt::Level OptLevel = CodeGenOpt::Default;
239
240 switch (CompileOpts.OptimizationLevel) {
241 default: break;
242 case 0: OptLevel = CodeGenOpt::None; break;
Bill Wendling6e9b8f62009-04-29 23:53:23 +0000243 case 3: OptLevel = CodeGenOpt::Aggressive; break;
244 }
245
Daniel Dunbard69bacc2008-10-21 23:49:24 +0000246 // Normal mode, emit a .s file by running the code generator.
247 // Note, this also adds codegenerator level optimization passes.
Chris Lattner03eacc72009-07-14 20:39:15 +0000248 switch (TM->addPassesToEmitFile(*PM, FormattedOutStream,
Bill Wendling6e9b8f62009-04-29 23:53:23 +0000249 TargetMachine::AssemblyFile, OptLevel)) {
Daniel Dunbard69bacc2008-10-21 23:49:24 +0000250 default:
251 case FileModel::Error:
252 Error = "Unable to interface with target machine!\n";
253 return false;
254 case FileModel::AsmFile:
255 break;
256 }
Mike Stump1eb44332009-09-09 15:08:12 +0000257
Duncan Sands813a2bb2009-05-31 04:09:57 +0000258 if (TM->addPassesToEmitFileFinish(*CodeGenPasses, (MachineCodeEmitter *)0,
259 OptLevel)) {
Daniel Dunbard69bacc2008-10-21 23:49:24 +0000260 Error = "Unable to interface with target machine!\n";
261 return false;
262 }
263 }
264
265 return true;
266}
267
268void BackendConsumer::CreatePasses() {
Daniel Dunbar70f92432008-10-23 05:50:47 +0000269 // In -O0 if checking is disabled, we don't even have per-function passes.
270 if (CompileOpts.VerifyModule)
271 getPerFunctionPasses()->add(createVerifierPass());
272
Daniel Dunbar10d861e2009-06-03 18:01:18 +0000273 // Assume that standard function passes aren't run for -O0.
274 if (CompileOpts.OptimizationLevel > 0)
275 llvm::createStandardFunctionPasses(getPerFunctionPasses(),
276 CompileOpts.OptimizationLevel);
277
278 llvm::Pass *InliningPass = 0;
279 switch (CompileOpts.Inlining) {
280 case CompileOptions::NoInlining: break;
Eli Friedmanb9b7dd62009-06-11 20:33:41 +0000281 case CompileOptions::NormalInlining: {
282 // Inline small functions
283 unsigned Threshold = (CompileOpts.OptimizeSize ||
284 CompileOpts.OptimizationLevel < 3) ? 50 : 200;
285 InliningPass = createFunctionInliningPass(Threshold);
Daniel Dunbar10d861e2009-06-03 18:01:18 +0000286 break;
Eli Friedmanb9b7dd62009-06-11 20:33:41 +0000287 }
Daniel Dunbar10d861e2009-06-03 18:01:18 +0000288 case CompileOptions::OnlyAlwaysInlining:
289 InliningPass = createAlwaysInlinerPass(); // Respect always_inline
290 break;
Daniel Dunbar70f92432008-10-23 05:50:47 +0000291 }
292
293 // For now we always create per module passes.
294 PassManager *PM = getPerModulePasses();
Mike Stump1eb44332009-09-09 15:08:12 +0000295 llvm::createStandardModulePasses(PM, CompileOpts.OptimizationLevel,
296 CompileOpts.OptimizeSize,
Daniel Dunbar10d861e2009-06-03 18:01:18 +0000297 CompileOpts.UnitAtATime,
298 CompileOpts.UnrollLoops,
299 CompileOpts.SimplifyLibCalls,
300 /*HaveExceptions=*/true,
301 InliningPass);
Daniel Dunbard69bacc2008-10-21 23:49:24 +0000302}
303
304/// EmitAssembly - Handle interaction with LLVM backend to generate
Mike Stump1eb44332009-09-09 15:08:12 +0000305/// actual machine code.
Daniel Dunbard69bacc2008-10-21 23:49:24 +0000306void BackendConsumer::EmitAssembly() {
307 // Silently ignore if we weren't initialized for some reason.
308 if (!TheModule || !TheTargetData)
309 return;
Mike Stump1eb44332009-09-09 15:08:12 +0000310
Chris Lattner8b76c0d2009-02-18 18:22:50 +0000311 TimeRegion Region(CompileOpts.TimePasses ? &CodeGenerationTime : 0);
Daniel Dunbard69bacc2008-10-21 23:49:24 +0000312
Daniel Dunbard611bac2008-10-27 20:40:41 +0000313 // Make sure IR generation is happy with the module. This is
314 // released by the module provider.
Daniel Dunbard69bacc2008-10-21 23:49:24 +0000315 Module *M = Gen->ReleaseModule();
316 if (!M) {
Daniel Dunbard611bac2008-10-27 20:40:41 +0000317 // The module has been released by IR gen on failures, do not
318 // double free.
319 ModuleProvider->releaseModule();
Daniel Dunbard69bacc2008-10-21 23:49:24 +0000320 TheModule = 0;
321 return;
322 }
323
324 assert(TheModule == M && "Unexpected module change during IR generation");
325
326 CreatePasses();
327
328 std::string Error;
Daniel Dunbar4c877cc2008-10-23 05:59:43 +0000329 if (!AddEmitPasses(Error)) {
Daniel Dunbard69bacc2008-10-21 23:49:24 +0000330 // FIXME: Don't fail this way.
Chris Lattnera85b3522009-08-23 05:57:09 +0000331 llvm::errs() << "ERROR: " << Error << "\n";
Daniel Dunbard69bacc2008-10-21 23:49:24 +0000332 ::exit(1);
333 }
334
335 // Run passes. For now we do all passes at once, but eventually we
336 // would like to have the option of streaming code generation.
337
338 if (PerFunctionPasses) {
Chris Lattner14f234e2009-03-06 06:46:31 +0000339 PrettyStackTraceString CrashInfo("Per-function optimization");
Mike Stump1eb44332009-09-09 15:08:12 +0000340
Daniel Dunbard69bacc2008-10-21 23:49:24 +0000341 PerFunctionPasses->doInitialization();
342 for (Module::iterator I = M->begin(), E = M->end(); I != E; ++I)
343 if (!I->isDeclaration())
344 PerFunctionPasses->run(*I);
345 PerFunctionPasses->doFinalization();
346 }
Mike Stump1eb44332009-09-09 15:08:12 +0000347
Chris Lattner49f28ca2009-03-05 08:00:35 +0000348 if (PerModulePasses) {
Chris Lattner14f234e2009-03-06 06:46:31 +0000349 PrettyStackTraceString CrashInfo("Per-module optimization passes");
Daniel Dunbard69bacc2008-10-21 23:49:24 +0000350 PerModulePasses->run(*M);
Chris Lattner49f28ca2009-03-05 08:00:35 +0000351 }
Mike Stump1eb44332009-09-09 15:08:12 +0000352
Daniel Dunbard69bacc2008-10-21 23:49:24 +0000353 if (CodeGenPasses) {
Chris Lattner14f234e2009-03-06 06:46:31 +0000354 PrettyStackTraceString CrashInfo("Code generation");
Daniel Dunbard69bacc2008-10-21 23:49:24 +0000355 CodeGenPasses->doInitialization();
356 for (Module::iterator I = M->begin(), E = M->end(); I != E; ++I)
357 if (!I->isDeclaration())
358 CodeGenPasses->run(*I);
359 CodeGenPasses->doFinalization();
360 }
361}
362
363ASTConsumer *clang::CreateBackendConsumer(BackendAction Action,
364 Diagnostic &Diags,
Daniel Dunbara034ba82009-02-17 19:47:34 +0000365 const LangOptions &LangOpts,
Daniel Dunbar70f92432008-10-23 05:50:47 +0000366 const CompileOptions &CompileOpts,
Daniel Dunbard69bacc2008-10-21 23:49:24 +0000367 const std::string& InFile,
Owen Anderson42253cc2009-07-01 17:00:06 +0000368 llvm::raw_ostream* OS,
Owen Anderson8f1ca782009-07-01 23:14:14 +0000369 LLVMContext& C) {
Owen Anderson42253cc2009-07-01 17:00:06 +0000370 return new BackendConsumer(Action, Diags, LangOpts, CompileOpts,
371 InFile, OS, C);
Daniel Dunbard69bacc2008-10-21 23:49:24 +0000372}