mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[AutoDiff upstream] [SIL] Add differentiable function instructions.
Add `differentiable_function` and `differentiable_function_extract` instructions. `differentiable_function` creates a `@differentiable` function-typed value from an original function operand and derivative function operands (optional). `differentiable_function_extract` extracts either the original or derivative function value from a `@differentiable` function. The differentiation transform canonicalizes `differentiable_function` instructions, filling in derivative function operands if missing. Resolves TF-1139 and TF-1140.
This commit is contained in:
@@ -2164,6 +2164,23 @@ public:
|
||||
// Differentiable programming instructions
|
||||
//===--------------------------------------------------------------------===//
|
||||
|
||||
DifferentiableFunctionInst *createDifferentiableFunction(
|
||||
SILLocation Loc, IndexSubset *ParameterIndices, SILValue OriginalFunction,
|
||||
Optional<std::pair<SILValue, SILValue>> JVPAndVJPFunctions = None) {
|
||||
return insert(DifferentiableFunctionInst::create(
|
||||
getModule(), getSILDebugLocation(Loc), ParameterIndices,
|
||||
OriginalFunction, JVPAndVJPFunctions, hasOwnership()));
|
||||
}
|
||||
|
||||
/// Note: explicit extractee type may be specified only in lowered SIL.
|
||||
DifferentiableFunctionExtractInst *createDifferentiableFunctionExtract(
|
||||
SILLocation Loc, NormalDifferentiableFunctionTypeComponent Extractee,
|
||||
SILValue Function, Optional<SILType> ExtracteeType = None) {
|
||||
return insert(new (getModule()) DifferentiableFunctionExtractInst(
|
||||
getModule(), getSILDebugLocation(Loc), Extractee, Function,
|
||||
ExtracteeType));
|
||||
}
|
||||
|
||||
/// Note: explicit function type may be specified only in lowered SIL.
|
||||
DifferentiabilityWitnessFunctionInst *createDifferentiabilityWitnessFunction(
|
||||
SILLocation Loc, DifferentiabilityWitnessFunctionKind WitnessKind,
|
||||
|
||||
Reference in New Issue
Block a user