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