Re: Data Structure Reorganizing Optimizations

pardo@cs.washington.edu (David Keppel)
Mon, 31 Oct 1994 18:51:01 GMT

          From comp.compilers

Related articles
[4 earlier articles]
Re: Data Structure Reorganizing Optimizations stripes@uunet.uu.net (1994-10-27)
Re: Data Structure Reorganizing Optimizations bret@icicle.winternet.com (1994-10-23)
Data Structure Reorganizing Optimizations leichter@zodiac.rutgers.edu (1994-10-31)
Re: Data Structure Reorganizing Optimizations yuri@shimari.cmf.nrl.navy.mil (1994-10-31)
Re: Data Structure Reorganizing Optimizations ddg@cci.com (1994-10-31)
Re: Data Structure Reorganizing Optimizations amos@nsof.co.il (1994-11-01)
Re: Data Structure Reorganizing Optimizations pardo@cs.washington.edu (1994-10-31)
Re: Data Structure Reorganizing Optimizations fjh@munta.cs.mu.OZ.AU (1994-11-02)
Re: Data Structure Reorganizing Optimizations jeremy@sour.sw.oz.au (1994-11-02)
Re: Data Structure Reorganizing Optimizations prochak@cibadiag.com (1994-11-02)
Re: Data Structure Reorganizing Optimizations pardo@cs.washington.edu (1994-11-09)
Re: Data Structure Reorganizing Optimizations kendall@pot.East.Sun.COM (1994-11-05)
Re: Data Structure Reorganizing Optimizations praetorius@figs.enet.dec.com (1994-11-09)
[9 later articles]
| List of all articles for this month |

Newsgroups: comp.arch,comp.compilers
From: pardo@cs.washington.edu (David Keppel)
Keywords: optimize, C
Organization: Computer Science & Engineering, U. of Washington, Seattle
References: 94-10-108 94-10-157
Date: Mon, 31 Oct 1994 18:51:01 GMT

>>[Why not permit compilers to perform "illegal" reorganizations?"]
>[Lots of things would break:
> where C structures describe hardware layouts,
> across system calls, things that read structures from disk, ....]


The C standard allows arbitrary *padding* choices for structure layout,
except that the first element appears at offset zero. Thus, two
identical structures compiled on the same machine may have differing
memory layouts.


The upshot is that *-> even without any reordering optimizations <-* all
of the following may break:


  - Structures that describe hardware layouts, such as device registers
  - Structure I/O to networks, disks, etc.
  - OS calls that pass structures
  - Inter-language calls passing structure data
  - Calls between C code fragments compiled with different compilers
  - Calls between C code compiled with the same compiler with different
      optimization levels


In practice, C compiler vendors try to maintain compatability with
whatever layout convention is used by the first compiler for the
machine, so programmers typically ``get away'' with writing unsafe
code.


Structure *reordering* optimizations would break lots of C code because
the C standard guarantees the *order* of structure elements. However,
much of the code I've seen that relies on structure order also relies
on structure *padding* (offsets) that the standard does not define.
Technically, such code is already broken. As optimizers improve, this
code is going to fail more and more often.


Blowing my own horn: see the `Portability' section of _Recommended C
Style and Coding Standards_, available via anonymous ftp from
`ftp.cs.washington.edu' in `pub/cstyle.tar.Z' or as formatted
PostScript(tm) from `pub/pardo/cstyle.ps.Z'. The files are compressed,
so be sure to do the transfer in binary (image) mode. Or via WWW, see
`http://www.cs.washington.edu/homes/pardo/papers.d/cstyle.html'. A
japanese translation of the style guide is also available.


;-D on ( Data strictures ) Pardo
--


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.