[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Guile-commits] 01/09: Reorganizing of intset/intmap helper functions
From: |
Andy Wingo |
Subject: |
[Guile-commits] 01/09: Reorganizing of intset/intmap helper functions |
Date: |
Wed, 15 Jul 2015 07:51:32 +0000 |
wingo pushed a commit to branch master
in repository guile.
commit 1bb7a7fa7af9157e4b6b04dfb46c2e0ddcf9cb45
Author: Andy Wingo <address@hidden>
Date: Mon Jul 13 11:01:43 2015 +0200
Reorganizing of intset/intmap helper functions
* module/language/cps2/split-rec.scm (intmap-keys): Move to utils.
* module/language/cps2/utils.scm (trivial-intset): New function.
(intmap-keys, invert-bijection, invert-partition): New functions.
---
module/language/cps2/split-rec.scm | 4 ----
module/language/cps2/utils.scm | 30 ++++++++++++++++++++++++++++++
2 files changed, 30 insertions(+), 4 deletions(-)
diff --git a/module/language/cps2/split-rec.scm
b/module/language/cps2/split-rec.scm
index 763ede5..20cb516 100644
--- a/module/language/cps2/split-rec.scm
+++ b/module/language/cps2/split-rec.scm
@@ -105,10 +105,6 @@ references."
(persistent-intset defs)))))))
(visit-fun kfun))
-(define (intmap-keys map)
- (persistent-intset
- (intmap-fold (lambda (k v keys) (intset-add! keys k)) map empty-intset)))
-
(define (compute-sorted-strongly-connected-components edges)
(define nodes
(intmap-keys edges))
diff --git a/module/language/cps2/utils.scm b/module/language/cps2/utils.scm
index d375925..e4ed473 100644
--- a/module/language/cps2/utils.scm
+++ b/module/language/cps2/utils.scm
@@ -37,7 +37,10 @@
;; Various utilities.
fold1 fold2
+ trivial-intset
intmap-map
+ intmap-keys
+ invert-bijection invert-partition
intset->intmap
worklist-fold
fixpoint
@@ -108,12 +111,39 @@
(lambda (s0 s1)
(lp l s0 s1)))))))
+(define (trivial-intset set)
+ "Returns the sole member of @var{set}, if @var{set} has exactly one
+member, or @code{#f} otherwise."
+ (let ((first (intset-next set)))
+ (and first
+ (not (intset-next set (1+ first)))
+ first)))
+
(define (intmap-map proc map)
(persistent-intmap
(intmap-fold (lambda (k v out) (intmap-replace! out k (proc k v)))
map
map)))
+(define (intmap-keys map)
+ "Return an intset of the keys in @var{map}."
+ (persistent-intset
+ (intmap-fold (lambda (k v keys) (intset-add! keys k)) map empty-intset)))
+
+(define (invert-bijection map)
+ "Assuming the values of @var{map} are integers and are unique, compute
+a map in which each value maps to its key. If the values are not
+unique, an error will be signalled."
+ (intmap-fold (lambda (k v out) (intmap-add out v k)) map empty-intmap))
+
+(define (invert-partition map)
+ "Assuming the values of @var{map} are disjoint intsets, compute a map
+in which each member of each set maps to its key. If the values are not
+disjoint, an error will be signalled."
+ (intmap-fold (lambda (k v* out)
+ (intset-fold (lambda (v out) (intmap-add out v k)) v* out))
+ map empty-intmap))
+
(define (intset->intmap f set)
(persistent-intmap
(intset-fold (lambda (label preds)
- [Guile-commits] branch master updated (dbe6247 -> 981802c), Andy Wingo, 2015/07/15
- [Guile-commits] 01/09: Reorganizing of intset/intmap helper functions,
Andy Wingo <=
- [Guile-commits] 02/09: intset-union fast paths, Andy Wingo, 2015/07/15
- [Guile-commits] 03/09: Fix intset-subtract to reliably produce empty-intset, Andy Wingo, 2015/07/15
- [Guile-commits] 04/09: CPS2 renumber works with first-order CPS, Andy Wingo, 2015/07/15
- [Guile-commits] 05/09: Tweak intset printing, Andy Wingo, 2015/07/15
- [Guile-commits] 06/09: Beginnings of first-order CPS optimization, Andy Wingo, 2015/07/15
- [Guile-commits] 07/09: Verify pass works on first-order CPS, Andy Wingo, 2015/07/15
- [Guile-commits] 09/09: Wire up new closure conversion pass, Andy Wingo, 2015/07/15
- [Guile-commits] 08/09: Add CPS2 closure conversion module, Andy Wingo, 2015/07/15