c86ef9e34aff51e095265d1597a27ba8f3c7ccb7
[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 (dopt 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 when (dopt Opt_GranMacros dflags &&
55 (node `elem` map snd regs || node_reqd)) $
56 do fetch
57 reschedule liveness node_reqd
58 where
59 liveness = mkRegLiveness regs 0 0
60
61 fetch :: FCode ()
62 fetch = panic "granFetch"
63 -- Was: absC (CMacroStmt GRAN_FETCH [])
64 --HWL: generate GRAN_FETCH macro for GrAnSim
65 -- currently GRAN_FETCH and GRAN_FETCH_AND_RESCHEDULE are miai
66
67 reschedule :: StgWord -> Bool -> Code
68 reschedule _liveness _node_reqd = panic "granReschedule"
69 -- Was: absC (CMacroStmt GRAN_RESCHEDULE [
70 -- mkIntCLit (I# (word2Int# liveness_mask)),
71 -- mkIntCLit (if node_reqd then 1 else 0)])
72
73
74 -------------------------
75 -- The @GRAN_YIELD@ macro is taken from JSM's code for Concurrent Haskell. It
76 -- allows to context-switch at places where @node@ is not alive (it uses the
77 -- @Continue@ rather than the @EnterNodeCode@ function in the RTS). We emit
78 -- this kind of macro at the beginning of the following kinds of basic bocks:
79 -- \begin{itemize}
80 -- \item Slow entry code where node is not alive (see @CgClosure.lhs@). Normally
81 -- we use @fetchAndReschedule@ at a slow entry code.
82 -- \item Fast entry code (see @CgClosure.lhs@).
83 -- \item Alternatives in case expressions (@CLabelledCode@ structures), provided
84 -- that they are not inlined (see @CgCases.lhs@). These alternatives will
85 -- be turned into separate functions.
86
87 granYield :: [(Id,GlobalReg)] -- Live registers
88 -> Bool -- Node reqd?
89 -> Code
90
91 granYield regs node_reqd
92 = do dflags <- getDynFlags
93 when (dopt Opt_GranMacros dflags && node_reqd) $ yield liveness
94 where
95 liveness = mkRegLiveness regs 0 0
96
97 yield :: StgWord -> Code
98 yield _liveness = panic "granYield"
99 -- Was : absC (CMacroStmt GRAN_YIELD
100 -- [mkIntCLit (I# (word2Int# liveness_mask))])
101
102