LLVM 22.0.0git
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 Embedding getInstVector (const Instruction &I) const
 Computes and returns the embedding for a given instruction in the function F.
LLVM_ABI Embedding getBBVector (const BasicBlock &BB) const
 Computes and returns the embedding for a given basic block in the function F.
LLVM_ABI Embedding getFunctionVector () const
 Computes and returns the embedding for the current function.
virtual void invalidateEmbeddings ()
 Invalidate embeddings if cached.

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)
Embedding computeEmbeddings () const
 Function to compute embeddings.
Embedding computeEmbeddings (const BasicBlock &BB) const
 Function to compute the embedding for a given basic block.
virtual Embedding computeEmbeddings (const Instruction &I) const =0
 Function to compute the embedding for a given instruction.

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

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 524 of file IR2Vec.h.

Constructor & Destructor Documentation

◆ Embedder()

LLVM_ABI llvm::ir2vec::Embedder::Embedder ( const Function & F,
const Vocabulary & Vocab )
inlineprotected

◆ ~Embedder()

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

References F, LLVM_ABI, Mode, and Vocab.

Member Function Documentation

◆ computeEmbeddings() [1/3]

Embedding Embedder::computeEmbeddings ( ) const
protected

Function to compute embeddings.

Definition at line 167 of file IR2Vec.cpp.

References computeEmbeddings(), llvm::depth_first(), Dimension, and F.

Referenced by computeEmbeddings(), computeEmbeddings(), getBBVector(), getFunctionVector(), and getInstVector().

◆ computeEmbeddings() [2/3]

Embedding Embedder::computeEmbeddings ( const BasicBlock & BB) const
protected

Function to compute the embedding for a given basic block.

Definition at line 179 of file IR2Vec.cpp.

References computeEmbeddings(), Dimension, I, and llvm::BasicBlock::instructionsWithoutDebug().

◆ computeEmbeddings() [3/3]

virtual Embedding llvm::ir2vec::Embedder::computeEmbeddings ( const Instruction & I) const
protectedpure virtual

Function to compute the embedding for a given instruction.

Specific to the kind of embeddings being computed.

References I.

◆ 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 156 of file IR2Vec.cpp.

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

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

◆ getBBVector()

LLVM_ABI Embedding llvm::ir2vec::Embedder::getBBVector ( const BasicBlock & BB) const
inline

Computes and returns the embedding for a given basic block in the function F.

Definition at line 566 of file IR2Vec.h.

References computeEmbeddings(), and LLVM_ABI.

◆ getFunctionVector()

LLVM_ABI Embedding llvm::ir2vec::Embedder::getFunctionVector ( ) const
inline

Computes and returns the embedding for the current function.

Definition at line 571 of file IR2Vec.h.

References computeEmbeddings(), and LLVM_ABI.

◆ getInstVector()

LLVM_ABI Embedding llvm::ir2vec::Embedder::getInstVector ( const Instruction & I) const
inline

Computes and returns the embedding for a given instruction in the function F.

Definition at line 560 of file IR2Vec.h.

References computeEmbeddings(), I, and LLVM_ABI.

◆ invalidateEmbeddings()

virtual void llvm::ir2vec::Embedder::invalidateEmbeddings ( )
inlinevirtual

Invalidate embeddings if cached.

The embeddings may not be relevant anymore when the IR changes due to transformations. In such cases, the cached embeddings should be invalidated to ensure correctness/recomputation. This is a no-op for SymbolicEmbedder but removes all the cached entries in FlowAwareEmbedder.

Reimplemented in llvm::ir2vec::FlowAwareEmbedder.

Definition at line 578 of file IR2Vec.h.

Member Data Documentation

◆ ArgWeight

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

Definition at line 534 of file IR2Vec.h.

Referenced by Embedder().

◆ Dimension

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

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

Definition at line 530 of file IR2Vec.h.

Referenced by computeEmbeddings(), computeEmbeddings(), and Embedder().

◆ F

◆ 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 534 of file IR2Vec.h.

Referenced by Embedder().

◆ TypeWeight

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

Definition at line 534 of file IR2Vec.h.

Referenced by Embedder().

◆ Vocab


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