Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add names to write barrier lowering #51000

Merged
merged 2 commits into from
Aug 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions src/llvm-late-gc-lowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2528,24 +2528,36 @@ bool LateLowerGCFrame::CleanupIR(Function &F, State *S, bool *CFGModified) {
if (CFGModified) {
*CFGModified = true;
}
auto DebugInfoMeta = F.getParent()->getModuleFlag("julia.debug_level");
int debug_info = 1;
if (DebugInfoMeta != nullptr) {
debug_info = cast<ConstantInt>(cast<ConstantAsMetadata>(DebugInfoMeta)->getValue())->getZExtValue();
}

IRBuilder<> builder(CI);
builder.SetCurrentDebugLocation(CI->getDebugLoc());
auto parBits = builder.CreateAnd(EmitLoadTag(builder, T_size, parent), 3);
auto parOldMarked = builder.CreateICmpEQ(parBits, ConstantInt::get(T_size, 3));
auto parBits = builder.CreateAnd(EmitLoadTag(builder, T_size, parent), GC_OLD_MARKED);
setName(parBits, "parent_bits", debug_info);
auto parOldMarked = builder.CreateICmpEQ(parBits, ConstantInt::get(T_size, GC_OLD_MARKED));
setName(parOldMarked, "parent_old_marked", debug_info);
auto mayTrigTerm = SplitBlockAndInsertIfThen(parOldMarked, CI, false);
builder.SetInsertPoint(mayTrigTerm);
setName(mayTrigTerm->getParent(), "may_trigger_wb", debug_info);
Value *anyChldNotMarked = NULL;
for (unsigned i = 1; i < CI->arg_size(); i++) {
Value *child = CI->getArgOperand(i);
Value *chldBit = builder.CreateAnd(EmitLoadTag(builder, T_size, child), 1);
Value *chldNotMarked = builder.CreateICmpEQ(chldBit, ConstantInt::get(T_size, 0));
Value *chldBit = builder.CreateAnd(EmitLoadTag(builder, T_size, child), GC_MARKED);
setName(chldBit, "child_bit", debug_info);
Value *chldNotMarked = builder.CreateICmpEQ(chldBit, ConstantInt::get(T_size, 0),"child_not_marked");
setName(chldNotMarked, "child_not_marked", debug_info);
anyChldNotMarked = anyChldNotMarked ? builder.CreateOr(anyChldNotMarked, chldNotMarked) : chldNotMarked;
}
assert(anyChldNotMarked); // handled by all_of test above
MDBuilder MDB(parent->getContext());
SmallVector<uint32_t, 2> Weights{1, 9};
auto trigTerm = SplitBlockAndInsertIfThen(anyChldNotMarked, mayTrigTerm, false,
MDB.createBranchWeights(Weights));
setName(trigTerm->getParent(), "trigger_wb", debug_info);
builder.SetInsertPoint(trigTerm);
if (CI->getCalledOperand() == write_barrier_func) {
builder.CreateCall(getOrDeclare(jl_intrinsics::queueGCRoot), parent);
Expand Down
7 changes: 7 additions & 0 deletions src/llvm-pass-helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,3 +311,10 @@ namespace jl_well_known {
return addGCAllocAttributes(allocTypedFunc);
});
}

void setName(llvm::Value *V, const llvm::Twine &Name, int debug_info)
{
if (debug_info >= 2 && !llvm::isa<llvm::Constant>(V)) {
V->setName(Name);
}
}
2 changes: 2 additions & 0 deletions src/llvm-pass-helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,6 @@ namespace jl_well_known {
extern const WellKnownFunctionDescription GCAllocTyped;
}

void setName(llvm::Value *V, const llvm::Twine &Name, int debug_info);

#endif
13 changes: 13 additions & 0 deletions test/llvmpasses/names.jl
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ function f7(a)
return a[2]
end

# COM: check write barrier names
mutable struct Barrier
b
end

# CHECK-LABEL: define {{(swiftcc )?}}double @julia_f1
# CHECK-SAME: double %"a::Float64"
# CHECK-SAME: double %"b::Float64"
Expand Down Expand Up @@ -173,3 +178,11 @@ emit(f6, E)
# CHECK-SAME: %"a::Tuple"
# CHECK: %"a::Tuple[2]_ptr.unbox
emit(f7,Tuple{Int,Int})

# CHECK: define {{(swiftcc )?}}nonnull {} addrspace(10)* @julia_Barrier
# CHECK-SAME: %"b::Int64"
# CHECK: %parent_bits
# CHECK: %parent_old_marked
# CHECK: %child_bit
# CHECK: %child_not_marked
emit(Barrier, Int64)