OmniSciDB  2e3a973ef4
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

◆ codegen_smem_dest_slot_ptr()

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 209 of file GpuSharedMemoryUtils.cpp.

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

Referenced by GpuSharedMemCodeBuilder::codegenInitialization().

215  {
216  const auto sql_type = get_compact_type(target_info);
217  const auto slot_bytes = query_mem_desc.getPaddedSlotWidthBytes(slot_idx);
218  auto ptr_type = [&context](const size_t slot_bytes, const SQLTypeInfo& sql_type) {
219  if (slot_bytes == sizeof(int32_t)) {
220  return llvm::Type::getInt32PtrTy(context, /*address_space=*/3);
221  } else {
222  CHECK(slot_bytes == sizeof(int64_t));
223  return llvm::Type::getInt64PtrTy(context, /*address_space=*/3);
224  }
225  UNREACHABLE() << "Invalid slot size encountered: " << std::to_string(slot_bytes);
226  return llvm::Type::getInt32PtrTy(context, /*address_space=*/3);
227  };
228 
229  const auto casted_dest_slot_address =
230  ir_builder.CreatePointerCast(ir_builder.CreateGEP(dest_byte_stream, byte_offset),
231  ptr_type(slot_bytes, sql_type),
232  "dest_slot_adr_" + std::to_string(slot_idx));
233  return casted_dest_slot_address;
234 }
#define UNREACHABLE()
Definition: Logger.h:241
std::string to_string(char const *&&v)
const int8_t getPaddedSlotWidthBytes(const size_t slot_idx) const
const SQLTypeInfo get_compact_type(const TargetInfo &target)
#define CHECK(condition)
Definition: Logger.h:197
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ replace_called_function_with()

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 365 of file GpuSharedMemoryUtils.cpp.

References run_benchmark_import::args, and UNREACHABLE.

Referenced by GpuSharedMemCodeBuilder::injectFunctionsInto().

367  {
368  for (auto it = llvm::inst_begin(main_func), e = llvm::inst_end(main_func); it != e;
369  ++it) {
370  if (!llvm::isa<llvm::CallInst>(*it)) {
371  continue;
372  }
373  auto& instruction = llvm::cast<llvm::CallInst>(*it);
374  if (std::string(instruction.getCalledFunction()->getName()) == target_func_name) {
375  std::vector<llvm::Value*> args;
376  for (size_t i = 0; i < instruction.getNumArgOperands(); ++i) {
377  args.push_back(instruction.getArgOperand(i));
378  }
379  llvm::ReplaceInstWithInst(&instruction,
380  llvm::CallInst::Create(replace_func, args, ""));
381  return;
382  }
383  }
384  UNREACHABLE() << "Target function " << target_func_name << " was not found in "
385  << replace_func->getName().str();
386 }
#define UNREACHABLE()
Definition: Logger.h:241
+ Here is the caller graph for this function: