- 
                Notifications
    
You must be signed in to change notification settings  - Fork 18
 
Add support for setting the inline attribute #3
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
Conversation
2021-05-20 Antoni Boucher <[email protected]> gcc/jit/ PR target/96089 * docs/topics/compatibility.rst (LIBGCCJIT_ABI_19): New ABI tag. * docs/topics/expressions.rst: Add documentation for the function gcc_jit_global_set_initializer_value. * jit-playback.c: New function (new_global_with_value). * jit-playback.h: New function (new_global_with_value). * jit-recording.c: Add support for setting a value to a global variable. * jit-recording.h: New function (set_initializer_value) and new field m_initializer_value. * libgccjit.c: New macro RETURN_IF_FAIL_PRINTF5 and new function (gcc_jit_global_set_initializer_value). * libgccjit.h: New function (gcc_jit_global_set_initializer_value). * libgccjit.map (LIBGCCJIT_ABI_19): New ABI tag. gcc/testsuite/ PR target/96089 * jit.dg/test-global-set-initializer.c: Add test for the new function (gcc_jit_global_set_initializer_value). Signed-off-by: Antoni Boucher <[email protected]>
2021-05-19 Antoni Boucher <[email protected]> gcc/jit/ PR target/100688 * docs/topics/compatibility.rst (LIBGCCJIT_ABI_18): New ABI tag. * docs/topics/expressions.rst: Add documentation for the function gcc_jit_lvalue_set_link_section. * jit-playback.h: New function (set_link_section) and rvalue::m_inner protected. * jit-recording.c: New function (set_link_section) and support for setting the link section. * jit-recording.h: New function (set_link_section) and new field m_link_section. * libgccjit.c: New function (gcc_jit_lvalue_set_link_section). * libgccjit.h: New function (gcc_jit_lvalue_set_link_section). * libgccjit.map (LIBGCCJIT_ABI_18): New ABI tag. gcc/testsuite/ PR target/100688 * jit.dg/all-non-failing-tests.h: Add test-link-section.c. * jit.dg/test-link_section.c: New test. Signed-off-by: Antoni Boucher <[email protected]>
…325] 2021-05-18 Antoni Boucher <[email protected]> gcc/jit/ PR target/95325 * docs/topics/types.rst: Add documentation for the new types GCC_JIT_TYPE_UINT8_T, GCC_JIT_TYPE_UINT16_T, GCC_JIT_TYPE_UINT32_T, GCC_JIT_TYPE_UINT64_T, GCC_JIT_TYPE_UINT128_T, GCC_JIT_TYPE_INT8_T, GCC_JIT_TYPE_INT16_T, GCC_JIT_TYPE_INT32_T, GCC_JIT_TYPE_INT64_T, GCC_JIT_TYPE_INT128_T. * jit-playback.c: Add support for the sized integer types. * jit-recording.c: Add support for the sized integer types. * libgccjit.h (GCC_JIT_TYPE_UINT8_T, GCC_JIT_TYPE_UINT16_T, GCC_JIT_TYPE_UINT32_T, GCC_JIT_TYPE_UINT64_T, GCC_JIT_TYPE_UINT128_T, GCC_JIT_TYPE_INT8_T, GCC_JIT_TYPE_INT16_T, GCC_JIT_TYPE_INT32_T, GCC_JIT_TYPE_INT64_T, GCC_JIT_TYPE_INT128_T): New enum variants for gcc_jit_types. gcc/testsuite/ PR target/95325 * jit.dg/test-types.c: Add tests for sized integer types. Signed-off-by: Antoni Boucher <[email protected]>
2021-05-18 Antoni Boucher <[email protected]> gcc/jit/ PR target/95415 * docs/topics/compatibility.rst (LIBGCCJIT_ABI_17): New ABI tag. * docs/topics/expressions.rst: Add document for the function gcc_jit_lvalue_set_tls_model. * jit-playback.h: New function (set_tls_model) and make rvalue::m_inner public. * jit-recording.c: New function (set_tls_model), new variables (tls_models and tls_model_enum_strings) and support for setting the tls model. * jit-recording.h: New function (set_tls_model) and new field m_tls_model. * libgccjit.c: New function (gcc_jit_lvalue_set_tls_model). * libgccjit.h: New function (gcc_jit_lvalue_set_tls_model) and new enum (gcc_jit_tls_model). * libgccjit.map (LIBGCCJIT_ABI_17): New ABI tag. gcc/testsuite/ PR target/95415 * jit.dg/all-non-failing-tests.h: Add test-tls.c. * jit.dg/test-tls.c: New test. Signed-off-by: Antoni Boucher <[email protected]>
2021-05-17 Antoni Boucher <[email protected]> gcc/jit/ PR target/PR96066 PR target/PR96067 * jit-builtins.c: Implement missing types for builtins. * jit-recording.c:: Allow sending a volatile const void * as argument. gcc/testsuite/ PR target/PR96066 PR target/PR96067 * jit.dg/all-non-failing-tests.h: Add test-builtin-types.c. * jit.dg/test-builtin-types.c Signed-off-by: Antoni Boucher <[email protected]>
2020-09-1 Antoni Boucher <[email protected]> gcc/jit/ PR target/96889 * docs/topics/compatibility.rst (LIBGCCJIT_ABI_16): New ABI tag. * docs/topics/functions.rst: Add documentation for the functions gcc_jit_function_get_return_type and gcc_jit_function_get_param_count * docs/topics/types.rst: Add documentation for the functions gcc_jit_function_type_get_return_type, gcc_jit_function_type_get_param_count, gcc_jit_function_type_get_param_type, gcc_jit_type_unqualified, gcc_jit_type_is_array, gcc_jit_type_is_bool, gcc_jit_type_is_function_ptr_type, gcc_jit_type_is_integral, gcc_jit_type_is_pointer, gcc_jit_type_is_vector, gcc_jit_vector_type_get_element_type, gcc_jit_vector_type_get_num_units, gcc_jit_struct_get_field, gcc_jit_type_is_struct, and gcc_jit_struct_get_field_count * libgccjit.c: (gcc_jit_function_get_return_type, gcc_jit_function_get_param_count, gcc_jit_function_type_get_return_type, gcc_jit_function_type_get_param_count, gcc_jit_function_type_get_param_type, gcc_jit_type_unqualified, gcc_jit_type_is_array, gcc_jit_type_is_bool, gcc_jit_type_is_function_ptr_type, gcc_jit_type_is_integral, gcc_jit_type_is_pointer, gcc_jit_type_is_vector, gcc_jit_vector_type_get_element_type, gcc_jit_vector_type_get_num_units, gcc_jit_struct_get_field, gcc_jit_type_is_struct, gcc_jit_struct_get_field_count): New functions. (struct gcc_jit_function_type, struct gcc_jit_vector_type): New types. * libgccjit.h: (gcc_jit_function_get_return_type, gcc_jit_function_get_param_count, gcc_jit_function_type_get_return_type, gcc_jit_function_type_get_param_count, gcc_jit_function_type_get_param_type, gcc_jit_type_unqualified, gcc_jit_type_is_array, gcc_jit_type_is_bool, gcc_jit_type_is_function_ptr_type, gcc_jit_type_is_integral, gcc_jit_type_is_pointer, gcc_jit_type_is_vector, gcc_jit_vector_type_get_element_type, gcc_jit_vector_type_get_num_units, gcc_jit_struct_get_field, gcc_jit_type_is_struct, gcc_jit_struct_get_field_count): New function declarations. (struct gcc_jit_function_type, struct gcc_jit_vector_type): New types. * jit-recording.h: New functions (is_struct and is_vector) * libgccjit.map (LIBGCCJIT_ABI_16): New ABI tag. gcc/testsuite/ PR target/96889 * jit.dg/all-non-failing-tests.h: Add test-reflection.c. * jit.dg/test-reflection.c: New test. Signed-off-by: Antoni Boucher <[email protected]>
2020-07-12 Antoni Boucher <[email protected]> gcc/jit/ PR target/95498 * jit-playback.c: Add support to handle truncation and extension in the convert function. gcc/testsuite/ PR target/95498 * jit.dg/all-non-failing-tests.h: New test. * jit.dg/test-cast.c: New test. Signed-off-by: Antoni Boucher <[email protected]>
Build and upload artifact on GitHub Actions
…rs [PR95325]" This reverts commit d8f75a8.
…325] 2021-05-18 Antoni Boucher <[email protected]> gcc/jit/ PR target/95325 * docs/topics/types.rst: Add documentation for the new types GCC_JIT_TYPE_UINT8_T, GCC_JIT_TYPE_UINT16_T, GCC_JIT_TYPE_UINT32_T, GCC_JIT_TYPE_UINT64_T, GCC_JIT_TYPE_UINT128_T, GCC_JIT_TYPE_INT8_T, GCC_JIT_TYPE_INT16_T, GCC_JIT_TYPE_INT32_T, GCC_JIT_TYPE_INT64_T, GCC_JIT_TYPE_INT128_T. * jit-builtins.c: Add support for BT_UINT128. * jit-playback.c: Add support for the sized integer types. * jit-recording.c: Add support for the sized integer types. * libgccjit.h (GCC_JIT_TYPE_UINT8_T, GCC_JIT_TYPE_UINT16_T, GCC_JIT_TYPE_UINT32_T, GCC_JIT_TYPE_UINT64_T, GCC_JIT_TYPE_UINT128_T, GCC_JIT_TYPE_INT8_T, GCC_JIT_TYPE_INT16_T, GCC_JIT_TYPE_INT32_T, GCC_JIT_TYPE_INT64_T, GCC_JIT_TYPE_INT128_T): New enum variants for gcc_jit_types. gcc/testsuite/ PR target/95325 * jit.dg/test-types.c: Add tests for sized integer types. Signed-off-by: Antoni Boucher <[email protected]>
…R96089]" This reverts commit f2a6769.
TODO: fail if global kind is imported TODO: doc 2021-05-20 Antoni Boucher <[email protected]> gcc/jit/ PR target/96089 * docs/topics/compatibility.rst (LIBGCCJIT_ABI_19): New ABI tag. * docs/topics/expressions.rst: Add documentation for the function gcc_jit_global_set_initializer_value. * jit-playback.c: New functions (new_global_with_value, set_global_initial_value, new_rvalue_from_struct, new_rvalue_from_array). * jit-playback.h: New functions (new_global_with_value, set_global_initial_value, new_rvalue_from_struct, new_rvalue_from_array). * jit-recording.c: Add support for setting a value to a global variable and new methods (global_initializer::write_reproducer, global_initializer::make_debug_string, global_initializer::write_to_dump, global_initializer::replay_into, context::new_global_value_initializer, memento_of_new_rvalue_from_struct::write_reproducer, memento_of_new_rvalue_from_struct::make_debug_string, memento_of_new_rvalue_from_struct::visit_children, memento_of_new_rvalue_from_struct::replay_into, memento_of_new_rvalue_from_struct:: memento_of_new_rvalue_from_struct, context::new_rvalue_from_struct, memento_of_new_rvalue_from_array::write_reproducer, memento_of_new_rvalue_from_array::make_debug_string, memento_of_new_rvalue_from_array::visit_children, memento_of_new_rvalue_from_array::replay_into, memento_of_new_rvalue_from_array:: memento_of_new_rvalue_from_array, new_rvalue_from_array). * jit-recording.h: New functions (set_initializer_value, new_global_value_initializer, new_rvalue_from_struct, new_rvalue_from_array), new field m_initializer_value and new classes (global_initializer, memento_of_new_rvalue_from_struct, memento_of_new_rvalue_from_array). * libgccjit.c: New macro RETURN_IF_FAIL_PRINTF5 and new functions (gcc_jit_global_set_initializer_value, gcc_jit_context_new_rvalue_from_struct, gcc_jit_context_new_rvalue_from_array). * libgccjit.h: New functions (gcc_jit_global_set_initializer_value, gcc_jit_context_new_rvalue_from_struct, gcc_jit_context_new_rvalue_from_array). * libgccjit.map (LIBGCCJIT_ABI_19): New ABI tag. gcc/testsuite/ PR target/96089 * jit.dg/test-global-set-initializer.c: Add test for the new function (gcc_jit_global_set_initializer_value).
| break; | ||
| case GCC_JIT_INLINE_MODE_ALWAYS_INLINE: | ||
| DECL_DECLARED_INLINE_P (fndecl) = 1; | ||
| DECL_DISREGARD_INLINE_LIMITS (fndecl) = 1; // FIXME: this line breaks compilation of sysroot, but seems required to make inlining work. | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a recursive #[inline(always)] function in libcore. Maybe that is the problem? In rust even #[inline(always)] is just a hint that should be ignored if it is impossible to inline.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a quick workaround, we could check in rustc_cg_gcc if the function is recursive and then refuse to emit any inline attributes for it. I highly doubt that DECL_DISREGARD_INLINE_LIMITS is a good idea here. I'll test tomorrow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Commeownist Why not? The doc says This is equivalent to using the always_inline attribute without the required diagnostics if the function cannot be inlined., but I'm not sure what it actually means. I'll have to read more code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@antoyo DECL_DISREGARD_INLINE_LIMITS is totally correct here, see this function. My mistake, confused it with something else.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function seems to actually check whether the function being inlined is recursive.
| 
           I've been secretly working on it yesterday. It's chaotic ATM so I'll publish it tomorrow, but here are my thoughts: 
 You don't need this access. If you take a hard look at  if you look at your own patch, you'll see that you also adding the  So this is how I'd do it: // C API
