|
207 | 207 | (define (egraph-eclasses egraph-data) |
208 | 208 | (egraph_get_eclasses (egraph-data-egraph-pointer egraph-data))) |
209 | 209 |
|
| 210 | +(define empty-u32vec (make-u32vector 0)) |
| 211 | + |
210 | 212 | ;; Extracts the nodes of an e-class as a vector |
211 | 213 | ;; where each enode is either a symbol, number, or list |
212 | 214 | (define (egraph-get-eclass egraph-data id) |
|
217 | 219 | (for ([enode (in-vector eclass)] |
218 | 220 | [i (in-naturals)]) |
219 | 221 | (when (and (symbol? enode) (not (hash-has-key? egg->herbie enode))) |
220 | | - (vector-set! eclass i (cons enode (make-u32vector 0))))) |
| 222 | + (vector-set! eclass i (cons enode empty-u32vec)))) |
221 | 223 | eclass) |
222 | 224 |
|
223 | 225 | (define (egraph-find egraph-data id) |
|
1204 | 1206 | (define root-ids (egraph-add-exprs egg-graph exprs ctx)) |
1205 | 1207 |
|
1206 | 1208 | ; run the schedule |
1207 | | - (define rule-apps (make-hash)) |
1208 | 1209 | (define egg-graph* |
1209 | | - (for/fold ([egg-graph egg-graph]) ([instr (in-list schedule)]) |
1210 | | - (match-define (cons rules params) instr) |
| 1210 | + (for/fold ([egg-graph egg-graph]) ([(rules params) (in-dict schedule)]) |
1211 | 1211 | ; run rules in the egraph |
1212 | 1212 | (define egg-rules (expand-rules rules)) |
1213 | 1213 | (define-values (egg-graph* iteration-data) (egraph-run-rules egg-graph egg-rules params)) |
1214 | 1214 |
|
1215 | 1215 | ; get cost statistics |
1216 | | - (for/fold ([time 0]) |
1217 | | - ([iter (in-list iteration-data)] |
1218 | | - [i (in-naturals)]) |
| 1216 | + (for ([iter (in-list iteration-data)] |
| 1217 | + [i (in-naturals)]) |
1219 | 1218 | (define cnt (iteration-data-num-nodes iter)) |
1220 | 1219 | (define cost (apply + (map (λ (id) (egraph-get-cost egg-graph* id i)) root-ids))) |
1221 | | - (define new-time (+ time (iteration-data-time iter))) |
1222 | | - (timeline-push! 'egraph i cnt cost new-time) |
1223 | | - new-time) |
1224 | | - |
1225 | | - ;; get rule statistics |
1226 | | - (for ([(egg-rule ffi-rule) (in-dict egg-rules)]) |
1227 | | - (define count (egraph-get-times-applied egg-graph* ffi-rule)) |
1228 | | - (define canon-name (hash-ref (*canon-names*) (rule-name egg-rule))) |
1229 | | - (hash-update! rule-apps canon-name (curry + count) count)) |
| 1220 | + (timeline-push! 'egraph i cnt cost (iteration-data-time iter))) |
1230 | 1221 |
|
1231 | 1222 | egg-graph*)) |
1232 | 1223 |
|
1233 | | - ; report rule statistics |
1234 | | - (for ([(name count) (in-hash rule-apps)]) |
1235 | | - (when (> count 0) |
1236 | | - (timeline-push! 'rules (~a name) count))) |
1237 | 1224 | ; root eclasses may have changed |
1238 | 1225 | (define root-ids* (map (lambda (id) (egraph-find egg-graph* id)) root-ids)) |
1239 | 1226 | ; return what we need |
|
0 commit comments