Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions src/ir/type-updating.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -408,11 +408,6 @@ Type GlobalTypeRewriter::getTempTupleType(Tuple tuple) {

namespace TypeUpdating {

bool canHandleAsLocal(Type type) {
// TODO: Inline this into its callers.
return type.isConcrete();
}

void handleNonDefaultableLocals(Function* func, Module& wasm) {
if (!wasm.features.hasReferenceTypes()) {
// No references, so no non-nullable ones at all.
Expand Down
4 changes: 0 additions & 4 deletions src/ir/type-updating.h
Original file line number Diff line number Diff line change
Expand Up @@ -556,10 +556,6 @@ class TypeMapper : public GlobalTypeRewriter {

namespace TypeUpdating {

// Checks whether a type is valid as a local, or whether
// handleNonDefaultableLocals() can handle it if not.
bool canHandleAsLocal(Type type);

// Finds non-nullable locals, which are currently not supported, and handles
// them. Atm this turns them into nullable ones, and adds ref.as_non_null on
// their uses (which keeps the type of the users identical).
Expand Down
35 changes: 4 additions & 31 deletions src/passes/Heap2Local.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1534,12 +1534,10 @@ struct Heap2Local {
// constant indexes, so they are effectively structs, and turning them into
// such allows uniform handling later.
for (auto* allocation : finder.arrayNews) {
// The point of this optimization is to replace heap allocations with
// locals, so we must be able to place the data in locals.
if (!canHandleAsLocals(allocation->type)) {
if (allocation->type == Type::unreachable) {
// Leave this for DCE.
continue;
}

EscapeAnalyzer analyzer(
localGraph, parents, branchTargets, passOptions, wasm);
if (!analyzer.escapes(allocation)) {
Expand All @@ -1554,11 +1552,10 @@ struct Heap2Local {

// Next, process all structNews.
for (auto* allocation : finder.structNews) {
// As above, we must be able to use locals for this data.
if (!canHandleAsLocals(allocation->type)) {
if (allocation->type == Type::unreachable) {
// Leave this for DCE.
continue;
}

// Check for escaping, noting relevant information as we go. If this does
// not escape, optimize it into locals.
EscapeAnalyzer analyzer(
Expand All @@ -1576,30 +1573,6 @@ struct Heap2Local {
EHUtils::handleBlockNestedPops(func, wasm);
}
}

bool canHandleAsLocal(const Field& field) {
return TypeUpdating::canHandleAsLocal(field.type);
}

bool canHandleAsLocals(Type type) {
if (type == Type::unreachable) {
return false;
}

auto heapType = type.getHeapType();
if (heapType.isStruct()) {
auto& fields = heapType.getStruct().fields;
for (auto field : fields) {
if (!canHandleAsLocal(field)) {
return false;
}
}
return true;
}

assert(heapType.isArray());
return canHandleAsLocal(heapType.getArray().element);
}
};

struct Heap2LocalPass : public WalkerPass<PostWalker<Heap2LocalPass>> {
Expand Down
15 changes: 0 additions & 15 deletions src/passes/Inlining.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,17 +186,6 @@ struct FunctionInfo {
}
};

static bool canHandleParams(Function* func) {
// We cannot inline a function if we cannot handle placing its params in a
// locals, as all params become locals.
for (auto param : func->getParams()) {
if (!TypeUpdating::canHandleAsLocal(param)) {
return false;
}
}
return true;
}

using NameInfoMap = std::unordered_map<Name, FunctionInfo>;

struct FunctionInfoScanner
Expand Down Expand Up @@ -246,10 +235,6 @@ struct FunctionInfoScanner
void visitFunction(Function* curr) {
auto& info = infos[curr->name];

if (!canHandleParams(curr)) {
info.inliningMode = InliningMode::Uninlineable;
}

info.size = Measurer::measure(curr->body);

// If the body is a simple instruction with roughly the same encoded size as
Expand Down
3 changes: 1 addition & 2 deletions src/passes/LocalCSE.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -354,8 +354,7 @@ struct Scanner
// them is not cheap, so leave them for later, after we know if there
// actually are any requests for reuse of this value (which is rare).
if (!curr->type.isConcrete() || curr->is<LocalGet>() ||
curr->is<LocalSet>() || Properties::isConstantExpression(curr) ||
!TypeUpdating::canHandleAsLocal(curr->type)) {
curr->is<LocalSet>() || Properties::isConstantExpression(curr)) {
return false;
}

Expand Down
4 changes: 0 additions & 4 deletions src/passes/OptimizeInstructions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1432,10 +1432,6 @@ struct OptimizeInstructions
// The call_ref is not reached; leave this for DCE.
return;
}
if (!TypeUpdating::canHandleAsLocal(lastOperandType)) {
// We cannot create a local, so we must give up.
return;
}
Index tempLocal = builder.addVar(
getFunction(),
TypeUpdating::getValidLocalType(lastOperandType, features));
Expand Down
3 changes: 1 addition & 2 deletions src/passes/call-utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,7 @@ convertToDirectCalls(T* curr,
// execute first, so we'll use locals for them all. First, see if any are
// unreachable, and if so stop trying to optimize and leave this for DCE.
for (auto* operand : operands) {
if (operand->type == Type::unreachable ||
!TypeUpdating::canHandleAsLocal(operand->type)) {
if (operand->type == Type::unreachable) {
return nullptr;
}
}
Expand Down
9 changes: 0 additions & 9 deletions src/passes/param-utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,15 +131,6 @@ RemovalOutcome removeParameter(const std::vector<Function*>& funcs,
}
}

// The type must be valid for us to handle as a local (since we
// replace the parameter with a local).
// TODO: if there are no references at all, we can avoid creating a
// local
bool typeIsValid = TypeUpdating::canHandleAsLocal(first->getLocalType(index));
if (!typeIsValid) {
return Failure;
}

// We can do it!

// Remove the parameter from the function. We must add a new local
Expand Down
8 changes: 2 additions & 6 deletions src/tools/fuzzing/fuzzing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1687,11 +1687,7 @@ Function* TranslateToFuzzReader::addFunction() {

Index numVars = upToSquared(fuzzParams->MAX_VARS);
for (Index i = 0; i < numVars; i++) {
auto type = getConcreteType();
if (!TypeUpdating::canHandleAsLocal(type)) {
type = Type::i32;
}
func->vars.push_back(type);
func->vars.push_back(getConcreteType());
}
// Generate the function creation context after we filled in locals, which it
// will scan.
Expand Down Expand Up @@ -3122,7 +3118,7 @@ Expression* TranslateToFuzzReader::makeLocalGet(Type type) {
// the time), or emit a local.get of a new local, or emit a local.tee of a new
// local.
auto choice = upTo(3);
if (choice == 0 || !TypeUpdating::canHandleAsLocal(type)) {
if (choice == 0) {
return makeConst(type);
}
// Otherwise, add a new local. If the type is not non-nullable then we may
Expand Down
Loading