void gcc_jit_function_add_attribute (gcc_jit_function *func, const char *attr)
{
  func->add_attribute (attr);
}
// jit-recording.h
class function : public memento
{
public:
  // ... snip ...
  virtual void add_attribute (const char *attr)  // <= add attribute
  { m_attributes.safe_push(attr); }
private:
  location *m_loc;
  enum gcc_jit_function_kind m_kind;
  type *m_return_type;
  auto_vec<string> m_attributes; // <= stored list of attrs
  string *m_name;
  auto_vec<param *> m_params;
  int m_is_variadic;
  enum built_in_function m_builtin_id;
  auto_vec<local *> m_locals;
  auto_vec<block *> m_blocks;
  type *m_fn_ptr_type;
};
// jit-playback.c
playback::function* playback::context::new_function (
              location *loc,
	      enum gcc_jit_function_kind kind,
	      type *return_type,
              auto_vec<string> *attributes, // <= pass stored attrs
	      const char *name,
	      const auto_vec<param *> *params,
	      int is_variadic,
	      enum built_in_function builtin_id)
{
  // ... snip ...
  // apply attributes
  FOR_EACH_VEC_ELT (*attributes, i, attr) {
    DECL_ATTRIBUTES (fndecl) = tree_cons (
           get_identifier (attr), 
 	   NULL, 
 	   DECL_ATTRIBUTES (fndecl)); 
}
 This was a quick pseudocode, but I think the idea is clear. I think the attributes-driven approach is more powerful, especially if we'll want to extend this to other attributes in future. Some examples I predict will come up: the  
 Yes, that's right. Keep in mind that  How about a hybrid approach? You add   | 
    
          
 Alternatively, we could take your current approach - which I like because it prevents the conflicting situation of   | 
    
          
 Yup, I like this.  | 
    
0a94141    to
    17858b5      
    Compare
  
