26 #include "llvm/Bitcode/BitcodeReader.h" 27 #include "llvm/CodeGen/MachineOptimizationRemarkEmitter.h" 28 #include "llvm/IR/DebugInfo.h" 29 #include "llvm/IR/DiagnosticInfo.h" 30 #include "llvm/IR/DiagnosticPrinter.h" 31 #include "llvm/IR/GlobalValue.h" 32 #include "llvm/IR/LLVMContext.h" 33 #include "llvm/IR/Module.h" 34 #include "llvm/IR/RemarkStreamer.h" 35 #include "llvm/IRReader/IRReader.h" 36 #include "llvm/Linker/Linker.h" 37 #include "llvm/Pass.h" 38 #include "llvm/Support/MemoryBuffer.h" 39 #include "llvm/Support/SourceMgr.h" 40 #include "llvm/Support/Timer.h" 41 #include "llvm/Support/ToolOutputFile.h" 42 #include "llvm/Support/YAMLTraits.h" 43 #include "llvm/Transforms/IPO/Internalize.h" 46 using namespace clang;
54 : CodeGenOpts(CGOpts), BackendCon(BCon) {}
56 bool handleDiagnostics(
const DiagnosticInfo &DI)
override;
59 return (CodeGenOpts.OptimizationRemarkAnalysisPattern &&
60 CodeGenOpts.OptimizationRemarkAnalysisPattern->match(PassName));
63 return (CodeGenOpts.OptimizationRemarkMissedPattern &&
64 CodeGenOpts.OptimizationRemarkMissedPattern->match(PassName));
67 return (CodeGenOpts.OptimizationRemarkPattern &&
68 CodeGenOpts.OptimizationRemarkPattern->match(PassName));
72 return (CodeGenOpts.OptimizationRemarkAnalysisPattern ||
73 CodeGenOpts.OptimizationRemarkMissedPattern ||
74 CodeGenOpts.OptimizationRemarkPattern);
83 using LinkModule = CodeGenAction::LinkModule;
85 virtual void anchor();
92 std::unique_ptr<raw_pwrite_stream> AsmOutStream;
95 Timer LLVMIRGeneration;
96 unsigned LLVMIRGenerationRefCount;
101 bool IRGenFinished =
false;
103 std::unique_ptr<CodeGenerator> Gen;
109 llvm::Module *CurLinkModule =
nullptr;
118 const std::string &InFile,
120 std::unique_ptr<raw_pwrite_stream> OS, LLVMContext &
C,
122 : Diags(Diags), Action(Action), HeaderSearchOpts(HeaderSearchOpts),
123 CodeGenOpts(CodeGenOpts), TargetOpts(TargetOpts), LangOpts(LangOpts),
124 AsmOutStream(
std::move(OS)), Context(nullptr),
125 LLVMIRGeneration(
"irgen",
"LLVM IR Generation Time"),
126 LLVMIRGenerationRefCount(0),
128 CodeGenOpts, C, CoverageInfo)),
129 LinkModules(
std::move(LinkModules)) {
131 llvm::TimePassesIsEnabled = TimePasses;
133 llvm::Module *
getModule()
const {
return Gen->GetModule(); }
135 return std::unique_ptr<llvm::Module>(Gen->ReleaseModule());
141 Gen->HandleCXXStaticMemberVarInstantiation(VD);
145 assert(!Context &&
"initialized multiple times");
150 LLVMIRGeneration.startTimer();
152 Gen->Initialize(Ctx);
155 LLVMIRGeneration.stopTimer();
161 "LLVM IR generation of declaration");
165 LLVMIRGenerationRefCount += 1;
166 if (LLVMIRGenerationRefCount == 1)
167 LLVMIRGeneration.startTimer();
170 Gen->HandleTopLevelDecl(D);
173 LLVMIRGenerationRefCount -= 1;
174 if (LLVMIRGenerationRefCount == 0)
175 LLVMIRGeneration.stopTimer();
184 "LLVM IR generation of inline function");
186 LLVMIRGeneration.startTimer();
188 Gen->HandleInlineFunctionDefinition(D);
191 LLVMIRGeneration.stopTimer();
197 HandleTopLevelDecl(D);
202 for (
auto &LM : LinkModules) {
203 if (LM.PropagateAttrs)
204 for (Function &F : *LM.Module)
205 Gen->CGM().AddDefaultFnAttrs(F);
207 CurLinkModule = LM.Module.get();
210 if (LM.Internalize) {
211 Err = Linker::linkModules(
212 *getModule(), std::move(LM.Module), LM.LinkFlags,
213 [](llvm::Module &M,
const llvm::StringSet<> &GVS) {
214 internalizeModule(M, [&GVS](const llvm::GlobalValue &GV) {
215 return !GV.hasName() || (GVS.count(GV.getName()) == 0);
219 Err = Linker::linkModules(*getModule(), std::move(LM.Module),
231 PrettyStackTraceString CrashInfo(
"Per-file LLVM IR generation");
233 LLVMIRGenerationRefCount += 1;
234 if (LLVMIRGenerationRefCount == 1)
235 LLVMIRGeneration.startTimer();
238 Gen->HandleTranslationUnit(C);
241 LLVMIRGenerationRefCount -= 1;
242 if (LLVMIRGenerationRefCount == 0)
243 LLVMIRGeneration.stopTimer();
246 IRGenFinished =
true;
255 LLVMContext &Ctx = getModule()->getContext();
256 LLVMContext::InlineAsmDiagHandlerTy OldHandler =
257 Ctx.getInlineAsmDiagnosticHandler();
258 void *OldContext = Ctx.getInlineAsmDiagnosticContext();
259 Ctx.setInlineAsmDiagnosticHandler(InlineAsmDiagHandler,
this);
261 std::unique_ptr<DiagnosticHandler> OldDiagnosticHandler =
262 Ctx.getDiagnosticHandler();
263 Ctx.setDiagnosticHandler(llvm::make_unique<ClangDiagnosticHandler>(
267 setupOptimizationRemarks(Ctx, CodeGenOpts.OptRecordFile,
268 CodeGenOpts.OptRecordPasses,
269 CodeGenOpts.OptRecordFormat,
270 CodeGenOpts.DiagnosticsWithHotness,
271 CodeGenOpts.DiagnosticsHotnessThreshold);
273 if (
Error E = OptRecordFileOrErr.takeError()) {
276 [&](
const RemarkSetupFileError &E) {
277 Diags.Report(diag::err_cannot_open_file)
278 << CodeGenOpts.OptRecordFile << E.message();
280 [&](
const RemarkSetupPatternError &E) {
281 Diags.Report(diag::err_drv_optimization_remark_pattern)
282 << E.message() << CodeGenOpts.OptRecordPasses;
284 [&](
const RemarkSetupFormatError &E) {
285 Diags.Report(diag::err_drv_optimization_remark_format)
286 << CodeGenOpts.OptRecordFormat;
290 std::unique_ptr<llvm::ToolOutputFile> OptRecordFile =
291 std::move(*OptRecordFileOrErr);
295 Ctx.setDiagnosticsHotnessRequested(
true);
301 EmbedBitcode(getModule(), CodeGenOpts, llvm::MemoryBufferRef());
305 getModule(), Action, std::move(AsmOutStream));
307 Ctx.setInlineAsmDiagnosticHandler(OldHandler, OldContext);
309 Ctx.setDiagnosticHandler(std::move(OldDiagnosticHandler));
312 OptRecordFile->keep();
318 "LLVM IR generation of declaration");
319 Gen->HandleTagDeclDefinition(D);
323 Gen->HandleTagDeclRequiredDefinition(D);
327 Gen->CompleteTentativeDefinition(D);
331 Gen->AssignInheritanceModel(RD);
335 Gen->HandleVTable(RD);
339 unsigned LocCookie) {
347 getBestLocationFromDebugLoc(
const llvm::DiagnosticInfoWithLocationBase &D,
348 bool &BadDebugInfo, StringRef &
Filename,
349 unsigned &
Line,
unsigned &Column)
const;
351 void InlineAsmDiagHandler2(
const llvm::SMDiagnostic &,
354 void DiagnosticHandlerImpl(
const llvm::DiagnosticInfo &DI);
358 bool InlineAsmDiagHandler(
const llvm::DiagnosticInfoInlineAsm &D);
362 bool StackSizeDiagHandler(
const llvm::DiagnosticInfoStackSize &D);
364 void UnsupportedDiagHandler(
const llvm::DiagnosticInfoUnsupported &D);
368 void EmitOptimizationMessage(
const llvm::DiagnosticInfoOptimizationBase &D,
371 OptimizationRemarkHandler(
const llvm::DiagnosticInfoOptimizationBase &D);
372 void OptimizationRemarkHandler(
373 const llvm::OptimizationRemarkAnalysisFPCommute &D);
374 void OptimizationRemarkHandler(
375 const llvm::OptimizationRemarkAnalysisAliasing &D);
376 void OptimizationFailureHandler(
377 const llvm::DiagnosticInfoOptimizationFailure &D);
380 void BackendConsumer::anchor() {}
384 BackendCon->DiagnosticHandlerImpl(DI);
395 const llvm::SourceMgr &LSM = *D.getSourceMgr();
399 const MemoryBuffer *LBuf =
400 LSM.getMemoryBuffer(LSM.FindBufferContainingLoc(D.getLoc()));
404 std::unique_ptr<llvm::MemoryBuffer> CBuf =
405 llvm::MemoryBuffer::getMemBufferCopy(LBuf->getBuffer(),
406 LBuf->getBufferIdentifier());
411 unsigned Offset = D.getLoc().getPointer() - LBuf->getBufferStart();
427 StringRef Message = D.getMessage();
428 if (Message.startswith(
"error: "))
429 Message = Message.substr(7);
433 if (D.getLoc() != SMLoc())
437 switch (D.getKind()) {
438 case llvm::SourceMgr::DK_Error:
439 DiagID = diag::err_fe_inline_asm;
441 case llvm::SourceMgr::DK_Warning:
442 DiagID = diag::warn_fe_inline_asm;
444 case llvm::SourceMgr::DK_Note:
445 DiagID = diag::note_fe_inline_asm;
447 case llvm::SourceMgr::DK_Remark:
448 llvm_unreachable(
"remarks unexpected");
454 Diags.Report(LocCookie, DiagID).AddString(Message);
456 if (D.getLoc().isValid()) {
460 for (
const std::pair<unsigned, unsigned> &Range : D.getRanges()) {
461 unsigned Column = D.getColumnNo();
472 Diags.Report(Loc, DiagID).AddString(Message);
475 #define ComputeDiagID(Severity, GroupName, DiagID) \ 477 switch (Severity) { \ 478 case llvm::DS_Error: \ 479 DiagID = diag::err_fe_##GroupName; \ 481 case llvm::DS_Warning: \ 482 DiagID = diag::warn_fe_##GroupName; \ 484 case llvm::DS_Remark: \ 485 llvm_unreachable("'remark' severity not expected"); \ 487 case llvm::DS_Note: \ 488 DiagID = diag::note_fe_##GroupName; \ 493 #define ComputeDiagRemarkID(Severity, GroupName, DiagID) \ 495 switch (Severity) { \ 496 case llvm::DS_Error: \ 497 DiagID = diag::err_fe_##GroupName; \ 499 case llvm::DS_Warning: \ 500 DiagID = diag::warn_fe_##GroupName; \ 502 case llvm::DS_Remark: \ 503 DiagID = diag::remark_fe_##GroupName; \ 505 case llvm::DS_Note: \ 506 DiagID = diag::note_fe_##GroupName; \ 515 std::string Message = D.getMsgStr().str();
523 Diags.Report(LocCookie, DiagID).AddString(Message);
530 Diags.Report(Loc, DiagID).AddString(Message);
538 if (D.getSeverity() != llvm::DS_Warning)
543 if (
const Decl *ND = Gen->GetDeclForMangledName(D.getFunction().getName())) {
545 Diags.Report(ND->getASTContext().getFullLoc(ND->getLocation()),
546 diag::warn_fe_frame_larger_than)
555 const llvm::DiagnosticInfoWithLocationBase &D,
bool &BadDebugInfo,
556 StringRef &
Filename,
unsigned &
Line,
unsigned &Column)
const {
561 if (D.isLocationAvailable()) {
562 D.getLocation(Filename, Line, Column);
566 FE = FileMgr.
getFile(D.getAbsolutePath());
581 if (
const Decl *FD = Gen->GetDeclForMangledName(D.getFunction().getName()))
582 Loc = FD->getASTContext().getFullLoc(FD->getLocation());
584 if (DILoc.
isInvalid() && D.isLocationAvailable())
589 Diags.Report(Loc, diag::note_fe_backend_invalid_loc)
590 << Filename << Line << Column;
596 const llvm::DiagnosticInfoUnsupported &D) {
598 assert(D.getSeverity() == llvm::DS_Error);
601 unsigned Line, Column;
602 bool BadDebugInfo =
false;
604 getBestLocationFromDebugLoc(D, BadDebugInfo, Filename, Line, Column);
606 Diags.Report(Loc, diag::err_fe_backend_unsupported) << D.getMessage().str();
613 Diags.Report(Loc, diag::note_fe_backend_invalid_loc)
614 << Filename << Line << Column;
618 const llvm::DiagnosticInfoOptimizationBase &D,
unsigned DiagID) {
620 assert(D.getSeverity() == llvm::DS_Remark ||
621 D.getSeverity() == llvm::DS_Warning);
624 unsigned Line, Column;
625 bool BadDebugInfo =
false;
627 getBestLocationFromDebugLoc(D, BadDebugInfo, Filename, Line, Column);
630 raw_string_ostream MsgStream(Msg);
631 MsgStream << D.getMsg();
634 MsgStream <<
" (hotness: " << *D.getHotness() <<
")";
636 Diags.Report(Loc, DiagID)
645 Diags.Report(Loc, diag::note_fe_backend_invalid_loc)
646 << Filename << Line << Column;
650 const llvm::DiagnosticInfoOptimizationBase &D) {
652 if (D.isVerbose() && !D.getHotness())
658 if (CodeGenOpts.OptimizationRemarkPattern &&
659 CodeGenOpts.OptimizationRemarkPattern->match(D.getPassName()))
660 EmitOptimizationMessage(D, diag::remark_fe_backend_optimization_remark);
661 }
else if (D.isMissed()) {
665 if (CodeGenOpts.OptimizationRemarkMissedPattern &&
666 CodeGenOpts.OptimizationRemarkMissedPattern->match(D.getPassName()))
667 EmitOptimizationMessage(
668 D, diag::remark_fe_backend_optimization_remark_missed);
670 assert(D.isAnalysis() &&
"Unknown remark type");
672 bool ShouldAlwaysPrint =
false;
673 if (
auto *ORA = dyn_cast<llvm::OptimizationRemarkAnalysis>(&D))
674 ShouldAlwaysPrint = ORA->shouldAlwaysPrint();
676 if (ShouldAlwaysPrint ||
677 (CodeGenOpts.OptimizationRemarkAnalysisPattern &&
678 CodeGenOpts.OptimizationRemarkAnalysisPattern->match(D.getPassName())))
679 EmitOptimizationMessage(
680 D, diag::remark_fe_backend_optimization_remark_analysis);
685 const llvm::OptimizationRemarkAnalysisFPCommute &D) {
690 if (D.shouldAlwaysPrint() ||
691 (CodeGenOpts.OptimizationRemarkAnalysisPattern &&
692 CodeGenOpts.OptimizationRemarkAnalysisPattern->match(D.getPassName())))
693 EmitOptimizationMessage(
694 D, diag::remark_fe_backend_optimization_remark_analysis_fpcommute);
698 const llvm::OptimizationRemarkAnalysisAliasing &D) {
703 if (D.shouldAlwaysPrint() ||
704 (CodeGenOpts.OptimizationRemarkAnalysisPattern &&
705 CodeGenOpts.OptimizationRemarkAnalysisPattern->match(D.getPassName())))
706 EmitOptimizationMessage(
707 D, diag::remark_fe_backend_optimization_remark_analysis_aliasing);
711 const llvm::DiagnosticInfoOptimizationFailure &D) {
712 EmitOptimizationMessage(D, diag::warn_fe_backend_optimization_failure);
718 unsigned DiagID = diag::err_fe_inline_asm;
719 llvm::DiagnosticSeverity
Severity = DI.getSeverity();
721 switch (DI.getKind()) {
722 case llvm::DK_InlineAsm:
723 if (InlineAsmDiagHandler(cast<DiagnosticInfoInlineAsm>(DI)))
727 case llvm::DK_StackSize:
728 if (StackSizeDiagHandler(cast<DiagnosticInfoStackSize>(DI)))
733 assert(CurLinkModule);
735 if (Severity != DS_Error)
737 DiagID = diag::err_fe_cannot_link_module;
739 case llvm::DK_OptimizationRemark:
742 OptimizationRemarkHandler(cast<OptimizationRemark>(DI));
744 case llvm::DK_OptimizationRemarkMissed:
747 OptimizationRemarkHandler(cast<OptimizationRemarkMissed>(DI));
749 case llvm::DK_OptimizationRemarkAnalysis:
752 OptimizationRemarkHandler(cast<OptimizationRemarkAnalysis>(DI));
754 case llvm::DK_OptimizationRemarkAnalysisFPCommute:
757 OptimizationRemarkHandler(cast<OptimizationRemarkAnalysisFPCommute>(DI));
759 case llvm::DK_OptimizationRemarkAnalysisAliasing:
762 OptimizationRemarkHandler(cast<OptimizationRemarkAnalysisAliasing>(DI));
764 case llvm::DK_MachineOptimizationRemark:
767 OptimizationRemarkHandler(cast<MachineOptimizationRemark>(DI));
769 case llvm::DK_MachineOptimizationRemarkMissed:
772 OptimizationRemarkHandler(cast<MachineOptimizationRemarkMissed>(DI));
774 case llvm::DK_MachineOptimizationRemarkAnalysis:
777 OptimizationRemarkHandler(cast<MachineOptimizationRemarkAnalysis>(DI));
779 case llvm::DK_OptimizationFailure:
782 OptimizationFailureHandler(cast<DiagnosticInfoOptimizationFailure>(DI));
784 case llvm::DK_Unsupported:
785 UnsupportedDiagHandler(cast<DiagnosticInfoUnsupported>(DI));
792 std::string MsgStorage;
794 raw_string_ostream Stream(MsgStorage);
795 DiagnosticPrinterRawOStream DP(Stream);
799 if (DiagID == diag::err_fe_cannot_link_module) {
800 Diags.Report(diag::err_fe_cannot_link_module)
801 << CurLinkModule->getModuleIdentifier() << MsgStorage;
807 Diags.Report(Loc, DiagID).AddString(MsgStorage);
812 : Act(_Act), VMContext(_VMContext ? _VMContext : new LLVMContext),
813 OwnsVMContext(!_VMContext) {}
833 return std::move(TheModule);
837 OwnsVMContext =
false;
841 static std::unique_ptr<raw_pwrite_stream>
858 llvm_unreachable(
"Invalid action!");
861 std::unique_ptr<ASTConsumer>
872 if (LinkModules.empty())
878 << F.Filename << BCBuf.getError().message();
884 getOwningLazyBitcodeModule(std::move(*BCBuf), *VMContext);
886 handleAllErrors(ModuleOrErr.takeError(), [&](ErrorInfoBase &EIB) {
888 << F.Filename << EIB.message();
893 LinkModules.push_back({std::move(ModuleOrErr.get()), F.PropagateAttrs,
894 F.Internalize, F.LinkFlags});
902 std::unique_ptr<PPCallbacks>(CoverageInfo));
909 std::move(LinkModules), std::move(OS), *VMContext, CoverageInfo));
916 std::unique_ptr<PPCallbacks> Callbacks =
922 return std::move(Result);
927 unsigned LocCookie) {
928 SM.print(
nullptr, llvm::errs());
932 switch (SM.getKind()) {
933 case llvm::SourceMgr::DK_Error:
934 DiagID = diag::err_fe_inline_asm;
936 case llvm::SourceMgr::DK_Warning:
937 DiagID = diag::warn_fe_inline_asm;
939 case llvm::SourceMgr::DK_Note:
940 DiagID = diag::note_fe_inline_asm;
942 case llvm::SourceMgr::DK_Remark:
943 llvm_unreachable(
"remarks unexpected");
946 Diags->Report(DiagID).AddString(
"cannot compile inline asm");
949 std::unique_ptr<llvm::Module>
950 CodeGenAction::loadModule(MemoryBufferRef MBRef) {
958 VMContext->enableDebugTypeODRUniquing();
960 auto DiagErrors = [&](
Error E) -> std::unique_ptr<llvm::Module> {
963 handleAllErrors(std::move(E), [&](ErrorInfoBase &EIB) {
971 return DiagErrors(BMsOrErr.takeError());
978 auto M = llvm::make_unique<llvm::Module>(
"empty", *VMContext);
983 Bm->parseModule(*VMContext);
985 return DiagErrors(MOrErr.takeError());
986 return std::move(*MOrErr);
989 llvm::SMDiagnostic Err;
990 if (std::unique_ptr<llvm::Module> M = parseIR(MBRef, Err, *VMContext))
997 if (Err.getLineNo() > 0) {
998 assert(Err.getColumnNo() >= 0);
1000 Err.getLineNo(), Err.getColumnNo() + 1);
1004 StringRef Msg = Err.getMessage();
1005 if (Msg.startswith(
"error: "))
1006 Msg = Msg.substr(7);
1020 std::unique_ptr<raw_pwrite_stream> OS =
1028 const llvm::MemoryBuffer *MainFile = SM.
getBuffer(FID, &Invalid);
1032 TheModule = loadModule(*MainFile);
1037 if (TheModule->getTargetTriple() != TargetOpts.
Triple) {
1039 diag::warn_fe_override_module)
1041 TheModule->setTargetTriple(TargetOpts.
Triple);
1045 MainFile->getMemBufferRef());
1047 LLVMContext &Ctx = TheModule->getContext();
1064 void EmitAssemblyAction::anchor() { }
1068 void EmitBCAction::anchor() { }
1072 void EmitLLVMAction::anchor() { }
1076 void EmitLLVMOnlyAction::anchor() { }
1080 void EmitCodeGenOnlyAction::anchor() { }
1084 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
const FileEntry * getFile(StringRef Filename, bool OpenFile=false, bool CacheFailure=true)
Lookup, cache, and verify the specified file (real or virtual).
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.
Cached information about one file (either on disk or in the virtual file system). ...
std::unique_ptr< raw_pwrite_stream > createNullOutputFile()
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
llvm::ErrorOr< std::unique_ptr< llvm::MemoryBuffer > > getBufferForFile(const FileEntry *Entry, bool isVolatile=false, bool ShouldCloseOpenFile=true)
Open the specified file as a MemoryBuffer, returning a new MemoryBuffer if successful, otherwise returning null.
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...
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.
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.
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...