OmniSciDB  addbbd5075
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ResultSetReductionCodegen.h File Reference
#include "ResultSetReductionJIT.h"
#include "ResultSetReductionOps.h"
#include <llvm/IR/LLVMContext.h>
#include <llvm/IR/Type.h>
+ Include dependency graph for ResultSetReductionCodegen.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

llvm::Typellvm_type (const Type type, llvm::LLVMContext &ctx)
 
void translate_function (const Function *function, llvm::Function *llvm_function, const ReductionCode &reduction_code, const std::unordered_map< const Function *, llvm::Function * > &f)
 

Function Documentation

llvm::Type* llvm_type ( const Type  type,
llvm::LLVMContext &  ctx 
)

Definition at line 26 of file ResultSetReductionCodegen.cpp.

References Double, DoublePtr, logger::FATAL, Float, FloatPtr, get_fp_type(), get_int_type(), Int1, Int32, Int32Ptr, Int64, Int64Ptr, Int64PtrPtr, Int8, Int8Ptr, LOG, run_benchmark_import::type, UNREACHABLE, Void, and VoidPtr.

Referenced by anonymous_namespace{ResultSetReductionJIT.cpp}::create_llvm_function(), StubGenerator::generateStub(), and anonymous_namespace{ResultSetReductionCodegen.cpp}::translate_body().

26  {
27  switch (type) {
28  case Type::Int1: {
29  return get_int_type(1, ctx);
30  }
31  case Type::Int8: {
32  return get_int_type(8, ctx);
33  }
34  case Type::Int32: {
35  return get_int_type(32, ctx);
36  }
37  case Type::Int64: {
38  return get_int_type(64, ctx);
39  }
40  case Type::Float: {
41  return get_fp_type(32, ctx);
42  }
43  case Type::Double: {
44  return get_fp_type(64, ctx);
45  }
46  case Type::Void: {
47  return llvm::Type::getVoidTy(ctx);
48  }
49  case Type::Int8Ptr: {
50  return llvm::PointerType::get(get_int_type(8, ctx), 0);
51  }
52  case Type::Int32Ptr: {
53  return llvm::PointerType::get(get_int_type(32, ctx), 0);
54  }
55  case Type::Int64Ptr: {
56  return llvm::PointerType::get(get_int_type(64, ctx), 0);
57  }
58  case Type::FloatPtr: {
59  return llvm::Type::getFloatPtrTy(ctx);
60  }
61  case Type::DoublePtr: {
62  return llvm::Type::getDoublePtrTy(ctx);
63  }
64  case Type::VoidPtr: {
65  return llvm::PointerType::get(get_int_type(8, ctx), 0);
66  }
67  case Type::Int64PtrPtr: {
68  return llvm::PointerType::get(llvm::PointerType::get(get_int_type(64, ctx), 0), 0);
69  }
70  default: {
71  LOG(FATAL) << "Argument type not supported: " << static_cast<int>(type);
72  break;
73  }
74  }
75  UNREACHABLE();
76  return nullptr;
77 }
#define LOG(tag)
Definition: Logger.h:188
#define UNREACHABLE()
Definition: Logger.h:237
llvm::Type * get_fp_type(const int width, llvm::LLVMContext &context)
llvm::Type * get_int_type(const int width, llvm::LLVMContext &context)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void translate_function ( const Function function,
llvm::Function *  llvm_function,
const ReductionCode reduction_code,
const std::unordered_map< const Function *, llvm::Function * > &  f 
)

Definition at line 355 of file ResultSetReductionCodegen.cpp.

References ReductionCode::cgen_state, cgen_state, CHECK(), anonymous_namespace{ResultSetReductionCodegen.cpp}::create_entry_block(), Double, logger::FATAL, Float, Int32, Int64, Int8, LOG, anonymous_namespace{ResultSetReductionCodegen.cpp}::translate_body(), and verify_function_ir().

Referenced by ResultSetReductionJIT::codegen().

358  {
359  auto cgen_state = reduction_code.cgen_state.get();
360  create_entry_block(llvm_function, cgen_state);
361  // Set the value mapping based on the input arguments.
362  std::unordered_map<const Value*, llvm::Value*> m;
363  auto llvm_arg_it = llvm_function->arg_begin();
364  for (size_t arg_idx = 0; arg_idx < function->arg_types().size(); ++arg_idx) {
365  llvm::Value* llvm_arg = &(*llvm_arg_it);
366  const auto it_ok = m.emplace(function->arg(arg_idx), llvm_arg);
367  CHECK(it_ok.second);
368  ++llvm_arg_it;
369  }
370  // Add mapping for the constants used by the function.
371  for (const auto& constant : function->constants()) {
372  llvm::Value* constant_llvm{nullptr};
373  switch (constant->type()) {
374  case Type::Int8: {
375  constant_llvm =
376  cgen_state->llInt<int8_t>(static_cast<ConstantInt*>(constant.get())->value());
377  break;
378  }
379  case Type::Int32: {
380  constant_llvm = cgen_state->llInt<int32_t>(
381  static_cast<ConstantInt*>(constant.get())->value());
382  break;
383  }
384  case Type::Int64: {
385  constant_llvm = cgen_state->llInt<int64_t>(
386  static_cast<ConstantInt*>(constant.get())->value());
387  break;
388  }
389  case Type::Float: {
390  constant_llvm = cgen_state->llFp(
391  static_cast<float>(static_cast<ConstantFP*>(constant.get())->value()));
392  break;
393  }
394  case Type::Double: {
395  constant_llvm =
396  cgen_state->llFp(static_cast<ConstantFP*>(constant.get())->value());
397  break;
398  }
399  default: {
400  LOG(FATAL) << "Constant type not supported: "
401  << static_cast<int>(constant->type());
402  }
403  }
404  CHECK(constant_llvm);
405  const auto it_ok = m.emplace(constant.get(), constant_llvm);
406  CHECK(it_ok.second);
407  }
408  translate_body(function->body(), function, llvm_function, reduction_code, m, f);
409  verify_function_ir(llvm_function);
410 }
std::unique_ptr< CgenState > cgen_state
void create_entry_block(llvm::Function *function, CgenState *cgen_state)
#define LOG(tag)
Definition: Logger.h:188
false auto cgen_state
void verify_function_ir(const llvm::Function *func)
CHECK(cgen_state)
void translate_body(const std::vector< std::unique_ptr< Instruction >> &body, const Function *function, llvm::Function *llvm_function, const ReductionCode &reduction_code, std::unordered_map< const Value *, llvm::Value * > &m, const std::unordered_map< const Function *, llvm::Function * > &f)

+ Here is the call graph for this function:

+ Here is the caller graph for this function: