1
0
Prechádzať zdrojové kódy

Need for aliasing is checked deep in subtree.

Herbert Vojčík 12 rokov pred
rodič
commit
3f44d46fa0

+ 26 - 0
js/Compiler-AST.deploy.js

@@ -186,6 +186,32 @@ return self}
 }),
 smalltalk.Node);
 
+smalltalk.addMethod(
+"_subtreeNeedsAliasing",
+smalltalk.method({
+selector: "subtreeNeedsAliasing",
+fn: function (){
+var self=this;
+var $1;
+var $early={};
+try {
+$1=smalltalk.send(smalltalk.send(smalltalk.send(self,"_shouldBeAliased",[]),"_or_",[(function(){
+return smalltalk.send(self,"_shouldBeInlined",[]);
+})]),"_or_",[(function(){
+smalltalk.send(smalltalk.send(self,"_nodes",[]),"_detect_ifNone_",[(function(node){
+return smalltalk.send(node,"_subtreeNeedsAliasing",[]);
+}),(function(){
+throw $early=[false];
+})]);
+return true;
+})]);
+return $1;
+}
+catch(e) {if(e===$early)return e[0]; throw e}
+}
+}),
+smalltalk.Node);
+
 
 
 smalltalk.addClass('AssignmentNode', smalltalk.Node, ['left', 'right'], 'Compiler-AST');

+ 31 - 0
js/Compiler-AST.js

@@ -262,6 +262,37 @@ referencedClasses: []
 }),
 smalltalk.Node);
 
+smalltalk.addMethod(
+"_subtreeNeedsAliasing",
+smalltalk.method({
+selector: "subtreeNeedsAliasing",
+category: 'accessing',
+fn: function (){
+var self=this;
+var $1;
+var $early={};
+try {
+$1=smalltalk.send(smalltalk.send(smalltalk.send(self,"_shouldBeAliased",[]),"_or_",[(function(){
+return smalltalk.send(self,"_shouldBeInlined",[]);
+})]),"_or_",[(function(){
+smalltalk.send(smalltalk.send(self,"_nodes",[]),"_detect_ifNone_",[(function(node){
+return smalltalk.send(node,"_subtreeNeedsAliasing",[]);
+}),(function(){
+throw $early=[false];
+})]);
+return true;
+})]);
+return $1;
+}
+catch(e) {if(e===$early)return e[0]; throw e}
+},
+args: [],
+source: "subtreeNeedsAliasing\x0a    ^(self shouldBeAliased or: [ self shouldBeInlined ]) or: [\x0a        self nodes detect: [ :node | node subtreeNeedsAliasing ] ifNone: [ ^false ].\x0a        true\x0a    ]",
+messageSends: ["or:", "detect:ifNone:", "subtreeNeedsAliasing", "nodes", "shouldBeInlined", "shouldBeAliased"],
+referencedClasses: []
+}),
+smalltalk.Node);
+
 
 
 smalltalk.addClass('AssignmentNode', smalltalk.Node, ['left', 'right'], 'Compiler-AST');

+ 10 - 10
js/Compiler-IR.deploy.js

