mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-01-31 20:51:52 +01:00
[OptRemark] Move YAML writing to IR
Before the patch this was in Analysis. Moving it to IR and making it implicit part of LLVMContext::diagnose allows the full opt-remark facility to be used outside passes e.g. the pass manager. Jessica is planning to use this to report function size after each pass. The same could be used for time reports. Tested with BUILD_SHARED_LIBS=On. llvm-svn: 314909
This commit is contained in:
parent
195b4a91cd
commit
04df6745f9
@ -164,11 +164,5 @@ public:
|
||||
/// \brief Run the analysis pass over a function and produce BFI.
|
||||
Result run(Function &F, FunctionAnalysisManager &AM);
|
||||
};
|
||||
|
||||
namespace yaml {
|
||||
template <> struct MappingTraits<DiagnosticInfoOptimizationBase *> {
|
||||
static void mapping(IO &io, DiagnosticInfoOptimizationBase *&OptDiag);
|
||||
};
|
||||
}
|
||||
}
|
||||
#endif // LLVM_IR_OPTIMIZATIONDIAGNOSTICINFO_H
|
||||
|
@ -987,6 +987,12 @@ public:
|
||||
void print(DiagnosticPrinter &DP) const override;
|
||||
};
|
||||
|
||||
namespace yaml {
|
||||
template <> struct MappingTraits<DiagnosticInfoOptimizationBase *> {
|
||||
static void mapping(IO &io, DiagnosticInfoOptimizationBase *&OptDiag);
|
||||
};
|
||||
} // namespace yaml
|
||||
|
||||
} // end namespace llvm
|
||||
|
||||
#endif // LLVM_IR_DIAGNOSTICINFO_H
|
||||
|
@ -64,86 +64,6 @@ Optional<uint64_t> OptimizationRemarkEmitter::computeHotness(const Value *V) {
|
||||
return BFI->getBlockProfileCount(cast<BasicBlock>(V));
|
||||
}
|
||||
|
||||
namespace llvm {
|
||||
namespace yaml {
|
||||
|
||||
void MappingTraits<DiagnosticInfoOptimizationBase *>::mapping(
|
||||
IO &io, DiagnosticInfoOptimizationBase *&OptDiag) {
|
||||
assert(io.outputting() && "input not yet implemented");
|
||||
|
||||
if (io.mapTag("!Passed",
|
||||
(OptDiag->getKind() == DK_OptimizationRemark ||
|
||||
OptDiag->getKind() == DK_MachineOptimizationRemark)))
|
||||
;
|
||||
else if (io.mapTag(
|
||||
"!Missed",
|
||||
(OptDiag->getKind() == DK_OptimizationRemarkMissed ||
|
||||
OptDiag->getKind() == DK_MachineOptimizationRemarkMissed)))
|
||||
;
|
||||
else if (io.mapTag(
|
||||
"!Analysis",
|
||||
(OptDiag->getKind() == DK_OptimizationRemarkAnalysis ||
|
||||
OptDiag->getKind() == DK_MachineOptimizationRemarkAnalysis)))
|
||||
;
|
||||
else if (io.mapTag("!AnalysisFPCommute",
|
||||
OptDiag->getKind() ==
|
||||
DK_OptimizationRemarkAnalysisFPCommute))
|
||||
;
|
||||
else if (io.mapTag("!AnalysisAliasing",
|
||||
OptDiag->getKind() ==
|
||||
DK_OptimizationRemarkAnalysisAliasing))
|
||||
;
|
||||
else if (io.mapTag("!Failure", OptDiag->getKind() == DK_OptimizationFailure))
|
||||
;
|
||||
else
|
||||
llvm_unreachable("Unknown remark type");
|
||||
|
||||
// These are read-only for now.
|
||||
DiagnosticLocation DL = OptDiag->getLocation();
|
||||
StringRef FN =
|
||||
GlobalValue::dropLLVMManglingEscape(OptDiag->getFunction().getName());
|
||||
|
||||
StringRef PassName(OptDiag->PassName);
|
||||
io.mapRequired("Pass", PassName);
|
||||
io.mapRequired("Name", OptDiag->RemarkName);
|
||||
if (!io.outputting() || DL.isValid())
|
||||
io.mapOptional("DebugLoc", DL);
|
||||
io.mapRequired("Function", FN);
|
||||
io.mapOptional("Hotness", OptDiag->Hotness);
|
||||
io.mapOptional("Args", OptDiag->Args);
|
||||
}
|
||||
|
||||
template <> struct MappingTraits<DiagnosticLocation> {
|
||||
static void mapping(IO &io, DiagnosticLocation &DL) {
|
||||
assert(io.outputting() && "input not yet implemented");
|
||||
|
||||
StringRef File = DL.getFilename();
|
||||
unsigned Line = DL.getLine();
|
||||
unsigned Col = DL.getColumn();
|
||||
|
||||
io.mapRequired("File", File);
|
||||
io.mapRequired("Line", Line);
|
||||
io.mapRequired("Column", Col);
|
||||
}
|
||||
|
||||
static const bool flow = true;
|
||||
};
|
||||
|
||||
// Implement this as a mapping for now to get proper quotation for the value.
|
||||
template <> struct MappingTraits<DiagnosticInfoOptimizationBase::Argument> {
|
||||
static void mapping(IO &io, DiagnosticInfoOptimizationBase::Argument &A) {
|
||||
assert(io.outputting() && "input not yet implemented");
|
||||
io.mapRequired(A.Key.data(), A.Val);
|
||||
if (A.Loc.isValid())
|
||||
io.mapOptional("DebugLoc", A.Loc);
|
||||
}
|
||||
};
|
||||
|
||||
} // end namespace yaml
|
||||
} // end namespace llvm
|
||||
|
||||
LLVM_YAML_IS_SEQUENCE_VECTOR(DiagnosticInfoOptimizationBase::Argument)
|
||||
|
||||
void OptimizationRemarkEmitter::computeHotness(
|
||||
DiagnosticInfoIROptimization &OptDiag) {
|
||||
const Value *V = OptDiag.getCodeRegion();
|
||||
@ -163,12 +83,6 @@ void OptimizationRemarkEmitter::emit(
|
||||
return;
|
||||
}
|
||||
|
||||
yaml::Output *Out = F->getContext().getDiagnosticsOutputFile();
|
||||
if (Out) {
|
||||
// For remarks the << operator takes a reference to a pointer.
|
||||
auto *P = &OptDiagBase;
|
||||
*Out << P;
|
||||
}
|
||||
F->getContext().diagnose(OptDiag);
|
||||
}
|
||||
|
||||
|
@ -60,12 +60,6 @@ void MachineOptimizationRemarkEmitter::emit(
|
||||
return;
|
||||
}
|
||||
|
||||
yaml::Output *Out = Ctx.getDiagnosticsOutputFile();
|
||||
if (Out) {
|
||||
auto *P = &const_cast<DiagnosticInfoOptimizationBase &>(OptDiagCommon);
|
||||
*Out << P;
|
||||
}
|
||||
|
||||
Ctx.diagnose(OptDiag);
|
||||
}
|
||||
|
||||
|
@ -341,3 +341,83 @@ std::string DiagnosticInfoOptimizationBase::getMsg() const {
|
||||
OS << Arg.Val;
|
||||
return OS.str();
|
||||
}
|
||||
|
||||
namespace llvm {
|
||||
namespace yaml {
|
||||
|
||||
void MappingTraits<DiagnosticInfoOptimizationBase *>::mapping(
|
||||
IO &io, DiagnosticInfoOptimizationBase *&OptDiag) {
|
||||
assert(io.outputting() && "input not yet implemented");
|
||||
|
||||
if (io.mapTag("!Passed",
|
||||
(OptDiag->getKind() == DK_OptimizationRemark ||
|
||||
OptDiag->getKind() == DK_MachineOptimizationRemark)))
|
||||
;
|
||||
else if (io.mapTag(
|
||||
"!Missed",
|
||||
(OptDiag->getKind() == DK_OptimizationRemarkMissed ||
|
||||
OptDiag->getKind() == DK_MachineOptimizationRemarkMissed)))
|
||||
;
|
||||
else if (io.mapTag(
|
||||
"!Analysis",
|
||||
(OptDiag->getKind() == DK_OptimizationRemarkAnalysis ||
|
||||
OptDiag->getKind() == DK_MachineOptimizationRemarkAnalysis)))
|
||||
;
|
||||
else if (io.mapTag("!AnalysisFPCommute",
|
||||
OptDiag->getKind() ==
|
||||
DK_OptimizationRemarkAnalysisFPCommute))
|
||||
;
|
||||
else if (io.mapTag("!AnalysisAliasing",
|
||||
OptDiag->getKind() ==
|
||||
DK_OptimizationRemarkAnalysisAliasing))
|
||||
;
|
||||
else if (io.mapTag("!Failure", OptDiag->getKind() == DK_OptimizationFailure))
|
||||
;
|
||||
else
|
||||
llvm_unreachable("Unknown remark type");
|
||||
|
||||
// These are read-only for now.
|
||||
DiagnosticLocation DL = OptDiag->getLocation();
|
||||
StringRef FN =
|
||||
GlobalValue::dropLLVMManglingEscape(OptDiag->getFunction().getName());
|
||||
|
||||
StringRef PassName(OptDiag->PassName);
|
||||
io.mapRequired("Pass", PassName);
|
||||
io.mapRequired("Name", OptDiag->RemarkName);
|
||||
if (!io.outputting() || DL.isValid())
|
||||
io.mapOptional("DebugLoc", DL);
|
||||
io.mapRequired("Function", FN);
|
||||
io.mapOptional("Hotness", OptDiag->Hotness);
|
||||
io.mapOptional("Args", OptDiag->Args);
|
||||
}
|
||||
|
||||
template <> struct MappingTraits<DiagnosticLocation> {
|
||||
static void mapping(IO &io, DiagnosticLocation &DL) {
|
||||
assert(io.outputting() && "input not yet implemented");
|
||||
|
||||
StringRef File = DL.getFilename();
|
||||
unsigned Line = DL.getLine();
|
||||
unsigned Col = DL.getColumn();
|
||||
|
||||
io.mapRequired("File", File);
|
||||
io.mapRequired("Line", Line);
|
||||
io.mapRequired("Column", Col);
|
||||
}
|
||||
|
||||
static const bool flow = true;
|
||||
};
|
||||
|
||||
// Implement this as a mapping for now to get proper quotation for the value.
|
||||
template <> struct MappingTraits<DiagnosticInfoOptimizationBase::Argument> {
|
||||
static void mapping(IO &io, DiagnosticInfoOptimizationBase::Argument &A) {
|
||||
assert(io.outputting() && "input not yet implemented");
|
||||
io.mapRequired(A.Key.data(), A.Val);
|
||||
if (A.Loc.isValid())
|
||||
io.mapOptional("DebugLoc", A.Loc);
|
||||
}
|
||||
};
|
||||
|
||||
} // end namespace yaml
|
||||
} // end namespace llvm
|
||||
|
||||
LLVM_YAML_IS_SEQUENCE_VECTOR(DiagnosticInfoOptimizationBase::Argument)
|
||||
|
@ -225,6 +225,14 @@ LLVMContext::getDiagnosticMessagePrefix(DiagnosticSeverity Severity) {
|
||||
}
|
||||
|
||||
void LLVMContext::diagnose(const DiagnosticInfo &DI) {
|
||||
if (auto *OptDiagBase = dyn_cast<DiagnosticInfoOptimizationBase>(&DI)) {
|
||||
yaml::Output *Out = getDiagnosticsOutputFile();
|
||||
if (Out) {
|
||||
// For remarks the << operator takes a reference to a pointer.
|
||||
auto *P = const_cast<DiagnosticInfoOptimizationBase *>(OptDiagBase);
|
||||
*Out << P;
|
||||
}
|
||||
}
|
||||
// If there is a report handler, use it.
|
||||
if (pImpl->DiagHandler &&
|
||||
(!pImpl->RespectDiagnosticFilters || isDiagnosticEnabled(DI)) &&
|
||||
|
Loading…
x
Reference in New Issue
Block a user