<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Mar 28, 2016, at 7:17 PM, Philip Reames via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" class="">llvm-dev@lists.llvm.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class="">
  
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type" class="">
  
  <div text="#000000" bgcolor="#FFFFFF" class="">
    Ke,<br class="">
    <br class="">
    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 class=""></div></div></blockquote><div><br class=""></div><div>FWIW, I’m very interested in seeing it go in, but haven’t had a lot of time to write a response.</div><br class=""><blockquote type="cite" class=""><div class=""><div text="#000000" bgcolor="#FFFFFF" class="">
    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 class=""></div></div></blockquote><div><br class=""></div><div>I don’t know about Ke’s use cases, but I at least am not very concerned with having any portion of LLVM optimize them.  Right now LLVM has no way to represent the information encoded here at all.</div><br class=""><blockquote type="cite" class=""><div class=""><div text="#000000" bgcolor="#FFFFFF" class="">
    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 class=""></div></div></blockquote><div><br class=""></div><div>Scopes are orthogonal to ordering constraints.  Scopes are about memory operation visibility, primarily in the context of a machine with non-coherent caches.  Imagine an accelerator with:</div><div><br class=""></div><div>- Per HW thread load/store buffers</div><div>- Per core L1</div><div>- Accelerator-wide L2</div><div>- Whole-system DRAM</div><div><br class=""></div><div>… and at any level of the hierarchy, the caching for one thread/core/accelerator may not be coherent with caches for other threads/cores/accelerators.</div><div><br class=""></div><div>Scopes allow the program author to express the requisite visibility for a memory option; an that needs to be visible to other cores within the accelerator may need to bypass or flush the per-core L1.  Communication to the host CPU or other accelerators may similarly need to bypass the the L2.</div><div><br class=""></div><div>—Owen</div><br class=""><blockquote type="cite" class=""><div class=""><div text="#000000" bgcolor="#FFFFFF" class="">
    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 class="">
    <br class="">
    Philip<br class="">
    <br class="">
    <div class="moz-cite-prefix">On 03/22/2016 01:42 PM, Ke Bai via
      llvm-dev wrote:<br class="">
    </div>
    <blockquote cite="mid:CAA6bMpozX=9e10Tktoh9t2jT3AZ=a7wF3u+okAatZ=M-c_V-EA@mail.gmail.com" type="cite" class="">
      <div dir="ltr" class="">
        <div class="gmail_default" style="font-family:arial,helvetica,sans-serif;color:rgb(11,83,148);display:inline">​
          ​</div>
        Dear all,<br class="">
        <br class="">
        Here is the plain text version of the proposal:<br class="">
        <br class="">
        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 class="">
        <a moz-do-not-send="true" href="https://groups.google.com/forum/#%21searchin/llvm-dev/hsail/llvm-dev/46eEpS5h0E4/i3T9xw-DNVYJ" class="">https://groups.google.com/forum/#!searchin/llvm-dev/hsail/llvm-dev/46eEpS5h0E4/i3T9xw-DNVYJ</a><br class="">
        <br class="">
        Here is our new proposal:<br class="">
        <br class="">
=================================================================<br class="">
        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 class="">
        <br class="">
        The proposed syntax for synchronization scope is as follows:<br class="">
        * Synchronization scopes are of arbitrary width, but implemented
        as unsigned in the bitcode, just like address spaces.<br class="">
        * Cross-thread is default.<br class="">
        * Keyword "singlethread" is unchanged<br class="">
        * New syntax "synchscope(n)" for other target-specific scopes. <br class="">
        * There is no keyword for cross-thread, but it can be specified
        as "synchscope(0)".<br class="">
        <br class="">
        The proposed new integer implementation expanded synchronization
        scopes are as follows: <br class="">
        ****************************************************************<br class="">
        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 class="">
        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 class="">
        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 class="">
                     
        <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 class="">
        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 class="">
        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 class="">
        ****************************************************************<br class="">
        <br class="">
        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 class="">
        <br class="">
        Name Mapping<br class="">
        <br class="">
        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 class="">
        <br class="">
        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 class="">
        <br class="">
        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 class="">
        <br class="">
        A bitcode example with the proposal<br class="">
