remove side-effect-free nodes in registerize; enable registerize in native optimizer

This commit is contained in:
Alon Zakai 2014-11-12 17:02:50 -08:00
Родитель 1a58369e2f
Коммит fd738c6754
2 изменённых файлов: 27 добавлений и 2 удалений

Просмотреть файл

@ -9,7 +9,7 @@ __rootpath__ = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
def path_from_root(*pathelems):
return os.path.join(__rootpath__, *pathelems)
NATIVE_PASSES = set(['asm', 'asmPreciseF32', 'receiveJSON', 'emitJSON', 'eliminate', 'eliminateMemSafe', 'simplifyExpressions', 'simplifyIfs', 'optimizeFrounds'])
NATIVE_PASSES = set(['asm', 'asmPreciseF32', 'receiveJSON', 'emitJSON', 'eliminate', 'eliminateMemSafe', 'simplifyExpressions', 'simplifyIfs', 'optimizeFrounds', 'registerize'])
JS_OPTIMIZER = path_from_root('tools', 'js-optimizer.js')

Просмотреть файл

@ -829,6 +829,19 @@ void clearEmptyNodes(Ref arr) {
}
if (skip) arr->setSize(arr->size() - skip);
}
void clearUselessNodes(Ref arr) {
int skip = 0;
for (int i = 0; i < arr->size(); i++) {
Ref curr = arr[i];
if (skip) {
arr[i-skip] = curr;
}
if (isEmpty(deStat(curr)) || (curr[0] == STAT && !hasSideEffects(curr[1]))) {
skip++;
}
}
if (skip) arr->setSize(arr->size() - skip);
}
void removeAllEmptySubNodes(Ref ast) {
traversePre(ast, [](Ref node) {
@ -842,6 +855,18 @@ void removeAllEmptySubNodes(Ref ast) {
}
});
}
void removeAllUselessSubNodes(Ref ast) {
traversePre(ast, [](Ref node) {
int index = -1;
if (node[0] == DEFUN) {
clearUselessNodes(node[3]);
} else if (node[0] == BLOCK && !!node[1]) {
clearUselessNodes(node[1]);
} else if (node[0] == SEQ && isEmpty(node[1])) {
safeCopy(node, node[2]);
}
});
}
Ref unVarify(Ref vars) { // transform var x=1, y=2 etc. into (x=1, y=2), i.e., the same assigns, but without a var definition
Ref ret = makeArray();
@ -2348,7 +2373,7 @@ void registerize(Ref ast) {
allVars.insert(node[1]->getIString());
}
});
removeAllEmptySubNodes(fun); // vacuum?
removeAllUselessSubNodes(fun); // vacuum?
StringTypeMap regTypes; // reg name -> type
auto getNewRegName = [&](int num, IString name) {
const char *str;