summaryrefslogtreecommitdiff
path: root/src/ir/properties.h
diff options
context:
space:
mode:
authorThomas Lively <tlively@google.com>2024-12-19 17:45:05 -0800
committerGitHub <noreply@github.com>2024-12-19 17:45:05 -0800
commit7c42700738fa9f9aff29dd930e9fd7f6cf71fc29 (patch)
tree75b8df675e6da753d1209f7b02c9781c8db6cc4e /src/ir/properties.h
parent74b2b064e59beee84e88afaa952a8c51cf9309a4 (diff)
downloadbinaryen-7c42700738fa9f9aff29dd930e9fd7f6cf71fc29.tar.gz
binaryen-7c42700738fa9f9aff29dd930e9fd7f6cf71fc29.tar.bz2
binaryen-7c42700738fa9f9aff29dd930e9fd7f6cf71fc29.zip
Do not optimize atomic gets in GUFA (#7161)
Conservatively avoid introducing synchronization bugs by not optimizing atomic struct.gets at all in GUFA. It is possible that we could be more precise in the future. Also remove obsolete logic dealing with the types of null values as a drive-by. All null values now have bottom types, so the type mismatch this code checked for is impossible.
Diffstat (limited to 'src/ir/properties.h')
-rw-r--r--src/ir/properties.h24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/ir/properties.h b/src/ir/properties.h
index 09486ee34..70f18c276 100644
--- a/src/ir/properties.h
+++ b/src/ir/properties.h
@@ -486,6 +486,30 @@ inline bool canEmitSelectWithArms(Expression* ifTrue, Expression* ifFalse) {
return ifTrue->type.isSingle() && ifFalse->type.isSingle();
}
+// If this instruction accesses memory or the heap, or otherwise participates in
+// shared memory synchronization, return the memory order corresponding to the
+// kind of synchronization it does. Return MemoryOrder::Unordered if there is no
+// synchronization. Does not look at children.
+inline MemoryOrder getMemoryOrder(Expression* curr) {
+ if (auto* get = curr->dynCast<StructGet>()) {
+ return get->order;
+ }
+ if (auto* set = curr->dynCast<StructSet>()) {
+ return set->order;
+ }
+ if (auto* load = curr->dynCast<Load>()) {
+ return load->isAtomic ? MemoryOrder::SeqCst : MemoryOrder::Unordered;
+ }
+ if (auto* store = curr->dynCast<Store>()) {
+ return store->isAtomic ? MemoryOrder::SeqCst : MemoryOrder::Unordered;
+ }
+ if (curr->is<AtomicRMW>() || curr->is<AtomicWait>() ||
+ curr->is<AtomicNotify>() || curr->is<AtomicFence>()) {
+ return MemoryOrder::SeqCst;
+ }
+ return MemoryOrder::Unordered;
+}
+
// A "generative" expression is one that can generate different results for the
// same inputs, and that difference is *not* explained by other expressions that
// interact with this one. This is an intrinsic/internal property of the