aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2011-09-24 12:05:20 -0700
committerAlon Zakai <alonzakai@gmail.com>2011-09-24 12:05:20 -0700
commitec318d92f2c5f645eab561efc461941405071131 (patch)
treead3166665aa670036544b7715077625c00d1d00e
parent8643df88d3b7484156caa9ab9378affbfeb895dc (diff)
improve option to disable exception catching; fixes ammo speed regression
-rw-r--r--src/intertyper.js22
-rw-r--r--src/jsifier.js1
-rw-r--r--src/settings.js27
-rw-r--r--tests/runner.py14
4 files changed, 34 insertions, 30 deletions
diff --git a/src/intertyper.js b/src/intertyper.js
index 280b8a3f..d431d54f 100644
--- a/src/intertyper.js
+++ b/src/intertyper.js
@@ -611,7 +611,6 @@ function intertyper(data, parseFunctions, baseLineNum) {
if (['tail'].indexOf(item.tokens[0].text) != -1) {
item.tokens.splice(0, 1);
}
- assertEq(item.tokens[0].text, type);
while (item.tokens[1].text in LLVM.PARAM_ATTR || item.tokens[1].text in LLVM.CALLING_CONVENTIONS) {
item.tokens.splice(1, 1);
}
@@ -652,19 +651,30 @@ function intertyper(data, parseFunctions, baseLineNum) {
if (item.indent == 2) {
// standalone call - not in assign
item.standalone = true;
- return [item];
+ return { forward: null, ret: [item], item: item };
}
- this.forwardItem(item, 'Reintegrator');
- return null;
+ return { forward: item, ret: [], item: item };
}
substrate.addActor('Call', {
processItem: function(item) {
- return makeCall.call(this, item, 'call');
+ var result = makeCall.call(this, item, 'call');
+ if (result.forward) this.forwardItem(result.forward, 'Reintegrator');
+ return result.ret;
}
});
substrate.addActor('Invoke', {
processItem: function(item) {
- return makeCall.call(this, item, 'invoke');
+ var result = makeCall.call(this, item, 'invoke');
+ if (DISABLE_EXCEPTION_CATCHING) {
+ result.item.intertype = 'call';
+ result.ret.push({
+ intertype: 'branch',
+ label: result.item.toLabel,
+ lineNum: (result.forward ? item.parentLineNum : item.lineNum) + 0.5
+ });
+ }
+ if (result.forward) this.forwardItem(result.forward, 'Reintegrator');
+ return result.ret;
}
});
// 'landingpad' - just a stub implementation
diff --git a/src/jsifier.js b/src/jsifier.js
index da8c4db7..493a6ecb 100644
--- a/src/jsifier.js
+++ b/src/jsifier.js
@@ -756,7 +756,6 @@ function JSify(data, functionsOnly, givenFunctions, givenGlobalVariables) {
// in an assignment
var call_ = makeFunctionCall(item.ident, item.params, item.funcData);
var branch = makeBranch(item.toLabel, item.currLabelId);
- if (DISABLE_EXCEPTIONS) return call_ + '; ' + branch;
var ret = '(function() { try { __THREW__ = false; return '
+ call_ + ' '
+ '} catch(e) { '
diff --git a/src/settings.js b/src/settings.js
index ef8b3999..ed4fcd05 100644
--- a/src/settings.js
+++ b/src/settings.js
@@ -3,15 +3,10 @@ QUANTUM_SIZE = 4; // This is the size of an individual field in a structure. 1 w
// lead to e.g. doubles and chars both taking 1 memory address. This
// is a form of 'compressed' memory, with shrinking and stretching
// according to the type, when compared to C/C++. On the other hand
- // 8 means all fields take 8 memory addresses, so a double takes
- // the same as a char. Note that we only actually store something in
- // the top address - the others are just empty, an 'alignment cost'
- // of sorts.
+ // the normal value of 4 means all fields take 4 memory addresses,
+ // as per the norm on a 32-bit machine.
//
- // 1 is somewhat faster, but dangerous.
- //
- // TODO: Cleverly analyze malloc, memset, memcpy etc. operations in
- // llvm, and replace with the proper values for us
+ // 1 is somewhat faster than 4, but dangerous.
CORRECT_SIGNS = 1; // Whether we make sure to convert unsigned values to signed values.
// Decreases performance with additional runtime checks. Might not be
@@ -70,14 +65,14 @@ SAFE_HEAP_LOG = 0; // Log out all SAFE_HEAP operations
LABEL_DEBUG = 0; // Print out labels and functions as we enter them
EXCEPTION_DEBUG = 1; // Print out exceptions in emscriptened code
LIBRARY_DEBUG = 0; // Print out when we enter a library call (library*.js)
-DISABLE_EXCEPTIONS = 0; // Disables generating code to actually catch exceptions. If the code you
- // are compiling does not actually rely on catching exceptions (but the
- // compiler generates code for it, maybe because of stdlibc++ stuff),
- // then this can make it much faster. If an exception actually happens,
- // it will not be caught and the program will halt (so this will not
- // introduce silent failures, which is good).
- // TODO: Make this also remove cxa_begin_catch etc., optimize relooper
- // for it, etc. (perhaps do all of this as preprocessing on .ll?)
+DISABLE_EXCEPTION_CATCHING = 0; // Disables generating code to actually catch exceptions. If the code you
+ // are compiling does not actually rely on catching exceptions (but the
+ // compiler generates code for it, maybe because of stdlibc++ stuff),
+ // then this can make it much faster. If an exception actually happens,
+ // it will not be caught and the program will halt (so this will not
+ // introduce silent failures, which is good).
+ // TODO: Make this also remove cxa_begin_catch etc., optimize relooper
+ // for it, etc. (perhaps do all of this as preprocessing on .ll?)
EXECUTION_TIMEOUT = -1; // Throw an exception after X seconds - useful to debug infinite loops
CHECK_OVERFLOWS = 0; // Add code that checks for overflows in integer math operations.
// There is currently not much to do to handle overflows if they occur.
diff --git a/tests/runner.py b/tests/runner.py
index 11f3c804..5674a160 100644
--- a/tests/runner.py
+++ b/tests/runner.py
@@ -180,7 +180,7 @@ class RunnerCore(unittest.TestCase):
def do_emscripten(self, filename, output_processor=None, append_ext=True, extra_args=[]):
# Run Emscripten
exported_settings = {}
- for setting in ['QUANTUM_SIZE', 'RELOOP', 'OPTIMIZE', 'ASSERTIONS', 'USE_TYPED_ARRAYS', 'SAFE_HEAP', 'CHECK_OVERFLOWS', 'CORRECT_OVERFLOWS', 'CORRECT_SIGNS', 'CHECK_SIGNS', 'CORRECT_OVERFLOWS_LINES', 'CORRECT_SIGNS_LINES', 'CORRECT_ROUNDINGS', 'CORRECT_ROUNDINGS_LINES', 'INVOKE_RUN', 'SAFE_HEAP_LINES', 'INIT_STACK', 'AUTO_OPTIMIZE', 'EXPORTED_FUNCTIONS', 'EXPORTED_GLOBALS', 'BUILD_AS_SHARED_LIB', 'INCLUDE_FULL_LIBRARY', 'RUNTIME_TYPE_INFO', 'DISABLE_EXCEPTIONS', 'FAST_MEMORY', 'EXCEPTION_DEBUG', 'PROFILE']:
+ for setting in ['QUANTUM_SIZE', 'RELOOP', 'OPTIMIZE', 'ASSERTIONS', 'USE_TYPED_ARRAYS', 'SAFE_HEAP', 'CHECK_OVERFLOWS', 'CORRECT_OVERFLOWS', 'CORRECT_SIGNS', 'CHECK_SIGNS', 'CORRECT_OVERFLOWS_LINES', 'CORRECT_SIGNS_LINES', 'CORRECT_ROUNDINGS', 'CORRECT_ROUNDINGS_LINES', 'INVOKE_RUN', 'SAFE_HEAP_LINES', 'INIT_STACK', 'AUTO_OPTIMIZE', 'EXPORTED_FUNCTIONS', 'EXPORTED_GLOBALS', 'BUILD_AS_SHARED_LIB', 'INCLUDE_FULL_LIBRARY', 'RUNTIME_TYPE_INFO', 'DISABLE_EXCEPTION_CATCHING', 'FAST_MEMORY', 'EXCEPTION_DEBUG', 'PROFILE']:
try:
value = eval(setting)
exported_settings[setting] = value
@@ -990,8 +990,8 @@ if 'benchmark' not in str(sys.argv):
'''
self.do_test(src, '*throw...caught!infunc...done!*')
- global DISABLE_EXCEPTIONS
- DISABLE_EXCEPTIONS = 1
+ global DISABLE_EXCEPTION_CATCHING
+ DISABLE_EXCEPTION_CATCHING = 1
self.do_test(src, 'Compiled code throwing an exception')
def test_typed_exceptions(self):
@@ -3147,7 +3147,7 @@ if 'benchmark' not in str(sys.argv):
global CORRECT_OVERFLOWS; CORRECT_OVERFLOWS = 0
global CORRECT_ROUNDINGS; CORRECT_ROUNDINGS = 0
global SAFE_HEAP; SAFE_HEAP = 0 # uses time.h to set random bytes, other stuff
- global DISABLE_EXCEPTIONS; DISABLE_EXCEPTIONS = 1
+ global DISABLE_EXCEPTION_CATCHING; DISABLE_EXCEPTION_CATCHING = 1
global FAST_MEMORY; FAST_MEMORY = 4*1024*1024
global INVOKE_RUN; INVOKE_RUN = 0 # We append code that does run() ourselves
@@ -4141,7 +4141,7 @@ Child2:9
exec('''
class %s(T):
def setUp(self):
- global COMPILER, QUANTUM_SIZE, RELOOP, OPTIMIZE, ASSERTIONS, USE_TYPED_ARRAYS, LLVM_OPTS, SAFE_HEAP, CHECK_OVERFLOWS, CORRECT_OVERFLOWS, CORRECT_OVERFLOWS_LINES, CORRECT_SIGNS, CORRECT_SIGNS_LINES, CHECK_SIGNS, COMPILER_TEST_OPTS, CORRECT_ROUNDINGS, CORRECT_ROUNDINGS_LINES, INVOKE_RUN, SAFE_HEAP_LINES, INIT_STACK, AUTO_OPTIMIZE, RUNTIME_TYPE_INFO, DISABLE_EXCEPTIONS, PROFILE
+ global COMPILER, QUANTUM_SIZE, RELOOP, OPTIMIZE, ASSERTIONS, USE_TYPED_ARRAYS, LLVM_OPTS, SAFE_HEAP, CHECK_OVERFLOWS, CORRECT_OVERFLOWS, CORRECT_OVERFLOWS_LINES, CORRECT_SIGNS, CORRECT_SIGNS_LINES, CHECK_SIGNS, COMPILER_TEST_OPTS, CORRECT_ROUNDINGS, CORRECT_ROUNDINGS_LINES, INVOKE_RUN, SAFE_HEAP_LINES, INIT_STACK, AUTO_OPTIMIZE, RUNTIME_TYPE_INFO, DISABLE_EXCEPTION_CATCHING, PROFILE
COMPILER = '%s'
llvm_opts = %d
@@ -4164,7 +4164,7 @@ class %s(T):
CHECK_SIGNS = 0 #1-(embetter or llvm_opts)
INIT_STACK = 0
RUNTIME_TYPE_INFO = 0
- DISABLE_EXCEPTIONS = 0
+ DISABLE_EXCEPTION_CATCHING = 0
PROFILE = 0
if LLVM_OPTS:
self.pick_llvm_opts(3, True)
@@ -4233,7 +4233,7 @@ else:
CORRECT_ROUNDINGS = 0
CORRECT_OVERFLOWS_LINES = CORRECT_SIGNS_LINES = CORRECT_ROUNDINGS_LINES = SAFE_HEAP_LINES = []
LLVM_OPTS = 1
- DISABLE_EXCEPTIONS = 1
+ DISABLE_EXCEPTION_CATCHING = 1
FAST_MEMORY = 10*1024*1024
TEST_REPS = 4