Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions llvm/include/llvm/Analysis/OptimizationRemarkEmitter.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ class OptimizationRemarkEmitter {
/// Output the remark via the diagnostic handler and to the
/// optimization record file.
void emit(DiagnosticInfoOptimizationBase &OptDiag);
/// Also allow r-value for OptDiag to allow emitting a temporarily-constructed
/// diagnostic.
void emit(DiagnosticInfoOptimizationBase &&OptDiag) { emit(OptDiag); }

/// Take a lambda that returns a remark which will be emitted. Second
/// argument is only used to restrict this to functions.
Expand Down
78 changes: 22 additions & 56 deletions llvm/include/llvm/IR/DiagnosticInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <iterator>
#include <optional>
#include <string>
#include <utility>

namespace llvm {

Expand Down Expand Up @@ -612,82 +613,47 @@ class DiagnosticInfoOptimizationBase : public DiagnosticInfoWithLocationBase {
/// common base class. This allows returning the result of the insertion
/// directly by value, e.g. return OptimizationRemarkAnalysis(...) << "blah".
template <class RemarkT>
RemarkT &
operator<<(RemarkT &R,
std::enable_if_t<
std::is_base_of<DiagnosticInfoOptimizationBase, RemarkT>::value,
StringRef>
S) {
R.insert(S);
return R;
}

/// Also allow r-value for the remark to allow insertion into a
/// temporarily-constructed remark.
template <class RemarkT>
RemarkT &
decltype(auto)
operator<<(RemarkT &&R,
std::enable_if_t<
std::is_base_of<DiagnosticInfoOptimizationBase, RemarkT>::value,
StringRef>
std::enable_if_t<std::is_base_of_v<DiagnosticInfoOptimizationBase,
std::remove_reference_t<RemarkT>>,
StringRef>
S) {
R.insert(S);
return R;
}

template <class RemarkT>
RemarkT &
operator<<(RemarkT &R,
std::enable_if_t<
std::is_base_of<DiagnosticInfoOptimizationBase, RemarkT>::value,
DiagnosticInfoOptimizationBase::Argument>
A) {
R.insert(A);
return R;
return std::forward<RemarkT>(R);
}

template <class RemarkT>
RemarkT &
decltype(auto)
operator<<(RemarkT &&R,
std::enable_if_t<
std::is_base_of<DiagnosticInfoOptimizationBase, RemarkT>::value,
DiagnosticInfoOptimizationBase::Argument>
std::enable_if_t<std::is_base_of_v<DiagnosticInfoOptimizationBase,
std::remove_reference_t<RemarkT>>,
DiagnosticInfoOptimizationBase::Argument>
A) {
R.insert(A);
return R;
}

template <class RemarkT>
RemarkT &
operator<<(RemarkT &R,
std::enable_if_t<
std::is_base_of<DiagnosticInfoOptimizationBase, RemarkT>::value,
DiagnosticInfoOptimizationBase::setIsVerbose>
V) {
R.insert(V);
return R;
return std::forward<RemarkT>(R);
}

template <class RemarkT>
RemarkT &
decltype(auto)
operator<<(RemarkT &&R,
std::enable_if_t<
std::is_base_of<DiagnosticInfoOptimizationBase, RemarkT>::value,
DiagnosticInfoOptimizationBase::setIsVerbose>
std::enable_if_t<std::is_base_of_v<DiagnosticInfoOptimizationBase,
std::remove_reference_t<RemarkT>>,
DiagnosticInfoOptimizationBase::setIsVerbose>
V) {
R.insert(V);
return R;
return std::forward<RemarkT>(R);
}

template <class RemarkT>
RemarkT &
operator<<(RemarkT &R,
std::enable_if_t<
std::is_base_of<DiagnosticInfoOptimizationBase, RemarkT>::value,
DiagnosticInfoOptimizationBase::setExtraArgs>
decltype(auto)
operator<<(RemarkT &&R,
std::enable_if_t<std::is_base_of_v<DiagnosticInfoOptimizationBase,
std::remove_reference_t<RemarkT>>,
DiagnosticInfoOptimizationBase::setExtraArgs>
EA) {
R.insert(EA);
return R;
return std::forward<RemarkT>(R);
}

/// Common features for diagnostics dealing with optimization remarks
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Analysis/InlineAdvisor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ static raw_ostream &operator<<(raw_ostream &R, const ore::NV &Arg) {
}

template <class RemarkT>
RemarkT &operator<<(RemarkT &&R, const InlineCost &IC) {
decltype(auto) operator<<(RemarkT &&R, const InlineCost &IC) {
using namespace ore;
if (IC.isAlways()) {
R << "(cost=always)";
Expand All @@ -350,7 +350,7 @@ RemarkT &operator<<(RemarkT &&R, const InlineCost &IC) {
}
if (const char *Reason = IC.getReason())
R << ": " << ore::NV("Reason", Reason);
return R;
return std::forward<RemarkT>(R);
}
} // namespace llvm

Expand Down