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