From 5b60e1b6fc5bdce06599512069037944f2194703 Mon Sep 17 00:00:00 2001 From: Eli Friedman Date: Wed, 20 Jul 2011 21:35:53 +0000 Subject: Commit LangRef changes for LLVM concurrency model. Start of supporting C++0x memory model and atomics. See thread on llvmdev titled "Reviving the new LLVM concurrency model". git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@135624 91177308-0d34-0410-b5e6-96231b3b80d8 --- docs/LangRef.html | 86 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) (limited to 'docs') diff --git a/docs/LangRef.html b/docs/LangRef.html index 5959b3d..07720e5 100644 --- a/docs/LangRef.html +++ b/docs/LangRef.html @@ -53,6 +53,7 @@
  • Data Layout
  • Pointer Aliasing Rules
  • Volatile Memory Accesses
  • +
  • Memory Model for Concurrent Operations
  • Type System @@ -1470,6 +1471,91 @@ synchronization behavior.

    + +

    + Memory Model for Concurrent Operations +

    + +
    + +

    The LLVM IR does not define any way to start parallel threads of execution +or to register signal handlers. Nonetheless, there are platform-specific +ways to create them, and we define LLVM IR's behavior in their presence. This +model is inspired by the C++0x memory model.

    + +

    We define a happens-before partial order as the least partial order +that

    +
      +
    • Is a superset of single-thread program order, and
    • +
    • When a synchronizes-with b, includes an edge from + a to b. Synchronizes-with pairs are introduced + by platform-specific techniques, like pthread locks, thread + creation, thread joining, etc., and by the atomic operations described + in the Atomic intrinsics section.
    • +
    + +

    Note that program order does not introduce happens-before edges +between a thread and signals executing inside that thread.

    + +

    Every (defined) read operation (load instructions, memcpy, atomic +loads/read-modify-writes, etc.) R reads a series of bytes written by +(defined) write operations (store instructions, atomic +stores/read-modify-writes, memcpy, etc.). For each byte, R reads the +value written by some write that it may see, given any relevant +happens-before constraints. Rbyte may +see any write to the same byte, except:

    + +
      +
    • If write1 happens before + write2, and write2 happens + before Rbyte, then Rbyte + must not see write1. +
    • If Rbyte happens before write3, + then Rbyte must not see + write3. +
    + +

    Given that definition, Rbyte is defined as follows: +

      +
    • If there is no write to the same byte that happens before + Rbyte, Rbyte returns + undef for that byte. +
    • If Rbyte may see exactly one write, + Rbyte returns the value written by that + write.
    • +
    • If Rbyte 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 R, if the set of + writes Rbyte may see is the same as the set + of writes another byte may see, they will both choose the same write. +
    • Otherwise Rbyte returns undef.
    • +
    + +

    R returns the value composed of the series of bytes it read. +This implies that some bytes within the value may be undef +without the entire value being undef. 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.

    + +

    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.

    + + + +
    + -- cgit v1.1