1 //===--- BackendUtil.cpp - LLVM Backend Utilities -------------------------===// 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 "clang/CodeGen/BackendUtil.h" 11 #include "clang/Basic/Diagnostic.h" 12 #include "clang/Basic/LangOptions.h" 13 #include "clang/Basic/TargetOptions.h" 14 #include "clang/Frontend/CodeGenOptions.h" 15 #include "clang/Frontend/FrontendDiagnostic.h" 16 #include "llvm/Analysis/Verifier.h" 17 #include "llvm/Assembly/PrintModulePass.h" 18 #include "llvm/Bitcode/ReaderWriter.h" 19 #include "llvm/CodeGen/RegAllocRegistry.h" 20 #include "llvm/CodeGen/SchedulerRegistry.h" 21 #include "llvm/DataLayout.h" 22 #include "llvm/MC/SubtargetFeature.h" 23 #include "llvm/Module.h" 24 #include "llvm/PassManager.h" 25 #include "llvm/TargetTransformInfo.h" 26 #include "llvm/Support/CommandLine.h" 27 #include "llvm/Support/FormattedStream.h" 28 #include "llvm/Support/PrettyStackTrace.h" 29 #include "llvm/Support/TargetRegistry.h" 30 #include "llvm/Support/Timer.h" 31 #include "llvm/Support/raw_ostream.h" 32 #include "llvm/Target/TargetLibraryInfo.h" 33 #include "llvm/Target/TargetMachine.h" 34 #include "llvm/Target/TargetOptions.h" 35 #include "llvm/Transforms/IPO.h" 36 #include "llvm/Transforms/IPO/PassManagerBuilder.h" 37 #include "llvm/Transforms/Instrumentation.h" 38 #include "llvm/Transforms/Scalar.h" 39 using namespace clang; 40 using namespace llvm; 41 42 namespace { 43 44 class EmitAssemblyHelper { 45 DiagnosticsEngine &Diags; 46 const CodeGenOptions &CodeGenOpts; 47 const clang::TargetOptions &TargetOpts; 48 const LangOptions &LangOpts; 49 Module *TheModule; 50 51 Timer CodeGenerationTime; 52 53 mutable PassManager *CodeGenPasses; 54 mutable PassManager *PerModulePasses; 55 mutable FunctionPassManager *PerFunctionPasses; 56 57 private: 58 PassManager *getCodeGenPasses(TargetMachine *TM) const { 59 if (!CodeGenPasses) { 60 CodeGenPasses = new PassManager(); 61 CodeGenPasses->add(new DataLayout(TheModule)); 62 // Add TargetTransformInfo. 63 if (TM) { 64 TargetTransformInfo *TTI = 65 new TargetTransformInfo(TM->getScalarTargetTransformInfo(), 66 TM->getVectorTargetTransformInfo()); 67 CodeGenPasses->add(TTI); 68 } 69 } 70 return CodeGenPasses; 71 } 72 73 PassManager *getPerModulePasses(TargetMachine *TM) const { 74 if (!PerModulePasses) { 75 PerModulePasses = new PassManager(); 76 PerModulePasses->add(new DataLayout(TheModule)); 77 if (TM) { 78 TargetTransformInfo *TTI = 79 new TargetTransformInfo(TM->getScalarTargetTransformInfo(), 80 TM->getVectorTargetTransformInfo()); 81 PerModulePasses->add(TTI); 82 } 83 } 84 return PerModulePasses; 85 } 86 87 FunctionPassManager *getPerFunctionPasses(TargetMachine *TM) const { 88 if (!PerFunctionPasses) { 89 PerFunctionPasses = new FunctionPassManager(TheModule); 90 PerFunctionPasses->add(new DataLayout(TheModule)); 91 if (TM) { 92 TargetTransformInfo *TTI = 93 new TargetTransformInfo(TM->getScalarTargetTransformInfo(), 94 TM->getVectorTargetTransformInfo()); 95 PerFunctionPasses->add(TTI); 96 } 97 } 98 return PerFunctionPasses; 99 } 100 101 102 void CreatePasses(TargetMachine *TM); 103 104 /// CreateTargetMachine - Generates the TargetMachine. 105 /// Returns Null if it is unable to create the target machine. 106 /// Some of our clang tests specify triples which are not built 107 /// into clang. This is okay because these tests check the generated 108 /// IR, and they require DataLayout which depends on the triple. 109 /// In this case, we allow this method to fail and not report an error. 110 /// When MustCreateTM is used, we print an error if we are unable to load 111 /// the requested target. 112 TargetMachine *CreateTargetMachine(bool MustCreateTM); 113 114 /// AddEmitPasses - Add passes necessary to emit assembly or LLVM IR. 115 /// 116 /// \return True on success. 117 bool AddEmitPasses(BackendAction Action, formatted_raw_ostream &OS, 118 TargetMachine *TM); 119 120 public: 121 EmitAssemblyHelper(DiagnosticsEngine &_Diags, 122 const CodeGenOptions &CGOpts, 123 const clang::TargetOptions &TOpts, 124 const LangOptions &LOpts, 125 Module *M) 126 : Diags(_Diags), CodeGenOpts(CGOpts), TargetOpts(TOpts), LangOpts(LOpts), 127 TheModule(M), CodeGenerationTime("Code Generation Time"), 128 CodeGenPasses(0), PerModulePasses(0), PerFunctionPasses(0) {} 129 130 ~EmitAssemblyHelper() { 131 delete CodeGenPasses; 132 delete PerModulePasses; 133 delete PerFunctionPasses; 134 } 135 136 void EmitAssembly(BackendAction Action, raw_ostream *OS); 137 }; 138 139 // We need this wrapper to access LangOpts from extension functions that 140 // we add to the PassManagerBuilder. 141 class PassManagerBuilderWrapper : public PassManagerBuilder { 142 public: 143 PassManagerBuilderWrapper(const CodeGenOptions &CGOpts, 144 const LangOptions &LangOpts) 145 : PassManagerBuilder(), CGOpts(CGOpts), LangOpts(LangOpts) {} 146 const CodeGenOptions &getCGOpts() const { return CGOpts; } 147 const LangOptions &getLangOpts() const { return LangOpts; } 148 private: 149 const CodeGenOptions &CGOpts; 150 const LangOptions &LangOpts; 151 }; 152 153 } 154 155 static void addObjCARCAPElimPass(const PassManagerBuilder &Builder, PassManagerBase &PM) { 156 if (Builder.OptLevel > 0) 157 PM.add(createObjCARCAPElimPass()); 158 } 159 160 static void addObjCARCExpandPass(const PassManagerBuilder &Builder, PassManagerBase &PM) { 161 if (Builder.OptLevel > 0) 162 PM.add(createObjCARCExpandPass()); 163 } 164 165 static void addObjCARCOptPass(const PassManagerBuilder &Builder, PassManagerBase &PM) { 166 if (Builder.OptLevel > 0) 167 PM.add(createObjCARCOptPass()); 168 } 169 170 static void addBoundsCheckingPass(const PassManagerBuilder &Builder, 171 PassManagerBase &PM) { 172 PM.add(createBoundsCheckingPass()); 173 } 174 175 static void addAddressSanitizerPasses(const PassManagerBuilder &Builder, 176 PassManagerBase &PM) { 177 const PassManagerBuilderWrapper &BuilderWrapper = 178 static_cast<const PassManagerBuilderWrapper&>(Builder); 179 const CodeGenOptions &CGOpts = BuilderWrapper.getCGOpts(); 180 const LangOptions &LangOpts = BuilderWrapper.getLangOpts(); 181 PM.add(createAddressSanitizerFunctionPass(LangOpts.SanitizeInitOrder, 182 LangOpts.SanitizeUseAfterReturn, 183 LangOpts.SanitizeUseAfterScope, 184 CGOpts.SanitizerBlacklistFile)); 185 PM.add(createAddressSanitizerModulePass(LangOpts.SanitizeInitOrder, 186 CGOpts.SanitizerBlacklistFile)); 187 } 188 189 static void addMemorySanitizerPass(const PassManagerBuilder &Builder, 190 PassManagerBase &PM) { 191 PM.add(createMemorySanitizerPass()); 192 } 193 194 static void addThreadSanitizerPass(const PassManagerBuilder &Builder, 195 PassManagerBase &PM) { 196 PM.add(createThreadSanitizerPass()); 197 } 198 199 void EmitAssemblyHelper::CreatePasses(TargetMachine *TM) { 200 unsigned OptLevel = CodeGenOpts.OptimizationLevel; 201 CodeGenOptions::InliningMethod Inlining = CodeGenOpts.getInlining(); 202 203 // Handle disabling of LLVM optimization, where we want to preserve the 204 // internal module before any optimization. 205 if (CodeGenOpts.DisableLLVMOpts) { 206 OptLevel = 0; 207 Inlining = CodeGenOpts.NoInlining; 208 } 209 210 PassManagerBuilderWrapper PMBuilder(CodeGenOpts, LangOpts); 211 PMBuilder.OptLevel = OptLevel; 212 PMBuilder.SizeLevel = CodeGenOpts.OptimizeSize; 213 214 PMBuilder.DisableSimplifyLibCalls = !CodeGenOpts.SimplifyLibCalls; 215 PMBuilder.DisableUnitAtATime = !CodeGenOpts.UnitAtATime; 216 PMBuilder.DisableUnrollLoops = !CodeGenOpts.UnrollLoops; 217 218 // In ObjC ARC mode, add the main ARC optimization passes. 219 if (LangOpts.ObjCAutoRefCount) { 220 PMBuilder.addExtension(PassManagerBuilder::EP_EarlyAsPossible, 221 addObjCARCExpandPass); 222 PMBuilder.addExtension(PassManagerBuilder::EP_ModuleOptimizerEarly, 223 addObjCARCAPElimPass); 224 PMBuilder.addExtension(PassManagerBuilder::EP_ScalarOptimizerLate, 225 addObjCARCOptPass); 226 } 227 228 if (LangOpts.SanitizeBounds) { 229 PMBuilder.addExtension(PassManagerBuilder::EP_ScalarOptimizerLate, 230 addBoundsCheckingPass); 231 PMBuilder.addExtension(PassManagerBuilder::EP_EnabledOnOptLevel0, 232 addBoundsCheckingPass); 233 } 234 235 if (LangOpts.SanitizeAddress) { 236 PMBuilder.addExtension(PassManagerBuilder::EP_OptimizerLast, 237 addAddressSanitizerPasses); 238 PMBuilder.addExtension(PassManagerBuilder::EP_EnabledOnOptLevel0, 239 addAddressSanitizerPasses); 240 } 241 242 if (LangOpts.SanitizeMemory) { 243 PMBuilder.addExtension(PassManagerBuilder::EP_OptimizerLast, 244 addMemorySanitizerPass); 245 PMBuilder.addExtension(PassManagerBuilder::EP_EnabledOnOptLevel0, 246 addMemorySanitizerPass); 247 } 248 249 if (LangOpts.SanitizeThread) { 250 PMBuilder.addExtension(PassManagerBuilder::EP_OptimizerLast, 251 addThreadSanitizerPass); 252 PMBuilder.addExtension(PassManagerBuilder::EP_EnabledOnOptLevel0, 253 addThreadSanitizerPass); 254 } 255 256 // Figure out TargetLibraryInfo. 257 Triple TargetTriple(TheModule->getTargetTriple()); 258 PMBuilder.LibraryInfo = new TargetLibraryInfo(TargetTriple); 259 if (!CodeGenOpts.SimplifyLibCalls) 260 PMBuilder.LibraryInfo->disableAllFunctions(); 261 262 switch (Inlining) { 263 case CodeGenOptions::NoInlining: break; 264 case CodeGenOptions::NormalInlining: { 265 // FIXME: Derive these constants in a principled fashion. 266 unsigned Threshold = 225; 267 if (CodeGenOpts.OptimizeSize == 1) // -Os 268 Threshold = 75; 269 else if (CodeGenOpts.OptimizeSize == 2) // -Oz 270 Threshold = 25; 271 else if (OptLevel > 2) 272 Threshold = 275; 273 PMBuilder.Inliner = createFunctionInliningPass(Threshold); 274 break; 275 } 276 case CodeGenOptions::OnlyAlwaysInlining: 277 // Respect always_inline. 278 if (OptLevel == 0) 279 // Do not insert lifetime intrinsics at -O0. 280 PMBuilder.Inliner = createAlwaysInlinerPass(false); 281 else 282 PMBuilder.Inliner = createAlwaysInlinerPass(); 283 break; 284 } 285 286 // Set up the per-function pass manager. 287 FunctionPassManager *FPM = getPerFunctionPasses(TM); 288 if (CodeGenOpts.VerifyModule) 289 FPM->add(createVerifierPass()); 290 PMBuilder.populateFunctionPassManager(*FPM); 291 292 // Set up the per-module pass manager. 293 PassManager *MPM = getPerModulePasses(TM); 294 295 if (CodeGenOpts.EmitGcovArcs || CodeGenOpts.EmitGcovNotes) { 296 MPM->add(createGCOVProfilerPass(CodeGenOpts.EmitGcovNotes, 297 CodeGenOpts.EmitGcovArcs, 298 TargetTriple.isMacOSX(), 299 false, 300 CodeGenOpts.DisableRedZone)); 301 302 if (CodeGenOpts.getDebugInfo() == CodeGenOptions::NoDebugInfo) 303 MPM->add(createStripSymbolsPass(true)); 304 } 305 306 PMBuilder.populateModulePassManager(*MPM); 307 } 308 309 TargetMachine *EmitAssemblyHelper::CreateTargetMachine(bool MustCreateTM) { 310 // Create the TargetMachine for generating code. 311 std::string Error; 312 std::string Triple = TheModule->getTargetTriple(); 313 const llvm::Target *TheTarget = TargetRegistry::lookupTarget(Triple, Error); 314 if (!TheTarget) { 315 if (MustCreateTM) 316 Diags.Report(diag::err_fe_unable_to_create_target) << Error; 317 return 0; 318 } 319 320 // FIXME: Expose these capabilities via actual APIs!!!! Aside from just 321 // being gross, this is also totally broken if we ever care about 322 // concurrency. 323 324 TargetMachine::setAsmVerbosityDefault(CodeGenOpts.AsmVerbose); 325 326 TargetMachine::setFunctionSections(CodeGenOpts.FunctionSections); 327 TargetMachine::setDataSections (CodeGenOpts.DataSections); 328 329 // FIXME: Parse this earlier. 330 llvm::CodeModel::Model CM; 331 if (CodeGenOpts.CodeModel == "small") { 332 CM = llvm::CodeModel::Small; 333 } else if (CodeGenOpts.CodeModel == "kernel") { 334 CM = llvm::CodeModel::Kernel; 335 } else if (CodeGenOpts.CodeModel == "medium") { 336 CM = llvm::CodeModel::Medium; 337 } else if (CodeGenOpts.CodeModel == "large") { 338 CM = llvm::CodeModel::Large; 339 } else { 340 assert(CodeGenOpts.CodeModel.empty() && "Invalid code model!"); 341 CM = llvm::CodeModel::Default; 342 } 343 344 SmallVector<const char *, 16> BackendArgs; 345 BackendArgs.push_back("clang"); // Fake program name. 346 if (!CodeGenOpts.DebugPass.empty()) { 347 BackendArgs.push_back("-debug-pass"); 348 BackendArgs.push_back(CodeGenOpts.DebugPass.c_str()); 349 } 350 if (!CodeGenOpts.LimitFloatPrecision.empty()) { 351 BackendArgs.push_back("-limit-float-precision"); 352 BackendArgs.push_back(CodeGenOpts.LimitFloatPrecision.c_str()); 353 } 354 if (llvm::TimePassesIsEnabled) 355 BackendArgs.push_back("-time-passes"); 356 for (unsigned i = 0, e = CodeGenOpts.BackendOptions.size(); i != e; ++i) 357 BackendArgs.push_back(CodeGenOpts.BackendOptions[i].c_str()); 358 if (CodeGenOpts.NoGlobalMerge) 359 BackendArgs.push_back("-global-merge=false"); 360 BackendArgs.push_back(0); 361 llvm::cl::ParseCommandLineOptions(BackendArgs.size() - 1, 362 BackendArgs.data()); 363 364 std::string FeaturesStr; 365 if (TargetOpts.Features.size()) { 366 SubtargetFeatures Features; 367 for (std::vector<std::string>::const_iterator 368 it = TargetOpts.Features.begin(), 369 ie = TargetOpts.Features.end(); it != ie; ++it) 370 Features.AddFeature(*it); 371 FeaturesStr = Features.getString(); 372 } 373 374 llvm::Reloc::Model RM = llvm::Reloc::Default; 375 if (CodeGenOpts.RelocationModel == "static") { 376 RM = llvm::Reloc::Static; 377 } else if (CodeGenOpts.RelocationModel == "pic") { 378 RM = llvm::Reloc::PIC_; 379 } else { 380 assert(CodeGenOpts.RelocationModel == "dynamic-no-pic" && 381 "Invalid PIC model!"); 382 RM = llvm::Reloc::DynamicNoPIC; 383 } 384 385 CodeGenOpt::Level OptLevel = CodeGenOpt::Default; 386 switch (CodeGenOpts.OptimizationLevel) { 387 default: break; 388 case 0: OptLevel = CodeGenOpt::None; break; 389 case 3: OptLevel = CodeGenOpt::Aggressive; break; 390 } 391 392 llvm::TargetOptions Options; 393 394 // Set frame pointer elimination mode. 395 if (!CodeGenOpts.DisableFPElim) { 396 Options.NoFramePointerElim = false; 397 Options.NoFramePointerElimNonLeaf = false; 398 } else if (CodeGenOpts.OmitLeafFramePointer) { 399 Options.NoFramePointerElim = false; 400 Options.NoFramePointerElimNonLeaf = true; 401 } else { 402 Options.NoFramePointerElim = true; 403 Options.NoFramePointerElimNonLeaf = true; 404 } 405 406 if (CodeGenOpts.UseInitArray) 407 Options.UseInitArray = true; 408 409 // Set float ABI type. 410 if (CodeGenOpts.FloatABI == "soft" || CodeGenOpts.FloatABI == "softfp") 411 Options.FloatABIType = llvm::FloatABI::Soft; 412 else if (CodeGenOpts.FloatABI == "hard") 413 Options.FloatABIType = llvm::FloatABI::Hard; 414 else { 415 assert(CodeGenOpts.FloatABI.empty() && "Invalid float abi!"); 416 Options.FloatABIType = llvm::FloatABI::Default; 417 } 418 419 // Set FP fusion mode. 420 switch (CodeGenOpts.getFPContractMode()) { 421 case CodeGenOptions::FPC_Off: 422 Options.AllowFPOpFusion = llvm::FPOpFusion::Strict; 423 break; 424 case CodeGenOptions::FPC_On: 425 Options.AllowFPOpFusion = llvm::FPOpFusion::Standard; 426 break; 427 case CodeGenOptions::FPC_Fast: 428 Options.AllowFPOpFusion = llvm::FPOpFusion::Fast; 429 break; 430 } 431 432 Options.LessPreciseFPMADOption = CodeGenOpts.LessPreciseFPMAD; 433 Options.NoInfsFPMath = CodeGenOpts.NoInfsFPMath; 434 Options.NoNaNsFPMath = CodeGenOpts.NoNaNsFPMath; 435 Options.NoZerosInBSS = CodeGenOpts.NoZeroInitializedInBSS; 436 Options.UnsafeFPMath = CodeGenOpts.UnsafeFPMath; 437 Options.UseSoftFloat = CodeGenOpts.SoftFloat; 438 Options.StackAlignmentOverride = CodeGenOpts.StackAlignment; 439 Options.RealignStack = CodeGenOpts.StackRealignment; 440 Options.DisableTailCalls = CodeGenOpts.DisableTailCalls; 441 Options.TrapFuncName = CodeGenOpts.TrapFuncName; 442 Options.PositionIndependentExecutable = LangOpts.PIELevel != 0; 443 Options.SSPBufferSize = CodeGenOpts.SSPBufferSize; 444 445 TargetMachine *TM = TheTarget->createTargetMachine(Triple, TargetOpts.CPU, 446 FeaturesStr, Options, 447 RM, CM, OptLevel); 448 449 if (CodeGenOpts.RelaxAll) 450 TM->setMCRelaxAll(true); 451 if (CodeGenOpts.SaveTempLabels) 452 TM->setMCSaveTempLabels(true); 453 if (CodeGenOpts.NoDwarf2CFIAsm) 454 TM->setMCUseCFI(false); 455 if (!CodeGenOpts.NoDwarfDirectoryAsm) 456 TM->setMCUseDwarfDirectory(true); 457 if (CodeGenOpts.NoExecStack) 458 TM->setMCNoExecStack(true); 459 460 return TM; 461 } 462 463 bool EmitAssemblyHelper::AddEmitPasses(BackendAction Action, 464 formatted_raw_ostream &OS, 465 TargetMachine *TM) { 466 467 // Create the code generator passes. 468 PassManager *PM = getCodeGenPasses(TM); 469 470 // Add LibraryInfo. 471 llvm::Triple TargetTriple(TheModule->getTargetTriple()); 472 TargetLibraryInfo *TLI = new TargetLibraryInfo(TargetTriple); 473 if (!CodeGenOpts.SimplifyLibCalls) 474 TLI->disableAllFunctions(); 475 PM->add(TLI); 476 477 // Add TargetTransformInfo. 478 PM->add(new TargetTransformInfo(TM->getScalarTargetTransformInfo(), 479 TM->getVectorTargetTransformInfo())); 480 481 // Normal mode, emit a .s or .o file by running the code generator. Note, 482 // this also adds codegenerator level optimization passes. 483 TargetMachine::CodeGenFileType CGFT = TargetMachine::CGFT_AssemblyFile; 484 if (Action == Backend_EmitObj) 485 CGFT = TargetMachine::CGFT_ObjectFile; 486 else if (Action == Backend_EmitMCNull) 487 CGFT = TargetMachine::CGFT_Null; 488 else 489 assert(Action == Backend_EmitAssembly && "Invalid action!"); 490 491 // Add ObjC ARC final-cleanup optimizations. This is done as part of the 492 // "codegen" passes so that it isn't run multiple times when there is 493 // inlining happening. 494 if (LangOpts.ObjCAutoRefCount && 495 CodeGenOpts.OptimizationLevel > 0) 496 PM->add(createObjCARCContractPass()); 497 498 if (TM->addPassesToEmitFile(*PM, OS, CGFT, 499 /*DisableVerify=*/!CodeGenOpts.VerifyModule)) { 500 Diags.Report(diag::err_fe_unable_to_interface_with_target); 501 return false; 502 } 503 504 return true; 505 } 506 507 void EmitAssemblyHelper::EmitAssembly(BackendAction Action, raw_ostream *OS) { 508 TimeRegion Region(llvm::TimePassesIsEnabled ? &CodeGenerationTime : 0); 509 llvm::formatted_raw_ostream FormattedOS; 510 511 bool UsesCodeGen = (Action != Backend_EmitNothing && 512 Action != Backend_EmitBC && 513 Action != Backend_EmitLL); 514 TargetMachine *TM = CreateTargetMachine(UsesCodeGen); 515 CreatePasses(TM); 516 517 switch (Action) { 518 case Backend_EmitNothing: 519 break; 520 521 case Backend_EmitBC: 522 getPerModulePasses(TM)->add(createBitcodeWriterPass(*OS)); 523 break; 524 525 case Backend_EmitLL: 526 FormattedOS.setStream(*OS, formatted_raw_ostream::PRESERVE_STREAM); 527 getPerModulePasses(TM)->add(createPrintModulePass(&FormattedOS)); 528 break; 529 530 default: 531 FormattedOS.setStream(*OS, formatted_raw_ostream::PRESERVE_STREAM); 532 if (!AddEmitPasses(Action, FormattedOS, TM)) 533 return; 534 } 535 536 // Before executing passes, print the final values of the LLVM options. 537 cl::PrintOptionValues(); 538 539 // Run passes. For now we do all passes at once, but eventually we 540 // would like to have the option of streaming code generation. 541 542 if (PerFunctionPasses) { 543 PrettyStackTraceString CrashInfo("Per-function optimization"); 544 545 PerFunctionPasses->doInitialization(); 546 for (Module::iterator I = TheModule->begin(), 547 E = TheModule->end(); I != E; ++I) 548 if (!I->isDeclaration()) 549 PerFunctionPasses->run(*I); 550 PerFunctionPasses->doFinalization(); 551 } 552 553 if (PerModulePasses) { 554 PrettyStackTraceString CrashInfo("Per-module optimization passes"); 555 PerModulePasses->run(*TheModule); 556 } 557 558 if (CodeGenPasses) { 559 PrettyStackTraceString CrashInfo("Code generation"); 560 CodeGenPasses->run(*TheModule); 561 } 562 } 563 564 void clang::EmitBackendOutput(DiagnosticsEngine &Diags, 565 const CodeGenOptions &CGOpts, 566 const clang::TargetOptions &TOpts, 567 const LangOptions &LOpts, 568 Module *M, 569 BackendAction Action, raw_ostream *OS) { 570 EmitAssemblyHelper AsmHelper(Diags, CGOpts, TOpts, LOpts, M); 571 572 AsmHelper.EmitAssembly(Action, OS); 573 } 574