OpenVDB  12.1.0
Namespaces | Macros | Typedefs | Functions
Utils.h File Reference

Utility code generation methods for performing various llvm operations. More...

#include "Types.h"
#include "../ast/Tokens.h"
#include "../Exceptions.h"
#include <openvdb/version.h>
#include <openvdb/util/Assert.h>
#include <llvm/IR/IRBuilder.h>
#include <llvm/IR/LLVMContext.h>
#include <llvm/Support/raw_ostream.h>

Go to the source code of this file.

Namespaces

 openvdb
 
 openvdb::v12_1
 
 openvdb::v12_1::ax
 
 openvdb::v12_1::ax::codegen
 

Macros

#define BIND_ARITHMETIC_CAST_OP(Function, Twine)
 
#define BIND_ARITHMETIC_CAST_OP_TRUNC(Function, Twine)
 
#define BIND_ARITHMETIC_CAST_OP_UIFP(Function, Twine)
 
#define BIND_ARITHMETIC_CAST_OP_ZEXT(Function, Twine)
 
#define BIND_ARITHMETIC_CAST_OP_FP(Function, Twine)
 
#define BIND_BINARY_OP(Function)
 

Typedefs

using CastFunction = std::function< llvm::Value *(llvm::IRBuilder<> &, llvm::Value *, llvm::Type *)>
 
using BinaryFunction = std::function< llvm::Value *(llvm::IRBuilder<> &, llvm::Value *, llvm::Value *)>
 

Functions

bool AssertOpaquePtrs ([[maybe_unused]]llvm::Value *opaque, [[maybe_unused]]llvm::Type *type)
 
void valuesToTypes (const std::vector< llvm::Value * > &values, std::vector< llvm::Type * > &types)
 Populate a vector of llvm Types from a vector of llvm values. More...
 
void llvmTypeToString (const llvm::Type *const type, std::string &str)
 Prints an llvm type to a std string. More...
 
template<typename ValueT >
llvm::Value * llvmPointerFromAddress (const ValueT *const &ptr, llvm::IRBuilder<> &builder)
 Return an llvm value representing a pointer to the provided ptr builtin ValueT. More...
 
llvm::Value * insertStaticAlloca (llvm::IRBuilder<> &B, llvm::Type *type, llvm::Value *size=nullptr)
 Insert a stack allocation at the beginning of the current function of the provided type and size. The IRBuilder's insertion point must be set to a BasicBlock with a valid Function parent. More...
 
llvm::Argument * extractArgument (llvm::Function *F, const size_t idx)
 
llvm::Argument * extractArgument (llvm::Function *F, const std::string &name)
 
llvm::Type * typePrecedence (llvm::Type *const typeA, llvm::Type *const typeB)
 Returns the highest order type from two LLVM Scalar types. More...
 
CastFunction llvmArithmeticConversion (const llvm::Type *const sourceType, const llvm::Type *const targetType, const std::string &twine="")
 Returns a CastFunction which represents the corresponding instruction to convert a source llvm Type to a target llvm Type. If the conversion is unsupported, throws an error. More...
 
BinaryFunction llvmBinaryConversion (const llvm::Type *const type, const ast::tokens::OperatorToken &token, const std::string &twine="")
 Returns a BinaryFunction representing the corresponding instruction to perform on two scalar values, relative to a provided operator token. Note that not all operations are supported on floating point types! If the token is not supported, or the llvm type is not a scalar type, throws an error. More...
 
bool isValidCast (llvm::Type *from, llvm::Type *to)
 Returns true if the llvm Type 'from' can be safely cast to the llvm Type 'to'. More...
 
llvm::Value * arithmeticConversion (llvm::Value *value, llvm::Type *targetType, llvm::IRBuilder<> &builder)
 Casts a scalar llvm Value to a target scalar llvm Type. Returns the cast scalar value of type targetType. More...
 
void arithmeticConversion (std::vector< llvm::Value * > &values, llvm::Type *targetElementType, llvm::IRBuilder<> &builder)
 Converts a vector of loaded llvm scalar values of the same type to a target scalar type. Each value is converted individually and the loaded result stored in the same location within values. More...
 
void arithmeticConversion (std::vector< llvm::Value * > &values, llvm::IRBuilder<> &builder)
 Converts a vector of loaded llvm scalar values to the highest precision type stored amongst them. Any values which are not scalar types are ignored. More...
 
void arithmeticConversion (llvm::Value *&valueA, llvm::Value *&valueB, llvm::IRBuilder<> &builder)
 Chooses the highest order llvm Type as defined by typePrecedence from either of the two incoming values and casts the other value to the choosen type if it is not already. The types of valueA and valueB are guaranteed to match. Both values must be scalar LLVM types. More...
 
llvm::Value * boolComparison (llvm::Value *value, llvm::IRBuilder<> &builder)
 Performs a C style boolean comparison from a given scalar LLVM value. More...
 
llvm::Value * binaryOperator (llvm::Value *lhs, llvm::Value *rhs, const ast::tokens::OperatorToken &token, llvm::IRBuilder<> &builder)
 

Detailed Description

Utility code generation methods for performing various llvm operations.

Authors
Nick Avramoussis

Macro Definition Documentation

#define BIND_ARITHMETIC_CAST_OP (   Function,
  Twine 
)
Value:
std::bind(&Function, \
std::placeholders::_1, \
std::placeholders::_2, \
std::placeholders::_3, \
Twine)
#define BIND_ARITHMETIC_CAST_OP_FP (   Function,
  Twine 
)
Value:
std::bind(&Function, \
std::placeholders::_1, \
std::placeholders::_2, \
std::placeholders::_3, \
Twine)
#define BIND_ARITHMETIC_CAST_OP_TRUNC (   Function,
  Twine 
)
Value:
std::bind(&Function, \
std::placeholders::_1, \
std::placeholders::_2, \
std::placeholders::_3, \
Twine)
#define BIND_ARITHMETIC_CAST_OP_UIFP (   Function,
  Twine 
)
Value:
std::bind(&Function, \
std::placeholders::_1, \
std::placeholders::_2, \
std::placeholders::_3, \
Twine)
#define BIND_ARITHMETIC_CAST_OP_ZEXT (   Function,
  Twine 
)
Value:
std::bind(&Function, \
std::placeholders::_1, \
std::placeholders::_2, \
std::placeholders::_3, \
Twine)
#define BIND_BINARY_OP (   Function)
Value:
[twine](llvm::IRBuilder<>& B, llvm::Value* L, llvm::Value* R) \
-> llvm::Value* { return B.Function(L, R, twine); }