diff options
author | Diego Novillo <dnovillo@google.com> | 2014-05-22 14:19:46 +0000 |
---|---|---|
committer | Diego Novillo <dnovillo@google.com> | 2014-05-22 14:19:46 +0000 |
commit | 7f8af8bf91ac2d33eceac932e3f5282ab2db25ba (patch) | |
tree | b06d9fa0fdd5966834b5095d553f2c184128e61c /llvm/lib/IR/LLVMContextImpl.cpp | |
parent | 8ff177ede3a1647b71a7db11e273f3dd81ef0ccb (diff) | |
download | bcm5719-llvm-7f8af8bf91ac2d33eceac932e3f5282ab2db25ba.tar.gz bcm5719-llvm-7f8af8bf91ac2d33eceac932e3f5282ab2db25ba.zip |
Add support for missed and analysis optimization remarks.
Summary:
This adds two new diagnostics: -pass-remarks-missed and
-pass-remarks-analysis. They take the same values as -pass-remarks but
are intended to be triggered in different contexts.
-pass-remarks-missed is used by LLVMContext::emitOptimizationRemarkMissed,
which passes call when they tried to apply a transformation but
couldn't.
-pass-remarks-analysis is used by LLVMContext::emitOptimizationRemarkAnalysis,
which passes call when they want to inform the user about analysis
results.
The patch also:
1- Adds support in the inliner for the two new remarks and a
test case.
2- Moves emitOptimizationRemark* functions to the llvm namespace.
3- Adds an LLVMContext argument instead of making them member functions
of LLVMContext.
Reviewers: qcolombet
Subscribers: llvm-commits
Differential Revision: http://reviews.llvm.org/D3682
llvm-svn: 209442
Diffstat (limited to 'llvm/lib/IR/LLVMContextImpl.cpp')
-rw-r--r-- | llvm/lib/IR/LLVMContextImpl.cpp | 68 |
1 files changed, 50 insertions, 18 deletions
diff --git a/llvm/lib/IR/LLVMContextImpl.cpp b/llvm/lib/IR/LLVMContextImpl.cpp index 2042374647d..24d325246d2 100644 --- a/llvm/lib/IR/LLVMContextImpl.cpp +++ b/llvm/lib/IR/LLVMContextImpl.cpp @@ -14,6 +14,7 @@ #include "LLVMContextImpl.h" #include "llvm/ADT/STLExtras.h" #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" @@ -48,20 +49,20 @@ LLVMContextImpl::LLVMContextImpl(LLVMContext &C) namespace { -/// \brief Regular expression corresponding to the value given in the -/// command line flag -pass-remarks. Passes whose name matches this -/// regexp will emit a diagnostic when calling -/// LLVMContext::emitOptimizationRemark. -static Regex *OptimizationRemarkPattern = nullptr; - +/// \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 { - void operator=(const std::string &Val) const { + std::shared_ptr<Regex> Pattern; + + void operator=(const std::string &Val) { // Create a regexp object to match pass names for emitOptimizationRemark. if (!Val.empty()) { - delete OptimizationRemarkPattern; - OptimizationRemarkPattern = new Regex(Val); + Pattern = std::make_shared<Regex>(Val); std::string RegexError; - if (!OptimizationRemarkPattern->isValid(RegexError)) + if (!Pattern->isValid(RegexError)) report_fatal_error("Invalid regular expression '" + Val + "' in -pass-remarks: " + RegexError, false); @@ -70,31 +71,62 @@ struct PassRemarksOpt { }; static PassRemarksOpt PassRemarksOptLoc; +static PassRemarksOpt PassRemarksMissedOptLoc; +static PassRemarksOpt PassRemarksAnalysisOptLoc; // -pass-remarks -// Command line flag to enable LLVMContext::emitOptimizationRemark() -// and LLVMContext::emitOptimizationNote() calls. +// Command line flag to enable emitOptimizationRemark() static cl::opt<PassRemarksOpt, true, cl::parser<std::string>> 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<PassRemarksOpt, true, cl::parser<std::string>> 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<PassRemarksOpt, true, cl::parser<std::string>> +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::optimizationRemarksEnabledFor(const char *PassName) const { - return OptimizationRemarkPattern && - OptimizationRemarkPattern->match(PassName); +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' // is a Constant*. - template<typename PairT> - void operator()(const PairT &P) { + template <typename PairT> void operator()(const PairT &P) { P.second->dropAllReferences(); } }; |