*****************************************************************<br class="">
        define void  <at> test(i32* %addr) {<br class="">
        ; forward compatibility<br class="">
          cmpxchg i32* %addr, i32 42, i32 0 singlethread monotonic
        monotonic<br class="">
        <br class="">
        ; new synchscope that will be defined by each backend<br class="">
          cmpxchg i32* %addr, i32 42, i32 0 synchscope(2) monotonic
        monotonic, 2<br class="">
          cmpxchg i32* %addr, i32 42, i32 0 synchscope(3) monotonic
        monotonic, 3<br class="">
        <br class="">
          ret void<br class="">
        }<br class="">
        <br class="">
        !synchscope = metadata !{{i32 0, !"SingleThread"}, {i32 2,
        !"WorkGroup"}, ...}<br class="">
*****************************************************************<br class="">
        <br class="">
        =================================================================
      </div>
      <div class="gmail_extra"><br class="">
        <div class="gmail_quote">On Thu, Jan 28, 2016 at 12:27 PM, Ke
          Bai <span dir="ltr" class=""><<a moz-do-not-send="true" href="mailto:kebai613@gmail.com" target="_blank" class="">kebai613@gmail.com</a>></span>
          wrote:<br class="">
          <blockquote class="gmail_quote" style="margin:0 0 0
            .8ex;border-left:1px #ccc solid;padding-left:1ex">
            <div dir="ltr" class="">
              <div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 16px; line-height: normal;" class=""><span style="font-family:Arial;white-space:pre-wrap;line-height:1.38" class="">Hi all,</span><br class="">
              </div>
              <div class=""><span class=""><br class=""><div style="line-height: 1.38; margin-top: 0pt; margin-bottom: 0pt;" class=""><span style="font-size:16px;font-family:Arial;color:rgb(34,34,34);vertical-align:baseline;white-space:pre-wrap" class="">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; vertical-align: baseline; white-space: pre-wrap; background-color: transparent;" class="">it can be found here:</span></div><div style="line-height: 1.38; margin-top: 0pt; margin-bottom: 0pt;" class=""><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" class=""><span style="font-size:16px;font-family:Arial;color:rgb(17,85,204);text-decoration:underline;vertical-align:baseline;white-space:pre-wrap" class=""></span></a><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></div>
                  <br class=""><div style="line-height: 1.38; margin-top: 0pt; margin-bottom: 0pt;" class=""><span style="font-size:16px;font-family:Arial;vertical-align:baseline;white-space:pre-wrap" class="">Here is our new proposal:</span></div>
                  <div class="">=================================================================</div>
                </span></div>
              <div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 16px; line-height: normal;" class=""><font style="color:rgb(33,33,33)" face="Arial,Helvetica,sans-serif" class="">We still let the
                  bitcode store memory scopes as </font><font style="color:rgb(33,33,33)" face="Arial,Helvetica,sans-serif" class=""><b class="">unsigned integers</b></font><font style="color:rgb(33,33,33)" face="Arial,Helvetica,sans-serif" class="">, 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" class=""><b class="">a global metadata
                    in the </b></font><font style="color:rgb(33,33,33)" face="Arial,Helvetica,sans-serif" class=""><b class="">file will provide
                    a map</b></font><font style="color:rgb(33,33,33)" face="Arial,Helvetica,sans-serif" class=""> 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" class="">behavior</font><font style="color:rgb(33,33,33)" face="Arial,Helvetica,sans-serif" class="">.</font></div>
              <div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 16px; line-height: normal;" class=""><font face="Calibri,Arial,Helvetica,sans-serif,Apple Color
                  Emoji,Segoe UI Emoji,NotoColorEmoji,Segoe UI
                  Symbol,Android Emoji,EmojiSymbols" size="2" color="#212121" class=""><span style="font-size:16px" class="">
                    <div style="margin-top:5.76pt;margin-bottom:10.8pt" class=""><font face="Calibri,Arial,Helvetica,sans-serif" class=""><font face="Arial,Helvetica,sans-serif" size="3" class=""><span style="font-size:12pt" class="">The proposed syntax
                            for synchronization scope is as follows:</span></font></font></div>
                  </span></font></div>
              <div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 16px; line-height: normal;" class=""><font face="Calibri,Arial,Helvetica,sans-serif,Apple Color
                  Emoji,Segoe UI Emoji,NotoColorEmoji,Segoe UI
                  Symbol,Android Emoji,EmojiSymbols" size="2" color="#212121" class=""><span style="font-size:16px" class="">
                    <ul style="margin-top:14pt;margin-bottom:14pt" class="">
                      <font face="Calibri,Arial,Helvetica,sans-serif" class="">
                        <li class=""><font face="Calibri,Arial,Helvetica,sans-serif" class=""><font face="Arial,Helvetica,sans-serif" size="3" class=""><span style="font-size:12pt" class="">Synch</span></font><font face="Arial,Helvetica,sans-serif" size="3" class=""><span style="font-size:12pt" class="">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" class=""><span style="font-size:11pt" class=""><br class="">
                              </span></font></font></li>
                        <li class=""><font face="Calibri,Arial,Helvetica,sans-serif" class=""><font face="Arial,Helvetica,sans-serif" size="3" class=""><span style="font-size:12pt" class="">Cross-thread is
                                default.</span></font><font face="Arial,Helvetica,sans-serif" size="2" class=""><span style="font-size:11pt" class=""><br class="">
                              </span></font></font></li>
                        <li class=""><font face="Calibri,Arial,Helvetica,sans-serif" class=""><font face="Arial,Helvetica,sans-serif" size="3" class=""><span style="font-size:12pt" class="">Keyword
                                "singlethread" is unchanged</span></font><font face="Arial,Helvetica,sans-serif" size="2" class=""><span style="font-size:11pt" class=""><br class="">
                              </span></font></font></li>
                        <li class=""><font face="Calibri,Arial,Helvetica,sans-serif" class=""><font face="Arial,Helvetica,sans-serif" size="3" class=""><span style="font-size:12pt" class="">New syntax
                                "synchscope(n)" for other
                                target-specific scopes. </span></font><font face="Arial,Helvetica,sans-serif" size="2" class=""><br class="">
                            </font></font></li>
                        <li class=""><font face="Calibri,Arial,Helvetica,sans-serif" class=""><font face="Arial,Helvetica,sans-serif" size="3" class=""><span style="font-size:12pt" class="">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" class=""><br class="">
                            </font></font></li>
                      </font>
                    </ul>
                  </span></font></div>
              <div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 16px; line-height: normal;" class=""><font face="Calibri,Arial,Helvetica,sans-serif,Apple Color
                  Emoji,Segoe UI Emoji,NotoColorEmoji,Segoe UI
                  Symbol,Android Emoji,EmojiSymbols" size="2" color="#212121" class=""><span style="font-size:16px" class=""><font face="Arial,Helvetica,sans-serif" class="">The proposed new
                      integer implementation expanded synchronization
                      scopes are as follows: </font></span></font></div>
              <div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 16px; line-height: normal;" class=""><font face="Calibri,Arial,Helvetica,sans-serif,Apple Color
                  Emoji,Segoe UI Emoji,NotoColorEmoji,Segoe UI
                  Symbol,Android Emoji,EmojiSymbols" size="2" color="#212121" class=""><span style="font-size:16px" class=""><font face="Arial,Helvetica,sans-serif" class="">
                      <table style="width:638px" width="638" cellpadding="7" cellspacing="0" class="">
                        <colgroup class=""><col style="width:154px" width="154" class=""></colgroup><colgroup class=""><col style="width:153px" width="153" class=""><col style="width:156px" width="156" class=""><col style="width:117px" width="117" class=""></colgroup><tbody class="">
                          <tr class="">
                            <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" class="">
                              <div style="margin-top:0px;margin-bottom:0px" class=""><font face="Arial,Helvetica,sans-serif" size="3" color="white" class=""><span style="font-size:12pt" lang="en-US" class=""><b class="">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" class="">
                              <div style="margin-top:0px;margin-bottom:0px" class=""><font face="Arial,Helvetica,sans-serif" size="3" color="white" class=""><span style="font-size:12pt" lang="en-US" class=""><b class="">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" class="">
                              <div style="margin-top:0px;margin-bottom:0px" class=""><font face="Arial,Helvetica,sans-serif" size="3" color="white" class=""><span style="font-size:12pt" lang="en-US" class=""><b class="">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" class="">
                              <div style="margin-top:0px;margin-bottom:0px" class=""><font face="Arial,Helvetica,sans-serif" size="3" color="white" class=""><span style="font-size:12pt" lang="en-US" class=""><b class="">Intermediate</b></span></font></div>
                            </td>
                          </tr>
                          <tr class="">
                            <td style="width:154px;padding:0px 5.76pt
                              0px 5.4pt;border:1pt solid rgb(0,0,1)" width="154" class="">
                              <div style="margin-top:0px;margin-bottom:0px" class=""><font face="Arial,Helvetica,sans-serif" size="3" class=""><span style="font-size:12pt" lang="en-US" class=""><b class="">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" class="">
                              <div style="margin-top:0px;margin-bottom:0px" class=""><font face="Arial,Helvetica,sans-serif" size="3" class=""><span style="font-size:12pt" lang="en-US" class="">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" class="">
                              <div style="margin-top:0px;margin-bottom:0px" class=""><font face="Arial,Helvetica,sans-serif" size="3" class=""><span style="font-size:12pt" lang="en-US" class="">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" class="">
                              <div style="margin-top:0px;margin-bottom:0px" class=""><font face="Arial,Helvetica,sans-serif" size="3" class=""><span style="font-size:12pt" lang="en-US" class="">unsigned n</span></font></div>
                            </td>
                          </tr>
                          <tr class="">
                            <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" class="">
                              <div style="margin-top:0px;margin-bottom:0px" class=""><font face="Arial,Helvetica,sans-serif" size="3" class=""><span style="font-size:12pt" lang="en-US" class=""><b class="">Assembly</b></span></font></div>
                            </td>
                            <td style="width:153px;padding:0px;border-style:none" width="153" class="">
                              <div style="margin-top:0px;margin-bottom:0px" class=""><font face="Arial,Helvetica,sans-serif" size="3" class=""><span style="font-size:12pt" lang="en-US" class="">singlethread,</span></font><font face="Arial,Helvetica,sans-serif" size="3" class=""><span style="font-size:12pt" lang="en-US" class=""><br class="">
                                  </span></font><font face="Arial,Helvetica,sans-serif" size="3" class=""><span style="font-size:12pt" lang="en-US" class="">synchscope(~0U)</span></font></div>
                            </td>
                            <td style="width:156px;padding:0px;border-style:none" width="156" class="">
                              <div style="margin-top:0px;margin-bottom:0px" align="justify" class=""><font face="Arial,Helvetica,sans-serif" size="3" class=""><span style="font-size:12pt" lang="en-US" class="">empty (default),</span></font><font face="Arial,Helvetica,sans-serif" size="3" class=""><span style="font-size:12pt" lang="en-US" class=""><br class="">
                                  </span></font><font face="Arial,Helvetica,sans-serif" size="3" class=""><span style="font-size:12pt" lang="en-US" class="">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" class="">
                              <div style="margin-top:0px;margin-bottom:0px" class=""><font face="Arial,Helvetica,sans-serif" size="3" class=""><span style="font-size:12pt" lang="en-US" class="">synchscope(n-1)</span></font></div>
                            </td>
                          </tr>
                          <tr class="">
                            <td style="width:154px;padding:0px 5.76pt
                              0px 5.4pt;border:1pt solid rgb(0,0,1)" width="154" class="">
                              <div style="margin-top:0px;margin-bottom:0px" class=""><font face="Arial,Helvetica,sans-serif" size="3" class=""><span style="font-size:12pt" lang="en-US" class=""><b class="">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" class="">
                              <div style="margin-top:0px;margin-bottom:0px" class=""><font face="Arial,Helvetica,sans-serif" size="3" class=""><span style="font-size:12pt" lang="en-US" class="">~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" class="">
                              <div style="margin-top:0px;margin-bottom:0px" class=""><font face="Arial,Helvetica,sans-serif" size="3" class=""><span style="font-size:12pt" lang="en-US" class="">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" class="">
                              <div style="margin-top:0px;margin-bottom:0px" class=""><font face="Arial,Helvetica,sans-serif" size="3" class=""><span style="font-size:12pt" lang="en-US" class="">unsigned n-1</span></font></div>
                            </td>
                          </tr>
                          <tr class="">
                            <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" class="">
                              <div style="margin-top:0px;margin-bottom:0px" class=""><font face="Arial,Helvetica,sans-serif" size="3" class=""><span style="font-size:12pt" lang="en-US" class=""><b class="">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" class="">
                              <div style="margin-top:0px;margin-bottom:0px" class=""><font face="Arial,Helvetica,sans-serif" size="3" class=""><span style="font-size:12pt" lang="en-US" class="">~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" class="">
                              <div style="margin-top:0px;margin-bottom:0px" class=""><font face="Arial,Helvetica,sans-serif" size="3" class=""><span style="font-size:12pt" lang="en-US" class="">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" class="">
                              <div style="margin-top:0px;margin-bottom:0px" class=""><font face="Arial,Helvetica,sans-serif" size="3" class=""><span style="font-size:12pt" lang="en-US" class="">unsigned n-1</span></font></div>
                            </td>
                          </tr>
                        </tbody>
                      </table>
                    </font>
                    <div style="margin-top:5.76pt;margin-bottom:10.8pt" class=""><font face="Calibri,Arial,Helvetica,sans-serif" class=""><font face="Arial,Helvetica,sans-serif" class=""><span lang="en-US" class="">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" class=""><span class=""><p dir="ltr" style="line-height:1.38;margin-top:6pt;margin-bottom:11pt" class=""><span style="font-family: Arial; font-weight: 700; vertical-align: baseline; white-space: pre-wrap;" class="">Name Mapping</span></p><p dir="ltr" style="line-height:1.38;margin-top:6pt;margin-bottom:11pt" class=""><span style="font-family: Arial; vertical-align: baseline; white-space: pre-wrap;" class="">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" class=""><span style="font-family: Arial; white-space: pre-wrap; line-height: 1.38;" class="">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" class=""><span style="font-family: Arial; line-height: 1.38; white-space: pre-wrap;" class="">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" class=""><font face="Calibri,Arial,Helvetica,sans-serif" class=""><font face="Arial,Helvetica,sans-serif" class=""><span lang="en-US" class=""><b class="">A </b></span></font><font face="Arial,Helvetica,sans-serif" class=""><b class="">bitcode
                            example with the proposal</b></font></font></div>
                  </span></font></div>
              <div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 16px; line-height: normal;" class=""><font face="Calibri,Arial,Helvetica,sans-serif,Apple Color
                  Emoji,Segoe UI Emoji,NotoColorEmoji,Segoe UI
                  Symbol,Android Emoji,EmojiSymbols" size="2" color="#212121" class=""><span style="font-size:16px" class=""><font face="Arial,Helvetica,sans-serif" size="3" class=""><span style="font-size:12pt" class="">define </span></font><font face="Arial,Helvetica,sans-serif" size="3" class=""><span style="font-size:12pt" class="">void  <at>
                        test(i32* %addr) {</span></font></span></font></div>
              <div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 16px; line-height: normal;" class=""><font face="Calibri,Arial,Helvetica,sans-serif,Apple Color
                  Emoji,Segoe UI Emoji,NotoColorEmoji,Segoe UI
                  Symbol,Android Emoji,EmojiSymbols" size="2" color="#212121" class=""><span style="font-size:16px" class=""><font face="Arial,Helvetica,sans-serif" size="3" class=""><span style="font-size:12pt" class="">; </span></font><font face="Arial,Helvetica,sans-serif" size="3" class=""><span style="font-size:12pt" class="">forward compatibility</span></font><font face="Arial,Helvetica,sans-serif" size="2" class=""><span style="font-size:11pt" class=""><br class="">
                      </span></font></span></font></div>
              <div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 16px; line-height: normal;" class=""><font face="Calibri,Arial,Helvetica,sans-serif,Apple Color
                  Emoji,Segoe UI Emoji,NotoColorEmoji,Segoe UI
                  Symbol,Android Emoji,EmojiSymbols" size="2" color="#212121" class=""><span style="font-size:16px" class=""><font face="Arial,Helvetica,sans-serif" size="3" class=""><span style="font-size:12pt" class="">  cmpxchg </span></font><font face="Arial,Helvetica,sans-serif" size="3" class=""><span style="font-size:12pt" class="">i32* %addr, i32 42, i32 0
                        singlethread monotonic monotonic</span></font></span></font></div>
              <div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 16px; line-height: normal;" class=""><font face="Calibri,Arial,Helvetica,sans-serif,Apple Color
                  Emoji,Segoe UI Emoji,NotoColorEmoji,Segoe UI
                  Symbol,Android Emoji,EmojiSymbols" size="2" color="#212121" class=""><span style="font-size:16px" class=""><font face="Arial,Helvetica,sans-serif" size="2" class=""><span style="font-size:11pt" class=""><br class="">
                      </span></font></span></font></div>
              <div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 16px; line-height: normal;" class=""><font face="Calibri,Arial,Helvetica,sans-serif,Apple Color
                  Emoji,Segoe UI Emoji,NotoColorEmoji,Segoe UI
                  Symbol,Android Emoji,EmojiSymbols" size="2" color="#212121" class=""><span style="font-size:16px" class=""><font face="Arial,Helvetica,sans-serif" size="3" class=""><span style="font-size:12pt" class="">; </span></font><font face="Arial,Helvetica,sans-serif" size="3" class=""><span style="font-size:12pt" class="">new synchscope that will
                        be defined by each backend</span></font></span></font></div>
              <div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 16px; line-height: normal;" class=""><font face="Calibri,Arial,Helvetica,sans-serif,Apple Color
                  Emoji,Segoe UI Emoji,NotoColorEmoji,Segoe UI
                  Symbol,Android Emoji,EmojiSymbols" size="2" color="#212121" class=""><span style="font-size:16px" class=""><font face="Arial,Helvetica,sans-serif" size="3" class=""><span style="font-size:12pt" class="">  cmpxchg </span></font><font face="Arial,Helvetica,sans-serif" size="3" class=""><span style="font-size:12pt" class="">i32* %addr, i32 42, i32 0
                        synchscope(2) monotonic monotonic, </span></font><font face="Arial,Helvetica,sans-serif" size="3" class=""><span style="font-size:12pt" class="">2</span></font></span></font></div>
              <div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 16px; line-height: normal;" class=""><font face="Calibri,Arial,Helvetica,sans-serif,Apple Color
                  Emoji,Segoe UI Emoji,NotoColorEmoji,Segoe UI
                  Symbol,Android Emoji,EmojiSymbols" size="2" color="#212121" class=""><span style="font-size:16px" class=""><font face="Arial,Helvetica,sans-serif" size="3" class=""><span style="font-size:12pt" class="">  cmpxchg </span></font><font face="Arial,Helvetica,sans-serif" size="3" class=""><span style="font-size:12pt" class="">i32* %addr, i32 42, i32 0
                        synchscope(3) monotonic monotonic, </span></font><font face="Arial,Helvetica,sans-serif" size="3" class=""><span style="font-size:12pt" class="">3</span></font></span></font></div>
              <div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 16px; line-height: normal;" class=""><font face="Calibri,Arial,Helvetica,sans-serif,Apple Color
                  Emoji,Segoe UI Emoji,NotoColorEmoji,Segoe UI
                  Symbol,Android Emoji,EmojiSymbols" size="2" color="#212121" class=""><span style="font-size:16px" class=""><font face="Arial,Helvetica,sans-serif" size="2" class=""><span style="font-size:11pt" class=""><br class="">
                      </span></font></span></font></div>
              <div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 16px; line-height: normal;" class=""><font face="Calibri,Arial,Helvetica,sans-serif,Apple Color
                  Emoji,Segoe UI Emoji,NotoColorEmoji,Segoe UI
                  Symbol,Android Emoji,EmojiSymbols" size="2" color="#212121" class=""><span style="font-size:16px" class=""><font face="Arial,Helvetica,sans-serif" size="3" class=""><span style="font-size:12pt" class="">  ret </span></font><font face="Arial,Helvetica,sans-serif" size="3" class=""><span style="font-size:12pt" class="">void</span></font></span></font></div>
              <div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 16px; line-height: normal;" class=""><font face="Calibri,Arial,Helvetica,sans-serif,Apple Color
                  Emoji,Segoe UI Emoji,NotoColorEmoji,Segoe UI
                  Symbol,Android Emoji,EmojiSymbols" size="2" color="#212121" class=""><span style="font-size:16px" class=""><font face="Arial,Helvetica,sans-serif" size="3" class=""><span style="font-size:12pt" class="">}</span></font></span></font></div>
              <div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 16px; line-height: normal;" class=""><font face="Calibri,Arial,Helvetica,sans-serif,Apple Color
                  Emoji,Segoe UI Emoji,NotoColorEmoji,Segoe UI
                  Symbol,Android Emoji,EmojiSymbols" size="2" color="#212121" class=""><span style="font-size:16px" class=""><font face="Arial,Helvetica,sans-serif" size="2" class=""><span style="font-size:11pt" class=""><br class="">
                      </span></font></span></font></div>
              <div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 16px; line-height: normal;" class=""><font face="Calibri,Arial,Helvetica,sans-serif,Apple Color
                  Emoji,Segoe UI Emoji,NotoColorEmoji,Segoe UI
                  Symbol,Android Emoji,EmojiSymbols" size="2" color="#212121" class=""><span style="font-size:16px" class=""><font face="Arial,Helvetica,sans-serif" size="3" class=""><span style="font-size:12pt" class="">!synchscope </span></font><font face="Arial,Helvetica,sans-serif" size="3" class=""><span style="font-size:12pt" class="">= metadata !{{i32 0,
                        !"SingleThread"}, </span></font><font face="Arial,Helvetica,sans-serif" size="3" class=""><span style="font-size:12pt" class="">{i32 2, !"WorkGroup"}, </span></font><font face="Arial,Helvetica,sans-serif" size="3" class=""><span style="font-size:12pt" class="">...}</span></font></span></font></div>
              <div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 16px; line-height: normal;" class=""><span style="color:rgb(33,33,33);font-family:'Helvetica
                  Neue',Helvetica,Arial,sans-serif;font-size:small;line-height:20px" class="">=================================================================</span></div>
              <div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 16px; line-height: normal;" class=""><span style="color:rgb(33,33,33);font-family:Arial;white-space:pre-wrap;line-height:1.38" class="">
