OmniSciDB  c07336695a
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.
34  CodeGenerator(CgenState* cgen_state, PlanState* plan_state)
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,
79  CgenState* cgen_state);
80 
81  static std::unique_ptr<llvm::TargetMachine> initializeNVPTXBackend();
82 
83  struct GPUCode {
84  std::vector<std::pair<void*, void*>> native_functions;
85  std::vector<std::tuple<void*, GpuCompilationContext*>> cached_functions;
86  };
87 
88  struct GPUTarget {
89  llvm::TargetMachine* nvptx_target_machine;
91  unsigned block_size;
94  };
95 
97  llvm::Function* func,
98  llvm::Function* wrapper_func,
99  const std::unordered_set<llvm::Function*>& live_funcs,
100  const CompilationOptions& co,
101  const GPUTarget& gpu_target);
102 
103  static bool prioritizeQuals(const RelAlgExecutionUnit& ra_exe_unit,
104  std::vector<Analyzer::Expr*>& primary_quals,
105  std::vector<Analyzer::Expr*>& deferred_quals);
106 
107  struct ExecutorRequired : public std::runtime_error {
109  : std::runtime_error("Executor required to generate this expression") {}
110  };
111 
112  private:
113  std::vector<llvm::Value*> codegen(const Analyzer::Constant*,
114  const EncodingType enc_type,
115  const int dict_id,
116  const CompilationOptions&);
117 
118  virtual std::vector<llvm::Value*> codegenColumn(const Analyzer::ColumnVar*,
119  const bool fetch_column,
120  const CompilationOptions&);
121 
122  llvm::Value* codegenArith(const Analyzer::BinOper*, const CompilationOptions&);
123 
124  llvm::Value* codegenUMinus(const Analyzer::UOper*, const CompilationOptions&);
125 
126  llvm::Value* codegenCmp(const Analyzer::BinOper*, const CompilationOptions&);
127 
128  llvm::Value* codegenCmp(const SQLOps,
129  const SQLQualifier,
130  std::vector<llvm::Value*>,
131  const SQLTypeInfo&,
132  const Analyzer::Expr*,
133  const CompilationOptions&);
134 
135  llvm::Value* codegenIsNull(const Analyzer::UOper*, const CompilationOptions&);
136 
137  llvm::Value* codegenIsNullNumber(llvm::Value*, const SQLTypeInfo&);
138 
139  llvm::Value* codegenLogical(const Analyzer::BinOper*, const CompilationOptions&);
140 
141  llvm::Value* codegenLogical(const Analyzer::UOper*, const CompilationOptions&);
142 
143  llvm::Value* codegenCast(const Analyzer::UOper*, const CompilationOptions&);
144 
145  llvm::Value* codegenCast(llvm::Value* operand_lv,
146  const SQLTypeInfo& operand_ti,
147  const SQLTypeInfo& ti,
148  const bool operand_is_const,
149  const CompilationOptions& co);
150 
151  llvm::Value* codegen(const Analyzer::InValues*, const CompilationOptions&);
152 
153  llvm::Value* codegen(const Analyzer::InIntegerSet* expr, const CompilationOptions& co);
154 
155  std::vector<llvm::Value*> codegen(const Analyzer::CaseExpr*, const CompilationOptions&);
156 
157  llvm::Value* codegen(const Analyzer::ExtractExpr*, const CompilationOptions&);
158 
159  llvm::Value* codegen(const Analyzer::DateaddExpr*, const CompilationOptions&);
160 
161  llvm::Value* codegen(const Analyzer::DatediffExpr*, const CompilationOptions&);
162 
163  llvm::Value* codegen(const Analyzer::DatetruncExpr*, const CompilationOptions&);
164 
165  llvm::Value* codegen(const Analyzer::CharLengthExpr*, const CompilationOptions&);
166 
167  llvm::Value* codegen(const Analyzer::KeyForStringExpr*, const CompilationOptions&);
168 
169  llvm::Value* codegen(const Analyzer::LikeExpr*, const CompilationOptions&);
170 
171  llvm::Value* codegen(const Analyzer::RegexpExpr*, const CompilationOptions&);
172 
173  llvm::Value* codegenUnnest(const Analyzer::UOper*, const CompilationOptions&);
174 
175  llvm::Value* codegenArrayAt(const Analyzer::BinOper*, const CompilationOptions&);
176 
177  llvm::Value* codegen(const Analyzer::CardinalityExpr*, const CompilationOptions&);
178 
179  std::vector<llvm::Value*> codegenArrayExpr(const Analyzer::ArrayExpr*,
180  const CompilationOptions&);
181 
182  llvm::Value* codegenFunctionOper(const Analyzer::FunctionOper*,
183  const CompilationOptions&);
184 
187  const CompilationOptions&);
188 
189  llvm::Value* codegen(const Analyzer::BinOper*, const CompilationOptions&);
190 
191  llvm::Value* codegen(const Analyzer::UOper*, const CompilationOptions&);
192 
193  std::vector<llvm::Value*> codegenHoistedConstantsLoads(const SQLTypeInfo& type_info,
194  const EncodingType enc_type,
195  const int dict_id,
196  const int16_t lit_off);
197 
198  std::vector<llvm::Value*> codegenHoistedConstantsPlaceholders(
199  const SQLTypeInfo& type_info,
200  const EncodingType enc_type,
201  const int16_t lit_off,
202  const std::vector<llvm::Value*>& literal_loads);
203 
204  std::vector<llvm::Value*> codegenColVar(const Analyzer::ColumnVar*,
205  const bool fetch_column,
206  const bool update_query_plan,
207  const CompilationOptions&);
208 
209  llvm::Value* codegenFixedLengthColVar(const Analyzer::ColumnVar* col_var,
210  llvm::Value* col_byte_stream,
211  llvm::Value* pos_arg);
212 
213  // Generates code for a fixed length column when a window function is active.
214  llvm::Value* codegenFixedLengthColVarInWindow(const Analyzer::ColumnVar* col_var,
215  llvm::Value* col_byte_stream,
216  llvm::Value* pos_arg);
217 
218  // Generate the position for the given window function and the query iteration position.
219  llvm::Value* codegenWindowPosition(WindowFunctionContext* window_func_context,
220  llvm::Value* pos_arg);
221 
222  std::vector<llvm::Value*> codegenVariableLengthStringColVar(
223  llvm::Value* col_byte_stream,
224  llvm::Value* pos_arg);
225 
226  llvm::Value* codegenRowId(const Analyzer::ColumnVar* col_var,
227  const CompilationOptions& co);
228 
229  llvm::Value* codgenAdjustFixedEncNull(llvm::Value*, const SQLTypeInfo&);
230 
231  std::vector<llvm::Value*> codegenOuterJoinNullPlaceholder(
232  const Analyzer::ColumnVar* col_var,
233  const bool fetch_column,
234  const CompilationOptions& co);
235 
236  llvm::Value* codegenIntArith(const Analyzer::BinOper*,
237  llvm::Value*,
238  llvm::Value*,
239  const CompilationOptions&);
240 
241  llvm::Value* codegenFpArith(const Analyzer::BinOper*, llvm::Value*, llvm::Value*);
242 
243  llvm::Value* codegenCastTimestampToDate(llvm::Value* ts_lv,
244  const int dimen,
245  const bool nullable);
246 
247  llvm::Value* codegenCastBetweenTimestamps(llvm::Value* ts_lv,
248  const int operand_dimen,
249  const int target_dimen,
250  const bool nullable);
251 
252  llvm::Value* codegenCastFromString(llvm::Value* operand_lv,
253  const SQLTypeInfo& operand_ti,
254  const SQLTypeInfo& ti,
255  const bool operand_is_const,
256  const CompilationOptions& co);
257 
258  llvm::Value* codegenCastToFp(llvm::Value* operand_lv,
259  const SQLTypeInfo& operand_ti,
260  const SQLTypeInfo& ti);
261 
262  llvm::Value* codegenCastFromFp(llvm::Value* operand_lv,
263  const SQLTypeInfo& operand_ti,
264  const SQLTypeInfo& ti);
265 
266  llvm::Value* codegenAdd(const Analyzer::BinOper*,
267  llvm::Value*,
268  llvm::Value*,
269  const std::string& null_typename,
270  const std::string& null_check_suffix,
271  const SQLTypeInfo&,
272  const CompilationOptions&);
273 
274  llvm::Value* codegenSub(const Analyzer::BinOper*,
275  llvm::Value*,
276  llvm::Value*,
277  const std::string& null_typename,
278  const std::string& null_check_suffix,
279  const SQLTypeInfo&,
280  const CompilationOptions&);
281 
282  void codegenSkipOverflowCheckForNull(llvm::Value* lhs_lv,
283  llvm::Value* rhs_lv,
284  llvm::BasicBlock* no_overflow_bb,
285  const SQLTypeInfo& ti);
286 
287  llvm::Value* codegenMul(const Analyzer::BinOper*,
288  llvm::Value*,
289  llvm::Value*,
290  const std::string& null_typename,
291  const std::string& null_check_suffix,
292  const SQLTypeInfo&,
293  const CompilationOptions&,
294  bool downscale = true);
295 
296  llvm::Value* codegenDiv(llvm::Value*,
297  llvm::Value*,
298  const std::string& null_typename,
299  const std::string& null_check_suffix,
300  const SQLTypeInfo&,
301  bool upscale = true);
302 
303  llvm::Value* codegenDeciDiv(const Analyzer::BinOper*, const CompilationOptions&);
304 
305  llvm::Value* codegenMod(llvm::Value*,
306  llvm::Value*,
307  const std::string& null_typename,
308  const std::string& null_check_suffix,
309  const SQLTypeInfo&);
310 
311  llvm::Value* codegenCase(const Analyzer::CaseExpr*,
312  llvm::Type* case_llvm_type,
313  const bool is_real_str,
314  const CompilationOptions&);
315 
316  llvm::Value* codegenExtractHighPrecisionTimestamps(llvm::Value*,
317  const SQLTypeInfo&,
318  const ExtractField&);
319 
320  llvm::Value* codegenDateTruncHighPrecisionTimestamps(llvm::Value*,
321  const SQLTypeInfo&,
322  const DatetruncField&);
323 
324  llvm::Value* codegenCmpDecimalConst(const SQLOps,
325  const SQLQualifier,
326  const Analyzer::Expr*,
327  const SQLTypeInfo&,
328  const Analyzer::Expr*,
329  const CompilationOptions&);
330 
331  llvm::Value* codegenOverlaps(const SQLOps,
332  const SQLQualifier,
333  const std::shared_ptr<Analyzer::Expr>,
334  const std::shared_ptr<Analyzer::Expr>,
335  const CompilationOptions&);
336 
337  llvm::Value* codegenStrCmp(const SQLOps,
338  const SQLQualifier,
339  const std::shared_ptr<Analyzer::Expr>,
340  const std::shared_ptr<Analyzer::Expr>,
341  const CompilationOptions&);
342 
343  llvm::Value* codegenQualifierCmp(const SQLOps,
344  const SQLQualifier,
345  std::vector<llvm::Value*>,
346  const Analyzer::Expr*,
347  const CompilationOptions&);
348 
349  llvm::Value* codegenLogicalShortCircuit(const Analyzer::BinOper*,
350  const CompilationOptions&);
351 
352  llvm::Value* codegenDictLike(const std::shared_ptr<Analyzer::Expr> arg,
353  const Analyzer::Constant* pattern,
354  const bool ilike,
355  const bool is_simple,
356  const char escape_char,
357  const CompilationOptions&);
358 
359  llvm::Value* codegenDictStrCmp(const std::shared_ptr<Analyzer::Expr>,
360  const std::shared_ptr<Analyzer::Expr>,
361  const SQLOps,
362  const CompilationOptions& co);
363 
364  llvm::Value* codegenDictRegexp(const std::shared_ptr<Analyzer::Expr> arg,
365  const Analyzer::Constant* pattern,
366  const char escape_char,
367  const CompilationOptions&);
368 
369  // Returns the IR value which holds true iff at least one match has been found for outer
370  // join, null if there's no outer join condition on the given nesting level.
371  llvm::Value* foundOuterJoinMatch(const ssize_t nesting_level) const;
372 
374 
375  llvm::Value* colByteStream(const Analyzer::ColumnVar* col_var,
376  const bool fetch_column,
377  const bool hoist_literals);
378 
379  std::shared_ptr<const Analyzer::Expr> hashJoinLhs(const Analyzer::ColumnVar* rhs) const;
380 
381  std::shared_ptr<const Analyzer::ColumnVar> hashJoinLhsTuple(
382  const Analyzer::ColumnVar* rhs,
383  const Analyzer::BinOper* tautological_eq) const;
384 
385  std::unique_ptr<InValuesBitmap> createInValuesBitmap(const Analyzer::InValues*,
386  const CompilationOptions&);
387 
388  bool checkExpressionRanges(const Analyzer::UOper*, int64_t, int64_t);
389 
390  bool checkExpressionRanges(const Analyzer::BinOper*, int64_t, int64_t);
391 
393  llvm::BasicBlock* args_null_bb;
394  llvm::BasicBlock* args_notnull_bb;
395  llvm::BasicBlock* orig_bb;
396  };
397 
399  const std::vector<llvm::Value*>& orig_arg_lvs);
400 
401  llvm::Value* endArgsNullcheck(const ArgNullcheckBBs&,
402  llvm::Value*,
403  const Analyzer::FunctionOper*);
404 
406  const std::vector<llvm::Value*>&);
407 
408  std::vector<llvm::Value*> codegenFunctionOperCastArgs(
409  const Analyzer::FunctionOper*,
410  const ExtensionFunction*,
411  const std::vector<llvm::Value*>&,
412  const std::unordered_map<llvm::Value*, llvm::Value*>&,
413  const CompilationOptions&);
414 
415  // Return LLVM intrinsic providing fast arithmetic with overflow check
416  // for the given binary operation.
417  llvm::Function* getArithWithOverflowIntrinsic(const Analyzer::BinOper* bin_oper,
418  llvm::Type* type);
419 
420  // Generate code for the given binary operation with overflow check.
421  // Signed integer add, sub and mul operations are supported. Overflow
422  // check is performed using LLVM arithmetic intrinsics which are not
423  // supported for GPU. Return the IR value which holds operation result.
424  llvm::Value* codegenBinOpWithOverflowForCPU(const Analyzer::BinOper* bin_oper,
425  llvm::Value* lhs_lv,
426  llvm::Value* rhs_lv,
427  const std::string& null_check_suffix,
428  const SQLTypeInfo& ti);
429 
430  Executor* executor_;
431 
432  protected:
433  Executor* executor() const {
434  if (!executor_) {
435  throw ExecutorRequired();
436  }
437  return executor_;
438  }
439 
442 };
443 
444 // Code generator specialized for scalar expressions which doesn't require an executor.
446  public:
447  // Constructor which takes the runtime module.
448  ScalarCodeGenerator(std::unique_ptr<llvm::Module> module)
449  : CodeGenerator(nullptr, nullptr), module_(std::move(module)) {}
450 
451  // Function generated for a given analyzer expression. For GPU, a wrapper which meets
452  // the kernel signature constraints (returns void, takes all arguments as pointers) is
453  // generated. Also returns the list of column expressions for which compatible input
454  // parameters must be passed to the input of the generated function.
456  llvm::Function* func;
457  llvm::Function* wrapper_func;
458  std::vector<std::shared_ptr<Analyzer::ColumnVar>> inputs;
459  };
460 
461  // Compiles the given scalar expression to IR and the list of columns in the expression,
462  // needed to provide inputs to the generated function.
463  CompiledExpression compile(const Analyzer::Expr* expr,
464  const bool fetch_columns,
465  const CompilationOptions& co);
466 
467  // Generates the native function pointers for each device.
468  // NB: this is separated from the compile method to allow building higher level code
469  // generators which can inline the IR for evaluating a single expression (for example
470  // loops).
471  std::vector<void*> generateNativeCode(const CompiledExpression& compiled_expression,
472  const CompilationOptions& co);
473 
474  CudaMgr_Namespace::CudaMgr* getCudaMgr() const { return cuda_mgr_.get(); }
475 
476  using ColumnMap =
477  std::unordered_map<InputColDescriptor, std::shared_ptr<Analyzer::ColumnVar>>;
478 
479  private:
480  std::vector<llvm::Value*> codegenColumn(const Analyzer::ColumnVar*,
481  const bool fetch_column,
482  const CompilationOptions&) override;
483 
484  // Collect the columns used by the given analyzer expressions and fills in the column
485  // map to be used during code generation.
486  ColumnMap prepare(const Analyzer::Expr*);
487 
488  std::vector<void*> generateNativeGPUCode(llvm::Function* func,
489  llvm::Function* wrapper_func,
490  const CompilationOptions& co);
491 
492  std::unique_ptr<llvm::Module> module_;
494  std::unique_ptr<CgenState> own_cgen_state_;
495  std::unique_ptr<PlanState> own_plan_state_;
496  std::unique_ptr<CudaMgr_Namespace::CudaMgr> cuda_mgr_;
497  std::vector<std::unique_ptr<GpuCompilationContext>> gpu_compilation_contexts_;
498  std::unique_ptr<llvm::TargetMachine> nvptx_target_machine_;
499 };
llvm::Value * codegenIntArith(const Analyzer::BinOper *, llvm::Value *, llvm::Value *, const CompilationOptions &)
std::vector< std::tuple< void *, GpuCompilationContext * > > cached_functions
Definition: CodeGenerator.h:85
std::vector< llvm::Value * > codegenHoistedConstants(const std::vector< const Analyzer::Constant *> &constants, const EncodingType enc_type, const int dict_id)
Definition: ConstantIR.cpp:287
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:84
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::shared_ptr< const Analyzer::ColumnVar > hashJoinLhsTuple(const Analyzer::ColumnVar *rhs, const Analyzer::BinOper *tautological_eq) const
Definition: ColumnIR.cpp:586
llvm::BasicBlock * args_notnull_bb
std::unique_ptr< PlanState > own_plan_state_
static ExecutionEngineWrapper generateNativeCPUCode(llvm::Function *func, const std::unordered_set< llvm::Function *> &live_funcs, const CompilationOptions &co)
std::shared_ptr< const Analyzer::Expr > hashJoinLhs(const Analyzer::ColumnVar *rhs) const
Definition: ColumnIR.cpp:539
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 &)
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
CgenState * cgen_state_
ExecutionEngineWrapper execution_engine_
SQLQualifier
Definition: sqldefs.h:69
llvm::Value * codegenRowId(const Analyzer::ColumnVar *col_var, const CompilationOptions &co)
Definition: ColumnIR.cpp:312
Executor * executor() const
static std::unordered_set< llvm::Function * > markDeadRuntimeFuncs(llvm::Module &module, const std::vector< llvm::Function *> &roots, const std::vector< llvm::Function *> &leaves)
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 &)
std::vector< llvm::Value * > codegenOuterJoinNullPlaceholder(const Analyzer::ColumnVar *col_var, const bool fetch_column, const CompilationOptions &co)
Definition: ColumnIR.cpp:412
CudaMgr_Namespace::CudaMgr * getCudaMgr() const
llvm::Value * codegenFunctionOperNullArg(const Analyzer::FunctionOper *, const std::vector< llvm::Value *> &)
std::unique_ptr< llvm::TargetMachine > nvptx_target_machine_
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:357
llvm::Value * codgenAdjustFixedEncNull(llvm::Value *, const SQLTypeInfo &)
Definition: ColumnIR.cpp:365
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 &)
std::vector< std::unique_ptr< GpuCompilationContext > > gpu_compilation_contexts_
llvm::Value * codegenExtractHighPrecisionTimestamps(llvm::Value *, const SQLTypeInfo &, const ExtractField &)
Definition: DateTimeIR.cpp:155
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 &)
llvm::Value * codegenArrayAt(const Analyzer::BinOper *, const CompilationOptions &)
Definition: ArrayIR.cpp:25
const CudaMgr_Namespace::CudaMgr * cuda_mgr
Definition: CodeGenerator.h:90
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:89
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
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)
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_
llvm::Value * foundOuterJoinMatch(const ssize_t nesting_level) const
Definition: ColumnIR.cpp:405
ArgNullcheckBBs beginArgsNullcheck(const Analyzer::FunctionOper *function_oper, const std::vector< llvm::Value *> &orig_arg_lvs)
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
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
std::unordered_map< InputColDescriptor, std::shared_ptr< Analyzer::ColumnVar > > ColumnMap
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 * codegenUMinus(const Analyzer::UOper *, const CompilationOptions &)
static bool prioritizeQuals(const RelAlgExecutionUnit &ra_exe_unit, std::vector< Analyzer::Expr *> &primary_quals, std::vector< Analyzer::Expr *> &deferred_quals)
Definition: LogicalIR.cpp:157
PlanState * plan_state_
std::vector< llvm::Value * > codegen(const Analyzer::Expr *, const bool fetch_columns, const CompilationOptions &)
Definition: IRCodegen.cpp:25
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
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
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 * posArg(const Analyzer::Expr *) const
Definition: ColumnIR.cpp:503
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:392
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:113
llvm::Value * codegenQualifierCmp(const SQLOps, const SQLQualifier, std::vector< llvm::Value *>, const Analyzer::Expr *, const CompilationOptions &)
Definition: CompareIR.cpp:471
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::vector< llvm::Value * > codegenVariableLengthStringColVar(llvm::Value *col_byte_stream, llvm::Value *pos_arg)
Definition: ColumnIR.cpp:298
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 * 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 &)