<html>
  <head>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    Ke,<br>
    <br>
    I'll be the bearer of bad news here.  The radio silence this
    proposal has gotten probably means there is not enough interest in
    the community in this proposal to see it land.<br>
    <br>
    One concern I have with the current proposal is that the
    optimization value of these scopes is not clear to me.  Is it only
    the backend which is expected to support optimizations over these
    scopes?  Or are you expecting the middle end optimizer to understand
    them?  If so, I'd suspect we'd need a refined definition which
    allows us to discuss relative strengths of memory scopes.  <br>
    <br>
    More fundamentally, it's not clear to me that "scope" is even the
    right model for this.  I could see a case where we'd want something
    along the lines of "acquire semantics on memory space 1, release
    semantics on memory space 2, cst_seq semantics on address space 3". 
    <br>
    <br>
    Also, unless I'm misreading on my skim of your proposal, the current
    definition of scope is slightly off from what you've specified.  A
    "seq_cst singlethread" fence is a much weaker fence than a "seq_cst
    crossthread".  It's probably easiest to reason about the current
    scheme as having the cross product of {singlethread, crossthread} x
    {orderings...} distinct orderings rather than a set of orderings
    with two overlapping scopes.  <br>
    <br>
    Philip<br>
    <br>
    <div class="moz-cite-prefix">On 03/22/2016 01:42 PM, Ke Bai via
      llvm-dev wrote:<br>
    </div>
    <blockquote
cite="mid:CAA6bMpozX=9e10Tktoh9t2jT3AZ=a7wF3u+okAatZ=M-c_V-EA@mail.gmail.com"
      type="cite">
      <div dir="ltr">
        <div class="gmail_default"
style="font-family:arial,helvetica,sans-serif;color:rgb(11,83,148);display:inline">​
          ​</div>
        Dear all,<br>
        <br>
        Here is the plain text version of the proposal:<br>
        <br>
        Currently, the LLVM IR uses a binary value
        (SingleThread/CrossThread) to represent synchronization scope on
        atomic instructions. We would like to enhance the representation
        of memory scopes in LLVM IR to allow more values than just the
        current two. The intention of this email is to invite comments
        on our proposal. There are some discussion before and it can be
        found here:<br>
        <a moz-do-not-send="true"
href="https://groups.google.com/forum/#%21searchin/llvm-dev/hsail/llvm-dev/46eEpS5h0E4/i3T9xw-DNVYJ">https://groups.google.com/forum/#!searchin/llvm-dev/hsail/llvm-dev/46eEpS5h0E4/i3T9xw-DNVYJ</a><br>
        <br>
        Here is our new proposal:<br>
        <br>
=================================================================<br>
        We still let the bitcode store memory scopes as "unsigned
        integers", since that is the easiest way to maintain
        compatibility. The values 0 and 1 are special. All other values
        are meaningful only within that bc file. In addition, "a global
        metadata in the file" will provide a map from unsigned integers
        to string symbols which should be used to interpret all the
        non-standard integers. If the global metadata is empty or
        non-existent, then all non-zero values will be mapped to
        "system", which is the current behavior.<br>
        <br>
        The proposed syntax for synchronization scope is as follows:<br>
        * Synchronization scopes are of arbitrary width, but implemented
        as unsigned in the bitcode, just like address spaces.<br>
        * Cross-thread is default.<br>
        * Keyword "singlethread" is unchanged<br>
        * New syntax "synchscope(n)" for other target-specific scopes. <br>
        * There is no keyword for cross-thread, but it can be specified
        as "synchscope(0)".<br>
        <br>
        The proposed new integer implementation expanded synchronization
        scopes are as follows: <br>
        ****************************************************************<br>
        Format        
        <div class="gmail_default"
style="font-family:arial,helvetica,sans-serif;color:rgb(11,83,148);display:inline">​
              ​ </div>
        Single Thread    
        <div class="gmail_default"
style="font-family:arial,helvetica,sans-serif;color:rgb(11,83,148);display:inline">​
                 ​</div>
        System (renamed)
        <div class="gmail_default"
style="font-family:arial,helvetica,sans-serif;color:rgb(11,83,148);display:inline">​
             ​</div>
         Intermediate<br>
        Bitcode      
        <div class="gmail_default"
style="font-family:arial,helvetica,sans-serif;color:rgb(11,83,148);display:inline">​
                </div>
        zero              
        <div class="gmail_default"
style="font-family:arial,helvetica,sans-serif;color:rgb(11,83,148);display:inline">​
                      </div>
        one              
        <div class="gmail_default"
style="font-family:arial,helvetica,sans-serif;color:rgb(11,83,148);display:inline">​
                      </div>
         unsigned n<br>
        Assembly    
        <div class="gmail_default"
style="font-family:arial,helvetica,sans-serif;color:rgb(11,83,148);display:inline">​
              ​</div>
        singlethread,    
        <div class="gmail_default"
style="font-family:arial,helvetica,sans-serif;color:rgb(11,83,148);display:inline">​
                  ​ </div>
        empty (default),  
        <div class="gmail_default"
style="font-family:arial,helvetica,sans-serif;color:rgb(11,83,148);display:inline">​
                 ​</div>
        synchscope(n-1)<br>
                     
        <div class="gmail_default"
