Skip to content

Commit 0d62e3c

Browse files
committed
[AutoDiff] Move dumpActivityInfo to DifferentiableActivityInfo class
1 parent 7d607ad commit 0d62e3c

File tree

3 files changed

+41
-32
lines changed

3 files changed

+41
-32
lines changed

include/swift/SILOptimizer/Analysis/DifferentiableActivityAnalysis.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,16 @@ class DifferentiableActivityInfo {
206206
/// Returns the activity of the given value for the given `SILAutoDiffIndices`
207207
/// (parameter indices and result index).
208208
Activity getActivity(SILValue value, const SILAutoDiffIndices &indices) const;
209+
210+
/// Prints activity information for the `indices` of the given `value`.
211+
void dumpActivityInfo(SILValue value,
212+
const SILAutoDiffIndices &indices,
213+
llvm::raw_ostream &s = llvm::dbgs()) const;
214+
215+
/// Prints activity information for the `indices` of the given `fn`.
216+
void dumpActivityInfo(SILFunction &fn, SILAutoDiffIndices indices,
217+
llvm::raw_ostream &s = llvm::dbgs()) const;
218+
209219
};
210220

211221
class DifferentiableActivityCollection {

lib/SILOptimizer/Analysis/DifferentiableActivityAnalysis.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,3 +421,32 @@ Activity DifferentiableActivityInfo::getActivity(
421421
activity |= ActivityFlags::Useful;
422422
return activity;
423423
}
424+
425+
void DifferentiableActivityInfo::dumpActivityInfo(
426+
SILValue value, const SILAutoDiffIndices &indices,
427+
llvm::raw_ostream &s) const {
428+
s << '[';
429+
auto activity = getActivity(value, indices);
430+
switch (activity.toRaw()) {
431+
case 0: s << "NONE"; break;
432+
case (unsigned)ActivityFlags::Varied: s << "VARIED"; break;
433+
case (unsigned)ActivityFlags::Useful: s << "USEFUL"; break;
434+
case (unsigned)ActivityFlags::Active: s << "ACTIVE"; break;
435+
}
436+
s << "] " << value;
437+
}
438+
439+
void DifferentiableActivityInfo::dumpActivityInfo(SILFunction &fn,
440+
SILAutoDiffIndices indices,
441+
llvm::raw_ostream &s) const {
442+
s << "Activity info for " << fn.getName() << " at " << indices << '\n';
443+
for (auto &bb : fn) {
444+
s << "bb" << bb.getDebugID() << ":\n";
445+
for (auto *arg : bb.getArguments())
446+
dumpActivityInfo(arg, indices, s);
447+
for (auto &inst : bb)
448+
for (auto res : inst.getResults())
449+
dumpActivityInfo(res, indices, s);
450+
s << '\n';
451+
}
452+
}

lib/SILOptimizer/Mandatory/Differentiation.cpp

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -262,36 +262,6 @@ class DifferentiationTransformer {
262262

263263
} // end anonymous namespace
264264

265-
static void dumpActivityInfo(SILValue value,
266-
const SILAutoDiffIndices &indices,
267-
const DifferentiableActivityInfo &activityInfo,
268-
llvm::raw_ostream &s = llvm::dbgs()) {
269-
s << '[';
270-
auto activity = activityInfo.getActivity(value, indices);
271-
switch (activity.toRaw()) {
272-
case 0: s << "NONE"; break;
273-
case (unsigned)ActivityFlags::Varied: s << "VARIED"; break;
274-
case (unsigned)ActivityFlags::Useful: s << "USEFUL"; break;
275-
case (unsigned)ActivityFlags::Active: s << "ACTIVE"; break;
276-
}
277-
s << "] " << value;
278-
}
279-
280-
static void dumpActivityInfo(SILFunction &fn, SILAutoDiffIndices indices,
281-
const DifferentiableActivityInfo &activityInfo,
282-
llvm::raw_ostream &s = llvm::dbgs()) {
283-
s << "Activity info for " << fn.getName() << " at " << indices << '\n';
284-
for (auto &bb : fn) {
285-
s << "bb" << bb.getDebugID() << ":\n";
286-
for (auto *arg : bb.getArguments())
287-
dumpActivityInfo(arg, indices, activityInfo, s);
288-
for (auto &inst : bb)
289-
for (auto res : inst.getResults())
290-
dumpActivityInfo(res, indices, activityInfo, s);
291-
s << '\n';
292-
}
293-
}
294-
295265
/// If the original function doesn't have a return, it cannot be differentiated.
296266
/// Returns true if error is emitted.
297267
static bool diagnoseNoReturn(ADContext &context, SILFunction *original,
@@ -1374,7 +1344,7 @@ class VJPEmitter final
13741344
vjp->getLoweredFunctionType()->getSubstGenericSignature(),
13751345
AutoDiffDerivativeFunctionKind::VJP);
13761346
LLVM_DEBUG(
1377-
dumpActivityInfo(*original, indices, activityInfo, getADDebugStream()));
1347+
activityInfo.dumpActivityInfo(*original, indices, getADDebugStream()));
13781348
return activityInfo;
13791349
}
13801350

@@ -2128,7 +2098,7 @@ class JVPEmitter final
21282098
jvp->getLoweredFunctionType()->getSubstGenericSignature(),
21292099
AutoDiffDerivativeFunctionKind::JVP);
21302100
LLVM_DEBUG(
2131-
dumpActivityInfo(*original, indices, activityInfo, getADDebugStream()));
2101+
activityInfo.dumpActivityInfo(*original, indices, getADDebugStream()));
21322102
return activityInfo;
21332103
}
21342104

0 commit comments

Comments
 (0)