1 //===--- CodeGenAction.cpp - LLVM Code Generation Frontend Action ---------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #include "clang/CodeGen/CodeGenAction.h" 10 #include "CodeGenModule.h" 11 #include "CoverageMappingGen.h" 12 #include "MacroPPCallbacks.h" 13 #include "clang/AST/ASTConsumer.h" 14 #include "clang/AST/ASTContext.h" 15 #include "clang/AST/DeclCXX.h" 16 #include "clang/AST/DeclGroup.h" 17 #include "clang/Basic/DiagnosticFrontend.h" 18 #include "clang/Basic/FileManager.h" 19 #include "clang/Basic/LangStandard.h" 20 #include "clang/Basic/SourceManager.h" 21 #include "clang/Basic/TargetInfo.h" 22 #include "clang/CodeGen/BackendUtil.h" 23 #include "clang/CodeGen/ModuleBuilder.h" 24 #include "clang/Driver/DriverDiagnostic.h" 25 #include "clang/Frontend/CompilerInstance.h" 26 #include "clang/Frontend/FrontendDiagnostic.h" 27 #include "clang/Lex/Preprocessor.h" 28 #include "llvm/Bitcode/BitcodeReader.h" 29 #include "llvm/CodeGen/MachineOptimizationRemarkEmitter.h" 30 #include "llvm/IR/DebugInfo.h" 31 #include "llvm/IR/DiagnosticInfo.h" 32 #include "llvm/IR/DiagnosticPrinter.h" 33 #include "llvm/IR/GlobalValue.h" 34 #include "llvm/IR/LLVMContext.h" 35 #include "llvm/IR/Module.h" 36 #include "llvm/IR/RemarkStreamer.h" 37 #include "llvm/IRReader/IRReader.h" 38 #include "llvm/Linker/Linker.h" 39 #include "llvm/Pass.h" 40 #include "llvm/Support/MemoryBuffer.h" 41 #include "llvm/Support/SourceMgr.h" 42 #include "llvm/Support/TimeProfiler.h" 43 #include "llvm/Support/Timer.h" 44 #include "llvm/Support/ToolOutputFile.h" 45 #include "llvm/Support/YAMLTraits.h" 46 #include "llvm/Transforms/IPO/Internalize.h" 47 48 #include <memory> 49 using namespace clang; 50 using namespace llvm; 51 52 namespace clang { 53 class BackendConsumer; 54 class ClangDiagnosticHandler final : public DiagnosticHandler { 55 public: 56 ClangDiagnosticHandler(const CodeGenOptions &CGOpts, BackendConsumer *BCon) 57 : CodeGenOpts(CGOpts), BackendCon(BCon) {} 58 59 bool handleDiagnostics(const DiagnosticInfo &DI) override; 60 61 bool isAnalysisRemarkEnabled(StringRef PassName) const override { 62 return (CodeGenOpts.OptimizationRemarkAnalysisPattern && 63 CodeGenOpts.OptimizationRemarkAnalysisPattern->match(PassName)); 64 } 65 bool isMissedOptRemarkEnabled(StringRef PassName) const override { 66 return (CodeGenOpts.OptimizationRemarkMissedPattern && 67 CodeGenOpts.OptimizationRemarkMissedPattern->match(PassName)); 68 } 69 bool isPassedOptRemarkEnabled(StringRef PassName) const override { 70 return (CodeGenOpts.OptimizationRemarkPattern && 71 CodeGenOpts.OptimizationRemarkPattern->match(PassName)); 72 } 73 74 bool isAnyRemarkEnabled() const override { 75 return (CodeGenOpts.OptimizationRemarkAnalysisPattern || 76 CodeGenOpts.OptimizationRemarkMissedPattern || 77 CodeGenOpts.OptimizationRemarkPattern); 78 } 79 80 private: 81 const CodeGenOptions &CodeGenOpts; 82 BackendConsumer *BackendCon; 83 }; 84 85 static void reportOptRecordError(Error E, DiagnosticsEngine &Diags, 86 const CodeGenOptions CodeGenOpts) { 87 handleAllErrors( 88 std::move(E), 89 [&](const RemarkSetupFileError &E) { 90 Diags.Report(diag::err_cannot_open_file) 91 << CodeGenOpts.OptRecordFile << E.message(); 92 }, 93 [&](const RemarkSetupPatternError &E) { 94 Diags.Report(diag::err_drv_optimization_remark_pattern) 95 << E.message() << CodeGenOpts.OptRecordPasses; 96 }, 97 [&](const RemarkSetupFormatError &E) { 98 Diags.Report(diag::err_drv_optimization_remark_format) 99 << CodeGenOpts.OptRecordFormat; 100 }); 101 } 102 103 class BackendConsumer : public ASTConsumer { 104 using LinkModule = CodeGenAction::LinkModule; 105 106 virtual void anchor(); 107 DiagnosticsEngine &Diags; 108 BackendAction Action; 109 const HeaderSearchOptions &HeaderSearchOpts; 110 const CodeGenOptions &CodeGenOpts; 111 const TargetOptions &TargetOpts; 112 const LangOptions &LangOpts; 113 std::unique_ptr<raw_pwrite_stream> AsmOutStream; 114 ASTContext *Context; 115 116 Timer LLVMIRGeneration; 117 unsigned LLVMIRGenerationRefCount; 118 119 /// True if we've finished generating IR. This prevents us from generating 120 /// additional LLVM IR after emitting output in HandleTranslationUnit. This 121 /// can happen when Clang plugins trigger additional AST deserialization. 122 bool IRGenFinished = false; 123 124 std::unique_ptr<CodeGenerator> Gen; 125 126 SmallVector<LinkModule, 4> LinkModules; 127 128 // This is here so that the diagnostic printer knows the module a diagnostic 129 // refers to. 130 llvm::Module *CurLinkModule = nullptr; 131 132 public: 133 BackendConsumer(BackendAction Action, DiagnosticsEngine &Diags, 134 const HeaderSearchOptions &HeaderSearchOpts, 135 const PreprocessorOptions &PPOpts, 136 const CodeGenOptions &CodeGenOpts, 137 const TargetOptions &TargetOpts, 138 const LangOptions &LangOpts, bool TimePasses, 139 const std::string &InFile, 140 SmallVector<LinkModule, 4> LinkModules, 141 std::unique_ptr<raw_pwrite_stream> OS, LLVMContext &C, 142 CoverageSourceInfo *CoverageInfo = nullptr) 143 : Diags(Diags), Action(Action), HeaderSearchOpts(HeaderSearchOpts), 144 CodeGenOpts(CodeGenOpts), TargetOpts(TargetOpts), LangOpts(LangOpts), 145 AsmOutStream(std::move(OS)), Context(nullptr), 146 LLVMIRGeneration("irgen", "LLVM IR Generation Time"), 147 LLVMIRGenerationRefCount(0), 148 Gen(CreateLLVMCodeGen(Diags, InFile, HeaderSearchOpts, PPOpts, 149 CodeGenOpts, C, CoverageInfo)), 150 LinkModules(std::move(LinkModules)) { 151 FrontendTimesIsEnabled = TimePasses; 152 llvm::TimePassesIsEnabled = TimePasses; 153 } 154 llvm::Module *getModule() const { return Gen->GetModule(); } 155 std::unique_ptr<llvm::Module> takeModule() { 156 return std::unique_ptr<llvm::Module>(Gen->ReleaseModule()); 157 } 158 159 CodeGenerator *getCodeGenerator() { return Gen.get(); } 160 161 void HandleCXXStaticMemberVarInstantiation(VarDecl *VD) override { 162 Gen->HandleCXXStaticMemberVarInstantiation(VD); 163 } 164 165 void Initialize(ASTContext &Ctx) override { 166 assert(!Context && "initialized multiple times"); 167 168 Context = &Ctx; 169 170 if (FrontendTimesIsEnabled) 171 LLVMIRGeneration.startTimer(); 172 173 Gen->Initialize(Ctx); 174 175 if (FrontendTimesIsEnabled) 176 LLVMIRGeneration.stopTimer(); 177 } 178 179 bool HandleTopLevelDecl(DeclGroupRef D) override { 180 PrettyStackTraceDecl CrashInfo(*D.begin(), SourceLocation(), 181 Context->getSourceManager(), 182 "LLVM IR generation of declaration"); 183 184 // Recurse. 185 if (FrontendTimesIsEnabled) { 186 LLVMIRGenerationRefCount += 1; 187 if (LLVMIRGenerationRefCount == 1) 188 LLVMIRGeneration.startTimer(); 189 } 190 191 Gen->HandleTopLevelDecl(D); 192 193 if (FrontendTimesIsEnabled) { 194 LLVMIRGenerationRefCount -= 1; 195 if (LLVMIRGenerationRefCount == 0) 196 LLVMIRGeneration.stopTimer(); 197 } 198 199 return true; 200 } 201 202 void HandleInlineFunctionDefinition(FunctionDecl *D) override { 203 PrettyStackTraceDecl CrashInfo(D, SourceLocation(), 204 Context->getSourceManager(), 205 "LLVM IR generation of inline function"); 206 if (FrontendTimesIsEnabled) 207 LLVMIRGeneration.startTimer(); 208 209 Gen->HandleInlineFunctionDefinition(D); 210 211 if (FrontendTimesIsEnabled) 212 LLVMIRGeneration.stopTimer(); 213 } 214 215 void HandleInterestingDecl(DeclGroupRef D) override { 216 // Ignore interesting decls from the AST reader after IRGen is finished. 217 if (!IRGenFinished) 218 HandleTopLevelDecl(D); 219 } 220 221 // Links each entry in LinkModules into our module. Returns true on error. 222 bool LinkInModules() { 223 for (auto &LM : LinkModules) { 224 if (LM.PropagateAttrs) 225 for (Function &F : *LM.Module) 226 Gen->CGM().AddDefaultFnAttrs(F); 227 228 CurLinkModule = LM.Module.get(); 229 230 bool Err; 231 if (LM.Internalize) { 232 Err = Linker::linkModules( 233 *getModule(), std::move(LM.Module), LM.LinkFlags, 234 [](llvm::Module &M, const llvm::StringSet<> &GVS) { 235 internalizeModule(M, [&GVS](const llvm::GlobalValue &GV) { 236 return !GV.hasName() || (GVS.count(GV.getName()) == 0); 237 }); 238 }); 239 } else { 240 Err = Linker::linkModules(*getModule(), std::move(LM.Module), 241 LM.LinkFlags); 242 } 243 244 if (Err) 245 return true; 246 } 247 return false; // success 248 } 249 250 void HandleTranslationUnit(ASTContext &C) override { 251 { 252 llvm::TimeTraceScope TimeScope("Frontend"); 253 PrettyStackTraceString CrashInfo("Per-file LLVM IR generation"); 254 if (FrontendTimesIsEnabled) { 255 LLVMIRGenerationRefCount += 1; 256 if (LLVMIRGenerationRefCount == 1) 257 LLVMIRGeneration.startTimer(); 258 } 259 260 Gen->HandleTranslationUnit(C); 261 262 if (FrontendTimesIsEnabled) { 263 LLVMIRGenerationRefCount -= 1; 264 if (LLVMIRGenerationRefCount == 0) 265 LLVMIRGeneration.stopTimer(); 266 } 267 268 IRGenFinished = true; 269 } 270 271 // Silently ignore if we weren't initialized for some reason. 272 if (!getModule()) 273 return; 274 275 // Install an inline asm handler so that diagnostics get printed through 276 // our diagnostics hooks. 277 LLVMContext &Ctx = getModule()->getContext(); 278 LLVMContext::InlineAsmDiagHandlerTy OldHandler = 279 Ctx.getInlineAsmDiagnosticHandler(); 280 void *OldContext = Ctx.getInlineAsmDiagnosticContext(); 281 Ctx.setInlineAsmDiagnosticHandler(InlineAsmDiagHandler, this); 282 283 std::unique_ptr<DiagnosticHandler> OldDiagnosticHandler = 284 Ctx.getDiagnosticHandler(); 285 Ctx.setDiagnosticHandler(std::make_unique<ClangDiagnosticHandler>( 286 CodeGenOpts, this)); 287 288 Expected<std::unique_ptr<llvm::ToolOutputFile>> OptRecordFileOrErr = 289 setupOptimizationRemarks( 290 Ctx, CodeGenOpts.OptRecordFile, CodeGenOpts.OptRecordPasses, 291 CodeGenOpts.OptRecordFormat, CodeGenOpts.DiagnosticsWithHotness, 292 CodeGenOpts.DiagnosticsHotnessThreshold); 293 294 if (Error E = OptRecordFileOrErr.takeError()) { 295 reportOptRecordError(std::move(E), Diags, CodeGenOpts); 296 return; 297 } 298 299 std::unique_ptr<llvm::ToolOutputFile> OptRecordFile = 300 std::move(*OptRecordFileOrErr); 301 302 if (OptRecordFile && 303 CodeGenOpts.getProfileUse() != CodeGenOptions::ProfileNone) 304 Ctx.setDiagnosticsHotnessRequested(true); 305 306 // Link each LinkModule into our module. 307 if (LinkInModules()) 308 return; 309 310 EmbedBitcode(getModule(), CodeGenOpts, llvm::MemoryBufferRef()); 311 312 EmitBackendOutput(Diags, HeaderSearchOpts, CodeGenOpts, TargetOpts, 313 LangOpts, C.getTargetInfo().getDataLayout(), 314 getModule(), Action, std::move(AsmOutStream)); 315 316 Ctx.setInlineAsmDiagnosticHandler(OldHandler, OldContext); 317 318 Ctx.setDiagnosticHandler(std::move(OldDiagnosticHandler)); 319 320 if (OptRecordFile) 321 OptRecordFile->keep(); 322 } 323 324 void HandleTagDeclDefinition(TagDecl *D) override { 325 PrettyStackTraceDecl CrashInfo(D, SourceLocation(), 326 Context->getSourceManager(), 327 "LLVM IR generation of declaration"); 328 Gen->HandleTagDeclDefinition(D); 329 } 330 331 void HandleTagDeclRequiredDefinition(const TagDecl *D) override { 332 Gen->HandleTagDeclRequiredDefinition(D); 333 } 334 335 void CompleteTentativeDefinition(VarDecl *D) override { 336 Gen->CompleteTentativeDefinition(D); 337 } 338 339 void CompleteExternalDeclaration(VarDecl *D) override { 340 Gen->CompleteExternalDeclaration(D); 341 } 342 343 void AssignInheritanceModel(CXXRecordDecl *RD) override { 344 Gen->AssignInheritanceModel(RD); 345 } 346 347 void HandleVTable(CXXRecordDecl *RD) override { 348 Gen->HandleVTable(RD); 349 } 350 351 static void InlineAsmDiagHandler(const llvm::SMDiagnostic &SM,void *Context, 352 unsigned LocCookie) { 353 SourceLocation Loc = SourceLocation::getFromRawEncoding(LocCookie); 354 ((BackendConsumer*)Context)->InlineAsmDiagHandler2(SM, Loc); 355 } 356 357 /// Get the best possible source location to represent a diagnostic that 358 /// may have associated debug info. 359 const FullSourceLoc 360 getBestLocationFromDebugLoc(const llvm::DiagnosticInfoWithLocationBase &D, 361 bool &BadDebugInfo, StringRef &Filename, 362 unsigned &Line, unsigned &Column) const; 363 364 void InlineAsmDiagHandler2(const llvm::SMDiagnostic &, 365 SourceLocation LocCookie); 366 367 void DiagnosticHandlerImpl(const llvm::DiagnosticInfo &DI); 368 /// Specialized handler for InlineAsm diagnostic. 369 /// \return True if the diagnostic has been successfully reported, false 370 /// otherwise. 371 bool InlineAsmDiagHandler(const llvm::DiagnosticInfoInlineAsm &D); 372 /// Specialized handler for StackSize diagnostic. 373 /// \return True if the diagnostic has been successfully reported, false 374 /// otherwise. 375 bool StackSizeDiagHandler(const llvm::DiagnosticInfoStackSize &D); 376 /// Specialized handler for unsupported backend feature diagnostic. 377 void UnsupportedDiagHandler(const llvm::DiagnosticInfoUnsupported &D); 378 /// Specialized handler for misexpect warnings. 379 /// Note that misexpect remarks are emitted through ORE 380 void MisExpectDiagHandler(const llvm::DiagnosticInfoMisExpect &D); 381 /// Specialized handlers for optimization remarks. 382 /// Note that these handlers only accept remarks and they always handle 383 /// them. 384 void EmitOptimizationMessage(const llvm::DiagnosticInfoOptimizationBase &D, 385 unsigned DiagID); 386 void 387 OptimizationRemarkHandler(const llvm::DiagnosticInfoOptimizationBase &D); 388 void OptimizationRemarkHandler( 389 const llvm::OptimizationRemarkAnalysisFPCommute &D); 390 void OptimizationRemarkHandler( 391 const llvm::OptimizationRemarkAnalysisAliasing &D); 392 void OptimizationFailureHandler( 393 const llvm::DiagnosticInfoOptimizationFailure &D); 394 }; 395 396 void BackendConsumer::anchor() {} 397 } 398 399 bool ClangDiagnosticHandler::handleDiagnostics(const DiagnosticInfo &DI) { 400 BackendCon->DiagnosticHandlerImpl(DI); 401 return true; 402 } 403 404 /// ConvertBackendLocation - Convert a location in a temporary llvm::SourceMgr 405 /// buffer to be a valid FullSourceLoc. 406 static FullSourceLoc ConvertBackendLocation(const llvm::SMDiagnostic &D, 407 SourceManager &CSM) { 408 // Get both the clang and llvm source managers. The location is relative to 409 // a memory buffer that the LLVM Source Manager is handling, we need to add 410 // a copy to the Clang source manager. 411 const llvm::SourceMgr &LSM = *D.getSourceMgr(); 412 413 // We need to copy the underlying LLVM memory buffer because llvm::SourceMgr 414 // already owns its one and clang::SourceManager wants to own its one. 415 const MemoryBuffer *LBuf = 416 LSM.getMemoryBuffer(LSM.FindBufferContainingLoc(D.getLoc())); 417 418 // Create the copy and transfer ownership to clang::SourceManager. 419 // TODO: Avoid copying files into memory. 420 std::unique_ptr<llvm::MemoryBuffer> CBuf = 421 llvm::MemoryBuffer::getMemBufferCopy(LBuf->getBuffer(), 422 LBuf->getBufferIdentifier()); 423 // FIXME: Keep a file ID map instead of creating new IDs for each location. 424 FileID FID = CSM.createFileID(std::move(CBuf)); 425 426 // Translate the offset into the file. 427 unsigned Offset = D.getLoc().getPointer() - LBuf->getBufferStart(); 428 SourceLocation NewLoc = 429 CSM.getLocForStartOfFile(FID).getLocWithOffset(Offset); 430 return FullSourceLoc(NewLoc, CSM); 431 } 432 433 434 /// InlineAsmDiagHandler2 - This function is invoked when the backend hits an 435 /// error parsing inline asm. The SMDiagnostic indicates the error relative to 436 /// the temporary memory buffer that the inline asm parser has set up. 437 void BackendConsumer::InlineAsmDiagHandler2(const llvm::SMDiagnostic &D, 438 SourceLocation LocCookie) { 439 // There are a couple of different kinds of errors we could get here. First, 440 // we re-format the SMDiagnostic in terms of a clang diagnostic. 441 442 // Strip "error: " off the start of the message string. 443 StringRef Message = D.getMessage(); 444 if (Message.startswith("error: ")) 445 Message = Message.substr(7); 446 447 // If the SMDiagnostic has an inline asm source location, translate it. 448 FullSourceLoc Loc; 449 if (D.getLoc() != SMLoc()) 450 Loc = ConvertBackendLocation(D, Context->getSourceManager()); 451 452 unsigned DiagID; 453 switch (D.getKind()) { 454 case llvm::SourceMgr::DK_Error: 455 DiagID = diag::err_fe_inline_asm; 456 break; 457 case llvm::SourceMgr::DK_Warning: 458 DiagID = diag::warn_fe_inline_asm; 459 break; 460 case llvm::SourceMgr::DK_Note: 461 DiagID = diag::note_fe_inline_asm; 462 break; 463 case llvm::SourceMgr::DK_Remark: 464 llvm_unreachable("remarks unexpected"); 465 } 466 // If this problem has clang-level source location information, report the 467 // issue in the source with a note showing the instantiated 468 // code. 469 if (LocCookie.isValid()) { 470 Diags.Report(LocCookie, DiagID).AddString(Message); 471 472 if (D.getLoc().isValid()) { 473 DiagnosticBuilder B = Diags.Report(Loc, diag::note_fe_inline_asm_here); 474 // Convert the SMDiagnostic ranges into SourceRange and attach them 475 // to the diagnostic. 476 for (const std::pair<unsigned, unsigned> &Range : D.getRanges()) { 477 unsigned Column = D.getColumnNo(); 478 B << SourceRange(Loc.getLocWithOffset(Range.first - Column), 479 Loc.getLocWithOffset(Range.second - Column)); 480 } 481 } 482 return; 483 } 484 485 // Otherwise, report the backend issue as occurring in the generated .s file. 486 // If Loc is invalid, we still need to report the issue, it just gets no 487 // location info. 488 Diags.Report(Loc, DiagID).AddString(Message); 489 } 490 491 #define ComputeDiagID(Severity, GroupName, DiagID) \ 492 do { \ 493 switch (Severity) { \ 494 case llvm::DS_Error: \ 495 DiagID = diag::err_fe_##GroupName; \ 496 break; \ 497 case llvm::DS_Warning: \ 498 DiagID = diag::warn_fe_##GroupName; \ 499 break; \ 500 case llvm::DS_Remark: \ 501 llvm_unreachable("'remark' severity not expected"); \ 502 break; \ 503 case llvm::DS_Note: \ 504 DiagID = diag::note_fe_##GroupName; \ 505 break; \ 506 } \ 507 } while (false) 508 509 #define ComputeDiagRemarkID(Severity, GroupName, DiagID) \ 510 do { \ 511 switch (Severity) { \ 512 case llvm::DS_Error: \ 513 DiagID = diag::err_fe_##GroupName; \ 514 break; \ 515 case llvm::DS_Warning: \ 516 DiagID = diag::warn_fe_##GroupName; \ 517 break; \ 518 case llvm::DS_Remark: \ 519 DiagID = diag::remark_fe_##GroupName; \ 520 break; \ 521 case llvm::DS_Note: \ 522 DiagID = diag::note_fe_##GroupName; \ 523 break; \ 524 } \ 525 } while (false) 526 527 bool 528 BackendConsumer::InlineAsmDiagHandler(const llvm::DiagnosticInfoInlineAsm &D) { 529 unsigned DiagID; 530 ComputeDiagID(D.getSeverity(), inline_asm, DiagID); 531 std::string Message = D.getMsgStr().str(); 532 533 // If this problem has clang-level source location information, report the 534 // issue as being a problem in the source with a note showing the instantiated 535 // code. 536 SourceLocation LocCookie = 537 SourceLocation::getFromRawEncoding(D.getLocCookie()); 538 if (LocCookie.isValid()) 539 Diags.Report(LocCookie, DiagID).AddString(Message); 540 else { 541 // Otherwise, report the backend diagnostic as occurring in the generated 542 // .s file. 543 // If Loc is invalid, we still need to report the diagnostic, it just gets 544 // no location info. 545 FullSourceLoc Loc; 546 Diags.Report(Loc, DiagID).AddString(Message); 547 } 548 // We handled all the possible severities. 549 return true; 550 } 551 552 bool 553 BackendConsumer::StackSizeDiagHandler(const llvm::DiagnosticInfoStackSize &D) { 554 if (D.getSeverity() != llvm::DS_Warning) 555 // For now, the only support we have for StackSize diagnostic is warning. 556 // We do not know how to format other severities. 557 return false; 558 559 if (const Decl *ND = Gen->GetDeclForMangledName(D.getFunction().getName())) { 560 // FIXME: Shouldn't need to truncate to uint32_t 561 Diags.Report(ND->getASTContext().getFullLoc(ND->getLocation()), 562 diag::warn_fe_frame_larger_than) 563 << static_cast<uint32_t>(D.getStackSize()) << Decl::castToDeclContext(ND); 564 return true; 565 } 566 567 return false; 568 } 569 570 const FullSourceLoc BackendConsumer::getBestLocationFromDebugLoc( 571 const llvm::DiagnosticInfoWithLocationBase &D, bool &BadDebugInfo, 572 StringRef &Filename, unsigned &Line, unsigned &Column) const { 573 SourceManager &SourceMgr = Context->getSourceManager(); 574 FileManager &FileMgr = SourceMgr.getFileManager(); 575 SourceLocation DILoc; 576 577 if (D.isLocationAvailable()) { 578 D.getLocation(Filename, Line, Column); 579 if (Line > 0) { 580 auto FE = FileMgr.getFile(Filename); 581 if (!FE) 582 FE = FileMgr.getFile(D.getAbsolutePath()); 583 if (FE) { 584 // If -gcolumn-info was not used, Column will be 0. This upsets the 585 // source manager, so pass 1 if Column is not set. 586 DILoc = SourceMgr.translateFileLineCol(*FE, Line, Column ? Column : 1); 587 } 588 } 589 BadDebugInfo = DILoc.isInvalid(); 590 } 591 592 // If a location isn't available, try to approximate it using the associated 593 // function definition. We use the definition's right brace to differentiate 594 // from diagnostics that genuinely relate to the function itself. 595 FullSourceLoc Loc(DILoc, SourceMgr); 596 if (Loc.isInvalid()) 597 if (const Decl *FD = Gen->GetDeclForMangledName(D.getFunction().getName())) 598 Loc = FD->getASTContext().getFullLoc(FD->getLocation()); 599 600 if (DILoc.isInvalid() && D.isLocationAvailable()) 601 // If we were not able to translate the file:line:col information 602 // back to a SourceLocation, at least emit a note stating that 603 // we could not translate this location. This can happen in the 604 // case of #line directives. 605 Diags.Report(Loc, diag::note_fe_backend_invalid_loc) 606 << Filename << Line << Column; 607 608 return Loc; 609 } 610 611 void BackendConsumer::UnsupportedDiagHandler( 612 const llvm::DiagnosticInfoUnsupported &D) { 613 // We only support errors. 614 assert(D.getSeverity() == llvm::DS_Error); 615 616 StringRef Filename; 617 unsigned Line, Column; 618 bool BadDebugInfo = false; 619 FullSourceLoc Loc = 620 getBestLocationFromDebugLoc(D, BadDebugInfo, Filename, Line, Column); 621 622 Diags.Report(Loc, diag::err_fe_backend_unsupported) << D.getMessage().str(); 623 624 if (BadDebugInfo) 625 // If we were not able to translate the file:line:col information 626 // back to a SourceLocation, at least emit a note stating that 627 // we could not translate this location. This can happen in the 628 // case of #line directives. 629 Diags.Report(Loc, diag::note_fe_backend_invalid_loc) 630 << Filename << Line << Column; 631 } 632 633 void BackendConsumer::MisExpectDiagHandler( 634 const llvm::DiagnosticInfoMisExpect &D) { 635 StringRef Filename; 636 unsigned Line, Column; 637 bool BadDebugInfo = false; 638 FullSourceLoc Loc = 639 getBestLocationFromDebugLoc(D, BadDebugInfo, Filename, Line, Column); 640 641 Diags.Report(Loc, diag::warn_profile_data_misexpect) << D.getMsg().str(); 642 643 if (BadDebugInfo) 644 // If we were not able to translate the file:line:col information 645 // back to a SourceLocation, at least emit a note stating that 646 // we could not translate this location. This can happen in the 647 // case of #line directives. 648 Diags.Report(Loc, diag::note_fe_backend_invalid_loc) 649 << Filename << Line << Column; 650 } 651 652 void BackendConsumer::EmitOptimizationMessage( 653 const llvm::DiagnosticInfoOptimizationBase &D, unsigned DiagID) { 654 // We only support warnings and remarks. 655 assert(D.getSeverity() == llvm::DS_Remark || 656 D.getSeverity() == llvm::DS_Warning); 657 658 StringRef Filename; 659 unsigned Line, Column; 660 bool BadDebugInfo = false; 661 FullSourceLoc Loc = 662 getBestLocationFromDebugLoc(D, BadDebugInfo, Filename, Line, Column); 663 664 std::string Msg; 665 raw_string_ostream MsgStream(Msg); 666 MsgStream << D.getMsg(); 667 668 if (D.getHotness()) 669 MsgStream << " (hotness: " << *D.getHotness() << ")"; 670 671 Diags.Report(Loc, DiagID) 672 << AddFlagValue(D.getPassName()) 673 << MsgStream.str(); 674 675 if (BadDebugInfo) 676 // If we were not able to translate the file:line:col information 677 // back to a SourceLocation, at least emit a note stating that 678 // we could not translate this location. This can happen in the 679 // case of #line directives. 680 Diags.Report(Loc, diag::note_fe_backend_invalid_loc) 681 << Filename << Line << Column; 682 } 683 684 void BackendConsumer::OptimizationRemarkHandler( 685 const llvm::DiagnosticInfoOptimizationBase &D) { 686 // Without hotness information, don't show noisy remarks. 687 if (D.isVerbose() && !D.getHotness()) 688 return; 689 690 if (D.isPassed()) { 691 // Optimization remarks are active only if the -Rpass flag has a regular 692 // expression that matches the name of the pass name in \p D. 693 if (CodeGenOpts.OptimizationRemarkPattern && 694 CodeGenOpts.OptimizationRemarkPattern->match(D.getPassName())) 695 EmitOptimizationMessage(D, diag::remark_fe_backend_optimization_remark); 696 } else if (D.isMissed()) { 697 // Missed optimization remarks are active only if the -Rpass-missed 698 // flag has a regular expression that matches the name of the pass 699 // name in \p D. 700 if (CodeGenOpts.OptimizationRemarkMissedPattern && 701 CodeGenOpts.OptimizationRemarkMissedPattern->match(D.getPassName())) 702 EmitOptimizationMessage( 703 D, diag::remark_fe_backend_optimization_remark_missed); 704 } else { 705 assert(D.isAnalysis() && "Unknown remark type"); 706 707 bool ShouldAlwaysPrint = false; 708 if (auto *ORA = dyn_cast<llvm::OptimizationRemarkAnalysis>(&D)) 709 ShouldAlwaysPrint = ORA->shouldAlwaysPrint(); 710 711 if (ShouldAlwaysPrint || 712 (CodeGenOpts.OptimizationRemarkAnalysisPattern && 713 CodeGenOpts.OptimizationRemarkAnalysisPattern->match(D.getPassName()))) 714 EmitOptimizationMessage( 715 D, diag::remark_fe_backend_optimization_remark_analysis); 716 } 717 } 718 719 void BackendConsumer::OptimizationRemarkHandler( 720 const llvm::OptimizationRemarkAnalysisFPCommute &D) { 721 // Optimization analysis remarks are active if the pass name is set to 722 // llvm::DiagnosticInfo::AlwasyPrint or if the -Rpass-analysis flag has a 723 // regular expression that matches the name of the pass name in \p D. 724 725 if (D.shouldAlwaysPrint() || 726 (CodeGenOpts.OptimizationRemarkAnalysisPattern && 727 CodeGenOpts.OptimizationRemarkAnalysisPattern->match(D.getPassName()))) 728 EmitOptimizationMessage( 729 D, diag::remark_fe_backend_optimization_remark_analysis_fpcommute); 730 } 731 732 void BackendConsumer::OptimizationRemarkHandler( 733 const llvm::OptimizationRemarkAnalysisAliasing &D) { 734 // Optimization analysis remarks are active if the pass name is set to 735 // llvm::DiagnosticInfo::AlwasyPrint or if the -Rpass-analysis flag has a 736 // regular expression that matches the name of the pass name in \p D. 737 738 if (D.shouldAlwaysPrint() || 739 (CodeGenOpts.OptimizationRemarkAnalysisPattern && 740 CodeGenOpts.OptimizationRemarkAnalysisPattern->match(D.getPassName()))) 741 EmitOptimizationMessage( 742 D, diag::remark_fe_backend_optimization_remark_analysis_aliasing); 743 } 744 745 void BackendConsumer::OptimizationFailureHandler( 746 const llvm::DiagnosticInfoOptimizationFailure &D) { 747 EmitOptimizationMessage(D, diag::warn_fe_backend_optimization_failure); 748 } 749 750 /// This function is invoked when the backend needs 751 /// to report something to the user. 752 void BackendConsumer::DiagnosticHandlerImpl(const DiagnosticInfo &DI) { 753 unsigned DiagID = diag::err_fe_inline_asm; 754 llvm::DiagnosticSeverity Severity = DI.getSeverity(); 755 // Get the diagnostic ID based. 756 switch (DI.getKind()) { 757 case llvm::DK_InlineAsm: 758 if (InlineAsmDiagHandler(cast<DiagnosticInfoInlineAsm>(DI))) 759 return; 760 ComputeDiagID(Severity, inline_asm, DiagID); 761 break; 762 case llvm::DK_StackSize: 763 if (StackSizeDiagHandler(cast<DiagnosticInfoStackSize>(DI))) 764 return; 765 ComputeDiagID(Severity, backend_frame_larger_than, DiagID); 766 break; 767 case DK_Linker: 768 assert(CurLinkModule); 769 // FIXME: stop eating the warnings and notes. 770 if (Severity != DS_Error) 771 return; 772 DiagID = diag::err_fe_cannot_link_module; 773 break; 774 case llvm::DK_OptimizationRemark: 775 // Optimization remarks are always handled completely by this 776 // handler. There is no generic way of emitting them. 777 OptimizationRemarkHandler(cast<OptimizationRemark>(DI)); 778 return; 779 case llvm::DK_OptimizationRemarkMissed: 780 // Optimization remarks are always handled completely by this 781 // handler. There is no generic way of emitting them. 782 OptimizationRemarkHandler(cast<OptimizationRemarkMissed>(DI)); 783 return; 784 case llvm::DK_OptimizationRemarkAnalysis: 785 // Optimization remarks are always handled completely by this 786 // handler. There is no generic way of emitting them. 787 OptimizationRemarkHandler(cast<OptimizationRemarkAnalysis>(DI)); 788 return; 789 case llvm::DK_OptimizationRemarkAnalysisFPCommute: 790 // Optimization remarks are always handled completely by this 791 // handler. There is no generic way of emitting them. 792 OptimizationRemarkHandler(cast<OptimizationRemarkAnalysisFPCommute>(DI)); 793 return; 794 case llvm::DK_OptimizationRemarkAnalysisAliasing: 795 // Optimization remarks are always handled completely by this 796 // handler. There is no generic way of emitting them. 797 OptimizationRemarkHandler(cast<OptimizationRemarkAnalysisAliasing>(DI)); 798 return; 799 case llvm::DK_MachineOptimizationRemark: 800 // Optimization remarks are always handled completely by this 801 // handler. There is no generic way of emitting them. 802 OptimizationRemarkHandler(cast<MachineOptimizationRemark>(DI)); 803 return; 804 case llvm::DK_MachineOptimizationRemarkMissed: 805 // Optimization remarks are always handled completely by this 806 // handler. There is no generic way of emitting them. 807 OptimizationRemarkHandler(cast<MachineOptimizationRemarkMissed>(DI)); 808 return; 809 case llvm::DK_MachineOptimizationRemarkAnalysis: 810 // Optimization remarks are always handled completely by this 811 // handler. There is no generic way of emitting them. 812 OptimizationRemarkHandler(cast<MachineOptimizationRemarkAnalysis>(DI)); 813 return; 814 case llvm::DK_OptimizationFailure: 815 // Optimization failures are always handled completely by this 816 // handler. 817 OptimizationFailureHandler(cast<DiagnosticInfoOptimizationFailure>(DI)); 818 return; 819 case llvm::DK_Unsupported: 820 UnsupportedDiagHandler(cast<DiagnosticInfoUnsupported>(DI)); 821 return; 822 case llvm::DK_MisExpect: 823 MisExpectDiagHandler(cast<DiagnosticInfoMisExpect>(DI)); 824 return; 825 default: 826 // Plugin IDs are not bound to any value as they are set dynamically. 827 ComputeDiagRemarkID(Severity, backend_plugin, DiagID); 828 break; 829 } 830 std::string MsgStorage; 831 { 832 raw_string_ostream Stream(MsgStorage); 833 DiagnosticPrinterRawOStream DP(Stream); 834 DI.print(DP); 835 } 836 837 if (DiagID == diag::err_fe_cannot_link_module) { 838 Diags.Report(diag::err_fe_cannot_link_module) 839 << CurLinkModule->getModuleIdentifier() << MsgStorage; 840 return; 841 } 842 843 // Report the backend message using the usual diagnostic mechanism. 844 FullSourceLoc Loc; 845 Diags.Report(Loc, DiagID).AddString(MsgStorage); 846 } 847 #undef ComputeDiagID 848 849 CodeGenAction::CodeGenAction(unsigned _Act, LLVMContext *_VMContext) 850 : Act(_Act), VMContext(_VMContext ? _VMContext : new LLVMContext), 851 OwnsVMContext(!_VMContext) {} 852 853 CodeGenAction::~CodeGenAction() { 854 TheModule.reset(); 855 if (OwnsVMContext) 856 delete VMContext; 857 } 858 859 bool CodeGenAction::hasIRSupport() const { return true; } 860 861 void CodeGenAction::EndSourceFileAction() { 862 // If the consumer creation failed, do nothing. 863 if (!getCompilerInstance().hasASTConsumer()) 864 return; 865 866 // Steal the module from the consumer. 867 TheModule = BEConsumer->takeModule(); 868 } 869 870 std::unique_ptr<llvm::Module> CodeGenAction::takeModule() { 871 return std::move(TheModule); 872 } 873 874 llvm::LLVMContext *CodeGenAction::takeLLVMContext() { 875 OwnsVMContext = false; 876 return VMContext; 877 } 878 879 static std::unique_ptr<raw_pwrite_stream> 880 GetOutputStream(CompilerInstance &CI, StringRef InFile, BackendAction Action) { 881 switch (Action) { 882 case Backend_EmitAssembly: 883 return CI.createDefaultOutputFile(false, InFile, "s"); 884 case Backend_EmitLL: 885 return CI.createDefaultOutputFile(false, InFile, "ll"); 886 case Backend_EmitBC: 887 return CI.createDefaultOutputFile(true, InFile, "bc"); 888 case Backend_EmitNothing: 889 return nullptr; 890 case Backend_EmitMCNull: 891 return CI.createNullOutputFile(); 892 case Backend_EmitObj: 893 return CI.createDefaultOutputFile(true, InFile, "o"); 894 } 895 896 llvm_unreachable("Invalid action!"); 897 } 898 899 std::unique_ptr<ASTConsumer> 900 CodeGenAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) { 901 BackendAction BA = static_cast<BackendAction>(Act); 902 std::unique_ptr<raw_pwrite_stream> OS = CI.takeOutputStream(); 903 if (!OS) 904 OS = GetOutputStream(CI, InFile, BA); 905 906 if (BA != Backend_EmitNothing && !OS) 907 return nullptr; 908 909 // Load bitcode modules to link with, if we need to. 910 if (LinkModules.empty()) 911 for (const CodeGenOptions::BitcodeFileToLink &F : 912 CI.getCodeGenOpts().LinkBitcodeFiles) { 913 auto BCBuf = CI.getFileManager().getBufferForFile(F.Filename); 914 if (!BCBuf) { 915 CI.getDiagnostics().Report(diag::err_cannot_open_file) 916 << F.Filename << BCBuf.getError().message(); 917 LinkModules.clear(); 918 return nullptr; 919 } 920 921 Expected<std::unique_ptr<llvm::Module>> ModuleOrErr = 922 getOwningLazyBitcodeModule(std::move(*BCBuf), *VMContext); 923 if (!ModuleOrErr) { 924 handleAllErrors(ModuleOrErr.takeError(), [&](ErrorInfoBase &EIB) { 925 CI.getDiagnostics().Report(diag::err_cannot_open_file) 926 << F.Filename << EIB.message(); 927 }); 928 LinkModules.clear(); 929 return nullptr; 930 } 931 LinkModules.push_back({std::move(ModuleOrErr.get()), F.PropagateAttrs, 932 F.Internalize, F.LinkFlags}); 933 } 934 935 CoverageSourceInfo *CoverageInfo = nullptr; 936 // Add the preprocessor callback only when the coverage mapping is generated. 937 if (CI.getCodeGenOpts().CoverageMapping) { 938 CoverageInfo = new CoverageSourceInfo; 939 CI.getPreprocessor().addPPCallbacks( 940 std::unique_ptr<PPCallbacks>(CoverageInfo)); 941 } 942 943 std::unique_ptr<BackendConsumer> Result(new BackendConsumer( 944 BA, CI.getDiagnostics(), CI.getHeaderSearchOpts(), 945 CI.getPreprocessorOpts(), CI.getCodeGenOpts(), CI.getTargetOpts(), 946 CI.getLangOpts(), CI.getFrontendOpts().ShowTimers, InFile, 947 std::move(LinkModules), std::move(OS), *VMContext, CoverageInfo)); 948 BEConsumer = Result.get(); 949 950 // Enable generating macro debug info only when debug info is not disabled and 951 // also macro debug info is enabled. 952 if (CI.getCodeGenOpts().getDebugInfo() != codegenoptions::NoDebugInfo && 953 CI.getCodeGenOpts().MacroDebugInfo) { 954 std::unique_ptr<PPCallbacks> Callbacks = 955 std::make_unique<MacroPPCallbacks>(BEConsumer->getCodeGenerator(), 956 CI.getPreprocessor()); 957 CI.getPreprocessor().addPPCallbacks(std::move(Callbacks)); 958 } 959 960 return std::move(Result); 961 } 962 963 static void BitcodeInlineAsmDiagHandler(const llvm::SMDiagnostic &SM, 964 void *Context, 965 unsigned LocCookie) { 966 SM.print(nullptr, llvm::errs()); 967 968 auto Diags = static_cast<DiagnosticsEngine *>(Context); 969 unsigned DiagID; 970 switch (SM.getKind()) { 971 case llvm::SourceMgr::DK_Error: 972 DiagID = diag::err_fe_inline_asm; 973 break; 974 case llvm::SourceMgr::DK_Warning: 975 DiagID = diag::warn_fe_inline_asm; 976 break; 977 case llvm::SourceMgr::DK_Note: 978 DiagID = diag::note_fe_inline_asm; 979 break; 980 case llvm::SourceMgr::DK_Remark: 981 llvm_unreachable("remarks unexpected"); 982 } 983 984 Diags->Report(DiagID).AddString("cannot compile inline asm"); 985 } 986 987 std::unique_ptr<llvm::Module> 988 CodeGenAction::loadModule(MemoryBufferRef MBRef) { 989 CompilerInstance &CI = getCompilerInstance(); 990 SourceManager &SM = CI.getSourceManager(); 991 992 // For ThinLTO backend invocations, ensure that the context 993 // merges types based on ODR identifiers. We also need to read 994 // the correct module out of a multi-module bitcode file. 995 if (!CI.getCodeGenOpts().ThinLTOIndexFile.empty()) { 996 VMContext->enableDebugTypeODRUniquing(); 997 998 auto DiagErrors = [&](Error E) -> std::unique_ptr<llvm::Module> { 999 unsigned DiagID = 1000 CI.getDiagnostics().getCustomDiagID(DiagnosticsEngine::Error, "%0"); 1001 handleAllErrors(std::move(E), [&](ErrorInfoBase &EIB) { 1002 CI.getDiagnostics().Report(DiagID) << EIB.message(); 1003 }); 1004 return {}; 1005 }; 1006 1007 Expected<std::vector<BitcodeModule>> BMsOrErr = getBitcodeModuleList(MBRef); 1008 if (!BMsOrErr) 1009 return DiagErrors(BMsOrErr.takeError()); 1010 BitcodeModule *Bm = FindThinLTOModule(*BMsOrErr); 1011 // We have nothing to do if the file contains no ThinLTO module. This is 1012 // possible if ThinLTO compilation was not able to split module. Content of 1013 // the file was already processed by indexing and will be passed to the 1014 // linker using merged object file. 1015 if (!Bm) { 1016 auto M = std::make_unique<llvm::Module>("empty", *VMContext); 1017 M->setTargetTriple(CI.getTargetOpts().Triple); 1018 return M; 1019 } 1020 Expected<std::unique_ptr<llvm::Module>> MOrErr = 1021 Bm->parseModule(*VMContext); 1022 if (!MOrErr) 1023 return DiagErrors(MOrErr.takeError()); 1024 return std::move(*MOrErr); 1025 } 1026 1027 llvm::SMDiagnostic Err; 1028 if (std::unique_ptr<llvm::Module> M = parseIR(MBRef, Err, *VMContext)) 1029 return M; 1030 1031 // Translate from the diagnostic info to the SourceManager location if 1032 // available. 1033 // TODO: Unify this with ConvertBackendLocation() 1034 SourceLocation Loc; 1035 if (Err.getLineNo() > 0) { 1036 assert(Err.getColumnNo() >= 0); 1037 Loc = SM.translateFileLineCol(SM.getFileEntryForID(SM.getMainFileID()), 1038 Err.getLineNo(), Err.getColumnNo() + 1); 1039 } 1040 1041 // Strip off a leading diagnostic code if there is one. 1042 StringRef Msg = Err.getMessage(); 1043 if (Msg.startswith("error: ")) 1044 Msg = Msg.substr(7); 1045 1046 unsigned DiagID = 1047 CI.getDiagnostics().getCustomDiagID(DiagnosticsEngine::Error, "%0"); 1048 1049 CI.getDiagnostics().Report(Loc, DiagID) << Msg; 1050 return {}; 1051 } 1052 1053 void CodeGenAction::ExecuteAction() { 1054 // If this is an IR file, we have to treat it specially. 1055 if (getCurrentFileKind().getLanguage() == Language::LLVM_IR) { 1056 BackendAction BA = static_cast<BackendAction>(Act); 1057 CompilerInstance &CI = getCompilerInstance(); 1058 auto &CodeGenOpts = CI.getCodeGenOpts(); 1059 auto &Diagnostics = CI.getDiagnostics(); 1060 std::unique_ptr<raw_pwrite_stream> OS = 1061 GetOutputStream(CI, getCurrentFile(), BA); 1062 if (BA != Backend_EmitNothing && !OS) 1063 return; 1064 1065 bool Invalid; 1066 SourceManager &SM = CI.getSourceManager(); 1067 FileID FID = SM.getMainFileID(); 1068 const llvm::MemoryBuffer *MainFile = SM.getBuffer(FID, &Invalid); 1069 if (Invalid) 1070 return; 1071 1072 TheModule = loadModule(*MainFile); 1073 if (!TheModule) 1074 return; 1075 1076 const TargetOptions &TargetOpts = CI.getTargetOpts(); 1077 if (TheModule->getTargetTriple() != TargetOpts.Triple) { 1078 Diagnostics.Report(SourceLocation(), 1079 diag::warn_fe_override_module) 1080 << TargetOpts.Triple; 1081 TheModule->setTargetTriple(TargetOpts.Triple); 1082 } 1083 1084 EmbedBitcode(TheModule.get(), CodeGenOpts, 1085 MainFile->getMemBufferRef()); 1086 1087 LLVMContext &Ctx = TheModule->getContext(); 1088 Ctx.setInlineAsmDiagnosticHandler(BitcodeInlineAsmDiagHandler, 1089 &Diagnostics); 1090 1091 Expected<std::unique_ptr<llvm::ToolOutputFile>> OptRecordFileOrErr = 1092 setupOptimizationRemarks( 1093 Ctx, CodeGenOpts.OptRecordFile, 1094 CodeGenOpts.OptRecordPasses, 1095 CodeGenOpts.OptRecordFormat, 1096 CodeGenOpts.DiagnosticsWithHotness, 1097 CodeGenOpts.DiagnosticsHotnessThreshold); 1098 1099 if (Error E = OptRecordFileOrErr.takeError()) { 1100 reportOptRecordError(std::move(E), Diagnostics, CodeGenOpts); 1101 return; 1102 } 1103 std::unique_ptr<llvm::ToolOutputFile> OptRecordFile = 1104 std::move(*OptRecordFileOrErr); 1105 1106 EmitBackendOutput(Diagnostics, CI.getHeaderSearchOpts(), 1107 CodeGenOpts, TargetOpts, CI.getLangOpts(), 1108 CI.getTarget().getDataLayout(), TheModule.get(), BA, 1109 std::move(OS)); 1110 1111 if (OptRecordFile) 1112 OptRecordFile->keep(); 1113 return; 1114 } 1115 1116 // Otherwise follow the normal AST path. 1117 this->ASTFrontendAction::ExecuteAction(); 1118 } 1119 1120 // 1121 1122 void EmitAssemblyAction::anchor() { } 1123 EmitAssemblyAction::EmitAssemblyAction(llvm::LLVMContext *_VMContext) 1124 : CodeGenAction(Backend_EmitAssembly, _VMContext) {} 1125 1126 void EmitBCAction::anchor() { } 1127 EmitBCAction::EmitBCAction(llvm::LLVMContext *_VMContext) 1128 : CodeGenAction(Backend_EmitBC, _VMContext) {} 1129 1130 void EmitLLVMAction::anchor() { } 1131 EmitLLVMAction::EmitLLVMAction(llvm::LLVMContext *_VMContext) 1132 : CodeGenAction(Backend_EmitLL, _VMContext) {} 1133 1134 void EmitLLVMOnlyAction::anchor() { } 1135 EmitLLVMOnlyAction::EmitLLVMOnlyAction(llvm::LLVMContext *_VMContext) 1136 : CodeGenAction(Backend_EmitNothing, _VMContext) {} 1137 1138 void EmitCodeGenOnlyAction::anchor() { } 1139 EmitCodeGenOnlyAction::EmitCodeGenOnlyAction(llvm::LLVMContext *_VMContext) 1140 : CodeGenAction(Backend_EmitMCNull, _VMContext) {} 1141 1142 void EmitObjAction::anchor() { } 1143 EmitObjAction::EmitObjAction(llvm::LLVMContext *_VMContext) 1144 : CodeGenAction(Backend_EmitObj, _VMContext) {} 1145