OpenVDB  9.0.1
Classes | Public Types | Public Member Functions | List of all members
FunctionBuilder Struct Reference

The FunctionBuilder class provides a builder pattern framework to allow easy and valid construction of AX functions. There are a number of complex tasks which may need to be performed during construction of C or IR function which are delegated to this builder, whilst ensuring that the constructed functions are guaranteed to be valid. More...

#include <openvdb_ax/codegen/FunctionTypes.h>

Classes

struct  Settings
 

Public Types

enum  DeclPreferrence { C, IR, Any }
 

Public Member Functions

 FunctionBuilder (const char *name)
 
template<typename Signature , bool SRet = false>
FunctionBuilderaddSignature (const IRFunctionBase::GeneratorCb &cb, const char *symbol=nullptr)
 
template<typename Signature , bool SRet = false>
FunctionBuilderaddSignature (const Signature *ptr, const char *symbol=nullptr)
 
template<typename Signature , bool SRet = false>
FunctionBuilderaddSignature (const IRFunctionBase::GeneratorCb &cb, const Signature *ptr, const char *symbol=nullptr)
 
FunctionBuilderaddDependency (const char *name)
 
FunctionBuildersetEmbedIR (bool on)
 
FunctionBuildersetConstantFold (bool on)
 
FunctionBuildersetArgumentNames (const std::vector< const char * > &names)
 
FunctionBuilderaddParameterAttribute (const size_t idx, const llvm::Attribute::AttrKind attr)
 
FunctionBuilderaddReturnAttribute (const llvm::Attribute::AttrKind attr)
 
FunctionBuilderaddFunctionAttribute (const llvm::Attribute::AttrKind attr)
 
FunctionBuildersetDocumentation (const char *doc)
 
FunctionBuildersetPreferredImpl (DeclPreferrence pref)
 
FunctionGroup::UniquePtr get () const
 

Detailed Description

The FunctionBuilder class provides a builder pattern framework to allow easy and valid construction of AX functions. There are a number of complex tasks which may need to be performed during construction of C or IR function which are delegated to this builder, whilst ensuring that the constructed functions are guaranteed to be valid.

Use the FunctionBuilder::addSignature methods to append function signatures. Finalize the group of functions with FunctionBuilder::get.

Member Enumeration Documentation

Enumerator
IR 
Any 

Constructor & Destructor Documentation

FunctionBuilder ( const char *  name)
inline

Member Function Documentation

FunctionBuilder& addDependency ( const char *  name)
inline
FunctionBuilder& addFunctionAttribute ( const llvm::Attribute::AttrKind  attr)
inline
FunctionBuilder& addParameterAttribute ( const size_t  idx,
const llvm::Attribute::AttrKind  attr 
)
inline

Parameter and Function Attributes. When designing a C binding, llvm will be unable to assign parameter markings to the return type, function body or parameter attributes due to there not being any visibility on the function itself during codegen. The best way to ensure performant C bindings is to ensure that the function is marked with the required llvm parameters. Some of the heavy hitters (which can have the most impact) are below:

Functions:

  • norecurse This function attribute indicates that the function does not call itself either directly or indirectly down any possible call path.
  • willreturn This function attribute indicates that a call of this function will either exhibit undefined behavior or comes back and continues execution at a point in the existing call stack that includes the current invocation.
  • nounwind This function attribute indicates that the function never raises an exception.
  • readnone On a function, this attribute indicates that the function computes its result (or decides to unwind an exception) based strictly on its arguments, without dereferencing any pointer arguments or otherwise accessing any mutable state (e.g. memory, control registers, etc) visible to caller functions.
  • readonly On a function, this attribute indicates that the function does not write through any pointer arguments (including byval arguments) or otherwise modify any state (e.g. memory, control registers, etc) visible to caller functions. control registers, etc) visible to caller functions.
  • writeonly On a function, this attribute indicates that the function may write to but does not read from memory.

Parameters:

  • noalias This indicates that objects accessed via pointer values based on the argument or return value are not also accessed, during the execution of the function, via pointer values not based on the argument or return value.
  • nonnull This indicates that the parameter or return pointer is not null.
  • readonly Indicates that the function does not write through this pointer argument, even though it may write to the memory that the pointer points to.
  • writeonly Indicates that the function may write to but does not read through this pointer argument (even though it may read from the memory that the pointer points to).
FunctionBuilder& addReturnAttribute ( const llvm::Attribute::AttrKind  attr)
inline
FunctionBuilder& addSignature ( const IRFunctionBase::GeneratorCb cb,
const char *  symbol = nullptr 
)
inline
FunctionBuilder& addSignature ( const Signature *  ptr,
const char *  symbol = nullptr 
)
inline
FunctionBuilder& addSignature ( const IRFunctionBase::GeneratorCb cb,
const Signature *  ptr,
const char *  symbol = nullptr 
)
inline
FunctionGroup::UniquePtr get ( ) const
inline
FunctionBuilder& setArgumentNames ( const std::vector< const char * > &  names)
inline
FunctionBuilder& setConstantFold ( bool  on)
inline
FunctionBuilder& setDocumentation ( const char *  doc)
inline
FunctionBuilder& setEmbedIR ( bool  on)
inline
FunctionBuilder& setPreferredImpl ( DeclPreferrence  pref)
inline