Enzyme main
Loading...
Searching...
No Matches
TypeAnalysis.cpp File Reference
#include <cstdint>
#include <deque>
#include <llvm/Config/llvm-config.h>
#include "llvm/Demangle/Demangle.h"
#include "llvm/Demangle/ItaniumDemangle.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/ModuleSlotTracker.h"
#include "llvm/IR/Type.h"
#include "llvm/IR/Value.h"
#include "llvm/IR/InstIterator.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/TimeProfiler.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/ADT/SmallSet.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/StringSet.h"
#include "llvm/IR/InlineAsm.h"
#include "../EnzymeLogic.h"
#include "../Utils.h"
#include "TypeAnalysis.h"
#include "../FunctionUtils.h"
#include "../LibraryFuncs.h"
#include "RustDebugInfo.h"
#include "TBAA.h"
#include <math.h>
#include "BlasTA.inc"
Include dependency graph for TypeAnalysis.cpp:

Go to the source code of this file.

Classes

struct  TypeHandler< T >
 This template class is defined to take the templated type T update the analysis of the first argument (val) to be type T As such, below we have several template specializations to convert various c/c++ to TypeAnalysis types. More...
 
struct  TypeHandler< double >
 
struct  TypeHandler< float >
 
struct  TypeHandler< long double >
 
struct  TypeHandler< double * >
 
struct  TypeHandler< float * >
 
struct  TypeHandler< long double * >
 
struct  TypeHandler< void >
 
struct  TypeHandler< void * >
 
struct  TypeHandler< int >
 
struct  TypeHandler< int * >
 
struct  TypeHandler< unsigned int >
 
struct  TypeHandler< unsigned int * >
 
struct  TypeHandler< long int >
 
struct  TypeHandler< long int * >
 
struct  TypeHandler< long unsigned int >
 
struct  TypeHandler< long unsigned int * >
 
struct  TypeHandler< long long int >
 
struct  TypeHandler< long long int * >
 
struct  TypeHandler< long long unsigned int >
 
struct  TypeHandler< long long unsigned int * >
 
struct  FunctionArgumentIterator< Arg0 >
 
struct  FunctionArgumentIterator< Arg0, Args... >
 

Macros

#define CONSIDER(fn)
 
#define CONSIDER2(fn, ...)
 

Functions

llvm::cl::opt< int > MaxIntOffset ("enzyme-max-int-offset", cl::init(100), cl::Hidden, cl::desc("Maximum type tree offset"))
 Maximum offset for type trees to keep.
 
llvm::cl::opt< unsigned > EnzymeMaxTypeDepth ("enzyme-max-type-depth", cl::init(6), cl::Hidden, cl::desc("Maximum type tree depth"))
 
llvm::cl::opt< bool > EnzymePrintType ("enzyme-print-type", cl::init(false), cl::Hidden, cl::desc("Print type analysis algorithm"))
 
llvm::cl::opt< bool > RustTypeRules ("enzyme-rust-type", cl::init(false), cl::Hidden, cl::desc("Enable rust-specific type rules"))
 
llvm::cl::opt< bool > EnzymeStrictAliasing ("enzyme-strict-aliasing", cl::init(true), cl::Hidden, cl::desc("Assume strict aliasing of types / type stability"))
 
static bool isItaniumEncoding (StringRef S)
 
bool dontAnalyze (StringRef str)
 
static SmallPtrSet< BasicBlock *, 1 > findLoopIndices (llvm::Value *val, LoopInfo &LI, DominatorTree &DT, SmallPtrSet< PHINode *, 1 > &seen)
 
void getConstantAnalysis (Constant *Val, TypeAnalyzer &TA, std::map< llvm::Value *, TypeTree > &analysis)
 Given a constant value, deduce any type information applicable.
 
template<typename T >
std::set< SmallVector< T, 4 > > getSet (ArrayRef< std::set< T > > todo, size_t idx)
 
template<typename RT , typename... Args>
void analyzeFuncTypesNoFn (CallBase &call, TypeAnalyzer &TA)
 
template<typename RT , typename... Args>
void analyzeFuncTypes (RT(*fn)(Args...), CallBase &call, TypeAnalyzer &TA)
 
void analyzeIntelSubscriptIntrinsic (IntrinsicInst &II, TypeAnalyzer &TA)
 
size_t skippedBytes (SmallSet< size_t, 8 > &offs, Type *T, const DataLayout &DL, size_t offset=0)
 
TypeTree defaultTypeTreeForLLVM (llvm::Type *ET, llvm::Instruction *I, bool intIsPointer)
 
FnTypeInfo preventTypeAnalysisLoops (const FnTypeInfo &oldTypeInfo_, llvm::Function *todiff)
 

Variables

const llvm::StringMap< llvm::Intrinsic::ID > LIBM_FUNCTIONS
 

