Skip to content

Commit

Permalink
Remove LLVMContextImpl::optimizationRemarkEnabledFor.
Browse files Browse the repository at this point in the history
Summary:
This patch moves the handling of -pass-remarks* over to
lib/DiagnosticInfo.cpp. This allows the removal of the
optimizationRemarkEnabledFor functions from LLVMContextImpl, as they're
not needed anymore.

Reviewers: qcolombet

Subscribers: llvm-commits

Differential Revision: http://reviews.llvm.org/D3878

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@209453 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
dnovillo committed May 22, 2014
1 parent 3957d42 commit c647710
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 105 deletions.
11 changes: 4 additions & 7 deletions include/llvm/IR/DiagnosticInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -271,10 +271,7 @@ class DiagnosticInfoOptimizationRemarkBase : public DiagnosticInfo {
/// or -pass-remarks-analysis). Note that this only handles the LLVM
/// flags. We cannot access Clang flags from here (they are handled
/// in BackendConsumer::OptimizationRemarkHandler).
///
/// \p pImpl points to the current LLVM context. It is needed to query the
/// value of the command line flag associated with this remark.
virtual bool isEnabled(LLVMContextImpl *pImpl) const = 0;
virtual bool isEnabled() const = 0;

/// Return true if location information is available for this diagnostic.
bool isLocationAvailable() const;
Expand Down Expand Up @@ -332,7 +329,7 @@ class DiagnosticInfoOptimizationRemark
}

/// \see DiagnosticInfoOptimizationRemarkBase::isEnabled.
virtual bool isEnabled(LLVMContextImpl *pImpl) const override;
virtual bool isEnabled() const override;
};

/// Diagnostic information for missed-optimization remarks.
Expand All @@ -359,7 +356,7 @@ class DiagnosticInfoOptimizationRemarkMissed
}

/// \see DiagnosticInfoOptimizationRemarkBase::isEnabled.
virtual bool isEnabled(LLVMContextImpl *pImpl) const override;
virtual bool isEnabled() const override;
};

/// Diagnostic information for optimization analysis remarks.
Expand Down Expand Up @@ -387,7 +384,7 @@ class DiagnosticInfoOptimizationRemarkAnalysis
}

/// \see DiagnosticInfoOptimizationRemarkBase::isEnabled.
virtual bool isEnabled(LLVMContextImpl *pImpl) const override;
virtual bool isEnabled() const override;
};

// Create wrappers for C Binding types (see CBindingWrapping.h).
Expand Down
77 changes: 68 additions & 9 deletions lib/IR/DiagnosticInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,69 @@
#include "llvm/IR/Metadata.h"
#include "llvm/IR/Module.h"
#include "llvm/Support/Atomic.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Regex.h"
#include <string>

using namespace llvm;

namespace {

/// \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 {
std::shared_ptr<Regex> Pattern;

void operator=(const std::string &Val) {
// Create a regexp object to match pass names for emitOptimizationRemark.
if (!Val.empty()) {
Pattern = std::make_shared<Regex>(Val);
std::string RegexError;
if (!Pattern->isValid(RegexError))
report_fatal_error("Invalid regular expression '" + Val +
"' in -pass-remarks: " + RegexError,
false);
}
};
};

static PassRemarksOpt PassRemarksOptLoc;
static PassRemarksOpt PassRemarksMissedOptLoc;
static PassRemarksOpt PassRemarksAnalysisOptLoc;

// -pass-remarks
// 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);
}

int llvm::getNextAvailablePluginDiagnosticKind() {
static sys::cas_flag PluginKindID = DK_FirstPluginKind;
return (int)sys::AtomicIncrement(&PluginKindID);
Expand Down Expand Up @@ -94,19 +153,19 @@ void DiagnosticInfoOptimizationRemarkBase::print(DiagnosticPrinter &DP) const {
DP << getLocationStr() << ": " << getMsg();
}

bool
DiagnosticInfoOptimizationRemark::isEnabled(LLVMContextImpl *pImpl) const {
return pImpl->optimizationRemarkEnabledFor(this);
bool DiagnosticInfoOptimizationRemark::isEnabled() const {
return PassRemarksOptLoc.Pattern &&
PassRemarksOptLoc.Pattern->match(getPassName());
}

bool DiagnosticInfoOptimizationRemarkMissed::isEnabled(
LLVMContextImpl *pImpl) const {
return pImpl->optimizationRemarkEnabledFor(this);
bool DiagnosticInfoOptimizationRemarkMissed::isEnabled() const {
return PassRemarksMissedOptLoc.Pattern &&
PassRemarksMissedOptLoc.Pattern->match(getPassName());
}

bool DiagnosticInfoOptimizationRemarkAnalysis::isEnabled(
LLVMContextImpl *pImpl) const {
return pImpl->optimizationRemarkEnabledFor(this);
bool DiagnosticInfoOptimizationRemarkAnalysis::isEnabled() const {
return PassRemarksAnalysisOptLoc.Pattern &&
PassRemarksAnalysisOptLoc.Pattern->match(getPassName());
}

void llvm::emitOptimizationRemark(LLVMContext &Ctx, const char *PassName,
Expand Down
6 changes: 3 additions & 3 deletions lib/IR/LLVMContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,15 @@ void LLVMContext::diagnose(const DiagnosticInfo &DI) {
// diagnostic and return.
switch (DI.getKind()) {
case llvm::DK_OptimizationRemark:
if (!cast<DiagnosticInfoOptimizationRemark>(DI).isEnabled(pImpl))
if (!cast<DiagnosticInfoOptimizationRemark>(DI).isEnabled())
return;
break;
case llvm::DK_OptimizationRemarkMissed:
if (!cast<DiagnosticInfoOptimizationRemarkMissed>(DI).isEnabled(pImpl))
if (!cast<DiagnosticInfoOptimizationRemarkMissed>(DI).isEnabled())
return;
break;
case llvm::DK_OptimizationRemarkAnalysis:
if (!cast<DiagnosticInfoOptimizationRemarkAnalysis>(DI).isEnabled(pImpl))
if (!cast<DiagnosticInfoOptimizationRemarkAnalysis>(DI).isEnabled())
return;
break;
default:
Expand Down
77 changes: 0 additions & 77 deletions lib/IR/LLVMContextImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
#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"
#include <algorithm>
using namespace llvm;

Expand Down Expand Up @@ -47,81 +45,6 @@ LLVMContextImpl::LLVMContextImpl(LLVMContext &C)
NamedStructTypesUniqueID = 0;
}

namespace {

/// \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 {
std::shared_ptr<Regex> Pattern;

void operator=(const std::string &Val) {
// Create a regexp object to match pass names for emitOptimizationRemark.
if (!Val.empty()) {
Pattern = std::make_shared<Regex>(Val);
std::string RegexError;
if (!Pattern->isValid(RegexError))
report_fatal_error("Invalid regular expression '" + Val +
"' in -pass-remarks: " + RegexError,
false);
}
};
};

static PassRemarksOpt PassRemarksOptLoc;
static PassRemarksOpt PassRemarksMissedOptLoc;
static PassRemarksOpt PassRemarksAnalysisOptLoc;

// -pass-remarks
// 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::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'
Expand Down
9 changes: 0 additions & 9 deletions lib/IR/LLVMContextImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -374,15 +374,6 @@ class LLVMContextImpl {
typedef DenseMap<const Function *, ReturnInst *> PrefixDataMapTy;
PrefixDataMapTy PrefixDataMap;

/// \brief Return true if the given pass name should emit optimization
/// remarks.
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);

Expand Down

0 comments on commit c647710

Please sign in to comment.