summaryrefslogtreecommitdiff
path: root/compiler/codeGen/StgCmmBind.hs
diff options
context:
space:
mode:
authorSimon Marlow <marlowsd@gmail.com>2012-10-03 09:30:56 +0100
committerSimon Marlow <marlowsd@gmail.com>2012-10-08 09:04:40 +0100
commita7c0387d20c1c9994d1100b14fbb8fb4e28a259e (patch)
treeb95d0a512f951a4a463f1aa5178b0cd5c4fdb410 /compiler/codeGen/StgCmmBind.hs
parentaed37acd4d157791381800d5de960a2461bcbef3 (diff)
downloadhaskell-a7c0387d20c1c9994d1100b14fbb8fb4e28a259e.tar.gz
Produce new-style Cmm from the Cmm parser
The main change here is that the Cmm parser now allows high-level cmm code with argument-passing and function calls. For example: foo ( gcptr a, bits32 b ) { if (b > 0) { // we can make tail calls passing arguments: jump stg_ap_0_fast(a); } return (x,y); } More details on the new cmm syntax are in Note [Syntax of .cmm files] in CmmParse.y. The old syntax is still more-or-less supported for those occasional code fragments that really need to explicitly manipulate the stack. However there are a couple of differences: it is now obligatory to give a list of live GlobalRegs on every jump, e.g. jump %ENTRY_CODE(Sp(0)) [R1]; Again, more details in Note [Syntax of .cmm files]. I have rewritten most of the .cmm files in the RTS into the new syntax, except for AutoApply.cmm which is generated by the genapply program: this file could be generated in the new syntax instead and would probably be better off for it, but I ran out of enthusiasm. Some other changes in this batch: - The PrimOp calling convention is gone, primops now use the ordinary NativeNodeCall convention. This means that primops and "foreign import prim" code must be written in high-level cmm, but they can now take more than 10 arguments. - CmmSink now does constant-folding (should fix #7219) - .cmm files now go through the cmmPipeline, and as a result we generate better code in many cases. All the object files generated for the RTS .cmm files are now smaller. Performance should be better too, but I haven't measured it yet. - RET_DYN frames are removed from the RTS, lots of code goes away - we now have some more canned GC points to cover unboxed-tuples with 2-4 pointers, which will reduce code size a little.
Diffstat (limited to 'compiler/codeGen/StgCmmBind.hs')
-rw-r--r--compiler/codeGen/StgCmmBind.hs41
1 files changed, 25 insertions, 16 deletions
diff --git a/compiler/codeGen/StgCmmBind.hs b/compiler/codeGen/StgCmmBind.hs
index 89d27dd161..5e46dcfd65 100644
--- a/compiler/codeGen/StgCmmBind.hs
+++ b/compiler/codeGen/StgCmmBind.hs
@@ -10,7 +10,7 @@ module StgCmmBind (
cgTopRhsClosure,
cgBind,
emitBlackHoleCode,
- pushUpdateFrame
+ pushUpdateFrame, emitUpdateFrame
) where
#include "HsVersions.h"
@@ -37,7 +37,6 @@ import CLabel
import StgSyn
import CostCentre
import Id
-import Control.Monad
import Name
import Module
import ListSetOps
@@ -48,6 +47,8 @@ import FastString
import Maybes
import DynFlags
+import Control.Monad
+
------------------------------------------------------------------------
-- Top-level bindings
------------------------------------------------------------------------
@@ -460,7 +461,7 @@ closureCodeBody top_lvl bndr cl_info cc args arity body fv_details
(CmmMachOp (mo_wordSub dflags)
[ CmmReg nodeReg
, mkIntExpr dflags (funTag dflags cl_info) ])
- ; whenC node_points (ldvEnterClosure cl_info)
+ ; when node_points (ldvEnterClosure cl_info)
; granYield arg_regs node_points
-- Main payload
@@ -525,8 +526,8 @@ thunkCode cl_info fv_details _cc node arity body
; entryHeapCheck cl_info node' arity [] $ do
{ -- Overwrite with black hole if necessary
-- but *after* the heap-overflow check
- ; whenC (blackHoleOnEntry cl_info && node_points)
- (blackHoleIt cl_info)
+ ; when (blackHoleOnEntry cl_info && node_points)
+ (blackHoleIt cl_info node)
-- Push update frame
; setupUpdate cl_info node $
@@ -545,13 +546,14 @@ thunkCode cl_info fv_details _cc node arity body
-- Update and black-hole wrappers
------------------------------------------------------------------------
-blackHoleIt :: ClosureInfo -> FCode ()
+blackHoleIt :: ClosureInfo -> LocalReg -> FCode ()
-- Only called for closures with no args
-- Node points to the closure
-blackHoleIt closure_info = emitBlackHoleCode (closureSingleEntry closure_info)
+blackHoleIt closure_info node
+ = emitBlackHoleCode (closureSingleEntry closure_info) (CmmReg (CmmLocal node))
-emitBlackHoleCode :: Bool -> FCode ()
-emitBlackHoleCode is_single_entry = do
+emitBlackHoleCode :: Bool -> CmmExpr -> FCode ()
+emitBlackHoleCode is_single_entry node = do
dflags <- getDynFlags
-- Eager blackholing is normally disabled, but can be turned on with
@@ -578,12 +580,12 @@ emitBlackHoleCode is_single_entry = do
-- profiling), so currently eager blackholing doesn't
-- work with profiling.
- whenC eager_blackholing $ do
+ when eager_blackholing $ do
tickyBlackHole (not is_single_entry)
- emitStore (cmmOffsetW dflags (CmmReg nodeReg) (fixedHdrSize dflags))
+ emitStore (cmmOffsetW dflags node (fixedHdrSize dflags))
(CmmReg (CmmGlobal CurrentTSO))
emitPrimCall [] MO_WriteBarrier []
- emitStore (CmmReg nodeReg) (CmmReg (CmmGlobal EagerBlackholeInfo))
+ emitStore node (CmmReg (CmmGlobal EagerBlackholeInfo))
setupUpdate :: ClosureInfo -> LocalReg -> FCode () -> FCode ()
-- Nota Bene: this function does not change Node (even if it's a CAF),
@@ -634,13 +636,20 @@ pushUpdateFrame lbl updatee body
let
hdr = fixedHdrSize dflags * wORD_SIZE dflags
frame = updfr + hdr + sIZEOF_StgUpdateFrame_NoHdr dflags
- off_updatee = hdr + oFFSET_StgUpdateFrame_updatee dflags
--
- emitStore (CmmStackSlot Old frame) (mkLblExpr lbl)
- emitStore (CmmStackSlot Old (frame - off_updatee)) updatee
- initUpdFrameProf frame
+ emitUpdateFrame dflags (CmmStackSlot Old frame) lbl updatee
withUpdFrameOff frame body
+emitUpdateFrame :: DynFlags -> CmmExpr -> CLabel -> CmmExpr -> FCode ()
+emitUpdateFrame dflags frame lbl updatee = do
+ let
+ hdr = fixedHdrSize dflags * wORD_SIZE dflags
+ off_updatee = hdr + oFFSET_StgUpdateFrame_updatee dflags
+ --
+ emitStore frame (mkLblExpr lbl)
+ emitStore (cmmOffset dflags frame off_updatee) updatee
+ initUpdFrameProf frame
+
-----------------------------------------------------------------------------
-- Entering a CAF
--