Merging in the new codegen branch
[ghc-hetmet.git] / compiler / codeGen / StgCmmGran.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/Commentary/CodingStyle#Warnings
16 -- for details
17
18 module StgCmmGran (
19         staticGranHdr,staticParHdr,
20         granThunk, granYield,
21         doGranAllocate
22   ) where
23
24 -- This entire module consists of no-op stubs at the moment
25 -- GranSim worked once, but it certainly doesn't any more
26 -- I've left the calls, though, in case anyone wants to resurrect it
27
28 import StgCmmMonad
29 import Id
30 import Cmm
31
32 staticGranHdr :: [CmmLit]
33 staticGranHdr = []
34
35 staticParHdr :: [CmmLit]
36 staticParHdr = []
37
38 doGranAllocate :: VirtualHpOffset -> FCode ()
39 -- Must be lazy in the amount of allocation
40 doGranAllocate n = return ()
41
42 granFetchAndReschedule :: [(Id,GlobalReg)] -> Bool -> FCode ()
43 granFetchAndReschedule regs node_reqd = return ()
44
45 granYield :: [LocalReg] -> Bool -> FCode ()
46 granYield regs node_reqd = return ()
47
48 granThunk :: Bool -> FCode ()
49 granThunk node_points = return ()
50
51 -----------------------------------------------------------------
52 {-   ------- Everything below here is commented out -------------
53 -----------------------------------------------------------------
54
55 -- Parallel header words in a static closure
56 staticParHdr :: [CmmLit]
57 -- Parallel header words in a static closure
58 staticParHdr = []
59
60 staticGranHdr :: [CmmLit]
61 -- Gransim header words in a static closure
62 staticGranHdr = []
63
64 doGranAllocate :: CmmExpr -> Code       
65 -- macro DO_GRAN_ALLOCATE
66 doGranAllocate hp 
67   | not opt_GranMacros = nopC
68   | otherwise          = panic "doGranAllocate"
69
70
71
72 -------------------------
73 granThunk :: Bool -> FCode ()
74 -- HWL: insert macros for GrAnSim; 2 versions depending on liveness of node
75 -- (we prefer fetchAndReschedule-style context switches to yield ones)
76 granThunk node_points 
77   | node_points = granFetchAndReschedule [] node_points 
78   | otherwise   = granYield              [] node_points
79
80 granFetchAndReschedule :: [(Id,GlobalReg)]  -- Live registers
81                        -> Bool                  -- Node reqd?
82                        -> Code
83 -- Emit code for simulating a fetch and then reschedule.
84 granFetchAndReschedule regs node_reqd
85   | opt_GranMacros && (node `elem` map snd regs || node_reqd)
86   = do { fetch
87        ; reschedule liveness node_reqd }
88   | otherwise
89   = nopC
90   where
91     liveness = mkRegLiveness regs 0 0
92
93 fetch = panic "granFetch"
94         -- Was: absC (CMacroStmt GRAN_FETCH [])
95         --HWL: generate GRAN_FETCH macro for GrAnSim
96         --     currently GRAN_FETCH and GRAN_FETCH_AND_RESCHEDULE are miai
97
98 reschedule liveness node_reqd = panic "granReschedule"
99         -- Was: absC  (CMacroStmt GRAN_RESCHEDULE [
100         --                mkIntCLit (I# (word2Int# liveness_mask)), 
101         --                mkIntCLit (if node_reqd then 1 else 0)])
102     
103
104 -------------------------
105 -- The @GRAN_YIELD@ macro is taken from JSM's  code for Concurrent Haskell. It
106 -- allows to context-switch at  places where @node@ is  not alive (it uses the
107 -- @Continue@ rather  than the @EnterNodeCode@  function in the  RTS). We emit
108 -- this kind of macro at the beginning of the following kinds of basic bocks:
109 -- \begin{itemize}
110 --  \item Slow entry code where node is not alive (see @CgClosure.lhs@). Normally 
111 --        we use @fetchAndReschedule@ at a slow entry code.
112 --  \item Fast entry code (see @CgClosure.lhs@).
113 --  \item Alternatives in case expressions (@CLabelledCode@ structures), provided
114 --        that they are not inlined (see @CgCases.lhs@). These alternatives will 
115 --        be turned into separate functions.
116
117 granYield :: [(Id,GlobalReg)]   -- Live registers
118           -> Bool               -- Node reqd?
119           -> Code 
120
121 granYield regs node_reqd
122   | opt_GranMacros && node_reqd = yield liveness
123   | otherwise                   = nopC
124   where
125      liveness = mkRegLiveness regs 0 0
126
127 yield liveness = panic "granYield"
128         -- Was : absC (CMacroStmt GRAN_YIELD 
129         --                  [mkIntCLit (I# (word2Int# liveness_mask))])
130
131 -}