~ubuntu-branches/ubuntu/vivid/emscripten/vivid

« back to all changes in this revision

Viewing changes to src/experimental/optimize_memcpy_for_ta1.diff

  • Committer: Package Import Robot
  • Author(s): Sylvestre Ledru
  • Date: 2013-05-02 13:11:51 UTC
  • Revision ID: package-import@ubuntu.com-20130502131151-q8dvteqr1ef2x7xz
Tags: upstream-1.4.1~20130504~adb56cb
ImportĀ upstreamĀ versionĀ 1.4.1~20130504~adb56cb

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
diff --git a/src/analyzer.js b/src/analyzer.js
 
2
index 526d024..a5074e1 100644
 
3
--- a/src/analyzer.js
 
4
+++ b/src/analyzer.js
 
5
@@ -462,15 +462,17 @@ function analyzer(data) {
 
6
   //
 
7
   // See settings.js for the meaning of QUANTUM_SIZE. The issue we fix here is,
 
8
   // to correct the .ll assembly code so that things work with QUANTUM_SIZE=1.
 
9
   //
 
10
   substrate.addActor('QuantumFixer', {
 
11
     processItem: function(item) {
 
12
       this.forwardItem(item, 'LabelAnalyzer');
 
13
+dprint('cheez qf!');
 
14
       if (QUANTUM_SIZE !== 1) return;
 
15
+dprint('cheez qf 2!');
 
16
 
 
17
       // ptrs: the indexes of parameters that are pointers, whose originalType is what we want
 
18
       // bytes: the index of the 'bytes' parameter
 
19
       // TODO: malloc, realloc?
 
20
       var FIXABLE_CALLS = {
 
21
         'memcpy': { ptrs: [0,1], bytes: 2 },
 
22
         'memmove': { ptrs: [0,1], bytes: 2 },
 
23
@@ -495,16 +497,22 @@ function analyzer(data) {
 
24
         return [0];
 
25
       }
 
26
 
 
27
       item.functions.forEach(function(func) {
 
28
         function getOriginalType(param) {
 
29
           function get() {
 
30
             if (param.intertype === 'value' && !isNumber(param.ident)) {
 
31
-              if (func.variables[param.ident]) {
 
32
-                return func.variables[param.ident].originalType || null;
 
33
+              var varData = func.variables[param.ident];
 
34
+              if (varData) {
 
35
+                if (varData.origin == 'load') {
 
36
+                  return varData.type; // we can trust this
 
37
+                }
 
38
+// To continue, we need proper type data inside getelementptr, by using type data. not a one liner.
 
39
+// TESTING: this makes a difference in fasta
 
40
+                return varData.originalType || null;
 
41
               } else {
 
42
                 return item.globalVariables[param.ident].originalType;
 
43
               }
 
44
             } else if (param.intertype === 'bitcast') {
 
45
               return param.params[0].type;
 
46
             } else if (param.intertype === 'getelementptr') {
 
47
               if (param.params[0].type[0] === '[') return param.params[0].type;
 
48
@@ -527,18 +535,21 @@ function analyzer(data) {
 
49
             var fixData = FIXABLE_CALLS[funcIdent];
 
50
             if (!fixData) return;
 
51
             var ptrs = fixData.ptrs.map(function(ptr) { return line.params[ptr] });
 
52
             var bytes = line.params[fixData.bytes].ident;
 
53
 
 
54
             // Only consider original types. This assumes memcpy always has pointers bitcast to i8*
 
55
             var originalTypes = ptrs.map(getOriginalType);
 
56
+dprint('cheez qf 2! ' + dump(func.variables) + ' :: ' + funcIdent + ',' + line.lineNum + ' : ' + dump(ptrs) + ' ==> ' + dump(originalTypes));
 
57
             for (var i = 0; i < originalTypes.length; i++) {
 
58
               if (!originalTypes[i]) return;
 
59
             }
 
60
+dprint('cheez qf 3!');
 
61
             originalTypes = originalTypes.map(function(type) { return removePointing(type) });
 
62
+dprint('zz cheez ' + [funcIdent, originalTypes]);
 
63
             var sizes = originalTypes.map(function(type) { return getSize(Types.types, type) });
 
64
             var fatSizes = originalTypes.map(function(type) { return getSize(Types.fatTypes, type, true) });
 
65
             // The sizes may not be identical, if we copy a descendant class into a parent class. We use
 
66
             // the smaller size in that case. However, this may also be a bug, it is hard to tell, hence a warning
 
67
             warn(dedup(sizes).length === 1, 'All sizes should probably be identical here: ' + dump(originalTypes) + ':' + dump(sizes) + ':' +
 
68
                  line.lineNum);
 
69
             warn(dedup(fatSizes).length === 1, 'All fat sizes should probably be identical here: ' + dump(originalTypes) + ':' + dump(sizes) + ':' +
 
70
diff --git a/src/parseTools.js b/src/parseTools.js
 
71
index 024026c..a15b89f 100644
 
72
--- a/src/parseTools.js
 
73
+++ b/src/parseTools.js
 
74
@@ -1078,14 +1078,29 @@ function makeSetValues(ptr, pos, value, type, num) {
 
75
       '}'
 
76
   }
 
77
 }
 
78
 
 
79
 var TYPED_ARRAY_SET_MIN = Infinity; // .set() as memcpy seems to just slow us down
 
80
 
 
81
 function makeCopyValues(dest, src, num, type, modifier) {
 
82
+  return '/* zz1 */ ' + makeCopyValuesX(dest, src, num, type, modifier) + ';' +
 
83
+         makeCopyValuesX(dest, src, num, type, modifier) + ';' +
 
84
+         makeCopyValuesX(dest, src, num, type, modifier) + ';' +
 
85
+         makeCopyValuesX(dest, src, num, type, modifier) + ';' +
 
86
+         makeCopyValuesX(dest, src, num, type, modifier) + ';' +
 
87
+         makeCopyValuesX(dest, src, num, type, modifier) + ';' +
 
88
+         makeCopyValuesX(dest, src, num, type, modifier) + ';' +
 
89
+         makeCopyValuesX(dest, src, num, type, modifier) + ';' +
 
90
+         makeCopyValuesX(dest, src, num, type, modifier) + ';' +
 
91
+         makeCopyValuesX(dest, src, num, type, modifier) + ';' +
 
92
+         makeCopyValuesX(dest, src, num, type, modifier) + ';' +
 
93
+         makeCopyValuesX(dest, src, num, type, modifier) + '; /* zz2*/';
 
94
+}
 
95
+
 
96
+function makeCopyValuesX(dest, src, num, type, modifier) {
 
97
   function safety(to, from) {
 
98
     to = to || (dest + '+' + 'mcpi');
 
99
     from = from || (src + '+' + 'mcpi');
 
100
     return (SAFE_HEAP ? 'SAFE_HEAP_COPY_HISTORY(' + to + ', ' + from + ')' : '');
 
101
   }
 
102
   if (USE_TYPED_ARRAYS <= 1) {
 
103
     if (isNumber(num)) {
 
104
diff --git a/src/utility.js b/src/utility.js
 
105
index 1ebbe52..1724c62 100644
 
106
--- a/src/utility.js
 
107
+++ b/src/utility.js
 
108
@@ -15,15 +15,15 @@ function dump(item) {
 
109
     while (text.length > 80) {
 
110
       ret += '// ' + text.substr(0,80) + '\n';
 
111
       text = text.substr(80);
 
112
     }
 
113
     return ret + '// ' + text;
 
114
   }
 
115
   try {
 
116
-    return lineify(JSON.stringify(item).substr(0, 80*25));
 
117
+    return lineify(JSON.stringify(item).substr(0, 800*25));
 
118
   } catch(e) {
 
119
     var ret = [];
 
120
     for (var i in item) {
 
121
       var j = item[i];
 
122
       if (typeof j === 'string' || typeof j === 'number') {
 
123
         ret.push(i + ': ' + j);
 
124
       } else {