Macro Definition Documentation

◆ CONSIDER

#define CONSIDER ( fn)
Value:
if (funcName == #fn) { \
analyzeFuncTypes(::fn, call, *this); \
return; \
}

Referenced by TypeAnalyzer::visitCallBase().

◆ CONSIDER2

#define CONSIDER2 ( fn,
... )
Value:
if (funcName == #fn) { \
analyzeFuncTypesNoFn<__VA_ARGS__>(call, *this); \
return; \
}

Referenced by TypeAnalyzer::visitCallBase().

Function Documentation

◆ analyzeFuncTypes()

template<typename RT , typename... Args>
void analyzeFuncTypes ( RT(* fn )(Args...),
CallBase & call,
TypeAnalyzer & TA )

Definition at line 4412 of file TypeAnalysis.cpp.

References analyzeFuncTypesNoFn(), and Args.

◆ analyzeFuncTypesNoFn()

template<typename RT , typename... Args>
void analyzeFuncTypesNoFn ( CallBase & call,
TypeAnalyzer & TA )

◆ analyzeIntelSubscriptIntrinsic()

◆ defaultTypeTreeForLLVM()

TypeTree defaultTypeTreeForLLVM ( llvm::Type * ET,
llvm::Instruction * I,
bool intIsPointer )

◆ dontAnalyze()

bool dontAnalyze ( StringRef str)

Definition at line 219 of file TypeAnalysis.cpp.

References isItaniumEncoding(), and str().

Referenced by TypeAnalyzer::visitCallBase().

◆ EnzymeMaxTypeDepth()

llvm::cl::opt< unsigned > EnzymeMaxTypeDepth ( "enzyme-max-type-depth" ,
cl::init(6) ,
cl::Hidden ,
cl::desc("Maximum type tree depth")  )

◆ EnzymePrintType()

llvm::cl::opt< bool > EnzymePrintType ( "enzyme-print-type" ,
cl::init(false) ,
cl::Hidden ,
cl::desc("Print type analysis algorithm")  )

◆ EnzymeStrictAliasing()

llvm::cl::opt< bool > EnzymeStrictAliasing ( "enzyme-strict-aliasing" ,
cl::init(true) ,
cl::Hidden ,
cl::desc("Assume strict aliasing of types / type stability")  )

◆ findLoopIndices()

static SmallPtrSet< BasicBlock *, 1 > findLoopIndices ( llvm::Value * val,
LoopInfo & LI,
DominatorTree & DT,
SmallPtrSet< PHINode *, 1 > & seen )
static

Definition at line 293 of file TypeAnalysis.cpp.

References findLoopIndices().

Referenced by findLoopIndices(), and TypeAnalyzer::visitGEPOperator().

◆ getConstantAnalysis()

◆ getSet()

template<typename T >
std::set< SmallVector< T, 4 > > getSet ( ArrayRef< std::set< T > > todo,
size_t idx )

Definition at line 1863 of file TypeAnalysis.cpp.

References getSet().

Referenced by analyzeIntelSubscriptIntrinsic(), getSet(), and TypeAnalyzer::visitGEPOperator().

◆ isItaniumEncoding()

static bool isItaniumEncoding ( StringRef S)
static

Definition at line 214 of file TypeAnalysis.cpp.

References startsWith().

Referenced by dontAnalyze().

◆ MaxIntOffset()

llvm::cl::opt< int > MaxIntOffset ( "enzyme-max-int-offset" ,
cl::init(100) ,
cl::Hidden ,
cl::desc("Maximum type tree offset")  )

Maximum offset for type trees to keep.

Referenced by TypeAnalyzer::getCallInfo(), FnTypeInfo::knownIntegralValues(), and TypeAnalyzer::visitCallBase().

◆ preventTypeAnalysisLoops()

FnTypeInfo preventTypeAnalysisLoops ( const FnTypeInfo & oldTypeInfo_,
llvm::Function * todiff )

Definition at line 6506 of file TypeAnalysis.cpp.

References FnTypeInfo::KnownValues.

Referenced by TypeAnalyzer::visitIPOCall().

◆ RustTypeRules()

llvm::cl::opt< bool > RustTypeRules ( "enzyme-rust-type" ,
cl::init(false) ,
cl::Hidden ,
cl::desc("Enable rust-specific type rules")  )

◆ skippedBytes()

size_t skippedBytes ( SmallSet< size_t, 8 > & offs,
Type * T,
const DataLayout & DL,
size_t offset = 0 )

Variable Documentation

◆ LIBM_FUNCTIONS

const llvm::StringMap<llvm::Intrinsic::ID> LIBM_FUNCTIONS

Definition at line 97 of file TypeAnalysis.cpp.

Referenced by isMemFreeLibMFunction().