Skip to content

Commit 0d4a079

Browse files
committed
Abstract emitting memcopy instructions so they are easier to instrument.
1 parent 8d1863c commit 0d4a079

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/lib/Imp.hs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -778,7 +778,7 @@ storeLeaf leafTy dest src = case getRefBufferType leafTy of
778778
BufferType Singleton (UnboxedValue _) -> store dest src
779779
BufferType idxStructure (UnboxedValue _) -> do
780780
numel <- computeElemCountImp idxStructure
781-
emitStatement $ MemCopy dest src numel
781+
memcopy dest src numel
782782
BufferType Singleton (BoxedBuffer elemTy) -> do
783783
load dest >>= freeBox elemTy
784784
Just boxIxStructure <- return $ tryGetBoxIdxStructure leafTy
@@ -823,7 +823,7 @@ cloneBox dest elemTy maybeBufferNumElem srcPtr = do
823823
newPtr <- emitAllocWithContext Unmanaged (elemTypeToBaseType elemTy) numElem
824824
store (sink dest) newPtr
825825
case elemTy of
826-
UnboxedValue _ -> emitStatement $ MemCopy newPtr (sink srcPtr) numElem
826+
UnboxedValue _ -> memcopy newPtr (sink srcPtr) numElem
827827
BoxedBuffer elemTy' -> do
828828
mapOffsetPtrs numElem [newPtr, sink srcPtr] \[newPtrOffset, srcPtrOffset] -> do
829829
load srcPtrOffset >>= cloneBox newPtrOffset elemTy' Nothing
@@ -1272,6 +1272,10 @@ impOffset ref (IIdxRepVal 0) = return ref
12721272
impOffset ref off = emitInstr $ IPtrOffset ref off
12731273
{-# INLINE impOffset #-}
12741274

1275+
memcopy :: (ImpBuilder m, Emits n) => IExpr n -> IExpr n -> IExpr n -> m n ()
1276+
memcopy new src numElem = emitStatement $ MemCopy new src numElem
1277+
{-# INLINE memcopy #-}
1278+
12751279
cast :: Emits n => IExpr n -> BaseType -> SubstImpM i n (IExpr n)
12761280
cast x bt = emitInstr $ ICastOp bt x
12771281

0 commit comments

Comments
 (0)