Skip to content

Commit fe207c5

Browse files
authored
NFC: rename pool_alloc to make the naming a bit more compatible with other GC impls (#55207)
Other GC implementations may not want to necessarily segregate small objects into object pools (e.g. may just want to allocate everything with Libc malloc). Let's rename `pool_alloc` to `small_alloc` to make it a bit more general in the sense that although we're exposing different allocation functions, we make no mention to the fact that they're using object pools under the hood.
1 parent 7ed5068 commit fe207c5

14 files changed

+49
-49
lines changed

src/gc.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1248,7 +1248,7 @@ pagetable_t alloc_map;
12481248
static NOINLINE jl_taggedvalue_t *gc_add_page(jl_gc_pool_t *p) JL_NOTSAFEPOINT
12491249
{
12501250
// Do not pass in `ptls` as argument. This slows down the fast path
1251-
// in pool_alloc significantly
1251+
// in small_alloc significantly
12521252
jl_ptls_t ptls = jl_current_task->ptls;
12531253
jl_gc_pagemeta_t *pg = jl_gc_alloc_page();
12541254
pg->osize = p->osize;
@@ -1262,13 +1262,13 @@ static NOINLINE jl_taggedvalue_t *gc_add_page(jl_gc_pool_t *p) JL_NOTSAFEPOINT
12621262
}
12631263

12641264
// Size includes the tag and the tag is not cleared!!
1265-
STATIC_INLINE jl_value_t *jl_gc_pool_alloc_inner(jl_ptls_t ptls, int pool_offset,
1265+
STATIC_INLINE jl_value_t *jl_gc_small_alloc_inner(jl_ptls_t ptls, int offset,
12661266
int osize)
12671267
{
12681268
// Use the pool offset instead of the pool address as the argument
12691269
// to workaround a llvm bug.
12701270
// Ref https://llvm.org/bugs/show_bug.cgi?id=27190
1271-
jl_gc_pool_t *p = (jl_gc_pool_t*)((char*)ptls + pool_offset);
1271+
jl_gc_pool_t *p = (jl_gc_pool_t*)((char*)ptls + offset);
12721272
assert(jl_atomic_load_relaxed(&ptls->gc_state) == 0);
12731273
#ifdef MEMDEBUG
12741274
return jl_gc_big_alloc(ptls, osize, NULL);
@@ -1319,19 +1319,19 @@ STATIC_INLINE jl_value_t *jl_gc_pool_alloc_inner(jl_ptls_t ptls, int pool_offset
13191319
return jl_valueof(v);
13201320
}
13211321

1322-
// Instrumented version of jl_gc_pool_alloc_inner, called into by LLVM-generated code.
1323-
JL_DLLEXPORT jl_value_t *jl_gc_pool_alloc(jl_ptls_t ptls, int pool_offset, int osize, jl_value_t* type)
1322+
// Instrumented version of jl_gc_small_alloc_inner, called into by LLVM-generated code.
1323+
JL_DLLEXPORT jl_value_t *jl_gc_small_alloc(jl_ptls_t ptls, int offset, int osize, jl_value_t* type)
13241324
{
1325-
jl_value_t *val = jl_gc_pool_alloc_inner(ptls, pool_offset, osize);
1325+
jl_value_t *val = jl_gc_small_alloc_inner(ptls, offset, osize);
13261326
maybe_record_alloc_to_profile(val, osize, (jl_datatype_t*)type);
13271327
return val;
13281328
}
13291329

1330-
// This wrapper exists only to prevent `jl_gc_pool_alloc_inner` from being inlined into
1331-
// its callers. We provide an external-facing interface for callers, and inline `jl_gc_pool_alloc_inner`
1330+
// This wrapper exists only to prevent `jl_gc_small_alloc_inner` from being inlined into
1331+
// its callers. We provide an external-facing interface for callers, and inline `jl_gc_small_alloc_inner`
13321332
// into this. (See https://github.com/JuliaLang/julia/pull/43868 for more details.)
1333-
jl_value_t *jl_gc_pool_alloc_noinline(jl_ptls_t ptls, int pool_offset, int osize) {
1334-
return jl_gc_pool_alloc_inner(ptls, pool_offset, osize);
1333+
jl_value_t *jl_gc_small_alloc_noinline(jl_ptls_t ptls, int offset, int osize) {
1334+
return jl_gc_small_alloc_inner(ptls, offset, osize);
13351335
}
13361336

13371337
int jl_gc_classify_pools(size_t sz, int *osize)

src/jl_exported_funcs.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@
168168
XX(jl_gc_new_weakref) \
169169
XX(jl_gc_new_weakref_th) \
170170
XX(jl_gc_num) \
171-
XX(jl_gc_pool_alloc) \
171+
XX(jl_gc_small_alloc) \
172172
XX(jl_gc_queue_multiroot) \
173173
XX(jl_gc_queue_root) \
174174
XX(jl_gc_safepoint) \

src/julia_internal.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ extern _Atomic(jl_typemap_entry_t*) call_cache[N_CALL_CACHE] JL_GLOBALLY_ROOTED;
346346
JL_DLLEXPORT extern int jl_lineno;
347347
JL_DLLEXPORT extern const char *jl_filename;
348348

349-
jl_value_t *jl_gc_pool_alloc_noinline(jl_ptls_t ptls, int pool_offset,
349+
jl_value_t *jl_gc_small_alloc_noinline(jl_ptls_t ptls, int offset,
350350
int osize);
351351
jl_value_t *jl_gc_big_alloc_noinline(jl_ptls_t ptls, size_t allocsz);
352352
JL_DLLEXPORT int jl_gc_classify_pools(size_t sz, int *osize) JL_NOTSAFEPOINT;
@@ -504,9 +504,9 @@ STATIC_INLINE jl_value_t *jl_gc_alloc_(jl_ptls_t ptls, size_t sz, void *ty)
504504
int pool_id = jl_gc_szclass(allocsz);
505505
jl_gc_pool_t *p = &ptls->gc_tls.heap.norm_pools[pool_id];
506506
int osize = jl_gc_sizeclasses[pool_id];
507-
// We call `jl_gc_pool_alloc_noinline` instead of `jl_gc_pool_alloc` to avoid double-counting in
507+
// We call `jl_gc_small_alloc_noinline` instead of `jl_gc_small_alloc` to avoid double-counting in
508508
// the Allocations Profiler. (See https://github.com/JuliaLang/julia/pull/43868 for more details.)
509-
v = jl_gc_pool_alloc_noinline(ptls, (char*)p - (char*)ptls, osize);
509+
v = jl_gc_small_alloc_noinline(ptls, (char*)p - (char*)ptls, osize);
510510
}
511511
else {
512512
if (allocsz < sz) // overflow in adding offs, size was "negative"

src/llvm-final-gc-lowering.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ struct FinalLowerGC: private JuliaPassContext {
4343

4444
private:
4545
Function *queueRootFunc;
46-
Function *poolAllocFunc;
46+
Function *smallAllocFunc;
4747
Function *bigAllocFunc;
4848
Function *allocTypedFunc;
4949
Instruction *pgcstack;
@@ -202,7 +202,7 @@ void FinalLowerGC::lowerGCAllocBytes(CallInst *target, Function &F)
202202
else {
203203
auto pool_offs = ConstantInt::get(Type::getInt32Ty(F.getContext()), offset);
204204
auto pool_osize = ConstantInt::get(Type::getInt32Ty(F.getContext()), osize);
205-
newI = builder.CreateCall(poolAllocFunc, { ptls, pool_offs, pool_osize, type });
205+
newI = builder.CreateCall(smallAllocFunc, { ptls, pool_offs, pool_osize, type });
206206
if (sz > 0)
207207
derefBytes = sz;
208208
}
@@ -238,7 +238,7 @@ bool FinalLowerGC::runOnFunction(Function &F)
238238
}
239239
LLVM_DEBUG(dbgs() << "FINAL GC LOWERING: Processing function " << F.getName() << "\n");
240240
queueRootFunc = getOrDeclare(jl_well_known::GCQueueRoot);
241-
poolAllocFunc = getOrDeclare(jl_well_known::GCPoolAlloc);
241+
smallAllocFunc = getOrDeclare(jl_well_known::GCSmallAlloc);
242242
bigAllocFunc = getOrDeclare(jl_well_known::GCBigAlloc);
243243
allocTypedFunc = getOrDeclare(jl_well_known::GCAllocTyped);
244244
T_size = F.getParent()->getDataLayout().getIntPtrType(F.getContext());

src/llvm-pass-helpers.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ namespace jl_intrinsics {
259259

260260
namespace jl_well_known {
261261
static const char *GC_BIG_ALLOC_NAME = XSTR(jl_gc_big_alloc);
262-
static const char *GC_POOL_ALLOC_NAME = XSTR(jl_gc_pool_alloc);
262+
static const char *GC_SMALL_ALLOC_NAME = XSTR(jl_gc_small_alloc);
263263
static const char *GC_QUEUE_ROOT_NAME = XSTR(jl_gc_queue_root);
264264
static const char *GC_ALLOC_TYPED_NAME = XSTR(jl_gc_alloc_typed);
265265

@@ -281,20 +281,20 @@ namespace jl_well_known {
281281
return addGCAllocAttributes(bigAllocFunc);
282282
});
283283

284-
const WellKnownFunctionDescription GCPoolAlloc(
285-
GC_POOL_ALLOC_NAME,
284+
const WellKnownFunctionDescription GCSmallAlloc(
285+
GC_SMALL_ALLOC_NAME,
286286
[](Type *T_size) {
287287
auto &ctx = T_size->getContext();
288288
auto T_prjlvalue = JuliaType::get_prjlvalue_ty(ctx);
289-
auto poolAllocFunc = Function::Create(
289+
auto smallAllocFunc = Function::Create(
290290
FunctionType::get(
291291
T_prjlvalue,
292292
{ PointerType::get(ctx, 0), Type::getInt32Ty(ctx), Type::getInt32Ty(ctx), T_size },
293293
false),
294294
Function::ExternalLinkage,
295-
GC_POOL_ALLOC_NAME);
296-
poolAllocFunc->addFnAttr(Attribute::getWithAllocSizeArgs(ctx, 2, None));
297-
return addGCAllocAttributes(poolAllocFunc);
295+
GC_SMALL_ALLOC_NAME);
296+
smallAllocFunc->addFnAttr(Attribute::getWithAllocSizeArgs(ctx, 2, None));
297+
return addGCAllocAttributes(smallAllocFunc);
298298
});
299299

300300
const WellKnownFunctionDescription GCQueueRoot(

src/llvm-pass-helpers.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,8 @@ namespace jl_well_known {
147147
// `jl_gc_big_alloc`: allocates bytes.
148148
extern const WellKnownFunctionDescription GCBigAlloc;
149149

150-
// `jl_gc_pool_alloc`: allocates bytes.
151-
extern const WellKnownFunctionDescription GCPoolAlloc;
150+
// `jl_gc_small_alloc`: allocates bytes.
151+
extern const WellKnownFunctionDescription GCSmallAlloc;
152152

153153
// `jl_gc_queue_root`: queues a GC root.
154154
extern const WellKnownFunctionDescription GCQueueRoot;

test/compiler/codegen.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -222,18 +222,18 @@ if opt_level > 0
222222
@test occursin("call i32 @memcmp(", compare_large_struct_ir) || occursin("call i32 @bcmp(", compare_large_struct_ir)
223223
@test !occursin("%gcframe", compare_large_struct_ir)
224224

225-
@test occursin("jl_gc_pool_alloc", get_llvm(MutableStruct, Tuple{}))
225+
@test occursin("jl_gc_small_alloc", get_llvm(MutableStruct, Tuple{}))
226226
breakpoint_mutable_ir = get_llvm(breakpoint_mutable, Tuple{MutableStruct})
227227
@test !occursin("%gcframe", breakpoint_mutable_ir)
228-
@test !occursin("jl_gc_pool_alloc", breakpoint_mutable_ir)
228+
@test !occursin("jl_gc_small_alloc", breakpoint_mutable_ir)
229229

230230
breakpoint_badref_ir = get_llvm(breakpoint_badref, Tuple{MutableStruct})
231231
@test !occursin("%gcframe", breakpoint_badref_ir)
232-
@test !occursin("jl_gc_pool_alloc", breakpoint_badref_ir)
232+
@test !occursin("jl_gc_small_alloc", breakpoint_badref_ir)
233233

234234
breakpoint_ptrstruct_ir = get_llvm(breakpoint_ptrstruct, Tuple{RealStruct})
235235
@test !occursin("%gcframe", breakpoint_ptrstruct_ir)
236-
@test !occursin("jl_gc_pool_alloc", breakpoint_ptrstruct_ir)
236+
@test !occursin("jl_gc_small_alloc", breakpoint_ptrstruct_ir)
237237
end
238238

239239
function two_breakpoint(a::Float64)
@@ -251,17 +251,17 @@ end
251251
if opt_level > 0
252252
breakpoint_f64_ir = get_llvm((a)->ccall(:jl_breakpoint, Cvoid, (Ref{Float64},), a),
253253
Tuple{Float64})
254-
@test !occursin("jl_gc_pool_alloc", breakpoint_f64_ir)
254+
@test !occursin("jl_gc_small_alloc", breakpoint_f64_ir)
255255
breakpoint_any_ir = get_llvm((a)->ccall(:jl_breakpoint, Cvoid, (Ref{Any},), a),
256256
Tuple{Float64})
257-
@test occursin("jl_gc_pool_alloc", breakpoint_any_ir)
257+
@test occursin("jl_gc_small_alloc", breakpoint_any_ir)
258258
two_breakpoint_ir = get_llvm(two_breakpoint, Tuple{Float64})
259-
@test !occursin("jl_gc_pool_alloc", two_breakpoint_ir)
259+
@test !occursin("jl_gc_small_alloc", two_breakpoint_ir)
260260
@test occursin("llvm.lifetime.end", two_breakpoint_ir)
261261

262262
@test load_dummy_ref(1234) === 1234
263263
load_dummy_ref_ir = get_llvm(load_dummy_ref, Tuple{Int})
264-
@test !occursin("jl_gc_pool_alloc", load_dummy_ref_ir)
264+
@test !occursin("jl_gc_small_alloc", load_dummy_ref_ir)
265265
# Hopefully this is reliable enough. LLVM should be able to optimize this to a direct return.
266266
@test occursin("ret $Iptr %\"x::$(Int)\"", load_dummy_ref_ir)
267267
end

test/llvmpasses/alloc-opt-gcframe.ll

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
1212
; OPAQUE: %current_task = getelementptr inbounds ptr, ptr %gcstack, i64 -12
1313
; OPAQUE: [[ptls_field:%.*]] = getelementptr inbounds ptr, ptr %current_task, i64 16
1414
; OPAQUE-NEXT: [[ptls_load:%.*]] = load ptr, ptr [[ptls_field]], align 8, !tbaa !0
15-
; OPAQUE-NEXT: %v = call noalias nonnull align {{[0-9]+}} dereferenceable({{[0-9]+}}) ptr addrspace(10) @ijl_gc_pool_alloc(ptr [[ptls_load]], i32 [[SIZE_T:[0-9]+]], i32 16, i64 {{.*}} @tag {{.*}})
15+
; OPAQUE-NEXT: %v = call noalias nonnull align {{[0-9]+}} dereferenceable({{[0-9]+}}) ptr addrspace(10) @ijl_gc_small_alloc(ptr [[ptls_load]], i32 [[SIZE_T:[0-9]+]], i32 16, i64 {{.*}} @tag {{.*}})
1616
; OPAQUE: store atomic ptr addrspace(10) @tag, ptr addrspace(10) {{.*}} unordered, align 8, !tbaa !4
1717

1818
define {} addrspace(10)* @return_obj() {
@@ -27,7 +27,7 @@ define {} addrspace(10)* @return_obj() {
2727
; CHECK-LABEL: @return_load
2828
; CHECK: alloca i64
2929
; CHECK-NOT: @julia.gc_alloc_obj
30-
; CHECK-NOT: @jl_gc_pool_alloc
30+
; CHECK-NOT: @jl_gc_small_alloc
3131
; OPAQUE: call void @llvm.lifetime.start{{.*}}(i64 8, ptr
3232
; CHECK-NOT: @tag
3333
; CHECK-NOT: @llvm.lifetime.end
@@ -48,7 +48,7 @@ define i64 @return_load(i64 %i) {
4848
; CHECK-LABEL: @ccall_obj
4949
; OPAQUE: call ptr @julia.get_pgcstack()
5050
; CHECK-NOT: @julia.gc_alloc_obj
51-
; CHECK: @ijl_gc_pool_alloc
51+
; CHECK: @ijl_gc_small_alloc
5252
; OPAQUE: store atomic ptr addrspace(10) @tag, ptr addrspace(10) {{.*}} unordered, align 8, !tbaa !4
5353
define void @ccall_obj(i8* %fptr) {
5454
%pgcstack = call {}*** @julia.get_pgcstack()
@@ -65,7 +65,7 @@ define void @ccall_obj(i8* %fptr) {
6565
; CHECK: alloca i64
6666
; OPAQUE: call ptr @julia.get_pgcstack()
6767
; CHECK-NOT: @julia.gc_alloc_obj
68-
; CHECK-NOT: @jl_gc_pool_alloc
68+
; CHECK-NOT: @jl_gc_small_alloc
6969
; OPAQUE: call void @llvm.lifetime.start{{.*}}(i64 8, ptr
7070
; OPAQUE: %f = bitcast ptr %fptr to ptr
7171
; Currently the GC frame lowering pass strips away all operand bundles
@@ -88,7 +88,7 @@ define void @ccall_ptr(i8* %fptr) {
8888
; CHECK-LABEL: @ccall_unknown_bundle
8989
; OPAQUE: call ptr @julia.get_pgcstack()
9090
; CHECK-NOT: @julia.gc_alloc_obj
91-
; CHECK: @ijl_gc_pool_alloc
91+
; CHECK: @ijl_gc_small_alloc
9292
; OPAQUE: store atomic ptr addrspace(10) @tag, ptr addrspace(10) {{.*}} unordered, align 8, !tbaa !4
9393
define void @ccall_unknown_bundle(i8* %fptr) {
9494
%pgcstack = call {}*** @julia.get_pgcstack()
@@ -151,7 +151,7 @@ L3:
151151
; CHECK-LABEL: @object_field
152152
; OPAQUE: call ptr @julia.get_pgcstack()
153153
; CHECK-NOT: @julia.gc_alloc_obj
154-
; CHECK-NOT: @jl_gc_pool_alloc
154+
; CHECK-NOT: @jl_gc_small_alloc
155155
; CHECK-NOT: store {} addrspace(10)* @tag, {} addrspace(10)* addrspace(10)* {{.*}}, align 8, !tbaa !4
156156
define void @object_field({} addrspace(10)* %field) {
157157
%pgcstack = call {}*** @julia.get_pgcstack()
@@ -169,7 +169,7 @@ define void @object_field({} addrspace(10)* %field) {
169169
; CHECK: alloca [16 x i8], align 16
170170
; OPAQUE: call ptr @julia.get_pgcstack()
171171
; CHECK-NOT: @julia.gc_alloc_obj
172-
; CHECK-NOT: @jl_gc_pool_alloc
172+
; CHECK-NOT: @jl_gc_small_alloc
173173
; OPAQUE: call void @llvm.memcpy.p0.p0.i64
174174
define void @memcpy_opt(i8* %v22) {
175175
top:
@@ -187,7 +187,7 @@ top:
187187
; CHECK-LABEL: @preserve_opt
188188
; OPAQUE: call ptr @julia.get_pgcstack()
189189
; CHECK-NOT: @julia.gc_alloc_obj
190-
; CHECK-NOT: @jl_gc_pool_alloc
190+
; CHECK-NOT: @jl_gc_small_alloc
191191
; CHECK-NOT: @llvm.lifetime.end
192192
; CHECK: @external_function
193193
define void @preserve_opt(i8* %v22) {
@@ -238,7 +238,7 @@ L3:
238238
}
239239
; CHECK-LABEL: }{{$}}
240240

241-
; OPAQUE: declare noalias nonnull ptr addrspace(10) @ijl_gc_pool_alloc(ptr,
241+
; OPAQUE: declare noalias nonnull ptr addrspace(10) @ijl_gc_small_alloc(ptr,
242242
; OPAQUE: declare noalias nonnull ptr addrspace(10) @ijl_gc_big_alloc(ptr,
243243
declare void @external_function()
244244
declare {}*** @julia.get_pgcstack()

test/llvmpasses/alloc-opt-pipeline.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ end
1717

1818
# CHECK-LABEL: @julia_haszerolayout
1919
# CHECK: top:
20-
# CHECK-NOT: @jl_gc_pool_alloc
20+
# CHECK-NOT: @jl_gc_small_alloc
2121
# CHECK: extractelement
2222
# CHECK: ret i8
2323
emit(haszerolayout, NTuple{32,VecElement{UInt8}})

test/llvmpasses/final-lower-gc.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ top:
5858
%pgcstack = call {}*** @julia.get_pgcstack()
5959
%ptls = call {}*** @julia.ptls_states()
6060
%ptls_i8 = bitcast {}*** %ptls to i8*
61-
; OPAQUE: %v = call noalias nonnull align {{[0-9]+}} dereferenceable({{[0-9]+}}) ptr addrspace(10) @ijl_gc_pool_alloc
61+
; OPAQUE: %v = call noalias nonnull align {{[0-9]+}} dereferenceable({{[0-9]+}}) ptr addrspace(10) @ijl_gc_small_alloc
6262
%v = call {} addrspace(10)* @julia.gc_alloc_bytes(i8* %ptls_i8, i64 8, i64 12341234)
6363
%0 = bitcast {} addrspace(10)* %v to {} addrspace(10)* addrspace(10)*
6464
%1 = getelementptr {} addrspace(10)*, {} addrspace(10)* addrspace(10)* %0, i64 -1

0 commit comments

Comments
 (0)