Skip to content

Commit

Permalink
Optimize access of array member in a structure.
Browse files Browse the repository at this point in the history
  • Loading branch information
shwqf committed Dec 25, 2022
1 parent 2b3f986 commit 3d118ea
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 20 deletions.
1 change: 0 additions & 1 deletion src/codegen/llvm.zig
Expand Up @@ -5868,7 +5868,6 @@ pub const FuncGen = struct {
.struct_field_ptr, .struct_field_ptr_index_0, .struct_field_ptr_index_1, .struct_field_ptr_index_2, .struct_field_ptr_index_3 => {
const load_ptr_inst = try self.resolveInst(load_ptr);
const gep = self.builder.buildInBoundsGEP(array_llvm_ty, load_ptr_inst, &indices, indices.len, "");
array_llvm_val.removeUnusedLoadArray();
return self.builder.buildLoad(elem_llvm_ty, gep, "");
},
else => {},
Expand Down
3 changes: 0 additions & 3 deletions src/codegen/llvm/bindings.zig
Expand Up @@ -256,9 +256,6 @@ pub const Value = opaque {

pub const addByValAttr = ZigLLVMAddByValAttr;
extern fn ZigLLVMAddByValAttr(Fn: *Value, ArgNo: c_uint, type: *Type) void;

pub const removeUnusedLoadArray = ZigLLVMRemoveUnusedLoadArray;
extern fn ZigLLVMRemoveUnusedLoadArray(Val: *Value) void;
};

pub const Type = opaque {
Expand Down
14 changes: 0 additions & 14 deletions src/zig_llvm.cpp
Expand Up @@ -186,20 +186,6 @@ unsigned ZigLLVMDataLayoutGetProgramAddressSpace(LLVMTargetDataRef TD) {
return unwrap(TD)->getProgramAddressSpace();
}

void ZigLLVMRemoveUnusedLoadArray(LLVMValueRef Val) {
auto *Ptr = unwrap(Val);
if (auto *AI = dyn_cast<AllocaInst>(Ptr)) {
if (AI->hasOneUse()) {
if (auto *CI = dyn_cast<CallInst>(AI->user_back())) {
if (CI->getIntrinsicID() == Intrinsic::memcpy) {
CI->eraseFromParent();
AI->eraseFromParent();
}
}
}
}
}

namespace {
// LLVM's time profiler can provide a hierarchy view of the time spent
// in each component. It generates JSON report in Chrome's "Trace Event"
Expand Down
2 changes: 0 additions & 2 deletions src/zig_llvm.h
Expand Up @@ -599,6 +599,4 @@ ZIG_EXTERN_C void ZigLLVMGetNativeTarget(enum ZigLLVM_ArchType *arch_type,
ZIG_EXTERN_C unsigned ZigLLVMDataLayoutGetStackAlignment(LLVMTargetDataRef TD);
ZIG_EXTERN_C unsigned ZigLLVMDataLayoutGetProgramAddressSpace(LLVMTargetDataRef TD);

ZIG_EXTERN_C void ZigLLVMRemoveUnusedLoadArray(LLVMValueRef Val);

#endif

0 comments on commit 3d118ea

Please sign in to comment.