From 9529d859fef6fe353081588ba96257519a20728a Mon Sep 17 00:00:00 2001 From: Sylvain Henry Date: Thu, 16 Dec 2021 17:19:44 +0100 Subject: Perf: avoid using (replicateM . length) when possible Extracted from !6622 --- compiler/GHC/CmmToAsm/AArch64/Instr.hs | 3 +-- compiler/GHC/CmmToAsm/PPC/Instr.hs | 3 +-- compiler/GHC/CmmToAsm/X86/Instr.hs | 3 +-- compiler/GHC/Runtime/Heap/Inspect.hs | 3 +-- 4 files changed, 4 insertions(+), 8 deletions(-) diff --git a/compiler/GHC/CmmToAsm/AArch64/Instr.hs b/compiler/GHC/CmmToAsm/AArch64/Instr.hs index 189f57464b..a3eba828f0 100644 --- a/compiler/GHC/CmmToAsm/AArch64/Instr.hs +++ b/compiler/GHC/CmmToAsm/AArch64/Instr.hs @@ -28,7 +28,6 @@ import GHC.Types.Unique.Supply import GHC.Utils.Panic -import Control.Monad (replicateM) import Data.Maybe (fromMaybe) import GHC.Stack @@ -461,7 +460,7 @@ allocMoreStack _ _ top@(CmmData _ _) = return (top,[]) allocMoreStack platform slots proc@(CmmProc info lbl live (ListGraph code)) = do let entries = entryBlocks proc - uniqs <- replicateM (length entries) getUniqueM + uniqs <- getUniquesM let delta = ((x + stackAlign - 1) `quot` stackAlign) * stackAlign -- round up diff --git a/compiler/GHC/CmmToAsm/PPC/Instr.hs b/compiler/GHC/CmmToAsm/PPC/Instr.hs index 2f99528498..524a7153b0 100644 --- a/compiler/GHC/CmmToAsm/PPC/Instr.hs +++ b/compiler/GHC/CmmToAsm/PPC/Instr.hs @@ -58,7 +58,6 @@ import GHC.Platform import GHC.Types.Unique.FM (listToUFM, lookupUFM) import GHC.Types.Unique.Supply -import Control.Monad (replicateM) import Data.Maybe (fromMaybe) @@ -116,7 +115,7 @@ allocMoreStack platform slots (CmmProc info lbl live (ListGraph code)) = do | entry `elem` infos -> infos | otherwise -> entry : infos - uniqs <- replicateM (length entries) getUniqueM + uniqs <- getUniquesM let delta = ((x + stackAlign - 1) `quot` stackAlign) * stackAlign -- round up diff --git a/compiler/GHC/CmmToAsm/X86/Instr.hs b/compiler/GHC/CmmToAsm/X86/Instr.hs index 6418144bb8..e055fafb61 100644 --- a/compiler/GHC/CmmToAsm/X86/Instr.hs +++ b/compiler/GHC/CmmToAsm/X86/Instr.hs @@ -66,7 +66,6 @@ import GHC.Types.Unique.Supply import GHC.Types.Basic (Alignment) import GHC.Cmm.DebugBlock (UnwindTable) -import Control.Monad import Data.Maybe (fromMaybe) -- Format of an x86/x86_64 memory address, in bytes. @@ -957,7 +956,7 @@ allocMoreStack _ _ top@(CmmData _ _) = return (top,[]) allocMoreStack platform slots proc@(CmmProc info lbl live (ListGraph code)) = do let entries = entryBlocks proc - uniqs <- replicateM (length entries) getUniqueM + uniqs <- getUniquesM let delta = ((x + stackAlign - 1) `quot` stackAlign) * stackAlign -- round up diff --git a/compiler/GHC/Runtime/Heap/Inspect.hs b/compiler/GHC/Runtime/Heap/Inspect.hs index c01cf10da3..52c79e50a3 100644 --- a/compiler/GHC/Runtime/Heap/Inspect.hs +++ b/compiler/GHC/Runtime/Heap/Inspect.hs @@ -839,8 +839,7 @@ cvObtainTerm hsc_env max_depth force old_ty hval = runTR hsc_env $ do traceTR (text "Not constructor" <+> ppr dcname) let dflags = hsc_dflags hsc_env tag = showPpr dflags dcname - vars <- replicateM (length pArgs) - (newVar liftedTypeKind) + vars <- mapM (const (newVar liftedTypeKind)) pArgs subTerms <- sequence $ zipWith (\x tv -> go (pred max_depth) tv tv x) pArgs vars return (Term my_ty (Left ('<' : tag ++ ">")) a subTerms) -- cgit v1.2.1