From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57281) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aVjDE-0002CM-Mx for qemu-devel@nongnu.org; Tue, 16 Feb 2016 12:14:57 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aVjD9-000169-L3 for qemu-devel@nongnu.org; Tue, 16 Feb 2016 12:14:56 -0500 Received: from mx1.redhat.com ([209.132.183.28]:54927) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aVjD9-000163-Cv for qemu-devel@nongnu.org; Tue, 16 Feb 2016 12:14:51 -0500 References: <1455582057-27565-1-git-send-email-eblake@redhat.com> <1455582057-27565-5-git-send-email-eblake@redhat.com> <87h9h8pqn3.fsf@blackfin.pond.sub.org> From: Eric Blake Message-ID: <56C3590A.6000208@redhat.com> Date: Tue, 16 Feb 2016 10:14:50 -0700 MIME-Version: 1.0 In-Reply-To: <87h9h8pqn3.fsf@blackfin.pond.sub.org> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="8xMiUvQfSEEaOqk6VRKnhTLEuhMecJmKj" Subject: Re: [Qemu-devel] [PATCH v10 04/13] qapi: Drop pointless gotos in generated code List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Markus Armbruster Cc: qemu-devel@nongnu.org, Michael Roth This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --8xMiUvQfSEEaOqk6VRKnhTLEuhMecJmKj Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 02/16/2016 09:27 AM, Markus Armbruster wrote: > Eric Blake writes: >=20 >> There's no point in emitting a goto if the very next thing >> emitted will be the label. A bit of cleverness in gen_visit_fields() >> will let us choose when to omit a final error check (basically, >> swap the order of emitted text within the loop, with the error >> check omitted on the first pass, then checking whether to emit a >> final check after the loop); and in turn omit unused labels. >> >> The change to generated code is a bit easier because we split out >> the reindentation of the remaining gotos in the previous patch. >> For example, in visit_type_ChardevReturn_fields(): >> >> | if (visit_optional(v, "pty", &obj->has_pty)) { >> | visit_type_str(v, "pty", &obj->pty, &err); >> | } >> |- if (err) { >> |- goto out; >> |- } >> |- >> |-out: >> | error_propagate(errp, err); >> >> Signed-off-by: Eric Blake >> >> @@ -1679,8 +1682,9 @@ def gen_visit_fields(members, prefix=3D'', need_= cast=3DFalse, skiperr=3DFalse, >> ret +=3D mcgen(''' >> } >> ''') >> + >> + if members and not skiplast: >> ret +=3D gen_err_check(skiperr=3Dskiperr, label=3Dlabel) >> - >> return ret >=20 > Is saving a goto the compiler can easily eliminate worth complicating > the code? I'm fine with dropping 3 and 4/13 if you think they don't add anything (and they do indeed make it more complicated to reason about when it is safe to drop a goto, and furthermore when to omit the label because all gotos were dropped). The generated code will occupy more source code bytes, but as you say, the optimizing compiler should not be bloating the code any differently based on whether the goto is present or absent. Okay, just in typing that, you've convinced me - ease of maintenance should triumph over concise generated code. --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --8xMiUvQfSEEaOqk6VRKnhTLEuhMecJmKj Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBCAAGBQJWw1kKAAoJEKeha0olJ0NqM0oIAIUZccZZWDZQxGH0LqFjgnkv fVRHFaddDWfLrDGdKJUYMmNGW+9FfPZvFBuiHii5/lgSfldNeMgHez0SdIbpmGag XCV+UJdpvH8PDIyqz1zpN4oDBkP7HuTbx4wHN/8l6MmTLgwQph75oLaaBAWSYCPS 37AdVlhBf0KhlU9Yk9u7wNoFhyyEhlQ2z96EWyOE5mEnRsXxfdzGdTmFuMlwNJO6 0lohdEKHNSXFlcHJD8PO29voXPZ1ExMuE/UyFF5rGqf2KBVO4EbsIPljGOCCPf/R JvSgQm0D/YiIMUaZx3DFpnmY8c+/55A/OmBVMxI4IJTL3/NRDS2xhXNjWS9e+RQ= =6mzb -----END PGP SIGNATURE----- --8xMiUvQfSEEaOqk6VRKnhTLEuhMecJmKj--