OmniSciDB  c1a53651b2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
anonymous_namespace{GpuSharedMemoryUtils.cpp} Namespace Reference

Functions

llvm::Value * codegen_smem_dest_slot_ptr (llvm::LLVMContext &context, const QueryMemoryDescriptor &query_mem_desc, llvm::IRBuilder<> &ir_builder, const size_t slot_idx, const TargetInfo &target_info, llvm::Value *dest_byte_stream, llvm::Value *byte_offset)
 
void replace_called_function_with (llvm::Function *main_func, const std::string &target_func_name, llvm::Function *replace_func)
 

Function Documentation

llvm::Value* anonymous_namespace{GpuSharedMemoryUtils.cpp}::codegen_smem_dest_slot_ptr ( llvm::LLVMContext &  context,
const QueryMemoryDescriptor query_mem_desc,
llvm::IRBuilder<> &  ir_builder,
const size_t  slot_idx,
const TargetInfo target_info,
llvm::Value *  dest_byte_stream,
llvm::Value *  byte_offset 
)

Definition at line 216 of file GpuSharedMemoryUtils.cpp.

References CHECK, get_compact_type(), QueryMemoryDescriptor::getPaddedSlotWidthBytes(), to_string(), and UNREACHABLE.

Referenced by GpuSharedMemCodeBuilder::codegenInitialization().

222  {
223  const auto sql_type = get_compact_type(target_info);
224  const auto slot_bytes = query_mem_desc.getPaddedSlotWidthBytes(slot_idx);
225  auto ptr_type = [&context](const size_t slot_bytes, const SQLTypeInfo& sql_type) {
226  if (slot_bytes == sizeof(int32_t)) {
227  return llvm::Type::getInt32PtrTy(context, /*address_space=*/3);
228  } else {
229  CHECK(slot_bytes == sizeof(int64_t));
230  return llvm::Type::getInt64PtrTy(context, /*address_space=*/3);
231  }
232  UNREACHABLE() << "Invalid slot size encountered: " << std::to_string(slot_bytes);
233  return llvm::Type::getInt32PtrTy(context, /*address_space=*/3);
234  };
235 
236  const auto casted_dest_slot_address = ir_builder.CreatePointerCast(
237  ir_builder.CreateGEP(
238  dest_byte_stream->getType()->getScalarType()->getPointerElementType(),
239  dest_byte_stream,
240  byte_offset),
241  ptr_type(slot_bytes, sql_type),
242  "dest_slot_adr_" + std::to_string(slot_idx));
243  return casted_dest_slot_address;
244 }
#define UNREACHABLE()
Definition: Logger.h:337
std::string to_string(char const *&&v)
const SQLTypeInfo get_compact_type(const TargetInfo &target)
const int8_t getPaddedSlotWidthBytes(const size_t slot_idx) const
#define CHECK(condition)
Definition: Logger.h:291

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void anonymous_namespace{GpuSharedMemoryUtils.cpp}::replace_called_function_with ( llvm::Function *  main_func,
const std::string &  target_func_name,
llvm::Function *  replace_func 
)

searches through the main function for the first appearance of called function "target_func_name", and if found it replaces it with replace_func while keeping the same arguments

Definition at line 375 of file GpuSharedMemoryUtils.cpp.

References run_benchmark_import::args, and UNREACHABLE.

Referenced by GpuSharedMemCodeBuilder::injectFunctionsInto().

377  {
378  for (auto it = llvm::inst_begin(main_func), e = llvm::inst_end(main_func); it != e;
379  ++it) {
380  if (!llvm::isa<llvm::CallInst>(*it)) {
381  continue;
382  }
383  auto& instruction = llvm::cast<llvm::CallInst>(*it);
384  if (std::string(instruction.getCalledFunction()->getName()) == target_func_name) {
385  std::vector<llvm::Value*> args;
386  for (size_t i = 0; i < instruction.getNumOperands() - 1; ++i) {
387  args.push_back(instruction.getArgOperand(i));
388  }
389  llvm::ReplaceInstWithInst(&instruction,
390  llvm::CallInst::Create(replace_func, args, ""));
391  return;
392  }
393  }
394  UNREACHABLE() << "Target function " << target_func_name << " was not found in "
395  << replace_func->getName().str();
396 }
#define UNREACHABLE()
Definition: Logger.h:337

+ Here is the caller graph for this function: