[llvm-commits] [llvm] r135624 - /llvm/trunk/docs/LangRef.html

Dan Gohman gohman at apple.com
Wed Jul 20 16:44:34 PDT 2011


On Jul 20, 2011, at 2:35 PM, Eli Friedman wrote:
>  For each byte, <var>R</var> reads the
> +value written by some write that it <i>may see</i>, given any relevant
> +<i>happens-before</i> constraints.

This sentence seems confusing.

It mentions "relevant happens-before constraints", however it's not clear what
those are until the following sentance. And, it seems to suggest that R always
reads the value of a write, which isn't always true.

Actually, it seems you could just delete this sentance without loosing
anything essential.

>  <var>R<sub>byte</sub></var> may
> +see any write to the same byte, except:</p>

The implicit transition from talking about R to talking about R_{byte} here is
mildly mysterious.

> +
> +<ul>
> +  <li>If <var>write<sub>1</sub></var> happens before
> +      <var>write<sub>2</sub></var>, and <var>write<sub>2</sub></var> happens
> +      before <var>R<sub>byte</sub></var>, then <var>R<sub>byte</sub></var>
> +      must not see <var>write<sub>1</sub></var>.
> +  <li>If <var>R<sub>byte</sub></var> happens before <var>write<sub>3</var>,
> +      then <var>R<sub>byte</sub></var> must not see
> +      <var>write<sub>3</sub></var>.

The use of the word "must" here is inconsistent with the rest of LangRef,
where it is used to constrain the IR producer, rather than the implementation.
Would "does" would convey the intended meaning better?

> +</ul>
> +
> +<p>Given that definition, <var>R<sub>byte</sub></var> is defined as follows:
> +<ul>
> +  <li>If there is no write to the same byte that happens before
> +    <var>R<sub>byte</sub></var>, <var>R<sub>byte</sub></var> returns 
> +    <tt>undef</tt> for that byte.

How do static initializers fit into this?

> +  <li>If <var>R<sub>byte</sub></var> may see exactly one write,
> +      <var>R<sub>byte</sub></var> returns the value written by that
> +      write.</li>

What if there's exactly one write, but the read also may-see the memory
before any writes happen?

> +  <li>If <var>R<sub>byte</sub></var> and all the writes it may see are
> +      atomic, it chooses one of those writes and returns it value.
> +      Given any two bytes in a given read <var>R</var>, if the set of
> +      writes <var>R<sub>byte</sub></var> may see is the same as the set
> +      of writes another byte may see, they will both choose the same write.

What if there are two multi-byte reads, and both their may-see sets contain
only atomic writes, but the sets are different? Can bytes from atomic
multi-byte writes be interleaved in this case?

Also, does this rule apply even when R is non-atomic? Is it intended to
require that all multi-byte reads must read all of their bytes simultaneously?

> +  <li>Otherwise <var>R<sub>byte</sub></var> returns <tt>undef</tt>.</li>
> +</ul>
> +
> +<p><var>R</var> returns the value composed of the series of bytes it read.
> +This implies that some bytes within the value may be <tt>undef</tt>
> +<b>without</b> the entire value being <tt>undef</tt>. Note that this only
> +defines the semantics of the operation; it doesn't mean that targets will
> +emit more than one instruction to read the series of bytes.</p>
> +
> +<p>Note that in cases where none of the atomic intrinsics are used, this model
> +places only one restriction on IR transformations on top of what is required
> +for single-threaded execution: introducing a store to a byte which might not
> +otherwise be stored to can introduce undefined behavior.</p>

Is it worth mentioning that this doesn't apply to pointers that
don't escape to other threads?

Dan




More information about the llvm-commits mailing list