[llvm-dev] Memory scope proposal

Philip Reames via llvm-dev llvm-dev at lists.llvm.org
Mon Apr 18 16:40:19 PDT 2016



On 04/18/2016 09:45 AM, Mehdi Amini via llvm-dev wrote:
>> On Apr 18, 2016, at 9:12 AM, Tom Stellard via llvm-dev <llvm-dev at lists.llvm.org> wrote:
>>
>> Here is the initial proposal with some formatting fixed:
>>
>> 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:
>> https://groups.google.com/forum/#!searchin/llvm-dev/hsail/llvm-dev/46eEpS5h0E4/i3T9xw-DNVYJ
>>
>> Here is our new proposal:
>>
>> =================================================================
>> 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.
>>
>> The proposed syntax for synchronization scope is as follows:
>> * Synchronization scopes are of arbitrary width, but implemented as
>>   unsigned in the bitcode, just like address spaces.
>> * Cross-thread is default.
>> * Keyword "singlethread" is unchanged
>> * New syntax "synchscope(n)" for other target-specific scopes.
>> * There is no keyword for cross-thread, but it can be specified as
>>   "synchscope(0)".
>
> Why not going with a metadata attachment directly and kill the "singlethread" keyword? Something like:
> Something like:
>
>   cmpxchg i32* %addr, i32 42, i32 0 monotonic monotonic, 3, !memory.scope{!42}
>   cmpxchg i32* %addr, i32 42, i32 0 monotonic monotonic, 3, !memory.scope{!43}
>
> ...
>
> !42 = !{"singlethread"}
> !43 = !{"L2"}
>
>
> I also avoids manipulating/pruning the global map, and target won't depend on integer to keep bitcode compatibility.
+1.  I like this idea.  Haven't given it serious thought, but on the 
surface this sounds nice. We'd need to establish a naming scheme so that 
targets could add meta tags without preventing upstream from adding 
generic ones going forward.

Philip



More information about the llvm-dev mailing list