OmniSciDB  72c90bc290
 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 220 of file GpuSharedMemoryUtils.cpp.

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

Referenced by GpuSharedMemCodeBuilder::codegenInitialization().

226  {
227  const auto sql_type = get_compact_type(target_info);
228  const auto slot_bytes = query_mem_desc.getPaddedSlotWidthBytes(slot_idx);
229  auto ptr_type = [&context](const size_t slot_bytes, const SQLTypeInfo& sql_type) {
230  if (slot_bytes == sizeof(int32_t)) {
231  return llvm::Type::getInt32PtrTy(context, /*address_space=*/3);
232  } else {
233  CHECK(slot_bytes == sizeof(int64_t));
234  return llvm::Type::getInt64PtrTy(context, /*address_space=*/3);
235  }
236  UNREACHABLE() << "Invalid slot size encountered: " << std::to_string(slot_bytes);
237  return llvm::Type::getInt32PtrTy(context, /*address_space=*/3);
238  };
239 
240  const auto casted_dest_slot_address = ir_builder.CreatePointerCast(
241  ir_builder.CreateGEP(
242  dest_byte_stream->getType()->getScalarType()->getPointerElementType(),
243  dest_byte_stream,
244  byte_offset),
245  ptr_type(slot_bytes, sql_type),
246  "dest_slot_adr_" + std::to_string(slot_idx));
247  return casted_dest_slot_address;
248 }
#define UNREACHABLE()
Definition: Logger.h:338
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 379 of file GpuSharedMemoryUtils.cpp.

References run_benchmark_import::args, CodegenUtil::getCalledFunctionName(), and UNREACHABLE.

Referenced by GpuSharedMemCodeBuilder::injectFunctionsInto().

381  {
382  for (auto it = llvm::inst_begin(main_func), e = llvm::inst_end(main_func); it != e;
383  ++it) {
384  if (!llvm::isa<llvm::CallInst>(*it)) {
385  continue;
386  }
387  auto& instruction = llvm::cast<llvm::CallInst>(*it);
388  auto const inst_func_name = CodegenUtil::getCalledFunctionName(instruction);
389  if (inst_func_name && *inst_func_name == target_func_name) {
390  std::vector<llvm::Value*> args;
391  for (size_t i = 0; i < instruction.getNumOperands() - 1; ++i) {
392  args.push_back(instruction.getArgOperand(i));
393  }
394  llvm::ReplaceInstWithInst(&instruction,
395  llvm::CallInst::Create(replace_func, args, ""));
396  return;
397  }
398  }
399  UNREACHABLE() << "Target function " << target_func_name << " was not found in "
400  << replace_func->getName().str();
401 }
std::optional< std::string_view > getCalledFunctionName(llvm::CallInst &call_inst)
#define UNREACHABLE()
Definition: Logger.h:338

+ Here is the call graph for this function:

+ Here is the caller graph for this function: