[project @ 1998-02-05 12:23:33 by simonm]
[ghc-hetmet.git] / ghc / compiler / nativeGen / StixMacro.lhs
index d49158b..ab0ecc4 100644 (file)
@@ -1,29 +1,25 @@
 %
-% (c) The AQUA Project, Glasgow University, 1993-1995
+% (c) The AQUA Project, Glasgow University, 1993-1996
 %
 
 \begin{code}
-#include "HsVersions.h"
-
-module StixMacro (
-       genMacroCode, doHeapCheck, smStablePtrTable,
+module StixMacro ( macroCode, heapCheck ) where
 
-       Target, StixTree, SplitUniqSupply, CAddrMode, CExprMacro,
-       CStmtMacro
-    ) where
+#include "HsVersions.h"
 
-import AbsCSyn
-import AbsPrel      ( PrimOp(..)
-                     IF_ATTACK_PRAGMAS(COMMA tagOf_PrimOp)
-                         IF_ATTACK_PRAGMAS(COMMA pprPrimOp)
-                   )
-import MachDesc            {- lots -}
-import CgCompInfo   ( sTD_UF_SIZE, uF_RET, uF_SUA, uF_SUB, uF_UPDATEE )
+import {-# SOURCE #-} StixPrim ( amodeToStix )
+
+import MachMisc
+import MachRegs
+import AbsCSyn         ( CStmtMacro(..), MagicId(..), mkIntCLit, CAddrMode )
+import Constants       ( uF_RET, uF_SUA, uF_SUB, uF_UPDATEE,
+                         sTD_UF_SIZE
+                       )
+import OrdList         ( OrdList )
+import PrimOp          ( PrimOp(..) )
+import PrimRep         ( PrimRep(..) )
 import Stix
-import SplitUniq
-import Unique
-import Util
-
+import UniqSupply      ( returnUs, thenUs, UniqSM )
 \end{code}
 
 The @ARGS_CHK_A{_LOAD_NODE}@ macros check for sufficient arguments on
@@ -35,32 +31,31 @@ closure address.
 mkIntCLit_0 = mkIntCLit 0 -- out here to avoid CAF (sigh)
 mkIntCLit_3 = mkIntCLit 3
 
-genMacroCode 
-    :: Target 
-    -> CStmtMacro          -- statement macro
+macroCode
+    :: CStmtMacro          -- statement macro
     -> [CAddrMode]         -- args
-    -> SUniqSM StixTreeList
+    -> UniqSM StixTreeList
 
-genMacroCode target ARGS_CHK_A_LOAD_NODE args = 
-    getUniqLabelNCG                                    `thenSUs` \ ulbl ->
-    let [words, lbl] = map (amodeToStix target) args
-       temp = StIndex PtrKind stgSpA words
-       test = StPrim AddrGeOp [stgSuA, temp]
-       cjmp = StCondJump ulbl test
-       assign = StAssign PtrKind stgNode lbl
-       join = StLabel ulbl
+macroCode ARGS_CHK_A_LOAD_NODE args
+  = getUniqLabelNCG                                    `thenUs` \ ulbl ->
+    let
+         [words, lbl] = map amodeToStix args
+         temp = StIndex PtrRep stgSpA words
+         test = StPrim AddrGeOp [stgSuA, temp]
+         cjmp = StCondJump ulbl test
+         assign = StAssign PtrRep stgNode lbl
+         join = StLabel ulbl
     in
-       returnSUs (\xs -> cjmp : assign : updatePAP : join : xs)
+    returnUs (\xs -> cjmp : assign : updatePAP : join : xs)
 
-genMacroCode target ARGS_CHK_A [words] = 
-    getUniqLabelNCG                                    `thenSUs` \ ulbl ->
-    let temp = StIndex PtrKind stgSpA (amodeToStix target words)
+macroCode ARGS_CHK_A [words]
+  = getUniqLabelNCG                                    `thenUs` \ ulbl ->
+    let temp = StIndex PtrRep stgSpA (amodeToStix words)
        test = StPrim AddrGeOp [stgSuA, temp]
        cjmp = StCondJump ulbl test
        join = StLabel ulbl
     in
-       returnSUs (\xs -> cjmp : updatePAP : join : xs)
-
+    returnUs (\xs -> cjmp : updatePAP : join : xs)
 \end{code}
 
 Like the macros above, the @ARGS_CHK_B{_LOAD_NODE}@ macros check for
@@ -70,44 +65,43 @@ also loads R1 with an appropriate closure address.  Note that the
 directions are swapped relative to the A stack.
 
 \begin{code}
-
-genMacroCode target ARGS_CHK_B_LOAD_NODE args = 
-    getUniqLabelNCG                                    `thenSUs` \ ulbl ->
-    let [words, lbl] = map (amodeToStix target) args
-       temp = StIndex PtrKind stgSuB (StPrim IntNegOp [words])
+macroCode ARGS_CHK_B_LOAD_NODE args
+  = getUniqLabelNCG                                    `thenUs` \ ulbl ->
+    let
+       [words, lbl] = map amodeToStix args
+       temp = StIndex PtrRep stgSuB (StPrim IntNegOp [words])
        test = StPrim AddrGeOp [stgSpB, temp]
        cjmp = StCondJump ulbl test
-       assign = StAssign PtrKind stgNode lbl
+       assign = StAssign PtrRep stgNode lbl
        join = StLabel ulbl
     in
-       returnSUs (\xs -> cjmp : assign : updatePAP : join : xs)
+    returnUs (\xs -> cjmp : assign : updatePAP : join : xs)
 
-genMacroCode target ARGS_CHK_B [words] = 
-    getUniqLabelNCG                                    `thenSUs` \ ulbl ->
-    let        temp = StIndex PtrKind stgSuB (StPrim IntNegOp [amodeToStix target words])
+macroCode ARGS_CHK_B [words]
+  = getUniqLabelNCG                                    `thenUs` \ ulbl ->
+    let
+       temp = StIndex PtrRep stgSuB (StPrim IntNegOp [amodeToStix words])
        test = StPrim AddrGeOp [stgSpB, temp]
        cjmp = StCondJump ulbl test
        join = StLabel ulbl
     in
-       returnSUs (\xs -> cjmp : updatePAP : join : xs)
-
+    returnUs (\xs -> cjmp : updatePAP : join : xs)
 \end{code}
 
 The @HEAP_CHK@ macro checks to see that there are enough words
 available in the heap (before reaching @HpLim@).  When a heap check
 fails, it has to call @PerformGC@ via the @PerformGC_wrapper@.  The
-call wrapper saves all of our volatile registers so that we don't have to.
+call wrapper saves all of our volatile registers so that we don't have
+to.
 
-Since there are @HEAP_CHK@s buried at unfortunate places in the integer
-primOps, this is just a wrapper.
+Since there are @HEAP_CHK@s buried at unfortunate places in the
+integer primOps, this is just a wrapper.
 
 \begin{code}
-
-genMacroCode target HEAP_CHK args =
-    let [liveness,words,reenter] = map (amodeToStix target) args
+macroCode HEAP_CHK args
+  = let [liveness,words,reenter] = map amodeToStix args
     in
-       doHeapCheck target liveness words reenter
-
+    heapCheck liveness words reenter
 \end{code}
 
 The @STK_CHK@ macro checks for enough space on the stack between @SpA@
@@ -117,40 +111,39 @@ enough space to continue.  Not that @_StackOverflow@ doesn't return,
 so we don't have to @callWrapper@ it.
 
 \begin{code}
-
-genMacroCode target STK_CHK [liveness, aWords, bWords, spa, spb, prim, reenter] = 
+macroCode STK_CHK [liveness, aWords, bWords, spa, spb, prim, reenter]
+  =
 {- Need to check to see if we are compiling with stack checks
-    getUniqLabelNCG                                    `thenSUs` \ ulbl ->
-    let words = StPrim IntNegOp 
-           [StPrim IntAddOp [amodeToStix target aWords, amodeToStix target bWords]]
-       temp = StIndex PtrKind stgSpA words
+   getUniqLabelNCG                                     `thenUs` \ ulbl ->
+    let words = StPrim IntNegOp
+           [StPrim IntAddOp [amodeToStix aWords, amodeToStix bWords]]
+       temp = StIndex PtrRep stgSpA words
        test = StPrim AddrGtOp [temp, stgSpB]
        cjmp = StCondJump ulbl test
        join = StLabel ulbl
     in
-       returnSUs (\xs -> cjmp : stackOverflow : join : xs)
+       returnUs (\xs -> cjmp : stackOverflow : join : xs)
 -}
-    returnSUs id
-
+    returnUs id
 \end{code}
 
-@UPD_CAF@ involves changing the info pointer of the closure, adding an indirection,
-and putting the new CAF on a linked list for the storage manager.
+@UPD_CAF@ involves changing the info pointer of the closure, adding an
+indirection, and putting the new CAF on a linked list for the storage
+manager.
 
 \begin{code}
-
-genMacroCode target UPD_CAF args =
-    let [cafptr,bhptr] = map (amodeToStix target) args
-       w0 = StInd PtrKind cafptr
-       w1 = StInd PtrKind (StIndex PtrKind cafptr (StInt 1))
-       w2 = StInd PtrKind (StIndex PtrKind cafptr (StInt 2))
-       a1 = StAssign PtrKind w0 caf_info
-       a2 = StAssign PtrKind w1 smCAFlist
-       a3 = StAssign PtrKind w2 bhptr
-       a4 = StAssign PtrKind smCAFlist cafptr
+macroCode UPD_CAF args
+  = let
+       [cafptr,bhptr] = map amodeToStix args
+       w0 = StInd PtrRep cafptr
+       w1 = StInd PtrRep (StIndex PtrRep cafptr (StInt 1))
+       w2 = StInd PtrRep (StIndex PtrRep cafptr (StInt 2))
+       a1 = StAssign PtrRep w0 caf_info
+       a2 = StAssign PtrRep w1 smCAFlist
+       a3 = StAssign PtrRep w2 bhptr
+       a4 = StAssign PtrRep smCAFlist cafptr
     in
-       returnSUs (\xs -> a1 : a2 : a3 : a4 : xs)
-
+    returnUs (\xs -> a1 : a2 : a3 : a4 : xs)
 \end{code}
 
 @UPD_IND@ is complicated by the fact that we are supporting the
@@ -158,58 +151,53 @@ Appel-style garbage collector by default.  This means some extra work
 if we update an old generation object.
 
 \begin{code}
-
-genMacroCode target UPD_IND args = 
-    getUniqLabelNCG                                    `thenSUs` \ ulbl ->
-    let [updptr, heapptr] = map (amodeToStix target) args
+macroCode UPD_IND args
+  = getUniqLabelNCG                                    `thenUs` \ ulbl ->
+    let
+       [updptr, heapptr] = map amodeToStix args
        test = StPrim AddrGtOp [updptr, smOldLim]
        cjmp = StCondJump ulbl test
-       updRoots = StAssign PtrKind smOldMutables updptr
+       updRoots = StAssign PtrRep smOldMutables updptr
        join = StLabel ulbl
-       upd0 = StAssign PtrKind (StInd PtrKind updptr) ind_info
-       upd1 = StAssign PtrKind (StInd PtrKind 
-               (StIndex PtrKind updptr (StInt 1))) smOldMutables
-       upd2 = StAssign PtrKind (StInd PtrKind 
-               (StIndex PtrKind updptr (StInt 2))) heapptr
+       upd0 = StAssign PtrRep (StInd PtrRep updptr) ind_info
+       upd1 = StAssign PtrRep (StInd PtrRep
+               (StIndex PtrRep updptr (StInt 1))) smOldMutables
+       upd2 = StAssign PtrRep (StInd PtrRep
+               (StIndex PtrRep updptr (StInt 2))) heapptr
     in
-       returnSUs (\xs -> cjmp : upd1 : updRoots : join : upd0 : upd2 : xs)
-
+    returnUs (\xs -> cjmp : upd1 : updRoots : join : upd0 : upd2 : xs)
 \end{code}
 
 @UPD_INPLACE_NOPTRS@ is only needed for ticky-ticky profiling.
 
 \begin{code}
-
-genMacroCode target UPD_INPLACE_NOPTRS args = returnSUs id
-
+macroCode UPD_INPLACE_NOPTRS args = returnUs id
 \end{code}
 
 @UPD_INPLACE_PTRS@ is complicated by the fact that we are supporting
-the Appel-style garbage collector by default.  This means some extra work 
-if we update an old generation object.
+the Appel-style garbage collector by default.  This means some extra
+work if we update an old generation object.
 
 \begin{code}
-
-genMacroCode target UPD_INPLACE_PTRS [liveness] =
-    getUniqLabelNCG                                    `thenSUs` \ ulbl ->
+macroCode UPD_INPLACE_PTRS [liveness]
+  = getUniqLabelNCG                                    `thenUs` \ ulbl ->
     let cjmp = StCondJump ulbl testOldLim
-        testOldLim = StPrim AddrGtOp [stgNode, smOldLim]
+       testOldLim = StPrim AddrGtOp [stgNode, smOldLim]
        join = StLabel ulbl
-        updUpd0 = StAssign PtrKind (StInd PtrKind stgNode) ind_info
-       updUpd1 = StAssign PtrKind (StInd PtrKind 
-                   (StIndex PtrKind stgNode (StInt 1))) smOldMutables
-       updUpd2 = StAssign PtrKind (StInd PtrKind 
-                   (StIndex PtrKind stgNode (StInt 2))) hpBack2
-       hpBack2 = StIndex PtrKind stgHp (StInt (-2))
-       updOldMutables = StAssign PtrKind smOldMutables stgNode
-       updUpdReg = StAssign PtrKind stgNode hpBack2
+       updUpd0 = StAssign PtrRep (StInd PtrRep stgNode) ind_info
+       updUpd1 = StAssign PtrRep (StInd PtrRep
+                   (StIndex PtrRep stgNode (StInt 1))) smOldMutables
+       updUpd2 = StAssign PtrRep (StInd PtrRep
+                   (StIndex PtrRep stgNode (StInt 2))) hpBack2
+       hpBack2 = StIndex PtrRep stgHp (StInt (-2))
+       updOldMutables = StAssign PtrRep smOldMutables stgNode
+       updUpdReg = StAssign PtrRep stgNode hpBack2
     in
-       genMacroCode target HEAP_CHK [liveness, mkIntCLit_3, mkIntCLit_0]
-                                                       `thenSUs` \ heap_chk ->
-       returnSUs (\xs -> (cjmp : 
-                           heap_chk (updUpd0 : updUpd1 : updUpd2 : 
-                                       updOldMutables : updUpdReg : join : xs)))
-
+    macroCode HEAP_CHK [liveness, mkIntCLit_3, mkIntCLit_0]
+                                                   `thenUs` \ heap_chk ->
+    returnUs (\xs -> (cjmp :
+                       heap_chk (updUpd0 : updUpd1 : updUpd2 :
+                                   updOldMutables : updUpdReg : join : xs)))
 \end{code}
 
 @UPD_BH_UPDATABLE@ is only used when running concurrent threads (in
@@ -217,123 +205,94 @@ the sequential case, the GC takes care of this).  However, we do need
 to handle @UPD_BH_SINGLE_ENTRY@ in all cases.
 
 \begin{code}
+macroCode UPD_BH_UPDATABLE args = returnUs id
 
-genMacroCode target UPD_BH_UPDATABLE args = returnSUs id
-
-genMacroCode target UPD_BH_SINGLE_ENTRY [arg] =
-    let
-       update = StAssign PtrKind (StInd PtrKind (amodeToStix target arg)) bh_info
+macroCode UPD_BH_SINGLE_ENTRY [arg]
+  = let
+       update = StAssign PtrRep (StInd PtrRep (amodeToStix arg)) bh_info
     in
-        returnSUs (\xs -> update : xs)
-
+    returnUs (\xs -> update : xs)
 \end{code}
 
 Push a four word update frame on the stack and slide the Su[AB]
 registers to the current Sp[AB] locations.
 
 \begin{code}
-
-genMacroCode target PUSH_STD_UPD_FRAME args =
-    let [bhptr, aWords, bWords] = map (amodeToStix target) args
-       frame n = StInd PtrKind 
-           (StIndex PtrKind stgSpB (StPrim IntAddOp 
+macroCode PUSH_STD_UPD_FRAME args
+  = let
+       [bhptr, aWords, bWords] = map amodeToStix args
+       frame n = StInd PtrRep
+           (StIndex PtrRep stgSpB (StPrim IntAddOp
                [bWords, StInt (toInteger (sTD_UF_SIZE - n))]))
 
-       a1 = StAssign PtrKind (frame uF_RET) stgRetReg
-       a2 = StAssign PtrKind (frame uF_SUB) stgSuB
-       a3 = StAssign PtrKind (frame uF_SUA) stgSuA
-       a4 = StAssign PtrKind (frame uF_UPDATEE) bhptr
+       a1 = StAssign PtrRep (frame uF_RET) stgRetReg
+       a2 = StAssign PtrRep (frame uF_SUB) stgSuB
+       a3 = StAssign PtrRep (frame uF_SUA) stgSuA
+       a4 = StAssign PtrRep (frame uF_UPDATEE) bhptr
 
-       updSuB = StAssign PtrKind
-           stgSuB (StIndex PtrKind stgSpB (StPrim IntAddOp 
+       updSuB = StAssign PtrRep
+           stgSuB (StIndex PtrRep stgSpB (StPrim IntAddOp
                [bWords, StInt (toInteger sTD_UF_SIZE)]))
-       updSuA = StAssign PtrKind
-           stgSuA (StIndex PtrKind stgSpA (StPrim IntNegOp [aWords]))
+       updSuA = StAssign PtrRep
+           stgSuA (StIndex PtrRep stgSpA (StPrim IntNegOp [aWords]))
     in
-       returnSUs (\xs -> a1 : a2 : a3 : a4 : updSuB : updSuA : xs)
-
+    returnUs (\xs -> a1 : a2 : a3 : a4 : updSuB : updSuA : xs)
 \end{code}
 
 Pop a standard update frame.
 
 \begin{code}
+macroCode POP_STD_UPD_FRAME args
+  = let
+       frame n = StInd PtrRep (StIndex PtrRep stgSpB (StInt (toInteger (-n))))
 
-genMacroCode target POP_STD_UPD_FRAME args =
-    let frame n = StInd PtrKind (StIndex PtrKind stgSpB (StInt (toInteger (-n))))
-
-       grabRet = StAssign PtrKind stgRetReg (frame uF_RET)
-       grabSuB = StAssign PtrKind stgSuB    (frame uF_SUB)
-       grabSuA = StAssign PtrKind stgSuA    (frame uF_SUA)
+       grabRet = StAssign PtrRep stgRetReg (frame uF_RET)
+       grabSuB = StAssign PtrRep stgSuB    (frame uF_SUB)
+       grabSuA = StAssign PtrRep stgSuA    (frame uF_SUA)
 
-       updSpB = StAssign PtrKind
-           stgSpB (StIndex PtrKind stgSpB (StInt (toInteger (-sTD_UF_SIZE))))
+       updSpB = StAssign PtrRep
+           stgSpB (StIndex PtrRep stgSpB (StInt (toInteger (-sTD_UF_SIZE))))
     in
-       returnSUs (\xs -> grabRet : grabSuB : grabSuA : updSpB : xs)
-
-\end{code}
-
-@PUSH_CON_UPD_FRAME@ appears to be unused at the moment.
-
-\begin{code}
-{- UNUSED:
-genMacroCode target PUSH_CON_UPD_FRAME args = 
-    panic "genMacroCode:PUSH_CON_UPD_FRAME"
--}
-\end{code}
-
-The @SET_ARITY@ and @CHK_ARITY@ macros are disabled for ``normal'' compilation.
-
-\begin{code}
-
-genMacroCode target SET_ARITY args = returnSUs id
-genMacroCode target CHK_ARITY args = returnSUs id
-
+    returnUs (\xs -> grabRet : grabSuB : grabSuA : updSpB : xs)
 \end{code}
 
 This one only applies if we have a machine register devoted to TagReg.
-
 \begin{code}
-
-genMacroCode target SET_TAG [tag] = 
-    let set_tag = StAssign IntKind stgTagReg (amodeToStix target tag)
+macroCode SET_TAG [tag]
+  = let set_tag = StAssign IntRep stgTagReg (amodeToStix tag)
     in
-        case stgReg target TagReg of
-            Always _ -> returnSUs id
-            Save _ -> returnSUs (\xs -> set_tag : xs)
-
+    case stgReg TagReg of
+      Always _ -> returnUs id
+      Save   _ -> returnUs (\ xs -> set_tag : xs)
 \end{code}
 
 Do the business for a @HEAP_CHK@, having converted the args to Trees
 of StixOp.
 
 \begin{code}
-
-doHeapCheck 
-    :: Target 
-    -> StixTree        -- liveness
+heapCheck
+    :: StixTree        -- liveness
     -> StixTree        -- words needed
     -> StixTree        -- always reenter node? (boolean)
-    -> SUniqSM StixTreeList
+    -> UniqSM StixTreeList
 
-doHeapCheck target liveness words reenter =
-    getUniqLabelNCG                                    `thenSUs` \ ulbl ->
-    let newHp = StIndex PtrKind stgHp words
-       assign = StAssign PtrKind stgHp newHp
+heapCheck liveness words reenter
+  = getUniqLabelNCG                                    `thenUs` \ ulbl ->
+    let newHp = StIndex PtrRep stgHp words
+       assign = StAssign PtrRep stgHp newHp
        test = StPrim AddrLeOp [stgHp, stgHpLim]
        cjmp = StCondJump ulbl test
-        arg = StPrim IntAddOp [StPrim IntMulOp [words, StInt 256], liveness]
+       arg = StPrim IntAddOp [StPrim IntMulOp [words, StInt 256], liveness]
        -- ToDo: Overflow?  (JSM)
-       gc = StCall SLIT("PerformGC_wrapper") VoidKind [arg]
+       gc = StCall SLIT("PerformGC_wrapper") VoidRep [arg]
        join = StLabel ulbl
     in
-       returnSUs (\xs -> assign : cjmp : gc : join : xs)
-
+    returnUs (\xs -> assign : cjmp : gc : join : xs)
 \end{code}
 
 Let's make sure that these CAFs are lifted out, shall we?
 
 \begin{code}
-
 -- Some common labels
 
 bh_info, caf_info, ind_info :: StixTree
@@ -347,35 +306,5 @@ ind_info  = sStLitLbl SLIT("Ind_info")
 updatePAP, stackOverflow :: StixTree
 
 updatePAP     = StJump (sStLitLbl SLIT("UpdatePAP"))
-stackOverflow = StCall SLIT("StackOverflow") VoidKind []
-
-\end{code}
-
-Storage manager nonsense.  Note that the indices are dependent on 
-the definition of the smInfo structure in SMinterface.lh
-
-\begin{code}
-
-#include "../../includes/platform.h"
-
-#if alpha_TARGET_ARCH
-#include "../../includes/alpha-dec-osf1.h"
-#else
-#if sunos4_TARGET_OS
-#include "../../includes/sparc-sun-sunos4.h"
-#else
-#include "../../includes/sparc-sun-solaris2.h"
-#endif
-#endif
-
-storageMgrInfo, smCAFlist, smOldMutables, smOldLim :: StixTree
-
-storageMgrInfo = sStLitLbl SLIT("StorageMgrInfo")
-smCAFlist  = StInd PtrKind (StIndex PtrKind storageMgrInfo (StInt SM_CAFLIST))
-smOldMutables = StInd PtrKind (StIndex PtrKind storageMgrInfo (StInt SM_OLDMUTABLES))
-smOldLim   = StInd PtrKind (StIndex PtrKind storageMgrInfo (StInt SM_OLDLIM))
-
-smStablePtrTable = StInd PtrKind 
-                        (StIndex PtrKind storageMgrInfo (StInt SM_STABLEPOINTERTABLE))
-
+stackOverflow = StCall SLIT("StackOverflow") VoidRep []
 \end{code}