OpenVDB 12.1.0

Loading...
Searching...
No Matches
FunctionGroup Struct Reference

A group of functions which all have the same name but different signatures. For example: float abs(float) double abs(double) As well as serving as a way of grouping common functions, this class provides an API for selecting the best possible function signature, should a match exist, against a provided set of argument types. More...

`#include <openvdb_ax/codegen/FunctionTypes.h>`

## Public Types
using | Ptr = std::shared_ptr<FunctionGroup>
using | UniquePtr = std::unique_ptr<FunctionGroup>
using | FunctionList = std::vector<Function::Ptr>

## Public Member Functions
| FunctionGroup (const char *name, const char *doc, const FunctionList &list)
| ~FunctionGroup ()=default
bool | HasUniqueTypeSignatures (llvm::LLVMContext &C) const
| Verify the function signatures in this group.
std::pair< const Function *, Function::SignatureMatch > | match (const ArgInfoVector &args, llvm::LLVMContext &C) const
| Given a vector of llvm types, automatically returns the best possible function declaration from the stored function list. The 'best' declaration is determined by the provided types compatibility to each functions signature.
Value | execute (const Arguments &args, llvm::IRBuilder<> &B) const
| Given a set of Arguments, find an EXPLICIT signature match, generate and execute the function body. If no explicit match exists, Value::Invalid() is returned.
Value | execute (const NativeArguments &args, llvm::IRBuilder<> &B) const
| Given a set of NativeArguments, find the best possible function signature, generate and execute the function body. Returns the return value of the function or Value::Invalid() if no Explicit or Implicit match is found.
const FunctionList & | list () const
| Accessor to the underlying function signature list.
const char * | name () const
const char * | doc () const
const Function * | match (const std::vector< llvm::Type * > &types, llvm::LLVMContext &C, Function::SignatureMatch *type=nullptr) const
llvm::Value * | execute (const std::vector< llvm::Value * > &args, llvm::IRBuilder<> &B) const
const Function * | execute (const std::vector< llvm::Value * > &args, llvm::IRBuilder<> &B, llvm::Value *&result) const
| Given a vector of llvm values, find the best possible function signature, generate and execute the function body. Returns the Function that was selected and executed or a nullptr if no valid match was found. Sets the result variable to the return value of the function (nullptr if void). If no match is found, the result variable if left unset.

## Detailed Description

A group of functions which all have the same name but different signatures. For example: float abs(float) double abs(double) As well as serving as a way of grouping common functions, this class provides an API for selecting the best possible function signature, should a match exist, against a provided set of argument types.

## Member Typedef Documentation

## ◆ FunctionList

using FunctionList = std::vector<Function::Ptr>

## ◆ Ptr

using Ptr = std::shared_ptr<FunctionGroup>

## ◆ UniquePtr

using UniquePtr = std::unique_ptr<FunctionGroup>

## Constructor & Destructor Documentation

## ◆ FunctionGroup()

FunctionGroup | ( | const char * | name,
|  | const char * | doc,
|  | const FunctionList & | list )
| inline

## ◆ ~FunctionGroup()

~FunctionGroup | ( |  | ) |
| default

## Member Function Documentation

## ◆ doc()

const char * doc | ( |  | ) | const
| inline

## ◆ execute() [1/4]

Value execute | ( | const Arguments & | args,
|  | llvm::IRBuilder<> & | B ) const

Given a set of Arguments, find an EXPLICIT signature match, generate and execute the function body. If no explicit match exists, Value::Invalid() is returned.

Note
  To ensure something is matched/executed, consider calling match() and Function::call instead. This method should only be used by internal methods that can assert an explicit match exists.

Parameters

  args | Function arguments
  B | The current llvm IRBuilder

## ◆ execute() [2/4]

Value execute | ( | const NativeArguments & | args,
|  | llvm::IRBuilder<> & | B ) const

Given a set of NativeArguments, find the best possible function signature, generate and execute the function body. Returns the return value of the function or Value::Invalid() if no Explicit or Implicit match is found.

Note
  This function will throw if no valid return is provided by the matched declaration implementation.

Parameters

  args | Natively supported function arguments
  B | The current llvm IRBuilder

## ◆ execute() [3/4]

llvm::Value * execute | ( | const std::vector< llvm::Value * > & | args,
|  | llvm::IRBuilder<> & | B ) const

Deprecated
  "FunctionGroup::execute which takes llvm::Value's and " "supports argument matching/casting is incompatible with LLVM 16+ and will be " "removed."

## ◆ execute() [4/4]

const Function * execute | ( | const std::vector< llvm::Value * > & | args,
|  | llvm::IRBuilder<> & | B,
|  | llvm::Value *& | result ) const

Given a vector of llvm values, find the best possible function signature, generate and execute the function body. Returns the Function that was selected and executed or a nullptr if no valid match was found. Sets the result variable to the return value of the function (nullptr if void). If no match is found, the result variable if left unset.

Note
  This function will throw if no valid return is provided by the matched declaration implementation.

Parameters

  args | A vector of values representing the function arguments
  B | The current llvm IRBuilder
  result | The result to set. nullptr on void return.

Returns
  The matched function. nullptr if no match was found

Deprecated
  "FunctionGroup::execute which takes llvm::Value's and " "supports argument matching/casting is incompatible with LLVM 16+ and will be " "removed."

## ◆ HasUniqueTypeSignatures()

bool HasUniqueTypeSignatures | ( | llvm::LLVMContext & | C | ) | const

Verify the function signatures in this group.

## ◆ list()

const FunctionList & list | ( |  | ) | const
| inline

Accessor to the underlying function signature list.

## ◆ match() [1/2]

std::pair< const Function *, Function::SignatureMatch > match | ( | const ArgInfoVector & | args,
|  | llvm::LLVMContext & | C ) const

Given a vector of llvm types, automatically returns the best possible function declaration from the stored function list. The 'best' declaration is determined by the provided types compatibility to each functions signature.

Note
  Returns a nullptr if no compatible match was found or if the function list is empty. A compatible match is defined as an Explicit, Implicit or Ambiguous match (where the latter returns the first matched implicit function where other implicit matches exist).
  If multiple implicit matches are found, the first match is returned and 'type' is set to Ambiguous (if provided).

Warning
  All funcions in this group must implement the types(ArgInfo) virtual function, which is optional in LLVM 15 but required from LLVM 16.

Parameters

  types | A vector of types representing the function argument types
  C | The llvm context
  type | If provided, type is set to the type of match that occurred

## ◆ match() [2/2]

const Function * match | ( | const std::vector< llvm::Type * > & | types,
|  | llvm::LLVMContext & | C,
|  | Function::SignatureMatch * | type = nullptr ) const

Warning
  Does not support detecting Ambiguous functions (returns Implicit in these cases).

Deprecated
  "Switch to AX's internal ArgInfo types for LLVM 16 onwards"

## ◆ name()

const char * name | ( |  | ) | const
| inline