[commit: ghc] master: Comments on virtHp, realHp (Trac #8864) (b0416e7)

git at git.haskell.org git at git.haskell.org
Thu Mar 13 12:25:09 UTC 2014


Repository : ssh://git@git.haskell.org/ghc

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/b0416e776d2959ac8b9903eb9301b7b967c53a8e/ghc

>---------------------------------------------------------------

commit b0416e776d2959ac8b9903eb9301b7b967c53a8e
Author: Simon Peyton Jones <simonpj at microsoft.com>
Date:   Tue Mar 11 13:09:21 2014 +0000

    Comments on virtHp, realHp (Trac #8864)
    
    Documentation in response to Johan's questions
    
    Plus, don't export hpRel from StgCmmHeap, StgCmmLayout
      (it is only used locally in StgCmmLayout)


>---------------------------------------------------------------

b0416e776d2959ac8b9903eb9301b7b967c53a8e
 compiler/codeGen/StgCmmHeap.hs   |    2 +-
 compiler/codeGen/StgCmmLayout.hs |    5 +++--
 compiler/codeGen/StgCmmMonad.hs  |   36 +++++++++++++++++++++++++++++++++---
 3 files changed, 37 insertions(+), 6 deletions(-)

diff --git a/compiler/codeGen/StgCmmHeap.hs b/compiler/codeGen/StgCmmHeap.hs
index 488a0e0..a3a47a6 100644
--- a/compiler/codeGen/StgCmmHeap.hs
+++ b/compiler/codeGen/StgCmmHeap.hs
@@ -8,7 +8,7 @@
 
 module StgCmmHeap (
         getVirtHp, setVirtHp, setRealHp,
-        getHpRelOffset, hpRel,
+        getHpRelOffset,
 
         entryHeapCheck, altHeapCheck, noEscapeHeapCheck, altHeapCheckReturnsTo,
         heapStackCheckGen,
diff --git a/compiler/codeGen/StgCmmLayout.hs b/compiler/codeGen/StgCmmLayout.hs
index 7fbcbce..59afc89 100644
--- a/compiler/codeGen/StgCmmLayout.hs
+++ b/compiler/codeGen/StgCmmLayout.hs
@@ -15,7 +15,7 @@ module StgCmmLayout (
 
         slowCall, directCall,
 
-        mkVirtHeapOffsets, mkVirtConstrOffsets, getHpRelOffset, hpRel,
+        mkVirtHeapOffsets, mkVirtConstrOffsets, getHpRelOffset, 
 
         ArgRep(..), toArgRep, argRepSizeW -- re-exported from StgCmmArgRep
   ) where
@@ -366,13 +366,14 @@ slowArgs dflags args -- careful: reps contains voids (V), but args does not
 ----        Laying out objects on the heap and stack
 -------------------------------------------------------------------------
 
--- The heap always grows upwards, so hpRel is easy
+-- The heap always grows upwards, so hpRel is easy to compute
 hpRel :: VirtualHpOffset         -- virtual offset of Hp
       -> VirtualHpOffset         -- virtual offset of The Thing
       -> WordOff                -- integer word offset
 hpRel hp off = off - hp
 
 getHpRelOffset :: VirtualHpOffset -> FCode CmmExpr
+-- See Note [Virtual and real heap pointers] in StgCmmMonad
 getHpRelOffset virtual_offset
   = do dflags <- getDynFlags
        hp_usg <- getHpUsage
diff --git a/compiler/codeGen/StgCmmMonad.hs b/compiler/codeGen/StgCmmMonad.hs
index 3d82e69..348b7b9 100644
--- a/compiler/codeGen/StgCmmMonad.hs
+++ b/compiler/codeGen/StgCmmMonad.hs
@@ -331,17 +331,47 @@ data CgState
 
      cgs_uniqs :: UniqSupply }
 
-data HeapUsage =
-  HeapUsage {
+data HeapUsage   -- See Note [Virtual and real heap pointers]
+  = HeapUsage {
         virtHp :: VirtualHpOffset,       -- Virtual offset of highest-allocated word
                                          --   Incremented whenever we allocate
         realHp :: VirtualHpOffset        -- realHp: Virtual offset of real heap ptr
                                          --   Used in instruction addressing modes
-  }
+    }
 
 type VirtualHpOffset = WordOff
 
 
+{- Note [Virtual and real heap pointers]
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+The code generator can allocate one or more objects contiguously, performing
+one heap check to cover allocation of all the objects at once.  Let's call
+this little chunk of heap space an "allocation chunk".  The code generator
+will emit code to
+  * Perform a heap-exhaustion check
+  * Move the heap pointer to the end of the allocation chunk
+  * Allocate multiple objects within the chunk
+
+The code generator uses VirtualHpOffsets to address words within a
+single allocation chunk; these start at one and increase positively.
+The first word of the chunk has VirtualHpOffset=1, the second has
+VirtualHpOffset=2, and so on.
+
+ * The field realHp tracks (the VirtualHpOffset) where the real Hp
+   register is pointing.  Typically it'll be pointing to the end of the
+   allocation chunk.
+
+ * The field virtHp gives the VirtualHpOffset of the highest-allocated
+   word so far.  It starts at zero (meaning no word has been allocated),
+   and increases whenever an object is allocated.
+
+The difference between realHp and virtHp gives the offset from the
+real Hp register of a particular word in the allocation chunk. This
+is what getHpRelOffset does.  Since the returned offset is relative
+to the real Hp register, it is valid only until you change the real
+Hp register.  (Changing virtHp doesn't matter.)
+-}
+
 
 initCgState :: UniqSupply -> CgState
 initCgState uniqs



More information about the ghc-commits mailing list