Add a class HasDynFlags(getDynFlags)
[ghc.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 -fno-warn-tabs #-}
12 -- The above warning supression flag is a temporary kludge.
13 -- While working on this module you are encouraged to remove it and
14 -- detab the module (please do the detabbing in a separate patch). See
15 -- http://hackage.haskell.org/trac/ghc/wiki/Commentary/CodingStyle#TabsvsSpaces
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 CmmExpr
30
31 staticGranHdr :: [CmmLit]
32 staticGranHdr = []
33
34 staticParHdr :: [CmmLit]
35 staticParHdr = []
36
37 doGranAllocate :: VirtualHpOffset -> FCode ()
38 -- Must be lazy in the amount of allocation
39 doGranAllocate _ = return ()
40
41 granYield :: [LocalReg] -> Bool -> FCode ()
42 granYield _regs _node_reqd = return ()
43
44 granThunk :: Bool -> FCode ()
45 granThunk _node_points = return ()
46
47 -----------------------------------------------------------------
48 {- ------- Everything below here is commented out -------------
49 -----------------------------------------------------------------
50
51 -- Parallel header words in a static closure
52 staticParHdr :: [CmmLit]
53 -- Parallel header words in a static closure
54 staticParHdr = []
55
56 staticGranHdr :: [CmmLit]
57 -- Gransim header words in a static closure
58 staticGranHdr = []
59
60 doGranAllocate :: CmmExpr -> Code
61 -- macro DO_GRAN_ALLOCATE
62 doGranAllocate hp
63 | not opt_GranMacros = nopC
64 | otherwise = panic "doGranAllocate"
65
66
67
68 -------------------------
69 granThunk :: Bool -> FCode ()
70 -- HWL: insert macros for GrAnSim; 2 versions depending on liveness of node
71 -- (we prefer fetchAndReschedule-style context switches to yield ones)
72 granThunk node_points
73 | node_points = granFetchAndReschedule [] node_points
74 | otherwise = granYield [] node_points
75
76 granFetchAndReschedule :: [(Id,GlobalReg)] -- Live registers
77 -> Bool -- Node reqd?
78 -> Code
79 -- Emit code for simulating a fetch and then reschedule.
80 granFetchAndReschedule regs node_reqd
81 | opt_GranMacros && (node `elem` map snd regs || node_reqd)
82 = do { fetch
83 ; reschedule liveness node_reqd }
84 | otherwise
85 = nopC
86 where
87 liveness = mkRegLiveness regs 0 0
88
89 fetch = panic "granFetch"
90 -- Was: absC (CMacroStmt GRAN_FETCH [])
91 --HWL: generate GRAN_FETCH macro for GrAnSim
92 -- currently GRAN_FETCH and GRAN_FETCH_AND_RESCHEDULE are miai
93
94 reschedule liveness node_reqd = panic "granReschedule"
95 -- Was: absC (CMacroStmt GRAN_RESCHEDULE [
96 -- mkIntCLit (I# (word2Int# liveness_mask)),
97 -- mkIntCLit (if node_reqd then 1 else 0)])
98
99
100 -------------------------
101 -- The @GRAN_YIELD@ macro is taken from JSM's code for Concurrent Haskell. It
102 -- allows to context-switch at places where @node@ is not alive (it uses the
103 -- @Continue@ rather than the @EnterNodeCode@ function in the RTS). We emit
104 -- this kind of macro at the beginning of the following kinds of basic bocks:
105 -- \begin{itemize}
106 -- \item Slow entry code where node is not alive (see @CgClosure.lhs@). Normally
107 -- we use @fetchAndReschedule@ at a slow entry code.
108 -- \item Fast entry code (see @CgClosure.lhs@).
109 -- \item Alternatives in case expressions (@CLabelledCode@ structures), provided
110 -- that they are not inlined (see @CgCases.lhs@). These alternatives will
111 -- be turned into separate functions.
112
113 granYield :: [(Id,GlobalReg)] -- Live registers
114 -> Bool -- Node reqd?
115 -> Code
116
117 granYield regs node_reqd
118 | opt_GranMacros && node_reqd = yield liveness
119 | otherwise = nopC
120 where
121 liveness = mkRegLiveness regs 0 0
122
123 yield liveness = panic "granYield"
124 -- Was : absC (CMacroStmt GRAN_YIELD
125 -- [mkIntCLit (I# (word2Int# liveness_mask))])
126
127 -}