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

[RFC/WIP] Intrinsics for NTuple{N, VecElement} #18470

Closed
wants to merge 6 commits into from
Closed
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
4 changes: 2 additions & 2 deletions base/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ function show_default(io::IO, x::ANY)
show(io, t)
print(io, '(')
nf = nfields(t)
if nf != 0 || t.size==0
nb = sizeof(x)
if nf != 0 || nb==0
if !show_circular(io, x)
recur_io = IOContext(io, :SHOWN_SET => x)
for i=1:nf
Expand All @@ -135,7 +136,6 @@ function show_default(io::IO, x::ANY)
end
end
else
nb = t.size
print(io, "0x")
p = data_pointer_from_objref(x)
for i=nb-1:-1:0
Expand Down
23 changes: 12 additions & 11 deletions src/abi_aarch64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ static Type *get_llvm_vectype(jl_datatype_t *dt)
// Short vector should be either 8 bytes or 16 bytes.
// Note that there are only two distinct fundamental types for
// short vectors so we normalize them to <2 x i32> and <4 x i32>
switch (dt->size) {
switch (jl_datatype_size(dt)) {
case 8:
lltype = T_vec64;
break;
Expand Down Expand Up @@ -67,7 +67,7 @@ static Type *get_llvm_fptype(jl_datatype_t *dt)
// `!dt->mutabl && dt->pointerfree && !dt->haspadding && dt->nfields == 0`
Type *lltype;
// Check size first since it's cheaper.
switch (dt->size) {
switch (jl_datatype_size(dt)) {
case 2:
lltype = T_float16;
break;
Expand Down Expand Up @@ -111,7 +111,7 @@ static bool isHFAorHVA(jl_datatype_t *dt, size_t dsz, size_t &nele, ElementType
{
// Assume:
// dt is a pointerfree type, (all members are isbits)
// dsz == dt->size > 0
// dsz == jl_datatype_size(dt) > 0
// 0 <= nele <= 3
// dt has no padding

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

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

// C.11
// The NGRN is set to 8.
Expand Down
12 changes: 6 additions & 6 deletions src/abi_arm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ static Type *get_llvm_fptype(jl_datatype_t *dt)
return NULL;
Type *lltype;
// Check size first since it's cheaper.
switch (dt->size) {
switch (jl_datatype_size(dt)) {
case 2:
lltype = T_float16;
break;
Expand Down Expand Up @@ -88,7 +88,7 @@ static size_t isLegalHA(jl_datatype_t *dt, Type *&base)
if (jl_is_structtype(dt)) {
// Fast path checks before descending the type hierarchy
// (4 x 128b vector == 64B max size)
if (dt->size > 64 || !dt->layout->pointerfree || dt->layout->haspadding)
if (jl_datatype_size(dt) > 64 || !dt->layout->pointerfree || dt->layout->haspadding)
return 0;

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

// Handle fundamental types
if (jl_is_bitstype(dt) && dt->size <= 8) {
if (jl_is_bitstype(dt) && jl_datatype_size(dt) <= 8) {
*reg = true;
return;
}
Expand Down Expand Up @@ -283,7 +283,7 @@ Type *preferred_llvm_type(jl_datatype_t *dt, bool isret)
align = 8;

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

}
6 changes: 3 additions & 3 deletions src/abi_ppc64le.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ bool use_sret(AbiState *state, jl_datatype_t *dt)
{
jl_datatype_t *ty0 = NULL;
bool hva = false;
if (dt->size > 16 && isHFA(dt, &ty0, &hva) > 8)
if (jl_datatype_size(dt) > 16 && isHFA(dt, &ty0, &hva) > 8)
return true;
return false;
}
Expand All @@ -106,14 +106,14 @@ void needPassByRef(AbiState *state, jl_datatype_t *dt, bool *byRef, bool *inReg)
{
jl_datatype_t *ty0 = NULL;
bool hva = false;
if (dt->size > 64 && isHFA(dt, &ty0, &hva) > 8)
if (jl_datatype_size(dt) > 64 && isHFA(dt, &ty0, &hva) > 8)
*byRef = true;
}

Type *preferred_llvm_type(jl_datatype_t *dt, bool isret)
{
// Arguments are either scalar or passed by value
size_t size = dt->size;
size_t size = jl_datatype_size(dt);
// don't need to change bitstypes
if (!jl_datatype_nfields(dt))
return NULL;
Expand Down
4 changes: 2 additions & 2 deletions src/abi_win32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ bool use_sret(AbiState *state, jl_datatype_t *dt)
{
// Use sret if the size of the argument is not one of 1, 2, 4, 8 bytes
// This covers the special case of Complex64
size_t size = dt->size;
size_t size = jl_datatype_size(dt);
if (size == 1 || size == 2 || size == 4 || size == 8)
return false;
return true;
Expand All @@ -62,7 +62,7 @@ Type *preferred_llvm_type(jl_datatype_t *dt, bool isret)
// rewrite integer sized (non-sret) struct to the corresponding integer
if (!dt->layout->nfields)
return NULL;
return Type::getIntNTy(jl_LLVMContext, dt->size * 8);
return Type::getIntNTy(jl_LLVMContext, jl_datatype_nbits(dt));
}

bool need_private_copy(jl_value_t *ty, bool byRef)
Expand Down
2 changes: 1 addition & 1 deletion src/abi_win64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Type *preferred_llvm_type(jl_datatype_t *dt, bool isret)
{
size_t size = jl_datatype_size(dt);
if (size > 0 && size <= 8 && !jl_is_bitstype(dt))
return Type::getIntNTy(jl_LLVMContext, size*8);
return Type::getIntNTy(jl_LLVMContext, jl_datatype_nbits(dt));
return NULL;
}

Expand Down
7 changes: 4 additions & 3 deletions src/abi_x86_64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,8 @@ Type *preferred_llvm_type(jl_datatype_t *dt, bool isret)
if (is_native_simd_type(dt))
return NULL;

int size = jl_datatype_size(dt);
size_t size = jl_datatype_size(dt);
size_t nbits = jl_datatype_nbits(dt);
if (size > 16 || size == 0)
return NULL;

Expand All @@ -221,7 +222,7 @@ Type *preferred_llvm_type(jl_datatype_t *dt, bool isret)
if (size >= 8)
types[0] = T_int64;
else
types[0] = Type::getIntNTy(jl_LLVMContext, size*8);
types[0] = Type::getIntNTy(jl_LLVMContext, nbits);
break;
case Sse:
if (size <= 4)
Expand All @@ -237,7 +238,7 @@ Type *preferred_llvm_type(jl_datatype_t *dt, bool isret)
return types[0];
case Integer:
assert(size > 8);
types[1] = Type::getIntNTy(jl_LLVMContext, (size-8)*8);
types[1] = Type::getIntNTy(jl_LLVMContext, (nbits-64));
return StructType::get(jl_LLVMContext,ArrayRef<Type*>(&types[0],2));
case Sse:
if (size <= 12)
Expand Down
6 changes: 3 additions & 3 deletions src/alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ JL_DLLEXPORT jl_value_t *jl_new_struct(jl_datatype_t *type, ...)
va_list args;
size_t nf = jl_datatype_nfields(type);
va_start(args, type);
jl_value_t *jv = jl_gc_alloc(ptls, type->size, type);
jl_value_t *jv = jl_gc_alloc(ptls, jl_datatype_size(type), type);
for(size_t i=0; i < nf; i++) {
jl_set_nth_field(jv, i, va_arg(args, jl_value_t*));
}
Expand All @@ -243,7 +243,7 @@ JL_DLLEXPORT jl_value_t *jl_new_structv(jl_datatype_t *type, jl_value_t **args,
jl_ptls_t ptls = jl_get_ptls_states();
if (type->instance != NULL) return type->instance;
size_t nf = jl_datatype_nfields(type);
jl_value_t *jv = jl_gc_alloc(ptls, type->size, type);
jl_value_t *jv = jl_gc_alloc(ptls, jl_datatype_size(type), type);
for(size_t i=0; i < na; i++) {
jl_set_nth_field(jv, i, args[i]);
}
Expand All @@ -259,7 +259,7 @@ JL_DLLEXPORT jl_value_t *jl_new_struct_uninit(jl_datatype_t *type)
{
jl_ptls_t ptls = jl_get_ptls_states();
if (type->instance != NULL) return type->instance;
size_t size = type->size;
size_t size = jl_datatype_size(type);
jl_value_t *jv = jl_gc_alloc(ptls, size, type);
if (size > 0)
memset(jl_data_ptr(jv), 0, size);
Expand Down
4 changes: 2 additions & 2 deletions src/builtins.c
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ JL_DLLEXPORT int jl_egal(jl_value_t *a, jl_value_t *b)
return dta->name == dtb->name && compare_svec(dta->parameters, dtb->parameters);
}
if (dt->mutabl) return 0;
size_t sz = dt->size;
size_t sz = jl_datatype_size(dt);
if (sz == 0) return 1;
size_t nf = jl_datatype_nfields(dt);
if (nf == 0)
Expand Down Expand Up @@ -359,7 +359,7 @@ JL_CALLABLE(jl_f_sizeof)
jl_datatype_t *dx = (jl_datatype_t*)x;
if (dx->name == jl_array_typename || dx == jl_symbol_type || dx == jl_simplevector_type)
jl_error("type does not have a canonical binary representation");
if (!(dx->name->names == jl_emptysvec && dx->size > 0)) {
if (!(dx->name->names == jl_emptysvec && jl_datatype_size(dx) > 0)) {
// names===() and size > 0 => bitstype, size always known
if (dx->abstract || !jl_is_leaf_type(x))
jl_error("argument is an abstract type; size is indeterminate");
Expand Down
2 changes: 1 addition & 1 deletion src/ccall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1157,7 +1157,7 @@ static std::string generate_func_sig(
// see pull req #978. need to annotate signext/zeroext for
// small integer arguments.
jl_datatype_t *bt = (jl_datatype_t*)tti;
if (bt->size < 4) {
if (jl_datatype_size(bt) < 4) {
if (jl_signed_type && jl_subtype(tti, (jl_value_t*)jl_signed_type, 0))
av = Attribute::SExt;
else
Expand Down
16 changes: 8 additions & 8 deletions src/cgutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ static DIType julia_type_to_di(jl_value_t *jt, DIBuilder *dbuilder, bool isboxed
#endif
}
if (jl_is_bitstype(jt)) {
uint64_t SizeInBits = 8*jdt->size;
uint64_t SizeInBits = jl_datatype_nbits(jdt);
#if JL_LLVM_VERSION >= 30700
llvm::DIType *t = dbuilder->createBasicType(
jl_symbol_name(jdt->name->name),
Expand Down Expand Up @@ -149,7 +149,7 @@ static DIType julia_type_to_di(jl_value_t *jt, DIBuilder *dbuilder, bool isboxed
tname, // Name
NULL, // File
0, // LineNumber
8 * jdt->size, // SizeInBits
jl_datatype_nbits(jdt), // SizeInBits
8 * jdt->layout->alignment, // AlignInBits
DIFlagZero, // Flags
NULL, // DerivedFrom
Expand Down Expand Up @@ -345,10 +345,10 @@ JL_DLLEXPORT Type *julia_type_to_llvm(jl_value_t *jt, bool *isboxed)
else if (nb == 16)
return T_float128;
}
return Type::getIntNTy(jl_LLVMContext, nb*8);
return Type::getIntNTy(jl_LLVMContext, jl_datatype_nbits(jt));
}
if (jl_isbits(jt)) {
if (((jl_datatype_t*)jt)->size == 0) {
if (jl_datatype_nbits(jt) == 0) {
return T_void;
}
return julia_struct_to_llvm(jt, isboxed);
Expand All @@ -371,7 +371,7 @@ static Type *julia_struct_to_llvm(jl_value_t *jt, bool *isboxed)
jl_datatype_t *jst = (jl_datatype_t*)jt;
if (jst->struct_decl == NULL) {
size_t ntypes = jl_datatype_nfields(jst);
if (ntypes == 0 || jst->size == 0)
if (ntypes == 0 || jl_datatype_nbits(jst) == 0)
return T_void;
StructType *structdecl;
if (!isTuple) {
Expand Down Expand Up @@ -1519,7 +1519,7 @@ static Value *boxed(const jl_cgval_t &vinfo, jl_codectx_t *ctx, bool gcrooted)
assert("Don't know how to box this type" && false);
return NULL;
}
else if (!jb->abstract && jb->size == 0) {
else if (!jb->abstract && jl_datatype_nbits(jb) == 0) {
assert(jb->instance != NULL);
return literal_pointer_val(jb->instance);
}
Expand Down Expand Up @@ -1731,7 +1731,7 @@ static jl_cgval_t emit_new_struct(jl_value_t *ty, size_t nargs, jl_value_t **arg
f1 = boxed(fval_info, ctx);
j++;
}
Value *strct = emit_allocobj(ctx, sty->size,
Value *strct = emit_allocobj(ctx, jl_datatype_size(sty),
literal_pointer_val((jl_value_t*)ty));
jl_cgval_t strctinfo = mark_julia_type(strct, true, ty, ctx);
if (f1) {
Expand Down Expand Up @@ -1769,7 +1769,7 @@ static jl_cgval_t emit_new_struct(jl_value_t *ty, size_t nargs, jl_value_t **arg
}
else if (!sty->mutabl) {
// 0 fields, ghost or bitstype
if (sty->size == 0)
if (jl_datatype_nbits(sty) == 0)
return ghostValue(sty);
if (nargs >= 2)
return emit_expr(args[1], ctx); // do side effects
Expand Down
8 changes: 4 additions & 4 deletions src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2499,7 +2499,7 @@ static bool emit_builtin_call(jl_cgval_t *ret, jl_value_t *f, jl_value_t **args,
size_t nd = jl_is_long(ndp) ? jl_unbox_long(ndp) : 1;
Value *idx = emit_array_nd_index(ary, args[1], nd, &args[2], nargs-1, ctx);
if (jl_array_store_unboxed(ety) &&
((jl_datatype_t*)ety)->size == 0) {
jl_datatype_size(ety) == 0) {
assert(jl_is_datatype(ety));
assert(((jl_datatype_t*)ety)->instance != NULL);
*ret = ghostValue(ety);
Expand Down Expand Up @@ -2534,7 +2534,7 @@ static bool emit_builtin_call(jl_cgval_t *ret, jl_value_t *f, jl_value_t **args,
size_t nd = jl_is_long(ndp) ? jl_unbox_long(ndp) : 1;
Value *idx = emit_array_nd_index(ary, args[1], nd, &args[3], nargs-2, ctx);
bool isboxed = !jl_array_store_unboxed(ety);
if (!isboxed && ((jl_datatype_t*)ety)->size == 0) {
if (!isboxed && jl_datatype_size(ety) == 0) {
// no-op, but emit expr for possible effects
assert(jl_is_datatype(ety));
emit_expr(args[2], ctx);
Expand Down Expand Up @@ -2739,8 +2739,8 @@ static bool emit_builtin_call(jl_cgval_t *ret, jl_value_t *f, jl_value_t **args,
// this is issue #8798
sty != jl_datatype_type) {
if (jl_is_leaf_type((jl_value_t*)sty) ||
(sty->name->names == jl_emptysvec && sty->size > 0)) {
*ret = mark_julia_type(ConstantInt::get(T_size, sty->size), false, jl_long_type, ctx);
(sty->name->names == jl_emptysvec && jl_datatype_size(sty) > 0)) {
*ret = mark_julia_type(ConstantInt::get(T_size, jl_datatype_size(sty)), false, jl_long_type, ctx);
JL_GC_POP();
return true;
}
Expand Down
Loading