style="font-family:arial,helvetica,sans-serif;color:rgb(11,83,148);display:inline">​
                 ​  </div>
        synchscope(~0U)  
        <div class="gmail_default"
style="font-family:arial,helvetica,sans-serif;color:rgb(11,83,148);display:inline">​
             ​ </div>
        synchscope(0)<br>
        In-memory    
        <div class="gmail_default"
style="font-family:arial,helvetica,sans-serif;color:rgb(11,83,148);display:inline">​
             </div>
        ~0U
        <div class="gmail_default"
style="font-family:arial,helvetica,sans-serif;color:rgb(11,83,148);display:inline">​
                                     z</div>
        ero              
        <div class="gmail_default"
style="font-family:arial,helvetica,sans-serif;color:rgb(11,83,148);display:inline">​
                     </div>
        unsigned n-1<br>
        SelectionDAG
        <div class="gmail_default"
style="font-family:arial,helvetica,sans-serif;color:rgb(11,83,148);display:inline">​
            </div>
        ~0U
        <div class="gmail_default"
style="font-family:arial,helvetica,sans-serif;color:rgb(11,83,148);display:inline">​
                                     ​</div>
        zero
        <div class="gmail_default"
style="font-family:arial,helvetica,sans-serif;color:rgb(11,83,148);display:inline">​
                                   </div>
        unsigned n-1<br>
        ****************************************************************<br>
        <br>
        The choice of “~0U” for singlethread makes it easy to maintain
        backward compatibility in the bitcode. The values 0 and 1 remain
        unchanged in the bitcode, and the reader simply decrements them
        by one to compute the correct value in the in-memory
        data-structure.<br>
        <br>
        Name Mapping<br>
        <br>
        Now we comes to name mapping from integers to strings. If a
        CLANG front end wants to map a language that has memory scopes
        (e.g. OpenCL) to LLVM IR, how does it determine what syncscopes
        to use? Without any rules, each target can define its own
        meaning for the scopes, can give them any name, and can map them
        to the LLVM-IR unit values in any way. In this case, I think
        each target have to provide a mapping function that maps a
        specific language’s name for a scope into that targets name for
        a scope that has conservatively the same semantics. Namely, the
        act of supporting a new language that has memory scopes requires
        every target to support that language to be updated accordingly.<br>
        <br>
        Therefore, in order to allow front end writers to share memory
        scope definitions when they match to avoid the effort of
        updating all targets for each language,it's better to define
        standard memory scope names. A target is free to implement them
        or not, but if a target does implement them they must have the
        defined relational semantics (e.g., hierarchical nesting). If a
        target does implement them then it will be able to support any
        language that uses them, including languages not yet invented. A
        new memory scope name can be added if the existing ones are
        insufficient. <br>
        <br>
        With the first try, we can define the standard scopes with what
        a common language that has memory scopes needs, e.g., OpenCL
        uses system, device, workgroup, workitem. It uses the same
        approach as LLVM has done for debug information. There are
        standard debug entities (that a common language (C) needs), and
        each new language uses those standard entities where there is a
        match, and subsequently defines only the delta.<br>
        <br>
        A bitcode example with the proposal<br>
*****************************************************************<br>
        define void  <at> test(i32* %addr) {<br>
        ; forward compatibility<br>
          cmpxchg i32* %addr, i32 42, i32 0 singlethread monotonic
        monotonic<br>
        <br>
        ; new synchscope that will be defined by each backend<br>
          cmpxchg i32* %addr, i32 42, i32 0 synchscope(2) monotonic
        monotonic, 2<br>
          cmpxchg i32* %addr, i32 42, i32 0 synchscope(3) monotonic
        monotonic, 3<br>
        <br>
          ret void<br>
        }<br>
        <br>
        !synchscope = metadata !{{i32 0, !"SingleThread"}, {i32 2,
        !"WorkGroup"}, ...}<br>
*****************************************************************<br>
        <br>
        =================================================================
      </div>
      <div class="gmail_extra"><br>
        <div class="gmail_quote">On Thu, Jan 28, 2016 at 12:27 PM, Ke
          Bai <span dir="ltr"><<a moz-do-not-send="true"
              href="mailto:kebai613@gmail.com" target="_blank">kebai613@gmail.com</a>></span>
          wrote:<br>
          <blockquote class="gmail_quote" style="margin:0 0 0
            .8ex;border-left:1px #ccc solid;padding-left:1ex">
            <div dir="ltr">
              <div
style="color:rgb(0,0,0);font-family:Calibri,Arial,Helvetica,sans-serif;font-size:16px;line-height:normal"><span style="font-family:Arial;white-space:pre-wrap;line-height:1.38">Hi all,</span><br>
              </div>
              <div><span><br>
                  <p dir="ltr"
                    style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:16px;font-family:Arial;color:rgb(34,34,34);vertical-align:baseline;white-space:pre-wrap">Currently, the LLVM IR uses a binary value (SingleThread/CrossThread) to represent synchronization scope on atomic instructions. We would like to enhance the representation of memory scopes in LLVM IR to allow more values than just the current two. The intention of this email is to invite comments on our proposal. There are some discussion before and </span><span style="font-size:16px;font-family:Arial;color:rgb(0,0,0);vertical-align:baseline;white-space:pre-wrap;background-color:transparent">it can be found here:</span></p>
                  <p dir="ltr"
                    style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><a
                      moz-do-not-send="true"
