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);
556 FE = FileMgr.
getFile(D.getAbsolutePath());
571 if (
const Decl *FD = Gen->GetDeclForMangledName(D.getFunction().getName()))
572 Loc = FD->getASTContext().getFullLoc(FD->getLocation());
574 if (DILoc.
isInvalid() && D.isLocationAvailable())
579 Diags.Report(Loc, diag::note_fe_backend_invalid_loc)
580 << Filename << Line << Column;
586 const llvm::DiagnosticInfoUnsupported &D) {
588 assert(D.getSeverity() == llvm::DS_Error);
591 unsigned Line, Column;
592 bool BadDebugInfo =
false;
594 getBestLocationFromDebugLoc(D, BadDebugInfo, Filename, Line, Column);
596 Diags.Report(Loc, diag::err_fe_backend_unsupported) << D.getMessage().str();
603 Diags.Report(Loc, diag::note_fe_backend_invalid_loc)
604 << Filename << Line << Column;
608 const llvm::DiagnosticInfoOptimizationBase &D,
unsigned DiagID) {
610 assert(D.getSeverity() == llvm::DS_Remark ||
611 D.getSeverity() == llvm::DS_Warning);
614 unsigned Line, Column;
615 bool BadDebugInfo =
false;
617 getBestLocationFromDebugLoc(D, BadDebugInfo, Filename, Line, Column);
620 raw_string_ostream MsgStream(Msg);
621 MsgStream << D.getMsg();
624 MsgStream <<
" (hotness: " << *D.getHotness() <<
")";
626 Diags.Report(Loc, DiagID)
635 Diags.Report(Loc, diag::note_fe_backend_invalid_loc)
636 << Filename << Line << Column;
640 const llvm::DiagnosticInfoOptimizationBase &D) {
642 if (D.isVerbose() && !D.getHotness())
648 if (CodeGenOpts.OptimizationRemarkPattern &&
649 CodeGenOpts.OptimizationRemarkPattern->match(D.getPassName()))
650 EmitOptimizationMessage(D, diag::remark_fe_backend_optimization_remark);
651 }
else if (D.isMissed()) {
655 if (CodeGenOpts.OptimizationRemarkMissedPattern &&
656 CodeGenOpts.OptimizationRemarkMissedPattern->match(D.getPassName()))
657 EmitOptimizationMessage(
658 D, diag::remark_fe_backend_optimization_remark_missed);
660 assert(D.isAnalysis() &&
"Unknown remark type");
662 bool ShouldAlwaysPrint =
false;
663 if (
auto *ORA = dyn_cast<llvm::OptimizationRemarkAnalysis>(&D))
664 ShouldAlwaysPrint = ORA->shouldAlwaysPrint();
666 if (ShouldAlwaysPrint ||
667 (CodeGenOpts.OptimizationRemarkAnalysisPattern &&
668 CodeGenOpts.OptimizationRemarkAnalysisPattern->match(D.getPassName())))
669 EmitOptimizationMessage(
670 D, diag::remark_fe_backend_optimization_remark_analysis);
675 const llvm::OptimizationRemarkAnalysisFPCommute &D) {
680 if (D.shouldAlwaysPrint() ||
681 (CodeGenOpts.OptimizationRemarkAnalysisPattern &&
682 CodeGenOpts.OptimizationRemarkAnalysisPattern->match(D.getPassName())))
683 EmitOptimizationMessage(
684 D, diag::remark_fe_backend_optimization_remark_analysis_fpcommute);
688 const llvm::OptimizationRemarkAnalysisAliasing &D) {
693 if (D.shouldAlwaysPrint() ||
694 (CodeGenOpts.OptimizationRemarkAnalysisPattern &&
695 CodeGenOpts.OptimizationRemarkAnalysisPattern->match(D.getPassName())))
696 EmitOptimizationMessage(
697 D, diag::remark_fe_backend_optimization_remark_analysis_aliasing);
701 const llvm::DiagnosticInfoOptimizationFailure &D) {
702 EmitOptimizationMessage(D, diag::warn_fe_backend_optimization_failure);
708 unsigned DiagID = diag::err_fe_inline_asm;
709 llvm::DiagnosticSeverity
Severity = DI.getSeverity();
711 switch (DI.getKind()) {
712 case llvm::DK_InlineAsm:
713 if (InlineAsmDiagHandler(cast<DiagnosticInfoInlineAsm>(DI)))
717 case llvm::DK_StackSize:
718 if (StackSizeDiagHandler(cast<DiagnosticInfoStackSize>(DI)))
723 assert(CurLinkModule);
725 if (Severity != DS_Error)
727 DiagID = diag::err_fe_cannot_link_module;
729 case llvm::DK_OptimizationRemark:
732 OptimizationRemarkHandler(cast<OptimizationRemark>(DI));
734 case llvm::DK_OptimizationRemarkMissed:
737 OptimizationRemarkHandler(cast<OptimizationRemarkMissed>(DI));
739 case llvm::DK_OptimizationRemarkAnalysis:
742 OptimizationRemarkHandler(cast<OptimizationRemarkAnalysis>(DI));
744 case llvm::DK_OptimizationRemarkAnalysisFPCommute:
747 OptimizationRemarkHandler(cast<OptimizationRemarkAnalysisFPCommute>(DI));
749 case llvm::DK_OptimizationRemarkAnalysisAliasing:
752 OptimizationRemarkHandler(cast<OptimizationRemarkAnalysisAliasing>(DI));
754 case llvm::DK_MachineOptimizationRemark:
757 OptimizationRemarkHandler(cast<MachineOptimizationRemark>(DI));
759 case llvm::DK_MachineOptimizationRemarkMissed:
762 OptimizationRemarkHandler(cast<MachineOptimizationRemarkMissed>(DI));
764 case llvm::DK_MachineOptimizationRemarkAnalysis:
767 OptimizationRemarkHandler(cast<MachineOptimizationRemarkAnalysis>(DI));
769 case llvm::DK_OptimizationFailure:
772 OptimizationFailureHandler(cast<DiagnosticInfoOptimizationFailure>(DI));
774 case llvm::DK_Unsupported:
775 UnsupportedDiagHandler(cast<DiagnosticInfoUnsupported>(DI));
782 std::string MsgStorage;
784 raw_string_ostream Stream(MsgStorage);
785 DiagnosticPrinterRawOStream DP(Stream);
789 if (DiagID == diag::err_fe_cannot_link_module) {
790 Diags.Report(diag::err_fe_cannot_link_module)
791 << CurLinkModule->getModuleIdentifier() << MsgStorage;
797 Diags.Report(Loc, DiagID).AddString(MsgStorage);
802 : Act(_Act), VMContext(_VMContext ? _VMContext : new LLVMContext),
803 OwnsVMContext(!_VMContext) {}
823 return std::move(TheModule);
827 OwnsVMContext =
false;
831 static std::unique_ptr<raw_pwrite_stream>
848 llvm_unreachable(
"Invalid action!");
851 std::unique_ptr<ASTConsumer>
862 if (LinkModules.empty())
868 << F.Filename << BCBuf.getError().message();
874 getOwningLazyBitcodeModule(std::move(*BCBuf), *VMContext);
876 handleAllErrors(ModuleOrErr.takeError(), [&](ErrorInfoBase &EIB) {
878 << F.Filename << EIB.message();
883 LinkModules.push_back({std::move(ModuleOrErr.get()), F.PropagateAttrs,
884 F.Internalize, F.LinkFlags});
892 std::unique_ptr<PPCallbacks>(CoverageInfo));
899 std::move(LinkModules), std::move(OS), *VMContext, CoverageInfo));
906 std::unique_ptr<PPCallbacks> Callbacks =
912 return std::move(Result);
917 unsigned LocCookie) {
918 SM.print(
nullptr, llvm::errs());
922 switch (SM.getKind()) {
923 case llvm::SourceMgr::DK_Error:
924 DiagID = diag::err_fe_inline_asm;
926 case llvm::SourceMgr::DK_Warning:
927 DiagID = diag::warn_fe_inline_asm;
929 case llvm::SourceMgr::DK_Note:
930 DiagID = diag::note_fe_inline_asm;
932 case llvm::SourceMgr::DK_Remark:
933 llvm_unreachable(
"remarks unexpected");
936 Diags->Report(DiagID).AddString(
"cannot compile inline asm");
939 std::unique_ptr<llvm::Module> CodeGenAction::loadModule(MemoryBufferRef MBRef) {
947 VMContext->enableDebugTypeODRUniquing();
949 auto DiagErrors = [&](
Error E) -> std::unique_ptr<llvm::Module> {
952 handleAllErrors(std::move(E), [&](ErrorInfoBase &EIB) {
960 return DiagErrors(BMsOrErr.takeError());
967 auto M = llvm::make_unique<llvm::Module>(
"empty", *VMContext);
972 Bm->parseModule(*VMContext);
974 return DiagErrors(MOrErr.takeError());
975 return std::move(*MOrErr);
978 llvm::SMDiagnostic Err;
979 if (std::unique_ptr<llvm::Module> M = parseIR(MBRef, Err, *VMContext))
986 if (Err.getLineNo() > 0) {
987 assert(Err.getColumnNo() >= 0);
989 Err.getLineNo(), Err.getColumnNo() + 1);
993 StringRef Msg = Err.getMessage();
994 if (Msg.startswith(
"error: "))
1009 std::unique_ptr<raw_pwrite_stream> OS =
1017 llvm::MemoryBuffer *MainFile = SM.
getBuffer(FID, &Invalid);
1021 TheModule = loadModule(*MainFile);
1026 if (TheModule->getTargetTriple() != TargetOpts.
Triple) {
1028 diag::warn_fe_override_module)
1030 TheModule->setTargetTriple(TargetOpts.
Triple);
1034 MainFile->getMemBufferRef());
1036 LLVMContext &Ctx = TheModule->getContext();
1053 void EmitAssemblyAction::anchor() { }
1057 void EmitBCAction::anchor() { }
1061 void EmitLLVMAction::anchor() { }
1065 void EmitLLVMOnlyAction::anchor() { }
1069 void EmitCodeGenOnlyAction::anchor() { }
1073 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.
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...