Commit 480e0661 authored by niteria's avatar niteria

Remove ufmToList

This documents nondeterminism in code generation and removes
the nondeterministic ufmToList function. In the future someone
will have to use nonDetUFMToList (with proper explanation)
or pprUFMWithKeys.
parent b6b20a50
...@@ -129,7 +129,7 @@ instance (Outputable statics, Outputable instr) ...@@ -129,7 +129,7 @@ instance (Outputable statics, Outputable instr)
$$ (if (not $ isNullUFM $ raCoalesced s) $$ (if (not $ isNullUFM $ raCoalesced s)
then text "# Registers coalesced." then text "# Registers coalesced."
$$ (vcat $ map ppr $ ufmToList $ raCoalesced s) $$ (pprUFMWithKeys (raCoalesced s) (vcat . map ppr))
$$ text "" $$ text ""
else empty) else empty)
...@@ -160,7 +160,7 @@ instance (Outputable statics, Outputable instr) ...@@ -160,7 +160,7 @@ instance (Outputable statics, Outputable instr)
$$ (if (not $ isNullUFM $ raCoalesced s) $$ (if (not $ isNullUFM $ raCoalesced s)
then text "# Registers coalesced." then text "# Registers coalesced."
$$ (vcat $ map ppr $ ufmToList $ raCoalesced s) $$ (pprUFMWithKeys (raCoalesced s) (vcat . map ppr))
$$ text "" $$ text ""
else empty) else empty)
......
...@@ -87,7 +87,10 @@ joinToTargets' block_live new_blocks block_id instr (dest:dests) ...@@ -87,7 +87,10 @@ joinToTargets' block_live new_blocks block_id instr (dest:dests)
-- and free up those registers which are now free. -- and free up those registers which are now free.
let to_free = let to_free =
[ r | (reg, loc) <- ufmToList assig [ r | (reg, loc) <- nonDetUFMToList assig
-- This is non-deterministic but we do not
-- currently support deterministic code-generation.
-- See Note [Unique Determinism and code generation]
, not (elemUniqSet_Directly reg live_set) , not (elemUniqSet_Directly reg live_set)
, r <- regsOfLoc loc ] , r <- regsOfLoc loc ]
...@@ -148,7 +151,10 @@ joinToTargets_again ...@@ -148,7 +151,10 @@ joinToTargets_again
src_assig dest_assig src_assig dest_assig
-- the assignments already match, no problem. -- the assignments already match, no problem.
| ufmToList dest_assig == ufmToList src_assig | nonDetUFMToList dest_assig == nonDetUFMToList src_assig
-- This is non-deterministic but we do not
-- currently support deterministic code-generation.
-- See Note [Unique Determinism and code generation]
= joinToTargets' block_live new_blocks block_id instr dests = joinToTargets' block_live new_blocks block_id instr dests
-- assignments don't match, need fixup code -- assignments don't match, need fixup code
...@@ -223,7 +229,10 @@ joinToTargets_again ...@@ -223,7 +229,10 @@ joinToTargets_again
-- --
makeRegMovementGraph :: RegMap Loc -> RegMap Loc -> [(Unique, Loc, [Loc])] makeRegMovementGraph :: RegMap Loc -> RegMap Loc -> [(Unique, Loc, [Loc])]
makeRegMovementGraph adjusted_assig dest_assig makeRegMovementGraph adjusted_assig dest_assig
= [ node | (vreg, src) <- ufmToList adjusted_assig = [ node | (vreg, src) <- nonDetUFMToList adjusted_assig
-- This is non-deterministic but we do not
-- currently support deterministic code-generation.
-- See Note [Unique Determinism and code generation]
-- source reg might not be needed at the dest: -- source reg might not be needed at the dest:
, Just loc <- [lookupUFM_Directly dest_assig vreg] , Just loc <- [lookupUFM_Directly dest_assig vreg]
, node <- expandNode vreg src loc ] , node <- expandNode vreg src loc ]
......
...@@ -620,7 +620,10 @@ saveClobberedTemps clobbered dying ...@@ -620,7 +620,10 @@ saveClobberedTemps clobbered dying
assig <- getAssigR assig <- getAssigR
let to_spill let to_spill
= [ (temp,reg) = [ (temp,reg)
| (temp, InReg reg) <- ufmToList assig | (temp, InReg reg) <- nonDetUFMToList assig
-- This is non-deterministic but we do not
-- currently support deterministic code-generation.
-- See Note [Unique Determinism and code generation]
, any (realRegsAlias reg) clobbered , any (realRegsAlias reg) clobbered
, temp `notElem` map getUnique dying ] , temp `notElem` map getUnique dying ]
...@@ -682,7 +685,10 @@ clobberRegs clobbered ...@@ -682,7 +685,10 @@ clobberRegs clobbered
setFreeRegsR $! foldr (frAllocateReg platform) freeregs clobbered setFreeRegsR $! foldr (frAllocateReg platform) freeregs clobbered
assig <- getAssigR assig <- getAssigR
setAssigR $! clobber assig (ufmToList assig) setAssigR $! clobber assig (nonDetUFMToList assig)
-- This is non-deterministic but we do not
-- currently support deterministic code-generation.
-- See Note [Unique Determinism and code generation]
where where
-- if the temp was InReg and clobbered, then we will have -- if the temp was InReg and clobbered, then we will have
...@@ -802,17 +808,23 @@ allocRegsAndSpill_spill reading keep spills alloc r rs assig spill_loc ...@@ -802,17 +808,23 @@ allocRegsAndSpill_spill reading keep spills alloc r rs assig spill_loc
-- the vregs we could kick out that are already in a slot -- the vregs we could kick out that are already in a slot
let candidates_inBoth let candidates_inBoth
= [ (temp, reg, mem) = [ (temp, reg, mem)
| (temp, InBoth reg mem) <- ufmToList assig | (temp, InBoth reg mem) <- nonDetUFMToList assig
, temp `notElem` keep' -- This is non-deterministic but we do not
, targetClassOfRealReg platform reg == classOfVirtualReg r ] -- currently support deterministic code-generation.
-- See Note [Unique Determinism and code generation]
, temp `notElem` keep'
, targetClassOfRealReg platform reg == classOfVirtualReg r ]
-- the vregs we could kick out that are only in a reg -- the vregs we could kick out that are only in a reg
-- this would require writing the reg to a new slot before using it. -- this would require writing the reg to a new slot before using it.
let candidates_inReg let candidates_inReg
= [ (temp, reg) = [ (temp, reg)
| (temp, InReg reg) <- ufmToList assig | (temp, InReg reg) <- nonDetUFMToList assig
, temp `notElem` keep' -- This is non-deterministic but we do not
, targetClassOfRealReg platform reg == classOfVirtualReg r ] -- currently support deterministic code-generation.
-- See Note [Unique Determinism and code generation]
, temp `notElem` keep'
, targetClassOfRealReg platform reg == classOfVirtualReg r ]
let result let result
...@@ -857,7 +869,7 @@ allocRegsAndSpill_spill reading keep spills alloc r rs assig spill_loc ...@@ -857,7 +869,7 @@ allocRegsAndSpill_spill reading keep spills alloc r rs assig spill_loc
= pprPanic ("RegAllocLinear.allocRegsAndSpill: no spill candidates\n") = pprPanic ("RegAllocLinear.allocRegsAndSpill: no spill candidates\n")
$ vcat $ vcat
[ text "allocating vreg: " <> text (show r) [ text "allocating vreg: " <> text (show r)
, text "assignment: " <> text (show $ ufmToList assig) , text "assignment: " <> ppr assig
, text "freeRegs: " <> text (show freeRegs) , text "freeRegs: " <> text (show freeRegs)
, text "initFreeRegs: " <> text (show (frInitFreeRegs platform `asTypeOf` freeRegs)) ] , text "initFreeRegs: " <> text (show (frInitFreeRegs platform `asTypeOf` freeRegs)) ]
......
...@@ -80,7 +80,6 @@ pprStats code statss ...@@ -80,7 +80,6 @@ pprStats code statss
$$ text "" $$ text ""
$$ text "-- spills-added" $$ text "-- spills-added"
$$ text "-- (reg_name, allocs, clobbers, loads, joinRR, joinRM)" $$ text "-- (reg_name, allocs, clobbers, loads, joinRR, joinRM)"
$$ (vcat $ map pprSpill $$ (pprUFMWithKeys spills (vcat . map pprSpill))
$ ufmToList spills)
$$ text "") $$ text "")
...@@ -462,10 +462,14 @@ slurpReloadCoalesce live ...@@ -462,10 +462,14 @@ slurpReloadCoalesce live
mergeSlotMaps :: UniqFM Reg -> UniqFM Reg -> UniqFM Reg mergeSlotMaps :: UniqFM Reg -> UniqFM Reg -> UniqFM Reg
mergeSlotMaps map1 map2 mergeSlotMaps map1 map2
= listToUFM = listToUFM
$ [ (k, r1) | (k, r1) <- ufmToList map1 $ [ (k, r1)
, case lookupUFM map2 k of | (k, r1) <- nonDetUFMToList map1
Nothing -> False -- This is non-deterministic but we do not
Just r2 -> r1 == r2 ] -- currently support deterministic code-generation.
-- See Note [Unique Determinism and code generation]
, case lookupUFM map2 k of
Nothing -> False
Just r2 -> r1 == r2 ]
-- | Strip away liveness information, yielding NatCmmDecl -- | Strip away liveness information, yielding NatCmmDecl
......
...@@ -66,7 +66,7 @@ import qualified Data.IntMap as M ...@@ -66,7 +66,7 @@ import qualified Data.IntMap as M
import Data.Data import Data.Data
import Data.List (sortBy) import Data.List (sortBy)
import Data.Function (on) import Data.Function (on)
import UniqFM (UniqFM, listToUFM_Directly, ufmToList, ufmToIntMap) import UniqFM (UniqFM, listToUFM_Directly, nonDetUFMToList, ufmToIntMap)
-- Note [Deterministic UniqFM] -- Note [Deterministic UniqFM]
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~ -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~
...@@ -372,7 +372,7 @@ instance Monoid (UniqDFM a) where ...@@ -372,7 +372,7 @@ instance Monoid (UniqDFM a) where
-- This should not be used in commited code, provided for convenience to -- This should not be used in commited code, provided for convenience to
-- make ad-hoc conversions when developing -- make ad-hoc conversions when developing
alwaysUnsafeUfmToUdfm :: UniqFM elt -> UniqDFM elt alwaysUnsafeUfmToUdfm :: UniqFM elt -> UniqDFM elt
alwaysUnsafeUfmToUdfm = listToUDFM_Directly . ufmToList alwaysUnsafeUfmToUdfm = listToUDFM_Directly . nonDetUFMToList
-- Output-ery -- Output-ery
......
...@@ -64,8 +64,8 @@ module UniqFM ( ...@@ -64,8 +64,8 @@ module UniqFM (
lookupWithDefaultUFM, lookupWithDefaultUFM_Directly, lookupWithDefaultUFM, lookupWithDefaultUFM_Directly,
nonDetEltsUFM, eltsUFM, nonDetKeysUFM, nonDetEltsUFM, eltsUFM, nonDetKeysUFM,
ufmToSet_Directly, ufmToSet_Directly,
nonDetUFMToList, ufmToList, ufmToIntMap, nonDetUFMToList, ufmToIntMap,
pprUniqFM, pprUFM, pluralUFM pprUniqFM, pprUFM, pprUFMWithKeys, pluralUFM
) where ) where
import Unique ( Uniquable(..), Unique, getKey ) import Unique ( Uniquable(..), Unique, getKey )
...@@ -184,7 +184,6 @@ lookupWithDefaultUFM_Directly ...@@ -184,7 +184,6 @@ lookupWithDefaultUFM_Directly
:: UniqFM elt -> elt -> Unique -> elt :: UniqFM elt -> elt -> Unique -> elt
eltsUFM :: UniqFM elt -> [elt] eltsUFM :: UniqFM elt -> [elt]
ufmToSet_Directly :: UniqFM elt -> S.IntSet ufmToSet_Directly :: UniqFM elt -> S.IntSet
ufmToList :: UniqFM elt -> [(Unique, elt)]
{- {-
************************************************************************ ************************************************************************
...@@ -286,7 +285,6 @@ lookupWithDefaultUFM (UFM m) v k = M.findWithDefault v (getKey $ getUnique k) m ...@@ -286,7 +285,6 @@ lookupWithDefaultUFM (UFM m) v k = M.findWithDefault v (getKey $ getUnique k) m
lookupWithDefaultUFM_Directly (UFM m) v u = M.findWithDefault v (getKey u) m lookupWithDefaultUFM_Directly (UFM m) v u = M.findWithDefault v (getKey u) m
eltsUFM (UFM m) = M.elems m eltsUFM (UFM m) = M.elems m
ufmToSet_Directly (UFM m) = M.keysSet m ufmToSet_Directly (UFM m) = M.keysSet m
ufmToList (UFM m) = map (\(k, v) -> (getUnique k, v)) $ M.toList m
anyUFM :: (elt -> Bool) -> UniqFM elt -> Bool anyUFM :: (elt -> Bool) -> UniqFM elt -> Bool
anyUFM p (UFM m) = M.fold ((||) . p) False m anyUFM p (UFM m) = M.fold ((||) . p) False m
...@@ -357,6 +355,18 @@ pprUFM :: UniqFM a -- ^ The things to be pretty printed ...@@ -357,6 +355,18 @@ pprUFM :: UniqFM a -- ^ The things to be pretty printed
-- printed -- printed
pprUFM ufm pp = pp (nonDetEltsUFM ufm) pprUFM ufm pp = pp (nonDetEltsUFM ufm)
-- | Pretty-print a non-deterministic set.
-- The order of variables is non-deterministic and for pretty-printing that
-- shouldn't be a problem.
-- Having this function helps contain the non-determinism created with
-- nonDetUFMToList.
pprUFMWithKeys
:: UniqFM a -- ^ The things to be pretty printed
-> ([(Unique, a)] -> SDoc) -- ^ The pretty printing function to use on the elements
-> SDoc -- ^ 'SDoc' where the things have been pretty
-- printed
pprUFMWithKeys ufm pp = pp (nonDetUFMToList ufm)
-- | Determines the pluralisation suffix appropriate for the length of a set -- | Determines the pluralisation suffix appropriate for the length of a set
-- in the same way that plural from Outputable does for lists. -- in the same way that plural from Outputable does for lists.
pluralUFM :: UniqFM a -> SDoc pluralUFM :: UniqFM a -> SDoc
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment