Skip to content

Commit

Permalink
move load of safepoint_page outside fence
Browse files Browse the repository at this point in the history
  • Loading branch information
vchuravy committed Dec 28, 2022
1 parent 27dfa53 commit 3ef7a67
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
9 changes: 5 additions & 4 deletions src/codegen_shared.h
Original file line number Diff line number Diff line change
Expand Up @@ -237,19 +237,20 @@ static inline void emit_signal_fence(llvm::IRBuilder<> &builder)
static inline void emit_gc_safepoint(llvm::IRBuilder<> &builder, llvm::Value *ptls, llvm::MDNode *tbaa)
{
using namespace llvm;
llvm::Value *signal_page = get_current_signal_page_from_ptls(builder, ptls, tbaa);
emit_signal_fence(builder);
Module *M = builder.GetInsertBlock()->getModule();
LLVMContext &C = builder.getContext();
// inline jlsafepoint_func->realize(M)
Function *F = M->getFunction("julia.safepoint");
if (!F) {
auto T_ppjlvalue = JuliaType::get_ppjlvalue_ty(builder.getContext());
FunctionType *FT = FunctionType::get(Type::getVoidTy(C), {T_ppjlvalue}, false);
auto T_size = getSizeTy(builder.getContext());
auto T_psize = T_size->getPointerTo();
FunctionType *FT = FunctionType::get(Type::getVoidTy(C), {T_psize}, false);
F = Function::Create(FT, Function::ExternalLinkage, "julia.safepoint", M);
F->addFnAttr(Attribute::InaccessibleMemOrArgMemOnly);
}

builder.CreateCall(F, {ptls});
builder.CreateCall(F, {signal_page});
emit_signal_fence(builder);
}

Expand Down
6 changes: 4 additions & 2 deletions src/llvm-final-gc-lowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,9 @@ Value *FinalLowerGC::lowerSafepoint(CallInst *target, Function &F)
assert(target->arg_size() == 1);
IRBuilder<> builder(target->getContext());
builder.SetInsertPoint(target);
Value* ptls = target->getOperand(0);
Value* load = builder.CreateLoad(getSizeTy(builder.getContext()), get_current_signal_page_from_ptls(builder, ptls, nullptr), true);
auto T_size = getSizeTy(builder.getContext());
Value* signal_page = target->getOperand(0);
Value* load = builder.CreateLoad(T_size, signal_page, true);
return load;
}

Expand Down Expand Up @@ -333,6 +334,7 @@ bool FinalLowerGC::runOnFunction(Function &F)
}

Value *callee = CI->getCalledOperand();
assert(callee);

if (callee == newGCFrameFunc) {
replaceInstruction(CI, lowerNewGCFrame(CI, F), it);
Expand Down
4 changes: 3 additions & 1 deletion src/llvm-pass-helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,12 @@ namespace jl_intrinsics {
const IntrinsicDescription safepoint(
SAFEPOINT_NAME,
[](const JuliaPassContext &context) {
auto T_size = getSizeTy(context.getLLVMContext());
auto T_psize = T_size->getPointerTo();
auto intrinsic = Function::Create(
FunctionType::get(
Type::getVoidTy(context.getLLVMContext()),
{JuliaType::get_ppjlvalue_ty(context.getLLVMContext())},
{T_psize},
false),
Function::ExternalLinkage,
SAFEPOINT_NAME);
Expand Down

0 comments on commit 3ef7a67

Please sign in to comment.