Enzyme main
Loading...
Searching...
No Matches
TypeTree Class Reference

Class representing the underlying types of values as sequences of offsets to a ConcreteType. More...

#include "TypeAnalysis/TypeTree.h"

Inheritance diagram for TypeTree:
Collaboration diagram for TypeTree:

Public Member Functions

 TypeTree ()
 
 TypeTree (ConcreteType dat)
 
const ConcreteTypeMapTypegetMapping () const
 Utility helper to lookup the mapping.
 
ConcreteType operator[] (const std::vector< int > Seq) const
 Lookup the underlying ConcreteType at a given offset sequence or Unknown if none exists.
 
bool IsFullyDetermined () const
 
bool insert (const std::vector< int > Seq, ConcreteType CT, bool PointerIntSame=false)
 Return if changed.
 
bool operator< (const TypeTree &vd) const
 How this TypeTree compares with another.
 
bool isKnown () const
 Whether this TypeTree contains any information.
 
bool isKnownPastPointer () const
 Whether this TypeTree knows any non-pointer information.
 
TypeTree JustInt () const
 Select only the Integer ConcreteTypes.
 
TypeTree Only (int Off, llvm::Instruction *orig) const
 Prepend an offset to all mappings.
 
TypeTree Data0 () const
 Peel off the outermost index at offset 0.
 
ConcreteType Inner0 () const
 Optimized version of Data0()[{}].
 
TypeTree Clear (size_t start, size_t end, size_t len) const
 Remove any mappings in the range [start, end) or [len, inf) This function has special handling for -1's.
 
TypeTree Lookup (size_t len, const llvm::DataLayout &dl) const
 Select all submappings whose first index is in range [0, len) and remove the first index.
 
void CanonicalizeInPlace (size_t len, const llvm::DataLayout &dl)
 Given that this tree represents something of at most size len, canonicalize this, creating -1's where possible.
 
TypeTree KeepMinusOne (bool &legal) const
 Keep only pointers (or anything's) to a repeated value (represented by -1)
 
llvm::Type * IsAllFloat (const size_t size, const llvm::DataLayout &dl) const
 
TypeTree ShiftIndices (const llvm::DataLayout &dl, const int offset, const int maxSize, size_t addOffset=0) const
 Replace mappings in the range in [offset, offset+maxSize] with those in.
 
TypeTree PurgeAnything () const
 Keep only mappings where the type is not an Anything
 
TypeTree ReplaceMinus () const
 Replace -1 with 0.
 
void ReplaceIntWithAnything ()
 Replace all integer subtypes with anything.
 
TypeTree JustAnything () const
 Keep only mappings where the type is an Anything
 
bool operator== (const TypeTree &RHS) const
 Chceck equality of two TypeTrees.
 
bool operator= (const TypeTree &RHS)
 Set this to another TypeTree, returning if this was changed.
 
bool checkedOrIn (const std::vector< int > &Seq, ConcreteType RHS, bool PointerIntSame, bool &LegalOr)
 
bool orIn (const std::vector< int > &Seq, ConcreteType RHS, bool PointerIntSame=false)
 
bool checkedOrIn (const TypeTree &RHS, bool PointerIntSame, bool &LegalOr)
 Set this to the logical or of itself and RHS, returning whether this value changed Setting PointerIntSame considers pointers and integers as equivalent If this is an illegal operation, LegalOr will be set to false.
 
bool orIn (const TypeTree &RHS, bool PointerIntSame)
 Set this to the logical or of itself and RHS, returning whether this value changed Setting PointerIntSame considers pointers and integers as equivalent This function will error if doing an illegal Operation.
 
bool orIn (const std::vector< int > Seq, ConcreteType CT, bool PointerIntSame)
 Set this to the logical or of itself and RHS, returning whether this value changed Setting PointerIntSame considers pointers and integers as equivalent This function will error if doing an illegal Operation.
 
bool operator|= (const TypeTree &RHS)
 Set this to the logical or of itself and RHS, returning whether this value changed This assumes that pointers and integers are distinct This function will error if doing an illegal Operation.
 
bool andIn (const TypeTree &RHS)
 Set this to the logical and of itself and RHS, returning whether this value changed If this and RHS are incompatible at an index, the result will be BaseType::Unknown.
 
bool operator&= (const TypeTree &RHS)
 Set this to the logical and of itself and RHS, returning whether this value changed If this and RHS are incompatible at an index, the result will be BaseType::Unknown.
 
bool binopIn (bool &Legal, const TypeTree &RHS, llvm::BinaryOperator::BinaryOps Op)
 Set this to the logical binop of itself and RHS, using the Binop Op, returning true if this was changed.
 
std::string str () const
 Returns a string representation of this TypeTree.
 
llvm::MDNode * toMD (llvm::LLVMContext &ctx)
 
void insertFromMD (llvm::MDNode *md, const std::vector< int > &prev={})
 

Static Public Member Functions

static TypeTree parse (llvm::StringRef str, llvm::LLVMContext &ctx)
 
static TypeTree fromMD (llvm::MDNode *md)
 

Detailed Description

Class representing the underlying types of values as sequences of offsets to a ConcreteType.

Definition at line 72 of file TypeTree.h.

Constructor & Destructor Documentation

◆ TypeTree() [1/2]

TypeTree::TypeTree ( )
inline

Definition at line 79 of file TypeTree.h.

Referenced by ShiftIndices().

◆ TypeTree() [2/2]

TypeTree::TypeTree ( ConcreteType dat)
inline

Definition at line 80 of file TypeTree.h.

References Unknown.

Member Function Documentation

◆ andIn()

bool TypeTree::andIn ( const TypeTree & RHS)
inline

Set this to the logical and of itself and RHS, returning whether this value changed If this and RHS are incompatible at an index, the result will be BaseType::Unknown.

Definition at line 1294 of file TypeTree.h.

References Unknown.

Referenced by operator&=().

◆ binopIn()

bool TypeTree::binopIn ( bool & Legal,
const TypeTree & RHS,
llvm::BinaryOperator::BinaryOps Op )
inline

Set this to the logical binop of itself and RHS, using the Binop Op, returning true if this was changed.

This function will error on an invalid type combination

Definition at line 1320 of file TypeTree.h.

References ConcreteType::binopIn(), and Unknown.

Referenced by TypeAnalyzer::visitBinaryOperation(), TypeAnalyzer::visitIntrinsicInst(), and TypeAnalyzer::visitPHINode().

◆ CanonicalizeInPlace()

void TypeTree::CanonicalizeInPlace ( size_t len,
const llvm::DataLayout & dl )
inline

Given that this tree represents something of at most size len, canonicalize this, creating -1's where possible.

Definition at line 676 of file TypeTree.h.

References insert(), Pointer, and str().

Referenced by getConstantAnalysis(), and TypeAnalyzer::visitCallBase().

◆ checkedOrIn() [1/2]

bool TypeTree::checkedOrIn ( const std::vector< int > & Seq,
ConcreteType RHS,
bool PointerIntSame,
bool & LegalOr )
inline

◆ checkedOrIn() [2/2]

bool TypeTree::checkedOrIn ( const TypeTree & RHS,
bool PointerIntSame,
bool & LegalOr )
inline

Set this to the logical or of itself and RHS, returning whether this value changed Setting PointerIntSame considers pointers and integers as equivalent If this is an illegal operation, LegalOr will be set to false.

Definition at line 1243 of file TypeTree.h.

References checkedOrIn().

◆ Clear()

TypeTree TypeTree::Clear ( size_t start,
size_t end,
size_t len ) const
inline

Remove any mappings in the range [start, end) or [len, inf) This function has special handling for -1's.

Definition at line 556 of file TypeTree.h.

References insert(), and orIn().

Referenced by TypeAnalyzer::visitInsertElementInst(), and TypeAnalyzer::visitInsertValueInst().

◆ Data0()

◆ fromMD()

static TypeTree TypeTree::fromMD ( llvm::MDNode * md)
inlinestatic

Definition at line 1442 of file TypeTree.h.

References insertFromMD().

Referenced by TypeAnalyzer::considerTBAA().

◆ getMapping()

const ConcreteTypeMapType & TypeTree::getMapping ( ) const
inline

Utility helper to lookup the mapping.

Definition at line 173 of file TypeTree.h.

◆ Inner0()

◆ insert()

◆ insertFromMD()

void TypeTree::insertFromMD ( llvm::MDNode * md,
const std::vector< int > & prev = {} )
inline

Definition at line 1425 of file TypeTree.h.

Referenced by EnzymeTypeTreeFromMD(), and fromMD().

◆ IsAllFloat()

llvm::Type * TypeTree::IsAllFloat ( const size_t size,
const llvm::DataLayout & dl ) const
inline

◆ IsFullyDetermined()

bool TypeTree::IsFullyDetermined ( ) const
inline

Definition at line 221 of file TypeTree.h.

References Pointer.

◆ isKnown()

bool TypeTree::isKnown ( ) const
inline

Whether this TypeTree contains any information.

Definition at line 431 of file TypeTree.h.

Referenced by TypeAnalyzer::considerRustDebugInfo().

◆ isKnownPastPointer()

bool TypeTree::isKnownPastPointer ( ) const
inline

Whether this TypeTree knows any non-pointer information.

Definition at line 443 of file TypeTree.h.

References Anything, and Pointer.

Referenced by TypeAnalyzer::considerTBAA().

◆ JustAnything()

TypeTree TypeTree::JustAnything ( ) const
inline

Keep only mappings where the type is an Anything

Definition at line 1083 of file TypeTree.h.

References Anything, and insert().

Referenced by TypeAnalyzer::visitSelectInst().

◆ JustInt()

TypeTree TypeTree::JustInt ( ) const
inline

Select only the Integer ConcreteTypes.

Definition at line 459 of file TypeTree.h.

References insert(), and Integer.

◆ KeepMinusOne()

TypeTree TypeTree::KeepMinusOne ( bool & legal) const
inline

Keep only pointers (or anything's) to a repeated value (represented by -1)

Definition at line 785 of file TypeTree.h.

References Anything, insert(), and Pointer.

◆ Lookup()

TypeTree TypeTree::Lookup ( size_t len,
const llvm::DataLayout & dl ) const
inline

◆ Only()

TypeTree TypeTree::Only ( int Off,
llvm::Instruction * orig ) const
inline

Prepend an offset to all mappings.

Definition at line 471 of file TypeTree.h.

References CustomErrorHandler, EmitWarning(), EnzymeMaxTypeDepth, EnzymeTypeWarning, str(), and TypeDepthExceeded.

Referenced by analyzeIntelSubscriptIntrinsic(), TypeHandler< double * >::analyzeType(), TypeHandler< double >::analyzeType(), TypeHandler< float * >::analyzeType(), TypeHandler< float >::analyzeType(), TypeHandler< int * >::analyzeType(), TypeHandler< int >::analyzeType(), TypeHandler< long double * >::analyzeType(), TypeHandler< long double >::analyzeType(), TypeHandler< long int * >::analyzeType(), TypeHandler< long int >::analyzeType(), TypeHandler< long long int * >::analyzeType(), TypeHandler< long long int >::analyzeType(), TypeHandler< long long unsigned int * >::analyzeType(), TypeHandler< long long unsigned int >::analyzeType(), TypeHandler< long unsigned int * >::analyzeType(), TypeHandler< long unsigned int >::analyzeType(), TypeHandler< unsigned int * >::analyzeType(), TypeHandler< unsigned int >::analyzeType(), TypeHandler< void * >::analyzeType(), TypeAnalyzer::considerRustDebugInfo(), TypeAnalyzer::considerTBAA(), defaultTypeTreeForLLVM(), AdjointGenerator::DifferentiableMemCopyFloats(), TypeAnalyzer::getAnalysis(), TypeAnalyzer::getCallInfo(), getConstantAnalysis(), parseDIType(), parseDIType(), parseTBAA(), parseTBAA(), TypeAnalyzer::runPHIHypotheses(), TypeAnalyzer::visitAtomicRMWInst(), TypeAnalyzer::visitBinaryOperation(), TypeAnalyzer::visitBinaryOperator(), TypeAnalyzer::visitCallBase(), TypeAnalyzer::visitCmpInst(), TypeAnalyzer::visitExtractElementInst(), TypeAnalyzer::visitFPExtInst(), TypeAnalyzer::visitFPToSIInst(), TypeAnalyzer::visitFPToUIInst(), TypeAnalyzer::visitFPTruncInst(), TypeAnalyzer::visitGEPOperator(), TypeAnalyzer::visitIntrinsicInst(), TypeAnalyzer::visitIPOCall(), AdjointGenerator::visitMemSetCommon(), AdjointGenerator::visitMemTransferCommon(), TypeAnalyzer::visitMemTransferCommon(), TypeAnalyzer::visitPHINode(), TypeAnalyzer::visitShuffleVectorInst(), TypeAnalyzer::visitSIToFPInst(), TypeAnalyzer::visitUIToFPInst(), and TypeAnalyzer::visitZExtInst().

◆ operator&=()

bool TypeTree::operator&= ( const TypeTree & RHS)
inline

Set this to the logical and of itself and RHS, returning whether this value changed If this and RHS are incompatible at an index, the result will be BaseType::Unknown.

Definition at line 1315 of file TypeTree.h.

References andIn().

◆ operator<()

bool TypeTree::operator< ( const TypeTree & vd) const
inline

How this TypeTree compares with another.

Definition at line 428 of file TypeTree.h.

◆ operator=()

bool TypeTree::operator= ( const TypeTree & RHS)
inline

Set this to another TypeTree, returning if this was changed.

Definition at line 1097 of file TypeTree.h.

◆ operator==()

bool TypeTree::operator== ( const TypeTree & RHS) const
inline

Chceck equality of two TypeTrees.

Definition at line 1094 of file TypeTree.h.

◆ operator[]()

ConcreteType TypeTree::operator[] ( const std::vector< int > Seq) const
inline

Lookup the underlying ConcreteType at a given offset sequence or Unknown if none exists.

Definition at line 177 of file TypeTree.h.

References Unknown.

Referenced by checkedOrIn(), Inner0(), IsAllFloat(), and ShiftIndices().

◆ operator|=()

bool TypeTree::operator|= ( const TypeTree & RHS)
inline

Set this to the logical or of itself and RHS, returning whether this value changed This assumes that pointers and integers are distinct This function will error if doing an illegal Operation.

Definition at line 1287 of file TypeTree.h.

References orIn().

◆ orIn() [1/3]

bool TypeTree::orIn ( const std::vector< int > & Seq,
ConcreteType RHS,
bool PointerIntSame = false )
inline

◆ orIn() [2/3]

bool TypeTree::orIn ( const std::vector< int > Seq,
ConcreteType CT,
bool PointerIntSame )
inline

Set this to the logical or of itself and RHS, returning whether this value changed Setting PointerIntSame considers pointers and integers as equivalent This function will error if doing an illegal Operation.

Definition at line 1271 of file TypeTree.h.

References checkedOrIn(), ConcreteType::str(), str(), and to_string().

◆ orIn() [3/3]

bool TypeTree::orIn ( const TypeTree & RHS,
bool PointerIntSame )
inline

Set this to the logical or of itself and RHS, returning whether this value changed Setting PointerIntSame considers pointers and integers as equivalent This function will error if doing an illegal Operation.

Definition at line 1256 of file TypeTree.h.

References checkedOrIn(), and str().

◆ parse()

static TypeTree TypeTree::parse ( llvm::StringRef str,
llvm::LLVMContext & ctx )
inlinestatic

Definition at line 86 of file TypeTree.h.

References str().

Referenced by TypeAnalyzer::considerTBAA(), and AdjointGenerator::visitMemTransferCommon().

◆ PurgeAnything()

◆ ReplaceIntWithAnything()

void TypeTree::ReplaceIntWithAnything ( )
inline

Replace all integer subtypes with anything.

Definition at line 1074 of file TypeTree.h.

References Anything, and Integer.

◆ ReplaceMinus()

TypeTree TypeTree::ReplaceMinus ( ) const
inline

Replace -1 with 0.

Definition at line 1059 of file TypeTree.h.

References Anything, and insert().

Referenced by TypeAnalyzer::visitStoreInst().

◆ ShiftIndices()

◆ str()

◆ toMD()

llvm::MDNode * TypeTree::toMD ( llvm::LLVMContext & ctx)
inline

Definition at line 1403 of file TypeTree.h.

References ConcreteType::str(), and Unknown.


The documentation for this class was generated from the following file: