[WebAssembly] wasm64: fix memory.init operand types

I had assumed they would all become in i64, but this is not necessary as long as data segments stay 32-bit, see:
https://github.com/WebAssembly/memory64/blob/master/proposals/memory64/Overview.md

Differential Revision: https://reviews.llvm.org/D85552
This commit is contained in:
Wouter van Oortmerssen 2020-08-07 13:24:43 -07:00
parent e912fffd3a
commit 582fd474dd
7 changed files with 15 additions and 8 deletions

View File

@ -350,7 +350,7 @@ void InputSegment::generateRelocationCode(raw_ostream &os) const {
// TODO(sbc): Encode the relocations in the data section and write a loop
// here to apply them.
uint32_t segmentVA = outputSeg->startVA + outputSegmentOffset;
uint64_t segmentVA = outputSeg->startVA + outputSegmentOffset;
for (const WasmRelocation &rel : relocations) {
uint64_t offset = rel.Offset - getInputSectionOffset();
uint64_t outputOffset = segmentVA + offset;

View File

@ -152,6 +152,7 @@ void DataSection::finalizeContents() {
initExpr.Opcode = WASM_OPCODE_GLOBAL_GET;
initExpr.Value.Global = WasmSym::memoryBase->getGlobalIndex();
} else {
// FIXME(wvo): I64?
initExpr.Opcode = WASM_OPCODE_I32_CONST;
initExpr.Value.Int32 = segment->startVA;
}

View File

@ -37,7 +37,7 @@ public:
uint32_t initFlags = 0;
uint32_t sectionOffset = 0;
uint32_t alignment = 0;
uint32_t startVA = 0;
uint64_t startVA = 0;
std::vector<InputSegment *> inputSegments;
// Sum of the size of the all the input segments

View File

@ -211,7 +211,7 @@ DefinedFunction *SymbolTable::addSyntheticFunction(StringRef name,
// exported via the --export flag. Otherwise we don't add the symbol and return
// nullptr.
DefinedData *SymbolTable::addOptionalDataSymbol(StringRef name,
uint32_t value) {
uint64_t value) {
Symbol *s = find(name);
if (!s && (config->exportAll || config->exportedSymbols.count(name) != 0))
s = insertName(name).first;

View File

@ -82,7 +82,7 @@ public:
InputGlobal *global);
DefinedFunction *addSyntheticFunction(StringRef name, uint32_t flags,
InputFunction *function);
DefinedData *addOptionalDataSymbol(StringRef name, uint32_t value = 0);
DefinedData *addOptionalDataSymbol(StringRef name, uint64_t value = 0);
void handleSymbolVariants();
void handleWeakUndefines();

View File

@ -354,8 +354,8 @@ static void addStartStopSymbols(const OutputSegment *seg) {
if (!isValidCIdentifier(name))
return;
LLVM_DEBUG(dbgs() << "addStartStopSymbols: " << name << "\n");
uint32_t start = seg->startVA;
uint32_t stop = start + seg->size;
uint64_t start = seg->startVA;
uint64_t stop = start + seg->size;
symtab->addOptionalDataSymbol(saver.save("__start_" + name), start);
symtab->addOptionalDataSymbol(saver.save("__stop_" + name), stop);
}
@ -838,7 +838,12 @@ void Writer::createInitMemoryFunction() {
for (const OutputSegment *s : segments) {
if (needsPassiveInitialization(s)) {
// destination address
writeI32Const(os, s->startVA, "destination address");
if (config->is64) {
writeI64Const(os, s->startVA, "destination address");
} else {
writeI32Const(os, static_cast<int32_t>(s->startVA),
"destination address");
}
// source segment offset
writeI32Const(os, 0, "segment offset");
// memory region size
@ -960,6 +965,7 @@ void Writer::createInitTLSFunction() {
writeU8(os, WASM_OPCODE_GLOBAL_SET, "global.set");
writeUleb128(os, WasmSym::tlsBase->getGlobalIndex(), "global index");
// FIXME(wvo): this local needs to be I64 in wasm64, or we need an extend op.
writeU8(os, WASM_OPCODE_LOCAL_GET, "local.get");
writeUleb128(os, 0, "local index");

View File

@ -39,7 +39,7 @@ let mayStore = 1, hasSideEffects = 1 in
defm MEMORY_INIT_A#B :
BULK_I<(outs),
(ins i32imm_op:$seg, i32imm_op:$idx, rc:$dest,
rc:$offset, rc:$size),
I32:$offset, I32:$size),
(outs), (ins i32imm_op:$seg, i32imm_op:$idx),
[],
"memory.init\t$seg, $idx, $dest, $offset, $size",