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)) {
130 llvm::TimePassesIsEnabled = TimePasses;
132 llvm::Module *
getModule()
const {
return Gen->GetModule(); }
134 return std::unique_ptr<llvm::Module>(Gen->ReleaseModule());
140 Gen->HandleCXXStaticMemberVarInstantiation(VD);
144 assert(!Context &&
"initialized multiple times");
149 LLVMIRGeneration.startTimer();
151 Gen->Initialize(Ctx);
154 LLVMIRGeneration.stopTimer();
160 "LLVM IR generation of declaration");
164 LLVMIRGenerationRefCount += 1;
165 if (LLVMIRGenerationRefCount == 1)
166 LLVMIRGeneration.startTimer();
169 Gen->HandleTopLevelDecl(D);
172 LLVMIRGenerationRefCount -= 1;
173 if (LLVMIRGenerationRefCount == 0)
174 LLVMIRGeneration.stopTimer();
183 "LLVM IR generation of inline function");
185 LLVMIRGeneration.startTimer();
187 Gen->HandleInlineFunctionDefinition(D);
190 LLVMIRGeneration.stopTimer();
196 HandleTopLevelDecl(D);
201 for (
auto &LM : LinkModules) {
202 if (LM.PropagateAttrs)
203 for (Function &F : *LM.Module)
204 Gen->CGM().AddDefaultFnAttrs(F);
206 CurLinkModule = LM.Module.get();
209 if (LM.Internalize) {
210 Err = Linker::linkModules(
211 *getModule(), std::move(LM.Module), LM.LinkFlags,
212 [](llvm::Module &M,
const llvm::StringSet<> &GVS) {
213 internalizeModule(M, [&GVS](const llvm::GlobalValue &GV) {
214 return !GV.hasName() || (GVS.count(GV.getName()) == 0);
218 Err = Linker::linkModules(*getModule(), std::move(LM.Module),
230 PrettyStackTraceString CrashInfo(
"Per-file LLVM IR generation");
232 LLVMIRGenerationRefCount += 1;
233 if (LLVMIRGenerationRefCount == 1)
234 LLVMIRGeneration.startTimer();
237 Gen->HandleTranslationUnit(C);
240 LLVMIRGenerationRefCount -= 1;
241 if (LLVMIRGenerationRefCount == 0)
242 LLVMIRGeneration.stopTimer();
245 IRGenFinished =
true;
254 LLVMContext &Ctx = getModule()->getContext();
255 LLVMContext::InlineAsmDiagHandlerTy OldHandler =
256 Ctx.getInlineAsmDiagnosticHandler();
257 void *OldContext = Ctx.getInlineAsmDiagnosticContext();
258 Ctx.setInlineAsmDiagnosticHandler(InlineAsmDiagHandler,
this);
260 std::unique_ptr<DiagnosticHandler> OldDiagnosticHandler =
261 Ctx.getDiagnosticHandler();
262 Ctx.setDiagnosticHandler(llvm::make_unique<ClangDiagnosticHandler>(
264 Ctx.setDiagnosticsHotnessRequested(CodeGenOpts.DiagnosticsWithHotness);
265 if (CodeGenOpts.DiagnosticsHotnessThreshold != 0)
266 Ctx.setDiagnosticsHotnessThreshold(
267 CodeGenOpts.DiagnosticsHotnessThreshold);
269 std::unique_ptr<llvm::ToolOutputFile> OptRecordFile;
270 if (!CodeGenOpts.OptRecordFile.empty()) {
272 OptRecordFile = llvm::make_unique<llvm::ToolOutputFile>(
273 CodeGenOpts.OptRecordFile, EC, sys::fs::F_None);
275 Diags.Report(diag::err_cannot_open_file) <<
276 CodeGenOpts.OptRecordFile << EC.message();
280 Ctx.setDiagnosticsOutputFile(
281 llvm::make_unique<yaml::Output>(OptRecordFile->os()));
284 Ctx.setDiagnosticsHotnessRequested(
true);
291 EmbedBitcode(getModule(), CodeGenOpts, llvm::MemoryBufferRef());
295 getModule(), Action, std::move(AsmOutStream));
297 Ctx.setInlineAsmDiagnosticHandler(OldHandler, OldContext);
299 Ctx.setDiagnosticHandler(std::move(OldDiagnosticHandler));
302 OptRecordFile->keep();
308 "LLVM IR generation of declaration");
309 Gen->HandleTagDeclDefinition(D);
313 Gen->HandleTagDeclRequiredDefinition(D);
317 Gen->CompleteTentativeDefinition(D);
321 Gen->AssignInheritanceModel(RD);
325 Gen->HandleVTable(RD);
329 unsigned LocCookie) {
337 getBestLocationFromDebugLoc(
const llvm::DiagnosticInfoWithLocationBase &D,
338 bool &BadDebugInfo, StringRef &
Filename,
339 unsigned &
Line,
unsigned &Column)
const;
341 void InlineAsmDiagHandler2(
const llvm::SMDiagnostic &,
344 void DiagnosticHandlerImpl(
const llvm::DiagnosticInfo &DI);
348 bool InlineAsmDiagHandler(
const llvm::DiagnosticInfoInlineAsm &D);
352 bool StackSizeDiagHandler(
const llvm::DiagnosticInfoStackSize &D);
354 void UnsupportedDiagHandler(
const llvm::DiagnosticInfoUnsupported &D);
358 void EmitOptimizationMessage(
const llvm::DiagnosticInfoOptimizationBase &D,
361 OptimizationRemarkHandler(
const llvm::DiagnosticInfoOptimizationBase &D);
362 void OptimizationRemarkHandler(
363 const llvm::OptimizationRemarkAnalysisFPCommute &D);
364 void OptimizationRemarkHandler(
365 const llvm::OptimizationRemarkAnalysisAliasing &D);
366 void OptimizationFailureHandler(
367 const llvm::DiagnosticInfoOptimizationFailure &D);
370 void BackendConsumer::anchor() {}
374 BackendCon->DiagnosticHandlerImpl(DI);
385 const llvm::SourceMgr &LSM = *D.getSourceMgr();
389 const MemoryBuffer *LBuf =
390 LSM.getMemoryBuffer(LSM.FindBufferContainingLoc(D.getLoc()));
394 std::unique_ptr<llvm::MemoryBuffer> CBuf =
395 llvm::MemoryBuffer::getMemBufferCopy(LBuf->getBuffer(),
396 LBuf->getBufferIdentifier());
401 unsigned Offset = D.getLoc().getPointer() - LBuf->getBufferStart();
417 StringRef Message = D.getMessage();
418 if (Message.startswith(
"error: "))
419 Message = Message.substr(7);
423 if (D.getLoc() != SMLoc())
427 switch (D.getKind()) {
428 case llvm::SourceMgr::DK_Error:
429 DiagID = diag::err_fe_inline_asm;
431 case llvm::SourceMgr::DK_Warning:
432 DiagID = diag::warn_fe_inline_asm;
434 case llvm::SourceMgr::DK_Note:
435 DiagID = diag::note_fe_inline_asm;
437 case llvm::SourceMgr::DK_Remark:
438 llvm_unreachable(
"remarks unexpected");
444 Diags.Report(LocCookie, DiagID).AddString(Message);
446 if (D.getLoc().isValid()) {
450 for (
const std::pair<unsigned, unsigned> &Range : D.getRanges()) {
451 unsigned Column = D.getColumnNo();
462 Diags.Report(Loc, DiagID).AddString(Message);
465 #define ComputeDiagID(Severity, GroupName, DiagID) \ 467 switch (Severity) { \ 468 case llvm::DS_Error: \ 469 DiagID = diag::err_fe_##GroupName; \ 471 case llvm::DS_Warning: \ 472 DiagID = diag::warn_fe_##GroupName; \ 474 case llvm::DS_Remark: \ 475 llvm_unreachable("'remark' severity not expected"); \ 477 case llvm::DS_Note: \ 478 DiagID = diag::note_fe_##GroupName; \ 483 #define ComputeDiagRemarkID(Severity, GroupName, DiagID) \ 485 switch (Severity) { \ 486 case llvm::DS_Error: \ 487 DiagID = diag::err_fe_##GroupName; \ 489 case llvm::DS_Warning: \ 490 DiagID = diag::warn_fe_##GroupName; \ 492 case llvm::DS_Remark: \ 493 DiagID = diag::remark_fe_##GroupName; \ 495 case llvm::DS_Note: \ 496 DiagID = diag::note_fe_##GroupName; \ 505 std::string Message = D.getMsgStr().str();
513 Diags.Report(LocCookie, DiagID).AddString(Message);
520 Diags.Report(Loc, DiagID).AddString(Message);
528 if (D.getSeverity() != llvm::DS_Warning)
533 if (
const Decl *ND = Gen->GetDeclForMangledName(D.getFunction().getName())) {
535 Diags.Report(ND->getASTContext().getFullLoc(ND->getLocation()),
536 diag::warn_fe_frame_larger_than)
545 const llvm::DiagnosticInfoWithLocationBase &D,
bool &BadDebugInfo,
546 StringRef &
Filename,
unsigned &
Line,
unsigned &Column)
const {
551 if (D.isLocationAvailable()) {
552 D.getLocation(&Filename, &Line, &Column);
554 if (FE && Line > 0) {
567 if (
const Decl *FD = Gen->GetDeclForMangledName(D.getFunction().getName()))
568 Loc = FD->getASTContext().getFullLoc(FD->getLocation());
570 if (DILoc.
isInvalid() && D.isLocationAvailable())
575 Diags.Report(Loc, diag::note_fe_backend_invalid_loc)
576 << Filename << Line << Column;
582 const llvm::DiagnosticInfoUnsupported &D) {
584 assert(D.getSeverity() == llvm::DS_Error);
587 unsigned Line, Column;
588 bool BadDebugInfo =
false;
590 getBestLocationFromDebugLoc(D, BadDebugInfo, Filename, Line, Column);
592 Diags.Report(Loc, diag::err_fe_backend_unsupported) << D.getMessage().str();
599 Diags.Report(Loc, diag::note_fe_backend_invalid_loc)
600 << Filename << Line << Column;
604 const llvm::DiagnosticInfoOptimizationBase &D,
unsigned DiagID) {
606 assert(D.getSeverity() == llvm::DS_Remark ||
607 D.getSeverity() == llvm::DS_Warning);
610 unsigned Line, Column;
611 bool BadDebugInfo =
false;
613 getBestLocationFromDebugLoc(D, BadDebugInfo, Filename, Line, Column);
616 raw_string_ostream MsgStream(Msg);
617 MsgStream << D.getMsg();
620 MsgStream <<
" (hotness: " << *D.getHotness() <<
")";
622 Diags.Report(Loc, DiagID)
631 Diags.Report(Loc, diag::note_fe_backend_invalid_loc)
632 << Filename << Line << Column;
636 const llvm::DiagnosticInfoOptimizationBase &D) {
638 if (D.isVerbose() && !D.getHotness())
644 if (CodeGenOpts.OptimizationRemarkPattern &&
645 CodeGenOpts.OptimizationRemarkPattern->match(D.getPassName()))
646 EmitOptimizationMessage(D, diag::remark_fe_backend_optimization_remark);
647 }
else if (D.isMissed()) {
651 if (CodeGenOpts.OptimizationRemarkMissedPattern &&
652 CodeGenOpts.OptimizationRemarkMissedPattern->match(D.getPassName()))
653 EmitOptimizationMessage(
654 D, diag::remark_fe_backend_optimization_remark_missed);
656 assert(D.isAnalysis() &&
"Unknown remark type");
658 bool ShouldAlwaysPrint =
false;
659 if (
auto *ORA = dyn_cast<llvm::OptimizationRemarkAnalysis>(&D))
660 ShouldAlwaysPrint = ORA->shouldAlwaysPrint();
662 if (ShouldAlwaysPrint ||
663 (CodeGenOpts.OptimizationRemarkAnalysisPattern &&
664 CodeGenOpts.OptimizationRemarkAnalysisPattern->match(D.getPassName())))
665 EmitOptimizationMessage(
666 D, diag::remark_fe_backend_optimization_remark_analysis);
671 const llvm::OptimizationRemarkAnalysisFPCommute &D) {
676 if (D.shouldAlwaysPrint() ||
677 (CodeGenOpts.OptimizationRemarkAnalysisPattern &&
678 CodeGenOpts.OptimizationRemarkAnalysisPattern->match(D.getPassName())))
679 EmitOptimizationMessage(
680 D, diag::remark_fe_backend_optimization_remark_analysis_fpcommute);
684 const llvm::OptimizationRemarkAnalysisAliasing &D) {
689 if (D.shouldAlwaysPrint() ||
690 (CodeGenOpts.OptimizationRemarkAnalysisPattern &&
691 CodeGenOpts.OptimizationRemarkAnalysisPattern->match(D.getPassName())))
692 EmitOptimizationMessage(
693 D, diag::remark_fe_backend_optimization_remark_analysis_aliasing);
697 const llvm::DiagnosticInfoOptimizationFailure &D) {
698 EmitOptimizationMessage(D, diag::warn_fe_backend_optimization_failure);
704 unsigned DiagID = diag::err_fe_inline_asm;
705 llvm::DiagnosticSeverity
Severity = DI.getSeverity();
707 switch (DI.getKind()) {
708 case llvm::DK_InlineAsm:
709 if (InlineAsmDiagHandler(cast<DiagnosticInfoInlineAsm>(DI)))
713 case llvm::DK_StackSize:
714 if (StackSizeDiagHandler(cast<DiagnosticInfoStackSize>(DI)))
719 assert(CurLinkModule);
721 if (Severity != DS_Error)
723 DiagID = diag::err_fe_cannot_link_module;
725 case llvm::DK_OptimizationRemark:
728 OptimizationRemarkHandler(cast<OptimizationRemark>(DI));
730 case llvm::DK_OptimizationRemarkMissed:
733 OptimizationRemarkHandler(cast<OptimizationRemarkMissed>(DI));
735 case llvm::DK_OptimizationRemarkAnalysis:
738 OptimizationRemarkHandler(cast<OptimizationRemarkAnalysis>(DI));
740 case llvm::DK_OptimizationRemarkAnalysisFPCommute:
743 OptimizationRemarkHandler(cast<OptimizationRemarkAnalysisFPCommute>(DI));
745 case llvm::DK_OptimizationRemarkAnalysisAliasing:
748 OptimizationRemarkHandler(cast<OptimizationRemarkAnalysisAliasing>(DI));
750 case llvm::DK_MachineOptimizationRemark:
753 OptimizationRemarkHandler(cast<MachineOptimizationRemark>(DI));
755 case llvm::DK_MachineOptimizationRemarkMissed:
758 OptimizationRemarkHandler(cast<MachineOptimizationRemarkMissed>(DI));
760 case llvm::DK_MachineOptimizationRemarkAnalysis:
763 OptimizationRemarkHandler(cast<MachineOptimizationRemarkAnalysis>(DI));
765 case llvm::DK_OptimizationFailure:
768 OptimizationFailureHandler(cast<DiagnosticInfoOptimizationFailure>(DI));
770 case llvm::DK_Unsupported:
771 UnsupportedDiagHandler(cast<DiagnosticInfoUnsupported>(DI));
778 std::string MsgStorage;
780 raw_string_ostream Stream(MsgStorage);
781 DiagnosticPrinterRawOStream DP(Stream);
785 if (DiagID == diag::err_fe_cannot_link_module) {
786 Diags.Report(diag::err_fe_cannot_link_module)
787 << CurLinkModule->getModuleIdentifier() << MsgStorage;
793 Diags.Report(Loc, DiagID).AddString(MsgStorage);
798 : Act(_Act), VMContext(_VMContext ? _VMContext : new LLVMContext),
799 OwnsVMContext(!_VMContext) {}
819 return std::move(TheModule);
823 OwnsVMContext =
false;
827 static std::unique_ptr<raw_pwrite_stream>
844 llvm_unreachable(
"Invalid action!");
847 std::unique_ptr<ASTConsumer>
858 if (LinkModules.empty())
864 << F.Filename << BCBuf.getError().message();
870 getOwningLazyBitcodeModule(std::move(*BCBuf), *VMContext);
872 handleAllErrors(ModuleOrErr.takeError(), [&](ErrorInfoBase &EIB) {
874 << F.Filename << EIB.message();
879 LinkModules.push_back({std::move(ModuleOrErr.get()), F.PropagateAttrs,
880 F.Internalize, F.LinkFlags});
888 std::unique_ptr<PPCallbacks>(CoverageInfo));
895 std::move(LinkModules), std::move(OS), *VMContext, CoverageInfo));
902 std::unique_ptr<PPCallbacks> Callbacks =
908 return std::move(Result);
913 unsigned LocCookie) {
914 SM.print(
nullptr, llvm::errs());
918 switch (SM.getKind()) {
919 case llvm::SourceMgr::DK_Error:
920 DiagID = diag::err_fe_inline_asm;
922 case llvm::SourceMgr::DK_Warning:
923 DiagID = diag::warn_fe_inline_asm;
925 case llvm::SourceMgr::DK_Note:
926 DiagID = diag::note_fe_inline_asm;
928 case llvm::SourceMgr::DK_Remark:
929 llvm_unreachable(
"remarks unexpected");
932 Diags->Report(DiagID).AddString(
"cannot compile inline asm");
935 std::unique_ptr<llvm::Module> CodeGenAction::loadModule(MemoryBufferRef MBRef) {
943 VMContext->enableDebugTypeODRUniquing();
945 auto DiagErrors = [&](
Error E) -> std::unique_ptr<llvm::Module> {
948 handleAllErrors(std::move(E), [&](ErrorInfoBase &EIB) {
956 return DiagErrors(BMsOrErr.takeError());
963 auto M = llvm::make_unique<llvm::Module>(
"empty", *VMContext);
968 Bm->parseModule(*VMContext);
970 return DiagErrors(MOrErr.takeError());
971 return std::move(*MOrErr);
974 llvm::SMDiagnostic Err;
975 if (std::unique_ptr<llvm::Module> M = parseIR(MBRef, Err, *VMContext))
982 if (Err.getLineNo() > 0) {
983 assert(Err.getColumnNo() >= 0);
985 Err.getLineNo(), Err.getColumnNo() + 1);
989 StringRef Msg = Err.getMessage();
990 if (Msg.startswith(
"error: "))
1005 std::unique_ptr<raw_pwrite_stream> OS =
1013 llvm::MemoryBuffer *MainFile = SM.
getBuffer(FID, &Invalid);
1017 TheModule = loadModule(*MainFile);
1022 if (TheModule->getTargetTriple() != TargetOpts.
Triple) {
1024 diag::warn_fe_override_module)
1026 TheModule->setTargetTriple(TargetOpts.
Triple);
1030 MainFile->getMemBufferRef());
1032 LLVMContext &Ctx = TheModule->getContext();
1049 void EmitAssemblyAction::anchor() { }
1053 void EmitBCAction::anchor() { }
1057 void EmitLLVMAction::anchor() { }
1061 void EmitLLVMOnlyAction::anchor() { }
1065 void EmitCodeGenOnlyAction::anchor() { }
1069 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.
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)
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.
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.
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...
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.
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...