OmniSciDB  1dac507f6e
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Codec.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2017 MapD Technologies, 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 #include "Codec.h"
18 #include "LLVMGlobalContext.h"
19 #include "Shared/Logger.h"
20 
21 #include <llvm/IR/Constants.h>
22 #include <llvm/IR/Instruction.h>
23 #include <llvm/IR/Module.h>
24 #include <llvm/IR/Value.h>
25 
26 FixedWidthInt::FixedWidthInt(const size_t byte_width) : byte_width_{byte_width} {}
27 
28 llvm::Instruction* FixedWidthInt::codegenDecode(llvm::Value* byte_stream,
29  llvm::Value* pos,
30  llvm::Module* module) const {
31  auto& context = getGlobalLLVMContext();
32  auto f = module->getFunction("fixed_width_int_decode");
33  CHECK(f);
34  llvm::Value* args[] = {
35  byte_stream,
36  llvm::ConstantInt::get(llvm::Type::getInt32Ty(context), byte_width_),
37  pos};
38  return llvm::CallInst::Create(f, args);
39 }
40 
42  : byte_width_{byte_width} {}
43 
44 llvm::Instruction* FixedWidthUnsigned::codegenDecode(llvm::Value* byte_stream,
45  llvm::Value* pos,
46  llvm::Module* module) const {
47  auto& context = getGlobalLLVMContext();
48  auto f = module->getFunction("fixed_width_unsigned_decode");
49  CHECK(f);
50  llvm::Value* args[] = {
51  byte_stream,
52  llvm::ConstantInt::get(llvm::Type::getInt32Ty(context), byte_width_),
53  pos};
54  return llvm::CallInst::Create(f, args);
55 }
56 
57 DiffFixedWidthInt::DiffFixedWidthInt(const size_t byte_width, const int64_t baseline)
58  : byte_width_{byte_width}, baseline_{baseline} {}
59 
60 llvm::Instruction* DiffFixedWidthInt::codegenDecode(llvm::Value* byte_stream,
61  llvm::Value* pos,
62  llvm::Module* module) const {
63  auto& context = getGlobalLLVMContext();
64  auto f = module->getFunction("diff_fixed_width_int_decode");
65  CHECK(f);
66  llvm::Value* args[] = {
67  byte_stream,
68  llvm::ConstantInt::get(llvm::Type::getInt32Ty(context), byte_width_),
69  llvm::ConstantInt::get(llvm::Type::getInt32Ty(context), baseline_),
70  pos};
71  return llvm::CallInst::Create(f, args);
72 }
73 
74 FixedWidthReal::FixedWidthReal(const bool is_double) : is_double_(is_double) {}
75 
76 llvm::Instruction* FixedWidthReal::codegenDecode(llvm::Value* byte_stream,
77  llvm::Value* pos,
78  llvm::Module* module) const {
79  auto f = module->getFunction(is_double_ ? "fixed_width_double_decode"
80  : "fixed_width_float_decode");
81  CHECK(f);
82  llvm::Value* args[] = {byte_stream, pos};
83  return llvm::CallInst::Create(f, args);
84 }
85 
87  : byte_width_{byte_width}, null_val_{byte_width == 4 ? NULL_INT : NULL_SMALLINT} {}
88 
89 llvm::Instruction* FixedWidthSmallDate::codegenDecode(llvm::Value* byte_stream,
90  llvm::Value* pos,
91  llvm::Module* module) const {
92  auto& context = getGlobalLLVMContext();
93  auto f = module->getFunction("fixed_width_small_date_decode");
94  CHECK(f);
95  llvm::Value* args[] = {
96  byte_stream,
97  llvm::ConstantInt::get(llvm::Type::getInt32Ty(context), byte_width_),
98  llvm::ConstantInt::get(llvm::Type::getInt32Ty(context), null_val_),
99  llvm::ConstantInt::get(llvm::Type::getInt64Ty(context), ret_null_val_),
100  pos};
101  return llvm::CallInst::Create(f, args);
102 }
FixedWidthUnsigned(const size_t byte_width)
Definition: Codec.cpp:41
std::unique_ptr< llvm::Module > module(runtime_module_shallow_copy(cgen_state))
llvm::Instruction * codegenDecode(llvm::Value *byte_stream, llvm::Value *pos, llvm::Module *module) const override
Definition: Codec.cpp:76
const size_t byte_width_
Definition: Codec.h:42
llvm::Instruction * codegenDecode(llvm::Value *byte_stream, llvm::Value *pos, llvm::Module *module) const override
Definition: Codec.cpp:60
FixedWidthSmallDate(const size_t byte_width)
Definition: Codec.cpp:86
FixedWidthReal(const bool is_double)
Definition: Codec.cpp:74
DiffFixedWidthInt(const size_t byte_width, const int64_t baseline)
Definition: Codec.cpp:57
llvm::Instruction * codegenDecode(llvm::Value *byte_stream, llvm::Value *pos, llvm::Module *module) const override
Definition: Codec.cpp:28
CHECK(cgen_state)
FixedWidthInt(const size_t byte_width)
Definition: Codec.cpp:26
const int64_t baseline_
Definition: Codec.h:65
const int32_t null_val_
Definition: Codec.h:88
llvm::Instruction * codegenDecode(llvm::Value *byte_stream, llvm::Value *pos, llvm::Module *module) const override
Definition: Codec.cpp:44
llvm::Instruction * codegenDecode(llvm::Value *byte_stream, llvm::Value *pos, llvm::Module *module) const override
Definition: Codec.cpp:89
#define NULL_INT
Definition: sqltypes.h:176
const size_t byte_width_
Definition: Codec.h:53
const bool is_double_
Definition: Codec.h:76
static constexpr int64_t ret_null_val_
Definition: Codec.h:89
llvm::LLVMContext & getGlobalLLVMContext()
const size_t byte_width_
Definition: Codec.h:64
#define NULL_SMALLINT
Definition: sqltypes.h:175
const size_t byte_width_
Definition: Codec.h:87