aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xemcc9
-rw-r--r--src/analyzer.js9
-rw-r--r--src/intertyper.js10
-rw-r--r--src/library.js4
-rw-r--r--src/modules.js2
-rw-r--r--src/parseTools.js48
-rw-r--r--system/include/xlocale.h8
-rw-r--r--tests/cases/phientryimplicitmix.ll30
-rwxr-xr-xtests/runner.py36
-rw-r--r--tools/shared.py7
10 files changed, 123 insertions, 40 deletions
diff --git a/emcc b/emcc
index d50b5a88..8a3e2bae 100755
--- a/emcc
+++ b/emcc
@@ -239,7 +239,8 @@ if EMMAKEN_CFLAGS: CC_ADDITIONAL_ARGS += EMMAKEN_CFLAGS.split(' ')
# ---------------- Utilities ---------------
SOURCE_SUFFIXES = ('.c', '.cpp', '.cxx', '.cc')
-BITCODE_SUFFIXES = ('.bc', '.o', '.ll')
+BITCODE_SUFFIXES = ('.bc', '.o', '.a', '.dylib')
+ASSEMBLY_SUFFIXES = ('.ll',)
def unsuffixed(name):
return '.'.join(name.split('.')[:-1])
@@ -376,7 +377,7 @@ try:
for i in range(len(newargs)): # find input files XXX this a simple heuristic. we should really analyze based on a full understanding of gcc params,
# right now we just assume that what is left contains no more |-x OPT| things
arg = newargs[i]
- if arg.endswith(SOURCE_SUFFIXES + BITCODE_SUFFIXES): # we already removed -o <target>, so all these should be inputs
+ if arg.endswith(SOURCE_SUFFIXES + BITCODE_SUFFIXES + ASSEMBLY_SUFFIXES): # we already removed -o <target>, so all these should be inputs
newargs[i] = ''
if os.path.exists(arg):
if arg.endswith(SOURCE_SUFFIXES):
@@ -384,7 +385,7 @@ try:
has_source_inputs = True
else:
# this should be bitcode, make sure it is valid
- if arg.endswith('.ll') or shared.Building.is_bitcode(arg):
+ if arg.endswith(ASSEMBLY_SUFFIXES) or shared.Building.is_bitcode(arg):
input_files.append(arg)
else:
print >> sys.stderr, 'emcc: %s: warning: Not valid LLVM bitcode' % arg
@@ -436,7 +437,7 @@ try:
print >> sys.stderr, 'emcc: compiler frontend failed to generate LLVM bitcode, halting'
sys.exit(1)
else: # bitcode
- if input_file.endswith(('.bc', '.o')):
+ if input_file.endswith(BITCODE_SUFFIXES):
if DEBUG: print >> sys.stderr, 'emcc: copying bitcode file: ', input_file
shutil.copyfile(input_file, in_temp(unsuffixed_basename(input_file) + '.o'))
else: #.ll
diff --git a/src/analyzer.js b/src/analyzer.js
index a4e7d52d..c5a8cea3 100644
--- a/src/analyzer.js
+++ b/src/analyzer.js
@@ -87,7 +87,7 @@ function analyzer(data, sidePass) {
} else if (item.functions.length > 0 && item.functions.slice(-1)[0].endLineNum === null) {
// Internal line
if (!currLabelFinished) {
- item.functions.slice(-1)[0].labels.slice(-1)[0].lines.push(subItem); // If this line fails, perhaps missing a label? LLVM_STYLE related?
+ item.functions.slice(-1)[0].labels.slice(-1)[0].lines.push(subItem); // If this line fails, perhaps missing a label?
if (subItem.intertype === 'branch') {
currLabelFinished = true;
}
@@ -1018,8 +1018,11 @@ function analyzer(data, sidePass) {
function getActualLabelId(labelId) {
var label = func.labelsDict[labelId];
if (!label) {
- assert(!unknownEntry, 'More than one unknown label in phi, so both cannot be an unlabelled entry, in ' + func.ident);
- unknownEntry = labelId;
+ if (!unknownEntry) {
+ unknownEntry = labelId;
+ } else {
+ assert(labelId == unknownEntry, 'More than one unknown label in phi, so both cannot be an unlabelled entry, in ' + func.ident);
+ }
labelId = ENTRY_IDENT;
label = func.labelsDict[labelId];
assert(label, 'Cannot find entry label when looking for it after seeing an unknown label in a phi');
diff --git a/src/intertyper.js b/src/intertyper.js
index d03810d4..341598fc 100644
--- a/src/intertyper.js
+++ b/src/intertyper.js
@@ -29,14 +29,6 @@ function intertyper(data, sidePass, baseLineNums) {
dprint('framework', 'Big picture: Starting intertyper, main pass=' + mainPass);
- if (mainPass) {
- if (LLVM_STYLE === null) {
- // new = clang on 2.8, old = llvm-gcc anywhere or clang on 2.7
- LLVM_STYLE = (data.indexOf('<label>') == -1 && data.indexOf('entry:') != -1) ? 'old' : 'new';
- //dprint('LLVM_STYLE: ' + LLVM_STYLE);
- }
- }
-
// Substrate
var substrate = new Substrate('Intertyper');
@@ -347,7 +339,7 @@ function intertyper(data, sidePass, baseLineNums) {
if (tokensLength >= 3 && token0Text == 'landingpad')
return 'Landingpad';
} else if (item.indent === 0) {
- if ((tokensLength >= 1 && token0Text.substr(-1) == ':') || // LLVM 2.7 format, or llvm-gcc in 2.8
+ if ((tokensLength >= 1 && token0Text.substr(-1) == ':') ||
(tokensLength >= 3 && token1Text == '<label>'))
return 'Label';
if (tokensLength >= 4 && token0Text == 'declare')
diff --git a/src/library.js b/src/library.js
index 6f1f2fe5..83a62273 100644
--- a/src/library.js
+++ b/src/library.js
@@ -3485,18 +3485,22 @@ LibraryManager.library = {
strtoll: function(str, endptr, base) {
return __parseInt(str, endptr, base, -9223372036854775200, 9223372036854775200, 64); // LLONG_MIN, LLONG_MAX; imprecise.
},
+ strtoll_l: 'strtoll', // no locale support yet
strtol__deps: ['_parseInt'],
strtol: function(str, endptr, base) {
return __parseInt(str, endptr, base, -2147483648, 2147483647, 32); // LONG_MIN, LONG_MAX.
},
+ strtol_l: 'strtol', // no locale support yet
strtoul__deps: ['_parseInt'],
strtoul: function(str, endptr, base) {
return __parseInt(str, endptr, base, 0, 4294967295, 32, true); // ULONG_MAX.
},
+ strtoul_l: 'strtoul', // no locale support yet
strtoull__deps: ['_parseInt'],
strtoull: function(str, endptr, base) {
return __parseInt(str, endptr, base, 0, 18446744073709551615, 64, true); // ULONG_MAX; imprecise.
},
+ strtoull_l: 'strtoull', // no locale support yet
atof: function(ptr) {
var str = Pointer_stringify(ptr);
diff --git a/src/modules.js b/src/modules.js
index cfc29014..52f14c2f 100644
--- a/src/modules.js
+++ b/src/modules.js
@@ -2,8 +2,6 @@
// Various namespace-like modules
-var LLVM_STYLE = null;
-
var LLVM = {
LINKAGES: set('private', 'linker_private', 'linker_private_weak', 'linker_private_weak_def_auto', 'internal',
'available_externally', 'linkonce', 'common', 'weak', 'appending', 'extern_weak', 'linkonce_odr',
diff --git a/src/parseTools.js b/src/parseTools.js
index f1413c1c..b68365a1 100644
--- a/src/parseTools.js
+++ b/src/parseTools.js
@@ -926,14 +926,17 @@ function makeGetValue(ptr, pos, type, noNeedFirst, unsigned, ignore, align, noSa
if (bytes > align) {
var ret = '(';
if (isIntImplemented(type)) {
- if (bytes <= 4) {
+ if (bytes == 4 && align == 2) {
+ // Special case that we can optimize
+ ret += makeGetValue(ptr, pos, 'i16', noNeedFirst, 2, ignore) + '+' +
+ '(' + makeGetValue(ptr, getFastValue(pos, '+', 2), 'i16', noNeedFirst, 2, ignore) + '<<16)';
+ } else if (bytes <= 4) {
+ ret = '';
for (var i = 0; i < bytes; i++) {
- ret += 'tempInt' + (i == 0 ? '=' : '|=((');
- ret += makeGetValue(ptr, getFastValue(pos, '+', i), 'i8', noNeedFirst, 1, ignore);
- if (i > 0) ret += ')<<' + (8*i) + ')';
- ret += ',';
+ ret += '(' + makeGetValue(ptr, getFastValue(pos, '+', i), 'i8', noNeedFirst, 1, ignore) + (i > 0 ? '<<' + (8*i) : '') + ')';
+ if (i < bytes-1) ret += '|';
}
- ret += makeSignOp('tempInt', type, unsigned ? 'un' : 're', true);
+ ret = '(' + makeSignOp(ret, type, unsigned ? 'un' : 're', true);
} else {
assert(bytes == 8);
ret += 'tempBigInt=' + makeGetValue(ptr, pos, 'i32', noNeedFirst, true, ignore, align) + ',';
@@ -1018,10 +1021,15 @@ function makeSetValue(ptr, pos, value, type, noNeedFirst, ignore, align, noSafe,
if (bytes > align) {
var ret = '';
if (isIntImplemented(type)) {
- if (bytes <= 4) {
+ if (bytes == 4 && align == 2) {
+ // Special case that we can optimize
+ ret += 'tempBigInt=' + value + sep;
+ ret += makeSetValue(ptr, pos, 'tempBigInt&0xffff', 'i16', noNeedFirst, ignore, 2) + sep;
+ ret += makeSetValue(ptr, getFastValue(pos, '+', 2), 'tempBigInt>>16', 'i16', noNeedFirst, ignore, 2) + sep;
+ } else if (bytes <= 4) {
ret += 'tempBigInt=' + value + sep;
for (var i = 0; i < bytes; i++) {
- ret += makeSetValue(ptr, getFastValue(pos, '+', i), 'tempBigInt&0xff', 'i8', noNeedFirst, ignore) + sep;
+ ret += makeSetValue(ptr, getFastValue(pos, '+', i), 'tempBigInt&0xff', 'i8', noNeedFirst, ignore, 1) + sep;
if (i < bytes-1) ret += 'tempBigInt>>=8' + sep;
}
} else {
@@ -1661,14 +1669,22 @@ function processMathop(item) {
case 'fptoui': case 'fptosi': return splitI64(ident1);
case 'icmp': {
switch (variant) {
- case 'uge': case 'sge': return ident1 + '[1] >= ' + ident2 + '[1] && (' + ident1 + '[1] > ' + ident2 + '[1] || ' +
- ident1 + '[0] >= ' + ident2 + '[0])';
- case 'ule': case 'sle': return ident1 + '[1] <= ' + ident2 + '[1] && (' + ident1 + '[1] < ' + ident2 + '[1] || ' +
- ident1 + '[0] <= ' + ident2 + '[0])';
- case 'ugt': case 'sgt': return ident1 + '[1] > ' + ident2 + '[1] || (' + ident1 + '[1] == ' + ident2 + '[1] && ' +
- ident1 + '[0] > ' + ident2 + '[0])';
- case 'ult': case 'slt': return ident1 + '[1] < ' + ident2 + '[1] || (' + ident1 + '[1] == ' + ident2 + '[1] && ' +
- ident1 + '[0] < ' + ident2 + '[0])';
+ case 'uge': return ident1 + '[1] >= ' + ident2 + '[1] && (' + ident1 + '[1] > ' + ident2 + '[1] || ' +
+ ident1 + '[0] >= ' + ident2 + '[0])';
+ case 'sge': return '(' + ident1 + '[1]|0) >= (' + ident2 + '[1]|0) && ((' + ident1 + '[1]|0) > (' + ident2 + '[1]|0) || ' +
+ '(' + ident1 + '[0]|0) >= (' + ident2 + '[0]|0))';
+ case 'ule': return ident1 + '[1] <= ' + ident2 + '[1] && (' + ident1 + '[1] < ' + ident2 + '[1] || ' +
+ ident1 + '[0] <= ' + ident2 + '[0])';
+ case 'sle': return '(' + ident1 + '[1]|0) <= (' + ident2 + '[1]|0) && ((' + ident1 + '[1]|0) < (' + ident2 + '[1]|0) || ' +
+ '(' + ident1 + '[0]|0) <= (' + ident2 + '[0]|0))';
+ case 'ugt': return ident1 + '[1] > ' + ident2 + '[1] || (' + ident1 + '[1] == ' + ident2 + '[1] && ' +
+ ident1 + '[0] > ' + ident2 + '[0])';
+ case 'sgt': return '(' + ident1 + '[1]|0) > (' + ident2 + '[1]|0) || ((' + ident1 + '[1]|0) == (' + ident2 + '[1]|0) && ' +
+ '(' + ident1 + '[0]|0) > (' + ident2 + '[0]|0))';
+ case 'ult': return ident1 + '[1] < ' + ident2 + '[1] || (' + ident1 + '[1] == ' + ident2 + '[1] && ' +
+ ident1 + '[0] < ' + ident2 + '[0])';
+ case 'slt': return '(' + ident1 + '[1]|0) < (' + ident2 + '[1]|0) || ((' + ident1 + '[1]|0) == (' + ident2 + '[1]|0) && ' +
+ '(' + ident1 + '[0]|0) < (' + ident2 + '[0]|0))';
case 'ne': case 'eq': {
// We must sign them, so we do not compare -1 to 255 (could have unsigned them both too)
// since LLVM tells us if <=, >= etc. comparisons are signed, but not == and !=.
diff --git a/system/include/xlocale.h b/system/include/xlocale.h
index 1162f9b0..bb3b50e5 100644
--- a/system/include/xlocale.h
+++ b/system/include/xlocale.h
@@ -5,6 +5,10 @@
#include <string.h>
#include <locale.h>
+#ifdef __cplusplus
+extern "C" {
+#endif
+
long long strtoll_l(const char *start, char **end, int base, locale_t loc);
unsigned long long strtoull_l(const char *start, char **end, int base, locale_t loc);
double strtold_l(const char *start, char **end, locale_t loc);
@@ -35,5 +39,9 @@ int towlower_l(wint_t wc, locale_t locale);
size_t strftime_l(char *s, size_t maxsize, const char *format, const struct tm *timeptr, locale_t locale);
+#ifdef __cplusplus
+}
+#endif
+
#endif /* _LOCALE_H_ */
diff --git a/tests/cases/phientryimplicitmix.ll b/tests/cases/phientryimplicitmix.ll
new file mode 100644
index 00000000..9223c059
--- /dev/null
+++ b/tests/cases/phientryimplicitmix.ll
@@ -0,0 +1,30 @@
+; ModuleID = 'tests/hello_world.bc'
+target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32-n8:16:32-S128"
+target triple = "i386-pc-linux-gnu"
+
+; Phi nodes can refer to the entry. And the entry might be unnamed, and doesn't even have a consistent implicit name!
+
+@.str = private unnamed_addr constant [15 x i8] c"hello, world!\0A\00", align 1 ; [#uses=1 type=[15 x i8]*]
+
+; [#uses=0]
+define i32 @main() {
+ %retval = alloca i32, align 4 ; [#uses=1 type=i32*]
+ %16 = trunc i32 1 to i1
+ br i1 %16, label %whoosh, label %26, !dbg !1269853 ; [debug line = 3920:5]
+
+whoosh: ; preds = %1
+ %25 = trunc i32 1 to i1
+ br label %26
+
+; <label>:26 ; preds = %17, %1
+ %27 = phi i1 [ false, %1 ], [ %25, %whoosh ] ; [#uses=1 type=i1]
+ %28 = phi i1 [ true, %1 ], [ %25, %whoosh ] ; [#uses=1 type=i1]
+ store i32 0, i32* %retval
+ %call = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([15 x i8]* @.str, i32 0, i32 0)) ; [#uses=0 type=i32]
+ %cal2 = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([15 x i8]* @.str, i32 0, i32 0), i32 %27) ; make sure %27 is used
+ %cal3 = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([15 x i8]* @.str, i32 0, i32 0), i32 %28) ; make sure %28 is used
+ ret i32 1
+}
+
+; [#uses=1]
+declare i32 @printf(i8*, ...)
diff --git a/tests/runner.py b/tests/runner.py
index 93511589..4fd7ddfc 100755
--- a/tests/runner.py
+++ b/tests/runner.py
@@ -583,6 +583,37 @@ if 'benchmark' not in str(sys.argv) and 'sanity' not in str(sys.argv):
'*-1,34359738367,4294967295,1073741823*\n' +
'*prod:34*')
+ src = r'''
+ #include <stdio.h>
+ #include <limits>
+
+ int main()
+ {
+ long long i,j,k;
+
+ i = 0;
+ j = -1,
+ k = 1;
+
+ printf( "*\n" );
+ printf( "%s\n", i > j ? "Ok": "Fail" );
+ printf( "%s\n", k > i ? "Ok": "Fail" );
+ printf( "%s\n", k > j ? "Ok": "Fail" );
+ printf( "%s\n", i < j ? "Fail": "Ok" );
+ printf( "%s\n", k < i ? "Fail": "Ok" );
+ printf( "%s\n", k < j ? "Fail": "Ok" );
+ printf( "%s\n", (i-j) >= k ? "Ok": "Fail" );
+ printf( "%s\n", (i-j) <= k ? "Ok": "Fail" );
+ printf( "%s\n", i > std::numeric_limits<long long>::min() ? "Ok": "Fail" );
+ printf( "%s\n", i < std::numeric_limits<long long>::max() ? "Ok": "Fail" );
+ printf( "*\n" );
+ }
+ '''
+
+ self.do_run(src, '*\nOk\nOk\nOk\nOk\nOk\nOk\nOk\nOk\nOk\nOk\n*')
+
+ # stuff that also needs sign corrections
+
Settings.CORRECT_SIGNS = 1
src = r'''
@@ -4370,9 +4401,6 @@ def process(filename):
poppler = self.get_library('poppler',
[os.path.join('poppler', '.libs', self.get_shared_library_name('libpoppler.so.13')),
- os.path.join('goo', '.libs', 'libgoo.a'),
- os.path.join('fofi', '.libs', 'libfofi.a'),
- os.path.join('splash', '.libs', 'libsplash.a'),
os.path.join('utils', 'pdftoppm.o'),
os.path.join('utils', 'parseargs.o')],
configure_args=['--disable-libjpeg', '--disable-libpng', '--disable-poppler-qt', '--disable-poppler-qt4', '--disable-cms'])
@@ -5704,9 +5732,7 @@ f.close()
self.assertIdentical(expected, output.replace('\n\n', '\n'))
def test_reminder(self):
- assert False, 'Optimize makeGet/SetValue to do 16-bit reads/writes when possible, not just 8'
assert False, 'Ensure all opts including linktime apply to bindings generator. might need to adjust visibility of bindings C funcs'
- assert False, 'Optimize double version of fasta benchmark'
elif 'benchmark' in str(sys.argv):
# Benchmarks. Run them with argument |benchmark|. To run a specific test, do
diff --git a/tools/shared.py b/tools/shared.py
index be45633a..db783e39 100644
--- a/tools/shared.py
+++ b/tools/shared.py
@@ -728,9 +728,14 @@ set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)'''.replace('$EMSCRIPTEN_ROOT', path_
# if the file doesn't exist or doesn't have valid symbols, it isn't bitcode
try:
defs = Building.llvm_nm(filename, stderr=PIPE)
- assert len(defs.defs) + len(defs.undefs) + len(defs.commons) > 0
+ # If no symbols found, it might just be an empty bitcode file, try to dis it
+ if len(defs.defs) + len(defs.undefs) + len(defs.commons) == 0:
+ test_ll = os.path.join(EMSCRIPTEN_TEMP_DIR, 'test.ll')
+ Building.llvm_dis(filename, test_ll)
+ assert os.path.exists(test_ll)
except:
return False
+
# look for magic signature
b = open(filename, 'r').read(4)
if b[0] == 'B' and b[1] == 'C':