-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;
-
-struct PassRemarksOpt {
- void operator=(const std::string &Val) const {
- // Create a regexp object to match pass names for emitOptimizationRemark.
- if (!Val.empty()) {
- delete OptimizationRemarkPattern;
- OptimizationRemarkPattern = new Regex(Val);
- 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);
-}
-
-