Skip to content

Commit 808f6e9

Browse files
committed
Update SCC annotations so that compiler profiling reports costs by pass sensibly.
1 parent 4c47ab0 commit 808f6e9

File tree

10 files changed

+19
-16
lines changed

10 files changed

+19
-16
lines changed

makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@
3939
# center insertion. This way (i) you're profiling optimized rather
4040
# than unoptimized Dex, and (ii) the profile data is restricted to our
4141
# {-# SCC #-} annotations, and thus not as overwhelming.
42+
# - As a reminder, runtime profiling is turned on by passing +RTS -p
43+
# -RTS to `dexprof`; you can read the resulting .prof file directly,
44+
# or postprocess it into a more legible form by for example
45+
# running `profiteur` on it and browsing the HTML page so
46+
# created.
4247
#
4348
# We keep the builds in separate .stack-work directories so they don't
4449
# step on each other's GHC-level compilation caches.

src/lib/Imp.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ toImpFunction cc (TopLam True destTy lam) = do
7474
void $ translateBlock body
7575
return []
7676
toImpFunction _ (TopLam False _ _) = error "expected a lambda in destination-passing form"
77+
{-# SCC toImpFunction #-}
7778

7879
getNaryLamImpArgTypesWithCC :: EnvReader m
7980
=> CallingConvention -> PiType SimpIR n -> m n [BaseType]
@@ -1431,8 +1432,7 @@ appSpecializedIxMethod d method args = do
14311432

14321433
-- === Abstracting link-time objects ===
14331434

1434-
abstractLinktimeObjects
1435-
:: forall m n. EnvReader m
1435+
abstractLinktimeObjects :: forall m n. EnvReader m
14361436
=> ImpFunction n -> m n (ClosedImpFunction n, [TopFunName n], [PtrName n])
14371437
abstractLinktimeObjects f = do
14381438
let allVars = freeVarsE f

src/lib/ImpToLLVM.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ impToLLVM logger fNameHint (ClosedImpFunction funBinders ptrBinders impFun) = do
182182
let sv = PtrSubstVal $ L.ConstantOperand $ globalReference ptrTy' v'
183183
return (defn, sv)
184184
return (defns, cnames, substVals)
185+
{-# SCC impToLLVM #-}
185186

186187
compileFunction
187188
:: (EnvReader m, MonadIO1 m)
@@ -296,6 +297,7 @@ compileFunction logger fName env fun@(ImpFunction (IFunType cc argTys retTys)
296297
mainFun <- makeFunction fName argParams (Just $ i64Lit 0)
297298
extraSpecs <- gets funSpecs
298299
return ([L.GlobalDefinition mainFun], extraSpecs, [])
300+
{-# SCC compileFunction #-}
299301

300302
compileInstr :: Compiler m => ImpInstr i -> m i o [Operand]
301303
compileInstr instr = case instr of

src/lib/Inline.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ inlineBindings :: (EnvReader m) => STopLam n -> m n (STopLam n)
2626
inlineBindings = liftLamExpr \(Abs decls ans) -> liftInlineM $
2727
buildScoped $ inlineDecls decls $ inline Stop ans
2828
{-# INLINE inlineBindings #-}
29+
{-# SCC inlineBindings #-}
2930

3031
-- === Data Structure ===
3132

src/lib/LLVM/Compile.hs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,12 @@ compileLLVM :: PassLogger -> LLVMOptLevel -> L.Module -> String -> IO BS.ByteStr
4949
compileLLVM logger opt ast exportName = do
5050
tm <- LLVM.Shims.newDefaultHostTargetMachine
5151
withContext \c -> do
52-
Mod.withModuleFromAST c ast \m -> do
52+
{-# SCC "LLVM.Internal.Module.withModuleFromAST" #-} Mod.withModuleFromAST c ast \m -> do
5353
standardCompilationPipeline opt
5454
logger
5555
[exportName] tm m
56-
Mod.moduleObject tm m
56+
{-# SCC "LLVM.Internal.Module.moduleObject" #-} Mod.moduleObject tm m
57+
{-# SCC compileLLVM #-}
5758

5859
-- === LLVM passes ===
5960

src/lib/Optimize.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ optimize = dceTop -- Clean up user code
3636
>=> unrollLoops
3737
>=> dceTop -- Clean up peephole-optimized code after unrolling
3838
>=> hoistLoopInvariant
39-
{-# SCC optimize #-}
4039

4140
-- === Peephole optimizations ===
4241

@@ -210,6 +209,7 @@ peepholeExpr expr = case expr of
210209

211210
unrollLoops :: EnvReader m => STopLam n -> m n (STopLam n)
212211
unrollLoops = liftLamExpr unrollLoopsBlock
212+
{-# SCC unrollLoops #-}
213213

214214
unrollLoopsBlock :: EnvReader m => SBlock n -> m n (SBlock n)
215215
unrollLoopsBlock b = liftM fst $

src/lib/Runtime.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ callEntryFun LLVMCallable{nativeFun, benchRequired, logger, resultTypes} args =
8282
sync
8383
logSkippingFilter logger [EvalTime avgTime (Just (benchRuns, totalTime + evalTime))]
8484
return results
85+
{-# SCC callEntryFun #-}
8586

8687
checkedCallFunPtr :: FD -> Ptr () -> Ptr () -> DexExecutable -> IO Double
8788
checkedCallFunPtr fd argsPtr resultPtr fPtr = do
@@ -91,7 +92,6 @@ checkedCallFunPtr fd argsPtr resultPtr fPtr = do
9192
return exitCode
9293
unless (exitCode == 0) $ throw RuntimeErr ""
9394
return duration
94-
{-# SCC checkedCallFunPtr #-}
9595

9696
withPipeToLogger :: PassLogger -> (FD -> IO a) -> IO a
9797
withPipeToLogger logger writeAction = do

src/lib/Simplify.hs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -246,19 +246,18 @@ data SimplifiedBlock n = SimplifiedBlock (SBlock n) (ReconstructAtom n)
246246
simplifyTopBlock
247247
:: (TopBuilder m, Mut n) => TopBlock CoreIR n -> m n (SimplifiedTopLam n)
248248
simplifyTopBlock (TopLam _ _ (LamExpr Empty body)) = do
249-
SimplifiedBlock block recon <- liftSimplifyM $ buildSimplifiedBlock $ simplifyBlock body
249+
SimplifiedBlock block recon <- liftSimplifyM do
250+
{-# SCC "Simplify" #-} buildSimplifiedBlock $ simplifyBlock body
250251
topLam <- asTopLam $ LamExpr Empty block
251252
return $ SimplifiedTopLam topLam recon
252253
simplifyTopBlock _ = error "not a block (nullary lambda)"
253-
{-# SCC simplifyTopBlock #-}
254254

255255
simplifyTopFunction :: (TopBuilder m, Mut n) => CTopLam n -> m n (STopLam n)
256256
simplifyTopFunction (TopLam False _ f) = do
257257
asTopLam =<< liftSimplifyM do
258-
(lam, CoerceReconAbs) <- simplifyLam f
258+
(lam, CoerceReconAbs) <- {-# SCC "Simplify" #-} simplifyLam f
259259
return lam
260260
simplifyTopFunction _ = error "shouldn't be in destination-passing style already"
261-
{-# SCC simplifyTopFunction #-}
262261

263262
applyReconTop :: (EnvReader m, Fallible1 m) => ReconstructAtom n -> SAtom n -> m n (CAtom n)
264263
applyReconTop = applyRecon

src/lib/TopLevel.hs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,6 @@ evalSourceBlock mname block = do
242242
_ -> return ()
243243
_ -> return ()
244244
return $ filterLogs block $ addResultCtx block result
245-
{-# SCC evalSourceBlock #-}
246245

247246
evalSourceBlock'
248247
:: (Topper m, Mut n) => ModuleSourceName -> SourceBlock -> m n ()
@@ -529,7 +528,6 @@ evalUExpr expr = do
529528
renamed <- logPass RenamePass $ renameSourceNamesUExpr expr
530529
typed <- checkPass TypePass $ inferTopUExpr renamed
531530
evalBlock typed
532-
{-# SCC evalUExpr #-}
533531

534532
whenOpt :: Topper m => a -> (a -> m n a) -> m n a
535533
whenOpt x act = getConfig <&> optLevel >>= \case
@@ -638,7 +636,6 @@ execUDecl mname decl = do
638636
vs <- forM xs \x -> emitTopLet hint PlainLet (Atom x)
639637
applyRename (bs@@>(atomVarName <$> vs)) sm >>= emitSourceMap
640638
UDeclResultDone sourceMap' -> emitSourceMap sourceMap'
641-
{-# SCC execUDecl #-}
642639

643640
compileTopLevelFun :: (Topper m, Mut n)
644641
=> CallingConvention -> STopLam n -> m n (ImpFunction n)
@@ -647,7 +644,6 @@ compileTopLevelFun cc fSimp = do
647644
fLower <- checkPass LowerPass $ lowerFullySequential True fOpt
648645
flOpt <- loweredOptimizations fLower
649646
checkPass ImpPass $ toImpFunction cc flOpt
650-
{-# SCC compileTopLevelFun #-}
651647

652648
printCodegen :: (Topper m, Mut n) => CAtom n -> m n String
653649
printCodegen x = do
@@ -716,7 +712,6 @@ packageLLVMCallable impFun = do
716712
logger <- getFilteredLogger
717713
let IFunType _ _ resultTypes = impFunType impFun
718714
return LLVMCallable{..}
719-
{-# SCC packageLLVMCallable #-}
720715

721716
compileToObjCode :: Topper m => WithCNameInterface LLVM.AST.Module -> m n FunObjCode
722717
compileToObjCode astWithNames = forM astWithNames \ast -> do

src/lib/Vectorize.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ vectorizeLoops width (TopLam d ty (LamExpr bsDestB body)) = liftEnvReaderM do
9999
(Abs b'' body'', errs) <- liftTopVectorizeM width $ vectorizeLoopsDestBlock body'
100100
return $ (TopLam d ty (LamExpr (bs' >>> UnaryNest b'') body''), errs)
101101
Nothing -> error "expected a trailing dest binder"
102+
{-# SCC vectorizeLoops #-}
102103

103104
liftTopVectorizeM :: (EnvReader m)
104105
=> Word32 -> TopVectorizeM i i a -> m i (a, Errs)
@@ -139,7 +140,6 @@ vectorizeLoopsDestBlock (Abs (destb:>destTy) body) = do
139140
withFreshBinder (getNameHint destb) destTy' \destb' -> do
140141
extendRenamer (destb @> binderName destb') do
141142
Abs destb' <$> buildBlock (vectorizeLoopsBlock body)
142-
{-# SCC vectorizeLoopsDestBlock #-}
143143

144144
vectorizeLoopsBlock :: (Emits o)
145145
=> Block SimpIR i -> TopVectorizeM i o (SAtom o)

0 commit comments

Comments
 (0)