OmniSciDB  a5dc49c757
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TargetExprBuilder.h
Go to the documentation of this file.
1 /*
2  * Copyright 2022 HEAVY.AI, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
23 #pragma once
24 
25 #include <Analyzer/Analyzer.h>
26 #include <Shared/TargetInfo.h>
27 
29 #include "GroupByAndAggregate.h"
30 
31 #include <vector>
32 
36  const int32_t base_slot_index,
37  const size_t target_idx,
38  const bool is_group_by)
39  : target_expr(target_expr)
40  , target_info(target_info)
41  , base_slot_index(base_slot_index)
42  , target_idx(target_idx)
43  , is_group_by(is_group_by) {}
44 
45  void codegen(GroupByAndAggregate* group_by_and_agg,
46  Executor* executor,
48  const CompilationOptions& co,
49  const GpuSharedMemoryContext& gpu_smem_context,
50  const std::tuple<llvm::Value*, llvm::Value*>& agg_out_ptr_w_idx,
51  const std::vector<llvm::Value*>& agg_out_vec,
52  llvm::Value* output_buffer_byte_stream,
53  llvm::Value* out_row_idx,
54  llvm::Value* varlen_output_buffer,
55  DiamondCodegen& diamond_codegen,
56  DiamondCodegen* sample_cfg = nullptr) const;
57 
58  void codegenAggregate(GroupByAndAggregate* group_by_and_agg,
59  Executor* executor,
61  const CompilationOptions& co,
62  const std::vector<llvm::Value*>& target_lvs,
63  const std::tuple<llvm::Value*, llvm::Value*>& agg_out_ptr_w_idx,
64  const std::vector<llvm::Value*>& agg_out_vec,
65  llvm::Value* output_buffer_byte_stream,
66  llvm::Value* out_row_idx,
67  llvm::Value* varlen_output_buffer,
68  int32_t slot_index) const;
69 
70  friend std::ostream& operator<<(std::ostream& os,
71  const TargetExprCodegen& target_expr_codegen);
72 
75 
76  int32_t base_slot_index;
77  size_t target_idx;
79 };
80 
83  : ra_exe_unit(ra_exe_unit), is_group_by(is_group_by) {}
84 
85  void operator()(const Analyzer::Expr* target_expr,
86  const Executor* executor,
88  const CompilationOptions& co);
89 
90  void codegen(GroupByAndAggregate* group_by_and_agg,
91  Executor* executor,
93  const CompilationOptions& co,
94  const GpuSharedMemoryContext& gpu_smem_context,
95  const std::tuple<llvm::Value*, llvm::Value*>& agg_out_ptr_w_idx,
96  const std::vector<llvm::Value*>& agg_out_vec,
97  llvm::Value* output_buffer_byte_stream,
98  llvm::Value* out_row_idx,
99  llvm::Value* varlen_output_buffer,
100  DiamondCodegen& diamond_codegen) const;
101 
103  GroupByAndAggregate* group_by_and_agg,
104  Executor* executor,
106  const CompilationOptions& co,
107  const std::tuple<llvm::Value*, llvm::Value*>& agg_out_ptr_w_idx,
108  const std::vector<llvm::Value*>& agg_out_vec,
109  llvm::Value* output_buffer_byte_stream,
110  llvm::Value* out_row_idx,
111  DiamondCodegen& diamond_codegen) const;
112 
114  GroupByAndAggregate* group_by_and_agg,
115  Executor* executor,
117  const CompilationOptions& co,
118  const std::tuple<llvm::Value*, llvm::Value*>& agg_out_ptr_w_idx,
119  const std::vector<llvm::Value*>& agg_out_vec,
120  llvm::Value* output_buffer_byte_stream,
121  llvm::Value* out_row_idx,
122  DiamondCodegen& diamond_codegen) const;
123 
125  GroupByAndAggregate* group_by_and_agg,
126  Executor* executor,
128  const CompilationOptions& co,
129  const std::tuple<llvm::Value*, llvm::Value*>& agg_out_ptr_w_idx,
130  const std::vector<llvm::Value*>& agg_out_vec,
131  llvm::Value* output_buffer_byte_stream,
132  llvm::Value* out_row_idx,
133  DiamondCodegen& diamond_codegen) const;
134 
135  llvm::Value* codegenSlotEmptyKey(llvm::Value* agg_col_ptr,
136  std::vector<llvm::Value*>& target_lvs,
137  Executor* executor,
139  const int64_t init_val) const;
140 
143 
145 
146  std::vector<TargetExprCodegen> target_exprs_to_codegen;
147  std::vector<TargetExprCodegen> sample_exprs_to_codegen;
148 
150 };
Defines data structures for the semantic analysis phase of query processing.
const RelAlgExecutionUnit & ra_exe_unit
void codegen(GroupByAndAggregate *group_by_and_agg, Executor *executor, const QueryMemoryDescriptor &query_mem_desc, const CompilationOptions &co, const GpuSharedMemoryContext &gpu_smem_context, const std::tuple< llvm::Value *, llvm::Value * > &agg_out_ptr_w_idx, const std::vector< llvm::Value * > &agg_out_vec, llvm::Value *output_buffer_byte_stream, llvm::Value *out_row_idx, llvm::Value *varlen_output_buffer, DiamondCodegen &diamond_codegen, DiamondCodegen *sample_cfg=nullptr) const
void codegenMultiSlotSampleExpressions(GroupByAndAggregate *group_by_and_agg, Executor *executor, const QueryMemoryDescriptor &query_mem_desc, const CompilationOptions &co, const std::tuple< llvm::Value *, llvm::Value * > &agg_out_ptr_w_idx, const std::vector< llvm::Value * > &agg_out_vec, llvm::Value *output_buffer_byte_stream, llvm::Value *out_row_idx, DiamondCodegen &diamond_codegen) const
std::vector< TargetExprCodegen > target_exprs_to_codegen
friend std::ostream & operator<<(std::ostream &os, const TargetExprCodegen &target_expr_codegen)
void operator()(const Analyzer::Expr *target_expr, const Executor *executor, QueryMemoryDescriptor &query_mem_desc, const CompilationOptions &co)
void codegenSampleExpressions(GroupByAndAggregate *group_by_and_agg, Executor *executor, const QueryMemoryDescriptor &query_mem_desc, const CompilationOptions &co, const std::tuple< llvm::Value *, llvm::Value * > &agg_out_ptr_w_idx, const std::vector< llvm::Value * > &agg_out_vec, llvm::Value *output_buffer_byte_stream, llvm::Value *out_row_idx, DiamondCodegen &diamond_codegen) const
std::vector< TargetExprCodegen > sample_exprs_to_codegen
void codegen(GroupByAndAggregate *group_by_and_agg, Executor *executor, const QueryMemoryDescriptor &query_mem_desc, const CompilationOptions &co, const GpuSharedMemoryContext &gpu_smem_context, const std::tuple< llvm::Value *, llvm::Value * > &agg_out_ptr_w_idx, const std::vector< llvm::Value * > &agg_out_vec, llvm::Value *output_buffer_byte_stream, llvm::Value *out_row_idx, llvm::Value *varlen_output_buffer, DiamondCodegen &diamond_codegen) const
TargetExprCodegenBuilder(const RelAlgExecutionUnit &ra_exe_unit, const bool is_group_by)
llvm::Value * codegenSlotEmptyKey(llvm::Value *agg_col_ptr, std::vector< llvm::Value * > &target_lvs, Executor *executor, const QueryMemoryDescriptor &query_mem_desc, const int64_t init_val) const
const Analyzer::Expr * target_expr
Descriptor for the result set buffer layout.
TargetExprCodegen(const Analyzer::Expr *target_expr, TargetInfo &target_info, const int32_t base_slot_index, const size_t target_idx, const bool is_group_by)
void codegenAggregate(GroupByAndAggregate *group_by_and_agg, Executor *executor, const QueryMemoryDescriptor &query_mem_desc, const CompilationOptions &co, const std::vector< llvm::Value * > &target_lvs, const std::tuple< llvm::Value *, llvm::Value * > &agg_out_ptr_w_idx, const std::vector< llvm::Value * > &agg_out_vec, llvm::Value *output_buffer_byte_stream, llvm::Value *out_row_idx, llvm::Value *varlen_output_buffer, int32_t slot_index) const
void codegenSingleSlotSampleExpression(GroupByAndAggregate *group_by_and_agg, Executor *executor, const QueryMemoryDescriptor &query_mem_desc, const CompilationOptions &co, const std::tuple< llvm::Value *, llvm::Value * > &agg_out_ptr_w_idx, const std::vector< llvm::Value * > &agg_out_vec, llvm::Value *output_buffer_byte_stream, llvm::Value *out_row_idx, DiamondCodegen &diamond_codegen) const