href="https://groups.google.com/forum/#%21searchin/llvm-dev/hsail/llvm-dev/46eEpS5h0E4/i3T9xw-DNVYJ"
                      style="text-decoration:none" target="_blank"><span style="font-size:16px;font-family:Arial;color:rgb(17,85,204);text-decoration:underline;vertical-align:baseline;white-space:pre-wrap"><a class="moz-txt-link-freetext" href="https://groups.google.com/forum/#!searchin/llvm-dev/hsail/llvm-dev/46eEpS5h0E4/i3T9xw-DNVYJ">https://groups.google.com/forum/#!searchin/llvm-dev/hsail/llvm-dev/46eEpS5h0E4/i3T9xw-DNVYJ</a></span></a></p>
                  <br>
                  <p dir="ltr"
                    style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:16px;font-family:Arial;vertical-align:baseline;white-space:pre-wrap">Here is our new proposal:</span></p>
                  <div>=================================================================</div>
                </span></div>
              <div
style="color:rgb(0,0,0);font-family:Calibri,Arial,Helvetica,sans-serif;font-size:16px;line-height:normal"><font
                  style="color:rgb(33,33,33)"
                  face="Arial,Helvetica,sans-serif">We still let the
                  bitcode store memory scopes as </font><font
                  style="color:rgb(33,33,33)"
                  face="Arial,Helvetica,sans-serif"><b>unsigned integers</b></font><font
                  style="color:rgb(33,33,33)"
                  face="Arial,Helvetica,sans-serif">, since that is the
                  easiest way to maintain compatibility. The values 0
                  and 1 are special. All other values are meaningful
                  only within that bc file. In addition, </font><font
                  style="color:rgb(33,33,33)"
                  face="Arial,Helvetica,sans-serif"><b>a global metadata
                    in the </b></font><font style="color:rgb(33,33,33)"
                  face="Arial,Helvetica,sans-serif"><b>file will provide
                    a map</b></font><font style="color:rgb(33,33,33)"
                  face="Arial,Helvetica,sans-serif"> from unsigned
                  integers to string symbols which should be used to
                  interpret all the non-standard integers. If the global
                  metadata is empty or non-existent, then all non-zero
                  values will be mapped to "system", which is the
                  current </font><font style="color:rgb(33,33,33)"
                  face="Arial,Helvetica,sans-serif">behavior</font><font
                  style="color:rgb(33,33,33)"
                  face="Arial,Helvetica,sans-serif">.</font></div>
              <div
style="color:rgb(0,0,0);font-family:Calibri,Arial,Helvetica,sans-serif;font-size:16px;line-height:normal"><font
                  face="Calibri,Arial,Helvetica,sans-serif,Apple Color
                  Emoji,Segoe UI Emoji,NotoColorEmoji,Segoe UI
                  Symbol,Android Emoji,EmojiSymbols" size="2"
                  color="#212121"><span style="font-size:16px">
                    <div style="margin-top:5.76pt;margin-bottom:10.8pt"><font
                        face="Calibri,Arial,Helvetica,sans-serif"><font
                          face="Arial,Helvetica,sans-serif" size="3"><span
                            style="font-size:12pt">The proposed syntax
                            for synchronization scope is as follows:</span></font></font></div>
                  </span></font></div>
              <div
style="color:rgb(0,0,0);font-family:Calibri,Arial,Helvetica,sans-serif;font-size:16px;line-height:normal"><font
                  face="Calibri,Arial,Helvetica,sans-serif,Apple Color
                  Emoji,Segoe UI Emoji,NotoColorEmoji,Segoe UI
                  Symbol,Android Emoji,EmojiSymbols" size="2"
                  color="#212121"><span style="font-size:16px">
                    <ul style="margin-top:14pt;margin-bottom:14pt">
                      <font face="Calibri,Arial,Helvetica,sans-serif">
                        <li><font
                            face="Calibri,Arial,Helvetica,sans-serif"><font
                              face="Arial,Helvetica,sans-serif" size="3"><span
                                style="font-size:12pt">Synch</span></font><font
                              face="Arial,Helvetica,sans-serif" size="3"><span
                                style="font-size:12pt">ronization scopes
                                are of arbitrary width, but implemented
                                as unsigned in the bitcode, just like
                                address spaces.</span></font><font
                              face="Arial,Helvetica,sans-serif" size="2"><span
                                style="font-size:11pt"><br>
                              </span></font></font></li>
                        <li><font
                            face="Calibri,Arial,Helvetica,sans-serif"><font
                              face="Arial,Helvetica,sans-serif" size="3"><span
                                style="font-size:12pt">Cross-thread is
                                default.</span></font><font
                              face="Arial,Helvetica,sans-serif" size="2"><span
                                style="font-size:11pt"><br>
                              </span></font></font></li>
                        <li><font
                            face="Calibri,Arial,Helvetica,sans-serif"><font
                              face="Arial,Helvetica,sans-serif" size="3"><span
                                style="font-size:12pt">Keyword
                                "singlethread" is unchanged</span></font><font
                              face="Arial,Helvetica,sans-serif" size="2"><span
                                style="font-size:11pt"><br>
                              </span></font></font></li>
                        <li><font
                            face="Calibri,Arial,Helvetica,sans-serif"><font
                              face="Arial,Helvetica,sans-serif" size="3"><span
                                style="font-size:12pt">New syntax
                                "synchscope(n)" for other
                                target-specific scopes. </span></font><font
                              face="Arial,Helvetica,sans-serif" size="2"><br>
                            </font></font></li>
                        <li><font
                            face="Calibri,Arial,Helvetica,sans-serif"><font
                              face="Arial,Helvetica,sans-serif" size="3"><span
                                style="font-size:12pt">There is no
                                keyword for cross-thread, but it can be
                                specified as "synchscope(0)".</span></font><font
                              face="Arial,Helvetica,sans-serif" size="2"><br>
                            </font></font></li>
                      </font>
                    </ul>
                  </span></font></div>
              <div
