Skip to content

Commit 8d2fac8

Browse files
authored
Merge pull request #18704 from JuliaLang/vc/jl_datatype_size
Cleanup the usage of `jl_datatype_size`
2 parents 0287a99 + 79dd895 commit 8d2fac8

15 files changed

+61
-58
lines changed

base/show.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@ function show_default(io::IO, x::ANY)
119119
show(io, t)
120120
print(io, '(')
121121
nf = nfields(t)
122-
if nf != 0 || t.size==0
122+
nb = sizeof(x)
123+
if nf != 0 || nb==0
123124
if !show_circular(io, x)
124125
recur_io = IOContext(io, :SHOWN_SET => x)
125126
for i=1:nf
@@ -135,7 +136,6 @@ function show_default(io::IO, x::ANY)
135136
end
136137
end
137138
else
138-
nb = t.size
139139
print(io, "0x")
140140
p = data_pointer_from_objref(x)
141141
for i=nb-1:-1:0

src/abi_aarch64.cpp

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ static Type *get_llvm_vectype(jl_datatype_t *dt)
3232
// Short vector should be either 8 bytes or 16 bytes.
3333
// Note that there are only two distinct fundamental types for
3434
// short vectors so we normalize them to <2 x i32> and <4 x i32>
35-
switch (dt->size) {
35+
switch (jl_datatype_size(dt)) {
3636
case 8:
3737
lltype = T_vec64;
3838
break;
@@ -67,7 +67,7 @@ static Type *get_llvm_fptype(jl_datatype_t *dt)
6767
// `!dt->mutabl && dt->pointerfree && !dt->haspadding && dt->nfields == 0`
6868
Type *lltype;
6969
// Check size first since it's cheaper.
70-
switch (dt->size) {
70+
switch (jl_datatype_size(dt)) {
7171
case 2:
7272
lltype = T_float16;
7373
break;
@@ -111,7 +111,7 @@ static bool isHFAorHVA(jl_datatype_t *dt, size_t dsz, size_t &nele, ElementType
111111
{
112112
// Assume:
113113
// dt is a pointerfree type, (all members are isbits)
114-
// dsz == dt->size > 0
114+
// dsz == jl_datatype_size(dt) > 0
115115
// 0 <= nele <= 3
116116
// dt has no padding
117117

@@ -181,7 +181,7 @@ static Type *isHFAorHVA(jl_datatype_t *dt, size_t &nele)
181181
// with a Fundamental Data Type that is a Short-Vector type and at most four
182182
// uniquely addressable members.
183183
// Maximum HFA and HVA size is 64 bytes (4 x fp128 or 16bytes vector)
184-
size_t dsz = dt->size;
184+
size_t dsz = jl_datatype_size(dt);
185185
if (dsz > 64 || !dt->layout || !dt->layout->pointerfree || dt->layout->haspadding)
186186
return NULL;
187187
nele = 0;
@@ -206,7 +206,7 @@ void needPassByRef(AbiState*, jl_datatype_t *dt, bool *byRef, bool*)
206206
// We only check for the total size and not whether it is a composite type
207207
// since there's no corresponding C type and we just treat such large
208208
// bitstype as a composite type of the right size.
209-
*byRef = dt->size > 16;
209+
*byRef = jl_datatype_size(dt) > 16;
210210
// B.4
211211
// If the argument type is a Composite Type then the size of the argument
212212
// is rounded up to the nearest multiple of 8 bytes.
@@ -262,7 +262,7 @@ static Type *classify_arg(jl_datatype_t *dt, bool *fpreg, bool *onstack,
262262
// done before starting step C but we do this here to avoid checking for
263263
// HFA and HVA twice. We don't check whether it is a composite type.
264264
// See `needPassByRef` above.
265-
if (dt->size > 16) {
265+
if (jl_datatype_size(dt) > 16) {
266266
*onstack = true;
267267
return NULL;
268268
}
@@ -295,8 +295,9 @@ static Type *classify_arg(jl_datatype_t *dt, bool *fpreg, bool *onstack,
295295
// pointers. We don't need to worry about floating points here since they
296296
// are handled above.
297297
if (jl_is_immutable(dt) && jl_datatype_nfields(dt) == 0 &&
298-
(dt->size == 1 || dt->size == 2 || dt->size == 4 ||
299-
dt->size == 8 || dt->size == 16))
298+
(jl_datatype_size(dt) == 1 || jl_datatype_size(dt) == 2 ||
299+
jl_datatype_size(dt) == 4 || jl_datatype_size(dt) == 8 ||
300+
jl_datatype_size(dt) == 16))
300301
return NULL;
301302

302303
// C.8
@@ -325,10 +326,10 @@ static Type *classify_arg(jl_datatype_t *dt, bool *fpreg, bool *onstack,
325326
// The type can fit in 8 x 8 bytes since it is handled by
326327
// need_pass_by_ref otherwise.
327328
// 0-size types (Void) won't be rewritten and that is what we want
328-
assert(dt->size <= 16); // Should be pass by reference otherwise
329-
*rewrite_len = (dt->size + 7) >> 3;
329+
assert(jl_datatype_size(dt) <= 16); // Should be pass by reference otherwise
330+
*rewrite_len = (jl_datatype_size(dt) + 7) >> 3;
330331
// Rewrite to [n x Int64] where n is the **size in dword**
331-
return dt->size ? T_int64 : NULL;
332+
return jl_datatype_size(dt) ? T_int64 : NULL;
332333

333334
// C.11
334335
// The NGRN is set to 8.

src/abi_arm.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ static Type *get_llvm_fptype(jl_datatype_t *dt)
4141
return NULL;
4242
Type *lltype;
4343
// Check size first since it's cheaper.
44-
switch (dt->size) {
44+
switch (jl_datatype_size(dt)) {
4545
case 2:
4646
lltype = T_float16;
4747
break;
@@ -88,7 +88,7 @@ static size_t isLegalHA(jl_datatype_t *dt, Type *&base)
8888
if (jl_is_structtype(dt)) {
8989
// Fast path checks before descending the type hierarchy
9090
// (4 x 128b vector == 64B max size)
91-
if (dt->size > 64 || !dt->layout->pointerfree || dt->layout->haspadding)
91+
if (jl_datatype_size(dt) > 64 || !dt->layout->pointerfree || dt->layout->haspadding)
9292
return 0;
9393

9494
base = NULL;
@@ -175,7 +175,7 @@ static void classify_return_arg(jl_datatype_t *dt, bool *reg,
175175
// 64-bit containerized vectors) is returned in r0 and r1.
176176
// - A word-sized Fundamental Data Type (eg., int, float) is returned in r0.
177177
// NOTE: assuming "fundamental type" == jl_is_bitstype, might need exact def
178-
if (jl_is_bitstype(dt) && dt->size <= 8) {
178+
if (jl_is_bitstype(dt) && jl_datatype_size(dt) <= 8) {
179179
*reg = true;
180180
return;
181181
}
@@ -196,7 +196,7 @@ static void classify_return_arg(jl_datatype_t *dt, bool *reg,
196196
// an address passed as an extra argument when the function was called
197197
// (§5.5, rule A.4). The memory to be used for the result may be modified
198198
// at any point during the function call.
199-
if (dt->size <= 4)
199+
if (jl_datatype_size(dt) <= 4)
200200
*reg = true;
201201
else
202202
*onstack = true;
@@ -237,7 +237,7 @@ static void classify_arg(jl_datatype_t *dt, bool *reg,
237237
return;
238238

239239
// Handle fundamental types
240-
if (jl_is_bitstype(dt) && dt->size <= 8) {
240+
if (jl_is_bitstype(dt) && jl_datatype_size(dt) <= 8) {
241241
*reg = true;
242242
return;
243243
}
@@ -283,7 +283,7 @@ Type *preferred_llvm_type(jl_datatype_t *dt, bool isret)
283283
align = 8;
284284

285285
Type *T = Type::getIntNTy(jl_LLVMContext, align*8);
286-
return ArrayType::get(T, (dt->size + align - 1) / align);
286+
return ArrayType::get(T, (jl_datatype_size(dt) + align - 1) / align);
287287
}
288288

289289
}

src/abi_ppc64le.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ bool use_sret(AbiState *state, jl_datatype_t *dt)
9797
{
9898
jl_datatype_t *ty0 = NULL;
9999
bool hva = false;
100-
if (dt->size > 16 && isHFA(dt, &ty0, &hva) > 8)
100+
if (jl_datatype_size(dt) > 16 && isHFA(dt, &ty0, &hva) > 8)
101101
return true;
102102
return false;
103103
}
@@ -106,14 +106,14 @@ void needPassByRef(AbiState *state, jl_datatype_t *dt, bool *byRef, bool *inReg)
106106
{
107107
jl_datatype_t *ty0 = NULL;
108108
bool hva = false;
109-
if (dt->size > 64 && isHFA(dt, &ty0, &hva) > 8)
109+
if (jl_datatype_size(dt) > 64 && isHFA(dt, &ty0, &hva) > 8)
110110
*byRef = true;
111111
}
112112

113113
Type *preferred_llvm_type(jl_datatype_t *dt, bool isret)
114114
{
115115
// Arguments are either scalar or passed by value
116-
size_t size = dt->size;
116+
size_t size = jl_datatype_size(dt);
117117
// don't need to change bitstypes
118118
if (!jl_datatype_nfields(dt))
119119
return NULL;

src/abi_win32.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ bool use_sret(AbiState *state, jl_datatype_t *dt)
4444
{
4545
// Use sret if the size of the argument is not one of 1, 2, 4, 8 bytes
4646
// This covers the special case of Complex64
47-
size_t size = dt->size;
47+
size_t size = jl_datatype_size(dt);
4848
if (size == 1 || size == 2 || size == 4 || size == 8)
4949
return false;
5050
return true;
@@ -62,7 +62,7 @@ Type *preferred_llvm_type(jl_datatype_t *dt, bool isret)
6262
// rewrite integer sized (non-sret) struct to the corresponding integer
6363
if (!dt->layout->nfields)
6464
return NULL;
65-
return Type::getIntNTy(jl_LLVMContext, dt->size * 8);
65+
return Type::getIntNTy(jl_LLVMContext, jl_datatype_nbits(dt));
6666
}
6767

6868
bool need_private_copy(jl_value_t *ty, bool byRef)

src/abi_win64.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ Type *preferred_llvm_type(jl_datatype_t *dt, bool isret)
6868
{
6969
size_t size = jl_datatype_size(dt);
7070
if (size > 0 && win64_reg_size(size) && !jl_is_bitstype(dt))
71-
return Type::getIntNTy(jl_LLVMContext, size*8);
71+
return Type::getIntNTy(jl_LLVMContext, jl_datatype_nbits(dt));
7272
return NULL;
7373
}
7474

src/abi_x86_64.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,8 @@ Type *preferred_llvm_type(jl_datatype_t *dt, bool isret)
207207
if (is_native_simd_type(dt))
208208
return NULL;
209209

210-
int size = jl_datatype_size(dt);
210+
size_t size = jl_datatype_size(dt);
211+
size_t nbits = jl_datatype_nbits(dt);
211212
if (size > 16 || size == 0)
212213
return NULL;
213214

@@ -221,7 +222,7 @@ Type *preferred_llvm_type(jl_datatype_t *dt, bool isret)
221222
if (size >= 8)
222223
types[0] = T_int64;
223224
else
224-
types[0] = Type::getIntNTy(jl_LLVMContext, size*8);
225+
types[0] = Type::getIntNTy(jl_LLVMContext, nbits);
225226
break;
226227
case Sse:
227228
if (size <= 4)
@@ -237,7 +238,7 @@ Type *preferred_llvm_type(jl_datatype_t *dt, bool isret)
237238
return types[0];
238239
case Integer:
239240
assert(size > 8);
240-
types[1] = Type::getIntNTy(jl_LLVMContext, (size-8)*8);
241+
types[1] = Type::getIntNTy(jl_LLVMContext, (nbits-64));
241242
return StructType::get(jl_LLVMContext,ArrayRef<Type*>(&types[0],2));
242243
case Sse:
243244
if (size <= 12)

src/alloc.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ JL_DLLEXPORT jl_value_t *jl_new_struct(jl_datatype_t *type, ...)
229229
va_list args;
230230
size_t nf = jl_datatype_nfields(type);
231231
va_start(args, type);
232-
jl_value_t *jv = jl_gc_alloc(ptls, type->size, type);
232+
jl_value_t *jv = jl_gc_alloc(ptls, jl_datatype_size(type), type);
233233
for(size_t i=0; i < nf; i++) {
234234
jl_set_nth_field(jv, i, va_arg(args, jl_value_t*));
235235
}
@@ -243,7 +243,7 @@ JL_DLLEXPORT jl_value_t *jl_new_structv(jl_datatype_t *type, jl_value_t **args,
243243
jl_ptls_t ptls = jl_get_ptls_states();
244244
if (type->instance != NULL) return type->instance;
245245
size_t nf = jl_datatype_nfields(type);
246-
jl_value_t *jv = jl_gc_alloc(ptls, type->size, type);
246+
jl_value_t *jv = jl_gc_alloc(ptls, jl_datatype_size(type), type);
247247
for(size_t i=0; i < na; i++) {
248248
jl_set_nth_field(jv, i, args[i]);
249249
}
@@ -259,7 +259,7 @@ JL_DLLEXPORT jl_value_t *jl_new_struct_uninit(jl_datatype_t *type)
259259
{
260260
jl_ptls_t ptls = jl_get_ptls_states();
261261
if (type->instance != NULL) return type->instance;
262-
size_t size = type->size;
262+
size_t size = jl_datatype_size(type);
263263
jl_value_t *jv = jl_gc_alloc(ptls, size, type);
264264
if (size > 0)
265265
memset(jl_data_ptr(jv), 0, size);

src/builtins.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ JL_DLLEXPORT int jl_egal(jl_value_t *a, jl_value_t *b)
329329
return dta->name == dtb->name && compare_svec(dta->parameters, dtb->parameters);
330330
}
331331
if (dt->mutabl) return 0;
332-
size_t sz = dt->size;
332+
size_t sz = jl_datatype_size(dt);
333333
if (sz == 0) return 1;
334334
size_t nf = jl_datatype_nfields(dt);
335335
if (nf == 0)
@@ -359,7 +359,7 @@ JL_CALLABLE(jl_f_sizeof)
359359
jl_datatype_t *dx = (jl_datatype_t*)x;
360360
if (dx->name == jl_array_typename || dx == jl_symbol_type || dx == jl_simplevector_type)
361361
jl_error("type does not have a canonical binary representation");
362-
if (!(dx->name->names == jl_emptysvec && dx->size > 0)) {
362+
if (!(dx->name->names == jl_emptysvec && jl_datatype_size(dx) > 0)) {
363363
// names===() and size > 0 => bitstype, size always known
364364
if (dx->abstract || !jl_is_leaf_type(x))
365365
jl_error("argument is an abstract type; size is indeterminate");

src/ccall.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1172,7 +1172,7 @@ static std::string generate_func_sig(
11721172
// see pull req #978. need to annotate signext/zeroext for
11731173
// small integer arguments.
11741174
jl_datatype_t *bt = (jl_datatype_t*)tti;
1175-
if (bt->size < 4) {
1175+
if (jl_datatype_size(bt) < 4) {
11761176
if (jl_signed_type && jl_subtype(tti, (jl_value_t*)jl_signed_type, 0))
11771177
av = Attribute::SExt;
11781178
else

src/cgutils.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ static DIType julia_type_to_di(jl_value_t *jt, DIBuilder *dbuilder, bool isboxed
113113
#endif
114114
}
115115
if (jl_is_bitstype(jt)) {
116-
uint64_t SizeInBits = 8*jdt->size;
116+
uint64_t SizeInBits = jl_datatype_nbits(jdt);
117117
#if JL_LLVM_VERSION >= 30700
118118
llvm::DIType *t = dbuilder->createBasicType(
119119
jl_symbol_name(jdt->name->name),
@@ -149,7 +149,7 @@ static DIType julia_type_to_di(jl_value_t *jt, DIBuilder *dbuilder, bool isboxed
149149
tname, // Name
150150
NULL, // File
151151
0, // LineNumber
152-
8 * jdt->size, // SizeInBits
152+
jl_datatype_nbits(jdt), // SizeInBits
153153
8 * jdt->layout->alignment, // AlignInBits
154154
DIFlagZero, // Flags
155155
NULL, // DerivedFrom
@@ -345,10 +345,10 @@ JL_DLLEXPORT Type *julia_type_to_llvm(jl_value_t *jt, bool *isboxed)
345345
else if (nb == 16)
346346
return T_float128;
347347
}
348-
return Type::getIntNTy(jl_LLVMContext, nb*8);
348+
return Type::getIntNTy(jl_LLVMContext, jl_datatype_nbits(jt));
349349
}
350350
if (jl_isbits(jt)) {
351-
if (((jl_datatype_t*)jt)->size == 0) {
351+
if (jl_datatype_nbits(jt) == 0) {
352352
return T_void;
353353
}
354354
return julia_struct_to_llvm(jt, isboxed);
@@ -371,7 +371,7 @@ static Type *julia_struct_to_llvm(jl_value_t *jt, bool *isboxed)
371371
jl_datatype_t *jst = (jl_datatype_t*)jt;
372372
if (jst->struct_decl == NULL) {
373373
size_t ntypes = jl_datatype_nfields(jst);
374-
if (ntypes == 0 || jst->size == 0)
374+
if (ntypes == 0 || jl_datatype_nbits(jst) == 0)
375375
return T_void;
376376
StructType *structdecl;
377377
if (!isTuple) {
@@ -1519,7 +1519,7 @@ static Value *boxed(const jl_cgval_t &vinfo, jl_codectx_t *ctx, bool gcrooted)
15191519
assert("Don't know how to box this type" && false);
15201520
return NULL;
15211521
}
1522-
else if (!jb->abstract && jb->size == 0) {
1522+
else if (!jb->abstract && jl_datatype_nbits(jb) == 0) {
15231523
assert(jb->instance != NULL);
15241524
return literal_pointer_val(jb->instance);
15251525
}
@@ -1731,7 +1731,7 @@ static jl_cgval_t emit_new_struct(jl_value_t *ty, size_t nargs, jl_value_t **arg
17311731
f1 = boxed(fval_info, ctx);
17321732
j++;
17331733
}
1734-
Value *strct = emit_allocobj(ctx, sty->size,
1734+
Value *strct = emit_allocobj(ctx, jl_datatype_size(sty),
17351735
literal_pointer_val((jl_value_t*)ty));
17361736
jl_cgval_t strctinfo = mark_julia_type(strct, true, ty, ctx);
17371737
if (f1) {
@@ -1769,7 +1769,7 @@ static jl_cgval_t emit_new_struct(jl_value_t *ty, size_t nargs, jl_value_t **arg
17691769
}
17701770
else if (!sty->mutabl) {
17711771
// 0 fields, ghost or bitstype
1772-
if (sty->size == 0)
1772+
if (jl_datatype_nbits(sty) == 0)
17731773
return ghostValue(sty);
17741774
if (nargs >= 2)
17751775
return emit_expr(args[1], ctx); // do side effects

src/codegen.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2499,7 +2499,7 @@ static bool emit_builtin_call(jl_cgval_t *ret, jl_value_t *f, jl_value_t **args,
24992499
size_t nd = jl_is_long(ndp) ? jl_unbox_long(ndp) : 1;
25002500
Value *idx = emit_array_nd_index(ary, args[1], nd, &args[2], nargs-1, ctx);
25012501
if (jl_array_store_unboxed(ety) &&
2502-
((jl_datatype_t*)ety)->size == 0) {
2502+
jl_datatype_size(ety) == 0) {
25032503
assert(jl_is_datatype(ety));
25042504
assert(((jl_datatype_t*)ety)->instance != NULL);
25052505
*ret = ghostValue(ety);
@@ -2534,7 +2534,7 @@ static bool emit_builtin_call(jl_cgval_t *ret, jl_value_t *f, jl_value_t **args,
25342534
size_t nd = jl_is_long(ndp) ? jl_unbox_long(ndp) : 1;
25352535
Value *idx = emit_array_nd_index(ary, args[1], nd, &args[3], nargs-2, ctx);
25362536
bool isboxed = !jl_array_store_unboxed(ety);
2537-
if (!isboxed && ((jl_datatype_t*)ety)->size == 0) {
2537+
if (!isboxed && jl_datatype_size(ety) == 0) {
25382538
// no-op, but emit expr for possible effects
25392539
assert(jl_is_datatype(ety));
25402540
emit_expr(args[2], ctx);
@@ -2739,8 +2739,8 @@ static bool emit_builtin_call(jl_cgval_t *ret, jl_value_t *f, jl_value_t **args,
27392739
// this is issue #8798
27402740
sty != jl_datatype_type) {
27412741
if (jl_is_leaf_type((jl_value_t*)sty) ||
2742-
(sty->name->names == jl_emptysvec && sty->size > 0)) {
2743-
*ret = mark_julia_type(ConstantInt::get(T_size, sty->size), false, jl_long_type, ctx);
2742+
(sty->name->names == jl_emptysvec && jl_datatype_size(sty) > 0)) {
2743+
*ret = mark_julia_type(ConstantInt::get(T_size, jl_datatype_size(sty)), false, jl_long_type, ctx);
27442744
JL_GC_POP();
27452745
return true;
27462746
}

0 commit comments

Comments
 (0)