diff --git a/taichi/codegen/codegen_llvm.cpp b/taichi/codegen/codegen_llvm.cpp index 5dd24f975d985..e18a76591a260 100644 --- a/taichi/codegen/codegen_llvm.cpp +++ b/taichi/codegen/codegen_llvm.cpp @@ -1541,6 +1541,22 @@ llvm::Value *CodeGenLLVM::offset_bit_ptr(llvm::Value *input_bit_ptr, return create_bit_ptr_struct(byte_ptr_base, new_bit_offset); } +std::tuple CodeGenLLVM::load_bit_pointer( + llvm::Value *ptr) { + // 1. load byte pointer + auto byte_ptr_in_bit_struct = + builder->CreateGEP(ptr, {tlctx->get_constant(0), tlctx->get_constant(0)}); + auto byte_ptr = builder->CreateLoad(byte_ptr_in_bit_struct); + TI_ASSERT(byte_ptr->getType()->getPointerElementType()->isIntegerTy(8)); + + // 2. load bit offset + auto bit_offset_in_bit_struct = + builder->CreateGEP(ptr, {tlctx->get_constant(0), tlctx->get_constant(1)}); + auto bit_offset = builder->CreateLoad(bit_offset_in_bit_struct); + TI_ASSERT(bit_offset->getType()->isIntegerTy(32)); + return std::make_tuple(byte_ptr, bit_offset); +} + void CodeGenLLVM::visit(SNodeLookupStmt *stmt) { llvm::Value *parent = nullptr; parent = llvm_val[stmt->input_snode]; diff --git a/taichi/codegen/codegen_llvm.h b/taichi/codegen/codegen_llvm.h index 9252e78a0d769..5cbe35cd4ea9e 100644 --- a/taichi/codegen/codegen_llvm.h +++ b/taichi/codegen/codegen_llvm.h @@ -317,6 +317,8 @@ class CodeGenLLVM : public IRVisitor, public LLVMModuleBuilder { llvm::Value *offset_bit_ptr(llvm::Value *input_bit_ptr, int bit_offset_delta); + std::tuple load_bit_pointer(llvm::Value *ptr); + void visit(SNodeLookupStmt *stmt) override; void visit(GetChStmt *stmt) override; diff --git a/taichi/llvm/llvm_codegen_utils.h b/taichi/llvm/llvm_codegen_utils.h index 17ae948854a00..073d35521f8c5 100644 --- a/taichi/llvm/llvm_codegen_utils.h +++ b/taichi/llvm/llvm_codegen_utils.h @@ -124,21 +124,6 @@ class LLVMModuleBuilder { llvm::Value *call(const std::string &func_name, Args &&...args) { return call(this->builder.get(), func_name, std::forward(args)...); } - - std::tuple load_bit_pointer(llvm::Value *ptr) { - // 1. load byte pointer - auto byte_ptr_in_bit_struct = builder->CreateGEP( - ptr, {tlctx->get_constant(0), tlctx->get_constant(0)}); - auto byte_ptr = builder->CreateLoad(byte_ptr_in_bit_struct); - TI_ASSERT(byte_ptr->getType()->getPointerElementType()->isIntegerTy(8)); - - // 2. load bit offset - auto bit_offset_in_bit_struct = builder->CreateGEP( - ptr, {tlctx->get_constant(0), tlctx->get_constant(1)}); - auto bit_offset = builder->CreateLoad(bit_offset_in_bit_struct); - TI_ASSERT(bit_offset->getType()->isIntegerTy(32)); - return std::make_tuple(byte_ptr, bit_offset); - } }; class RuntimeObject {