OmniSciDB  1dac507f6e
 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:185
#define UNREACHABLE()
Definition: Logger.h:234
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 348 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().

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