OmniSciDB  c07336695a
CodeGeneratorTest.cpp File Reference
#include <gtest/gtest.h>
#include <llvm/Bitcode/BitcodeReader.h>
#include <llvm/IR/Function.h>
#include <llvm/IR/Module.h>
#include <llvm/IR/Verifier.h>
#include <llvm/Support/SourceMgr.h>
#include <llvm/Support/raw_os_ostream.h>
#include "../Analyzer/Analyzer.h"
#include "../QueryEngine/CodeGenerator.h"
#include "../QueryEngine/Execute.h"
#include "../QueryEngine/IRCodegenUtils.h"
#include "../QueryEngine/LLVMGlobalContext.h"
#include "../Shared/mapdpath.h"
#include "TestHelpers.h"
+ Include dependency graph for CodeGeneratorTest.cpp:

Go to the source code of this file.

Functions

 TEST (CodeGeneratorTest, IntegerConstant)
 
 TEST (CodeGeneratorTest, IntegerAdd)
 
 TEST (CodeGeneratorTest, IntegerColumn)
 
 TEST (CodeGeneratorTest, IntegerExpr)
 
int main (int argc, char **argv)
 

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 358 of file CodeGeneratorTest.cpp.

References TestHelpers::init_logger_stderr_only().

358  {
360  testing::InitGoogleTest(&argc, argv);
361  int err = RUN_ALL_TESTS();
362  return err;
363 }
void init_logger_stderr_only(int argc, char const *const *argv)
Definition: TestHelpers.h:194
+ Here is the call graph for this function:

◆ TEST() [1/4]

TEST ( CodeGeneratorTest  ,
IntegerConstant   
)

Definition at line 33 of file CodeGeneratorTest.cpp.

References CHECK, ScalarCodeGenerator::compile(), CPU, anonymous_namespace{ImportTest.cpp}::d(), Default, ScalarCodeGenerator::generateNativeCode(), getGlobalLLVMContext(), Datum::intval, kINT, out, read_template_module(), and verify_function_ir().

Referenced by TEST().

33  {
34  auto& ctx = getGlobalLLVMContext();
35  std::unique_ptr<llvm::Module> module(read_template_module(ctx));
36  ScalarCodeGenerator code_generator(std::move(module));
38 
39  Datum d;
40  d.intval = 42;
41  auto constant = makeExpr<Analyzer::Constant>(kINT, false, d);
42  const auto compiled_expr = code_generator.compile(constant.get(), true, co);
43  verify_function_ir(compiled_expr.func);
44  ASSERT_TRUE(compiled_expr.inputs.empty());
45 
46  using FuncPtr = int (*)(int*);
47  auto func_ptr = reinterpret_cast<FuncPtr>(
48  code_generator.generateNativeCode(compiled_expr, co).front());
49  CHECK(func_ptr);
50  int out;
51  int err = func_ptr(&out);
52  ASSERT_EQ(err, 0);
53  ASSERT_EQ(out, d.intval);
54 }
void d(const SQLTypes expected_type, const std::string &str)
Definition: ImportTest.cpp:268
int32_t intval
Definition: sqltypes.h:125
void verify_function_ir(const llvm::Function *func)
llvm::Module * read_template_module(llvm::LLVMContext &context)
llvm::LLVMContext & getGlobalLLVMContext()
#define CHECK(condition)
Definition: Logger.h:187
Definition: sqltypes.h:47
const int8_t const int64_t const uint64_t const int32_t const int64_t int64_t ** out
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ TEST() [2/4]

TEST ( CodeGeneratorTest  ,
IntegerAdd   
)

Definition at line 56 of file CodeGeneratorTest.cpp.

References CHECK, ScalarCodeGenerator::compile(), CPU, anonymous_namespace{ImportTest.cpp}::d(), Default, ScalarCodeGenerator::generateNativeCode(), getGlobalLLVMContext(), Datum::intval, kINT, kONE, kPLUS, out, read_template_module(), and verify_function_ir().

56  {
57  auto& ctx = getGlobalLLVMContext();
58  std::unique_ptr<llvm::Module> module(read_template_module(ctx));
59  ScalarCodeGenerator code_generator(std::move(module));
61 
62  Datum d;
63  d.intval = 42;
64  auto lhs = makeExpr<Analyzer::Constant>(kINT, false, d);
65  auto rhs = makeExpr<Analyzer::Constant>(kINT, false, d);
66  auto plus = makeExpr<Analyzer::BinOper>(kINT, kPLUS, kONE, lhs, rhs);
67  const auto compiled_expr = code_generator.compile(plus.get(), true, co);
68  verify_function_ir(compiled_expr.func);
69  ASSERT_TRUE(compiled_expr.inputs.empty());
70 
71  using FuncPtr = int (*)(int*);
72  auto func_ptr = reinterpret_cast<FuncPtr>(
73  code_generator.generateNativeCode(compiled_expr, co).front());
74  CHECK(func_ptr);
75  int out;
76  int err = func_ptr(&out);
77  ASSERT_EQ(err, 0);
78  ASSERT_EQ(out, d.intval + d.intval);
79 }
void d(const SQLTypes expected_type, const std::string &str)
Definition: ImportTest.cpp:268
Definition: sqldefs.h:41
int32_t intval
Definition: sqltypes.h:125
void verify_function_ir(const llvm::Function *func)
Definition: sqldefs.h:69
llvm::Module * read_template_module(llvm::LLVMContext &context)
llvm::LLVMContext & getGlobalLLVMContext()
#define CHECK(condition)
Definition: Logger.h:187
Definition: sqltypes.h:47
const int8_t const int64_t const uint64_t const int32_t const int64_t int64_t ** out
+ Here is the call graph for this function:

