diff --git a/include/llvm/IR/DiagnosticInfo.h b/include/llvm/IR/DiagnosticInfo.h index 8e334c996d9..e78a42b9977 100644 --- a/include/llvm/IR/DiagnosticInfo.h +++ b/include/llvm/IR/DiagnosticInfo.h @@ -271,10 +271,7 @@ public: /// or -pass-remarks-analysis). Note that this only handles the LLVM /// flags. We cannot access Clang flags from here (they are handled /// in BackendConsumer::OptimizationRemarkHandler). - /// - /// \p pImpl points to the current LLVM context. It is needed to query the - /// value of the command line flag associated with this remark. - virtual bool isEnabled(LLVMContextImpl *pImpl) const = 0; + virtual bool isEnabled() const = 0; /// Return true if location information is available for this diagnostic. bool isLocationAvailable() const; @@ -332,7 +329,7 @@ public: } /// \see DiagnosticInfoOptimizationRemarkBase::isEnabled. - virtual bool isEnabled(LLVMContextImpl *pImpl) const override; + virtual bool isEnabled() const override; }; /// Diagnostic information for missed-optimization remarks. @@ -359,7 +356,7 @@ public: } /// \see DiagnosticInfoOptimizationRemarkBase::isEnabled. - virtual bool isEnabled(LLVMContextImpl *pImpl) const override; + virtual bool isEnabled() const override; }; /// Diagnostic information for optimization analysis remarks. @@ -387,7 +384,7 @@ public: } /// \see DiagnosticInfoOptimizationRemarkBase::isEnabled. - virtual bool isEnabled(LLVMContextImpl *pImpl) const override; + virtual bool isEnabled() const override; }; // Create wrappers for C Binding types (see CBindingWrapping.h). diff --git a/lib/IR/DiagnosticInfo.cpp b/lib/IR/DiagnosticInfo.cpp index 68a69183aff..6eeb16220ea 100644 --- a/lib/IR/DiagnosticInfo.cpp +++ b/lib/IR/DiagnosticInfo.cpp @@ -23,10 +23,69 @@ #include "llvm/IR/Metadata.h" #include "llvm/IR/Module.h" #include "llvm/Support/Atomic.h" +#include "llvm/Support/CommandLine.h" +#include "llvm/Support/Regex.h" #include using namespace llvm; +namespace { + +/// \brief Regular expression corresponding to the value given in one of the +/// -pass-remarks* command line flags. Passes whose name matches this regexp +/// will emit a diagnostic when calling the associated diagnostic function +/// (emitOptimizationRemark, emitOptimizationRemarkMissed or +/// emitOptimizationRemarkAnalysis). +struct PassRemarksOpt { + std::shared_ptr Pattern; + + void operator=(const std::string &Val) { + // Create a regexp object to match pass names for emitOptimizationRemark. + if (!Val.empty()) { + Pattern = std::make_shared(Val); + std::string RegexError; + if (!Pattern->isValid(RegexError)) + report_fatal_error("Invalid regular expression '" + Val + + "' in -pass-remarks: " + RegexError, + false); + } + }; +}; + +static PassRemarksOpt PassRemarksOptLoc; +static PassRemarksOpt PassRemarksMissedOptLoc; +static PassRemarksOpt PassRemarksAnalysisOptLoc; + +// -pass-remarks +// Command line flag to enable emitOptimizationRemark() +static cl::opt> +PassRemarks("pass-remarks", cl::value_desc("pattern"), + cl::desc("Enable optimization remarks from passes whose name match " + "the given regular expression"), + cl::Hidden, cl::location(PassRemarksOptLoc), cl::ValueRequired, + cl::ZeroOrMore); + +// -pass-remarks-missed +// Command line flag to enable emitOptimizationRemarkMissed() +static cl::opt> PassRemarksMissed( + "pass-remarks-missed", cl::value_desc("pattern"), + cl::desc("Enable missed optimization remarks from passes whose name match " + "the given regular expression"), + cl::Hidden, cl::location(PassRemarksMissedOptLoc), cl::ValueRequired, + cl::ZeroOrMore); + +// -pass-remarks-analysis +// Command line flag to enable emitOptimizationRemarkAnalysis() +static cl::opt> +PassRemarksAnalysis( + "pass-remarks-analysis", cl::value_desc("pattern"), + cl::desc( + "Enable optimization analysis remarks from passes whose name match " + "the given regular expression"), + cl::Hidden, cl::location(PassRemarksAnalysisOptLoc), cl::ValueRequired, + cl::ZeroOrMore); +} + int llvm::getNextAvailablePluginDiagnosticKind() { static sys::cas_flag PluginKindID = DK_FirstPluginKind; return (int)sys::AtomicIncrement(&PluginKindID); @@ -94,19 +153,19 @@ void DiagnosticInfoOptimizationRemarkBase::print(DiagnosticPrinter &DP) const { DP << getLocationStr() << ": " << getMsg(); } -bool -DiagnosticInfoOptimizationRemark::isEnabled(LLVMContextImpl *pImpl) const { - return pImpl->optimizationRemarkEnabledFor(this); +bool DiagnosticInfoOptimizationRemark::isEnabled() const { + return PassRemarksOptLoc.Pattern && + PassRemarksOptLoc.Pattern->match(getPassName()); } -bool DiagnosticInfoOptimizationRemarkMissed::isEnabled( - LLVMContextImpl *pImpl) const { - return pImpl->optimizationRemarkEnabledFor(this); +bool DiagnosticInfoOptimizationRemarkMissed::isEnabled() const { + return PassRemarksMissedOptLoc.Pattern && + PassRemarksMissedOptLoc.Pattern->match(getPassName()); } -bool DiagnosticInfoOptimizationRemarkAnalysis::isEnabled( - LLVMContextImpl *pImpl) const { - return pImpl->optimizationRemarkEnabledFor(this); +bool DiagnosticInfoOptimizationRemarkAnalysis::isEnabled() const { + return PassRemarksAnalysisOptLoc.Pattern && + PassRemarksAnalysisOptLoc.Pattern->match(getPassName()); } void llvm::emitOptimizationRemark(LLVMContext &Ctx, const char *PassName, diff --git a/lib/IR/LLVMContext.cpp b/lib/IR/LLVMContext.cpp index 7b75d42b85e..de825f00b20 100644 --- a/lib/IR/LLVMContext.cpp +++ b/lib/IR/LLVMContext.cpp @@ -148,15 +148,15 @@ void LLVMContext::diagnose(const DiagnosticInfo &DI) { // diagnostic and return. switch (DI.getKind()) { case llvm::DK_OptimizationRemark: - if (!cast(DI).isEnabled(pImpl)) + if (!cast(DI).isEnabled()) return; break; case llvm::DK_OptimizationRemarkMissed: - if (!cast(DI).isEnabled(pImpl)) + if (!cast(DI).isEnabled()) return; break; case llvm::DK_OptimizationRemarkAnalysis: - if (!cast(DI).isEnabled(pImpl)) + if (!cast(DI).isEnabled()) return; break; default: diff --git a/lib/IR/LLVMContextImpl.cpp b/lib/IR/LLVMContextImpl.cpp index 24d325246d2..4c2791f0a8d 100644 --- a/lib/IR/LLVMContextImpl.cpp +++ b/lib/IR/LLVMContextImpl.cpp @@ -16,8 +16,6 @@ #include "llvm/IR/Attributes.h" #include "llvm/IR/DiagnosticInfo.h" #include "llvm/IR/Module.h" -#include "llvm/Support/CommandLine.h" -#include "llvm/Support/Regex.h" #include using namespace llvm; @@ -47,81 +45,6 @@ LLVMContextImpl::LLVMContextImpl(LLVMContext &C) NamedStructTypesUniqueID = 0; } -namespace { - -/// \brief Regular expression corresponding to the value given in one of the -/// -pass-remarks* command line flags. Passes whose name matches this regexp -/// will emit a diagnostic when calling the associated diagnostic function -/// (emitOptimizationRemark, emitOptimizationRemarkMissed or -/// emitOptimizationRemarkAnalysis). -struct PassRemarksOpt { - std::shared_ptr Pattern; - - void operator=(const std::string &Val) { - // Create a regexp object to match pass names for emitOptimizationRemark. - if (!Val.empty()) { - Pattern = std::make_shared(Val); - std::string RegexError; - if (!Pattern->isValid(RegexError)) - report_fatal_error("Invalid regular expression '" + Val + - "' in -pass-remarks: " + RegexError, - false); - } - }; -}; - -static PassRemarksOpt PassRemarksOptLoc; -static PassRemarksOpt PassRemarksMissedOptLoc; -static PassRemarksOpt PassRemarksAnalysisOptLoc; - -// -pass-remarks -// Command line flag to enable emitOptimizationRemark() -static cl::opt> -PassRemarks("pass-remarks", cl::value_desc("pattern"), - cl::desc("Enable optimization remarks from passes whose name match " - "the given regular expression"), - cl::Hidden, cl::location(PassRemarksOptLoc), cl::ValueRequired, - cl::ZeroOrMore); - -// -pass-remarks-missed -// Command line flag to enable emitOptimizationRemarkMissed() -static cl::opt> PassRemarksMissed( - "pass-remarks-missed", cl::value_desc("pattern"), - cl::desc("Enable missed optimization remarks from passes whose name match " - "the given regular expression"), - cl::Hidden, cl::location(PassRemarksMissedOptLoc), cl::ValueRequired, - cl::ZeroOrMore); - -// -pass-remarks-analysis -// Command line flag to enable emitOptimizationRemarkAnalysis() -static cl::opt> -PassRemarksAnalysis( - "pass-remarks-analysis", cl::value_desc("pattern"), - cl::desc( - "Enable optimization analysis remarks from passes whose name match " - "the given regular expression"), - cl::Hidden, cl::location(PassRemarksAnalysisOptLoc), cl::ValueRequired, - cl::ZeroOrMore); -} - -bool LLVMContextImpl::optimizationRemarkEnabledFor( - const DiagnosticInfoOptimizationRemark *DI) const { - return PassRemarksOptLoc.Pattern && - PassRemarksOptLoc.Pattern->match(DI->getPassName()); -} - -bool LLVMContextImpl::optimizationRemarkEnabledFor( - const DiagnosticInfoOptimizationRemarkMissed *DI) const { - return PassRemarksMissedOptLoc.Pattern && - PassRemarksMissedOptLoc.Pattern->match(DI->getPassName()); -} - -bool LLVMContextImpl::optimizationRemarkEnabledFor( - const DiagnosticInfoOptimizationRemarkAnalysis *DI) const { - return PassRemarksAnalysisOptLoc.Pattern && - PassRemarksAnalysisOptLoc.Pattern->match(DI->getPassName()); -} - namespace { struct DropReferences { // Takes the value_type of a ConstantUniqueMap's internal map, whose 'second' diff --git a/lib/IR/LLVMContextImpl.h b/lib/IR/LLVMContextImpl.h index 6ad9b8a70af..808c239bff5 100644 --- a/lib/IR/LLVMContextImpl.h +++ b/lib/IR/LLVMContextImpl.h @@ -374,15 +374,6 @@ public: typedef DenseMap PrefixDataMapTy; PrefixDataMapTy PrefixDataMap; - /// \brief Return true if the given pass name should emit optimization - /// remarks. - bool optimizationRemarkEnabledFor( - const DiagnosticInfoOptimizationRemark *DI) const; - bool optimizationRemarkEnabledFor( - const DiagnosticInfoOptimizationRemarkMissed *DI) const; - bool optimizationRemarkEnabledFor( - const DiagnosticInfoOptimizationRemarkAnalysis *DI) const; - int getOrAddScopeRecordIdxEntry(MDNode *N, int ExistingIdx); int getOrAddScopeInlinedAtIdxEntry(MDNode *Scope, MDNode *IA,int ExistingIdx);