</span></div>
              <div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 16px; line-height: normal;" class=""><span style="color:rgb(33,33,33);font-family:Arial;white-space:pre-wrap;line-height:1.38" class="">Thank you!</span></div>
              <div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 16px; line-height: normal;" class=""><span style="color:rgb(33,33,33);font-family:Arial;white-space:pre-wrap;line-height:1.38" class="">
</span></div>
              <div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 16px; line-height: normal;" class=""><span style="color:rgb(33,33,33);font-family:Arial;white-space:pre-wrap;line-height:1.38" class="">---</span></div>
              <div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 16px; line-height: normal;" class=""><span style="color:rgb(33,33,33);font-family:Arial;white-space:pre-wrap;line-height:1.38" class="">Best regards,</span><br class="">
              </div>
              <div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 16px; line-height: normal;" class=""><span class=""><span style="font-family:Arial;color:rgb(33,33,33);vertical-align:baseline;white-space:pre-wrap" class="">Ke</span></span><br class="">
              </div>
            </div>
          </blockquote>
        </div>
        <br class="">
        <br clear="all" class="">
        <div class=""><br class="">
        </div>
        -- <br class="">
        <div class="gmail_signature">
          <div dir="ltr" class="">
            <div class=""><font color="#0b5394" class="">Best Regard,<br class="">
                Ke Bai, Ph.D.</font><br class="">
            </div>
          </div>
        </div>
      </div>
      <br class="">
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br class="">
      <pre wrap="" class="">_______________________________________________
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 class="">
  </div>

_______________________________________________<br class="">LLVM Developers mailing list<br class=""><a href="mailto:llvm-dev@lists.llvm.org" class="">llvm-dev@lists.llvm.org</a><br class="">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev<br class=""></div></blockquote></div><br class=""></body></html>