OpenVDB  12.0.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_0
 
 openvdb::v12_0::ax
 
 openvdb::v12_0::ax::codegen
 

Macros

#define BIND_ARITHMETIC_CAST_OP(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

auto ir_load (llvm::IRBuilder<> &B, llvm::Value *ptr, const char *Name="")
 Alias around IR load inst. More...
 
auto ir_gep (llvm::IRBuilder<> &B, llvm::Value *ptr, llvm::ArrayRef< llvm::Value * > IdxList, const char *Name="")
 Alias around IR gep inst. More...
 
auto ir_constgep2_64 (llvm::IRBuilder<> &B, llvm::Value *ptr, uint64_t Idx0, uint64_t Idx1, const char *Name="")
 Alias around IR gep2_64 inst. More...
 
auto ir_constinboundsgep2_64 (llvm::IRBuilder<> &B, llvm::Value *ptr, uint64_t Idx0, uint64_t Idx1, const char *Name="")
 Alias around IR in bounds gep2_64 inst. More...
 
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...
 
llvm::Type * getBaseContainedType (llvm::Type *const type)
 Return the base llvm value which is being pointed to through any number of layered pointers. 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...
 
llvm::Value * arrayCast (llvm::Value *ptrToArray, llvm::Type *targetElementType, llvm::IRBuilder<> &builder)
 Casts an array to another array of equal size but of a different element type. Both source and target array element types must be scalar types. The source array llvm Value should be a pointer to the array to cast. 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)
 
llvm::Value * arrayIndexUnpack (llvm::Value *ptrToArray, const int16_t index, llvm::IRBuilder<> &builder)
 Unpack a particular element of an array and return a pointer to that element The provided llvm Value is expected to be a pointer to an array. More...
 
void arrayUnpack (llvm::Value *ptrToArray, std::vector< llvm::Value * > &values, llvm::IRBuilder<> &builder, const bool loadElements=false)
 Unpack an array type into llvm Values which represent all its elements The provided llvm Value is expected to be a pointer to an array If loadElements is true, values will store loaded llvm values instead of pointers to the array elements. More...
 
void array3Unpack (llvm::Value *ptrToArray, llvm::Value *&value1, llvm::Value *&value2, llvm::Value *&value3, llvm::IRBuilder<> &builder)
 Unpack the first three elements of an array. The provided llvm Value is expected to be a pointer to an array. More...
 
llvm::Value * array3Pack (llvm::Value *value1, llvm::Value *value2, llvm::Value *value3, llvm::IRBuilder<> &builder)
 Pack three values into a new array and return a pointer to the newly allocated array. If the values are of a mismatching type, the highets order type is uses, as defined by typePrecedence. All llvm values are expected to a be a loaded scalar type. More...
 
llvm::Value * arrayPack (llvm::Value *value, llvm::IRBuilder<> &builder, const size_t size=3)
 Pack a loaded llvm scalar value into a new array of a specified size and return a pointer to the newly allocated array. Each element of the new array will have the value of the given scalar. More...
 
llvm::Value * arrayPack (const std::vector< llvm::Value * > &values, llvm::IRBuilder<> &builder)
 Pack a vector of loaded llvm scalar values into a new array of equal size and return a pointer to the newly allocated array. More...
 
llvm::Value * arrayPackCast (std::vector< llvm::Value * > &values, llvm::IRBuilder<> &builder)
 Pack a vector of loaded llvm scalar values into a new array of equal size and return a pointer to the newly allocated array. arrayPackCast first checks all the contained types in values and casts all types to the highest order type present. All llvm values in values are expected to be loaded scalar types. More...
 
llvm::Value * scalarToMatrix (llvm::Value *scalar, llvm::IRBuilder<> &builder, const size_t dim=3)
 

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_BINARY_OP (   Function)
Value:
[twine](llvm::IRBuilder<>& B, llvm::Value* L, llvm::Value* R) \
-> llvm::Value* { return B.Function(L, R, twine); }