Admin message

Due to a large amount of spam we do not allow new users to create repositories, they are "external" users. If you are a new user and want to create a repository, for example for forking GHC, open a new issue on ghc/ghc using the "get-verified" issue template

enable GHC LLVM backend to use LLVM provided CAS / Atomicity primitives?
LLVM provides a number of atomicity / memory ordering primitives. currently the CAS primops exposed at the CMM level are ffi'd inline assembly fun calls. this means that for certain concurrency primops, we've got fun calls within funcalls that could be easily inlined if we did it in a more llvm direct way. A notable example of this is the implementation of ` stg_atomicModifyMutVarzh ` relevant basic llmv docs are the following [Atomic llvm ops](http://llvm.org/docs/LangRef.html#cmpxchg-instruction) [semantics of the various ordering levels](http://llvm.org/docs/Atomics.html) relevant locations in the ghc source [CAS inline assembly](https://github.com/ghc/ghc/blob/master/includes/stg/SMP.h#L170) [defn of atomicModifyMutVar cmm code](https://github.com/ghc/ghc/blob/master/rts/PrimOps.cmm#L282) Based upon my reading of the relevant GHC cmm code, and reading the semantics of the LLVM operations, the right level of atomic ordering in the generated bit code would be "SequentiallyConsistent". a first step would be to modify the CMM -\> LLVM pass to substitute the cas funcall with the right llvm operation. This ** SEEMS ** like it'd be very very easy to do and low hanging fruit. Theres a few upsides that ** might ** come out of this. 1. would be easy to augment to also provide a doubleCAS primitive, which would be useful in writing various lock free data structures. 1. would increase the portability / ease of retargeting new platforms / hardware via LLVM. (not needing to worry about the target's memory consistency model / write new cases of inline assembly) 1. (this would need benchmarks) could potentially improve the performance of certain heavy concurrency operations by eliminating a funcall in an otherwise tight loop. 1. Theres probably other interesting possible upside, such as perhaps having more of the rts be nicely writeable in CMM? (esp since theres now native funcall support) 1. Also would make the CMM memory model a bit more explicit perhaps? This seems like a \*relatively\* managable patch to write. I'm up for spending time on this if, should it work, it'd be likely to be merged in. it'd also be a good warm up for a number of other things I want to do, including http://hackage.haskell.org/trac/ghc/ticket/5567\##7883 <details><summary>Trac metadata</summary> | Trac field | Value | | ---------------------- | -------------- | | Version | 7.7 | | Type | FeatureRequest | | TypeOfFailure | OtherFailure | | Priority | normal | | Resolution | Unresolved | | Component | Compiler | | Test case | | | Differential revisions | | | BlockedBy | | | Related | | | Blocking | | | CC | | | Operating system | | | Architecture | | </details> <!-- {"blocked_by":[],"summary":"enable GHC LLVM backend to use LLVM provided CAS / Atomicity primitives?","status":"New","operating_system":"","component":"Compiler","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"7.7","keywords":[],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"FeatureRequest","description":"LLVM provides a number of atomicity / memory ordering primitives.\r\n\r\ncurrently the CAS primops exposed at the CMM level are ffi'd inline assembly fun calls. this means that for certain concurrency primops, we've got fun calls within funcalls that could be easily inlined if we did it in a more llvm direct way. A notable example of this is the implementation of {{{ stg_atomicModifyMutVarzh }}}\r\n\r\n\r\nrelevant basic llmv docs are the following\r\n[http://llvm.org/docs/LangRef.html#cmpxchg-instruction Atomic llvm ops]\r\n\r\n[http://llvm.org/docs/Atomics.html semantics of the various ordering levels]\r\n\r\nrelevant locations in the ghc source\r\n[https://github.com/ghc/ghc/blob/master/includes/stg/SMP.h#L170 CAS inline assembly]\r\n\r\n[https://github.com/ghc/ghc/blob/master/rts/PrimOps.cmm#L282 defn of atomicModifyMutVar cmm code]\r\n\r\n\r\nBased upon my reading of the relevant GHC cmm code, and reading the semantics of the LLVM operations, the right level of atomic ordering in the generated bit code would be \"SequentiallyConsistent\".\r\n\r\na first step would be to modify the CMM -> LLVM pass to substitute the cas funcall with the right llvm operation. This ''' SEEMS ''' like it'd be very very easy to do and low hanging fruit. \r\n\r\nTheres a few upsides that ''' might ''' come out of this. \r\n\r\n 1. would be easy to augment to also provide a doubleCAS primitive, which would be useful in writing various lock free data structures.\r\n 2. would increase the portability / ease of retargeting new platforms / hardware via LLVM. (not needing to worry about the target's memory consistency model / write new cases of inline assembly)\r\n 3. (this would need benchmarks) could potentially improve the performance of certain heavy concurrency operations by eliminating a funcall in an otherwise tight loop.\r\n 4. Theres probably other interesting possible upside, such as perhaps having more of the rts be nicely writeable in CMM? (esp since theres now native funcall support)\r\n 5. Also would make the CMM memory model a bit more explicit perhaps?\r\n \r\n\r\nThis seems like a *relatively* managable patch to write. I'm up for spending time on this if, should it work, it'd be likely to be merged in.\r\n\r\nit'd also be a good warm up for a number of other things I want to do, including http://hackage.haskell.org/trac/ghc/ticket/5567#comment:10 \r\n\r\n","type_of_failure":"OtherFailure","blocking":[]} -->
issue