[Compiler-rt][PATCH] Fix MSVC compilation of lib/profile/InstrProfData.inc

Xinliang David Li via llvm-commits llvm-commits at lists.llvm.org
Sun Dec 20 11:05:17 PST 2015


We can not use template for C runtime.

Here we only care about updating pointer values, so we can have two
versions one for _WIN32 and one for _WIN64. I will help adding the
support.

David

On Sun, Dec 20, 2015 at 4:08 AM, Johan Engelen <jbc.engelen at gmail.com> wrote:
>
>
> On Sat, Dec 19, 2015 at 8:00 PM, Xinliang David Li <davidxl at google.com>
> wrote:
>>
>> On Sat, Dec 19, 2015 at 10:27 AM, Johan Engelen <jbc.engelen at gmail.com>
>> wrote:
>> >
>> > 2. COMPILER_RT_HAS_ATOMICS should not be 1 for MSVC. Unfortunately, MSVC
>> > does not have a drop-in replacement for GCC's
>> > __sync_bool_compare_and_swap,
>> > and so a fix is non-trivial.
>>
>> How about InterlockedCompareExchange?
>
>
> I think something like this might work, but I'm not sure.
> InterlockedCompareExchange is not overloaded for different types, like
> __sync_bool_compare_and_swap is.
>
> template <typename T>
> bool BoolCmpXchg(T *Ptr, T OldV, T NewV) {
>   T origval;
>   if (sizeof(T) == 8)
>      origval = InterlockedCompareExchange64(Ptr, NewV, OldV);
>   else if (sizeof(T) == 4)
>      origval = InterlockedCompareExchange(Ptr, NewV, OldV);
>   else if (sizeof(T) == 2)
>      origval = InterlockedCompareExchange16(Ptr, NewV, OldV);
>   else
>      assert(0);
>   return origval == OldV
> }
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>


More information about the llvm-commits mailing list