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" 49 using namespace clang;
57 : CodeGenOpts(CGOpts), BackendCon(BCon) {}
59 bool handleDiagnostics(
const DiagnosticInfo &DI)
override;
62 return (CodeGenOpts.OptimizationRemarkAnalysisPattern &&
63 CodeGenOpts.OptimizationRemarkAnalysisPattern->match(PassName));
66 return (CodeGenOpts.OptimizationRemarkMissedPattern &&
67 CodeGenOpts.OptimizationRemarkMissedPattern->match(PassName));
70 return (CodeGenOpts.OptimizationRemarkPattern &&
71 CodeGenOpts.OptimizationRemarkPattern->match(PassName));
75 return (CodeGenOpts.OptimizationRemarkAnalysisPattern ||
76 CodeGenOpts.OptimizationRemarkMissedPattern ||
77 CodeGenOpts.OptimizationRemarkPattern);
86 using LinkModule = CodeGenAction::LinkModule;
88 virtual void anchor();
95 std::unique_ptr<raw_pwrite_stream> AsmOutStream;
98 Timer LLVMIRGeneration;
99 unsigned LLVMIRGenerationRefCount;
104 bool IRGenFinished =
false;
106 std::unique_ptr<CodeGenerator> Gen;
112 llvm::Module *CurLinkModule =
nullptr;
121 const std::string &InFile,
123 std::unique_ptr<raw_pwrite_stream> OS, LLVMContext &
C,
125 : Diags(Diags), Action(Action), HeaderSearchOpts(HeaderSearchOpts),
126 CodeGenOpts(CodeGenOpts), TargetOpts(TargetOpts), LangOpts(LangOpts),
127 AsmOutStream(
std::move(OS)), Context(nullptr),
128 LLVMIRGeneration(
"irgen",
"LLVM IR Generation Time"),
129 LLVMIRGenerationRefCount(0),
131 CodeGenOpts, C, CoverageInfo)),
132 LinkModules(
std::move(LinkModules)) {
134 llvm::TimePassesIsEnabled = TimePasses;
136 llvm::Module *
getModule()
const {
return Gen->GetModule(); }
138 return std::unique_ptr<llvm::Module>(Gen->ReleaseModule());
144 Gen->HandleCXXStaticMemberVarInstantiation(VD);
148 assert(!Context &&
"initialized multiple times");
153 LLVMIRGeneration.startTimer();
155 Gen->Initialize(Ctx);
158 LLVMIRGeneration.stopTimer();
164 "LLVM IR generation of declaration");
168 LLVMIRGenerationRefCount += 1;
169 if (LLVMIRGenerationRefCount == 1)
170 LLVMIRGeneration.startTimer();
173 Gen->HandleTopLevelDecl(D);
176 LLVMIRGenerationRefCount -= 1;
177 if (LLVMIRGenerationRefCount == 0)
178 LLVMIRGeneration.stopTimer();
187 "LLVM IR generation of inline function");
189 LLVMIRGeneration.startTimer();
191 Gen->HandleInlineFunctionDefinition(D);
194 LLVMIRGeneration.stopTimer();
200 HandleTopLevelDecl(D);
205 for (
auto &LM : LinkModules) {
206 if (LM.PropagateAttrs)
207 for (Function &F : *LM.Module)
208 Gen->CGM().AddDefaultFnAttrs(F);
210 CurLinkModule = LM.Module.get();
213 if (LM.Internalize) {
214 Err = Linker::linkModules(
215 *getModule(), std::move(LM.Module), LM.LinkFlags,
216 [](llvm::Module &M,
const llvm::StringSet<> &GVS) {
217 internalizeModule(M, [&GVS](const llvm::GlobalValue &GV) {
218 return !GV.hasName() || (GVS.count(GV.getName()) == 0);
222 Err = Linker::linkModules(*getModule(), std::move(LM.Module),
234 llvm::TimeTraceScope TimeScope(
"Frontend", StringRef(
""));
235 PrettyStackTraceString CrashInfo(
"Per-file LLVM IR generation");
237 LLVMIRGenerationRefCount += 1;
238 if (LLVMIRGenerationRefCount == 1)
239 LLVMIRGeneration.startTimer();
242 Gen->HandleTranslationUnit(C);
245 LLVMIRGenerationRefCount -= 1;
246 if (LLVMIRGenerationRefCount == 0)
247 LLVMIRGeneration.stopTimer();
250 IRGenFinished =
true;
259 LLVMContext &Ctx = getModule()->getContext();
260 LLVMContext::InlineAsmDiagHandlerTy OldHandler =
261 Ctx.getInlineAsmDiagnosticHandler();
262 void *OldContext = Ctx.getInlineAsmDiagnosticContext();
263 Ctx.setInlineAsmDiagnosticHandler(InlineAsmDiagHandler,
this);
265 std::unique_ptr<DiagnosticHandler> OldDiagnosticHandler =
266 Ctx.getDiagnosticHandler();
267 Ctx.setDiagnosticHandler(std::make_unique<ClangDiagnosticHandler>(
271 setupOptimizationRemarks(Ctx, CodeGenOpts.OptRecordFile,
272 CodeGenOpts.OptRecordPasses,
273 CodeGenOpts.OptRecordFormat,
274 CodeGenOpts.DiagnosticsWithHotness,
275 CodeGenOpts.DiagnosticsHotnessThreshold);
277 if (
Error E = OptRecordFileOrErr.takeError()) {
280 [&](
const RemarkSetupFileError &E) {
281 Diags.Report(diag::err_cannot_open_file)
282 << CodeGenOpts.OptRecordFile << E.message();
284 [&](
const RemarkSetupPatternError &E) {
285 Diags.Report(diag::err_drv_optimization_remark_pattern)
286 << E.message() << CodeGenOpts.OptRecordPasses;
288 [&](
const RemarkSetupFormatError &E) {
289 Diags.Report(diag::err_drv_optimization_remark_format)
290 << CodeGenOpts.OptRecordFormat;
294 std::unique_ptr<llvm::ToolOutputFile> OptRecordFile =
295 std::move(*OptRecordFileOrErr);
299 Ctx.setDiagnosticsHotnessRequested(
true);
305 EmbedBitcode(getModule(), CodeGenOpts, llvm::MemoryBufferRef());
309 getModule(), Action, std::move(AsmOutStream));
311 Ctx.setInlineAsmDiagnosticHandler(OldHandler, OldContext);
313 Ctx.setDiagnosticHandler(std::move(OldDiagnosticHandler));
316 OptRecordFile->keep();
322 "LLVM IR generation of declaration");
323 Gen->HandleTagDeclDefinition(D);
327 Gen->HandleTagDeclRequiredDefinition(D);
331 Gen->CompleteTentativeDefinition(D);
335 Gen->AssignInheritanceModel(RD);
339 Gen->HandleVTable(RD);
343 unsigned LocCookie) {
351 getBestLocationFromDebugLoc(
const llvm::DiagnosticInfoWithLocationBase &D,
352 bool &BadDebugInfo, StringRef &
Filename,
353 unsigned &
Line,
unsigned &Column)
const;
355 void InlineAsmDiagHandler2(
const llvm::SMDiagnostic &,
358 void DiagnosticHandlerImpl(
const llvm::DiagnosticInfo &DI);
362 bool InlineAsmDiagHandler(
const llvm::DiagnosticInfoInlineAsm &D);
366 bool StackSizeDiagHandler(
const llvm::DiagnosticInfoStackSize &D);
368 void UnsupportedDiagHandler(
const llvm::DiagnosticInfoUnsupported &D);
371 void MisExpectDiagHandler(
const llvm::DiagnosticInfoMisExpect &D);
375 void EmitOptimizationMessage(
const llvm::DiagnosticInfoOptimizationBase &D,
378 OptimizationRemarkHandler(
const llvm::DiagnosticInfoOptimizationBase &D);
379 void OptimizationRemarkHandler(
380 const llvm::OptimizationRemarkAnalysisFPCommute &D);
381 void OptimizationRemarkHandler(
382 const llvm::OptimizationRemarkAnalysisAliasing &D);
383 void OptimizationFailureHandler(
384 const llvm::DiagnosticInfoOptimizationFailure &D);
387 void BackendConsumer::anchor() {}
391 BackendCon->DiagnosticHandlerImpl(DI);
402 const llvm::SourceMgr &LSM = *D.getSourceMgr();
406 const MemoryBuffer *LBuf =
407 LSM.getMemoryBuffer(LSM.FindBufferContainingLoc(D.getLoc()));
411 std::unique_ptr<llvm::MemoryBuffer> CBuf =
412 llvm::MemoryBuffer::getMemBufferCopy(LBuf->getBuffer(),
413 LBuf->getBufferIdentifier());
418 unsigned Offset = D.getLoc().getPointer() - LBuf->getBufferStart();
434 StringRef Message = D.getMessage();
435 if (Message.startswith(
"error: "))
436 Message = Message.substr(7);
440 if (D.getLoc() != SMLoc())
444 switch (D.getKind()) {
445 case llvm::SourceMgr::DK_Error:
446 DiagID = diag::err_fe_inline_asm;
448 case llvm::SourceMgr::DK_Warning:
449 DiagID = diag::warn_fe_inline_asm;
451 case llvm::SourceMgr::DK_Note:
452 DiagID = diag::note_fe_inline_asm;
454 case llvm::SourceMgr::DK_Remark:
455 llvm_unreachable(
"remarks unexpected");
461 Diags.Report(LocCookie, DiagID).AddString(Message);
463 if (D.getLoc().isValid()) {
467 for (
const std::pair<unsigned, unsigned> &Range : D.getRanges()) {
468 unsigned Column = D.getColumnNo();
479 Diags.Report(Loc, DiagID).AddString(Message);
482 #define ComputeDiagID(Severity, GroupName, DiagID) \ 484 switch (Severity) { \ 485 case llvm::DS_Error: \ 486 DiagID = diag::err_fe_##GroupName; \ 488 case llvm::DS_Warning: \ 489 DiagID = diag::warn_fe_##GroupName; \ 491 case llvm::DS_Remark: \ 492 llvm_unreachable("'remark' severity not expected"); \ 494 case llvm::DS_Note: \ 495 DiagID = diag::note_fe_##GroupName; \ 500 #define ComputeDiagRemarkID(Severity, GroupName, DiagID) \ 502 switch (Severity) { \ 503 case llvm::DS_Error: \ 504 DiagID = diag::err_fe_##GroupName; \ 506 case llvm::DS_Warning: \ 507 DiagID = diag::warn_fe_##GroupName; \ 509 case llvm::DS_Remark: \ 510 DiagID = diag::remark_fe_##GroupName; \ 512 case llvm::DS_Note: \ 513 DiagID = diag::note_fe_##GroupName; \ 522 std::string Message = D.getMsgStr().str();
530 Diags.Report(LocCookie, DiagID).AddString(Message);
537 Diags.Report(Loc, DiagID).AddString(Message);
545 if (D.getSeverity() != llvm::DS_Warning)
550 if (
const Decl *ND = Gen->GetDeclForMangledName(D.getFunction().getName())) {
552 Diags.Report(ND->getASTContext().getFullLoc(ND->getLocation()),
553 diag::warn_fe_frame_larger_than)
562 const llvm::DiagnosticInfoWithLocationBase &D,
bool &BadDebugInfo,
563 StringRef &
Filename,
unsigned &
Line,
unsigned &Column)
const {
568 if (D.isLocationAvailable()) {
569 D.getLocation(Filename, Line, Column);
571 auto FE = FileMgr.
getFile(Filename);
573 FE = FileMgr.
getFile(D.getAbsolutePath());
588 if (
const Decl *FD = Gen->GetDeclForMangledName(D.getFunction().getName()))
589 Loc = FD->getASTContext().getFullLoc(FD->getLocation());
591 if (DILoc.
isInvalid() && D.isLocationAvailable())
596 Diags.Report(Loc, diag::note_fe_backend_invalid_loc)
597 << Filename << Line << Column;
603 const llvm::DiagnosticInfoUnsupported &D) {
605 assert(D.getSeverity() == llvm::DS_Error);
608 unsigned Line, Column;
609 bool BadDebugInfo =
false;
611 getBestLocationFromDebugLoc(D, BadDebugInfo, Filename, Line, Column);
613 Diags.Report(Loc, diag::err_fe_backend_unsupported) << D.getMessage().str();
620 Diags.Report(Loc, diag::note_fe_backend_invalid_loc)
621 << Filename << Line << Column;
625 const llvm::DiagnosticInfoMisExpect &D) {
627 unsigned Line, Column;
628 bool BadDebugInfo =
false;
630 getBestLocationFromDebugLoc(D, BadDebugInfo, Filename, Line, Column);
632 Diags.Report(Loc, diag::warn_profile_data_misexpect) << D.getMsg().str();
639 Diags.Report(Loc, diag::note_fe_backend_invalid_loc)
640 << Filename << Line << Column;
644 const llvm::DiagnosticInfoOptimizationBase &D,
unsigned DiagID) {
646 assert(D.getSeverity() == llvm::DS_Remark ||
647 D.getSeverity() == llvm::DS_Warning);
650 unsigned Line, Column;
651 bool BadDebugInfo =
false;
653 getBestLocationFromDebugLoc(D, BadDebugInfo, Filename, Line, Column);
656 raw_string_ostream MsgStream(Msg);
657 MsgStream << D.getMsg();
660 MsgStream <<
" (hotness: " << *D.getHotness() <<
")";
662 Diags.Report(Loc, DiagID)
671 Diags.Report(Loc, diag::note_fe_backend_invalid_loc)
672 << Filename << Line << Column;
676 const llvm::DiagnosticInfoOptimizationBase &D) {
678 if (D.isVerbose() && !D.getHotness())
684 if (CodeGenOpts.OptimizationRemarkPattern &&
685 CodeGenOpts.OptimizationRemarkPattern->match(D.getPassName()))
686 EmitOptimizationMessage(D, diag::remark_fe_backend_optimization_remark);
687 }
else if (D.isMissed()) {
691 if (CodeGenOpts.OptimizationRemarkMissedPattern &&
692 CodeGenOpts.OptimizationRemarkMissedPattern->match(D.getPassName()))
693 EmitOptimizationMessage(
694 D, diag::remark_fe_backend_optimization_remark_missed);
696 assert(D.isAnalysis() &&
"Unknown remark type");
698 bool ShouldAlwaysPrint =
false;
699 if (
auto *ORA = dyn_cast<llvm::OptimizationRemarkAnalysis>(&D))
700 ShouldAlwaysPrint = ORA->shouldAlwaysPrint();
702 if (ShouldAlwaysPrint ||
703 (CodeGenOpts.OptimizationRemarkAnalysisPattern &&
704 CodeGenOpts.OptimizationRemarkAnalysisPattern->match(D.getPassName())))
705 EmitOptimizationMessage(
706 D, diag::remark_fe_backend_optimization_remark_analysis);
711 const llvm::OptimizationRemarkAnalysisFPCommute &D) {
716 if (D.shouldAlwaysPrint() ||
717 (CodeGenOpts.OptimizationRemarkAnalysisPattern &&
718 CodeGenOpts.OptimizationRemarkAnalysisPattern->match(D.getPassName())))
719 EmitOptimizationMessage(
720 D, diag::remark_fe_backend_optimization_remark_analysis_fpcommute);
724 const llvm::OptimizationRemarkAnalysisAliasing &D) {
729 if (D.shouldAlwaysPrint() ||
730 (CodeGenOpts.OptimizationRemarkAnalysisPattern &&
731 CodeGenOpts.OptimizationRemarkAnalysisPattern->match(D.getPassName())))
732 EmitOptimizationMessage(
733 D, diag::remark_fe_backend_optimization_remark_analysis_aliasing);
737 const llvm::DiagnosticInfoOptimizationFailure &D) {
738 EmitOptimizationMessage(D, diag::warn_fe_backend_optimization_failure);
744 unsigned DiagID = diag::err_fe_inline_asm;
745 llvm::DiagnosticSeverity
Severity = DI.getSeverity();
747 switch (DI.getKind()) {
748 case llvm::DK_InlineAsm:
749 if (InlineAsmDiagHandler(cast<DiagnosticInfoInlineAsm>(DI)))
753 case llvm::DK_StackSize:
754 if (StackSizeDiagHandler(cast<DiagnosticInfoStackSize>(DI)))
759 assert(CurLinkModule);
761 if (Severity != DS_Error)
763 DiagID = diag::err_fe_cannot_link_module;
765 case llvm::DK_OptimizationRemark:
768 OptimizationRemarkHandler(cast<OptimizationRemark>(DI));
770 case llvm::DK_OptimizationRemarkMissed:
773 OptimizationRemarkHandler(cast<OptimizationRemarkMissed>(DI));
775 case llvm::DK_OptimizationRemarkAnalysis:
778 OptimizationRemarkHandler(cast<OptimizationRemarkAnalysis>(DI));
780 case llvm::DK_OptimizationRemarkAnalysisFPCommute:
783 OptimizationRemarkHandler(cast<OptimizationRemarkAnalysisFPCommute>(DI));
785 case llvm::DK_OptimizationRemarkAnalysisAliasing:
788 OptimizationRemarkHandler(cast<OptimizationRemarkAnalysisAliasing>(DI));
790 case llvm::DK_MachineOptimizationRemark:
793 OptimizationRemarkHandler(cast<MachineOptimizationRemark>(DI));
795 case llvm::DK_MachineOptimizationRemarkMissed:
798 OptimizationRemarkHandler(cast<MachineOptimizationRemarkMissed>(DI));
800 case llvm::DK_MachineOptimizationRemarkAnalysis:
803 OptimizationRemarkHandler(cast<MachineOptimizationRemarkAnalysis>(DI));
805 case llvm::DK_OptimizationFailure:
808 OptimizationFailureHandler(cast<DiagnosticInfoOptimizationFailure>(DI));
810 case llvm::DK_Unsupported:
811 UnsupportedDiagHandler(cast<DiagnosticInfoUnsupported>(DI));
813 case llvm::DK_MisExpect:
814 MisExpectDiagHandler(cast<DiagnosticInfoMisExpect>(DI));
821 std::string MsgStorage;
823 raw_string_ostream Stream(MsgStorage);
824 DiagnosticPrinterRawOStream DP(Stream);
828 if (DiagID == diag::err_fe_cannot_link_module) {
829 Diags.Report(diag::err_fe_cannot_link_module)
830 << CurLinkModule->getModuleIdentifier() << MsgStorage;
836 Diags.Report(Loc, DiagID).AddString(MsgStorage);
841 : Act(_Act), VMContext(_VMContext ? _VMContext : new LLVMContext),
842 OwnsVMContext(!_VMContext) {}
862 return std::move(TheModule);
866 OwnsVMContext =
false;
870 static std::unique_ptr<raw_pwrite_stream>
887 llvm_unreachable(
"Invalid action!");
890 std::unique_ptr<ASTConsumer>
901 if (LinkModules.empty())
907 << F.Filename << BCBuf.getError().message();
913 getOwningLazyBitcodeModule(std::move(*BCBuf), *VMContext);
915 handleAllErrors(ModuleOrErr.takeError(), [&](ErrorInfoBase &EIB) {
917 << F.Filename << EIB.message();
922 LinkModules.push_back({std::move(ModuleOrErr.get()), F.PropagateAttrs,
923 F.Internalize, F.LinkFlags});
931 std::unique_ptr<PPCallbacks>(CoverageInfo));
938 std::move(LinkModules), std::move(OS), *VMContext, CoverageInfo));
945 std::unique_ptr<PPCallbacks> Callbacks =
951 return std::move(Result);
956 unsigned LocCookie) {
957 SM.print(
nullptr, llvm::errs());
961 switch (SM.getKind()) {
962 case llvm::SourceMgr::DK_Error:
963 DiagID = diag::err_fe_inline_asm;
965 case llvm::SourceMgr::DK_Warning:
966 DiagID = diag::warn_fe_inline_asm;
968 case llvm::SourceMgr::DK_Note:
969 DiagID = diag::note_fe_inline_asm;
971 case llvm::SourceMgr::DK_Remark:
972 llvm_unreachable(
"remarks unexpected");
975 Diags->Report(DiagID).AddString(
"cannot compile inline asm");
978 std::unique_ptr<llvm::Module>
979 CodeGenAction::loadModule(MemoryBufferRef MBRef) {
987 VMContext->enableDebugTypeODRUniquing();
989 auto DiagErrors = [&](
Error E) -> std::unique_ptr<llvm::Module> {
992 handleAllErrors(std::move(E), [&](ErrorInfoBase &EIB) {
1000 return DiagErrors(BMsOrErr.takeError());
1007 auto M = std::make_unique<llvm::Module>(
"empty", *VMContext);
1012 Bm->parseModule(*VMContext);
1014 return DiagErrors(MOrErr.takeError());
1015 return std::move(*MOrErr);
1018 llvm::SMDiagnostic Err;
1019 if (std::unique_ptr<llvm::Module> M = parseIR(MBRef, Err, *VMContext))
1026 if (Err.getLineNo() > 0) {
1027 assert(Err.getColumnNo() >= 0);
1029 Err.getLineNo(), Err.getColumnNo() + 1);
1033 StringRef Msg = Err.getMessage();
1034 if (Msg.startswith(
"error: "))
1035 Msg = Msg.substr(7);
1049 std::unique_ptr<raw_pwrite_stream> OS =
1057 const llvm::MemoryBuffer *MainFile = SM.
getBuffer(FID, &Invalid);
1061 TheModule = loadModule(*MainFile);
1066 if (TheModule->getTargetTriple() != TargetOpts.
Triple) {
1068 diag::warn_fe_override_module)
1070 TheModule->setTargetTriple(TargetOpts.
Triple);
1074 MainFile->getMemBufferRef());
1076 LLVMContext &Ctx = TheModule->getContext();
1093 void EmitAssemblyAction::anchor() { }
1097 void EmitBCAction::anchor() { }
1101 void EmitLLVMAction::anchor() { }
1105 void EmitLLVMOnlyAction::anchor() { }
1109 void EmitCodeGenOnlyAction::anchor() { }
1113 void EmitObjAction::anchor() { }
SourceLocation getLocForStartOfFile(FileID FID) const
Return the source location corresponding to the first byte of the specified file. ...
void EmitOptimizationMessage(const llvm::DiagnosticInfoOptimizationBase &D, unsigned DiagID)
Specialized handlers for optimization remarks.
Defines the clang::ASTContext interface.
LangOptions & getLangOpts()
void HandleInlineFunctionDefinition(FunctionDecl *D) override
This callback is invoked each time an inline (method or friend) function definition in a class is com...
Represents a function declaration or definition.
PreprocessorOptions & getPreprocessorOpts()
static void InlineAsmDiagHandler(const llvm::SMDiagnostic &SM, void *Context, unsigned LocCookie)
SourceLocation getLocWithOffset(int Offset) const
Return a source location with the specified offset from this SourceLocation.
static DeclContext * castToDeclContext(const Decl *)
bool isPassedOptRemarkEnabled(StringRef PassName) const override
Implements support for file system lookup, file system caching, and directory search management...
bool hasIRSupport() const override
Does this action support use with IR files?
ASTConsumer - This is an abstract interface that should be implemented by clients that read ASTs...
Defines the clang::FileManager interface and associated types.
Emit human-readable LLVM assembly.
Specialize PointerLikeTypeTraits to allow LazyGenerationalUpdatePtr to be placed into a PointerUnion...
Run CodeGen, but don't emit anything.
void EndSourceFileAction() override
Callback at the end of processing a single input.
void ExecuteAction() override
Implement the ExecuteAction interface by running Sema on the already-initialized AST consumer...
Defines the SourceManager interface.
Decl - This represents one declaration (or definition), e.g.
bool HandleTopLevelDecl(DeclGroupRef D) override
HandleTopLevelDecl - Handle the specified top-level declaration.
friend class BackendConsumer
Stores additional source code information like skipped ranges which is required by the coverage mappi...
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
const TargetInfo & getTargetInfo() const
void HandleTagDeclRequiredDefinition(const TagDecl *D) override
This callback is invoked the first time each TagDecl is required to be complete.
std::unique_ptr< llvm::Module > takeModule()
PreprocessorOptions - This class is used for passing the various options used in preprocessor initial...
Don't emit anything (benchmarking mode)
Represents a variable declaration or definition.
Options for controlling the target.
Severity
Enum values that allow the client to map NOTEs, WARNINGs, and EXTENSIONs to either Ignore (nothing)...
void HandleTagDeclDefinition(TagDecl *D) override
HandleTagDeclDefinition - This callback is invoked each time a TagDecl (e.g.
bool StackSizeDiagHandler(const llvm::DiagnosticInfoStackSize &D)
Specialized handler for StackSize diagnostic.
FileManager & getFileManager() const
bool isAnyRemarkEnabled() const override
#define ComputeDiagRemarkID(Severity, GroupName, DiagID)
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
static SourceLocation getFromRawEncoding(unsigned Encoding)
Turn a raw encoding of a SourceLocation object into a real SourceLocation.
void OptimizationFailureHandler(const llvm::DiagnosticInfoOptimizationFailure &D)
SourceLocation translateFileLineCol(const FileEntry *SourceFile, unsigned Line, unsigned Col) const
Get the source location for the given file:line:col triplet.
void CompleteTentativeDefinition(VarDecl *D) override
CompleteTentativeDefinition - Callback invoked at the end of a translation unit to notify the consume...
CodeGenOptions & getCodeGenOpts()
void ExecuteAction() override
Callback to run the program action, using the initialized compiler instance.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
CompilerInstance & getCompilerInstance() const
FrontendOptions & getFrontendOpts()
Concrete class used by the front-end to report problems and issues.
void DiagnosticHandlerImpl(const llvm::DiagnosticInfo &DI)
This function is invoked when the backend needs to report something to the user.
CodeGenerator * CreateLLVMCodeGen(DiagnosticsEngine &Diags, llvm::StringRef ModuleName, const HeaderSearchOptions &HeaderSearchOpts, const PreprocessorOptions &PreprocessorOpts, const CodeGenOptions &CGO, llvm::LLVMContext &C, CoverageSourceInfo *CoverageInfo=nullptr)
CreateLLVMCodeGen - Create a CodeGenerator instance.
void HandleInterestingDecl(DeclGroupRef D) override
HandleInterestingDecl - Handle the specified interesting declaration.
bool isMissedOptRemarkEnabled(StringRef PassName) const override
static void BitcodeInlineAsmDiagHandler(const llvm::SMDiagnostic &SM, void *Context, unsigned LocCookie)
The primary public interface to the Clang code generator.
HeaderSearchOptions & getHeaderSearchOpts()
bool handleDiagnostics(const DiagnosticInfo &DI) override
A little helper class used to produce diagnostics.
BackendConsumer * BEConsumer
EmitLLVMAction(llvm::LLVMContext *_VMContext=nullptr)
~CodeGenAction() override
const FileEntry * getFileEntryForID(FileID FID) const
Returns the FileEntry record for the provided FileID.
const AnnotatedLine * Line
CodeGenAction(unsigned _Act, llvm::LLVMContext *_VMContext=nullptr)
Create a new code generation action.
FileID createFileID(const FileEntry *SourceFile, SourceLocation IncludePos, SrcMgr::CharacteristicKind FileCharacter, int LoadedID=0, unsigned LoadedOffset=0)
Create a new FileID that represents the specified file being #included from the specified IncludePosi...
unsigned ShowTimers
Show timers for individual actions.
Defines the clang::Preprocessor interface.
Emit native object files.
EmitObjAction(llvm::LLVMContext *_VMContext=nullptr)
void OptimizationRemarkHandler(const llvm::DiagnosticInfoOptimizationBase &D)
InputKind getCurrentFileKind() const
The result type of a method or function.
static std::unique_ptr< raw_pwrite_stream > GetOutputStream(CompilerInstance &CI, StringRef InFile, BackendAction Action)
EmitBCAction(llvm::LLVMContext *_VMContext=nullptr)
llvm::Module * getModule() const
static FullSourceLoc ConvertBackendLocation(const llvm::SMDiagnostic &D, SourceManager &CSM)
ConvertBackendLocation - Convert a location in a temporary llvm::SourceMgr buffer to be a valid FullS...
Emit native assembly files.
void UnsupportedDiagHandler(const llvm::DiagnosticInfoUnsupported &D)
Specialized handler for unsupported backend feature diagnostic.
EmitCodeGenOnlyAction(llvm::LLVMContext *_VMContext=nullptr)
void AssignInheritanceModel(CXXRecordDecl *RD) override
Callback invoked when an MSInheritanceAttr has been attached to a CXXRecordDecl.
CompilerInstance - Helper class for managing a single instance of the Clang compiler.
Encodes a location in the source.
std::unique_ptr< llvm::raw_pwrite_stream > takeOutputStream()
Represents the declaration of a struct/union/class/enum.
std::unique_ptr< raw_pwrite_stream > createNullOutputFile()
void MisExpectDiagHandler(const llvm::DiagnosticInfoMisExpect &D)
Specialized handler for misexpect warnings.
const llvm::DataLayout & getDataLayout() const
#define ComputeDiagID(Severity, GroupName, DiagID)
unsigned getCustomDiagID(Level L, const char(&FormatString)[N])
Return an ID for a diagnostic with the specified format string and level.
std::vector< BitcodeFileToLink > LinkBitcodeFiles
The files specified here are linked in to the module before optimizations.
EmitLLVMOnlyAction(llvm::LLVMContext *_VMContext=nullptr)
std::string ThinLTOIndexFile
Name of the function summary index file to use for ThinLTO function importing.
std::unique_ptr< llvm::Module > takeModule()
Take the generated LLVM module, for use after the action has been run.
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
const llvm::MemoryBuffer * getBuffer(FileID FID, SourceLocation Loc, bool *Invalid=nullptr) const
Return the buffer for the specified FileID.
void EmbedBitcode(llvm::Module *M, const CodeGenOptions &CGOpts, llvm::MemoryBufferRef Buf)
Dataflow Directional Tag Classes.
bool isValid() const
Return true if this is a valid SourceLocation object.
FileManager & getFileManager() const
Return the current file manager to the caller.
bool FrontendTimesIsEnabled
If the user specifies the -ftime-report argument on an Clang command line then the value of this bool...
FileID getMainFileID() const
Returns the FileID of the main source file.
StringRef getCurrentFile() const
void EmitBackendOutput(DiagnosticsEngine &Diags, const HeaderSearchOptions &, const CodeGenOptions &CGOpts, const TargetOptions &TOpts, const LangOptions &LOpts, const llvm::DataLayout &TDesc, llvm::Module *M, BackendAction Action, std::unique_ptr< raw_pwrite_stream > OS)
SourceManager & getSourceManager() const
Return the current source manager.
void InlineAsmDiagHandler2(const llvm::SMDiagnostic &, SourceLocation LocCookie)
InlineAsmDiagHandler2 - This function is invoked when the backend hits an error parsing inline asm...
const FullSourceLoc getBestLocationFromDebugLoc(const llvm::DiagnosticInfoWithLocationBase &D, bool &BadDebugInfo, StringRef &Filename, unsigned &Line, unsigned &Column) const
Get the best possible source location to represent a diagnostic that may have associated debug info...
llvm::Expected< llvm::BitcodeModule > FindThinLTOModule(llvm::MemoryBufferRef MBRef)
void HandleVTable(CXXRecordDecl *RD) override
Callback involved at the end of a translation unit to notify the consumer that a vtable for the given...
llvm::ErrorOr< const FileEntry * > getFile(StringRef Filename, bool OpenFile=false, bool CacheFailure=true)
Lookup, cache, and verify the specified file (real or virtual).
void Initialize(ASTContext &Ctx) override
Initialize - This is called to initialize the consumer, providing the ASTContext. ...
TargetInfo & getTarget() const
CodeGenOptions - Track various options which control how the code is optimized and passed to the back...
std::unique_ptr< ASTConsumer > CreateASTConsumer(CompilerInstance &CI, StringRef InFile) override
Create the AST consumer object for this action, if supported.
std::unique_ptr< raw_pwrite_stream > createDefaultOutputFile(bool Binary=true, StringRef BaseInput="", StringRef Extension="")
Create the default output file (from the invocation's options) and add it to the list of tracked outp...
SourceManager & getSourceManager()
Preprocessor & getPreprocessor() const
Return the current preprocessor.
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate.h) and friends (in DeclFriend.h).
EmitAssemblyAction(llvm::LLVMContext *_VMContext=nullptr)
Represents a C++ struct/union/class.
llvm::LLVMContext * takeLLVMContext()
Take the LLVM context used by this action.
CodeGenerator * getCodeGenerator()
void HandleCXXStaticMemberVarInstantiation(VarDecl *VD) override
HandleCXXStaticMemberVarInstantiation - Tell the consumer that this.
ClangDiagnosticHandler(const CodeGenOptions &CGOpts, BackendConsumer *BCon)
Defines the clang::TargetInfo interface.
A SourceLocation and its associated SourceManager.
DiagnosticsEngine & getDiagnostics() const
Get the current diagnostics engine.
LLVM IR: we accept this so that we can run the optimizer on it, and compile it to assembly or object ...
void HandleTranslationUnit(ASTContext &C) override
HandleTranslationUnit - This method is called when the ASTs for entire translation unit have been par...
BackendConsumer(BackendAction Action, DiagnosticsEngine &Diags, const HeaderSearchOptions &HeaderSearchOpts, const PreprocessorOptions &PPOpts, const CodeGenOptions &CodeGenOpts, const TargetOptions &TargetOpts, const LangOptions &LangOpts, bool TimePasses, const std::string &InFile, SmallVector< LinkModule, 4 > LinkModules, std::unique_ptr< raw_pwrite_stream > OS, LLVMContext &C, CoverageSourceInfo *CoverageInfo=nullptr)
A trivial tuple used to represent a source range.
llvm::ErrorOr< std::unique_ptr< llvm::MemoryBuffer > > getBufferForFile(const FileEntry *Entry, bool isVolatile=false)
Open the specified file as a MemoryBuffer, returning a new MemoryBuffer if successful, otherwise returning null.
bool isAnalysisRemarkEnabled(StringRef PassName) const override
std::string Triple
The name of the target triple to compile for.
TargetOptions & getTargetOpts()
void addPPCallbacks(std::unique_ptr< PPCallbacks > C)
This class handles loading and caching of source files into memory.
PrettyStackTraceDecl - If a crash occurs, indicate that it happened when doing something to a specifi...