Skip to content

Added support for creating constant Rvalues backed by different intiger sizes. #71

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

Open
wants to merge 1 commit 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
16 changes: 15 additions & 1 deletion gcc/jit/libgccjit++.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,10 @@ namespace gccjit
int value) const;
rvalue new_rvalue (type numeric_type,
long value) const;
#ifdef __SIZEOF_INT128__
rvalue new_rvalue (type numeric_type,
__int128_t value) const;
#endif
rvalue zero (type numeric_type) const;
rvalue one (type numeric_type) const;
rvalue new_rvalue (type numeric_type,
Expand Down Expand Up @@ -941,7 +945,17 @@ context::new_rvalue (type numeric_type,
numeric_type.get_inner_type (),
value));
}

#ifdef __SIZEOF_INT128__
inline rvalue
context::new_rvalue (type numeric_type,
__int128_t value) const
{
return rvalue (
gcc_jit_context_new_rvalue_from_int128 (m_inner_ctxt,
numeric_type.get_inner_type (),
value));
}
#endif
inline rvalue
context::zero (type numeric_type) const
{
Expand Down
54 changes: 54 additions & 0 deletions gcc/jit/libgccjit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2020,6 +2020,35 @@ gcc_jit_rvalue_set_type (gcc_jit_rvalue *rvalue, gcc_jit_type *new_type)
"not a numeric type: %s", \
NUMERIC_TYPE->get_debug_string ()); \
JIT_END_STMT
/* Public entrypoint. See description in libgccjit.h.

After error-checking, the real work is done by the
gcc::jit::recording::context::new_rvalue_from_const <int> method in
jit-recording.cc. */
gcc_jit_rvalue *
gcc_jit_context_new_rvalue_from_char (gcc_jit_context *ctxt,
gcc_jit_type *numeric_type,
char value)
{
RETURN_NULL_IF_FAIL (ctxt, NULL, NULL, "NULL context");
JIT_LOG_FUNC (ctxt->get_logger ());
RETURN_NULL_IF_FAIL_NONNULL_NUMERIC_TYPE (ctxt, numeric_type);

return ((gcc_jit_rvalue *)ctxt
->new_rvalue_from_const <char> (numeric_type, value));
}
gcc_jit_rvalue *
gcc_jit_context_new_rvalue_from_short (gcc_jit_context *ctxt,
gcc_jit_type *numeric_type,
short value)
{
RETURN_NULL_IF_FAIL (ctxt, NULL, NULL, "NULL context");
JIT_LOG_FUNC (ctxt->get_logger ());
RETURN_NULL_IF_FAIL_NONNULL_NUMERIC_TYPE (ctxt, numeric_type);

return ((gcc_jit_rvalue *)ctxt
->new_rvalue_from_const <short> (numeric_type, value));
}

