2626#include " ir/import-utils.h"
2727#include " ir/load-utils.h"
2828#include " pass.h"
29+ #include " support/string.h"
2930#include " wasm-builder.h"
3031#include " wasm.h"
3132
@@ -37,18 +38,28 @@ static const Name SEGFAULT_IMPORT("segfault");
3738static const Name ALIGNFAULT_IMPORT (" alignfault" );
3839
3940static Name getLoadName (Load* curr) {
40- std::string ret = " SAFE_HEAP_LOAD_" ;
41- ret += curr->type .toString ();
42- ret += " _" + std::to_string (curr->bytes ) + " _" ;
41+ std::vector<std::string> parts{curr->type .toString (),
42+ std::to_string (curr->bytes )};
4343 if (LoadUtils::isSignRelevant (curr) && !curr->signed_ ) {
44- ret += " U_ " ;
44+ parts. push_back ( " U " ) ;
4545 }
46- if (curr->isAtomic ()) {
47- ret += " A" ;
48- } else {
49- ret += std::to_string (curr->align );
46+
47+ switch (curr->order ) {
48+ case MemoryOrder::Unordered: {
49+ parts.push_back (std::to_string (curr->align ));
50+ break ;
51+ }
52+ case MemoryOrder::SeqCst: {
53+ parts.push_back (" SC" );
54+ break ;
55+ }
56+ case MemoryOrder::AcqRel: {
57+ parts.push_back (" AR" );
58+ break ;
59+ }
5060 }
51- return ret;
61+
62+ return " SAFE_HEAP_LOAD_" + String::join (parts, " _" );
5263}
5364
5465static Name getStoreName (Store* curr) {
@@ -232,10 +243,11 @@ struct SafeHeap : public Pass {
232243 if (align > bytes) {
233244 continue ;
234245 }
235- for (auto isAtomic : {true , false }) {
236- load.order =
237- isAtomic ? MemoryOrder::SeqCst : MemoryOrder::Unordered;
238- if (isAtomic &&
246+ for (auto memoryOrder : {MemoryOrder::Unordered,
247+ MemoryOrder::AcqRel,
248+ MemoryOrder::SeqCst}) {
249+ load.order = memoryOrder;
250+ if (load.isAtomic () &&
239251 !isPossibleAtomicOperation (
240252 align, bytes, module ->memories [0 ]->shared , type)) {
241253 continue ;
@@ -412,8 +424,9 @@ struct SafeHeap : public Pass {
412424 bool is64,
413425 Name memory) {
414426 bool lowMemUnused = getPassOptions ().lowMemoryUnused ;
415- auto upperOp = is64 ? lowMemUnused ? LtUInt64 : EqInt64
416- : lowMemUnused ? LtUInt32 : EqInt32;
427+ auto upperOp = is64 ? lowMemUnused ? LtUInt64 : EqInt64
428+ : lowMemUnused ? LtUInt32
429+ : EqInt32;
417430 auto upperBound = lowMemUnused ? PassOptions::LowMemoryBound : 0 ;
418431 Expression* brkLocation;
419432 if (sbrk.is ()) {
0 commit comments