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