Skip to content

Commit a476be0

Browse files
authored
Merge pull request #51 from zedar/add_git_jit_type_is_float
add git_jit_type_is_float()
2 parents 4c5565b + a6d92cb commit a476be0

File tree

5 files changed

+76
-0
lines changed

5 files changed

+76
-0
lines changed

gcc/jit/docs/topics/types.rst

+5
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,11 @@ Reflection API
436436
437437
Return non-zero if the type is an integral.
438438

439+
.. function:: int\
440+
gcc_jit_type_is_floating_point (gcc_jit_type *type)
441+
442+
Return non-zero if the type is floating point.
443+
439444
.. function:: gcc_jit_type *\
440445
gcc_jit_type_is_pointer (gcc_jit_type *type)
441446

gcc/jit/libgccjit.cc

+17
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,23 @@ gcc_jit_type_is_integral (gcc_jit_type *type)
650650
return type->is_int ();
651651
}
652652

653+
/* Public entrypoint. See description in libgccjit.h.
654+
655+
After error-checking, the real work is done by the
656+
gcc::jit::recording::type::is_float method, in
657+
jit-recording.cc. */
658+
659+
int
660+
gcc_jit_type_is_floating_point (gcc_jit_type *type)
661+
{
662+
RETURN_VAL_IF_FAIL (type, FALSE, NULL, NULL, "NULL type");
663+
664+
if (type->is_vector())
665+
return false;
666+
667+
return type->is_float ();
668+
}
669+
653670
/* Public entrypoint. See description in libgccjit.h.
654671
655672
After error-checking, the real work is done by the

gcc/jit/libgccjit.h

+4
Original file line numberDiff line numberDiff line change
@@ -2091,6 +2091,10 @@ gcc_jit_function_type_get_param_type (gcc_jit_function_type *function_type,
20912091
extern int
20922092
gcc_jit_type_is_integral (gcc_jit_type *type);
20932093

2094+
/* Return non-zero if the type is floating point */
2095+
extern int
2096+
gcc_jit_type_is_floating_point(gcc_jit_type * type);
2097+
20942098
/* Return the type pointed by the pointer type or NULL if it's not a
20952099
* pointer. */
20962100
extern gcc_jit_type *

gcc/jit/libgccjit.map

+5
Original file line numberDiff line numberDiff line change
@@ -357,3 +357,8 @@ LIBGCCJIT_ABI_39 {
357357
global:
358358
gcc_jit_target_info_supports_target_dependent_type;
359359
} LIBGCCJIT_ABI_38;
360+
361+
LIBGCCJIT_ABI_40 {
362+
global:
363+
gcc_jit_type_is_floating_point;
364+
} LIBGCCJIT_ABI_39;

gcc/testsuite/jit.dg/test-reflection.c

+45
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,52 @@ verify_code (gcc_jit_context *ctxt, gcc_jit_result *result)
2424
gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_DOUBLE);
2525
CHECK_VALUE (gcc_jit_function_get_return_type(builtin_sin), double_type);
2626
CHECK (!gcc_jit_type_is_integral(double_type));
27+
CHECK (gcc_jit_type_is_floating_point(double_type));
28+
29+
gcc_jit_type *float_type =
30+
gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_FLOAT);
31+
CHECK (!gcc_jit_type_is_bool(float_type));
32+
CHECK (!gcc_jit_type_is_integral(float_type));
33+
CHECK (gcc_jit_type_is_floating_point(float_type));
34+
35+
gcc_jit_target_info *target_info = gcc_jit_context_get_target_info(ctxt);
36+
if (target_info != NULL && gcc_jit_target_info_supports_target_dependent_type(target_info, GCC_JIT_TYPE_FLOAT16))
37+
{
38+
gcc_jit_type *float16_type = gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_FLOAT16);
39+
CHECK (!gcc_jit_type_is_bool(float16_type));
40+
CHECK (!gcc_jit_type_is_integral(float16_type));
41+
CHECK (gcc_jit_type_is_floating_point(float16_type));
42+
}
43+
44+
if (target_info != NULL && gcc_jit_target_info_supports_target_dependent_type(target_info, GCC_JIT_TYPE_FLOAT32))
45+
{
46+
gcc_jit_type *float32_type = gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_FLOAT32);
47+
CHECK (!gcc_jit_type_is_bool(float32_type));
48+
CHECK (!gcc_jit_type_is_integral(float32_type));
49+
CHECK (gcc_jit_type_is_floating_point(float32_type));
50+
}
51+
52+
if (target_info != NULL && gcc_jit_target_info_supports_target_dependent_type(target_info, GCC_JIT_TYPE_FLOAT64))
53+
{
54+
gcc_jit_type *float64_type = gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_FLOAT64);
55+
CHECK (!gcc_jit_type_is_bool(float64_type));
56+
CHECK (!gcc_jit_type_is_integral(float64_type));
57+
CHECK (gcc_jit_type_is_floating_point(float64_type));
58+
}
59+
60+
if (target_info != NULL && gcc_jit_target_info_supports_target_dependent_type(target_info, GCC_JIT_TYPE_FLOAT128))
61+
{
62+
gcc_jit_type *float128_type = gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_FLOAT128);
63+
CHECK (!gcc_jit_type_is_bool(float128_type));
64+
CHECK (!gcc_jit_type_is_integral(float128_type));
65+
CHECK (gcc_jit_type_is_floating_point(float128_type));
66+
}
2767

2868
gcc_jit_type *bool_type =
2969
gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_BOOL);
3070
CHECK (gcc_jit_type_is_bool(bool_type));
3171
CHECK (!gcc_jit_type_is_integral(bool_type));
72+
CHECK (!gcc_jit_type_is_floating_point(bool_type));
3273

3374
gcc_jit_type *aligned_bool_type =
3475
gcc_jit_type_get_aligned(gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_BOOL), 8);
@@ -42,15 +83,19 @@ verify_code (gcc_jit_context *ctxt, gcc_jit_result *result)
4283
gcc_jit_type *int64 =
4384
gcc_jit_context_get_int_type(ctxt, 8, 1);
4485
CHECK (gcc_jit_type_is_integral(int64));
86+
CHECK (!gcc_jit_type_is_floating_point(int64));
4587
gcc_jit_type *uint64 =
4688
gcc_jit_context_get_int_type(ctxt, 8, 0);
4789
CHECK (gcc_jit_type_is_integral(uint64));
90+
CHECK (!gcc_jit_type_is_floating_point(uint64));
4891
gcc_jit_type *int8 =
4992
gcc_jit_context_get_int_type(ctxt, 1, 1);
5093
CHECK (gcc_jit_type_is_integral(int8));
94+
CHECK (!gcc_jit_type_is_floating_point(int8));
5195
gcc_jit_type *uint8 =
5296
gcc_jit_context_get_int_type(ctxt, 1, 0);
5397
CHECK (gcc_jit_type_is_integral(uint8));
98+
CHECK (!gcc_jit_type_is_floating_point(uint8));
5499

55100
CHECK (!gcc_jit_type_dyncast_vector(double_type));
56101
gcc_jit_type *vec_type = gcc_jit_type_get_vector (double_type, 4);

0 commit comments

Comments
 (0)