|
209 | 209 | (batchref-idx (batch-push! batch term)))) |
210 | 210 | (batchref batch idx)) |
211 | 211 |
|
212 | | -(define (normalize-cost c min-cost) |
213 | | - (exact-round (* (/ c min-cost) 100))) |
| 212 | +;; Egglog requires integer costs, but Herbie uses floating-point costs. |
| 213 | +;; Scale by 1000 to convert Herbie's float costs to Egglog's integer costs. |
| 214 | +(define (normalize-cost c) |
| 215 | + (exact-round (* c 1000))) |
214 | 216 |
|
215 | 217 | (define (prelude curr-program #:mixed-egraph? [mixed-egraph? #t]) |
216 | 218 | (define pform (*active-platform*)) |
|
220 | 222 |
|
221 | 223 | (egglog-program-add! spec-egraph curr-program) |
222 | 224 |
|
223 | | - ;;; To add support for floating point cost (which egglog does not support), compute |
224 | | - ;;; the minimum by accumulating all raw costs and normalize them |
225 | | - (define raw-costs '()) |
226 | | - |
227 | | - ;; Add raw num-typed-nodes and var-typed-nodes costs |
228 | | - (for ([repr (in-list (all-repr-names))]) |
229 | | - (set! raw-costs (cons (platform-repr-cost pform (get-representation repr)) raw-costs))) |
230 | | - |
231 | | - ;; Add raw platform-impl-nodes |
232 | | - (for ([impl (in-list (platform-impls pform))]) |
233 | | - (set! raw-costs (cons (impl-info impl 'cost) raw-costs))) |
234 | | - |
235 | | - (define nonzero-costs (filter (negate zero?) raw-costs)) |
236 | | - (define min-cost |
237 | | - (if (empty? nonzero-costs) |
238 | | - 1 |
239 | | - (apply min nonzero-costs))) |
240 | | - |
241 | 225 | (define typed-graph |
242 | 226 | `(datatype MTy |
243 | | - ,@(num-typed-nodes pform min-cost) |
244 | | - ,@(var-typed-nodes pform min-cost) |
| 227 | + ,@(num-typed-nodes pform) |
| 228 | + ,@(var-typed-nodes pform) |
245 | 229 | (Approx M MTy) |
246 | | - ,@(platform-impl-nodes pform min-cost))) |
| 230 | + ,@(platform-impl-nodes pform))) |
247 | 231 | (egglog-program-add! typed-graph curr-program) |
248 | 232 |
|
249 | 233 | (egglog-program-add! `(constructor do-lower (M String) MTy :unextractable) curr-program) |
|
358 | 342 | `(,(serialize-op sound-op) ,@(make-list arity 'M) M :cost 4294967295) |
359 | 343 | `(,(serialize-op unsound-op) ,@(make-list arity 'M) :cost 4294967295))))) |
360 | 344 |
|
361 | | -(define (platform-impl-nodes pform min-cost) |
| 345 | +(define (platform-impl-nodes pform) |
362 | 346 | (for/list ([impl (in-list (platform-impls pform))]) |
363 | 347 | (define arity (length (impl-info impl 'itype))) |
364 | 348 | (define typed-name (string->symbol (string-append (symbol->string (serialize-impl impl)) "Ty"))) |
|
367 | 351 | `(,typed-name ,@(for/list ([i (in-range arity)]) |
368 | 352 | 'MTy) |
369 | 353 | :cost |
370 | | - ,(normalize-cost (impl-info impl 'cost) min-cost)))) |
| 354 | + ,(normalize-cost (impl-info impl 'cost))))) |
371 | 355 |
|
372 | 356 | (define (typed-num-id repr-name) |
373 | 357 | (string->symbol (string-append "Num" (symbol->string repr-name)))) |
374 | 358 |
|
375 | 359 | (define (typed-var-id repr-name) |
376 | 360 | (string->symbol (string-append "Var" (symbol->string repr-name)))) |
377 | 361 |
|
378 | | -(define (num-typed-nodes pform min-cost) |
| 362 | +(define (num-typed-nodes pform) |
379 | 363 | (for/list ([repr (in-list (all-repr-names))] |
380 | 364 | #:when (not (eq? repr 'bool))) |
381 | 365 | `(,(typed-num-id repr) BigRat |
382 | 366 | :cost |
383 | | - ,(normalize-cost (platform-repr-cost pform (get-representation repr)) |
384 | | - min-cost)))) |
| 367 | + ,(normalize-cost (platform-repr-cost pform (get-representation repr)))))) |
385 | 368 |
|
386 | | -(define (var-typed-nodes pform min-cost) |
| 369 | +(define (var-typed-nodes pform) |
387 | 370 | (for/list ([repr (in-list (all-repr-names))]) |
388 | 371 | `(,(typed-var-id repr) String |
389 | 372 | :cost |
390 | | - ,(normalize-cost (platform-repr-cost pform (get-representation repr)) |
391 | | - min-cost)))) |
| 373 | + ,(normalize-cost (platform-repr-cost pform (get-representation repr)))))) |
392 | 374 |
|
393 | 375 | (define (num-lowering-rules) |
394 | 376 | (for/list ([repr (in-list (all-repr-names))] |
|
0 commit comments