Add full compiler barriers to any fence that lacked a compiler barrier. (mono/mono...
authorJay Krell <jaykrell@microsoft.com>
Fri, 13 Dec 2019 21:49:15 +0000 (13:49 -0800)
committerAlexander Köplinger <alex.koeplinger@outlook.com>
Fri, 13 Dec 2019 21:49:15 +0000 (22:49 +0100)
A compiler barrier generates no code.
It "only" inhibits certain compiler optimizations, which I do not consider
particularly worrisome, as most code is "fully" optimized, and
compiler barriers are relatively rare.

It could be a concern in code paths that greatly benefit
from compiler optimizations and for which barriers greatly
inhibits the compiler.

I would further suggest, though it is not here, that any compiler
half barrier (read, write) be a compiler full barrier instead,
as they sound pretty cheap, so simplify.

Similar cannot be said about CPU barriers.
They do not always generate code, but when they do, it can cost.

This is follow-up from https://github.com/mono/mono/pull/17849#issuecomment-556273801
https://github.com/mono/mono/pull/17849#issuecomment-557661604.

Commit migrated from https://github.com/mono/mono/commit/e76fb5dbf92c34a944f6e3d5654a51661acbf6d8

src/mono/mono/utils/mono-memory-model.h

index ce01307..de71af7 100644 (file)
@@ -87,11 +87,11 @@ LDR R3, [R4, R0]
 
 #elif defined(__s390x__)
 
-#define STORE_STORE_FENCE do {} while (0)
-#define LOAD_LOAD_FENCE  do {} while (0)
-#define STORE_LOAD_FENCE do {} while (0)
-#define LOAD_STORE_FENCE do {} while (0)
-#define STORE_RELEASE_FENCE do {} while (0)
+#define STORE_STORE_FENCE   mono_compiler_barrier ()
+#define LOAD_LOAD_FENCE     mono_compiler_barrier ()
+#define STORE_LOAD_FENCE    mono_compiler_barrier ()
+#define LOAD_STORE_FENCE    mono_compiler_barrier ()
+#define STORE_RELEASE_FENCE mono_compiler_barrier ()
 
 #else
 
@@ -108,35 +108,35 @@ LDR R3, [R4, R0]
 #endif
 
 #ifndef STORE_STORE_FENCE
-#define STORE_STORE_FENCE
+#define STORE_STORE_FENCE   mono_compiler_barrier ()
 #endif 
 
 #ifndef LOAD_LOAD_FENCE
-#define LOAD_LOAD_FENCE
+#define LOAD_LOAD_FENCE     mono_compiler_barrier ()
 #endif 
 
 #ifndef STORE_LOAD_FENCE
-#define STORE_LOAD_FENCE
+#define STORE_LOAD_FENCE    mono_compiler_barrier ()
 #endif 
 
 #ifndef LOAD_STORE_FENCE
-#define LOAD_STORE_FENCE
+#define LOAD_STORE_FENCE    mono_compiler_barrier ()
 #endif 
 
 #ifndef STORE_RELEASE_FENCE
-#define STORE_RELEASE_FENCE
+#define STORE_RELEASE_FENCE mono_compiler_barrier ()
 #endif
 
 #ifndef LOAD_RELEASE_FENCE
-#define LOAD_RELEASE_FENCE
+#define LOAD_RELEASE_FENCE  mono_compiler_barrier ()
 #endif
 
 #ifndef STORE_ACQUIRE_FENCE
-#define STORE_ACQUIRE_FENCE
+#define STORE_ACQUIRE_FENCE mono_compiler_barrier ()
 #endif
 
 #ifndef LOAD_ACQUIRE_FENCE
-#define LOAD_ACQUIRE_FENCE
+#define LOAD_ACQUIRE_FENCE mono_compiler_barrier ()
 #endif