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/IRReader/IRReader.h" 35 #include "llvm/Linker/Linker.h" 36 #include "llvm/Pass.h" 37 #include "llvm/Support/MemoryBuffer.h" 38 #include "llvm/Support/SourceMgr.h" 39 #include "llvm/Support/Timer.h" 40 #include "llvm/Support/ToolOutputFile.h" 41 #include "llvm/Support/YAMLTraits.h" 42 #include "llvm/Transforms/IPO/Internalize.h" 45 using namespace clang;
53 : CodeGenOpts(CGOpts), BackendCon(BCon) {}
55 bool handleDiagnostics(
const DiagnosticInfo &DI)
override;
58 return (CodeGenOpts.OptimizationRemarkAnalysisPattern &&
59 CodeGenOpts.OptimizationRemarkAnalysisPattern->match(PassName));
62 return (CodeGenOpts.OptimizationRemarkMissedPattern &&
63 CodeGenOpts.OptimizationRemarkMissedPattern->match(PassName));
66 return (CodeGenOpts.OptimizationRemarkPattern &&
67 CodeGenOpts.OptimizationRemarkPattern->match(PassName));
71 return (CodeGenOpts.OptimizationRemarkAnalysisPattern ||
72 CodeGenOpts.OptimizationRemarkMissedPattern ||
73 CodeGenOpts.OptimizationRemarkPattern);
82 using LinkModule = CodeGenAction::LinkModule;
84 virtual void anchor();
91 std::unique_ptr<raw_pwrite_stream> AsmOutStream;
94 Timer LLVMIRGeneration;
95 unsigned LLVMIRGenerationRefCount;
100 bool IRGenFinished =
false;
102 std::unique_ptr<CodeGenerator> Gen;
108 llvm::Module *CurLinkModule =
nullptr;
117 const std::string &InFile,
119 std::unique_ptr<raw_pwrite_stream> OS, LLVMContext &
C,
121 : Diags(Diags), Action(Action), HeaderSearchOpts(HeaderSearchOpts),
122 CodeGenOpts(CodeGenOpts), TargetOpts(TargetOpts), LangOpts(LangOpts),
123 AsmOutStream(
std::move(OS)), Context(nullptr),
124 LLVMIRGeneration(
"irgen",
"LLVM IR Generation Time"),
125 LLVMIRGenerationRefCount(0),
127 CodeGenOpts, C, CoverageInfo)),
128 LinkModules(
std::move(LinkModules)) {
129 llvm::TimePassesIsEnabled = TimePasses;
131 llvm::Module *
getModule()
const {
return Gen->GetModule(); }
133 return std::unique_ptr<llvm::Module>(Gen->ReleaseModule());
139 Gen->HandleCXXStaticMemberVarInstantiation(VD);
143 assert(!Context &&
"initialized multiple times");
147 if (llvm::TimePassesIsEnabled)
148 LLVMIRGeneration.startTimer();
150 Gen->Initialize(Ctx);
152 if (llvm::TimePassesIsEnabled)
153 LLVMIRGeneration.stopTimer();
159 "LLVM IR generation of declaration");
162 if (llvm::TimePassesIsEnabled) {
163 LLVMIRGenerationRefCount += 1;
164 if (LLVMIRGenerationRefCount == 1)
165 LLVMIRGeneration.startTimer();
168 Gen->HandleTopLevelDecl(D);
170 if (llvm::TimePassesIsEnabled) {
171 LLVMIRGenerationRefCount -= 1;
172 if (LLVMIRGenerationRefCount == 0)
173 LLVMIRGeneration.stopTimer();
182 "LLVM IR generation of inline function");
183 if (llvm::TimePassesIsEnabled)
184 LLVMIRGeneration.startTimer();
186 Gen->HandleInlineFunctionDefinition(D);
188 if (llvm::TimePassesIsEnabled)
189 LLVMIRGeneration.stopTimer();
195 HandleTopLevelDecl(D);
200 for (
auto &LM : LinkModules) {
201 if (LM.PropagateAttrs)
202 for (Function &F : *LM.Module)
203 Gen->CGM().AddDefaultFnAttrs(F);
205 CurLinkModule = LM.Module.get();
208 if (LM.Internalize) {
209 Err = Linker::linkModules(
210 *getModule(), std::move(LM.Module), LM.LinkFlags,
211 [](llvm::Module &M,
const llvm::StringSet<> &GVS) {
212 internalizeModule(M, [&GVS](const llvm::GlobalValue &GV) {
213 return !GV.hasName() || (GVS.count(GV.getName()) == 0);
217 Err = Linker::linkModules(*getModule(), std::move(LM.Module),
229 PrettyStackTraceString CrashInfo(
"Per-file LLVM IR generation");
230 if (llvm::TimePassesIsEnabled) {
231 LLVMIRGenerationRefCount += 1;
232 if (LLVMIRGenerationRefCount == 1)
233 LLVMIRGeneration.startTimer();
236 Gen->HandleTranslationUnit(C);
238 if (llvm::TimePassesIsEnabled) {
239 LLVMIRGenerationRefCount -= 1;
240 if (LLVMIRGenerationRefCount == 0)
241 LLVMIRGeneration.stopTimer();
244 IRGenFinished =
true;
253 LLVMContext &Ctx = getModule()->getContext();
254 LLVMContext::InlineAsmDiagHandlerTy OldHandler =
255 Ctx.getInlineAsmDiagnosticHandler();
256 void *OldContext = Ctx.getInlineAsmDiagnosticContext();
257 Ctx.setInlineAsmDiagnosticHandler(InlineAsmDiagHandler,
this);
259 std::unique_ptr<DiagnosticHandler> OldDiagnosticHandler =
260 Ctx.getDiagnosticHandler();
261 Ctx.setDiagnosticHandler(llvm::make_unique<ClangDiagnosticHandler>(
263 Ctx.setDiagnosticsHotnessRequested(CodeGenOpts.DiagnosticsWithHotness);
264 if (CodeGenOpts.DiagnosticsHotnessThreshold != 0)
265 Ctx.setDiagnosticsHotnessThreshold(
266 CodeGenOpts.DiagnosticsHotnessThreshold);
268 std::unique_ptr<llvm::ToolOutputFile> OptRecordFile;
269 if (!CodeGenOpts.OptRecordFile.empty()) {
271 OptRecordFile = llvm::make_unique<llvm::ToolOutputFile>(
272 CodeGenOpts.OptRecordFile, EC, sys::fs::F_None);
274 Diags.Report(diag::err_cannot_open_file) <<
275 CodeGenOpts.OptRecordFile << EC.message();
279 Ctx.setDiagnosticsOutputFile(
280 llvm::make_unique<yaml::Output>(OptRecordFile->os()));
283 Ctx.setDiagnosticsHotnessRequested(
true);
290 EmbedBitcode(getModule(), CodeGenOpts, llvm::MemoryBufferRef());
294 getModule(), Action, std::move(AsmOutStream));
296 Ctx.setInlineAsmDiagnosticHandler(OldHandler, OldContext);
298 Ctx.setDiagnosticHandler(std::move(OldDiagnosticHandler));
301 OptRecordFile->keep();
307 "LLVM IR generation of declaration");
308 Gen->HandleTagDeclDefinition(D);
312 Gen->HandleTagDeclRequiredDefinition(D);
316 Gen->CompleteTentativeDefinition(D);
320 Gen->AssignInheritanceModel(RD);
324 Gen->HandleVTable(RD);
328 unsigned LocCookie) {
336 getBestLocationFromDebugLoc(
const llvm::DiagnosticInfoWithLocationBase &D,
337 bool &BadDebugInfo, StringRef &
Filename,
338 unsigned &
Line,
unsigned &Column)
const;
340 void InlineAsmDiagHandler2(
const llvm::SMDiagnostic &,
343 void DiagnosticHandlerImpl(
const llvm::DiagnosticInfo &DI);
347 bool InlineAsmDiagHandler(
const llvm::DiagnosticInfoInlineAsm &D);
351 bool StackSizeDiagHandler(
const llvm::DiagnosticInfoStackSize &D);
353 void UnsupportedDiagHandler(
const llvm::DiagnosticInfoUnsupported &D);
357 void EmitOptimizationMessage(
const llvm::DiagnosticInfoOptimizationBase &D,
360 OptimizationRemarkHandler(
const llvm::DiagnosticInfoOptimizationBase &D);
361 void OptimizationRemarkHandler(
362 const llvm::OptimizationRemarkAnalysisFPCommute &D);
363 void OptimizationRemarkHandler(
364 const llvm::OptimizationRemarkAnalysisAliasing &D);
365 void OptimizationFailureHandler(
366 const llvm::DiagnosticInfoOptimizationFailure &D);
369 void BackendConsumer::anchor() {}
373 BackendCon->DiagnosticHandlerImpl(DI);
384 const llvm::SourceMgr &LSM = *D.getSourceMgr();
388 const MemoryBuffer *LBuf =
389 LSM.getMemoryBuffer(LSM.FindBufferContainingLoc(D.getLoc()));
393 std::unique_ptr<llvm::MemoryBuffer> CBuf =
394 llvm::MemoryBuffer::getMemBufferCopy(LBuf->getBuffer(),
395 LBuf->getBufferIdentifier());
400 unsigned Offset = D.getLoc().getPointer() - LBuf->getBufferStart();
416 StringRef Message = D.getMessage();
417 if (Message.startswith(
"error: "))
418 Message = Message.substr(7);
422 if (D.getLoc() != SMLoc())
426 switch (D.getKind()) {
427 case llvm::SourceMgr::DK_Error:
428 DiagID = diag::err_fe_inline_asm;
430 case llvm::SourceMgr::DK_Warning:
431 DiagID = diag::warn_fe_inline_asm;
433 case llvm::SourceMgr::DK_Note:
434 DiagID = diag::note_fe_inline_asm;
436 case llvm::SourceMgr::DK_Remark:
437 llvm_unreachable(
"remarks unexpected");
443 Diags.Report(LocCookie, DiagID).AddString(Message);
445 if (D.getLoc().isValid()) {
449 for (
const std::pair<unsigned, unsigned> &Range : D.getRanges()) {
450 unsigned Column = D.getColumnNo();
461 Diags.Report(Loc, DiagID).AddString(Message);
464 #define ComputeDiagID(Severity, GroupName, DiagID) \ 466 switch (Severity) { \ 467 case llvm::DS_Error: \ 468 DiagID = diag::err_fe_##GroupName; \ 470 case llvm::DS_Warning: \ 471 DiagID = diag::warn_fe_##GroupName; \ 473 case llvm::DS_Remark: \ 474 llvm_unreachable("'remark' severity not expected"); \ 476 case llvm::DS_Note: \ 477 DiagID = diag::note_fe_##GroupName; \ 482 #define ComputeDiagRemarkID(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 DiagID = diag::remark_fe_##GroupName; \ 494 case llvm::DS_Note: \ 495 DiagID = diag::note_fe_##GroupName; \ 504 std::string Message = D.getMsgStr().str();
512 Diags.Report(LocCookie, DiagID).AddString(Message);
519 Diags.Report(Loc, DiagID).AddString(Message);
527 if (D.getSeverity() != llvm::DS_Warning)
532 if (
const Decl *ND = Gen->GetDeclForMangledName(D.getFunction().getName())) {
534 Diags.Report(ND->getASTContext().getFullLoc(ND->getLocation()),
535 diag::warn_fe_frame_larger_than)
544 const llvm::DiagnosticInfoWithLocationBase &D,
bool &BadDebugInfo,
545 StringRef &
Filename,
unsigned &
Line,
unsigned &Column)
const {
550 if (D.isLocationAvailable()) {
551 D.getLocation(&Filename, &Line, &Column);
553 if (FE && Line > 0) {
566 if (
const Decl *FD = Gen->GetDeclForMangledName(D.getFunction().getName()))
567 Loc = FD->getASTContext().getFullLoc(FD->getLocation());
569 if (DILoc.
isInvalid() && D.isLocationAvailable())
574 Diags.Report(Loc, diag::note_fe_backend_invalid_loc)
575 << Filename << Line << Column;
581 const llvm::DiagnosticInfoUnsupported &D) {
583 assert(D.getSeverity() == llvm::DS_Error);
586 unsigned Line, Column;
587 bool BadDebugInfo =
false;
589 getBestLocationFromDebugLoc(D, BadDebugInfo, Filename, Line, Column);
591 Diags.Report(Loc, diag::err_fe_backend_unsupported) << D.getMessage().str();
598 Diags.Report(Loc, diag::note_fe_backend_invalid_loc)
599 << Filename << Line << Column;
603 const llvm::DiagnosticInfoOptimizationBase &D,
unsigned DiagID) {
605 assert(D.getSeverity() == llvm::DS_Remark ||
606 D.getSeverity() == llvm::DS_Warning);
609 unsigned Line, Column;
610 bool BadDebugInfo =
false;
612 getBestLocationFromDebugLoc(D, BadDebugInfo, Filename, Line, Column);
615 raw_string_ostream MsgStream(Msg);
616 MsgStream << D.getMsg();
619 MsgStream <<
" (hotness: " << *D.getHotness() <<
")";
621 Diags.Report(Loc, DiagID)
630 Diags.Report(Loc, diag::note_fe_backend_invalid_loc)
631 << Filename << Line << Column;
635 const llvm::DiagnosticInfoOptimizationBase &D) {
637 if (D.isVerbose() && !D.getHotness())
643 if (CodeGenOpts.OptimizationRemarkPattern &&
644 CodeGenOpts.OptimizationRemarkPattern->match(D.getPassName()))
645 EmitOptimizationMessage(D, diag::remark_fe_backend_optimization_remark);
646 }
else if (D.isMissed()) {
650 if (CodeGenOpts.OptimizationRemarkMissedPattern &&
651 CodeGenOpts.OptimizationRemarkMissedPattern->match(D.getPassName()))
652 EmitOptimizationMessage(
653 D, diag::remark_fe_backend_optimization_remark_missed);
655 assert(D.isAnalysis() &&
"Unknown remark type");
657 bool ShouldAlwaysPrint =
false;
658 if (
auto *ORA = dyn_cast<llvm::OptimizationRemarkAnalysis>(&D))
659 ShouldAlwaysPrint = ORA->shouldAlwaysPrint();
661 if (ShouldAlwaysPrint ||
662 (CodeGenOpts.OptimizationRemarkAnalysisPattern &&
663 CodeGenOpts.OptimizationRemarkAnalysisPattern->match(D.getPassName())))
664 EmitOptimizationMessage(
665 D, diag::remark_fe_backend_optimization_remark_analysis);
670 const llvm::OptimizationRemarkAnalysisFPCommute &D) {
675 if (D.shouldAlwaysPrint() ||
676 (CodeGenOpts.OptimizationRemarkAnalysisPattern &&
677 CodeGenOpts.OptimizationRemarkAnalysisPattern->match(D.getPassName())))
678 EmitOptimizationMessage(
679 D, diag::remark_fe_backend_optimization_remark_analysis_fpcommute);
683 const llvm::OptimizationRemarkAnalysisAliasing &D) {
688 if (D.shouldAlwaysPrint() ||
689 (CodeGenOpts.OptimizationRemarkAnalysisPattern &&
690 CodeGenOpts.OptimizationRemarkAnalysisPattern->match(D.getPassName())))
691 EmitOptimizationMessage(
692 D, diag::remark_fe_backend_optimization_remark_analysis_aliasing);
696 const llvm::DiagnosticInfoOptimizationFailure &D) {
697 EmitOptimizationMessage(D, diag::warn_fe_backend_optimization_failure);
703 unsigned DiagID = diag::err_fe_inline_asm;
704 llvm::DiagnosticSeverity
Severity = DI.getSeverity();
706 switch (DI.getKind()) {
707 case llvm::DK_InlineAsm:
708 if (InlineAsmDiagHandler(cast<DiagnosticInfoInlineAsm>(DI)))
712 case llvm::DK_StackSize:
713 if (StackSizeDiagHandler(cast<DiagnosticInfoStackSize>(DI)))
718 assert(CurLinkModule);
720 if (Severity != DS_Error)
722 DiagID = diag::err_fe_cannot_link_module;
724 case llvm::DK_OptimizationRemark:
727 OptimizationRemarkHandler(cast<OptimizationRemark>(DI));
729 case llvm::DK_OptimizationRemarkMissed:
732 OptimizationRemarkHandler(cast<OptimizationRemarkMissed>(DI));
734 case llvm::DK_OptimizationRemarkAnalysis:
737 OptimizationRemarkHandler(cast<OptimizationRemarkAnalysis>(DI));
739 case llvm::DK_OptimizationRemarkAnalysisFPCommute:
742 OptimizationRemarkHandler(cast<OptimizationRemarkAnalysisFPCommute>(DI));
744 case llvm::DK_OptimizationRemarkAnalysisAliasing:
747 OptimizationRemarkHandler(cast<OptimizationRemarkAnalysisAliasing>(DI));
749 case llvm::DK_MachineOptimizationRemark:
752 OptimizationRemarkHandler(cast<MachineOptimizationRemark>(DI));
754 case llvm::DK_MachineOptimizationRemarkMissed:
757 OptimizationRemarkHandler(cast<MachineOptimizationRemarkMissed>(DI));
759 case llvm::DK_MachineOptimizationRemarkAnalysis:
762 OptimizationRemarkHandler(cast<MachineOptimizationRemarkAnalysis>(DI));
764 case llvm::DK_OptimizationFailure:
767 OptimizationFailureHandler(cast<DiagnosticInfoOptimizationFailure>(DI));
769 case llvm::DK_Unsupported:
770 UnsupportedDiagHandler(cast<DiagnosticInfoUnsupported>(DI));
777 std::string MsgStorage;
779 raw_string_ostream Stream(MsgStorage);
780 DiagnosticPrinterRawOStream DP(Stream);
784 if (DiagID == diag::err_fe_cannot_link_module) {
785 Diags.Report(diag::err_fe_cannot_link_module)
786 << CurLinkModule->getModuleIdentifier() << MsgStorage;
792 Diags.Report(Loc, DiagID).AddString(MsgStorage);
797 : Act(_Act), VMContext(_VMContext ? _VMContext : new LLVMContext),
798 OwnsVMContext(!_VMContext) {}
818 return std::move(TheModule);
822 OwnsVMContext =
false;
826 static std::unique_ptr<raw_pwrite_stream>
843 llvm_unreachable(
"Invalid action!");
846 std::unique_ptr<ASTConsumer>
849 std::unique_ptr<raw_pwrite_stream> OS =
GetOutputStream(CI, InFile, BA);
854 if (LinkModules.empty())
860 << F.Filename << BCBuf.getError().message();
866 getOwningLazyBitcodeModule(std::move(*BCBuf), *VMContext);
868 handleAllErrors(ModuleOrErr.takeError(), [&](ErrorInfoBase &EIB) {
870 << F.Filename << EIB.message();
875 LinkModules.push_back({std::move(ModuleOrErr.get()), F.PropagateAttrs,
876 F.Internalize, F.LinkFlags});
884 std::unique_ptr<PPCallbacks>(CoverageInfo));
891 std::move(LinkModules), std::move(OS), *VMContext, CoverageInfo));
898 std::unique_ptr<PPCallbacks> Callbacks =
904 return std::move(Result);
909 unsigned LocCookie) {
910 SM.print(
nullptr, llvm::errs());
914 switch (SM.getKind()) {
915 case llvm::SourceMgr::DK_Error:
916 DiagID = diag::err_fe_inline_asm;
918 case llvm::SourceMgr::DK_Warning:
919 DiagID = diag::warn_fe_inline_asm;
921 case llvm::SourceMgr::DK_Note:
922 DiagID = diag::note_fe_inline_asm;
924 case llvm::SourceMgr::DK_Remark:
925 llvm_unreachable(
"remarks unexpected");
928 Diags->Report(DiagID).AddString(
"cannot compile inline asm");
931 std::unique_ptr<llvm::Module> CodeGenAction::loadModule(MemoryBufferRef MBRef) {
939 VMContext->enableDebugTypeODRUniquing();
941 auto DiagErrors = [&](
Error E) -> std::unique_ptr<llvm::Module> {
944 handleAllErrors(std::move(E), [&](ErrorInfoBase &EIB) {
952 return DiagErrors(BMOrErr.takeError());
955 BMOrErr->parseModule(*VMContext);
957 return DiagErrors(MOrErr.takeError());
958 return std::move(*MOrErr);
961 llvm::SMDiagnostic Err;
962 if (std::unique_ptr<llvm::Module> M = parseIR(MBRef, Err, *VMContext))
969 if (Err.getLineNo() > 0) {
970 assert(Err.getColumnNo() >= 0);
972 Err.getLineNo(), Err.getColumnNo() + 1);
976 StringRef Msg = Err.getMessage();
977 if (Msg.startswith(
"error: "))
992 std::unique_ptr<raw_pwrite_stream> OS =
1000 llvm::MemoryBuffer *MainFile = SM.
getBuffer(FID, &Invalid);
1004 TheModule = loadModule(*MainFile);
1009 if (TheModule->getTargetTriple() != TargetOpts.
Triple) {
1011 diag::warn_fe_override_module)
1013 TheModule->setTargetTriple(TargetOpts.
Triple);
1017 MainFile->getMemBufferRef());
1019 LLVMContext &Ctx = TheModule->getContext();
1036 void EmitAssemblyAction::anchor() { }
1040 void EmitBCAction::anchor() { }
1044 void EmitLLVMAction::anchor() { }
1048 void EmitLLVMOnlyAction::anchor() { }
1052 void EmitCodeGenOnlyAction::anchor() { }
1056 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...
An instance of this class is created to represent 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.
DominatorTree GraphTraits specialization so the DominatorTree can be iterable by generic graph iterat...
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)
VarDecl - An instance of this class is created to represent 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.
llvm::MemoryBuffer * getBuffer(FileID FID, SourceLocation Loc, bool *Invalid=nullptr) const
Return the buffer for the specified FileID.
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.
TagDecl - 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...
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.
FileID getMainFileID() const
Returns the FileID of the main source file.
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.
const StringRef getCurrentFile() const
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...