summaryrefslogtreecommitdiff
path: root/src/passes
diff options
context:
space:
mode:
Diffstat (limited to 'src/passes')
-rw-r--r--src/passes/AlignmentLowering.cpp56
-rw-r--r--src/passes/AvoidReinterprets.cpp8
-rw-r--r--src/passes/GenerateDynCalls.cpp9
-rw-r--r--src/passes/InstrumentMemory.cpp28
-rw-r--r--src/passes/Memory64Lowering.cpp2
-rw-r--r--src/passes/MemoryPacking.cpp8
-rw-r--r--src/passes/MultiMemoryLowering.cpp6
-rw-r--r--src/passes/SafeHeap.cpp64
-rw-r--r--src/passes/SimplifyLocals.cpp6
-rw-r--r--src/passes/SpillPointers.cpp2
-rw-r--r--src/passes/StackCheck.cpp8
-rw-r--r--src/passes/Table64Lowering.cpp2
12 files changed, 102 insertions, 97 deletions
diff --git a/src/passes/AlignmentLowering.cpp b/src/passes/AlignmentLowering.cpp
index d0ceeb610..52849ebac 100644
--- a/src/passes/AlignmentLowering.cpp
+++ b/src/passes/AlignmentLowering.cpp
@@ -35,10 +35,10 @@ struct AlignmentLowering : public WalkerPass<PostWalker<AlignmentLowering>> {
return curr;
}
auto mem = getModule()->getMemory(curr->memory);
- auto indexType = mem->indexType;
+ auto addressType = mem->addressType;
Builder builder(*getModule());
assert(curr->type == Type::i32);
- auto temp = builder.addVar(getFunction(), indexType);
+ auto temp = builder.addVar(getFunction(), addressType);
Expression* ret;
if (curr->bytes == 2) {
ret = builder.makeBinary(
@@ -47,7 +47,7 @@ struct AlignmentLowering : public WalkerPass<PostWalker<AlignmentLowering>> {
false,
curr->offset,
1,
- builder.makeLocalGet(temp, indexType),
+ builder.makeLocalGet(temp, addressType),
Type::i32,
curr->memory),
builder.makeBinary(
@@ -56,7 +56,7 @@ struct AlignmentLowering : public WalkerPass<PostWalker<AlignmentLowering>> {
false,
curr->offset + 1,
1,
- builder.makeLocalGet(temp, indexType),
+ builder.makeLocalGet(temp, addressType),
Type::i32,
curr->memory),
builder.makeConst(int32_t(8))));
@@ -73,7 +73,7 @@ struct AlignmentLowering : public WalkerPass<PostWalker<AlignmentLowering>> {
false,
curr->offset,
1,
- builder.makeLocalGet(temp, indexType),
+ builder.makeLocalGet(temp, addressType),
Type::i32,
curr->memory),
builder.makeBinary(
@@ -82,7 +82,7 @@ struct AlignmentLowering : public WalkerPass<PostWalker<AlignmentLowering>> {
false,
curr->offset + 1,
1,
- builder.makeLocalGet(temp, indexType),
+ builder.makeLocalGet(temp, addressType),
Type::i32,
curr->memory),
builder.makeConst(int32_t(8)))),
@@ -94,7 +94,7 @@ struct AlignmentLowering : public WalkerPass<PostWalker<AlignmentLowering>> {
false,
curr->offset + 2,
1,
- builder.makeLocalGet(temp, indexType),
+ builder.makeLocalGet(temp, addressType),
Type::i32,
curr->memory),
builder.makeConst(int32_t(16))),
@@ -104,7 +104,7 @@ struct AlignmentLowering : public WalkerPass<PostWalker<AlignmentLowering>> {
false,
curr->offset + 3,
1,
- builder.makeLocalGet(temp, indexType),
+ builder.makeLocalGet(temp, addressType),
Type::i32,
curr->memory),
builder.makeConst(int32_t(24)))));
@@ -115,7 +115,7 @@ struct AlignmentLowering : public WalkerPass<PostWalker<AlignmentLowering>> {
false,
curr->offset,
2,
- builder.makeLocalGet(temp, indexType),
+ builder.makeLocalGet(temp, addressType),
Type::i32,
curr->memory),
builder.makeBinary(
@@ -124,7 +124,7 @@ struct AlignmentLowering : public WalkerPass<PostWalker<AlignmentLowering>> {
false,
curr->offset + 2,
2,
- builder.makeLocalGet(temp, indexType),
+ builder.makeLocalGet(temp, addressType),
Type::i32,
curr->memory),
builder.makeConst(int32_t(16))));
@@ -145,8 +145,8 @@ struct AlignmentLowering : public WalkerPass<PostWalker<AlignmentLowering>> {
Builder builder(*getModule());
assert(curr->value->type == Type::i32);
auto mem = getModule()->getMemory(curr->memory);
- auto indexType = mem->indexType;
- auto tempPtr = builder.addVar(getFunction(), indexType);
+ auto addressType = mem->addressType;
+ auto tempPtr = builder.addVar(getFunction(), addressType);
auto tempValue = builder.addVar(getFunction(), Type::i32);
auto* block =
builder.makeBlock({builder.makeLocalSet(tempPtr, curr->ptr),
@@ -156,7 +156,7 @@ struct AlignmentLowering : public WalkerPass<PostWalker<AlignmentLowering>> {
builder.makeStore(1,
curr->offset,
1,
- builder.makeLocalGet(tempPtr, indexType),
+ builder.makeLocalGet(tempPtr, addressType),
builder.makeLocalGet(tempValue, Type::i32),
Type::i32,
curr->memory));
@@ -164,7 +164,7 @@ struct AlignmentLowering : public WalkerPass<PostWalker<AlignmentLowering>> {
1,
curr->offset + 1,
1,
- builder.makeLocalGet(tempPtr, indexType),
+ builder.makeLocalGet(tempPtr, addressType),
builder.makeBinary(ShrUInt32,
builder.makeLocalGet(tempValue, Type::i32),
builder.makeConst(int32_t(8))),
@@ -176,7 +176,7 @@ struct AlignmentLowering : public WalkerPass<PostWalker<AlignmentLowering>> {
builder.makeStore(1,
curr->offset,
1,
- builder.makeLocalGet(tempPtr, indexType),
+ builder.makeLocalGet(tempPtr, addressType),
builder.makeLocalGet(tempValue, Type::i32),
Type::i32,
curr->memory));
@@ -184,7 +184,7 @@ struct AlignmentLowering : public WalkerPass<PostWalker<AlignmentLowering>> {
1,
curr->offset + 1,
1,
- builder.makeLocalGet(tempPtr, indexType),
+ builder.makeLocalGet(tempPtr, addressType),
builder.makeBinary(ShrUInt32,
builder.makeLocalGet(tempValue, Type::i32),
builder.makeConst(int32_t(8))),
@@ -194,7 +194,7 @@ struct AlignmentLowering : public WalkerPass<PostWalker<AlignmentLowering>> {
1,
curr->offset + 2,
1,
- builder.makeLocalGet(tempPtr, indexType),
+ builder.makeLocalGet(tempPtr, addressType),
builder.makeBinary(ShrUInt32,
builder.makeLocalGet(tempValue, Type::i32),
builder.makeConst(int32_t(16))),
@@ -204,7 +204,7 @@ struct AlignmentLowering : public WalkerPass<PostWalker<AlignmentLowering>> {
1,
curr->offset + 3,
1,
- builder.makeLocalGet(tempPtr, indexType),
+ builder.makeLocalGet(tempPtr, addressType),
builder.makeBinary(ShrUInt32,
builder.makeLocalGet(tempValue, Type::i32),
builder.makeConst(int32_t(24))),
@@ -215,7 +215,7 @@ struct AlignmentLowering : public WalkerPass<PostWalker<AlignmentLowering>> {
builder.makeStore(2,
curr->offset,
2,
- builder.makeLocalGet(tempPtr, indexType),
+ builder.makeLocalGet(tempPtr, addressType),
builder.makeLocalGet(tempValue, Type::i32),
Type::i32,
curr->memory));
@@ -223,7 +223,7 @@ struct AlignmentLowering : public WalkerPass<PostWalker<AlignmentLowering>> {
2,
curr->offset + 2,
2,
- builder.makeLocalGet(tempPtr, indexType),
+ builder.makeLocalGet(tempPtr, addressType),
builder.makeBinary(ShrUInt32,
builder.makeLocalGet(tempValue, Type::i32),
builder.makeConst(int32_t(16))),
@@ -275,15 +275,15 @@ struct AlignmentLowering : public WalkerPass<PostWalker<AlignmentLowering>> {
}
// Load two 32-bit pieces, and combine them.
auto mem = getModule()->getMemory(curr->memory);
- auto indexType = mem->indexType;
- auto temp = builder.addVar(getFunction(), indexType);
+ auto addressType = mem->addressType;
+ auto temp = builder.addVar(getFunction(), addressType);
auto* set = builder.makeLocalSet(temp, curr->ptr);
Expression* low =
lowerLoadI32(builder.makeLoad(4,
false,
curr->offset,
curr->align,
- builder.makeLocalGet(temp, indexType),
+ builder.makeLocalGet(temp, addressType),
Type::i32,
curr->memory));
low = builder.makeUnary(ExtendUInt32, low);
@@ -296,7 +296,7 @@ struct AlignmentLowering : public WalkerPass<PostWalker<AlignmentLowering>> {
false,
curr->offset + 4,
curr->align,
- builder.makeLocalGet(temp, indexType),
+ builder.makeLocalGet(temp, addressType),
Type::i32,
curr->memory));
high = builder.makeUnary(ExtendUInt32, high);
@@ -357,8 +357,8 @@ struct AlignmentLowering : public WalkerPass<PostWalker<AlignmentLowering>> {
}
// Store as two 32-bit pieces.
auto mem = getModule()->getMemory(curr->memory);
- auto indexType = mem->indexType;
- auto tempPtr = builder.addVar(getFunction(), indexType);
+ auto addressType = mem->addressType;
+ auto tempPtr = builder.addVar(getFunction(), addressType);
auto* setPtr = builder.makeLocalSet(tempPtr, curr->ptr);
auto tempValue = builder.addVar(getFunction(), Type::i64);
auto* setValue = builder.makeLocalSet(tempValue, value);
@@ -368,7 +368,7 @@ struct AlignmentLowering : public WalkerPass<PostWalker<AlignmentLowering>> {
builder.makeStore(4,
curr->offset,
curr->align,
- builder.makeLocalGet(tempPtr, indexType),
+ builder.makeLocalGet(tempPtr, addressType),
low,
Type::i32,
curr->memory));
@@ -385,7 +385,7 @@ struct AlignmentLowering : public WalkerPass<PostWalker<AlignmentLowering>> {
builder.makeStore(4,
curr->offset + 4,
curr->align,
- builder.makeLocalGet(tempPtr, indexType),
+ builder.makeLocalGet(tempPtr, addressType),
high,
Type::i32,
curr->memory));
diff --git a/src/passes/AvoidReinterprets.cpp b/src/passes/AvoidReinterprets.cpp
index 94ae42b61..32a190180 100644
--- a/src/passes/AvoidReinterprets.cpp
+++ b/src/passes/AvoidReinterprets.cpp
@@ -121,7 +121,7 @@ struct AvoidReinterprets : public WalkerPass<PostWalker<AvoidReinterprets>> {
if (info.reinterpreted && canReplaceWithReinterpret(load)) {
// We should use another load here, to avoid reinterprets.
auto mem = getModule()->getMemory(load->memory);
- info.ptrLocal = Builder::addVar(func, mem->indexType);
+ info.ptrLocal = Builder::addVar(func, mem->addressType);
info.reinterpretedLocal =
Builder::addVar(func, load->type.reinterpret());
} else {
@@ -176,8 +176,8 @@ struct AvoidReinterprets : public WalkerPass<PostWalker<AvoidReinterprets>> {
Builder builder(*module);
auto* ptr = curr->ptr;
auto mem = getModule()->getMemory(curr->memory);
- auto indexType = mem->indexType;
- curr->ptr = builder.makeLocalGet(info.ptrLocal, indexType);
+ auto addressType = mem->addressType;
+ curr->ptr = builder.makeLocalGet(info.ptrLocal, addressType);
// Note that the other load can have its sign set to false - if the
// original were an integer, the other is a float anyhow; and if
// original were a float, we don't know what sign to use.
@@ -186,7 +186,7 @@ struct AvoidReinterprets : public WalkerPass<PostWalker<AvoidReinterprets>> {
builder.makeLocalSet(
info.reinterpretedLocal,
makeReinterpretedLoad(
- curr, builder.makeLocalGet(info.ptrLocal, indexType))),
+ curr, builder.makeLocalGet(info.ptrLocal, addressType))),
curr}));
}
}
diff --git a/src/passes/GenerateDynCalls.cpp b/src/passes/GenerateDynCalls.cpp
index 6e6e0a717..8d2f3fa24 100644
--- a/src/passes/GenerateDynCalls.cpp
+++ b/src/passes/GenerateDynCalls.cpp
@@ -146,11 +146,12 @@ void GenerateDynCalls::generateDynCallThunk(HeapType funcType) {
auto* table = wasm->addTable(Builder::makeTable(Name::fromInt(0)));
table->module = ENV;
table->base = "__indirect_function_table";
- table->indexType = wasm->memories[0]->indexType;
+ table->addressType = wasm->memories[0]->addressType;
}
auto& table = wasm->tables[0];
- namedParams.emplace_back("fptr", table->indexType); // function pointer param
- params.push_back(table->indexType);
+ namedParams.emplace_back("fptr",
+ table->addressType); // function pointer param
+ params.push_back(table->addressType);
int p = 0;
for (const auto& param : sig.params) {
namedParams.emplace_back(std::to_string(p++), param);
@@ -159,7 +160,7 @@ void GenerateDynCalls::generateDynCallThunk(HeapType funcType) {
auto f = builder.makeFunction(
name, std::move(namedParams), Signature(Type(params), sig.results), {});
f->hasExplicitName = true;
- Expression* fptr = builder.makeLocalGet(0, table->indexType);
+ Expression* fptr = builder.makeLocalGet(0, table->addressType);
std::vector<Expression*> args;
Index i = 0;
for (const auto& param : sig.params) {
diff --git a/src/passes/InstrumentMemory.cpp b/src/passes/InstrumentMemory.cpp
index b3c9aebbd..9bba5f537 100644
--- a/src/passes/InstrumentMemory.cpp
+++ b/src/passes/InstrumentMemory.cpp
@@ -104,14 +104,14 @@ struct InstrumentMemory : public WalkerPass<PostWalker<InstrumentMemory>> {
id++;
Builder builder(*getModule());
auto mem = getModule()->getMemory(curr->memory);
- auto indexType = mem->indexType;
- auto offset = builder.makeConstPtr(curr->offset.addr, indexType);
+ auto addressType = mem->addressType;
+ auto offset = builder.makeConstPtr(curr->offset.addr, addressType);
curr->ptr = builder.makeCall(load_ptr,
{builder.makeConst(int32_t(id)),
builder.makeConst(int32_t(curr->bytes)),
offset,
curr->ptr},
- indexType);
+ addressType);
Name target;
switch (curr->type.getBasic()) {
case Type::i32:
@@ -137,14 +137,14 @@ struct InstrumentMemory : public WalkerPass<PostWalker<InstrumentMemory>> {
id++;
Builder builder(*getModule());
auto mem = getModule()->getMemory(curr->memory);
- auto indexType = mem->indexType;
- auto offset = builder.makeConstPtr(curr->offset.addr, indexType);
+ auto addressType = mem->addressType;
+ auto offset = builder.makeConstPtr(curr->offset.addr, addressType);
curr->ptr = builder.makeCall(store_ptr,
{builder.makeConst(int32_t(id)),
builder.makeConst(int32_t(curr->bytes)),
offset,
curr->ptr},
- indexType);
+ addressType);
Name target;
switch (curr->value->type.getBasic()) {
case Type::i32:
@@ -251,20 +251,24 @@ struct InstrumentMemory : public WalkerPass<PostWalker<InstrumentMemory>> {
}
void visitModule(Module* curr) {
- auto indexType =
- curr->memories.empty() ? Type::i32 : curr->memories[0]->indexType;
+ auto addressType =
+ curr->memories.empty() ? Type::i32 : curr->memories[0]->addressType;
// Load.
- addImport(
- curr, load_ptr, {Type::i32, Type::i32, indexType, indexType}, indexType);
+ addImport(curr,
+ load_ptr,
+ {Type::i32, Type::i32, addressType, addressType},
+ addressType);
addImport(curr, load_val_i32, {Type::i32, Type::i32}, Type::i32);
addImport(curr, load_val_i64, {Type::i32, Type::i64}, Type::i64);
addImport(curr, load_val_f32, {Type::i32, Type::f32}, Type::f32);
addImport(curr, load_val_f64, {Type::i32, Type::f64}, Type::f64);
// Store.
- addImport(
- curr, store_ptr, {Type::i32, Type::i32, indexType, indexType}, indexType);
+ addImport(curr,
+ store_ptr,
+ {Type::i32, Type::i32, addressType, addressType},
+ addressType);
addImport(curr, store_val_i32, {Type::i32, Type::i32}, Type::i32);
addImport(curr, store_val_i64, {Type::i32, Type::i64}, Type::i64);
addImport(curr, store_val_f32, {Type::i32, Type::f32}, Type::f32);
diff --git a/src/passes/Memory64Lowering.cpp b/src/passes/Memory64Lowering.cpp
index 0a19d11c8..a3913c759 100644
--- a/src/passes/Memory64Lowering.cpp
+++ b/src/passes/Memory64Lowering.cpp
@@ -187,7 +187,7 @@ struct Memory64Lowering : public WalkerPass<PostWalker<Memory64Lowering>> {
// we don't want to depend on that specific ordering.
for (auto& memory : module->memories) {
if (memory->is64()) {
- memory->indexType = Type::i32;
+ memory->addressType = Type::i32;
if (memory->hasMax() && memory->max > Memory::kMaxSize32) {
memory->max = Memory::kMaxSize32;
}
diff --git a/src/passes/MemoryPacking.cpp b/src/passes/MemoryPacking.cpp
index ad562faf4..6c411378b 100644
--- a/src/passes/MemoryPacking.cpp
+++ b/src/passes/MemoryPacking.cpp
@@ -92,7 +92,7 @@ makeGtShiftedMemorySize(Builder& builder, Module& module, MemoryInit* curr) {
curr->dest,
builder.makeBinary(mem->is64() ? ShlInt64 : ShlInt32,
builder.makeMemorySize(mem->name),
- builder.makeConstPtr(16, mem->indexType)));
+ builder.makeConstPtr(16, mem->addressType)));
}
} // anonymous namespace
@@ -781,7 +781,7 @@ void MemoryPacking::createReplacements(Module* module,
// Calculate dest, either as a const or as an addition to the dest local
Expression* dest;
- Type ptrType = module->getMemory(init->memory)->indexType;
+ Type ptrType = module->getMemory(init->memory)->addressType;
if (auto* c = init->dest->dynCast<Const>()) {
dest =
builder.makeConstPtr(c->value.getInteger() + bytesWritten, ptrType);
@@ -819,8 +819,8 @@ void MemoryPacking::createReplacements(Module* module,
replacements[init] =
[module, init, setVar, getVars, result](Function* function) {
if (setVar != nullptr) {
- auto indexType = module->getMemory(init->memory)->indexType;
- Index destVar = Builder(*module).addVar(function, indexType);
+ auto addressType = module->getMemory(init->memory)->addressType;
+ Index destVar = Builder(*module).addVar(function, addressType);
*setVar = destVar;
for (auto* getVar : getVars) {
*getVar = destVar;
diff --git a/src/passes/MultiMemoryLowering.cpp b/src/passes/MultiMemoryLowering.cpp
index b214959f7..c22477b79 100644
--- a/src/passes/MultiMemoryLowering.cpp
+++ b/src/passes/MultiMemoryLowering.cpp
@@ -430,7 +430,7 @@ struct MultiMemoryLowering : public Pass {
Memory& getFirstMemory() { return *wasm->memories[0]; }
void prepCombinedMemory() {
- pointerType = getFirstMemory().indexType;
+ pointerType = getFirstMemory().addressType;
memoryInfo = pointerType == Type::i32 ? Builder::MemoryInfo::Memory32
: Builder::MemoryInfo::Memory64;
isShared = getFirstMemory().shared;
@@ -439,7 +439,7 @@ struct MultiMemoryLowering : public Pass {
// We are assuming that each memory is configured the same as the first
// and assert if any of the memories does not match this configuration
assert(memory->shared == isShared);
- assert(memory->indexType == pointerType);
+ assert(memory->addressType == pointerType);
// TODO: handle memory import for memories other than the first
if (memory->name != getFirstMemory().name && memory->imported()) {
@@ -690,7 +690,7 @@ struct MultiMemoryLowering : public Pass {
void addCombinedMemory() {
auto memory = Builder::makeMemory(combinedMemory);
memory->shared = isShared;
- memory->indexType = pointerType;
+ memory->addressType = pointerType;
memory->initial = totalInitialPages;
memory->max = totalMaxPages;
if (isImported) {
diff --git a/src/passes/SafeHeap.cpp b/src/passes/SafeHeap.cpp
index 7baeb365e..195900696 100644
--- a/src/passes/SafeHeap.cpp
+++ b/src/passes/SafeHeap.cpp
@@ -85,7 +85,7 @@ struct AccessInstrumenter : public WalkerPass<PostWalker<AccessInstrumenter>> {
auto memory = getModule()->getMemory(curr->memory);
replaceCurrent(builder.makeCall(
getLoadName(curr),
- {curr->ptr, builder.makeConstPtr(curr->offset.addr, memory->indexType)},
+ {curr->ptr, builder.makeConstPtr(curr->offset.addr, memory->addressType)},
curr->type));
}
@@ -99,7 +99,7 @@ struct AccessInstrumenter : public WalkerPass<PostWalker<AccessInstrumenter>> {
replaceCurrent(builder.makeCall(
getStoreName(curr),
{curr->ptr,
- builder.makeConstPtr(curr->offset.addr, memory->indexType),
+ builder.makeConstPtr(curr->offset.addr, memory->addressType),
curr->value},
Type::none));
}
@@ -156,7 +156,7 @@ struct SafeHeap : public Pass {
void addImports(Module* module) {
ImportInfo info(*module);
- auto indexType = module->memories[0]->indexType;
+ auto addressType = module->memories[0]->addressType;
if (auto* existing = info.getImportedFunction(ENV, GET_SBRK_PTR)) {
getSbrkPtr = existing->name;
} else if (auto* existing = module->getExportOrNull(GET_SBRK_PTR)) {
@@ -165,7 +165,7 @@ struct SafeHeap : public Pass {
sbrk = existing->name;
} else {
auto import = Builder::makeFunction(
- GET_SBRK_PTR, Signature(Type::none, indexType), {});
+ GET_SBRK_PTR, Signature(Type::none, addressType), {});
getSbrkPtr = GET_SBRK_PTR;
import->module = ENV;
import->base = GET_SBRK_PTR;
@@ -283,17 +283,17 @@ struct SafeHeap : public Pass {
}
// pointer, offset
auto memory = module->getMemory(style.memory);
- auto indexType = memory->indexType;
- auto funcSig = Signature({indexType, indexType}, style.type);
- auto func = Builder::makeFunction(name, funcSig, {indexType});
+ auto addressType = memory->addressType;
+ auto funcSig = Signature({addressType, addressType}, style.type);
+ auto func = Builder::makeFunction(name, funcSig, {addressType});
Builder builder(*module);
auto* block = builder.makeBlock();
// stash the sum of the pointer (0) and the size (1) in a local (2)
block->list.push_back(builder.makeLocalSet(
2,
builder.makeBinary(memory->is64() ? AddInt64 : AddInt32,
- builder.makeLocalGet(0, indexType),
- builder.makeLocalGet(1, indexType))));
+ builder.makeLocalGet(0, addressType),
+ builder.makeLocalGet(1, addressType))));
// check for reading past valid memory: if pointer + offset + bytes
block->list.push_back(makeBoundsCheck(style.type,
builder,
@@ -301,7 +301,7 @@ struct SafeHeap : public Pass {
2,
style.bytes,
module,
- memory->indexType,
+ memory->addressType,
memory->is64(),
memory->name));
// check proper alignment
@@ -312,7 +312,7 @@ struct SafeHeap : public Pass {
// do the load
auto* load = module->allocator.alloc<Load>();
*load = style; // basically the same as the template we are given!
- load->ptr = builder.makeLocalGet(2, indexType);
+ load->ptr = builder.makeLocalGet(2, addressType);
Expression* last = load;
if (load->isAtomic && load->signed_) {
// atomic loads cannot be signed, manually sign it
@@ -332,19 +332,19 @@ struct SafeHeap : public Pass {
return;
}
auto memory = module->getMemory(style.memory);
- auto indexType = memory->indexType;
+ auto addressType = memory->addressType;
bool is64 = memory->is64();
// pointer, offset, value
auto funcSig =
- Signature({indexType, indexType, style.valueType}, Type::none);
- auto func = Builder::makeFunction(name, funcSig, {indexType});
+ Signature({addressType, addressType, style.valueType}, Type::none);
+ auto func = Builder::makeFunction(name, funcSig, {addressType});
Builder builder(*module);
auto* block = builder.makeBlock();
block->list.push_back(builder.makeLocalSet(
3,
builder.makeBinary(is64 ? AddInt64 : AddInt32,
- builder.makeLocalGet(0, indexType),
- builder.makeLocalGet(1, indexType))));
+ builder.makeLocalGet(0, addressType),
+ builder.makeLocalGet(1, addressType))));
// check for reading past valid memory: if pointer + offset + bytes
block->list.push_back(makeBoundsCheck(style.valueType,
builder,
@@ -352,7 +352,7 @@ struct SafeHeap : public Pass {
3,
style.bytes,
module,
- indexType,
+ addressType,
is64,
memory->name));
// check proper alignment
@@ -364,7 +364,7 @@ struct SafeHeap : public Pass {
auto* store = module->allocator.alloc<Store>();
*store = style; // basically the same as the template we are given!
store->memory = memory->name;
- store->ptr = builder.makeLocalGet(3, indexType);
+ store->ptr = builder.makeLocalGet(3, addressType);
store->value = builder.makeLocalGet(2, style.valueType);
block->list.push_back(store);
block->finalize(Type::none);
@@ -378,8 +378,8 @@ struct SafeHeap : public Pass {
Module* module,
Name memoryName) {
auto memory = module->getMemory(memoryName);
- auto indexType = memory->indexType;
- Expression* ptrBits = builder.makeLocalGet(local, indexType);
+ auto addressType = memory->addressType;
+ Expression* ptrBits = builder.makeLocalGet(local, addressType);
if (memory->is64()) {
ptrBits = builder.makeUnary(WrapInt64, ptrBits);
}
@@ -399,7 +399,7 @@ struct SafeHeap : public Pass {
Index sumLocal,
Index bytes,
Module* module,
- Type indexType,
+ Type addressType,
bool is64,
Name memory) {
bool lowMemUnused = getPassOptions().lowMemoryUnused;
@@ -408,38 +408,38 @@ struct SafeHeap : public Pass {
auto upperBound = lowMemUnused ? PassOptions::LowMemoryBound : 0;
Expression* brkLocation;
if (sbrk.is()) {
- brkLocation =
- builder.makeCall(sbrk, {builder.makeConstPtr(0, indexType)}, indexType);
+ brkLocation = builder.makeCall(
+ sbrk, {builder.makeConstPtr(0, addressType)}, addressType);
} else {
Expression* sbrkPtr;
if (dynamicTopPtr.is()) {
- sbrkPtr = builder.makeGlobalGet(dynamicTopPtr, indexType);
+ sbrkPtr = builder.makeGlobalGet(dynamicTopPtr, addressType);
} else {
- sbrkPtr = builder.makeCall(getSbrkPtr, {}, indexType);
+ sbrkPtr = builder.makeCall(getSbrkPtr, {}, addressType);
}
auto size = is64 ? 8 : 4;
brkLocation =
- builder.makeLoad(size, false, 0, size, sbrkPtr, indexType, memory);
+ builder.makeLoad(size, false, 0, size, sbrkPtr, addressType, memory);
}
auto gtuOp = is64 ? GtUInt64 : GtUInt32;
auto addOp = is64 ? AddInt64 : AddInt32;
auto* upperCheck =
builder.makeBinary(upperOp,
- builder.makeLocalGet(sumLocal, indexType),
- builder.makeConstPtr(upperBound, indexType));
+ builder.makeLocalGet(sumLocal, addressType),
+ builder.makeConstPtr(upperBound, addressType));
auto* lowerCheck = builder.makeBinary(
gtuOp,
builder.makeBinary(addOp,
- builder.makeLocalGet(sumLocal, indexType),
- builder.makeConstPtr(bytes, indexType)),
+ builder.makeLocalGet(sumLocal, addressType),
+ builder.makeConstPtr(bytes, addressType)),
brkLocation);
// Check for an overflow when adding the pointer and the size, using the
// rule that for any unsigned x and y,
// x + y < x <=> x + y overflows
auto* overflowCheck =
builder.makeBinary(is64 ? LtUInt64 : LtUInt32,
- builder.makeLocalGet(sumLocal, indexType),
- builder.makeLocalGet(ptrLocal, indexType));
+ builder.makeLocalGet(sumLocal, addressType),
+ builder.makeLocalGet(ptrLocal, addressType));
// Add an unreachable right after the call to segfault for performance
// reasons: the call never returns, and this helps optimizations benefit
// from that.
diff --git a/src/passes/SimplifyLocals.cpp b/src/passes/SimplifyLocals.cpp
index eca503ad4..cf0b74950 100644
--- a/src/passes/SimplifyLocals.cpp
+++ b/src/passes/SimplifyLocals.cpp
@@ -1088,15 +1088,15 @@ struct SimplifyLocals
}
auto bestType = func->getLocalType(best);
- auto indexType = func->getLocalType(index);
- if (!Type::isSubType(indexType, bestType)) {
+ auto addressType = func->getLocalType(index);
+ if (!Type::isSubType(addressType, bestType)) {
// This is less refined than the current best; ignore.
continue;
}
// This is better if it has a more refined type, or if it has more
// uses.
- if (indexType != bestType ||
+ if (addressType != bestType ||
getNumGetsIgnoringCurr(index) > getNumGetsIgnoringCurr(best)) {
best = index;
}
diff --git a/src/passes/SpillPointers.cpp b/src/passes/SpillPointers.cpp
index db7fca85a..cfa432a4e 100644
--- a/src/passes/SpillPointers.cpp
+++ b/src/passes/SpillPointers.cpp
@@ -79,7 +79,7 @@ struct SpillPointers
Type pointerType;
void spillPointers() {
- pointerType = getModule()->memories[0]->indexType;
+ pointerType = getModule()->memories[0]->addressType;
// we only care about possible pointers
auto* func = getFunction();
diff --git a/src/passes/StackCheck.cpp b/src/passes/StackCheck.cpp
index ce5d346b9..31bf791fd 100644
--- a/src/passes/StackCheck.cpp
+++ b/src/passes/StackCheck.cpp
@@ -151,17 +151,17 @@ struct StackCheck : public Pass {
Builder builder(*module);
// Add the globals.
- Type indexType =
- module->memories.empty() ? Type::i32 : module->memories[0]->indexType;
+ Type addressType =
+ module->memories.empty() ? Type::i32 : module->memories[0]->addressType;
auto stackBase =
module->addGlobal(builder.makeGlobal(stackBaseName,
stackPointer->type,
- builder.makeConstPtr(0, indexType),
+ builder.makeConstPtr(0, addressType),
Builder::Mutable));
auto stackLimit =
module->addGlobal(builder.makeGlobal(stackLimitName,
stackPointer->type,
- builder.makeConstPtr(0, indexType),
+ builder.makeConstPtr(0, addressType),
Builder::Mutable));
// Instrument all the code.
diff --git a/src/passes/Table64Lowering.cpp b/src/passes/Table64Lowering.cpp
index b4a538df9..1167515de 100644
--- a/src/passes/Table64Lowering.cpp
+++ b/src/passes/Table64Lowering.cpp
@@ -144,7 +144,7 @@ struct Table64Lowering : public WalkerPass<PostWalker<Table64Lowering>> {
// we don't want to depend on that specific ordering.
for (auto& table : module->tables) {
if (table->is64()) {
- table->indexType = Type::i32;
+ table->addressType = Type::i32;
}
}
}