OpenVDB 11.0.0

Loading...
Searching...
No Matches
Public Types | Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
IRFunctionBase Struct Referenceabstract

The base/abstract definition for an IR function. More...

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

Inheritance diagram for IRFunctionBase:

## Public Types
using | Ptr = std::shared_ptr<IRFunctionBase>
using | GeneratorCb
| The IR callback function which will write the LLVM IR for this function's body.
enum | SignatureMatch { None = 0 , Size , Implicit , Explicit }
| The result type from calls to Function::match. More...

## Public Member Functions
void | setEmbedIR (bool on)
| Enable or disable the embedding of IR. Embedded IR is currently required for function which use parent function parameters.
bool | hasEmbedIR () const
llvm::Function * | create (llvm::LLVMContext &C, llvm::Module *M) const override
| Override for the creation of an IR function. This ensures that the body and prototype of the function are generated if a Module is provided.
llvm::Value * | call (const std::vector< llvm::Value * > &args, llvm::IRBuilder<> &B, const bool cast) const override
| Override for call, which is only necessary if mEmbedIR is true, as the IR generation for embedded functions is delayed until the function is called. If mEmbedIR is false, this simply calls Function::call.
virtual llvm::Type * | types (std::vector< llvm::Type * > &, llvm::LLVMContext &) const =0
| Populate a vector of llvm::Types which describe this function signature. This method is used by Function::create, Function::print and Function::match.
llvm::Function * | create (llvm::Module &M) const
| Convenience method which always uses the provided module to find the function or insert it if necessary.
llvm::Function * | get (const llvm::Module &M) const
| Convenience method for calling M.getFunction(symbol). Returns a nullptr if the function has not yet been created or if it is embedded IR.
virtual SignatureMatch | match (const std::vector< llvm::Type * > &inputs, llvm::LLVMContext &C) const
| The base implementation for determining how a vector of llvm arguments translates to this functions signature. Returns an enum which represents the available mapping.
size_t | size () const
| The number of arguments that this function has.
const char * | symbol () const
| The function symbol name.
const char * | argName (const size_t idx) const
| Returns the descriptive name of the given argument index.
virtual void | print (llvm::LLVMContext &C, std::ostream &os, const char *name=nullptr, const bool axTypes=true) const
| Print this function's signature to the provided ostream.
bool | hasParamAttribute (const size_t i, const llvm::Attribute::AttrKind &kind) const
| Builder methods.
void | setArgumentNames (std::vector< const char * > names)
const std::vector< const char * > & | dependencies () const
void | setDependencies (std::vector< const char * > deps)
void | setFnAttributes (const std::vector< llvm::Attribute::AttrKind > &in)
void | setRetAttributes (const std::vector< llvm::Attribute::AttrKind > &in)
void | setParamAttributes (const size_t i, const std::vector< llvm::Attribute::AttrKind > &in)

## Protected Member Functions
void | verifyResultType (const llvm::Type *result, const llvm::Type *expected) const
| IRFunctionBase (const std::string &symbol, const GeneratorCb &gen, const size_t size)
| ~IRFunctionBase () override=default

## Static Protected Member Functions
static void | cast (std::vector< llvm::Value * > &args, const std::vector< llvm::Type * > &types, llvm::IRBuilder<> &B)
| Cast the provided arguments to the given type as supported by implicit casting of function types. If the types already match OR if a cast cannot be performed, nothing is done to the argument.

## Protected Attributes
const GeneratorCb | mGen
bool | mEmbedIR

## Detailed Description

The base/abstract definition for an IR function.

## Member Typedef Documentation

## ◆ GeneratorCb

using GeneratorCb

Initial value:
std::function<llvm::Value*
(const std::vector<llvm::Value*>&, llvm::IRBuilder<>&)>

The IR callback function which will write the LLVM IR for this function's body.

The first argument is the vector of functional arguments. i.e. a representation of the value that the callback has been invoked with. The last argument is the IR builder which should be used to generate the function body IR.

Note
  You can return a nullptr from this method which will represent a ret void, a ret void instruction, or an actual value

## ◆ Ptr

using Ptr = std::shared_ptr<IRFunctionBase>

## Member Enumeration Documentation

## ◆ SignatureMatch

enum SignatureMatch
| inherited

The result type from calls to Function::match.

Enumerator
None |
Size |
Implicit |
Explicit |

## Constructor & Destructor Documentation

## ◆ IRFunctionBase()

IRFunctionBase | ( | const std::string & | symbol,
|  | const GeneratorCb & | gen,
|  | const size_t | size )
| inline protected

## ◆ ~IRFunctionBase()

~IRFunctionBase | ( |  | ) |
| override protected default

## Member Function Documentation

## ◆ argName()

const char * argName | ( | const size_t | idx | ) | const
| inline inherited

Returns the descriptive name of the given argument index.

If the index is greater than the number of arguments, an empty string is returned.

Parameters

  idx | The index of the argument

## ◆ call()

llvm::Value * call | ( | const std::vector< llvm::Value * > & | args,
|  | llvm::IRBuilder<> & | B,
|  | const bool | cast ) const
| override virtual

Override for call, which is only necessary if mEmbedIR is true, as the IR generation for embedded functions is delayed until the function is called. If mEmbedIR is false, this simply calls Function::call.

Reimplemented from Function.

Reimplemented in SRetFunction< SignatureT, IRFunction< SignatureT > >.

## ◆ cast()

