-
Notifications
You must be signed in to change notification settings - Fork 787
Mutli-Memories Support in IR #4811
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
fd11edc
71b0eef
74c77a7
44946d4
bcd6039
79bca3c
15c144d
4d5f7c3
c0c4f2a
6c9893b
9382618
e26e2f4
d782e2c
229ffbb
f33e5f7
c1ee8ac
c4461dc
426fc5d
c5d0499
c31ebd9
7a63097
4c8f27d
b844b03
4c55570
de54f52
02e67e4
3bb69ea
dda71a8
527933d
8b35c36
a8a1f61
496eaf2
58e3e47
f9d4a9f
3ef831b
fc02ee1
d8b3dde
1d8ba1e
084cc5d
e37fca2
d23f062
2d18836
a006a94
5018f49
5c41ffe
d820c76
0e90a2b
ab6fb81
eeae770
ef2df16
59640ce
feff650
18e9b06
cd1e3b3
74ae82c
3709558
2dbe0ce
4acd9df
7b44ae4
73716db
0249723
6bd54f5
2340669
af99ee0
432d05e
c04851c
ee685b7
d1b2723
2d7d965
236d6c7
fc85a8e
e9dea49
d28e552
6e7a30d
a5c6413
e535ad7
b849e74
94d52a5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -746,7 +746,8 @@ BINARYEN_API BinaryenExpressionRef BinaryenLoad(BinaryenModuleRef module, | |
uint32_t offset, | ||
uint32_t align, | ||
BinaryenType type, | ||
BinaryenExpressionRef ptr); | ||
BinaryenExpressionRef ptr, | ||
const char* name); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure name is clear enough here. Perhaps |
||
// Store: align can be 0, in which case it will be the natural alignment (equal | ||
// to bytes) | ||
BINARYEN_API BinaryenExpressionRef BinaryenStore(BinaryenModuleRef module, | ||
|
@@ -755,7 +756,8 @@ BINARYEN_API BinaryenExpressionRef BinaryenStore(BinaryenModuleRef module, | |
uint32_t align, | ||
BinaryenExpressionRef ptr, | ||
BinaryenExpressionRef value, | ||
BinaryenType type); | ||
BinaryenType type, | ||
const char* name); | ||
BINARYEN_API BinaryenExpressionRef BinaryenConst(BinaryenModuleRef module, | ||
struct BinaryenLiteral value); | ||
BINARYEN_API BinaryenExpressionRef BinaryenUnary(BinaryenModuleRef module, | ||
|
@@ -776,51 +778,57 @@ BINARYEN_API BinaryenExpressionRef BinaryenDrop(BinaryenModuleRef module, | |
// Return: value can be NULL | ||
BINARYEN_API BinaryenExpressionRef BinaryenReturn(BinaryenModuleRef module, | ||
BinaryenExpressionRef value); | ||
BINARYEN_API BinaryenExpressionRef BinaryenMemorySize(BinaryenModuleRef module); | ||
BINARYEN_API BinaryenExpressionRef | ||
BinaryenMemoryGrow(BinaryenModuleRef module, BinaryenExpressionRef delta); | ||
BINARYEN_API BinaryenExpressionRef BinaryenMemorySize(BinaryenModuleRef module, | ||
const char* name); | ||
BINARYEN_API BinaryenExpressionRef BinaryenMemoryGrow( | ||
BinaryenModuleRef module, BinaryenExpressionRef delta, const char* name); | ||
BINARYEN_API BinaryenExpressionRef BinaryenNop(BinaryenModuleRef module); | ||
BINARYEN_API BinaryenExpressionRef | ||
BinaryenUnreachable(BinaryenModuleRef module); | ||
BINARYEN_API BinaryenExpressionRef | ||
BinaryenAtomicLoad(BinaryenModuleRef module, | ||
uint32_t bytes, | ||
uint32_t offset, | ||
BinaryenType type, | ||
BinaryenExpressionRef ptr); | ||
BINARYEN_API BinaryenExpressionRef BinaryenAtomicLoad(BinaryenModuleRef module, | ||
uint32_t bytes, | ||
uint32_t offset, | ||
BinaryenType type, | ||
BinaryenExpressionRef ptr, | ||
const char* name); | ||
BINARYEN_API BinaryenExpressionRef | ||
BinaryenAtomicStore(BinaryenModuleRef module, | ||
uint32_t bytes, | ||
uint32_t offset, | ||
BinaryenExpressionRef ptr, | ||
BinaryenExpressionRef value, | ||
BinaryenType type); | ||
BinaryenType type, | ||
const char* name); | ||
BINARYEN_API BinaryenExpressionRef | ||
BinaryenAtomicRMW(BinaryenModuleRef module, | ||
BinaryenOp op, | ||
BinaryenIndex bytes, | ||
BinaryenIndex offset, | ||
BinaryenExpressionRef ptr, | ||
BinaryenExpressionRef value, | ||
BinaryenType type); | ||
BinaryenType type, | ||
const char* name); | ||
BINARYEN_API BinaryenExpressionRef | ||
BinaryenAtomicCmpxchg(BinaryenModuleRef module, | ||
BinaryenIndex bytes, | ||
BinaryenIndex offset, | ||
BinaryenExpressionRef ptr, | ||
BinaryenExpressionRef expected, | ||
BinaryenExpressionRef replacement, | ||
BinaryenType type); | ||
BinaryenType type, | ||
const char* name); | ||
BINARYEN_API BinaryenExpressionRef | ||
BinaryenAtomicWait(BinaryenModuleRef module, | ||
BinaryenExpressionRef ptr, | ||
BinaryenExpressionRef expected, | ||
BinaryenExpressionRef timeout, | ||
BinaryenType type); | ||
BinaryenType type, | ||
const char* name); | ||
BINARYEN_API BinaryenExpressionRef | ||
BinaryenAtomicNotify(BinaryenModuleRef module, | ||
BinaryenExpressionRef ptr, | ||
BinaryenExpressionRef notifyCount); | ||
BinaryenExpressionRef notifyCount, | ||
const char* name); | ||
BINARYEN_API BinaryenExpressionRef | ||
BinaryenAtomicFence(BinaryenModuleRef module); | ||
BINARYEN_API BinaryenExpressionRef | ||
|
@@ -853,33 +861,39 @@ BINARYEN_API BinaryenExpressionRef BinaryenSIMDLoad(BinaryenModuleRef module, | |
BinaryenOp op, | ||
uint32_t offset, | ||
uint32_t align, | ||
BinaryenExpressionRef ptr); | ||
BinaryenExpressionRef ptr, | ||
const char* name); | ||
BINARYEN_API BinaryenExpressionRef | ||
BinaryenSIMDLoadStoreLane(BinaryenModuleRef module, | ||
BinaryenOp op, | ||
uint32_t offset, | ||
uint32_t align, | ||
uint8_t index, | ||
BinaryenExpressionRef ptr, | ||
BinaryenExpressionRef vec); | ||
BinaryenExpressionRef vec, | ||
const char* name); | ||
BINARYEN_API BinaryenExpressionRef | ||
BinaryenMemoryInit(BinaryenModuleRef module, | ||
uint32_t segment, | ||
BinaryenExpressionRef dest, | ||
BinaryenExpressionRef offset, | ||
BinaryenExpressionRef size); | ||
BinaryenExpressionRef size, | ||
const char* name); | ||
BINARYEN_API BinaryenExpressionRef BinaryenDataDrop(BinaryenModuleRef module, | ||
uint32_t segment); | ||
BINARYEN_API BinaryenExpressionRef | ||
BinaryenMemoryCopy(BinaryenModuleRef module, | ||
BinaryenExpressionRef dest, | ||
BinaryenExpressionRef source, | ||
BinaryenExpressionRef size); | ||
BinaryenExpressionRef size, | ||
const char* destMemory, | ||
const char* sourceMemory); | ||
BINARYEN_API BinaryenExpressionRef | ||
BinaryenMemoryFill(BinaryenModuleRef module, | ||
BinaryenExpressionRef dest, | ||
BinaryenExpressionRef value, | ||
BinaryenExpressionRef size); | ||
BinaryenExpressionRef size, | ||
const char* name); | ||
BINARYEN_API BinaryenExpressionRef BinaryenRefNull(BinaryenModuleRef module, | ||
BinaryenType type); | ||
BINARYEN_API BinaryenExpressionRef BinaryenRefIs(BinaryenModuleRef module, | ||
|
@@ -2194,6 +2208,9 @@ BINARYEN_API void BinaryenAddTagImport(BinaryenModuleRef module, | |
BinaryenType params, | ||
BinaryenType results); | ||
|
||
// Memory | ||
BINARYEN_REF(Memory); | ||
|
||
// Exports | ||
|
||
BINARYEN_REF(Export); | ||
|
@@ -2310,8 +2327,7 @@ BinaryenGetElementSegment(BinaryenModuleRef module, const char* name); | |
BINARYEN_API BinaryenElementSegmentRef | ||
BinaryenGetElementSegmentByIndex(BinaryenModuleRef module, BinaryenIndex index); | ||
|
||
// Memory. One per module | ||
|
||
// This will create a memory, overwriting any existing memory | ||
// Each memory has data in segments, a start offset in segmentOffsets, and a | ||
// size in segmentSizes. exportName can be NULL | ||
BINARYEN_API void BinaryenSetMemory(BinaryenModuleRef module, | ||
|
@@ -2323,16 +2339,22 @@ BINARYEN_API void BinaryenSetMemory(BinaryenModuleRef module, | |
BinaryenExpressionRef* segmentOffsets, | ||
BinaryenIndex* segmentSizes, | ||
BinaryenIndex numSegments, | ||
bool shared); | ||
bool shared, | ||
const char* name); | ||
|
||
BINARYEN_API bool BinaryenHasMemory(BinaryenModuleRef module); | ||
BINARYEN_API BinaryenIndex BinaryenMemoryGetInitial(BinaryenModuleRef module); | ||
BINARYEN_API bool BinaryenMemoryHasMax(BinaryenModuleRef module); | ||
BINARYEN_API BinaryenIndex BinaryenMemoryGetMax(BinaryenModuleRef module); | ||
BINARYEN_API const char* | ||
BinaryenMemoryImportGetModule(BinaryenModuleRef module); | ||
BINARYEN_API const char* BinaryenMemoryImportGetBase(BinaryenModuleRef module); | ||
BINARYEN_API bool BinaryenMemoryIsShared(BinaryenModuleRef module); | ||
BINARYEN_API BinaryenIndex BinaryenMemoryGetInitial(BinaryenModuleRef module, | ||
const char* name); | ||
BINARYEN_API bool BinaryenMemoryHasMax(BinaryenModuleRef module, | ||
const char* name); | ||
BINARYEN_API BinaryenIndex BinaryenMemoryGetMax(BinaryenModuleRef module, | ||
const char* name); | ||
BINARYEN_API const char* BinaryenMemoryImportGetModule(BinaryenModuleRef module, | ||
const char* name); | ||
BINARYEN_API const char* BinaryenMemoryImportGetBase(BinaryenModuleRef module, | ||
const char* name); | ||
BINARYEN_API bool BinaryenMemoryIsShared(BinaryenModuleRef module, | ||
const char* name); | ||
|
||
// Memory segments. Query utilities. | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,19 +30,25 @@ namespace wasm::MemoryUtils { | |
// Flattens memory into a single data segment, or no segment. If there is | ||
// a segment, it starts at 0. | ||
// Returns true if successful (e.g. relocatable segments cannot be flattened). | ||
// Does not yet support multi-memories | ||
bool flatten(Module& wasm); | ||
|
||
// Ensures that the memory exists (of minimal size). | ||
inline void ensureExists(Memory& memory) { | ||
if (!memory.exists) { | ||
memory.exists = true; | ||
memory.initial = memory.max = 1; | ||
// Ensures that a memory exists (of minimal size). | ||
inline void ensureExists(Module* wasm) { | ||
if (wasm->memories.empty()) { | ||
auto memory = Builder::makeMemory("0"); | ||
memory->initial = memory->max = 1; | ||
wasm->addMemory(std::move(memory)); | ||
} | ||
} | ||
|
||
// Try to merge segments until they fit into web limitations. | ||
// Return true if successful. | ||
// Does not yet support multi-memories | ||
inline bool ensureLimitedSegments(Module& module) { | ||
if (module.memories.size() > 1) { | ||
return false; | ||
} | ||
Comment on lines
+49
to
+51
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if we should produce a fatal error here (and in similar places) so we don't forget to come back and fix it up later. @kripken, wdyt? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree that fatal errors are better in places like this. |
||
auto& dataSegments = module.dataSegments; | ||
if (dataSegments.size() <= WebLimitations::MaxDataSegments) { | ||
return true; | ||
|
@@ -136,6 +142,7 @@ inline bool ensureLimitedSegments(Module& module) { | |
c->type = Type::i32; | ||
|
||
auto combined = Builder::makeDataSegment(); | ||
combined->memory = module.memories[0]->name; | ||
combined->offset = c; | ||
for (Index j = i; j < dataSegments.size(); j++) { | ||
auto& segment = dataSegments[j]; | ||
|
@@ -156,6 +163,7 @@ inline bool ensureLimitedSegments(Module& module) { | |
} | ||
|
||
dataSegments.swap(mergedSegments); | ||
module.updateDataSegmentsMap(); | ||
return true; | ||
} | ||
} // namespace wasm::MemoryUtils | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This pass can probably halt with an error (like on line 49 above) if there are no memories. Please also add a comment that we are assuming that memory 0 is the "main" memory here.