Skip to content

Commit bed83aa

Browse files
authored
---
yaml --- r: 293887 b: refs/heads/tensorflow c: 5e00fdd h: refs/heads/master i: 293885: 2363e4e 293883: d3814ec 293879: f8e9400 293871: 2e8d8cc 293855: 4b54b29 293823: 7570ea4 293759: d1893ee 293631: d0f8079 293375: 093a42c 292863: 24b455d
1 parent 1b438fc commit bed83aa

File tree

4 files changed

+27
-25
lines changed

4 files changed

+27
-25
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -816,7 +816,7 @@ refs/tags/swift-DEVELOPMENT-SNAPSHOT-2018-04-25-a: 22f738a831d43aff2b9c9773bcb65
816816
refs/tags/swift-DEVELOPMENT-SNAPSHOT-2018-05-08-a: 7d98cc16689baba5c8a3b90a9329bdcc1a12b4e9
817817
refs/heads/cherr42: a566ad54b073c2c56ac0a705d0a5bed9743135a5
818818
"refs/heads/codable_test_comment_fix": fc8f6824f7f347e1e8db55bff62db385c5728b5a
819-
refs/heads/tensorflow: 79518bec6768cf5b1dce6a6886f2f7218d0d07b9
819+
refs/heads/tensorflow: 5e00fdd2728b5af180914c8d8f1a3848cfce88dc
820820
refs/tags/swift-4.1-DEVELOPMENT-SNAPSHOT-2018-05-11-a: 8126fd7a652e2f70ad6d76505239e34fb2ef3e1a
821821
refs/tags/swift-4.1-DEVELOPMENT-SNAPSHOT-2018-05-12-a: b3fd3dd84df6717f2e2e9df58c6d7e99fed57086
822822
refs/tags/swift-4.1-DEVELOPMENT-SNAPSHOT-2018-05-13-a: 71135119579039dc321c5f65d870050fe36efda2

branches/tensorflow/lib/SILGen/SILGenBuiltin.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1078,12 +1078,11 @@ static ManagedValue emitBuiltinAutoDiffApplyAssociatedFunction(
10781078
continue;
10791079

10801080
if (argumentValue->getType().isObject()) {
1081-
SGF.B.createDestroyValue(loc, argumentValue);
1081+
SGF.B.emitDestroyValueOperation(loc, argumentValue);
10821082
continue;
10831083
}
10841084

1085-
if (false)
1086-
SGF.B.createDestroyAddr(loc, argumentValue);
1085+
SGF.B.createDestroyAddr(loc, argumentValue);
10871086
}
10881087
};
10891088

@@ -1096,7 +1095,8 @@ static ManagedValue emitBuiltinAutoDiffApplyAssociatedFunction(
10961095
auto curryLevelArgVals = ArrayRef<SILValue>(origFnArgVals).slice(
10971096
currentParameter, curryLevel->getNumParameters());
10981097
auto applyResult = SGF.B.createApply(
1099-
loc, assocFn, SubstitutionMap(), curryLevelArgVals, /*isNonThrowing*/ false);
1098+
loc, assocFn, SubstitutionMap(), curryLevelArgVals,
1099+
/*isNonThrowing*/ false);
11001100
currentParameter += curryLevel->getNumParameters();
11011101

11021102
if (assocFnNeedsDestroy)
@@ -1125,8 +1125,8 @@ static ManagedValue emitBuiltinAutoDiffApplyAssociatedFunction(
11251125
currentParameter);
11261126
for (auto origFnArgVal : curryLevelArgVals)
11271127
applyArgs.push_back(origFnArgVal);
1128-
auto differential = SGF.B.createApply(loc, assocFn, SubstitutionMap(), applyArgs,
1129-
/*isNonThrowing*/ false);
1128+
auto differential = SGF.B.createApply(
1129+
loc, assocFn, SubstitutionMap(), applyArgs, /*isNonThrowing*/ false);
11301130

