diff options
author | Ben Gamari <bgamari.foss@gmail.com> | 2015-06-16 20:16:08 +0200 |
---|---|---|
committer | Ben Gamari <ben@smart-cactus.org> | 2015-06-16 20:16:08 +0200 |
commit | 681973c31c614185229bdae4f6b7ab4f6e64753d (patch) | |
tree | 9ef8257217c05f4a05828a04e24199f42e0e2fe0 /compiler/cmm/CmmMachOp.hs | |
parent | d20031d4c88b256cdae264cb05d9d850e973d956 (diff) | |
download | haskell-681973c31c614185229bdae4f6b7ab4f6e64753d.tar.gz |
Encode alignment in MO_Memcpy and friends
Summary:
Alignment needs to be a compile-time constant. Previously the code
generators had to jump through hoops to ensure this was the case as the
alignment was passed as a CmmExpr in the arguments list. Now we take
care of this up front.
This fixes #8131.
Authored-by: Reid Barton <rwbarton@gmail.com>
Dusted-off-by: Ben Gamari <ben@smart-cactus.org>
Tests for T8131
Test Plan: Validate
Reviewers: rwbarton, austin
Reviewed By: rwbarton, austin
Subscribers: bgamari, carter, thomie
Differential Revision: https://phabricator.haskell.org/D624
GHC Trac Issues: #8131
Diffstat (limited to 'compiler/cmm/CmmMachOp.hs')
-rw-r--r-- | compiler/cmm/CmmMachOp.hs | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/compiler/cmm/CmmMachOp.hs b/compiler/cmm/CmmMachOp.hs index e9215d5021..f3f9e74a0b 100644 --- a/compiler/cmm/CmmMachOp.hs +++ b/compiler/cmm/CmmMachOp.hs @@ -21,6 +21,7 @@ module CmmMachOp -- CallishMachOp , CallishMachOp(..), callishMachOpHints , pprCallishMachOp + , machOpMemcpyishAlign -- Atomic read-modify-write , AtomicMachOp(..) @@ -565,12 +566,12 @@ data CallishMachOp -- would the majority of use cases in ghc anyways - -- Note that these three MachOps all take 1 extra parameter than the - -- standard C lib versions. The extra (last) parameter contains - -- alignment of the pointers. Used for optimisation in backends. - | MO_Memcpy - | MO_Memset - | MO_Memmove + -- These three MachOps are parameterised by the known alignment + -- of the destination and source (for memcpy/memmove) pointers. + -- This information may be used for optimisation in backends. + | MO_Memcpy Int + | MO_Memset Int + | MO_Memmove Int | MO_PopCnt Width | MO_Clz Width @@ -600,8 +601,16 @@ pprCallishMachOp mo = text (show mo) callishMachOpHints :: CallishMachOp -> ([ForeignHint], [ForeignHint]) callishMachOpHints op = case op of - MO_Memcpy -> ([], [AddrHint,AddrHint,NoHint,NoHint]) - MO_Memset -> ([], [AddrHint,NoHint,NoHint,NoHint]) - MO_Memmove -> ([], [AddrHint,AddrHint,NoHint,NoHint]) - _ -> ([],[]) + MO_Memcpy _ -> ([], [AddrHint,AddrHint,NoHint]) + MO_Memset _ -> ([], [AddrHint,NoHint,NoHint]) + MO_Memmove _ -> ([], [AddrHint,AddrHint,NoHint]) + _ -> ([],[]) -- empty lists indicate NoHint + +-- | The alignment of a 'memcpy'-ish operation. +machOpMemcpyishAlign :: CallishMachOp -> Maybe Int +machOpMemcpyishAlign op = case op of + MO_Memcpy align -> Just align + MO_Memset align -> Just align + MO_Memmove align -> Just align + _ -> Nothing |