|
Enzyme main
|
#include <cstdint>#include <deque>#include <llvm/Config/llvm-config.h>#include <memory>#include "llvm/ADT/ArrayRef.h"#include "llvm/ADT/ImmutableSet.h"#include "llvm/ADT/SmallSet.h"#include "llvm/ADT/StringMap.h"#include "llvm/ADT/StringSet.h"#include "llvm/ADT/STLExtras.h"#include "llvm/IR/Constants.h"#include "llvm/IR/Function.h"#include "llvm/IR/InstrTypes.h"#include "llvm/IR/Instructions.h"#include "llvm/IR/IntrinsicInst.h"#include "llvm/IR/Type.h"#include "llvm/IR/Value.h"#include "llvm/IR/InstIterator.h"#include "llvm/Support/CommandLine.h"#include "llvm/Support/ErrorOr.h"#include "llvm/Support/FileSystem.h"#include "llvm/Support/MemoryBuffer.h"#include "llvm/Support/TimeProfiler.h"#include "llvm/Support/raw_ostream.h"#include "llvm/IR/InlineAsm.h"#include "ActivityAnalysis.h"#include "Utils.h"#include "llvm/Demangle/Demangle.h"#include "FunctionUtils.h"#include "LibraryFuncs.h"#include "TypeAnalysis/TBAA.h"#include "llvm/Analysis/ValueTracking.h"#include <map>#include <set>#include <unordered_map>#include "ActivityAnalysis.h"#include "Dialect/Dialect.h"#include "Interfaces/GradientUtils.h"#include "Interfaces/Utils.h"#include "mlir/Dialect/Func/IR/FuncOps.h"#include "mlir/Dialect/LLVMIR/LLVMDialect.h"#include "mlir/Dialect/LLVMIR/LLVMTypes.h"#include "mlir/Dialect/MemRef/IR/MemRef.h"#include "mlir/IR/BuiltinAttributes.h"#include "mlir/IR/Matchers.h"#include "mlir/IR/Region.h"#include "mlir/IR/RegionKindInterface.h"#include "mlir/IR/SymbolTable.h"#include "mlir/Interfaces/CallInterfaces.h"#include "mlir/Interfaces/CastInterfaces.h"#include "mlir/Interfaces/ControlFlowInterfaces.h"#include "mlir/Interfaces/SideEffectInterfaces.h"#include "mlir/Interfaces/ViewLikeInterface.h"#include "llvm/IR/Intrinsics.h"#include "llvm/Support/ModRef.h"#include "Interfaces/AutoDiffOpInterface.h"Go to the source code of this file.
Macros | |
| #define | addAttribute addAttributeAtIndex |
| #define | removeAttribute removeAttributeAtIndex |
| #define | getAttribute getAttributeAtIndex |
| #define | hasAttribute hasAttributeAtIndex |
Functions | |
| cl::opt< bool > | EnzymePrintActivity ("enzyme-print-activity", cl::init(false), cl::Hidden, cl::desc("Print activity analysis algorithm")) |
| cl::opt< bool > | EnzymeNonmarkedGlobalsInactive ("enzyme-globals-default-inactive", cl::init(false), cl::Hidden, cl::desc("Consider all nonmarked globals to be inactive")) |
| cl::opt< bool > | EnzymeEmptyFnInactive ("enzyme-emptyfn-inactive", cl::init(false), cl::Hidden, cl::desc("Empty functions are considered inactive")) |
| cl::opt< bool > | EnzymeGlobalActivity ("enzyme-global-activity", cl::init(false), cl::Hidden, cl::desc("Enable correct global activity analysis")) |
| cl::opt< bool > | EnzymeDisableActivityAnalysis ("enzyme-disable-activity-analysis", cl::init(false), cl::Hidden, cl::desc("Disable activity analysis")) |
| cl::opt< bool > | EnzymeEnableRecursiveHypotheses ("enzyme-enable-recursive-activity", cl::init(true), cl::Hidden, cl::desc("Enable re-evaluation of activity analysis from updated results")) |
| cl::list< std::string > | EnzymeLoadInactiveFiles ("enzyme-load-inactive-file", llvm::cl::ZeroOrMore, llvm::cl::Hidden, llvm::cl::desc("Load additional inactive functions from file"), llvm::cl::value_desc("File Name")) |
| bool | isInactiveCall (CallBase &CI) |
| Return whether the call is always inactive by definition. | |
| bool | isInactiveCallInst (CallBase &CB, llvm::TargetLibraryInfo &TLI) |
| static void | propagateArgumentInformation (TargetLibraryInfo &TLI, CallInst &CI, llvm::function_ref< bool(Value *)> propagateFromOperand) |
| Call the function propagateFromOperand on all operands of CI that could impact the activity of the call instruction. | |
| bool | isValuePotentiallyUsedAsPointer (llvm::Value *val) |
| std::optional< Value > | getStored (Operation *op) |
| static Operation * | getFunctionFromCall (CallOpInterface iface) |
| static bool | isReadOnly (Operation *op) |
| static bool | isFunctionReturn (Operation *op) |
| static bool | isValuePotentiallyUsedAsPointer (Value val) |
| static bool | mayAllocateMemory (Operation *op) |
| static bool | mayReadFromMemory (Operation *op) |
| static bool | mayWriteToMemory (Operation *op) |
| static FunctionOpInterface | getFunctionIfArgument (Value value) |
| static std::optional< SmallVector< Value > > | getPotentialTerminatorUsers (Operation *op, Value parent) |
| static SmallVector< Value > | getPotentialIncomingValues (OpResult res) |
| static SmallVector< Value > | getPotentialIncomingValues (BlockArgument arg) |
| static Operation * | getAncestorInRegion (Operation *op, Region *region) |
Return an ancestor of op that resides in the given region or nullptr if there is no such ancestor. | |
| static void | allFollowersOf (Operation *op, function_ref< WalkResult(Operation *)> f) |
Call f on all operations that may be executed after op. | |
Variables | ||
| static const StringSet | InactiveGlobals | |
| const llvm::StringMap< size_t > | MPIInactiveCommAllocators | |
| struct { | ||
| bool cached = false | ||
| SmallVector< StringRef, 128 > functionNames | ||
| SmallVector< std::unique_ptr< MemoryBuffer >, 8 > contents | ||
| } | InactiveFileCache | |
| Cache if a file is loaded with inactive demangled function names. | ||
| static const char * | KnownInactiveFunctionsStartingWith [] | |
| static const char * | KnownInactiveFunctionsContains [] | |
| static const std::set< std::string > | InactiveGlobals | |
| static const std::set< std::string > | KnownInactiveFunctionInsts | |
| static const std::set< std::string > | KnownInactiveFunctions | |
| static const char * | DemangledKnownInactiveFunctionsStartingWith [] | |
| static const unsigned | constantIntrinsics [] | |
| constexpr bool | EnzymePrintActivity = false | |
| #define addAttribute addAttributeAtIndex |
| #define getAttribute getAttributeAtIndex |
| #define hasAttribute hasAttributeAtIndex |
| #define removeAttribute removeAttributeAtIndex |
|
static |
Call f on all operations that may be executed after op.
Definition at line 1403 of file ActivityAnalysis.cpp.
References getAncestorInRegion().
Referenced by mlir::enzyme::ActivityAnalyzer::isConstantValue().
| cl::opt< bool > EnzymeDisableActivityAnalysis | ( | "enzyme-disable-activity-analysis" | , |
| cl::init(false) | , | ||
| cl::Hidden | , | ||
| cl::desc("Disable activity analysis") | ) |
| cl::opt< bool > EnzymeEmptyFnInactive | ( | "enzyme-emptyfn-inactive" | , |
| cl::init(false) | , | ||
| cl::Hidden | , | ||
| cl::desc("Empty functions are considered inactive") | ) |
| cl::opt< bool > EnzymeEnableRecursiveHypotheses | ( | "enzyme-enable-recursive-activity" | , |
| cl::init(true) | , | ||
| cl::Hidden | , | ||
| cl::desc("Enable re-evaluation of activity analysis from updated results") | ) |
| cl::opt< bool > EnzymeGlobalActivity | ( | "enzyme-global-activity" | , |
| cl::init(false) | , | ||
| cl::Hidden | , | ||
| cl::desc("Enable correct global activity analysis") | ) |
| cl::list< std::string > EnzymeLoadInactiveFiles | ( | "enzyme-load-inactive-file" | , |
| llvm::cl::ZeroOrMore | , | ||
| llvm::cl::Hidden | , | ||
| llvm::cl::desc("Load additional inactive functions from file") | , | ||
| llvm::cl::value_desc("File Name") | ) |
| cl::opt< bool > EnzymeNonmarkedGlobalsInactive | ( | "enzyme-globals-default-inactive" | , |
| cl::init(false) | , | ||
| cl::Hidden | , | ||
| cl::desc("Consider all nonmarked globals to be inactive") | ) |
| cl::opt< bool > EnzymePrintActivity | ( | "enzyme-print-activity" | , |
| cl::init(false) | , | ||
| cl::Hidden | , | ||
| cl::desc("Print activity analysis algorithm") | ) |
|
static |
Return an ancestor of op that resides in the given region or nullptr if there is no such ancestor.
Definition at line 1395 of file ActivityAnalysis.cpp.
Referenced by allFollowersOf().
|
static |
Definition at line 464 of file ActivityAnalysis.cpp.
Referenced by copy_lower_to_upper(), fixSparse_inner(), getOrInsertExponentialAllocator(), TraceGenerator::handleArbitraryCall(), isAllocationCall(), ActivityAnalyzer::isConstantInstruction(), mlir::enzyme::ActivityAnalyzer::isConstantOperation(), mlir::enzyme::ActivityAnalyzer::isConstantValue(), TraceUtils::isObserveCall(), isProduct(), TraceUtils::isSampleCall(), isSum(), mlir::enzyme::ActivityAnalyzer::isValueInactiveFromUsers(), TypeAnalyzer::run(), TypeAnalyzer::visitCallBase(), AdjointGenerator::visitCallInst(), InstructionBatcher::visitCallInst(), and TraceGenerator::visitCallInst().
|
static |
Definition at line 1132 of file ActivityAnalysis.cpp.
Referenced by mlir::enzyme::ActivityAnalyzer::isConstantValue().
|
static |
Definition at line 1279 of file ActivityAnalysis.cpp.
|
static |
Definition at line 1214 of file ActivityAnalysis.cpp.
Referenced by mlir::enzyme::ActivityAnalyzer::isConstantValue().
|
static |
Definition at line 1148 of file ActivityAnalysis.cpp.
References isFunctionReturn().
Referenced by mlir::enzyme::ActivityAnalyzer::isValueInactiveFromUsers().
| std::optional< Value > getStored | ( | Operation * | op | ) |
Definition at line 204 of file DataFlowActivityAnalysis.cpp.
Referenced by mlir::enzyme::DataFlowActivityAnalyzer::isInactiveOperation(), mlir::enzyme::DenseActivityAnnotationAnalysis::visitOperation(), mlir::enzyme::DenseBackwardActivityAnalysis::visitOperation(), mlir::enzyme::DenseBackwardActivityAnnotationAnalysis::visitOperation(), mlir::enzyme::DenseForwardActivityAnalysis::visitOperation(), and mlir::enzyme::PointsToPointerAnalysis::visitOperation().
|
static |
Definition at line 1044 of file ActivityAnalysis.cpp.
References mlir::enzyme::isFunctionReturnLike().
Referenced by getPotentialTerminatorUsers(), mlir::enzyme::ActivityAnalyzer::isValueInactiveFromUsers(), and isValuePotentiallyUsedAsPointer().
| bool isInactiveCall | ( | CallBase & | CI | ) |
Return whether the call is always inactive by definition.
Definition at line 227 of file ActivityAnalysis.cpp.
| bool isInactiveCallInst | ( | CallBase & | CB, |
| llvm::TargetLibraryInfo & | TLI ) |
Definition at line 677 of file ActivityAnalysis.cpp.
|
static |
Definition at line 474 of file ActivityAnalysis.cpp.
References isReadOnly().
Referenced by DetectPointerArgOfFn(), fixSparse_inner(), fixSparseIndices(), isReadOnly(), mlir::enzyme::ActivityAnalyzer::isReadOnly(), mlir::enzyme::ActivityAnalyzer::isValueInactiveFromUsers(), and AdjointGenerator::recursivelyHandleSubfunction().
| bool isValuePotentiallyUsedAsPointer | ( | llvm::Value * | val | ) |
Definition at line 1276 of file ActivityAnalysis.cpp.
Referenced by mlir::enzyme::ActivityAnalyzer::isConstantValue().
|
static |
Definition at line 1050 of file ActivityAnalysis.cpp.
References EnzymePrintActivity, and isFunctionReturn().
|
static |
Definition at line 1114 of file ActivityAnalysis.cpp.
Referenced by mlir::enzyme::ActivityAnalyzer::isConstantValue().
|
static |
Definition at line 1120 of file ActivityAnalysis.cpp.
Referenced by mlir::enzyme::ActivityAnalyzer::isConstantValue().
|
static |
Definition at line 1126 of file ActivityAnalysis.cpp.
Referenced by mlir::enzyme::ActivityAnalyzer::isConstantValue().
|
inlinestatic |
Call the function propagateFromOperand on all operands of CI that could impact the activity of the call instruction.
Only the first argument (magnitude) of copysign is active
Definition at line 832 of file ActivityAnalysis.cpp.
| bool cached = false |
Definition at line 179 of file ActivityAnalysis.cpp.
Referenced by AdjointGenerator::handleKnownCallDerivatives(), mlir::enzyme::DataFlowActivityAnalyzer::isInactiveOperation(), mlir::enzyme::DataFlowActivityAnalyzer::isInactiveValue(), and mlir::enzyme::LoopCheckpointing< FinalClass, OpName >::reverseBinomial().
|
static |
Definition at line 216 of file ActivityAnalysis.cpp.
| SmallVector<std::unique_ptr<MemoryBuffer>, 8> contents |
Definition at line 182 of file ActivityAnalysis.cpp.
|
static |
Definition at line 172 of file ActivityAnalysis.cpp.
Referenced by mlir::enzyme::ActivityAnalyzer::isConstantValue().
|
constexpr |
Definition at line 472 of file ActivityAnalysis.cpp.
Referenced by PreProcessCache::CloneFunctionWithReturns(), mlir::enzyme::ActivityAnalyzer::isConstantOperation(), mlir::enzyme::ActivityAnalyzer::isConstantValue(), mlir::enzyme::ActivityAnalyzer::isValueActivelyStoredOrReturned(), mlir::enzyme::ActivityAnalyzer::isValueInactiveFromUsers(), and isValuePotentiallyUsedAsPointer().
| SmallVector<StringRef, 128> functionNames |
Definition at line 181 of file ActivityAnalysis.cpp.
| struct { ... } InactiveFileCache |
Cache if a file is loaded with inactive demangled function names.
|
static |
Definition at line 117 of file ActivityAnalysis.cpp.
|
static |
Definition at line 39 of file ActivityAnalysis.cpp.
|
static |
Definition at line 81 of file ActivityAnalysis.cpp.
Referenced by mlir::enzyme::ActivityAnalyzer::isConstantOperation(), and mlir::enzyme::ActivityAnalyzer::isConstantValue().
|
static |
Definition at line 90 of file ActivityAnalysis.cpp.
Referenced by mlir::enzyme::ActivityAnalyzer::isConstantValue().
|
static |
Definition at line 35 of file ActivityAnalysis.cpp.
Referenced by mlir::enzyme::ActivityAnalyzer::isConstantValue().
|
static |
Definition at line 26 of file ActivityAnalysis.cpp.
Referenced by mlir::enzyme::ActivityAnalyzer::isConstantValue().
| static const std::map< std::string, size_t > MPIInactiveCommAllocators |
Definition at line 160 of file ActivityAnalysis.cpp.
Referenced by AdjointGenerator::handleKnownCallDerivatives(), AdjointGenerator::handleMPI(), and mlir::enzyme::ActivityAnalyzer::isConstantValue().