style="color:rgb(0,0,0);font-family:Calibri,Arial,Helvetica,sans-serif;font-size:16px;line-height:normal"><font
                  face="Calibri,Arial,Helvetica,sans-serif,Apple Color
                  Emoji,Segoe UI Emoji,NotoColorEmoji,Segoe UI
                  Symbol,Android Emoji,EmojiSymbols" size="2"
                  color="#212121"><span style="font-size:16px"><font
                      face="Arial,Helvetica,sans-serif">The proposed new
                      integer implementation expanded synchronization
                      scopes are as follows: </font></span></font></div>
              <div
style="color:rgb(0,0,0);font-family:Calibri,Arial,Helvetica,sans-serif;font-size:16px;line-height:normal"><font
                  face="Calibri,Arial,Helvetica,sans-serif,Apple Color
                  Emoji,Segoe UI Emoji,NotoColorEmoji,Segoe UI
                  Symbol,Android Emoji,EmojiSymbols" size="2"
                  color="#212121"><span style="font-size:16px"><font
                      face="Arial,Helvetica,sans-serif">
                      <table style="width:638px" width="638"
                        cellpadding="7" cellspacing="0">
                        <colgroup><col style="width:154px" width="154"></colgroup><colgroup><col
                            style="width:153px" width="153"><col
                            style="width:156px" width="156"><col
                            style="width:117px" width="117"></colgroup><tbody>
                          <tr>
                            <td style="width:154px;padding:0px 0px 0px
                              5.4pt;border-style:solid none none
solid;border-top-width:1pt;border-left-width:1pt;border-top-color:rgb(0,0,1);border-left-color:rgb(0,0,1);background-color:black"
                              width="154">
                              <div
                                style="margin-top:0px;margin-bottom:0px"><font
                                  face="Arial,Helvetica,sans-serif"
                                  size="3" color="white"><span
                                    style="font-size:12pt" lang="en-US"><b>Format</b></span></font></div>
                            </td>
                            <td
                              style="width:153px;padding:0px;border-style:solid
                              none
none;border-top-width:1pt;border-top-color:rgb(0,0,1);background-color:black"
                              width="153">
                              <div
                                style="margin-top:0px;margin-bottom:0px"><font
                                  face="Arial,Helvetica,sans-serif"
                                  size="3" color="white"><span
                                    style="font-size:12pt" lang="en-US"><b>Single
                                      Thread</b></span></font></div>
                            </td>
                            <td
                              style="width:156px;padding:0px;border-style:solid
                              none
none;border-top-width:1pt;border-top-color:rgb(0,0,1);background-color:black"
                              width="156">
                              <div
                                style="margin-top:0px;margin-bottom:0px"><font
                                  face="Arial,Helvetica,sans-serif"
                                  size="3" color="white"><span
                                    style="font-size:12pt" lang="en-US"><b>System
                                      (renamed)</b></span></font></div>
                            </td>
                            <td style="width:117px;padding:0px 5.76pt
                              0px 0px;border-style:solid solid none
