[PATCH 2/2] asm inline
Richard Sandiford
richard.sandiford@arm.com
Tue Dec 4 15:31:00 GMT 2018
Segher Boessenkool <segher@kernel.crashing.org> writes:
> diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c
> index 81c520a..9b572d7 100644
> --- a/gcc/c/c-typeck.c
> +++ b/gcc/c/c-typeck.c
> @@ -10315,7 +10315,7 @@ build_asm_stmt (tree cv_qualifier, tree args)
> are subtly different. We use a ASM_EXPR node to represent this. */
> tree
> build_asm_expr (location_t loc, tree string, tree outputs, tree inputs,
> - tree clobbers, tree labels, bool simple)
> + tree clobbers, tree labels, bool simple, bool is_inline)
> {
> tree tail;
> tree args;
Function comment doesn't document the new parameter.
> diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
> index 733c42f..87d54b1 100644
> --- a/gcc/cp/semantics.c
> +++ b/gcc/cp/semantics.c
> @@ -1486,7 +1486,7 @@ finish_compound_stmt (tree stmt)
>
> tree
> finish_asm_stmt (int volatile_p, tree string, tree output_operands,
> - tree input_operands, tree clobbers, tree labels)
> + tree input_operands, tree clobbers, tree labels, bool inline_p)
> {
> tree r;
> tree t;
Same here.
> @@ -19608,6 +19610,17 @@ cp_parser_asm_definition (cp_parser* parser)
> else
> done = true;
> break;
> + case RID_INLINE:
> + if (!inline_p && parser->in_function_body)
> + {
> + /* Remember that we saw the `inline' keyword. */
> + inline_p = true;
> + /* Consume the token. */
> + cp_lexer_consume_token (parser->lexer);
> + }
> + else
> + done = true;
> + break;
> case RID_GOTO:
> if (!goto_p && parser->in_function_body)
> {
Hmm, so we allow top-level "asm volatile" in C++ but not C?
Probably worth having tests to show that we (intentionally) don't
allow top-level "asm inline".
> @@ -1640,6 +1640,7 @@ finish_asm_stmt (int volatile_p, tree string, tree output_operands,
> output_operands, input_operands,
> clobbers, labels);
> ASM_VOLATILE_P (r) = volatile_p || noutputs == 0;
> + ASM_INLINE_P (r) = inline_p;
> r = maybe_cleanup_point_expr_void (r);
> return add_stmt (r);
> }
> diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi
> index 2791f25..cebbfc7 100644
> --- a/gcc/doc/extend.texi
> +++ b/gcc/doc/extend.texi
> @@ -8382,6 +8382,10 @@ various @option{-std} options, use @code{__asm__} instead of
> @item volatile
> The optional @code{volatile} qualifier has no effect.
> All basic @code{asm} blocks are implicitly volatile.
> +
> +@item inline
> +If you use the @code{inline} qualifier, then for inlining purposes the size
> +of the asm is taken as the smallest size possible (@pxref{Size of an asm}).
> @end table
>
> @subsubheading Parameters
You need to update the syntax above too, which currently reads:
@example
asm @r{[} volatile @r{]} ( @var{AssemblerInstructions} )
@end example
Same for the equivalent extended asm docs.
> @@ -3932,6 +3933,27 @@ gimple_asm_set_volatile (gasm *asm_stmt, bool volatile_p)
> }
>
>
> +/* Return true ASM_STMT ASM_STMT is an asm statement marked inline. */
> +
> +static inline bool
> +gimple_asm_inline_p (const gasm *asm_stmt)
> +{
> + return (asm_stmt->subcode & GF_ASM_INLINE) != 0;
> +}
Return true if ASM_STMT is ...
(Or "Return true if asm statement ASM_STMT is marked inline", since gasm
forces it to be an asm statement.)
> diff --git a/gcc/tree-inline.c b/gcc/tree-inline.c
> index 5aa782b..7e9ed99 100644
> --- a/gcc/tree-inline.c
> +++ b/gcc/tree-inline.c
> @@ -4109,6 +4109,9 @@ estimate_num_insns (gimple *stmt, eni_weights *weights)
> with very long asm statements. */
> if (count > 1000)
> count = 1000;
> + /* If this asm is asm inline, count anything as minimum size. */
> + if (gimple_asm_inline_p (as_a <gasm *> (stmt)))
> + count = !!count;
FWIW, since Marc found it confusing too... I think MIN (count, 1) would
show the intent more clearerly. But that's just personal preference,
no need to change.
OK with those changes, thanks.
Richard
More information about the Gcc-patches
mailing list