forked from heavyai/heavydb
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrayIR.cpp
More file actions
53 lines (50 loc) · 2.64 KB
/
ArrayIR.cpp
File metadata and controls
53 lines (50 loc) · 2.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*
* Copyright 2017 MapD Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "Execute.h"
llvm::Value* Executor::codegenUnnest(const Analyzer::UOper* uoper, const CompilationOptions& co) {
return codegen(uoper->get_operand(), true, co).front();
}
llvm::Value* Executor::codegenArrayAt(const Analyzer::BinOper* array_at, const CompilationOptions& co) {
const auto arr_expr = array_at->get_left_operand();
const auto idx_expr = array_at->get_right_operand();
const auto& idx_ti = idx_expr->get_type_info();
CHECK(idx_ti.is_integer());
auto idx_lvs = codegen(idx_expr, true, co);
CHECK_EQ(size_t(1), idx_lvs.size());
auto idx_lv = idx_lvs.front();
if (idx_ti.get_logical_size() < 8) {
idx_lv = cgen_state_->ir_builder_.CreateCast(
llvm::Instruction::CastOps::SExt, idx_lv, get_int_type(64, cgen_state_->context_));
}
const auto& array_ti = arr_expr->get_type_info();
CHECK(array_ti.is_array());
const auto& elem_ti = array_ti.get_elem_type();
const std::string array_at_fname{
elem_ti.is_fp() ? "array_at_" + std::string(elem_ti.get_type() == kDOUBLE ? "double_checked" : "float_checked")
: "array_at_int" + std::to_string(elem_ti.get_logical_size() * 8) + "_t_checked"};
const auto ret_ty = elem_ti.is_fp() ? (elem_ti.get_type() == kDOUBLE ? llvm::Type::getDoubleTy(cgen_state_->context_)
: llvm::Type::getFloatTy(cgen_state_->context_))
: get_int_type(elem_ti.get_logical_size() * 8, cgen_state_->context_);
const auto arr_lvs = codegen(arr_expr, true, co);
CHECK_EQ(size_t(1), arr_lvs.size());
return cgen_state_->emitExternalCall(array_at_fname,
ret_ty,
{arr_lvs.front(),
posArg(arr_expr),
idx_lv,
elem_ti.is_fp() ? static_cast<llvm::Value*>(inlineFpNull(elem_ti))
: static_cast<llvm::Value*>(inlineIntNull(elem_ti))});
}