OmniSciDB  fe05a0c208
 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:194
#define UNREACHABLE()
Definition: Logger.h:247
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 360 of file ResultSetReductionCodegen.cpp.

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

Referenced by ResultSetReductionJIT::codegen(), and GpuReductionHelperJIT::codegen().

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

+ Here is the call graph for this function:

+ Here is the caller graph for this function: