Skip to content

Commit

Permalink
Make review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
aidanhs committed Apr 4, 2015
1 parent 2edcba7 commit 44db833
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 18 deletions.
7 changes: 4 additions & 3 deletions emcc
Expand Up @@ -1070,6 +1070,10 @@ try:
memory_init_file = True
assert closure is not 2, 'EMTERPRETIFY requires valid asm.js, and is incompatible with closure 2 which disables that'

if shared.Settings.DEAD_FUNCTIONS and not js_opts:
js_opts = True
logging.warning('enabling js opts for DEAD_FUNCTIONS')

if proxy_to_worker:
shared.Settings.PROXY_TO_WORKER = 1

Expand Down Expand Up @@ -1491,12 +1495,9 @@ try:
js_optimizer_queue = []
js_optimizer_extra_info = {}

# Regardless of what -OX mode we're in, dead functions should be removed. This pass
# should be considered first so other optimisations aren't taken along for the ride.
if shared.Settings.DEAD_FUNCTIONS:
js_optimizer_queue += ['eliminateDeadFuncs']
js_optimizer_extra_info['dead_functions'] = shared.Settings.DEAD_FUNCTIONS
flush_js_optimizer_queue()

if opt_level >= 1 and js_opts:
logging.debug('running js post-opts')
Expand Down
9 changes: 3 additions & 6 deletions tools/js-optimizer.js
Expand Up @@ -7921,13 +7921,10 @@ function asmLastOpts(ast) {
function eliminateDeadFuncs(ast) {
assert(asm);
assert(extraInfo && extraInfo.dead_functions);
var dead_functions = extraInfo.dead_functions;
var deadFunctions = set(extraInfo.dead_functions);
traverseGeneratedFunctions(ast, function (fun, type) {
for (var i = 0; i < dead_functions.length; i++) {
if (dead_functions[i] === fun[1]) {
break;
}
return;
if (!(fun[1] in deadFunctions)) {
return;
}
var asmData = normalizeAsm(fun);
fun[3] = [['stat', ['call', ['name', 'abort'], []]]];
Expand Down
16 changes: 7 additions & 9 deletions tools/optimizer/optimizer.cpp
Expand Up @@ -3876,20 +3876,18 @@ void eliminateDeadFuncs(Ref ast) {
IString DEAD_FUNCTIONS("dead_functions");
IString ABORT("abort");
assert(extraInfo->has(DEAD_FUNCTIONS));
Ref dead_functions = extraInfo[DEAD_FUNCTIONS];
StringSet deadFunctions;
for (size_t i = 0; i < extraInfo[DEAD_FUNCTIONS]->size(); i++) {
deadFunctions.insert(extraInfo[DEAD_FUNCTIONS][i]->getIString());
}
traverseFunctions(ast, [&](Ref fun) {
for (size_t i = 0; i < dead_functions->size(); i++) {
if (dead_functions[i] == fun[1].get()->getCString()) {
break;
}
return;
if (!deadFunctions.has(fun[1].get()->getIString())) {
return;
}
AsmData asmData(fun);
fun[3]->setSize(1);
fun[3][0] = make1(STAT, make2(CALL, makeName(ABORT), makeArray()));
while (asmData.vars.size() > 0) {
asmData.deleteVar(asmData.vars[0]);
}
asmData.vars.clear();
asmData.denormalize();
});
}
Expand Down

0 comments on commit 44db833

Please sign in to comment.