OmniSciDB  1dac507f6e
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
CodeGenerator.h
Go to the documentation of this file.
1 /*
2  * Copyright 2019 OmniSci, 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 
17 #pragma once
18 
19 #include <llvm/IR/Value.h>
20 
21 #include "../Analyzer/Analyzer.h"
22 #include "Execute.h"
23 
24 // Code generation utility to be used for queries and scalar expressions.
26  public:
28  : executor_(executor)
29  , cgen_state_(executor->cgen_state_.get())
30  , plan_state_(executor->plan_state_.get()) {}
31 
32  // Overload which can be used without an executor, for SQL scalar expression code
33  // generation.
35  : executor_(nullptr), cgen_state_(cgen_state), plan_state_(plan_state) {}
36 
37  // Generates IR value(s) for the given analyzer expression.
38  std::vector<llvm::Value*> codegen(const Analyzer::Expr*,
39  const bool fetch_columns,
40  const CompilationOptions&);
41 
42  // Generates constant values in the literal buffer of a query.
43  std::vector<llvm::Value*> codegenHoistedConstants(
44  const std::vector<const Analyzer::Constant*>& constants,
45  const EncodingType enc_type,
46  const int dict_id);
47 
48  llvm::ConstantInt* codegenIntConst(const Analyzer::Constant* constant);
49 
50  llvm::Value* codegenCastBetweenIntTypes(llvm::Value* operand_lv,
51  const SQLTypeInfo& operand_ti,
52  const SQLTypeInfo& ti,
53  bool upscale = true);
54 
55  void codegenCastBetweenIntTypesOverflowChecks(llvm::Value* operand_lv,
56  const SQLTypeInfo& operand_ti,
57  const SQLTypeInfo& ti,
58  const int64_t scale);
59 
60  // Generates the index of the current row in the context of query execution.
61  llvm::Value* posArg(const Analyzer::Expr*) const;
62 
63  llvm::Value* toBool(llvm::Value*);
64 
65  llvm::Value* castArrayPointer(llvm::Value* ptr, const SQLTypeInfo& elem_ti);
66 
67  static std::unordered_set<llvm::Function*> markDeadRuntimeFuncs(
68  llvm::Module& module,
69  const std::vector<llvm::Function*>& roots,
70  const std::vector<llvm::Function*>& leaves);
71 
73  llvm::Function* func,
74  const std::unordered_set<llvm::Function*>& live_funcs,
75  const CompilationOptions& co);
76 
77  static std::string generatePTX(const std::string& cuda_llir,
78  llvm::TargetMachine* nvptx_target_machine,
80 
81  static std::unique_ptr<llvm::TargetMachine> initializeNVPTXBackend();
82 
83  static bool alwaysCloneRuntimeFunction(const llvm::Function* func);
84 
85  struct GPUCode {
86  std::vector<std::pair<void*, void*>> native_functions;
87  std::vector<std::tuple<void*, GpuCompilationContext*>> cached_functions;
88  };
89 
90  struct GPUTarget {
91  llvm::TargetMachine* nvptx_target_machine;
93  unsigned block_size;
96  };
97 
99  llvm::Function* func,
100  llvm::Function* wrapper_func,
101  const std::unordered_set<llvm::Function*>& live_funcs,
102  const CompilationOptions& co,
103  const GPUTarget& gpu_target);
104 
105  static void link_udf_module(const std::unique_ptr<llvm::Module>& udf_module,
106  llvm::Module& module,
108  llvm::Linker::Flags flags = llvm::Linker::Flags::None);
109 
110  static bool prioritizeQuals(const RelAlgExecutionUnit& ra_exe_unit,
111  std::vector<Analyzer::Expr*>& primary_quals,
112  std::vector<Analyzer::Expr*>& deferred_quals);
113 
114  struct ExecutorRequired : public std::runtime_error {
116  : std::runtime_error("Executor required to generate this expression") {}
117  };
118 
119  private:
120  std::vector<llvm::Value*> codegen(const Analyzer::Constant*,
121  const EncodingType enc_type,
122  const int dict_id,
123  const CompilationOptions&);
124 
125  virtual std::vector<llvm::Value*> codegenColumn(const Analyzer::ColumnVar*,
126  const bool fetch_column,
127  const CompilationOptions&);
128 
129  llvm::Value* codegenArith(const Analyzer::BinOper*, const CompilationOptions&);
130 
131  llvm::Value* codegenUMinus(const Analyzer::UOper*, const CompilationOptions&);
132 
133  llvm::Value* codegenCmp(const Analyzer::BinOper*, const CompilationOptions&);
134 
135  llvm::Value* codegenCmp(const SQLOps,
136  const SQLQualifier,
137  std::vector<llvm::Value*>,
138  const SQLTypeInfo&,
139  const Analyzer::Expr*,
140  const CompilationOptions&);
141 
142  llvm::Value* codegenIsNull(const Analyzer::UOper*, const CompilationOptions&);
143 
144  llvm::Value* codegenIsNullNumber(llvm::Value*, const SQLTypeInfo&);
145 
146  llvm::Value* codegenLogical(const Analyzer::BinOper*, const CompilationOptions&);
147 
148  llvm::Value* codegenLogical(const Analyzer::UOper*, const CompilationOptions&);
149 
150  llvm::Value* codegenCast(const Analyzer::UOper*, const CompilationOptions&);
151 
152  llvm::Value* codegenCast(llvm::Value* operand_lv,
153  const SQLTypeInfo& operand_ti,
154  const SQLTypeInfo& ti,
155  const bool operand_is_const,
156  const CompilationOptions& co);
157 
158  llvm::Value* codegen(const Analyzer::InValues*, const CompilationOptions&);
159 
160  llvm::Value* codegen(const Analyzer::InIntegerSet* expr, const CompilationOptions& co);
161 
162  std::vector<llvm::Value*> codegen(const Analyzer::CaseExpr*, const CompilationOptions&);
163 
164  llvm::Value* codegen(const Analyzer::ExtractExpr*, const CompilationOptions&);
165 
166  llvm::Value* codegen(const Analyzer::DateaddExpr*, const CompilationOptions&);
167 
168  llvm::Value* codegen(const Analyzer::DatediffExpr*, const CompilationOptions&);
169 
170  llvm::Value* codegen(const Analyzer::DatetruncExpr*, const CompilationOptions&);
171 
172  llvm::Value* codegen(const Analyzer::CharLengthExpr*, const CompilationOptions&);
173 
174  llvm::Value* codegen(const Analyzer::KeyForStringExpr*, const CompilationOptions&);
175 
176  llvm::Value* codegen(const Analyzer::LowerExpr*, const CompilationOptions&);
177 
178  llvm::Value* codegen(const Analyzer::LikeExpr*, const CompilationOptions&);
179 
180  llvm::Value* codegen(const Analyzer::RegexpExpr*, const CompilationOptions&);
181 
182  llvm::Value* codegenUnnest(const Analyzer::UOper*, const CompilationOptions&);
183 
184  llvm::Value* codegenArrayAt(const Analyzer::BinOper*, const CompilationOptions&);
185 
186  llvm::Value* codegen(const Analyzer::CardinalityExpr*, const CompilationOptions&);
187 
188  std::vector<llvm::Value*> codegenArrayExpr(const Analyzer::ArrayExpr*,
189  const CompilationOptions&);
190 
191  std::vector<llvm::Value*> codegenGeoExpr(const Analyzer::GeoExpr*,
192  const CompilationOptions&);
193 
194  llvm::Value* codegenFunctionOper(const Analyzer::FunctionOper*,
195  const CompilationOptions&);
196 
199  const CompilationOptions&);
200 
201  llvm::Value* codegen(const Analyzer::BinOper*, const CompilationOptions&);
202 
203  llvm::Value* codegen(const Analyzer::UOper*, const CompilationOptions&);
204 
205  std::vector<llvm::Value*> codegenHoistedConstantsLoads(const SQLTypeInfo& type_info,
206  const EncodingType enc_type,
207  const int dict_id,
208  const int16_t lit_off);
209 
210  std::vector<llvm::Value*> codegenHoistedConstantsPlaceholders(
211  const SQLTypeInfo& type_info,
212  const EncodingType enc_type,
213  const int16_t lit_off,
214  const std::vector<llvm::Value*>& literal_loads);
215 
216  std::vector<llvm::Value*> codegenColVar(const Analyzer::ColumnVar*,
217  const bool fetch_column,
218  const bool update_query_plan,
219  const CompilationOptions&);
220 
221  llvm::Value* codegenFixedLengthColVar(const Analyzer::ColumnVar* col_var,
222  llvm::Value* col_byte_stream,
223  llvm::Value* pos_arg);
224 
225  // Generates code for a fixed length column when a window function is active.
226  llvm::Value* codegenFixedLengthColVarInWindow(const Analyzer::ColumnVar* col_var,
227  llvm::Value* col_byte_stream,
228  llvm::Value* pos_arg);
229 
230  // Generate the position for the given window function and the query iteration position.
231  llvm::Value* codegenWindowPosition(WindowFunctionContext* window_func_context,
232  llvm::Value* pos_arg);
233 
234  std::vector<llvm::Value*> codegenVariableLengthStringColVar(
235  llvm::Value* col_byte_stream,
236  llvm::Value* pos_arg);
237 
238  llvm::Value* codegenRowId(const Analyzer::ColumnVar* col_var,
239  const CompilationOptions& co);
240 
241  llvm::Value* codgenAdjustFixedEncNull(llvm::Value*, const SQLTypeInfo&);
242 
243  std::vector<llvm::Value*> codegenOuterJoinNullPlaceholder(
244  const Analyzer::ColumnVar* col_var,
245  const bool fetch_column,
246  const CompilationOptions& co);
247 
248  llvm::Value* codegenIntArith(const Analyzer::BinOper*,
249  llvm::Value*,
250  llvm::Value*,
251  const CompilationOptions&);
252 
253  llvm::Value* codegenFpArith(const Analyzer::BinOper*, llvm::Value*, llvm::Value*);
254 
255  llvm::Value* codegenCastTimestampToDate(llvm::Value* ts_lv,
256  const int dimen,
257  const bool nullable);
258 
259  llvm::Value* codegenCastBetweenTimestamps(llvm::Value* ts_lv,
260  const int operand_dimen,
261  const int target_dimen,
262  const bool nullable);
263 
264  llvm::Value* codegenCastFromString(llvm::Value* operand_lv,
265  const SQLTypeInfo& operand_ti,
266  const SQLTypeInfo& ti,
267  const bool operand_is_const,
268  const CompilationOptions& co);
269 
270  llvm::Value* codegenCastToFp(llvm::Value* operand_lv,
271  const SQLTypeInfo& operand_ti,
272  const SQLTypeInfo& ti);
273 
274  llvm::Value* codegenCastFromFp(llvm::Value* operand_lv,
275  const SQLTypeInfo& operand_ti,
276  const SQLTypeInfo& ti);
277 
278  llvm::Value* codegenAdd(const Analyzer::BinOper*,
279  llvm::Value*,
280  llvm::Value*,
281  const std::string& null_typename,
282  const std::string& null_check_suffix,
283  const SQLTypeInfo&,
284  const CompilationOptions&);
285 
286  llvm::Value* codegenSub(const Analyzer::BinOper*,
287  llvm::Value*,
288  llvm::Value*,
289  const std::string& null_typename,
290  const std::string& null_check_suffix,
291  const SQLTypeInfo&,
292  const CompilationOptions&);
293 
294  void codegenSkipOverflowCheckForNull(llvm::Value* lhs_lv,
295  llvm::Value* rhs_lv,
296  llvm::BasicBlock* no_overflow_bb,
297  const SQLTypeInfo& ti);
298 
299  llvm::Value* codegenMul(const Analyzer::BinOper*,
300  llvm::Value*,
301  llvm::Value*,
302  const std::string& null_typename,
303  const std::string& null_check_suffix,
304  const SQLTypeInfo&,
305  const CompilationOptions&,
306  bool downscale = true);
307 
308  llvm::Value* codegenDiv(llvm::Value*,
309  llvm::Value*,
310  const std::string& null_typename,
311  const std::string& null_check_suffix,
312  const SQLTypeInfo&,
313  bool upscale = true);
314 
315  llvm::Value* codegenDeciDiv(const Analyzer::BinOper*, const CompilationOptions&);
316 
317  llvm::Value* codegenMod(llvm::Value*,
318  llvm::Value*,
319  const std::string& null_typename,
320  const std::string& null_check_suffix,
321  const SQLTypeInfo&);
322 
323  llvm::Value* codegenCase(const Analyzer::CaseExpr*,
324  llvm::Type* case_llvm_type,
325  const bool is_real_str,
326  const CompilationOptions&);
327 
328  llvm::Value* codegenExtractHighPrecisionTimestamps(llvm::Value*,
329  const SQLTypeInfo&,
330  const ExtractField&);
331 
332  llvm::Value* codegenDateTruncHighPrecisionTimestamps(llvm::Value*,
333  const SQLTypeInfo&,
334  const DatetruncField&);
335 
336  llvm::Value* codegenCmpDecimalConst(const SQLOps,
337  const SQLQualifier,
338  const Analyzer::Expr*,
339  const SQLTypeInfo&,
340  const Analyzer::Expr*,
341  const CompilationOptions&);
342 
343  llvm::Value* codegenOverlaps(const SQLOps,
344  const SQLQualifier,
345  const std::shared_ptr<Analyzer::Expr>,
346  const std::shared_ptr<Analyzer::Expr>,
347  const CompilationOptions&);
348 
349  llvm::Value* codegenStrCmp(const SQLOps,
350  const SQLQualifier,
351  const std::shared_ptr<Analyzer::Expr>,
352  const std::shared_ptr<Analyzer::Expr>,
353  const CompilationOptions&);
354 
355  llvm::Value* codegenQualifierCmp(const SQLOps,
356  const SQLQualifier,
357  std::vector<llvm::Value*>,
358  const Analyzer::Expr*,
359  const CompilationOptions&);
360 
361  llvm::Value* codegenLogicalShortCircuit(const Analyzer::BinOper*,
362  const CompilationOptions&);
363 
364  llvm::Value* codegenDictLike(const std::shared_ptr<Analyzer::Expr> arg,
365  const Analyzer::Constant* pattern,
366  const bool ilike,
367  const bool is_simple,
368  const char escape_char,
369  const CompilationOptions&);
370 
371  llvm::Value* codegenDictStrCmp(const std::shared_ptr<Analyzer::Expr>,
372  const std::shared_ptr<Analyzer::Expr>,
373  const SQLOps,
374  const CompilationOptions& co);
375 
376  llvm::Value* codegenDictRegexp(const std::shared_ptr<Analyzer::Expr> arg,
377  const Analyzer::Constant* pattern,
378  const char escape_char,
379  const CompilationOptions&);
380 
381  // Returns the IR value which holds true iff at least one match has been found for outer
382  // join, null if there's no outer join condition on the given nesting level.
383  llvm::Value* foundOuterJoinMatch(const ssize_t nesting_level) const;
384 
386 
387  llvm::Value* colByteStream(const Analyzer::ColumnVar* col_var,
388  const bool fetch_column,
389  const bool hoist_literals);
390 
391  std::shared_ptr<const Analyzer::Expr> hashJoinLhs(const Analyzer::ColumnVar* rhs) const;
392 
393  std::shared_ptr<const Analyzer::ColumnVar> hashJoinLhsTuple(
394  const Analyzer::ColumnVar* rhs,
395  const Analyzer::BinOper* tautological_eq) const;
396 
397  std::unique_ptr<InValuesBitmap> createInValuesBitmap(const Analyzer::InValues*,
398  const CompilationOptions&);
399 
400  bool checkExpressionRanges(const Analyzer::UOper*, int64_t, int64_t);
401 
402  bool checkExpressionRanges(const Analyzer::BinOper*, int64_t, int64_t);
403 
405  llvm::BasicBlock* args_null_bb;
406  llvm::BasicBlock* args_notnull_bb;
407  llvm::BasicBlock* orig_bb;
408  };
409 
411  const std::vector<llvm::Value*>& orig_arg_lvs);
412 
413  llvm::Value* endArgsNullcheck(const ArgNullcheckBBs&,
414  llvm::Value*,
415  const Analyzer::FunctionOper*);
416 
418  const std::vector<llvm::Value*>&);
419 
420  llvm::StructType* createArrayStructType(const std::string& udf_func_name,
421  size_t param_num);
422 
423  void codegenArrayArgs(const std::string& udf_func_name,
424  size_t param_num,
425  llvm::Value* array_buf,
426  llvm::Value* array_size,
427  llvm::Value* array_is_null,
428  std::vector<llvm::Value*>& output_args);
429 
430  llvm::StructType* createPointStructType(const std::string& udf_func_name,
431  size_t param_num);
432 
433  void codegenGeoPointArgs(const std::string& udf_func_name,
434  size_t param_num,
435  llvm::Value* point_buf,
436  llvm::Value* point_size,
437  llvm::Value* compression,
438  llvm::Value* input_srid,
439  llvm::Value* output_srid,
440  std::vector<llvm::Value*>& output_args);
441 
442  llvm::StructType* createLineStringStructType(const std::string& udf_func_name,
443  size_t param_num);
444 
445  void codegenGeoLineStringArgs(const std::string& udf_func_name,
446  size_t param_num,
447  llvm::Value* line_string_buf,
448  llvm::Value* line_string_size,
449  llvm::Value* compression,
450  llvm::Value* input_srid,
451  llvm::Value* output_srid,
452  std::vector<llvm::Value*>& output_args);
453 
454  llvm::StructType* createPolygonStructType(const std::string& udf_func_name,
455  size_t param_num);
456 
457  void codegenGeoPolygonArgs(const std::string& udf_func_name,
458  size_t param_num,
459  llvm::Value* polygon_buf,
460  llvm::Value* polygon_size,
461  llvm::Value* ring_sizes_buf,
462  llvm::Value* num_rings,
463  llvm::Value* compression,
464  llvm::Value* input_srid,
465  llvm::Value* output_srid,
466  std::vector<llvm::Value*>& output_args);
467 
468  std::vector<llvm::Value*> codegenFunctionOperCastArgs(
469  const Analyzer::FunctionOper*,
470  const ExtensionFunction*,
471  const std::vector<llvm::Value*>&,
472  const std::unordered_map<llvm::Value*, llvm::Value*>&,
473  const CompilationOptions&);
474 
475  // Return LLVM intrinsic providing fast arithmetic with overflow check
476  // for the given binary operation.
477  llvm::Function* getArithWithOverflowIntrinsic(const Analyzer::BinOper* bin_oper,
478  llvm::Type* type);
479 
480  // Generate code for the given binary operation with overflow check.
481  // Signed integer add, sub and mul operations are supported. Overflow
482  // check is performed using LLVM arithmetic intrinsics which are not
483  // supported for GPU. Return the IR value which holds operation result.
484  llvm::Value* codegenBinOpWithOverflowForCPU(const Analyzer::BinOper* bin_oper,
485  llvm::Value* lhs_lv,
486  llvm::Value* rhs_lv,
487  const std::string& null_check_suffix,
488  const SQLTypeInfo& ti);
489 
490  Executor* executor_;
491 
492  protected:
493  Executor* executor() const {
494  if (!executor_) {
495  throw ExecutorRequired();
496  }
497  return executor_;
498  }
499 
502 };
503 
504 // Code generator specialized for scalar expressions which doesn't require an executor.
506  public:
507  // Constructor which takes the runtime module.
508  ScalarCodeGenerator(std::unique_ptr<llvm::Module> module)
509  : CodeGenerator(nullptr, nullptr), module_(std::move(module)) {}
510 
511  // Function generated for a given analyzer expression. For GPU, a wrapper which meets
512  // the kernel signature constraints (returns void, takes all arguments as pointers) is
513  // generated. Also returns the list of column expressions for which compatible input
514  // parameters must be passed to the input of the generated function.
516  llvm::Function* func;
517  llvm::Function* wrapper_func;
518  std::vector<std::shared_ptr<Analyzer::ColumnVar>> inputs;
519  };
520 
521  // Compiles the given scalar expression to IR and the list of columns in the expression,
522  // needed to provide inputs to the generated function.
524  const bool fetch_columns,
525  const CompilationOptions& co);
526 
527  // Generates the native function pointers for each device.
528  // NB: this is separated from the compile method to allow building higher level code
529  // generators which can inline the IR for evaluating a single expression (for example
530  // loops).
531  std::vector<void*> generateNativeCode(const CompiledExpression& compiled_expression,
532  const CompilationOptions& co);
533 
535 
536  using ColumnMap =
537  std::unordered_map<InputColDescriptor, std::shared_ptr<Analyzer::ColumnVar>>;
538 
539  private:
540  std::vector<llvm::Value*> codegenColumn(const Analyzer::ColumnVar*,
541  const bool fetch_column,
542  const CompilationOptions&) override;
543 
544  // Collect the columns used by the given analyzer expressions and fills in the column
545  // map to be used during code generation.
547 
548  std::vector<void*> generateNativeGPUCode(llvm::Function* func,
549  llvm::Function* wrapper_func,
550  const CompilationOptions& co);
551 
552  std::unique_ptr<llvm::Module> module_;
554  std::unique_ptr<CgenState> own_cgen_state_;
555  std::unique_ptr<PlanState> own_plan_state_;
556  std::unique_ptr<CudaMgr_Namespace::CudaMgr> cuda_mgr_;
557  std::vector<std::unique_ptr<GpuCompilationContext>> gpu_compilation_contexts_;
558  std::unique_ptr<llvm::TargetMachine> nvptx_target_machine_;
559 };
560 
565 std::unique_ptr<llvm::Module> runtime_module_shallow_copy(CgenState* cgen_state);
566 
570 std::vector<llvm::Value*> generate_column_heads_load(const int num_columns,
571  llvm::Value* byte_stream_arg,
572  llvm::IRBuilder<>& ir_builder,
573  llvm::LLVMContext& ctx);
llvm::StructType * createLineStringStructType(const std::string &udf_func_name, size_t param_num)
llvm::Value * codegenIntArith(const Analyzer::BinOper *, llvm::Value *, llvm::Value *, const CompilationOptions &)
std::vector< std::tuple< void *, GpuCompilationContext * > > cached_functions
Definition: CodeGenerator.h:87
CompiledExpression compile(const Analyzer::Expr *expr, const bool fetch_columns, const CompilationOptions &co)
llvm::Value * codegenCastFromFp(llvm::Value *operand_lv, const SQLTypeInfo &operand_ti, const SQLTypeInfo &ti)
Definition: CastIR.cpp:388
std::vector< std::pair< void *, void * > > native_functions
Definition: CodeGenerator.h:86
std::vector< llvm::Value * > codegenColumn(const Analyzer::ColumnVar *, const bool fetch_column, const CompilationOptions &) override
llvm::Value * codegenStrCmp(const SQLOps, const SQLQualifier, const std::shared_ptr< Analyzer::Expr >, const std::shared_ptr< Analyzer::Expr >, const CompilationOptions &)
Definition: CompareIR.cpp:311
std::unique_ptr< llvm::Module > module(runtime_module_shallow_copy(cgen_state))
std::vector< void * > generateNativeCode(const CompiledExpression &compiled_expression, const CompilationOptions &co)
std::unique_ptr< llvm::Module > runtime_module_shallow_copy(CgenState *cgen_state)
llvm::BasicBlock * args_notnull_bb
std::unique_ptr< PlanState > own_plan_state_
EncodingType
Definition: encodetypes.h:22
static std::string generatePTX(const std::string &cuda_llir, llvm::TargetMachine *nvptx_target_machine, CgenState *cgen_state)
llvm::Value * codegenArith(const Analyzer::BinOper *, const CompilationOptions &)
CgenState * cgen_state_
ExecutionEngineWrapper execution_engine_
void codegenGeoPolygonArgs(const std::string &udf_func_name, size_t param_num, llvm::Value *polygon_buf, llvm::Value *polygon_size, llvm::Value *ring_sizes_buf, llvm::Value *num_rings, llvm::Value *compression, llvm::Value *input_srid, llvm::Value *output_srid, std::vector< llvm::Value * > &output_args)
std::vector< llvm::Value * > codegenFunctionOperCastArgs(const Analyzer::FunctionOper *, const ExtensionFunction *, const std::vector< llvm::Value * > &, const std::unordered_map< llvm::Value *, llvm::Value * > &, const CompilationOptions &)
SQLQualifier
Definition: sqldefs.h:69
llvm::Value * codegenRowId(const Analyzer::ColumnVar *col_var, const CompilationOptions &co)
Definition: ColumnIR.cpp:312
llvm::StructType * createArrayStructType(const std::string &udf_func_name, size_t param_num)
SQLOps
Definition: sqldefs.h:29
llvm::Value * codegenMod(llvm::Value *, llvm::Value *, const std::string &null_typename, const std::string &null_check_suffix, const SQLTypeInfo &)
llvm::Value * codegenFunctionOperNullArg(const Analyzer::FunctionOper *, const std::vector< llvm::Value * > &)
std::vector< llvm::Value * > codegenOuterJoinNullPlaceholder(const Analyzer::ColumnVar *col_var, const bool fetch_column, const CompilationOptions &co)
Definition: ColumnIR.cpp:412
std::unique_ptr< llvm::TargetMachine > nvptx_target_machine_
llvm::Value * posArg(const Analyzer::Expr *) const
Definition: ColumnIR.cpp:503
llvm::Value * castArrayPointer(llvm::Value *ptr, const SQLTypeInfo &elem_ti)
static GPUCode generateNativeGPUCode(llvm::Function *func, llvm::Function *wrapper_func, const std::unordered_set< llvm::Function * > &live_funcs, const CompilationOptions &co, const GPUTarget &gpu_target)
llvm::Value * codegenCastToFp(llvm::Value *operand_lv, const SQLTypeInfo &operand_ti, const SQLTypeInfo &ti)
Definition: CastIR.cpp:357
llvm::Value * codgenAdjustFixedEncNull(llvm::Value *, const SQLTypeInfo &)
Definition: ColumnIR.cpp:365
std::vector< std::unique_ptr< GpuCompilationContext > > gpu_compilation_contexts_
llvm::Value * codegenExtractHighPrecisionTimestamps(llvm::Value *, const SQLTypeInfo &, const ExtractField &)
Definition: DateTimeIR.cpp:155
llvm::StructType * createPointStructType(const std::string &udf_func_name, size_t param_num)
virtual std::vector< llvm::Value * > codegenColumn(const Analyzer::ColumnVar *, const bool fetch_column, const CompilationOptions &)
Definition: ColumnIR.cpp:92
llvm::Value * codegenDeciDiv(const Analyzer::BinOper *, const CompilationOptions &)
static ExecutionEngineWrapper generateNativeCPUCode(llvm::Function *func, const std::unordered_set< llvm::Function * > &live_funcs, const CompilationOptions &co)
llvm::Value * codegenArrayAt(const Analyzer::BinOper *, const CompilationOptions &)
Definition: ArrayIR.cpp:25
ArgNullcheckBBs beginArgsNullcheck(const Analyzer::FunctionOper *function_oper, const std::vector< llvm::Value * > &orig_arg_lvs)
std::unordered_map< InputColDescriptor, std::shared_ptr< Analyzer::ColumnVar >> ColumnMap
static bool prioritizeQuals(const RelAlgExecutionUnit &ra_exe_unit, std::vector< Analyzer::Expr * > &primary_quals, std::vector< Analyzer::Expr * > &deferred_quals)
Definition: LogicalIR.cpp:157
const CudaMgr_Namespace::CudaMgr * cuda_mgr
Definition: CodeGenerator.h:92
std::unique_ptr< CudaMgr_Namespace::CudaMgr > cuda_mgr_
llvm::Value * codegenFpArith(const Analyzer::BinOper *, llvm::Value *, llvm::Value *)
llvm::Value * codegenIsNull(const Analyzer::UOper *, const CompilationOptions &)
Definition: LogicalIR.cpp:368
llvm::TargetMachine * nvptx_target_machine
Definition: CodeGenerator.h:91
false auto cgen_state
void codegenArrayArgs(const std::string &udf_func_name, size_t param_num, llvm::Value *array_buf, llvm::Value *array_size, llvm::Value *array_is_null, std::vector< llvm::Value * > &output_args)
std::shared_ptr< const Analyzer::Expr > hashJoinLhs(const Analyzer::ColumnVar *rhs) const
Definition: ColumnIR.cpp:539
CudaMgr_Namespace::CudaMgr * getCudaMgr() const
std::vector< llvm::Value * > codegenGeoExpr(const Analyzer::GeoExpr *, const CompilationOptions &)
Definition: GeoIR.cpp:20
llvm::Value * codegenDiv(llvm::Value *, llvm::Value *, const std::string &null_typename, const std::string &null_check_suffix, const SQLTypeInfo &, bool upscale=true)
llvm::Value * codegenCmpDecimalConst(const SQLOps, const SQLQualifier, const Analyzer::Expr *, const SQLTypeInfo &, const Analyzer::Expr *, const CompilationOptions &)
Definition: CompareIR.cpp:341
std::vector< llvm::Value * > codegenHoistedConstants(const std::vector< const Analyzer::Constant * > &constants, const EncodingType enc_type, const int dict_id)
Definition: ConstantIR.cpp:287
static std::unordered_set< llvm::Function * > markDeadRuntimeFuncs(llvm::Module &module, const std::vector< llvm::Function * > &roots, const std::vector< llvm::Function * > &leaves)
ScalarCodeGenerator(std::unique_ptr< llvm::Module > module)
DatetruncField
Definition: DateTruncate.h:42
std::vector< llvm::Value * > codegenHoistedConstantsLoads(const SQLTypeInfo &type_info, const EncodingType enc_type, const int dict_id, const int16_t lit_off)
Definition: ConstantIR.cpp:115
void codegenSkipOverflowCheckForNull(llvm::Value *lhs_lv, llvm::Value *rhs_lv, llvm::BasicBlock *no_overflow_bb, const SQLTypeInfo &ti)
std::vector< llvm::Value * > codegenHoistedConstantsPlaceholders(const SQLTypeInfo &type_info, const EncodingType enc_type, const int16_t lit_off, const std::vector< llvm::Value * > &literal_loads)
Definition: ConstantIR.cpp:213
CodeGenerator(Executor *executor)
Definition: CodeGenerator.h:27
llvm::Value * codegenBinOpWithOverflowForCPU(const Analyzer::BinOper *bin_oper, llvm::Value *lhs_lv, llvm::Value *rhs_lv, const std::string &null_check_suffix, const SQLTypeInfo &ti)
llvm::Value * codegenFunctionOper(const Analyzer::FunctionOper *, const CompilationOptions &)
llvm::Value * codegenCastBetweenIntTypes(llvm::Value *operand_lv, const SQLTypeInfo &operand_ti, const SQLTypeInfo &ti, bool upscale=true)
Definition: CastIR.cpp:228
Executor * executor_
const int32_t groups_buffer_size return nullptr
llvm::Value * codegenOverlaps(const SQLOps, const SQLQualifier, const std::shared_ptr< Analyzer::Expr >, const std::shared_ptr< Analyzer::Expr >, const CompilationOptions &)
Definition: CompareIR.cpp:238
llvm::Value * codegenDictStrCmp(const std::shared_ptr< Analyzer::Expr >, const std::shared_ptr< Analyzer::Expr >, const SQLOps, const CompilationOptions &co)
llvm::Value * codegenCastTimestampToDate(llvm::Value *ts_lv, const int dimen, const bool nullable)
Definition: CastIR.cpp:107
static void link_udf_module(const std::unique_ptr< llvm::Module > &udf_module, llvm::Module &module, CgenState *cgen_state, llvm::Linker::Flags flags=llvm::Linker::Flags::None)
std::vector< llvm::Value * > codegenArrayExpr(const Analyzer::ArrayExpr *, const CompilationOptions &)
Definition: ArrayIR.cpp:88
llvm::Value * codegenDictRegexp(const std::shared_ptr< Analyzer::Expr > arg, const Analyzer::Constant *pattern, const char escape_char, const CompilationOptions &)
llvm::BasicBlock * args_null_bb
llvm::Function * getArithWithOverflowIntrinsic(const Analyzer::BinOper *bin_oper, llvm::Type *type)
std::vector< llvm::Value * > codegenColVar(const Analyzer::ColumnVar *, const bool fetch_column, const bool update_query_plan, const CompilationOptions &)
Definition: ColumnIR.cpp:103
llvm::Value * codegenUMinus(const Analyzer::UOper *, const CompilationOptions &)
void codegenGeoPointArgs(const std::string &udf_func_name, size_t param_num, llvm::Value *point_buf, llvm::Value *point_size, llvm::Value *compression, llvm::Value *input_srid, llvm::Value *output_srid, std::vector< llvm::Value * > &output_args)
PlanState * plan_state_
std::vector< llvm::Value * > codegen(const Analyzer::Expr *, const bool fetch_columns, const CompilationOptions &)
Definition: IRCodegen.cpp:25
llvm::StructType * createPolygonStructType(const std::string &udf_func_name, size_t param_num)
llvm::Value * codegenQualifierCmp(const SQLOps, const SQLQualifier, std::vector< llvm::Value * >, const Analyzer::Expr *, const CompilationOptions &)
Definition: CompareIR.cpp:471
llvm::Value * endArgsNullcheck(const ArgNullcheckBBs &, llvm::Value *, const Analyzer::FunctionOper *)
llvm::Value * codegenSub(const Analyzer::BinOper *, llvm::Value *, llvm::Value *, const std::string &null_typename, const std::string &null_check_suffix, const SQLTypeInfo &, const CompilationOptions &)
void codegenCastBetweenIntTypesOverflowChecks(llvm::Value *operand_lv, const SQLTypeInfo &operand_ti, const SQLTypeInfo &ti, const int64_t scale)
Definition: CastIR.cpp:300
static bool alwaysCloneRuntimeFunction(const llvm::Function *func)
ColumnMap prepare(const Analyzer::Expr *)
std::unique_ptr< CgenState > own_cgen_state_
llvm::Value * codegenCase(const Analyzer::CaseExpr *, llvm::Type *case_llvm_type, const bool is_real_str, const CompilationOptions &)
Definition: CaseIR.cpp:54
std::vector< llvm::Value * > generate_column_heads_load(const int num_columns, llvm::Value *byte_stream_arg, llvm::IRBuilder<> &ir_builder, llvm::LLVMContext &ctx)
Expression class for the LOWER (lowercase) string function. The &quot;arg&quot; constructor parameter must be a...
Definition: Analyzer.h:740
std::vector< void * > generateNativeGPUCode(llvm::Function *func, llvm::Function *wrapper_func, const CompilationOptions &co)
ExtractField
llvm::Value * toBool(llvm::Value *)
Definition: LogicalIR.cpp:333
llvm::Value * codegenFixedLengthColVarInWindow(const Analyzer::ColumnVar *col_var, llvm::Value *col_byte_stream, llvm::Value *pos_arg)
Definition: ColumnIR.cpp:270
llvm::Value * codegenFunctionOperWithCustomTypeHandling(const Analyzer::FunctionOperWithCustomTypeHandling *, const CompilationOptions &)
llvm::Value * codegenCmp(const Analyzer::BinOper *, const CompilationOptions &)
Definition: CompareIR.cpp:184
llvm::ConstantInt * codegenIntConst(const Analyzer::Constant *constant)
Definition: ConstantIR.cpp:88
static std::unique_ptr< llvm::TargetMachine > initializeNVPTXBackend()
llvm::Value * codegenUnnest(const Analyzer::UOper *, const CompilationOptions &)
Definition: ArrayIR.cpp:20
llvm::Value * colByteStream(const Analyzer::ColumnVar *col_var, const bool fetch_column, const bool hoist_literals)
Definition: ColumnIR.cpp:487
llvm::Value * codegenIsNullNumber(llvm::Value *, const SQLTypeInfo &)
Definition: LogicalIR.cpp:397
llvm::Value * codegenLogical(const Analyzer::BinOper *, const CompilationOptions &)
Definition: LogicalIR.cpp:289
llvm::Value * codegenWindowPosition(WindowFunctionContext *window_func_context, llvm::Value *pos_arg)
Definition: ColumnIR.cpp:221
std::unique_ptr< llvm::Module > module_
std::vector< std::shared_ptr< Analyzer::ColumnVar > > inputs
llvm::Value * codegenCastFromString(llvm::Value *operand_lv, const SQLTypeInfo &operand_ti, const SQLTypeInfo &ti, const bool operand_is_const, const CompilationOptions &co)
Definition: CastIR.cpp:164
CodeGenerator(CgenState *cgen_state, PlanState *plan_state)
Definition: CodeGenerator.h:34
llvm::Value * codegenCast(const Analyzer::UOper *, const CompilationOptions &)
Definition: CastIR.cpp:20
llvm::Value * codegenDateTruncHighPrecisionTimestamps(llvm::Value *, const SQLTypeInfo &, const DatetruncField &)
Definition: DateTimeIR.cpp:198
std::unique_ptr< InValuesBitmap > createInValuesBitmap(const Analyzer::InValues *, const CompilationOptions &)
Definition: InValuesIR.cpp:108
llvm::Value * codegenMul(const Analyzer::BinOper *, llvm::Value *, llvm::Value *, const std::string &null_typename, const std::string &null_check_suffix, const SQLTypeInfo &, const CompilationOptions &, bool downscale=true)
std::shared_ptr< const Analyzer::ColumnVar > hashJoinLhsTuple(const Analyzer::ColumnVar *rhs, const Analyzer::BinOper *tautological_eq) const
Definition: ColumnIR.cpp:586
std::vector< llvm::Value * > codegenVariableLengthStringColVar(llvm::Value *col_byte_stream, llvm::Value *pos_arg)
Definition: ColumnIR.cpp:298
void codegenGeoLineStringArgs(const std::string &udf_func_name, size_t param_num, llvm::Value *line_string_buf, llvm::Value *line_string_size, llvm::Value *compression, llvm::Value *input_srid, llvm::Value *output_srid, std::vector< llvm::Value * > &output_args)
llvm::Value * codegenAdd(const Analyzer::BinOper *, llvm::Value *, llvm::Value *, const std::string &null_typename, const std::string &null_check_suffix, const SQLTypeInfo &, const CompilationOptions &)
bool checkExpressionRanges(const Analyzer::UOper *, int64_t, int64_t)
llvm::Value * codegenFixedLengthColVar(const Analyzer::ColumnVar *col_var, llvm::Value *col_byte_stream, llvm::Value *pos_arg)
Definition: ColumnIR.cpp:234
llvm::Value * codegenLogicalShortCircuit(const Analyzer::BinOper *, const CompilationOptions &)
Definition: LogicalIR.cpp:188
llvm::Value * foundOuterJoinMatch(const ssize_t nesting_level) const
Definition: ColumnIR.cpp:405
llvm::Value * codegenCastBetweenTimestamps(llvm::Value *ts_lv, const int operand_dimen, const int target_dimen, const bool nullable)
Definition: CastIR.cpp:136
llvm::Value * resolveGroupedColumnReference(const Analyzer::ColumnVar *)
Definition: ColumnIR.cpp:468
llvm::Value * codegenDictLike(const std::shared_ptr< Analyzer::Expr > arg, const Analyzer::Constant *pattern, const bool ilike, const bool is_simple, const char escape_char, const CompilationOptions &)
Executor * executor() const