    Whenever C1 and C2 are integer constants, X is of a wrapping type, and cmp is a relational operator, the expression X +- C1 cmp C2 can be simplified in the following cases: (a) If cmp is <= and C2 -+ C1 == +INF(1), we can transform the initial comparison in the following way: X +- C1 <= C2 -INF <= X +- C1 <= C2 (add left hand side which holds for any X, C1) -INF -+ C1 <= X <= C2 -+ C1 (add -+C1 to all 3 expressions) -INF -+ C1 <= X <= +INF (due to (1)) -INF -+ C1 <= X (eliminate the right hand side since it holds for any X) (b) By analogy, if cmp if >= and C2 -+ C1 == -INF(1), use the following sequence of transformations: X +- C1 >= C2 +INF >= X +- C1 >= C2 (add left hand side which holds for any X, C1) +INF -+ C1 >= X >= C2 -+ C1 (add -+C1 to all 3 expressions) +INF -+ C1 >= X >= -INF (due to (1)) +INF -+ C1 >= X (eliminate the right hand side since it holds for any X) (c) The > and < cases are negations of (a) and (b), respectively. This transformation allows to occasionally save add / sub instructions, for instance the expression 3 + (uint32_t)f() < 2 compiles to cmn w0, #4 cset w0, ls instead of add w0, w0, 3 cmp w0, 2 cset w0, ls on aarch64. Testcases that go together with this patch have been split into two separate files, one containing testcases for unsigned variables and the other for wrapping signed ones (and thus compiled with -fwrapv). Additionally, one aarch64 test has been adjusted since the patch has caused the generated code to change from cmn w0, #2 csinc w0, w1, wzr, cc (x < -2) to cmn w0, #3 csinc w0, w1, wzr, cs (x <= -3) This patch has been bootstrapped and regtested on aarch64, x86_64, and i386, and additionally regtested on riscv32. gcc/ChangeLog: PR tree-optimization/116024 * match.pd: New transformation around integer comparison. gcc/testsuite/ChangeLog: * gcc.dg/tree-ssa/pr116024-2.c: New test. * gcc.dg/tree-ssa/pr116024-2-fwrapv.c: Ditto. * gcc.target/aarch64/gtu_to_ltu_cmp_1.c: Adjust.
This patch folds svindex with constant arguments into a vector series.
We implemented this in svindex_impl::fold using the function build_vec_series.
For example,
svuint64_t f1 ()
{
  return svindex_u642 (10, 3);
}
compiled with -O2 -march=armv8.2-a+sve, is folded to {10, 13, 16, ...}
in the gimple pass lower.
This optimization benefits cases where svindex is used in combination with
other gimple-level optimizations.
For example,
svuint64_t f2 ()
{
    return svmul_x (svptrue_b64 (), svindex_u64 (10, 3), 5);
}
has previously been compiled to
f2:
        index   z0.d, #10, #3
        mul     z0.d, z0.d, #5
        ret
Now, it is compiled to
f2:
        mov     x0, 50
        index   z0.d, x0, #15
        ret
We added test cases checking
- the application of the transform during gimple for constant arguments,
- the interaction with another gimple-level optimization.
The patch was bootstrapped and regtested on aarch64-linux-gnu, no regression.
OK for mainline?
Signed-off-by: Jennifer Schmitz <[email protected]>
gcc/
	* config/aarch64/aarch64-sve-builtins-base.cc
	(svindex_impl::fold): Add constant folding.
gcc/testsuite/
	* gcc.target/aarch64/sve/index_const_fold.c: New test.
    This patch adds a new param vect-scalar-cost-multiplier to scale the scalar
costing during vectorization.  If the cost is set high enough and when using
the dynamic cost model it has the effect of effectively disabling the
costing vs scalar and assumes all vectorization to be profitable.
This is similar to using the unlimited cost model, but unlike unlimited it
does not fully disable the vector cost model.  That means that we still
perform comparisons between vector modes.  And it means it also still does
costing for alias analysis.
As an example, the following:
void
foo (char *restrict a, int *restrict b, int *restrict c,
     int *restrict d, int stride)
{
    if (stride <= 1)
        return;
    for (int i = 0; i < 3; i++)
        {
            int res = c[i];
            int t = b[i * stride];
            if (a[i] != 0)
                res = t * d[i];
            c[i] = res;
        }
}
compiled with -O3 -march=armv8-a+sve -fvect-cost-model=dynamic fails to
vectorize as it assumes scalar would be faster, and with
-fvect-cost-model=unlimited it picks a vector type that's so big that the large
sequence generated is working on mostly inactive lanes:
        ...
        and     p3.b, p3/z, p4.b, p4.b
        whilelo p0.s, wzr, w7
        ld1w    z23.s, p3/z, [x3, #3, mul vl]
        ld1w    z28.s, p0/z, [x5, z31.s, sxtw 2]
        add     x0, x5, x0
        punpklo p6.h, p6.b
        ld1w    z27.s, p4/z, [x0, z31.s, sxtw 2]
        and     p6.b, p6/z, p0.b, p0.b
        punpklo p4.h, p7.b
        ld1w    z24.s, p6/z, [x3, #2, mul vl]
        and     p4.b, p4/z, p2.b, p2.b
        uqdecw  w6
        ld1w    z26.s, p4/z, [x3]
        whilelo p1.s, wzr, w6
        mul     z27.s, p5/m, z27.s, z23.s
        ld1w    z29.s, p1/z, [x4, z31.s, sxtw 2]
        punpkhi p7.h, p7.b
        mul     z24.s, p5/m, z24.s, z28.s
        and     p7.b, p7/z, p1.b, p1.b
        mul     z26.s, p5/m, z26.s, z30.s
        ld1w    z25.s, p7/z, [x3, #1, mul vl]
        st1w    z27.s, p3, [x2, #3, mul vl]
        mul     z25.s, p5/m, z25.s, z29.s
        st1w    z24.s, p6, [x2, #2, mul vl]
        st1w    z25.s, p7, [x2, #1, mul vl]
        st1w    z26.s, p4, [x2]
        ...
With -fvect-cost-model=dynamic --param vect-scalar-cost-multiplier=200
you get more reasonable code:
foo:
        cmp     w4, 1
        ble     .L1
        ptrue   p7.s, vl3
        index   z0.s, #0, w4
        ld1b    z29.s, p7/z, [x0]
        ld1w    z30.s, p7/z, [x1, z0.s, sxtw 2]
	ptrue   p6.b, all
        cmpne   p7.b, p7/z, z29.b, #0
        ld1w    z31.s, p7/z, [x3]
	mul     z31.s, p6/m, z31.s, z30.s
        st1w    z31.s, p7, [x2]
.L1:
        ret
This model has been useful internally for performance exploration and cost-model
validation.  It allows us to force realistic vectorization overriding the cost
model to be able to tell whether it's correct wrt to profitability.
gcc/ChangeLog:
	* params.opt (vect-scalar-cost-multiplier): New.
	* tree-vect-loop.cc (vect_estimate_min_profitable_iters): Use it.
	* doc/invoke.texi (vect-scalar-cost-multiplier): Document it.
gcc/testsuite/ChangeLog:
	* gcc.target/aarch64/sve/cost_model_16.c: New test.
    
@Commeownist Here's the work I started for rust-lang/rustc_codegen_gcc#87 . There are some issues noted as FIXME in the code, though.
I can't remember if we have access to
c-familyin libgccjit, so I don't know if we could have agcc_jit_function_add_attributefunction as you suggested.I still think it's worth having functions specific to inlining because I believe the
inlinekeyword needs to be set separately for#[inline].