none;border-top-width:1pt;border-right-width:1pt;border-top-color:rgb(0,0,1);border-right-color:rgb(0,0,1);background-color:black"
                              width="117">
                              <div
                                style="margin-top:0px;margin-bottom:0px"><font
                                  face="Arial,Helvetica,sans-serif"
                                  size="3" color="white"><span
                                    style="font-size:12pt" lang="en-US"><b>Intermediate</b></span></font></div>
                            </td>
                          </tr>
                          <tr>
                            <td style="width:154px;padding:0px 5.76pt
                              0px 5.4pt;border:1pt solid rgb(0,0,1)"
                              width="154">
                              <div
                                style="margin-top:0px;margin-bottom:0px"><font
                                  face="Arial,Helvetica,sans-serif"
                                  size="3"><span style="font-size:12pt"
                                    lang="en-US"><b>Bitcode</b></span></font></div>
                            </td>
                            <td style="width:153px;padding:0px 5.76pt
                              0px 5.4pt;border:1pt solid rgb(0,0,1)"
                              width="153">
                              <div
                                style="margin-top:0px;margin-bottom:0px"><font
                                  face="Arial,Helvetica,sans-serif"
                                  size="3"><span style="font-size:12pt"
                                    lang="en-US">zero</span></font></div>
                            </td>
                            <td style="width:156px;padding:0px 5.76pt
                              0px 5.4pt;border:1pt solid rgb(0,0,1)"
                              width="156">
                              <div
                                style="margin-top:0px;margin-bottom:0px"><font
                                  face="Arial,Helvetica,sans-serif"
                                  size="3"><span style="font-size:12pt"
                                    lang="en-US">one</span></font></div>
                            </td>
                            <td style="width:117px;padding:0px 5.76pt
                              0px 5.4pt;border:1pt solid rgb(0,0,1)"
                              width="117">
                              <div
                                style="margin-top:0px;margin-bottom:0px"><font
                                  face="Arial,Helvetica,sans-serif"
                                  size="3"><span style="font-size:12pt"
                                    lang="en-US">unsigned n</span></font></div>
                            </td>
                          </tr>
                          <tr>
                            <td style="width:154px;padding:0px 0px 0px
                              5.4pt;border-style:none none none
                              solid;border-left-width:1pt;border-left-color:rgb(0,0,1)"
                              width="154">
                              <div
                                style="margin-top:0px;margin-bottom:0px"><font
                                  face="Arial,Helvetica,sans-serif"
                                  size="3"><span style="font-size:12pt"
                                    lang="en-US"><b>Assembly</b></span></font></div>
                            </td>
                            <td
                              style="width:153px;padding:0px;border-style:none"
                              width="153">
                              <div
                                style="margin-top:0px;margin-bottom:0px"><font
                                  face="Arial,Helvetica,sans-serif"
                                  size="3"><span style="font-size:12pt"
                                    lang="en-US">singlethread,</span></font><font
                                  face="Arial,Helvetica,sans-serif"
                                  size="3"><span style="font-size:12pt"
                                    lang="en-US"><br>
                                  </span></font><font
                                  face="Arial,Helvetica,sans-serif"
                                  size="3"><span style="font-size:12pt"
                                    lang="en-US">synchscope(~0U)</span></font></div>
                            </td>
                            <td
                              style="width:156px;padding:0px;border-style:none"
                              width="156">
                              <div
                                style="margin-top:0px;margin-bottom:0px"
                                align="justify"><font
                                  face="Arial,Helvetica,sans-serif"
                                  size="3"><span style="font-size:12pt"
                                    lang="en-US">empty (default),</span></font><font
                                  face="Arial,Helvetica,sans-serif"
                                  size="3"><span style="font-size:12pt"
                                    lang="en-US"><br>
                                  </span></font><font
                                  face="Arial,Helvetica,sans-serif"
                                  size="3"><span style="font-size:12pt"
                                    lang="en-US">synchscope(0)</span></font></div>
                            </td>
                            <td style="width:117px;padding:0px 5.76pt
                              0px 0px;border-style:none solid none
                              none;border-right-width:1pt;border-right-color:rgb(0,0,1)"
                              width="117">
                              <div
                                style="margin-top:0px;margin-bottom:0px"><font
                                  face="Arial,Helvetica,sans-serif"
                                  size="3"><span style="font-size:12pt"
                                    lang="en-US">synchscope(n-1)</span></font></div>
                            </td>
                          </tr>
                          <tr>
                            <td style="width:154px;padding:0px 5.76pt
                              0px 5.4pt;border:1pt solid rgb(0,0,1)"
                              width="154">
                              <div
                                style="margin-top:0px;margin-bottom:0px"><font
                                  face="Arial,Helvetica,sans-serif"
                                  size="3"><span style="font-size:12pt"
                                    lang="en-US"><b>In-memory</b></span></font></div>
                            </td>
                            <td style="width:153px;padding:0px 5.76pt
                              0px 5.4pt;border:1pt solid rgb(0,0,1)"
                              width="153">
                              <div
                                style="margin-top:0px;margin-bottom:0px"><font
                                  face="Arial,Helvetica,sans-serif"
                                  size="3"><span style="font-size:12pt"
                                    lang="en-US">~0U</span></font></div>
                            </td>
                            <td style="width:156px;padding:0px 5.76pt
                              0px 5.4pt;border:1pt solid rgb(0,0,1)"
                              width="156">
                              <div
                                style="margin-top:0px;margin-bottom:0px"><font
                                  face="Arial,Helvetica,sans-serif"
                                  size="3"><span style="font-size:12pt"
                                    lang="en-US">zero</span></font></div>
                            </td>
                            <td style="width:117px;padding:0px 5.76pt
                              0px 5.4pt;border:1pt solid rgb(0,0,1)"
                              width="117">
                              <div
                                style="margin-top:0px;margin-bottom:0px"><font
                                  face="Arial,Helvetica,sans-serif"
                                  size="3"><span style="font-size:12pt"
                                    lang="en-US">unsigned n-1</span></font></div>
                            </td>
                          </tr>
                          <tr>
                            <td style="width:154px;padding:0px 0px 0px
                              5.4pt;border-style:none none solid
solid;border-bottom-width:1pt;border-left-width:1pt;border-bottom-color:rgb(0,0,1);border-left-color:rgb(0,0,1)"
                              width="154">
                              <div
                                style="margin-top:0px;margin-bottom:0px"><font
                                  face="Arial,Helvetica,sans-serif"
                                  size="3"><span style="font-size:12pt"
                                    lang="en-US"><b>SelectionDAG</b></span></font></div>
                            </td>
                            <td
                              style="width:153px;padding:0px;border-style:none
                              none
                              solid;border-bottom-width:1pt;border-bottom-color:rgb(0,0,1)"
                              width="153">
                              <div
                                style="margin-top:0px;margin-bottom:0px"><font
                                  face="Arial,Helvetica,sans-serif"
                                  size="3"><span style="font-size:12pt"
                                    lang="en-US">~0U</span></font></div>
                            </td>
                            <td
                              style="width:156px;padding:0px;border-style:none
                              none
                              solid;border-bottom-width:1pt;border-bottom-color:rgb(0,0,1)"
                              width="156">
                              <div
                                style="margin-top:0px;margin-bottom:0px"><font
                                  face="Arial,Helvetica,sans-serif"
                                  size="3"><span style="font-size:12pt"
                                    lang="en-US">zero</span></font></div>
                            </td>
                            <td style="width:117px;padding:0px 5.76pt
                              0px 0px;border-style:none solid solid
