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 AssignInheritanceModel(CXXRecordDecl *RD) override { 340 Gen->AssignInheritanceModel(RD); 341 } 342 343 void HandleVTable(CXXRecordDecl *RD) override { 344 Gen->HandleVTable(RD); 345 } 346 347 static void InlineAsmDiagHandler(const llvm::SMDiagnostic &SM,void *Context, 348 unsigned LocCookie) { 349 SourceLocation Loc = SourceLocation::getFromRawEncoding(LocCookie); 350 ((BackendConsumer*)Context)->InlineAsmDiagHandler2(SM, Loc); 351 } 352 353 /// Get the best possible source location to represent a diagnostic that 354 /// may have associated debug info. 355 const FullSourceLoc 356 getBestLocationFromDebugLoc(const llvm::DiagnosticInfoWithLocationBase &D, 357 bool &BadDebugInfo, StringRef &Filename, 358 unsigned &Line, unsigned &Column) const; 359 360 void InlineAsmDiagHandler2(const llvm::SMDiagnostic &, 361 SourceLocation LocCookie); 362 363 void DiagnosticHandlerImpl(const llvm::DiagnosticInfo &DI); 364 /// Specialized handler for InlineAsm diagnostic. 365 /// \return True if the diagnostic has been successfully reported, false 366 /// otherwise. 367 bool InlineAsmDiagHandler(const llvm::DiagnosticInfoInlineAsm &D); 368 /// Specialized handler for StackSize diagnostic. 369 /// \return True if the diagnostic has been successfully reported, false 370 /// otherwise. 371 bool StackSizeDiagHandler(const llvm::DiagnosticInfoStackSize &D); 372 /// Specialized handler for unsupported backend feature diagnostic. 373 void UnsupportedDiagHandler(const llvm::DiagnosticInfoUnsupported &D); 374 /// Specialized handler for misexpect warnings. 375 /// Note that misexpect remarks are emitted through ORE 376 void MisExpectDiagHandler(const llvm::DiagnosticInfoMisExpect &D); 377 /// Specialized handlers for optimization remarks. 378 /// Note that these handlers only accept remarks and they always handle 379 /// them. 380 void EmitOptimizationMessage(const llvm::DiagnosticInfoOptimizationBase &D, 381 unsigned DiagID); 382 void 383 OptimizationRemarkHandler(const llvm::DiagnosticInfoOptimizationBase &D); 384 void OptimizationRemarkHandler( 385 const llvm::OptimizationRemarkAnalysisFPCommute &D); 386 void OptimizationRemarkHandler( 387 const llvm::OptimizationRemarkAnalysisAliasing &D); 388 void OptimizationFailureHandler( 389 const llvm::DiagnosticInfoOptimizationFailure &D); 390 }; 391 392 void BackendConsumer::anchor() {} 393 } 394 395 bool ClangDiagnosticHandler::handleDiagnostics(const DiagnosticInfo &DI) { 396 BackendCon->DiagnosticHandlerImpl(DI); 397 return true; 398 } 399 400 /// ConvertBackendLocation - Convert a location in a temporary llvm::SourceMgr 401 /// buffer to be a valid FullSourceLoc. 402 static FullSourceLoc ConvertBackendLocation(const llvm::SMDiagnostic &D, 403 SourceManager &CSM) { 404 // Get both the clang and llvm source managers. The location is relative to 405 // a memory buffer that the LLVM Source Manager is handling, we need to add 406 // a copy to the Clang source manager. 407 const llvm::SourceMgr &LSM = *D.getSourceMgr(); 408 409 // We need to copy the underlying LLVM memory buffer because llvm::SourceMgr 410 // already owns its one and clang::SourceManager wants to own its one. 411 const MemoryBuffer *LBuf = 412 LSM.getMemoryBuffer(LSM.FindBufferContainingLoc(D.getLoc())); 413 414 // Create the copy and transfer ownership to clang::SourceManager. 415 // TODO: Avoid copying files into memory. 416 std::unique_ptr<llvm::MemoryBuffer> CBuf = 417 llvm::MemoryBuffer::getMemBufferCopy(LBuf->getBuffer(), 418 LBuf->getBufferIdentifier()); 419 // FIXME: Keep a file ID map instead of creating new IDs for each location. 420 FileID FID = CSM.createFileID(std::move(CBuf)); 421 422 // Translate the offset into the file. 423 unsigned Offset = D.getLoc().getPointer() - LBuf->getBufferStart(); 424 SourceLocation NewLoc = 425 CSM.getLocForStartOfFile(FID).getLocWithOffset(Offset); 426 return FullSourceLoc(NewLoc, CSM); 427 } 428 429 430 /// InlineAsmDiagHandler2 - This function is invoked when the backend hits an 431 /// error parsing inline asm. The SMDiagnostic indicates the error relative to 432 /// the temporary memory buffer that the inline asm parser has set up. 433 void BackendConsumer::InlineAsmDiagHandler2(const llvm::SMDiagnostic &D, 434 SourceLocation LocCookie) { 435 // There are a couple of different kinds of errors we could get here. First, 436 // we re-format the SMDiagnostic in terms of a clang diagnostic. 437 438 // Strip "error: " off the start of the message string. 439 StringRef Message = D.getMessage(); 440 if (Message.startswith("error: ")) 441 Message = Message.substr(7); 442 443 // If the SMDiagnostic has an inline asm source location, translate it. 444 FullSourceLoc Loc; 445 if (D.getLoc() != SMLoc()) 446 Loc = ConvertBackendLocation(D, Context->getSourceManager()); 447 448 unsigned DiagID; 449 switch (D.getKind()) { 450 case llvm::SourceMgr::DK_Error: 451 DiagID = diag::err_fe_inline_asm; 452 break; 453 case llvm::SourceMgr::DK_Warning: 454 DiagID = diag::warn_fe_inline_asm; 455 break; 456 case llvm::SourceMgr::DK_Note: 457 DiagID = diag::note_fe_inline_asm; 458 break; 459 case llvm::SourceMgr::DK_Remark: 460 llvm_unreachable("remarks unexpected"); 461 } 462 // If this problem has clang-level source location information, report the 463 // issue in the source with a note showing the instantiated 464 // code. 465 if (LocCookie.isValid()) { 466 Diags.Report(LocCookie, DiagID).AddString(Message); 467 468 if (D.getLoc().isValid()) { 469 DiagnosticBuilder B = Diags.Report(Loc, diag::note_fe_inline_asm_here); 470 // Convert the SMDiagnostic ranges into SourceRange and attach them 471 // to the diagnostic. 472 for (const std::pair<unsigned, unsigned> &Range : D.getRanges()) { 473 unsigned Column = D.getColumnNo(); 474 B << SourceRange(Loc.getLocWithOffset(Range.first - Column), 475 Loc.getLocWithOffset(Range.second - Column)); 476 } 477 } 478 return; 479 } 480 481 // Otherwise, report the backend issue as occurring in the generated .s file. 482 // If Loc is invalid, we still need to report the issue, it just gets no 483 // location info. 484 Diags.Report(Loc, DiagID).AddString(Message); 485 } 486 487 #define ComputeDiagID(Severity, GroupName, DiagID) \ 488 do { \ 489 switch (Severity) { \ 490 case llvm::DS_Error: \ 491 DiagID = diag::err_fe_##GroupName; \ 492 break; \ 493 case llvm::DS_Warning: \ 494 DiagID = diag::warn_fe_##GroupName; \ 495 break; \ 496 case llvm::DS_Remark: \ 497 llvm_unreachable("'remark' severity not expected"); \ 498 break; \ 499 case llvm::DS_Note: \ 500 DiagID = diag::note_fe_##GroupName; \ 501 break; \ 502 } \ 503 } while (false) 504 505 #define ComputeDiagRemarkID(Severity, GroupName, DiagID) \ 506 do { \ 507 switch (Severity) { \ 508 case llvm::DS_Error: \ 509 DiagID = diag::err_fe_##GroupName; \ 510 break; \ 511 case llvm::DS_Warning: \ 512 DiagID = diag::warn_fe_##GroupName; \ 513 break; \ 514 case llvm::DS_Remark: \ 515 DiagID = diag::remark_fe_##GroupName; \ 516 break; \ 517 case llvm::DS_Note: \ 518 DiagID = diag::note_fe_##GroupName; \ 519 break; \ 520 } \ 521 } while (false) 522 523 bool 524 BackendConsumer::InlineAsmDiagHandler(const llvm::DiagnosticInfoInlineAsm &D) { 525 unsigned DiagID; 526 ComputeDiagID(D.getSeverity(), inline_asm, DiagID); 527 std::string Message = D.getMsgStr().str(); 528 529 // If this problem has clang-level source location information, report the 530 // issue as being a problem in the source with a note showing the instantiated 531 // code. 532 SourceLocation LocCookie = 533 SourceLocation::getFromRawEncoding(D.getLocCookie()); 534 if (LocCookie.isValid()) 535 Diags.Report(LocCookie, DiagID).AddString(Message); 536 else { 537 // Otherwise, report the backend diagnostic as occurring in the generated 538 // .s file. 539 // If Loc is invalid, we still need to report the diagnostic, it just gets 540 // no location info. 541 FullSourceLoc Loc; 542 Diags.Report(Loc, DiagID).AddString(Message); 543 } 544 // We handled all the possible severities. 545 return true; 546 } 547 548 bool 549 BackendConsumer::StackSizeDiagHandler(const llvm::DiagnosticInfoStackSize &D) { 550 if (D.getSeverity() != llvm::DS_Warning) 551 // For now, the only support we have for StackSize diagnostic is warning. 552 // We do not know how to format other severities. 553 return false; 554 555 if (const Decl *ND = Gen->GetDeclForMangledName(D.getFunction().getName())) { 556 // FIXME: Shouldn't need to truncate to uint32_t 557 Diags.Report(ND->getASTContext().getFullLoc(ND->getLocation()), 558 diag::warn_fe_frame_larger_than) 559 << static_cast<uint32_t>(D.getStackSize()) << Decl::castToDeclContext(ND); 560 return true; 561 } 562 563 return false; 564 } 565 566 const FullSourceLoc BackendConsumer::getBestLocationFromDebugLoc( 567 const llvm::DiagnosticInfoWithLocationBase &D, bool &BadDebugInfo, 568 StringRef &Filename, unsigned &Line, unsigned &Column) const { 569 SourceManager &SourceMgr = Context->getSourceManager(); 570 FileManager &FileMgr = SourceMgr.getFileManager(); 571 SourceLocation DILoc; 572 573 if (D.isLocationAvailable()) { 574 D.getLocation(Filename, Line, Column); 575 if (Line > 0) { 576 auto FE = FileMgr.getFile(Filename); 577 if (!FE) 578 FE = FileMgr.getFile(D.getAbsolutePath()); 579 if (FE) { 580 // If -gcolumn-info was not used, Column will be 0. This upsets the 581 // source manager, so pass 1 if Column is not set. 582 DILoc = SourceMgr.translateFileLineCol(*FE, Line, Column ? Column : 1); 583 } 584 } 585 BadDebugInfo = DILoc.isInvalid(); 586 } 587 588 // If a location isn't available, try to approximate it using the associated 589 // function definition. We use the definition's right brace to differentiate 590 // from diagnostics that genuinely relate to the function itself. 591 FullSourceLoc Loc(DILoc, SourceMgr); 592 if (Loc.isInvalid()) 593 if (const Decl *FD = Gen->GetDeclForMangledName(D.getFunction().getName())) 594 Loc = FD->getASTContext().getFullLoc(FD->getLocation()); 595 596 if (DILoc.isInvalid() && D.isLocationAvailable()) 597 // If we were not able to translate the file:line:col information 598 // back to a SourceLocation, at least emit a note stating that 599 // we could not translate this location. This can happen in the 600 // case of #line directives. 601 Diags.Report(Loc, diag::note_fe_backend_invalid_loc) 602 << Filename << Line << Column; 603 604 return Loc; 605 } 606 607 void BackendConsumer::UnsupportedDiagHandler( 608 const llvm::DiagnosticInfoUnsupported &D) { 609 // We only support errors. 610 assert(D.getSeverity() == llvm::DS_Error); 611 612 StringRef Filename; 613 unsigned Line, Column; 614 bool BadDebugInfo = false; 615 FullSourceLoc Loc = 616 getBestLocationFromDebugLoc(D, BadDebugInfo, Filename, Line, Column); 617 618 Diags.Report(Loc, diag::err_fe_backend_unsupported) << D.getMessage().str(); 619 620 if (BadDebugInfo) 621 // If we were not able to translate the file:line:col information 622 // back to a SourceLocation, at least emit a note stating that 623 // we could not translate this location. This can happen in the 624 // case of #line directives. 625 Diags.Report(Loc, diag::note_fe_backend_invalid_loc) 626 << Filename << Line << Column; 627 } 628 629 void BackendConsumer::MisExpectDiagHandler( 630 const llvm::DiagnosticInfoMisExpect &D) { 631 StringRef Filename; 632 unsigned Line, Column; 633 bool BadDebugInfo = false; 634 FullSourceLoc Loc = 635 getBestLocationFromDebugLoc(D, BadDebugInfo, Filename, Line, Column); 636 637 Diags.Report(Loc, diag::warn_profile_data_misexpect) << D.getMsg().str(); 638 639 if (BadDebugInfo) 640 // If we were not able to translate the file:line:col information 641 // back to a SourceLocation, at least emit a note stating that 642 // we could not translate this location. This can happen in the 643 // case of #line directives. 644 Diags.Report(Loc, diag::note_fe_backend_invalid_loc) 645 << Filename << Line << Column; 646 } 647 648 void BackendConsumer::EmitOptimizationMessage( 649 const llvm::DiagnosticInfoOptimizationBase &D, unsigned DiagID) { 650 // We only support warnings and remarks. 651 assert(D.getSeverity() == llvm::DS_Remark || 652 D.getSeverity() == llvm::DS_Warning); 653 654 StringRef Filename; 655 unsigned Line, Column; 656 bool BadDebugInfo = false; 657 FullSourceLoc Loc = 658 getBestLocationFromDebugLoc(D, BadDebugInfo, Filename, Line, Column); 659 660 std::string Msg; 661 raw_string_ostream MsgStream(Msg); 662 MsgStream << D.getMsg(); 663 664 if (D.getHotness()) 665 MsgStream << " (hotness: " << *D.getHotness() << ")"; 666 667 Diags.Report(Loc, DiagID) 668 << AddFlagValue(D.getPassName()) 669 << MsgStream.str(); 670 671 if (BadDebugInfo) 672 // If we were not able to translate the file:line:col information 673 // back to a SourceLocation, at least emit a note stating that 674 // we could not translate this location. This can happen in the 675 // case of #line directives. 676 Diags.Report(Loc, diag::note_fe_backend_invalid_loc) 677 << Filename << Line << Column; 678 } 679 680 void BackendConsumer::OptimizationRemarkHandler( 681 const llvm::DiagnosticInfoOptimizationBase &D) { 682 // Without hotness information, don't show noisy remarks. 683 if (D.isVerbose() && !D.getHotness()) 684 return; 685 686 if (D.isPassed()) { 687 // Optimization remarks are active only if the -Rpass flag has a regular 688 // expression that matches the name of the pass name in \p D. 689 if (CodeGenOpts.OptimizationRemarkPattern && 690 CodeGenOpts.OptimizationRemarkPattern->match(D.getPassName())) 691 EmitOptimizationMessage(D, diag::remark_fe_backend_optimization_remark); 692 } else if (D.isMissed()) { 693 // Missed optimization remarks are active only if the -Rpass-missed 694 // flag has a regular expression that matches the name of the pass 695 // name in \p D. 696 if (CodeGenOpts.OptimizationRemarkMissedPattern && 697 CodeGenOpts.OptimizationRemarkMissedPattern->match(D.getPassName())) 698 EmitOptimizationMessage( 699 D, diag::remark_fe_backend_optimization_remark_missed); 700 } else { 701 assert(D.isAnalysis() && "Unknown remark type"); 702 703 bool ShouldAlwaysPrint = false; 704 if (auto *ORA = dyn_cast<llvm::OptimizationRemarkAnalysis>(&D)) 705 ShouldAlwaysPrint = ORA->shouldAlwaysPrint(); 706 707 if (ShouldAlwaysPrint || 708 (CodeGenOpts.OptimizationRemarkAnalysisPattern && 709 CodeGenOpts.OptimizationRemarkAnalysisPattern->match(D.getPassName()))) 710 EmitOptimizationMessage( 711 D, diag::remark_fe_backend_optimization_remark_analysis); 712 } 713 } 714 715 void BackendConsumer::OptimizationRemarkHandler( 716 const llvm::OptimizationRemarkAnalysisFPCommute &D) { 717 // Optimization analysis remarks are active if the pass name is set to 718 // llvm::DiagnosticInfo::AlwasyPrint or if the -Rpass-analysis flag has a 719 // regular expression that matches the name of the pass name in \p D. 720 721 if (D.shouldAlwaysPrint() || 722 (CodeGenOpts.OptimizationRemarkAnalysisPattern && 723 CodeGenOpts.OptimizationRemarkAnalysisPattern->match(D.getPassName()))) 724 EmitOptimizationMessage( 725 D, diag::remark_fe_backend_optimization_remark_analysis_fpcommute); 726 } 727 728 void BackendConsumer::OptimizationRemarkHandler( 729 const llvm::OptimizationRemarkAnalysisAliasing &D) { 730 // Optimization analysis remarks are active if the pass name is set to 731 // llvm::DiagnosticInfo::AlwasyPrint or if the -Rpass-analysis flag has a 732 // regular expression that matches the name of the pass name in \p D. 733 734 if (D.shouldAlwaysPrint() || 735 (CodeGenOpts.OptimizationRemarkAnalysisPattern && 736 CodeGenOpts.OptimizationRemarkAnalysisPattern->match(D.getPassName()))) 737 EmitOptimizationMessage( 738 D, diag::remark_fe_backend_optimization_remark_analysis_aliasing); 739 } 740 741 void BackendConsumer::OptimizationFailureHandler( 742 const llvm::DiagnosticInfoOptimizationFailure &D) { 743 EmitOptimizationMessage(D, diag::warn_fe_backend_optimization_failure); 744 } 745 746 /// This function is invoked when the backend needs 747 /// to report something to the user. 748 void BackendConsumer::DiagnosticHandlerImpl(const DiagnosticInfo &DI) { 749 unsigned DiagID = diag::err_fe_inline_asm; 750 llvm::DiagnosticSeverity Severity = DI.getSeverity(); 751 // Get the diagnostic ID based. 752 switch (DI.getKind()) { 753 case llvm::DK_InlineAsm: 754 if (InlineAsmDiagHandler(cast<DiagnosticInfoInlineAsm>(DI))) 755 return; 756 ComputeDiagID(Severity, inline_asm, DiagID); 757 break; 758 case llvm::DK_StackSize: 759 if (StackSizeDiagHandler(cast<DiagnosticInfoStackSize>(DI))) 760 return; 761 ComputeDiagID(Severity, backend_frame_larger_than, DiagID); 762 break; 763 case DK_Linker: 764 assert(CurLinkModule); 765 // FIXME: stop eating the warnings and notes. 766 if (Severity != DS_Error) 767 return; 768 DiagID = diag::err_fe_cannot_link_module; 769 break; 770 case llvm::DK_OptimizationRemark: 771 // Optimization remarks are always handled completely by this 772 // handler. There is no generic way of emitting them. 773 OptimizationRemarkHandler(cast<OptimizationRemark>(DI)); 774 return; 775 case llvm::DK_OptimizationRemarkMissed: 776 // Optimization remarks are always handled completely by this 777 // handler. There is no generic way of emitting them. 778 OptimizationRemarkHandler(cast<OptimizationRemarkMissed>(DI)); 779 return; 780 case llvm::DK_OptimizationRemarkAnalysis: 781 // Optimization remarks are always handled completely by this 782 // handler. There is no generic way of emitting them. 783 OptimizationRemarkHandler(cast<OptimizationRemarkAnalysis>(DI)); 784 return; 785 case llvm::DK_OptimizationRemarkAnalysisFPCommute: 786 // Optimization remarks are always handled completely by this 787 // handler. There is no generic way of emitting them. 788 OptimizationRemarkHandler(cast<OptimizationRemarkAnalysisFPCommute>(DI)); 789 return; 790 case llvm::DK_OptimizationRemarkAnalysisAliasing: 791 // Optimization remarks are always handled completely by this 792 // handler. There is no generic way of emitting them. 793 OptimizationRemarkHandler(cast<OptimizationRemarkAnalysisAliasing>(DI)); 794 return; 795 case llvm::DK_MachineOptimizationRemark: 796 // Optimization remarks are always handled completely by this 797 // handler. There is no generic way of emitting them. 798 OptimizationRemarkHandler(cast<MachineOptimizationRemark>(DI)); 799 return; 800 case llvm::DK_MachineOptimizationRemarkMissed: 801 // Optimization remarks are always handled completely by this 802 // handler. There is no generic way of emitting them. 803 OptimizationRemarkHandler(cast<MachineOptimizationRemarkMissed>(DI)); 804 return; 805 case llvm::DK_MachineOptimizationRemarkAnalysis: 806 // Optimization remarks are always handled completely by this 807 // handler. There is no generic way of emitting them. 808 OptimizationRemarkHandler(cast<MachineOptimizationRemarkAnalysis>(DI)); 809 return; 810 case llvm::DK_OptimizationFailure: 811 // Optimization failures are always handled completely by this 812 // handler. 813 OptimizationFailureHandler(cast<DiagnosticInfoOptimizationFailure>(DI)); 814 return; 815 case llvm::DK_Unsupported: 816 UnsupportedDiagHandler(cast<DiagnosticInfoUnsupported>(DI)); 817 return; 818 case llvm::DK_MisExpect: 819 MisExpectDiagHandler(cast<DiagnosticInfoMisExpect>(DI)); 820 return; 821 default: 822 // Plugin IDs are not bound to any value as they are set dynamically. 823 ComputeDiagRemarkID(Severity, backend_plugin, DiagID); 824 break; 825 } 826 std::string MsgStorage; 827 { 828 raw_string_ostream Stream(MsgStorage); 829 DiagnosticPrinterRawOStream DP(Stream); 830 DI.print(DP); 831 } 832 833 if (DiagID == diag::err_fe_cannot_link_module) { 834 Diags.Report(diag::err_fe_cannot_link_module) 835 << CurLinkModule->getModuleIdentifier() << MsgStorage; 836 return; 837 } 838 839 // Report the backend message using the usual diagnostic mechanism. 840 FullSourceLoc Loc; 841 Diags.Report(Loc, DiagID).AddString(MsgStorage); 842 } 843 #undef ComputeDiagID 844 845 CodeGenAction::CodeGenAction(unsigned _Act, LLVMContext *_VMContext) 846 : Act(_Act), VMContext(_VMContext ? _VMContext : new LLVMContext), 847 OwnsVMContext(!_VMContext) {} 848 849 CodeGenAction::~CodeGenAction() { 850 TheModule.reset(); 851 if (OwnsVMContext) 852 delete VMContext; 853 } 854 855 bool CodeGenAction::hasIRSupport() const { return true; } 856 857 void CodeGenAction::EndSourceFileAction() { 858 // If the consumer creation failed, do nothing. 859 if (!getCompilerInstance().hasASTConsumer()) 860 return; 861 862 // Steal the module from the consumer. 863 TheModule = BEConsumer->takeModule(); 864 } 865 866 std::unique_ptr<llvm::Module> CodeGenAction::takeModule() { 867 return std::move(TheModule); 868 } 869 870 llvm::LLVMContext *CodeGenAction::takeLLVMContext() { 871 OwnsVMContext = false; 872 return VMContext; 873 } 874 875 static std::unique_ptr<raw_pwrite_stream> 876 GetOutputStream(CompilerInstance &CI, StringRef InFile, BackendAction Action) { 877 switch (Action) { 878 case Backend_EmitAssembly: 879 return CI.createDefaultOutputFile(false, InFile, "s"); 880 case Backend_EmitLL: 881 return CI.createDefaultOutputFile(false, InFile, "ll"); 882 case Backend_EmitBC: 883 return CI.createDefaultOutputFile(true, InFile, "bc"); 884 case Backend_EmitNothing: 885 return nullptr; 886 case Backend_EmitMCNull: 887 return CI.createNullOutputFile(); 888 case Backend_EmitObj: 889 return CI.createDefaultOutputFile(true, InFile, "o"); 890 } 891 892 llvm_unreachable("Invalid action!"); 893 } 894 895 std::unique_ptr<ASTConsumer> 896 CodeGenAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) { 897 BackendAction BA = static_cast<BackendAction>(Act); 898 std::unique_ptr<raw_pwrite_stream> OS = CI.takeOutputStream(); 899 if (!OS) 900 OS = GetOutputStream(CI, InFile, BA); 901 902 if (BA != Backend_EmitNothing && !OS) 903 return nullptr; 904 905 // Load bitcode modules to link with, if we need to. 906 if (LinkModules.empty()) 907 for (const CodeGenOptions::BitcodeFileToLink &F : 908 CI.getCodeGenOpts().LinkBitcodeFiles) { 909 auto BCBuf = CI.getFileManager().getBufferForFile(F.Filename); 910 if (!BCBuf) { 911 CI.getDiagnostics().Report(diag::err_cannot_open_file) 912 << F.Filename << BCBuf.getError().message(); 913 LinkModules.clear(); 914 return nullptr; 915 } 916 917 Expected<std::unique_ptr<llvm::Module>> ModuleOrErr = 918 getOwningLazyBitcodeModule(std::move(*BCBuf), *VMContext); 919 if (!ModuleOrErr) { 920 handleAllErrors(ModuleOrErr.takeError(), [&](ErrorInfoBase &EIB) { 921 CI.getDiagnostics().Report(diag::err_cannot_open_file) 922 << F.Filename << EIB.message(); 923 }); 924 LinkModules.clear(); 925 return nullptr; 926 } 927 LinkModules.push_back({std::move(ModuleOrErr.get()), F.PropagateAttrs, 928 F.Internalize, F.LinkFlags}); 929 } 930 931 CoverageSourceInfo *CoverageInfo = nullptr; 932 // Add the preprocessor callback only when the coverage mapping is generated. 933 if (CI.getCodeGenOpts().CoverageMapping) { 934 CoverageInfo = new CoverageSourceInfo; 935 CI.getPreprocessor().addPPCallbacks( 936 std::unique_ptr<PPCallbacks>(CoverageInfo)); 937 } 938 939 std::unique_ptr<BackendConsumer> Result(new BackendConsumer( 940 BA, CI.getDiagnostics(), CI.getHeaderSearchOpts(), 941 CI.getPreprocessorOpts(), CI.getCodeGenOpts(), CI.getTargetOpts(), 942 CI.getLangOpts(), CI.getFrontendOpts().ShowTimers, InFile, 943 std::move(LinkModules), std::move(OS), *VMContext, CoverageInfo)); 944 BEConsumer = Result.get(); 945 946 // Enable generating macro debug info only when debug info is not disabled and 947 // also macro debug info is enabled. 948 if (CI.getCodeGenOpts().getDebugInfo() != codegenoptions::NoDebugInfo && 949 CI.getCodeGenOpts().MacroDebugInfo) { 950 std::unique_ptr<PPCallbacks> Callbacks = 951 std::make_unique<MacroPPCallbacks>(BEConsumer->getCodeGenerator(), 952 CI.getPreprocessor()); 953 CI.getPreprocessor().addPPCallbacks(std::move(Callbacks)); 954 } 955 956 return std::move(Result); 957 } 958 959 static void BitcodeInlineAsmDiagHandler(const llvm::SMDiagnostic &SM, 960 void *Context, 961 unsigned LocCookie) { 962 SM.print(nullptr, llvm::errs()); 963 964 auto Diags = static_cast<DiagnosticsEngine *>(Context); 965 unsigned DiagID; 966 switch (SM.getKind()) { 967 case llvm::SourceMgr::DK_Error: 968 DiagID = diag::err_fe_inline_asm; 969 break; 970 case llvm::SourceMgr::DK_Warning: 971 DiagID = diag::warn_fe_inline_asm; 972 break; 973 case llvm::SourceMgr::DK_Note: 974 DiagID = diag::note_fe_inline_asm; 975 break; 976 case llvm::SourceMgr::DK_Remark: 977 llvm_unreachable("remarks unexpected"); 978 } 979 980 Diags->Report(DiagID).AddString("cannot compile inline asm"); 981 } 982 983 std::unique_ptr<llvm::Module> 984 CodeGenAction::loadModule(MemoryBufferRef MBRef) { 985 CompilerInstance &CI = getCompilerInstance(); 986 SourceManager &SM = CI.getSourceManager(); 987 988 // For ThinLTO backend invocations, ensure that the context 989 // merges types based on ODR identifiers. We also need to read 990 // the correct module out of a multi-module bitcode file. 991 if (!CI.getCodeGenOpts().ThinLTOIndexFile.empty()) { 992 VMContext->enableDebugTypeODRUniquing(); 993 994 auto DiagErrors = [&](Error E) -> std::unique_ptr<llvm::Module> { 995 unsigned DiagID = 996 CI.getDiagnostics().getCustomDiagID(DiagnosticsEngine::Error, "%0"); 997 handleAllErrors(std::move(E), [&](ErrorInfoBase &EIB) { 998 CI.getDiagnostics().Report(DiagID) << EIB.message(); 999 }); 1000 return {}; 1001 }; 1002 1003 Expected<std::vector<BitcodeModule>> BMsOrErr = getBitcodeModuleList(MBRef); 1004 if (!BMsOrErr) 1005 return DiagErrors(BMsOrErr.takeError()); 1006 BitcodeModule *Bm = FindThinLTOModule(*BMsOrErr); 1007 // We have nothing to do if the file contains no ThinLTO module. This is 1008 // possible if ThinLTO compilation was not able to split module. Content of 1009 // the file was already processed by indexing and will be passed to the 1010 // linker using merged object file. 1011 if (!Bm) { 1012 auto M = std::make_unique<llvm::Module>("empty", *VMContext); 1013 M->setTargetTriple(CI.getTargetOpts().Triple); 1014 return M; 1015 } 1016 Expected<std::unique_ptr<llvm::Module>> MOrErr = 1017 Bm->parseModule(*VMContext); 1018 if (!MOrErr) 1019 return DiagErrors(MOrErr.takeError()); 1020 return std::move(*MOrErr); 1021 } 1022 1023 llvm::SMDiagnostic Err; 1024 if (std::unique_ptr<llvm::Module> M = parseIR(MBRef, Err, *VMContext)) 1025 return M; 1026 1027 // Translate from the diagnostic info to the SourceManager location if 1028 // available. 1029 // TODO: Unify this with ConvertBackendLocation() 1030 SourceLocation Loc; 1031 if (Err.getLineNo() > 0) { 1032 assert(Err.getColumnNo() >= 0); 1033 Loc = SM.translateFileLineCol(SM.getFileEntryForID(SM.getMainFileID()), 1034 Err.getLineNo(), Err.getColumnNo() + 1); 1035 } 1036 1037 // Strip off a leading diagnostic code if there is one. 1038 StringRef Msg = Err.getMessage(); 1039 if (Msg.startswith("error: ")) 1040 Msg = Msg.substr(7); 1041 1042 unsigned DiagID = 1043 CI.getDiagnostics().getCustomDiagID(DiagnosticsEngine::Error, "%0"); 1044 1045 CI.getDiagnostics().Report(Loc, DiagID) << Msg; 1046 return {}; 1047 } 1048 1049 void CodeGenAction::ExecuteAction() { 1050 // If this is an IR file, we have to treat it specially. 1051 if (getCurrentFileKind().getLanguage() == Language::LLVM_IR) { 1052 BackendAction BA = static_cast<BackendAction>(Act); 1053 CompilerInstance &CI = getCompilerInstance(); 1054 auto &CodeGenOpts = CI.getCodeGenOpts(); 1055 auto &Diagnostics = CI.getDiagnostics(); 1056 std::unique_ptr<raw_pwrite_stream> OS = 1057 GetOutputStream(CI, getCurrentFile(), BA); 1058 if (BA != Backend_EmitNothing && !OS) 1059 return; 1060 1061 bool Invalid; 1062 SourceManager &SM = CI.getSourceManager(); 1063 FileID FID = SM.getMainFileID(); 1064 const llvm::MemoryBuffer *MainFile = SM.getBuffer(FID, &Invalid); 1065 if (Invalid) 1066 return; 1067 1068 TheModule = loadModule(*MainFile); 1069 if (!TheModule) 1070 return; 1071 1072 const TargetOptions &TargetOpts = CI.getTargetOpts(); 1073 if (TheModule->getTargetTriple() != TargetOpts.Triple) { 1074 Diagnostics.Report(SourceLocation(), 1075 diag::warn_fe_override_module) 1076 << TargetOpts.Triple; 1077 TheModule->setTargetTriple(TargetOpts.Triple); 1078 } 1079 1080 EmbedBitcode(TheModule.get(), CodeGenOpts, 1081 MainFile->getMemBufferRef()); 1082 1083 LLVMContext &Ctx = TheModule->getContext(); 1084 Ctx.setInlineAsmDiagnosticHandler(BitcodeInlineAsmDiagHandler, 1085 &Diagnostics); 1086 1087 Expected<std::unique_ptr<llvm::ToolOutputFile>> OptRecordFileOrErr = 1088 setupOptimizationRemarks( 1089 Ctx, CodeGenOpts.OptRecordFile, 1090 CodeGenOpts.OptRecordPasses, 1091 CodeGenOpts.OptRecordFormat, 1092 CodeGenOpts.DiagnosticsWithHotness, 1093 CodeGenOpts.DiagnosticsHotnessThreshold); 1094 1095 if (Error E = OptRecordFileOrErr.takeError()) { 1096 reportOptRecordError(std::move(E), Diagnostics, CodeGenOpts); 1097 return; 1098 } 1099 std::unique_ptr<llvm::ToolOutputFile> OptRecordFile = 1100 std::move(*OptRecordFileOrErr); 1101 1102 EmitBackendOutput(Diagnostics, CI.getHeaderSearchOpts(), 1103 CodeGenOpts, TargetOpts, CI.getLangOpts(), 1104 CI.getTarget().getDataLayout(), TheModule.get(), BA, 1105 std::move(OS)); 1106 1107 if (OptRecordFile) 1108 OptRecordFile->keep(); 1109 return; 1110 } 1111 1112 // Otherwise follow the normal AST path. 1113 this->ASTFrontendAction::ExecuteAction(); 1114 } 1115 1116 // 1117 1118 void EmitAssemblyAction::anchor() { } 1119 EmitAssemblyAction::EmitAssemblyAction(llvm::LLVMContext *_VMContext) 1120 : CodeGenAction(Backend_EmitAssembly, _VMContext) {} 1121 1122 void EmitBCAction::anchor() { } 1123 EmitBCAction::EmitBCAction(llvm::LLVMContext *_VMContext) 1124 : CodeGenAction(Backend_EmitBC, _VMContext) {} 1125 1126 void EmitLLVMAction::anchor() { } 1127 EmitLLVMAction::EmitLLVMAction(llvm::LLVMContext *_VMContext) 1128 : CodeGenAction(Backend_EmitLL, _VMContext) {} 1129 1130 void EmitLLVMOnlyAction::anchor() { } 1131 EmitLLVMOnlyAction::EmitLLVMOnlyAction(llvm::LLVMContext *_VMContext) 1132 : CodeGenAction(Backend_EmitNothing, _VMContext) {} 1133 1134 void EmitCodeGenOnlyAction::anchor() { } 1135 EmitCodeGenOnlyAction::EmitCodeGenOnlyAction(llvm::LLVMContext *_VMContext) 1136 : CodeGenAction(Backend_EmitMCNull, _VMContext) {} 1137 1138 void EmitObjAction::anchor() { } 1139 EmitObjAction::EmitObjAction(llvm::LLVMContext *_VMContext) 1140 : CodeGenAction(Backend_EmitObj, _VMContext) {} 1141