From 5730f86331df4aa9b3d7b5ab59b1ebeafceaeadb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Sinan=20A=C4=9Facan?= Date: Fri, 22 Mar 2019 10:06:37 +0300 Subject: Minor refactoring in copy array primops: - `emitCopySmallArray` now checks size before generating code and doesn't generate any code when size is 0. `emitCopyArray` already does this so this makes small/large array cases the same in argument checking. - In both `emitCopySmallArray` and `emitCopyArray` read the `dflags` after checking the argument. --- compiler/codeGen/StgCmmPrim.hs | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) (limited to 'compiler/codeGen/StgCmmPrim.hs') diff --git a/compiler/codeGen/StgCmmPrim.hs b/compiler/codeGen/StgCmmPrim.hs index a6f3395425..714e544f8f 100644 --- a/compiler/codeGen/StgCmmPrim.hs +++ b/compiler/codeGen/StgCmmPrim.hs @@ -2174,9 +2174,10 @@ emitCopyArray :: (CmmExpr -> CmmExpr -> CmmExpr -> CmmExpr -> ByteOff -> CmmExpr -- ^ offset in destination array -> WordOff -- ^ number of elements to copy -> FCode () -emitCopyArray copy src0 src_off dst0 dst_off0 n = do - dflags <- getDynFlags +emitCopyArray copy src0 src_off dst0 dst_off0 n = when (n /= 0) $ do + dflags <- getDynFlags + -- Passed as arguments (be careful) src <- assignTempE src0 dst <- assignTempE dst0 @@ -2236,23 +2237,24 @@ emitCopySmallArray :: (CmmExpr -> CmmExpr -> CmmExpr -> CmmExpr -> ByteOff -> CmmExpr -- ^ offset in destination array -> WordOff -- ^ number of elements to copy -> FCode () -emitCopySmallArray copy src0 src_off dst0 dst_off n = do - dflags <- getDynFlags +emitCopySmallArray copy src0 src_off dst0 dst_off n = + when (n /= 0) $ do + dflags <- getDynFlags - -- Passed as arguments (be careful) - src <- assignTempE src0 - dst <- assignTempE dst0 + -- Passed as arguments (be careful) + src <- assignTempE src0 + dst <- assignTempE dst0 - -- Set the dirty bit in the header. - emit (setInfo dst (CmmLit (CmmLabel mkSMAP_DIRTY_infoLabel))) + -- Set the dirty bit in the header. + emit (setInfo dst (CmmLit (CmmLabel mkSMAP_DIRTY_infoLabel))) - dst_p <- assignTempE $ cmmOffsetExprW dflags - (cmmOffsetB dflags dst (smallArrPtrsHdrSize dflags)) dst_off - src_p <- assignTempE $ cmmOffsetExprW dflags - (cmmOffsetB dflags src (smallArrPtrsHdrSize dflags)) src_off - let bytes = wordsToBytes dflags n + dst_p <- assignTempE $ cmmOffsetExprW dflags + (cmmOffsetB dflags dst (smallArrPtrsHdrSize dflags)) dst_off + src_p <- assignTempE $ cmmOffsetExprW dflags + (cmmOffsetB dflags src (smallArrPtrsHdrSize dflags)) src_off + let bytes = wordsToBytes dflags n - copy src dst dst_p src_p bytes + copy src dst dst_p src_p bytes -- | Takes an info table label, a register to return the newly -- allocated array in, a source array, an offset in the source array, -- cgit v1.2.1