OmniSciDB  04ee39c94c
IRCodegenUtils.h File Reference
#include <llvm/IR/Constants.h>
#include <llvm/IR/LLVMContext.h>
#include <llvm/IR/Type.h>
#include "Shared/Logger.h"
+ Include dependency graph for IRCodegenUtils.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

llvm::ArrayType * get_int_array_type (int const width, int count, llvm::LLVMContext &context)
 
llvm::VectorType * get_int_vector_type (int const width, int count, llvm::LLVMContext &context)
 
llvm::Type * get_int_type (const int width, llvm::LLVMContext &context)
 
llvm::Type * get_fp_type (const int width, llvm::LLVMContext &context)
 
template<class T >
llvm::ConstantInt * ll_int (const T v, llvm::LLVMContext &context)
 
llvm::ConstantInt * ll_bool (const bool v, llvm::LLVMContext &context)
 
llvm::Module * read_template_module (llvm::LLVMContext &context)
 
template<class T >
std::string serialize_llvm_object (const T *llvm_obj)
 
void verify_function_ir (const llvm::Function *func)
 

Function Documentation

◆ get_fp_type()

llvm::Type* get_fp_type ( const int  width,
llvm::LLVMContext &  context 
)
inline

Definition at line 95 of file IRCodegenUtils.h.

References logger::FATAL, LOG, and UNREACHABLE.

Referenced by CodeGenerator::endArgsNullcheck().

95  {
96  switch (width) {
97  case 64:
98  return llvm::Type::getDoubleTy(context);
99  case 32:
100  return llvm::Type::getFloatTy(context);
101  default:
102  LOG(FATAL) << "Unsupported floating point width: " << width;
103  }
104  UNREACHABLE();
105  return nullptr;
106 }
#define LOG(tag)
Definition: Logger.h:182
#define UNREACHABLE()
Definition: Logger.h:231
+ Here is the caller graph for this function:

◆ get_int_array_type()

llvm::ArrayType* get_int_array_type ( int const  width,
int  count,
llvm::LLVMContext &  context 
)
inline

Definition at line 24 of file IRCodegenUtils.h.

References logger::FATAL, and LOG.

Referenced by CodeGenerator::codegenArrayExpr(), and CodeGenerator::codegenCast().

26  {
27  switch (width) {
28  case 64:
29  return llvm::ArrayType::get(llvm::Type::getInt64Ty(context), count);
30  case 32:
31  return llvm::ArrayType::get(llvm::Type::getInt32Ty(context), count);
32  break;
33  case 16:
34  return llvm::ArrayType::get(llvm::Type::getInt16Ty(context), count);
35  break;
36  case 8:
37  return llvm::ArrayType::get(llvm::Type::getInt8Ty(context), count);
38  break;
39  case 1:
40  return llvm::ArrayType::get(llvm::Type::getInt1Ty(context), count);
41  break;
42  default:
43  LOG(FATAL) << "Unsupported integer width: " << width;
44  }
45  return nullptr;
46 }
#define LOG(tag)
Definition: Logger.h:182
+ Here is the caller graph for this function:

◆ get_int_type()

llvm::Type* get_int_type ( const int  width,
llvm::LLVMContext &  context 
)
inline

Definition at line 72 of file IRCodegenUtils.h.

References logger::FATAL, LOG, and UNREACHABLE.

Referenced by CgenState::addStringConstant(), Executor::aggregateWindowStatePtr(), Executor::castToIntPtrTyIn(), CgenState::castToTypeIn(), TargetExprCodegen::codegen(), JoinLoop::codegen(), GroupByAndAggregate::codegen(), CodeGenerator::codegen(), GroupByAndAggregate::codegenAggArg(), GroupByAndAggregate::codegenAggColumnPtr(), Executor::codegenAggregateWindowState(), CodeGenerator::codegenArrayAt(), CodeGenerator::codegenArrayExpr(), CodeGenerator::codegenCastBetweenIntTypes(), CodeGenerator::codegenCastBetweenIntTypesOverflowChecks(), CodeGenerator::codegenCastBetweenTimestamps(), CodeGenerator::codegenCastFromFp(), CodeGenerator::codegenCastFromString(), CodeGenerator::codegenCastTimestampToDate(), GroupByAndAggregate::codegenCountDistinct(), CodeGenerator::codegenDateTruncHighPrecisionTimestamps(), CodeGenerator::codegenDiv(), GroupByAndAggregate::codegenEstimator(), CodeGenerator::codegenFixedLengthColVar(), CodeGenerator::codegenFunctionOperCastArgs(), CodeGenerator::codegenFunctionOperWithCustomTypeHandling(), CodeGenerator::codegenHoistedConstantsLoads(), CodeGenerator::codegenIsNull(), OverlapsJoinHashTable::codegenKey(), BaselineJoinHashTable::codegenKey(), BaselineJoinHashTable::codegenMatchingSet(), GroupByAndAggregate::codegenMultiColumnPerfectHash(), GroupByAndAggregate::codegenPerfectHashFunction(), CodeGenerator::codegenQualifierCmp(), BaselineJoinHashTable::codegenSlot(), TargetExprCodegenBuilder::codegenSlotEmptyKey(), CodeGenerator::codegenVariableLengthStringColVar(), Executor::codegenWindowAvgEpilogue(), Executor::codegenWindowFunctionAggregate(), Executor::codegenWindowFunctionStateInit(), GroupByAndAggregate::codegenWindowRowPointer(), CodeGenerator::codgenAdjustFixedEncNull(), ScalarCodeGenerator::compile(), anonymous_namespace{NativeCodegen.cpp}::create_row_function(), anonymous_namespace{ResultSetReductionJIT.cpp}::emit_read_int_from_buff(), CodeGenerator::endArgsNullcheck(), JoinLoop::evaluateOuterJoinCondition(), anonymous_namespace{ExtensionsIR.cpp}::ext_arg_type_to_llvm_type(), anonymous_namespace{ResultSetReductionJIT.cpp}::generate_loop_body(), GroupByAndAggregate::getAdditionalLiteral(), Executor::groupByColumnCodegen(), Executor::inlineHoistedLiterals(), ll_bool(), ll_int(), anonymous_namespace{ScalarCodeGenerator.cpp}::llvm_type_from_sql(), CodeGenerator::posArg(), ResultSetReductionJIT::reduceLoop(), ResultSetReductionJIT::reduceOneEntryBaselineIdx(), anonymous_namespace{ResultSetReductionJIT.cpp}::setup_is_empty_entry(), anonymous_namespace{ResultSetReductionJIT.cpp}::setup_reduce_loop(), anonymous_namespace{ResultSetReductionJIT.cpp}::setup_reduce_one_entry(), and anonymous_namespace{ResultSetReductionJIT.cpp}::setup_reduce_one_entry_idx().

72  {
73  switch (width) {
74  case 64:
75  return llvm::Type::getInt64Ty(context);
76  case 32:
77  return llvm::Type::getInt32Ty(context);
78  break;
79  case 16:
80  return llvm::Type::getInt16Ty(context);
81  break;
82  case 8:
83  return llvm::Type::getInt8Ty(context);
84  break;
85  case 1:
86  return llvm::Type::getInt1Ty(context);
87  break;
88  default:
89  LOG(FATAL) << "Unsupported integer width: " << width;
90  }
91  UNREACHABLE();
92  return nullptr;
93 }
#define LOG(tag)
Definition: Logger.h:182
#define UNREACHABLE()
Definition: Logger.h:231

◆ get_int_vector_type()

llvm::VectorType* get_int_vector_type ( int const  width,
int  count,
llvm::LLVMContext &  context 
)
inline

Definition at line 48 of file IRCodegenUtils.h.

References logger::FATAL, and LOG.

50  {
51  switch (width) {
52  case 64:
53  return llvm::VectorType::get(llvm::Type::getInt64Ty(context), count);
54  case 32:
55  return llvm::VectorType::get(llvm::Type::getInt32Ty(context), count);
56  break;
57  case 16:
58  return llvm::VectorType::get(llvm::Type::getInt16Ty(context), count);
59  break;
60  case 8:
61  return llvm::VectorType::get(llvm::Type::getInt8Ty(context), count);
62  break;
63  case 1:
64  return llvm::VectorType::get(llvm::Type::getInt1Ty(context), count);
65  break;
66  default:
67  LOG(FATAL) << "Unsupported integer width: " << width;
68  }
69  return nullptr;
70 }
#define LOG(tag)
Definition: Logger.h:182