@@ -120,14 +120,12 @@ smalltalk.method({
 selector: "temporallyDependentList:",
 fn: function (nodes){
 var self=this;
-var $1,$3,$2;
+var $1,$2,$4,$3,$5;
 var threshold;
 var result;
 threshold=(0);
 smalltalk.send(nodes,"_withIndexDo_",[(function(each,i){
-$1=smalltalk.send(smalltalk.send(each,"_shouldBeInlined",[]),"_or_",[(function(){
-return smalltalk.send(each,"_shouldBeAliased",[]);
-})]);
+$1=smalltalk.send(each,"_subtreeNeedsAliasing",[]);
 if(smalltalk.assert($1)){
 threshold=i;
 return threshold;
@@ -135,15 +133,17 @@ return threshold;
 })]);
 result=smalltalk.send((smalltalk.OrderedCollection || OrderedCollection),"_new",[]);
 smalltalk.send(nodes,"_withIndexDo_",[(function(each,i){
-$3=smalltalk.send(i,"__lt_eq",[threshold]);
-if(smalltalk.assert($3)){
-$2=smalltalk.send(self,"_alias_",[each]);
+$2=result;
+$4=smalltalk.send(i,"__lt_eq",[threshold]);
+if(smalltalk.assert($4)){
+$3=smalltalk.send(self,"_alias_",[each]);
 } else {
-$2=smalltalk.send(self,"_visit_",[each]);
+$3=smalltalk.send(self,"_visit_",[each]);
 };
-return smalltalk.send(result,"_add_",[$2]);
+return smalltalk.send($2,"_add_",[$3]);
 })]);
-return result;
+$5=result;
+return $5;
 }
 }),
 smalltalk.IRASTTranslator);

+ 12 - 12
js/Compiler-IR.js

@@ -162,14 +162,12 @@ selector: "temporallyDependentList:",
 category: 'visiting',
 fn: function (nodes){
 var self=this;
-var $1,$3,$2;
+var $1,$2,$4,$3,$5;
 var threshold;
 var result;
 threshold=(0);
 smalltalk.send(nodes,"_withIndexDo_",[(function(each,i){
-$1=smalltalk.send(smalltalk.send(each,"_shouldBeInlined",[]),"_or_",[(function(){
-return smalltalk.send(each,"_shouldBeAliased",[]);
-})]);
+$1=smalltalk.send(each,"_subtreeNeedsAliasing",[]);
 if(smalltalk.assert($1)){
 threshold=i;
 return threshold;
@@ -177,19 +175,21 @@ return threshold;
 })]);
 result=smalltalk.send((smalltalk.OrderedCollection || OrderedCollection),"_new",[]);
 smalltalk.send(nodes,"_withIndexDo_",[(function(each,i){
-$3=smalltalk.send(i,"__lt_eq",[threshold]);
-if(smalltalk.assert($3)){
-$2=smalltalk.send(self,"_alias_",[each]);
+$2=result;
+$4=smalltalk.send(i,"__lt_eq",[threshold]);
+if(smalltalk.assert($4)){
+$3=smalltalk.send(self,"_alias_",[each]);
 } else {
-$2=smalltalk.send(self,"_visit_",[each]);
+$3=smalltalk.send(self,"_visit_",[each]);
 };
-return smalltalk.send(result,"_add_",[$2]);
+return smalltalk.send($2,"_add_",[$3]);
 })]);
-return result;
+$5=result;
+return $5;
 },
 args: ["nodes"],
-source: "temporallyDependentList: nodes\x0a\x09| threshold result |\x0a    threshold := 0.\x0a    \x0a    nodes withIndexDo: [ :each :i |\x0a        (each shouldBeInlined or: [ each shouldBeAliased ])\x0a\x09\x09    ifTrue: [ threshold := i ]].\x0a\x0a\x09result := OrderedCollection new.\x0a\x09nodes withIndexDo: [ :each :i | \x0a\x09\x09result add: (i <= threshold\x0a\x09\x09\x09ifTrue: [ self alias: each ]\x0a\x09\x09\x09ifFalse: [ self visit: each ])].\x0a\x0a    ^result\x0a",
-messageSends: ["withIndexDo:", "ifTrue:", "or:", "shouldBeAliased", "shouldBeInlined", "new", "add:", "ifTrue:ifFalse:", "alias:", "visit:", "<="],
+source: "temporallyDependentList: nodes\x0a\x09| threshold result |\x0a    threshold := 0.\x0a    \x0a    nodes withIndexDo: [ :each :i |\x0a        each subtreeNeedsAliasing\x0a\x09\x09    ifTrue: [ threshold := i ]].\x0a\x0a\x09result := OrderedCollection new.\x0a\x09nodes withIndexDo: [ :each :i | \x0a\x09\x09result add: (i <= threshold\x0a\x09\x09\x09ifTrue: [ self alias: each ]\x0a\x09\x09\x09ifFalse: [ self visit: each ])].\x0a\x0a    ^result\x0a",
+messageSends: ["withIndexDo:", "ifTrue:", "subtreeNeedsAliasing", "new", "add:", "ifTrue:ifFalse:", "alias:", "visit:", "<="],
 referencedClasses: ["OrderedCollection"]
 }),
 smalltalk.IRASTTranslator);

+ 7 - 0
st/Compiler-AST.st

@@ -29,6 +29,13 @@ shouldBeInlined
 
 shouldBeInlined: aBoolean
 	shouldBeInlined := aBoolean
+!
+
+subtreeNeedsAliasing
+    ^(self shouldBeAliased or: [ self shouldBeInlined ]) or: [
+        self nodes detect: [ :node | node subtreeNeedsAliasing ] ifNone: [ ^false ].
+        true
+    ]
 ! !
 
 !Node methodsFor: 'building'!

+ 1 - 1
st/Compiler-IR.st

@@ -81,7 +81,7 @@ temporallyDependentList: nodes
     threshold := 0.
     
     nodes withIndexDo: [ :each :i |
-        (each shouldBeInlined or: [ each shouldBeAliased ])
+        each subtreeNeedsAliasing
 		    ifTrue: [ threshold := i ]].
 
 	result := OrderedCollection new.