|
Enzyme main
|
#include "AdjointGenerator.h"


Public Member Functions | |
| AdjointGenerator (DerivativeMode Mode, GradientUtils *gutils, llvm::ArrayRef< DIFFE_TYPE > constant_args, DIFFE_TYPE retType, std::function< unsigned(llvm::Instruction *, CacheType, llvm::IRBuilder<> &)> getIndex, const std::map< llvm::CallInst *, std::pair< bool, const std::vector< bool > > > overwritten_args_map, const AugmentedReturn *augmentedReturn, const std::map< llvm::ReturnInst *, llvm::StoreInst * > *replacedReturns, const llvm::SmallPtrSetImpl< const llvm::Value * > &unnecessaryValues, const llvm::SmallPtrSetImpl< const llvm::Instruction * > &unnecessaryInstructions, const llvm::SmallPtrSetImpl< const llvm::Instruction * > &unnecessaryStores, const llvm::SmallPtrSetImpl< llvm::BasicBlock * > &oldUnreachable) | |
| void | eraseIfUnused (llvm::Instruction &I, bool erase=true, bool check=true) |
| void | shadowStoreSchedule (llvm::Instruction &I, llvm::Value *orig_ptr, bool &forwardsShadow, bool &backwardsShadow) |
| Which pass(es) emit the shadow counterpart of the store-like instruction I into the duplicated memory at orig_ptr: the augmented primal (forwardsShadow) and/or the reverse pass (backwardsShadow, for shadow allocations only materialized there), and neither of them for shadow arguments that must not be written. | |
| void | resolveShadowPlaceholder (llvm::Instruction &I, llvm::Value *shadow=nullptr) |
| Resolve the shadow placeholder of the active instruction I in a pass which does not otherwise compute its shadow, replacing it by the given value (a zero shadow if null). | |
| void | addAtomicRMWValueAdjoint (llvm::Instruction &I, llvm::Value *ptr, llvm::Value *val, llvm::Type *loadTy, llvm::Type *FT, bool negate, llvm::Align align, llvm::AtomicOrdering order, llvm::SyncScope::ID ssid, bool isVolatile) |
| Reverse-mode adjoint of the value operand val of an atomic modification new = old + val (negate == false) or new = old - val (negate == true) of the active location ptr by the instruction I, whose result is inactive: the adjoint of val is (the negation of) the contents of the shadow location, read as loadTy (holding the bits of the floating point type FT) with the ordering downgraded for the reverse pass. | |
| llvm::Value * | MPI_TYPE_SIZE (llvm::Value *DT, llvm::IRBuilder<> &B, llvm::Type *intType, llvm::Function *caller) |
| llvm::Value * | MPI_COMM_RANK (llvm::Value *comm, llvm::IRBuilder<> &B, llvm::Type *rankTy, llvm::Function *caller) |
| llvm::Value * | MPI_COMM_SIZE (llvm::Value *comm, llvm::IRBuilder<> &B, llvm::Type *rankTy, llvm::Function *caller) |
| void | visitInstruction (llvm::Instruction &inst) |
| void | forwardModeInvertedPointerFallback (llvm::Instruction &I) |
| void | visitAllocaInst (llvm::AllocaInst &I) |
| void | visitICmpInst (llvm::ICmpInst &I) |
| void | visitFCmpInst (llvm::FCmpInst &I) |
| void | visitLoadLike (llvm::Instruction &I, llvm::MaybeAlign alignment, bool constantval, llvm::Value *mask=nullptr, llvm::Value *orig_maskInit=nullptr) |
| void | visitLoadInst (llvm::LoadInst &LI) |
| void | visitAtomicRMWInst (llvm::AtomicRMWInst &I) |
| void | visitStoreInst (llvm::StoreInst &SI) |
| void | visitCommonStore (llvm::Instruction &I, llvm::Value *orig_ptr, llvm::Value *orig_val, llvm::MaybeAlign prevalign, bool isVolatile, llvm::AtomicOrdering ordering, llvm::SyncScope::ID syncScope, llvm::Value *mask) |
| void | visitGetElementPtrInst (llvm::GetElementPtrInst &gep) |
| void | visitPHINode (llvm::PHINode &phi) |
| void | visitCastInst (llvm::CastInst &I) |
| void | visitSelectInst (llvm::SelectInst &SI) |
| void | createSelectInstAdjoint (llvm::SelectInst &SI) |
| void | visitExtractElementInst (llvm::ExtractElementInst &EEI) |
| void | visitInsertElementInst (llvm::InsertElementInst &IEI) |
| void | visitShuffleVectorInst (llvm::ShuffleVectorInst &SVI) |
| void | visitExtractValueInst (llvm::ExtractValueInst &EVI) |
| void | visitInsertValueInst (llvm::InsertValueInst &IVI) |
| void | getReverseBuilder (llvm::IRBuilder<> &Builder2, bool original=true) |
| void | getForwardBuilder (llvm::IRBuilder<> &Builder2) |
| llvm::Value * | diffe (llvm::Value *val, llvm::IRBuilder<> &Builder) |
| void | setDiffe (llvm::Value *val, llvm::Value *dif, llvm::IRBuilder<> &Builder) |
| template<typename Func , typename... Args> | |
| llvm::Value * | applyChainRule (llvm::Type *diffType, llvm::IRBuilder<> &Builder, Func rule, Args... args) |
| Unwraps a vector derivative from its internal representation and applies a function f to each element. | |
| template<typename Func , typename... Args> | |
| void | applyChainRule (llvm::IRBuilder<> &Builder, Func rule, Args... args) |
| Unwraps a vector derivative from its internal representation and applies a function f to each element. | |
| template<typename Func > | |
| void | applyChainRule (llvm::ArrayRef< llvm::Value * > diffs, llvm::IRBuilder<> &Builder, Func rule) |
| Unwraps an collection of constant vector derivatives from their internal representations and applies a function f to each element. | |
| bool | shouldFree () |
| llvm::SmallVector< llvm::SelectInst *, 4 > | addToDiffe (llvm::Value *val, llvm::Value *dif, llvm::IRBuilder<> &Builder, llvm::Type *T, llvm::Value *mask=nullptr) |
| llvm::Value * | lookup (llvm::Value *val, llvm::IRBuilder<> &Builder) |
| void | visitBinaryOperator (llvm::BinaryOperator &BO) |
| void | createBinaryOperatorAdjoint (llvm::BinaryOperator &BO) |
| void | createBinaryOperatorDual (llvm::BinaryOperator &BO) |
| void | visitMemSetInst (llvm::MemSetInst &MS) |
| void | visitMemSetCommon (llvm::CallInst &MS) |
| void | visitMemTransferInst (llvm::MemTransferInst &MTI) |
| void | visitMemTransferCommon (llvm::Intrinsic::ID ID, llvm::MaybeAlign srcAlign, llvm::MaybeAlign dstAlign, llvm::CallInst &MTI, llvm::Value *orig_dst, llvm::Value *orig_src, llvm::Value *new_size, llvm::Value *isVolatile) |
| void | visitFenceInst (llvm::FenceInst &FI) |
| void | visitIntrinsicInst (llvm::IntrinsicInst &II) |
| bool | handleAdjointForIntrinsic (llvm::Intrinsic::ID ID, llvm::Instruction &I, llvm::SmallVectorImpl< llvm::Value * > &orig_ops) |
| void | visitOMPCall (llvm::CallInst &call) |
| void | DifferentiableMemCopyFloats (llvm::CallInst &call, llvm::Value *origArg, llvm::Value *dsto, llvm::Value *srco, llvm::Value *len_arg, llvm::IRBuilder<> &Builder2, llvm::ArrayRef< llvm::OperandBundleDef > ReverseDefs) |
| void | recursivelyHandleSubfunction (llvm::CallInst &call, llvm::Function *called, bool subsequent_calls_may_write, const std::vector< bool > &overwritten_args, bool shadowReturnUsed, DIFFE_TYPE subretType, bool subretused) |
| void | handleMPI (llvm::CallInst &call, llvm::Function *called, llvm::StringRef funcName) |
| bool | handleKnownCallDerivatives (llvm::CallInst &call, llvm::Function *called, llvm::StringRef funcName, bool subsequent_calls_may_write, const std::vector< bool > &overwritten_args, llvm::CallInst *const newCall) |
| void | visitCallInst (llvm::CallInst &call) |
Static Public Member Functions | |
| static llvm::AtomicOrdering | reverseLoadOrdering (llvm::AtomicOrdering order) |
| The ordering with which the reverse pass may read a location that the primal modified atomically with the given ordering. | |
Definition at line 54 of file AdjointGenerator.h.
|
inline |
Definition at line 77 of file AdjointGenerator.h.
References TypeAnalyzer::analysis, TypeResults::analyzer, TypeResults::getFunction(), and GradientUtils::oldFunc.
|
inline |
Reverse-mode adjoint of the value operand val of an atomic modification new = old + val (negate == false) or new = old - val (negate == true) of the active location ptr by the instruction I, whose result is inactive: the adjoint of val is (the negation of) the contents of the shadow location, read as loadTy (holding the bits of the floating point type FT) with the ordering downgraded for the reverse pass.
Definition at line 200 of file AdjointGenerator.h.
References addToDiffe(), applyChainRule(), getReverseBuilder(), GradientUtils::invertPointerM(), GradientUtils::isConstantValue(), lookup(), and reverseLoadOrdering().
Referenced by handleKnownCallDerivatives(), and visitAtomicRMWInst().
|
inline |
Definition at line 2439 of file AdjointGenerator.h.
Referenced by addAtomicRMWValueAdjoint(), createBinaryOperatorAdjoint(), createSelectInstAdjoint(), handleAdjointForIntrinsic(), recursivelyHandleSubfunction(), visitBinaryOperator(), visitCastInst(), visitInsertElementInst(), and visitLoadLike().
|
inline |
Unwraps an collection of constant vector derivatives from their internal representations and applies a function f to each element.
Definition at line 2426 of file AdjointGenerator.h.
|
inline |
Unwraps a vector derivative from its internal representation and applies a function f to each element.
Definition at line 2419 of file AdjointGenerator.h.
|
inline |
Unwraps a vector derivative from its internal representation and applies a function f to each element.
Return values of f are collected and wrapped.
Definition at line 2410 of file AdjointGenerator.h.
Referenced by addAtomicRMWValueAdjoint(), createBinaryOperatorAdjoint(), createBinaryOperatorDual(), handleAdjointForIntrinsic(), handleKnownCallDerivatives(), visitAtomicRMWInst(), visitBinaryOperator(), visitCastInst(), visitCommonStore(), visitInsertValueInst(), visitLoadLike(), visitMemSetCommon(), and visitMemTransferCommon().
|
inline |
Definition at line 2583 of file AdjointGenerator.h.
References TypeResults::addingType(), addToDiffe(), TypeTree::allFloat(), applyChainRule(), checkedMul(), containsOnlyAtMostTopBit(), CreateSelect(), diffe(), EmitNoDerivativeError(), GradientUtils::getNewFromOriginal(), getReverseBuilder(), GradientUtils::getShadowType(), GradientUtils::isConstantInstruction(), GradientUtils::isConstantValue(), isZero(), TypeResults::knownIntegralValues(), lookup(), looseTypeAnalysis, CacheUtility::newFunc, GradientUtils::oldFunc, TypeResults::query(), setDiffe(), TypeTree::str(), and GradientUtils::strongZero.
Referenced by visitBinaryOperator().
|
inline |
Definition at line 2861 of file AdjointGenerator.h.
References TypeResults::addingType(), TypeTree::allFloat(), applyChainRule(), checkedMul(), containsOnlyAtMostTopBit(), CreateSelect(), diffe(), EmitNoDerivativeError(), GradientUtils::erase(), forwardModeInvertedPointerFallback(), getForwardBuilder(), GradientUtils::getNewFromOriginal(), GradientUtils::getShadowType(), GradientUtils::invertedPointers, GradientUtils::isConstantInstruction(), GradientUtils::isConstantValue(), isZero(), TypeResults::knownIntegralValues(), looseTypeAnalysis, CacheUtility::newFunc, GradientUtils::oldFunc, TypeResults::query(), GradientUtils::replaceAWithB(), setDiffe(), TypeTree::str(), and GradientUtils::strongZero.
Referenced by visitBinaryOperator().
|
inline |
Definition at line 1662 of file AdjointGenerator.h.
References TypeResults::addingType(), addToDiffe(), CreateSelect(), diffe(), LoopContext::exitBlocks, GradientUtils::getContext(), GradientUtils::getNewFromOriginal(), GradientUtils::getOrInsertConditionalIndex(), getReverseBuilder(), GradientUtils::getShadowType(), LoopContext::header, LoopContext::incvar, GradientUtils::isConstantInstruction(), GradientUtils::isConstantValue(), lookup(), GradientUtils::lookupM(), looseTypeAnalysis, CacheUtility::newFunc, GradientUtils::OrigLI, OUT_DIFF, and setDiffe().
Referenced by visitSelectInst().
|
inline |
Definition at line 2396 of file AdjointGenerator.h.
References ReverseModePrimal.
Referenced by createBinaryOperatorAdjoint(), createBinaryOperatorDual(), createSelectInstAdjoint(), handleAdjointForIntrinsic(), recursivelyHandleSubfunction(), visitBinaryOperator(), visitCastInst(), visitExtractElementInst(), visitExtractValueInst(), visitInsertElementInst(), visitInsertValueInst(), visitLoadLike(), and visitShuffleVectorInst().
|
inline |
Definition at line 5070 of file AdjointGenerator.h.
References TypeTree::Data0(), TypeResults::dump(), EmitFailure(), getInt8PtrTy(), getOrInsertDifferentialFloatMemcpy(), getPointerType(), GradientUtils::isAtomic(), looseTypeAnalysis, CacheUtility::newFunc, TypeTree::Only(), TypeResults::query(), and TypeTree::ShiftIndices().
Referenced by handleMPI().
|
inline |
Definition at line 114 of file AdjointGenerator.h.
References GradientUtils::eraseWithPlaceholder(), GradientUtils::getNewFromOriginal(), and GradientUtils::knownRecomputeHeuristic.
Referenced by handleKnownCallDerivatives(), handleMPI(), recursivelyHandleSubfunction(), visitAllocaInst(), visitAtomicRMWInst(), visitBinaryOperator(), visitCallInst(), visitCastInst(), visitExtractElementInst(), visitExtractValueInst(), visitFCmpInst(), visitFenceInst(), visitGetElementPtrInst(), visitICmpInst(), visitInsertElementInst(), visitInsertValueInst(), visitInstruction(), visitIntrinsicInst(), visitLoadInst(), visitMemSetCommon(), visitMemTransferCommon(), visitOMPCall(), visitPHINode(), visitSelectInst(), visitShuffleVectorInst(), and visitStoreInst().
|
inline |
Definition at line 471 of file AdjointGenerator.h.
References GradientUtils::erase(), getForwardBuilder(), GradientUtils::invertedPointers, GradientUtils::invertPointerM(), DifferentialUseAnalysis::is_value_needed_in_reverse(), GradientUtils::isConstantValue(), and GradientUtils::replaceAWithB().
Referenced by createBinaryOperatorDual(), visitAllocaInst(), visitCastInst(), visitExtractElementInst(), visitExtractValueInst(), visitGetElementPtrInst(), visitInsertElementInst(), visitInsertValueInst(), visitIntrinsicInst(), visitPHINode(), visitSelectInst(), and visitShuffleVectorInst().
|
inline |
Definition at line 2392 of file AdjointGenerator.h.
Referenced by createBinaryOperatorDual(), forwardModeInvertedPointerFallback(), handleAdjointForIntrinsic(), handleKnownCallDerivatives(), handleMPI(), recursivelyHandleSubfunction(), visitAtomicRMWInst(), visitInstruction(), and visitMemSetCommon().
|
inline |
Definition at line 2388 of file AdjointGenerator.h.
Referenced by addAtomicRMWValueAdjoint(), createBinaryOperatorAdjoint(), createSelectInstAdjoint(), handleAdjointForIntrinsic(), handleKnownCallDerivatives(), handleMPI(), recursivelyHandleSubfunction(), visitBinaryOperator(), visitCallInst(), visitCastInst(), visitCommonStore(), visitExtractElementInst(), visitExtractValueInst(), visitFenceInst(), visitInsertElementInst(), visitInsertValueInst(), visitLoadLike(), visitMemSetCommon(), visitOMPCall(), and visitShuffleVectorInst().
|
inline |
Definition at line 4105 of file AdjointGenerator.h.
References addToDiffe(), applyChainRule(), CreateSelect(), diffe(), EmitNoDerivativeError(), EmitWarning(), ForwardMode, ForwardModeError, ForwardModeSplit, getForwardBuilder(), getIntrinsicDeclaration(), GradientUtils::getNewFromOriginal(), getReverseBuilder(), GradientUtils::getShadowType(), GradientUtils::isConstantInstruction(), GradientUtils::isConstantValue(), lookup(), looseTypeAnalysis, CacheUtility::newFunc, GradientUtils::oldFunc, parseTBAA(), ReverseModeCombined, ReverseModeGradient, ReverseModePrimal, setDiffe(), visitCommonStore(), and visitLoadLike().
Referenced by handleKnownCallDerivatives(), visitCallInst(), and visitIntrinsicInst().
| bool AdjointGenerator::handleKnownCallDerivatives | ( | llvm::CallInst & | call, |
| llvm::Function * | called, | ||
| llvm::StringRef | funcName, | ||
| bool | subsequent_calls_may_write, | ||
| const std::vector< bool > & | overwritten_args, | ||
| llvm::CallInst *const | newCall ) |
Definition at line 2356 of file CallDerivatives.cpp.
References addAtomicRMWValueAdjoint(), GradientUtils::addReverseBlock(), GradientUtils::allocationsToBeRematerialized, applyChainRule(), GradientUtils::backwardsOnlyShadows, cached, GradientUtils::cacheForReverse(), canonicalizeMPIName(), classifyAtomicModifyOp(), CreateAllocation(), CreateDealloc(), CustomErrorHandler, DUP_ARG, EmitNoDerivativeError(), EmitWarningAlways(), EnzymeFreeInternalAllocations, EnzymeJuliaAddrLoad, EnzymeShadowAllocRewrite, GradientUtils::erase(), eraseIfUnused(), extractBLAS(), GradientUtils::extractMeta(), TypeResults::firstPointer(), ForwardMode, ForwardModeError, ForwardModeSplit, freeKnownAllocation(), getFast(), getForwardBuilder(), getInt8PtrTy(), GradientUtils::getInvertedBundles(), GradientUtils::getNewFromOriginal(), getOrInsertPerCallingConv(), GradientUtils::getReturnDiffeType(), getReverseBuilder(), GradientUtils::getShadowType(), getUndefinedValueForType(), getUnqual(), GradientUtils::getWidth(), handleAdjointForIntrinsic(), handleMPI(), hasMetadata(), hasSingleGCPreserveEnd(), GradientUtils::invertedPointers, GradientUtils::invertPointerM(), DifferentialUseAnalysis::is_value_needed_in_reverse(), isAllocationFunction(), GradientUtils::isConstantInstruction(), GradientUtils::isConstantValue(), isMemFreeLibMFunction(), GradientUtils::knownRecomputeHeuristic, GradientUtils::legalRecompute(), lookup(), GradientUtils::lookupM(), looseTypeAnalysis, MixedActivityError, MixedActivityHint, MPIInactiveCommAllocators, CacheUtility::newFunc, None, GradientUtils::oldFunc, Pointer, GradientUtils::populateSeenFromKnownRecompute(), Primal, GradientUtils::rematerializableAllocations, GradientUtils::rematerializedPrimalOrShadowAllocations, GradientUtils::replaceAWithB(), resolveShadowPlaceholder(), GradientUtils::reverseBlocks, GradientUtils::reverseBlockToPrimal, ReverseModeCombined, ReverseModeGradient, ReverseModePrimal, GradientUtils::runtimeActivity, Self, setDiffe(), Shadow, shadowHandlers, shadowStoreSchedule(), shouldFree(), startsWith(), str(), Tape, GradientUtils::TapesToPreventRecomputation, CacheUtility::TLI, GradientUtils::unnecessaryIntermediates, and zeroKnownAllocation().
Referenced by visitCallInst().
| void AdjointGenerator::handleMPI | ( | llvm::CallInst & | call, |
| llvm::Function * | called, | ||
| llvm::StringRef | funcName ) |
Definition at line 95 of file CallDerivatives.cpp.
References GradientUtils::addReverseBlock(), GradientUtils::cacheForReverse(), canonicalizeMPIName(), CreateAllocation(), CreateDealloc(), createMPIForwardCall(), CreateSelect(), DifferentiableMemCopyFloats(), EmitNoDerivativeError(), eraseIfUnused(), TypeResults::firstPointer(), ForwardMode, ForwardModeError, ForwardModeSplit, getFast(), getForwardBuilder(), getInt8PtrTy(), getIntrinsicDeclaration(), GradientUtils::getInvertedBundles(), getMPIHelper(), getMPIMemberPtr(), GradientUtils::getNewFromOriginal(), getOrInsertDifferentialMPI_Wait(), getOrInsertDifferentialWaitallSave(), getOrInsertOpFloatSum(), getRenamedPerCallingConv(), getReverseBuilder(), getUnqual(), GradientUtils::getWidth(), CacheUtility::inversionAllocs, GradientUtils::invertPointerM(), IRECV, GradientUtils::isConstantInstruction(), GradientUtils::isConstantValue(), ISEND, isFortranMPICall(), isSum(), lookup(), MPI_COMM_RANK(), MPI_COMM_SIZE(), MPI_TYPE_SIZE(), MPIInactiveCommAllocators, CacheUtility::newFunc, None, GradientUtils::oldFunc, Primal, GradientUtils::reverseBlocks, GradientUtils::reverseBlockToPrimal, ReverseModeCombined, ReverseModeGradient, ReverseModePrimal, Shadow, shouldFree(), Tape, and GradientUtils::TapesToPreventRecomputation.
Referenced by handleKnownCallDerivatives().
|
inline |
Definition at line 2445 of file AdjointGenerator.h.
References GradientUtils::lookupM().
Referenced by addAtomicRMWValueAdjoint(), createBinaryOperatorAdjoint(), createSelectInstAdjoint(), handleAdjointForIntrinsic(), handleKnownCallDerivatives(), handleMPI(), recursivelyHandleSubfunction(), visitBinaryOperator(), visitCommonStore(), visitInsertElementInst(), visitLoadLike(), and visitOMPCall().
|
inline |
Definition at line 315 of file AdjointGenerator.h.
References addFunctionNoCapture(), getInt8PtrTy(), getRenamedPerCallingConv(), getUnqual(), CacheUtility::inversionAllocs, and isFortranMPICall().
Referenced by handleMPI().
|
inline |
Definition at line 370 of file AdjointGenerator.h.
References addFunctionNoCapture(), getInt8PtrTy(), getRenamedPerCallingConv(), getUnqual(), CacheUtility::inversionAllocs, and isFortranMPICall().
Referenced by handleMPI().
|
inline |
Definition at line 230 of file AdjointGenerator.h.
References addFunctionNoCapture(), getInt8PtrTy(), getRenamedPerCallingConv(), getUnqual(), CacheUtility::inversionAllocs, and isFortranMPICall().
Referenced by handleMPI().
|
inline |
We only need the shadow pointer for non-forward Mode if it is used in a non return setting
topLevel
Definition at line 5230 of file AdjointGenerator.h.
References TypeResults::addingType(), addToDiffe(), TypeResults::analyzer, TypeResults::anyPointer(), GradientUtils::AtomicAdd, GradientUtils::backwardsOnlyShadows, Both, GradientUtils::cacheForReverse(), CONSTANT, AugmentedReturn::constant_args, convertSRetTypeToString(), EnzymeLogic::CreateAugmentedPrimal(), CreateDealloc(), EnzymeLogic::CreateForwardDiff(), EnzymeLogic::CreatePrimalAndGradient(), CustomErrorHandler, diffe(), DifferentialReturn, dumpMap(), DUP_ARG, DUP_NONEED, EmitFailure(), EmitNoDerivativeError(), GradientUtils::erase(), eraseIfUnused(), ErrorIfRuntimeInactive(), GradientUtils::fictiousPHIs, AugmentedReturn::fn, ForwardMode, ForwardModeError, ForwardModeSplit, getBaseObject(), TypeResults::getCallInfo(), getDefaultFunctionTypeForAugmentation(), getDefaultFunctionTypeForGradient(), GradientUtils::getDiffeType(), getFast(), getForwardBuilder(), getFuncNameFromCall(), getFunctionTypeForClone(), getInt8PtrTy(), GradientUtils::getInvertedBundles(), GradientUtils::getNewFromOriginal(), getPointerType(), getReverseBuilder(), GradientUtils::getShadowType(), getUndefinedValueForType(), getUnqual(), GradientUtils::getWidth(), IndexMappingError, insert_or_assign2(), InternalError, TypeAnalyzer::interprocedural, GradientUtils::invertedPointers, GradientUtils::invertPointerM(), DifferentialUseAnalysis::is_value_needed_in_reverse(), isAllocationCall(), GradientUtils::isConstantInstruction(), GradientUtils::isConstantValue(), isMemFreeLibMFunction(), isNoCapture(), GradientUtils::isOriginal(), isReadOnly(), isWriteOnly(), GradientUtils::knownRecomputeHeuristic, legalCombinedForwardReverse(), GradientUtils::Logic, lookup(), GradientUtils::lookupM(), CacheUtility::newFunc, GradientUtils::newToOriginalFn, None, GradientUtils::nowrite_shadows, GradientUtils::oldFunc, GradientUtils::originalToNewFn, OUT_DIFF, Pointer, GradientUtils::populateSeenFromKnownRecompute(), Primal, PrimalParamAttrsToPreserve, TypeResults::query(), GradientUtils::replaceAndRemoveUnwrapCacheFor(), GradientUtils::replaceAWithB(), Return, AugmentedReturn::returns, ReverseModeCombined, ReverseModeGradient, ReverseModePrimal, GradientUtils::runtimeActivity, Self, setDiffe(), Shadow, ShadowParamAttrsToPreserve, shouldAugmentCall(), shouldDisableNoWrite(), shouldFree(), str(), GradientUtils::strongZero, AugmentedReturn::subaugmentations, Tape, GradientUtils::TapesToPreventRecomputation, AugmentedReturn::tapeType, CacheUtility::TLI, to_string(), GradientUtils::unnecessaryIntermediates, and whatType().
Referenced by visitCallInst().
|
inline |
Resolve the shadow placeholder of the active instruction I in a pass which does not otherwise compute its shadow, replacing it by the given value (a zero shadow if null).
Definition at line 168 of file AdjointGenerator.h.
References GradientUtils::erase(), GradientUtils::getShadowType(), GradientUtils::invertedPointers, and GradientUtils::replaceAWithB().
Referenced by handleKnownCallDerivatives().
|
inlinestatic |
The ordering with which the reverse pass may read a location that the primal modified atomically with the given ordering.
Definition at line 186 of file AdjointGenerator.h.
Referenced by addAtomicRMWValueAdjoint().
|
inline |
Definition at line 2401 of file AdjointGenerator.h.
References ReverseModePrimal.
Referenced by createBinaryOperatorAdjoint(), createBinaryOperatorDual(), createSelectInstAdjoint(), handleAdjointForIntrinsic(), handleKnownCallDerivatives(), recursivelyHandleSubfunction(), visitAtomicRMWInst(), visitCastInst(), visitExtractElementInst(), visitExtractValueInst(), visitInsertElementInst(), visitInsertValueInst(), visitInstruction(), and visitShuffleVectorInst().
|
inline |
Which pass(es) emit the shadow counterpart of the store-like instruction I into the duplicated memory at orig_ptr: the augmented primal (forwardsShadow) and/or the reverse pass (backwardsShadow, for shadow allocations only materialized there), and neither of them for shadow arguments that must not be written.
Definition at line 140 of file AdjointGenerator.h.
References GradientUtils::backwardsOnlyShadows, getBaseObject(), and GradientUtils::nowrite_shadows.
Referenced by handleKnownCallDerivatives(), visitCommonStore(), visitMemSetCommon(), and visitMemTransferCommon().
|
inline |
Definition at line 2431 of file AdjointGenerator.h.
References ForwardModeSplit, ReverseModeCombined, and ReverseModeGradient.
Referenced by handleKnownCallDerivatives(), handleMPI(), recursivelyHandleSubfunction(), and visitOMPCall().
|
inline |
Definition at line 506 of file AdjointGenerator.h.
References eraseIfUnused(), ForwardMode, ForwardModeError, forwardModeInvertedPointerFallback(), and ForwardModeSplit.
|
inline |
Definition at line 908 of file AdjointGenerator.h.
References addAtomicRMWValueAdjoint(), applyChainRule(), EmitNoDerivativeError(), eraseIfUnused(), TypeResults::firstPointer(), ForwardMode, ForwardModeError, ForwardModeSplit, getForwardBuilder(), GradientUtils::getNewFromOriginal(), GradientUtils::getShadowType(), GradientUtils::invertPointerM(), GradientUtils::isConstantInstruction(), GradientUtils::isConstantValue(), looseTypeAnalysis, CacheUtility::newFunc, TypeResults::query(), ReverseModeCombined, ReverseModeGradient, ReverseModePrimal, and setDiffe().
|
inline |
Definition at line 2449 of file AdjointGenerator.h.
References addToDiffe(), applyChainRule(), createBinaryOperatorAdjoint(), createBinaryOperatorDual(), CreateSelect(), diffe(), eraseIfUnused(), LoopContext::exitBlocks, ForwardMode, ForwardModeError, ForwardModeSplit, GradientUtils::getContext(), GradientUtils::getNewFromOriginal(), GradientUtils::getOriginalFromNew(), GradientUtils::getOrInsertTotalMultiplicativeProduct(), getReverseBuilder(), LoopContext::header, GradientUtils::isConstantInstruction(), GradientUtils::isConstantValue(), lookup(), GradientUtils::OrigLI, OUT_DIFF, LoopContext::preheader, ReverseModeCombined, ReverseModeGradient, ReverseModePrimal, and GradientUtils::strongZero.
|
inline |
Definition at line 6595 of file AdjointGenerator.h.
References GradientUtils::cacheForReverse(), DifferentialUseAnalysis::callShouldNotUseDerivative(), EnzymeLogic::CreateNoFree(), customCallHandlers, customFwdCallHandlers, EmitWarning(), EnzymeGlobalActivity, EnzymeJuliaAddrLoad, GradientUtils::erase(), eraseIfUnused(), ForwardMode, ForwardModeError, ForwardModeSplit, getBaseObject(), getFast(), getFuncNameFromCall(), getFunctionFromCall(), GradientUtils::getNewFromOriginal(), GradientUtils::getReturnDiffeType(), getReverseBuilder(), GradientUtils::getShadowType(), handleAdjointForIntrinsic(), handleKnownCallDerivatives(), IndexMappingError, insert_or_assign2(), GradientUtils::invertedPointers, DifferentialUseAnalysis::is_value_needed_in_reverse(), isAllocationCall(), GradientUtils::isConstantInstruction(), GradientUtils::isConstantValue(), isSpecialPtr(), GradientUtils::knownRecomputeHeuristic, GradientUtils::legalRecompute(), GradientUtils::Logic, GradientUtils::lookupM(), GradientUtils::populateSeenFromKnownRecompute(), Primal, TypeResults::query(), recursivelyHandleSubfunction(), GradientUtils::replaceAWithB(), ReverseModeCombined, ReverseModeGradient, ReverseModePrimal, Self, Shadow, startsWith(), AugmentedReturn::subaugmentations, Tape, AugmentedReturn::tapeIndices, CacheUtility::TLI, GradientUtils::unnecessaryIntermediates, visitIntrinsicInst(), and visitOMPCall().
|
inline |
Definition at line 1526 of file AdjointGenerator.h.
References TypeResults::addingType(), addToDiffe(), applyChainRule(), diffe(), EmitNoDerivativeError(), EmitNoTypeError(), EmitWarning(), eraseIfUnused(), ForwardMode, ForwardModeError, forwardModeInvertedPointerFallback(), ForwardModeSplit, GradientUtils::getNewFromOriginal(), getReverseBuilder(), GradientUtils::getShadowType(), Integer, GradientUtils::isConstantInstruction(), GradientUtils::isConstantValue(), looseTypeAnalysis, CacheUtility::newFunc, TypeResults::query(), ReverseModeCombined, ReverseModeGradient, ReverseModePrimal, setDiffe(), and str().
|
inline |
Storing a floating point value
Only need to update the reverse function
Storing an integer or pointer
Only need to update the forward function
Definition at line 1073 of file AdjointGenerator.h.
References GradientUtils::addReverseBlock(), Anything, applyChainRule(), CustomErrorHandler, defaultTypeTreeForLLVM(), EmitNoTypeError(), EmitWarning(), EmitWarningAlways(), EmitWarningEnabled(), GradientUtils::extractMeta(), ForwardMode, ForwardModeError, ForwardModeSplit, getBaseObject(), GradientUtils::getDerivativeAliasScope(), getFast(), getIntrinsicDeclaration(), GradientUtils::getNewFromOriginal(), getReverseBuilder(), GradientUtils::getShadowType(), GradientUtils::getWidth(), Integer, GradientUtils::invertPointerM(), isAllocationCall(), GradientUtils::isConstantValue(), ConcreteType::isFloat(), ConcreteType::isKnown(), TypeTree::Lookup(), lookup(), looseTypeAnalysis, MixedActivityError, MixedActivityHint, CacheUtility::newFunc, GradientUtils::oldFunc, parseTBAA(), Pointer, TypeResults::query(), ReverseModeCombined, ReverseModeGradient, ReverseModePrimal, GradientUtils::runtimeActivity, GradientUtils::setPtrDiffe(), shadowStoreSchedule(), str(), and CacheUtility::TLI.
Referenced by handleAdjointForIntrinsic(), and visitStoreInst().
|
inline |
Definition at line 1770 of file AdjointGenerator.h.
References TypeResults::addingType(), diffe(), eraseIfUnused(), GradientUtils::extractMeta(), ForwardMode, ForwardModeError, forwardModeInvertedPointerFallback(), ForwardModeSplit, GradientUtils::getNewFromOriginal(), getReverseBuilder(), GradientUtils::getShadowType(), GradientUtils::getWidth(), GradientUtils::isConstantInstruction(), GradientUtils::isConstantValue(), CacheUtility::newFunc, ReverseModeCombined, ReverseModeGradient, ReverseModePrimal, and setDiffe().
|
inline |
Definition at line 1991 of file AdjointGenerator.h.
References Anything, diffe(), EmitNoTypeError(), eraseIfUnused(), ForwardMode, ForwardModeError, forwardModeInvertedPointerFallback(), ForwardModeSplit, getReverseBuilder(), GradientUtils::getShadowType(), Integer, GradientUtils::isConstantInstruction(), GradientUtils::isConstantValue(), looseTypeAnalysis, CacheUtility::newFunc, GradientUtils::oldFunc, TypeResults::query(), ReverseModeCombined, ReverseModeGradient, ReverseModePrimal, setDiffe(), and str().
|
inline |
Definition at line 522 of file AdjointGenerator.h.
References eraseIfUnused().
|
inline |
Definition at line 4007 of file AdjointGenerator.h.
References EnzymeJuliaAddrLoad, eraseIfUnused(), getReverseBuilder(), ReverseModeCombined, and ReverseModeGradient.
|
inline |
Definition at line 1494 of file AdjointGenerator.h.
References eraseIfUnused(), ForwardMode, ForwardModeError, forwardModeInvertedPointerFallback(), and ForwardModeSplit.
|
inline |
Definition at line 520 of file AdjointGenerator.h.
References eraseIfUnused().
|
inline |
Definition at line 1827 of file AdjointGenerator.h.
References TypeResults::addingType(), addToDiffe(), diffe(), eraseIfUnused(), GradientUtils::extractMeta(), ForwardMode, ForwardModeError, forwardModeInvertedPointerFallback(), ForwardModeSplit, GradientUtils::getNewFromOriginal(), getReverseBuilder(), GradientUtils::getShadowType(), GradientUtils::getWidth(), GradientUtils::isConstantInstruction(), GradientUtils::isConstantValue(), lookup(), CacheUtility::newFunc, ReverseModeCombined, ReverseModeGradient, ReverseModePrimal, and setDiffe().
|
inline |
Definition at line 2100 of file AdjointGenerator.h.
References Anything, applyChainRule(), diffe(), EmitNoTypeError(), eraseIfUnused(), ForwardMode, ForwardModeError, forwardModeInvertedPointerFallback(), ForwardModeSplit, getReverseBuilder(), GradientUtils::getShadowType(), hasMetadata(), TypeResults::intType(), GradientUtils::isConstantValue(), looseTypeAnalysis, CacheUtility::newFunc, parseTrueType(), Pointer, TypeResults::query(), ReverseModeCombined, ReverseModeGradient, ReverseModePrimal, setDiffe(), and str().
|
inline |
Definition at line 425 of file AdjointGenerator.h.
References EmitNoDerivativeError(), eraseIfUnused(), ForwardMode, ForwardModeError, ForwardModeSplit, getForwardBuilder(), GradientUtils::getNewFromOriginal(), GradientUtils::getShadowType(), GradientUtils::isConstantInstruction(), GradientUtils::isConstantValue(), ReverseModePrimal, setDiffe(), and to_string().
|
inline |
Definition at line 4049 of file AdjointGenerator.h.
References GradientUtils::cacheForReverse(), eraseIfUnused(), ForwardMode, ForwardModeError, forwardModeInvertedPointerFallback(), ForwardModeSplit, getFast(), GradientUtils::getNewFromOriginal(), handleAdjointForIntrinsic(), isIntelSubscriptIntrinsic(), GradientUtils::knownRecomputeHeuristic, Self, and visitMemSetCommon().
Referenced by visitCallInst().
|
inline |
Definition at line 881 of file AdjointGenerator.h.
References eraseIfUnused(), CacheUtility::newFunc, parseTBAA(), and visitLoadLike().
|
inline |
Store inverted pointer loads that need to be cached for use in reverse pass
Store loads that need to be cached for use in reverse pass
Definition at line 524 of file AdjointGenerator.h.
References addToDiffe(), applyChainRule(), GradientUtils::cacheForReverse(), GradientUtils::can_modref_map, CreateSelect(), defaultTypeTreeForLLVM(), diffe(), EmitNoTypeError(), EmitWarning(), EmitWarningEnabled(), GradientUtils::erase(), ForwardMode, ForwardModeError, ForwardModeSplit, GradientUtils::getDerivativeAliasScope(), GradientUtils::getNewFromOriginal(), getReverseBuilder(), GradientUtils::getShadowType(), GradientUtils::getWidth(), hasMetadata(), GradientUtils::invertedPointers, GradientUtils::invertPointerM(), DifferentialUseAnalysis::is_value_needed_in_reverse(), GradientUtils::isConstantInstruction(), GradientUtils::isConstantValue(), GradientUtils::knownRecomputeHeuristic, lookup(), looseTypeAnalysis, CacheUtility::newFunc, nonmarkedglobals_inactiveloads, GradientUtils::populateSeenFromKnownRecompute(), Primal, TypeResults::query(), ReverseModeCombined, ReverseModeGradient, ReverseModePrimal, GradientUtils::runtimeActivity, Self, Shadow, str(), and GradientUtils::unnecessaryIntermediates.
Referenced by handleAdjointForIntrinsic(), and visitLoadInst().
|
inline |
Definition at line 3138 of file AdjointGenerator.h.
References GradientUtils::allocationsToBeRematerialized, applyChainRule(), TypeTree::Data0(), TypeResults::dump(), EmitNoDerivativeError(), EmitNoTypeError(), EmitWarning(), eraseIfUnused(), ForwardMode, ForwardModeError, ForwardModeSplit, getBaseObject(), getForwardBuilder(), getFuncNameFromCall(), GradientUtils::getInvertedBundles(), GradientUtils::getNewFromOriginal(), getReverseBuilder(), hasMetadata(), Integer, GradientUtils::invertPointerM(), isAllocationCall(), GradientUtils::isConstantValue(), GradientUtils::lookupM(), looseTypeAnalysis, MD_ToCopy, CacheUtility::newFunc, TypeTree::Only(), parseTrueType(), Pointer, Primal, TypeResults::query(), GradientUtils::rematerializableAllocations, ReverseModeCombined, ReverseModeGradient, ReverseModePrimal, Shadow, shadowStoreSchedule(), TypeTree::ShiftIndices(), sliceTrueType(), startsWith(), str(), and CacheUtility::TLI.
Referenced by visitIntrinsicInst(), and visitMemSetInst().
|
inline |
Definition at line 3136 of file AdjointGenerator.h.
References visitMemSetCommon().
|
inline |
Definition at line 3626 of file AdjointGenerator.h.
References Anything, applyChainRule(), TypeTree::Data0(), TypeResults::dump(), EmitNoTypeError(), EmitWarning(), eraseIfUnused(), ForwardMode, ForwardModeError, getInt8PtrTy(), GradientUtils::getNewFromOriginal(), hasMetadata(), Integer, GradientUtils::invertPointerM(), GradientUtils::isConstantValue(), looseTypeAnalysis, CacheUtility::newFunc, TypeTree::Only(), TypeTree::parse(), parseTrueType(), Pointer, TypeTree::PurgeAnything(), TypeResults::query(), GradientUtils::runtimeActivity, shadowStoreSchedule(), TypeTree::ShiftIndices(), sliceTrueType(), str(), SubTransferHelper(), and Unknown.
Referenced by visitMemTransferInst().
|
inline |
Definition at line 3615 of file AdjointGenerator.h.
References GradientUtils::getNewFromOriginal(), and visitMemTransferCommon().
|
inline |
Definition at line 4464 of file AdjointGenerator.h.
References TypeResults::addingType(), TypeResults::analyzer, FnTypeInfo::Arguments, GradientUtils::backwardsOnlyShadows, GradientUtils::cacheForReverse(), CONSTANT, AugmentedReturn::constant_args, EnzymeLogic::CreateAugmentedPrimal(), CreateDealloc(), EnzymeLogic::CreatePrimalAndGradient(), DifferentialReturn, DUP_ARG, DUP_NONEED, GradientUtils::erase(), eraseIfUnused(), AugmentedReturn::fn, ForwardModeSplit, getBaseObject(), GradientUtils::getDiffeType(), getFast(), getFuncNameFromCall(), GradientUtils::getNewFromOriginal(), getPointerType(), getReverseBuilder(), getUnqual(), GradientUtils::getWidth(), TypeTree::insert(), insert_or_assign2(), Integer, TypeAnalyzer::interprocedural, IntToFloatTy(), CacheUtility::inversionAllocs, GradientUtils::invertPointerM(), isAllocationCall(), GradientUtils::isConstantValue(), isMemFreeLibMFunction(), TypeResults::knownIntegralValues(), FnTypeInfo::KnownValues, LegalFullUnwrap, GradientUtils::Logic, lookup(), CacheUtility::newFunc, GradientUtils::nowrite_shadows, GradientUtils::oldFunc, OUT_DIFF, Pointer, TypeResults::query(), Return, FnTypeInfo::Return, AugmentedReturn::returns, ReverseModeCombined, ReverseModeGradient, ReverseModePrimal, GradientUtils::runtimeActivity, shouldFree(), GradientUtils::strongZero, AugmentedReturn::subaugmentations, Tape, AugmentedReturn::tapeIndices, AugmentedReturn::tapeIndiciesToFree, AugmentedReturn::tapeType, CacheUtility::TLI, GradientUtils::unwrapM(), GradientUtils::unwrappedLoads, and whatType().
Referenced by visitCallInst().
|
inline |
Definition at line 1508 of file AdjointGenerator.h.
References eraseIfUnused(), ForwardMode, ForwardModeError, forwardModeInvertedPointerFallback(), ForwardModeSplit, ReverseModeCombined, ReverseModeGradient, and ReverseModePrimal.
|
inline |
Definition at line 1638 of file AdjointGenerator.h.
References createSelectInstAdjoint(), eraseIfUnused(), ForwardMode, ForwardModeError, forwardModeInvertedPointerFallback(), ForwardModeSplit, GradientUtils::isConstantInstruction(), ReverseModeCombined, ReverseModeGradient, and ReverseModePrimal.
|
inline |
Definition at line 1920 of file AdjointGenerator.h.
References TypeResults::addingType(), diffe(), eraseIfUnused(), GradientUtils::extractMeta(), ForwardMode, ForwardModeError, forwardModeInvertedPointerFallback(), ForwardModeSplit, getReverseBuilder(), GradientUtils::getShadowType(), GradientUtils::getWidth(), GradientUtils::isConstantInstruction(), GradientUtils::isConstantValue(), CacheUtility::newFunc, ReverseModeCombined, ReverseModeGradient, ReverseModePrimal, and setDiffe().
|
inline |
Definition at line 1028 of file AdjointGenerator.h.
References GradientUtils::allocationsToBeRematerialized, eraseIfUnused(), GradientUtils::rematerializableAllocations, ReverseModeGradient, and visitCommonStore().