Enzyme main
Loading...
Searching...
No Matches
FunctionUtils.h File Reference
#include <deque>
#include <set>
#include <llvm/Config/llvm-config.h>
#include "SCEV/ScalarEvolution.h"
#include "SCEV/ScalarEvolutionExpander.h"
#include "Utils.h"
#include "llvm/Analysis/AliasAnalysis.h"
#include "llvm/Analysis/LoopAnalysisManager.h"
#include "llvm/Analysis/TargetLibraryInfo.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/Type.h"
#include "llvm/IR/Instructions.h"
#include "llvm/Transforms/Utils/ValueMapper.h"
#include "llvm/ADT/STLExtras.h"
Include dependency graph for FunctionUtils.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  PreProcessCache
 

Enumerations

enum class  UseReq { Need , Recur , Cached }
 

Functions

bool DetectReadonlyOrThrow (llvm::Module &M)
 
static void getExitBlocks (const llvm::Loop *L, llvm::SmallPtrSetImpl< llvm::BasicBlock * > &ExitBlocks)
 
static llvm::SmallVector< llvm::BasicBlock *, 3 > getLatches (const llvm::Loop *L, const llvm::SmallPtrSetImpl< llvm::BasicBlock * > &ExitBlocks)
 
static llvm::SmallPtrSet< llvm::BasicBlock *, 4 > getGuaranteedUnreachable (llvm::Function *F)
 
static void calculateUnusedValues (const llvm::Function &oldFunc, llvm::SmallPtrSetImpl< const llvm::Value * > &unnecessaryValues, llvm::SmallPtrSetImpl< const llvm::Instruction * > &unnecessaryInstructions, bool returnValue, llvm::function_ref< bool(const llvm::Value *)> valneeded, llvm::function_ref< UseReq(const llvm::Instruction *)> instneeded, llvm::function_ref< bool(const llvm::Instruction *, const llvm::Value *)> useneeded)
 
static void calculateUnusedStores (const llvm::Function &oldFunc, llvm::SmallPtrSetImpl< const llvm::Instruction * > &unnecessaryStores, llvm::function_ref< bool(const llvm::Instruction *)> needStore)
 
void RecursivelyReplaceAddressSpace (llvm::Value *AI, llvm::Value *rep, bool legal)
 
void ReplaceFunctionImplementation (llvm::Module &M)
 
bool couldFunctionArgumentCapture (llvm::CallInst *CI, llvm::Value *val)
 Is the use of value val as an argument of call CI potentially captured.
 
llvm::FunctionType * getFunctionTypeForClone (llvm::FunctionType *FTy, DerivativeMode mode, unsigned width, llvm::Type *additionalArg, llvm::ArrayRef< DIFFE_TYPE > constant_args, bool diffeReturnArg, bool returnTape, bool returnPrimal, bool returnShadow)
 
bool LowerSparsification (llvm::Function *F, bool replaceAll=true)
 Lower __enzyme_todense, returning if changed.
 

Variables

llvm::cl::opt< bool > EnzymeAlwaysInlineDiff
 

Enumeration Type Documentation

◆ UseReq

enum class UseReq
strong
Enumerator
Need 
Recur 
Cached 

Definition at line 251 of file FunctionUtils.h.

Function Documentation

◆ calculateUnusedStores()

static void calculateUnusedStores ( const llvm::Function & oldFunc,
llvm::SmallPtrSetImpl< const llvm::Instruction * > & unnecessaryStores,
llvm::function_ref< bool(const llvm::Instruction *)> needStore )
inlinestatic

Definition at line 374 of file FunctionUtils.h.

References GradientUtils::oldFunc.

◆ calculateUnusedValues()

static void calculateUnusedValues ( const llvm::Function & oldFunc,
llvm::SmallPtrSetImpl< const llvm::Value * > & unnecessaryValues,
llvm::SmallPtrSetImpl< const llvm::Instruction * > & unnecessaryInstructions,
bool returnValue,
llvm::function_ref< bool(const llvm::Value *)> valneeded,
llvm::function_ref< UseReq(const llvm::Instruction *)> instneeded,
llvm::function_ref< bool(const llvm::Instruction *, const llvm::Value *)> useneeded )
inlinestatic

Definition at line 256 of file FunctionUtils.h.

References Cached, endsWith(), Need, GradientUtils::oldFunc, and Recur.

◆ couldFunctionArgumentCapture()

bool couldFunctionArgumentCapture ( llvm::CallInst * CI,
llvm::Value * val )

Is the use of value val as an argument of call CI potentially captured.

Definition at line 182 of file FunctionUtils.cpp.

Referenced by PreProcessCache::preprocessForClone().

◆ DetectReadonlyOrThrow()

bool DetectReadonlyOrThrow ( llvm::Module & M)

◆ getExitBlocks()

static void getExitBlocks ( const llvm::Loop * L,
llvm::SmallPtrSetImpl< llvm::BasicBlock * > & ExitBlocks )
inlinestatic

Definition at line 124 of file FunctionUtils.h.

Referenced by CacheUtility::getContext().

◆ getFunctionTypeForClone()

llvm::FunctionType * getFunctionTypeForClone ( llvm::FunctionType * FTy,
DerivativeMode mode,
unsigned width,
llvm::Type * additionalArg,
llvm::ArrayRef< DIFFE_TYPE > constant_args,
bool diffeReturnArg,
bool returnTape,
bool returnPrimal,
bool returnShadow )

◆ getGuaranteedUnreachable()

static llvm::SmallPtrSet< llvm::BasicBlock *, 4 > getGuaranteedUnreachable ( llvm::Function * F)
inlinestatic

◆ getLatches()

static llvm::SmallVector< llvm::BasicBlock *, 3 > getLatches ( const llvm::Loop * L,
const llvm::SmallPtrSetImpl< llvm::BasicBlock * > & ExitBlocks )
inlinestatic

Definition at line 166 of file FunctionUtils.h.

Referenced by CacheUtility::getContext().

◆ LowerSparsification()

bool LowerSparsification ( llvm::Function * F,
bool replaceAll = true )

Lower __enzyme_todense, returning if changed.

Definition at line 8936 of file FunctionUtils.cpp.

References contains(), EnzymeAutoSparsity(), fixSparseIndices(), getFuncNameFromCall(), and replaceToDense().

Referenced by EnzymeLowerSparsification().

◆ RecursivelyReplaceAddressSpace()

void RecursivelyReplaceAddressSpace ( llvm::Value * AI,
llvm::Value * rep,
bool legal )

◆ ReplaceFunctionImplementation()

void ReplaceFunctionImplementation ( llvm::Module & M)

Variable Documentation

◆ EnzymeAlwaysInlineDiff

llvm::cl::opt<bool> EnzymeAlwaysInlineDiff
extern