Skip to content

Commit 331dd4a

Browse files
committed
Merge branch 'p-rcook-duplicate-function-elimination' of https://github.com/rcook/emscripten into incoming
2 parents 69192b1 + 98b4cf4 commit 331dd4a

32 files changed

+1603
-30
lines changed

AUTHORS

+3-1
Original file line numberDiff line numberDiff line change
@@ -232,4 +232,6 @@ a license to everyone to use it as detailed in LICENSE.)
232232
* Nick Shin <[email protected]>
233233
* Gregg Tavares <[email protected]>
234234
* Tanner Rogalsky <[email protected]>
235-
235+
* Richard Cook <[email protected]> (copyright owned by Tableau Software, Inc.)
236+
* Arnab Choudhury <[email protected]> (copyright owned by Tableau Software, Inc.)
237+
* Charles Vaughn <[email protected]> (copyright owned by Tableau Software, Inc.)

emcc.py

+5
Original file line numberDiff line numberDiff line change
@@ -1634,6 +1634,11 @@ def do_minify(): # minifies the code. this is also when we do certain optimizati
16341634
else:
16351635
JSOptimizer.queue += ['registerize']
16361636

1637+
# NOTE: Important that this comes after registerize/registerizeHarder
1638+
if shared.Settings.ELIMINATE_DUPLICATE_FUNCTIONS and opt_level >= 2:
1639+
JSOptimizer.flush()
1640+
shared.Building.eliminate_duplicate_funcs(final)
1641+
16371642
if not shared.Settings.EMTERPRETIFY:
16381643
do_minify()
16391644

src/settings.js

+5
Original file line numberDiff line numberDiff line change
@@ -681,4 +681,9 @@ var PTHREADS_PROFILING = 0; // True when building with --threadprofiler
681681

682682
var MAX_GLOBAL_ALIGN = -1; // received from the backend
683683

