summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/IR/LLVMContext.cpp3
-rw-r--r--lib/IR/LLVMContextImpl.cpp55
-rw-r--r--lib/IR/LLVMContextImpl.h4
3 files changed, 61 insertions, 1 deletions
diff --git a/lib/IR/LLVMContext.cpp b/lib/IR/LLVMContext.cpp
index 3f05561a2c..0c922005b7 100644
--- a/lib/IR/LLVMContext.cpp
+++ b/lib/IR/LLVMContext.cpp
@@ -160,7 +160,8 @@ void LLVMContext::emitOptimizationRemark(const char *PassName,
const Function &Fn,
const DebugLoc &DLoc,
const Twine &Msg) {
- diagnose(DiagnosticInfoOptimizationRemark(PassName, Fn, DLoc, Msg));
+ if (pImpl->optimizationRemarksEnabledFor(PassName))
+ diagnose(DiagnosticInfoOptimizationRemark(PassName, Fn, DLoc, Msg));
}
//===----------------------------------------------------------------------===//
diff --git a/lib/IR/LLVMContextImpl.cpp b/lib/IR/LLVMContextImpl.cpp
index ebff9d3a51..d34f5b4841 100644
--- a/lib/IR/LLVMContextImpl.cpp
+++ b/lib/IR/LLVMContextImpl.cpp
@@ -15,6 +15,8 @@
#include "llvm/ADT/STLExtras.h"
#include "llvm/IR/Attributes.h"
#include "llvm/IR/Module.h"
+#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/Regex.h"
#include <algorithm>
using namespace llvm;
@@ -43,6 +45,59 @@ 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 = 0;
+
+/// \brief String to hold all the values passed via -pass-remarks. Every
+/// instance of -pass-remarks on the command line will be concatenated
+/// to this string. Values are stored inside braces and concatenated with
+/// the '|' operator. This implements the expected semantics that multiple
+/// -pass-remarks are additive.
+static std::string OptimizationRemarkExpr;
+
+struct PassRemarksOpt {
+ void operator=(const std::string &Val) const {
+ // Create a regexp object to match pass names for emitOptimizationRemark.
+ if (!Val.empty()) {
+ if (!OptimizationRemarkExpr.empty())
+ OptimizationRemarkExpr += "|";
+ OptimizationRemarkExpr += "(" + Val + ")";
+ delete OptimizationRemarkPattern;
+ OptimizationRemarkPattern = new Regex(OptimizationRemarkExpr);
+ std::string RegexError;
+ if (!OptimizationRemarkPattern->isValid(RegexError))
+ report_fatal_error("Invalid regular expression '" + Val +
+ "' in -pass-remarks: " + RegexError,
+ false);
+ }
+ };
+};
+
+static PassRemarksOpt PassRemarksOptLoc;
+
+// -pass-remarks
+// Command line flag to enable LLVMContext::emitOptimizationRemark()
+// and LLVMContext::emitOptimizationNote() calls.
+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);
+}
+
+bool
+LLVMContextImpl::optimizationRemarksEnabledFor(const char *PassName) const {
+ return OptimizationRemarkPattern &&
+ OptimizationRemarkPattern->match(PassName);
+}
+
+
+namespace {
struct DropReferences {
// Takes the value_type of a ConstantUniqueMap's internal map, whose 'second'
// is a Constant*.
diff --git a/lib/IR/LLVMContextImpl.h b/lib/IR/LLVMContextImpl.h
index dc77d291f4..48b3511367 100644
--- a/lib/IR/LLVMContextImpl.h
+++ b/lib/IR/LLVMContextImpl.h
@@ -368,6 +368,10 @@ public:
typedef DenseMap<const Function *, ReturnInst *> PrefixDataMapTy;
PrefixDataMapTy PrefixDataMap;
+ /// \brief Return true if the given pass name should emit optimization
+ /// remarks.
+ bool optimizationRemarksEnabledFor(const char *PassName) const;
+
int getOrAddScopeRecordIdxEntry(MDNode *N, int ExistingIdx);
int getOrAddScopeInlinedAtIdxEntry(MDNode *Scope, MDNode *IA,int ExistingIdx);