comparison graal/com.oracle.truffle.api.dsl/src/com/oracle/truffle/api/dsl/internal/DSLShare.java @ 16922:0ea0c4133b78

Truffle-DSL: fixed polymorphic to monomorphic transition. It remained polymorphic in some cases.
author Christian Humer <christian.humer@gmail.com>
date Mon, 25 Aug 2014 16:30:40 +0200
parents f5541b01f374
children 1680a4ddc2a7
comparison
equal deleted inserted replaced
16921:f5541b01f374 16922:0ea0c4133b78
97 } 97 }
98 98
99 public static <T extends Node & DSLNode> T rewriteToPolymorphic(Node oldNode, DSLNode uninitializedDSL, T polymorphic, DSLNode currentCopy, DSLNode newNodeDSL, String message) { 99 public static <T extends Node & DSLNode> T rewriteToPolymorphic(Node oldNode, DSLNode uninitializedDSL, T polymorphic, DSLNode currentCopy, DSLNode newNodeDSL, String message) {
100 assert getNext(oldNode) == null; 100 assert getNext(oldNode) == null;
101 assert getPrevious(oldNode) == null; 101 assert getPrevious(oldNode) == null;
102 assert newNodeDSL != null;
102 103
103 Node uninitialized = (Node) uninitializedDSL; 104 Node uninitialized = (Node) uninitializedDSL;
104 Node newNode = (Node) newNodeDSL; 105 Node newNode = (Node) newNodeDSL;
105 polymorphic.adoptChildren0(oldNode, (Node) currentCopy); 106 polymorphic.adoptChildren0(oldNode, (Node) currentCopy);
106 107
107 updateSourceSection(oldNode, uninitialized); 108 updateSourceSection(oldNode, uninitialized);
108 if (newNode == null) { 109 // new specialization
109 // fallback 110 updateSourceSection(oldNode, newNode);
110 currentCopy.adoptChildren0(null, uninitialized); 111 newNodeDSL.adoptChildren0(null, uninitialized);
111 } else { 112 currentCopy.adoptChildren0(null, newNode);
112 // new specialization
113 updateSourceSection(oldNode, newNode);
114 newNodeDSL.adoptChildren0(null, uninitialized);
115 currentCopy.adoptChildren0(null, newNode);
116 }
117 113
118 oldNode.replace(polymorphic, message); 114 oldNode.replace(polymorphic, message);
119 115
120 assert polymorphic.getNext0() == currentCopy; 116 assert polymorphic.getNext0() == currentCopy;
121 assert newNode != null ? currentCopy.getNext0() == newNode : currentCopy.getNext0() == uninitialized; 117 assert newNode != null ? currentCopy.getNext0() == newNode : currentCopy.getNext0() == uninitialized;
163 cur = getPrevious(cur); 159 cur = getPrevious(cur);
164 } 160 }
165 assert prev.getCost() == NodeCost.POLYMORPHIC; 161 assert prev.getCost() == NodeCost.POLYMORPHIC;
166 162
167 updateSourceSection(prev, newNode); 163 updateSourceSection(prev, newNode);
168 if (depth == 0) { 164 if (depth <= 1) {
169 newNode.adoptChildren0(prev, null); 165 newNode.adoptChildren0(prev, null);
170 return prev.replace(newNode, "Polymorphic to monomorphic."); 166 return prev.replace(newNode, "Polymorphic to monomorphic.");
171 } else { 167 } else {
172 newNode.adoptChildren0(null, uninitialized); 168 newNode.adoptChildren0(null, uninitialized);
173 ((DSLNode) prev).updateTypes0(mergeTypes(newNode, types)); 169 ((DSLNode) prev).updateTypes0(mergeTypes(newNode, types));