summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/asm2wasm.h14
-rw-r--r--src/emscripten-optimizer/simple_ast.h4
-rw-r--r--src/passes/PrintCallGraph.cpp47
-rw-r--r--test/passes/print-call-graph.txt185
-rw-r--r--test/unit.asm.js4
-rw-r--r--test/unit.fromasm.imprecise.no-opts5
-rw-r--r--test/unit.fromasm.no-opts5
7 files changed, 122 insertions, 142 deletions
diff --git a/src/asm2wasm.h b/src/asm2wasm.h
index 377b6b20b..87fd10649 100644
--- a/src/asm2wasm.h
+++ b/src/asm2wasm.h
@@ -443,9 +443,13 @@ private:
std::map<unsigned, Ref> tempNums;
- Literal checkLiteral(Ref ast) {
+ Literal checkLiteral(Ref ast, bool rawIsInteger = true) {
if (ast[0] == NUM) {
- return Literal((int32_t)ast[1]->getInteger());
+ if (rawIsInteger) {
+ return Literal((int32_t)ast[1]->getInteger());
+ } else {
+ return Literal(ast[1]->getNumber());
+ }
} else if (ast[0] == UNARY_PREFIX) {
if (ast[1] == PLUS && ast[2][0] == NUM) {
return Literal((double)ast[2][1]->getNumber());
@@ -1475,10 +1479,8 @@ Function* Asm2WasmBuilder::processFunction(Ref ast) {
}
if (name == Math_fround) {
assert(ast[2]->size() == 1);
- Literal lit = checkLiteral(ast[2][0]);
- if (lit.type == i32) {
- return builder.makeConst(Literal((float)lit.geti32()));
- } else if (lit.type == f64) {
+ Literal lit = checkLiteral(ast[2][0], false /* raw is float */);
+ if (lit.type == f64) {
return builder.makeConst(Literal((float)lit.getf64()));
}
auto ret = allocator.alloc<Unary>();
diff --git a/src/emscripten-optimizer/simple_ast.h b/src/emscripten-optimizer/simple_ast.h
index 3f0d363df..20de952c1 100644
--- a/src/emscripten-optimizer/simple_ast.h
+++ b/src/emscripten-optimizer/simple_ast.h
@@ -225,9 +225,9 @@ struct Value {
return boo;
}
- int getInteger() { // convenience function to get a known integer
+ int32_t getInteger() { // convenience function to get a known integer
assert(fmod(getNumber(), 1) == 0);
- int ret = int(getNumber());
+ int32_t ret = getNumber();
assert(double(ret) == getNumber()); // no loss in conversion
return ret;
}
diff --git a/src/passes/PrintCallGraph.cpp b/src/passes/PrintCallGraph.cpp
index 33fcb3457..233ae3a0c 100644
--- a/src/passes/PrintCallGraph.cpp
+++ b/src/passes/PrintCallGraph.cpp
@@ -33,20 +33,25 @@ struct PrintCallGraph : public Pass {
o << "digraph call {\n";
o << " rankdir = LR;\n";
o << " subgraph cluster_key {\n";
- o << " node [shape=box, style=rounded, fontname=courier, fontsize=10];\n";
+ o << " node [shape=box, fontname=courier, fontsize=10];\n";
o << " edge [fontname=courier, fontsize=10];\n";
o << " label = \"Key\";\n";
- o << " \"Import\" [style=\"filled, rounded\", fillcolor=\"turquoise\"];\n";
- o << " \"Export\" [style=\"filled, rounded\", fillcolor=\"gray\"];\n";
+ o << " \"Import\" [style=\"filled\", fillcolor=\"turquoise\"];\n";
+ o << " \"Export\" [style=\"filled\", fillcolor=\"gray\"];\n";
+ o << " \"Indirect Target\" [style=\"filled, rounded\", fillcolor=\"white\"];\n";
o << " \"A\" -> \"B\" [style=\"filled, rounded\", label = \"Direct Call\"];\n";
- o << " \"C\" -> \"D\" [style=\"filled, rounded, dashed\", label = \"Possible Indirect Call\"];\n";
o << " }\n\n";
- o << " node [shape=box,style=rounded, fontname=courier, fontsize=10];\n";
+ o << " node [shape=box, fontname=courier, fontsize=10];\n";
+
+ // All Functions
+ for (auto& func : module->functions) {
+ std::cout << " \"" << func.get()->name << "\" [style=\"filled\", fillcolor=\"white\"];\n";
+ }
// Imports Nodes
for (auto& curr : module->imports) {
if (curr->kind == ExternalKind::Function) {
- o << " \"" << curr->name << "\" [style=\"filled, rounded\", fillcolor=\"turquoise\"];\n";
+ o << " \"" << curr->name << "\" [style=\"filled\", fillcolor=\"turquoise\"];\n";
}
}
@@ -54,7 +59,7 @@ struct PrintCallGraph : public Pass {
for (auto& curr : module->exports) {
if (curr->kind == ExternalKind::Function) {
Function* func = module->getFunction(curr->value);
- o << " \"" << func->name << "\" [style=\"filled, rounded\", fillcolor=\"gray\"];\n";
+ o << " \"" << func->name << "\" [style=\"filled\", fillcolor=\"gray\"];\n";
}
}
@@ -64,16 +69,9 @@ struct PrintCallGraph : public Pass {
std::set<Name> visitedTargets; // Used to avoid printing duplicate edges.
std::vector<Function*> allIndirectTargets;
CallPrinter(Module *module) : module(module) {
- // Gather targets of indirect calls.
- for (auto& segment : module->table.segments) {
- for (auto& curr : segment.data) {
- allIndirectTargets.push_back(module->getFunction(curr));
- }
- }
// Walk function bodies.
for (auto& func : module->functions) {
currFunction = func.get();
- std::cout << " \"" << func->name << "\";\n";
visitedTargets.clear();
walk(func.get()->body);
}
@@ -90,20 +88,17 @@ struct PrintCallGraph : public Pass {
visitedTargets.insert(name);
std::cout << " \"" << currFunction->name << "\" -> \"" << name << "\"; // callImport\n";
}
- void visitCallIndirect(CallIndirect *curr) {
- // Find eligible indirect targets.
- auto* currType = module->getFunctionType(curr->fullType);
- for (auto& target : allIndirectTargets) {
- auto* targetType = module->getFunctionType(target->type);
- if (targetType->structuralComparison(*currType)) continue;
- auto name = target->name;
- if (visitedTargets.count(name) > 0) continue;
- visitedTargets.insert(name);
- std::cout << " \"" << currFunction->name << "\" -> \"" << name << "\" [style=\"dashed\"]; // callIndirect\n";
- }
- }
};
CallPrinter printer(module);
+
+ // Indirect Targets
+ for (auto& segment : module->table.segments) {
+ for (auto& curr : segment.data) {
+ auto* func = module->getFunction(curr);
+ o << " \"" << func->name << "\" [style=\"filled, rounded\"];\n";
+ }
+ }
+
o << "}\n";
}
};
diff --git a/test/passes/print-call-graph.txt b/test/passes/print-call-graph.txt
index 4558194ef..b12b95828 100644
--- a/test/passes/print-call-graph.txt
+++ b/test/passes/print-call-graph.txt
@@ -1,146 +1,115 @@
digraph call {
rankdir = LR;
subgraph cluster_key {
- node [shape=box, style=rounded, fontname=courier, fontsize=10];
+ node [shape=box, fontname=courier, fontsize=10];
edge [fontname=courier, fontsize=10];
label = "Key";
- "Import" [style="filled, rounded", fillcolor="turquoise"];
- "Export" [style="filled, rounded", fillcolor="gray"];
+ "Import" [style="filled", fillcolor="turquoise"];
+ "Export" [style="filled", fillcolor="gray"];
+ "Indirect Target" [style="filled, rounded", fillcolor="white"];
"A" -> "B" [style="filled, rounded", label = "Direct Call"];
- "C" -> "D" [style="filled, rounded, dashed", label = "Possible Indirect Call"];
}
- node [shape=box,style=rounded, fontname=courier, fontsize=10];
- "$abort" [style="filled, rounded", fillcolor="turquoise"];
- "$_pthread_cleanup_pop" [style="filled, rounded", fillcolor="turquoise"];
- "$___lock" [style="filled, rounded", fillcolor="turquoise"];
- "$___syscall6" [style="filled, rounded", fillcolor="turquoise"];
- "$_pthread_cleanup_push" [style="filled, rounded", fillcolor="turquoise"];
- "$___syscall140" [style="filled, rounded", fillcolor="turquoise"];
- "$_emscripten_memcpy_big" [style="filled, rounded", fillcolor="turquoise"];
- "$___syscall54" [style="filled, rounded", fillcolor="turquoise"];
- "$___unlock" [style="filled, rounded", fillcolor="turquoise"];
- "$___syscall146" [style="filled, rounded", fillcolor="turquoise"];
- "$_fflush" [style="filled, rounded", fillcolor="gray"];
- "$_main" [style="filled, rounded", fillcolor="gray"];
- "$_pthread_self" [style="filled, rounded", fillcolor="gray"];
- "$_memset" [style="filled, rounded", fillcolor="gray"];
- "$_malloc" [style="filled, rounded", fillcolor="gray"];
- "$_memcpy" [style="filled, rounded", fillcolor="gray"];
- "$_free" [style="filled, rounded", fillcolor="gray"];
- "$___errno_location" [style="filled, rounded", fillcolor="gray"];
- "$runPostSets" [style="filled, rounded", fillcolor="gray"];
- "$stackAlloc" [style="filled, rounded", fillcolor="gray"];
- "$stackSave" [style="filled, rounded", fillcolor="gray"];
- "$stackRestore" [style="filled, rounded", fillcolor="gray"];
- "$establishStackSpace" [style="filled, rounded", fillcolor="gray"];
- "$setThrew" [style="filled, rounded", fillcolor="gray"];
- "$setTempRet0" [style="filled, rounded", fillcolor="gray"];
- "$getTempRet0" [style="filled, rounded", fillcolor="gray"];
- "$dynCall_ii" [style="filled, rounded", fillcolor="gray"];
- "$dynCall_iiii" [style="filled, rounded", fillcolor="gray"];
- "$dynCall_vi" [style="filled, rounded", fillcolor="gray"];
- "$dynCall_v" [style="filled, rounded", fillcolor="gray"];
- "$stackAlloc";
- "$stackSave";
- "$stackRestore";
- "$establishStackSpace";
- "$setThrew";
- "$setTempRet0";
- "$getTempRet0";
- "$_malloc";
- "$_free";
- "$_main";
+ node [shape=box, fontname=courier, fontsize=10];
+ "$stackAlloc" [style="filled", fillcolor="white"];
+ "$stackSave" [style="filled", fillcolor="white"];
+ "$stackRestore" [style="filled", fillcolor="white"];
+ "$establishStackSpace" [style="filled", fillcolor="white"];
+ "$setThrew" [style="filled", fillcolor="white"];
+ "$setTempRet0" [style="filled", fillcolor="white"];
+ "$getTempRet0" [style="filled", fillcolor="white"];
+ "$_malloc" [style="filled", fillcolor="white"];
+ "$_free" [style="filled", fillcolor="white"];
+ "$_main" [style="filled", fillcolor="white"];
+ "$___stdio_close" [style="filled", fillcolor="white"];
+ "$___stdio_write" [style="filled", fillcolor="white"];
+ "$___stdio_seek" [style="filled", fillcolor="white"];
+ "$___syscall_ret" [style="filled", fillcolor="white"];
+ "$___errno_location" [style="filled", fillcolor="white"];
+ "$_cleanup_387" [style="filled", fillcolor="white"];
+ "$___stdout_write" [style="filled", fillcolor="white"];
+ "$_fflush" [style="filled", fillcolor="white"];
+ "$___fflush_unlocked" [style="filled", fillcolor="white"];
+ "$__Znwj" [style="filled", fillcolor="white"];
+ "$__ZSt15get_new_handlerv" [style="filled", fillcolor="white"];
+ "$runPostSets" [style="filled", fillcolor="white"];
+ "$_memset" [style="filled", fillcolor="white"];
+ "$_memcpy" [style="filled", fillcolor="white"];
+ "$_pthread_self" [style="filled", fillcolor="white"];
+ "$dynCall_ii" [style="filled", fillcolor="white"];
+ "$dynCall_iiii" [style="filled", fillcolor="white"];
+ "$dynCall_vi" [style="filled", fillcolor="white"];
+ "$dynCall_v" [style="filled", fillcolor="white"];
+ "$b0" [style="filled", fillcolor="white"];
+ "$b1" [style="filled", fillcolor="white"];
+ "$b2" [style="filled", fillcolor="white"];
+ "$b3" [style="filled", fillcolor="white"];
+ "$abort" [style="filled", fillcolor="turquoise"];
+ "$_pthread_cleanup_pop" [style="filled", fillcolor="turquoise"];
+ "$___lock" [style="filled", fillcolor="turquoise"];
+ "$___syscall6" [style="filled", fillcolor="turquoise"];
+ "$_pthread_cleanup_push" [style="filled", fillcolor="turquoise"];
+ "$___syscall140" [style="filled", fillcolor="turquoise"];
+ "$_emscripten_memcpy_big" [style="filled", fillcolor="turquoise"];
+ "$___syscall54" [style="filled", fillcolor="turquoise"];
+ "$___unlock" [style="filled", fillcolor="turquoise"];
+ "$___syscall146" [style="filled", fillcolor="turquoise"];
+ "$_fflush" [style="filled", fillcolor="gray"];
+ "$_main" [style="filled", fillcolor="gray"];
+ "$_pthread_self" [style="filled", fillcolor="gray"];
+ "$_memset" [style="filled", fillcolor="gray"];
+ "$_malloc" [style="filled", fillcolor="gray"];
+ "$_memcpy" [style="filled", fillcolor="gray"];
+ "$_free" [style="filled", fillcolor="gray"];
+ "$___errno_location" [style="filled", fillcolor="gray"];
+ "$runPostSets" [style="filled", fillcolor="gray"];
+ "$stackAlloc" [style="filled", fillcolor="gray"];
+ "$stackSave" [style="filled", fillcolor="gray"];
+ "$stackRestore" [style="filled", fillcolor="gray"];
+ "$establishStackSpace" [style="filled", fillcolor="gray"];
+ "$setThrew" [style="filled", fillcolor="gray"];
+ "$setTempRet0" [style="filled", fillcolor="gray"];
+ "$getTempRet0" [style="filled", fillcolor="gray"];
+ "$dynCall_ii" [style="filled", fillcolor="gray"];
+ "$dynCall_iiii" [style="filled", fillcolor="gray"];
+ "$dynCall_vi" [style="filled", fillcolor="gray"];
+ "$dynCall_v" [style="filled", fillcolor="gray"];
"$_main" -> "$__Znwj"; // call
- "$___stdio_close";
"$___stdio_close" -> "$___syscall6"; // callImport
"$___stdio_close" -> "$___syscall_ret"; // call
- "$___stdio_write";
"$___stdio_write" -> "$_pthread_cleanup_push"; // callImport
"$___stdio_write" -> "$___syscall146"; // callImport
"$___stdio_write" -> "$___syscall_ret"; // call
"$___stdio_write" -> "$_pthread_cleanup_pop"; // callImport
- "$___stdio_seek";
"$___stdio_seek" -> "$___syscall140"; // callImport
"$___stdio_seek" -> "$___syscall_ret"; // call
- "$___syscall_ret";
"$___syscall_ret" -> "$___errno_location"; // call
- "$___errno_location";
"$___errno_location" -> "$_pthread_self"; // call
- "$_cleanup_387";
"$_cleanup_387" -> "$_free"; // call
- "$___stdout_write";
"$___stdout_write" -> "$___syscall54"; // callImport
"$___stdout_write" -> "$___stdio_write"; // call
- "$_fflush";
"$_fflush" -> "$___fflush_unlocked"; // call
"$_fflush" -> "$_malloc"; // call
"$_fflush" -> "$_free"; // call
"$_fflush" -> "$_fflush"; // call
"$_fflush" -> "$___lock"; // callImport
"$_fflush" -> "$___unlock"; // callImport
- "$___fflush_unlocked";
- "$___fflush_unlocked" -> "$b0" [style="dashed"]; // callIndirect
- "$___fflush_unlocked" -> "$___stdio_close" [style="dashed"]; // callIndirect
- "$___fflush_unlocked" -> "$b2" [style="dashed"]; // callIndirect
- "$___fflush_unlocked" -> "$_cleanup_387" [style="dashed"]; // callIndirect
- "$___fflush_unlocked" -> "$b3" [style="dashed"]; // callIndirect
- "$__Znwj";
"$__Znwj" -> "$_malloc"; // call
"$__Znwj" -> "$__ZSt15get_new_handlerv"; // call
- "$__Znwj" -> "$b0" [style="dashed"]; // callIndirect
- "$__Znwj" -> "$___stdio_close" [style="dashed"]; // callIndirect
- "$__Znwj" -> "$b1" [style="dashed"]; // callIndirect
- "$__Znwj" -> "$___stdout_write" [style="dashed"]; // callIndirect
- "$__Znwj" -> "$___stdio_seek" [style="dashed"]; // callIndirect
- "$__Znwj" -> "$___stdio_write" [style="dashed"]; // callIndirect
- "$__Znwj" -> "$b2" [style="dashed"]; // callIndirect
- "$__Znwj" -> "$_cleanup_387" [style="dashed"]; // callIndirect
- "$__ZSt15get_new_handlerv";
- "$runPostSets";
- "$_memset";
- "$_memcpy";
"$_memcpy" -> "$_emscripten_memcpy_big"; // callImport
- "$_pthread_self";
- "$dynCall_ii";
- "$dynCall_ii" -> "$b1" [style="dashed"]; // callIndirect
- "$dynCall_ii" -> "$___stdout_write" [style="dashed"]; // callIndirect
- "$dynCall_ii" -> "$___stdio_seek" [style="dashed"]; // callIndirect
- "$dynCall_ii" -> "$___stdio_write" [style="dashed"]; // callIndirect
- "$dynCall_ii" -> "$b2" [style="dashed"]; // callIndirect
- "$dynCall_ii" -> "$_cleanup_387" [style="dashed"]; // callIndirect
- "$dynCall_ii" -> "$b3" [style="dashed"]; // callIndirect
- "$dynCall_iiii";
- "$dynCall_iiii" -> "$b0" [style="dashed"]; // callIndirect
- "$dynCall_iiii" -> "$___stdio_close" [style="dashed"]; // callIndirect
- "$dynCall_iiii" -> "$b2" [style="dashed"]; // callIndirect
- "$dynCall_iiii" -> "$_cleanup_387" [style="dashed"]; // callIndirect
- "$dynCall_iiii" -> "$b3" [style="dashed"]; // callIndirect
- "$dynCall_vi";
- "$dynCall_vi" -> "$b0" [style="dashed"]; // callIndirect
- "$dynCall_vi" -> "$___stdio_close" [style="dashed"]; // callIndirect
- "$dynCall_vi" -> "$b1" [style="dashed"]; // callIndirect
- "$dynCall_vi" -> "$___stdout_write" [style="dashed"]; // callIndirect
- "$dynCall_vi" -> "$___stdio_seek" [style="dashed"]; // callIndirect
- "$dynCall_vi" -> "$___stdio_write" [style="dashed"]; // callIndirect
- "$dynCall_vi" -> "$b3" [style="dashed"]; // callIndirect
- "$dynCall_v";
- "$dynCall_v" -> "$b0" [style="dashed"]; // callIndirect
- "$dynCall_v" -> "$___stdio_close" [style="dashed"]; // callIndirect
- "$dynCall_v" -> "$b1" [style="dashed"]; // callIndirect
- "$dynCall_v" -> "$___stdout_write" [style="dashed"]; // callIndirect
- "$dynCall_v" -> "$___stdio_seek" [style="dashed"]; // callIndirect
- "$dynCall_v" -> "$___stdio_write" [style="dashed"]; // callIndirect
- "$dynCall_v" -> "$b2" [style="dashed"]; // callIndirect
- "$dynCall_v" -> "$_cleanup_387" [style="dashed"]; // callIndirect
- "$b0";
"$b0" -> "$abort"; // callImport
- "$b1";
"$b1" -> "$abort"; // callImport
- "$b2";
"$b2" -> "$abort"; // callImport
- "$b3";
"$b3" -> "$abort"; // callImport
+ "$b0" [style="filled, rounded"];
+ "$___stdio_close" [style="filled, rounded"];
+ "$b1" [style="filled, rounded"];
+ "$___stdout_write" [style="filled, rounded"];
+ "$___stdio_seek" [style="filled, rounded"];
+ "$___stdio_write" [style="filled, rounded"];
+ "$b2" [style="filled, rounded"];
+ "$_cleanup_387" [style="filled, rounded"];
+ "$b3" [style="filled, rounded"];
}
(module
(type $FUNCSIG$iiii (func (param i32 i32 i32) (result i32)))
diff --git a/test/unit.asm.js b/test/unit.asm.js
index 6ccf6c489..f002965ec 100644
--- a/test/unit.asm.js
+++ b/test/unit.asm.js
@@ -589,6 +589,10 @@ function asm(global, env, buffer) {
return;
}
+ function big_fround() {
+ return Math_fround(4294967295);
+ }
+
function dropIgnoredImportsInIf($0,$1,$2) {
$0 = $0|0;
$1 = $1|0;
diff --git a/test/unit.fromasm.imprecise.no-opts b/test/unit.fromasm.imprecise.no-opts
index f372b2d57..608d68dcb 100644
--- a/test/unit.fromasm.imprecise.no-opts
+++ b/test/unit.fromasm.imprecise.no-opts
@@ -1677,6 +1677,11 @@
)
(return)
)
+ (func $big_fround (result f32)
+ (return
+ (f32.const 4294967296)
+ )
+ )
(func $dropIgnoredImportsInIf (param $$0 i32) (param $$1 i32) (param $$2 i32)
(block $do-once
(if
diff --git a/test/unit.fromasm.no-opts b/test/unit.fromasm.no-opts
index 0b90cb3b8..0b8a67ca7 100644
--- a/test/unit.fromasm.no-opts
+++ b/test/unit.fromasm.no-opts
@@ -1683,6 +1683,11 @@
)
(return)
)
+ (func $big_fround (result f32)
+ (return
+ (f32.const 4294967296)
+ )
+ )
(func $dropIgnoredImportsInIf (param $$0 i32) (param $$1 i32) (param $$2 i32)
(block $do-once
(if