Add opt remarks to Generic Specializer pass

Adds a combined API to output both debug message and optimization remarks.

The previously added test partial_specialization_debug.sil ensures that it's an
NFC for debug output.
This commit is contained in:
Adam Nemet
2017-11-10 11:35:03 -08:00
parent 7ba352c4d7
commit bd8764caaa
7 changed files with 231 additions and 19 deletions

View File

@@ -17,6 +17,7 @@
#define DEBUG_TYPE "sil-generic-specializer"
#include "swift/SIL/OptimizationRemark.h"
#include "swift/SIL/SILFunction.h"
#include "swift/SIL/SILInstruction.h"
#include "swift/SILOptimizer/Utils/Generics.h"
@@ -49,6 +50,7 @@ class GenericSpecializer : public SILFunctionTransform {
bool GenericSpecializer::specializeAppliesInFunction(SILFunction &F) {
DeadInstructionSet DeadApplies;
llvm::SmallSetVector<SILInstruction *, 8> Applies;
OptRemark::Emitter ORE(DEBUG_TYPE, F.getModule());
bool Changed = false;
for (auto &BB : F) {
@@ -67,8 +69,17 @@ bool GenericSpecializer::specializeAppliesInFunction(SILFunction &F) {
continue;
auto *Callee = Apply.getReferencedFunction();
if (!Callee || !Callee->isDefinition())
if (!Callee)
continue;
if (!Callee->isDefinition()) {
ORE.emit([&]() {
using namespace OptRemark;
return RemarkMissed("NoDef", *I)
<< "Unable to specialize generic function "
<< NV("Callee", Callee) << " since definition is not visible";
});
continue;
}
Applies.insert(Apply.getInstruction());
}
@@ -87,7 +98,7 @@ bool GenericSpecializer::specializeAppliesInFunction(SILFunction &F) {
// We have a call that can potentially be specialized, so
// attempt to do so.
llvm::SmallVector<SILFunction *, 2> NewFunctions;
trySpecializeApplyOfGeneric(Apply, DeadApplies, NewFunctions);
trySpecializeApplyOfGeneric(Apply, DeadApplies, NewFunctions, ORE);
// Remove all the now-dead applies. We must do this immediately
// rather than defer it in order to avoid problems with cloning