◆ TEST() [3/4]

TEST ( CodeGeneratorTest  ,
IntegerColumn   
)

Definition at line 81 of file CodeGeneratorTest.cpp.

References CHECK, ScalarCodeGenerator::compile(), CPU, Default, ScalarCodeGenerator::generateNativeCode(), getGlobalLLVMContext(), kINT, out, read_template_module(), and verify_function_ir().

81  {
82  auto& ctx = getGlobalLLVMContext();
83  std::unique_ptr<llvm::Module> module(read_template_module(ctx));
84  ScalarCodeGenerator code_generator(std::move(module));
86 
87  SQLTypeInfo ti(kINT, false);
88  int table_id = 1;
89  int column_id = 5;
90  int rte_idx = 0;
91  auto col = makeExpr<Analyzer::ColumnVar>(ti, table_id, column_id, rte_idx);
92  const auto compiled_expr = code_generator.compile(col.get(), true, co);
93  verify_function_ir(compiled_expr.func);
94  ASSERT_EQ(compiled_expr.inputs.size(), size_t(1));
95  ASSERT_TRUE(*compiled_expr.inputs.front() == *col);
96 
97  using FuncPtr = int (*)(int*, int);
98  auto func_ptr = reinterpret_cast<FuncPtr>(
99  code_generator.generateNativeCode(compiled_expr, co).front());
100  CHECK(func_ptr);
101  int out;
102  int err = func_ptr(&out, 17);
103  ASSERT_EQ(err, 0);
104  ASSERT_EQ(out, 17);
105 }
void verify_function_ir(const llvm::Function *func)
llvm::Module * read_template_module(llvm::LLVMContext &context)
llvm::LLVMContext & getGlobalLLVMContext()
#define CHECK(condition)
Definition: Logger.h:187
Definition: sqltypes.h:47
const int8_t const int64_t const uint64_t const int32_t const int64_t int64_t ** out
+ Here is the call graph for this function:

◆ TEST() [4/4]

TEST ( CodeGeneratorTest  ,
IntegerExpr   
)

Definition at line 107 of file CodeGeneratorTest.cpp.

References CudaMgr_Namespace::CudaMgr::allocateDeviceMem(), CHECK, ScalarCodeGenerator::compile(), CudaMgr_Namespace::CudaMgr::copyDeviceToHost(), CudaMgr_Namespace::CudaMgr::copyHostToDevice(), CPU, anonymous_namespace{ImportTest.cpp}::d(), Default, CudaMgr_Namespace::CudaMgr::freeDeviceMem(), ScalarCodeGenerator::generateNativeCode(), ScalarCodeGenerator::getCudaMgr(), getGlobalLLVMContext(), GPU, Datum::intval, kINT, kONE, kPLUS, out, read_template_module(), TEST(), and verify_function_ir().

107  {
108  auto& ctx = getGlobalLLVMContext();
109  std::unique_ptr<llvm::Module> module(read_template_module(ctx));
110  ScalarCodeGenerator code_generator(std::move(module));
112 
113  SQLTypeInfo ti(kINT, false);
114  int table_id = 1;
115  int column_id = 5;
116  int rte_idx = 0;
117  auto lhs = makeExpr<Analyzer::ColumnVar>(ti, table_id, column_id, rte_idx);
118  Datum d;
119  d.intval = 42;
120  auto rhs = makeExpr<Analyzer::Constant>(kINT, false, d);
121  auto plus = makeExpr<Analyzer::BinOper>(kINT, kPLUS, kONE, lhs, rhs);
122  const auto compiled_expr = code_generator.compile(plus.get(), true, co);
123  verify_function_ir(compiled_expr.func);
124  ASSERT_EQ(compiled_expr.inputs.size(), size_t(1));
125  ASSERT_TRUE(*compiled_expr.inputs.front() == *lhs);
126 
127  using FuncPtr = int (*)(int*, int);
128  auto func_ptr = reinterpret_cast<FuncPtr>(
129  code_generator.generateNativeCode(compiled_expr, co).front());
130  CHECK(func_ptr);
131  int out;
132  int err = func_ptr(&out, 58);
133  ASSERT_EQ(err, 0);
134  ASSERT_EQ(out, 100);
135 }
void d(const SQLTypes expected_type, const std::string &str)
Definition: ImportTest.cpp:268
Definition: sqldefs.h:41
void verify_function_ir(const llvm::Function *func)
Definition: sqldefs.h:69
llvm::Module * read_template_module(llvm::LLVMContext &context)
llvm::LLVMContext & getGlobalLLVMContext()
#define CHECK(condition)
Definition: Logger.h:187
Definition: sqltypes.h:47
const int8_t const int64_t const uint64_t const int32_t const int64_t int64_t ** out
+ Here is the call graph for this function: