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);
89 [&](
const RemarkSetupFileError &E) {
90 Diags.
Report(diag::err_cannot_open_file)
93 [&](
const RemarkSetupPatternError &E) {
94 Diags.
Report(diag::err_drv_optimization_remark_pattern)
97 [&](
const RemarkSetupFormatError &E) {
98 Diags.
Report(diag::err_drv_optimization_remark_format)
104 using LinkModule = CodeGenAction::LinkModule;
106 virtual void anchor();
113 std::unique_ptr<raw_pwrite_stream> AsmOutStream;
116 Timer LLVMIRGeneration;
117 unsigned LLVMIRGenerationRefCount;
122 bool IRGenFinished =
false;
124 std::unique_ptr<CodeGenerator> Gen;
130 llvm::Module *CurLinkModule =
nullptr;
139 const std::string &InFile,
141 std::unique_ptr<raw_pwrite_stream> OS, LLVMContext &
C,
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),
149 CodeGenOpts, C, CoverageInfo)),
150 LinkModules(
std::move(LinkModules)) {
152 llvm::TimePassesIsEnabled = TimePasses;
166 : Diags(Diags), Action(Action), HeaderSearchOpts(HeaderSearchOpts),
167 CodeGenOpts(CodeGenOpts), TargetOpts(TargetOpts), LangOpts(LangOpts),
169 LLVMIRGeneration(
"irgen",
"LLVM IR Generation Time"),
170 LLVMIRGenerationRefCount(0),
172 CodeGenOpts, C, CoverageInfo)),
173 LinkModules(
std::move(LinkModules)) {
175 llvm::TimePassesIsEnabled = TimePasses;
177 llvm::Module *
getModule()
const {
return Gen->GetModule(); }
179 return std::unique_ptr<llvm::Module>(Gen->ReleaseModule());
185 Gen->HandleCXXStaticMemberVarInstantiation(VD);
189 assert(!Context &&
"initialized multiple times");
194 LLVMIRGeneration.startTimer();
196 Gen->Initialize(Ctx);
199 LLVMIRGeneration.stopTimer();
205 "LLVM IR generation of declaration");
209 LLVMIRGenerationRefCount += 1;
210 if (LLVMIRGenerationRefCount == 1)
211 LLVMIRGeneration.startTimer();
214 Gen->HandleTopLevelDecl(D);
217 LLVMIRGenerationRefCount -= 1;
218 if (LLVMIRGenerationRefCount == 0)
219 LLVMIRGeneration.stopTimer();
228 "LLVM IR generation of inline function");
230 LLVMIRGeneration.startTimer();
232 Gen->HandleInlineFunctionDefinition(D);
235 LLVMIRGeneration.stopTimer();
241 HandleTopLevelDecl(D);
246 for (
auto &LM : LinkModules) {
247 if (LM.PropagateAttrs)
248 for (Function &F : *LM.Module)
249 Gen->CGM().AddDefaultFnAttrs(F);
251 CurLinkModule = LM.Module.get();
254 if (LM.Internalize) {
255 Err = Linker::linkModules(
256 *getModule(), std::move(LM.Module), LM.LinkFlags,
257 [](llvm::Module &M,
const llvm::StringSet<> &GVS) {
258 internalizeModule(M, [&GVS](const llvm::GlobalValue &GV) {
259 return !GV.hasName() || (GVS.count(GV.getName()) == 0);
263 Err = Linker::linkModules(*getModule(), std::move(LM.Module),
275 llvm::TimeTraceScope TimeScope(
"Frontend");
276 PrettyStackTraceString CrashInfo(
"Per-file LLVM IR generation");
278 LLVMIRGenerationRefCount += 1;
279 if (LLVMIRGenerationRefCount == 1)
280 LLVMIRGeneration.startTimer();
283 Gen->HandleTranslationUnit(C);
286 LLVMIRGenerationRefCount -= 1;
287 if (LLVMIRGenerationRefCount == 0)
288 LLVMIRGeneration.stopTimer();
291 IRGenFinished =
true;
300 LLVMContext &Ctx = getModule()->getContext();
301 LLVMContext::InlineAsmDiagHandlerTy OldHandler =
302 Ctx.getInlineAsmDiagnosticHandler();
303 void *OldContext = Ctx.getInlineAsmDiagnosticContext();
304 Ctx.setInlineAsmDiagnosticHandler(InlineAsmDiagHandler,
this);
306 std::unique_ptr<DiagnosticHandler> OldDiagnosticHandler =
307 Ctx.getDiagnosticHandler();
308 Ctx.setDiagnosticHandler(std::make_unique<ClangDiagnosticHandler>(
312 setupOptimizationRemarks(
313 Ctx, CodeGenOpts.OptRecordFile, CodeGenOpts.OptRecordPasses,
314 CodeGenOpts.OptRecordFormat, CodeGenOpts.DiagnosticsWithHotness,
315 CodeGenOpts.DiagnosticsHotnessThreshold);
317 if (
Error E = OptRecordFileOrErr.takeError()) {
322 std::unique_ptr<llvm::ToolOutputFile> OptRecordFile =
323 std::move(*OptRecordFileOrErr);
327 Ctx.setDiagnosticsHotnessRequested(
true);
333 EmbedBitcode(getModule(), CodeGenOpts, llvm::MemoryBufferRef());
337 getModule(), Action, std::move(AsmOutStream));
339 Ctx.setInlineAsmDiagnosticHandler(OldHandler, OldContext);
341 Ctx.setDiagnosticHandler(std::move(OldDiagnosticHandler));
344 OptRecordFile->keep();
350 "LLVM IR generation of declaration");
351 Gen->HandleTagDeclDefinition(D);
355 Gen->HandleTagDeclRequiredDefinition(D);
359 Gen->CompleteTentativeDefinition(D);
363 Gen->CompleteExternalDeclaration(D);
367 Gen->AssignInheritanceModel(RD);
371 Gen->HandleVTable(RD);
375 unsigned LocCookie) {
383 getBestLocationFromDebugLoc(
const llvm::DiagnosticInfoWithLocationBase &D,
384 bool &BadDebugInfo, StringRef &
Filename,
385 unsigned &
Line,
unsigned &Column)
const;
387 void InlineAsmDiagHandler2(
const llvm::SMDiagnostic &,
390 void DiagnosticHandlerImpl(
const llvm::DiagnosticInfo &DI);
394 bool InlineAsmDiagHandler(
const llvm::DiagnosticInfoInlineAsm &D);
398 bool StackSizeDiagHandler(
const llvm::DiagnosticInfoStackSize &D);
400 void UnsupportedDiagHandler(
const llvm::DiagnosticInfoUnsupported &D);
403 void MisExpectDiagHandler(
const llvm::DiagnosticInfoMisExpect &D);
407 void EmitOptimizationMessage(
const llvm::DiagnosticInfoOptimizationBase &D,
410 OptimizationRemarkHandler(
const llvm::DiagnosticInfoOptimizationBase &D);
411 void OptimizationRemarkHandler(
412 const llvm::OptimizationRemarkAnalysisFPCommute &D);
413 void OptimizationRemarkHandler(
414 const llvm::OptimizationRemarkAnalysisAliasing &D);
415 void OptimizationFailureHandler(
416 const llvm::DiagnosticInfoOptimizationFailure &D);
419 void BackendConsumer::anchor() {}
423 BackendCon->DiagnosticHandlerImpl(DI);
434 const llvm::SourceMgr &LSM = *D.getSourceMgr();
438 const MemoryBuffer *LBuf =
439 LSM.getMemoryBuffer(LSM.FindBufferContainingLoc(D.getLoc()));
443 std::unique_ptr<llvm::MemoryBuffer> CBuf =
444 llvm::MemoryBuffer::getMemBufferCopy(LBuf->getBuffer(),
445 LBuf->getBufferIdentifier());
450 unsigned Offset = D.getLoc().getPointer() - LBuf->getBufferStart();
466 StringRef Message = D.getMessage();
467 if (Message.startswith(
"error: "))
468 Message = Message.substr(7);
472 if (D.getLoc() != SMLoc())
476 switch (D.getKind()) {
477 case llvm::SourceMgr::DK_Error:
478 DiagID = diag::err_fe_inline_asm;
480 case llvm::SourceMgr::DK_Warning:
481 DiagID = diag::warn_fe_inline_asm;
483 case llvm::SourceMgr::DK_Note:
484 DiagID = diag::note_fe_inline_asm;
486 case llvm::SourceMgr::DK_Remark:
487 llvm_unreachable(
"remarks unexpected");
493 Diags.Report(LocCookie, DiagID).AddString(Message);
495 if (D.getLoc().isValid()) {
499 for (
const std::pair<unsigned, unsigned> &Range : D.getRanges()) {
500 unsigned Column = D.getColumnNo();
511 Diags.Report(Loc, DiagID).AddString(Message);
514 #define ComputeDiagID(Severity, GroupName, DiagID) \ 516 switch (Severity) { \ 517 case llvm::DS_Error: \ 518 DiagID = diag::err_fe_##GroupName; \ 520 case llvm::DS_Warning: \ 521 DiagID = diag::warn_fe_##GroupName; \ 523 case llvm::DS_Remark: \ 524 llvm_unreachable("'remark' severity not expected"); \ 526 case llvm::DS_Note: \ 527 DiagID = diag::note_fe_##GroupName; \ 532 #define ComputeDiagRemarkID(Severity, GroupName, DiagID) \ 534 switch (Severity) { \ 535 case llvm::DS_Error: \ 536 DiagID = diag::err_fe_##GroupName; \ 538 case llvm::DS_Warning: \ 539 DiagID = diag::warn_fe_##GroupName; \ 541 case llvm::DS_Remark: \ 542 DiagID = diag::remark_fe_##GroupName; \ 544 case llvm::DS_Note: \ 545 DiagID = diag::note_fe_##GroupName; \ 554 std::string Message = D.getMsgStr().str();
562 Diags.Report(LocCookie, DiagID).AddString(Message);
569 Diags.Report(Loc, DiagID).AddString(Message);
577 if (D.getSeverity() != llvm::DS_Warning)
582 if (
const Decl *ND = Gen->GetDeclForMangledName(D.getFunction().getName())) {
584 Diags.Report(ND->getASTContext().getFullLoc(ND->getLocation()),
585 diag::warn_fe_frame_larger_than)
594 const llvm::DiagnosticInfoWithLocationBase &D,
bool &BadDebugInfo,
595 StringRef &
Filename,
unsigned &
Line,
unsigned &Column)
const {
600 if (D.isLocationAvailable()) {
601 D.getLocation(Filename, Line, Column);
603 auto FE = FileMgr.
getFile(Filename);
605 FE = FileMgr.
getFile(D.getAbsolutePath());
620 if (
const Decl *FD = Gen->GetDeclForMangledName(D.getFunction().getName()))
621 Loc = FD->getASTContext().getFullLoc(FD->getLocation());
623 if (DILoc.
isInvalid() && D.isLocationAvailable())
628 Diags.Report(Loc, diag::note_fe_backend_invalid_loc)
629 << Filename << Line << Column;
635 const llvm::DiagnosticInfoUnsupported &D) {
637 assert(D.getSeverity() == llvm::DS_Error);
640 unsigned Line, Column;
641 bool BadDebugInfo =
false;
644 raw_string_ostream MsgStream(Msg);
648 if (Context !=
nullptr) {
649 Loc = getBestLocationFromDebugLoc(D, BadDebugInfo, Filename, Line, Column);
650 MsgStream << D.getMessage();
652 DiagnosticPrinterRawOStream DP(MsgStream);
655 Diags.Report(Loc, diag::err_fe_backend_unsupported) << MsgStream.str();
662 Diags.Report(Loc, diag::note_fe_backend_invalid_loc)
663 << Filename << Line << Column;
667 const llvm::DiagnosticInfoMisExpect &D) {
669 unsigned Line, Column;
670 bool BadDebugInfo =
false;
673 raw_string_ostream MsgStream(Msg);
674 DiagnosticPrinterRawOStream DP(MsgStream);
678 if (Context !=
nullptr) {
679 Loc = getBestLocationFromDebugLoc(D, BadDebugInfo, Filename, Line, Column);
680 MsgStream << D.getMsg();
682 DiagnosticPrinterRawOStream DP(MsgStream);
685 Diags.Report(Loc, diag::warn_profile_data_misexpect) << MsgStream.str();
692 Diags.Report(Loc, diag::note_fe_backend_invalid_loc)
693 << Filename << Line << Column;
697 const llvm::DiagnosticInfoOptimizationBase &D,
unsigned DiagID) {
699 assert(D.getSeverity() == llvm::DS_Remark ||
700 D.getSeverity() == llvm::DS_Warning);
703 unsigned Line, Column;
704 bool BadDebugInfo =
false;
707 raw_string_ostream MsgStream(Msg);
711 if (Context !=
nullptr) {
712 Loc = getBestLocationFromDebugLoc(D, BadDebugInfo, Filename, Line, Column);
713 MsgStream << D.getMsg();
715 DiagnosticPrinterRawOStream DP(MsgStream);
720 MsgStream <<
" (hotness: " << *D.getHotness() <<
")";
722 Diags.Report(Loc, DiagID)
731 Diags.Report(Loc, diag::note_fe_backend_invalid_loc)
732 << Filename << Line << Column;
736 const llvm::DiagnosticInfoOptimizationBase &D) {
738 if (D.isVerbose() && !D.getHotness())
744 if (CodeGenOpts.OptimizationRemarkPattern &&
745 CodeGenOpts.OptimizationRemarkPattern->match(D.getPassName()))
746 EmitOptimizationMessage(D, diag::remark_fe_backend_optimization_remark);
747 }
else if (D.isMissed()) {
751 if (CodeGenOpts.OptimizationRemarkMissedPattern &&
752 CodeGenOpts.OptimizationRemarkMissedPattern->match(D.getPassName()))
753 EmitOptimizationMessage(
754 D, diag::remark_fe_backend_optimization_remark_missed);
756 assert(D.isAnalysis() &&
"Unknown remark type");
758 bool ShouldAlwaysPrint =
false;
759 if (
auto *ORA = dyn_cast<llvm::OptimizationRemarkAnalysis>(&D))
760 ShouldAlwaysPrint = ORA->shouldAlwaysPrint();
762 if (ShouldAlwaysPrint ||
763 (CodeGenOpts.OptimizationRemarkAnalysisPattern &&
764 CodeGenOpts.OptimizationRemarkAnalysisPattern->match(D.getPassName())))
765 EmitOptimizationMessage(
766 D, diag::remark_fe_backend_optimization_remark_analysis);
771 const llvm::OptimizationRemarkAnalysisFPCommute &D) {
776 if (D.shouldAlwaysPrint() ||
777 (CodeGenOpts.OptimizationRemarkAnalysisPattern &&
778 CodeGenOpts.OptimizationRemarkAnalysisPattern->match(D.getPassName())))
779 EmitOptimizationMessage(
780 D, diag::remark_fe_backend_optimization_remark_analysis_fpcommute);
784 const llvm::OptimizationRemarkAnalysisAliasing &D) {
789 if (D.shouldAlwaysPrint() ||
790 (CodeGenOpts.OptimizationRemarkAnalysisPattern &&
791 CodeGenOpts.OptimizationRemarkAnalysisPattern->match(D.getPassName())))
792 EmitOptimizationMessage(
793 D, diag::remark_fe_backend_optimization_remark_analysis_aliasing);
797 const llvm::DiagnosticInfoOptimizationFailure &D) {
798 EmitOptimizationMessage(D, diag::warn_fe_backend_optimization_failure);
804 unsigned DiagID = diag::err_fe_inline_asm;
805 llvm::DiagnosticSeverity
Severity = DI.getSeverity();
807 switch (DI.getKind()) {
808 case llvm::DK_InlineAsm:
809 if (InlineAsmDiagHandler(cast<DiagnosticInfoInlineAsm>(DI)))
813 case llvm::DK_StackSize:
814 if (StackSizeDiagHandler(cast<DiagnosticInfoStackSize>(DI)))
819 assert(CurLinkModule);
821 if (Severity != DS_Error)
823 DiagID = diag::err_fe_cannot_link_module;
825 case llvm::DK_OptimizationRemark:
828 OptimizationRemarkHandler(cast<OptimizationRemark>(DI));
830 case llvm::DK_OptimizationRemarkMissed:
833 OptimizationRemarkHandler(cast<OptimizationRemarkMissed>(DI));
835 case llvm::DK_OptimizationRemarkAnalysis:
838 OptimizationRemarkHandler(cast<OptimizationRemarkAnalysis>(DI));
840 case llvm::DK_OptimizationRemarkAnalysisFPCommute:
843 OptimizationRemarkHandler(cast<OptimizationRemarkAnalysisFPCommute>(DI));
845 case llvm::DK_OptimizationRemarkAnalysisAliasing:
848 OptimizationRemarkHandler(cast<OptimizationRemarkAnalysisAliasing>(DI));
850 case llvm::DK_MachineOptimizationRemark:
853 OptimizationRemarkHandler(cast<MachineOptimizationRemark>(DI));
855 case llvm::DK_MachineOptimizationRemarkMissed:
858 OptimizationRemarkHandler(cast<MachineOptimizationRemarkMissed>(DI));
860 case llvm::DK_MachineOptimizationRemarkAnalysis:
863 OptimizationRemarkHandler(cast<MachineOptimizationRemarkAnalysis>(DI));
865 case llvm::DK_OptimizationFailure:
868 OptimizationFailureHandler(cast<DiagnosticInfoOptimizationFailure>(DI));
870 case llvm::DK_Unsupported:
871 UnsupportedDiagHandler(cast<DiagnosticInfoUnsupported>(DI));
873 case llvm::DK_MisExpect:
874 MisExpectDiagHandler(cast<DiagnosticInfoMisExpect>(DI));
881 std::string MsgStorage;
883 raw_string_ostream Stream(MsgStorage);
884 DiagnosticPrinterRawOStream DP(Stream);
888 if (DiagID == diag::err_fe_cannot_link_module) {
889 Diags.Report(diag::err_fe_cannot_link_module)
890 << CurLinkModule->getModuleIdentifier() << MsgStorage;
896 Diags.Report(Loc, DiagID).AddString(MsgStorage);
901 : Act(_Act), VMContext(_VMContext ? _VMContext : new LLVMContext),
902 OwnsVMContext(!_VMContext) {}
922 return std::move(TheModule);
926 OwnsVMContext =
false;
930 static std::unique_ptr<raw_pwrite_stream>
947 llvm_unreachable(
"Invalid action!");
950 std::unique_ptr<ASTConsumer>
961 if (LinkModules.empty())
967 << F.Filename << BCBuf.getError().message();
973 getOwningLazyBitcodeModule(std::move(*BCBuf), *VMContext);
975 handleAllErrors(ModuleOrErr.takeError(), [&](ErrorInfoBase &EIB) {
977 << F.Filename << EIB.message();
982 LinkModules.push_back({std::move(ModuleOrErr.get()), F.PropagateAttrs,
983 F.Internalize, F.LinkFlags});
991 std::unique_ptr<PPCallbacks>(CoverageInfo));
998 std::move(LinkModules), std::move(OS), *VMContext, CoverageInfo));
1005 std::unique_ptr<PPCallbacks> Callbacks =
1011 return std::move(Result);
1016 unsigned LocCookie) {
1017 SM.print(
nullptr, llvm::errs());
1021 switch (SM.getKind()) {
1022 case llvm::SourceMgr::DK_Error:
1023 DiagID = diag::err_fe_inline_asm;
1025 case llvm::SourceMgr::DK_Warning:
1026 DiagID = diag::warn_fe_inline_asm;
1028 case llvm::SourceMgr::DK_Note:
1029 DiagID = diag::note_fe_inline_asm;
1031 case llvm::SourceMgr::DK_Remark:
1032 llvm_unreachable(
"remarks unexpected");
1035 Diags->Report(DiagID).AddString(
"cannot compile inline asm");
1038 std::unique_ptr<llvm::Module>
1039 CodeGenAction::loadModule(MemoryBufferRef MBRef) {
1047 VMContext->enableDebugTypeODRUniquing();
1049 auto DiagErrors = [&](
Error E) -> std::unique_ptr<llvm::Module> {
1052 handleAllErrors(std::move(E), [&](ErrorInfoBase &EIB) {
1060 return DiagErrors(BMsOrErr.takeError());
1067 auto M = std::make_unique<llvm::Module>(
"empty", *VMContext);
1072 Bm->parseModule(*VMContext);
1074 return DiagErrors(MOrErr.takeError());
1075 return std::move(*MOrErr);
1078 llvm::SMDiagnostic Err;
1079 if (std::unique_ptr<llvm::Module> M = parseIR(MBRef, Err, *VMContext))
1086 if (Err.getLineNo() > 0) {
1087 assert(Err.getColumnNo() >= 0);
1089 Err.getLineNo(), Err.getColumnNo() + 1);
1093 StringRef Msg = Err.getMessage();
1094 if (Msg.startswith(
"error: "))
1095 Msg = Msg.substr(7);
1111 std::unique_ptr<raw_pwrite_stream> OS =
1119 const llvm::MemoryBuffer *MainFile = SM.
getBuffer(FID, &Invalid);
1123 TheModule = loadModule(*MainFile);
1128 if (TheModule->getTargetTriple() != TargetOpts.
Triple) {
1130 diag::warn_fe_override_module)
1132 TheModule->setTargetTriple(TargetOpts.
Triple);
1136 MainFile->getMemBufferRef());
1138 LLVMContext &Ctx = TheModule->getContext();
1148 std::move(LinkModules), *VMContext,
nullptr);
1149 Ctx.setDiagnosticHandler(
1150 std::make_unique<ClangDiagnosticHandler>(CodeGenOpts, &
Result));
1153 setupOptimizationRemarks(
1154 Ctx, CodeGenOpts.OptRecordFile, CodeGenOpts.OptRecordPasses,
1155 CodeGenOpts.OptRecordFormat, CodeGenOpts.DiagnosticsWithHotness,
1156 CodeGenOpts.DiagnosticsHotnessThreshold);
1158 if (
Error E = OptRecordFileOrErr.takeError()) {
1162 std::unique_ptr<llvm::ToolOutputFile> OptRecordFile =
1163 std::move(*OptRecordFileOrErr);
1171 OptRecordFile->keep();
1181 void EmitAssemblyAction::anchor() { }
1185 void EmitBCAction::anchor() { }
1189 void EmitLLVMAction::anchor() { }
1193 void EmitLLVMOnlyAction::anchor() { }
1197 void EmitCodeGenOnlyAction::anchor() { }
1201 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
std::string OptRecordPasses
The regex that filters the passes that should be saved to the optimization records.
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.
static void reportOptRecordError(Error E, DiagnosticsEngine &Diags, const CodeGenOptions CodeGenOpts)
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.
Don't generate debug info.
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()
void CompleteExternalDeclaration(VarDecl *D) override
CompleteExternalDeclaration - Callback invoked at the end of a translation unit to notify the consume...
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)
std::string OptRecordFormat
The format used for serializing remarks (default: YAML)
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.
BackendConsumer(BackendAction Action, DiagnosticsEngine &Diags, const HeaderSearchOptions &HeaderSearchOpts, const PreprocessorOptions &PPOpts, const CodeGenOptions &CodeGenOpts, const TargetOptions &TargetOpts, const LangOptions &LangOpts, bool TimePasses, SmallVector< LinkModule, 4 > LinkModules, LLVMContext &C, CoverageSourceInfo *CoverageInfo=nullptr)
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 ...
std::string OptRecordFile
The name of the file to which the backend should save YAML optimization records.
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...