static void cast | ( | std::vector< llvm::Value * > & | args,
|  | const std::vector< llvm::Type * > & | types,
|  | llvm::IRBuilder<> & | B )
| static protected inherited

Cast the provided arguments to the given type as supported by implicit casting of function types. If the types already match OR if a cast cannot be performed, nothing is done to the argument.

## ◆ create() [1/2]

llvm::Function * create | ( | llvm::Module & | M | ) | const
| inline inherited

Convenience method which always uses the provided module to find the function or insert it if necessary.

Parameters

  M | The llvm::Module to use

## ◆ create() [2/2]

llvm::Function * create | ( | llvm::LLVMContext & | C,
|  | llvm::Module * | M ) const
| override virtual

Override for the creation of an IR function. This ensures that the body and prototype of the function are generated if a Module is provided.

Note
  A nullptr is returned if mEmbedIR is true and no action is performed.
  Throws if this function has been initialized with a nullptr generator callback. In this case, the function prototype will be created, but not the function body.
  Throws if the return type of the generator callback does not match the function prototype. In this case, both the prototype and the function body will be created and inserted, but the IR will be invalid.

Reimplemented from Function.

## ◆ dependencies()

const std::vector< const char * > & dependencies | ( |  | ) | const
| inline inherited

## ◆ get()

llvm::Function * get | ( | const llvm::Module & | M | ) | const
| inherited

Convenience method for calling M.getFunction(symbol). Returns a nullptr if the function has not yet been created or if it is embedded IR.

Parameters

  M | The llvm::Module to use

## ◆ hasEmbedIR()

bool hasEmbedIR | ( |  | ) | const
| inline

## ◆ hasParamAttribute()

bool hasParamAttribute | ( | const size_t | i,
|  | const llvm::Attribute::AttrKind & | kind ) const
| inline inherited

Builder methods.

## ◆ match()

virtual SignatureMatch match | ( | const std::vector< llvm::Type * > & | inputs,
|  | llvm::LLVMContext & | C ) const
| virtual inherited

The base implementation for determining how a vector of llvm arguments translates to this functions signature. Returns an enum which represents the available mapping.

This method calls types() to figure out the function signature, then compares each argument type to the type in the input vector. If the types match exactly, an Explicit match is found. If the sizes of the inputs and signature differ, no match is found and None is returned. If however, the sizes match and there exists a valid implicit cast from the input type to the signature type for every input, an Implicit match is returned. Finally, if the sizes match but there is no implicit cast mapping, Size is returned. i8 -> i32 : Implicit i32 -> i32 : Explicit str -> i32 : Size (i32,i32) -> i32 : None

Note
  Due to the way CFunctionSRet is implemented, the LLVM Context must be provided in case we have a zero arg function signature with a SRET.

Parameters

  inputs | The input types
  C | The LLVM Context

Reimplemented in SRetFunction< SignatureT, CFunction< SignatureT > >, and SRetFunction< SignatureT, IRFunction< SignatureT > >.

## ◆ print()

virtual void print | ( | llvm::LLVMContext & | C,
|  | std::ostream & | os,
|  | const char * | name = nullptr,
|  | const bool | axTypes = true ) const
| virtual inherited

Print this function's signature to the provided ostream.

This is intended to return a descriptive front end user string rather than the function's IR representation. This function is virtual so that derived classes can customize how they present frontend information.

See also
  printSignature

Parameters

  C | The llvm context
  os | The ostream to print to
  name | The name to insert into the description.
  axTypes | Whether to print llvm IR or AX Types.

Reimplemented in SRetFunction< SignatureT, CFunction< SignatureT > >, and SRetFunction< SignatureT, IRFunction< SignatureT > >.

## ◆ setArgumentNames()

void setArgumentNames | ( | std::vector< const char * > | names | ) |
| inline inherited

## ◆ setDependencies()

void setDependencies | ( | std::vector< const char * > | deps | ) |
| inline inherited

## ◆ setEmbedIR()

void setEmbedIR | ( | bool | on | ) |
| inline

Enable or disable the embedding of IR. Embedded IR is currently required for function which use parent function parameters.

## ◆ setFnAttributes()

void setFnAttributes | ( | const std::vector< llvm::Attribute::AttrKind > & | in | ) |
| inline inherited

## ◆ setParamAttributes()

void setParamAttributes | ( | const size_t | i,
|  | const std::vector< llvm::Attribute::AttrKind > & | in )
| inline inherited

## ◆ setRetAttributes()

void setRetAttributes | ( | const std::vector< llvm::Attribute::AttrKind > & | in | ) |
| inline inherited

## ◆ size()

size_t size | ( |  | ) | const
| inline inherited

The number of arguments that this function has.

## ◆ symbol()

const char * symbol | ( |  | ) | const
| inline inherited

The function symbol name.

This will be used as its identifier in IR and must be unique.

## ◆ types()

virtual llvm::Type * types | ( | std::vector< llvm::Type * > & | ,
|  | llvm::LLVMContext & | ) const
| pure virtual inherited

Populate a vector of llvm::Types which describe this function signature. This method is used by Function::create, Function::print and Function::match.

Implemented in CFunction< SignatureT >, and IRFunction< SignatureT >.

## ◆ verifyResultType()

void verifyResultType | ( | const llvm::Type * | result,
|  | const llvm::Type * | expected ) const
| inline protected

## Member Data Documentation

## ◆ mEmbedIR

bool mEmbedIR
| protected

## ◆ mGen

const GeneratorCb mGen
| protected