aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/eliminator/asm-eliminator-test-output.js10
-rw-r--r--tools/eliminator/asm-eliminator-test.js16
-rw-r--r--tools/js-optimizer.js30
-rw-r--r--tools/shared.py8
4 files changed, 53 insertions, 11 deletions
diff --git a/tools/eliminator/asm-eliminator-test-output.js b/tools/eliminator/asm-eliminator-test-output.js
index e477c320..b519cdf9 100644
--- a/tools/eliminator/asm-eliminator-test-output.js
+++ b/tools/eliminator/asm-eliminator-test-output.js
@@ -123,4 +123,14 @@ function switchy() {
continue;
}
}
+function confuusion() {
+ var i = +0, j = +0;
+ func1(+i);
+ j = i;
+ func2(+j);
+}
+function tempDouble(a) {
+ a = +a;
+ f(a * a);
+}
diff --git a/tools/eliminator/asm-eliminator-test.js b/tools/eliminator/asm-eliminator-test.js
index acc07edb..ff67af47 100644
--- a/tools/eliminator/asm-eliminator-test.js
+++ b/tools/eliminator/asm-eliminator-test.js
@@ -156,5 +156,19 @@ function switchy() {
continue;
}
}
-// EMSCRIPTEN_GENERATED_FUNCTIONS: ["asm", "__Z11printResultPiS_j", "_segment_holding", "__ZN5identC2EiPKcPci", "_vec2Length", "exc", "label"]
+function confuusion() {
+ var i = +0;
+ func1(+i);
+ var j = i; // add this var in the middle. should show up with right type later, auto-inferred from i's type
+ func2(+j);
+}
+function tempDouble(a) {
+ a = +a;
+ var x = +0, y = +0;
+ // CastAway can leave things like this as variables no longer needed. We need to identify that x's value has no side effects so it can be completely cleaned up
+ x = (HEAP32[((tempDoublePtr)>>2)]=((HEAP32[(($_sroa_0_0__idx1)>>2)])|0),HEAP32[(((tempDoublePtr)+(4))>>2)]=((HEAP32[((($_sroa_0_0__idx1)+(4))>>2)])|0),(+(HEAPF64[(tempDoublePtr)>>3])));
+ y = a*a;
+ f(y);
+}
+// EMSCRIPTEN_GENERATED_FUNCTIONS: ["asm", "__Z11printResultPiS_j", "_segment_holding", "__ZN5identC2EiPKcPci", "_vec2Length", "exc", "label", "confuusion", "tempDouble"]
diff --git a/tools/js-optimizer.js b/tools/js-optimizer.js
index b82d23d3..56ff971c 100644
--- a/tools/js-optimizer.js
+++ b/tools/js-optimizer.js
@@ -1392,7 +1392,12 @@ function normalizeAsm(func) {
var name = v[0];
var value = v[1];
if (!(name in data.vars)) {
- data.vars[name] = detectAsmCoercion(value);
+ if (value[0] != 'name') {
+ data.vars[name] = detectAsmCoercion(value); // detect by coercion
+ } else {
+ var origin = value[1];
+ data.vars[name] = data.vars[origin] || ASM_INT; // detect by origin variable, or assume int for non-locals
+ }
}
}
unVarify(node[1], node);
@@ -1837,13 +1842,22 @@ function eliminate(ast, memSafe) {
potentials[name] = 1;
} else if (uses[name] == 0 && (!definitions[name] || definitions[name] <= 1)) { // no uses, no def or 1 def (cannot operate on phis, and the llvm optimizer will remove unneeded phis anyhow)
var hasSideEffects = false;
- if (values[name]) {
- traverse(values[name], function(node, type) {
- if (!(type in NODES_WITHOUT_ELIMINATION_SIDE_EFFECTS)) {
- hasSideEffects = true; // cannot remove this unused variable, constructing it has side effects
- return true;
- }
- });
+ var value = values[name];
+ if (value) {
+ // TODO: merge with other side effect code
+ // First, pattern-match
+ // (HEAP32[((tempDoublePtr)>>2)]=((HEAP32[(($_sroa_0_0__idx1)>>2)])|0),HEAP32[(((tempDoublePtr)+(4))>>2)]=((HEAP32[((($_sroa_0_0__idx1)+(4))>>2)])|0),(+(HEAPF64[(tempDoublePtr)>>3])))
+ // which has no side effects and is the special form of converting double to i64.
+ if (!(value[0] == 'seq' && value[1][0] == 'assign' && value[1][2][0] == 'sub' && value[1][2][2][0] == 'binary' && value[1][2][2][1] == '>>' &&
+ value[1][2][2][2][0] == 'name' && value[1][2][2][2][1] == 'tempDoublePtr')) {
+ // If not that, then traverse and scan normally.
+ traverse(value, function(node, type) {
+ if (!(type in NODES_WITHOUT_ELIMINATION_SIDE_EFFECTS)) {
+ hasSideEffects = true; // cannot remove this unused variable, constructing it has side effects
+ return true;
+ }
+ });
+ }
}
if (!hasSideEffects) {
varsToRemove[name] = !definitions[name] ? 2 : 1; // remove it normally
diff --git a/tools/shared.py b/tools/shared.py
index 2bd219a9..cc056074 100644
--- a/tools/shared.py
+++ b/tools/shared.py
@@ -295,7 +295,7 @@ def check_node_version():
# we re-check sanity when the settings are changed)
# We also re-check sanity and clear the cache when the version changes
-EMSCRIPTEN_VERSION = '1.4.2'
+EMSCRIPTEN_VERSION = '1.4.3'
def generate_sanity():
return EMSCRIPTEN_VERSION + '|' + get_llvm_target()
@@ -495,7 +495,7 @@ except:
# Target choice. Must be synced with src/settings.js (TARGET_*)
def get_llvm_target():
- return os.environ.get('EMCC_LLVM_TARGET') or 'i386-pc-linux-gnu' # 'le32-unknown-nacl'
+ return os.environ.get('EMCC_LLVM_TARGET') or 'le32-unknown-nacl' # 'i386-pc-linux-gnu'
LLVM_TARGET = get_llvm_target()
try:
@@ -509,6 +509,9 @@ COMPILER_OPTS = COMPILER_OPTS + ['-m32', '-U__i386__', '-U__i386', '-Ui386',
'-D__IEEE_LITTLE_ENDIAN', '-fno-math-errno', '-fno-threadsafe-statics',
'-target', LLVM_TARGET]
+if LLVM_TARGET == 'le32-unknown-nacl':
+ COMPILER_OPTS += ['-U__native_client__', '-U__pnacl__', '-U__ELF__'] # The nacl target is originally used for Google Native Client. Emscripten is not NaCl, so remove the platform #define, when using their triple.
+
USE_EMSDK = not os.environ.get('EMMAKEN_NO_SDK')
if USE_EMSDK:
@@ -675,6 +678,7 @@ class Settings:
Settings.RELOOP = 1
if opt_level >= 3:
# Aside from these, -O3 also runs closure compiler and llvm lto
+ Settings.FORCE_ALIGNED_MEMORY = 1
Settings.DOUBLE_MODE = 0
Settings.PRECISE_I64_MATH = 0
if noisy: logging.warning('Applying some potentially unsafe optimizations! (Use -O2 if this fails.)')