OmniSciDB  a5dc49c757
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CodeGenerator.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 
17 #pragma once
18 
19 #include <llvm/IR/Value.h>
20 
21 #include "../Analyzer/Analyzer.h"
22 #include "Execute.h"
23 #include "Shared/DbObjectKeys.h"
24 
25 class AbstractMLModel;
26 class AbstractTreeModel;
27 
28 // Code generation utility to be used for queries and scalar expressions.
30  public:
32  : executor_(executor)
33  , cgen_state_(executor->cgen_state_.get())
34  , plan_state_(executor->plan_state_.get()) {}
35 
36  // Overload which can be used without an executor, for SQL scalar expression code
37  // generation.
38  CodeGenerator(CgenState* cgen_state, PlanState* plan_state)
39  : executor_(nullptr), cgen_state_(cgen_state), plan_state_(plan_state) {}
40 
41  // Generates IR value(s) for the given analyzer expression.
42  std::vector<llvm::Value*> codegen(const Analyzer::Expr*,
43  const bool fetch_columns,
44  const CompilationOptions&);
45 
46  llvm::Value* codegenPerRowStringOper(const Analyzer::StringOper* string_oper,
47  const CompilationOptions& co);
48 
49  llvm::Value* codegenPseudoStringOper(
50  const Analyzer::ColumnVar*,
51  const std::vector<StringOps_Namespace::StringOpInfo>& string_op_infos,
52  const CompilationOptions&);
53 
54  // Generates constant values in the literal buffer of a query.
55  std::vector<llvm::Value*> codegenHoistedConstants(
56  const std::vector<const Analyzer::Constant*>& constants,
57  const EncodingType enc_type,
58  const shared::StringDictKey& dict_id);
59 
60  static llvm::ConstantInt* codegenIntConst(const Analyzer::Constant* constant,
61  CgenState* cgen_state);
62 
63  llvm::Value* codegenCastBetweenIntTypes(llvm::Value* operand_lv,
64  const SQLTypeInfo& operand_ti,
65  const SQLTypeInfo& ti,
66  bool upscale = true);
67 
68  void codegenCastBetweenIntTypesOverflowChecks(llvm::Value* operand_lv,
69  const SQLTypeInfo& operand_ti,
70  const SQLTypeInfo& ti,
71  const int64_t scale);
72 
73  // Generates the index of the current row in the context of query execution.
74  llvm::Value* posArg(const Analyzer::Expr*) const;
75 
76  llvm::Value* toBool(llvm::Value*);
77 
78  llvm::Value* castArrayPointer(llvm::Value* ptr, const SQLTypeInfo& elem_ti);
79 
80  static std::unordered_set<llvm::Function*> markDeadRuntimeFuncs(
81  llvm::Module& module,
82  const std::vector<llvm::Function*>& roots,
83  const std::vector<llvm::Function*>& leaves);
84 
86  llvm::Function* func,
87  const std::unordered_set<llvm::Function*>& live_funcs,
88  const CompilationOptions& co);
89 
90  static std::string generatePTX(const std::string& cuda_llir,
91  llvm::TargetMachine* nvptx_target_machine,
92  llvm::LLVMContext& context);
93 
94  static std::unique_ptr<llvm::TargetMachine> initializeNVPTXBackend(
96 
97  static bool alwaysCloneRuntimeFunction(const llvm::Function* func);
98 
99  struct GPUTarget {
100  llvm::TargetMachine* nvptx_target_machine;
104  };
105 
106  static void linkModuleWithLibdevice(Executor* executor,
107  llvm::Module& module,
108  llvm::PassManagerBuilder& pass_manager_builder,
109  const GPUTarget& gpu_target);
110 
111  static std::shared_ptr<GpuCompilationContext> generateNativeGPUCode(
112  Executor* executor,
113  llvm::Function* func,
114  llvm::Function* wrapper_func,
115  const std::unordered_set<llvm::Function*>& live_funcs,
116  const bool is_gpu_smem_used,
117  const CompilationOptions& co,
118  const GPUTarget& gpu_target);
119 
120  static void link_udf_module(const std::unique_ptr<llvm::Module>& udf_module,
121  llvm::Module& module,
122  CgenState* cgen_state,
123  llvm::Linker::Flags flags = llvm::Linker::Flags::None);
124 
125  static bool prioritizeQuals(const RelAlgExecutionUnit& ra_exe_unit,
126  std::vector<Analyzer::Expr*>& primary_quals,
127  std::vector<Analyzer::Expr*>& deferred_quals,
128  const PlanState::HoistedFiltersSet& hoisted_quals);
129 
130  struct ExecutorRequired : public std::runtime_error {
132  : std::runtime_error("Executor required to generate this expression") {}
133  };
134 
137  Executor* executor,
138  llvm::Value* nullable_lv,
139  const SQLTypeInfo& nullable_ti,
140  const std::string& name = "");
141 
142  llvm::Value* finalize(llvm::Value* null_lv, llvm::Value* notnull_lv);
143 
144  CgenState* cgen_state{nullptr};
145  std::string name;
146  llvm::BasicBlock* nullcheck_bb{nullptr};
147  llvm::PHINode* nullcheck_value{nullptr};
148  std::unique_ptr<DiamondCodegen> null_check;
149  };
150 
151  static ArrayLoadCodegen codegenGeoArrayLoadAndNullcheck(llvm::Value* byte_stream,
152  llvm::Value* pos,
153  const SQLTypeInfo& ti,
154  CgenState* cgen_state);
155 
156  llvm::Value* codegenCastBetweenTimestamps(llvm::Value* ts_lv,
157  const SQLTypeInfo& operand_dimen,
158  const SQLTypeInfo& target_dimen,
159  const bool nullable);
160 
161  // Generate the position for the given window function and the query iteration position.
162  llvm::Value* codegenWindowPosition(const WindowFunctionContext* window_func_context,
163  llvm::Value* pos_arg);
164 
165  private:
166  std::vector<llvm::Value*> codegen(const Analyzer::Constant*,
167  const EncodingType enc_type,
168  const shared::StringDictKey& dict_id,
169  const CompilationOptions&);
170 
171  virtual std::vector<llvm::Value*> codegenColumn(const Analyzer::ColumnVar*,
172  const bool fetch_column,
173  const CompilationOptions&);
174 
175  llvm::Value* codegenArith(const Analyzer::BinOper*, const CompilationOptions&);
176 
177  llvm::Value* codegenUMinus(const Analyzer::UOper*, const CompilationOptions&);
178 
179  llvm::Value* codegenCmp(const Analyzer::BinOper*, const CompilationOptions&);
180 
181  llvm::Value* codegenCmp(const SQLOps,
182  const SQLQualifier,
183  std::vector<llvm::Value*>,
184  const SQLTypeInfo&,
185  const Analyzer::Expr*,
186  const CompilationOptions&);
187 
188  llvm::Value* codegenIsNull(const Analyzer::UOper*, const CompilationOptions&);
189 
190  llvm::Value* codegenIsNullNumber(llvm::Value*, const SQLTypeInfo&);
191 
192  llvm::Value* codegenLogical(const Analyzer::BinOper*, const CompilationOptions&);
193 
194  llvm::Value* codegenLogical(const Analyzer::UOper*, const CompilationOptions&);
195 
196  llvm::Value* codegenCast(const Analyzer::UOper*, const CompilationOptions&);
197 
198  llvm::Value* codegenCast(llvm::Value* operand_lv,
199  const SQLTypeInfo& operand_ti,
200  const SQLTypeInfo& ti,
201  const bool operand_is_const,
202  const CompilationOptions& co);
203 
204  llvm::Value* codegen(const Analyzer::InValues*, const CompilationOptions&);
205 
206  llvm::Value* codegen(const Analyzer::InIntegerSet* expr, const CompilationOptions& co);
207 
208  std::vector<llvm::Value*> codegen(const Analyzer::CaseExpr*, const CompilationOptions&);
209 
210  llvm::Value* codegen(const Analyzer::ExtractExpr*, const CompilationOptions&);
211 
212  llvm::Value* codegen(const Analyzer::DateaddExpr*, const CompilationOptions&);
213 
214  llvm::Value* codegen(const Analyzer::DatediffExpr*, const CompilationOptions&);
215 
216  llvm::Value* codegen(const Analyzer::DatetruncExpr*, const CompilationOptions&);
217 
218  llvm::Value* codegen(const Analyzer::CharLengthExpr*, const CompilationOptions&);
219 
220  llvm::Value* codegen(const Analyzer::KeyForStringExpr*, const CompilationOptions&);
221 
222  llvm::Value* codegen(const Analyzer::SampleRatioExpr*, const CompilationOptions&);
223 
224  llvm::Value* codegen(const Analyzer::WidthBucketExpr*, const CompilationOptions&);
225 
227  const CompilationOptions&);
228 
230  const CompilationOptions&);
231 
232  llvm::Value* codegen(const Analyzer::MLPredictExpr*, const CompilationOptions&);
233 
234  llvm::Value* codegen(const Analyzer::PCAProjectExpr*, const CompilationOptions&);
235 
236  llvm::Value* codegenLinRegPredict(const Analyzer::MLPredictExpr*,
237  const std::shared_ptr<AbstractMLModel>& model,
238  const CompilationOptions&);
239 
241  const std::shared_ptr<AbstractTreeModel>& tree_model,
242  const CompilationOptions&);
243 
244  llvm::Value* codegen(const Analyzer::StringOper*, const CompilationOptions&);
245 
246  llvm::Value* codegen(const Analyzer::LikeExpr*, const CompilationOptions&);
247 
248  llvm::Value* codegen(const Analyzer::RegexpExpr*, const CompilationOptions&);
249 
250  llvm::Value* codegenUnnest(const Analyzer::UOper*, const CompilationOptions&);
251 
252  llvm::Value* codegenArrayAt(const Analyzer::BinOper*, const CompilationOptions&);
253 
254  llvm::Value* codegen(const Analyzer::CardinalityExpr*, const CompilationOptions&);
255 
256  std::vector<llvm::Value*> codegenArrayExpr(const Analyzer::ArrayExpr*,
257  const CompilationOptions&);
258 
259  std::vector<llvm::Value*> codegenGeoColumnVar(const Analyzer::GeoColumnVar*,
260  const bool fetch_columns,
261  const CompilationOptions& co);
262 
263  std::vector<llvm::Value*> codegenGeoExpr(const Analyzer::GeoExpr*,
264  const CompilationOptions&);
265 
266  std::vector<llvm::Value*> codegenGeoConstant(const Analyzer::GeoConstant*,
267  const CompilationOptions&);
268 
269  std::vector<llvm::Value*> codegenGeoOperator(const Analyzer::GeoOperator*,
270  const CompilationOptions&);
271 
272  std::vector<llvm::Value*> codegenGeoUOper(const Analyzer::GeoUOper*,
273  const CompilationOptions&);
274 
275  std::vector<llvm::Value*> codegenGeoBinOper(const Analyzer::GeoBinOper*,
276  const CompilationOptions&);
277 
278  std::vector<llvm::Value*> codegenGeosPredicateCall(const std::string&,
279  std::vector<llvm::Value*>,
280  const CompilationOptions&);
281 
282  std::vector<llvm::Value*> codegenGeosConstructorCall(const std::string&,
283  std::vector<llvm::Value*>,
284  llvm::Value*,
285  const CompilationOptions&);
286 
287  std::vector<llvm::Value*> codegenGeoArgs(
288  const std::vector<std::shared_ptr<Analyzer::Expr>>&,
289  const CompilationOptions&);
290 
291  llvm::Value* codegenFunctionOper(const Analyzer::FunctionOper*,
292  const CompilationOptions&);
293 
296  const CompilationOptions&);
297 
298  llvm::Value* codegen(const Analyzer::BinOper*, const CompilationOptions&);
299 
300  llvm::Value* codegen(const Analyzer::UOper*, const CompilationOptions&);
301 
302  std::vector<llvm::Value*> codegenHoistedConstantsLoads(
303  const SQLTypeInfo& type_info,
304  const EncodingType enc_type,
305  const shared::StringDictKey& dict_id,
306  const int16_t lit_off,
307  const size_t lit_bytes);
308 
309  std::vector<llvm::Value*> codegenHoistedConstantsPlaceholders(
310  const SQLTypeInfo& type_info,
311  const EncodingType enc_type,
312  const int16_t lit_off,
313  const std::vector<llvm::Value*>& literal_loads);
314 
315  std::vector<llvm::Value*> codegenColVar(const Analyzer::ColumnVar*,
316  const bool fetch_column,
317  const bool update_query_plan,
318  const CompilationOptions&);
319 
320  llvm::Value* codegenFixedLengthColVar(
321  const Analyzer::ColumnVar* col_var,
322  llvm::Value* col_byte_stream,
323  llvm::Value* pos_arg,
324  const WindowFunctionContext* window_function_context = nullptr);
325 
326  // Generates code for a fixed length column when a window function is active.
328  const Analyzer::ColumnVar* col_var,
329  llvm::Value* col_byte_stream,
330  llvm::Value* pos_arg,
331  const CompilationOptions& co,
332  const WindowFunctionContext* window_function_context = nullptr);
333 
334  std::vector<llvm::Value*> codegenVariableLengthStringColVar(
335  llvm::Value* col_byte_stream,
336  llvm::Value* pos_arg);
337 
338  llvm::Value* codegenRowId(const Analyzer::ColumnVar* col_var,
339  const CompilationOptions& co);
340 
341  llvm::Value* codgenAdjustFixedEncNull(llvm::Value*, const SQLTypeInfo&);
342 
343  std::vector<llvm::Value*> codegenOuterJoinNullPlaceholder(
344  const Analyzer::ColumnVar* col_var,
345  const bool fetch_column,
346  const CompilationOptions& co);
347 
348  llvm::Value* codegenIntArith(const Analyzer::BinOper*,
349  llvm::Value*,
350  llvm::Value*,
351  const CompilationOptions&);
352 
353  llvm::Value* codegenFpArith(const Analyzer::BinOper*, llvm::Value*, llvm::Value*);
354 
355  llvm::Value* codegenCastTimestampToTime(llvm::Value* ts_lv,
356  const int dimen,
357  const bool nullable);
358 
359  llvm::Value* codegenCastTimestampToDate(llvm::Value* ts_lv,
360  const int dimen,
361  const bool nullable);
362 
363  llvm::Value* codegenCastFromString(llvm::Value* operand_lv,
364  const SQLTypeInfo& operand_ti,
365  const SQLTypeInfo& ti,
366  const bool operand_is_const,
367  const CompilationOptions& co);
368 
369  llvm::Value* codegenCastNonStringToString(llvm::Value* operand_lv,
370  const SQLTypeInfo& operand_ti,
371  const SQLTypeInfo& ti,
372  const bool operand_is_const,
373  const CompilationOptions& co);
374 
375  llvm::Value* codegenCastToFp(llvm::Value* operand_lv,
376  const SQLTypeInfo& operand_ti,
377  const SQLTypeInfo& ti);
378 
379  llvm::Value* codegenCastFromFp(llvm::Value* operand_lv,
380  const SQLTypeInfo& operand_ti,
381  const SQLTypeInfo& ti);
382 
383  llvm::Value* codegenAdd(const Analyzer::BinOper*,
384  llvm::Value*,
385  llvm::Value*,
386  const std::string& null_typename,
387  const std::string& null_check_suffix,
388  const SQLTypeInfo&,
389  const CompilationOptions&);
390 
391  llvm::Value* codegenSub(const Analyzer::BinOper*,
392  llvm::Value*,
393  llvm::Value*,
394  const std::string& null_typename,
395  const std::string& null_check_suffix,
396  const SQLTypeInfo&,
397  const CompilationOptions&);
398 
399  void codegenSkipOverflowCheckForNull(llvm::Value* lhs_lv,
400  llvm::Value* rhs_lv,
401  llvm::BasicBlock* no_overflow_bb,
402  const SQLTypeInfo& ti);
403 
404  llvm::Value* codegenMul(const Analyzer::BinOper*,
405  llvm::Value*,
406  llvm::Value*,
407  const std::string& null_typename,
408  const std::string& null_check_suffix,
409  const SQLTypeInfo&,
410  const CompilationOptions&,
411  bool downscale = true);
412 
413  llvm::Value* codegenDiv(llvm::Value*,
414  llvm::Value*,
415  const std::string& null_typename,
416  const std::string& null_check_suffix,
417  const SQLTypeInfo&,
418  bool upscale = true);
419 
420  llvm::Value* codegenDeciDiv(const Analyzer::BinOper*, const CompilationOptions&);
421 
422  llvm::Value* codegenMod(llvm::Value*,
423  llvm::Value*,
424  const std::string& null_typename,
425  const std::string& null_check_suffix,
426  const SQLTypeInfo&);
427 
428  llvm::Value* codegenCase(const Analyzer::CaseExpr*,
429  llvm::Type* case_llvm_type,
430  const bool is_real_str,
431  const CompilationOptions&);
432 
433  llvm::Value* codegenExtractHighPrecisionTimestamps(llvm::Value*,
434  const SQLTypeInfo&,
435  const ExtractField&);
436 
437  llvm::Value* codegenDateTruncHighPrecisionTimestamps(llvm::Value*,
438  const SQLTypeInfo&,
439  const DatetruncField&);
440 
441  llvm::Value* codegenCmpDecimalConst(const SQLOps,
442  const SQLQualifier,
443  const Analyzer::Expr*,
444  const SQLTypeInfo&,
445  const Analyzer::Expr*,
446  const CompilationOptions&);
447 
448  llvm::Value* codegenBoundingBoxIntersect(const SQLOps,
449  const SQLQualifier,
450  const std::shared_ptr<Analyzer::Expr>,
451  const std::shared_ptr<Analyzer::Expr>,
452  const CompilationOptions&);
453 
454  llvm::Value* codegenStrCmp(const SQLOps,
455  const SQLQualifier,
456  const std::shared_ptr<Analyzer::Expr>,
457  const std::shared_ptr<Analyzer::Expr>,
458  const CompilationOptions&);
459 
460  llvm::Value* codegenQualifierCmp(const SQLOps,
461  const SQLQualifier,
462  std::vector<llvm::Value*>,
463  const Analyzer::Expr*,
464  const CompilationOptions&);
465 
466  llvm::Value* codegenLogicalShortCircuit(const Analyzer::BinOper*,
467  const CompilationOptions&);
468 
469  llvm::Value* codegenDictLike(const std::shared_ptr<Analyzer::Expr> arg,
470  const Analyzer::Constant* pattern,
471  const bool ilike,
472  const bool is_simple,
473  const char escape_char,
474  const CompilationOptions&);
475 
476  llvm::Value* codegenDictStrCmp(const std::shared_ptr<Analyzer::Expr>,
477  const std::shared_ptr<Analyzer::Expr>,
478  const SQLOps,
479  const CompilationOptions& co);
480 
481  llvm::Value* codegenDictRegexp(const std::shared_ptr<Analyzer::Expr> arg,
482  const Analyzer::Constant* pattern,
483  const char escape_char,
484  const CompilationOptions&);
485 
486  // Returns the IR value which holds true iff at least one match has been found for outer
487  // join, null if there's no outer join condition on the given nesting level.
488  llvm::Value* foundOuterJoinMatch(const size_t nesting_level) const;
489 
491 
492  llvm::Value* colByteStream(const Analyzer::ColumnVar* col_var,
493  const bool fetch_column,
494  const bool hoist_literals);
495 
496  std::shared_ptr<const Analyzer::Expr> hashJoinLhs(const Analyzer::ColumnVar* rhs) const;
497 
498  std::shared_ptr<const Analyzer::ColumnVar> hashJoinLhsTuple(
499  const Analyzer::ColumnVar* rhs,
500  const Analyzer::BinOper* tautological_eq) const;
501 
502  bool needCastForHashJoinLhs(const Analyzer::ColumnVar* rhs) const;
503 
504  std::unique_ptr<InValuesBitmap> createInValuesBitmap(const Analyzer::InValues*,
505  const CompilationOptions&);
506 
507  bool checkExpressionRanges(const Analyzer::UOper*, int64_t, int64_t);
508 
509  bool checkExpressionRanges(const Analyzer::BinOper*, int64_t, int64_t);
510 
512  llvm::BasicBlock* args_null_bb;
513  llvm::BasicBlock* args_notnull_bb;
514  llvm::BasicBlock* orig_bb;
515  };
516 
517  std::tuple<ArgNullcheckBBs, llvm::Value*> beginArgsNullcheck(
518  const Analyzer::FunctionOper* function_oper,
519  const std::vector<llvm::Value*>& orig_arg_lvs);
520 
521  llvm::Value* endArgsNullcheck(const ArgNullcheckBBs&,
522  llvm::Value*,
523  llvm::Value*,
524  const Analyzer::FunctionOper*);
525 
527  const std::vector<llvm::Value*>&);
528 
529  llvm::Value* codegenCompression(const SQLTypeInfo& type_info);
530 
531  std::pair<llvm::Value*, llvm::Value*> codegenArrayBuff(llvm::Value* chunk,
532  llvm::Value* row_pos,
533  SQLTypes array_type,
534  bool cast_and_extend);
535 
536  void codegenBufferArgs(const std::string& udf_func_name,
537  size_t param_num,
538  llvm::Value* buffer_buf,
539  llvm::Value* buffer_size,
540  llvm::Value* buffer_is_null,
541  std::vector<llvm::Value*>& output_args);
542 
543  llvm::StructType* createPointStructType(const std::string& udf_func_name,
544  size_t param_num);
545 
546  void codegenGeoPointArgs(const std::string& udf_func_name,
547  size_t param_num,
548  llvm::Value* point_buf,
549  llvm::Value* point_size,
550  llvm::Value* compression,
551  llvm::Value* input_srid,
552  llvm::Value* output_srid,
553  std::vector<llvm::Value*>& output_args);
554 
555  llvm::StructType* createMultiPointStructType(const std::string& udf_func_name,
556  size_t param_num);
557 
558  void codegenGeoMultiPointArgs(const std::string& udf_func_name,
559  size_t param_num,
560  llvm::Value* multi_point_buf,
561  llvm::Value* multi_point_size,
562  // TODO: bounds?
563  llvm::Value* compression,
564  llvm::Value* input_srid,
565  llvm::Value* output_srid,
566  std::vector<llvm::Value*>& output_args);
567 
568  llvm::StructType* createLineStringStructType(const std::string& udf_func_name,
569  size_t param_num);
570 
571  void codegenGeoLineStringArgs(const std::string& udf_func_name,
572  size_t param_num,
573  llvm::Value* line_string_buf,
574  llvm::Value* line_string_size,
575  llvm::Value* compression,
576  llvm::Value* input_srid,
577  llvm::Value* output_srid,
578  std::vector<llvm::Value*>& output_args);
579 
580  llvm::StructType* createMultiLineStringStructType(const std::string& udf_func_name,
581  size_t param_num);
582 
583  void codegenGeoMultiLineStringArgs(const std::string& udf_func_name,
584  size_t param_num,
585  llvm::Value* multi_linestring_coords,
586  llvm::Value* multi_linestring_size,
587  llvm::Value* linestring_sizes,
588  llvm::Value* linestring_sizes_size,
589  // TODO: bounds?
590  llvm::Value* compression,
591  llvm::Value* input_srid,
592  llvm::Value* output_srid,
593  std::vector<llvm::Value*>& output_args);
594 
595  llvm::StructType* createPolygonStructType(const std::string& udf_func_name,
596  size_t param_num);
597 
598  void codegenGeoPolygonArgs(const std::string& udf_func_name,
599  size_t param_num,
600  llvm::Value* polygon_buf,
601  llvm::Value* polygon_size,
602  llvm::Value* ring_sizes_buf,
603  llvm::Value* num_rings,
604  llvm::Value* compression,
605  llvm::Value* input_srid,
606  llvm::Value* output_srid,
607  std::vector<llvm::Value*>& output_args);
608 
609  llvm::StructType* createMultiPolygonStructType(const std::string& udf_func_name,
610  size_t param_num);
611 
612  void codegenGeoMultiPolygonArgs(const std::string& udf_func_name,
613  size_t param_num,
614  llvm::Value* polygon_coords,
615  llvm::Value* polygon_coords_size,
616  llvm::Value* ring_sizes_buf,
617  llvm::Value* ring_sizes,
618  llvm::Value* polygon_bounds,
619  llvm::Value* polygon_bounds_sizes,
620  llvm::Value* compression,
621  llvm::Value* input_srid,
622  llvm::Value* output_srid,
623  std::vector<llvm::Value*>& output_args);
624 
625  std::vector<llvm::Value*> codegenFunctionOperCastArgs(
626  const Analyzer::FunctionOper*,
627  const ExtensionFunction*,
628  const std::vector<llvm::Value*>&,
629  const std::vector<size_t>&,
630  const std::unordered_map<llvm::Value*, llvm::Value*>&,
631  const CompilationOptions&);
632 
633  llvm::StructType* createStringViewStructType();
634 
635  // Return LLVM intrinsic providing fast arithmetic with overflow check
636  // for the given binary operation.
637  llvm::Function* getArithWithOverflowIntrinsic(const Analyzer::BinOper* bin_oper,
638  llvm::Type* type);
639 
640  // Generate code for the given binary operation with overflow check.
641  // Signed integer add, sub and mul operations are supported. Overflow
642  // check is performed using LLVM arithmetic intrinsics which are not
643  // supported for GPU. Return the IR value which holds operation result.
644  llvm::Value* codegenBinOpWithOverflowForCPU(const Analyzer::BinOper* bin_oper,
645  llvm::Value* lhs_lv,
646  llvm::Value* rhs_lv,
647  const std::string& null_check_suffix,
648  const SQLTypeInfo& ti);
649 
650  std::pair<std::vector<llvm::Value*>, std::unique_ptr<CodeGenerator::NullCheckCodegen>>
652  const CompilationOptions& co,
653  const size_t arg_idx,
654  const bool codegen_nullcheck);
655 
656  Executor* executor_;
657 
658  protected:
659  Executor* executor() const {
660  if (!executor_) {
661  throw ExecutorRequired();
662  }
663  return executor_;
664  }
665 
668  friend class GroupByAndAggregate;
669 
670  private:
671  // mutex to protect the critical section in initializeNVPTXBackend
672  static std::mutex initialize_nvptx_mutex_;
673  // mutex to protect the critical sections in
674  // generateNativeCPUCode/create_execution_engine
675  static std::mutex initialize_cpu_backend_mutex_;
676 };
677 
678 // Code generator specialized for scalar expressions which doesn't require an executor.
680  public:
681  // Constructor which takes the runtime module.
682  ScalarCodeGenerator(std::unique_ptr<llvm::Module> llvm_module)
683  : CodeGenerator(nullptr, nullptr), module_(std::move(llvm_module)) {}
684 
685  // Function generated for a given analyzer expression. For GPU, a wrapper which meets
686  // the kernel signature constraints (returns void, takes all arguments as pointers) is
687  // generated. Also returns the list of column expressions for which compatible input
688  // parameters must be passed to the input of the generated function.
690  llvm::Function* func;
691  llvm::Function* wrapper_func;
692  std::vector<std::shared_ptr<Analyzer::ColumnVar>> inputs;
693  };
694 
695  // Compiles the given scalar expression to IR and the list of columns in the expression,
696  // needed to provide inputs to the generated function.
698  const bool fetch_columns,
699  const CompilationOptions& co);
700 
701  // Generates the native function pointers for each device.
702  // NB: this is separated from the compile method to allow building higher level code
703  // generators which can inline the IR for evaluating a single expression (for example
704  // loops).
705  std::vector<void*> generateNativeCode(Executor* executor,
706  const CompiledExpression& compiled_expression,
707  const CompilationOptions& co);
708 
710 
711  using ColumnMap =
712  std::unordered_map<InputColDescriptor, std::shared_ptr<Analyzer::ColumnVar>>;
713 
714  private:
715  std::vector<llvm::Value*> codegenColumn(const Analyzer::ColumnVar*,
716  const bool fetch_column,
717  const CompilationOptions&) override;
718 
719  // Collect the columns used by the given analyzer expressions and fills in the column
720  // map to be used during code generation.
722 
723  std::vector<void*> generateNativeGPUCode(Executor* executor,
724  llvm::Function* func,
725  llvm::Function* wrapper_func,
726  const CompilationOptions& co);
727 
728  std::unique_ptr<llvm::Module> module_;
730  std::unique_ptr<CgenState> own_cgen_state_;
731  std::unique_ptr<PlanState> own_plan_state_;
732  std::unique_ptr<CudaMgr_Namespace::CudaMgr> cuda_mgr_;
733  std::shared_ptr<GpuCompilationContext> gpu_compilation_context_;
734  std::unique_ptr<llvm::TargetMachine> nvptx_target_machine_;
735 };
736 
741 std::unique_ptr<llvm::Module> runtime_module_shallow_copy(CgenState* cgen_state);
742 
746 std::vector<llvm::Value*> generate_column_heads_load(const int num_columns,
747  llvm::Value* byte_stream_arg,
748  llvm::IRBuilder<>& ir_builder,
749  llvm::LLVMContext& ctx);
llvm::StructType * createLineStringStructType(const std::string &udf_func_name, size_t param_num)
void codegenGeoMultiPolygonArgs(const std::string &udf_func_name, size_t param_num, llvm::Value *polygon_coords, llvm::Value *polygon_coords_size, llvm::Value *ring_sizes_buf, llvm::Value *ring_sizes, llvm::Value *polygon_bounds, llvm::Value *polygon_bounds_sizes, llvm::Value *compression, llvm::Value *input_srid, llvm::Value *output_srid, std::vector< llvm::Value * > &output_args)
llvm::Value * codegenIntArith(const Analyzer::BinOper *, llvm::Value *, llvm::Value *, const CompilationOptions &)
llvm::Value * codegenPerRowStringOper(const Analyzer::StringOper *string_oper, const CompilationOptions &co)
CompiledExpression compile(const Analyzer::Expr *expr, const bool fetch_columns, const CompilationOptions &co)
NullCheckCodegen(CgenState *cgen_state, Executor *executor, llvm::Value *nullable_lv, const SQLTypeInfo &nullable_ti, const std::string &name="")
Definition: IRCodegen.cpp:1493
llvm::Value * codegenCastFromFp(llvm::Value *operand_lv, const SQLTypeInfo &operand_ti, const SQLTypeInfo &ti)
Definition: CastIR.cpp:601
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:372
llvm::Value * codegenConstantWidthBucketExpr(const Analyzer::WidthBucketExpr *, const CompilationOptions &)
Definition: IRCodegen.cpp:364
std::unique_ptr< llvm::Module > runtime_module_shallow_copy(CgenState *cgen_state)
llvm::BasicBlock * args_notnull_bb
llvm::BasicBlock * nullcheck_bb
SQLTypes
Definition: sqltypes.h:65
std::unique_ptr< PlanState > own_plan_state_
llvm::Value * codegenTreeRegPredict(const Analyzer::MLPredictExpr *, const std::shared_ptr< AbstractTreeModel > &tree_model, const CompilationOptions &)
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)
llvm::Value * codegenCastNonStringToString(llvm::Value *operand_lv, const SQLTypeInfo &operand_ti, const SQLTypeInfo &ti, const bool operand_is_const, const CompilationOptions &co)
Definition: CastIR.cpp:350
SQLQualifier
Definition: sqldefs.h:74
llvm::Value * codegenRowId(const Analyzer::ColumnVar *col_var, const CompilationOptions &co)
Definition: ColumnIR.cpp:391
llvm::StructType * createMultiPointStructType(const std::string &udf_func_name, size_t param_num)
std::vector< llvm::Value * > codegenFunctionOperCastArgs(const Analyzer::FunctionOper *, const ExtensionFunction *, const std::vector< llvm::Value * > &, const std::vector< size_t > &, const std::unordered_map< llvm::Value *, llvm::Value * > &, const CompilationOptions &)
llvm::StructType * createMultiLineStringStructType(const std::string &udf_func_name, size_t param_num)
SQLOps
Definition: sqldefs.h:31
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:496
std::unique_ptr< llvm::TargetMachine > nvptx_target_machine_
llvm::Value * posArg(const Analyzer::Expr *) const
Definition: ColumnIR.cpp:590
std::shared_ptr< GpuCompilationContext > gpu_compilation_context_
llvm::Value * castArrayPointer(llvm::Value *ptr, const SQLTypeInfo &elem_ti)
llvm::Value * codegenCastToFp(llvm::Value *operand_lv, const SQLTypeInfo &operand_ti, const SQLTypeInfo &ti)
Definition: CastIR.cpp:558
llvm::Value * codgenAdjustFixedEncNull(llvm::Value *, const SQLTypeInfo &)
Definition: ColumnIR.cpp:448
llvm::Value * codegenPseudoStringOper(const Analyzer::ColumnVar *, const std::vector< StringOps_Namespace::StringOpInfo > &string_op_infos, const CompilationOptions &)
llvm::Value * foundOuterJoinMatch(const size_t nesting_level) const
Definition: ColumnIR.cpp:489
llvm::Value * codegenExtractHighPrecisionTimestamps(llvm::Value *, const SQLTypeInfo &, const ExtractField &)
Definition: DateTimeIR.cpp:260
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:94
std::unordered_set< std::shared_ptr< Analyzer::Expr >> HoistedFiltersSet
Definition: PlanState.h:45
llvm::Value * codegenDeciDiv(const Analyzer::BinOper *, const CompilationOptions &)
std::vector< llvm::Value * > codegenHoistedConstants(const std::vector< const Analyzer::Constant * > &constants, const EncodingType enc_type, const shared::StringDictKey &dict_id)
Definition: ConstantIR.cpp:373
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:26
llvm::Value * codegenLinRegPredict(const Analyzer::MLPredictExpr *, const std::shared_ptr< AbstractMLModel > &model, const CompilationOptions &)
std::unordered_map< InputColDescriptor, std::shared_ptr< Analyzer::ColumnVar >> ColumnMap
static std::string generatePTX(const std::string &cuda_llir, llvm::TargetMachine *nvptx_target_machine, llvm::LLVMContext &context)
std::vector< llvm::Value * > codegenGeoBinOper(const Analyzer::GeoBinOper *, const CompilationOptions &)
Definition: GeoIR.cpp:263
const CudaMgr_Namespace::CudaMgr * cuda_mgr
void codegenBufferArgs(const std::string &udf_func_name, size_t param_num, llvm::Value *buffer_buf, llvm::Value *buffer_size, llvm::Value *buffer_is_null, std::vector< llvm::Value * > &output_args)
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:381
llvm::TargetMachine * nvptx_target_machine
std::pair< llvm::Value *, llvm::Value * > codegenArrayBuff(llvm::Value *chunk, llvm::Value *row_pos, SQLTypes array_type, bool cast_and_extend)
std::shared_ptr< const Analyzer::Expr > hashJoinLhs(const Analyzer::ColumnVar *rhs) const
Definition: ColumnIR.cpp:630
llvm::Value * codegenWindowPosition(const WindowFunctionContext *window_func_context, llvm::Value *pos_arg)
Definition: ColumnIR.cpp:235
EncodingType
Definition: sqltypes.h:240
CudaMgr_Namespace::CudaMgr * getCudaMgr() const
std::vector< llvm::Value * > codegenGeoExpr(const Analyzer::GeoExpr *, const CompilationOptions &)
Definition: GeoIR.cpp:97
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:402
std::tuple< ArgNullcheckBBs, llvm::Value * > beginArgsNullcheck(const Analyzer::FunctionOper *function_oper, const std::vector< llvm::Value * > &orig_arg_lvs)
std::vector< llvm::Value * > codegenGeoOperator(const Analyzer::GeoOperator *, const CompilationOptions &)
Definition: GeoIR.cpp:149
static std::unordered_set< llvm::Function * > markDeadRuntimeFuncs(llvm::Module &module, const std::vector< llvm::Function * > &roots, const std::vector< llvm::Function * > &leaves)
DatetruncField
Definition: DateTruncate.h:27
std::vector< llvm::Value * > codegenGeoUOper(const Analyzer::GeoUOper *, const CompilationOptions &)
Definition: GeoIR.cpp:183
void codegenSkipOverflowCheckForNull(llvm::Value *lhs_lv, llvm::Value *rhs_lv, llvm::BasicBlock *no_overflow_bb, const SQLTypeInfo &ti)
std::vector< llvm::Value * > codegenHoistedConstantsLoads(const SQLTypeInfo &type_info, const EncodingType enc_type, const shared::StringDictKey &dict_id, const int16_t lit_off, const size_t lit_bytes)
Definition: ConstantIR.cpp:142
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:280
CodeGenerator(Executor *executor)
Definition: CodeGenerator.h:31
void codegenGeoMultiPointArgs(const std::string &udf_func_name, size_t param_num, llvm::Value *multi_point_buf, llvm::Value *multi_point_size, llvm::Value *compression, llvm::Value *input_srid, llvm::Value *output_srid, std::vector< llvm::Value * > &output_args)
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 * codegenWidthBucketExpr(const Analyzer::WidthBucketExpr *, const CompilationOptions &)
Definition: IRCodegen.cpp:437
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:427
Executor * executor_
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:162
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:97
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
void codegenGeoMultiLineStringArgs(const std::string &udf_func_name, size_t param_num, llvm::Value *multi_linestring_coords, llvm::Value *multi_linestring_size, llvm::Value *linestring_sizes, llvm::Value *linestring_sizes_size, llvm::Value *compression, llvm::Value *input_srid, llvm::Value *output_srid, std::vector< llvm::Value * > &output_args)
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:106
ScalarCodeGenerator(std::unique_ptr< llvm::Module > llvm_module)
std::vector< llvm::Value * > codegenGeosConstructorCall(const std::string &, std::vector< llvm::Value * >, llvm::Value *, const CompilationOptions &)
Definition: GeoIR.cpp:485
llvm::Value * codegenUMinus(const Analyzer::UOper *, const CompilationOptions &)
static std::mutex initialize_cpu_backend_mutex_
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:30
static llvm::ConstantInt * codegenIntConst(const Analyzer::Constant *constant, CgenState *cgen_state)
Definition: ConstantIR.cpp:89
Expression class for string functions The &quot;arg&quot; constructor parameter must be an expression that reso...
Definition: Analyzer.h:1601
std::vector< llvm::Value * > codegenGeosPredicateCall(const std::string &, std::vector< llvm::Value * >, const CompilationOptions &)
Definition: GeoIR.cpp:452
llvm::StructType * createPolygonStructType(const std::string &udf_func_name, size_t param_num)
static std::shared_ptr< GpuCompilationContext > generateNativeGPUCode(Executor *executor, llvm::Function *func, llvm::Function *wrapper_func, const std::unordered_set< llvm::Function * > &live_funcs, const bool is_gpu_smem_used, const CompilationOptions &co, const GPUTarget &gpu_target)
llvm::Value * codegenQualifierCmp(const SQLOps, const SQLQualifier, std::vector< llvm::Value * >, const Analyzer::Expr *, const CompilationOptions &)
Definition: CompareIR.cpp:589
llvm::Value * codegenFixedLengthColVarInWindow(const Analyzer::ColumnVar *col_var, llvm::Value *col_byte_stream, llvm::Value *pos_arg, const CompilationOptions &co, const WindowFunctionContext *window_function_context=nullptr)
Definition: ColumnIR.cpp:299
llvm::Value * endArgsNullcheck(const ArgNullcheckBBs &, llvm::Value *, 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:500
static bool alwaysCloneRuntimeFunction(const llvm::Function *func)
ColumnMap prepare(const Analyzer::Expr *)
static ArrayLoadCodegen codegenGeoArrayLoadAndNullcheck(llvm::Value *byte_stream, llvm::Value *pos, const SQLTypeInfo &ti, CgenState *cgen_state)
Definition: GeoIR.cpp:25
llvm::StructType * createStringViewStructType()
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:65
std::vector< llvm::Value * > generate_column_heads_load(const int num_columns, llvm::Value *byte_stream_arg, llvm::IRBuilder<> &ir_builder, llvm::LLVMContext &ctx)
llvm::Value * codegenBoundingBoxIntersect(const SQLOps, const SQLQualifier, const std::shared_ptr< Analyzer::Expr >, const std::shared_ptr< Analyzer::Expr >, const CompilationOptions &)
Definition: CompareIR.cpp:285
static void linkModuleWithLibdevice(Executor *executor, llvm::Module &module, llvm::PassManagerBuilder &pass_manager_builder, const GPUTarget &gpu_target)
ExtractField
llvm::Value * toBool(llvm::Value *)
Definition: LogicalIR.cpp:344
std::vector< llvm::Value * > codegenGeoColumnVar(const Analyzer::GeoColumnVar *, const bool fetch_columns, const CompilationOptions &co)
Definition: GeoIR.cpp:54
static bool prioritizeQuals(const RelAlgExecutionUnit &ra_exe_unit, std::vector< Analyzer::Expr * > &primary_quals, std::vector< Analyzer::Expr * > &deferred_quals, const PlanState::HoistedFiltersSet &hoisted_quals)
Definition: LogicalIR.cpp:158
std::vector< void * > generateNativeGPUCode(Executor *executor, llvm::Function *func, llvm::Function *wrapper_func, const CompilationOptions &co)
llvm::Value * codegenFunctionOperWithCustomTypeHandling(const Analyzer::FunctionOperWithCustomTypeHandling *, const CompilationOptions &)
llvm::Value * codegenCmp(const Analyzer::BinOper *, const CompilationOptions &)
Definition: CompareIR.cpp:230
bool needCastForHashJoinLhs(const Analyzer::ColumnVar *rhs) const
Definition: ColumnIR.cpp:706
llvm::Value * codegenCastBetweenTimestamps(llvm::Value *ts_lv, const SQLTypeInfo &operand_dimen, const SQLTypeInfo &target_dimen, const bool nullable)
Definition: CastIR.cpp:199
std::pair< std::vector< llvm::Value * >, std::unique_ptr< CodeGenerator::NullCheckCodegen > > codegenStringFetchAndEncode(const Analyzer::StringOper *expr, const CompilationOptions &co, const size_t arg_idx, const bool codegen_nullcheck)
llvm::Value * codegenUnnest(const Analyzer::UOper *, const CompilationOptions &)
Definition: ArrayIR.cpp:20
std::vector< llvm::Value * > codegenGeoArgs(const std::vector< std::shared_ptr< Analyzer::Expr >> &, const CompilationOptions &)
Definition: GeoIR.cpp:371
llvm::Value * finalize(llvm::Value *null_lv, llvm::Value *notnull_lv)
Definition: IRCodegen.cpp:1530
llvm::Value * colByteStream(const Analyzer::ColumnVar *col_var, const bool fetch_column, const bool hoist_literals)
Definition: ColumnIR.cpp:574
llvm::Value * codegenIsNullNumber(llvm::Value *, const SQLTypeInfo &)
Definition: LogicalIR.cpp:416
llvm::Value * codegenLogical(const Analyzer::BinOper *, const CompilationOptions &)
Definition: LogicalIR.cpp:299
std::unique_ptr< llvm::Module > module_
llvm::Value * codegenCompression(const SQLTypeInfo &type_info)
llvm::Value * codegenCastTimestampToTime(llvm::Value *ts_lv, const int dimen, const bool nullable)
Definition: CastIR.cpp:142
std::vector< llvm::Value * > codegenGeoConstant(const Analyzer::GeoConstant *, const CompilationOptions &)
Definition: GeoIR.cpp:111
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:231
CodeGenerator(CgenState *cgen_state, PlanState *plan_state)
Definition: CodeGenerator.h:38
llvm::Value * codegenCast(const Analyzer::UOper *, const CompilationOptions &)
Definition: CastIR.cpp:21
llvm::Value * codegenDateTruncHighPrecisionTimestamps(llvm::Value *, const SQLTypeInfo &, const DatetruncField &)
Definition: DateTimeIR.cpp:304
std::unique_ptr< InValuesBitmap > createInValuesBitmap(const Analyzer::InValues *, const CompilationOptions &)
Definition: InValuesIR.cpp:112
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:769
llvm::Value * codegenFixedLengthColVar(const Analyzer::ColumnVar *col_var, llvm::Value *col_byte_stream, llvm::Value *pos_arg, const WindowFunctionContext *window_function_context=nullptr)
Definition: ColumnIR.cpp:248
std::vector< llvm::Value * > codegenVariableLengthStringColVar(llvm::Value *col_byte_stream, llvm::Value *pos_arg)
Definition: ColumnIR.cpp:377
std::vector< void * > generateNativeCode(Executor *executor, const CompiledExpression &compiled_expression, const CompilationOptions &co)
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 * codegenLogicalShortCircuit(const Analyzer::BinOper *, const CompilationOptions &)
Definition: LogicalIR.cpp:197
std::unique_ptr< DiamondCodegen > null_check
static std::unique_ptr< llvm::TargetMachine > initializeNVPTXBackend(const CudaMgr_Namespace::NvidiaDeviceArch arch)
llvm::Value * resolveGroupedColumnReference(const Analyzer::ColumnVar *)
Definition: ColumnIR.cpp:554
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 &)
static std::mutex initialize_nvptx_mutex_
Executor * executor() const
llvm::StructType * createMultiPolygonStructType(const std::string &udf_func_name, size_t param_num)