none;border-right-width:1pt;border-bottom-width:1pt;border-right-color:rgb(0,0,1);border-bottom-color:rgb(0,0,1)"
                              width="117">
                              <div
                                style="margin-top:0px;margin-bottom:0px"><font
                                  face="Arial,Helvetica,sans-serif"
                                  size="3"><span style="font-size:12pt"
                                    lang="en-US">unsigned n-1</span></font></div>
                            </td>
                          </tr>
                        </tbody>
                      </table>
                    </font>
                    <div style="margin-top:5.76pt;margin-bottom:10.8pt"><font
                        face="Calibri,Arial,Helvetica,sans-serif"><font
                          face="Arial,Helvetica,sans-serif"><span
                            lang="en-US">The choice of “~0U” for
                            singlethread makes it easy to maintain
                            backward compatibility in the bitcode. The
                            values 0 and 1 remain unchanged in the
                            bitcode, and the reader simply decrements
                            them by one to compute the correct value in
                            the in-memory data-structure.</span></font></font></div>
                    <div style="margin-top:5.76pt;margin-bottom:10.8pt"><span>
                        <p dir="ltr"
                          style="line-height:1.38;margin-top:6pt;margin-bottom:11pt"><span style="font-family:Arial;color:rgb(0,0,0);font-weight:700;vertical-align:baseline;white-space:pre-wrap">Name Mapping</span></p>
                        <p dir="ltr"
                          style="line-height:1.38;margin-top:6pt;margin-bottom:11pt"><span style="font-family:Arial;color:rgb(0,0,0);vertical-align:baseline;white-space:pre-wrap">Now we comes to name mapping from integers to strings. If a CLANG front end wants to map a language that has memory scopes (e.g. OpenCL) to LLVM IR, how does it determine what syncscopes to use? Without any rules, each target can define its own meaning for the scopes, can give them any name, and can map them to the LLVM-IR unit values in any way. In this case, I think each target have to provide a mapping function that maps a specific language’s name for a scope into that targets name for a scope that has conservatively the same semantics. Namely, the act of supporting a new language that has memory scopes requires every target to support that language to be updated accordingly.</span></p>
                        <p dir="ltr"
                          style="line-height:1.38;margin-top:6pt;margin-bottom:11pt"><span style="color:rgb(0,0,0);font-family:Arial;white-space:pre-wrap;line-height:1.38">Therefore, in order to allow front end writers to share memory scope definitions when they match to avoid the effort of updating all targets for each language,it's better to define standard memory scope names. A target is free to implement them or not, but if a target does implement them they must have the defined relational semantics (e.g., hierarchical nesting). If a target does implement them then it will be able to support any language that uses them, including languages not yet invented. A new memory scope name can be added if the existing ones are insufficient. </span></p>
                        <p dir="ltr"
                          style="line-height:1.38;margin-top:6pt;margin-bottom:11pt"><span style="color:rgb(0,0,0);font-family:Arial;line-height:1.38;white-space:pre-wrap">With the first try, we can define the standard scopes with what a common language that has memory scopes needs, e.g., OpenCL uses system, device, workgroup, workitem. It uses the same approach as LLVM has done for debug information. There are standard debug entities (that a common language (C) needs), and each new language uses those standard entities where there is a match, and subsequently defines only the delta.</span></p>
                      </span></div>
                    <div style="margin-top:5.76pt;margin-bottom:10.8pt"><font
                        face="Calibri,Arial,Helvetica,sans-serif"><font
                          face="Arial,Helvetica,sans-serif"><span
                            lang="en-US"><b>A </b></span></font><font
                          face="Arial,Helvetica,sans-serif"><b>bitcode
                            example with the proposal</b></font></font></div>
                  </span></font></div>
              <div