11311131
if (assocFnNeedsDestroy)
11321132
SGF.B.createDestroyValue(loc, assocFn);
@@ -1143,8 +1143,9 @@ static ManagedValue emitBuiltinAutoDiffApplyAssociatedFunction(
11431143
// Apply the last curry level, in the case where it only has direct results.
11441144
auto curryLevelArgVals = ArrayRef<SILValue>(origFnArgVals).slice(
11451145
currentParameter);
1146-
auto resultTuple = SGF.B.createApply(loc, assocFn, SubstitutionMap(), curryLevelArgVals,
1147-
/*isNonThrowing*/ false);
1146+
auto resultTuple = SGF.B.createApply(
1147+
loc, assocFn, SubstitutionMap(), curryLevelArgVals,
1148+
/*isNonThrowing*/ false);
11481149

11491150
if (assocFnNeedsDestroy)
11501151
SGF.B.createDestroyValue(loc, assocFn);

branches/tensorflow/lib/SILGen/SILGenPoly.cpp

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3245,13 +3245,8 @@ static ManagedValue createAutoDiffThunk(SILGenFunction &SGF,
32453245
CanAnyFunctionType outputSubstType) {
32463246
// Applies a thunk to all the components by extracting them, applying thunks
32473247
// to all of them, and then putting them back together.
3248-
32493248
auto sourceType = fn.getType().castTo<SILFunctionType>();
32503249

3251-
// We're never going to pass `fn` into anything that consumes it, so get its
3252-
// value without disabling cleanup.
3253-
auto fnValue = fn.getValue();
3254-
32553250
auto withoutDifferentiablePattern = [](AbstractionPattern pattern)
32563251
-> AbstractionPattern {
32573252
auto patternType = cast<AnyFunctionType>(pattern.getType());
@@ -3269,10 +3264,13 @@ static ManagedValue createAutoDiffThunk(SILGenFunction &SGF,
32693264
auto outputOrigTypeNotDiff = withoutDifferentiablePattern(outputOrigType);
32703265
auto &expectedTLNotDiff = SGF.getTypeLowering(outputOrigTypeNotDiff,
32713266
outputSubstTypeNotDiff);
3272-
SILValue original = SGF.B.createAutoDiffFunctionExtractOriginal(loc, fnValue);
3273-
auto managedOriginal = original->getType().isTrivial(SGF.F)
3274-
? ManagedValue::forTrivialObjectRValue(original)
3275-
: ManagedValue::forBorrowedObjectRValue(original);
3267+
// `autodiff_function_extract` is consuming; copy `fn` before passing as
3268+
// operand.
3269+
auto copiedFnValue = fn.copy(SGF, loc);
3270+
auto *original = SGF.B.createAutoDiffFunctionExtractOriginal(
3271+
loc, copiedFnValue.forward(SGF));
3272+
auto managedOriginal = SGF.emitManagedRValueWithCleanup(original);
3273+
32763274
ManagedValue originalThunk = createThunk(
32773275
SGF, loc, managedOriginal, inputOrigTypeNotDiff, inputSubstTypeNotDiff,
32783276
outputOrigTypeNotDiff, outputSubstTypeNotDiff, expectedTLNotDiff);
@@ -3309,12 +3307,12 @@ static ManagedValue createAutoDiffThunk(SILGenFunction &SGF,
33093307
kind);
33103308
auto &assocFnExpectedTL = SGF.getTypeLowering(assocFnOutputOrigType,
33113309
assocFnOutputSubstType);
3312-
auto assocFn = SGF.B.createAutoDiffFunctionExtract(
3313-
loc, kind,
3314-
/*differentiationOrder*/ 1, fnValue);
3315-
auto managedAssocFn = assocFn->getType().isTrivial(SGF.F)
3316-
? ManagedValue::forTrivialObjectRValue(assocFn)
3317-
: ManagedValue::forBorrowedObjectRValue(assocFn);
3310+
// `autodiff_function_extract` is consuming; copy `fn` before passing as
3311+
// operand.
3312+
auto copiedFnValue = fn.copy(SGF, loc);
3313+
auto *assocFn = SGF.B.createAutoDiffFunctionExtract(
3314+
loc, kind, /*differentiationOrder*/ 1, copiedFnValue.forward(SGF));
3315+
auto managedAssocFn = SGF.emitManagedRValueWithCleanup(assocFn);
33183316
return createThunk(SGF, loc, managedAssocFn, assocFnInputOrigType,
33193317
assocFnInputSubstType, assocFnOutputOrigType,
33203318
assocFnOutputSubstType, assocFnExpectedTL);

branches/tensorflow/test/AutoDiff/builtin_differential_operators.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
// RUN: %target-run
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-build-swift %s -parse-stdlib -o %t/Builtins
3+
// RUN: %target-codesign %t/Builtins
4+
// RUN: %target-run %t/Builtins
25
// REQUIRES: executable_test
36

47
import Swift

0 commit comments

Comments
 (0)