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

Use gc alloc instead of alloc typed in lowering #48642

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions src/jl_exported_funcs.inc
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@
XX(jl_gc_add_finalizer_th) \
XX(jl_gc_add_ptr_finalizer) \
XX(jl_gc_add_quiescent) \
XX(jl_gc_alloc) \
Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@staticfloat @vtjnash any reason why this wasn't included before?

Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not especially, though we try to make the API larger than necessary (this is not in src/julia.h for example), they get named mangled which is mildly annoying for debugging, and it is only needed for external C clients, not sysimg linking (which already gets direct access to all of libjulia-internal)

XX(jl_gc_allocobj) \
XX(jl_gc_alloc_0w) \
XX(jl_gc_alloc_1w) \
Expand Down
12 changes: 6 additions & 6 deletions src/llvm-final-gc-lowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ struct FinalLowerGC: private JuliaPassContext {
Function *queueRootFunc;
Function *poolAllocFunc;
Function *bigAllocFunc;
Function *allocTypedFunc;
Function *allocFunc;
Instruction *pgcstack;

// Lowers a `julia.new_gc_frame` intrinsic.
Expand Down Expand Up @@ -236,7 +236,7 @@ Value *FinalLowerGC::lowerGCAllocBytes(CallInst *target, Function &F)
} else {
auto size = builder.CreateZExtOrTrunc(target->getArgOperand(1), getSizeTy(F.getContext()));
size = builder.CreateAdd(size, ConstantInt::get(getSizeTy(F.getContext()), sizeof(void*)));
newI = builder.CreateCall(allocTypedFunc, { ptls, size, ConstantPointerNull::get(Type::getInt8PtrTy(F.getContext())) });
newI = builder.CreateCall(allocFunc, { ptls, size, ConstantPointerNull::get(Type::getInt8PtrTy(F.getContext())) });
derefAttr = Attribute::getWithDereferenceableBytes(F.getContext(), sizeof(void*));
}
newI->setAttributes(newI->getCalledFunction()->getAttributes());
Expand All @@ -253,9 +253,9 @@ bool FinalLowerGC::doInitialization(Module &M) {
queueRootFunc = getOrDeclare(jl_well_known::GCQueueRoot);
poolAllocFunc = getOrDeclare(jl_well_known::GCPoolAlloc);
bigAllocFunc = getOrDeclare(jl_well_known::GCBigAlloc);
allocTypedFunc = getOrDeclare(jl_well_known::GCAllocTyped);
allocFunc = getOrDeclare(jl_well_known::GCAlloc);

GlobalValue *functionList[] = {queueRootFunc, poolAllocFunc, bigAllocFunc, allocTypedFunc};
GlobalValue *functionList[] = {queueRootFunc, poolAllocFunc, bigAllocFunc, allocFunc};
unsigned j = 0;
for (unsigned i = 0; i < sizeof(functionList) / sizeof(void*); i++) {
if (!functionList[i])
Expand All @@ -271,8 +271,8 @@ bool FinalLowerGC::doInitialization(Module &M) {

bool FinalLowerGC::doFinalization(Module &M)
{
GlobalValue *functionList[] = {queueRootFunc, poolAllocFunc, bigAllocFunc, allocTypedFunc};
queueRootFunc = poolAllocFunc = bigAllocFunc = allocTypedFunc = nullptr;
GlobalValue *functionList[] = {queueRootFunc, poolAllocFunc, bigAllocFunc, allocFunc};
queueRootFunc = poolAllocFunc = bigAllocFunc = allocFunc = nullptr;
auto used = M.getGlobalVariable("llvm.compiler.used");
if (!used)
return false;
Expand Down
14 changes: 7 additions & 7 deletions src/llvm-pass-helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ namespace jl_well_known {
static const char *GC_BIG_ALLOC_NAME = XSTR(jl_gc_big_alloc);
static const char *GC_POOL_ALLOC_NAME = XSTR(jl_gc_pool_alloc);
static const char *GC_QUEUE_ROOT_NAME = XSTR(jl_gc_queue_root);
static const char *GC_ALLOC_TYPED_NAME = XSTR(jl_gc_alloc_typed);
static const char *GC_ALLOC_NAME = XSTR(jl_gc_alloc);

using jl_intrinsics::addGCAllocAttributes;

Expand Down Expand Up @@ -278,10 +278,10 @@ namespace jl_well_known {
return func;
});

const WellKnownFunctionDescription GCAllocTyped(
GC_ALLOC_TYPED_NAME,
const WellKnownFunctionDescription GCAlloc(
GC_ALLOC_NAME,
[](const JuliaPassContext &context) {
auto allocTypedFunc = Function::Create(
auto allocFunc = Function::Create(
FunctionType::get(
context.T_prjlvalue,
{ Type::getInt8PtrTy(context.getLLVMContext()),
Expand All @@ -291,8 +291,8 @@ namespace jl_well_known {
Type::getInt8PtrTy(context.getLLVMContext()) },
false),
Function::ExternalLinkage,
GC_ALLOC_TYPED_NAME);
allocTypedFunc->addFnAttr(Attribute::getWithAllocSizeArgs(context.getLLVMContext(), 1, None));
return addGCAllocAttributes(allocTypedFunc, context.getLLVMContext());
GC_ALLOC_NAME);
allocFunc->addFnAttr(Attribute::getWithAllocSizeArgs(context.getLLVMContext(), 1, None));
return addGCAllocAttributes(allocFunc, context.getLLVMContext());
});
}
4 changes: 2 additions & 2 deletions src/llvm-pass-helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ namespace jl_well_known {
// `jl_gc_queue_root`: queues a GC root.
extern const WellKnownFunctionDescription GCQueueRoot;

// `jl_gc_alloc_typed`: allocates bytes.
extern const WellKnownFunctionDescription GCAllocTyped;
// `jl_gc_alloc`: allocates bytes.
extern const WellKnownFunctionDescription GCAlloc;
}

#endif