◆ ll_bool()

llvm::ConstantInt* ll_bool ( const bool  v,
llvm::LLVMContext &  context 
)
inline

Definition at line 114 of file IRCodegenUtils.h.

References get_int_type(), read_template_module(), serialize_llvm_object(), and verify_function_ir().

Referenced by JoinLoop::codegen(), JoinLoop::evaluateOuterJoinCondition(), and CgenState::llBool().

114  {
115  return static_cast<llvm::ConstantInt*>(
116  llvm::ConstantInt::get(get_int_type(1, context), v));
117 }
llvm::Type * get_int_type(const int width, llvm::LLVMContext &context)
T v(const TargetValue &r)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ll_int()

template<class T >
llvm::ConstantInt* ll_int ( const T  v,
llvm::LLVMContext &  context 
)
inline

Definition at line 109 of file IRCodegenUtils.h.

References get_int_type().

Referenced by JoinLoop::codegen(), anonymous_namespace{JoinLoopTest.cpp}::generate_descriptors(), CgenState::inlineIntMaxMin(), and CgenState::llInt().

109  {
110  return static_cast<llvm::ConstantInt*>(
111  llvm::ConstantInt::get(get_int_type(sizeof(v) * 8, context), v));
112 }
llvm::Type * get_int_type(const int width, llvm::LLVMContext &context)
T v(const TargetValue &r)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ read_template_module()

llvm::Module* read_template_module ( llvm::LLVMContext &  context)

Definition at line 888 of file NativeCodegen.cpp.

References CHECK, and mapd_root_abs_path().

Referenced by anonymous_namespace{NativeCodegen.cpp}::get_agg_fnames(), ll_bool(), and TEST().

888  {
889  llvm::SMDiagnostic err;
890 
891  auto buffer_or_error = llvm::MemoryBuffer::getFile(mapd_root_abs_path() +
892  "/QueryEngine/RuntimeFunctions.bc");
893  CHECK(!buffer_or_error.getError());
894  llvm::MemoryBuffer* buffer = buffer_or_error.get().get();
895 
896  auto owner = llvm::parseBitcodeFile(buffer->getMemBufferRef(), context);
897  CHECK(!owner.takeError());
898  auto module = owner.get().release();
899  CHECK(module);
900 
901  return module;
902 }
std::string mapd_root_abs_path()
Definition: mapdpath.h:30
#define CHECK(condition)
Definition: Logger.h:187
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ serialize_llvm_object()

template<class T >
std::string serialize_llvm_object ( const T *  llvm_obj)

Definition at line 128 of file NativeCodegen.cpp.

Referenced by Executor::compileWorkUnit(), ResultSetReductionJIT::finalizeReductionCode(), ll_bool(), Executor::optimizeAndCodegenCPU(), and Executor::optimizeAndCodegenGPU().

128  {
129  std::stringstream ss;
130  llvm::raw_os_ostream os(ss);
131  llvm_obj->print(os);
132  os.flush();
133  return ss.str();
134 }
+ Here is the caller graph for this function:

◆ verify_function_ir()

void verify_function_ir ( const llvm::Function *  func)

Definition at line 44 of file JoinLoopTest.cpp.

References logger::FATAL, and LOG.

Referenced by Executor::compileWorkUnit(), anonymous_namespace{JoinLoopTest.cpp}::create_loop_test_function(), ResultSetReductionJIT::isEmpty(), ll_bool(), ResultSetReductionJIT::reduceLoop(), ResultSetReductionJIT::reduceOneEntryBaseline(), ResultSetReductionJIT::reduceOneEntryBaselineIdx(), ResultSetReductionJIT::reduceOneEntryNoCollisions(), ResultSetReductionJIT::reduceOneEntryNoCollisionsIdx(), ResultSetReductionJIT::reduceOneEntryTargetsNoCollisions(), and TEST().

44  {
45  std::stringstream err_ss;
46  llvm::raw_os_ostream err_os(err_ss);
47  if (llvm::verifyFunction(*func, &err_os)) {
48  func->print(llvm::outs());
49  LOG(FATAL) << err_ss.str();
50  }
51 }
#define LOG(tag)
Definition: Logger.h:182
+ Here is the caller graph for this function: