switch to all or nothing named globals, and add testing
This commit is contained in:
Родитель
9d20f0799c
Коммит
6782b5e97f
|
@ -507,7 +507,7 @@ function intertyper(data, sidePass, baseLineNums) {
|
||||||
private_: private_,
|
private_: private_,
|
||||||
lineNum: item.lineNum
|
lineNum: item.lineNum
|
||||||
};
|
};
|
||||||
if (NUM_NAMED_GLOBALS >= 0) {
|
if (!NAMED_GLOBALS) {
|
||||||
Variables.globals[ret.ident].type = ret.type;
|
Variables.globals[ret.ident].type = ret.type;
|
||||||
}
|
}
|
||||||
Types.needAnalysis[ret.type] = 0;
|
Types.needAnalysis[ret.type] = 0;
|
||||||
|
|
|
@ -250,7 +250,7 @@ function JSify(data, functionsOnly, givenFunctions) {
|
||||||
processItem: function(item) {
|
processItem: function(item) {
|
||||||
function needsPostSet(value) {
|
function needsPostSet(value) {
|
||||||
return value[0] in UNDERSCORE_OPENPARENS || value.substr(0, 14) === 'CHECK_OVERFLOW'
|
return value[0] in UNDERSCORE_OPENPARENS || value.substr(0, 14) === 'CHECK_OVERFLOW'
|
||||||
|| false; // TODO: interact with output of makeGlobalUse/makeGlobalDef
|
|| value.substr(0, 6) === 'GLOBAL';
|
||||||
}
|
}
|
||||||
|
|
||||||
item.intertype = 'GlobalVariableStub';
|
item.intertype = 'GlobalVariableStub';
|
||||||
|
@ -265,16 +265,9 @@ function JSify(data, functionsOnly, givenFunctions) {
|
||||||
var constant = null;
|
var constant = null;
|
||||||
var allocator = (BUILD_AS_SHARED_LIB && !item.external) ? 'ALLOC_NORMAL' : 'ALLOC_STATIC';
|
var allocator = (BUILD_AS_SHARED_LIB && !item.external) ? 'ALLOC_NORMAL' : 'ALLOC_STATIC';
|
||||||
var index = null;
|
var index = null;
|
||||||
if (NUM_NAMED_GLOBALS >= 0) {
|
if (!NAMED_GLOBALS) {
|
||||||
if (Variables.seenGlobals < NUM_NAMED_GLOBALS) {
|
index = makeGlobalUse(item.ident);
|
||||||
Variables.seenGlobals++; // named
|
allocator = 'ALLOC_NONE';
|
||||||
} else {
|
|
||||||
// indexed
|
|
||||||
Variables.indexedGlobals[item.ident] = Variables.nextIndexedOffset;
|
|
||||||
index = makeGlobalUse(item.ident);
|
|
||||||
Variables.nextIndexedOffset += Runtime.alignMemory(calcAllocatedSize(Variables.globals[item.ident].type));
|
|
||||||
allocator = 'ALLOC_NONE';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (item.external && BUILD_AS_SHARED_LIB) {
|
if (item.external && BUILD_AS_SHARED_LIB) {
|
||||||
// External variables in shared libraries should not be declared as
|
// External variables in shared libraries should not be declared as
|
||||||
|
|
|
@ -178,7 +178,6 @@ var Variables = {
|
||||||
indexedGlobals: {}, // for indexed globals, ident ==> index
|
indexedGlobals: {}, // for indexed globals, ident ==> index
|
||||||
// Used in calculation of indexed globals
|
// Used in calculation of indexed globals
|
||||||
nextIndexedOffset: 0,
|
nextIndexedOffset: 0,
|
||||||
seenGlobals: 0,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
var Types = {
|
var Types = {
|
||||||
|
|
|
@ -357,12 +357,18 @@ function hasVarArgs(params) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function makeGlobalDef(ident) {
|
function makeGlobalDef(ident) {
|
||||||
if (ident in Variables.indexedGlobals) return '';
|
if (!NAMED_GLOBALS) return '';
|
||||||
return 'var ' + ident + ';'; // TODO: add option for namespacing or offsetting to allow reducing the number of globals
|
return 'var ' + ident + ';'; // TODO: add option for namespacing or offsetting to allow reducing the number of globals
|
||||||
}
|
}
|
||||||
|
|
||||||
function makeGlobalUse(ident) {
|
function makeGlobalUse(ident) {
|
||||||
if (ident in Variables.indexedGlobals) return getFastValue('GLOBAL_BASE', '+', Variables.indexedGlobals[ident]);
|
if (!NAMED_GLOBALS) {
|
||||||
|
if (!(ident in Variables.indexedGlobals)) {
|
||||||
|
Variables.indexedGlobals[ident] = Variables.nextIndexedOffset;
|
||||||
|
Variables.nextIndexedOffset += Runtime.alignMemory(calcAllocatedSize(Variables.globals[ident].type));
|
||||||
|
}
|
||||||
|
return getFastValue('GLOBAL_BASE', '+', Variables.indexedGlobals[ident]);
|
||||||
|
}
|
||||||
return ident; // TODO: add option for namespacing or offsetting to allow reducing the number of globals
|
return ident; // TODO: add option for namespacing or offsetting to allow reducing the number of globals
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -194,10 +194,9 @@ var PGO = 0; // Profile-guided optimization.
|
||||||
// All CORRECT_* options default to 1 with PGO builds.
|
// All CORRECT_* options default to 1 with PGO builds.
|
||||||
// See https://github.com/kripken/emscripten/wiki/Optimizing-Code for more info
|
// See https://github.com/kripken/emscripten/wiki/Optimizing-Code for more info
|
||||||
|
|
||||||
var NUM_NAMED_GLOBALS = -1; // If >= 0, the number of globals we allow to be named. Other globals
|
var NAMED_GLOBALS = 1; // If 1, we use global variables for globals. Otherwise
|
||||||
// are then referred to by a base plus an offset (called an indexed global),
|
// they are referred to by a base plus an offset (called an indexed global),
|
||||||
// saving global variables but adding runtime overhead. If -1, then we
|
// saving global variables but adding runtime overhead.
|
||||||
// allow all globals to be named.
|
|
||||||
|
|
||||||
var PROFILE = 0; // Enables runtime profiling. See test_profiling for a usage example.
|
var PROFILE = 0; // Enables runtime profiling. See test_profiling for a usage example.
|
||||||
|
|
||||||
|
|
|
@ -1645,9 +1645,9 @@ c5,de,15,8a
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
'''
|
'''
|
||||||
for named, expected in [(-1, 0), (0, 100), (1, 98), (5, 88), (1000, 0)]:
|
for named, expected in [(0, 100), (1, 0)]:
|
||||||
print named
|
print named
|
||||||
Settings.NUM_NAMED_GLOBALS = named
|
Settings.NAMED_GLOBALS = named
|
||||||
self.do_run(src, '4:10,177,543,def\n4\nwowie\ntoo\n76\n5\n(null)\n/* a comment */\n// another\ntest\n', ['wowie', 'too', '74'])
|
self.do_run(src, '4:10,177,543,def\n4\nwowie\ntoo\n76\n5\n(null)\n/* a comment */\n// another\ntest\n', ['wowie', 'too', '74'])
|
||||||
if self.emcc_args == []:
|
if self.emcc_args == []:
|
||||||
gen = open(self.in_dir('src.cpp.o.js')).read()
|
gen = open(self.in_dir('src.cpp.o.js')).read()
|
||||||
|
@ -5956,7 +5956,7 @@ void*:16
|
||||||
self.do_run(path_from_root('tests', 'cubescript'), '*\nTemp is 33\n9\n5\nhello, everyone\n*', main_file='command.cpp')
|
self.do_run(path_from_root('tests', 'cubescript'), '*\nTemp is 33\n9\n5\nhello, everyone\n*', main_file='command.cpp')
|
||||||
|
|
||||||
def test_gcc_unmangler(self):
|
def test_gcc_unmangler(self):
|
||||||
Settings.NUM_NAMED_GLOBALS = 0 # test coverage for this
|
Settings.NAMED_GLOBALS = 0 # test coverage for this
|
||||||
|
|
||||||
Building.COMPILER_TEST_OPTS = ['-I' + path_from_root('third_party')]
|
Building.COMPILER_TEST_OPTS = ['-I' + path_from_root('third_party')]
|
||||||
|
|
||||||
|
@ -7401,6 +7401,7 @@ class %s(T):
|
||||||
Settings.EMULATE_UNALIGNED_ACCESSES = int(Settings.USE_TYPED_ARRAYS == 2 and Building.LLVM_OPTS == 2)
|
Settings.EMULATE_UNALIGNED_ACCESSES = int(Settings.USE_TYPED_ARRAYS == 2 and Building.LLVM_OPTS == 2)
|
||||||
Settings.DOUBLE_MODE = 1 if Settings.USE_TYPED_ARRAYS and Building.LLVM_OPTS == 0 else 0
|
Settings.DOUBLE_MODE = 1 if Settings.USE_TYPED_ARRAYS and Building.LLVM_OPTS == 0 else 0
|
||||||
Settings.PRECISE_I64_MATH = 0
|
Settings.PRECISE_I64_MATH = 0
|
||||||
|
Settings.NAMED_GLOBALS = 0 if not (embetter and llvm_opts) else 1
|
||||||
|
|
||||||
Building.pick_llvm_opts(3)
|
Building.pick_llvm_opts(3)
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче