OpenVDB: openvdb_ax/codegen/PointComputeGenerator.h Source File

OpenVDB 9.0.0

PointComputeGenerator.h
Go to the documentation of this file.
1// Copyright Contributors to the OpenVDB Project
2// SPDX-License-Identifier: MPL-2.0
3
4/// @file codegen/PointComputeGenerator.h
5///
6/// @authors Nick Avramoussis, Matt Warner, Francisco Gochez, Richard Jones
7///
8/// @brief The visitor framework and function definition for point data
9/// grid code generation
10///
11
12#ifndef OPENVDB_AX_POINT_COMPUTE_GENERATOR_HAS_BEEN_INCLUDED
13#define OPENVDB_AX_POINT_COMPUTE_GENERATOR_HAS_BEEN_INCLUDED
14
15#include "ComputeGenerator.h"
16#include "FunctionTypes.h"
17#include "Types.h"
18#include "Utils.h"
19
20#include "../compiler/AttributeRegistry.h"
21
22#include <openvdb/version.h>
23
24namespace openvdb {
25 OPENVDB_USE_VERSION_NAMESPACE
26namespace OPENVDB_VERSION_NAME {
27
28namespace ax {
29namespace codegen {
30
31/// @brief The function definition and signature which is built by the
32/// PointComputeGenerator.
33///
34/// The argument structure is as follows:
35///
36/// 1) - A void pointer to the CustomData
37/// 2) - A void pointer to the leaf AttributeSet
38/// 3) - An unsigned integer, representing the leaf relative point
39/// id being executed
40/// 4) - A void pointer to a vector of void pointers, representing an
41/// array of attribute handles
42/// 5) - A void pointer to a vector of void pointers, representing an
43/// array of group handles
44/// 6) - A void pointer to a LeafLocalData object, used to track newly
45/// initialized attributes and arrays
46///
47 struct PointKernel
48{
49 /// The signature of the generated function
50 using Signature =
51 void(const void* const,
52 const void* const,
53 uint64_t,
54 void**,
55 void**,
56 void*);
57
58 using FunctionTraitsT = codegen::FunctionTraits<Signature>;
59 static const size_t N_ARGS = FunctionTraitsT::N_ARGS;
60
61 /// The argument key names available during code generation
62 static const std::array<std::string, N_ARGS>& argumentKeys();
63 static std::string getDefaultName();
64};
65
66/// @brief An additional function built by the PointComputeGenerator.
67/// Currently both compute and compute range functions have the same
68/// signature
69 struct PointRangeKernel : public PointKernel
70{
71 static std::string getDefaultName();
72};
73
74
75///////////////////////////////////////////////////////////////////////////
76///////////////////////////////////////////////////////////////////////////
77
78namespace codegen_internal {
79
80/// @brief Visitor object which will generate llvm IR for a syntax tree which has been generated from
81/// AX that targets point grids. The IR will represent 2 functions : one that executes over
82/// single points and one that executes over a collection of points. This is primarily used by the
83/// Compiler class.
84 struct PointComputeGenerator : public ComputeGenerator
85{
86 /// @brief Constructor
87 /// @param module llvm Module for generating IR
88 /// @param options Options for the function registry behaviour
89 /// @param functionRegistry Function registry object which will be used when generating IR
90 /// for function calls
91 /// @param logger Logger for collecting logical errors and warnings
92 PointComputeGenerator(llvm::Module& module,
93 const FunctionOptions& options,
94 FunctionRegistry& functionRegistry,
95 Logger& logger);
96
97 ~PointComputeGenerator() override = default;
98
99 using ComputeGenerator::traverse;
100 using ComputeGenerator::visit;
101
102 AttributeRegistry::Ptr generate(const ast::Tree& node);
103 bool visit(const ast::Attribute*) override;
104
105private:
106 llvm::Value* attributeHandleFromToken(const std::string&);
107 void getAttributeValue(const std::string& globalName, llvm::Value* location);
108};
109
110} // namespace namespace codegen_internal
111
112} // namespace codegen
113} // namespace ax
114} // namespace OPENVDB_VERSION_NAME
115} // namespace openvdb
116
117#endif // OPENVDB_AX_POINT_COMPUTE_GENERATOR_HAS_BEEN_INCLUDED
118
ComputeGenerator.h
The core visitor framework for code generation.
FunctionTypes.h
Contains frameworks for creating custom AX functions which can be registered within the FunctionRegis...
Types.h
Consolidated llvm types for most supported types.
openvdb::v9_0::ax::AttributeRegistry::Ptr
std::shared_ptr< AttributeRegistry > Ptr
Definition: AttributeRegistry.h:41
openvdb::v9_0::ax::Logger
Logger for collecting errors and warnings that occur during AX compilation.
Definition: Logger.h:55
openvdb::v9_0::ax::codegen::FunctionRegistry
The function registry which is used for function code generation. Each time a function is visited wit...
Definition: FunctionRegistry.h:37
openvdb
Definition: Exceptions.h:13
Utils.h
Utility classes and functions for OpenVDB plugins.
openvdb::v9_0::ax::FunctionOptions
Options that control how functions behave.
Definition: CompilerOptions.h:25
openvdb::v9_0::ax::ast::Attribute
Attributes represent any access to a primitive value, typically associated with the '@' symbol syntax...
Definition: AST.h:1874
openvdb::v9_0::ax::ast::Tree
A Tree is the highest concrete (non-abstract) node in the entire AX AST hierarchy....
Definition: AST.h:562
openvdb::v9_0::ax::codegen::FunctionTraits
Templated function traits which provides compile-time index access to the types of the function signa...
Definition: Types.h:259
openvdb::v9_0::ax::codegen::PointKernel
The function definition and signature which is built by the PointComputeGenerator.
Definition: PointComputeGenerator.h:48
openvdb::v9_0::ax::codegen::PointKernel::Signature
void(const void *const, const void *const, uint64_t, void **, void **, void *) Signature
The signature of the generated function.
Definition: PointComputeGenerator.h:56
openvdb::v9_0::ax::codegen::PointKernel::argumentKeys
static const std::array< std::string, N_ARGS > & argumentKeys()
The argument key names available during code generation.
openvdb::v9_0::ax::codegen::PointKernel::getDefaultName
static std::string getDefaultName()
openvdb::v9_0::ax::codegen::PointRangeKernel
An additional function built by the PointComputeGenerator. Currently both compute and compute range f...
Definition: PointComputeGenerator.h:70
openvdb::v9_0::ax::codegen::PointRangeKernel::getDefaultName
static std::string getDefaultName()
openvdb::v9_0::ax::codegen::codegen_internal::ComputeGenerator
Visitor object which will generate llvm IR for a syntax tree. This provides the majority of the code ...
Definition: ComputeGenerator.h:87
openvdb::v9_0::ax::codegen::codegen_internal::PointComputeGenerator
Visitor object which will generate llvm IR for a syntax tree which has been generated from AX that ta...
Definition: PointComputeGenerator.h:85
openvdb::v9_0::ax::codegen::codegen_internal::PointComputeGenerator::generate
AttributeRegistry::Ptr generate(const ast::Tree &node)
openvdb::v9_0::ax::codegen::codegen_internal::PointComputeGenerator::~PointComputeGenerator
~PointComputeGenerator() override=default
openvdb::v9_0::ax::codegen::codegen_internal::PointComputeGenerator::visit
bool visit(const ast::Attribute *) override
Visitor methods for all AST nodes which implement IR generation.
openvdb::v9_0::ax::codegen::codegen_internal::PointComputeGenerator::PointComputeGenerator
PointComputeGenerator(llvm::Module &module, const FunctionOptions &options, FunctionRegistry &functionRegistry, Logger &logger)
Constructor.
OPENVDB_VERSION_NAME
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h.in:116
OPENVDB_USE_VERSION_NAMESPACE
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h.in:202