Path: blob/main/contrib/llvm-project/clang/lib/CodeGen/BackendConsumer.h
35233 views
//===--- BackendConsumer.h - LLVM BackendConsumer Header File -------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#ifndef LLVM_CLANG_LIB_CODEGEN_BACKENDCONSUMER_H9#define LLVM_CLANG_LIB_CODEGEN_BACKENDCONSUMER_H1011#include "clang/CodeGen/BackendUtil.h"12#include "clang/CodeGen/CodeGenAction.h"1314#include "llvm/IR/DiagnosticInfo.h"15#include "llvm/Support/Timer.h"1617namespace llvm {18class DiagnosticInfoDontCall;19}2021namespace clang {22class ASTContext;23class CodeGenAction;24class CoverageSourceInfo;2526class BackendConsumer : public ASTConsumer {27using LinkModule = CodeGenAction::LinkModule;2829virtual void anchor();30DiagnosticsEngine &Diags;31BackendAction Action;32const HeaderSearchOptions &HeaderSearchOpts;33const CodeGenOptions &CodeGenOpts;34const TargetOptions &TargetOpts;35const LangOptions &LangOpts;36std::unique_ptr<raw_pwrite_stream> AsmOutStream;37ASTContext *Context;38IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS;3940llvm::Timer LLVMIRGeneration;41unsigned LLVMIRGenerationRefCount;4243/// True if we've finished generating IR. This prevents us from generating44/// additional LLVM IR after emitting output in HandleTranslationUnit. This45/// can happen when Clang plugins trigger additional AST deserialization.46bool IRGenFinished = false;4748bool TimerIsEnabled = false;4950std::unique_ptr<CodeGenerator> Gen;5152SmallVector<LinkModule, 4> LinkModules;5354// A map from mangled names to their function's source location, used for55// backend diagnostics as the Clang AST may be unavailable. We actually use56// the mangled name's hash as the key because mangled names can be very57// long and take up lots of space. Using a hash can cause name collision,58// but that is rare and the consequences are pointing to a wrong source59// location which is not severe. This is a vector instead of an actual map60// because we optimize for time building this map rather than time61// retrieving an entry, as backend diagnostics are uncommon.62std::vector<std::pair<llvm::hash_code, FullSourceLoc>>63ManglingFullSourceLocs;646566// This is here so that the diagnostic printer knows the module a diagnostic67// refers to.68llvm::Module *CurLinkModule = nullptr;6970public:71BackendConsumer(BackendAction Action, DiagnosticsEngine &Diags,72IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS,73const HeaderSearchOptions &HeaderSearchOpts,74const PreprocessorOptions &PPOpts,75const CodeGenOptions &CodeGenOpts,76const TargetOptions &TargetOpts, const LangOptions &LangOpts,77const std::string &InFile,78SmallVector<LinkModule, 4> LinkModules,79std::unique_ptr<raw_pwrite_stream> OS, llvm::LLVMContext &C,80CoverageSourceInfo *CoverageInfo = nullptr);8182// This constructor is used in installing an empty BackendConsumer83// to use the clang diagnostic handler for IR input files. It avoids84// initializing the OS field.85BackendConsumer(BackendAction Action, DiagnosticsEngine &Diags,86IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS,87const HeaderSearchOptions &HeaderSearchOpts,88const PreprocessorOptions &PPOpts,89const CodeGenOptions &CodeGenOpts,90const TargetOptions &TargetOpts, const LangOptions &LangOpts,91llvm::Module *Module, SmallVector<LinkModule, 4> LinkModules,92llvm::LLVMContext &C,93CoverageSourceInfo *CoverageInfo = nullptr);9495llvm::Module *getModule() const;96std::unique_ptr<llvm::Module> takeModule();9798CodeGenerator *getCodeGenerator();99100void HandleCXXStaticMemberVarInstantiation(VarDecl *VD) override;101void Initialize(ASTContext &Ctx) override;102bool HandleTopLevelDecl(DeclGroupRef D) override;103void HandleInlineFunctionDefinition(FunctionDecl *D) override;104void HandleInterestingDecl(DeclGroupRef D) override;105void HandleTranslationUnit(ASTContext &C) override;106void HandleTagDeclDefinition(TagDecl *D) override;107void HandleTagDeclRequiredDefinition(const TagDecl *D) override;108void CompleteTentativeDefinition(VarDecl *D) override;109void CompleteExternalDeclaration(DeclaratorDecl *D) override;110void AssignInheritanceModel(CXXRecordDecl *RD) override;111void HandleVTable(CXXRecordDecl *RD) override;112113// Links each entry in LinkModules into our module. Returns true on error.114bool LinkInModules(llvm::Module *M);115116/// Get the best possible source location to represent a diagnostic that117/// may have associated debug info.118const FullSourceLoc getBestLocationFromDebugLoc(119const llvm::DiagnosticInfoWithLocationBase &D,120bool &BadDebugInfo, StringRef &Filename,121unsigned &Line, unsigned &Column) const;122123std::optional<FullSourceLoc> getFunctionSourceLocation(124const llvm::Function &F) const;125126void DiagnosticHandlerImpl(const llvm::DiagnosticInfo &DI);127/// Specialized handler for InlineAsm diagnostic.128/// \return True if the diagnostic has been successfully reported, false129/// otherwise.130bool InlineAsmDiagHandler(const llvm::DiagnosticInfoInlineAsm &D);131/// Specialized handler for diagnostics reported using SMDiagnostic.132void SrcMgrDiagHandler(const llvm::DiagnosticInfoSrcMgr &D);133/// Specialized handler for StackSize diagnostic.134/// \return True if the diagnostic has been successfully reported, false135/// otherwise.136bool StackSizeDiagHandler(const llvm::DiagnosticInfoStackSize &D);137/// Specialized handler for ResourceLimit diagnostic.138/// \return True if the diagnostic has been successfully reported, false139/// otherwise.140bool ResourceLimitDiagHandler(const llvm::DiagnosticInfoResourceLimit &D);141142/// Specialized handler for unsupported backend feature diagnostic.143void UnsupportedDiagHandler(const llvm::DiagnosticInfoUnsupported &D);144/// Specialized handlers for optimization remarks.145/// Note that these handlers only accept remarks and they always handle146/// them.147void EmitOptimizationMessage(const llvm::DiagnosticInfoOptimizationBase &D,148unsigned DiagID);149void150OptimizationRemarkHandler(const llvm::DiagnosticInfoOptimizationBase &D);151void OptimizationRemarkHandler(152const llvm::OptimizationRemarkAnalysisFPCommute &D);153void OptimizationRemarkHandler(154const llvm::OptimizationRemarkAnalysisAliasing &D);155void OptimizationFailureHandler(156const llvm::DiagnosticInfoOptimizationFailure &D);157void DontCallDiagHandler(const llvm::DiagnosticInfoDontCall &D);158/// Specialized handler for misexpect warnings.159/// Note that misexpect remarks are emitted through ORE160void MisExpectDiagHandler(const llvm::DiagnosticInfoMisExpect &D);161};162163} // namespace clang164#endif165166167