summaryrefslogtreecommitdiffstats
path: root/llvm/lib/IR/LLVMContextImpl.cpp
diff options
context:
space:
mode:
authorDiego Novillo <dnovillo@google.com>2014-04-08 16:42:38 +0000
committerDiego Novillo <dnovillo@google.com>2014-04-08 16:42:38 +0000
commitc6574c1aa3b3e0f1e4ce5732188d61642c1c7d19 (patch)
tree208e5fd0e6717d3cf5d5411b8317c2ed56c9d779 /llvm/lib/IR/LLVMContextImpl.cpp
parenta9298b22976513857f7c8ded491e67c6a95a04c9 (diff)
downloadbcm5719-llvm-c6574c1aa3b3e0f1e4ce5732188d61642c1c7d19.tar.gz
bcm5719-llvm-c6574c1aa3b3e0f1e4ce5732188d61642c1c7d19.zip
Add -pass-remarks flag to 'opt'.
Summary: This adds support in 'opt' to filter pass remarks emitted by optimization passes. A new flag -pass-remarks specifies which passes should emit a diagnostic when LLVMContext::emitOptimizationRemark is invoked. This will allow the front end to simply pass along the regular expression from its own -Rpass flag when launching the backend. Depends on D3227. Reviewers: qcolombet CC: llvm-commits Differential Revision: http://llvm-reviews.chandlerc.com/D3291 llvm-svn: 205775
Diffstat (limited to 'llvm/lib/IR/LLVMContextImpl.cpp')
-rw-r--r--llvm/lib/IR/LLVMContextImpl.cpp55
1 files changed, 55 insertions, 0 deletions
diff --git a/llvm/lib/IR/LLVMContextImpl.cpp b/llvm/lib/IR/LLVMContextImpl.cpp
index ebff9d3a51f..d34f5b48410 100644
--- a/llvm/lib/IR/LLVMContextImpl.cpp
+++ b/llvm/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*.
OpenPOWER on IntegriCloud