[cfe-commits] r142281 - in /cfe/trunk: include/clang/Basic/Builtins.def lib/AST/ExprConstant.cpp test/CodeGen/atomic-ops.c
Eli Friedman
eli.friedman at gmail.com
Mon Oct 17 14:44:23 PDT 2011
Author: efriedma
Date: Mon Oct 17 16:44:23 2011
New Revision: 142281
URL: http://llvm.org/viewvc/llvm-project?rev=142281&view=rev
Log:
Initial implementation of __atomic_is_lock_free. The input is the size of an atomic type rather than an atomic type itself just to save some implementation pain; I can change that if it seems worthwhile.
I think this is the last hook needed for <atomic> besides defines for ATOMIC_CHAR_LOCK_FREE and friends.
Modified:
cfe/trunk/include/clang/Basic/Builtins.def
cfe/trunk/lib/AST/ExprConstant.cpp
cfe/trunk/test/CodeGen/atomic-ops.c
Modified: cfe/trunk/include/clang/Basic/Builtins.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Builtins.def?rev=142281&r1=142280&r2=142281&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/Builtins.def (original)
+++ cfe/trunk/include/clang/Basic/Builtins.def Mon Oct 17 16:44:23 2011
@@ -598,6 +598,7 @@
BUILTIN(__atomic_fetch_xor, "v.", "t")
BUILTIN(__atomic_thread_fence, "vi", "n")
BUILTIN(__atomic_signal_fence, "vi", "n")
+BUILTIN(__atomic_is_lock_free, "iz", "n")
// Non-overloaded atomic builtins.
BUILTIN(__sync_synchronize, "v.", "n")
Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=142281&r1=142280&r2=142281&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Mon Oct 17 16:44:23 2011
@@ -1344,6 +1344,50 @@
}
return Error(E->getLocStart(), diag::note_invalid_subexpr_in_ice, E);
+
+ case Builtin::BI__atomic_is_lock_free: {
+ APSInt SizeVal;
+ if (!EvaluateInteger(E->getArg(0), SizeVal, Info))
+ return false;
+
+ // For __atomic_is_lock_free(sizeof(_Atomic(T))), if the size is a power
+ // of two less than the maximum inline atomic width, we know it is
+ // lock-free. If the size isn't a power of two, or greater than the
+ // maximum alignment where we promote atomics, we know it is not lock-free
+ // (at least not in the sense of atomic_is_lock_free). Otherwise,
+ // the answer can only be determined at runtime; for example, 16-byte
+ // atomics have lock-free implementations on some, but not all,
+ // x86-64 processors.
+
+ // Check power-of-two.
+ CharUnits Size = CharUnits::fromQuantity(SizeVal.getZExtValue());
+ if (!Size.isPowerOfTwo())
+#if 0
+ // FIXME: Suppress this folding until the ABI for the promotion width
+ // settles.
+ return Success(0, E);
+#else
+ return Error(E->getLocStart(), diag::note_invalid_subexpr_in_ice, E);
+#endif
+
+#if 0
+ // Check against promotion width.
+ // FIXME: Suppress this folding until the ABI for the promotion width
+ // settles.
+ unsigned PromoteWidthBits =
+ Info.Ctx.getTargetInfo().getMaxAtomicPromoteWidth();
+ if (Size > Info.Ctx.toCharUnitsFromBits(PromoteWidthBits))
+ return Success(0, E);
+#endif
+
+ // Check against inlining width.
+ unsigned InlineWidthBits =
+ Info.Ctx.getTargetInfo().getMaxAtomicInlineWidth();
+ if (Size <= Info.Ctx.toCharUnitsFromBits(InlineWidthBits))
+ return Success(1, E);
+
+ return Error(E->getLocStart(), diag::note_invalid_subexpr_in_ice, E);
+ }
}
}
Modified: cfe/trunk/test/CodeGen/atomic-ops.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/atomic-ops.c?rev=142281&r1=142280&r2=142281&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/atomic-ops.c (original)
+++ cfe/trunk/test/CodeGen/atomic-ops.c Mon Oct 17 16:44:23 2011
@@ -75,3 +75,9 @@
// CHECK: atomicrmw xchg i32*
return __atomic_exchange(c, (X){2}, memory_order_seq_cst);
}
+
+int lock_free() {
+ // CHECK: @lock_free
+ // CHECK: ret i32 1
+ return __atomic_is_lock_free(sizeof(_Atomic(int)));
+}
\ No newline at end of file
More information about the cfe-commits
mailing list