112 List<UseEntry> usages = new ArrayList<>();
113 double bestCost = 0;
114 int numMat = 0;
115
116 // collect children costs
117 AbstractBlockBase<?> child = block.getFirstDominated();
118 while (child != null) {
119 if (isMarked(child)) {
120 NodeCost childCost = tree.getCost(child);
121 assert childCost != null : "Child with null cost? block: " + child;
122 usages.addAll(childCost.getUsages());
123 numMat += childCost.getNumMaterializations();
124 bestCost += childCost.getBestCost();
125 }
126 child = child.getDominatedSibling();
127 }
128 assert numMat > 0 : "No materialization? " + numMat;
129
130 // choose block
131 List<UseEntry> usagesBlock = tree.getUsages(block);
132 double probabilityBlock = block.probability();
133
134 if (!usagesBlock.isEmpty() || shouldMaterializerInCurrentBlock(probabilityBlock, bestCost, numMat)) {
135 // mark current block as potential materialization position
136 usages.addAll(usagesBlock);
137 bestCost = probabilityBlock;
138 numMat = 1;
139 tree.set(Flags.CANDIDATE, block);
140 } else {
141 // stick with the current solution
142 }
143
144 NodeCost nodeCost = new NodeCost(bestCost, usages, numMat);
145 tree.setCost(block, nodeCost);
146 }
147
148 /**
149 * This is the cost function that decides whether a materialization should be inserted in the
150 * current block.
151 * <p>
152 * Note that this function does not take into account if a materialization is required despite
|
112 List<UseEntry> usages = new ArrayList<>();
113 double bestCost = 0;
114 int numMat = 0;
115
116 // collect children costs
117 AbstractBlockBase<?> child = block.getFirstDominated();
118 while (child != null) {
119 if (isMarked(child)) {
120 NodeCost childCost = tree.getCost(child);
121 assert childCost != null : "Child with null cost? block: " + child;
122 usages.addAll(childCost.getUsages());
123 numMat += childCost.getNumMaterializations();
124 bestCost += childCost.getBestCost();
125 }
126 child = child.getDominatedSibling();
127 }
128 assert numMat > 0 : "No materialization? " + numMat;
129
130 // choose block
131 List<UseEntry> usagesBlock = tree.getUsages(block);
132 double probabilityBlock = block.getRelativeFrequency();
133
134 if (!usagesBlock.isEmpty() || shouldMaterializerInCurrentBlock(probabilityBlock, bestCost, numMat)) {
135 // mark current block as potential materialization position
136 usages.addAll(usagesBlock);
137 bestCost = probabilityBlock;
138 numMat = 1;
139 tree.set(Flags.CANDIDATE, block);
140 } else {
141 // stick with the current solution
142 }
143
144 NodeCost nodeCost = new NodeCost(bestCost, usages, numMat);
145 tree.setCost(block, nodeCost);
146 }
147
148 /**
149 * This is the cost function that decides whether a materialization should be inserted in the
150 * current block.
151 * <p>
152 * Note that this function does not take into account if a materialization is required despite
|