Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
24 changes: 18 additions & 6 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 @@ -625,14 +626,14 @@ operator<<(RemarkT &R,
/// Also allow r-value for the remark to allow insertion into a
/// temporarily-constructed remark.
template <class RemarkT>
RemarkT &
RemarkT &&
operator<<(RemarkT &&R,
std::enable_if_t<
std::is_base_of<DiagnosticInfoOptimizationBase, RemarkT>::value,
StringRef>
S) {
R.insert(S);
return R;
return std::move(R);
}

template <class RemarkT>
Expand All @@ -647,14 +648,14 @@ operator<<(RemarkT &R,
}

template <class RemarkT>
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::move(R);
}

template <class RemarkT>
Expand All @@ -669,14 +670,14 @@ operator<<(RemarkT &R,
}

template <class RemarkT>
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::move(R);
}

template <class RemarkT>
Expand All @@ -690,6 +691,17 @@ operator<<(RemarkT &R,
return R;
}

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

/// Common features for diagnostics dealing with optimization remarks
/// that are used by IR passes.
class DiagnosticInfoIROptimization : public DiagnosticInfoOptimizationBase {
Expand Down
9 changes: 7 additions & 2 deletions llvm/lib/Analysis/InlineAdvisor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,7 @@ static raw_ostream &operator<<(raw_ostream &R, const ore::NV &Arg) {
return R << Arg.Val;
}

template <class RemarkT>
RemarkT &operator<<(RemarkT &&R, const InlineCost &IC) {
template <class RemarkT> RemarkT &operator<<(RemarkT &R, const InlineCost &IC) {
using namespace ore;
if (IC.isAlways()) {
R << "(cost=always)";
Expand All @@ -352,6 +351,12 @@ RemarkT &operator<<(RemarkT &&R, const InlineCost &IC) {
R << ": " << ore::NV("Reason", Reason);
return R;
}

template <class RemarkT>
RemarkT &&operator<<(RemarkT &&R, const InlineCost &IC) {
static_cast<RemarkT &>(R) << IC;
return std::move(R);
}
} // namespace llvm

std::string llvm::inlineCostStr(const InlineCost &IC) {
Expand Down