684+
// Duplicate function elimination
685+
var ELIMINATE_DUPLICATE_FUNCTIONS = 0; // disabled by default
686+
var ELIMINATE_DUPLICATE_FUNCTIONS_PASSES = 5;
687+
var ELIMINATE_DUPLICATE_FUNCTIONS_DUMP_EQUIVALENT_FUNCTIONS = 0;
688+
684689
// Reserved: variables containing POINTER_MASKING.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// EMSCRIPTEN_START_ASM
2+
var asm = (function(global, env, buffer) {
3+
"use asm";
4+
var e = 0;
5+
6+
// EMSCRIPTEN_START_FUNCS
7+
function a() {
8+
var c = 0.0;
9+
return 0;
10+
}
11+
// EMSCRIPTEN_END_FUNCS
12+
var f = 0;
13+
})(Module.asmGlobalArg, Module.asmLibraryArg, buffer);
14+
// EMSCRIPTEN_END_ASM
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// EMSCRIPTEN_START_ASM
2+
var asm = (function(global, env, buffer) {
3+
"use asm";
4+
var e = 0;
5+
6+
// EMSCRIPTEN_START_FUNCS
7+
function a() {
8+
var c = +0;
9+
return 0;
10+
}
11+
function b() {
12+
var c = +0;
13+
return 0;
14+
}
15+
// EMSCRIPTEN_END_FUNCS
16+
var f = 0;
17+
})(Module.asmGlobalArg, Module.asmLibraryArg, buffer);
18+
// EMSCRIPTEN_END_ASM
19+
// EMSCRIPTEN_GENERATED_FUNCTIONS
20+
21+
22+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// EMSCRIPTEN_START_ASM
2+
var asm = (function(global, env, buffer) {
3+
"use asm";
4+
5+
// EMSCRIPTEN_START_FUNCS
6+
function d() {
7+
a();
8+
e();
9+
return;
10+
}
11+
12+
function c() {
13+
a();
14+
return;
15+
}
16+
17+
function a() {
18+
return 0;
19+
}
20+
21+
// EMSCRIPTEN_END_FUNCS
22+
23+
var f = [ a ];
24+
})(Module.asmGlobalArg, Module.asmLibraryArg, buffer);
25+
// EMSCRIPTEN_END_ASM
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
var asm = (function(global, env, buffer) {
2+
"use asm";
3+
function a()
4+
{
5+
return 0;
6+
}
7+
8+
function b()
9+
{
10+
return 0;
11+
}
12+
13+
function c()
14+
{
15+
a();
16+
return;
17+
}
18+
19+
function d()
20+
{
21+
b();
22+
23+
// We expect that b gets replaced by a below
24+
var f = [b];
25+
e();
26+
27+
return;
28+
}
29+
30+
})(Module.asmGlobalArg, Module.asmLibraryArg, buffer);
31+
32+
// {"b":"a"}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// EMSCRIPTEN_START_ASM
2+
var asm = (function(global, env, buffer) {
3+
"use asm";
4+
// EMSCRIPTEN_START_FUNCS
5+
function a() {
6+
return 0;
7+
}
8+
function b() {
9+
return 0;
10+
}
11+
function c() {
12+
a();
13+
return;
14+
}
15+
function d() {
16+
b();
17+
e();
18+
return;
19+
}
20+
// EMSCRIPTEN_END_FUNCS
21+
var f = [ b ];
22+
})(Module.asmGlobalArg, Module.asmLibraryArg, buffer);
23+
// EMSCRIPTEN_END_ASM
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
var asm = (function(global, env, buffer) {
2+
"use asm";
3+
function a()
4+
{
5+
return 0;
6+
}
7+
8+
function c()
9+
{
10+
a();
11+
return;
12+
}
13+
14+
function d()
15+
{
16+
a();
17+
return;
18+
}
19+
20+
})(Module.asmGlobalArg, Module.asmLibraryArg, buffer);
21+
22+
// {"d":"c"}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
var asm = (function(global, env, buffer) {
2+
"use asm";
3+
function a() {
4+
return 0;
5+
}
6+
function c() {
7+
a();
8+
return;
9+
}
10+
function d() {
11+
a();
12+
return;
13+
}
14+
})(Module.asmGlobalArg, Module.asmLibraryArg, buffer);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
var asm = (function(global, env, buffer) {
2+
"use asm";
3+
function a() {
4+
return 0;
5+
}
6+
function c() {
7+
a();
8+
return;
9+
}
10+
})(Module.asmGlobalArg, Module.asmLibraryArg, buffer);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
var asm = (function(global, env, buffer) {
2+
"use asm";
3+
function a()
4+
{
5+
return 0;
6+
}
7+
8+
function b()
9+
{
10+
return 0;
11+
}
12+
13+
function c()
14+
{
15+
a();
16+
return;
17+
}
18+
19+
function d()
20+
{
21+
b();
22+
return;
23+
}
24+
25+
})(Module.asmGlobalArg, Module.asmLibraryArg, buffer);
26+
27+
// {"b":"a"}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
var asm = (function(global, env, buffer) {
2+
"use asm";
3+
function a() {
4+
return 0;
5+
}
6+
function b() {
7+
return 0;
8+
}
9+
function c() {
10+
a();
11+
return;
12+
}
13+
function d() {
14+
b();
15+
return;
16+
}
17+
})(Module.asmGlobalArg, Module.asmLibraryArg, buffer);
18+
19+
20+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
var asm = (function(global, env, buffer) {
2+
"use asm";
3+
function a() {
4+
return 0;
5+
}
6+
function c() {
7+
a();
8+
return;
9+
}
10+
function d() {
11+
a();
12+
var f = {
13+
g: a
14+
};
15+
e();
16+
return;
17+
}
18+
})(Module.asmGlobalArg, Module.asmLibraryArg, buffer);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
var asm = (function(global, env, buffer) {
2+
"use asm";
3+
function a()
4+
{
5+
return 0;
6+
}
7+
8+
function b()
9+
{
10+
return 0;
11+
}
12+
13+
function c()
14+
{
15+
a();
16+
return;
17+
}
18+
19+
function d()
20+
{
21+
b();
22+
23+
// We expect that b gets replaced by a below
24+
var f = {
25+
g: b
26+
};
27+
e();
28+
29+
return;
30+
}
31+
32+
})(Module.asmGlobalArg, Module.asmLibraryArg, buffer);
33+
34+
// {"b":"a"}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
var asm = (function(global, env, buffer) {
2+
"use asm";
3+
function a() {
4+
return 0;
5+
}
6+
function b() {
7+
return 0;
8+
}
9+
function c() {
10+
a();
11+
return;
12+
}
13+
function d() {
14+
b();
15+
var f = {
16+
g: b
17+
};
18+
e();
19+
return;
20+
}
21+
})(Module.asmGlobalArg, Module.asmLibraryArg, buffer);
22+
23+
24+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
var asm = (function(global, env, buffer) {
2+
"use asm";
3+
function a() {
4+
return 0;
5+
}
6+
function c() {
7+
a();
8+
return;
9+
}
10+
function d() {
11+
a();
12+
var e = a;
13+
e();
14+
return;
15+
}
16+
})(Module.asmGlobalArg, Module.asmLibraryArg, buffer);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
var asm = (function(global, env, buffer) {
2+
"use asm";
3+
function a()
4+
{
5+
return 0;
6+
}
7+
8+
function b()
9+
{
10+
return 0;
11+
}
12+
13+
function c()
14+
{
15+
a();
16+
return;
17+
}
18+
19+
function d()
20+
{
21+
b();
22+
23+
// We expect that b gets replaced by a below
24+
var e = b;
25+
e();
26+
27+
return;
28+
}
29+
30+
})(Module.asmGlobalArg, Module.asmLibraryArg, buffer);
31+
32+
// {"b" : "a"}

0 commit comments

Comments
 (0)