Some alpha renaming
[ghc.git] / compiler / codeGen / CgParallel.hs
1 -----------------------------------------------------------------------------
2 --
3 -- (c) The University of Glasgow -2006
4 --
5 -- Code generation relaed to GpH
6 -- (a) parallel
7 -- (b) GranSim
8 --
9 -----------------------------------------------------------------------------
10
11 module CgParallel(
12 staticGranHdr,staticParHdr,
13 granFetchAndReschedule, granYield,
14 doGranAllocate
15 ) where
16
17 import CgMonad
18 import CgCallConv
19 import DynFlags
20 import Id
21 import OldCmm
22 import Outputable
23 import SMRep
24
25 import Control.Monad
26
27 staticParHdr :: [CmmLit]
28 -- Parallel header words in a static closure
29 staticParHdr = []
30
31 --------------------------------------------------------
32 -- GranSim stuff
33 --------------------------------------------------------
34
35 staticGranHdr :: [CmmLit]
36 -- Gransim header words in a static closure
37 staticGranHdr = []
38
39 doGranAllocate :: CmmExpr -> Code
40 -- macro DO_GRAN_ALLOCATE
41 doGranAllocate _hp
42 = do dflags <- getDynFlags
43 when (gopt Opt_GranMacros dflags) $ panic "doGranAllocate"
44
45
46
47 -------------------------
48 granFetchAndReschedule :: [(Id,GlobalReg)] -- Live registers
49 -> Bool -- Node reqd?
50 -> Code
51 -- Emit code for simulating a fetch and then reschedule.
52 granFetchAndReschedule regs node_reqd
53 = do dflags <- getDynFlags
54 let liveness = mkRegLiveness dflags regs 0 0
55 when (gopt Opt_GranMacros dflags &&
56 (node `elem` map snd regs || node_reqd)) $
57 do fetch
58 reschedule liveness node_reqd
59
60 fetch :: FCode ()
61 fetch = panic "granFetch"
62 -- Was: absC (CMacroStmt GRAN_FETCH [])
63 --HWL: generate GRAN_FETCH macro for GrAnSim
64 -- currently GRAN_FETCH and GRAN_FETCH_AND_RESCHEDULE are miai
65
66 reschedule :: StgWord -> Bool -> Code
67 reschedule _liveness _node_reqd = panic "granReschedule"
68 -- Was: absC (CMacroStmt GRAN_RESCHEDULE [
69 -- mkIntCLit (I# (word2Int# liveness_mask)),
70 -- mkIntCLit (if node_reqd then 1 else 0)])
71
72
73 -------------------------
74 -- The @GRAN_YIELD@ macro is taken from JSM's code for Concurrent Haskell. It
75 -- allows to context-switch at places where @node@ is not alive (it uses the
76 -- @Continue@ rather than the @EnterNodeCode@ function in the RTS). We emit
77 -- this kind of macro at the beginning of the following kinds of basic bocks:
78 -- \begin{itemize}
79 -- \item Slow entry code where node is not alive (see @CgClosure.lhs@). Normally
80 -- we use @fetchAndReschedule@ at a slow entry code.
81 -- \item Fast entry code (see @CgClosure.lhs@).
82 -- \item Alternatives in case expressions (@CLabelledCode@ structures), provided
83 -- that they are not inlined (see @CgCases.lhs@). These alternatives will
84 -- be turned into separate functions.
85
86 granYield :: [(Id,GlobalReg)] -- Live registers
87 -> Bool -- Node reqd?
88 -> Code
89
90 granYield regs node_reqd
91 = do dflags <- getDynFlags
92 let liveness = mkRegLiveness dflags regs 0 0
93 when (gopt Opt_GranMacros dflags && node_reqd) $ yield liveness
94
95 yield :: StgWord -> Code
96 yield _liveness = panic "granYield"
97 -- Was : absC (CMacroStmt GRAN_YIELD
98 -- [mkIntCLit (I# (word2Int# liveness_mask))])
99
100