LLVM 22.0.0git
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
llvm::ir2vec::Embedder Class Referenceabstract

Embedder provides the interface to generate embeddings (vector representations) for instructions, basic blocks, and functions. More...

#include "llvm/Analysis/IR2Vec.h"

Inheritance diagram for llvm::ir2vec::Embedder:
[legend]

Public Member Functions

virtual ~Embedder ()=default
 
LLVM_ABI const InstEmbeddingsMapgetInstVecMap () const
 Returns a map containing instructions and the corresponding embeddings for the function F if it has been computed.
 
LLVM_ABI const BBEmbeddingsMapgetBBVecMap () const
 Returns a map containing basic block and the corresponding embeddings for the function F if it has been computed.
 
LLVM_ABI const EmbeddinggetBBVector (const BasicBlock &BB) const
 Returns the embedding for a given basic block in the function F if it has been computed.
 
LLVM_ABI const EmbeddinggetFunctionVector () const
 Computes and returns the embedding for the current function.
 

Static Public Member Functions

static LLVM_ABI std::unique_ptr< Embeddercreate (IR2VecKind Mode, const Function &F, const Vocabulary &Vocab)
 Factory method to create an Embedder object.
 

Protected Member Functions

LLVM_ABI Embedder (const Function &F, const Vocabulary &Vocab)
 
void computeEmbeddings () const
 Function to compute embeddings.
 
virtual void computeEmbeddings (const BasicBlock &BB) const =0
 Function to compute the embedding for a given basic block.
 

Protected Attributes

const FunctionF
 
const VocabularyVocab
 
const unsigned Dimension
 Dimension of the vector representation; captured from the input vocabulary.
 
const float OpcWeight
 Weights for different entities (like opcode, arguments, types) in the IR instructions to generate the vector representation.
 
const float TypeWeight
 
const float ArgWeight
 
Embedding FuncVector
 
BBEmbeddingsMap BBVecMap
 
InstEmbeddingsMap InstVecMap
 

Detailed Description

Embedder provides the interface to generate embeddings (vector representations) for instructions, basic blocks, and functions.

The vector representations are generated using IR2Vec algorithms.

The Embedder class is an abstract class and it is intended to be subclassed for different IR2Vec algorithms like Symbolic and Flow-aware.

Definition at line 332 of file IR2Vec.h.

Constructor & Destructor Documentation

◆ Embedder()

Embedder::Embedder ( const Function F,
const Vocabulary Vocab 
)
protected

Definition at line 155 of file IR2Vec.cpp.

◆ ~Embedder()

virtual llvm::ir2vec::Embedder::~Embedder ( )
virtualdefault

Member Function Documentation

◆ computeEmbeddings() [1/2]

void Embedder::computeEmbeddings ( ) const
protected

Function to compute embeddings.

It generates embeddings for all the instructions and basic blocks in the function F.

Definition at line 198 of file IR2Vec.cpp.

References BBVecMap, computeEmbeddings(), llvm::depth_first(), F, FuncVector, and llvm::GlobalValue::isDeclaration().

Referenced by computeEmbeddings(), getBBVecMap(), getBBVector(), getFunctionVector(), and getInstVecMap().

◆ computeEmbeddings() [2/2]

virtual void llvm::ir2vec::Embedder::computeEmbeddings ( const BasicBlock BB) const
protectedpure virtual

Function to compute the embedding for a given basic block.

Specific to the kind of embeddings being computed.

◆ create()

std::unique_ptr< Embedder > Embedder::create ( IR2VecKind  Mode,
const Function F,
const Vocabulary Vocab 
)
static

Factory method to create an Embedder object.

Definition at line 160 of file IR2Vec.cpp.

References F, llvm::FlowAware, llvm::Symbolic, and Vocab.

Referenced by llvm::IR2VecPrinterPass::run().

◆ getBBVecMap()

const BBEmbeddingsMap & Embedder::getBBVecMap ( ) const

Returns a map containing basic block and the corresponding embeddings for the function F if it has been computed.

If not, it computes the embeddings for the function and returns the map.

Definition at line 177 of file IR2Vec.cpp.

References BBVecMap, computeEmbeddings(), and llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::empty().

◆ getBBVector()

const Embedding & Embedder::getBBVector ( const BasicBlock BB) const

Returns the embedding for a given basic block in the function F if it has been computed.

If not, it computes the embedding for the basic block and returns it.

Definition at line 183 of file IR2Vec.cpp.

References BBVecMap, computeEmbeddings(), llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::end(), and llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::find().

◆ getFunctionVector()

const Embedding & Embedder::getFunctionVector ( ) const

Computes and returns the embedding for the current function.

Definition at line 191 of file IR2Vec.cpp.

References computeEmbeddings(), and FuncVector.

◆ getInstVecMap()

const InstEmbeddingsMap & Embedder::getInstVecMap ( ) const

Returns a map containing instructions and the corresponding embeddings for the function F if it has been computed.

If not, it computes the embeddings for the function and returns the map.

Definition at line 171 of file IR2Vec.cpp.

References computeEmbeddings(), llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::empty(), and InstVecMap.

Member Data Documentation

◆ ArgWeight

const float llvm::ir2vec::Embedder::ArgWeight
protected

Definition at line 342 of file IR2Vec.h.

◆ BBVecMap

BBEmbeddingsMap llvm::ir2vec::Embedder::BBVecMap
mutableprotected

Definition at line 347 of file IR2Vec.h.

Referenced by computeEmbeddings(), getBBVecMap(), and getBBVector().

◆ Dimension

const unsigned llvm::ir2vec::Embedder::Dimension
protected

Dimension of the vector representation; captured from the input vocabulary.

Definition at line 338 of file IR2Vec.h.

◆ F

const Function& llvm::ir2vec::Embedder::F
protected

Definition at line 334 of file IR2Vec.h.

Referenced by computeEmbeddings(), and create().

◆ FuncVector

Embedding llvm::ir2vec::Embedder::FuncVector
mutableprotected

Definition at line 346 of file IR2Vec.h.

Referenced by computeEmbeddings(), and getFunctionVector().

◆ InstVecMap

InstEmbeddingsMap llvm::ir2vec::Embedder::InstVecMap
mutableprotected

Definition at line 348 of file IR2Vec.h.

Referenced by getInstVecMap().

◆ OpcWeight

const float llvm::ir2vec::Embedder::OpcWeight
protected

Weights for different entities (like opcode, arguments, types) in the IR instructions to generate the vector representation.

Definition at line 342 of file IR2Vec.h.

◆ TypeWeight

const float llvm::ir2vec::Embedder::TypeWeight
protected

Definition at line 342 of file IR2Vec.h.

◆ Vocab

const Vocabulary& llvm::ir2vec::Embedder::Vocab
protected

Definition at line 335 of file IR2Vec.h.

Referenced by create().


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