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;
50 using LinkModule = CodeGenAction::LinkModule;
52 virtual void anchor();
59 std::unique_ptr<raw_pwrite_stream> AsmOutStream;
62 Timer LLVMIRGeneration;
63 unsigned LLVMIRGenerationRefCount;
68 bool IRGenFinished =
false;
70 std::unique_ptr<CodeGenerator> Gen;
76 llvm::Module *CurLinkModule =
nullptr;
85 const std::string &InFile,
87 std::unique_ptr<raw_pwrite_stream> OS, LLVMContext &C,
89 : Diags(Diags), Action(Action), HeaderSearchOpts(HeaderSearchOpts),
90 CodeGenOpts(CodeGenOpts), TargetOpts(TargetOpts), LangOpts(LangOpts),
91 AsmOutStream(std::move(OS)),
Context(nullptr),
92 LLVMIRGeneration(
"irgen",
"LLVM IR Generation Time"),
93 LLVMIRGenerationRefCount(0),
95 CodeGenOpts, C, CoverageInfo)),
96 LinkModules(std::move(LinkModules)) {
97 llvm::TimePassesIsEnabled = TimePasses;
99 llvm::Module *
getModule()
const {
return Gen->GetModule(); }
101 return std::unique_ptr<llvm::Module>(Gen->ReleaseModule());
107 Gen->HandleCXXStaticMemberVarInstantiation(VD);
111 assert(!
Context &&
"initialized multiple times");
115 if (llvm::TimePassesIsEnabled)
116 LLVMIRGeneration.startTimer();
118 Gen->Initialize(Ctx);
120 if (llvm::TimePassesIsEnabled)
121 LLVMIRGeneration.stopTimer();
127 "LLVM IR generation of declaration");
130 if (llvm::TimePassesIsEnabled) {
131 LLVMIRGenerationRefCount += 1;
132 if (LLVMIRGenerationRefCount == 1)
133 LLVMIRGeneration.startTimer();
136 Gen->HandleTopLevelDecl(D);
138 if (llvm::TimePassesIsEnabled) {
139 LLVMIRGenerationRefCount -= 1;
140 if (LLVMIRGenerationRefCount == 0)
141 LLVMIRGeneration.stopTimer();
150 "LLVM IR generation of inline function");
151 if (llvm::TimePassesIsEnabled)
152 LLVMIRGeneration.startTimer();
154 Gen->HandleInlineFunctionDefinition(D);
156 if (llvm::TimePassesIsEnabled)
157 LLVMIRGeneration.stopTimer();
163 HandleTopLevelDecl(D);
168 for (
auto &LM : LinkModules) {
169 if (LM.PropagateAttrs)
170 for (Function &F : *LM.Module)
171 Gen->CGM().AddDefaultFnAttrs(F);
173 CurLinkModule = LM.Module.get();
176 if (LM.Internalize) {
177 Err = Linker::linkModules(
178 *getModule(), std::move(LM.Module), LM.LinkFlags,
179 [](llvm::Module &M,
const llvm::StringSet<> &GVS) {
180 internalizeModule(M, [&GVS](
const llvm::GlobalValue &GV) {
181 return !GV.hasName() || (GVS.count(GV.getName()) == 0);
185 Err = Linker::linkModules(*getModule(), std::move(LM.Module),
197 PrettyStackTraceString CrashInfo(
"Per-file LLVM IR generation");
198 if (llvm::TimePassesIsEnabled) {
199 LLVMIRGenerationRefCount += 1;
200 if (LLVMIRGenerationRefCount == 1)
201 LLVMIRGeneration.startTimer();
204 Gen->HandleTranslationUnit(C);
206 if (llvm::TimePassesIsEnabled) {
207 LLVMIRGenerationRefCount -= 1;
208 if (LLVMIRGenerationRefCount == 0)
209 LLVMIRGeneration.stopTimer();
212 IRGenFinished =
true;
221 LLVMContext &Ctx = getModule()->getContext();
222 LLVMContext::InlineAsmDiagHandlerTy OldHandler =
223 Ctx.getInlineAsmDiagnosticHandler();
224 void *OldContext = Ctx.getInlineAsmDiagnosticContext();
225 Ctx.setInlineAsmDiagnosticHandler(InlineAsmDiagHandler,
this);
227 LLVMContext::DiagnosticHandlerTy OldDiagnosticHandler =
228 Ctx.getDiagnosticHandler();
229 void *OldDiagnosticContext = Ctx.getDiagnosticContext();
230 Ctx.setDiagnosticHandler(DiagnosticHandler,
this);
231 Ctx.setDiagnosticsHotnessRequested(CodeGenOpts.DiagnosticsWithHotness);
232 if (CodeGenOpts.DiagnosticsHotnessThreshold != 0)
233 Ctx.setDiagnosticsHotnessThreshold(
234 CodeGenOpts.DiagnosticsHotnessThreshold);
236 std::unique_ptr<llvm::tool_output_file> OptRecordFile;
237 if (!CodeGenOpts.OptRecordFile.empty()) {
240 llvm::make_unique<llvm::tool_output_file>(CodeGenOpts.OptRecordFile,
241 EC, sys::fs::F_None);
243 Diags.Report(diag::err_cannot_open_file) <<
244 CodeGenOpts.OptRecordFile << EC.message();
248 Ctx.setDiagnosticsOutputFile(
249 llvm::make_unique<yaml::Output>(OptRecordFile->os()));
252 Ctx.setDiagnosticsHotnessRequested(
true);
259 EmbedBitcode(getModule(), CodeGenOpts, llvm::MemoryBufferRef());
263 getModule(),
Action, std::move(AsmOutStream));
265 Ctx.setInlineAsmDiagnosticHandler(OldHandler, OldContext);
267 Ctx.setDiagnosticHandler(OldDiagnosticHandler, OldDiagnosticContext);
270 OptRecordFile->keep();
276 "LLVM IR generation of declaration");
277 Gen->HandleTagDeclDefinition(D);
281 Gen->HandleTagDeclRequiredDefinition(D);
285 Gen->CompleteTentativeDefinition(D);
289 Gen->AssignInheritanceModel(RD);
293 Gen->HandleVTable(RD);
297 unsigned LocCookie) {
310 getBestLocationFromDebugLoc(
const llvm::DiagnosticInfoWithLocationBase &D,
311 bool &BadDebugInfo, StringRef &
Filename,
314 void InlineAsmDiagHandler2(
const llvm::SMDiagnostic &,
317 void DiagnosticHandlerImpl(
const llvm::DiagnosticInfo &DI);
321 bool InlineAsmDiagHandler(
const llvm::DiagnosticInfoInlineAsm &D);
325 bool StackSizeDiagHandler(
const llvm::DiagnosticInfoStackSize &D);
327 void UnsupportedDiagHandler(
const llvm::DiagnosticInfoUnsupported &D);
331 void EmitOptimizationMessage(
const llvm::DiagnosticInfoOptimizationBase &D,
334 OptimizationRemarkHandler(
const llvm::DiagnosticInfoOptimizationBase &D);
335 void OptimizationRemarkHandler(
336 const llvm::OptimizationRemarkAnalysisFPCommute &D);
337 void OptimizationRemarkHandler(
338 const llvm::OptimizationRemarkAnalysisAliasing &D);
339 void OptimizationFailureHandler(
340 const llvm::DiagnosticInfoOptimizationFailure &D);
343 void BackendConsumer::anchor() {}
357 const MemoryBuffer *LBuf =
358 LSM.getMemoryBuffer(LSM.FindBufferContainingLoc(D.getLoc()));
362 std::unique_ptr<llvm::MemoryBuffer> CBuf =
363 llvm::MemoryBuffer::getMemBufferCopy(LBuf->getBuffer(),
364 LBuf->getBufferIdentifier());
369 unsigned Offset = D.getLoc().getPointer() - LBuf->getBufferStart();
385 StringRef Message = D.getMessage();
386 if (Message.startswith(
"error: "))
387 Message = Message.substr(7);
391 if (D.getLoc() != SMLoc())
395 switch (D.getKind()) {
396 case llvm::SourceMgr::DK_Error:
397 DiagID = diag::err_fe_inline_asm;
399 case llvm::SourceMgr::DK_Warning:
400 DiagID = diag::warn_fe_inline_asm;
402 case llvm::SourceMgr::DK_Note:
403 DiagID = diag::note_fe_inline_asm;
412 if (D.getLoc().isValid()) {
416 for (
const std::pair<unsigned, unsigned> &Range : D.getRanges()) {
417 unsigned Column = D.getColumnNo();
431 #define ComputeDiagID(Severity, GroupName, DiagID) \
433 switch (Severity) { \
434 case llvm::DS_Error: \
435 DiagID = diag::err_fe_##GroupName; \
437 case llvm::DS_Warning: \
438 DiagID = diag::warn_fe_##GroupName; \
440 case llvm::DS_Remark: \
441 llvm_unreachable("'remark' severity not expected"); \
443 case llvm::DS_Note: \
444 DiagID = diag::note_fe_##GroupName; \
449 #define ComputeDiagRemarkID(Severity, GroupName, DiagID) \
451 switch (Severity) { \
452 case llvm::DS_Error: \
453 DiagID = diag::err_fe_##GroupName; \
455 case llvm::DS_Warning: \
456 DiagID = diag::warn_fe_##GroupName; \
458 case llvm::DS_Remark: \
459 DiagID = diag::remark_fe_##GroupName; \
461 case llvm::DS_Note: \
462 DiagID = diag::note_fe_##GroupName; \
471 std::string Message = D.getMsgStr().str();
494 if (D.getSeverity() != llvm::DS_Warning)
499 if (
const Decl *ND = Gen->GetDeclForMangledName(D.getFunction().getName())) {
501 Diags.
Report(ND->getASTContext().getFullLoc(ND->getLocation()),
502 diag::warn_fe_frame_larger_than)
511 const llvm::DiagnosticInfoWithLocationBase &D,
bool &BadDebugInfo,
517 if (D.isLocationAvailable()) {
518 D.getLocation(&Filename, &Line, &Column);
520 if (FE && Line > 0) {
533 if (
const Decl *FD = Gen->GetDeclForMangledName(D.getFunction().getName()))
534 Loc = FD->getASTContext().getFullLoc(FD->getLocation());
536 if (DILoc.
isInvalid() && D.isLocationAvailable())
541 Diags.
Report(Loc, diag::note_fe_backend_invalid_loc)
542 << Filename << Line <<
Column;
548 const llvm::DiagnosticInfoUnsupported &D) {
550 assert(D.getSeverity() == llvm::DS_Error);
554 bool BadDebugInfo =
false;
558 Diags.
Report(Loc, diag::err_fe_backend_unsupported) << D.getMessage().str();
565 Diags.
Report(Loc, diag::note_fe_backend_invalid_loc)
566 << Filename << Line <<
Column;
570 const llvm::DiagnosticInfoOptimizationBase &D,
unsigned DiagID) {
572 assert(D.getSeverity() == llvm::DS_Remark ||
573 D.getSeverity() == llvm::DS_Warning);
577 bool BadDebugInfo =
false;
582 raw_string_ostream MsgStream(Msg);
583 MsgStream << D.getMsg();
586 MsgStream <<
" (hotness: " << *D.getHotness() <<
")";
597 Diags.
Report(Loc, diag::note_fe_backend_invalid_loc)
598 << Filename << Line <<
Column;
602 const llvm::DiagnosticInfoOptimizationBase &D) {
609 }
else if (D.isMissed()) {
616 D, diag::remark_fe_backend_optimization_remark_missed);
618 assert(D.isAnalysis() &&
"Unknown remark type");
620 bool ShouldAlwaysPrint =
false;
621 if (
auto *ORA = dyn_cast<llvm::OptimizationRemarkAnalysis>(&D))
622 ShouldAlwaysPrint = ORA->shouldAlwaysPrint();
624 if (ShouldAlwaysPrint ||
628 D, diag::remark_fe_backend_optimization_remark_analysis);
633 const llvm::OptimizationRemarkAnalysisFPCommute &D) {
638 if (D.shouldAlwaysPrint() ||
642 D, diag::remark_fe_backend_optimization_remark_analysis_fpcommute);
646 const llvm::OptimizationRemarkAnalysisAliasing &D) {
651 if (D.shouldAlwaysPrint() ||
655 D, diag::remark_fe_backend_optimization_remark_analysis_aliasing);
659 const llvm::DiagnosticInfoOptimizationFailure &D) {
666 unsigned DiagID = diag::err_fe_inline_asm;
667 llvm::DiagnosticSeverity
Severity = DI.getSeverity();
669 switch (DI.getKind()) {
670 case llvm::DK_InlineAsm:
675 case llvm::DK_StackSize:
681 assert(CurLinkModule);
683 if (Severity != DS_Error)
685 DiagID = diag::err_fe_cannot_link_module;
687 case llvm::DK_OptimizationRemark:
692 case llvm::DK_OptimizationRemarkMissed:
697 case llvm::DK_OptimizationRemarkAnalysis:
702 case llvm::DK_OptimizationRemarkAnalysisFPCommute:
707 case llvm::DK_OptimizationRemarkAnalysisAliasing:
712 case llvm::DK_MachineOptimizationRemark:
717 case llvm::DK_MachineOptimizationRemarkMissed:
722 case llvm::DK_MachineOptimizationRemarkAnalysis:
727 case llvm::DK_OptimizationFailure:
732 case llvm::DK_Unsupported:
740 std::string MsgStorage;
742 raw_string_ostream Stream(MsgStorage);
743 DiagnosticPrinterRawOStream DP(Stream);
747 if (DiagID == diag::err_fe_cannot_link_module) {
748 Diags.
Report(diag::err_fe_cannot_link_module)
749 << CurLinkModule->getModuleIdentifier() << MsgStorage;
760 : Act(_Act), VMContext(_VMContext ? _VMContext : new LLVMContext),
761 OwnsVMContext(!_VMContext) {}
781 return std::move(TheModule);
785 OwnsVMContext =
false;
789 static std::unique_ptr<raw_pwrite_stream>
806 llvm_unreachable(
"Invalid action!");
809 std::unique_ptr<ASTConsumer>
812 std::unique_ptr<raw_pwrite_stream> OS =
GetOutputStream(CI, InFile, BA);
817 if (LinkModules.empty())
823 << F.Filename << BCBuf.getError().message();
829 getOwningLazyBitcodeModule(std::move(*BCBuf), *VMContext);
831 handleAllErrors(ModuleOrErr.takeError(), [&](ErrorInfoBase &EIB) {
833 << F.Filename << EIB.message();
838 LinkModules.push_back({std::move(ModuleOrErr.get()), F.PropagateAttrs,
839 F.Internalize, F.LinkFlags});
847 std::unique_ptr<PPCallbacks>(CoverageInfo));
854 std::move(LinkModules), std::move(OS), *VMContext, CoverageInfo));
861 std::unique_ptr<PPCallbacks> Callbacks =
867 return std::move(Result);
872 unsigned LocCookie) {
873 SM.print(
nullptr, llvm::errs());
877 switch (SM.getKind()) {
878 case llvm::SourceMgr::DK_Error:
879 DiagID = diag::err_fe_inline_asm;
881 case llvm::SourceMgr::DK_Warning:
882 DiagID = diag::warn_fe_inline_asm;
884 case llvm::SourceMgr::DK_Note:
885 DiagID = diag::note_fe_inline_asm;
889 Diags->Report(DiagID).AddString(
"cannot compile inline asm");
892 std::unique_ptr<llvm::Module> CodeGenAction::loadModule(MemoryBufferRef MBRef) {
900 VMContext->enableDebugTypeODRUniquing();
902 auto DiagErrors = [&](
Error E) -> std::unique_ptr<llvm::Module> {
905 handleAllErrors(std::move(
E), [&](ErrorInfoBase &EIB) {
913 return DiagErrors(BMOrErr.takeError());
916 BMOrErr->parseModule(*VMContext);
918 return DiagErrors(MOrErr.takeError());
919 return std::move(*MOrErr);
922 llvm::SMDiagnostic Err;
923 if (std::unique_ptr<llvm::Module> M = parseIR(MBRef, Err, *VMContext))
930 if (Err.getLineNo() > 0) {
931 assert(Err.getColumnNo() >= 0);
933 Err.getLineNo(), Err.getColumnNo() + 1);
937 StringRef Msg = Err.getMessage();
938 if (Msg.startswith(
"error: "))
953 std::unique_ptr<raw_pwrite_stream> OS =
961 llvm::MemoryBuffer *MainFile = SM.
getBuffer(FID, &Invalid);
965 TheModule = loadModule(*MainFile);
970 if (TheModule->getTargetTriple() != TargetOpts.
Triple) {
972 diag::warn_fe_override_module)
974 TheModule->setTargetTriple(TargetOpts.
Triple);
978 MainFile->getMemBufferRef());
980 LLVMContext &Ctx = TheModule->getContext();
997 void EmitAssemblyAction::anchor() { }
1001 void EmitBCAction::anchor() { }
1005 void EmitLLVMAction::anchor() { }
1009 void EmitLLVMOnlyAction::anchor() { }
1013 void EmitCodeGenOnlyAction::anchor() { }
1017 void EmitObjAction::anchor() { }
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...
FunctionDecl - 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)
static DeclContext * castToDeclContext(const Decl *)
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.
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.
std::shared_ptr< llvm::Regex > OptimizationRemarkMissedPattern
Regular expression to select optimizations for which we should enable missed optimization remarks...
Decl - This represents one declaration (or definition), e.g.
CompilerInstance & getCompilerInstance() const
bool HandleTopLevelDecl(DeclGroupRef D) override
HandleTopLevelDecl - Handle the specified top-level declaration.
llvm::MemoryBuffer * getBuffer(FileID FID, SourceLocation Loc, bool *Invalid=nullptr) const
Return the buffer for the specified FileID.
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.
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()
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...
PreprocessorOptions - This class is used for passing the various options used in preprocessor initial...
TargetInfo & getTarget() const
Don't emit anything (benchmarking mode)
VarDecl - An instance of this class is created to represent a variable declaration or definition...
SourceManager & getSourceManager() const
Return the current source manager.
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.
InputKind getCurrentFileKind() const
bool StackSizeDiagHandler(const llvm::DiagnosticInfoStackSize &D)
Specialized handler for StackSize diagnostic.
#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)
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...
const TargetInfo & getTargetInfo() const
SourceLocation getLocWithOffset(int Offset) const
Return a source location with the specified offset from this SourceLocation.
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.
static void DiagnosticHandler(const llvm::DiagnosticInfo &DI, void *Context)
static void BitcodeInlineAsmDiagHandler(const llvm::SMDiagnostic &SM, void *Context, unsigned LocCookie)
The primary public interface to the Clang code generator.
HeaderSearchOptions & getHeaderSearchOpts()
SourceLocation translateFileLineCol(const FileEntry *SourceFile, unsigned Line, unsigned Col) const
Get the source location for the given file:line:col triplet.
Preprocessor & getPreprocessor() const
Return the current preprocessor.
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
const FileEntry * getFileEntryForID(FileID FID) const
Returns the FileEntry record for the provided FileID.
EmitLLVMAction(llvm::LLVMContext *_VMContext=nullptr)
~CodeGenAction() override
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...
FileManager & getFileManager() const
unsigned ShowTimers
Show timers for individual actions.
Defines the clang::Preprocessor interface.
std::shared_ptr< llvm::Regex > OptimizationRemarkPattern
Regular expression to select optimizations for which we should enable optimization remarks...
void AddString(StringRef S) const
Emit native object files.
EmitObjAction(llvm::LLVMContext *_VMContext=nullptr)
void OptimizationRemarkHandler(const llvm::DiagnosticInfoOptimizationBase &D)
DiagnosticsEngine & getDiagnostics() const
Get the current diagnostics engine.
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)
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.
bool isValid() const
Return true if this is a valid SourceLocation object.
TagDecl - Represents the declaration of a struct/union/class/enum.
const StringRef getCurrentFile() const
Cached information about one file (either on disk or in the virtual file system). ...
std::unique_ptr< raw_pwrite_stream > createNullOutputFile()
std::shared_ptr< llvm::Regex > OptimizationRemarkAnalysisPattern
Regular expression to select optimizations for which we should enable optimization analyses...
#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.
FileID getMainFileID() const
Returns the FileID of the main source file.
llvm::Module * getModule() const
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)
FileManager & getFileManager() const
Return the current file manager to the caller.
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)
detail::InMemoryDirectory::const_iterator E
void InlineAsmDiagHandler2(const llvm::SMDiagnostic &, SourceLocation LocCookie)
InlineAsmDiagHandler2 - This function is invoked when the backend hits an error parsing inline asm...
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. ...
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()
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.
Defines the clang::TargetInfo interface.
A SourceLocation and its associated SourceManager.
void HandleTranslationUnit(ASTContext &C) override
HandleTranslationUnit - This method is called when the ASTs for entire translation unit have been par...
SourceLocation getLocForStartOfFile(FileID FID) const
Return the source location corresponding to the first byte of the specified file. ...
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.
const llvm::DataLayout & getDataLayout() const
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...