/* Public entrypoint. See description in libgccjit.h.

Expand Down Expand Up @@ -2058,7 +2087,20 @@ gcc_jit_context_new_rvalue_from_long (gcc_jit_context *ctxt,
return ((gcc_jit_rvalue *)ctxt
->new_rvalue_from_const <long> (numeric_type, value));
}
#ifdef __SIZEOF_INT128__
Copy link

Choose a reason for hiding this comment

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

I believe the way we should handle the case where 128-bit integers are not supported is by adding an error and returning NULL: so the function would still be defined on targets that don't support them.

gcc_jit_rvalue *
gcc_jit_context_new_rvalue_from_int128 (gcc_jit_context *ctxt,
gcc_jit_type *numeric_type,
__int128_t value)
{
RETURN_NULL_IF_FAIL (ctxt, NULL, NULL, "NULL context");
JIT_LOG_FUNC (ctxt->get_logger ());
RETURN_NULL_IF_FAIL_NONNULL_NUMERIC_TYPE (ctxt, numeric_type);

return ((gcc_jit_rvalue *)ctxt
->new_rvalue_from_const <__int128_t> (numeric_type, value));
}
#endif
/* Public entrypoint. See description in libgccjit.h.

This is essentially equivalent to:
Expand Down Expand Up @@ -2111,6 +2153,18 @@ gcc_jit_context_new_rvalue_from_double (gcc_jit_context *ctxt,
return ((gcc_jit_rvalue *)ctxt
->new_rvalue_from_const <double> (numeric_type, value));
}
gcc_jit_rvalue *
Copy link

Choose a reason for hiding this comment

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

Suggested change
gcc_jit_rvalue *
gcc_jit_rvalue *

gcc_jit_context_new_rvalue_from_float (gcc_jit_context *ctxt,
gcc_jit_type *numeric_type,
float value)
{
RETURN_NULL_IF_FAIL (ctxt, NULL, NULL, "NULL context");
JIT_LOG_FUNC (ctxt->get_logger ());
RETURN_NULL_IF_FAIL_NONNULL_NUMERIC_TYPE (ctxt, numeric_type);

return ((gcc_jit_rvalue *)ctxt
->new_rvalue_from_const <float> (numeric_type, value));
}

/* Public entrypoint. See description in libgccjit.h.

Expand Down
20 changes: 18 additions & 2 deletions gcc/jit/libgccjit.h
Original file line number Diff line number Diff line change
Expand Up @@ -1098,6 +1098,14 @@ gcc_jit_rvalue_set_type (gcc_jit_rvalue *rvalue, gcc_jit_type *new_type);

/* Integer constants. */
extern gcc_jit_rvalue *
gcc_jit_context_new_rvalue_from_char (gcc_jit_context *ctxt,
gcc_jit_type *numeric_type,
char value);
extern gcc_jit_rvalue *
gcc_jit_context_new_rvalue_from_short (gcc_jit_context *ctxt,
gcc_jit_type *numeric_type,
short value);
extern gcc_jit_rvalue *
gcc_jit_context_new_rvalue_from_int (gcc_jit_context *ctxt,
gcc_jit_type *numeric_type,
int value);
Expand All @@ -1106,7 +1114,12 @@ extern gcc_jit_rvalue *
gcc_jit_context_new_rvalue_from_long (gcc_jit_context *ctxt,
gcc_jit_type *numeric_type,
long value);

#ifdef __SIZEOF_INT128__
extern gcc_jit_rvalue *
gcc_jit_context_new_rvalue_from_int128 (gcc_jit_context *ctxt,
gcc_jit_type *numeric_type,
__int128_t value);
#endif
extern gcc_jit_rvalue *
gcc_jit_context_zero (gcc_jit_context *ctxt,
gcc_jit_type *numeric_type);
Expand All @@ -1120,7 +1133,10 @@ extern gcc_jit_rvalue *
gcc_jit_context_new_rvalue_from_double (gcc_jit_context *ctxt,
gcc_jit_type *numeric_type,
double value);

extern gcc_jit_rvalue *
gcc_jit_context_new_rvalue_from_float(gcc_jit_context *ctxt,
gcc_jit_type *numeric_type,
float value);
/* Pointers. */
extern gcc_jit_rvalue *
gcc_jit_context_new_rvalue_from_ptr (gcc_jit_context *ctxt,
Expand Down
7 changes: 7 additions & 0 deletions gcc/jit/libgccjit.map
Original file line number Diff line number Diff line change
Expand Up @@ -373,3 +373,10 @@ LIBGCCJIT_ABI_42 {
global:
gcc_jit_lvalue_add_attribute;
} LIBGCCJIT_ABI_41;
LIBGCCJIT_ABI_43 {
Copy link

Choose a reason for hiding this comment

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

Suggested change
LIBGCCJIT_ABI_43 {
LIBGCCJIT_ABI_43 {

global:
gcc_jit_context_new_rvalue_from_float;
gcc_jit_context_new_rvalue_from_int128;
gcc_jit_context_new_rvalue_from_short;
gcc_jit_context_new_rvalue_from_char;
} LIBGCCJIT_ABI_42;