@@ -113,6 +113,16 @@ struct AutoDiffConfig {
113
113
SWIFT_DEBUG_DUMP;
114
114
};
115
115
116
+ // / Key for caching SIL derivative function types.
117
+ struct SILAutoDiffDerivativeFunctionKey {
118
+ SILFunctionType *originalType;
119
+ IndexSubset *parameterIndices;
120
+ IndexSubset *resultIndices;
121
+ AutoDiffDerivativeFunctionKind kind;
122
+ CanGenericSignature derivativeFnGenSig;
123
+ bool isReabstractionThunk;
124
+ };
125
+
116
126
class ParsedAutoDiffParameter {
117
127
public:
118
128
enum class Kind { Named, Ordered, Self };
@@ -281,8 +291,11 @@ namespace llvm {
281
291
282
292
using swift::AutoDiffConfig;
283
293
using swift::AutoDiffDerivativeFunctionKind;
294
+ using swift::CanGenericSignature;
284
295
using swift::GenericSignature;
285
296
using swift::IndexSubset;
297
+ using swift::SILAutoDiffDerivativeFunctionKey;
298
+ using swift::SILFunctionType;
286
299
287
300
template <typename T> struct DenseMapInfo ;
288
301
@@ -354,6 +367,50 @@ template <> struct DenseMapInfo<AutoDiffDerivativeFunctionKind> {
354
367
}
355
368
};
356
369
370
+ template <> struct DenseMapInfo <SILAutoDiffDerivativeFunctionKey> {
371
+ static bool isEqual (const SILAutoDiffDerivativeFunctionKey lhs,
372
+ const SILAutoDiffDerivativeFunctionKey rhs) {
373
+ return lhs.originalType == rhs.originalType &&
374
+ lhs.parameterIndices == rhs.parameterIndices &&
375
+ lhs.resultIndices == rhs.resultIndices &&
376
+ lhs.kind .rawValue == rhs.kind .rawValue &&
377
+ lhs.derivativeFnGenSig == rhs.derivativeFnGenSig &&
378
+ lhs.isReabstractionThunk == rhs.isReabstractionThunk ;
379
+ }
380
+
381
+ static inline SILAutoDiffDerivativeFunctionKey getEmptyKey () {
382
+ return {DenseMapInfo<SILFunctionType *>::getEmptyKey (),
383
+ DenseMapInfo<IndexSubset *>::getEmptyKey (),
384
+ DenseMapInfo<IndexSubset *>::getEmptyKey (),
385
+ AutoDiffDerivativeFunctionKind::innerty (
386
+ DenseMapInfo<unsigned >::getEmptyKey ()),
387
+ CanGenericSignature (DenseMapInfo<GenericSignature>::getEmptyKey ()),
388
+ (bool )DenseMapInfo<unsigned >::getEmptyKey ()};
389
+ }
390
+
391
+ static inline SILAutoDiffDerivativeFunctionKey getTombstoneKey () {
392
+ return {
393
+ DenseMapInfo<SILFunctionType *>::getTombstoneKey (),
394
+ DenseMapInfo<IndexSubset *>::getTombstoneKey (),
395
+ DenseMapInfo<IndexSubset *>::getTombstoneKey (),
396
+ AutoDiffDerivativeFunctionKind::innerty (
397
+ DenseMapInfo<unsigned >::getTombstoneKey ()),
398
+ CanGenericSignature (DenseMapInfo<GenericSignature>::getTombstoneKey ()),
399
+ (bool )DenseMapInfo<unsigned >::getTombstoneKey ()};
400
+ }
401
+
402
+ static unsigned getHashValue (const SILAutoDiffDerivativeFunctionKey &Val) {
403
+ return hash_combine (
404
+ DenseMapInfo<SILFunctionType *>::getHashValue (Val.originalType ),
405
+ DenseMapInfo<IndexSubset *>::getHashValue (Val.parameterIndices ),
406
+ DenseMapInfo<IndexSubset *>::getHashValue (Val.resultIndices ),
407
+ DenseMapInfo<unsigned >::getHashValue ((unsigned )Val.kind .rawValue ),
408
+ DenseMapInfo<GenericSignature>::getHashValue (Val.derivativeFnGenSig ),
409
+ DenseMapInfo<unsigned >::getHashValue (
410
+ (unsigned )Val.isReabstractionThunk ));
411
+ }
412
+ };
413
+
357
414
} // end namespace llvm
358
415
359
416
#endif // SWIFT_AST_AUTODIFF_H
0 commit comments