summaryrefslogtreecommitdiff
path: root/lib/IR
diff options
context:
space:
mode:
authorDiego Novillo <dnovillo@google.com>2014-05-22 14:19:46 +0000
committerDiego Novillo <dnovillo@google.com>2014-05-22 14:19:46 +0000
commitd16404a0e79a176b7698d9c7bc1ec146ae2f2f1b (patch)
tree0625bc75c6159aa7dc9a60c9fec3c0e609618b38 /lib/IR
parentde70176f5ff5465cb32828ffcd70797c6ccb1f81 (diff)
downloadllvm-d16404a0e79a176b7698d9c7bc1ec146ae2f2f1b.tar.gz
llvm-d16404a0e79a176b7698d9c7bc1ec146ae2f2f1b.tar.bz2
llvm-d16404a0e79a176b7698d9c7bc1ec146ae2f2f1b.tar.xz
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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@209442 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/IR')
-rw-r--r--lib/IR/DiagnosticInfo.cpp50
-rw-r--r--lib/IR/LLVMContext.cpp35
-rw-r--r--lib/IR/LLVMContextImpl.cpp68
-rw-r--r--lib/IR/LLVMContextImpl.h10
4 files changed, 123 insertions, 40 deletions
diff --git a/lib/IR/DiagnosticInfo.cpp b/lib/IR/DiagnosticInfo.cpp
index 3f8100f985..68a69183af 100644
--- a/lib/IR/DiagnosticInfo.cpp
+++ b/lib/IR/DiagnosticInfo.cpp
@@ -12,6 +12,7 @@
// Diagnostics reporting is still done as part of the LLVMContext.
//===----------------------------------------------------------------------===//
+#include "LLVMContextImpl.h"
#include "llvm/ADT/Twine.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DebugInfo.h"
@@ -67,20 +68,20 @@ void DiagnosticInfoSampleProfile::print(DiagnosticPrinter &DP) const {
DP << getMsg();
}
-bool DiagnosticInfoOptimizationRemark::isLocationAvailable() const {
+bool DiagnosticInfoOptimizationRemarkBase::isLocationAvailable() const {
return getFunction().getParent()->getNamedMetadata("llvm.dbg.cu") != nullptr;
}
-void DiagnosticInfoOptimizationRemark::getLocation(StringRef *Filename,
- unsigned *Line,
- unsigned *Column) const {
+void DiagnosticInfoOptimizationRemarkBase::getLocation(StringRef *Filename,
+ unsigned *Line,
+ unsigned *Column) const {
DILocation DIL(getDebugLoc().getAsMDNode(getFunction().getContext()));
*Filename = DIL.getFilename();
*Line = DIL.getLineNumber();
*Column = DIL.getColumnNumber();
}
-const std::string DiagnosticInfoOptimizationRemark::getLocationStr() const {
+const std::string DiagnosticInfoOptimizationRemarkBase::getLocationStr() const {
StringRef Filename("<unknown>");
unsigned Line = 0;
unsigned Column = 0;
@@ -89,6 +90,43 @@ const std::string DiagnosticInfoOptimizationRemark::getLocationStr() const {
return Twine(Filename + ":" + Twine(Line) + ":" + Twine(Column)).str();
}
-void DiagnosticInfoOptimizationRemark::print(DiagnosticPrinter &DP) const {
+void DiagnosticInfoOptimizationRemarkBase::print(DiagnosticPrinter &DP) const {
DP << getLocationStr() << ": " << getMsg();
}
+
+bool
+DiagnosticInfoOptimizationRemark::isEnabled(LLVMContextImpl *pImpl) const {
+ return pImpl->optimizationRemarkEnabledFor(this);
+}
+
+bool DiagnosticInfoOptimizationRemarkMissed::isEnabled(
+ LLVMContextImpl *pImpl) const {
+ return pImpl->optimizationRemarkEnabledFor(this);
+}
+
+bool DiagnosticInfoOptimizationRemarkAnalysis::isEnabled(
+ LLVMContextImpl *pImpl) const {
+ return pImpl->optimizationRemarkEnabledFor(this);
+}
+
+void llvm::emitOptimizationRemark(LLVMContext &Ctx, const char *PassName,
+ const Function &Fn, const DebugLoc &DLoc,
+ const Twine &Msg) {
+ Ctx.diagnose(DiagnosticInfoOptimizationRemark(PassName, Fn, DLoc, Msg));
+}
+
+void llvm::emitOptimizationRemarkMissed(LLVMContext &Ctx, const char *PassName,
+ const Function &Fn,
+ const DebugLoc &DLoc,
+ const Twine &Msg) {
+ Ctx.diagnose(DiagnosticInfoOptimizationRemarkMissed(PassName, Fn, DLoc, Msg));
+}
+
+void llvm::emitOptimizationRemarkAnalysis(LLVMContext &Ctx,
+ const char *PassName,
+ const Function &Fn,
+ const DebugLoc &DLoc,
+ const Twine &Msg) {
+ Ctx.diagnose(
+ DiagnosticInfoOptimizationRemarkAnalysis(PassName, Fn, DLoc, Msg));
+}
diff --git a/lib/IR/LLVMContext.cpp b/lib/IR/LLVMContext.cpp
index 5f94dca1eb..7b75d42b85 100644
--- a/lib/IR/LLVMContext.cpp
+++ b/lib/IR/LLVMContext.cpp
@@ -142,14 +142,26 @@ void LLVMContext::diagnose(const DiagnosticInfo &DI) {
return;
}
- // Optimization remarks are selective. They need to check whether
- // the regexp pattern, passed via -pass-remarks, matches the name
- // of the pass that is emitting the diagnostic. If there is no match,
- // ignore the diagnostic and return.
- if (DI.getKind() == llvm::DK_OptimizationRemark &&
- !pImpl->optimizationRemarksEnabledFor(
- cast<DiagnosticInfoOptimizationRemark>(DI).getPassName()))
- return;
+ // Optimization remarks are selective. They need to check whether the regexp
+ // pattern, passed via one of the -pass-remarks* flags, matches the name of
+ // the pass that is emitting the diagnostic. If there is no match, ignore the
+ // diagnostic and return.
+ switch (DI.getKind()) {
+ case llvm::DK_OptimizationRemark:
+ if (!cast<DiagnosticInfoOptimizationRemark>(DI).isEnabled(pImpl))
+ return;
+ break;
+ case llvm::DK_OptimizationRemarkMissed:
+ if (!cast<DiagnosticInfoOptimizationRemarkMissed>(DI).isEnabled(pImpl))
+ return;
+ break;
+ case llvm::DK_OptimizationRemarkAnalysis:
+ if (!cast<DiagnosticInfoOptimizationRemarkAnalysis>(DI).isEnabled(pImpl))
+ return;
+ break;
+ default:
+ break;
+ }
// Otherwise, print the message with a prefix based on the severity.
std::string MsgStorage;
@@ -177,13 +189,6 @@ void LLVMContext::emitError(unsigned LocCookie, const Twine &ErrorStr) {
diagnose(DiagnosticInfoInlineAsm(LocCookie, ErrorStr));
}
-void LLVMContext::emitOptimizationRemark(const char *PassName,
- const Function &Fn,
- const DebugLoc &DLoc,
- const Twine &Msg) {
- diagnose(DiagnosticInfoOptimizationRemark(PassName, Fn, DLoc, Msg));
-}
-
//===----------------------------------------------------------------------===//
// Metadata Kind Uniquing
//===----------------------------------------------------------------------===//
diff --git a/lib/IR/LLVMContextImpl.cpp b/lib/IR/LLVMContextImpl.cpp
index 2042374647..24d325246d 100644
--- a/lib/IR/LLVMContextImpl.cpp
+++ b/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();
}
};
diff --git a/lib/IR/LLVMContextImpl.h b/lib/IR/LLVMContextImpl.h
index b1ad9ff4a5..6ad9b8a70a 100644
--- a/lib/IR/LLVMContextImpl.h
+++ b/lib/IR/LLVMContextImpl.h
@@ -37,6 +37,9 @@ namespace llvm {
class ConstantInt;
class ConstantFP;
+class DiagnosticInfoOptimizationRemark;
+class DiagnosticInfoOptimizationRemarkMissed;
+class DiagnosticInfoOptimizationRemarkAnalysis;
class LLVMContext;
class Type;
class Value;
@@ -373,7 +376,12 @@ public:
/// \brief Return true if the given pass name should emit optimization
/// remarks.
- bool optimizationRemarksEnabledFor(const char *PassName) const;
+ 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);