[llvm] r335823 - Unify sorted asserts to use the existing atomic pattern

Hans Wennborg via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 28 03:29:24 PDT 2018


r335831 to follow-up :-)

On Thu, Jun 28, 2018 at 12:03 PM, Benjamin Kramer via llvm-commits
<llvm-commits at lists.llvm.org> wrote:
> Author: d0k
> Date: Thu Jun 28 03:03:45 2018
> New Revision: 335823
>
> URL: http://llvm.org/viewvc/llvm-project?rev=335823&view=rev
> Log:
> Unify sorted asserts to use the existing atomic pattern
>
> These are all benign races and only visible in !NDEBUG. tsan complains
> about it, but a simple atomic bool is sufficient to make it happy.
>
> Modified:
>     llvm/trunk/lib/Target/ARM/ARMExpandPseudoInsts.cpp
>     llvm/trunk/lib/Target/X86/X86EvexToVex.cpp
>     llvm/trunk/lib/Target/X86/X86InstrInfo.cpp
>
> Modified: llvm/trunk/lib/Target/ARM/ARMExpandPseudoInsts.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/ARMExpandPseudoInsts.cpp?rev=335823&r1=335822&r2=335823&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Target/ARM/ARMExpandPseudoInsts.cpp (original)
> +++ llvm/trunk/lib/Target/ARM/ARMExpandPseudoInsts.cpp Thu Jun 28 03:03:45 2018
> @@ -415,11 +415,11 @@ static const NEONLdStTableEntry NEONLdSt
>  static const NEONLdStTableEntry *LookupNEONLdSt(unsigned Opcode) {
>  #ifndef NDEBUG
>    // Make sure the table is sorted.
> -  static bool TableChecked = false;
> -  if (!TableChecked) {
> +  static std::atomic<bool> TableChecked(false);
> +  if (!TableChecked.load(std::memory_order_relaxed)) {
>      assert(std::is_sorted(std::begin(NEONLdStTable), std::end(NEONLdStTable)) &&
>             "NEONLdStTable is not sorted!");
> -    TableChecked = true;
> +    TablesChecked.store(true, std::memory_order_relaxed);
>    }
>  #endif
>
>
> Modified: llvm/trunk/lib/Target/X86/X86EvexToVex.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86EvexToVex.cpp?rev=335823&r1=335822&r2=335823&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Target/X86/X86EvexToVex.cpp (original)
> +++ llvm/trunk/lib/Target/X86/X86EvexToVex.cpp Thu Jun 28 03:03:45 2018
> @@ -239,15 +239,15 @@ bool EvexToVexInstPass::CompressEvexToVe
>
>  #ifndef NDEBUG
>    // Make sure the tables are sorted.
> -  static bool TableChecked = false;
> -  if (!TableChecked) {
> +  static std::atomic<bool> TableChecked(false);
> +  if (!TableChecked.load(std::memory_order_relaxed)) {
>      assert(std::is_sorted(std::begin(X86EvexToVex128CompressTable),
>                            std::end(X86EvexToVex128CompressTable)) &&
>             "X86EvexToVex128CompressTable is not sorted!");
>      assert(std::is_sorted(std::begin(X86EvexToVex256CompressTable),
>                            std::end(X86EvexToVex256CompressTable)) &&
>             "X86EvexToVex256CompressTable is not sorted!");
> -    TableChecked = true;
> +    TablesChecked.store(true, std::memory_order_relaxed);
>    }
>  #endif
>
>
> Modified: llvm/trunk/lib/Target/X86/X86InstrInfo.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86InstrInfo.cpp?rev=335823&r1=335822&r2=335823&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Target/X86/X86InstrInfo.cpp (original)
> +++ llvm/trunk/lib/Target/X86/X86InstrInfo.cpp Thu Jun 28 03:03:45 2018
> @@ -5413,7 +5413,8 @@ X86InstrInfo::X86InstrInfo(X86Subtarget
>
>  #ifndef NDEBUG
>    // Make sure the tables are sorted.
> -  static bool LLVM_ATTRIBUTE_UNUSED FoldTablesChecked = [] {
> +  static std::atomic<bool> FoldTablesChecked(false);
> +  if (!FoldTablesChecked.load(std::memory_order_relaxed)) {
>      assert(std::is_sorted(std::begin(MemoryFoldTable2Addr),
>                            std::end(MemoryFoldTable2Addr)) &&
>             std::adjacent_find(std::begin(MemoryFoldTable2Addr),
> @@ -5450,8 +5451,8 @@ X86InstrInfo::X86InstrInfo(X86Subtarget
>                                std::end(MemoryFoldTable4)) ==
>             std::end(MemoryFoldTable4) &&
>             "MemoryFoldTable4 is not sorted and unique!");
> -    return true;
> -  }();
> +    FoldTablesChecked.store(true, std::memory_order_relaxed);
> +  }
>  #endif
>  }
>
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits


More information about the llvm-commits mailing list