style="color:rgb(0,0,0);font-family:Calibri,Arial,Helvetica,sans-serif;font-size:16px;line-height:normal"><font
                  face="Calibri,Arial,Helvetica,sans-serif,Apple Color
                  Emoji,Segoe UI Emoji,NotoColorEmoji,Segoe UI
                  Symbol,Android Emoji,EmojiSymbols" size="2"
                  color="#212121"><span style="font-size:16px"><font
                      face="Arial,Helvetica,sans-serif" size="3"><span
                        style="font-size:12pt">define </span></font><font
                      face="Arial,Helvetica,sans-serif" size="3"><span
                        style="font-size:12pt">void  <at>
                        test(i32* %addr) {</span></font></span></font></div>
              <div
style="color:rgb(0,0,0);font-family:Calibri,Arial,Helvetica,sans-serif;font-size:16px;line-height:normal"><font
                  face="Calibri,Arial,Helvetica,sans-serif,Apple Color
                  Emoji,Segoe UI Emoji,NotoColorEmoji,Segoe UI
                  Symbol,Android Emoji,EmojiSymbols" size="2"
                  color="#212121"><span style="font-size:16px"><font
                      face="Arial,Helvetica,sans-serif" size="3"><span
                        style="font-size:12pt">; </span></font><font
                      face="Arial,Helvetica,sans-serif" size="3"><span
                        style="font-size:12pt">forward compatibility</span></font><font
                      face="Arial,Helvetica,sans-serif" size="2"><span
                        style="font-size:11pt"><br>
                      </span></font></span></font></div>
              <div
style="color:rgb(0,0,0);font-family:Calibri,Arial,Helvetica,sans-serif;font-size:16px;line-height:normal"><font
                  face="Calibri,Arial,Helvetica,sans-serif,Apple Color
                  Emoji,Segoe UI Emoji,NotoColorEmoji,Segoe UI
                  Symbol,Android Emoji,EmojiSymbols" size="2"
                  color="#212121"><span style="font-size:16px"><font
                      face="Arial,Helvetica,sans-serif" size="3"><span
                        style="font-size:12pt">  cmpxchg </span></font><font
                      face="Arial,Helvetica,sans-serif" size="3"><span
                        style="font-size:12pt">i32* %addr, i32 42, i32 0
                        singlethread monotonic monotonic</span></font></span></font></div>
              <div
style="color:rgb(0,0,0);font-family:Calibri,Arial,Helvetica,sans-serif;font-size:16px;line-height:normal"><font
                  face="Calibri,Arial,Helvetica,sans-serif,Apple Color
                  Emoji,Segoe UI Emoji,NotoColorEmoji,Segoe UI
                  Symbol,Android Emoji,EmojiSymbols" size="2"
                  color="#212121"><span style="font-size:16px"><font
                      face="Arial,Helvetica,sans-serif" size="2"><span
                        style="font-size:11pt"><br>
                      </span></font></span></font></div>
              <div
style="color:rgb(0,0,0);font-family:Calibri,Arial,Helvetica,sans-serif;font-size:16px;line-height:normal"><font
                  face="Calibri,Arial,Helvetica,sans-serif,Apple Color
                  Emoji,Segoe UI Emoji,NotoColorEmoji,Segoe UI
                  Symbol,Android Emoji,EmojiSymbols" size="2"
                  color="#212121"><span style="font-size:16px"><font
                      face="Arial,Helvetica,sans-serif" size="3"><span
                        style="font-size:12pt">; </span></font><font
                      face="Arial,Helvetica,sans-serif" size="3"><span
                        style="font-size:12pt">new synchscope that will
                        be defined by each backend</span></font></span></font></div>
              <div
style="color:rgb(0,0,0);font-family:Calibri,Arial,Helvetica,sans-serif;font-size:16px;line-height:normal"><font
                  face="Calibri,Arial,Helvetica,sans-serif,Apple Color
                  Emoji,Segoe UI Emoji,NotoColorEmoji,Segoe UI
                  Symbol,Android Emoji,EmojiSymbols" size="2"
                  color="#212121"><span style="font-size:16px"><font
                      face="Arial,Helvetica,sans-serif" size="3"><span
                        style="font-size:12pt">  cmpxchg </span></font><font
                      face="Arial,Helvetica,sans-serif" size="3"><span
                        style="font-size:12pt">i32* %addr, i32 42, i32 0
                        synchscope(2) monotonic monotonic, </span></font><font
                      face="Arial,Helvetica,sans-serif" size="3"><span
                        style="font-size:12pt">2</span></font></span></font></div>
              <div
style="color:rgb(0,0,0);font-family:Calibri,Arial,Helvetica,sans-serif;font-size:16px;line-height:normal"><font
                  face="Calibri,Arial,Helvetica,sans-serif,Apple Color
                  Emoji,Segoe UI Emoji,NotoColorEmoji,Segoe UI
                  Symbol,Android Emoji,EmojiSymbols" size="2"
                  color="#212121"><span style="font-size:16px"><font
                      face="Arial,Helvetica,sans-serif" size="3"><span
                        style="font-size:12pt">  cmpxchg </span></font><font
                      face="Arial,Helvetica,sans-serif" size="3"><span
                        style="font-size:12pt">i32* %addr, i32 42, i32 0
                        synchscope(3) monotonic monotonic, </span></font><font
                      face="Arial,Helvetica,sans-serif" size="3"><span
                        style="font-size:12pt">3</span></font></span></font></div>
              <div
style="color:rgb(0,0,0);font-family:Calibri,Arial,Helvetica,sans-serif;font-size:16px;line-height:normal"><font
                  face="Calibri,Arial,Helvetica,sans-serif,Apple Color
                  Emoji,Segoe UI Emoji,NotoColorEmoji,Segoe UI
                  Symbol,Android Emoji,EmojiSymbols" size="2"
                  color="#212121"><span style="font-size:16px"><font
                      face="Arial,Helvetica,sans-serif" size="2"><span
                        style="font-size:11pt"><br>
                      </span></font></span></font></div>
              <div
style="color:rgb(0,0,0);font-family:Calibri,Arial,Helvetica,sans-serif;font-size:16px;line-height:normal"><font
                  face="Calibri,Arial,Helvetica,sans-serif,Apple Color
                  Emoji,Segoe UI Emoji,NotoColorEmoji,Segoe UI
                  Symbol,Android Emoji,EmojiSymbols" size="2"
                  color="#212121"><span style="font-size:16px"><font
                      face="Arial,Helvetica,sans-serif" size="3"><span
                        style="font-size:12pt">  ret </span></font><font
                      face="Arial,Helvetica,sans-serif" size="3"><span
                        style="font-size:12pt">void</span></font></span></font></div>
              <div
style="color:rgb(0,0,0);font-family:Calibri,Arial,Helvetica,sans-serif;font-size:16px;line-height:normal"><font
                  face="Calibri,Arial,Helvetica,sans-serif,Apple Color
                  Emoji,Segoe UI Emoji,NotoColorEmoji,Segoe UI
                  Symbol,Android Emoji,EmojiSymbols" size="2"
                  color="#212121"><span style="font-size:16px"><font
                      face="Arial,Helvetica,sans-serif" size="3"><span
                        style="font-size:12pt">}</span></font></span></font></div>
              <div
