diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/passes/GUFA.cpp | 19 | ||||
-rw-r--r-- | src/passes/Heap2Local.cpp | 4 |
2 files changed, 22 insertions, 1 deletions
diff --git a/src/passes/GUFA.cpp b/src/passes/GUFA.cpp index 137ffda17..8f58eaf8a 100644 --- a/src/passes/GUFA.cpp +++ b/src/passes/GUFA.cpp @@ -255,6 +255,25 @@ struct GUFAOptimizer } } + void visitRefCast(RefCast* curr) { + auto currType = curr->type; + auto inferredType = getContents(curr).getType(); + if (inferredType.isRef() && inferredType != currType && + Type::isSubType(inferredType, currType)) { + // We have inferred that this will only contain something of a more + // refined type, so we might as well cast to that more refined type. + // + // Note that we could in principle apply this in all expressions by adding + // a cast. However, to be careful with code size, we only refine existing + // casts for now. + curr->type = inferredType; + } + + // Apply the usual optimizations as well, such as potentially replacing this + // with a constant. + visitExpression(curr); + } + // TODO: If an instruction would trap on null, like struct.get, we could // remove it here if it has no possible contents and if we are in // traps-never-happen mode (that is, we'd have proven it can only trap, diff --git a/src/passes/Heap2Local.cpp b/src/passes/Heap2Local.cpp index 91298106d..fccbc3321 100644 --- a/src/passes/Heap2Local.cpp +++ b/src/passes/Heap2Local.cpp @@ -191,7 +191,9 @@ struct Heap2LocalOptimizer { localGraph.computeSetInfluences(); // All the allocations in the function. - // TODO: Arrays (of constant size) as well. + // TODO: Arrays (of constant size) as well, if all element accesses use + // constant indexes. One option might be to first convert such + // nonescaping arrays into structs. FindAll<StructNew> allocations(func->body); for (auto* allocation : allocations.list) { |