diff options
author | Alon Zakai <alonzakai@gmail.com> | 2013-09-27 13:15:17 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2013-09-27 13:15:17 -0700 |
commit | 2d45e5d75b9d7b475256415cc2c28225b89d6129 (patch) | |
tree | 4ffc4ff16a18f60242fc8a31177c0fa17e75dbd9 /src | |
parent | c2560b71f88d68ec6817f44729cd97517eda512d (diff) |
intertyper fast paths setup and proof of concept
Diffstat (limited to 'src')
-rw-r--r-- | src/compiler.js | 1 | ||||
-rw-r--r-- | src/intertyper.js | 55 | ||||
-rw-r--r-- | src/settings.js | 2 |
3 files changed, 52 insertions, 6 deletions
diff --git a/src/compiler.js b/src/compiler.js index 94197390..24136551 100644 --- a/src/compiler.js +++ b/src/compiler.js @@ -275,6 +275,7 @@ function compile(raw) { JSify(analyzed); //dumpInterProf(); + //printErr('Paths (fast, slow): ' + [fastPaths, slowPaths]); phase = null; diff --git a/src/intertyper.js b/src/intertyper.js index 525096f5..f452c955 100644 --- a/src/intertyper.js +++ b/src/intertyper.js @@ -3,6 +3,8 @@ // LLVM assembly => internal intermediate representation, which is ready // to be processed by the later stages. +var fastPaths = 0, slowPaths = 0; + // Line tokenizer function tokenizer(item, inner) { //assert(item.lineNum != 40000); @@ -373,6 +375,14 @@ function intertyper(lines, sidePass, baseLineNums) { // Line parsers to intermediate form // globals: type or variable + function noteGlobalVariable(ret) { + if (!NAMED_GLOBALS) { + Variables.globals[ret.ident].type = ret.type; + Variables.globals[ret.ident].external = ret.external; + } + Types.needAnalysis[ret.type] = 0; + } + function globalHandler(item) { function scanConst(value, type) { // Gets an array of constant items, separated by ',' tokens @@ -497,7 +507,6 @@ function intertyper(lines, sidePass, baseLineNums) { external = true; item.tokens.splice(2, 1); } - Types.needAnalysis[item.tokens[2].text] = 0; var ret = { intertype: 'globalVariable', ident: toNiceIdent(ident), @@ -507,11 +516,7 @@ function intertyper(lines, sidePass, baseLineNums) { named: named, lineNum: item.lineNum }; - if (!NAMED_GLOBALS) { - Variables.globals[ret.ident].type = ret.type; - Variables.globals[ret.ident].external = external; - } - Types.needAnalysis[ret.type] = 0; + noteGlobalVariable(ret); if (ident == '@llvm.global_ctors') { ret.ctors = []; if (item.tokens[3].item) { @@ -984,9 +989,47 @@ function intertyper(lines, sidePass, baseLineNums) { return ret; } + // Fast paths - quick parses of common patterns, avoid tokenizing entirely + + function tryFastPaths(line) { + var m, ret; + if (phase === 'pre') { + // string constant + if (0) { // works, but not worth it m = /([@\.\w\d_]+) = (private )?(unnamed_addr )?(constant )?(\[\d+ x i8\]) c"([^"]+)".*/.exec(line.lineText)) { + if (m[1] === '@llvm.global_ctors') return ret; + ret = { + intertype: 'globalVariable', + ident: toNiceIdent(m[1]), + type: m[5], + external: false, + private_: m[2] !== null, + named: m[3] === null, + lineNum: line.lineNum, + value: { + intertype: 'string', + text: m[6] + } + }; + noteGlobalVariable(ret); + } + } + if (ret) { + fastPaths++; + if (COMPILER_ASSERTIONS) { + //printErr(['\n', JSON.stringify(ret), '\n', JSON.stringify(triager(tokenizer(line)))]); + assert(JSON.stringify(ret) === JSON.stringify(triager(tokenizer(line))), 'fast path'); + } + finalResults.push(ret); + } + return ret; + } + // Input lineSplitter().forEach(function(line) { + if (tryFastPaths(line)) return; + slowPaths++; + //var time = Date.now(); var t = tokenizer(line); diff --git a/src/settings.js b/src/settings.js index 0daafa35..0a4765fd 100644 --- a/src/settings.js +++ b/src/settings.js @@ -426,6 +426,8 @@ var JS_CHUNK_SIZE = 10240; // Used as a maximum size before breaking up expressi var EXPORT_NAME = 'Module'; // Global variable to export the module as for environments without a standardized module // loading system (e.g. the browser and SM shell). +var COMPILER_ASSERTIONS = 0; // costly (slow) compile-time assertions + // Compiler debugging options var DEBUG_TAGS_SHOWING = []; // Some useful items: |