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