style="color:rgb(0,0,0);font-family:Calibri,Arial,Helvetica,sans-serif;font-size:16px;line-height:normal"><font
                  face="Calibri,Arial,Helvetica,sans-serif,Apple Color
                  Emoji,Segoe UI Emoji,NotoColorEmoji,Segoe UI
                  Symbol,Android Emoji,EmojiSymbols" size="2"
                  color="#212121"><span style="font-size:16px"><font
                      face="Arial,Helvetica,sans-serif" size="2"><span
                        style="font-size:11pt"><br>
                      </span></font></span></font></div>
              <div
style="color:rgb(0,0,0);font-family:Calibri,Arial,Helvetica,sans-serif;font-size:16px;line-height:normal"><font
                  face="Calibri,Arial,Helvetica,sans-serif,Apple Color
                  Emoji,Segoe UI Emoji,NotoColorEmoji,Segoe UI
                  Symbol,Android Emoji,EmojiSymbols" size="2"
                  color="#212121"><span style="font-size:16px"><font
                      face="Arial,Helvetica,sans-serif" size="3"><span
                        style="font-size:12pt">!synchscope </span></font><font
                      face="Arial,Helvetica,sans-serif" size="3"><span
                        style="font-size:12pt">= metadata !{{i32 0,
                        !"SingleThread"}, </span></font><font
                      face="Arial,Helvetica,sans-serif" size="3"><span
                        style="font-size:12pt">{i32 2, !"WorkGroup"}, </span></font><font
                      face="Arial,Helvetica,sans-serif" size="3"><span
                        style="font-size:12pt">...}</span></font></span></font></div>
              <div
style="color:rgb(0,0,0);font-family:Calibri,Arial,Helvetica,sans-serif;font-size:16px;line-height:normal"><span
                  style="color:rgb(33,33,33);font-family:'Helvetica
                  Neue',Helvetica,Arial,sans-serif;font-size:small;line-height:20px">=================================================================</span></div>
              <div
style="color:rgb(0,0,0);font-family:Calibri,Arial,Helvetica,sans-serif;font-size:16px;line-height:normal"><span style="color:rgb(33,33,33);font-family:Arial;white-space:pre-wrap;line-height:1.38">
</span></div>
              <div
style="color:rgb(0,0,0);font-family:Calibri,Arial,Helvetica,sans-serif;font-size:16px;line-height:normal"><span style="color:rgb(33,33,33);font-family:Arial;white-space:pre-wrap;line-height:1.38">Thank you!</span></div>
              <div
style="color:rgb(0,0,0);font-family:Calibri,Arial,Helvetica,sans-serif;font-size:16px;line-height:normal"><span style="color:rgb(33,33,33);font-family:Arial;white-space:pre-wrap;line-height:1.38">
</span></div>
              <div
style="color:rgb(0,0,0);font-family:Calibri,Arial,Helvetica,sans-serif;font-size:16px;line-height:normal"><span style="color:rgb(33,33,33);font-family:Arial;white-space:pre-wrap;line-height:1.38">---</span></div>
              <div
style="color:rgb(0,0,0);font-family:Calibri,Arial,Helvetica,sans-serif;font-size:16px;line-height:normal"><span style="color:rgb(33,33,33);font-family:Arial;white-space:pre-wrap;line-height:1.38">Best regards,</span><br>
              </div>
              <div
style="color:rgb(0,0,0);font-family:Calibri,Arial,Helvetica,sans-serif;font-size:16px;line-height:normal"><span><span style="font-family:Arial;color:rgb(33,33,33);vertical-align:baseline;white-space:pre-wrap">Ke</span></span><br>
              </div>
            </div>
          </blockquote>
        </div>
        <br>
        <br clear="all">
        <div><br>
        </div>
        -- <br>
        <div class="gmail_signature">
          <div dir="ltr">
            <div><font color="#0b5394">Best Regard,<br>
                Ke Bai, Ph.D.</font><br>
            </div>
          </div>
        </div>
      </div>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">_______________________________________________
LLVM Developers mailing list
<a class="moz-txt-link-abbreviated" href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>
<a class="moz-txt-link-freetext" href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a>
</pre>
    </blockquote>
    <br>
  </body>
</html>