Replacing copyins and copyouts with data-movement instructions
[ghc.git] / compiler / cmm / BlockId.hs
1 module BlockId
2 ( BlockId(..), mkBlockId -- ToDo: BlockId should be abstract, but it isn't yet
3 , BlockEnv, emptyBlockEnv, lookupBlockEnv, extendBlockEnv, mkBlockEnv
4 , BlockSet, emptyBlockSet, elemBlockSet, extendBlockSet, sizeBlockSet, mkBlockSet
5 ) where
6
7 import Outputable
8 import UniqFM
9 import Unique
10 import UniqSet
11
12 ----------------------------------------------------------------
13 --- Block Ids, their environments, and their sets
14
15 {- Note [Unique BlockId]
16 ~~~~~~~~~~~~~~~~~~~~~~~~
17 Although a 'BlockId' is a local label, for reasons of implementation,
18 'BlockId's must be unique within an entire compilation unit. The reason
19 is that each local label is mapped to an assembly-language label, and in
20 most assembly languages allow, a label is visible throughout the enitre
21 compilation unit in which it appears.
22 -}
23
24 newtype BlockId = BlockId Unique
25 deriving (Eq,Ord)
26
27 instance Uniquable BlockId where
28 getUnique (BlockId u) = u
29
30 mkBlockId :: Unique -> BlockId
31 mkBlockId uniq = BlockId uniq
32
33 instance Show BlockId where
34 show (BlockId u) = show u
35
36 instance Outputable BlockId where
37 ppr = ppr . getUnique
38
39
40 type BlockEnv a = UniqFM {- BlockId -} a
41 emptyBlockEnv :: BlockEnv a
42 emptyBlockEnv = emptyUFM
43 mkBlockEnv :: [(BlockId,a)] -> BlockEnv a
44 mkBlockEnv = listToUFM
45 lookupBlockEnv :: BlockEnv a -> BlockId -> Maybe a
46 lookupBlockEnv = lookupUFM
47 extendBlockEnv :: BlockEnv a -> BlockId -> a -> BlockEnv a
48 extendBlockEnv = addToUFM
49
50 type BlockSet = UniqSet BlockId
51 emptyBlockSet :: BlockSet
52 emptyBlockSet = emptyUniqSet
53 elemBlockSet :: BlockId -> BlockSet -> Bool
54 elemBlockSet = elementOfUniqSet
55 extendBlockSet :: BlockSet -> BlockId -> BlockSet
56 extendBlockSet = addOneToUniqSet
57 mkBlockSet :: [BlockId] -> BlockSet
58 mkBlockSet = mkUniqSet
59 sizeBlockSet :: BlockSet -> Int
60 sizeBlockSet = sizeUniqSet